Skip to content

Commit b820933

Browse files
committed
Address PR review feedback (#5742)
- Preserve Sim references adjacent to right-shift operators - Add regression coverage for signed and unsigned shifts Note: pre-existing type-check failures in audit exports and linked workspace dependencies were not addressed by this PR.
1 parent a5e1c3d commit b820933

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

apps/sim/lib/workflows/blocks/format-function-code.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ return { input, result };`,
108108
})
109109
})
110110

111+
it('preserves Sim references followed by right-shift operators', async () => {
112+
const cases = [
113+
['<start.value>>>2', '<start.value> >> 2'],
114+
['<start.value>>>>2', '<start.value> >>> 2'],
115+
]
116+
117+
for (const [shift, expectedShift] of cases) {
118+
const code = `const shifted=${shift};return shifted;`
119+
120+
await expect(formatFunctionCode(code, CodeLanguage.JavaScript)).resolves.toEqual({
121+
code: `const shifted = ${expectedShift};\nreturn shifted;`,
122+
changed: true,
123+
error: null,
124+
})
125+
}
126+
})
127+
111128
it('preserves statement boundaries around Sim references', async () => {
112129
const code = 'const items=<start.items>;[1,2].forEach(console.log);'
113130

apps/sim/lib/workflows/blocks/format-function-code.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ function looksLikeLanguageComparison(
100100
source: string,
101101
language: FormattableCodeLanguage
102102
): boolean {
103-
if (source[index - 1] === '<' || source[index + length] === '>') return true
103+
const followsLeftAngleBracket = source[index - 1] === '<'
104+
const followedByRightAngleBracket = source[index + length] === '>'
105+
const followedByRightShiftOperator = source.startsWith('>>', index + length)
106+
if (followsLeftAngleBracket || (followedByRightAngleBracket && !followedByRightShiftOperator)) {
107+
return true
108+
}
104109

105110
const sourceBeforeReference = source.slice(0, index).trimEnd()
106111
const sourceAfterReference = source.slice(index + length).trimStart()

0 commit comments

Comments
 (0)