@adrianhelvik/hooks.macro
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -201,7 +201,13 @@ "use strict"; | ||
Expression: function Expression(path) { | ||
if (!t.isIdentifier(path)) { | ||
var openingElement; | ||
if (t.isJSXElement(path)) { | ||
openingElement = path.node.openingElement.name; | ||
} | ||
if (!t.isIdentifier(path) && !t.isJSXElement(path)) { | ||
return; | ||
} | ||
var binding = path.scope.getBinding(path.node.name); // Reference without a binding (such as globals) are excluded | ||
var binding = path.scope.getBinding(openingElement ? openingElement.name : path.node.name); // Reference without a binding (such as globals) are excluded | ||
@@ -237,3 +243,5 @@ if (binding == null) { | ||
visitor(path); | ||
visitor(openingElement ? { | ||
node: openingElement | ||
} : path); | ||
} | ||
@@ -246,13 +254,10 @@ }); | ||
var visitedEntryNodes = []; | ||
var references = []; | ||
var references = {}; | ||
visitInputsReferences(parentPath, createPath, babel, visitedEntryNodes, function (_ref) { | ||
var node = _ref.node; | ||
if (!references.some(function (reference) { | ||
return reference.name === node.name; | ||
})) { | ||
references.push(node); | ||
} | ||
references[node.name] = true; | ||
}); | ||
parentPath.replaceWith(t.callExpression(importedHookName, [createPath.node, t.arrayExpression(references)])); | ||
parentPath.replaceWith(t.callExpression(importedHookName, [createPath.node, t.arrayExpression(Object.keys(references).map(function (name) { | ||
return t.identifier(name); | ||
}))])); | ||
} | ||
@@ -259,0 +264,0 @@ |
{ | ||
"name": "@adrianhelvik/hooks.macro", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"author": "Pier Paolo Ramon <ramonpierre@gmail.com>, Adrian Helvik <adrianhelvik100@gmail.com>", | ||
@@ -5,0 +5,0 @@ "main": "build/hooks.macro.js", |
25199
303