Skip to content

Commit

Permalink
chore(transformer): enable class-properties plugin (#7750)
Browse files Browse the repository at this point in the history
Done!
  • Loading branch information
Dunqing committed Dec 31, 2024
1 parent 0592a8b commit e5ee38f
Show file tree
Hide file tree
Showing 11 changed files with 13,456 additions and 2,878 deletions.
10 changes: 2 additions & 8 deletions crates/oxc_transformer/src/options/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ impl EnvOptions {
es2021: ES2021Options { logical_assignment_operators: true },
es2022: ES2022Options {
class_static_block: true,
class_properties: if include_unfinished_plugins {
Some(ClassPropertiesOptions::default())
} else {
None
},
class_properties: Some(ClassPropertiesOptions::default()),
},
}
}
Expand Down Expand Up @@ -140,9 +136,7 @@ impl EnvOptions {
}
}
engine_targets.insert(Engine::Es, es_target.unwrap_or(ESTarget::default()).version());
let mut env_options = EnvOptions::from(engine_targets);
env_options.es2022.class_properties = None;
Ok(env_options)
Ok(EnvOptions::from(engine_targets))
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_transformer/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ impl From<ESTarget> for TransformOptions {
use crate::options::es_target::ESVersion;
let mut engine_targets = EngineTargets::default();
engine_targets.insert(Engine::Es, target.version());
let mut env = EnvOptions::from(engine_targets);
env.es2022.class_properties = None;
let env = EnvOptions::from(engine_targets);
Self { env, ..Self::default() }
}
}
Expand Down
9 changes: 1 addition & 8 deletions crates/oxc_transformer/tests/integrations/es_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn es_target() {
("es2020", "a ||= b"),
("es2019", "1n ** 2n"), // test target error
("es2021", "class foo { static {} }"),
("es2021", "class Foo { #a; }"), // Plugin not ready
("es2021", "class Foo { #a; }"),
];

// Test no transformation for esnext.
Expand Down Expand Up @@ -54,13 +54,6 @@ fn es_target() {
}
}

#[test]
fn no_class_properties() {
let code = "class Foo { #a; }";
let options = TransformOptions::from(ESTarget::from_str("es2015").unwrap());
assert_eq!(test(code, &options), Ok(codegen(code, SourceType::mjs())));
}

#[test]
fn target_list_pass() {
// https://vite.dev/config/build-options.html#build-target
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
source: crates/oxc_transformer/tests/integrations/es_target.rs
assertion_line: 50
snapshot_kind: text
---
########## 0 es5
() => {}
Expand Down Expand Up @@ -80,13 +78,16 @@ a || (a = b);
########## 10 es2021
class foo { static {} }
----------
class foo {
static #_ = (() => {})();
}
class foo {}
(() => {})();

########## 11 es2021
class Foo { #a; }
----------
import _classPrivateFieldInitSpec from '@babel/runtime/helpers/classPrivateFieldInitSpec';
var _a = new WeakMap();
class Foo {
#a;
constructor() {
_classPrivateFieldInitSpec(this, _a, void 0);
}
}
11 changes: 10 additions & 1 deletion napi/transform/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ describe('target', () => {
const ret = transform('test.js', code, { target: 'es2015' });
expect(ret.errors.length).toBe(0);
expect(ret.code).toBeDefined();
expect(ret.code).toEqual(code);
expect(ret.code).toMatchInlineSnapshot(`
"import _classPrivateFieldInitSpec from "@babel/runtime/helpers/classPrivateFieldInitSpec";
var _a = new WeakMap();
class Foo {
constructor() {
_classPrivateFieldInitSpec(this, _a, void 0);
}
}
"
`);
});
});

Expand Down
74 changes: 56 additions & 18 deletions tasks/coverage/snapshots/semantic_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 54a8389f

