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 providing forceScope for nested reflect #17

Merged
merged 1 commit into from
Mar 18, 2024
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
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
}
})
});