Skip to content

Commit 7965c85

Browse files
committed
[GR-22308] Instance class field can be named 'static'.
PullRequest: js/1457
2 parents 8e898c2 + 5bc9c4a commit 7965c85

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

graal-js/src/com.oracle.js.parser/src/com/oracle/js/parser/Parser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,9 +1563,12 @@ private ClassNode classTail(int classLineNumber, long classToken, IdentNode clas
15631563
break;
15641564
}
15651565
boolean isStatic = false;
1566-
if (type == STATIC && lookahead() != LPAREN) {
1567-
isStatic = true;
1568-
next();
1566+
if (type == STATIC) {
1567+
TokenType nextToken = lookahead();
1568+
if (nextToken != LPAREN && nextToken != ASSIGN && nextToken != SEMICOLON && nextToken != RBRACE) {
1569+
isStatic = true;
1570+
next();
1571+
} // else method/field named 'static'
15691572
}
15701573
long classElementToken = token;
15711574
int classElementLine = line;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* Tests of class field named 'static'.
10+
*
11+
* @option ecmascript-version=2021
12+
*/
13+
14+
load('assert.js');
15+
16+
class C { static }
17+
18+
assertFalse(C.hasOwnProperty('static'));
19+
assertTrue(new C().hasOwnProperty('static'));
20+
21+
class D {
22+
static
23+
static
24+
static
25+
}
26+
27+
assertTrue(D.hasOwnProperty('static'));
28+
assertTrue(new D().hasOwnProperty('static'));
29+
30+
true;

graal-js/test/test262.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,14 +1681,6 @@
16811681
"filePath" : "language/expressions/class/elements/private-field-after-optional-chain.js",
16821682
"status" : "FAIL",
16831683
"comment" : "new failures update 2020-04-01"
1684-
}, {
1685-
"filePath" : "language/expressions/class/elements/static-as-valid-instance-field-assigned.js",
1686-
"status" : "FAIL",
1687-
"comment" : "new failures update 2020-04-01"
1688-
}, {
1689-
"filePath" : "language/expressions/class/elements/static-as-valid-instance-field.js",
1690-
"status" : "FAIL",
1691-
"comment" : "new failures update 2020-04-01"
16921684
}, {
16931685
"filePath" : "language/expressions/class/elements/syntax/early-errors/grammar-special-meth-ctor-async-meth.js",
16941686
"status" : "FAIL",
@@ -1709,14 +1701,6 @@
17091701
"filePath" : "language/statements/class/elements/private-field-after-optional-chain.js",
17101702
"status" : "FAIL",
17111703
"comment" : "new failures update 2020-04-01"
1712-
}, {
1713-
"filePath" : "language/statements/class/elements/static-as-valid-instance-field-assigned.js",
1714-
"status" : "FAIL",
1715-
"comment" : "new failures update 2020-04-01"
1716-
}, {
1717-
"filePath" : "language/statements/class/elements/static-as-valid-instance-field.js",
1718-
"status" : "FAIL",
1719-
"comment" : "new failures update 2020-04-01"
17201704
}, {
17211705
"filePath" : "language/statements/class/elements/syntax/early-errors/grammar-special-meth-ctor-async-meth.js",
17221706
"status" : "FAIL",

0 commit comments

Comments
 (0)