Skip to content

Commit a4a1a51

Browse files
committed
Merge pull request #4111 from Microsoft/systemModuleWithEmitHelpers
Fix the emit helper emit inside the system modules
2 parents adfac92 + bfc4dd1 commit a4a1a51

File tree

5 files changed

+123
-8
lines changed

5 files changed

+123
-8
lines changed

src/compiler/emitter.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6259,6 +6259,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
62596259
write(`], function(${exportFunctionForFile}) {`);
62606260
writeLine();
62616261
increaseIndent();
6262+
emitEmitHelpers(node);
62626263
emitCaptureThisForNodeIfNecessary(node);
62636264
emitSystemModuleBody(node, startIndex);
62646265
decreaseIndent();
@@ -6330,6 +6331,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
63306331
}
63316332

63326333
function emitAMDModule(node: SourceFile, startIndex: number) {
6334+
emitEmitHelpers(node);
63336335
collectExternalModuleInfo(node);
63346336

63356337
writeLine();
@@ -6351,6 +6353,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
63516353
}
63526354

63536355
function emitCommonJSModule(node: SourceFile, startIndex: number) {
6356+
emitEmitHelpers(node);
63546357
collectExternalModuleInfo(node);
63556358
emitExportStarHelper();
63566359
emitCaptureThisForNodeIfNecessary(node);
@@ -6360,6 +6363,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
63606363
}
63616364

63626365
function emitUMDModule(node: SourceFile, startIndex: number) {
6366+
emitEmitHelpers(node);
63636367
collectExternalModuleInfo(node);
63646368

63656369
// 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
63896393
exportSpecifiers = undefined;
63906394
exportEquals = undefined;
63916395
hasExportStars = false;
6396+
emitEmitHelpers(node);
63926397
emitCaptureThisForNodeIfNecessary(node);
63936398
emitLinesStartingAt(node.statements, startIndex);
63946399
emitTempDeclarations(/*newLine*/ true);
@@ -6527,14 +6532,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
65276532
}
65286533
}
65296534

6530-
function emitSourceFileNode(node: SourceFile) {
6531-
// Start new file on new line
6532-
writeLine();
6533-
emitDetachedComments(node);
6534-
6535-
// emit prologue directives prior to __extends
6536-
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
6537-
6535+
function emitEmitHelpers(node: SourceFile): void {
65386536
// Only emit helpers if the user did not say otherwise.
65396537
if (!compilerOptions.noEmitHelpers) {
65406538
// Only Emit __extends function when target ES5.
@@ -6562,6 +6560,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
65626560
awaiterEmitted = true;
65636561
}
65646562
}
6563+
}
6564+
6565+
function emitSourceFileNode(node: SourceFile) {
6566+
// Start new file on new line
6567+
writeLine();
6568+
emitDetachedComments(node);
6569+
6570+
// emit prologue directives prior to __extends
6571+
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
65656572

65666573
if (isExternalModule(node) || compilerOptions.isolatedModules) {
65676574
if (languageVersion >= ScriptTarget.ES6) {
@@ -6585,6 +6592,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
65856592
exportSpecifiers = undefined;
65866593
exportEquals = undefined;
65876594
hasExportStars = false;
6595+
emitEmitHelpers(node);
65886596
emitCaptureThisForNodeIfNecessary(node);
65896597
emitLinesStartingAt(node.statements, startIndex);
65906598
emitTempDeclarations(/*newLine*/ true);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [tests/cases/compiler/systemModuleWithSuperClass.ts] ////
2+
3+
//// [foo.ts]
4+
5+
export class Foo {
6+
a: string;
7+
}
8+
9+
//// [bar.ts]
10+
import {Foo} from './foo';
11+
export class Bar extends Foo {
12+
b: string;
13+
}
14+
15+
//// [foo.js]
16+
System.register([], function(exports_1) {
17+
var Foo;
18+
return {
19+
setters:[],
20+
execute: function() {
21+
Foo = (function () {
22+
function Foo() {
23+
}
24+
return Foo;
25+
})();
26+
exports_1("Foo", Foo);
27+
}
28+
}
29+
});
30+
//// [bar.js]
31+
System.register(['./foo'], function(exports_1) {
32+
var __extends = (this && this.__extends) || function (d, b) {
33+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
34+
function __() { this.constructor = d; }
35+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36+
};
37+
var foo_1;
38+
var Bar;
39+
return {
40+
setters:[
41+
function (_foo_1) {
42+
foo_1 = _foo_1;
43+
}],
44+
execute: function() {
45+
Bar = (function (_super) {
46+
__extends(Bar, _super);
47+
function Bar() {
48+
_super.apply(this, arguments);
49+
}
50+
return Bar;
51+
})(foo_1.Foo);
52+
exports_1("Bar", Bar);
53+
}
54+
}
55+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/foo.ts ===
2+
3+
export class Foo {
4+
>Foo : Symbol(Foo, Decl(foo.ts, 0, 0))
5+
6+
a: string;
7+
>a : Symbol(a, Decl(foo.ts, 1, 18))
8+
}
9+
10+
=== tests/cases/compiler/bar.ts ===
11+
import {Foo} from './foo';
12+
>Foo : Symbol(Foo, Decl(bar.ts, 0, 8))
13+
14+
export class Bar extends Foo {
15+
>Bar : Symbol(Bar, Decl(bar.ts, 0, 26))
16+
>Foo : Symbol(Foo, Decl(bar.ts, 0, 8))
17+
18+
b: string;
19+
>b : Symbol(b, Decl(bar.ts, 1, 30))
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/foo.ts ===
2+
3+
export class Foo {
4+
>Foo : Foo
5+
6+
a: string;
7+
>a : string
8+
}
9+
10+
=== tests/cases/compiler/bar.ts ===
11+
import {Foo} from './foo';
12+
>Foo : typeof Foo
13+
14+
export class Bar extends Foo {
15+
>Bar : Bar
16+
>Foo : Foo
17+
18+
b: string;
19+
>b : string
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @module: system
2+
3+
// @Filename: foo.ts
4+
export class Foo {
5+
a: string;
6+
}
7+
8+
// @Filename: bar.ts
9+
import {Foo} from './foo';
10+
export class Bar extends Foo {
11+
b: string;
12+
}

0 commit comments

Comments
 (0)