diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 764ee67e85..893db52aad 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -1827,6 +1827,8 @@ Token Parser::consume_and_validate_numeric_literal() auto token = consume(TokenType::NumericLiteral); if (m_parser_state.m_strict_mode && is_unprefixed_octal_number(token.value())) syntax_error("Unprefixed octal number not allowed in strict mode", literal_start_line, literal_start_column); + if (match_identifier_name() && m_parser_state.m_current_token.trivia().is_empty()) + syntax_error("Numeric literal must not be immediately followed by identifier"); return token; } diff --git a/Libraries/LibJS/Tests/numeric-literals-basic.js b/Libraries/LibJS/Tests/numeric-literals-basic.js index 93a1815a49..f226581320 100644 --- a/Libraries/LibJS/Tests/numeric-literals-basic.js +++ b/Libraries/LibJS/Tests/numeric-literals-basic.js @@ -46,4 +46,6 @@ test("invalid numeric literals", () => { expect("0b").not.toEval(); expect("0o").not.toEval(); expect("'use strict'; 0755").not.toEval(); + expect("1in[]").not.toEval(); + expect("2instanceof foo").not.toEval(); });