Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transformer/class-properties): create temp vars in correct scope #7824

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
// Create binding for private property key
if let PropertyKey::PrivateIdentifier(ident) = &prop.key {
// Note: Current scope is outside class.
let binding = ctx.generate_uid_in_current_scope(
ident.name.as_str(),
SymbolFlags::FunctionScopedVariable,
);
let binding = ctx.generate_uid_in_current_hoist_scope(&ident.name);
private_props.insert(
ident.name.clone(),
PrivateProp { binding, is_static: prop.r#static },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use oxc_syntax::symbol::{SymbolFlags, SymbolId};
use oxc_syntax::symbol::SymbolId;
use oxc_traverse::{BoundIdentifier, TraverseCtx};

/// Store for bindings for class.
Expand Down Expand Up @@ -98,6 +98,6 @@ impl<'a> ClassBindings<'a> {
// TODO(improve-on-babel): If class name var isn't mutated, no need for temp var for
// class declaration. Can just use class binding.
let name = name_binding.map_or("Class", |binding| binding.name.as_str());
ctx.generate_uid_in_current_scope(name, SymbolFlags::FunctionScopedVariable)
ctx.generate_uid_in_current_hoist_scope(name)
}
}
25 changes: 4 additions & 21 deletions tasks/transform_conformance/snapshots/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 54a8389f

Passed: 578/927
Passed: 579/927

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down Expand Up @@ -276,7 +276,7 @@ x Output mismatch
x Output mismatch


# babel-plugin-transform-class-properties (192/264)
# babel-plugin-transform-class-properties (193/264)
* assumption-constantSuper/complex-super-class/input.js
x Output mismatch

Expand Down Expand Up @@ -400,14 +400,11 @@ x Output mismatch

* private-loose/nested-class-extends-computed-redeclared/input.js
Bindings mismatch:
after transform: ScopeId(2): ["Nested", "_foo2"]
after transform: ScopeId(2): ["Nested", "_foo2", "_foo3"]
rebuilt : ScopeId(3): ["Nested", "_foo2", "_foo3", "_this$foo"]
Bindings mismatch:
after transform: ScopeId(3): ["_foo3", "_this$foo"]
after transform: ScopeId(3): ["_this$foo"]
rebuilt : ScopeId(4): []
Symbol scope ID mismatch for "_foo3":
after transform: SymbolId(5): ScopeId(3)
rebuilt : SymbolId(2): ScopeId(3)
Symbol scope ID mismatch for "_this$foo":
after transform: SymbolId(6): ScopeId(3)
rebuilt : SymbolId(3): ScopeId(3)
Expand Down Expand Up @@ -505,20 +502,6 @@ x Output mismatch
* regression/7951/input.mjs
x Output mismatch

* regression/8882/input.js
Bindings mismatch:
after transform: ScopeId(0): ["classes"]
rebuilt : ScopeId(0): ["_A", "_bar", "classes"]
Bindings mismatch:
after transform: ScopeId(2): ["_A", "_bar", "_i"]
rebuilt : ScopeId(2): ["_i"]
Symbol scope ID mismatch for "_A":
after transform: SymbolId(4): ScopeId(2)
rebuilt : SymbolId(2): ScopeId(0)
Symbol scope ID mismatch for "_bar":
after transform: SymbolId(3): ScopeId(2)
rebuilt : SymbolId(3): ScopeId(0)


# babel-plugin-transform-nullish-coalescing-operator (5/12)
* assumption-noDocumentAll/transform/input.js
Expand Down
Loading