ladybird/Userland/Libraries/LibJS/Tests/syntax/slash-after-block.js
Simon Wanner a2efecac03 LibJS: Parse slashes after reserved identifiers correctly
Previously we were unable to parse code like `yield/2` because `/2`
was parsed as a regex. At the same time `for (a in / b/)` was parsed
as a division.

This is solved by defaulting to division in the lexer, but calling
`force_slash_as_regex()` from the parser whenever an IdentifierName
is parsed as a ReservedWord.
2023-06-10 07:20:33 +02:00

48 lines
1.6 KiB
JavaScript

test("slash token resolution in lexer", () => {
expect(`{ blah.blah; }\n/foo/`).toEval();
expect("``/foo/").not.toEval();
expect("1/foo/").not.toEval();
expect("1/foo").toEval();
expect("{} /foo/").toEval();
expect("{} /=/").toEval();
expect("{} /=a/").toEval();
expect("{} /* */ /=a/").toEval();
expect("{} /* /a/ */ /=a/").toEval();
expect("(function () {} / 1)").toEval();
expect("(function () {} / 1)").toEval();
expect("+a++ / 1").toEval();
expect("+a-- / 1").toEval();
expect("a.in / b").toEval();
expect("a.instanceof / b").toEval();
expect("class A { #name; d = a.#name / b; }").toEval();
expect("async / b").toEval();
expect("a.delete / b").toEval();
expect("delete / b/").toEval();
expect("a.in / b").toEval();
expect("for (a in / b/) {}").toEval();
expect("a.instanceof / b").toEval();
expect("a instanceof / b/").toEval();
expect("new / b/").toEval();
expect("null / b").toEval();
expect("for (a of / b/) {}").toEval();
expect("a.return / b").toEval();
expect("function foo() { return / b/ }").toEval();
expect("throw / b/").toEval();
expect("a.typeof / b").toEval();
expect("a.void / b").toEval();
expect("void / b/").toEval();
expect("await / b").toEval();
expect("await / b/").not.toEval();
expect("async function foo() { await / b }").not.toEval();
expect("async function foo() { await / b/ }").toEval();
expect("yield / b").toEval();
expect("yield / b/").not.toEval();
expect("function* foo() { yield / b }").not.toEval();
expect("function* foo() { yield / b/ }").toEval();
});