Skip to content

Commit 11ddc98

Browse files
Fix style properties that are not identifiers
Closes GH-8. Reviewed-by: Christian Murphy <[email protected]> Reviewed-by: Remco Haszing <[email protected]>
1 parent df12a44 commit 11ddc98

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/handlers/element.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {svg, find, hastToReact} from 'property-information'
1616
import {stringify as spaces} from 'space-separated-tokens'
1717
import {
1818
start as identifierStart,
19-
cont as identifierCont
19+
cont as identifierCont,
20+
name as identifierName
2021
} from 'estree-util-is-identifier-name'
2122
import styleToObject from 'style-to-object'
2223

@@ -105,7 +106,9 @@ export function element(node, state) {
105106
method: false,
106107
shorthand: false,
107108
computed: false,
108-
key: {type: 'Identifier', name: cssProp},
109+
key: identifierName(cssProp)
110+
? {type: 'Identifier', name: cssProp}
111+
: {type: 'Literal', value: cssProp},
109112
value: {type: 'Literal', value: String(styleObject[cssProp])},
110113
kind: 'init'
111114
})

test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ test('toEstree', () => {
627627
}),
628628
{handlers: jsx}
629629
).value,
630-
'<h1 style={{\n background-color: "red"\n}}>{"x"}</h1>;\n',
630+
'<h1 style={{\n "background-color": "red"\n}}>{"x"}</h1>;\n',
631631
"should support `stylePropertyNameCase: 'css'`"
632632
)
633633

@@ -641,7 +641,7 @@ test('toEstree', () => {
641641
),
642642
{handlers: jsx}
643643
).value,
644-
'<h1 style={{\n WebkitTransform: "rotate(0.01turn)",\n msTransform: "rotate(0.01turn)",\n --fg: "#0366d6",\n color: "var(--fg)"\n}} />;\n',
644+
'<h1 style={{\n WebkitTransform: "rotate(0.01turn)",\n msTransform: "rotate(0.01turn)",\n "--fg": "#0366d6",\n color: "var(--fg)"\n}} />;\n',
645645
'should support vendor prefixes and css variables (dom)'
646646
)
647647

@@ -656,7 +656,7 @@ test('toEstree', () => {
656656
),
657657
{handlers: jsx}
658658
).value,
659-
'<h1 style={{\n -webkit-transform: "rotate(0.01turn)",\n -ms-transform: "rotate(0.01turn)",\n --fg: "#0366d6",\n color: "var(--fg)"\n}} />;\n',
659+
'<h1 style={{\n "-webkit-transform": "rotate(0.01turn)",\n "-ms-transform": "rotate(0.01turn)",\n "--fg": "#0366d6",\n color: "var(--fg)"\n}} />;\n',
660660
'should support vendor prefixes and css variables (css)'
661661
)
662662
})

0 commit comments

Comments
 (0)