diff --git a/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx b/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx index 4dc6ef98..1aa106c8 100644 --- a/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx +++ b/packages/components/src/components/SquiggleViewer/ExpressionViewer.tsx @@ -248,7 +248,7 @@ export const ExpressionViewer: React.FC = ({ value, width }) => { {(_) => value.value .entries() - .filter(([key, _]) => !key.match(/^(Math|System)\./)) + .filter(([key, _]) => !key.match(/^(__result__)$/)) .map(([key, r]) => ( `"${arg.replace(new RegExp('"', "g"), '\\"')}"`; const argsSource = args .map((arg) => (typeof arg === "number" ? arg : quote(arg))) .join(","); - const functionNameSource = this.location.path.items + + // end expression values are exposed in bindings via secret `__result__` variable and we can access them through it + const pathItems = [ + ...(this.location.path.root === "result" ? ["__result__"] : []), + ...this.location.path.items, + ]; + + // full function name, e.g. foo.bar[3].baz + const functionNameSource = pathItems .map((item, i) => typeof item === "string" ? (i ? "." + item : item) : `[${item}]` ) .join(""); + + // something like: foo.bar[3].baz(1,2,3) const source = `${functionNameSource}(${argsSource})`; + project.setSource(callId, source); project.setContinues(callId, [sourceId]); project.run(callId);