Skip to content

Commit

Permalink
remove error recovery for CSS meta-syntax and ";"
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jan 25, 2022
1 parent cccc6c6 commit 1dd0b94
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
18 changes: 0 additions & 18 deletions internal/css_parser/css_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,15 +1295,6 @@ loop:
case css_lexer.TOpenBrace, css_lexer.TEndOfFile:
break loop

case css_lexer.TSemicolon:
// Error recovery if the block is omitted (likely some CSS meta-syntax)
if !isAlreadyInvalid {
p.expect(css_lexer.TOpenBrace)
}
prelude := p.convertTokens(p.tokens[preludeStart:p.index])
p.advance()
return css_ast.Rule{Loc: preludeLoc, Data: &css_ast.RQualified{Prelude: prelude}}

default:
p.parseComponentValue()
}
Expand Down Expand Up @@ -1343,15 +1334,6 @@ stop:
case css_lexer.TEndOfFile, css_lexer.TSemicolon, css_lexer.TCloseBrace:
break stop

case css_lexer.TOpenBrace:
// Error recovery if there is an unexpected block (likely some CSS meta-syntax)
p.parseComponentValue()
p.eat(css_lexer.TWhitespace)
if ok && !p.peek(css_lexer.TSemicolon) {
p.expect(css_lexer.TSemicolon)
}
break stop

default:
p.parseComponentValue()
}
Expand Down
3 changes: 2 additions & 1 deletion internal/css_parser/css_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,10 @@ func TestBadQualifiedRules(t *testing.T) {
expectParseError(t, "$bad: rule;", "<stdin>: WARNING: Unexpected \"$\"\n")
expectParseError(t, "$bad { color: red }", "<stdin>: WARNING: Unexpected \"$\"\n")
expectParseError(t, "a { div.major { color: blue } color: red }", "<stdin>: WARNING: Expected \":\" but found \".\"\n")
expectParseError(t, "a { div:hover { color: blue } color: red }", "<stdin>: WARNING: Expected \";\"\n")
expectParseError(t, "a { div:hover { color: blue } color: red }", "")
expectParseError(t, "a { div:hover { color: blue }; color: red }", "")
expectParseError(t, "a { div:hover { color: blue } ; color: red }", "")
expectParseError(t, "! { x: {} }", "<stdin>: WARNING: Unexpected \"!\"\n")
}

func TestAtRule(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions internal/css_printer/css_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ func TestNestedSelector(t *testing.T) {
}

func TestBadQualifiedRules(t *testing.T) {
expectPrinted(t, "$bad: rule;", "$bad: rule {\n}\n")
expectPrinted(t, "a { div.major { color: blue } color: red }", "a {\n div.major { color: blue };\n color: red;\n}\n")
expectPrinted(t, "a { div:hover { color: blue } color: red }", "a {\n div: hover { color: blue };\n color: red;\n}\n")
expectPrinted(t, ";", "; {\n}\n")
expectPrinted(t, "$bad: rule;", "$bad: rule; {\n}\n")
expectPrinted(t, "a {}; b {};", "a {\n}\n; b {\n}\n; {\n}\n")
expectPrinted(t, "a { div.major { color: blue } color: red }", "a {\n div.major { color: blue } color: red;\n}\n")
expectPrinted(t, "a { div:hover { color: blue } color: red }", "a {\n div: hover { color: blue } color: red;\n}\n")
expectPrinted(t, "a { div:hover { color: blue }; color: red }", "a {\n div: hover { color: blue };\n color: red;\n}\n")

expectPrinted(t, "$bad{ color: red }", "$bad {\n color: red;\n}\n")
Expand Down

0 comments on commit 1dd0b94

Please sign in to comment.