mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -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;
|
||||
|
||||
@@ -5,4 +5,3 @@ export = a;
|
||||
|
||||
//// [es6ExportAssignment.js]
|
||||
var a = 10;
|
||||
module.exports = a;
|
||||
|
||||
@@ -22,19 +22,12 @@ var x1: number = defaultBinding6;
|
||||
|
||||
//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js]
|
||||
var a = 10;
|
||||
module.exports = a;
|
||||
//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js]
|
||||
var defaultBinding1 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0");
|
||||
var x1 = defaultBinding1;
|
||||
var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0");
|
||||
var x1 = defaultBinding2;
|
||||
var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0");
|
||||
var x1 = defaultBinding3;
|
||||
var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0");
|
||||
var x1 = defaultBinding4;
|
||||
var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0");
|
||||
var x1 = defaultBinding5;
|
||||
var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0");
|
||||
var x1 = defaultBinding6;
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ var x: number = nameSpaceBinding.a;
|
||||
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js]
|
||||
exports.a = 10;
|
||||
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js]
|
||||
var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0");
|
||||
var x = nameSpaceBinding.a;
|
||||
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ var x: number = defaultBinding;
|
||||
|
||||
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js]
|
||||
var a = 10;
|
||||
module.exports = a;
|
||||
//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js]
|
||||
var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0");
|
||||
var x = defaultBinding;
|
||||
|
||||
|
||||
|
||||
@@ -10,5 +10,4 @@ import a = require("server");
|
||||
|
||||
//// [server.js]
|
||||
var a = 10;
|
||||
module.exports = a;
|
||||
//// [client.js]
|
||||
|
||||
@@ -24,5 +24,4 @@ from;
|
||||
}
|
||||
from;
|
||||
"es6ImportNamedImportParsingError_0";
|
||||
var _module_1 = require();
|
||||
"es6ImportNamedImportParsingError_0";
|
||||
|
||||
@@ -11,7 +11,6 @@ import "es6ImportWithoutFromClause_0";
|
||||
//// [es6ImportWithoutFromClause_0.js]
|
||||
exports.a = 10;
|
||||
//// [es6ImportWithoutFromClause_1.js]
|
||||
require("es6ImportWithoutFromClause_0");
|
||||
|
||||
|
||||
//// [es6ImportWithoutFromClause_0.d.ts]
|
||||
|
||||
@@ -10,7 +10,6 @@ import "es6ImportWithoutFromClauseNonInstantiatedModule_0";
|
||||
|
||||
//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js]
|
||||
//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js]
|
||||
require("es6ImportWithoutFromClauseNonInstantiatedModule_0");
|
||||
|
||||
|
||||
//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts]
|
||||
|
||||
Reference in New Issue
Block a user