semantic_babel Summary:
AST Parsed : 2218/2218 (100.00%)
Positive Passed: 1889/2218 (85.17%)
Positive Passed: 1885/2218 (84.99%)
tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.3-function-in-if-body/input.js
semantic error: Symbol scope ID mismatch for "f":
after transform: SymbolId(0): ScopeId(4294967294)
Expand All @@ -26,12 +26,42 @@ semantic error: A 'return' statement can only be used within a function body.
tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/328/input.js
semantic error: A 'return' statement can only be used within a function body.

tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-methods/async/input.js
semantic error: Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(StrictMode | Function)
rebuilt : ScopeId(4): ScopeFlags(Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-methods/async-generator/input.js
semantic error: Scope flags mismatch:
after transform: ScopeId(2): ScopeFlags(StrictMode | Function)
rebuilt : ScopeId(4): ScopeFlags(Function)
Scope flags mismatch:
after transform: ScopeId(3): ScopeFlags(StrictMode)
rebuilt : ScopeId(5): ScopeFlags(0x0)
Scope flags mismatch:
after transform: ScopeId(4): ScopeFlags(StrictMode)
rebuilt : ScopeId(6): ScopeFlags(0x0)
Scope flags mismatch:
after transform: ScopeId(5): ScopeFlags(StrictMode)
rebuilt : ScopeId(7): ScopeFlags(0x0)

tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-properties/await-in-private-property-in-params-of-async-arrow/input.js
semantic error: Expected a semicolon or an implicit semicolon after a statement, but found none

tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/arguments-in-key/input.js
semantic error: 'arguments' is not allowed in class field initializer

tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/await-identifier-in-computed-property-inside-params-of-function-inside-params-of-async-function/input.js
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["_asyncToGenerator", "_defineProperty"]
rebuilt : ScopeId(0): ["_asyncToGenerator", "_await", "_defineProperty"]
Bindings mismatch:
after transform: ScopeId(2): ["_await", "f", "x"]
rebuilt : ScopeId(2): ["f", "x"]
Symbol scope ID mismatch for "_await":
after transform: SymbolId(3): ScopeId(2)
rebuilt : SymbolId(2): ScopeId(0)

tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/await-in-property-in-params-of-async-arrow/input.js
semantic error: Expected a semicolon or an implicit semicolon after a statement, but found none

Expand Down Expand Up @@ -80,8 +110,8 @@ rebuilt : ScopeId(1): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-property/typescript/input.js
semantic error: Unresolved references mismatch:
after transform: ["Array", "foo"]
rebuilt : ["foo"]
after transform: ["Array", "WeakMap", "foo", "require"]
rebuilt : ["WeakMap", "foo", "require"]

tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/enum/input.js
semantic error: Bindings mismatch:
Expand Down Expand Up @@ -119,16 +149,16 @@ rebuilt : []

tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/loc-index-property/input.js
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["AssertsFoo", "Foo"]
rebuilt : ScopeId(0): ["AssertsFoo"]
after transform: ScopeId(0): ["AssertsFoo", "Foo", "_defineProperty"]
rebuilt : ScopeId(0): ["AssertsFoo", "_defineProperty"]
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
rebuilt : ScopeId(0): [ScopeId(1)]

tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/typescript/loc-index-property-babel-7/input.js
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["AssertsFoo", "Foo"]
rebuilt : ScopeId(0): ["AssertsFoo"]
after transform: ScopeId(0): ["AssertsFoo", "Foo", "_defineProperty"]
rebuilt : ScopeId(0): ["AssertsFoo", "_defineProperty"]
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
rebuilt : ScopeId(0): [ScopeId(1)]
Expand Down Expand Up @@ -188,7 +218,7 @@ rebuilt : []
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-this-with-predicate/input.ts
semantic error: Symbol reference IDs mismatch for "Foo":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)]
rebuilt : SymbolId(0): []
rebuilt : SymbolId(1): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-var/input.ts
semantic error: Scope children mismatch:
Expand All @@ -207,19 +237,19 @@ rebuilt : []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation/input.ts
semantic error: Symbol reference IDs mismatch for "AbstractClass":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(3)]
rebuilt : SymbolId(0): [ReferenceId(0)]
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(3), ReferenceId(9)]
rebuilt : SymbolId(1): [ReferenceId(1), ReferenceId(2)]
Symbol reference IDs mismatch for "ConcreteClass":
after transform: SymbolId(2): [ReferenceId(4), ReferenceId(6)]
rebuilt : SymbolId(1): [ReferenceId(1)]
rebuilt : SymbolId(2): [ReferenceId(3)]

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/assign/TSTypeParameterInstantiation-babel-7/input.ts
semantic error: Symbol reference IDs mismatch for "AbstractClass":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(3)]
rebuilt : SymbolId(0): [ReferenceId(0)]
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(3), ReferenceId(9)]
rebuilt : SymbolId(1): [ReferenceId(1), ReferenceId(2)]
Symbol reference IDs mismatch for "ConcreteClass":
after transform: SymbolId(2): [ReferenceId(4), ReferenceId(6)]
rebuilt : SymbolId(1): [ReferenceId(1)]
rebuilt : SymbolId(2): [ReferenceId(3)]

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/cast/as/input.ts
semantic error: Unresolved references mismatch:
Expand Down Expand Up @@ -266,8 +296,8 @@ rebuilt : ScopeId(5): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/async-named-properties/input.ts
semantic error: Scope children mismatch:
after transform: ScopeId(1): [ScopeId(2)]
rebuilt : ScopeId(1): []
after transform: ScopeId(1): [ScopeId(2), ScopeId(3)]
rebuilt : ScopeId(1): [ScopeId(2)]

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/async-optional-method/input.js
semantic error: Scope children mismatch:
Expand Down Expand Up @@ -400,8 +430,11 @@ semantic error: A required parameter cannot follow an optional parameter.

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/private-method-overload/input.ts
semantic error: Scope children mismatch:
after transform: ScopeId(1): [ScopeId(2), ScopeId(3), ScopeId(4)]
after transform: ScopeId(1): [ScopeId(2), ScopeId(3), ScopeId(5)]
rebuilt : ScopeId(1): [ScopeId(2)]
Symbol flags mismatch for "_f":
after transform: SymbolId(4): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(3): SymbolFlags(BlockScopedVariable | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/properties/input.ts
semantic error: Identifier `x` has already been declared
Expand All @@ -413,6 +446,11 @@ Identifier `x` has already been declared
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/static/input.ts
semantic error: Function implementation is missing or not immediately following the declaration.

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/static-asi/input.ts
semantic error: Symbol flags mismatch for "_method":
after transform: SymbolId(2): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(3): SymbolFlags(BlockScopedVariable | Function)

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/const/initializer-ambient-context/input.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["N"]
Expand Down Expand Up @@ -1876,7 +1914,7 @@ rebuilt : ["f"]
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/type-arguments/instantiation-expression-asi/input.ts
semantic error: Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7)]
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6)]
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(6), ScopeId(8)]
Unresolved references mismatch:
after transform: ["f", "true"]
rebuilt : ["f"]
Expand Down
22 changes: 11 additions & 11 deletions tasks/coverage/snapshots/semantic_misc.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ rebuilt : []

