Skip to content

Commit

Permalink
feat: support legal comments (#246)
Browse files Browse the repository at this point in the history
* feat: add legalComments

* feat: add legalComments

* refactor

Co-authored-by: asins <asinsimple@alibaba-inc.com>
Co-authored-by: EGOIST <0x142857@gmail.com>
  • Loading branch information
3 people committed Jun 3, 2021
1 parent a436a17 commit 920eee9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { existsSync, statSync } from 'fs'
import { extname, resolve, dirname, join } from 'path'
import { Plugin, PluginContext } from 'rollup'
import { transform, Loader, formatMessages, Message } from 'esbuild'
import {
transform,
Loader,
formatMessages,
Message,
CommonOptions,
} from 'esbuild'
import { createFilter, FilterPattern } from '@rollup/pluginutils'
import { getOptions } from './options'
import { bundle } from './bundle'
Expand All @@ -21,6 +27,7 @@ export type Options = {
minifyWhitespace?: boolean
minifyIdentifiers?: boolean
minifySyntax?: boolean
legalComments?: CommonOptions['legalComments']
target?: string | string[]
/**
* Requires esbuild >= 0.12.1
Expand Down Expand Up @@ -160,6 +167,7 @@ export default (options: Options = {}): Plugin => {
define: options.define,
sourcemap: options.sourceMap !== false,
sourcefile: id,
legalComments: options.legalComments,
})

await warn(this, result.warnings)
Expand Down
18 changes: 18 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ test('minify syntax only', async () => {
`)
})


test('legal comments none', async () => {
mockfs({
'./fixture/index.js': `/** @preserve comment */
/*!
* comment
*/
//! comment
console.log(1 === 1);
`,
})
const output = await build({ minify: true, legalComments: 'none' })
expect(output[0].code).toMatchInlineSnapshot(`
"console.log(!0);
"
`)
})

test('load index.(x)', async () => {
mockfs({
'./fixture/index.js': `
Expand Down

0 comments on commit 920eee9

Please sign in to comment.