Skip to content

Commit

Permalink
Merge pull request #26 from effector/fix/support-chaining
Browse files Browse the repository at this point in the history
Propagate `name` when chaining methods
  • Loading branch information
kireevmp authored Nov 1, 2024
2 parents 6d2501e + b18c9d4 commit 8ef0fe5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-seahorses-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effector/swc-plugin": patch
---

Fix propagating `name` when chaining methods (issue #25)
16 changes: 9 additions & 7 deletions src/visitors/sid/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::rc::Rc;

use swc_core::{
common::{sync::Lrc, SourceMapper},
common::{SourceMapper, sync::Lrc},
ecma::{
ast::*,
atoms::JsWord,
utils::private_ident,
visit::{noop_visit_mut_type, VisitMut, VisitMutWith},
visit::{VisitMut, VisitMutWith, noop_visit_mut_type},
},
quote,
};
Expand All @@ -16,11 +16,11 @@ use self::{
method::MethodTransformer,
};
use crate::{
Config,
constants::EffectorMethod,
state::EffectorImport,
utils::{to_domain_method, to_method, TryKeyOf},
utils::{TryKeyOf, to_domain_method, to_method},
visitors::{MutableState, VisitorMeta},
Config,
};

mod call_identity;
Expand Down Expand Up @@ -185,9 +185,11 @@ impl VisitMut for UnitIdentifier {
}

fn visit_mut_call_expr(&mut self, node: &mut CallExpr) {
// 'consume' name information, so that nested nodes
// don't infer their names from far above
self.visit_stacked(None, node);
// CallExpr -> callee do infer `name`
node.callee.visit_mut_children_with(self);

// CallExpr -> args do not inherit the name
self.visit_stacked(None, &mut node.args);

self.transform_method(node);
self.transform_factory(node);
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/store/chaining/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions tests/fixtures/store/chaining/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createEvent, createStore } from 'effector';

const event = createEvent();
const $store = createStore(0).on(event, (_, value) => value);
9 changes: 9 additions & 0 deletions tests/fixtures/store/chaining/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createEvent, createStore } from 'effector';
const event = createEvent({
sid: "3g0kdzwe",
name: "event"
});
const $store = createStore(0, {
sid: "cjscsjrm",
name: "$store"
}).on(event, (_, value)=>value);

0 comments on commit 8ef0fe5

Please sign in to comment.