Skip to content

Commit 992cf8d

Browse files
authored
Fix parsing body-less at-rule without terminating semicolon (tailwindlabs#13978)
* ensure body-less at-rules without semicolon are parsed correctly * update changelog
1 parent 8e97a48 commit 992cf8d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Discard invalid classes such as `bg-red-[#000]` ([#13970](https://github.com/tailwindlabs/tailwindcss/pull/13970))
13+
- Fix parsing body-less at-rule without terminating semicolon ([#13978](https://github.com/tailwindlabs/tailwindcss/pull/13978))
1314

1415
## [4.0.0-alpha.17] - 2024-07-04
1516

packages/tailwindcss/src/css-parser.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,14 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
633633
).toEqual([{ kind: 'rule', selector: '@charset "UTF-8"', nodes: [] }])
634634
})
635635

636+
it('should parse an at-rule without a block or semicolon', () => {
637+
expect(
638+
parse(`
639+
@tailwind utilities
640+
`),
641+
).toEqual([{ kind: 'rule', selector: '@tailwind utilities', nodes: [] }])
642+
})
643+
636644
it("should parse an at-rule without a block or semicolon when it's the last rule in a block", () => {
637645
expect(
638646
parse(`

packages/tailwindcss/src/css-parser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,13 @@ export function parse(input: string) {
461461
}
462462
}
463463

464+
// If we have a leftover `buffer` that happens to start with an `@` then it
465+
// means that we have an at-rule that is not terminated with a semicolon at
466+
// the end of the input.
467+
if (buffer[0] === '@') {
468+
ast.push(rule(buffer.trim(), []))
469+
}
470+
464471
// When we are done parsing then everything should be balanced. If we still
465472
// have a leftover `parent`, then it means that we have an unterminated block.
466473
if (closingBracketStack.length > 0 && parent) {

0 commit comments

Comments
 (0)