Browse Source

LibJS: Allow division after `this` token

This fixes the root cause of #21747, so it makes the clock work on
https://toaruos.org
Simon Wanner 1 year ago
parent
commit
a3f34263fd

+ 1 - 1
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<ThisExpression>({ m_source_code, rule_start.position(), position() }) };
     case TokenType::Class:
         return { parse_class_expression(false) };

+ 4 - 0
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();
 });