Skip to content

Commit ca9d8f8

Browse files
committed
[GR-54508] Decorators should not be enabled in ES 2023.
PullRequest: js/3162
2 parents 02c5d72 + 313ed6f commit ca9d8f8

File tree

6 files changed

+58
-33
lines changed

6 files changed

+58
-33
lines changed

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141

4242
package com.oracle.js.parser;
4343

44+
import static com.oracle.js.parser.ScriptEnvironment.ES_2015;
45+
import static com.oracle.js.parser.ScriptEnvironment.ES_2017;
46+
import static com.oracle.js.parser.ScriptEnvironment.ES_2020;
47+
import static com.oracle.js.parser.ScriptEnvironment.ES_2021;
48+
import static com.oracle.js.parser.ScriptEnvironment.ES_2022;
49+
import static com.oracle.js.parser.ScriptEnvironment.ES_STAGING;
4450
import static com.oracle.js.parser.TokenType.ACCESSOR;
4551
import static com.oracle.js.parser.TokenType.ARROW;
4652
import static com.oracle.js.parser.TokenType.AS;
@@ -910,42 +916,39 @@ private boolean useBlockScope() {
910916
* ES6 (a.k.a. ES2015) or newer.
911917
*/
912918
private boolean isES6() {
913-
return env.ecmaScriptVersion >= 6;
919+
return env.ecmaScriptVersion >= ES_2015;
914920
}
915921

916922
/**
917923
* ES2017 or newer.
918924
*/
919925
private boolean isES2017() {
920-
return env.ecmaScriptVersion >= 8;
926+
return env.ecmaScriptVersion >= ES_2017;
921927
}
922928

923929
/**
924930
* ES2020 or newer.
925931
*/
926932
private boolean isES2020() {
927-
return env.ecmaScriptVersion >= 11;
933+
return env.ecmaScriptVersion >= ES_2020;
928934
}
929935

930936
/**
931937
* ES2021 or newer.
932938
*/
933939
private boolean isES2021() {
934-
return env.ecmaScriptVersion >= 12;
940+
return env.ecmaScriptVersion >= ES_2021;
935941
}
936942

937943
/**
938944
* ES2022 or newer.
939945
*/
940946
private boolean isES2022() {
941-
return env.ecmaScriptVersion >= 13;
947+
return env.ecmaScriptVersion >= ES_2022;
942948
}
943949

944-
/**
945-
* ES2023 or newer.
946-
*/
947-
private boolean isES2023() {
948-
return env.ecmaScriptVersion >= 14;
950+
private boolean isClassDecorators() {
951+
return env.ecmaScriptVersion >= ES_STAGING;
949952
}
950953

951954
private boolean isClassFields() {
@@ -1609,7 +1612,7 @@ private ClassNode classDeclaration(boolean yield, boolean await, boolean default
16091612
assert type == CLASS || type == AT;
16101613
List<Expression> classDecorators = null;
16111614
if (type == AT) {
1612-
assert isES2023();
1615+
assert isClassDecorators();
16131616
classDecorators = decoratorList(yield, await);
16141617
}
16151618

@@ -1652,7 +1655,7 @@ private ClassNode classExpression(boolean yield, boolean await) {
16521655
assert type == CLASS || type == AT;
16531656
List<Expression> classDecorators = null;
16541657
if (type == AT) {
1655-
assert isES2023();
1658+
assert isClassDecorators();
16561659
classDecorators = decoratorList(yield, await);
16571660
}
16581661
int classLineNumber = line;
@@ -1745,7 +1748,7 @@ private ClassNode classTail(int classLineNumber, long classToken, IdentNode clas
17451748
hasClassElementDecorators = true;
17461749
}
17471750
boolean isAutoAccessor = false;
1748-
if (isES2023() && type == ACCESSOR) {
1751+
if (isClassDecorators() && type == ACCESSOR) {
17491752
TokenType nextToken = lookaheadNoLineTerminator();
17501753
if (nextToken != LPAREN && nextToken != ASSIGN && nextToken != SEMICOLON && nextToken != RBRACE && nextToken != EOL) {
17511754
isAutoAccessor = true;
@@ -1755,7 +1758,7 @@ private ClassNode classTail(int classLineNumber, long classToken, IdentNode clas
17551758
boolean isStatic = false;
17561759
if (type == STATIC) {
17571760
TokenType nextToken = lookahead();
1758-
if (isES2023() && nextToken == ACCESSOR) {
1761+
if (isClassDecorators() && nextToken == ACCESSOR) {
17591762
next();
17601763
nextToken = lookaheadNoLineTerminator();
17611764
if (nextToken != LPAREN && nextToken != ASSIGN && nextToken != SEMICOLON && nextToken != RBRACE && nextToken != EOL) {
@@ -7595,7 +7598,7 @@ private boolean lookaheadIsAsyncMethod(boolean allowPrivate) {
75957598
* </pre>
75967599
*/
75977600
public List<Expression> decoratorList(boolean yield, boolean await) {
7598-
assert isES2023();
7601+
assert isClassDecorators();
75997602
List<Expression> decoratorList = new ArrayList<>();
76007603
while (type == AT) {
76017604
next();

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,19 @@
4747
* Parser environment consists of command line options, and output and error writers, etc.
4848
*/
4949
public final class ScriptEnvironment {
50+
51+
public static final int ES_2015 = 6;
52+
public static final int ES_2016 = 7;
53+
public static final int ES_2017 = 8;
54+
public static final int ES_2018 = 9;
55+
public static final int ES_2019 = 10;
56+
public static final int ES_2020 = 11;
57+
public static final int ES_2021 = 12;
58+
public static final int ES_2022 = 13;
59+
public static final int ES_2023 = 14;
60+
public static final int ES_2024 = 15;
61+
public static final int ES_STAGING = Integer.MAX_VALUE;
62+
5063
/** Error writer for this environment */
5164
private final PrintWriter err;
5265

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141

4242
package com.oracle.js.parser;
4343

44+
import static com.oracle.js.parser.ScriptEnvironment.ES_2015;
45+
import static com.oracle.js.parser.ScriptEnvironment.ES_2020;
46+
import static com.oracle.js.parser.ScriptEnvironment.ES_2021;
47+
import static com.oracle.js.parser.ScriptEnvironment.ES_STAGING;
4448
import static com.oracle.js.parser.TokenKind.BINARY;
4549
import static com.oracle.js.parser.TokenKind.BRACKET;
4650
import static com.oracle.js.parser.TokenKind.CONTEXTUAL;
@@ -79,13 +83,13 @@ public enum TokenType {
7983
BIT_AND (BINARY, "&", 8, true),
8084
AND (BINARY, "&&", 5, true),
8185
ASSIGN_BIT_AND (BINARY, "&=", 2, false),
82-
ASSIGN_AND (BINARY, "&&=", 2, false, 12),
86+
ASSIGN_AND (BINARY, "&&=", 2, false, ES_2021),
8387
LPAREN (BRACKET, "(", 17, true),
8488
RPAREN (BRACKET, ")", 0, true),
8589
MUL (BINARY, "*", 13, true),
8690
ASSIGN_MUL (BINARY, "*=", 2, false),
87-
EXP (BINARY, "**", 14, false, 6),
88-
ASSIGN_EXP (BINARY, "**=", 2, false, 6),
91+
EXP (BINARY, "**", 14, false, ES_2015),
92+
ASSIGN_EXP (BINARY, "**=", 2, false, ES_2015),
8993
ADD (BINARY, "+", 12, true),
9094
INCPREFIX (UNARY, "++", 16, true),
9195
ASSIGN_ADD (BINARY, "+=", 2, false),
@@ -121,14 +125,14 @@ public enum TokenType {
121125
BIT_OR (BINARY, "|", 6, true),
122126
ASSIGN_BIT_OR (BINARY, "|=", 2, false),
123127
OR (BINARY, "||", 4, true),
124-
ASSIGN_OR (BINARY, "||=", 2, false, 12),
128+
ASSIGN_OR (BINARY, "||=", 2, false, ES_2021),
125129
RBRACE (BRACKET, "}"),
126130
BIT_NOT (UNARY, "~", 15, false),
127131
ELLIPSIS (UNARY, "..."),
128-
NULLISHCOALESC (BINARY, "??", 4, true, 11),
129-
ASSIGN_NULLCOAL(BINARY, "??=", 2, false, 12),
130-
OPTIONAL_CHAIN (BRACKET, "?.", 18, true, 11),
131-
AT (UNARY, "@", 0, true, 14),
132+
NULLISHCOALESC (BINARY, "??", 4, true, ES_2020),
133+
ASSIGN_NULLCOAL(BINARY, "??=", 2, false, ES_2021),
134+
OPTIONAL_CHAIN (BRACKET, "?.", 18, true, ES_2020),
135+
AT (UNARY, "@", 0, true, ES_STAGING),
132136

133137
// ECMA 7.6.1.1 Keywords, 7.6.1.2 Future Reserved Words.
134138
// All other Java keywords are commented out.

graal-js/src/com.oracle.truffle.js.parser/src/com/oracle/truffle/js/parser/GraalJSParserHelper.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -61,6 +61,7 @@
6161
import com.oracle.truffle.api.strings.TruffleString;
6262
import com.oracle.truffle.js.parser.internal.ir.debug.JSONWriter;
6363
import com.oracle.truffle.js.runtime.Errors;
64+
import com.oracle.truffle.js.runtime.JSConfig;
6465
import com.oracle.truffle.js.runtime.JSContext;
6566
import com.oracle.truffle.js.runtime.JSException;
6667
import com.oracle.truffle.js.runtime.JSParserOptions;
@@ -182,7 +183,11 @@ protected Function<Number, TruffleString> getNumberToStringConverter() {
182183
private static ScriptEnvironment makeScriptEnvironment(JSParserOptions parserOptions) {
183184
ScriptEnvironment.Builder builder = ScriptEnvironment.builder();
184185
builder.strict(parserOptions.strict());
185-
builder.ecmaScriptVersion(parserOptions.ecmaScriptVersion());
186+
int ecmaScriptVersion = parserOptions.ecmaScriptVersion();
187+
if (ecmaScriptVersion == JSConfig.StagingECMAScriptVersion) {
188+
ecmaScriptVersion = ScriptEnvironment.ES_STAGING;
189+
}
190+
builder.ecmaScriptVersion(ecmaScriptVersion);
186191
builder.emptyStatements(parserOptions.emptyStatements());
187192
builder.syntaxExtensions(parserOptions.syntaxExtensions());
188193
builder.scripting(parserOptions.scripting());

graal-js/src/com.oracle.truffle.js.test/js/decorators/hello_decorators_es2023.js renamed to graal-js/src/com.oracle.truffle.js.test/js/decorators/hello_decorators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.

graal-js/src/com.oracle.truffle.js.test/js/decorators/hello_decorators_es2022.js renamed to graal-js/src/com.oracle.truffle.js.test/js/decorators/hello_decorators_es2024.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
66
*/
77

88
/**
9-
* @option ecmascript-version=2022
9+
* @option ecmascript-version=latest
1010
*/
1111

1212
load('../assert.js');
@@ -22,7 +22,7 @@ syntaxError(`
2222
2323
@dec
2424
class C {};
25-
25+
2626
`,'Expected an operand ');
2727

2828

@@ -31,7 +31,7 @@ syntaxError(`
3131
class C {
3232
accessor foo = 42;
3333
};
34-
34+
3535
`, 'Expected ( but found foo');
3636

3737

@@ -40,7 +40,7 @@ syntaxError(`
4040
class C {
4141
static accessor foo = 42;
4242
};
43-
43+
4444
`, 'Expected ( but found foo');
4545

4646

@@ -52,7 +52,7 @@ syntaxError(`
5252

5353

5454
//---------------------------------------------//
55-
// 'accessor' is a valid field name in es2022: no exceptions.
55+
// 'accessor' is a valid field name in es2023: no exceptions.
5656
class C1 { accessor }
5757
class C2 { static accessor }
5858
class C3 { static accessor = 42; }

0 commit comments

Comments
 (0)