Skip to content

Commit

Permalink
Merge branch 'feature/noEmitExtends' of https://github.com/whitneyit/…
Browse files Browse the repository at this point in the history
…TypeScript into whitneyit-feature/noEmitExtends
  • Loading branch information
mhegazy committed May 1, 2015
2 parents 892bc6d + 76fa4b8 commit 93bf569
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 16 deletions.
1 change: 1 addition & 0 deletions bin/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ declare module "typescript" {
mapRoot?: string;
module?: ModuleKind;
noEmit?: boolean;
noEmitHelpers?: boolean;
noEmitOnError?: boolean;
noErrorTruncation?: boolean;
noImplicitAny?: boolean;
Expand Down
1 change: 1 addition & 0 deletions bin/typescriptServices.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ declare module ts {
mapRoot?: string;
module?: ModuleKind;
noEmit?: boolean;
noEmitHelpers?: boolean;
noEmitOnError?: boolean;
noErrorTruncation?: boolean;
noImplicitAny?: boolean;
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ module ts {
type: "boolean",
description: Diagnostics.Do_not_emit_outputs,
},
{
name: "noEmitHelpers",
type: "boolean"
},
{
name: "noEmitOnError",
type: "boolean",
Expand Down
42 changes: 27 additions & 15 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5487,6 +5487,9 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
}

write("[\"require\", \"exports\"");
if (compilerOptions.noEmitHelpers) {
write(", \"__extends\"");
}
if (aliasedModuleNames.length) {
write(", ");
write(aliasedModuleNames.join(", "));
Expand All @@ -5496,6 +5499,9 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
write(unaliasedModuleNames.join(", "));
}
write("], function (require, exports");
if (compilerOptions.noEmitHelpers) {
write(", __extends");
}
if (importAliasNames.length) {
write(", ");
write(importAliasNames.join(", "));
Expand Down Expand Up @@ -5614,24 +5620,30 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {

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

if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate) {
writeLines(decorateHelper);
if (compilerOptions.emitDecoratorMetadata) {
writeLines(metadataHelper);
// Only emit helpers if the user did not say otherwise.
if (!compilerOptions.noEmitHelpers) {

// Only Emit __extends function when target ES5.
// For target ES6 and above, we can emit classDeclaration as is.
if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends)) {
writeLines(extendsHelper);
extendsEmitted = true;
}

if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate) {
writeLines(decorateHelper);
if (compilerOptions.emitDecoratorMetadata) {
writeLines(metadataHelper);
}
decorateEmitted = true;
}

if (!paramEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitParam) {
writeLines(paramHelper);
paramEmitted = true;
}
decorateEmitted = true;
}

if (!paramEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitParam) {
writeLines(paramHelper);
paramEmitted = true;
}

if (isExternalModule(node) || compilerOptions.separateCompilation) {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,7 @@ module ts {
mapRoot?: string;
module?: ModuleKind;
noEmit?: boolean;
noEmitHelpers?: boolean;
noEmitOnError?: boolean;
noErrorTruncation?: boolean;
noImplicitAny?: boolean;
Expand Down
6 changes: 5 additions & 1 deletion src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,10 @@ module Harness {
}
break;

case 'noemithelpers':
options.noEmitHelpers = !!setting.value;
break;

case 'noemitonerror':
options.noEmitOnError = !!setting.value;
break;
Expand Down Expand Up @@ -1477,7 +1481,7 @@ module Harness {

// List of allowed metadata names
var fileMetadataNames = ["filename", "comments", "declaration", "module",
"nolib", "sourcemap", "target", "out", "outdir", "noemitonerror",
"nolib", "sourcemap", "target", "out", "outdir", "noemithelpers", "noemitonerror",
"noimplicitany", "noresolve", "newline", "newlines", "emitbom",
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/noEmitHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [noEmitHelpers.ts]

class A { }
class B extends A { }


//// [noEmitHelpers.js]
var A = (function () {
function A() {
}
return A;
})();
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
return B;
})(A);
9 changes: 9 additions & 0 deletions tests/baselines/reference/noEmitHelpers.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/compiler/noEmitHelpers.ts ===

class A { }
>A : Symbol(A, Decl(noEmitHelpers.ts, 0, 0))

class B extends A { }
>B : Symbol(B, Decl(noEmitHelpers.ts, 1, 11))
>A : Symbol(A, Decl(noEmitHelpers.ts, 0, 0))

9 changes: 9 additions & 0 deletions tests/baselines/reference/noEmitHelpers.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/compiler/noEmitHelpers.ts ===

class A { }
>A : A

class B extends A { }
>B : B
>A : A

4 changes: 4 additions & 0 deletions tests/cases/compiler/noEmitHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @noemithelpers: true

class A { }
class B extends A { }

0 comments on commit 93bf569

Please sign in to comment.