Skip to content

Commit

Permalink
JS: fix parsing invalid private identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Nov 2, 2023
1 parent 004a0d6 commit 0e9290a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
1 change: 0 additions & 1 deletion js/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func TestJS(t *testing.T) {
{"{};;", "{} ;"},
{"{}\n;", "{} ;"},
{"- - --3", "- - --3;"},
//{"A:#0XbBB", ""},
}

re := regexp.MustCompile("\n *")
Expand Down
1 change: 0 additions & 1 deletion js/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func (l *Lexer) Next() (TokenType, []byte) {
if l.consumeIdentifierToken() {
return PrivateIdentifierToken, l.r.Shift()
}
return ErrorToken, nil
default:
if l.consumeIdentifierToken() {
if prevNumericLiteral {
Expand Down
5 changes: 4 additions & 1 deletion js/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,16 @@ func (p *Parser) parseStmt(allowDeclaration bool) (stmt IStmt) {
case DebuggerToken:
stmt = &DebuggerStmt{}
p.next()
case SemicolonToken, ErrorToken:
case SemicolonToken:
stmt = &EmptyStmt{}
p.next()
case CommentToken, CommentLineTerminatorToken:
// bang comment
stmt = &Comment{p.data}
p.next()
case ErrorToken:
stmt = &EmptyStmt{}
return
default:
if p.retrn && p.tt == ReturnToken {
p.next()
Expand Down
1 change: 1 addition & 0 deletions js/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ func TestParseError(t *testing.T) {
{"export async", "expected function instead of EOF in export statement"},
{"throw", "unexpected EOF in expression"},
{"throw\n", "unexpected newline in throw statement"},
{"#private", "expected in instead of EOF in relational expression"},

// no declarations
{"if(a) function f(){}", "unexpected function in statement"},
Expand Down

0 comments on commit 0e9290a

Please sign in to comment.