Skip to content

Commit

Permalink
Bugfix: CSS error position information
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Apr 19, 2019
1 parent c02ca09 commit b8d8be7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions css/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (p *Parser) parseDeclarationList() GrammarType {
p.initBuf()
p.l.r.Move(-len(p.data))
p.err = parse.NewErrorLexer("unexpected token in declaration", p.l.r)
p.l.r.Move(len(p.data))
return p.parseDeclarationError(p.tt, p.data, true)
}

Expand Down Expand Up @@ -320,8 +321,7 @@ func (p *Parser) parseQualifiedRule() GrammarType {
p.state = append(p.state, (*Parser).parseQualifiedRuleDeclarationList)
return BeginRulesetGrammar
} else if tt == ErrorToken {
p.l.r.Move(-1)
p.err = parse.NewErrorLexer("expected left brace in qualified rule", p.l.r)
p.err = parse.NewErrorLexer("unexpected ending in qualified rule", p.l.r)
return ErrorGrammar
} else if tt == LeftParenthesisToken || tt == LeftBraceToken || tt == LeftBracketToken || tt == FunctionToken {
p.level++
Expand Down Expand Up @@ -366,6 +366,7 @@ func (p *Parser) parseDeclaration() GrammarType {
if tt != ColonToken {
p.l.r.Move(-len(data))
p.err = parse.NewErrorLexer("expected colon in declaration", p.l.r)
p.l.r.Move(len(data))
return p.parseDeclarationError(tt, data, false)
}

Expand Down Expand Up @@ -426,6 +427,7 @@ func (p *Parser) parseCustomProperty() GrammarType {
if tt, data := p.popToken(false); tt != ColonToken {
p.l.r.Move(-len(data))
p.err = parse.NewErrorLexer("expected colon in custom property", p.l.r)
p.l.r.Move(len(data))
return ErrorGrammar
}
val := []byte{}
Expand Down
4 changes: 2 additions & 2 deletions css/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ func TestParseError(t *testing.T) {
col int
}{
{false, "selector", 9},
{true, "color 0", 8},
{true, "--color 0", 10},
{true, "color 0", 7},
{true, "--color 0", 9},
{true, "--custom-variable:0", 0},
}
for _, tt := range parseErrorTests {
Expand Down

0 comments on commit b8d8be7

Please sign in to comment.