Emit the helpers inside the module body

Fixes #3655
This commit is contained in:
Sheetal Nandi 2015-07-31 11:54:03 -07:00
parent cd018e1af4
commit bfc4dd14da
2 changed files with 21 additions and 13 deletions

View File

@ -6259,6 +6259,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(`], function(${exportFunctionForFile}) {`);
writeLine();
increaseIndent();
emitEmitHelpers(node);
emitCaptureThisForNodeIfNecessary(node);
emitSystemModuleBody(node, startIndex);
decreaseIndent();
@ -6330,6 +6331,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitAMDModule(node: SourceFile, startIndex: number) {
emitEmitHelpers(node);
collectExternalModuleInfo(node);
writeLine();
@ -6351,6 +6353,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitCommonJSModule(node: SourceFile, startIndex: number) {
emitEmitHelpers(node);
collectExternalModuleInfo(node);
emitExportStarHelper();
emitCaptureThisForNodeIfNecessary(node);
@ -6360,6 +6363,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
function emitUMDModule(node: SourceFile, startIndex: number) {
emitEmitHelpers(node);
collectExternalModuleInfo(node);
// Module is detected first to support Browserify users that load into a browser with an AMD loader
@ -6389,6 +6393,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
exportSpecifiers = undefined;
exportEquals = undefined;
hasExportStars = false;
emitEmitHelpers(node);
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
emitTempDeclarations(/*newLine*/ true);
@ -6527,14 +6532,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
}
function emitSourceFileNode(node: SourceFile) {
// Start new file on new line
writeLine();
emitDetachedComments(node);
// emit prologue directives prior to __extends
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
function emitEmitHelpers(node: SourceFile): void {
// Only emit helpers if the user did not say otherwise.
if (!compilerOptions.noEmitHelpers) {
// Only Emit __extends function when target ES5.
@ -6562,6 +6560,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
awaiterEmitted = true;
}
}
}
function emitSourceFileNode(node: SourceFile) {
// Start new file on new line
writeLine();
emitDetachedComments(node);
// emit prologue directives prior to __extends
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
if (isExternalModule(node) || compilerOptions.isolatedModules) {
if (languageVersion >= ScriptTarget.ES6) {
@ -6585,6 +6592,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
exportSpecifiers = undefined;
exportEquals = undefined;
hasExportStars = false;
emitEmitHelpers(node);
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
emitTempDeclarations(/*newLine*/ true);

View File

@ -28,12 +28,12 @@ System.register([], function(exports_1) {
}
});
//// [bar.js]
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
System.register(['./foo'], function(exports_1) {
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var foo_1;
var Bar;
return {