8000 Fix: Account for !important tag when checking for content quotes · emotion-js/emotion@e417f1a · GitHub
[go: up one dir, main page]

Skip to content

Commit e417f1a

Browse files
committed
Fix: Account for !important tag when checking for content quotes
1 parent cce67ec commit e417f1a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/serialize/src/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,28 @@ if (isDevelopment) {
136136

137137
processStyleValue = (key: string, value: string | number) => {
138138
if (key === 'content') {
139+
let isProperlyQuoted = false
140+
if (typeof value === 'string') {
141+
const first = value.charAt(0)
142+
if ((first === '"' || first === "'") && value.length > 1) {
143+
const closingIndex = value.lastIndexOf(first)
144+
if (closingIndex > 0) {
145+
const remainder = value.slice(closingIndex + 1).trim()
146+
if (
147+
closingIndex === value.length - 1 ||
148+
remainder === '' ||
149+
remainder === '!important'
150+
) {
151+
isProperlyQuoted = true
152+
}
15 8151 3+
}
154+
}
155+
}
139156
if (
140157
typeof value !== 'string' ||
141158
(contentValues.indexOf(value) === -1 &&
142159
!contentValuePattern.test(value) &&
143-
(value.charAt(0) !== value.charAt(value.length - 1) ||
144-
(value.charAt(0) !== '"' && value.charAt(0) !== "'")))
160+
!isProperlyQuoted)
145161
) {
146162
throw new Error(
147163
`You seem to be using a value for 'content' without quotes, try replacing it with \`content: '"${value}"'\``

0 commit comments

Comments
 (0)
0