From a3f34263fdf3ca3e5d08c5b382d207dcee51ab75 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sat, 4 Nov 2023 20:40:12 +0100 Subject: [PATCH] LibJS: Allow division after `this` token This fixes the root cause of #21747, so it makes the clock work on https://toaruos.org --- Userland/Libraries/LibJS/Parser.cpp | 2 +- Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 21b8987992..1f2b26ebda 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1643,7 +1643,7 @@ Parser::PrimaryExpressionParseResult Parser::parse_primary_expression() return { move(expression) }; } case TokenType::This: - consume(); + consume_and_allow_division(); return { create_ast_node({ m_source_code, rule_start.position(), position() }) }; case TokenType::Class: return { parse_class_expression(false) }; diff --git a/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js b/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js index b140469f41..4f30340c5a 100644 --- a/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js +++ b/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js @@ -45,4 +45,8 @@ test("slash token resolution in lexer", () => { expect("yield / b/").not.toEval(); expect("function* foo() { yield / b }").not.toEval(); expect("function* foo() { yield / b/ }").toEval(); + + expect("this / 1").toEval(); + expect("this / 1 /").not.toEval(); + expect("this / 1 / 1").toEval(); });