Skip to content

Commit

Permalink
fix: empty code error
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Sep 29, 2024
1 parent 64a1b95 commit 4a4b05c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 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 @@ -7,6 +7,11 @@ test("no-op returns the same code", async () => {
assert.equal(code, await visitAllIdentifiers(code, async (name) => name));
});

test("no-op returns the same empty code", async () => {
const code = "";
assert.equal(code, await visitAllIdentifiers(code, async (name) => name));
});

test("renames a simple variable", async () => {
const code = `const a = 1;`;
assert.equal(
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/local-llm-rename/visit-all-identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export async function visitAllIdentifiers(
onProgress?.(1);

const stringified = await transformFromAstAsync(ast);
if (!stringified?.code) {
if (stringified?.code == null) {
throw new Error("Failed to stringify code");
}
return stringified?.code;
return stringified.code;
}

function findIdentifierWithLargestScopeNotVisited(
Expand Down

0 comments on commit 4a4b05c

Please sign in to comment.