tasks/coverage/misc/pass/oxc-3948-1.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["BrowserWorkingCopyBackupTracker", "CancellationToken", "DisposableStore", "EditorPart", "EditorService", "IEditorGroupsService", "IEditorService", "IFilesConfigurationService", "IInstantiationService", "ILifecycleService", "ILogService", "IUntitledTextResourceEditorInput", "IWorkingCopyBackup", "IWorkingCopyBackupService", "IWorkingCopyEditorHandler", "IWorkingCopyEditorService", "IWorkingCopyService", "InMemoryTestWorkingCopyBackupService", "LifecyclePhase", "Schemas", "TestServiceAccessor", "TestWorkingCopy", "URI", "UntitledTextEditorInput", "VSBuffer", "_asyncToGenerator", "assert", "bufferToReadable", "createEditorPart", "ensureNoDisposablesAreLeakedInTestSuite", "isWindows", "registerTestResourceEditor", "timeout", "toResource", "toTypedWorkingCopyId", "toUntypedWorkingCopyId", "workbenchInstantiationService", "workbenchTeardown"]
rebuilt : ScopeId(0): ["BrowserWorkingCopyBackupTracker", "DisposableStore", "EditorService", "IEditorGroupsService", "IEditorService", "IFilesConfigurationService", "ILifecycleService", "ILogService", "IWorkingCopyBackupService", "IWorkingCopyEditorService", "IWorkingCopyService", "InMemoryTestWorkingCopyBackupService", "LifecyclePhase", "Schemas", "TestServiceAccessor", "TestWorkingCopy", "URI", "UntitledTextEditorInput", "VSBuffer", "_asyncToGenerator", "assert", "bufferToReadable", "createEditorPart", "ensureNoDisposablesAreLeakedInTestSuite", "isWindows", "registerTestResourceEditor", "timeout", "toResource", "toTypedWorkingCopyId", "toUntypedWorkingCopyId", "workbenchInstantiationService", "workbenchTeardown"]
after transform: ScopeId(0): ["BrowserWorkingCopyBackupTracker", "CancellationToken", "DisposableStore", "EditorPart", "EditorService", "IEditorGroupsService", "IEditorService", "IFilesConfigurationService", "IInstantiationService", "ILifecycleService", "ILogService", "IUntitledTextResourceEditorInput", "IWorkingCopyBackup", "IWorkingCopyBackupService", "IWorkingCopyEditorHandler", "IWorkingCopyEditorService", "IWorkingCopyService", "InMemoryTestWorkingCopyBackupService", "LifecyclePhase", "Schemas", "TestServiceAccessor", "TestWorkingCopy", "URI", "UntitledTextEditorInput", "VSBuffer", "_asyncToGenerator", "_defineProperty", "assert", "bufferToReadable", "createEditorPart", "ensureNoDisposablesAreLeakedInTestSuite", "isWindows", "registerTestResourceEditor", "timeout", "toResource", "toTypedWorkingCopyId", "toUntypedWorkingCopyId", "workbenchInstantiationService", "workbenchTeardown"]
rebuilt : ScopeId(0): ["BrowserWorkingCopyBackupTracker", "DisposableStore", "EditorService", "IEditorGroupsService", "IEditorService", "IFilesConfigurationService", "ILifecycleService", "ILogService", "IWorkingCopyBackupService", "IWorkingCopyEditorService", "IWorkingCopyService", "InMemoryTestWorkingCopyBackupService", "LifecyclePhase", "Schemas", "TestServiceAccessor", "TestWorkingCopy", "URI", "UntitledTextEditorInput", "VSBuffer", "_asyncToGenerator", "_defineProperty", "assert", "bufferToReadable", "createEditorPart", "ensureNoDisposablesAreLeakedInTestSuite", "isWindows", "registerTestResourceEditor", "timeout", "toResource", "toTypedWorkingCopyId", "toUntypedWorkingCopyId", "workbenchInstantiationService", "workbenchTeardown"]
Symbol reference IDs mismatch for "URI":
after transform: SymbolId(1): [ReferenceId(109), ReferenceId(117), ReferenceId(156), ReferenceId(158), ReferenceId(160), ReferenceId(162)]
rebuilt : SymbolId(1): [ReferenceId(158), ReferenceId(160), ReferenceId(162), ReferenceId(164)]
rebuilt : SymbolId(1): [ReferenceId(161), ReferenceId(163), ReferenceId(165), ReferenceId(167)]
Symbol reference IDs mismatch for "IEditorService":
after transform: SymbolId(2): [ReferenceId(23), ReferenceId(24), ReferenceId(67), ReferenceId(184)]
rebuilt : SymbolId(2): [ReferenceId(17), ReferenceId(58), ReferenceId(185)]
rebuilt : SymbolId(2): [ReferenceId(17), ReferenceId(60), ReferenceId(188)]
Symbol reference IDs mismatch for "IEditorGroupsService":
after transform: SymbolId(4): [ReferenceId(25), ReferenceId(26), ReferenceId(57), ReferenceId(176)]
rebuilt : SymbolId(3): [ReferenceId(18), ReferenceId(49), ReferenceId(178)]
rebuilt : SymbolId(3): [ReferenceId(18), ReferenceId(51), ReferenceId(181)]
Symbol reference IDs mismatch for "EditorService":
after transform: SymbolId(5): [ReferenceId(61), ReferenceId(64), ReferenceId(178), ReferenceId(181)]
rebuilt : SymbolId(4): [ReferenceId(55), ReferenceId(182)]
rebuilt : SymbolId(4): [ReferenceId(57), ReferenceId(185)]
Symbol reference IDs mismatch for "IWorkingCopyBackupService":
after transform: SymbolId(7): [ReferenceId(11), ReferenceId(12), ReferenceId(51), ReferenceId(170)]
rebuilt : SymbolId(5): [ReferenceId(11), ReferenceId(43), ReferenceId(172)]
rebuilt : SymbolId(5): [ReferenceId(11), ReferenceId(45), ReferenceId(175)]
Symbol reference IDs mismatch for "IFilesConfigurationService":
after transform: SymbolId(10): [ReferenceId(13), ReferenceId(14)]
rebuilt : SymbolId(8): [ReferenceId(12)]
Expand All @@ -72,19 +72,19 @@ after transform: SymbolId(17): [ReferenceId(38), ReferenceId(87)]
rebuilt : SymbolId(13): [ReferenceId(31)]
Symbol reference IDs mismatch for "InMemoryTestWorkingCopyBackupService":
after transform: SymbolId(19): [ReferenceId(43), ReferenceId(46), ReferenceId(165)]
rebuilt : SymbolId(15): [ReferenceId(38), ReferenceId(167)]
rebuilt : SymbolId(15): [ReferenceId(40), ReferenceId(170)]
Symbol reference IDs mismatch for "TestServiceAccessor":
after transform: SymbolId(21): [ReferenceId(1), ReferenceId(40), ReferenceId(71), ReferenceId(155), ReferenceId(188)]
rebuilt : SymbolId(17): [ReferenceId(62), ReferenceId(189)]
rebuilt : SymbolId(17): [ReferenceId(64), ReferenceId(192)]
Symbol reference IDs mismatch for "IWorkingCopyEditorService":
after transform: SymbolId(32): [ReferenceId(21), ReferenceId(22)]
rebuilt : SymbolId(26): [ReferenceId(16)]
Symbol reference IDs mismatch for "TestWorkingCopyBackupTracker":
after transform: SymbolId(39): [ReferenceId(42), ReferenceId(74), ReferenceId(154), ReferenceId(215)]
rebuilt : SymbolId(34): [ReferenceId(65), ReferenceId(216)]
rebuilt : SymbolId(35): [ReferenceId(67), ReferenceId(219)]
Unresolved reference IDs mismatch for "Promise":
after transform: [ReferenceId(36), ReferenceId(39), ReferenceId(82), ReferenceId(114), ReferenceId(153), ReferenceId(282)]
rebuilt : [ReferenceId(289)]
rebuilt : [ReferenceId(292)]

tasks/coverage/misc/pass/oxc-4449.ts
semantic error: Bindings mismatch:
Expand Down
Loading

0 comments on commit e5ee38f

Please sign in to comment.