-
-
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
Allow sourceType:unambiguous as a way to tell Babylon to guess the type. #6789
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5763/ |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5740/ |
Should add a readme change for the new option? @bmeck @Kovensky |
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.
looks good, probably want a doc change in a few places
(!child.exportKind || child.exportKind === "value")) || | ||
child.type === "ExportDefaultDeclaration", | ||
); | ||
} |
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.
👆 Neat! (I might borrow this helper)
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.
Yeah this is basically to stay in line with babel/babylon#771 since Flowtype just indiscriminately allows mixing ES6 import/export and CommonJS and it seems fine to allow type import/export inside sourceType:script
files.
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.
@loganfsmyth Who made your avatar!?
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.
Got it from Matt Cummings. His commissions are open again: https://twitter.com/EiffelArt/status/928017289416495105
} catch (scriptError) {} | ||
|
||
throw moduleError; | ||
} |
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.
👆 This aligns with my approach as well.
) { | ||
throw new Error( | ||
`.${key} must be "module", "script", "unambiguous", or undefined`, | ||
); |
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.
The alphabetical listing of these sourceTypes in the error text is satisfying!
@@ -91,3 +111,16 @@ function getParserClass( | |||
} | |||
return cls; | |||
} | |||
|
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.
Could hasModuleSyntax
be simplified?
Is there ever a child.type
of ImportDeclaration
and friends
that don't have the accompanying importKind
and exportKind
values?
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 believe when the flow
parsing isn't enabled, they aren't set.
Repost of babel/babylon#449. Also added tweaks to option parsing so that the option passes through properly.