Skip to content

Commit

Permalink
fix(transformer/react): refresh plugin has incorrect reference flags (#…
Browse files Browse the repository at this point in the history
…5656)

As you see the diff
  • Loading branch information
Dunqing committed Sep 11, 2024
1 parent ffbc462 commit a891c31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 71 deletions.
11 changes: 8 additions & 3 deletions crates/oxc_transformer/src/react/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,13 @@ impl<'a> ReactRefresh<'a> {
fn create_registration(
&mut self,
persistent_id: Atom<'a>,
reference_flags: ReferenceFlags,
ctx: &mut TraverseCtx<'a>,
) -> AssignmentTarget<'a> {
let symbol_id = ctx.generate_uid_in_root_scope("c", SymbolFlags::FunctionScopedVariable);
self.registrations.push((symbol_id, persistent_id));
let name = ctx.ast.atom(ctx.symbols().get_name(symbol_id));
let ident = ctx.create_reference_id(SPAN, name, Some(symbol_id), ReferenceFlags::Write);
let ident = ctx.create_reference_id(SPAN, name, Some(symbol_id), reference_flags);
let ident = ctx.ast.simple_assignment_target_from_identifier_reference(ident);
ctx.ast.assignment_target_simple(ident)
}
Expand Down Expand Up @@ -557,7 +558,11 @@ impl<'a> ReactRefresh<'a> {
*expr = ctx.ast.expression_assignment(
SPAN,
AssignmentOperator::Assign,
self.create_registration(ctx.ast.atom(inferred_name), ctx),
self.create_registration(
ctx.ast.atom(inferred_name),
ReferenceFlags::read_write(),
ctx,
),
ctx.ast.move_expression(expr),
);
}
Expand All @@ -584,7 +589,7 @@ impl<'a> ReactRefresh<'a> {
id: &BindingIdentifier<'a>,
ctx: &mut TraverseCtx<'a>,
) -> Statement<'a> {
let left = self.create_registration(id.name.clone(), ctx);
let left = self.create_registration(id.name.clone(), ReferenceFlags::Write, ctx);
let right = ctx.create_bound_reference_id(
SPAN,
id.name.clone(),
Expand Down
70 changes: 2 additions & 68 deletions tasks/transform_conformance/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 3bcfee23

Passed: 32/52
Passed: 38/52

# All Passed:
* babel-plugin-transform-nullish-coalescing-operator
Expand Down Expand Up @@ -167,12 +167,7 @@ rebuilt : SymbolId(2): []
x Output mismatch


# babel-plugin-transform-react-jsx (18/30)
* refresh/can-handle-implicit-arrow-returns/input.jsx
Reference flags mismatch:
after transform: ReferenceId(18): ReferenceFlags(Write)
rebuilt : ReferenceId(31): ReferenceFlags(Read | Write)

# babel-plugin-transform-react-jsx (24/30)
* refresh/does-not-get-tripped-by-iifes/input.jsx
Bindings mismatch:
after transform: ScopeId(0): []
Expand All @@ -187,20 +182,6 @@ rebuilt : SymbolId(0): ScopeId(0)
* refresh/does-not-transform-it-because-it-is-not-used-in-the-AST/input.jsx
x Output mismatch

* refresh/generates-signatures-for-function-expressions-calling-hooks/input.jsx
Reference flags mismatch:
after transform: ReferenceId(18): ReferenceFlags(Write)
rebuilt : ReferenceId(4): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(17): ReferenceFlags(Write)
rebuilt : ReferenceId(7): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(22): ReferenceFlags(Write)
rebuilt : ReferenceId(19): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(21): ReferenceFlags(Write)
rebuilt : ReferenceId(22): ReferenceFlags(Read | Write)

* refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx
Missing ScopeId
Scope children mismatch:
Expand All @@ -214,53 +195,6 @@ Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(4)]
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(5), ScopeId(6)]

* refresh/registers-capitalized-identifiers-in-hoc-calls/input.jsx
Reference flags mismatch:
after transform: ReferenceId(8): ReferenceFlags(Write)
rebuilt : ReferenceId(3): ReferenceFlags(Read | Write)

* refresh/registers-likely-hocs-with-inline-functions-1/input.jsx
Reference flags mismatch:
after transform: ReferenceId(5): ReferenceFlags(Write)
rebuilt : ReferenceId(1): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(9): ReferenceFlags(Write)
rebuilt : ReferenceId(6): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(8): ReferenceFlags(Write)
rebuilt : ReferenceId(8): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(14): ReferenceFlags(Write)
rebuilt : ReferenceId(12): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(13): ReferenceFlags(Write)
rebuilt : ReferenceId(14): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(12): ReferenceFlags(Write)
rebuilt : ReferenceId(16): ReferenceFlags(Read | Write)

* refresh/registers-likely-hocs-with-inline-functions-2/input.jsx
Reference flags mismatch:
after transform: ReferenceId(4): ReferenceFlags(Write)
rebuilt : ReferenceId(0): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Write)
rebuilt : ReferenceId(2): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(2): ReferenceFlags(Write)
rebuilt : ReferenceId(4): ReferenceFlags(Read | Write)

* refresh/registers-likely-hocs-with-inline-functions-3/input.jsx
Reference flags mismatch:
after transform: ReferenceId(4): ReferenceFlags(Write)
rebuilt : ReferenceId(0): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Write)
rebuilt : ReferenceId(2): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(2): ReferenceFlags(Write)
rebuilt : ReferenceId(4): ReferenceFlags(Read | Write)

* refresh/supports-typescript-namespace-syntax/input.tsx
x Output mismatch

Expand Down

0 comments on commit a891c31

Please sign in to comment.