From 0e9290acff5367a6c4713b7dc3ffd52e3e9fdbff Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Thu, 2 Nov 2023 12:32:02 -0300 Subject: [PATCH] JS: fix parsing invalid private identifier --- js/ast_test.go | 1 - js/lex.go | 1 - js/parse.go | 5 ++++- js/parse_test.go | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/js/ast_test.go b/js/ast_test.go index 8d60306..eeab979 100644 --- a/js/ast_test.go +++ b/js/ast_test.go @@ -118,7 +118,6 @@ func TestJS(t *testing.T) { {"{};;", "{} ;"}, {"{}\n;", "{} ;"}, {"- - --3", "- - --3;"}, - //{"A:#0XbBB", ""}, } re := regexp.MustCompile("\n *") diff --git a/js/lex.go b/js/lex.go index fa3bf72..ac00e85 100644 --- a/js/lex.go +++ b/js/lex.go @@ -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 { diff --git a/js/parse.go b/js/parse.go index 44c0da9..dda1cf6 100644 --- a/js/parse.go +++ b/js/parse.go @@ -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() diff --git a/js/parse_test.go b/js/parse_test.go index ba31d47..940a2fa 100644 --- a/js/parse_test.go +++ b/js/parse_test.go @@ -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"},