feat(css): emit named exports for JS keyword class names in CSS modules#22393
feat(css): emit named exports for JS keyword class names in CSS modules#22393semimikoh wants to merge 3 commits into
Conversation
3a8f159 to
f216993
Compare
sapphi-red
left a comment
There was a problem hiding this comment.
I think this will break existing apps when the app targets browsers that does not support the arbitrary names feature.
I guess we need to conditionally enable this when the target supports them. or maybe we can transpile it somehow.
f216993 to
cd583a2
Compare
|
Thanks for the review, good catch! @sapphi-red I've updated this to conditionally enable arbitrary named exports based on
The support boundaries match esbuild's compat table for Added tests for both supported ( |
Would you send this change to |
|
@sapphi-red
While there I also fixed a latent bug: a As you suggested, I've patched |
CSS modules containing class names that match JavaScript reserved keywords
(e.g.
switch,if,for,class) were not emitted as named exports,making them accessible only via the default export object.
Summary
dataToEsmskips named export generation when a key fails thekey === makeLegalIdentifier(key)check — reserved words likeswitchget prefixed to
_switch, so they never matchincludeArbitraryNames: trueoption to thedataToEsmcall incssPostPlugin, which emits string-named exports for such keys:export { _arbitrary0 as "switch" }(
styles.switch) or string literal import (import { "switch" as s })Related
Fixes #14050
Test plan
Added playground test case with a CSS module containing a
.switchclass,verifying it is correctly applied via
import * as keywordModandkeywordMod.switch