Skip to content

Commit e915f7f

Browse files
authored
Ensure whitespace is stripped from debug Ids (#428)
1 parent 3f54e5f commit e915f7f

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

.changeset/thick-tigers-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/css': patch
3+
---
4+
5+
Ensure whitespace is stripped from debug Ids
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { setFileScope, endFileScope } from './fileScope';
2+
import { generateIdentifier } from './identifier';
3+
4+
describe('identifier', () => {
5+
beforeAll(() => {
6+
setFileScope('test');
7+
});
8+
9+
afterAll(() => {
10+
endFileScope();
11+
});
12+
13+
it(`should create a valid identifier`, () => {
14+
expect(generateIdentifier(undefined)).toMatchInlineSnapshot(`"skkcyc0"`);
15+
});
16+
17+
it('should create a valid identifier with a debug id', () => {
18+
expect(generateIdentifier('debug')).toMatchInlineSnapshot(
19+
`"debug__skkcyc1"`,
20+
);
21+
});
22+
23+
it('should create a valid identifier with a debug id with whitespace', () => {
24+
expect(generateIdentifier('debug and more')).toMatchInlineSnapshot(
25+
`"debug_and_more__skkcyc2"`,
26+
);
27+
});
28+
});

packages/css/src/identifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getIdentOption } from './adapter';
44
import { getAndIncrementRefCounter, getFileScope } from './fileScope';
55

66
function getDevPrefix(debugId: string | undefined) {
7-
const parts = debugId ? [debugId] : [];
7+
const parts = debugId ? [debugId.replace(/\s/g, '_')] : [];
88
const { filePath } = getFileScope();
99

1010
const matches = filePath.match(

0 commit comments

Comments
 (0)