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

Support modules when targeting ES6 and an ES6 ModuleKind #4811

Merged
merged 8 commits into from
Sep 24, 2015

Conversation

weswigham
Copy link
Member

#4806 and a part of #4389 refer to this change - people have been wanting to be able to disable emitting es6 module syntax when targeting es6 for awhile, and this allows them to do just that. While this could wait until we re-architect our emit for even more granular emit, even with our current emitter this wasn't a bad change to make.

Feelings about it?

@@ -76,10 +76,11 @@ namespace ts {
"amd": ModuleKind.AMD,
"system": ModuleKind.System,
"umd": ModuleKind.UMD,
"es6": ModuleKind.ES6,
Copy link
Contributor

Choose a reason for hiding this comment

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

you do not need that. just leave target as es6 and allow for additional --module flag. today we make it an error to use --target es6 with --module; relaxing this should be sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

Internally we checked for language version like it was a module kind in a number of places. Is it just a matter of not wanting to make it able to be specified explicitly?

Copy link
Contributor

Choose a reason for hiding this comment

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

we do not support target: es5 with module: es6, so why allow it and add additional burden on users.
--target es6 with no --module is implied to be es6, if another --module tareget is specified, emit should use that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, so I'm just removing it as an option for the --module command line flag.

@weswigham
Copy link
Member Author

@mhegazy anything else that I would need to look into for this? I looked through the diagnostic messages to see if we had any other features which were marked as ES6 dependent but were really ES6 module dependent, such as import foo = and export = and swapped them to depend on the module kind.

@@ -13379,9 +13379,9 @@ namespace ts {
}
}
else {
if (languageVersion >= ScriptTarget.ES6 && !isInAmbientContext(node)) {
if (compilerOptions.module === ModuleKind.ES6 && !isInAmbientContext(node)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(languageVersion >= ScriptTarget.ES6 && !compilerOptions.module), or set that at the top of the file such as language version

Copy link
Contributor

Choose a reason for hiding this comment

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

if you are adding an "es6" to module kind.

var modulekind = compilerOptions.module ?  compilerOptions.module  :  compilerOptions.target === LaguageTaret.ES6 ? ModuleKind.ES6 : ModuleKind.None.

@weswigham weswigham mentioned this pull request Sep 17, 2015
4 tasks
@@ -44,6 +44,7 @@ namespace ts {

let compilerOptions = host.getCompilerOptions();
let languageVersion = compilerOptions.target || ScriptTarget.ES3;
var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None;
Copy link
Member

Choose a reason for hiding this comment

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

s/var/let

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it would be better to remove ModuleKind.ES6, as it could be confusing to API consumers, and instead use this here:

let moduleKind = compilerOptions.module || ModuleKind.None;
let nativeModules = languageVersion >= ScriptTarget.ES6 && moduleKind === ModuleKind.None;

Then use the nativeModules boolean variable when checking below, or merely inline the expression used to compute 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.

Perhaps it would be better to remove ModuleKind.ES6, as it could be confusing to API consumers, and instead use this here

Please no. Not having ES6 as a module kind is all kinds of not forward compatible and causes odd checks which depend on there not being module kinds alongside specific language versions. Going forward, when we implement #4813 those forms of exports will not be ES6 compatible module emit, but can be compiled to ES6 compatible module emit. In effect, when we add an ES7 target and ES7 compatible module emit feature, we're going to need an ES6 module kind (and, to be consistent, hopefully an ES7 module kind!). Additionally, not having an ES6 module kind makes specifying that you want to emit an ES6 module style bundle for #4754 awkward. (Do I target ES6 but not specify module output type at all? That's oddly inconsistent.)

--module is one of our few variable feature flags at present, it's time we start treating it as such. ES6 is a kind of module emit. We should treat it as such. The module format is part of the ES6 spec, true, but nothing inherently ties the feature to the ES6 target only. Right now it seems nonsensical to ask for ES6 module syntax with a target below ES6 (since we know of 0 runtimes which support ES6 modules and yet support no other ES6 features), but we certainly could emit it.

IMO, having an ES6 module kind simplifies our API. When a module kind is set, it now controls the emit for the module format. Full stop.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 22, 2015

👍

@mhegazy
Copy link
Contributor

mhegazy commented Sep 22, 2015

can you refresh.

@weswigham
Copy link
Member Author

@mhegazy refreshed & retested.

@weswigham
Copy link
Member Author

Ping @mhegazy: do we want to merge this?

@weswigham
Copy link
Member Author

@rbuckton said he was looking for this, so I'm interpreting your 👍 as an lgtm now.

weswigham added a commit that referenced this pull request Sep 24, 2015
Support modules when targeting ES6 and an ES6 ModuleKind
@weswigham weswigham merged commit dd660dc into microsoft:master Sep 24, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Sep 25, 2015

👍

@philipbjorge
Copy link

@weswigham -- Thanks for this work. This unblocks a much better integration story between TypeScript and Ember-CLI 👍

@WangJi
Copy link

WangJi commented Oct 14, 2015

very good job.

@weswigham weswigham deleted the es6-module-type branch August 17, 2017 23:03
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants