Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokens loaded by composes are not exported #251

Merged
merged 3 commits into from
May 22, 2024
Merged

Tokens loaded by composes are not exported #251

merged 3 commits into from
May 22, 2024

Conversation

mizdra
Copy link
Owner

@mizdra mizdra commented May 22, 2024

Assume you have the following CSS Modules file

/* a.module.css */
.foo {
  composes: bar from "./b.module.css";
}
/* b.module.css */
.bar {
  color: blue;
}

happy-css-modules interprets that the classes a and b (internally called "token") are exported from a.module.css. Then happy-css-modules generates .d.ts like this

// a.module.css.d.ts
declare const styles:
  & Readonly<{ "foo": string }>
  & Readonly<Pick<(typeof import("./b.module.css"))["default"], "bar">>
;
export default styles;

But this is wrong: the css-loader treats only a tokens from a.module.css as if they were exported.

So we decided to change the behavior of happy-css-modules, so that it generates .d.ts like this

// a.module.css.d.ts
declare const styles:
  & Readonly<{ "foo": string }>
;
export default styles;

@mizdra mizdra added the Type: Fix Fix bug. label May 22, 2024
@mizdra mizdra force-pushed the fix-composes-token branch from 202343c to 9e0b61a Compare May 22, 2024 15:36
@mizdra mizdra force-pushed the fix-composes-token branch from 9e0b61a to d644098 Compare May 22, 2024 15:38
@mizdra mizdra force-pushed the fix-composes-token branch from 1d9b7c6 to c919d01 Compare May 22, 2024 15:59
@mizdra mizdra merged commit 6e41547 into main May 22, 2024
6 checks passed
@mizdra mizdra deleted the fix-composes-token branch May 22, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Fix Fix bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant