-
Notifications
You must be signed in to change notification settings - Fork 12.9k
ES6 emit for new import / export syntax #2335
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
e902d84
ES6 doesnt support import id = require("mod") syntax
mhegazy 61a5bfb
Report error on export assignment with es6 and above target
mhegazy a6e4e04
Add tests
mhegazy 04ea7fe
Handel isDeclaration visible for imports
mhegazy b52d9ec
Report error if module gen target is specified in es6
mhegazy 4ef687c
Add tests
mhegazy 7b3e50f
Emit in ES6 module if script target is es6 or higher
mhegazy 8c26507
Support for emitting import declaration in es6 format
mhegazy 3ed8bcc
Simplify module kind selection
mhegazy 4b75484
Fix the checks with language version to use default es3
sheetalkamat 006ed82
Remove references with exports.id as es6 module doesnt have exports.id
sheetalkamat 29b2214
Do not rewrite substitute named import reference when generating es6 …
sheetalkamat 05932fd
Es6 module emit for export VarDeclaration, export LexicalDeclaration
sheetalkamat b9f63a8
Emit es6 export ModuleDeclaration
mhegazy 58d1959
Emit ES6 module enum declaration
mhegazy b091fa5
Emit export function declaration in es6 format
mhegazy 6bcbe82
Emit export class declaration in es6 format.
mhegazy 680cf6d
Emit export internal import equals declaration in es6 format
mhegazy fe9fff5
Export * and export { names } emit in es6 format
mhegazy b3c8bcb
Emit export default in ES6
mhegazy b6bbf06
Update error message
mhegazy 8e06265
Merge branch 'master' into es6ImportExportEmit
mhegazy b6a6d85
Merge branch 'master' into es6ImportExportEmit
mhegazy c984e81
Fix issue of the default binding not elided if namedImport is reference
mhegazy c877b1e
Add tests
mhegazy 090148f
Merge branch 'master' into es6ImportExportEmit
mhegazy 5845d2d
Merge branch 'master' into es6ImportExportEmit
mhegazy eb954e1
Respond to code review comments
mhegazy cb012e0
Merge branch 'master' into es6ImportExportEmit
mhegazy 9910869
Do not emit "export" for classes within modules, and do not write the…
mhegazy 3d80243
Export classes defined wihtin internal modules correctelly
mhegazy 1932f72
Handel export name bindings in internal modules in ES6
mhegazy 766cb68
Add comments
mhegazy a06ce61
Merge branch 'master' into es6ImportExportEmit
mhegazy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -783,7 +783,7 @@ module ts { | |
} | ||
|
||
function getExportsForModule(moduleSymbol: Symbol): SymbolTable { | ||
if (compilerOptions.target < ScriptTarget.ES6) { | ||
if (languageVersion < ScriptTarget.ES6) { | ||
// A default export hides all other exports in CommonJS and AMD modules | ||
let defaultSymbol = getExportAssignmentSymbol(moduleSymbol); | ||
if (defaultSymbol) { | ||
|
@@ -1812,6 +1812,11 @@ module ts { | |
case SyntaxKind.ParenthesizedType: | ||
return isDeclarationVisible(<Declaration>node.parent); | ||
|
||
case SyntaxKind.ImportClause: | ||
case SyntaxKind.NamespaceImport: | ||
case SyntaxKind.ImportSpecifier: | ||
return false; | ||
|
||
// Type parameters are always visible | ||
case SyntaxKind.TypeParameter: | ||
// Source file is always visible | ||
|
@@ -10093,6 +10098,12 @@ module ts { | |
} | ||
} | ||
} | ||
else { | ||
if (languageVersion >= ScriptTarget.ES6) { | ||
// Import equals declaration is deprecated in es6 or above | ||
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -10140,6 +10151,11 @@ module ts { | |
} | ||
|
||
checkExternalModuleExports(container); | ||
|
||
if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) { | ||
// export assignment is deprecated in es6 or above | ||
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); | ||
} | ||
} | ||
|
||
function getModuleStatements(node: Declaration): ModuleElement[] { | ||
|
@@ -10182,7 +10198,7 @@ module ts { | |
if (!links.exportsChecked) { | ||
let defaultSymbol = getExportAssignmentSymbol(moduleSymbol); | ||
if (defaultSymbol) { | ||
if (hasExportedMembers(moduleSymbol)) { | ||
if (languageVersion < ScriptTarget.ES6 && hasExportedMembers(moduleSymbol)) { | ||
let declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; | ||
error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); | ||
} | ||
|
@@ -11005,7 +11021,15 @@ module ts { | |
|
||
function getExportNameSubstitution(symbol: Symbol, location: Node): string { | ||
if (isExternalModuleSymbol(symbol.parent)) { | ||
return "exports." + unescapeIdentifier(symbol.name); | ||
var symbolName = unescapeIdentifier(symbol.name); | ||
// If this is es6 or higher, just use the name of the export | ||
// no need to qualify it. | ||
if (languageVersion >= ScriptTarget.ES6) { | ||
return symbolName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment why we don't prefix export name with 'exports.' when emitting for ES6+? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
} | ||
else { | ||
return "exports." + symbolName; | ||
} | ||
} | ||
let node = location; | ||
let containerSymbol = getParentOfSymbol(symbol); | ||
|
@@ -11033,7 +11057,7 @@ module ts { | |
return getExportNameSubstitution(exportSymbol, node.parent); | ||
} | ||
// Named imports from ES6 import declarations are rewritten | ||
if (symbol.flags & SymbolFlags.Alias) { | ||
if (symbol.flags & SymbolFlags.Alias && languageVersion < ScriptTarget.ES6) { | ||
return getAliasNameSubstitution(symbol); | ||
} | ||
} | ||
|
@@ -11069,7 +11093,6 @@ module ts { | |
return true; | ||
} | ||
} | ||
return forEachChild(node, isReferencedAliasDeclaration); | ||
} | ||
|
||
function isImplementationOfOverload(node: FunctionLikeDeclaration) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this documented with Jonathan as a breaking change? (it seems like a very big one, erroring on an entire feature if you move to ES6).
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. that is the current design. we will have a blog post about moving to the new module syntax.