Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Mar 17, 2021
1 parent 45bdb10 commit 1d080da
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/colocated-babel-plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
function registerRefs(newPath, getRefPaths) {
if (Array.isArray(newPath)) {
if (newPath.length > 1) {
throw new Error(
'registerRefs is only meant to handle single node transformations. Received more than one path node.'
);
}

newPath = newPath[0];
}

let refPaths = getRefPaths(newPath);

for (let ref of refPaths) {
let binding = ref.scope.getBinding(ref.node.name);
if (binding !== undefined) {
binding.reference(ref);
}
}
}


// For ease of debuggin / tweaking:
// https://astexplorer.net/#/gist/bcca584efdab6c981a75618642c76a22/1e1d262eaeb47b7da66150e0781a02b96e597b25
module.exports = function (babel) {
Expand Down Expand Up @@ -39,7 +61,7 @@ module.exports = function (babel) {
.find(({ node }) => {
return exportName === 'default'
? t.isImportDefaultSpecifier(node)
: node.imported.name === exportName;
: node.imported && node.imported.name === exportName;
});

if (importSpecifier) {
Expand Down

0 comments on commit 1d080da

Please sign in to comment.