Skip to content

Commit

Permalink
fix: generateUid with invalid name
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Aug 2, 2024
1 parent 7582c1f commit 256ed61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/webcrack/src/ast-utils/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function generateUid(scope: Scope, name: string = 'temp'): string {
let uid = '';
let i = 1;
do {
uid = i > 1 ? `${name}${i}` : toIdentifier(name);
uid = toIdentifier(i > 1 ? `${name}${i}` : name);
i++;
} while (
scope.hasLabel(uid) ||
Expand Down
7 changes: 7 additions & 0 deletions packages/webcrack/test/mangle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ test('variable', () => {
expectJS('const x = require("fs");').toMatchInlineSnapshot(
`const fs = require("fs");`,
);
expectJS(`
const x = require("node:fs");
const y = require("node:fs");
`).toMatchInlineSnapshot(`
const nodeFs = require("node:fs");
const nodeFs2 = require("node:fs");
`);
});

test('ignore exports', () => {
Expand Down

0 comments on commit 256ed61

Please sign in to comment.