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

Allow hyphens inside css classes #1254

Merged
merged 6 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/css/src/identifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ describe('identifier', () => {
);
});

it('should allow hyphens in a class name', () => {
expect(generateIdentifier("a-b")).toMatchInlineSnapshot(`"abc_a-b_s0xkdr1_packagetest_file"`);
expect(generateIdentifier("a-b-c")).toMatchInlineSnapshot(`"abc_a-b-c_s0xkdr2_packagetest_file"`);
});

it('rejects invalid identifiers', () => {
// getIdentOption() does not remove spaces from the debug info so the
// resulting identifier should be invalid here.
Expand Down
2 changes: 1 addition & 1 deletion packages/css/src/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function generateIdentifier(
packageName,
});

if (!identifier.match(/^[A-Z_][0-9A-Z_]+$/i)) {
if (!identifier.match(/^[A-Z_][0-9A-Z_\-]+$/i)) {
mrm007 marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(
`Identifier function returned invalid indentifier: "${identifier}"`,
);
Expand Down