Skip to content

Commit f676841

Browse files
committed
refactor(semantic): add strict mode in scope flags for class definitions
1 parent 03ad1e3 commit f676841

File tree

3 files changed

+13
-56
lines changed

3 files changed

+13
-56
lines changed

crates/oxc_semantic/src/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ impl<'a> SemanticBuilder<'a> {
258258

259259
pub fn strict_mode(&self) -> bool {
260260
self.current_scope_flags().is_strict_mode()
261-
|| self.current_node_flags.contains(NodeFlags::Class)
262261
}
263262

264263
pub fn set_function_node_flag(&mut self, flag: NodeFlags) {
@@ -421,6 +420,12 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
421420
if flags.contains(ScopeFlags::Top) { None } else { Some(self.current_scope_id) };
422421

423422
let mut flags = flags;
423+
424+
if !flags.is_strict_mode() && self.current_node_flags.has_class() {
425+
// NOTE A class definition is always strict mode code.
426+
flags |= ScopeFlags::StrictMode;
427+
};
428+
424429
if let Some(parent_scope_id) = parent_scope_id {
425430
flags = self.scope.get_new_scope_flags(flags, parent_scope_id);
426431
}

tasks/coverage/parser_babel.snap

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ commit: 12619ffe
33
parser_babel Summary:
44
AST Parsed : 2093/2101 (99.62%)
55
Positive Passed: 2083/2101 (99.14%)
6-
Negative Passed: 1380/1501 (91.94%)
6+
Negative Passed: 1379/1501 (91.87%)
77
Expect Syntax Error: "annex-b/disabled/1.1-html-comments-close/input.js"
88
Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions/input.js"
99
Expect Syntax Error: "annex-b/disabled/3.1-sloppy-labeled-functions-if-body/input.js"
@@ -39,6 +39,7 @@ Expect Syntax Error: "esprima/es2015-arrow-function/invalid-param-strict-mode/in
3939
Expect Syntax Error: "esprima/es2015-generator/generator-parameter-binding-property-reserved/input.js"
4040
Expect Syntax Error: "esprima/invalid-syntax/migrated_0101/input.js"
4141
Expect Syntax Error: "esprima/invalid-syntax/migrated_0276/input.js"
42+
Expect Syntax Error: "esprima/invalid-syntax/migrated_0278/input.js"
4243
Expect Syntax Error: "typescript/cast/satisfies-const-error/input.ts"
4344
Expect Syntax Error: "typescript/cast/unparenthesized-assert-and-assign/input.ts"
4445
Expect Syntax Error: "typescript/cast/unparenthesized-type-assertion-and-assign/input.ts"
@@ -9688,12 +9689,6 @@ Expect to Parse: "typescript/types/const-type-parameters-babel-7/input.ts"
96889689
· ────
96899690
╰────
96909691

9691-
× The keyword 'static' is reserved
9692-
╭─[esprima/invalid-syntax/migrated_0278/input.js:1:18]
9693-
1 │ class A {static [static](){};}
9694-
· ──────
9695-
╰────
9696-
96979692
× A 'set' accessor cannot have rest parameter.
96989693
╭─[esprima/rest-parameter/invalid-setter-rest/input.js:1:13]
96999694
1 │ x = { set f(...y) {} }

tasks/coverage/parser_typescript.snap

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ commit: d8086f14
33
parser_typescript Summary:
44
AST Parsed : 5279/5283 (99.92%)
55
Positive Passed: 5272/5283 (99.79%)
6-
Negative Passed: 1094/4875 (22.44%)
6+
Negative Passed: 1090/4875 (22.36%)
77
Expect Syntax Error: "compiler/ClassDeclaration10.ts"
88
Expect Syntax Error: "compiler/ClassDeclaration11.ts"
99
Expect Syntax Error: "compiler/ClassDeclaration13.ts"
@@ -2321,6 +2321,8 @@ Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames38
23212321
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames38_ES6.ts"
23222322
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames39_ES5.ts"
23232323
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames39_ES6.ts"
2324+
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames3_ES5.ts"
2325+
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames3_ES6.ts"
23242326
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames42_ES5.ts"
23252327
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames42_ES6.ts"
23262328
Expect Syntax Error: "conformance/es6/computedProperties/computedPropertyNames43_ES5.ts"
@@ -3287,7 +3289,9 @@ Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parse
32873289
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName31.ts"
32883290
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName32.ts"
32893291
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName34.ts"
3292+
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts"
32903293
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName37.ts"
3294+
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts"
32913295
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName4.ts"
32923296
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName40.ts"
32933297
Expect Syntax Error: "conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts"
@@ -9690,21 +9694,6 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
96909694
16 │ }
96919695
╰────
96929696

9693-
× The keyword 'package' is reserved
9694-
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:27:17]
9695-
26 │ class F1 implements public.private.implements { }
9696-
27 │ class G extends package { }
9697-
· ───────
9698-
28 │ class H extends package.A { }
9699-
╰────
9700-
9701-
× The keyword 'package' is reserved
9702-
╭─[compiler/strictModeReservedWordInClassDeclaration.ts:28:17]
9703-
27 │ class G extends package { }
9704-
28 │ class H extends package.A { }
9705-
· ───────
9706-
╰────
9707-
97089697
× The keyword 'public' is reserved
97099698
╭─[compiler/strictModeReservedWordInDestructuring.ts:2:6]
97109699
1 │ "use strict"
@@ -13073,22 +13062,6 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1307313062
5 │ }
1307413063
╰────
1307513064

13076-
× Delete of an unqualified identifier in strict mode.
13077-
╭─[conformance/es6/computedProperties/computedPropertyNames3_ES5.ts:5:17]
13078-
4 │ static [() => { }]() { }
13079-
5 │ get [delete id]() { }
13080-
· ──
13081-
6 │ set [[0, 1]](v) { }
13082-
╰────
13083-
13084-
× Delete of an unqualified identifier in strict mode.
13085-
╭─[conformance/es6/computedProperties/computedPropertyNames3_ES6.ts:5:17]
13086-
4 │ static [() => { }]() { }
13087-
5 │ get [delete id]() { }
13088-
· ──
13089-
6 │ set [[0, 1]](v) { }
13090-
╰────
13091-
1309213065
× Identifier `` has already been declared
1309313066
╭─[conformance/es6/computedProperties/computedPropertyNames40_ES5.ts:8:6]
1309413067
7 │ // Computed properties
@@ -19143,22 +19116,6 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts"
1914319116
3 │ }
1914419117
╰────
1914519118

19146-
× The keyword 'public' is reserved
19147-
╭─[conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts:2:6]
19148-
1 │ class C {
19149-
2 │ [public ]: string;
19150-
· ──────
19151-
3 │ }
19152-
╰────
19153-
19154-
× The keyword 'public' is reserved
19155-
╭─[conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts:2:6]
19156-
1 │ class C {
19157-
2 │ [public]() { }
19158-
· ──────
19159-
3 │ }
19160-
╰────
19161-
1916219119
× The keyword 'public' is reserved
1916319120
╭─[conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName39.ts:3:6]
1916419121
2 │ class C {

0 commit comments

Comments
 (0)