diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 3ec7b1230a..7cf08879ea 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -1095,6 +1095,7 @@ declare module "typescript" { mapRoot?: string; module?: ModuleKind; noEmit?: boolean; + noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; noImplicitAny?: boolean; diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 9b5072a058..92427e18f2 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -1095,6 +1095,7 @@ declare module ts { mapRoot?: string; module?: ModuleKind; noEmit?: boolean; + noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; noImplicitAny?: boolean; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 15a67db77e..da31878403 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -71,6 +71,10 @@ module ts { type: "boolean", description: Diagnostics.Do_not_emit_outputs, }, + { + name: "noEmitHelpers", + type: "boolean" + }, { name: "noEmitOnError", type: "boolean", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9e3e18b031..020952a765 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5614,24 +5614,28 @@ var __param = (this && this.__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; } - decorateEmitted = true; - } - if (!paramEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitParam) { - writeLines(paramHelper); - paramEmitted = 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; + } } if (isExternalModule(node) || compilerOptions.separateCompilation) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4799f31406..9e7e6ac732 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1657,6 +1657,7 @@ module ts { mapRoot?: string; module?: ModuleKind; noEmit?: boolean; + noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; noImplicitAny?: boolean; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 6af77e3d74..30ae22a9e4 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -990,6 +990,14 @@ module Harness { } break; + case 'emitdecoratormetadata': + options.emitDecoratorMetadata = setting.value === 'true'; + break; + + case 'noemithelpers': + options.noEmitHelpers = setting.value === 'true'; + break; + case 'noemitonerror': options.noEmitOnError = !!setting.value; break; @@ -1477,12 +1485,12 @@ 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", "separatecompilation", "inlinesourcemap", "maproot", "sourceroot", - "inlinesources"]; + "inlinesources", "emitdecoratormetadata"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/tests/baselines/reference/noEmitHelpers.js b/tests/baselines/reference/noEmitHelpers.js new file mode 100644 index 0000000000..8db5cd862b --- /dev/null +++ b/tests/baselines/reference/noEmitHelpers.js @@ -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); diff --git a/tests/baselines/reference/noEmitHelpers.symbols b/tests/baselines/reference/noEmitHelpers.symbols new file mode 100644 index 0000000000..efd281c812 --- /dev/null +++ b/tests/baselines/reference/noEmitHelpers.symbols @@ -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)) + diff --git a/tests/baselines/reference/noEmitHelpers.types b/tests/baselines/reference/noEmitHelpers.types new file mode 100644 index 0000000000..d25bd88255 --- /dev/null +++ b/tests/baselines/reference/noEmitHelpers.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/noEmitHelpers.ts === + +class A { } +>A : A + +class B extends A { } +>B : B +>A : A + diff --git a/tests/baselines/reference/noEmitHelpers2.js b/tests/baselines/reference/noEmitHelpers2.js new file mode 100644 index 0000000000..1bd4237767 --- /dev/null +++ b/tests/baselines/reference/noEmitHelpers2.js @@ -0,0 +1,22 @@ +//// [noEmitHelpers2.ts] + +function decorator() { } + +@decorator +class A { + constructor(a: number, @decorator b: string) { + } +} + +//// [noEmitHelpers2.js] +function decorator() { } +var A = (function () { + function A(a, b) { + } + A = __decorate([ + decorator, + __param(1, decorator), + __metadata('design:paramtypes', [Number, String]) + ], A); + return A; +})(); diff --git a/tests/baselines/reference/noEmitHelpers2.symbols b/tests/baselines/reference/noEmitHelpers2.symbols new file mode 100644 index 0000000000..3a3e3ec94c --- /dev/null +++ b/tests/baselines/reference/noEmitHelpers2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/noEmitHelpers2.ts === + +function decorator() { } +>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0)) + +@decorator +>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0)) + +class A { +>A : Symbol(A, Decl(noEmitHelpers2.ts, 1, 24)) + + constructor(a: number, @decorator b: string) { +>a : Symbol(a, Decl(noEmitHelpers2.ts, 5, 16)) +>decorator : Symbol(decorator, Decl(noEmitHelpers2.ts, 0, 0)) +>b : Symbol(b, Decl(noEmitHelpers2.ts, 5, 26)) + } +} diff --git a/tests/baselines/reference/noEmitHelpers2.types b/tests/baselines/reference/noEmitHelpers2.types new file mode 100644 index 0000000000..2a5b5413a7 --- /dev/null +++ b/tests/baselines/reference/noEmitHelpers2.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/noEmitHelpers2.ts === + +function decorator() { } +>decorator : () => void + +@decorator +>decorator : () => void + +class A { +>A : A + + constructor(a: number, @decorator b: string) { +>a : number +>decorator : () => void +>b : string + } +} diff --git a/tests/cases/compiler/noEmitHelpers.ts b/tests/cases/compiler/noEmitHelpers.ts new file mode 100644 index 0000000000..cb37c0db96 --- /dev/null +++ b/tests/cases/compiler/noEmitHelpers.ts @@ -0,0 +1,4 @@ +// @noemithelpers: true + +class A { } +class B extends A { } diff --git a/tests/cases/compiler/noEmitHelpers2.ts b/tests/cases/compiler/noEmitHelpers2.ts new file mode 100644 index 0000000000..df71f4fae8 --- /dev/null +++ b/tests/cases/compiler/noEmitHelpers2.ts @@ -0,0 +1,11 @@ +// @noemithelpers: true +// @emitdecoratormetadata: true +// @target: es5 + +function decorator() { } + +@decorator +class A { + constructor(a: number, @decorator b: string) { + } +} \ No newline at end of file