Skip to content

Commit 3330510

Browse files
committed
turn some unexpected values into errors
1 parent b1c3e68 commit 3330510

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/tailwindcss/src/css-parser.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ export function parse(input: string) {
292292
} else {
293293
ast.push(declaration)
294294
}
295+
} else {
296+
throw new Error(`Invalid custom property, expected a value`)
295297
}
296298

297299
buffer = ''
@@ -345,6 +347,20 @@ export function parse(input: string) {
345347
} else {
346348
ast.push(declaration)
347349
}
350+
} else if (input.charCodeAt(i - 1) === SEMICOLON || input.charCodeAt(i + 1) === SEMICOLON) {
351+
let startSemiColonIdx = i
352+
while (input.charCodeAt(startSemiColonIdx - 1) === SEMICOLON) {
353+
startSemiColonIdx--
354+
}
355+
let endSemiColonIdx = i
356+
while (input.charCodeAt(endSemiColonIdx) === SEMICOLON) {
357+
endSemiColonIdx++
358+
}
359+
throw new Error(`Unexpected: \`${input.slice(startSemiColonIdx, endSemiColonIdx)}\``)
360+
} else if (buffer.length == 0) {
361+
throw new Error('Unexpected semicolon')
362+
} else {
363+
throw new Error(`Invalid declaration: \`${buffer.trim()}\``)
348364
}
349365

350366
buffer = ''
@@ -442,6 +458,8 @@ export function parse(input: string) {
442458
let node = parseDeclaration(buffer, colonIdx)
443459
if (node) {
444460
parent.nodes.push(node)
461+
} else {
462+
throw new Error(`Invalid declaration: \`${buffer.trim()}\``)
445463
}
446464
}
447465
}

0 commit comments

Comments
 (0)