Skip to content

Commit 3916fa3

Browse files
fix: don't remove comments (#5)
1 parent 6912085 commit 3916fa3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/unassert.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,24 @@ export default function unassert(options = {}) {
5858
if (!filter(id)) { return null; }
5959

6060
return new Promise((resolve) => {
61-
const ast = acorn.parse(code, {sourceType: 'module', locations: true});
61+
const comments = [];
62+
const tokens = [];
63+
64+
const ast = acorn.parse(code, {
65+
sourceType: 'module',
66+
ecmaVersion: 'latest',
67+
locations: true,
68+
ranges: true,
69+
onComment: comments,
70+
onToken: tokens,
71+
});
72+
73+
escodegen.attachComments(ast, comments, tokens);
6274
const unassertedAst = escodegen.generate(unassertjs(ast), {
6375
sourceMap: id,
6476
sourceContent: code,
65-
sourceMapWithCode: true
77+
sourceMapWithCode: true,
78+
comment: true,
6679
});
6780

6881
const inMap = options.sourcemap && handleIncomingSourceMap(code);

0 commit comments

Comments
 (0)