Skip to content

Commit fe3ad5a

Browse files
Preserve case of css variables when parsing (#61)
Before when parsing --testVariable0 it would end up as --test-variable-0. We still want to convert properties to kebab-case in the typical case so we only bail for css custom properties.
1 parent 35baec6 commit fe3ad5a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

parser.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ function dashify (str) {
3737
function decl (parent, name, value) {
3838
if (value === false || value === null) return
3939

40-
name = dashify(name)
40+
if (!name.startsWith('--')) {
41+
name = dashify(name)
42+
}
43+
4144
if (typeof value === 'number') {
4245
if (value === 0 || UNITLESS[name]) {
4346
value = value.toString()

test/parser.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,14 @@ it('supports PostCSS syntax API', () => {
105105
let result = postcss().process({ color: 'black' }, { parser: postcssJS })
106106
expect(result.css).toEqual('color: black')
107107
})
108+
109+
it('preseves casing for css variables', () => {
110+
let root = postcssJS.parse({
111+
'--testVariable0': '0',
112+
'--test-Variable-1': '1',
113+
'--test-variable-2': '2'
114+
})
115+
expect(root.toString()).toEqual(
116+
'--testVariable0: 0;\n--test-Variable-1: 1;\n--test-variable-2: 2'
117+
)
118+
})

0 commit comments

Comments
 (0)