Skip to content

Commit ea25c3c

Browse files
icecrasher321claude
andcommitted
fix(executor): start a new identifier at the character before it
A token continues only when the character immediately before it belongs to the same token. Asking the previous *significant* character instead made a name after a line break look like a continuation, so it kept whatever property-access answer the last token had: `const seen = params.a.b` on one line left the `if` on the next carrying `b`'s, which turned the statement head into a method call and the regex after it into division. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 522980c commit ea25c3c

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

apps/sim/executor/variables/resolver.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,25 @@ describe('VariableResolver function block inputs', () => {
10001000
expect(code).toContain(`Number('' + JSON.stringify(globalThis["__blockRef_2"]) + '')`)
10011001
})
10021002

1003+
it('starts a new identifier at a line break rather than continuing the last one', async () => {
1004+
const { block, ctx, resolver } = createResolver('javascript')
1005+
1006+
const result = await resolver.resolveInputsForFunctionBlock(
1007+
ctx,
1008+
'function',
1009+
{
1010+
// `if` begins a statement here; reading the previous *significant* character would
1011+
// see the `b` of `params.b` and carry its property-access answer into this token.
1012+
code: ['const seen = params.a.b', `if (seen) /['"]/.test('<producer.result>')`].join('\n'),
1013+
},
1014+
block
1015+
)
1016+
1017+
expect(result.resolvedInputs.code).toContain(
1018+
`.test('' + JSON.stringify(globalThis["__blockRef_0"]) + '')`
1019+
)
1020+
})
1021+
10031022
it('divides after a postfix update rather than opening a regex', async () => {
10041023
const { block, ctx, resolver } = createResolver('javascript')
10051024

apps/sim/executor/variables/resolver.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,10 +1479,10 @@ export class VariableResolver {
14791479
lastSignificantIndex = i
14801480
}
14811481
if (this.isJavaScriptIdentifierChar(char)) {
1482-
if (
1483-
previousSignificantIndex < 0 ||
1484-
!this.isJavaScriptIdentifierChar(template[previousSignificantIndex])
1485-
) {
1482+
// An identifier continues only when the character right before it is part of the same
1483+
// token. Asking the previous *significant* character instead treats a name after a
1484+
// line break as a continuation and leaves it carrying the last one's answer.
1485+
if (i === 0 || !this.isJavaScriptIdentifierChar(template[i - 1])) {
14861486
identifierFollowsPropertyAccess = template[previousSignificantIndex] === '.'
14871487
}
14881488
} else if (char === '(') {
@@ -1561,10 +1561,10 @@ export class VariableResolver {
15611561
lastSignificantIndex = i
15621562
}
15631563
if (this.isJavaScriptIdentifierChar(char)) {
1564-
if (
1565-
previousSignificantIndex < 0 ||
1566-
!this.isJavaScriptIdentifierChar(template[previousSignificantIndex])
1567-
) {
1564+
// An identifier continues only when the character right before it is part of the same
1565+
// token. Asking the previous *significant* character instead treats a name after a
1566+
// line break as a continuation and leaves it carrying the last one's answer.
1567+
if (i === 0 || !this.isJavaScriptIdentifierChar(template[i - 1])) {
15681568
identifierFollowsPropertyAccess = template[previousSignificantIndex] === '.'
15691569
}
15701570
} else if (char === '(') {

0 commit comments

Comments
 (0)