feat(pluginutils): named exports for reserved-word keys + fix duplicate default export in dataToEsm#2002
Conversation
|
@CharlieHelps please do a thorough review of this PR to determine if it's ready to merge. Look at the diff, reviews, comments, and referenced issues/docs/links to build a complete understanding. Then respond with a comment that includes a list of MUST fix items that must be fixed before the the PR is merged, and a list of IMPROVEMENTS that shouldn't block the merge but may be quick improvements or things that could be addressed in a follow up PR. The MUST fix items should explain exactly what's wrong and what needs to change to resolve the problem. Both should be numbered lists and the IMPROVEMENTS list should continue counting up from the MUST list. It's OK if there are no IMPROVEMENTS or MUST fix items, you can just omit the lists. |
|
I did a full review of this PR: diff, tests, existing comments/reviews, and linked context ( I don’t see any merge-blocking issues, and I also don’t have any non-blocking follow-up improvements to suggest right now. This looks ready to merge. |

…in dataToEsm
Rollup Plugin Name:
@rollup/pluginutilsThis PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
resolves #2001
Description
Two related changes to
dataToEsm:1. Feature — emit ES2015-safe named exports for reserved-word / identifier-name keys
A key that is a valid
IdentifierNamebut not a legal binding identifier (areserved word, global, or literal —
switch,await,null,true, …) is nowre-exported with the unquoted
export { _x as switch }form, which is validsince ES2015. Previously such keys were emitted as named exports only under
includeArbitraryNames, and then via the quoted ES2022 form(
export { _x as "switch" }).This is what Vite needs for CSS-modules named exports: a class such as
.switchor
.defaultshould produce a named export even when targeting browsers thatpredate arbitrary module namespace names (vitejs/vite#22393).
The unquoted form covers that without
includeArbitraryNames; the quoted formstays opt-in and is now used only for keys that are not valid
IdentifierNames(e.g.
foo-bar).2. Bugfix — avoid a duplicate default export for a
defaultkeydataToEsmalways appends a trailingexport default {...}. A key nameddefaultwas also emitted asexport { _x as "default" }(underincludeArbitraryNames), producing two default exports and aSyntaxError: Duplicate export of 'default'. Adefaultkey is now exposed onlythrough the default export object.
Steps to execute / reproduce