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:
Mohamed Hegazy
2015-03-11 23:29:30 -07:00
parent 4ef687c5fa
commit 7b3e50fb98
9 changed files with 15 additions and 17 deletions

View File

@@ -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;