Skip to content

Commit

Permalink
Make use of __Node__ import and resolve it
Browse files Browse the repository at this point in the history
  • Loading branch information
aboeglin committed Jun 29, 2020
1 parent 48f81a4 commit f73f24d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-snake-render-engine",
"version": "1.0.0-alpha-1",
"version": "1.0.0-alpha-2",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
10 changes: 6 additions & 4 deletions src/fixtures/node/output.js
@@ -1,7 +1,9 @@
import SRE from "snake-render-engine";
const SomeNode = Node(props => {});
const MyNode = Node(() => {});
import SRE, { __Node__ } from "snake-render-engine";

const SomeNode = __Node__(props => {});

const MyNode = __Node__(() => {});

const fn = () => {
const OtherNode = Node(() => {});
const OtherNode = __Node__(() => {});
};
4 changes: 3 additions & 1 deletion src/index.js
@@ -1,4 +1,5 @@
const SRE_PKG_NAME = "snake-render-engine";
const NODE_FUNCTION = "__Node__";

let isImported = false;

Expand All @@ -11,13 +12,14 @@ module.exports = ({ types: t }) => ({
isCapitalized(path.parent.id.name) &&
isImported
) {
const out = t.callExpression(t.identifier("Node"), [path.parent.init]);
const out = t.callExpression(t.identifier(NODE_FUNCTION), [path.parent.init]);
path.replaceWith(out);
}
},
ImportDefaultSpecifier: (path) => {
if (path.parent.source.value === SRE_PKG_NAME) {
isImported = true;
path.parent.specifiers.push(t.importSpecifier(t.identifier(NODE_FUNCTION), t.identifier(NODE_FUNCTION)))
}
},
},
Expand Down

0 comments on commit f73f24d

Please sign in to comment.