fix(core): Opt-out from optimizations if $item is used (#12036)

This commit is contained in:
Tomi Turtiainen 2024-12-04 14:32:28 +02:00 committed by GitHub
parent 75ed749172
commit 872535a40c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -17,7 +17,7 @@ describe('BuiltInsParser', () => {
const parseAndExpectOk = (code: string) => { const parseAndExpectOk = (code: string) => {
const result = parser.parseUsedBuiltIns(code); const result = parser.parseUsedBuiltIns(code);
if (!result.ok) { if (!result.ok) {
fail(result.error); throw result.error;
} }
return result.result; return result.result;
@ -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('ECMAScript syntax', () => {
describe('ES2020', () => { describe('ES2020', () => {
it('should parse optional chaining', () => { it('should parse optional chaining', () => {

View file

@ -125,6 +125,11 @@ export class BuiltInsParser {
private visitIdentifier = (node: Identifier, state: BuiltInsParserState) => { private visitIdentifier = (node: Identifier, state: BuiltInsParserState) => {
if (node.name === '$env') { if (node.name === '$env') {
state.markEnvAsNeeded(); 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 ( } else if (
node.name === '$input' || node.name === '$input' ||
node.name === '$json' || node.name === '$json' ||