Skip to content

Commit 1d080da

Browse files
author
Chris Garrett
committed
wip
1 parent 45bdb10 commit 1d080da

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/colocated-babel-plugin.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
function registerRefs(newPath, getRefPaths) {
2+
if (Array.isArray(newPath)) {
3+
if (newPath.length > 1) {
4+
throw new Error(
5+
'registerRefs is only meant to handle single node transformations. Received more than one path node.'
6+
);
7+
}
8+
9+
newPath = newPath[0];
10+
}
11+
12+
let refPaths = getRefPaths(newPath);
13+
14+
for (let ref of refPaths) {
15+
let binding = ref.scope.getBinding(ref.node.name);
16+
if (binding !== undefined) {
17+
binding.reference(ref);
18+
}
19+
}
20+
}
21+
22+
123
// For ease of debuggin / tweaking:
224
// https://astexplorer.net/#/gist/bcca584efdab6c981a75618642c76a22/1e1d262eaeb47b7da66150e0781a02b96e597b25
325
module.exports = function (babel) {
@@ -39,7 +61,7 @@ module.exports = function (babel) {
3961
.find(({ node }) => {
4062
return exportName === 'default'
4163
? t.isImportDefaultSpecifier(node)
42-
: node.imported.name === exportName;
64+
: node.imported && node.imported.name === exportName;
4365
});
4466

4567
if (importSpecifier) {

0 commit comments

Comments
 (0)