Skip to content
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

Merged
merged 4 commits into from May 23, 2019
Merged

Allow JS with isolated modules #31483

merged 4 commits into from May 23, 2019

Conversation

sandersn
Copy link
Member

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

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.
@sandersn
Copy link
Member Author

@RyanCavanaugh You might have opinions about the new error wording.

{
"compilerOptions": {
"allowJs": true,
"noEmit": true,
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll try it.

Copy link
Member Author

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.

@sandersn sandersn merged commit 4d27361 into master May 23, 2019
@sandersn sandersn deleted the allow-js-in-isolatedmodules branch May 23, 2019 18:09
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.

@ts-check for .js files with isolatedModules causes 'use strict' to error
2 participants