mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 10:40:34 -05:00
Emit in ES6 module if script target is es6 or higher
Conflicts: src/compiler/emitter.ts tests/baselines/reference/es6ImportDefaultBinding.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js tests/baselines/reference/es6ImportNameSpaceImport.js tests/baselines/reference/es6ImportNamedImport.js
This commit is contained in:
@@ -5207,6 +5207,7 @@ module ts {
|
||||
}
|
||||
|
||||
function emitAMDModule(node: SourceFile, startIndex: number) {
|
||||
createExternalModuleInfo(node);
|
||||
writeLine();
|
||||
write("define(");
|
||||
sortAMDModules(node.amdDependencies);
|
||||
@@ -5257,6 +5258,16 @@ module ts {
|
||||
}
|
||||
|
||||
function emitCommonJSModule(node: SourceFile, startIndex: number) {
|
||||
createExternalModuleInfo(node);
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitLinesStartingAt(node.statements, startIndex);
|
||||
emitTempDeclarations(/*newLine*/ true);
|
||||
emitExportDefault(node, /*emitAsReturn*/ false);
|
||||
}
|
||||
|
||||
function emitES6Module(node: SourceFile, startIndex: number) {
|
||||
externalImports = undefined;
|
||||
exportSpecifiers = undefined;
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitLinesStartingAt(node.statements, startIndex);
|
||||
emitTempDeclarations(/*newLine*/ true);
|
||||
@@ -5323,13 +5334,15 @@ module ts {
|
||||
extendsEmitted = true;
|
||||
}
|
||||
if (isExternalModule(node)) {
|
||||
createExternalModuleInfo(node);
|
||||
if (compilerOptions.module === ModuleKind.AMD) {
|
||||
emitAMDModule(node, startIndex);
|
||||
}
|
||||
else {
|
||||
else if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.target < ScriptTarget.ES6) {
|
||||
emitCommonJSModule(node, startIndex);
|
||||
}
|
||||
else {
|
||||
emitES6Module(node, startIndex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
externalImports = undefined;
|
||||
|
||||
Reference in New Issue
Block a user