fix(editor): In Sub-workflow Conversion handle standalone accessor and accessor[0] cases correctly (#16086)

This commit is contained in:
Charlie Kolb
2025-06-06 12:49:11 +02:00
committed by GitHub
parent 576ff4d3b8
commit eb71c41e93
2 changed files with 25 additions and 3 deletions

View File

@@ -207,7 +207,7 @@ function parseExpressionMapping(
return { return {
nodeNameInExpression, nodeNameInExpression,
originalExpression: `${exprStart}.${parts[0]}`, // $('abc').first() originalExpression: `${exprStart}.${parts[0]}`, // $('abc').first()
replacementPrefix: `$('${startNodeName}').${accessorPrefix}`, // $('Start').first() replacementPrefix: `$('${startNodeName}').${accessorPrefix}.json`, // $('Start').first().json
replacementName: `${nodeNamePlainJs}_${convertDataAccessorName(originalName)}`, // nodeName_firstItem, nodeName_itemMatching_20 replacementName: `${nodeNamePlainJs}_${convertDataAccessorName(originalName)}`, // nodeName_firstItem, nodeName_itemMatching_20
}; };
} else { } else {
@@ -266,7 +266,9 @@ function extractExpressionCandidate(expression: string, startIndex: number, endI
// Note that by choosing match 0 we use `itemMatching` matches over `item` // Note that by choosing match 0 we use `itemMatching` matches over `item`
// matches by relying on the order in ITEM_TO_DATA_ACCESSORS // matches by relying on the order in ITEM_TO_DATA_ACCESSORS
const after_accessor_idx = endIndex + (firstPartException[0]?.[0].length ?? -1) + 1; let after_accessor_idx = endIndex + (firstPartException[0]?.[0].length ?? -1);
// skip `.` to continue, but halt before other symbols like `[` in `all()[0]`
if (expression[after_accessor_idx + 1] === '.') after_accessor_idx += 1;
const after_accessor = expression.slice(after_accessor_idx); const after_accessor = expression.slice(after_accessor_idx);
const firstInvalidCharMatch = INVALID_JS_DOT_PATH.exec(after_accessor); const firstInvalidCharMatch = INVALID_JS_DOT_PATH.exec(after_accessor);
@@ -296,6 +298,7 @@ function parseCandidateMatch(
const candidate = extractExpressionCandidate(expression, startIndex, endIndex); const candidate = extractExpressionCandidate(expression, startIndex, endIndex);
if (candidate === null) return null; if (candidate === null) return null;
return parseExpressionMapping( return parseExpressionMapping(
candidate, candidate,
nodeNameInExpression, nodeNameInExpression,

View File

@@ -508,6 +508,8 @@ describe('NodeReferenceParserUtils', () => {
'$("A").last().json.myField', '$("A").last().json.myField',
'$("A").all().json.myField', '$("A").all().json.myField',
'$("A").item.json.myField', '$("A").item.json.myField',
'$("A").first()',
'$("A").all()',
]), ]),
]; ];
nodeNames = ['A', 'B']; nodeNames = ['A', 'B'];
@@ -517,6 +519,8 @@ describe('NodeReferenceParserUtils', () => {
['myField_lastItem', '$("A").last().json.myField'], ['myField_lastItem', '$("A").last().json.myField'],
['myField_allItems', '$("A").all().json.myField'], ['myField_allItems', '$("A").all().json.myField'],
['myField', '$("A").item.json.myField'], ['myField', '$("A").item.json.myField'],
['A_firstItem', '$("A").first()'],
['A_allItems', '$("A").all()'],
]); ]);
expect(result.nodes).toEqual([ expect(result.nodes).toEqual([
{ {
@@ -526,6 +530,8 @@ describe('NodeReferenceParserUtils', () => {
p1: "={{ $('Start').last().json.myField_lastItem }}", p1: "={{ $('Start').last().json.myField_lastItem }}",
p2: "={{ $('Start').first().json.myField_allItems }}", p2: "={{ $('Start').first().json.myField_allItems }}",
p3: "={{ $('Start').item.json.myField }}", p3: "={{ $('Start').item.json.myField }}",
p4: "={{ $('Start').first().json.A_firstItem }}",
p5: "={{ $('Start').first().json.A_allItems }}",
}, },
}, },
]); ]);
@@ -695,7 +701,20 @@ describe('NodeReferenceParserUtils', () => {
}, },
]); ]);
}); });
it('should support handle unexpected code after the data accessor', () => {
nodes = [makeNode('A', ['$("B").all()[0].json.first_node_variable'])];
nodeNames = ['A', 'B'];
const result = extractReferencesInNodeExpressions(nodes, nodeNames, startNodeName);
expect([...result.variables.entries()]).toEqual([['B_allItems', '$("B").all()']]);
expect(result.nodes).toEqual([
{
name: 'A',
parameters: {
p0: "={{ $('Start').first().json.B_allItems[0].json.first_node_variable }}",
},
},
]);
});
it('should carry over unrelated properties', () => { it('should carry over unrelated properties', () => {
nodes = [ nodes = [
{ {