From 8aa6447d270469a08cf579be20528b6118f08459 Mon Sep 17 00:00:00 2001 From: Deepak kudi Date: Thu, 4 Jun 2026 09:56:42 +0530 Subject: [PATCH] fix: rewrite paper re-exports in babel plugin --- .../__fixtures__/rewrite-imports/code.js | 2 + .../__fixtures__/rewrite-imports/output.js | 1 + src/babel/index.js | 64 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/src/babel/__fixtures__/rewrite-imports/code.js b/src/babel/__fixtures__/rewrite-imports/code.js index f1253a5e08..1f086dddb1 100644 --- a/src/babel/__fixtures__/rewrite-imports/code.js +++ b/src/babel/__fixtures__/rewrite-imports/code.js @@ -12,3 +12,5 @@ import { withTheme, LightTheme, } from 'react-native-paper'; + +export { TextInput } from 'react-native-paper'; diff --git a/src/babel/__fixtures__/rewrite-imports/output.js b/src/babel/__fixtures__/rewrite-imports/output.js index bbe342ad0d..816199d92e 100644 --- a/src/babel/__fixtures__/rewrite-imports/output.js +++ b/src/babel/__fixtures__/rewrite-imports/output.js @@ -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"; diff --git a/src/babel/index.js b/src/babel/index.js index f93f07e01e..9f5182fe8b 100644 --- a/src/babel/index.js +++ b/src/babel/index.js @@ -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]; + + 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; + }, []) + ); + path.requeue(); }, },