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 JS with isolated modules #31483
Conversation
Previously legacy JS code was not allowed; it was required to use ES6 module syntax. Unfortunately, the check happens after parsing but before binding, and the commonjs module indicator isn't set until binding because it's not syntactically simple like the ES6 module indicator, which is set during parsing. So I decided that JS should be allowed during isolatedModules unconditionally. We're not going to be transforming it anyway.
@RyanCavanaugh You might have opinions about the new error wording. |
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"noEmit": true, |
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.
What happens when noEmit
is false
?
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.
error saying that you can't overwrite index.js. The real example of this is from babel pipelines, where we recommended people use isolatedModules, so they use babel for emit, not 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.
But you could change it to emit into the outDir
right? Would it affect in some way the emit that could happen?
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'll try it.
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 shouldn't affect emit because we're not transforming js as far as I know. I pushed a commit with outDir
replacing noEmit
in the test.
Previously legacy JS code was not allowed; it was required to use ES6 module syntax. Unfortunately, the check happens after parsing but before binding, and the commonjs module indicator isn't set until binding because it's not syntactically simple like the ES6 module indicator, which is set during parsing.
So I decided that JS should be allowed during isolatedModules unconditionally. We're not going to be transforming it anyway.
I also improved the error message, which mentions namespaces when most erroneous code it encounters will just be global scripts.
Fixes #29087