Skip to content

Commit 4f1b406

Browse files
authored
Merge pull request #1 from simonkberg/fix/import-map
Map non-default named exports to the correct file
2 parents 2cbe1b9 + 3574c8c commit 4f1b406

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

source/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
export default function ({types: t}) {
2+
const namespace = 'react-router/lib'
3+
const importMap = {
4+
createRoutes: 'RouteUtils',
5+
locationShape: 'PropTypes',
6+
routerShape: 'PropTypes',
7+
formatPattern: 'PatternUtils'
8+
}
9+
210
const canReplace = ({ specifiers }) => {
311
return specifiers.length > 0 && specifiers.every((specifier) => {
412
return t.isImportSpecifier(specifier)
@@ -8,9 +16,18 @@ export default function ({types: t}) {
816

917
const replace = (specifiers) => {
1018
return specifiers.map(({local, imported}) => {
19+
const mapped = importMap[imported.name]
20+
21+
if (typeof mapped !== 'undefined') {
22+
return t.importDeclaration(
23+
[t.importSpecifier(local, imported)],
24+
t.stringLiteral(`${namespace}/${mapped}`)
25+
);
26+
}
27+
1128
return t.importDeclaration(
12-
[t.importDefaultSpecifier(t.identifier(local.name))],
13-
t.stringLiteral(`react-router/lib/${imported.name}`)
29+
[t.importDefaultSpecifier(local)],
30+
t.stringLiteral(`${namespace}/${imported.name}`)
1431
);
1532
});
1633
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { createRoutes, locationShape, routerShape } from 'react-router';
2+
import { formatPattern as format } from 'react-router';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createRoutes } from 'react-router/lib/RouteUtils';
2+
import { locationShape } from 'react-router/lib/PropTypes';
3+
import { routerShape } from 'react-router/lib/PropTypes';
4+
import { formatPattern as format } from 'react-router/lib/PatternUtils';

0 commit comments

Comments
 (0)