Skip to content

Commit 689c09c

Browse files
committed
Merge branch 'whitneyit-feature/noEmitExtends'
2 parents 9438355 + 3c99527 commit 689c09c

14 files changed

+144
-17
lines changed

bin/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ declare module "typescript" {
10951095
mapRoot?: string;
10961096
module?: ModuleKind;
10971097
noEmit?: boolean;
1098+
noEmitHelpers?: boolean;
10981099
noEmitOnError?: boolean;
10991100
noErrorTruncation?: boolean;
11001101
noImplicitAny?: boolean;

bin/typescriptServices.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ declare module ts {
10951095
mapRoot?: string;
10961096
module?: ModuleKind;
10971097
noEmit?: boolean;
1098+
noEmitHelpers?: boolean;
10981099
noEmitOnError?: boolean;
10991100
noErrorTruncation?: boolean;
11001101
noImplicitAny?: boolean;

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ module ts {
7171
type: "boolean",
7272
description: Diagnostics.Do_not_emit_outputs,
7373
},
74+
{
75+
name: "noEmitHelpers",
76+
type: "boolean"
77+
},
7478
{
7579
name: "noEmitOnError",
7680
type: "boolean",

src/compiler/emitter.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5614,24 +5614,28 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
56145614

56155615
// emit prologue directives prior to __extends
56165616
var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
5617-
// Only Emit __extends function when target ES5.
5618-
// For target ES6 and above, we can emit classDeclaration as is.
5619-
if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends)) {
5620-
writeLines(extendsHelper);
5621-
extendsEmitted = true;
5622-
}
56235617

5624-
if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate) {
5625-
writeLines(decorateHelper);
5626-
if (compilerOptions.emitDecoratorMetadata) {
5627-
writeLines(metadataHelper);
5618+
// Only emit helpers if the user did not say otherwise.
5619+
if (!compilerOptions.noEmitHelpers) {
5620+
// Only Emit __extends function when target ES5.
5621+
// For target ES6 and above, we can emit classDeclaration as is.
5622+
if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends)) {
5623+
writeLines(extendsHelper);
5624+
extendsEmitted = true;
5625+
}
5626+
5627+
if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate) {
5628+
writeLines(decorateHelper);
5629+
if (compilerOptions.emitDecoratorMetadata) {
5630+
writeLines(metadataHelper);
5631+
}
5632+
decorateEmitted = true;
56285633
}
5629-
decorateEmitted = true;
5630-
}
56315634

5632-
if (!paramEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitParam) {
5633-
writeLines(paramHelper);
5634-
paramEmitted = true;
5635+
if (!paramEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitParam) {
5636+
writeLines(paramHelper);
5637+
paramEmitted = true;
5638+
}
56355639
}
56365640

56375641
if (isExternalModule(node) || compilerOptions.separateCompilation) {

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,7 @@ module ts {
16571657
mapRoot?: string;
16581658
module?: ModuleKind;
16591659
noEmit?: boolean;
1660+
noEmitHelpers?: boolean;
16601661
noEmitOnError?: boolean;
16611662
noErrorTruncation?: boolean;
16621663
noImplicitAny?: boolean;

src/harness/harness.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,14 @@ module Harness {
990990
}
991991
break;
992992

993+
case 'emitdecoratormetadata':
994+
options.emitDecoratorMetadata = setting.value === 'true';
995+
break;
996+
997+
case 'noemithelpers':
998+
options.noEmitHelpers = setting.value === 'true';
999+
break;
1000+
9931001
case 'noemitonerror':
9941002
options.noEmitOnError = !!setting.value;
9951003
break;
@@ -1477,12 +1485,12 @@ module Harness {
14771485

14781486
// List of allowed metadata names
14791487
var fileMetadataNames = ["filename", "comments", "declaration", "module",
1480-
"nolib", "sourcemap", "target", "out", "outdir", "noemitonerror",
1488+
"nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror",
14811489
"noimplicitany", "noresolve", "newline", "newlines", "emitbom",
14821490
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
14831491
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
14841492
"separatecompilation", "inlinesourcemap", "maproot", "sourceroot",
1485-
"inlinesources"];
1493+
"inlinesources", "emitdecoratormetadata"];
14861494

14871495
function extractCompilerSettings(content: string): CompilerSetting[] {
14881496

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [noEmitHelpers.ts]
2+
3+
class A { }
4+
class B extends A { }
5+
6+
7+
//// [noEmitHelpers.js]
8+
var A = (function () {
9+
function A() {
10+
}
11+
return A;
12+
})();
13+
var B = (function (_super) {
14+
__extends(B, _super);
15+
function B() {
16+
_super.apply(this, arguments);
17+
}
18+
return B;
19+
})(A);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/noEmitHelpers.ts ===
2+
3+
class A { }
4+
>A : Symbol(A, Decl(noEmitHelpers.ts, 0, 0))
5+
6+
class B extends A { }
7+
>B : Symbol(B, Decl(noEmitHelpers.ts, 1, 11))
8+
>A : Symbol(A, Decl(noEmitHelpers.ts, 0, 0))
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/noEmitHelpers.ts ===
2+
3+
class A { }
4+
>A : A
5+
6+
class B extends A { }
7+
>B : B
8+
>A : A
9+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [noEmitHelpers2.ts]
2+
3+
function decorator() { }
4+
5+
@decorator
6+
class A {
7+
constructor(a: number, @decorator b: string) {
8+
}
9+
}
10+
11+
//// [noEmitHelpers2.js]
12+
function decorator() { }
13+
var A = (function () {
14+
function A(a, b) {
15+
}
16+
A = __decorate([
17+
decorator,
18+
__param(1, decorator),
19+
__metadata('design:paramtypes', [Number, String])
20+
], A);
21+
return A;
22+
})();

0 commit comments

Comments
 (0)