Skip to content

Commit 522980c

Browse files
icecrasher321claude
andcommitted
fix(executor): divide after a postfix update
`+` and `-` precede a regex as operators, but doubled they end a value, so `i++ / 2` was scanning a regex from the division and swallowing whatever quotes followed it on that line. The check now reads the pair rather than the single character; a lone `+` still admits `params.n + /re/.test(x)`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 4a6ced5 commit 522980c

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

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

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

1003+
it('divides after a postfix update rather than opening a regex', async () => {
1004+
const { block, ctx, resolver } = createResolver('javascript')
1005+
1006+
const result = await resolver.resolveInputsForFunctionBlock(
1007+
ctx,
1008+
'function',
1009+
{
1010+
code: [
1011+
`let i = params.i; const half = i++ / 2 + Number('<producer.result>')`,
1012+
// The same characters as an operator still precede a regex.
1013+
`const hit = params.n + /['"]/.test('<producer.result>')`,
1014+
].join('\n'),
1015+
},
1016+
block
1017+
)
1018+
1019+
const code = result.resolvedInputs.code as string
1020+
expect(code).toContain(`Number('' + JSON.stringify(globalThis["__blockRef_0"]) + '')`)
1021+
expect(code).toContain(`.test('' + JSON.stringify(globalThis["__blockRef_1"]) + '')`)
1022+
})
1023+
10031024
it('does not read a method named after a keyword as a control-flow head', async () => {
10041025
const { block, ctx, resolver } = createResolver('javascript')
10051026

apps/sim/executor/variables/resolver.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,13 @@ export class VariableResolver {
11651165
if (previous === '/' && closes.regexCloseIndices.has(previousSignificantIndex)) {
11661166
return false
11671167
}
1168+
// `+` and `-` precede a regex as operators but end a value when doubled: `i++ / 2` divides.
1169+
if (
1170+
(previous === '+' || previous === '-') &&
1171+
template[previousSignificantIndex - 1] === previous
1172+
) {
1173+
return false
1174+
}
11681175
if (JAVASCRIPT_REGEX_ALLOWED_AFTER.has(previous)) {
11691176
return true
11701177
}

0 commit comments

Comments
 (0)