-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Better error messages when Babel fails to parse import = and export =… #7079
Conversation
… syntax from typescript when using babel-plugin-transform-typescript
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6288/ |
Can you run |
Sure..
|
Also, it would be better to split the message on multiple lines (lines should be no longer than 80 chars) e.g. throw buildCodeframeError(
"bla bla bla ... .... " +
"second line to make " +
"them shorter"
); |
On its way.. :)
…On Thu, Dec 21, 2017 at 3:09 AM, Nicolò Ribaudo ***@***.***> wrote:
Also, it would be better to split the message on multiple lines (lines
should be no longer than 80 chars)
e.g.
throw buildCodeframeError(
"bla bla bla ... .... " +
"second line to make " +
"them shorter"
);
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#7079 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFYnVl6XdpEtH1hFku5a7a-wszcDjiZnks5tCX6igaJpZM4RI9ub>
.
|
@@ -205,11 +205,19 @@ export default function() { | |||
}, | |||
|
|||
TSImportEqualsDeclaration(path) { | |||
throw path.buildCodeFrameError("`import =` is not supported."); | |||
throw path.buildCodeFrameError( | |||
"`import =` is not supported in Babel's Typescript parser " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use plugin
instead of parser
, since it is parsed correctly but not transformed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not. Because If you don't use any plugins. It breaks still..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe is not supported by @babel/plugin-transform-typescript
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not. Because If you don't use any plugins. It breaks still..
If you don' transform it, it works. https://runkit.com/embed/bsijdhpw0mq9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure either. I wish Babel could parse this to "importdeclaration = Identifier"
I could write codemod to migrate all our legacyJS files to TS. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's go with is not supported by @babel/plugin-transform-typescript
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.. On its way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish Babel could parse this to "importdeclaration = Identifier"
I could write codemod to migrate all our legacyJS files to TS. :)
Just use import identifier from "module"
😛
import =
is only kept for backward compatibility, so it is "legacyTS" https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#1133-import-require-declarations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright Just a grammar review here before I add
throw path.buildCodeFrameError(
"`import =` is not supported by @babel/plugin-transform-typescript \n" +
"Please consider using " +
"`import <moduleName> from '<moduleName>';` alongside " +
"Typescript's --allowSyntheticDefaultImports option.",
);
throw path.buildCodeFrameError("`export =` is not supported."); | ||
throw path.buildCodeFrameError( | ||
"`export =` is not supported in Babel's Typescript parser because " + | ||
"there is no valid ES6 implementation for it.\nPlease consider using `export <value>;`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't export =
more like export default <value>
than export <value>
? (I don't use TS very much, so I'm not sure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Basically you could only export one object earlier. Now support
export default <value>
& export <value>
@@ -205,11 +205,19 @@ export default function() { | |||
}, | |||
|
|||
TSImportEqualsDeclaration(path) { | |||
throw path.buildCodeFrameError("`import =` is not supported."); | |||
throw path.buildCodeFrameError( | |||
"`import =` is not supported by @babel/plugin-transform-typescript \n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the trailing space (the other message is ok)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolo-ribaudo it was there earlier too. If I remove it on terminal the words look very closely attached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I meant before \n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Yaaaaay.. Cannot express how glad I am.. :) |
@gs-akhan This just need another approval, than can be merged 🙂 |
… syntax from typescript when using babel-plugin-transform-typescript
The error messages displayed when Typescript's
import =
andexport =
were very less descriptive. Giving users no clue about what to do next..Hence this messages can improve things regarding on how to fix their imports and exports in Typescript.
Detailed discussion can be found at
#7062
#7067
Thanks