Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/custom-property-at-end-of-input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Parse a custom property at the end of the input when it has no trailing `;` (e.g. `--foo: bar` as the last declaration)
25 changes: 25 additions & 0 deletions packages/tailwindcss/src/css-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,31 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
).toEqual([{ kind: 'declaration', property: '--foo', value: 'bar', important: true }])
})

it('should parse a custom property with a missing ending `;` at the end of the input', () => {
expect(parse('--foo: bar')).toEqual([
{ kind: 'declaration', property: '--foo', value: 'bar', important: false },
])
expect(parse('--foo: bar !important')).toEqual([
{ kind: 'declaration', property: '--foo', value: 'bar', important: true },
])
expect(parse('--foo: var(--bar)')).toEqual([
{ kind: 'declaration', property: '--foo', value: 'var(--bar)', important: false },
])
expect(parse("--foo: 'bar'")).toEqual([
{ kind: 'declaration', property: '--foo', value: "'bar'", important: false },
])
expect(parse('--foo: {}')).toEqual([
{ kind: 'declaration', property: '--foo', value: '{}', important: false },
])
expect(parse('--foo: bar /* baz */')).toEqual([
{ kind: 'declaration', property: '--foo', value: 'bar /* baz */', important: false },
])
expect(parse('--foo: bar;\n--baz: rgb(0 0 0)')).toEqual([
{ kind: 'declaration', property: '--foo', value: 'bar', important: false },
{ kind: 'declaration', property: '--baz', value: 'rgb(0 0 0)', important: false },
])
})

it('should parse a custom property with an embedded programming language', () => {
expect(
parse(css`
Expand Down
20 changes: 16 additions & 4 deletions packages/tailwindcss/src/css-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,7 @@ export function parse(input: string, opts?: ParseOptions) {
// ^
// }
// ```
else if (
(peekChar === CLOSE_CURLY || input.length - 1 === j) &&
closingBracketStack.length === 0
) {
else if (peekChar === CLOSE_CURLY && closingBracketStack.length === 0) {
i = j - 1
buffer += input.slice(start, j)
break
Expand Down Expand Up @@ -310,6 +307,21 @@ export function parse(input: string, opts?: ParseOptions) {
}
}

// We reached the end of the input without finding a `;` or `}` that ends
// the custom property, which means that the rest of the input is part of
// the custom property.
//
// E.g.:
//
// ```css
// --custom: value
// ^
// ```
if (buffer.length === 0) {
buffer = input.slice(start)
i = input.length
}

let declaration = parseDeclaration(buffer, colonIdx, valueEnd)
if (!declaration) {
throw new CssSyntaxError(
Expand Down
Loading