Skip to content

Commit

Permalink
fix(core): Opt-out from optimizations if $item is used (#12036)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored and ivov committed Dec 4, 2024
1 parent b0f6c6f commit dfa1806
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('BuiltInsParser', () => {
const parseAndExpectOk = (code: string) => {
const result = parser.parseUsedBuiltIns(code);
if (!result.ok) {
fail(result.error);
throw result.error;
}

return result.result;
Expand Down Expand Up @@ -151,6 +151,13 @@ describe('BuiltInsParser', () => {
});
});

describe('$item', () => {
it('should require all nodes and input when $item is used', () => {
const state = parseAndExpectOk('$item("0").$node["my node"].json["title"]');
expect(state).toEqual(new BuiltInsParserState({ needsAllNodes: true, needs$input: true }));
});
});

describe('ECMAScript syntax', () => {
describe('ES2020', () => {
it('should parse optional chaining', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export class BuiltInsParser {
private visitIdentifier = (node: Identifier, state: BuiltInsParserState) => {
if (node.name === '$env') {
state.markEnvAsNeeded();
} else if (node.name === '$item') {
// $item is legacy syntax that is basically an alias for WorkflowDataProxy
// and allows accessing any data. We need to support it for backwards
// compatibility, but we're not gonna implement any optimizations
state.markNeedsAllNodes();
} else if (
node.name === '$input' ||
node.name === '$json' ||
Expand Down

0 comments on commit dfa1806

Please sign in to comment.