-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Discard invalid declarations when parsing CSS #16093
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
Changes from 1 commit
350d667
650bfe5
6f58ccc
857c7e3
368fb26
7d8c054
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -329,6 +329,28 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { | |
| ]) | ||
| }) | ||
|
|
||
| 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, | ||
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| it('should parse a custom property with a block including nested "css"', () => { | ||
| expect( | ||
| parse(css` | ||
|
|
@@ -1041,34 +1063,6 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { | |
| }, | ||
| ]) | ||
| }) | ||
|
|
||
| // TODO: These should probably be errors in some cases? | ||
| it('discards invalid declarations', () => { | ||
| // This shouldn't parse as a custom property declaration | ||
| expect(parse(`--foo`)).toEqual([]) | ||
|
|
||
| // This shouldn't parse as a rule followed by a declaration | ||
| expect(parse(`@plugin "foo" {};`)).toEqual([ | ||
| { | ||
| kind: 'at-rule', | ||
| name: '@plugin', | ||
| params: '"foo"', | ||
| nodes: [], | ||
| }, | ||
| ]) | ||
|
|
||
| // This shouldn't parse as consecutive declarations | ||
| expect(parse(`;;;`)).toEqual([]) | ||
|
|
||
| // This shouldn't parse as a rule with a declaration inside of it | ||
| expect(parse(`.foo { bar }`)).toEqual([ | ||
| { | ||
| kind: 'rule', | ||
| selector: '.foo', | ||
| nodes: [], | ||
| }, | ||
| ]) | ||
| }) | ||
| }) | ||
|
|
||
| describe('errors', () => { | ||
|
|
@@ -1125,5 +1119,39 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { | |
| `), | ||
| ).toThrowErrorMatchingInlineSnapshot(`[Error: Unterminated string: "Hello world!;"]`) | ||
| }) | ||
|
|
||
| it('should error when incomplete custom properties are used', () => { | ||
| expect(() => parse('--foo')).toThrowErrorMatchingInlineSnapshot( | ||
| `[Error: Invalid custom property, expected a value]`, | ||
| ) | ||
| }) | ||
|
|
||
| it('should error when incomplete custom properties are used inside rules', () => { | ||
| expect(() => parse('.foo { --bar }')).toThrowErrorMatchingInlineSnapshot( | ||
| `[Error: Invalid custom property, expected a value]`, | ||
| ) | ||
| }) | ||
|
|
||
| it('should error when a declaration is incomplete', () => { | ||
| expect(() => parse('.foo { bar }')).toThrowErrorMatchingInlineSnapshot( | ||
| `[Error: Invalid declaration: \`bar\`]`, | ||
| ) | ||
| }) | ||
|
|
||
| it('should error when a semicolon exists after an at-rule with a body', () => { | ||
| expect(() => parse('@plugin "foo" {} ;')).toThrowErrorMatchingInlineSnapshot( | ||
| `[Error: Unexpected semicolon]`, | ||
| ) | ||
| }) | ||
|
|
||
| it('should error when consecutive semicolons exist', () => { | ||
| expect(() => parse(';;;')).toThrowErrorMatchingInlineSnapshot(`[Error: Unexpected: \`;;;\`]`) | ||
|
||
| }) | ||
|
|
||
| it('should error when consecutive semicolons exist after a declaration', () => { | ||
| expect(() => parse('.foo { color: red;;; }')).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.
Added these just in case we broke something with unexpected semicolon detection