Skip to content

Commit

Permalink
Merge branch 'master' into update-dep-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrm007 authored Jan 27, 2024
2 parents 9c5a08f + f373d7f commit d4c924c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .changeset/strong-ducks-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@vanilla-extract/css': patch
'@vanilla-extract/esbuild-plugin': patch
'@vanilla-extract/next-plugin': patch
'@vanilla-extract/rollup-plugin': patch
'@vanilla-extract/vite-plugin': patch
'@vanilla-extract/webpack-plugin': patch
---

Allow hyphens in class names when using a custom identifier
9 changes: 9 additions & 0 deletions packages/css/src/identifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ 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)) {
throw new Error(
`Identifier function returned invalid indentifier: "${identifier}"`,
);
Expand Down
2 changes: 1 addition & 1 deletion site/docs/integrations/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc)
- A custom identifier function takes an object parameter with properties `hash`, `filePath`, `debugId`, and `packageName`, and returns a customized identifier. e.g.

```ts
VanillaExtractPlugin({
new VanillaExtractPlugin({
identifiers: ({ hash }) => `prefix_${hash}`
});
```
Expand Down

0 comments on commit d4c924c

Please sign in to comment.