Skip to content

Commit 3534815

Browse files
authored
Bugfix: preserve Terser annotations during Babel pass (#848)
* Bugfix: preserve Terser annotations during Babel pass We were stripping out everything except `__PURE__`, but Terser has a number of annotations using that format - these were previously being ignored. * Create late-bags-argue.md * Add test for Terser annotations
1 parent a5a222e commit 3534815

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

.changeset/late-bags-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"microbundle": patch
3+
---
4+
5+
Bugfix: preserve Terser annotations like `/*@__NOINLINE__*/` during Babel pass

src/lib/babel-custom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export default () => {
196196
babelOptions.generatorOpts = {
197197
minified: true,
198198
compact: true,
199-
shouldPrintComment: comment => /[@#]__PURE__/.test(comment),
199+
shouldPrintComment: comment => /[@#]__[A-Z]+__/.test(comment),
200200
};
201201
}
202202

test/__snapshots__/index.test.js.snap

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,54 @@ exports[`fixtures build shebang with microbundle 5`] = `
26192619
"
26202620
`;
26212621
2622+
exports[`fixtures build terser-annotations with microbundle 1`] = `
2623+
"Used script: microbundle
2624+
2625+
Directory tree:
2626+
2627+
terser-annotations
2628+
dist
2629+
terser-annotations.esm.js
2630+
terser-annotations.esm.js.map
2631+
terser-annotations.js
2632+
terser-annotations.js.map
2633+
terser-annotations.umd.js
2634+
terser-annotations.umd.js.map
2635+
mangle.json
2636+
package.json
2637+
src
2638+
index.js
2639+
2640+
2641+
Build \\"terserAnnotations\\" to dist:
2642+
112 B: terser-annotations.js.gz
2643+
86 B: terser-annotations.js.br
2644+
117 B: terser-annotations.esm.js.gz
2645+
88 B: terser-annotations.esm.js.br
2646+
200 B: terser-annotations.umd.js.gz
2647+
159 B: terser-annotations.umd.js.br"
2648+
`;
2649+
2650+
exports[`fixtures build terser-annotations with microbundle 2`] = `6`;
2651+
2652+
exports[`fixtures build terser-annotations with microbundle 3`] = `
2653+
"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;
2654+
//# sourceMappingURL=terser-annotations.esm.js.map
2655+
"
2656+
`;
2657+
2658+
exports[`fixtures build terser-annotations with microbundle 4`] = `
2659+
"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)}};
2660+
//# sourceMappingURL=terser-annotations.js.map
2661+
"
2662+
`;
2663+
2664+
exports[`fixtures build terser-annotations with microbundle 5`] = `
2665+
"!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)}}});
2666+
//# sourceMappingURL=terser-annotations.umd.js.map
2667+
"
2668+
`;
2669+
26222670
exports[`fixtures build ts-custom-declaration with microbundle 1`] = `
26232671
"Used script: microbundle --generateTypes false
26242672
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"minify": {
3+
"mangle": {
4+
"keep_fnames": true
5+
}
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "terser-annotations"
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function shouldBeInlined(a, b) {
2+
return a + b;
3+
}
4+
5+
function shouldBePreserved(a, b) {
6+
return a - b;
7+
}
8+
9+
export default function main(a, b) {
10+
const inlined = /*@__INLINE__*/ shouldBeInlined(a, b);
11+
const preserved = /*@__NOINLINE__*/ shouldBePreserved(a, b);
12+
return { inlined, preserved };
13+
}

0 commit comments

Comments
 (0)