Skip to content

Commit

Permalink
recover from unexpected brace at top-level (#1876)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfaulkner authored Dec 21, 2021
1 parent b52096b commit 6082ad8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/css_parser/css_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,15 @@ loop:
}

switch p.current().Kind {
case css_lexer.TEndOfFile, css_lexer.TCloseBrace:
case css_lexer.TEndOfFile:
break loop

case css_lexer.TCloseBrace:
if context.isTopLevel {
p.unexpected()
p.advance()
continue
}
break loop

case css_lexer.TWhitespace:
Expand Down
17 changes: 17 additions & 0 deletions internal/css_parser/css_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1612,3 +1612,20 @@ func TestFont(t *testing.T) {
expectPrintedMangleMinify(t, "a { font: italic small-caps bold ultra-condensed 1rem/1.2 'aaa bbb' }", "a{font:italic small-caps 700 ultra-condensed 1rem/1.2 aaa bbb}")
expectPrintedMangleMinify(t, "a { font: italic small-caps bold ultra-condensed 1rem / 1.2 'aaa bbb' }", "a{font:italic small-caps 700 ultra-condensed 1rem/1.2 aaa bbb}")
}

func TestWarningUnexpectedCloseBrace(t *testing.T) {
expectParseError(t, ".red {\n color: red;\n}\n}\n.blue {\n color: blue;\n}\n.green {\n color: green;\n}\n",
`<stdin>: WARNING: Unexpected "}"
`)
expectPrinted(t, ".red {\n color: red;\n}\n}\n.blue {\n color: blue;\n}\n.green {\n color: green;\n}\n",
`.red {
color: red;
}
.blue {
color: blue;
}
.green {
color: green;
}
`)
}

0 comments on commit 6082ad8

Please sign in to comment.