diff --git a/packages/webcrack/src/ast-utils/scope.ts b/packages/webcrack/src/ast-utils/scope.ts index c8fb4828..bb322e6a 100644 --- a/packages/webcrack/src/ast-utils/scope.ts +++ b/packages/webcrack/src/ast-utils/scope.ts @@ -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) || diff --git a/packages/webcrack/test/mangle.test.ts b/packages/webcrack/test/mangle.test.ts index 1499e942..a0972528 100644 --- a/packages/webcrack/test/mangle.test.ts +++ b/packages/webcrack/test/mangle.test.ts @@ -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', () => {