Skip to content

Add section "return multiple nodes"#4

Merged
itsdouges merged 6 commits intoitsdouges:masterfrom
bendtherules:return-multiple-nodes
Jan 3, 2020
Merged

Add section "return multiple nodes"#4
itsdouges merged 6 commits intoitsdouges:masterfrom
bendtherules:return-multiple-nodes

Conversation

@bendtherules
Copy link
Copy Markdown
Contributor

@bendtherules bendtherules commented Jan 3, 2020

Part of #2.
Added doc and example.

@bendtherules bendtherules changed the title return-multiple-node - Add example to duplicate statements return-multiple-node - Add example to duplicate expression statements Jan 3, 2020
@bendtherules bendtherules changed the title return-multiple-node - Add example to duplicate expression statements Add section "return multiple nodes" Jan 3, 2020
// If it is a expression statement,
if (ts.isExpressionStatement(node)) {
// Clone it
const newNode = ts.getMutableClone(node);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

watch out for this - ts-loader doesn't play nicely (theres a section at the bottom of the handbook that mentions this). only found this out yesterday hehe

could you re-do this with either updateExpressionStatement or just returning the node twice?

[node, node]

@itsdouges
Copy link
Copy Markdown
Owner

love it, just the one comment

@bendtherules
Copy link
Copy Markdown
Contributor Author

Done.

I hope ts-loader supports it well in the future. Although it works here, little concerned with moving a node around without cloning as it contains reference to its position in the source file and such.

@itsdouges itsdouges merged commit da6b0bd into itsdouges:master Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants