Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/vite/src/node/__tests__/plugins/terser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ describe('terser', () => {
},
load(id) {
if (id === '\0entry.js') {
return `const foo = 1;console.log(foo)`
return `
const foo = 1;
console.log(foo);
const bar = { hello: 1, ["world"]: 2 };
console.log(bar.hello + bar["world"]);
`
}
},
},
Expand All @@ -52,4 +57,21 @@ describe('terser', () => {
})
expect(resultCode).toContain('prefix_')
})

test('nameCache', async () => {
const nameCache = {}

await run({
compress: false,
mangle: {
properties: {
keep_quoted: true,
},
},
nameCache,
})

expect(nameCache).toHaveProperty('props.props.$hello')
expect(nameCache).not.toHaveProperty('props.props.$world')
})
})
3 changes: 2 additions & 1 deletion packages/vite/src/node/plugins/terser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export function terserPlugin(config: ResolvedConfig): Plugin {
(typeof options.mangle.properties === 'object' &&
options.mangle.properties.nth_identifier?.get))) ||
typeof options.format?.comments === 'function' ||
typeof options.output?.comments === 'function'
typeof options.output?.comments === 'function' ||
options.nameCache
)
},
max: maxWorkers,
Expand Down
Loading