Skip to content

Commit

Permalink
fix: forceScope in nested reflect
Browse files Browse the repository at this point in the history
  • Loading branch information
kireevmp committed Mar 18, 2024
1 parent 65ac53b commit 3378bab
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wise-waves-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effector-swc-plugin": patch
---

Fix providing `forceScope` for nested `reflect` usage
7 changes: 6 additions & 1 deletion src/visitors/force_scope/reflect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::ops::DerefMut;

use swc_core::ecma::{ast::*, visit::VisitMut};
use swc_core::ecma::{
ast::*,
visit::{VisitMut, VisitMutWith},
};

use crate::{
constants::EffectorMethod,
Expand Down Expand Up @@ -39,6 +42,8 @@ impl ForceReflectScope {

impl VisitMut for ForceReflectScope {
fn visit_mut_call_expr(&mut self, node: &mut CallExpr) {
node.visit_mut_children_with(self);

let state = self.state.borrow();

let method = node
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/view/force_scope/reflect_nested/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "forceScope": true }
10 changes: 10 additions & 0 deletions tests/fixtures/view/force_scope/reflect_nested/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { reflect } from "@effector/reflect";

const Reflected = reflect({
view: reflect({
view: Input,
bind: { inner: $name }
}),
bind: { outer: $name },
useUnitConfig: { forceScope: false }
});
29 changes: 29 additions & 0 deletions tests/fixtures/view/force_scope/reflect_nested/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { withFactory as _effector$factory } from 'effector';
import { reflect } from "@effector/reflect";
const Reflected = _effector$factory({
sid: "dm21p9d0",
name: "Reflected",
method: "reflect",
fn: ()=>reflect({
view: _effector$factory({
sid: "atcsv5is",
name: "view",
method: "reflect",
fn: ()=>reflect({
view: Input,
bind: {
inner: $name
},
useUnitConfig: {
forceScope: true
}
})
}),
bind: {
outer: $name
},
useUnitConfig: {
forceScope: false
}
})
});

0 comments on commit 3378bab

Please sign in to comment.