Skip to content

fix: rewrite paper re-exports in babel plugin#4969

Open
puneetdixit200 wants to merge 1 commit into
callstack:mainfrom
puneetdixit200:fix-babel-reexport-rewrite
Open

fix: rewrite paper re-exports in babel plugin#4969
puneetdixit200 wants to merge 1 commit into
callstack:mainfrom
puneetdixit200:fix-babel-reexport-rewrite

Conversation

@puneetdixit200
Copy link
Copy Markdown

Motivation

The Babel plugin rewrites imports from react-native-paper to component-specific paths, but it currently leaves re-exports unchanged. That means a barrel like:

export { TextInput } from 'react-native-paper';

still points at the package root instead of the mapped component path.

This adds the same mapping behavior for named re-exports while preserving unmapped symbols on the generated index path.

Related issue

Fixes #4874

Test plan

  • yarn test src/babel/__tests__/index.js --runInBand
  • yarn eslint src/babel/index.js src/babel/__tests__/index.js --max-warnings=0
  • git diff --check
  • Pre-commit hook full Jest run: 55 suites passed, 738 tests passed, 1 skipped

Copilot AI review requested due to automatic review settings June 4, 2026 04:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support to the Babel “rewire” transform to rewrite export { ... } from '<pkg>' re-exports (not just import ... from '<pkg>') into the appropriate deep export paths based on the existing mappings.

Changes:

  • Add an ExportNamedDeclaration visitor that rewrites re-exports from the configured package to mapped deep paths or the package index.
  • Preserve/export-alias semantics for mapped exports (including default / namespace cases).
  • Update rewrite-imports fixtures to cover a re-export case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/babel/index.js Adds re-export rewriting logic for ExportNamedDeclaration nodes.
src/babel/fixtures/rewrite-imports/code.js Adds an input example that re-exports TextInput from the package.
src/babel/fixtures/rewrite-imports/output.js Updates expected output to a deep re-export (default as TextInput).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/babel/index.js
Comment on lines +72 to +73
path.node.specifiers.reduce((declarations, specifier) => {
const mapping = mappings[specifier.local.name];
Comment thread src/babel/index.js
path.node.source.value = `${name}/${index}`;
path.replaceWithMultiple(
path.node.specifiers.reduce((declarations, specifier) => {
const mapping = mappings[specifier.local.name];
Comment thread src/babel/index.js
case 'default':
s = t.exportSpecifier(
t.identifier('default'),
t.identifier(specifier.exported.name)
Comment thread src/babel/index.js
default:
s = t.exportSpecifier(
t.identifier(mapping.name),
t.identifier(specifier.exported.name)
Comment thread src/babel/index.js
Comment on lines +71 to +121
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;
}, [])
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

babel plugin does not handle re-exports, causes incorrect theming

2 participants