From 0a7e246273e821be2a2f5dc3ce93c3329f85e608 Mon Sep 17 00:00:00 2001 From: Christian Mortaro Date: Wed, 12 Jul 2023 22:39:58 -0300 Subject: [PATCH 1/2] :bug: fix inner components as props --- package.json | 2 +- .../inject_inner_components_to_class.rs | 1 + src/tests/inject_inner_components_to_class.rs | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ceed464..9504fe6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swc-plugin-nullstack", - "version": "0.1.3", + "version": "0.1.4", "description": "SWC plugin for Nullstack", "main": "./dist/swc-plugin-nullstack.wasm", "author": "Mortaro", diff --git a/src/loaders/inject_inner_components_to_class.rs b/src/loaders/inject_inner_components_to_class.rs index 64010e9..94991fb 100644 --- a/src/loaders/inject_inner_components_to_class.rs +++ b/src/loaders/inject_inner_components_to_class.rs @@ -160,6 +160,7 @@ impl VisitMut for InjectInnerComponentVisitor { self.is_inside_tag = true; n.name.visit_mut_children_with(self); self.is_inside_tag = false; + n.visit_mut_children_with(self); } } diff --git a/src/tests/inject_inner_components_to_class.rs b/src/tests/inject_inner_components_to_class.rs index 61d6ccc..36066dd 100644 --- a/src/tests/inject_inner_components_to_class.rs +++ b/src/tests/inject_inner_components_to_class.rs @@ -590,4 +590,29 @@ test!( } } "# +); + +test!( + syntax(), + |_| tr(InjectInnerComponentVisitor::default()), + inject_inner_components_when_passed_as_props, + r#" + const OtherComponent = () => {} + class Component { + renderInnerComponent() { return false } + render() { + return } /> + } + } + "#, + r#" + const OtherComponent = () => {} + class Component { + renderInnerComponent() { return false } + render() { + const InnerComponent = this.renderInnerComponent + return } /> + } + } + "# ); \ No newline at end of file From f5bc6f2a79b91789679eb1c1b900ffe9a0c31ac7 Mon Sep 17 00:00:00 2001 From: Christian Mortaro Date: Wed, 12 Jul 2023 22:41:18 -0300 Subject: [PATCH 2/2] :bug: fix inner components as props --- src/tests/inject_inner_components_to_class.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tests/inject_inner_components_to_class.rs b/src/tests/inject_inner_components_to_class.rs index 36066dd..39ef39a 100644 --- a/src/tests/inject_inner_components_to_class.rs +++ b/src/tests/inject_inner_components_to_class.rs @@ -615,4 +615,26 @@ test!( } } "# +); + +test!( + syntax(), + |_| tr(InjectInnerComponentVisitor::default()), + skip_inject_inner_components_when_passed_as_props_that_should_be_regular_constant, + r#" + const OtherComponent = () => {} + class Component { + render() { + return + } + } + "#, + r#" + const OtherComponent = () => {} + class Component { + render() { + return + } + } + "# ); \ No newline at end of file