-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discard invalid declarations when parsing CSS #16093
Conversation
a92ff26
to
5ba4703
Compare
it('should parse a custom property with an empty value', () => { | ||
expect(parse('--foo:;')).toEqual([ | ||
{ | ||
kind: 'declaration', | ||
property: '--foo', | ||
value: '', | ||
important: false, | ||
}, | ||
]) | ||
}) | ||
|
||
it('should parse a custom property with a space value', () => { | ||
expect(parse('--foo: ;')).toEqual([ | ||
{ | ||
kind: 'declaration', | ||
property: '--foo', | ||
value: '', | ||
important: false, | ||
}, | ||
]) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these just in case we broke something with unexpected semicolon detection
}) | ||
|
||
it('should error when consecutive semicolons exist', () => { | ||
expect(() => parse(';;;')).toThrowErrorMatchingInlineSnapshot(`[Error: Unexpected: \`;;;\`]`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also just throw the same Unexpected semicolon
error, I'm indifferent on this one.
I think once we have proper span/location, we could highlight the full ;;;
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this but I think the error is fine as is
5ba4703
to
0309756
Compare
459f274
to
ddf7dfb
Compare
Let's us some early returns and simplify some error messages.
ddf7dfb
to
7d8c054
Compare
Can't approve the PR since I opened it originally lol but LGTM 👍 |
I discovered this when triaging an error someone had on Tailwind Play.
;
we often assume a valid declaration precedes it but that may not be the caseThis PR fixes all three of these by ignoring these invalid cases. Though some should probably be turned into errors.