fix(core): Handle item, items and $node correctly in JS task runner (no-changelog) (#11660)

This commit is contained in:
Tomi Turtiainen 2024-11-11 13:55:55 +02:00 committed by GitHub
parent f1e2df7d07
commit 0a05aa4862
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -62,6 +62,15 @@ describe('BuiltInsParser', () => {
expect(state).toEqual(new BuiltInsParserState({ needs$input: true }));
});
test.each([['items'], ['item']])(
'should mark input as needed when %s is used',
(identifier) => {
const state = parseAndExpectOk(`return ${identifier};`);
expect(state).toEqual(new BuiltInsParserState({ needs$input: true }));
},
);
});
describe('$(...)', () => {
@ -135,6 +144,13 @@ describe('BuiltInsParser', () => {
);
});
describe('$node', () => {
it('should require all nodes when $node is used', () => {
const state = parseAndExpectOk('return $node["name"];');
expect(state).toEqual(new BuiltInsParserState({ needsAllNodes: true, needs$input: true }));
});
});
describe('ECMAScript syntax', () => {
describe('ES2020', () => {
it('should parse optional chaining', () => {

View file

@ -125,8 +125,19 @@ export class BuiltInsParser {
private visitIdentifier = (node: Identifier, state: BuiltInsParserState) => {
if (node.name === '$env') {
state.markEnvAsNeeded();
} else if (node.name === '$input' || node.name === '$json') {
} else if (
node.name === '$input' ||
node.name === '$json' ||
node.name === 'items' ||
// item is deprecated but we still need to support it
node.name === 'item'
) {
state.markInputAsNeeded();
} else if (node.name === '$node') {
// $node is legacy way of accessing any node's output. We need to
// support it for backward compatibility, but we're not gonna
// implement any optimizations
state.markNeedsAllNodes();
} else if (node.name === '$execution') {
state.markExecutionAsNeeded();
} else if (node.name === '$prevNode') {