Skip to content

Commit

Permalink
feat: Add keepNames option (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Oct 15, 2021
1 parent 90481fa commit 8839713
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Options = {
minifyWhitespace?: boolean
minifyIdentifiers?: boolean
minifySyntax?: boolean
keepNames?: boolean
legalComments?: CommonOptions['legalComments']
target?: string | string[]
/**
Expand Down Expand Up @@ -170,6 +171,7 @@ export default (options: Options = {}): Plugin => {
sourcefile: id,
pure: options.pure,
legalComments: options.legalComments,
keepNames: options.keepNames,
})

await warn(this, result.warnings)
Expand Down
14 changes: 13 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ test('minify', async () => {
`)
})

test('keepNames', async () => {
mockfs({
'./fixture/index.js': `
export default class Foo {}
`,
})
const output = await build({ minify: true, keepNames: true })
expect(output[0].code).toMatchInlineSnapshot(`
"var a=Object.defineProperty,t=(e,r)=>a(e,\\"name\\",{value:r,configurable:!0});class o{}t(o,\\"Foo\\");export default o;
"
`)
})

test('minify whitespace only', async () => {
mockfs({
'./fixture/index.js': `
Expand All @@ -106,7 +119,6 @@ test('minify syntax only', async () => {
`)
})


test('legal comments none', async () => {
mockfs({
'./fixture/index.js': `/** @preserve comment */
Expand Down

0 comments on commit 8839713

Please sign in to comment.