Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/babel/__fixtures__/rewrite-imports/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ import {
withTheme,
LightTheme,
} from 'react-native-paper';

export { TextInput } from 'react-native-paper';
1 change: 1 addition & 0 deletions src/babel/__fixtures__/rewrite-imports/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ import { Palette } from "react-native-paper/lib/module/theme/tokens";
import { NonExistent, NonExistentSecond as Stuff, LightTheme } from "react-native-paper/lib/module/index.js";
import { ThemeProvider } from "react-native-paper/lib/module/core/theming";
import { withTheme } from "react-native-paper/lib/module/core/theming";
export { default as TextInput } from "react-native-paper/lib/module/components/TextInput";
64 changes: 64 additions & 0 deletions src/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,70 @@ module.exports = function rewire(babel, options) {
}, [])
);

path.requeue();
},
ExportNamedDeclaration(path) {
if (
!path.node.source ||
path.node.source.value !== name ||
path.node[SKIP]
) {
return;
}

path.node.source.value = `${name}/${index}`;
path.replaceWithMultiple(
path.node.specifiers.reduce((declarations, specifier) => {
const mapping = mappings[specifier.local.name];
Comment on lines +72 to +73

if (mapping) {
const alias = `${name}/${mapping.path}`;
let s;

switch (mapping.name) {
case 'default':
s = t.exportSpecifier(
t.identifier('default'),
t.identifier(specifier.exported.name)
);
break;
case '*':
s = t.exportNamespaceSpecifier(
t.identifier(specifier.exported.name)
);
break;
default:
s = t.exportSpecifier(
t.identifier(mapping.name),
t.identifier(specifier.exported.name)
);
}

declarations.push(
t.exportNamedDeclaration(null, [s], t.stringLiteral(alias))
);
} else {
const previous = declarations.find(
(d) => d.source.value === path.node.source.value
);

if (previous) {
previous.specifiers.push(specifier);
} else {
const node = t.exportNamedDeclaration(
null,
[specifier],
path.node.source
);
node[SKIP] = true;
declarations.push(node);
}
}

return declarations;
}, [])
);
Comment on lines +71 to +121

path.requeue();
},
},
Expand Down