1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibJS: Replace the verify in private identifier with a syntax error

Since sometimes expressions are parsed without checking we can hit this
expression without it being followed by an 'in'.
This commit is contained in:
davidot 2021-11-27 00:16:01 +01:00 committed by Linus Groh
parent b7c7d54167
commit c2ebaa9d87
2 changed files with 15 additions and 2 deletions

View file

@ -96,6 +96,18 @@ test("slash after private identifier is treated as division", () => {
expect(A.getDivided()).toBe(2);
});
test("private identifier not followed by 'in' throws", () => {
expect(`class A { #field = 2; method() { return #field instanceof 1; }}`).not.toEval();
expect(`class A { #field = 2; method() { return #field < 1; }}`).not.toEval();
expect(`class A { #field = 2; method() { return #field + 1; }}`).not.toEval();
expect(`class A { #field = 2; method() { return #field ** 1; }}`).not.toEval();
expect(`class A { #field = 2; method() { return !#field; } }`).not.toEval();
expect(`class A { #field = 2; method() { return ~#field; } }`).not.toEval();
expect(`class A { #field = 2; method() { return ++#field; } }`).not.toEval();
expect(`class A { #field = 2; method() { return #field in 1; }}`).toEval();
});
test("cannot have static and non static field with the same description", () => {
expect("class A { static #simple; #simple; }").not.toEval();
});