Fix #__PURE__ annotations being ignored by Rolldown/Vite 8 (#568)#569
Open
hrithik-infinite wants to merge 1 commit into
Open
Fix #__PURE__ annotations being ignored by Rolldown/Vite 8 (#568)#569hrithik-infinite wants to merge 1 commit into
hrithik-infinite wants to merge 1 commit into
Conversation
Remove the redundant surrounding parens from `(/*#__PURE__*/foo())` patterns. TypeScript inserts a space between the opening `(` and the leading comment when emitting, producing `( /*#__PURE__*/foo())` in the published bundles. Rolldown (used by Vite 8) cannot associate the annotation with the call when the comment is positioned between the open paren and the expression, so the annotation is silently ignored and the call is no longer tree-shaken. Removing the wrapping parens lets TypeScript emit `/*#__PURE__*/ foo()`, which Rolldown interprets correctly. Patterns where the parens are required for a top-level `as` cast are left untouched, because TypeScript already strips both the parens and the cast from the emit, producing a clean annotation. For the `!!(/*#__PURE__*/foo())` callers in `hasDocument`/`hasWindow`/ `hasNavigator`/`hasHistory`, removing the parens places the comment adjacent to `!!`, which TypeScript then drops. The inner annotations were redundant — the parent functions are already marked `/*#__NO_SIDE_EFFECTS__*/`, so callers can drop the calls when the result is unused. Verified the published bundles now contain zero `( /*#__PURE__*/` occurrences (was 159 in v0.14.0); 153 `#__PURE__` annotations are still emitted in valid positions. All node tests pass (1361 es5 + 1371 esnext).
Author
Author
|
Heads up — I'm also seeing 13 Let me know which you'd prefer:
Either is fine with me. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #568 —
/*#__PURE__*/annotations in the published ESM/ES5 bundles were positioned inside the wrapping parentheses (( /*#__PURE__*/foo())), which Rolldown (and therefore Vite 8) cannot interpret. The annotation was silently ignored, so tree-shaking did not kick in for the affected values and downstream Vite 8 builds emitted[INVALID_ANNOTATION]warnings.Root cause
The source uses
(/*#__PURE__*/foo())(no space between(and/*). When TypeScript emits the wrapped form, it inserts a single space between(and the leading comment, producing( /*#__PURE__*/foo())in the published artifacts. Rolldown only recognises the annotation when it is immediately adjacent to the call expression token; the inserted space disqualifies it.This affected all 159
( /*#__PURE__*/occurrences in each ofdist/es5/mod/ts-utils.jsanddist/es6/mod/ts-utils.js.Fix
Remove the redundant surrounding parens from
(/*#__PURE__*/foo())patterns in source. TypeScript then emits/*#__PURE__*/ foo(), which Rolldown interprets correctly.ascast ((/*#__PURE__*/foo() as Type)) are left untouched — TypeScript already strips both the parens and the cast in the emit, producing a clean annotation.!!(/*#__PURE__*/foo())callers inhasDocument/hasWindow/hasNavigator/hasHistory, removing the parens places the comment adjacent to!!, which TypeScript then drops. The inner annotations were redundant — the parent functions are already marked/*#__NO_SIDE_EFFECTS__*/, so callers can drop the calls when the result is unused.Verification
dist/es5/mod/ts-utils.js,dist/es6/mod/ts-utils.js,dist/es5/main/ts-utils.js,dist/es6/main/ts-utils.js): zero( /*#__PURE__*/occurrences (was 159 in eachmodbundle in v0.14.0). 153 valid#__PURE__annotations are still emitted, all in positions Rolldown accepts.isNode,isWebWorker,getDocument,getWindow,getNavigator,getHistorynow emit as/*#__PURE__*/ _getGlobalInstFn(...)instead of( /*#__PURE__*/_getGlobalInstFn(...)).