Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
fix: keep names in esbuild minification (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Aug 20, 2022
1 parent ac726c2 commit 4687e8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/transform/get-esbuild-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const getEsbuildOptions = (
* Disabled until esbuild supports names in source maps:
* https://github.com/evanw/esbuild/issues/1296
*/
// minify: true, keepNames: true,
// minify: true,
keepNames: true,
minifySyntax: true,
minifyWhitespace: true,

Expand Down
16 changes: 12 additions & 4 deletions tests/specs/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const fixtures = {
ts: `
export default 'default value' as string;
export const named: string = 'named';
export const functionName: string = (function named() {}).name;
`,

esm: `
export default 'default value';
export const named = 'named';
export const functionName = (function named() {}).name;
`,
};

Expand All @@ -33,9 +35,11 @@ export default testSuite(({ describe }) => {
'/file.js': transformed.code,
}));

expect(JSON.stringify(fsRequire('/file.js'))).toBe(
'{"default":"default value","named":"named"}',
);
expect(fsRequire('/file.js')).toStrictEqual({
default: 'default value',
functionName: 'named',
named: 'named',
});
});

test('transforms file with inline sourcemap string', () => {
Expand Down Expand Up @@ -83,7 +87,11 @@ export default testSuite(({ describe }) => {
);

const imported = await import(base64Module(transformed.code));
expect(JSON.stringify(imported)).toMatch('{"default":"default value","named":"named"}');
expect({ ...imported }).toStrictEqual({
default: 'default value',
functionName: 'named',
named: 'named',
});
});

test('sourcemap file', async () => {
Expand Down

0 comments on commit 4687e8a

Please sign in to comment.