fix: remove misplaced /*#__PURE__*/ annotations#3072
Open
CemYil03 wants to merge 1 commit into
Open
Conversation
Rolldown only honors /*#__PURE__*/ immediately before a function call or `new` expression; annotations on object literals and regex literals trigger [INVALID_ANNOTATION] warnings (esbuild/Terser silently ignored them). Drop the misplaced annotations across scalar Configs and the PostalCode/ObjectID regex tables. The valid annotations on `new GraphQLScalarType(...)`, `Object.assign(...)`, and `new RegExp(...)` are kept, so dead-code elimination is unchanged.
Author
|
@ardatan could you take a look please? |
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.
Description
Bundling
graphql-scalarswith Vite 6 / Rolldown produces hundreds of[INVALID_ANNOTATION]warnings such as:Root cause. Per the
Rolldown DCE docs,
the
/*#__PURE__*/annotation is only honored when it sits immediately before afunction call or
newexpression. The repository placed annotations infront of object literals (
= /*#__PURE__*/ { ... }) and regex literals(
/*#__PURE__*/ /…/) in many scalars. esbuild/Terser silently ignored thosepositions; Rolldown logs each one.
Fix. Drop only the misplaced annotations:
Config = /*#__PURE__*/ { … }becomesConfig = { … }(
BigInt,Byte,Cuid,Currency,EmailAddress,HSL,HexColorCode,Hexadecimal,LocalDateTime,NonNegativeFloat,NonNegativeInt,UUID,iso-date/Date,iso-date/DateTime,iso-date/DateTimeISO,iso-date/Duration,json/JSON,json/JSONObject).src/scalars/PostalCode.ts(20 regex entries) andsrc/scalars/ObjectID.ts(1 regex).
Every annotation that actually does something is preserved — the
/*#__PURE__*/ new GraphQLScalarType(...)instantiations and the/*#__PURE__*/ Object.assign(...)//*#__PURE__*/ new RegExp(...)calls — sodead-code elimination behavior is unchanged. The DCE benefit was always being
delivered by the annotation in front of the
new GraphQLScalarType(Config)call, not by the no-op annotation in front of the
Configobject literal.No runtime change. No public API change. Patch-level changeset added.
Type of change
expected)
Screenshots/Sandbox (if appropriate/relevant):
Reproduction (before vs. after) using Rolldown directly against the built ESM
output:
Byte.js,Cuid.js,UUID.js,PostalCode.js, etc.).INVALID_ANNOTATION warnings: 0.How Has This Been Tested?
yarn build— succeeds; bob single-build emits the package as before.yarn jest --forceExit --no-watchman— 2797/2797 tests pass, 98 snapshots green.grep -RnE '/\*#__PURE__\*/\s*[{/]' src/— returns nothing (no/*#__PURE__*/left in front of{or/).grep -Rn '__PURE__' src/— only matches in front ofnew,Object.assign, ornew RegExp.the rebuilt
dist/esmand confirmed Rolldown reports 0INVALID_ANNOTATIONwarnings (down from hundreds).Test Environment:
Checklist:
CONTRIBUTING doc and the
style guidelines of this project
removing comments that the consumer's bundler rejects
annotations
Rolldown reproduction above; the existing 2797-test suite remains green and is the
behavioral guardrail
Further comments
The annotations were not load-bearing where they were removed: in TypeScript,
the only side-effect-free expressions in these files are the
new GraphQLScalarType(...)/Object.assign(...)/new RegExp(...)calls, andthose still carry their
/*#__PURE__*/comments. The annotations attached toobject literals and regex literals never produced any DCE benefit — they were
dead comments under esbuild/Terser too; Rolldown is simply louder about it.
Alternatives considered:
onwarnhook). Rejected— every downstream consumer would have to add the same workaround.
= /*#__PURE__*/ (() => ({ … }))()). Rejected — adds runtime cost andbytes for zero DCE gain over the existing annotation on the
new GraphQLScalarType(...)call.patch release that quiets every consumer's bundler.