New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-export statements are omitted from output using @babel/plugin-transform-typescript@7.5.0 #10162
Comments
Hey @elliottsj! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Ah thanks for the report! I did want to confirm, is this only happening with the TS plugin? edit: looking at https://github.com/babel/babel/releases/tag/v7.5.0 there's a few TS PRs. I'm thinking it's from #10034, so might not be too hard of a fix cc @Wolvereness? @airato I would pin to the TS plugin to 7.4.5 for now, apologies! |
Yes, I've only noticed this issue with the TS plugin. Pinned to 7.4.5 for now. Thanks! |
I'm having the same problem |
I just stepped through this after running into the same issue and I can confirm that 8d492b1 is the issue. The only change to that part of the code since v7.4.5 was that particular commit. |
I noticed that all my default exports were missing.
with
with
@Wolvereness related to a6392bd |
@Wolvereness Hi I just figure out a quick fix of this issue and it works well on my cases. Are you also working on a fix? If so I would leave it as-is and stop here. diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js
index a768907a5..79ca00102 100644
--- a/packages/babel-plugin-transform-typescript/src/index.js
+++ b/packages/babel-plugin-transform-typescript/src/index.js
@@ -98,9 +98,10 @@ export default declare(
ExportNamedDeclaration(path) {
// remove export declaration if it's exporting only types
if (
+ !path.node.source &&
path.node.specifiers.length > 0 &&
!path.node.specifiers.find(exportSpecifier =>
- path.scope.hasOwnBinding(exportSpecifier.local.name),
+ path.scope.hasBinding(exportSpecifier.local.name),
)
) {
path.remove();
@@ -109,7 +110,10 @@ export default declare(
ExportSpecifier(path) {
// remove type exports
- if (!path.scope.hasOwnBinding(path.node.local.name)) {
+ if (
+ !path.parent.source &&
+ !path.scope.hasBinding(path.node.local.name)
+ ) {
path.remove();
}
},
@@ -118,7 +122,7 @@ export default declare(
// remove whole declaration if it's exporting a TS type
if (
t.isIdentifier(path.node.declaration) &&
- !path.scope.hasOwnBinding(path.node.declaration.name)
+ !path.scope.hasBinding(path.node.declaration.name)
) {
path.remove();
}
|
Edit: was told I may have messed up the tests - updated with reruns, and this is only bff79e1 (fix commit):
bff79e1~1:
8d492b1 (my rewrite commit):
8d492b1~1:
2080042 No change from parent:
2080042~1
@pixelass - Your issue is probably unrelated based on these tests. |
pointless annoying conventional commit messages restrictions....... 🤬 Restrict `@babel/plugin-transform-typescript` to v7.4.x see babel/babel#10162
This issue seems still exists in v7.5.1. |
In my case: |
@qiqiboy @JoshRobertson Can you share your code? |
sample repo here: https://github.com/JoshRobertson/babel-typescript-issue |
@JoshRobertson Babel can't handle re-exports of TypeScript types, since we don't do cross-file analysis and by looking at this code: export { Avatar, AvatarProps } from "./Avatar"; it's impossible to know that Since usages of If you want to make that warning go away, you can "hint" Babel that export { Avatar } from "./Avatar";
import { AvatarProps as Props } from "./Avatar";
export type AvatarProps = Props; |
{
"plugins": ["react-hot-loader/babel", "@babel/plugin-transform-typescript"]
} Input: export defualt 'Foo'; Output: const _default = 'Foo';
; // what??? May this is related with |
Yes, it is a problem with Would you be willing to open a PR to that package (or open an issue)? |
So that stuff was there for years, and everybody was just lucky :) |
If someone could verify gaearon/react-hot-loader#1293 with a patch @nicolo-ribaudo proposed - I'll issue a new version of React-Hot-Loader. |
Seems to be fixed for me by updating |
We just released Babel 7.5.2. Please check that in your lockfile it contains v7.5.2 of |
Bug Report
Current Behavior
Using
@babel/plugin-transform-typescript@7.5.0
via@babel/preset-typescript@7.3.3
, re-export statements are omitted from the transpiled output.Repro:
Note that separate import + export statements transpile properly:
Input Code
Expected behavior/code
The re-export statement should be included in the output.
Babel Configuration (.babelrc, package.json, cli command)
Environment
Babel version(s):
Node/npm version: Node v10.15.0, npm 6.9.0
OS: macOS 10.14.5
Monorepo: no
How you are using Babel: see above
The text was updated successfully, but these errors were encountered: