developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.06k stars 361 forks source link

Terser pure annotation stripped from build #871

Closed dwightjack closed 3 years ago

dwightjack commented 3 years ago

Hello!

I am using a /*#__PURE__*/ annotation to make a library tree shakable, but the annotation is stripped out from the build.

I am probably doing something wrong. Any hint on how to fix this?

developit commented 3 years ago

Interesting - this should have been fixed by #848 - any chance you're ending up with an old version of Microbundle from npx?

Perhaps there's a separate issue where TS is stripping the annotation.

dwightjack commented 3 years ago

Hi, thanks for your support. I've tried to remove package-lock and node_modules to refresh the package, but the problem persists.

I've created a minimal example repo here: https://github.com/dwightjack/demo-microbundle

In the dist folder, I see that the comment is removed from the bundled files.

Perhaps there's a separate issue where TS is stripping the annotation.

The file in the demo repo is a plan JS file (not sure if TS parses it anyway, though).

dwightjack commented 3 years ago

I was trying to verify if this is a problem with terser, and I noticed that the format.comments regexp might be incorrect. I think it should be:

// note the "+" after the character set
- /^\s*([@#]__[A-Z]__\s*$|@cc_on)/
+ /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/
dwightjack commented 3 years ago

I confirm this has been fixed in version 0.14.0.