Skip to content

Commit

Permalink
Private static properties WIP 4
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 15, 2024
1 parent af9198c commit 371b428
Show file tree
Hide file tree
Showing 5 changed files with 853 additions and 2,280 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/es2022/class_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
};

// Convert to assignment or `_defineProperty` call, depending on `loose` option
// TODO: Skip this for static private properties?
if let ClassName::Name(name) = &self.class_name {
let binding = if self.is_declaration {
// Can only not have a binding if is `export default class {}`
Expand All @@ -566,12 +567,11 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
}
let ClassName::Binding(class_binding) = &self.class_name else { unreachable!() };

let assignee = class_binding.create_read_expression(ctx);

let init_expr = if let PropertyKey::PrivateIdentifier(ident) = &mut prop.key {
self.create_private_static_init_assignment(ident, value, ctx)
} else {
// Convert to assignment or `_defineProperty` call, depending on `loose` option
let assignee = class_binding.create_read_expression(ctx);
self.create_init_assignment(prop, value, assignee, ctx)
};
self.insert_after.push(init_expr);
Expand Down
66 changes: 15 additions & 51 deletions tasks/coverage/snapshots/semantic_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,17 @@ rebuilt : ScopeId(3): ScopeFlags(Function)
Scope parent mismatch:
after transform: ScopeId(2): Some(ScopeId(1))
rebuilt : ScopeId(3): Some(ScopeId(0))
Symbol reference IDs mismatch for "Foo":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(5), ReferenceId(7)]
rebuilt : SymbolId(0): [ReferenceId(0)]
Reference symbol mismatch for "_x":
after transform: SymbolId(2) "_x"
rebuilt : <None>
Reference flags mismatch for "_x":
after transform: ReferenceId(6): ReferenceFlags(Read | Write)
after transform: ReferenceId(5): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(5): ReferenceFlags(Write)
Reference symbol mismatch for "_m":
after transform: SymbolId(3) "_m"
rebuilt : <None>
Reference flags mismatch for "_m":
after transform: ReferenceId(8): ReferenceFlags(Read | Write)
after transform: ReferenceId(6): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(6): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand All @@ -123,14 +120,11 @@ rebuilt : ScopeId(3): ScopeFlags(Function)
Scope parent mismatch:
after transform: ScopeId(2): Some(ScopeId(1))
rebuilt : ScopeId(3): Some(ScopeId(0))
Symbol reference IDs mismatch for "Foo":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)]
rebuilt : SymbolId(0): [ReferenceId(0)]
Reference symbol mismatch for "_m":
after transform: SymbolId(1) "_m"
rebuilt : <None>
Reference flags mismatch for "_m":
after transform: ReferenceId(2): ReferenceFlags(Read | Write)
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(1): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand All @@ -140,14 +134,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Foo", "_x"]
rebuilt : ScopeId(0): ["Foo"]
Symbol reference IDs mismatch for "Foo":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)]
rebuilt : SymbolId(0): [ReferenceId(0)]
Reference symbol mismatch for "_x":
after transform: SymbolId(1) "_x"
rebuilt : <None>
Reference flags mismatch for "_x":
after transform: ReferenceId(2): ReferenceFlags(Read | Write)
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(1): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand All @@ -157,14 +148,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Foo", "_x"]
rebuilt : ScopeId(0): ["Foo"]
Symbol reference IDs mismatch for "Foo":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)]
rebuilt : SymbolId(0): [ReferenceId(0)]
Reference symbol mismatch for "_x":
after transform: SymbolId(1) "_x"
rebuilt : <None>
Reference flags mismatch for "_x":
after transform: ReferenceId(2): ReferenceFlags(Read | Write)
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(1): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand All @@ -174,14 +162,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Foo", "_x"]
rebuilt : ScopeId(0): ["Foo"]
Symbol reference IDs mismatch for "Foo":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1)]
rebuilt : SymbolId(0): [ReferenceId(0)]
Reference symbol mismatch for "_x":
after transform: SymbolId(1) "_x"
rebuilt : <None>
Reference flags mismatch for "_x":
after transform: ReferenceId(2): ReferenceFlags(Read | Write)
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(1): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand All @@ -191,20 +176,17 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "_x", "_y"]
rebuilt : ScopeId(0): ["A"]
Symbol reference IDs mismatch for "A":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2)]
rebuilt : SymbolId(0): []
Reference symbol mismatch for "_x":
after transform: SymbolId(1) "_x"
rebuilt : <None>
Reference flags mismatch for "_x":
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
after transform: ReferenceId(0): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(0): ReferenceFlags(Write)
Reference symbol mismatch for "_y":
after transform: SymbolId(2) "_y"
rebuilt : <None>
Reference flags mismatch for "_y":
after transform: ReferenceId(3): ReferenceFlags(Read | Write)
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(1): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand Down Expand Up @@ -516,14 +498,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "_bar", "_classPrivateFieldInitSpec", "_foo"]
rebuilt : ScopeId(0): ["A", "_classPrivateFieldInitSpec", "_foo"]
Symbol reference IDs mismatch for "A":
after transform: SymbolId(0): [ReferenceId(3)]
rebuilt : SymbolId(2): []
Reference symbol mismatch for "_bar":
after transform: SymbolId(3) "_bar"
rebuilt : <None>
Reference flags mismatch for "_bar":
after transform: ReferenceId(4): ReferenceFlags(Read | Write)
after transform: ReferenceId(3): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(4): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: ["WeakMap", "foo", "require"]
Expand All @@ -533,14 +512,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "_bar", "_classPrivateFieldInitSpec", "_foo"]
rebuilt : ScopeId(0): ["A", "_classPrivateFieldInitSpec", "_foo"]
Symbol reference IDs mismatch for "A":
after transform: SymbolId(0): [ReferenceId(3)]
rebuilt : SymbolId(2): []
Reference symbol mismatch for "_bar":
after transform: SymbolId(3) "_bar"
rebuilt : <None>
Reference flags mismatch for "_bar":
after transform: ReferenceId(4): ReferenceFlags(Read | Write)
after transform: ReferenceId(3): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(4): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: ["WeakMap", "foo", "require"]
Expand All @@ -550,14 +526,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "_bar", "_classPrivateFieldInitSpec", "_foo"]
rebuilt : ScopeId(0): ["A", "_classPrivateFieldInitSpec", "_foo"]
Symbol reference IDs mismatch for "A":
after transform: SymbolId(0): [ReferenceId(3)]
rebuilt : SymbolId(2): []
Reference symbol mismatch for "_bar":
after transform: SymbolId(3) "_bar"
rebuilt : <None>
Reference flags mismatch for "_bar":
after transform: ReferenceId(4): ReferenceFlags(Read | Write)
after transform: ReferenceId(3): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(4): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: ["WeakMap", "foo", "require"]
Expand All @@ -567,14 +540,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/estree/class-private-pr
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "_bar", "_classPrivateFieldInitSpec", "_foo", "_qux"]
rebuilt : ScopeId(0): ["A", "_classPrivateFieldInitSpec", "_foo", "_qux"]
Symbol reference IDs mismatch for "A":
after transform: SymbolId(0): [ReferenceId(4)]
rebuilt : SymbolId(3): []
Reference symbol mismatch for "_bar":
after transform: SymbolId(3) "_bar"
rebuilt : <None>
Reference flags mismatch for "_bar":
after transform: ReferenceId(5): ReferenceFlags(Read | Write)
after transform: ReferenceId(4): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(7): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: ["Array", "WeakMap", "foo", "require"]
Expand Down Expand Up @@ -1074,20 +1044,17 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/privat
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "_x", "_y"]
rebuilt : ScopeId(0): ["A"]
Symbol reference IDs mismatch for "A":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2)]
rebuilt : SymbolId(0): []
Reference symbol mismatch for "_x":
after transform: SymbolId(1) "_x"
rebuilt : <None>
Reference flags mismatch for "_x":
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
after transform: ReferenceId(0): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(0): ReferenceFlags(Write)
Reference symbol mismatch for "_y":
after transform: SymbolId(2) "_y"
rebuilt : <None>
Reference flags mismatch for "_y":
after transform: ReferenceId(3): ReferenceFlags(Read | Write)
after transform: ReferenceId(1): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(1): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand All @@ -1114,14 +1081,11 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/static
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A", "_asyncToGenerator", "_computedProp", "_defineProperty", "_prop"]
rebuilt : ScopeId(0): ["A", "_asyncToGenerator", "_computedProp", "_defineProperty"]
Symbol reference IDs mismatch for "A":
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(4)]
rebuilt : SymbolId(3): [ReferenceId(3), ReferenceId(6)]
Reference symbol mismatch for "_prop":
after transform: SymbolId(2) "_prop"
rebuilt : <None>
Reference flags mismatch for "_prop":
after transform: ReferenceId(3): ReferenceFlags(Read | Write)
after transform: ReferenceId(2): ReferenceFlags(Read | Write)
rebuilt : ReferenceId(4): ReferenceFlags(Write)
Unresolved references mismatch:
after transform: []
Expand Down
Loading

0 comments on commit 371b428

Please sign in to comment.