Skip to content

Commit

Permalink
Fix strict mode crashing on arguemnts assign
Browse files Browse the repository at this point in the history
The script was assumed to be in `strict` mode, which is the
functionality of `sourceType: "module"`. This is wrong, as we cannot
assume that the script would be in a strict mode.
  • Loading branch information
jehna committed Dec 16, 2024
1 parent 9c633db commit e39a616
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/plugins/local-llm-rename/visit-all-identifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,20 @@ const bar = 2;
`.trim()
);
});

test("should not craash to 'arguments' assigning", async () => {
const code = `
function foo() {
arguments = '??';
}
`.trim();
const result = await visitAllIdentifiers(code, async () => "foobar", 200);
assert.equal(
result,
`
function foobar() {
arguments = '??';
}
`.trim()
);
});
2 changes: 1 addition & 1 deletion src/plugins/local-llm-rename/visit-all-identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function visitAllIdentifiers(
contextWindowSize: number,
onProgress?: (percentageDone: number) => void
) {
const ast = await parseAsync(code);
const ast = await parseAsync(code, { sourceType: "script" });
const renames = new Set<string>();
const visited = new Set<string>();

Expand Down

0 comments on commit e39a616

Please sign in to comment.