Default classname is ok in default export mode, not named mode
I have a class named default, and I'm using default exports mode. I'm getting a lot of confusing warnings from this plugin, which claims it's problematic, but it works, and I can't see how:
const $mangled = '.default-abc123';
export default {
default: $mangled;
}
is ok, and so shouldn't emit a warning.
Similarly, if they're composed, it shouldn't be an issue at all as we don't export the default named class by name.
Only lightningcss seems to drop the default class in composed modules; both postcss and lightningcss incorrectly export the default class as the default export of the module, as evidenced by the tests in the first PR of this commit. Both, however, do correctly emit the default class in the default export object.
I don't know why lightningcss isn't happy with composed classes called default...in my usage it's been ok and I can't see anything in this plugin that's mangling it. Will take a nosey later
As far as I can see this is a bug in lightningcss.
Raised https://github.com/parcel-bundler/lightningcss/issues/908
It looks like lightningcss is interpreting the value of compses as a css custom ident, and thus forbidding names like default.
I think the conflict only occurs when the export mode is both
As the logic currently stands, using exportMode 'named' omits classes named 'default' - if I change to assert for their presence it fails.
JestAssertionError: expect(received).toMatchObject(expected)
- Expected - 1
+ Received + 0
Object {
"style": Object {
- "default": "_default_1733f38",
"typeof": "_typeof_06003d4",
},
}
at <anonymous> (/home/bill/git/vite-css-modules/tests/specs/patched/postcss.spec.ts:1012:22)
at async file:///home/bill/git/vite-css-modules/node_modules/.pnpm/[email protected]/node_modules/manten/dist/index.mjs:2:1723
at async J (file:///home/bill/git/vite-css-modules/node_modules/.pnpm/[email protected]/node_modules/manten/dist/index.mjs:2:1323)
at async K (file:///home/bill/git/vite-css-modules/node_modules/.pnpm/[email protected]/node_modules/manten/dist/index.mjs:2:1666)
✖ vite 6.3.2 › Patched › PostCSS › default as named export › should omit in named exports (1.7s)
I can't remember whether the logic for this is in this plugin or in postcss/lightningcss, but as things stand only "default" mode supports "default" named classes
Ah, found the offending line and fixed.
:tada: This PR is included in version 1.9.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket: