From e39a616ceb45883b3dbf520924f621734e1534f0 Mon Sep 17 00:00:00 2001 From: Jesse Luoto Date: Mon, 16 Dec 2024 20:54:29 +0200 Subject: [PATCH] Fix strict mode crashing on arguemnts assign 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. --- .../visit-all-identifiers.test.ts | 17 +++++++++++++++++ .../local-llm-rename/visit-all-identifiers.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/plugins/local-llm-rename/visit-all-identifiers.test.ts b/src/plugins/local-llm-rename/visit-all-identifiers.test.ts index e821218..a1d3a9a 100644 --- a/src/plugins/local-llm-rename/visit-all-identifiers.test.ts +++ b/src/plugins/local-llm-rename/visit-all-identifiers.test.ts @@ -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() + ); +}); diff --git a/src/plugins/local-llm-rename/visit-all-identifiers.ts b/src/plugins/local-llm-rename/visit-all-identifiers.ts index bcd434c..f50024e 100644 --- a/src/plugins/local-llm-rename/visit-all-identifiers.ts +++ b/src/plugins/local-llm-rename/visit-all-identifiers.ts @@ -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(); const visited = new Set();