Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
/** If removeComments is true, no leading-comments needed to be emitted **/
let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos: number) { } : emitLeadingCommentsOfPositionWorker;

let moduleEmitDelegates: Map<(node: SourceFile, startIndex: number) => void> = {
let moduleEmitDelegates: Map<(node: SourceFile) => void> = {
[ModuleKind.ES6]: emitES6Module,
[ModuleKind.AMD]: emitAMDModule,
[ModuleKind.System]: emitSystemModule,
Expand Down Expand Up @@ -6594,7 +6594,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write("}"); // execute
}

function emitSystemModule(node: SourceFile, startIndex: number): void {
function emitSystemModule(node: SourceFile): void {
collectExternalModuleInfo(node);
// System modules has the following shape
// System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */})
Expand Down Expand Up @@ -6639,6 +6639,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(`], function(${exportFunctionForFile}) {`);
writeLine();
increaseIndent();
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
emitEmitHelpers(node);
emitCaptureThisForNodeIfNecessary(node);
emitSystemModuleBody(node, dependencyGroups, startIndex);
Expand Down Expand Up @@ -6732,7 +6733,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write(") {");
}

function emitAMDModule(node: SourceFile, startIndex: number) {
function emitAMDModule(node: SourceFile) {
emitEmitHelpers(node);
collectExternalModuleInfo(node);

Expand All @@ -6743,6 +6744,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
}
emitAMDDependencies(node, /*includeNonAmdDependencies*/ true);
increaseIndent();
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
emitExportStarHelper();
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
Expand All @@ -6753,7 +6755,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write("});");
}

function emitCommonJSModule(node: SourceFile, startIndex: number) {
function emitCommonJSModule(node: SourceFile) {
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
emitEmitHelpers(node);
collectExternalModuleInfo(node);
emitExportStarHelper();
Expand All @@ -6763,7 +6766,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitExportEquals(/*emitAsReturn*/ false);
}

function emitUMDModule(node: SourceFile, startIndex: number) {
function emitUMDModule(node: SourceFile) {
emitEmitHelpers(node);
collectExternalModuleInfo(node);

Expand All @@ -6782,6 +6785,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
})(`);
emitAMDFactoryHeader(dependencyNames);
increaseIndent();
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true);
emitExportStarHelper();
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
Expand All @@ -6792,11 +6796,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
write("});");
}

function emitES6Module(node: SourceFile, startIndex: number) {
function emitES6Module(node: SourceFile) {
externalImports = undefined;
exportSpecifiers = undefined;
exportEquals = undefined;
hasExportStars = false;
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
emitEmitHelpers(node);
emitCaptureThisForNodeIfNecessary(node);
emitLinesStartingAt(node.statements, startIndex);
Expand Down Expand Up @@ -6985,14 +6990,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitShebang();
emitDetachedComments(node);

// emit prologue directives prior to __extends
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);

if (isExternalModule(node) || compilerOptions.isolatedModules) {
let emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[ModuleKind.CommonJS];
emitModule(node, startIndex);
emitModule(node);
}
else {
// emit prologue directives prior to __extends
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
externalImports = undefined;
exportSpecifiers = undefined;
exportEquals = undefined;
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/modulePrologueAMD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [modulePrologueAMD.ts]
"use strict";

export class Foo {}

//// [modulePrologueAMD.js]
define(["require", "exports"], function (require, exports) {
"use strict";
var Foo = (function () {
function Foo() {
}
return Foo;
})();
exports.Foo = Foo;
});
6 changes: 6 additions & 0 deletions tests/baselines/reference/modulePrologueAMD.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/modulePrologueAMD.ts ===
"use strict";

export class Foo {}
>Foo : Symbol(Foo, Decl(modulePrologueAMD.ts, 0, 13))

7 changes: 7 additions & 0 deletions tests/baselines/reference/modulePrologueAMD.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/modulePrologueAMD.ts ===
"use strict";
>"use strict" : string

export class Foo {}
>Foo : Foo

13 changes: 13 additions & 0 deletions tests/baselines/reference/modulePrologueCommonjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [modulePrologueCommonjs.ts]
"use strict";

export class Foo {}

//// [modulePrologueCommonjs.js]
"use strict";
var Foo = (function () {
function Foo() {
}
return Foo;
})();
exports.Foo = Foo;
6 changes: 6 additions & 0 deletions tests/baselines/reference/modulePrologueCommonjs.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/modulePrologueCommonjs.ts ===
"use strict";

export class Foo {}
>Foo : Symbol(Foo, Decl(modulePrologueCommonjs.ts, 0, 13))

7 changes: 7 additions & 0 deletions tests/baselines/reference/modulePrologueCommonjs.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/modulePrologueCommonjs.ts ===
"use strict";
>"use strict" : string

export class Foo {}
>Foo : Foo

9 changes: 9 additions & 0 deletions tests/baselines/reference/modulePrologueES6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [modulePrologueES6.ts]
"use strict";

export class Foo {}

//// [modulePrologueES6.js]
"use strict";
export class Foo {
}
6 changes: 6 additions & 0 deletions tests/baselines/reference/modulePrologueES6.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/modulePrologueES6.ts ===
"use strict";

export class Foo {}
>Foo : Symbol(Foo, Decl(modulePrologueES6.ts, 0, 13))

7 changes: 7 additions & 0 deletions tests/baselines/reference/modulePrologueES6.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/modulePrologueES6.ts ===
"use strict";
>"use strict" : string

export class Foo {}
>Foo : Foo

21 changes: 21 additions & 0 deletions tests/baselines/reference/modulePrologueSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [modulePrologueSystem.ts]
"use strict";

export class Foo {}

//// [modulePrologueSystem.js]
System.register([], function(exports_1) {
"use strict";
var Foo;
return {
setters:[],
execute: function() {
Foo = (function () {
function Foo() {
}
return Foo;
})();
exports_1("Foo", Foo);
}
}
});
6 changes: 6 additions & 0 deletions tests/baselines/reference/modulePrologueSystem.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/modulePrologueSystem.ts ===
"use strict";

export class Foo {}
>Foo : Symbol(Foo, Decl(modulePrologueSystem.ts, 0, 13))

7 changes: 7 additions & 0 deletions tests/baselines/reference/modulePrologueSystem.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/modulePrologueSystem.ts ===
"use strict";
>"use strict" : string

export class Foo {}
>Foo : Foo

22 changes: 22 additions & 0 deletions tests/baselines/reference/modulePrologueUmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//// [modulePrologueUmd.ts]
"use strict";

export class Foo {}

//// [modulePrologueUmd.js]
(function (factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
}
else if (typeof define === 'function' && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
var Foo = (function () {
function Foo() {
}
return Foo;
})();
exports.Foo = Foo;
});
6 changes: 6 additions & 0 deletions tests/baselines/reference/modulePrologueUmd.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/compiler/modulePrologueUmd.ts ===
"use strict";

export class Foo {}
>Foo : Symbol(Foo, Decl(modulePrologueUmd.ts, 0, 13))

7 changes: 7 additions & 0 deletions tests/baselines/reference/modulePrologueUmd.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/modulePrologueUmd.ts ===
"use strict";
>"use strict" : string

export class Foo {}
>Foo : Foo

4 changes: 4 additions & 0 deletions tests/cases/compiler/modulePrologueAMD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @module: amd
"use strict";

export class Foo {}
4 changes: 4 additions & 0 deletions tests/cases/compiler/modulePrologueCommonjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @module: commonjs
"use strict";

export class Foo {}
5 changes: 5 additions & 0 deletions tests/cases/compiler/modulePrologueES6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @module: es6
// @target: es6
"use strict";

export class Foo {}
4 changes: 4 additions & 0 deletions tests/cases/compiler/modulePrologueSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @module: system
"use strict";

export class Foo {}
4 changes: 4 additions & 0 deletions tests/cases/compiler/modulePrologueUmd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @module: umd
"use strict";

export class Foo {}