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
5 changes: 5 additions & 0 deletions .changeset/late-bags-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"microbundle": patch
---

Bugfix: preserve Terser annotations like `/*@__NOINLINE__*/` during Babel pass
2 changes: 1 addition & 1 deletion src/lib/babel-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default () => {
babelOptions.generatorOpts = {
minified: true,
compact: true,
shouldPrintComment: comment => /[@#]__PURE__/.test(comment),
shouldPrintComment: comment => /[@#]__[A-Z]+__/.test(comment),
};
}

Expand Down
48 changes: 48 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,54 @@ exports[`fixtures build shebang with microbundle 5`] = `
"
`;

exports[`fixtures build terser-annotations with microbundle 1`] = `
"Used script: microbundle

Directory tree:

terser-annotations
dist
terser-annotations.esm.js
terser-annotations.esm.js.map
terser-annotations.js
terser-annotations.js.map
terser-annotations.umd.js
terser-annotations.umd.js.map
mangle.json
package.json
src
index.js


Build \\"terserAnnotations\\" to dist:
112 B: terser-annotations.js.gz
86 B: terser-annotations.js.br
117 B: terser-annotations.esm.js.gz
88 B: terser-annotations.esm.js.br
200 B: terser-annotations.umd.js.gz
159 B: terser-annotations.umd.js.br"
`;

exports[`fixtures build terser-annotations with microbundle 2`] = `6`;

exports[`fixtures build terser-annotations with microbundle 3`] = `
"function shouldBePreserved(e,n){return e-n}function main(e,n){return{inlined:function(e,n){return e+n}(e,n),preserved:shouldBePreserved(e,n)}}export default main;
//# sourceMappingURL=terser-annotations.esm.js.map
"
`;

exports[`fixtures build terser-annotations with microbundle 4`] = `
"function shouldBePreserved(e,r){return e-r}module.exports=function(e,r){return{inlined:function(e,r){return e+r}(e,r),preserved:shouldBePreserved(e,r)}};
//# sourceMappingURL=terser-annotations.js.map
"
`;

exports[`fixtures build terser-annotations with microbundle 5`] = `
"!function(e,n){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=n():\\"function\\"==typeof define&&define.amd?define(n):(e||self).terserAnnotations=n()}(this,function(){function shouldBePreserved(e,n){return e-n}return function(e,n){return{inlined:function(e,n){return e+n}(e,n),preserved:shouldBePreserved(e,n)}}});
//# sourceMappingURL=terser-annotations.umd.js.map
"
`;

exports[`fixtures build ts-custom-declaration with microbundle 1`] = `
"Used script: microbundle --generateTypes false

Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/terser-annotations/mangle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"minify": {
"mangle": {
"keep_fnames": true
}
}
}
3 changes: 3 additions & 0 deletions test/fixtures/terser-annotations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "terser-annotations"
}
13 changes: 13 additions & 0 deletions test/fixtures/terser-annotations/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function shouldBeInlined(a, b) {
return a + b;
}

function shouldBePreserved(a, b) {
return a - b;
}

export default function main(a, b) {
const inlined = /*@__INLINE__*/ shouldBeInlined(a, b);
const preserved = /*@__NOINLINE__*/ shouldBePreserved(a, b);
return { inlined, preserved };
}