Open Boshen opened 1 month ago
https://github.com/evanw/esbuild/blob/332727499e62315cff4ecaff9fa8b86336555e46/internal/js_ast/js_ast.go#L613-L621
esbuild
decides whether to print the PURE
annotation comments in printer
by marking CanBeUnwrappedIfUnused
during the parser phase.
consider the pure comments may attach to a newly generated AstNode
so the original Span
based comment lookup may invalid in this scenario, after reading https://github.com/oxc-project/backlog/issues/140, I think we could attach the PURE comment to AstNodeAddress
rather than original span
Babel inserts /*#__PURE__*/
comments on generated nodes in class properties transform. We're currently unable to do this (though maybe it's not important).
// Input
class C {
#x = 1;
}
// Output
var _x = /*#__PURE__*/ new WeakMap();
class C {
constructor() {
_classPrivateFieldInitSpec(this, _x, 1);
}
}
Babel inserts
/*#__PURE__*/
comments on generated nodes in class properties transform. We're currently unable to do this (though maybe it's not important).// Input class C { #x = 1; } // Output var _x = /*#__PURE__*/ new WeakMap(); class C { constructor() { _classPrivateFieldInitSpec(this, _x, 1); } }
It depends, from a transformer view it does not matter, but from a bundler view it does matter since it may generate large bundle compare using babel.
Example of babel output:
We lack
/*#__PURE__*/
.