From d6ae55708d993852a8dd81d6978c81b4bb4203ed Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 12 Oct 2015 14:25:39 -0700 Subject: [PATCH 01/25] Do not mark class members as ambient or export. Even members of ambient classes. These flags have no useful semantics there, and it prevents ambient classes from merging properly with interfaces. --- src/compiler/checker.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 228b1067bb0..cf8a2d676b4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10992,7 +10992,13 @@ namespace ts { function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags): NodeFlags { let flags = getCombinedNodeFlags(n); - if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && isInAmbientContext(n)) { + + // children of classes (even ambient classes) should not be marked as ambient or export + // because those flags have no useful semantics there. + if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && + n.parent.kind !== SyntaxKind.ClassDeclaration && + n.parent.kind !== SyntaxKind.ClassExpression && + isInAmbientContext(n)) { if (!(flags & NodeFlags.Ambient)) { // It is nested in an ambient context, which means it is automatically exported flags |= NodeFlags.Export; From 3a55c849c7bb2107492eb3c98c04d33af943bf8e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 12 Oct 2015 14:26:45 -0700 Subject: [PATCH 02/25] Assert that ambient classes merge with interfaces Specifically, overloads are recognised as having the same export/ambient flags when merging the two. --- ...mbientClassMergesOverloadsWithInterface.js | 12 ++++++++++ ...tClassMergesOverloadsWithInterface.symbols | 22 +++++++++++++++++++ ...entClassMergesOverloadsWithInterface.types | 22 +++++++++++++++++++ ...mbientClassMergesOverloadsWithInterface.ts | 8 +++++++ 4 files changed, 64 insertions(+) create mode 100644 tests/baselines/reference/ambientClassMergesOverloadsWithInterface.js create mode 100644 tests/baselines/reference/ambientClassMergesOverloadsWithInterface.symbols create mode 100644 tests/baselines/reference/ambientClassMergesOverloadsWithInterface.types create mode 100644 tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts diff --git a/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.js b/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.js new file mode 100644 index 00000000000..417aedc4abc --- /dev/null +++ b/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.js @@ -0,0 +1,12 @@ +//// [ambientClassMergesOverloadsWithInterface.ts] +declare class C { + baz(): any; + foo(n: number): any; +} +interface C { + foo(n: number): any; + bar(): any; +} + + +//// [ambientClassMergesOverloadsWithInterface.js] diff --git a/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.symbols b/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.symbols new file mode 100644 index 00000000000..9a5eb13d21d --- /dev/null +++ b/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts === +declare class C { +>C : Symbol(C, Decl(ambientClassMergesOverloadsWithInterface.ts, 0, 0), Decl(ambientClassMergesOverloadsWithInterface.ts, 3, 1)) + + baz(): any; +>baz : Symbol(baz, Decl(ambientClassMergesOverloadsWithInterface.ts, 0, 17)) + + foo(n: number): any; +>foo : Symbol(foo, Decl(ambientClassMergesOverloadsWithInterface.ts, 1, 15), Decl(ambientClassMergesOverloadsWithInterface.ts, 4, 13)) +>n : Symbol(n, Decl(ambientClassMergesOverloadsWithInterface.ts, 2, 8)) +} +interface C { +>C : Symbol(C, Decl(ambientClassMergesOverloadsWithInterface.ts, 0, 0), Decl(ambientClassMergesOverloadsWithInterface.ts, 3, 1)) + + foo(n: number): any; +>foo : Symbol(foo, Decl(ambientClassMergesOverloadsWithInterface.ts, 1, 15), Decl(ambientClassMergesOverloadsWithInterface.ts, 4, 13)) +>n : Symbol(n, Decl(ambientClassMergesOverloadsWithInterface.ts, 5, 8)) + + bar(): any; +>bar : Symbol(bar, Decl(ambientClassMergesOverloadsWithInterface.ts, 5, 24)) +} + diff --git a/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.types b/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.types new file mode 100644 index 00000000000..7a271b82865 --- /dev/null +++ b/tests/baselines/reference/ambientClassMergesOverloadsWithInterface.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts === +declare class C { +>C : C + + baz(): any; +>baz : () => any + + foo(n: number): any; +>foo : { (n: number): any; (n: number): any; } +>n : number +} +interface C { +>C : C + + foo(n: number): any; +>foo : { (n: number): any; (n: number): any; } +>n : number + + bar(): any; +>bar : () => any +} + diff --git a/tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts b/tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts new file mode 100644 index 00000000000..6a6d3658b63 --- /dev/null +++ b/tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts @@ -0,0 +1,8 @@ +declare class C { + baz(): any; + foo(n: number): any; +} +interface C { + foo(n: number): any; + bar(): any; +} From 92c2d4846559403dee053a1fad04e55e21a0868c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 12 Oct 2015 14:37:10 -0700 Subject: [PATCH 03/25] Lint: remove trailing whitespace --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf8a2d676b4..188b09d4898 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10992,7 +10992,7 @@ namespace ts { function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags): NodeFlags { let flags = getCombinedNodeFlags(n); - + // children of classes (even ambient classes) should not be marked as ambient or export // because those flags have no useful semantics there. if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && From 12b7a998e9a22c811994a23ca4480c8ce5a3f78a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 6 Oct 2015 09:47:16 -0700 Subject: [PATCH 04/25] Add test case --- .../reference/moduleMergeConstructor.js | 38 +++++++++++++++ .../reference/moduleMergeConstructor.symbols | 45 ++++++++++++++++++ .../reference/moduleMergeConstructor.types | 47 +++++++++++++++++++ .../cases/compiler/moduleMergeConstructor.ts | 26 ++++++++++ 4 files changed, 156 insertions(+) create mode 100644 tests/baselines/reference/moduleMergeConstructor.js create mode 100644 tests/baselines/reference/moduleMergeConstructor.symbols create mode 100644 tests/baselines/reference/moduleMergeConstructor.types create mode 100644 tests/cases/compiler/moduleMergeConstructor.ts diff --git a/tests/baselines/reference/moduleMergeConstructor.js b/tests/baselines/reference/moduleMergeConstructor.js new file mode 100644 index 00000000000..9922a4c06ae --- /dev/null +++ b/tests/baselines/reference/moduleMergeConstructor.js @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/moduleMergeConstructor.ts] //// + +//// [foo.d.ts] + +declare module "foo" { + export class Foo { + // constructor(): Foo; + method1(): any; + } +} + +//// [foo-ext.d.ts] +declare module "foo" { + export interface Foo { + method2(): any; + } +} + +//// [index.ts] +import * as foo from "foo"; + +class Test { + bar: foo.Foo; + constructor() { + this.bar = new foo.Foo(); + } +} + + +//// [index.js] +define(["require", "exports", "foo"], function (require, exports, foo) { + var Test = (function () { + function Test() { + this.bar = new foo.Foo(); + } + return Test; + })(); +}); diff --git a/tests/baselines/reference/moduleMergeConstructor.symbols b/tests/baselines/reference/moduleMergeConstructor.symbols new file mode 100644 index 00000000000..2cea885f8c2 --- /dev/null +++ b/tests/baselines/reference/moduleMergeConstructor.symbols @@ -0,0 +1,45 @@ +=== tests/cases/compiler/foo.d.ts === + +declare module "foo" { + export class Foo { +>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + + // constructor(): Foo; + method1(): any; +>method1 : Symbol(method1, Decl(foo.d.ts, 2, 22)) + } +} + +=== tests/cases/compiler/foo-ext.d.ts === +declare module "foo" { + export interface Foo { +>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + + method2(): any; +>method2 : Symbol(method2, Decl(foo-ext.d.ts, 1, 26)) + } +} + +=== tests/cases/compiler/index.ts === +import * as foo from "foo"; +>foo : Symbol(foo, Decl(index.ts, 0, 6)) + +class Test { +>Test : Symbol(Test, Decl(index.ts, 0, 27)) + + bar: foo.Foo; +>bar : Symbol(bar, Decl(index.ts, 2, 12)) +>foo : Symbol(foo, Decl(index.ts, 0, 6)) +>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + + constructor() { + this.bar = new foo.Foo(); +>this.bar : Symbol(bar, Decl(index.ts, 2, 12)) +>this : Symbol(Test, Decl(index.ts, 0, 27)) +>bar : Symbol(bar, Decl(index.ts, 2, 12)) +>foo.Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) +>foo : Symbol(foo, Decl(index.ts, 0, 6)) +>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) + } +} + diff --git a/tests/baselines/reference/moduleMergeConstructor.types b/tests/baselines/reference/moduleMergeConstructor.types new file mode 100644 index 00000000000..bec91285f03 --- /dev/null +++ b/tests/baselines/reference/moduleMergeConstructor.types @@ -0,0 +1,47 @@ +=== tests/cases/compiler/foo.d.ts === + +declare module "foo" { + export class Foo { +>Foo : Foo + + // constructor(): Foo; + method1(): any; +>method1 : () => any + } +} + +=== tests/cases/compiler/foo-ext.d.ts === +declare module "foo" { + export interface Foo { +>Foo : Foo + + method2(): any; +>method2 : () => any + } +} + +=== tests/cases/compiler/index.ts === +import * as foo from "foo"; +>foo : typeof foo + +class Test { +>Test : Test + + bar: foo.Foo; +>bar : foo.Foo +>foo : any +>Foo : foo.Foo + + constructor() { + this.bar = new foo.Foo(); +>this.bar = new foo.Foo() : foo.Foo +>this.bar : foo.Foo +>this : this +>bar : foo.Foo +>new foo.Foo() : foo.Foo +>foo.Foo : typeof foo.Foo +>foo : typeof foo +>Foo : typeof foo.Foo + } +} + diff --git a/tests/cases/compiler/moduleMergeConstructor.ts b/tests/cases/compiler/moduleMergeConstructor.ts new file mode 100644 index 00000000000..cb312ba6327 --- /dev/null +++ b/tests/cases/compiler/moduleMergeConstructor.ts @@ -0,0 +1,26 @@ +// @module: amd + +// @filename: foo.d.ts +declare module "foo" { + export class Foo { + // constructor(): Foo; + method1(): any; + } +} + +// @filename: foo-ext.d.ts +declare module "foo" { + export interface Foo { + method2(): any; + } +} + +// @filename: index.ts +import * as foo from "foo"; + +class Test { + bar: foo.Foo; + constructor() { + this.bar = new foo.Foo(); + } +} From e964cb10ca56e81cf8daa2f2a1a019f66087781f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 14 Oct 2015 12:16:14 -0700 Subject: [PATCH 05/25] Make constructor use merged parent symbol Previously in getSignatureFromDeclaration, it just used the parent symbol without checking whether it was merged. --- src/compiler/checker.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fe203ac52c9..cd1574fa581 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3679,7 +3679,9 @@ namespace ts { function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature { let links = getNodeLinks(declaration); if (!links.resolvedSignature) { - let classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface((declaration.parent).symbol) : undefined; + let classType = declaration.kind === SyntaxKind.Constructor ? + getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent).symbol)) + : undefined; let typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; let parameters: Symbol[] = []; From c66bbd8cea670d7cc5533f1d5d542bff72374ad0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 14 Oct 2015 12:43:56 -0700 Subject: [PATCH 06/25] Tests now correctly include a constructor --- tests/baselines/reference/moduleMergeConstructor.js | 2 +- tests/baselines/reference/moduleMergeConstructor.symbols | 4 ++-- tests/baselines/reference/moduleMergeConstructor.types | 2 +- tests/cases/compiler/moduleMergeConstructor.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/moduleMergeConstructor.js b/tests/baselines/reference/moduleMergeConstructor.js index 9922a4c06ae..f47e5791117 100644 --- a/tests/baselines/reference/moduleMergeConstructor.js +++ b/tests/baselines/reference/moduleMergeConstructor.js @@ -4,7 +4,7 @@ declare module "foo" { export class Foo { - // constructor(): Foo; + constructor(); method1(): any; } } diff --git a/tests/baselines/reference/moduleMergeConstructor.symbols b/tests/baselines/reference/moduleMergeConstructor.symbols index 2cea885f8c2..a960ad07e7e 100644 --- a/tests/baselines/reference/moduleMergeConstructor.symbols +++ b/tests/baselines/reference/moduleMergeConstructor.symbols @@ -4,9 +4,9 @@ declare module "foo" { export class Foo { >Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22)) - // constructor(): Foo; + constructor(); method1(): any; ->method1 : Symbol(method1, Decl(foo.d.ts, 2, 22)) +>method1 : Symbol(method1, Decl(foo.d.ts, 3, 22)) } } diff --git a/tests/baselines/reference/moduleMergeConstructor.types b/tests/baselines/reference/moduleMergeConstructor.types index bec91285f03..48a2f010293 100644 --- a/tests/baselines/reference/moduleMergeConstructor.types +++ b/tests/baselines/reference/moduleMergeConstructor.types @@ -4,7 +4,7 @@ declare module "foo" { export class Foo { >Foo : Foo - // constructor(): Foo; + constructor(); method1(): any; >method1 : () => any } diff --git a/tests/cases/compiler/moduleMergeConstructor.ts b/tests/cases/compiler/moduleMergeConstructor.ts index cb312ba6327..018dc867df6 100644 --- a/tests/cases/compiler/moduleMergeConstructor.ts +++ b/tests/cases/compiler/moduleMergeConstructor.ts @@ -3,7 +3,7 @@ // @filename: foo.d.ts declare module "foo" { export class Foo { - // constructor(): Foo; + constructor(); method1(): any; } } From 6798bd576bcc9a4c5c8f8fd8d25cd53a55ad085a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 15 Oct 2015 09:45:38 -0700 Subject: [PATCH 07/25] Primitives are not assignable to any-type indexers `string/numberIndexTypesRelatedTo` needs to prevent primitives from being assignable to an indexer of type 'any'. However, these two functions take an apparent type, which no longer has the primitive flag set. I thought of three ways to provide this information: 1. Pass the original type into `string/numberIndexTypesRelatedTo` and check its flag. 2. Record a boolean `isPrimitive` before converting to the apparent type, and pass it to `string/numberIndexTypesRelatedTo`. 3. Create a helper function `isPrimitive` that takes the apparent type and compares it to globalString/Number/Boolean/ESSymbolType. I decided on (1) because it seems like the simplest and safest. But none of the options are elegant. Please suggest improvements. --- src/compiler/checker.ts | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b13520cee2d..20ef9160333 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4895,7 +4895,7 @@ namespace ts { if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Intersection) && target.flags & TypeFlags.ObjectType) { // Report structural errors only if we haven't reported any errors yet let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; - if (result = objectTypeRelatedTo(apparentType, target, reportStructuralErrors)) { + if (result = objectTypeRelatedTo(apparentType, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } @@ -4917,7 +4917,7 @@ namespace ts { return result; } } - return objectTypeRelatedTo(source, target, /*reportErrors*/ false); + return objectTypeRelatedTo(source, source, target, /*reportErrors*/ false); } if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { return typeParameterIdenticalTo(source, target); @@ -5071,11 +5071,11 @@ namespace ts { // Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are // equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion // and issue an error. Otherwise, actually compare the structure of the two types. - function objectTypeRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary { + function objectTypeRelatedTo(apparentSource: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { if (overflow) { return Ternary.False; } - let id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; + let id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id; let related = relation[id]; if (related !== undefined) { // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate @@ -5102,28 +5102,28 @@ namespace ts { maybeStack = []; expandingFlags = 0; } - sourceStack[depth] = source; + sourceStack[depth] = apparentSource; targetStack[depth] = target; maybeStack[depth] = {}; maybeStack[depth][id] = RelationComparisonResult.Succeeded; depth++; let saveExpandingFlags = expandingFlags; - if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth)) expandingFlags |= 1; + if (!(expandingFlags & 1) && isDeeplyNestedGeneric(apparentSource, sourceStack, depth)) expandingFlags |= 1; if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth)) expandingFlags |= 2; let result: Ternary; if (expandingFlags === 3) { result = Ternary.Maybe; } else { - result = propertiesRelatedTo(source, target, reportErrors); + result = propertiesRelatedTo(apparentSource, target, reportErrors); if (result) { - result &= signaturesRelatedTo(source, target, SignatureKind.Call, reportErrors); + result &= signaturesRelatedTo(apparentSource, target, SignatureKind.Call, reportErrors); if (result) { - result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors); + result &= signaturesRelatedTo(apparentSource, target, SignatureKind.Construct, reportErrors); if (result) { - result &= stringIndexTypesRelatedTo(source, target, reportErrors); + result &= stringIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); if (result) { - result &= numberIndexTypesRelatedTo(source, target, reportErrors); + result &= numberIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); } } } @@ -5454,12 +5454,17 @@ namespace ts { return result; } - function stringIndexTypesRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary { + function stringIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.String, source, target); } let targetType = getIndexTypeOfType(target, IndexKind.String); - if (targetType && !(targetType.flags & TypeFlags.Any)) { + if (targetType) { + if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + // non-primitive assignment to any is always allowed, eg + // `var x: { [index: string]: any } = { property: 12 };` + return Ternary.True; + } let sourceType = getIndexTypeOfType(source, IndexKind.String); if (!sourceType) { if (reportErrors) { @@ -5479,12 +5484,17 @@ namespace ts { return Ternary.True; } - function numberIndexTypesRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary { + function numberIndexTypesRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary { if (relation === identityRelation) { return indexTypesIdenticalTo(IndexKind.Number, source, target); } let targetType = getIndexTypeOfType(target, IndexKind.Number); - if (targetType && !(targetType.flags & TypeFlags.Any)) { + if (targetType) { + if ((targetType.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive)) { + // non-primitive assignment to any is always allowed, eg + // `var x: { [index: number]: any } = { property: 12 };` + return Ternary.True; + } let sourceStringType = getIndexTypeOfType(source, IndexKind.String); let sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); if (!(sourceStringType || sourceNumberType)) { From 8eacd41ab0300259c4837702e0dfddf22bd22e8a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 15 Oct 2015 09:52:31 -0700 Subject: [PATCH 08/25] Add tests and accept baselines --- .../baselines/reference/assignmentCompat1.errors.txt | 10 +++++++++- tests/baselines/reference/assignmentCompat1.js | 5 +++++ tests/baselines/reference/indexTypeCheck.errors.txt | 5 ++++- tests/baselines/reference/intTypeCheck.errors.txt | 12 +++++++++++- tests/cases/compiler/assignmentCompat1.ts | 3 +++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/assignmentCompat1.errors.txt b/tests/baselines/reference/assignmentCompat1.errors.txt index edb8d28eecc..93afdbe1bcb 100644 --- a/tests/baselines/reference/assignmentCompat1.errors.txt +++ b/tests/baselines/reference/assignmentCompat1.errors.txt @@ -2,9 +2,11 @@ tests/cases/compiler/assignmentCompat1.ts(4,1): error TS2322: Type '{ [index: st Property 'one' is missing in type '{ [index: string]: any; }'. tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. Property 'one' is missing in type '{ [index: number]: any; }'. +tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'. + Index signature is missing in type 'String'. -==== tests/cases/compiler/assignmentCompat1.ts (2 errors) ==== +==== tests/cases/compiler/assignmentCompat1.ts (3 errors) ==== var x = { one: 1 }; var y: { [index: string]: any }; var z: { [index: number]: any }; @@ -18,4 +20,10 @@ tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: nu !!! error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. !!! error TS2322: Property 'one' is missing in type '{ [index: number]: any; }'. z = x; // Ok because index signature type is any + y = "foo"; // Error + ~ +!!! error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'. +!!! error TS2322: Index signature is missing in type 'String'. + z = "foo"; // Error + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompat1.js b/tests/baselines/reference/assignmentCompat1.js index 740a44cced4..a873c24c567 100644 --- a/tests/baselines/reference/assignmentCompat1.js +++ b/tests/baselines/reference/assignmentCompat1.js @@ -6,6 +6,9 @@ x = y; // Error y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any +y = "foo"; // Error +z = "foo"; // Error + //// [assignmentCompat1.js] @@ -16,3 +19,5 @@ x = y; // Error y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any +y = "foo"; // Error +z = "foo"; // Error diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 2ea5a2f413a..06b844f8321 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -1,13 +1,14 @@ tests/cases/compiler/indexTypeCheck.ts(2,2): error TS1021: An index signature must have a type annotation. tests/cases/compiler/indexTypeCheck.ts(3,2): error TS1021: An index signature must have a type annotation. tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. +tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/compiler/indexTypeCheck.ts (7 errors) ==== +==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ==== interface Red { [n:number]; // ok ~~~~~~~~~~~ @@ -36,6 +37,8 @@ tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression interface Green { [n:number]: Orange; // error + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. [s:string]: Yellow; // ok } diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 7f1cc88e2a2..e48d1b1dc73 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -30,6 +30,8 @@ tests/cases/compiler/intTypeCheck.ts(134,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(134,22): error TS2304: Cannot find name 'i3'. tests/cases/compiler/intTypeCheck.ts(135,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. + Index signature is missing in type 'Boolean'. tests/cases/compiler/intTypeCheck.ts(148,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(148,22): error TS2304: Cannot find name 'i4'. tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -66,12 +68,14 @@ tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(190,22): error TS2304: Cannot find name 'i7'. tests/cases/compiler/intTypeCheck.ts(191,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. + Index signature is missing in type 'Boolean'. tests/cases/compiler/intTypeCheck.ts(204,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(204,22): error TS2304: Cannot find name 'i8'. tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -==== tests/cases/compiler/intTypeCheck.ts (61 errors) ==== +==== tests/cases/compiler/intTypeCheck.ts (63 errors) ==== interface i1 { //Property Signatures p; @@ -280,6 +284,9 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit //var obj40: i4 = function foo() { }; var obj41: i4 = anyVar; var obj42: i4 = new anyVar; + ~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'i4'. +!!! error TS2322: Index signature is missing in type 'Boolean'. ~ !!! error TS1109: Expression expected. ~~ @@ -402,6 +409,9 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit //var obj84: i8 = function foo() { }; var obj85: i8 = anyVar; var obj86: i8 = new anyVar; + ~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'i8'. +!!! error TS2322: Index signature is missing in type 'Boolean'. ~ !!! error TS1109: Expression expected. ~~ diff --git a/tests/cases/compiler/assignmentCompat1.ts b/tests/cases/compiler/assignmentCompat1.ts index b37a11b20d9..54dc91adab0 100644 --- a/tests/cases/compiler/assignmentCompat1.ts +++ b/tests/cases/compiler/assignmentCompat1.ts @@ -5,3 +5,6 @@ x = y; // Error y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any +y = "foo"; // Error +z = "foo"; // Error + From 5cd0ca19af72f1cdeebf16e3310bf746a567afce Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 15 Oct 2015 11:04:36 -0700 Subject: [PATCH 09/25] Add test case, correct existing test case Existing: String assignment to a numeric indexer should succeed, not fail. (The baseline was already correct but the inline comment was wrong.) New: Boolean assignment to a numeric indexer should fail. --- tests/baselines/reference/assignmentCompat1.errors.txt | 10 ++++++++-- tests/baselines/reference/assignmentCompat1.js | 6 ++++-- tests/cases/compiler/assignmentCompat1.ts | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/assignmentCompat1.errors.txt b/tests/baselines/reference/assignmentCompat1.errors.txt index 93afdbe1bcb..7539af92887 100644 --- a/tests/baselines/reference/assignmentCompat1.errors.txt +++ b/tests/baselines/reference/assignmentCompat1.errors.txt @@ -4,9 +4,11 @@ tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: nu Property 'one' is missing in type '{ [index: number]: any; }'. tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'. Index signature is missing in type 'String'. +tests/cases/compiler/assignmentCompat1.ts(10,1): error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'. + Index signature is missing in type 'Boolean'. -==== tests/cases/compiler/assignmentCompat1.ts (3 errors) ==== +==== tests/cases/compiler/assignmentCompat1.ts (4 errors) ==== var x = { one: 1 }; var y: { [index: string]: any }; var z: { [index: number]: any }; @@ -24,6 +26,10 @@ tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is n ~ !!! error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'. !!! error TS2322: Index signature is missing in type 'String'. - z = "foo"; // Error + z = "foo"; // OK, string has numeric indexer + z = false; // Error + ~ +!!! error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'. +!!! error TS2322: Index signature is missing in type 'Boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompat1.js b/tests/baselines/reference/assignmentCompat1.js index a873c24c567..7451d342fa1 100644 --- a/tests/baselines/reference/assignmentCompat1.js +++ b/tests/baselines/reference/assignmentCompat1.js @@ -7,7 +7,8 @@ y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any y = "foo"; // Error -z = "foo"; // Error +z = "foo"; // OK, string has numeric indexer +z = false; // Error @@ -20,4 +21,5 @@ y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any y = "foo"; // Error -z = "foo"; // Error +z = "foo"; // OK, string has numeric indexer +z = false; // Error diff --git a/tests/cases/compiler/assignmentCompat1.ts b/tests/cases/compiler/assignmentCompat1.ts index 54dc91adab0..e93da76d95e 100644 --- a/tests/cases/compiler/assignmentCompat1.ts +++ b/tests/cases/compiler/assignmentCompat1.ts @@ -6,5 +6,6 @@ y = x; // Ok because index signature type is any x = z; // Error z = x; // Ok because index signature type is any y = "foo"; // Error -z = "foo"; // Error +z = "foo"; // OK, string has numeric indexer +z = false; // Error From 35a303ac01e43ec59ff425aec1427413d046e6e7 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 16 Oct 2015 10:50:56 -0700 Subject: [PATCH 10/25] Do not report errors for classes and interfaces merging --- src/compiler/checker.ts | 15 --- src/compiler/diagnosticMessages.json | 4 - .../reference/augmentedTypesClass2.errors.txt | 8 +- .../augmentedTypesInterface.errors.txt | 8 +- .../classAbstractMergedDeclaration.errors.txt | 14 +- .../classAndInterfaceWithSameName.errors.txt | 14 +- .../reference/clinterfaces.errors.txt | 52 -------- .../baselines/reference/clinterfaces.symbols | 52 ++++++++ tests/baselines/reference/clinterfaces.types | 52 ++++++++ .../baselines/reference/declInput.errors.txt | 19 --- tests/baselines/reference/declInput.symbols | 28 ++++ tests/baselines/reference/declInput.types | 38 ++++++ .../defaultExportsCannotMerge03.errors.txt | 5 +- ...ifiersAcrossContainerBoundaries.errors.txt | 8 +- ...IdentifiersAcrossFileBoundaries.errors.txt | 16 +-- .../reference/interfaceClassMerging.js | 76 +++++++++++ .../reference/interfaceClassMerging.symbols | 113 ++++++++++++++++ .../reference/interfaceClassMerging.types | 124 ++++++++++++++++++ .../reference/interfaceClassMerging2.js | 66 ++++++++++ .../reference/interfaceClassMerging2.symbols | 76 +++++++++++ .../reference/interfaceClassMerging2.types | 83 ++++++++++++ .../interfaceDeclaration2.errors.txt | 22 ---- .../reference/interfaceDeclaration2.symbols | 26 ++++ .../reference/interfaceDeclaration2.types | 26 ++++ .../reference/mergedClassInterface.errors.txt | 67 ---------- .../reference/mergedClassInterface.symbols | 96 ++++++++++++++ .../reference/mergedClassInterface.types | 96 ++++++++++++++ .../reference/nameCollisions.errors.txt | 14 +- ...tringsArrayTypeDefinedInES5Mode.errors.txt | 5 +- ...ingsArrayTypeRedefinedInES6Mode.errors.txt | 5 +- tests/cases/compiler/interfaceClassMerging.ts | 39 ++++++ .../cases/compiler/interfaceClassMerging2.ts | 35 +++++ 32 files changed, 1037 insertions(+), 265 deletions(-) delete mode 100644 tests/baselines/reference/clinterfaces.errors.txt create mode 100644 tests/baselines/reference/clinterfaces.symbols create mode 100644 tests/baselines/reference/clinterfaces.types delete mode 100644 tests/baselines/reference/declInput.errors.txt create mode 100644 tests/baselines/reference/declInput.symbols create mode 100644 tests/baselines/reference/declInput.types create mode 100644 tests/baselines/reference/interfaceClassMerging.js create mode 100644 tests/baselines/reference/interfaceClassMerging.symbols create mode 100644 tests/baselines/reference/interfaceClassMerging.types create mode 100644 tests/baselines/reference/interfaceClassMerging2.js create mode 100644 tests/baselines/reference/interfaceClassMerging2.symbols create mode 100644 tests/baselines/reference/interfaceClassMerging2.types delete mode 100644 tests/baselines/reference/interfaceDeclaration2.errors.txt create mode 100644 tests/baselines/reference/interfaceDeclaration2.symbols create mode 100644 tests/baselines/reference/interfaceDeclaration2.types delete mode 100644 tests/baselines/reference/mergedClassInterface.errors.txt create mode 100644 tests/baselines/reference/mergedClassInterface.symbols create mode 100644 tests/baselines/reference/mergedClassInterface.types create mode 100644 tests/cases/compiler/interfaceClassMerging.ts create mode 100644 tests/cases/compiler/interfaceClassMerging2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b13520cee2d..bccc47d56a2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12874,11 +12874,6 @@ namespace ts { } checkClassLikeDeclaration(node); - // Interfaces cannot be merged with non-ambient classes. - if (getSymbolOfNode(node).flags & SymbolFlags.Interface && !isInAmbientContext(node)) { - error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface); - } - forEach(node.members, checkSourceElement); } @@ -13164,16 +13159,6 @@ namespace ts { checkIndexConstraints(type); } } - - // Interfaces cannot merge with non-ambient classes. - if (symbol && symbol.declarations) { - for (let declaration of symbol.declarations) { - if (declaration.kind === SyntaxKind.ClassDeclaration && !isInAmbientContext(declaration)) { - error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface); - break; - } - } - } } forEach(getInterfaceBaseTypeNodes(node), heritageElement => { if (!isSupportedExpressionWithTypeArguments(heritageElement)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a8ed6ac6127..b2c1e6f0d5e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1620,10 +1620,6 @@ "category": "Error", "code":2517 }, - "Only an ambient class can be merged with an interface.": { - "category": "Error", - "code": 2518 - }, "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": { "category": "Error", "code": 2520 diff --git a/tests/baselines/reference/augmentedTypesClass2.errors.txt b/tests/baselines/reference/augmentedTypesClass2.errors.txt index 278dca816fa..7a203f06e90 100644 --- a/tests/baselines/reference/augmentedTypesClass2.errors.txt +++ b/tests/baselines/reference/augmentedTypesClass2.errors.txt @@ -1,24 +1,18 @@ -tests/cases/compiler/augmentedTypesClass2.ts(4,7): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/augmentedTypesClass2.ts(10,11): error TS2518: Only an ambient class can be merged with an interface. tests/cases/compiler/augmentedTypesClass2.ts(16,7): error TS2300: Duplicate identifier 'c33'. tests/cases/compiler/augmentedTypesClass2.ts(21,6): error TS2300: Duplicate identifier 'c33'. -==== tests/cases/compiler/augmentedTypesClass2.ts (4 errors) ==== +==== tests/cases/compiler/augmentedTypesClass2.ts (2 errors) ==== // Checking class with other things in type space not value space // class then interface class c11 { // error - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. foo() { return 1; } } interface c11 { // error - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. bar(): void; } diff --git a/tests/baselines/reference/augmentedTypesInterface.errors.txt b/tests/baselines/reference/augmentedTypesInterface.errors.txt index 690bf8b7a99..534cba43ba1 100644 --- a/tests/baselines/reference/augmentedTypesInterface.errors.txt +++ b/tests/baselines/reference/augmentedTypesInterface.errors.txt @@ -1,10 +1,8 @@ -tests/cases/compiler/augmentedTypesInterface.ts(12,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/augmentedTypesInterface.ts(16,7): error TS2518: Only an ambient class can be merged with an interface. tests/cases/compiler/augmentedTypesInterface.ts(23,11): error TS2300: Duplicate identifier 'i3'. tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate identifier 'i3'. -==== tests/cases/compiler/augmentedTypesInterface.ts (4 errors) ==== +==== tests/cases/compiler/augmentedTypesInterface.ts (2 errors) ==== // interface then interface interface i { @@ -17,14 +15,10 @@ tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate i // interface then class interface i2 { // error - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. foo(): void; } class i2 { // error - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. bar() { return 1; } diff --git a/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt b/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt index b3a2dec5e9c..3e18d8796fb 100644 --- a/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt +++ b/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt @@ -1,7 +1,3 @@ -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(7,16): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(8,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(10,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(11,16): error TS2518: Only an ambient class can be merged with an interface. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(13,16): error TS2300: Duplicate identifier 'CC1'. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(14,7): error TS2300: Duplicate identifier 'CC1'. tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(16,7): error TS2300: Duplicate identifier 'CC2'. @@ -20,7 +16,7 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(39,1): error TS2511: Cannot create an instance of the abstract class 'DCC1'. -==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (20 errors) ==== +==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (16 errors) ==== abstract class CM {} module CM {} @@ -28,18 +24,10 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst abstract class MC {} abstract class CI {} - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. interface CI {} - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. interface IC {} - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. abstract class IC {} - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. abstract class CC1 {} ~~~ diff --git a/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt b/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt index 332024b74fd..62f1e6c71f7 100644 --- a/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt +++ b/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt @@ -1,37 +1,25 @@ -tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,7): error TS2518: Only an ambient class can be merged with an interface. tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,11): error TS2300: Duplicate identifier 'foo'. -tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,11): error TS2518: Only an ambient class can be merged with an interface. tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,15): error TS2300: Duplicate identifier 'foo'. -tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(5,11): error TS2518: Only an ambient class can be merged with an interface. tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(6,9): error TS2300: Duplicate identifier 'bar'. -tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(9,15): error TS2518: Only an ambient class can be merged with an interface. tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(10,9): error TS2300: Duplicate identifier 'bar'. -==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (8 errors) ==== +==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (4 errors) ==== class C { foo: string; } - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. ~~~ !!! error TS2300: Duplicate identifier 'foo'. interface C { foo: string; } // error - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. ~~~ !!! error TS2300: Duplicate identifier 'foo'. module M { class D { - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. bar: string; ~~~ !!! error TS2300: Duplicate identifier 'bar'. } interface D { // error - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. bar: string; ~~~ !!! error TS2300: Duplicate identifier 'bar'. diff --git a/tests/baselines/reference/clinterfaces.errors.txt b/tests/baselines/reference/clinterfaces.errors.txt deleted file mode 100644 index 5960e6ae32b..00000000000 --- a/tests/baselines/reference/clinterfaces.errors.txt +++ /dev/null @@ -1,52 +0,0 @@ -tests/cases/compiler/clinterfaces.ts(2,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/clinterfaces.ts(3,15): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/clinterfaces.ts(4,15): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/clinterfaces.ts(5,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/clinterfaces.ts(8,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/clinterfaces.ts(12,7): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/clinterfaces.ts(16,7): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/clinterfaces.ts(20,11): error TS2518: Only an ambient class can be merged with an interface. - - -==== tests/cases/compiler/clinterfaces.ts (8 errors) ==== - module M { - class C { } - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. - interface C { } - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. - interface D { } - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. - class D { } - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. - } - - interface Foo { - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - a: string; - } - - class Foo{ - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - b: number; - } - - class Bar{ - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - b: number; - } - - interface Bar { - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - a: string; - } - - export = Foo; - \ No newline at end of file diff --git a/tests/baselines/reference/clinterfaces.symbols b/tests/baselines/reference/clinterfaces.symbols new file mode 100644 index 00000000000..76c7d74b521 --- /dev/null +++ b/tests/baselines/reference/clinterfaces.symbols @@ -0,0 +1,52 @@ +=== tests/cases/compiler/clinterfaces.ts === +module M { +>M : Symbol(M, Decl(clinterfaces.ts, 0, 0)) + + class C { } +>C : Symbol(C, Decl(clinterfaces.ts, 0, 10), Decl(clinterfaces.ts, 1, 15)) + + interface C { } +>C : Symbol(C, Decl(clinterfaces.ts, 0, 10), Decl(clinterfaces.ts, 1, 15)) + + interface D { } +>D : Symbol(D, Decl(clinterfaces.ts, 2, 19), Decl(clinterfaces.ts, 3, 19)) + + class D { } +>D : Symbol(D, Decl(clinterfaces.ts, 2, 19), Decl(clinterfaces.ts, 3, 19)) +} + +interface Foo { +>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1)) +>T : Symbol(T, Decl(clinterfaces.ts, 7, 14), Decl(clinterfaces.ts, 11, 10)) + + a: string; +>a : Symbol(a, Decl(clinterfaces.ts, 7, 18)) +} + +class Foo{ +>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1)) +>T : Symbol(T, Decl(clinterfaces.ts, 7, 14), Decl(clinterfaces.ts, 11, 10)) + + b: number; +>b : Symbol(b, Decl(clinterfaces.ts, 11, 13)) +} + +class Bar{ +>Bar : Symbol(Bar, Decl(clinterfaces.ts, 13, 1), Decl(clinterfaces.ts, 17, 1)) +>T : Symbol(T, Decl(clinterfaces.ts, 15, 10), Decl(clinterfaces.ts, 19, 14)) + + b: number; +>b : Symbol(b, Decl(clinterfaces.ts, 15, 13)) +} + +interface Bar { +>Bar : Symbol(Bar, Decl(clinterfaces.ts, 13, 1), Decl(clinterfaces.ts, 17, 1)) +>T : Symbol(T, Decl(clinterfaces.ts, 15, 10), Decl(clinterfaces.ts, 19, 14)) + + a: string; +>a : Symbol(a, Decl(clinterfaces.ts, 19, 18)) +} + +export = Foo; +>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1)) + diff --git a/tests/baselines/reference/clinterfaces.types b/tests/baselines/reference/clinterfaces.types new file mode 100644 index 00000000000..18c27f33e55 --- /dev/null +++ b/tests/baselines/reference/clinterfaces.types @@ -0,0 +1,52 @@ +=== tests/cases/compiler/clinterfaces.ts === +module M { +>M : typeof M + + class C { } +>C : C + + interface C { } +>C : C + + interface D { } +>D : D + + class D { } +>D : D +} + +interface Foo { +>Foo : Foo +>T : T + + a: string; +>a : string +} + +class Foo{ +>Foo : Foo +>T : T + + b: number; +>b : number +} + +class Bar{ +>Bar : Bar +>T : T + + b: number; +>b : number +} + +interface Bar { +>Bar : Bar +>T : T + + a: string; +>a : string +} + +export = Foo; +>Foo : Foo + diff --git a/tests/baselines/reference/declInput.errors.txt b/tests/baselines/reference/declInput.errors.txt deleted file mode 100644 index 179db3598ab..00000000000 --- a/tests/baselines/reference/declInput.errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -tests/cases/compiler/declInput.ts(1,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/declInput.ts(5,7): error TS2518: Only an ambient class can be merged with an interface. - - -==== tests/cases/compiler/declInput.ts (2 errors) ==== - interface bar { - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - - } - - class bar { - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - public f() { return ''; } - public g() { return {a: null, b: undefined, c: void 4 }; } - public h(x = 4, y = null, z = '') { x++; } - } - \ No newline at end of file diff --git a/tests/baselines/reference/declInput.symbols b/tests/baselines/reference/declInput.symbols new file mode 100644 index 00000000000..90f075218c0 --- /dev/null +++ b/tests/baselines/reference/declInput.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/declInput.ts === +interface bar { +>bar : Symbol(bar, Decl(declInput.ts, 0, 0), Decl(declInput.ts, 2, 1)) + +} + +class bar { +>bar : Symbol(bar, Decl(declInput.ts, 0, 0), Decl(declInput.ts, 2, 1)) + + public f() { return ''; } +>f : Symbol(f, Decl(declInput.ts, 4, 11)) + + public g() { return {a: null, b: undefined, c: void 4 }; } +>g : Symbol(g, Decl(declInput.ts, 5, 27)) +>a : Symbol(a, Decl(declInput.ts, 6, 23)) +>bar : Symbol(bar, Decl(declInput.ts, 0, 0), Decl(declInput.ts, 2, 1)) +>b : Symbol(b, Decl(declInput.ts, 6, 36)) +>undefined : Symbol(undefined) +>c : Symbol(c, Decl(declInput.ts, 6, 50)) + + public h(x = 4, y = null, z = '') { x++; } +>h : Symbol(h, Decl(declInput.ts, 6, 65)) +>x : Symbol(x, Decl(declInput.ts, 7, 11)) +>y : Symbol(y, Decl(declInput.ts, 7, 17)) +>z : Symbol(z, Decl(declInput.ts, 7, 27)) +>x : Symbol(x, Decl(declInput.ts, 7, 11)) +} + diff --git a/tests/baselines/reference/declInput.types b/tests/baselines/reference/declInput.types new file mode 100644 index 00000000000..e59e3811fdf --- /dev/null +++ b/tests/baselines/reference/declInput.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/declInput.ts === +interface bar { +>bar : bar + +} + +class bar { +>bar : bar + + public f() { return ''; } +>f : () => string +>'' : string + + public g() { return {a: null, b: undefined, c: void 4 }; } +>g : () => { a: bar; b: any; c: any; } +>{a: null, b: undefined, c: void 4 } : { a: bar; b: undefined; c: undefined; } +>a : bar +>null : bar +>bar : bar +>null : null +>b : undefined +>undefined : undefined +>c : undefined +>void 4 : undefined +>4 : number + + public h(x = 4, y = null, z = '') { x++; } +>h : (x?: number, y?: any, z?: string) => void +>x : number +>4 : number +>y : any +>null : null +>z : string +>'' : string +>x++ : number +>x : number +} + diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt index 11e9c63b893..e8782abedd6 100644 --- a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt +++ b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt @@ -1,10 +1,9 @@ tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. -tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2518: Only an ambient class can be merged with an interface. tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. tests/cases/conformance/es6/modules/m2.ts(1,20): error TS2307: Cannot find module 'm1'. -==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== export default class Decl { ~~~~ @@ -13,8 +12,6 @@ tests/cases/conformance/es6/modules/m2.ts(1,20): error TS2307: Cannot find modul interface Decl { ~~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - ~~~~ !!! error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. p1: number; p2: number; diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt index 731e9748203..ed4c23bdd60 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt +++ b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt @@ -1,21 +1,15 @@ -tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(2,22): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(5,18): error TS2518: Only an ambient class can be merged with an interface. tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(9,21): error TS2300: Duplicate identifier 'f'. tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(12,18): error TS2300: Duplicate identifier 'f'. tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(37,12): error TS2300: Duplicate identifier 'x'. tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(41,16): error TS2300: Duplicate identifier 'x'. -==== tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts (6 errors) ==== +==== tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts (4 errors) ==== module M { export interface I { } - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. } module M { export class I { } // error - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. } module M { diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt index 9867441f770..db7d0205fc9 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt +++ b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt @@ -1,24 +1,16 @@ -tests/cases/compiler/file1.ts(2,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/file1.ts(3,7): error TS2518: Only an ambient class can be merged with an interface. tests/cases/compiler/file1.ts(4,7): error TS2300: Duplicate identifier 'C2'. tests/cases/compiler/file1.ts(5,10): error TS2300: Duplicate identifier 'f'. tests/cases/compiler/file1.ts(9,12): error TS2300: Duplicate identifier 'x'. -tests/cases/compiler/file2.ts(1,7): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/file2.ts(2,11): error TS2518: Only an ambient class can be merged with an interface. tests/cases/compiler/file2.ts(3,10): error TS2300: Duplicate identifier 'C2'. tests/cases/compiler/file2.ts(4,7): error TS2300: Duplicate identifier 'f'. tests/cases/compiler/file2.ts(7,8): error TS2433: A namespace declaration cannot be in a different file from a class or function with which it is merged tests/cases/compiler/file2.ts(8,16): error TS2300: Duplicate identifier 'x'. -==== tests/cases/compiler/file1.ts (5 errors) ==== +==== tests/cases/compiler/file1.ts (3 errors) ==== interface I { } - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. class C1 { } - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. class C2 { } ~~ !!! error TS2300: Duplicate identifier 'C2'. @@ -39,13 +31,9 @@ tests/cases/compiler/file2.ts(8,16): error TS2300: Duplicate identifier 'x'. } } -==== tests/cases/compiler/file2.ts (6 errors) ==== +==== tests/cases/compiler/file2.ts (4 errors) ==== class I { } // error -- cannot merge interface with non-ambient class - ~ -!!! error TS2518: Only an ambient class can be merged with an interface. interface C1 { } // error -- cannot merge interface with non-ambient class - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. function C2() { } // error -- cannot merge function with non-ambient class ~~ !!! error TS2300: Duplicate identifier 'C2'. diff --git a/tests/baselines/reference/interfaceClassMerging.js b/tests/baselines/reference/interfaceClassMerging.js new file mode 100644 index 00000000000..565884e95ef --- /dev/null +++ b/tests/baselines/reference/interfaceClassMerging.js @@ -0,0 +1,76 @@ +//// [interfaceClassMerging.ts] +interface Foo { + method(a: number): string; + optionalMethod?(a: number): string; + property: string; + optionalProperty?: string; +} + +class Foo { + additionalProperty: string; + + additionalMethod(a: number): string { + return this.method(0); + } +} + +class Bar extends Foo { + method(a: number) { + return this.optionalProperty; + } +} + + +var bar = new Bar(); +bar.method(0); +bar.optionalMethod(1); +bar.property; +bar.optionalProperty; +bar.additionalProperty; +bar.additionalMethod(2); + +var obj: { + method(a: number): string; + property: string; + additionalProperty: string; + additionalMethod(a: number): string; +}; + +bar = obj; +obj = bar; + + +//// [interfaceClassMerging.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Foo = (function () { + function Foo() { + } + Foo.prototype.additionalMethod = function (a) { + return this.method(0); + }; + return Foo; +})(); +var Bar = (function (_super) { + __extends(Bar, _super); + function Bar() { + _super.apply(this, arguments); + } + Bar.prototype.method = function (a) { + return this.optionalProperty; + }; + return Bar; +})(Foo); +var bar = new Bar(); +bar.method(0); +bar.optionalMethod(1); +bar.property; +bar.optionalProperty; +bar.additionalProperty; +bar.additionalMethod(2); +var obj; +bar = obj; +obj = bar; diff --git a/tests/baselines/reference/interfaceClassMerging.symbols b/tests/baselines/reference/interfaceClassMerging.symbols new file mode 100644 index 00000000000..eda94cedafd --- /dev/null +++ b/tests/baselines/reference/interfaceClassMerging.symbols @@ -0,0 +1,113 @@ +=== tests/cases/compiler/interfaceClassMerging.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(interfaceClassMerging.ts, 0, 0), Decl(interfaceClassMerging.ts, 5, 1)) + + method(a: number): string; +>method : Symbol(method, Decl(interfaceClassMerging.ts, 0, 15)) +>a : Symbol(a, Decl(interfaceClassMerging.ts, 1, 11)) + + optionalMethod?(a: number): string; +>optionalMethod : Symbol(optionalMethod, Decl(interfaceClassMerging.ts, 1, 30)) +>a : Symbol(a, Decl(interfaceClassMerging.ts, 2, 20)) + + property: string; +>property : Symbol(property, Decl(interfaceClassMerging.ts, 2, 39)) + + optionalProperty?: string; +>optionalProperty : Symbol(optionalProperty, Decl(interfaceClassMerging.ts, 3, 21)) +} + +class Foo { +>Foo : Symbol(Foo, Decl(interfaceClassMerging.ts, 0, 0), Decl(interfaceClassMerging.ts, 5, 1)) + + additionalProperty: string; +>additionalProperty : Symbol(additionalProperty, Decl(interfaceClassMerging.ts, 7, 11)) + + additionalMethod(a: number): string { +>additionalMethod : Symbol(additionalMethod, Decl(interfaceClassMerging.ts, 8, 31)) +>a : Symbol(a, Decl(interfaceClassMerging.ts, 10, 21)) + + return this.method(0); +>this.method : Symbol(method, Decl(interfaceClassMerging.ts, 0, 15)) +>this : Symbol(Foo, Decl(interfaceClassMerging.ts, 0, 0), Decl(interfaceClassMerging.ts, 5, 1)) +>method : Symbol(method, Decl(interfaceClassMerging.ts, 0, 15)) + } +} + +class Bar extends Foo { +>Bar : Symbol(Bar, Decl(interfaceClassMerging.ts, 13, 1)) +>Foo : Symbol(Foo, Decl(interfaceClassMerging.ts, 0, 0), Decl(interfaceClassMerging.ts, 5, 1)) + + method(a: number) { +>method : Symbol(method, Decl(interfaceClassMerging.ts, 15, 23)) +>a : Symbol(a, Decl(interfaceClassMerging.ts, 16, 11)) + + return this.optionalProperty; +>this.optionalProperty : Symbol(Foo.optionalProperty, Decl(interfaceClassMerging.ts, 3, 21)) +>this : Symbol(Bar, Decl(interfaceClassMerging.ts, 13, 1)) +>optionalProperty : Symbol(Foo.optionalProperty, Decl(interfaceClassMerging.ts, 3, 21)) + } +} + + +var bar = new Bar(); +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>Bar : Symbol(Bar, Decl(interfaceClassMerging.ts, 13, 1)) + +bar.method(0); +>bar.method : Symbol(Bar.method, Decl(interfaceClassMerging.ts, 15, 23)) +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>method : Symbol(Bar.method, Decl(interfaceClassMerging.ts, 15, 23)) + +bar.optionalMethod(1); +>bar.optionalMethod : Symbol(Foo.optionalMethod, Decl(interfaceClassMerging.ts, 1, 30)) +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>optionalMethod : Symbol(Foo.optionalMethod, Decl(interfaceClassMerging.ts, 1, 30)) + +bar.property; +>bar.property : Symbol(Foo.property, Decl(interfaceClassMerging.ts, 2, 39)) +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>property : Symbol(Foo.property, Decl(interfaceClassMerging.ts, 2, 39)) + +bar.optionalProperty; +>bar.optionalProperty : Symbol(Foo.optionalProperty, Decl(interfaceClassMerging.ts, 3, 21)) +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>optionalProperty : Symbol(Foo.optionalProperty, Decl(interfaceClassMerging.ts, 3, 21)) + +bar.additionalProperty; +>bar.additionalProperty : Symbol(Foo.additionalProperty, Decl(interfaceClassMerging.ts, 7, 11)) +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>additionalProperty : Symbol(Foo.additionalProperty, Decl(interfaceClassMerging.ts, 7, 11)) + +bar.additionalMethod(2); +>bar.additionalMethod : Symbol(Foo.additionalMethod, Decl(interfaceClassMerging.ts, 8, 31)) +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>additionalMethod : Symbol(Foo.additionalMethod, Decl(interfaceClassMerging.ts, 8, 31)) + +var obj: { +>obj : Symbol(obj, Decl(interfaceClassMerging.ts, 30, 3)) + + method(a: number): string; +>method : Symbol(method, Decl(interfaceClassMerging.ts, 30, 10)) +>a : Symbol(a, Decl(interfaceClassMerging.ts, 31, 11)) + + property: string; +>property : Symbol(property, Decl(interfaceClassMerging.ts, 31, 30)) + + additionalProperty: string; +>additionalProperty : Symbol(additionalProperty, Decl(interfaceClassMerging.ts, 32, 21)) + + additionalMethod(a: number): string; +>additionalMethod : Symbol(additionalMethod, Decl(interfaceClassMerging.ts, 33, 31)) +>a : Symbol(a, Decl(interfaceClassMerging.ts, 34, 21)) + +}; + +bar = obj; +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) +>obj : Symbol(obj, Decl(interfaceClassMerging.ts, 30, 3)) + +obj = bar; +>obj : Symbol(obj, Decl(interfaceClassMerging.ts, 30, 3)) +>bar : Symbol(bar, Decl(interfaceClassMerging.ts, 22, 3)) + diff --git a/tests/baselines/reference/interfaceClassMerging.types b/tests/baselines/reference/interfaceClassMerging.types new file mode 100644 index 00000000000..0b17005c868 --- /dev/null +++ b/tests/baselines/reference/interfaceClassMerging.types @@ -0,0 +1,124 @@ +=== tests/cases/compiler/interfaceClassMerging.ts === +interface Foo { +>Foo : Foo + + method(a: number): string; +>method : (a: number) => string +>a : number + + optionalMethod?(a: number): string; +>optionalMethod : (a: number) => string +>a : number + + property: string; +>property : string + + optionalProperty?: string; +>optionalProperty : string +} + +class Foo { +>Foo : Foo + + additionalProperty: string; +>additionalProperty : string + + additionalMethod(a: number): string { +>additionalMethod : (a: number) => string +>a : number + + return this.method(0); +>this.method(0) : string +>this.method : (a: number) => string +>this : this +>method : (a: number) => string +>0 : number + } +} + +class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + method(a: number) { +>method : (a: number) => string +>a : number + + return this.optionalProperty; +>this.optionalProperty : string +>this : this +>optionalProperty : string + } +} + + +var bar = new Bar(); +>bar : Bar +>new Bar() : Bar +>Bar : typeof Bar + +bar.method(0); +>bar.method(0) : string +>bar.method : (a: number) => string +>bar : Bar +>method : (a: number) => string +>0 : number + +bar.optionalMethod(1); +>bar.optionalMethod(1) : string +>bar.optionalMethod : (a: number) => string +>bar : Bar +>optionalMethod : (a: number) => string +>1 : number + +bar.property; +>bar.property : string +>bar : Bar +>property : string + +bar.optionalProperty; +>bar.optionalProperty : string +>bar : Bar +>optionalProperty : string + +bar.additionalProperty; +>bar.additionalProperty : string +>bar : Bar +>additionalProperty : string + +bar.additionalMethod(2); +>bar.additionalMethod(2) : string +>bar.additionalMethod : (a: number) => string +>bar : Bar +>additionalMethod : (a: number) => string +>2 : number + +var obj: { +>obj : { method(a: number): string; property: string; additionalProperty: string; additionalMethod(a: number): string; } + + method(a: number): string; +>method : (a: number) => string +>a : number + + property: string; +>property : string + + additionalProperty: string; +>additionalProperty : string + + additionalMethod(a: number): string; +>additionalMethod : (a: number) => string +>a : number + +}; + +bar = obj; +>bar = obj : { method(a: number): string; property: string; additionalProperty: string; additionalMethod(a: number): string; } +>bar : Bar +>obj : { method(a: number): string; property: string; additionalProperty: string; additionalMethod(a: number): string; } + +obj = bar; +>obj = bar : Bar +>obj : { method(a: number): string; property: string; additionalProperty: string; additionalMethod(a: number): string; } +>bar : Bar + diff --git a/tests/baselines/reference/interfaceClassMerging2.js b/tests/baselines/reference/interfaceClassMerging2.js new file mode 100644 index 00000000000..66146e29684 --- /dev/null +++ b/tests/baselines/reference/interfaceClassMerging2.js @@ -0,0 +1,66 @@ +//// [interfaceClassMerging2.ts] +interface Foo { + interfaceFooMethod(): this; + interfaceFooProperty: this; +} + +class Foo { + classFooProperty: this; + + classFooMethod(): this { + return this; + } +} + + +interface Bar { + interfaceBarMethod(): this; + interfaceBarProperty: this; +} + +class Bar extends Foo { + classBarProperty: this; + + classBarMethod(): this { + return this; + } +} + + +var bar = new Bar(); +bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); + + +var foo = new Foo(); + +foo = bar; + + +//// [interfaceClassMerging2.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Foo = (function () { + function Foo() { + } + Foo.prototype.classFooMethod = function () { + return this; + }; + return Foo; +})(); +var Bar = (function (_super) { + __extends(Bar, _super); + function Bar() { + _super.apply(this, arguments); + } + Bar.prototype.classBarMethod = function () { + return this; + }; + return Bar; +})(Foo); +var bar = new Bar(); +bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +var foo = new Foo(); +foo = bar; diff --git a/tests/baselines/reference/interfaceClassMerging2.symbols b/tests/baselines/reference/interfaceClassMerging2.symbols new file mode 100644 index 00000000000..98949cc5461 --- /dev/null +++ b/tests/baselines/reference/interfaceClassMerging2.symbols @@ -0,0 +1,76 @@ +=== tests/cases/compiler/interfaceClassMerging2.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(interfaceClassMerging2.ts, 0, 0), Decl(interfaceClassMerging2.ts, 3, 1)) + + interfaceFooMethod(): this; +>interfaceFooMethod : Symbol(interfaceFooMethod, Decl(interfaceClassMerging2.ts, 0, 15)) + + interfaceFooProperty: this; +>interfaceFooProperty : Symbol(interfaceFooProperty, Decl(interfaceClassMerging2.ts, 1, 31)) +} + +class Foo { +>Foo : Symbol(Foo, Decl(interfaceClassMerging2.ts, 0, 0), Decl(interfaceClassMerging2.ts, 3, 1)) + + classFooProperty: this; +>classFooProperty : Symbol(classFooProperty, Decl(interfaceClassMerging2.ts, 5, 11)) + + classFooMethod(): this { +>classFooMethod : Symbol(classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) + + return this; +>this : Symbol(Foo, Decl(interfaceClassMerging2.ts, 0, 0), Decl(interfaceClassMerging2.ts, 3, 1)) + } +} + + +interface Bar { +>Bar : Symbol(Bar, Decl(interfaceClassMerging2.ts, 11, 1), Decl(interfaceClassMerging2.ts, 17, 1)) + + interfaceBarMethod(): this; +>interfaceBarMethod : Symbol(interfaceBarMethod, Decl(interfaceClassMerging2.ts, 14, 15)) + + interfaceBarProperty: this; +>interfaceBarProperty : Symbol(interfaceBarProperty, Decl(interfaceClassMerging2.ts, 15, 31)) +} + +class Bar extends Foo { +>Bar : Symbol(Bar, Decl(interfaceClassMerging2.ts, 11, 1), Decl(interfaceClassMerging2.ts, 17, 1)) +>Foo : Symbol(Foo, Decl(interfaceClassMerging2.ts, 0, 0), Decl(interfaceClassMerging2.ts, 3, 1)) + + classBarProperty: this; +>classBarProperty : Symbol(classBarProperty, Decl(interfaceClassMerging2.ts, 19, 23)) + + classBarMethod(): this { +>classBarMethod : Symbol(classBarMethod, Decl(interfaceClassMerging2.ts, 20, 27)) + + return this; +>this : Symbol(Bar, Decl(interfaceClassMerging2.ts, 11, 1), Decl(interfaceClassMerging2.ts, 17, 1)) + } +} + + +var bar = new Bar(); +>bar : Symbol(bar, Decl(interfaceClassMerging2.ts, 28, 3)) +>Bar : Symbol(Bar, Decl(interfaceClassMerging2.ts, 11, 1), Decl(interfaceClassMerging2.ts, 17, 1)) + +bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +>bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) +>bar.classFooMethod().interfaceFooMethod().classBarMethod : Symbol(Bar.classBarMethod, Decl(interfaceClassMerging2.ts, 20, 27)) +>bar.classFooMethod().interfaceFooMethod : Symbol(Foo.interfaceFooMethod, Decl(interfaceClassMerging2.ts, 0, 15)) +>bar.classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) +>bar : Symbol(bar, Decl(interfaceClassMerging2.ts, 28, 3)) +>classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) +>interfaceFooMethod : Symbol(Foo.interfaceFooMethod, Decl(interfaceClassMerging2.ts, 0, 15)) +>classBarMethod : Symbol(Bar.classBarMethod, Decl(interfaceClassMerging2.ts, 20, 27)) +>classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) + + +var foo = new Foo(); +>foo : Symbol(foo, Decl(interfaceClassMerging2.ts, 32, 3)) +>Foo : Symbol(Foo, Decl(interfaceClassMerging2.ts, 0, 0), Decl(interfaceClassMerging2.ts, 3, 1)) + +foo = bar; +>foo : Symbol(foo, Decl(interfaceClassMerging2.ts, 32, 3)) +>bar : Symbol(bar, Decl(interfaceClassMerging2.ts, 28, 3)) + diff --git a/tests/baselines/reference/interfaceClassMerging2.types b/tests/baselines/reference/interfaceClassMerging2.types new file mode 100644 index 00000000000..127777cb70c --- /dev/null +++ b/tests/baselines/reference/interfaceClassMerging2.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/interfaceClassMerging2.ts === +interface Foo { +>Foo : Foo + + interfaceFooMethod(): this; +>interfaceFooMethod : () => this + + interfaceFooProperty: this; +>interfaceFooProperty : this +} + +class Foo { +>Foo : Foo + + classFooProperty: this; +>classFooProperty : this + + classFooMethod(): this { +>classFooMethod : () => this + + return this; +>this : this + } +} + + +interface Bar { +>Bar : Bar + + interfaceBarMethod(): this; +>interfaceBarMethod : () => this + + interfaceBarProperty: this; +>interfaceBarProperty : this +} + +class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + classBarProperty: this; +>classBarProperty : this + + classBarMethod(): this { +>classBarMethod : () => this + + return this; +>this : this + } +} + + +var bar = new Bar(); +>bar : Bar +>new Bar() : Bar +>Bar : typeof Bar + +bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +>bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod() : Bar +>bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod : () => Bar +>bar.classFooMethod().interfaceFooMethod().classBarMethod() : Bar +>bar.classFooMethod().interfaceFooMethod().classBarMethod : () => Bar +>bar.classFooMethod().interfaceFooMethod() : Bar +>bar.classFooMethod().interfaceFooMethod : () => Bar +>bar.classFooMethod() : Bar +>bar.classFooMethod : () => Bar +>bar : Bar +>classFooMethod : () => Bar +>interfaceFooMethod : () => Bar +>classBarMethod : () => Bar +>classFooMethod : () => Bar + + +var foo = new Foo(); +>foo : Foo +>new Foo() : Foo +>Foo : typeof Foo + +foo = bar; +>foo = bar : Bar +>foo : Foo +>bar : Bar + diff --git a/tests/baselines/reference/interfaceDeclaration2.errors.txt b/tests/baselines/reference/interfaceDeclaration2.errors.txt deleted file mode 100644 index db525e6f21f..00000000000 --- a/tests/baselines/reference/interfaceDeclaration2.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/compiler/interfaceDeclaration2.ts(4,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/interfaceDeclaration2.ts(5,7): error TS2518: Only an ambient class can be merged with an interface. - - -==== tests/cases/compiler/interfaceDeclaration2.ts (2 errors) ==== - interface I1 { } - module I1 { } - - interface I2 { } - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - class I2 { } - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - - interface I3 { } - function I3() { } - - interface I4 { } - var I4:number; - - \ No newline at end of file diff --git a/tests/baselines/reference/interfaceDeclaration2.symbols b/tests/baselines/reference/interfaceDeclaration2.symbols new file mode 100644 index 00000000000..e8588107355 --- /dev/null +++ b/tests/baselines/reference/interfaceDeclaration2.symbols @@ -0,0 +1,26 @@ +=== tests/cases/compiler/interfaceDeclaration2.ts === +interface I1 { } +>I1 : Symbol(I1, Decl(interfaceDeclaration2.ts, 0, 0), Decl(interfaceDeclaration2.ts, 0, 16)) + +module I1 { } +>I1 : Symbol(I1, Decl(interfaceDeclaration2.ts, 0, 0), Decl(interfaceDeclaration2.ts, 0, 16)) + +interface I2 { } +>I2 : Symbol(I2, Decl(interfaceDeclaration2.ts, 1, 13), Decl(interfaceDeclaration2.ts, 3, 16)) + +class I2 { } +>I2 : Symbol(I2, Decl(interfaceDeclaration2.ts, 1, 13), Decl(interfaceDeclaration2.ts, 3, 16)) + +interface I3 { } +>I3 : Symbol(I3, Decl(interfaceDeclaration2.ts, 4, 12), Decl(interfaceDeclaration2.ts, 6, 16)) + +function I3() { } +>I3 : Symbol(I3, Decl(interfaceDeclaration2.ts, 4, 12), Decl(interfaceDeclaration2.ts, 6, 16)) + +interface I4 { } +>I4 : Symbol(I4, Decl(interfaceDeclaration2.ts, 7, 17), Decl(interfaceDeclaration2.ts, 10, 3)) + +var I4:number; +>I4 : Symbol(I4, Decl(interfaceDeclaration2.ts, 7, 17), Decl(interfaceDeclaration2.ts, 10, 3)) + + diff --git a/tests/baselines/reference/interfaceDeclaration2.types b/tests/baselines/reference/interfaceDeclaration2.types new file mode 100644 index 00000000000..78e7a990ee6 --- /dev/null +++ b/tests/baselines/reference/interfaceDeclaration2.types @@ -0,0 +1,26 @@ +=== tests/cases/compiler/interfaceDeclaration2.ts === +interface I1 { } +>I1 : I1 + +module I1 { } +>I1 : any + +interface I2 { } +>I2 : I2 + +class I2 { } +>I2 : I2 + +interface I3 { } +>I3 : I3 + +function I3() { } +>I3 : () => void + +interface I4 { } +>I4 : I4 + +var I4:number; +>I4 : number + + diff --git a/tests/baselines/reference/mergedClassInterface.errors.txt b/tests/baselines/reference/mergedClassInterface.errors.txt deleted file mode 100644 index 5b23b046db7..00000000000 --- a/tests/baselines/reference/mergedClassInterface.errors.txt +++ /dev/null @@ -1,67 +0,0 @@ -tests/cases/conformance/classes/classDeclarations/file1.ts(11,7): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/conformance/classes/classDeclarations/file1.ts(13,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/conformance/classes/classDeclarations/file1.ts(15,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/conformance/classes/classDeclarations/file1.ts(17,7): error TS2518: Only an ambient class can be merged with an interface. - - -==== tests/cases/conformance/classes/classDeclarations/file1.ts (4 errors) ==== - - - declare class C1 { } - - interface C1 { } - - interface C2 { } - - declare class C2 { } - - class C3 { } // error -- cannot merge non-ambient class and interface - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - - interface C3 { } // error -- cannot merge non-ambient class and interface - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - - interface C4 { } // error -- cannot merge non-ambient class and interface - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - - class C4 { } // error -- cannot merge non-ambient class and interface - ~~ -!!! error TS2518: Only an ambient class can be merged with an interface. - - interface C5 { - x1: number; - } - - declare class C5 { - x2: number; - } - - interface C5 { - x3: number; - } - - interface C5 { - x4: number; - } - - // checks if properties actually were merged - var c5 : C5; - c5.x1; - c5.x2; - c5.x3; - c5.x4; - -==== tests/cases/conformance/classes/classDeclarations/file2.ts (0 errors) ==== - - declare class C6 { } - - interface C7 { } - -==== tests/cases/conformance/classes/classDeclarations/file3.ts (0 errors) ==== - - interface C6 { } - - declare class C7 { } \ No newline at end of file diff --git a/tests/baselines/reference/mergedClassInterface.symbols b/tests/baselines/reference/mergedClassInterface.symbols new file mode 100644 index 00000000000..9e886eaa4d8 --- /dev/null +++ b/tests/baselines/reference/mergedClassInterface.symbols @@ -0,0 +1,96 @@ +=== tests/cases/conformance/classes/classDeclarations/file1.ts === + + +declare class C1 { } +>C1 : Symbol(C1, Decl(file1.ts, 0, 0), Decl(file1.ts, 2, 20)) + +interface C1 { } +>C1 : Symbol(C1, Decl(file1.ts, 0, 0), Decl(file1.ts, 2, 20)) + +interface C2 { } +>C2 : Symbol(C2, Decl(file1.ts, 4, 16), Decl(file1.ts, 6, 16)) + +declare class C2 { } +>C2 : Symbol(C2, Decl(file1.ts, 4, 16), Decl(file1.ts, 6, 16)) + +class C3 { } // error -- cannot merge non-ambient class and interface +>C3 : Symbol(C3, Decl(file1.ts, 8, 20), Decl(file1.ts, 10, 12)) + +interface C3 { } // error -- cannot merge non-ambient class and interface +>C3 : Symbol(C3, Decl(file1.ts, 8, 20), Decl(file1.ts, 10, 12)) + +interface C4 { } // error -- cannot merge non-ambient class and interface +>C4 : Symbol(C4, Decl(file1.ts, 12, 16), Decl(file1.ts, 14, 16)) + +class C4 { } // error -- cannot merge non-ambient class and interface +>C4 : Symbol(C4, Decl(file1.ts, 12, 16), Decl(file1.ts, 14, 16)) + +interface C5 { +>C5 : Symbol(C5, Decl(file1.ts, 16, 12), Decl(file1.ts, 20, 1), Decl(file1.ts, 24, 1), Decl(file1.ts, 28, 1)) + + x1: number; +>x1 : Symbol(x1, Decl(file1.ts, 18, 14)) +} + +declare class C5 { +>C5 : Symbol(C5, Decl(file1.ts, 16, 12), Decl(file1.ts, 20, 1), Decl(file1.ts, 24, 1), Decl(file1.ts, 28, 1)) + + x2: number; +>x2 : Symbol(x2, Decl(file1.ts, 22, 18)) +} + +interface C5 { +>C5 : Symbol(C5, Decl(file1.ts, 16, 12), Decl(file1.ts, 20, 1), Decl(file1.ts, 24, 1), Decl(file1.ts, 28, 1)) + + x3: number; +>x3 : Symbol(x3, Decl(file1.ts, 26, 14)) +} + +interface C5 { +>C5 : Symbol(C5, Decl(file1.ts, 16, 12), Decl(file1.ts, 20, 1), Decl(file1.ts, 24, 1), Decl(file1.ts, 28, 1)) + + x4: number; +>x4 : Symbol(x4, Decl(file1.ts, 30, 14)) +} + +// checks if properties actually were merged +var c5 : C5; +>c5 : Symbol(c5, Decl(file1.ts, 35, 3)) +>C5 : Symbol(C5, Decl(file1.ts, 16, 12), Decl(file1.ts, 20, 1), Decl(file1.ts, 24, 1), Decl(file1.ts, 28, 1)) + +c5.x1; +>c5.x1 : Symbol(C5.x1, Decl(file1.ts, 18, 14)) +>c5 : Symbol(c5, Decl(file1.ts, 35, 3)) +>x1 : Symbol(C5.x1, Decl(file1.ts, 18, 14)) + +c5.x2; +>c5.x2 : Symbol(C5.x2, Decl(file1.ts, 22, 18)) +>c5 : Symbol(c5, Decl(file1.ts, 35, 3)) +>x2 : Symbol(C5.x2, Decl(file1.ts, 22, 18)) + +c5.x3; +>c5.x3 : Symbol(C5.x3, Decl(file1.ts, 26, 14)) +>c5 : Symbol(c5, Decl(file1.ts, 35, 3)) +>x3 : Symbol(C5.x3, Decl(file1.ts, 26, 14)) + +c5.x4; +>c5.x4 : Symbol(C5.x4, Decl(file1.ts, 30, 14)) +>c5 : Symbol(c5, Decl(file1.ts, 35, 3)) +>x4 : Symbol(C5.x4, Decl(file1.ts, 30, 14)) + +=== tests/cases/conformance/classes/classDeclarations/file2.ts === + +declare class C6 { } +>C6 : Symbol(C6, Decl(file2.ts, 0, 0), Decl(file3.ts, 0, 0)) + +interface C7 { } +>C7 : Symbol(C7, Decl(file2.ts, 1, 20), Decl(file3.ts, 1, 16)) + +=== tests/cases/conformance/classes/classDeclarations/file3.ts === + +interface C6 { } +>C6 : Symbol(C6, Decl(file2.ts, 0, 0), Decl(file3.ts, 0, 0)) + +declare class C7 { } +>C7 : Symbol(C7, Decl(file2.ts, 1, 20), Decl(file3.ts, 1, 16)) + diff --git a/tests/baselines/reference/mergedClassInterface.types b/tests/baselines/reference/mergedClassInterface.types new file mode 100644 index 00000000000..0e75434a5b1 --- /dev/null +++ b/tests/baselines/reference/mergedClassInterface.types @@ -0,0 +1,96 @@ +=== tests/cases/conformance/classes/classDeclarations/file1.ts === + + +declare class C1 { } +>C1 : C1 + +interface C1 { } +>C1 : C1 + +interface C2 { } +>C2 : C2 + +declare class C2 { } +>C2 : C2 + +class C3 { } // error -- cannot merge non-ambient class and interface +>C3 : C3 + +interface C3 { } // error -- cannot merge non-ambient class and interface +>C3 : C3 + +interface C4 { } // error -- cannot merge non-ambient class and interface +>C4 : C4 + +class C4 { } // error -- cannot merge non-ambient class and interface +>C4 : C4 + +interface C5 { +>C5 : C5 + + x1: number; +>x1 : number +} + +declare class C5 { +>C5 : C5 + + x2: number; +>x2 : number +} + +interface C5 { +>C5 : C5 + + x3: number; +>x3 : number +} + +interface C5 { +>C5 : C5 + + x4: number; +>x4 : number +} + +// checks if properties actually were merged +var c5 : C5; +>c5 : C5 +>C5 : C5 + +c5.x1; +>c5.x1 : number +>c5 : C5 +>x1 : number + +c5.x2; +>c5.x2 : number +>c5 : C5 +>x2 : number + +c5.x3; +>c5.x3 : number +>c5 : C5 +>x3 : number + +c5.x4; +>c5.x4 : number +>c5 : C5 +>x4 : number + +=== tests/cases/conformance/classes/classDeclarations/file2.ts === + +declare class C6 { } +>C6 : C6 + +interface C7 { } +>C7 : C7 + +=== tests/cases/conformance/classes/classDeclarations/file3.ts === + +interface C6 { } +>C6 : C6 + +declare class C7 { } +>C7 : C7 + diff --git a/tests/baselines/reference/nameCollisions.errors.txt b/tests/baselines/reference/nameCollisions.errors.txt index 5c32d464070..5977b039847 100644 --- a/tests/baselines/reference/nameCollisions.errors.txt +++ b/tests/baselines/reference/nameCollisions.errors.txt @@ -11,13 +11,9 @@ tests/cases/compiler/nameCollisions.ts(33,11): error TS2300: Duplicate identifie tests/cases/compiler/nameCollisions.ts(34,14): error TS2300: Duplicate identifier 'C'. tests/cases/compiler/nameCollisions.ts(36,14): error TS2300: Duplicate identifier 'C2'. tests/cases/compiler/nameCollisions.ts(37,11): error TS2300: Duplicate identifier 'C2'. -tests/cases/compiler/nameCollisions.ts(42,11): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/nameCollisions.ts(43,15): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/nameCollisions.ts(45,15): error TS2518: Only an ambient class can be merged with an interface. -tests/cases/compiler/nameCollisions.ts(46,11): error TS2518: Only an ambient class can be merged with an interface. -==== tests/cases/compiler/nameCollisions.ts (17 errors) ==== +==== tests/cases/compiler/nameCollisions.ts (13 errors) ==== module T { var x = 2; ~ @@ -86,16 +82,8 @@ tests/cases/compiler/nameCollisions.ts(46,11): error TS2518: Only an ambient cla interface fi { } // ok class cli { } - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. interface cli { } // error - ~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. interface cli2 { } - ~~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. class cli2 { } // error - ~~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index 69d686c3156..94ab5028647 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -1,13 +1,10 @@ -tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2518: Only an ambient class can be merged with an interface. tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{}'. -==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (2 errors) ==== +==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (1 errors) ==== class TemplateStringsArray { - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. } function f(x: TemplateStringsArray, y: number, z: number) { diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt index 02ccd7f2413..f410d408482 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt @@ -1,13 +1,10 @@ -tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(2,7): error TS2518: Only an ambient class can be merged with an interface. tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'. Property 'raw' is missing in type '{}'. -==== tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts (2 errors) ==== +==== tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts (1 errors) ==== class TemplateStringsArray { - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2518: Only an ambient class can be merged with an interface. } function f(x: TemplateStringsArray, y: number, z: number) { diff --git a/tests/cases/compiler/interfaceClassMerging.ts b/tests/cases/compiler/interfaceClassMerging.ts new file mode 100644 index 00000000000..266dc35b1e5 --- /dev/null +++ b/tests/cases/compiler/interfaceClassMerging.ts @@ -0,0 +1,39 @@ +interface Foo { + method(a: number): string; + optionalMethod?(a: number): string; + property: string; + optionalProperty?: string; +} + +class Foo { + additionalProperty: string; + + additionalMethod(a: number): string { + return this.method(0); + } +} + +class Bar extends Foo { + method(a: number) { + return this.optionalProperty; + } +} + + +var bar = new Bar(); +bar.method(0); +bar.optionalMethod(1); +bar.property; +bar.optionalProperty; +bar.additionalProperty; +bar.additionalMethod(2); + +var obj: { + method(a: number): string; + property: string; + additionalProperty: string; + additionalMethod(a: number): string; +}; + +bar = obj; +obj = bar; diff --git a/tests/cases/compiler/interfaceClassMerging2.ts b/tests/cases/compiler/interfaceClassMerging2.ts new file mode 100644 index 00000000000..cd32a93c988 --- /dev/null +++ b/tests/cases/compiler/interfaceClassMerging2.ts @@ -0,0 +1,35 @@ +interface Foo { + interfaceFooMethod(): this; + interfaceFooProperty: this; +} + +class Foo { + classFooProperty: this; + + classFooMethod(): this { + return this; + } +} + + +interface Bar { + interfaceBarMethod(): this; + interfaceBarProperty: this; +} + +class Bar extends Foo { + classBarProperty: this; + + classBarMethod(): this { + return this; + } +} + + +var bar = new Bar(); +bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); + + +var foo = new Foo(); + +foo = bar; From 3749fe854d1e49196d3074032705b3f8d939bf8e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 16 Oct 2015 12:28:48 -0700 Subject: [PATCH 11/25] Bumped version to 1.8.0. --- package.json | 2 +- src/compiler/program.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 28f2c1b5755..7b8abfaae43 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.7.0", + "version": "1.8.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 86719ff30b4..d76e7585d15 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -12,7 +12,7 @@ namespace ts { let emptyArray: any[] = []; - export const version = "1.7.0"; + export const version = "1.8.0"; export function findConfigFile(searchPath: string): string { let fileName = "tsconfig.json"; From d8237dc2f39f80d75a882d8813f4d550565f46a5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 16 Oct 2015 12:31:29 -0700 Subject: [PATCH 12/25] Updated the LKG. --- lib/lib.core.es6.d.ts | 29 +- lib/lib.d.ts | 152 +- lib/lib.dom.d.ts | 152 +- lib/lib.es6.d.ts | 152 +- lib/lib.webworker.d.ts | 7 +- lib/tsc.js | 17198 +++++++++++++------------- lib/tsserver.js | 19714 +++++++++++++++-------------- lib/typescript.d.ts | 529 +- lib/typescript.js | 22508 ++++++++++++++++++---------------- lib/typescriptServices.d.ts | 529 +- lib/typescriptServices.js | 22508 ++++++++++++++++++---------------- 11 files changed, 43102 insertions(+), 40376 deletions(-) diff --git a/lib/lib.core.es6.d.ts b/lib/lib.core.es6.d.ts index fd115497f8a..6d6a68559f8 100644 --- a/lib/lib.core.es6.d.ts +++ b/lib/lib.core.es6.d.ts @@ -3965,7 +3965,34 @@ interface ObjectConstructor { * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. - * @param sources One or more source objects to copy properties from. + * @param source The source object from which to copy properties. + */ + assign(target: T, source: U): T & U; + + /** + * Copy the values of all of the enumerable own properties from one or more source objects to a + * target object. Returns the target object. + * @param target The target object to copy to. + * @param source1 The first source object from which to copy properties. + * @param source2 The second source object from which to copy properties. + */ + assign(target: T, source1: U, source2: V): T & U & V; + + /** + * Copy the values of all of the enumerable own properties from one or more source objects to a + * target object. Returns the target object. + * @param target The target object to copy to. + * @param source1 The first source object from which to copy properties. + * @param source2 The second source object from which to copy properties. + * @param source3 The third source object from which to copy properties. + */ + assign(target: T, source1: U, source2: V, source3: W): T & U & V & W; + + /** + * Copy the values of all of the enumerable own properties from one or more source objects to a + * target object. Returns the target object. + * @param target The target object to copy to. + * @param sources One or more source objects from which to copy properties */ assign(target: any, ...sources: any[]): any; diff --git a/lib/lib.d.ts b/lib/lib.d.ts index a65fc96e43f..40a29796586 100644 --- a/lib/lib.d.ts +++ b/lib/lib.d.ts @@ -4243,8 +4243,8 @@ interface AnalyserNode extends AudioNode { smoothingTimeConstant: number; getByteFrequencyData(array: Uint8Array): void; getByteTimeDomainData(array: Uint8Array): void; - getFloatFrequencyData(array: any): void; - getFloatTimeDomainData(array: any): void; + getFloatFrequencyData(array: Float32Array): void; + getFloatTimeDomainData(array: Float32Array): void; } declare var AnalyserNode: { @@ -4331,7 +4331,7 @@ interface AudioBuffer { length: number; numberOfChannels: number; sampleRate: number; - getChannelData(channel: number): any; + getChannelData(channel: number): Float32Array; } declare var AudioBuffer: { @@ -4375,7 +4375,7 @@ interface AudioContext extends EventTarget { createMediaElementSource(mediaElement: HTMLMediaElement): MediaElementAudioSourceNode; createOscillator(): OscillatorNode; createPanner(): PannerNode; - createPeriodicWave(real: any, imag: any): PeriodicWave; + createPeriodicWave(real: Float32Array, imag: Float32Array): PeriodicWave; createScriptProcessor(bufferSize?: number, numberOfInputChannels?: number, numberOfOutputChannels?: number): ScriptProcessorNode; createStereoPanner(): StereoPannerNode; createWaveShaper(): WaveShaperNode; @@ -4433,7 +4433,7 @@ interface AudioParam { linearRampToValueAtTime(value: number, endTime: number): void; setTargetAtTime(target: number, startTime: number, timeConstant: number): void; setValueAtTime(value: number, startTime: number): void; - setValueCurveAtTime(values: any, startTime: number, duration: number): void; + setValueCurveAtTime(values: Float32Array, startTime: number, duration: number): void; } declare var AudioParam: { @@ -4509,7 +4509,7 @@ interface BiquadFilterNode extends AudioNode { frequency: AudioParam; gain: AudioParam; type: string; - getFrequencyResponse(frequencyHz: any, magResponse: any, phaseResponse: any): void; + getFrequencyResponse(frequencyHz: Float32Array, magResponse: Float32Array, phaseResponse: Float32Array): void; } declare var BiquadFilterNode: { @@ -5108,7 +5108,7 @@ declare var CanvasPattern: { interface CanvasRenderingContext2D { canvas: HTMLCanvasElement; - fillStyle: any; + fillStyle: string | CanvasGradient | CanvasPattern; font: string; globalAlpha: number; globalCompositeOperation: string; @@ -5123,7 +5123,7 @@ interface CanvasRenderingContext2D { shadowColor: string; shadowOffsetX: number; shadowOffsetY: number; - strokeStyle: any; + strokeStyle: string | CanvasGradient | CanvasPattern; textAlign: string; textBaseline: string; arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void; @@ -6491,8 +6491,6 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven importNode(importedNode: Node, deep: boolean): Node; msElementsFromPoint(x: number, y: number): NodeList; msElementsFromRect(left: number, top: number, width: number, height: number): NodeList; - msGetPrintDocumentForNamedFlow(flowName: string): Document; - msSetPrintDocumentUriForNamedFlow(flowName: string, uri: string): void; /** * Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method. * @param url Specifies a MIME type for the document. @@ -11314,27 +11312,6 @@ declare var MSHTMLWebViewElement: { new(): MSHTMLWebViewElement; } -interface MSHeaderFooter { - URL: string; - dateLong: string; - dateShort: string; - font: string; - htmlFoot: string; - htmlHead: string; - page: number; - pageTotal: number; - textFoot: string; - textHead: string; - timeLong: string; - timeShort: string; - title: string; -} - -declare var MSHeaderFooter: { - prototype: MSHeaderFooter; - new(): MSHeaderFooter; -} - interface MSInputMethodContext extends EventTarget { compositionEndOffset: number; compositionStartOffset: number; @@ -11493,24 +11470,6 @@ declare var MSPointerEvent: { new(typeArg: string, eventInitDict?: PointerEventInit): MSPointerEvent; } -interface MSPrintManagerTemplatePrinter extends MSTemplatePrinter, EventTarget { - percentScale: number; - showHeaderFooter: boolean; - shrinkToFit: boolean; - drawPreviewPage(element: HTMLElement, pageNumber: number): void; - endPrint(): void; - getPrintTaskOptionValue(key: string): any; - invalidatePreview(): void; - setPageCount(pageCount: number): void; - startPrint(): void; - addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; -} - -declare var MSPrintManagerTemplatePrinter: { - prototype: MSPrintManagerTemplatePrinter; - new(): MSPrintManagerTemplatePrinter; -} - interface MSRangeCollection { length: number; item(index: number): Range; @@ -11558,63 +11517,6 @@ declare var MSStreamReader: { new(): MSStreamReader; } -interface MSTemplatePrinter { - collate: boolean; - copies: number; - currentPage: boolean; - currentPageAvail: boolean; - duplex: boolean; - footer: string; - frameActive: boolean; - frameActiveEnabled: boolean; - frameAsShown: boolean; - framesetDocument: boolean; - header: string; - headerFooterFont: string; - marginBottom: number; - marginLeft: number; - marginRight: number; - marginTop: number; - orientation: string; - pageFrom: number; - pageHeight: number; - pageTo: number; - pageWidth: number; - selectedPages: boolean; - selection: boolean; - selectionEnabled: boolean; - unprintableBottom: number; - unprintableLeft: number; - unprintableRight: number; - unprintableTop: number; - usePrinterCopyCollate: boolean; - createHeaderFooter(): MSHeaderFooter; - deviceSupports(property: string): any; - ensurePrintDialogDefaults(): boolean; - getPageMarginBottom(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginBottomImportant(pageRule: CSSPageRule): boolean; - getPageMarginLeft(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginLeftImportant(pageRule: CSSPageRule): boolean; - getPageMarginRight(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginRightImportant(pageRule: CSSPageRule): boolean; - getPageMarginTop(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginTopImportant(pageRule: CSSPageRule): boolean; - printBlankPage(): void; - printNonNative(document: any): boolean; - printNonNativeFrames(document: any, activeFrame: boolean): void; - printPage(element: HTMLElement): void; - showPageSetupDialog(): boolean; - showPrintDialog(): boolean; - startDoc(title: string): boolean; - stopDoc(): void; - updatePageStatus(status: number): void; -} - -declare var MSTemplatePrinter: { - prototype: MSTemplatePrinter; - new(): MSTemplatePrinter; -} - interface MSWebViewAsyncOperation extends EventTarget { error: DOMError; oncomplete: (ev: Event) => any; @@ -12032,6 +11934,10 @@ declare var Node: { } interface NodeFilter { + acceptNode(n: Node): number; +} + +declare var NodeFilter: { FILTER_ACCEPT: number; FILTER_REJECT: number; FILTER_SKIP: number; @@ -12049,7 +11955,6 @@ interface NodeFilter { SHOW_PROCESSING_INSTRUCTION: number; SHOW_TEXT: number; } -declare var NodeFilter: NodeFilter; interface NodeIterator { expandEntityReferences: boolean; @@ -12759,7 +12664,6 @@ declare var SVGDescElement: { interface SVGElement extends Element { id: string; - className: any; onclick: (ev: MouseEvent) => any; ondblclick: (ev: MouseEvent) => any; onfocusin: (ev: FocusEvent) => any; @@ -12773,6 +12677,7 @@ interface SVGElement extends Element { ownerSVGElement: SVGSVGElement; viewportElement: SVGElement; xmlbase: string; + className: any; addEventListener(type: "MSGestureChange", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureDoubleTap", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureEnd", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; @@ -14934,7 +14839,7 @@ declare var WEBGL_depth_texture: { } interface WaveShaperNode extends AudioNode { - curve: any; + curve: Float32Array; oversample: string; } @@ -15121,34 +15026,34 @@ interface WebGLRenderingContext { texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; - uniform1fv(location: WebGLUniformLocation, v: any): void; + uniform1fv(location: WebGLUniformLocation, v: Float32Array): void; uniform1i(location: WebGLUniformLocation, x: number): void; uniform1iv(location: WebGLUniformLocation, v: Int32Array): void; uniform2f(location: WebGLUniformLocation, x: number, y: number): void; - uniform2fv(location: WebGLUniformLocation, v: any): void; + uniform2fv(location: WebGLUniformLocation, v: Float32Array): void; uniform2i(location: WebGLUniformLocation, x: number, y: number): void; uniform2iv(location: WebGLUniformLocation, v: Int32Array): void; uniform3f(location: WebGLUniformLocation, x: number, y: number, z: number): void; - uniform3fv(location: WebGLUniformLocation, v: any): void; + uniform3fv(location: WebGLUniformLocation, v: Float32Array): void; uniform3i(location: WebGLUniformLocation, x: number, y: number, z: number): void; uniform3iv(location: WebGLUniformLocation, v: Int32Array): void; uniform4f(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; - uniform4fv(location: WebGLUniformLocation, v: any): void; + uniform4fv(location: WebGLUniformLocation, v: Float32Array): void; uniform4i(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; uniform4iv(location: WebGLUniformLocation, v: Int32Array): void; - uniformMatrix2fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; - uniformMatrix3fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; - uniformMatrix4fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; + uniformMatrix2fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; + uniformMatrix3fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; + uniformMatrix4fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; useProgram(program: WebGLProgram): void; validateProgram(program: WebGLProgram): void; vertexAttrib1f(indx: number, x: number): void; - vertexAttrib1fv(indx: number, values: any): void; + vertexAttrib1fv(indx: number, values: Float32Array): void; vertexAttrib2f(indx: number, x: number, y: number): void; - vertexAttrib2fv(indx: number, values: any): void; + vertexAttrib2fv(indx: number, values: Float32Array): void; vertexAttrib3f(indx: number, x: number, y: number, z: number): void; - vertexAttrib3fv(indx: number, values: any): void; + vertexAttrib3fv(indx: number, values: Float32Array): void; vertexAttrib4f(indx: number, x: number, y: number, z: number, w: number): void; - vertexAttrib4fv(indx: number, values: any): void; + vertexAttrib4fv(indx: number, values: Float32Array): void; vertexAttribPointer(indx: number, size: number, type: number, normalized: boolean, stride: number, offset: number): void; viewport(x: number, y: number, width: number, height: number): void; ACTIVE_ATTRIBUTES: number; @@ -15912,7 +15817,6 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window locationbar: BarProp; menubar: BarProp; msAnimationStartTime: number; - msTemplatePrinter: MSTemplatePrinter; name: string; navigator: Navigator; offscreenBuffering: string | boolean; @@ -16649,7 +16553,6 @@ interface XMLHttpRequestEventTarget { addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; } - interface NodeListOf extends NodeList { length: number; item(index: number): TNode; @@ -16670,8 +16573,6 @@ interface EventListenerObject { handleEvent(evt: Event): void; } -declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; - interface MessageEventInit extends EventInit { data?: any; origin?: string; @@ -16687,6 +16588,8 @@ interface ProgressEventInit extends EventInit { total?: number; } +declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; + interface ErrorEventHandler { (message: string, filename?: string, lineno?: number, colno?: number, error?:Error): void; } @@ -16747,7 +16650,6 @@ declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msAnimationStartTime: number; -declare var msTemplatePrinter: MSTemplatePrinter; declare var name: string; declare var navigator: Navigator; declare var offscreenBuffering: string | boolean; diff --git a/lib/lib.dom.d.ts b/lib/lib.dom.d.ts index 849560ac0d2..41d569ba9f7 100644 --- a/lib/lib.dom.d.ts +++ b/lib/lib.dom.d.ts @@ -419,8 +419,8 @@ interface AnalyserNode extends AudioNode { smoothingTimeConstant: number; getByteFrequencyData(array: Uint8Array): void; getByteTimeDomainData(array: Uint8Array): void; - getFloatFrequencyData(array: any): void; - getFloatTimeDomainData(array: any): void; + getFloatFrequencyData(array: Float32Array): void; + getFloatTimeDomainData(array: Float32Array): void; } declare var AnalyserNode: { @@ -507,7 +507,7 @@ interface AudioBuffer { length: number; numberOfChannels: number; sampleRate: number; - getChannelData(channel: number): any; + getChannelData(channel: number): Float32Array; } declare var AudioBuffer: { @@ -551,7 +551,7 @@ interface AudioContext extends EventTarget { createMediaElementSource(mediaElement: HTMLMediaElement): MediaElementAudioSourceNode; createOscillator(): OscillatorNode; createPanner(): PannerNode; - createPeriodicWave(real: any, imag: any): PeriodicWave; + createPeriodicWave(real: Float32Array, imag: Float32Array): PeriodicWave; createScriptProcessor(bufferSize?: number, numberOfInputChannels?: number, numberOfOutputChannels?: number): ScriptProcessorNode; createStereoPanner(): StereoPannerNode; createWaveShaper(): WaveShaperNode; @@ -609,7 +609,7 @@ interface AudioParam { linearRampToValueAtTime(value: number, endTime: number): void; setTargetAtTime(target: number, startTime: number, timeConstant: number): void; setValueAtTime(value: number, startTime: number): void; - setValueCurveAtTime(values: any, startTime: number, duration: number): void; + setValueCurveAtTime(values: Float32Array, startTime: number, duration: number): void; } declare var AudioParam: { @@ -685,7 +685,7 @@ interface BiquadFilterNode extends AudioNode { frequency: AudioParam; gain: AudioParam; type: string; - getFrequencyResponse(frequencyHz: any, magResponse: any, phaseResponse: any): void; + getFrequencyResponse(frequencyHz: Float32Array, magResponse: Float32Array, phaseResponse: Float32Array): void; } declare var BiquadFilterNode: { @@ -1284,7 +1284,7 @@ declare var CanvasPattern: { interface CanvasRenderingContext2D { canvas: HTMLCanvasElement; - fillStyle: any; + fillStyle: string | CanvasGradient | CanvasPattern; font: string; globalAlpha: number; globalCompositeOperation: string; @@ -1299,7 +1299,7 @@ interface CanvasRenderingContext2D { shadowColor: string; shadowOffsetX: number; shadowOffsetY: number; - strokeStyle: any; + strokeStyle: string | CanvasGradient | CanvasPattern; textAlign: string; textBaseline: string; arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void; @@ -2667,8 +2667,6 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven importNode(importedNode: Node, deep: boolean): Node; msElementsFromPoint(x: number, y: number): NodeList; msElementsFromRect(left: number, top: number, width: number, height: number): NodeList; - msGetPrintDocumentForNamedFlow(flowName: string): Document; - msSetPrintDocumentUriForNamedFlow(flowName: string, uri: string): void; /** * Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method. * @param url Specifies a MIME type for the document. @@ -7490,27 +7488,6 @@ declare var MSHTMLWebViewElement: { new(): MSHTMLWebViewElement; } -interface MSHeaderFooter { - URL: string; - dateLong: string; - dateShort: string; - font: string; - htmlFoot: string; - htmlHead: string; - page: number; - pageTotal: number; - textFoot: string; - textHead: string; - timeLong: string; - timeShort: string; - title: string; -} - -declare var MSHeaderFooter: { - prototype: MSHeaderFooter; - new(): MSHeaderFooter; -} - interface MSInputMethodContext extends EventTarget { compositionEndOffset: number; compositionStartOffset: number; @@ -7669,24 +7646,6 @@ declare var MSPointerEvent: { new(typeArg: string, eventInitDict?: PointerEventInit): MSPointerEvent; } -interface MSPrintManagerTemplatePrinter extends MSTemplatePrinter, EventTarget { - percentScale: number; - showHeaderFooter: boolean; - shrinkToFit: boolean; - drawPreviewPage(element: HTMLElement, pageNumber: number): void; - endPrint(): void; - getPrintTaskOptionValue(key: string): any; - invalidatePreview(): void; - setPageCount(pageCount: number): void; - startPrint(): void; - addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; -} - -declare var MSPrintManagerTemplatePrinter: { - prototype: MSPrintManagerTemplatePrinter; - new(): MSPrintManagerTemplatePrinter; -} - interface MSRangeCollection { length: number; item(index: number): Range; @@ -7734,63 +7693,6 @@ declare var MSStreamReader: { new(): MSStreamReader; } -interface MSTemplatePrinter { - collate: boolean; - copies: number; - currentPage: boolean; - currentPageAvail: boolean; - duplex: boolean; - footer: string; - frameActive: boolean; - frameActiveEnabled: boolean; - frameAsShown: boolean; - framesetDocument: boolean; - header: string; - headerFooterFont: string; - marginBottom: number; - marginLeft: number; - marginRight: number; - marginTop: number; - orientation: string; - pageFrom: number; - pageHeight: number; - pageTo: number; - pageWidth: number; - selectedPages: boolean; - selection: boolean; - selectionEnabled: boolean; - unprintableBottom: number; - unprintableLeft: number; - unprintableRight: number; - unprintableTop: number; - usePrinterCopyCollate: boolean; - createHeaderFooter(): MSHeaderFooter; - deviceSupports(property: string): any; - ensurePrintDialogDefaults(): boolean; - getPageMarginBottom(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginBottomImportant(pageRule: CSSPageRule): boolean; - getPageMarginLeft(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginLeftImportant(pageRule: CSSPageRule): boolean; - getPageMarginRight(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginRightImportant(pageRule: CSSPageRule): boolean; - getPageMarginTop(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginTopImportant(pageRule: CSSPageRule): boolean; - printBlankPage(): void; - printNonNative(document: any): boolean; - printNonNativeFrames(document: any, activeFrame: boolean): void; - printPage(element: HTMLElement): void; - showPageSetupDialog(): boolean; - showPrintDialog(): boolean; - startDoc(title: string): boolean; - stopDoc(): void; - updatePageStatus(status: number): void; -} - -declare var MSTemplatePrinter: { - prototype: MSTemplatePrinter; - new(): MSTemplatePrinter; -} - interface MSWebViewAsyncOperation extends EventTarget { error: DOMError; oncomplete: (ev: Event) => any; @@ -8208,6 +8110,10 @@ declare var Node: { } interface NodeFilter { + acceptNode(n: Node): number; +} + +declare var NodeFilter: { FILTER_ACCEPT: number; FILTER_REJECT: number; FILTER_SKIP: number; @@ -8225,7 +8131,6 @@ interface NodeFilter { SHOW_PROCESSING_INSTRUCTION: number; SHOW_TEXT: number; } -declare var NodeFilter: NodeFilter; interface NodeIterator { expandEntityReferences: boolean; @@ -8935,7 +8840,6 @@ declare var SVGDescElement: { interface SVGElement extends Element { id: string; - className: any; onclick: (ev: MouseEvent) => any; ondblclick: (ev: MouseEvent) => any; onfocusin: (ev: FocusEvent) => any; @@ -8949,6 +8853,7 @@ interface SVGElement extends Element { ownerSVGElement: SVGSVGElement; viewportElement: SVGElement; xmlbase: string; + className: any; addEventListener(type: "MSGestureChange", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureDoubleTap", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureEnd", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; @@ -11110,7 +11015,7 @@ declare var WEBGL_depth_texture: { } interface WaveShaperNode extends AudioNode { - curve: any; + curve: Float32Array; oversample: string; } @@ -11297,34 +11202,34 @@ interface WebGLRenderingContext { texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; - uniform1fv(location: WebGLUniformLocation, v: any): void; + uniform1fv(location: WebGLUniformLocation, v: Float32Array): void; uniform1i(location: WebGLUniformLocation, x: number): void; uniform1iv(location: WebGLUniformLocation, v: Int32Array): void; uniform2f(location: WebGLUniformLocation, x: number, y: number): void; - uniform2fv(location: WebGLUniformLocation, v: any): void; + uniform2fv(location: WebGLUniformLocation, v: Float32Array): void; uniform2i(location: WebGLUniformLocation, x: number, y: number): void; uniform2iv(location: WebGLUniformLocation, v: Int32Array): void; uniform3f(location: WebGLUniformLocation, x: number, y: number, z: number): void; - uniform3fv(location: WebGLUniformLocation, v: any): void; + uniform3fv(location: WebGLUniformLocation, v: Float32Array): void; uniform3i(location: WebGLUniformLocation, x: number, y: number, z: number): void; uniform3iv(location: WebGLUniformLocation, v: Int32Array): void; uniform4f(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; - uniform4fv(location: WebGLUniformLocation, v: any): void; + uniform4fv(location: WebGLUniformLocation, v: Float32Array): void; uniform4i(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; uniform4iv(location: WebGLUniformLocation, v: Int32Array): void; - uniformMatrix2fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; - uniformMatrix3fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; - uniformMatrix4fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; + uniformMatrix2fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; + uniformMatrix3fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; + uniformMatrix4fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; useProgram(program: WebGLProgram): void; validateProgram(program: WebGLProgram): void; vertexAttrib1f(indx: number, x: number): void; - vertexAttrib1fv(indx: number, values: any): void; + vertexAttrib1fv(indx: number, values: Float32Array): void; vertexAttrib2f(indx: number, x: number, y: number): void; - vertexAttrib2fv(indx: number, values: any): void; + vertexAttrib2fv(indx: number, values: Float32Array): void; vertexAttrib3f(indx: number, x: number, y: number, z: number): void; - vertexAttrib3fv(indx: number, values: any): void; + vertexAttrib3fv(indx: number, values: Float32Array): void; vertexAttrib4f(indx: number, x: number, y: number, z: number, w: number): void; - vertexAttrib4fv(indx: number, values: any): void; + vertexAttrib4fv(indx: number, values: Float32Array): void; vertexAttribPointer(indx: number, size: number, type: number, normalized: boolean, stride: number, offset: number): void; viewport(x: number, y: number, width: number, height: number): void; ACTIVE_ATTRIBUTES: number; @@ -12088,7 +11993,6 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window locationbar: BarProp; menubar: BarProp; msAnimationStartTime: number; - msTemplatePrinter: MSTemplatePrinter; name: string; navigator: Navigator; offscreenBuffering: string | boolean; @@ -12825,7 +12729,6 @@ interface XMLHttpRequestEventTarget { addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; } - interface NodeListOf extends NodeList { length: number; item(index: number): TNode; @@ -12846,8 +12749,6 @@ interface EventListenerObject { handleEvent(evt: Event): void; } -declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; - interface MessageEventInit extends EventInit { data?: any; origin?: string; @@ -12863,6 +12764,8 @@ interface ProgressEventInit extends EventInit { total?: number; } +declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; + interface ErrorEventHandler { (message: string, filename?: string, lineno?: number, colno?: number, error?:Error): void; } @@ -12923,7 +12826,6 @@ declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msAnimationStartTime: number; -declare var msTemplatePrinter: MSTemplatePrinter; declare var name: string; declare var navigator: Navigator; declare var offscreenBuffering: string | boolean; diff --git a/lib/lib.es6.d.ts b/lib/lib.es6.d.ts index 75ba647a128..a7bf8f05076 100644 --- a/lib/lib.es6.d.ts +++ b/lib/lib.es6.d.ts @@ -5558,8 +5558,8 @@ interface AnalyserNode extends AudioNode { smoothingTimeConstant: number; getByteFrequencyData(array: Uint8Array): void; getByteTimeDomainData(array: Uint8Array): void; - getFloatFrequencyData(array: any): void; - getFloatTimeDomainData(array: any): void; + getFloatFrequencyData(array: Float32Array): void; + getFloatTimeDomainData(array: Float32Array): void; } declare var AnalyserNode: { @@ -5646,7 +5646,7 @@ interface AudioBuffer { length: number; numberOfChannels: number; sampleRate: number; - getChannelData(channel: number): any; + getChannelData(channel: number): Float32Array; } declare var AudioBuffer: { @@ -5690,7 +5690,7 @@ interface AudioContext extends EventTarget { createMediaElementSource(mediaElement: HTMLMediaElement): MediaElementAudioSourceNode; createOscillator(): OscillatorNode; createPanner(): PannerNode; - createPeriodicWave(real: any, imag: any): PeriodicWave; + createPeriodicWave(real: Float32Array, imag: Float32Array): PeriodicWave; createScriptProcessor(bufferSize?: number, numberOfInputChannels?: number, numberOfOutputChannels?: number): ScriptProcessorNode; createStereoPanner(): StereoPannerNode; createWaveShaper(): WaveShaperNode; @@ -5748,7 +5748,7 @@ interface AudioParam { linearRampToValueAtTime(value: number, endTime: number): void; setTargetAtTime(target: number, startTime: number, timeConstant: number): void; setValueAtTime(value: number, startTime: number): void; - setValueCurveAtTime(values: any, startTime: number, duration: number): void; + setValueCurveAtTime(values: Float32Array, startTime: number, duration: number): void; } declare var AudioParam: { @@ -5824,7 +5824,7 @@ interface BiquadFilterNode extends AudioNode { frequency: AudioParam; gain: AudioParam; type: string; - getFrequencyResponse(frequencyHz: any, magResponse: any, phaseResponse: any): void; + getFrequencyResponse(frequencyHz: Float32Array, magResponse: Float32Array, phaseResponse: Float32Array): void; } declare var BiquadFilterNode: { @@ -6423,7 +6423,7 @@ declare var CanvasPattern: { interface CanvasRenderingContext2D { canvas: HTMLCanvasElement; - fillStyle: any; + fillStyle: string | CanvasGradient | CanvasPattern; font: string; globalAlpha: number; globalCompositeOperation: string; @@ -6438,7 +6438,7 @@ interface CanvasRenderingContext2D { shadowColor: string; shadowOffsetX: number; shadowOffsetY: number; - strokeStyle: any; + strokeStyle: string | CanvasGradient | CanvasPattern; textAlign: string; textBaseline: string; arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void; @@ -7806,8 +7806,6 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven importNode(importedNode: Node, deep: boolean): Node; msElementsFromPoint(x: number, y: number): NodeList; msElementsFromRect(left: number, top: number, width: number, height: number): NodeList; - msGetPrintDocumentForNamedFlow(flowName: string): Document; - msSetPrintDocumentUriForNamedFlow(flowName: string, uri: string): void; /** * Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method. * @param url Specifies a MIME type for the document. @@ -12629,27 +12627,6 @@ declare var MSHTMLWebViewElement: { new(): MSHTMLWebViewElement; } -interface MSHeaderFooter { - URL: string; - dateLong: string; - dateShort: string; - font: string; - htmlFoot: string; - htmlHead: string; - page: number; - pageTotal: number; - textFoot: string; - textHead: string; - timeLong: string; - timeShort: string; - title: string; -} - -declare var MSHeaderFooter: { - prototype: MSHeaderFooter; - new(): MSHeaderFooter; -} - interface MSInputMethodContext extends EventTarget { compositionEndOffset: number; compositionStartOffset: number; @@ -12808,24 +12785,6 @@ declare var MSPointerEvent: { new(typeArg: string, eventInitDict?: PointerEventInit): MSPointerEvent; } -interface MSPrintManagerTemplatePrinter extends MSTemplatePrinter, EventTarget { - percentScale: number; - showHeaderFooter: boolean; - shrinkToFit: boolean; - drawPreviewPage(element: HTMLElement, pageNumber: number): void; - endPrint(): void; - getPrintTaskOptionValue(key: string): any; - invalidatePreview(): void; - setPageCount(pageCount: number): void; - startPrint(): void; - addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; -} - -declare var MSPrintManagerTemplatePrinter: { - prototype: MSPrintManagerTemplatePrinter; - new(): MSPrintManagerTemplatePrinter; -} - interface MSRangeCollection { length: number; item(index: number): Range; @@ -12873,63 +12832,6 @@ declare var MSStreamReader: { new(): MSStreamReader; } -interface MSTemplatePrinter { - collate: boolean; - copies: number; - currentPage: boolean; - currentPageAvail: boolean; - duplex: boolean; - footer: string; - frameActive: boolean; - frameActiveEnabled: boolean; - frameAsShown: boolean; - framesetDocument: boolean; - header: string; - headerFooterFont: string; - marginBottom: number; - marginLeft: number; - marginRight: number; - marginTop: number; - orientation: string; - pageFrom: number; - pageHeight: number; - pageTo: number; - pageWidth: number; - selectedPages: boolean; - selection: boolean; - selectionEnabled: boolean; - unprintableBottom: number; - unprintableLeft: number; - unprintableRight: number; - unprintableTop: number; - usePrinterCopyCollate: boolean; - createHeaderFooter(): MSHeaderFooter; - deviceSupports(property: string): any; - ensurePrintDialogDefaults(): boolean; - getPageMarginBottom(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginBottomImportant(pageRule: CSSPageRule): boolean; - getPageMarginLeft(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginLeftImportant(pageRule: CSSPageRule): boolean; - getPageMarginRight(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginRightImportant(pageRule: CSSPageRule): boolean; - getPageMarginTop(pageRule: CSSPageRule, pageWidth: number, pageHeight: number): any; - getPageMarginTopImportant(pageRule: CSSPageRule): boolean; - printBlankPage(): void; - printNonNative(document: any): boolean; - printNonNativeFrames(document: any, activeFrame: boolean): void; - printPage(element: HTMLElement): void; - showPageSetupDialog(): boolean; - showPrintDialog(): boolean; - startDoc(title: string): boolean; - stopDoc(): void; - updatePageStatus(status: number): void; -} - -declare var MSTemplatePrinter: { - prototype: MSTemplatePrinter; - new(): MSTemplatePrinter; -} - interface MSWebViewAsyncOperation extends EventTarget { error: DOMError; oncomplete: (ev: Event) => any; @@ -13347,6 +13249,10 @@ declare var Node: { } interface NodeFilter { + acceptNode(n: Node): number; +} + +declare var NodeFilter: { FILTER_ACCEPT: number; FILTER_REJECT: number; FILTER_SKIP: number; @@ -13364,7 +13270,6 @@ interface NodeFilter { SHOW_PROCESSING_INSTRUCTION: number; SHOW_TEXT: number; } -declare var NodeFilter: NodeFilter; interface NodeIterator { expandEntityReferences: boolean; @@ -14074,7 +13979,6 @@ declare var SVGDescElement: { interface SVGElement extends Element { id: string; - className: any; onclick: (ev: MouseEvent) => any; ondblclick: (ev: MouseEvent) => any; onfocusin: (ev: FocusEvent) => any; @@ -14088,6 +13992,7 @@ interface SVGElement extends Element { ownerSVGElement: SVGSVGElement; viewportElement: SVGElement; xmlbase: string; + className: any; addEventListener(type: "MSGestureChange", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureDoubleTap", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; addEventListener(type: "MSGestureEnd", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void; @@ -16249,7 +16154,7 @@ declare var WEBGL_depth_texture: { } interface WaveShaperNode extends AudioNode { - curve: any; + curve: Float32Array; oversample: string; } @@ -16436,34 +16341,34 @@ interface WebGLRenderingContext { texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, video: HTMLVideoElement): void; texSubImage2D(target: number, level: number, xoffset: number, yoffset: number, format: number, type: number, pixels: ImageData): void; uniform1f(location: WebGLUniformLocation, x: number): void; - uniform1fv(location: WebGLUniformLocation, v: any): void; + uniform1fv(location: WebGLUniformLocation, v: Float32Array): void; uniform1i(location: WebGLUniformLocation, x: number): void; uniform1iv(location: WebGLUniformLocation, v: Int32Array): void; uniform2f(location: WebGLUniformLocation, x: number, y: number): void; - uniform2fv(location: WebGLUniformLocation, v: any): void; + uniform2fv(location: WebGLUniformLocation, v: Float32Array): void; uniform2i(location: WebGLUniformLocation, x: number, y: number): void; uniform2iv(location: WebGLUniformLocation, v: Int32Array): void; uniform3f(location: WebGLUniformLocation, x: number, y: number, z: number): void; - uniform3fv(location: WebGLUniformLocation, v: any): void; + uniform3fv(location: WebGLUniformLocation, v: Float32Array): void; uniform3i(location: WebGLUniformLocation, x: number, y: number, z: number): void; uniform3iv(location: WebGLUniformLocation, v: Int32Array): void; uniform4f(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; - uniform4fv(location: WebGLUniformLocation, v: any): void; + uniform4fv(location: WebGLUniformLocation, v: Float32Array): void; uniform4i(location: WebGLUniformLocation, x: number, y: number, z: number, w: number): void; uniform4iv(location: WebGLUniformLocation, v: Int32Array): void; - uniformMatrix2fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; - uniformMatrix3fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; - uniformMatrix4fv(location: WebGLUniformLocation, transpose: boolean, value: any): void; + uniformMatrix2fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; + uniformMatrix3fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; + uniformMatrix4fv(location: WebGLUniformLocation, transpose: boolean, value: Float32Array): void; useProgram(program: WebGLProgram): void; validateProgram(program: WebGLProgram): void; vertexAttrib1f(indx: number, x: number): void; - vertexAttrib1fv(indx: number, values: any): void; + vertexAttrib1fv(indx: number, values: Float32Array): void; vertexAttrib2f(indx: number, x: number, y: number): void; - vertexAttrib2fv(indx: number, values: any): void; + vertexAttrib2fv(indx: number, values: Float32Array): void; vertexAttrib3f(indx: number, x: number, y: number, z: number): void; - vertexAttrib3fv(indx: number, values: any): void; + vertexAttrib3fv(indx: number, values: Float32Array): void; vertexAttrib4f(indx: number, x: number, y: number, z: number, w: number): void; - vertexAttrib4fv(indx: number, values: any): void; + vertexAttrib4fv(indx: number, values: Float32Array): void; vertexAttribPointer(indx: number, size: number, type: number, normalized: boolean, stride: number, offset: number): void; viewport(x: number, y: number, width: number, height: number): void; ACTIVE_ATTRIBUTES: number; @@ -17227,7 +17132,6 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window locationbar: BarProp; menubar: BarProp; msAnimationStartTime: number; - msTemplatePrinter: MSTemplatePrinter; name: string; navigator: Navigator; offscreenBuffering: string | boolean; @@ -17964,7 +17868,6 @@ interface XMLHttpRequestEventTarget { addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; } - interface NodeListOf extends NodeList { length: number; item(index: number): TNode; @@ -17985,8 +17888,6 @@ interface EventListenerObject { handleEvent(evt: Event): void; } -declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; - interface MessageEventInit extends EventInit { data?: any; origin?: string; @@ -18002,6 +17903,8 @@ interface ProgressEventInit extends EventInit { total?: number; } +declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; + interface ErrorEventHandler { (message: string, filename?: string, lineno?: number, colno?: number, error?:Error): void; } @@ -18062,7 +17965,6 @@ declare var location: Location; declare var locationbar: BarProp; declare var menubar: BarProp; declare var msAnimationStartTime: number; -declare var msTemplatePrinter: MSTemplatePrinter; declare var name: string; declare var navigator: Navigator; declare var offscreenBuffering: string | boolean; diff --git a/lib/lib.webworker.d.ts b/lib/lib.webworker.d.ts index 85bcfb1498e..7995a03a40f 100644 --- a/lib/lib.webworker.d.ts +++ b/lib/lib.webworker.d.ts @@ -234,7 +234,7 @@ interface AudioBuffer { length: number; numberOfChannels: number; sampleRate: number; - getChannelData(channel: number): any; + getChannelData(channel: number): Float32Array; } declare var AudioBuffer: { @@ -1111,7 +1111,6 @@ interface WorkerUtils extends Object, WindowBase64 { setTimeout(handler: any, timeout?: any, ...args: any[]): number; } - interface BlobPropertyBag { type?: string; endings?: string; @@ -1126,8 +1125,6 @@ interface EventListenerObject { handleEvent(evt: Event): void; } -declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; - interface MessageEventInit extends EventInit { data?: any; origin?: string; @@ -1143,6 +1140,8 @@ interface ProgressEventInit extends EventInit { total?: number; } +declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; + interface ErrorEventHandler { (message: string, filename?: string, lineno?: number, colno?: number, error?:Error): void; } diff --git a/lib/tsc.js b/lib/tsc.js index 3d2b7f3956a..07ff723b17c 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -410,8 +410,11 @@ var ts; } ts.chainDiagnosticMessages = chainDiagnosticMessages; function concatenateDiagnosticMessageChains(headChain, tailChain) { - Debug.assert(!headChain.next); - headChain.next = tailChain; + var lastChain = headChain; + while (lastChain.next) { + lastChain = lastChain.next; + } + lastChain.next = tailChain; return headChain; } ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains; @@ -627,6 +630,9 @@ var ts; } ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl; function getBaseFileName(path) { + if (!path) { + return undefined; + } var i = path.lastIndexOf(ts.directorySeparator); return i < 0 ? path : path.substring(i + 1); } @@ -650,6 +656,20 @@ var ts; } ts.fileExtensionIs = fileExtensionIs; ts.supportedExtensions = [".ts", ".tsx", ".d.ts"]; + ts.moduleFileExtensions = ts.supportedExtensions; + function isSupportedSourceFileName(fileName) { + if (!fileName) { + return false; + } + for (var _i = 0; _i < ts.supportedExtensions.length; _i++) { + var extension = ts.supportedExtensions[_i]; + if (fileExtensionIs(fileName, extension)) { + return true; + } + } + return false; + } + ts.isSupportedSourceFileName = isSupportedSourceFileName; var extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"]; function removeFileExtension(path) { for (var _i = 0; _i < extensionsToRemove.length; _i++) { @@ -726,6 +746,16 @@ var ts; } Debug.fail = fail; })(Debug = ts.Debug || (ts.Debug = {})); + function copyListRemovingItem(item, list) { + var copiedList = []; + for (var i = 0, len = list.length; i < len; i++) { + if (list[i] !== item) { + copiedList.push(list[i]); + } + } + return copiedList; + } + ts.copyListRemovingItem = copyListRemovingItem; })(ts || (ts = {})); var ts; (function (ts) { @@ -864,6 +894,76 @@ var ts; var _fs = require("fs"); var _path = require("path"); var _os = require("os"); + function createWatchedFileSet(interval, chunkSize) { + if (interval === void 0) { interval = 2500; } + if (chunkSize === void 0) { chunkSize = 30; } + var watchedFiles = []; + var nextFileToCheck = 0; + var watchTimer; + function getModifiedTime(fileName) { + return _fs.statSync(fileName).mtime; + } + function poll(checkedIndex) { + var watchedFile = watchedFiles[checkedIndex]; + if (!watchedFile) { + return; + } + _fs.stat(watchedFile.fileName, function (err, stats) { + if (err) { + watchedFile.callback(watchedFile.fileName); + } + else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) { + watchedFile.mtime = getModifiedTime(watchedFile.fileName); + watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0); + } + }); + } + function startWatchTimer() { + watchTimer = setInterval(function () { + var count = 0; + var nextToCheck = nextFileToCheck; + var firstCheck = -1; + while ((count < chunkSize) && (nextToCheck !== firstCheck)) { + poll(nextToCheck); + if (firstCheck < 0) { + firstCheck = nextToCheck; + } + nextToCheck++; + if (nextToCheck === watchedFiles.length) { + nextToCheck = 0; + } + count++; + } + nextFileToCheck = nextToCheck; + }, interval); + } + function addFile(fileName, callback) { + var file = { + fileName: fileName, + callback: callback, + mtime: getModifiedTime(fileName) + }; + watchedFiles.push(file); + if (watchedFiles.length === 1) { + startWatchTimer(); + } + return file; + } + function removeFile(file) { + watchedFiles = ts.copyListRemovingItem(file, watchedFiles); + } + return { + getModifiedTime: getModifiedTime, + poll: poll, + startWatchTimer: startWatchTimer, + addFile: addFile, + removeFile: removeFile + }; + } + var watchedFileSet = createWatchedFileSet(); + function isNode4OrLater() { + return parseInt(process.version.charAt(1)) >= 4; + } var platform = _os.platform(); var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; function readFile(fileName, encoding) { @@ -944,16 +1044,21 @@ var ts; readFile: readFile, writeFile: writeFile, watchFile: function (fileName, callback) { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); - return { - close: function () { _fs.unwatchFile(fileName, fileChanged); } - }; - function fileChanged(curr, prev) { - if (+curr.mtime <= +prev.mtime) { - return; - } - callback(fileName); + if (isNode4OrLater()) { + return _fs.watch(fileName, function (eventName, relativeFileName) { return callback(fileName); }); } + var watchedFile = watchedFileSet.addFile(fileName, callback); + return { + close: function () { return watchedFileSet.removeFile(watchedFile); } + }; + }, + watchDirectory: function (path, callback, recursive) { + return _fs.watch(path, { persisten: true, recursive: !!recursive }, function (eventName, relativeFileName) { + if (eventName === "rename") { + callback(!relativeFileName ? relativeFileName : ts.normalizePath(ts.combinePaths(path, relativeFileName))); + } + ; + }); }, resolvePath: function (path) { return _path.resolve(path); @@ -1050,7 +1155,7 @@ var ts; Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." }, _0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: { code: 1062, category: ts.DiagnosticCategory.Error, key: "{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method." }, An_export_assignment_cannot_be_used_in_a_namespace: { code: 1063, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a namespace." }, - Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: ts.DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." }, + In_ambient_enum_declarations_member_initializer_must_be_constant_expression: { code: 1066, category: ts.DiagnosticCategory.Error, key: "In ambient enum declarations member initializer must be constant expression." }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: ts.DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." }, @@ -1138,7 +1243,7 @@ var ts; Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." }, A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." }, - An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, + An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1183, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, @@ -1156,10 +1261,9 @@ var ts; An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: ts.DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, - Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, - Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, - Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." }, - Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead." }, + Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead." }, + Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'es6' when targeting 'ES5' or lower." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, @@ -1188,10 +1292,6 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, - Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning: { code: 1236, category: ts.DiagnosticCategory.Error, key: "Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning." }, - with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, - await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, - Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, @@ -1202,6 +1302,10 @@ var ts; _0_modifier_cannot_be_used_with_1_modifier: { code: 1243, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." }, Abstract_methods_can_only_appear_within_an_abstract_class: { code: 1244, category: ts.DiagnosticCategory.Error, key: "Abstract methods can only appear within an abstract class." }, Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: { code: 1245, category: ts.DiagnosticCategory.Error, key: "Method '{0}' cannot have an implementation because it is marked abstract." }, + with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, + await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, + Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, + can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment: { code: 1312, category: ts.DiagnosticCategory.Error, key: "'=' can only be used in an object literal property inside a destructuring assignment." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -1326,7 +1430,7 @@ var ts; In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element: { code: 2432, category: ts.DiagnosticCategory.Error, key: "In an enum with multiple declarations, only one declaration can omit an initializer for its first enum element." }, A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged: { code: 2433, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be in a different file from a class or function with which it is merged" }, A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: { code: 2434, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be located prior to a class or function with which it is merged" }, - Ambient_modules_cannot_be_nested_in_other_modules: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules." }, + Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules or namespaces." }, Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." }, Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: 2437, category: ts.DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" }, Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" }, @@ -1414,6 +1518,9 @@ var ts; yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: ts.DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: ts.DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: ts.DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value." }, + A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface: { code: 2526, category: ts.DiagnosticCategory.Error, key: "A 'this' type is available only in a non-static member of a class or interface." }, + The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary: { code: 2527, category: ts.DiagnosticCategory.Error, key: "The inferred type of '{0}' references an inaccessible 'this' type. A type annotation is necessary." }, + A_module_cannot_have_multiple_default_exports: { code: 2528, category: ts.DiagnosticCategory.Error, key: "A module cannot have multiple default exports." }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: ts.DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: ts.DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, @@ -1514,7 +1621,7 @@ var ts; Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: ts.DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." }, Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." }, Option_0_cannot_be_specified_with_option_1: { code: 5053, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." }, - A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5053, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, + A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5054, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -1526,7 +1633,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, - Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" }, + Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -1547,7 +1654,7 @@ var ts; Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." }, + Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'." }, Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: ts.DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: ts.DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, @@ -1568,7 +1675,6 @@ var ts; Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, - Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, @@ -1615,81 +1721,83 @@ var ts; Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: ts.DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." }, JSX_attribute_expected: { code: 17003, category: ts.DiagnosticCategory.Error, key: "JSX attribute expected." }, Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: ts.DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." }, - A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" } + A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }, + An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17006, category: ts.DiagnosticCategory.Error, key: "An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, + A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." } }; })(ts || (ts = {})); var ts; (function (ts) { function tokenIsIdentifierOrKeyword(token) { - return token >= 67; + return token >= 69; } ts.tokenIsIdentifierOrKeyword = tokenIsIdentifierOrKeyword; var textToToken = { - "abstract": 113, - "any": 115, - "as": 114, - "boolean": 118, - "break": 68, - "case": 69, - "catch": 70, - "class": 71, - "continue": 73, - "const": 72, - "constructor": 119, - "debugger": 74, - "declare": 120, - "default": 75, - "delete": 76, - "do": 77, - "else": 78, - "enum": 79, - "export": 80, - "extends": 81, - "false": 82, - "finally": 83, - "for": 84, - "from": 131, - "function": 85, - "get": 121, - "if": 86, - "implements": 104, - "import": 87, - "in": 88, - "instanceof": 89, - "interface": 105, - "is": 122, - "let": 106, - "module": 123, - "namespace": 124, - "new": 90, - "null": 91, - "number": 126, - "package": 107, - "private": 108, - "protected": 109, - "public": 110, - "require": 125, - "return": 92, - "set": 127, - "static": 111, - "string": 128, - "super": 93, - "switch": 94, - "symbol": 129, - "this": 95, - "throw": 96, - "true": 97, - "try": 98, - "type": 130, - "typeof": 99, - "var": 100, - "void": 101, - "while": 102, - "with": 103, - "yield": 112, - "async": 116, - "await": 117, - "of": 132, + "abstract": 115, + "any": 117, + "as": 116, + "boolean": 120, + "break": 70, + "case": 71, + "catch": 72, + "class": 73, + "continue": 75, + "const": 74, + "constructor": 121, + "debugger": 76, + "declare": 122, + "default": 77, + "delete": 78, + "do": 79, + "else": 80, + "enum": 81, + "export": 82, + "extends": 83, + "false": 84, + "finally": 85, + "for": 86, + "from": 133, + "function": 87, + "get": 123, + "if": 88, + "implements": 106, + "import": 89, + "in": 90, + "instanceof": 91, + "interface": 107, + "is": 124, + "let": 108, + "module": 125, + "namespace": 126, + "new": 92, + "null": 93, + "number": 128, + "package": 109, + "private": 110, + "protected": 111, + "public": 112, + "require": 127, + "return": 94, + "set": 129, + "static": 113, + "string": 130, + "super": 95, + "switch": 96, + "symbol": 131, + "this": 97, + "throw": 98, + "true": 99, + "try": 100, + "type": 132, + "typeof": 101, + "var": 102, + "void": 103, + "while": 104, + "with": 105, + "yield": 114, + "async": 118, + "await": 119, + "of": 134, "{": 15, "}": 16, "(": 17, @@ -1711,37 +1819,39 @@ var ts; "=>": 34, "+": 35, "-": 36, + "**": 38, "*": 37, - "/": 38, - "%": 39, - "++": 40, - "--": 41, - "<<": 42, + "/": 39, + "%": 40, + "++": 41, + "--": 42, + "<<": 43, ">": 43, - ">>>": 44, - "&": 45, - "|": 46, - "^": 47, - "!": 48, - "~": 49, - "&&": 50, - "||": 51, - "?": 52, - ":": 53, - "=": 55, - "+=": 56, - "-=": 57, - "*=": 58, - "/=": 59, - "%=": 60, - "<<=": 61, - ">>=": 62, - ">>>=": 63, - "&=": 64, - "|=": 65, - "^=": 66, - "@": 54 + ">>": 44, + ">>>": 45, + "&": 46, + "|": 47, + "^": 48, + "!": 49, + "~": 50, + "&&": 51, + "||": 52, + "?": 53, + ":": 54, + "=": 56, + "+=": 57, + "-=": 58, + "*=": 59, + "**=": 60, + "/=": 61, + "%=": 62, + "<<=": 63, + ">>=": 64, + ">>>=": 65, + "&=": 66, + "|=": 67, + "^=": 68, + "@": 55 }; var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; @@ -2143,8 +2253,8 @@ var ts; getTokenValue: function () { return tokenValue; }, hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, - isIdentifier: function () { return token === 67 || token > 103; }, - isReservedWord: function () { return token >= 68 && token <= 103; }, + isIdentifier: function () { return token === 69 || token > 105; }, + isReservedWord: function () { return token >= 70 && token <= 105; }, isUnterminated: function () { return tokenIsUnterminated; }, reScanGreaterToken: reScanGreaterToken, reScanSlashToken: reScanSlashToken, @@ -2166,16 +2276,6 @@ var ts; onError(message, length || 0); } } - function isIdentifierStart(ch) { - return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || - ch === 36 || ch === 95 || - ch > 127 && isUnicodeIdentifierStart(ch, languageVersion); - } - function isIdentifierPart(ch) { - return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || - ch >= 48 && ch <= 57 || ch === 36 || ch === 95 || - ch > 127 && isUnicodeIdentifierPart(ch, languageVersion); - } function scanNumber() { var start = pos; while (isDigit(text.charCodeAt(pos))) @@ -2430,12 +2530,12 @@ var ts; var start = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (isIdentifierPart(ch)) { + if (isIdentifierPart(ch, languageVersion)) { pos++; } else if (ch === 92) { ch = peekUnicodeEscape(); - if (!(ch >= 0 && isIdentifierPart(ch))) { + if (!(ch >= 0 && isIdentifierPart(ch, languageVersion))) { break; } result += text.substring(start, pos); @@ -2458,7 +2558,7 @@ var ts; return token = textToToken[tokenValue]; } } - return token = 67; + return token = 69; } function scanBinaryOrOctalDigits(base) { ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8"); @@ -2537,7 +2637,7 @@ var ts; } return pos += 2, token = 31; } - return pos++, token = 48; + return pos++, token = 49; case 34: case 39: tokenValue = scanString(); @@ -2546,42 +2646,48 @@ var ts; return token = scanTemplateAndSetTokenValue(); case 37: if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 60; + return pos += 2, token = 62; } - return pos++, token = 39; + return pos++, token = 40; case 38: if (text.charCodeAt(pos + 1) === 38) { - return pos += 2, token = 50; + return pos += 2, token = 51; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 64; + return pos += 2, token = 66; } - return pos++, token = 45; + return pos++, token = 46; case 40: return pos++, token = 17; case 41: return pos++, token = 18; case 42: if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 58; + return pos += 2, token = 59; + } + if (text.charCodeAt(pos + 1) === 42) { + if (text.charCodeAt(pos + 2) === 61) { + return pos += 3, token = 60; + } + return pos += 2, token = 38; } return pos++, token = 37; case 43: if (text.charCodeAt(pos + 1) === 43) { - return pos += 2, token = 40; + return pos += 2, token = 41; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 56; + return pos += 2, token = 57; } return pos++, token = 35; case 44: return pos++, token = 24; case 45: if (text.charCodeAt(pos + 1) === 45) { - return pos += 2, token = 41; + return pos += 2, token = 42; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 57; + return pos += 2, token = 58; } return pos++, token = 36; case 46: @@ -2636,9 +2742,9 @@ var ts; } } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 59; + return pos += 2, token = 61; } - return pos++, token = 38; + return pos++, token = 39; case 48: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) { pos += 2; @@ -2686,7 +2792,7 @@ var ts; tokenValue = "" + scanNumber(); return token = 8; case 58: - return pos++, token = 53; + return pos++, token = 54; case 59: return pos++, token = 23; case 60: @@ -2701,14 +2807,16 @@ var ts; } if (text.charCodeAt(pos + 1) === 60) { if (text.charCodeAt(pos + 2) === 61) { - return pos += 3, token = 61; + return pos += 3, token = 63; } - return pos += 2, token = 42; + return pos += 2, token = 43; } if (text.charCodeAt(pos + 1) === 61) { return pos += 2, token = 28; } - if (text.charCodeAt(pos + 1) === 47 && languageVariant === 1) { + if (languageVariant === 1 && + text.charCodeAt(pos + 1) === 47 && + text.charCodeAt(pos + 2) !== 42) { return pos += 2, token = 26; } return pos++, token = 25; @@ -2731,7 +2839,7 @@ var ts; if (text.charCodeAt(pos + 1) === 62) { return pos += 2, token = 34; } - return pos++, token = 55; + return pos++, token = 56; case 62: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -2744,35 +2852,35 @@ var ts; } return pos++, token = 27; case 63: - return pos++, token = 52; + return pos++, token = 53; case 91: return pos++, token = 19; case 93: return pos++, token = 20; case 94: if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 66; + return pos += 2, token = 68; } - return pos++, token = 47; + return pos++, token = 48; case 123: return pos++, token = 15; case 124: if (text.charCodeAt(pos + 1) === 124) { - return pos += 2, token = 51; + return pos += 2, token = 52; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 65; + return pos += 2, token = 67; } - return pos++, token = 46; + return pos++, token = 47; case 125: return pos++, token = 16; case 126: - return pos++, token = 49; + return pos++, token = 50; case 64: - return pos++, token = 54; + return pos++, token = 55; case 92: var cookedChar = peekUnicodeEscape(); - if (cookedChar >= 0 && isIdentifierStart(cookedChar)) { + if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); @@ -2780,9 +2888,9 @@ var ts; error(ts.Diagnostics.Invalid_character); return pos++, token = 0; default: - if (isIdentifierStart(ch)) { + if (isIdentifierStart(ch, languageVersion)) { pos++; - while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos))) + while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92) { @@ -2809,14 +2917,14 @@ var ts; if (text.charCodeAt(pos) === 62) { if (text.charCodeAt(pos + 1) === 62) { if (text.charCodeAt(pos + 2) === 61) { - return pos += 3, token = 63; + return pos += 3, token = 65; } - return pos += 2, token = 44; + return pos += 2, token = 45; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 62; + return pos += 2, token = 64; } - return pos++, token = 43; + return pos++, token = 44; } if (text.charCodeAt(pos) === 61) { return pos++, token = 29; @@ -2825,7 +2933,7 @@ var ts; return token; } function reScanSlashToken() { - if (token === 38 || token === 59) { + if (token === 39 || token === 61) { var p = tokenPos + 1; var inEscape = false; var inCharacterClass = false; @@ -2859,7 +2967,7 @@ var ts; } p++; } - while (p < end && isIdentifierPart(text.charCodeAt(p))) { + while (p < end && isIdentifierPart(text.charCodeAt(p), languageVersion)) { p++; } pos = p; @@ -2902,14 +3010,14 @@ var ts; break; } } - return token = 234; + return token = 236; } function scanJsxIdentifier() { if (tokenIsIdentifierOrKeyword(token)) { var firstCharPosition = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (ch === 45 || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) { + if (ch === 45 || ((firstCharPosition === pos) ? isIdentifierStart(ch, languageVersion) : isIdentifierPart(ch, languageVersion))) { pos++; } else { @@ -2976,16 +3084,16 @@ var ts; (function (ts) { ts.bindTime = 0; function getModuleInstanceState(node) { - if (node.kind === 213 || node.kind === 214) { + if (node.kind === 215 || node.kind === 216) { return 0; } else if (ts.isConstEnumDeclaration(node)) { return 2; } - else if ((node.kind === 220 || node.kind === 219) && !(node.flags & 1)) { + else if ((node.kind === 222 || node.kind === 221) && !(node.flags & 1)) { return 0; } - else if (node.kind === 217) { + else if (node.kind === 219) { var state = 0; ts.forEachChild(node, function (n) { switch (getModuleInstanceState(n)) { @@ -3001,7 +3109,7 @@ var ts; }); return state; } - else if (node.kind === 216) { + else if (node.kind === 218) { return getModuleInstanceState(node.body); } else { @@ -3020,6 +3128,7 @@ var ts; var container; var blockScopeContainer; var lastContainer; + var seenThisKeyword; var inStrictMode = !!file.externalModuleIndicator; var symbolCount = 0; var Symbol = ts.objectAllocator.getSymbolConstructor(); @@ -3053,10 +3162,10 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 216 && node.name.kind === 9) { + if (node.kind === 218 && node.name.kind === 9) { return "\"" + node.name.text + "\""; } - if (node.name.kind === 134) { + if (node.name.kind === 136) { var nameExpression = node.name.expression; ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression)); return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text); @@ -3064,22 +3173,22 @@ var ts; return node.name.text; } switch (node.kind) { - case 142: + case 144: return "__constructor"; - case 150: - case 145: - return "__call"; - case 151: - case 146: - return "__new"; + case 152: case 147: + return "__call"; + case 153: + case 148: + return "__new"; + case 149: return "__index"; - case 226: + case 228: return "__export"; - case 225: + case 227: return node.isExportEquals ? "export=" : "default"; - case 211: - case 212: + case 213: + case 214: return node.flags & 1024 ? "default" : undefined; } } @@ -3088,7 +3197,8 @@ var ts; } function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); - var name = node.flags & 1024 && parent ? "default" : getDeclarationName(node); + var isDefaultExport = node.flags & 1024; + var name = isDefaultExport && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { symbol = ts.hasProperty(symbolTable, name) @@ -3104,6 +3214,11 @@ var ts; var message = symbol.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + ts.forEach(symbol.declarations, function (declaration) { + if (declaration.flags & 1024) { + message = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + } + }); ts.forEach(symbol.declarations, function (declaration) { file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); @@ -3121,7 +3236,7 @@ var ts; function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1; if (symbolFlags & 8388608) { - if (node.kind === 228 || (node.kind === 219 && hasExportModifier)) { + if (node.kind === 230 || (node.kind === 221 && hasExportModifier)) { return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { @@ -3160,44 +3275,51 @@ var ts; blockScopeContainer = node; blockScopeContainer.locals = undefined; } - ts.forEachChild(node, bind); + if (node.kind === 215) { + seenThisKeyword = false; + ts.forEachChild(node, bind); + node.flags = seenThisKeyword ? node.flags | 524288 : node.flags & ~524288; + } + else { + ts.forEachChild(node, bind); + } container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } function getContainerFlags(node) { switch (node.kind) { - case 184: - case 212: - case 213: + case 186: + case 214: case 215: - case 153: - case 163: + case 217: + case 155: + case 165: return 1; + case 147: + case 148: + case 149: + case 143: + case 142: + case 213: + case 144: case 145: case 146: - case 147: - case 141: - case 140: - case 211: - case 142: - case 143: - case 144: - case 150: - case 151: - case 171: - case 172: - case 216: - case 246: - case 214: - return 5; - case 242: - case 197: - case 198: - case 199: + case 152: + case 153: + case 173: + case 174: case 218: + case 248: + case 216: + return 5; + case 244: + case 199: + case 200: + case 201: + case 220: return 2; - case 190: + case 192: return ts.isFunctionLike(node.parent) ? 0 : 2; } return 0; @@ -3213,33 +3335,33 @@ var ts; } function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) { switch (container.kind) { - case 216: + case 218: return declareModuleMember(node, symbolFlags, symbolExcludes); - case 246: + case 248: return declareSourceFileMember(node, symbolFlags, symbolExcludes); - case 184: - case 212: + case 186: + case 214: return declareClassMember(node, symbolFlags, symbolExcludes); - case 215: + case 217: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); - case 153: - case 163: - case 213: + case 155: + case 165: + case 215: return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); - case 150: - case 151: + case 152: + case 153: + case 147: + case 148: + case 149: + case 143: + case 142: + case 144: case 145: case 146: - case 147: - case 141: - case 140: - case 142: - case 143: - case 144: - case 211: - case 171: - case 172: - case 214: + case 213: + case 173: + case 174: + case 216: return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } @@ -3263,11 +3385,11 @@ var ts; return false; } function hasExportDeclarations(node) { - var body = node.kind === 246 ? node : node.body; - if (body.kind === 246 || body.kind === 217) { + var body = node.kind === 248 ? node : node.body; + if (body.kind === 248 || body.kind === 219) { for (var _i = 0, _a = body.statements; _i < _a.length; _i++) { var stat = _a[_i]; - if (stat.kind === 226 || stat.kind === 225) { + if (stat.kind === 228 || stat.kind === 227) { return true; } } @@ -3322,11 +3444,11 @@ var ts; var seen = {}; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - if (prop.name.kind !== 67) { + if (prop.name.kind !== 69) { continue; } var identifier = prop.name; - var currentKind = prop.kind === 243 || prop.kind === 244 || prop.kind === 141 + var currentKind = prop.kind === 245 || prop.kind === 246 || prop.kind === 143 ? 1 : 2; var existingKind = seen[identifier.text]; @@ -3348,10 +3470,10 @@ var ts; } function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { - case 216: + case 218: declareModuleMember(node, symbolFlags, symbolExcludes); break; - case 246: + case 248: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolFlags, symbolExcludes); break; @@ -3369,8 +3491,8 @@ var ts; } function checkStrictModeIdentifier(node) { if (inStrictMode && - node.originalKeywordKind >= 104 && - node.originalKeywordKind <= 112 && + node.originalKeywordKind >= 106 && + node.originalKeywordKind <= 114 && !ts.isIdentifierName(node)) { if (!file.parseDiagnostics.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); @@ -3397,17 +3519,17 @@ var ts; } } function checkStrictModeDeleteExpression(node) { - if (inStrictMode && node.expression.kind === 67) { + if (inStrictMode && node.expression.kind === 69) { var span = ts.getErrorSpanForNode(file, node.expression); file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode)); } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 && + return node.kind === 69 && (node.text === "eval" || node.text === "arguments"); } function checkStrictModeEvalOrArguments(contextNode, name) { - if (name && name.kind === 67) { + if (name && name.kind === 69) { var identifier = name; if (isEvalOrArgumentsIdentifier(identifier)) { var span = ts.getErrorSpanForNode(file, name); @@ -3441,7 +3563,7 @@ var ts; } function checkStrictModePrefixUnaryExpression(node) { if (inStrictMode) { - if (node.operator === 40 || node.operator === 41) { + if (node.operator === 41 || node.operator === 42) { checkStrictModeEvalOrArguments(node, node.operand); } } @@ -3470,17 +3592,17 @@ var ts; } function updateStrictMode(node) { switch (node.kind) { - case 246: - case 217: + case 248: + case 219: updateStrictModeStatementList(node.statements); return; - case 190: + case 192: if (ts.isFunctionLike(node.parent)) { updateStrictModeStatementList(node.statements); } return; - case 212: - case 184: + case 214: + case 186: inStrictMode = true; return; } @@ -3503,88 +3625,91 @@ var ts; } function bindWorker(node) { switch (node.kind) { - case 67: + case 69: return checkStrictModeIdentifier(node); - case 179: + case 181: return checkStrictModeBinaryExpression(node); - case 242: + case 244: return checkStrictModeCatchClause(node); - case 173: + case 175: return checkStrictModeDeleteExpression(node); case 8: return checkStrictModeNumericLiteral(node); - case 178: + case 180: return checkStrictModePostfixUnaryExpression(node); - case 177: + case 179: return checkStrictModePrefixUnaryExpression(node); - case 203: + case 205: return checkStrictModeWithStatement(node); - case 135: + case 97: + seenThisKeyword = true; + return; + case 137: return declareSymbolAndAddToSymbolTable(node, 262144, 530912); - case 136: - return bindParameter(node); - case 209: - case 161: - return bindVariableDeclarationOrBindingElement(node); - case 139: case 138: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); - case 243: - case 244: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); - case 245: - return bindPropertyOrMethodOrAccessor(node, 8, 107455); - case 145: - case 146: - case 147: - return declareSymbolAndAddToSymbolTable(node, 131072, 0); + return bindParameter(node); + case 211: + case 163: + return bindVariableDeclarationOrBindingElement(node); case 141: case 140: + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + case 245: + case 246: + return bindPropertyOrMethodOrAccessor(node, 4, 107455); + case 247: + return bindPropertyOrMethodOrAccessor(node, 8, 107455); + case 147: + case 148: + case 149: + return declareSymbolAndAddToSymbolTable(node, 131072, 0); + case 143: + case 142: return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); - case 211: + case 213: checkStrictModeFunctionName(node); return declareSymbolAndAddToSymbolTable(node, 16, 106927); - case 142: - return declareSymbolAndAddToSymbolTable(node, 16384, 0); - case 143: - return bindPropertyOrMethodOrAccessor(node, 32768, 41919); case 144: + return declareSymbolAndAddToSymbolTable(node, 16384, 0); + case 145: + return bindPropertyOrMethodOrAccessor(node, 32768, 41919); + case 146: return bindPropertyOrMethodOrAccessor(node, 65536, 74687); - case 150: - case 151: - return bindFunctionOrConstructorType(node); + case 152: case 153: + return bindFunctionOrConstructorType(node); + case 155: return bindAnonymousDeclaration(node, 2048, "__type"); - case 163: + case 165: return bindObjectLiteralExpression(node); - case 171: - case 172: + case 173: + case 174: checkStrictModeFunctionName(node); var bindingName = node.name ? node.name.text : "__function"; return bindAnonymousDeclaration(node, 16, bindingName); - case 184: - case 212: - return bindClassLikeDeclaration(node); - case 213: - return bindBlockScopedDeclaration(node, 64, 792960); + case 186: case 214: - return bindBlockScopedDeclaration(node, 524288, 793056); + return bindClassLikeDeclaration(node); case 215: - return bindEnumDeclaration(node); + return bindBlockScopedDeclaration(node, 64, 792960); case 216: + return bindBlockScopedDeclaration(node, 524288, 793056); + case 217: + return bindEnumDeclaration(node); + case 218: return bindModuleDeclaration(node); - case 219: - case 222: - case 224: - case 228: - return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 221: - return bindImportClause(node); + case 224: case 226: + case 230: + return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); + case 223: + return bindImportClause(node); + case 228: return bindExportDeclaration(node); - case 225: + case 227: return bindExportAssignment(node); - case 246: + case 248: return bindSourceFileIfExternalModule(); } } @@ -3598,7 +3723,7 @@ var ts; if (!container.symbol || !container.symbol.exports) { bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } - else if (node.expression.kind === 67) { + else if (node.expression.kind === 69) { declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); } else { @@ -3619,7 +3744,7 @@ var ts; } } function bindClassLikeDeclaration(node) { - if (node.kind === 212) { + if (node.kind === 214) { bindBlockScopedDeclaration(node, 32, 899519); } else { @@ -3672,7 +3797,7 @@ var ts; declareSymbolAndAddToSymbolTable(node, 1, 107455); } if (node.flags & 112 && - node.parent.kind === 142 && + node.parent.kind === 144 && ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); @@ -3718,7 +3843,8 @@ var ts; increaseIndent: function () { }, decreaseIndent: function () { }, clear: function () { return str = ""; }, - trackSymbol: function () { } + trackSymbol: function () { }, + reportInaccessibleThisError: function () { } }; } return stringWriters.pop(); @@ -3780,7 +3906,7 @@ var ts; } } function getSourceFileOfNode(node) { - while (node && node.kind !== 246) { + while (node && node.kind !== 248) { node = node.parent; } return node; @@ -3871,15 +3997,15 @@ var ts; return current; } switch (current.kind) { - case 246: + case 248: + case 220: + case 244: case 218: - case 242: - case 216: - case 197: - case 198: case 199: + case 200: + case 201: return current; - case 190: + case 192: if (!isFunctionLike(current.parent)) { return current; } @@ -3890,9 +4016,9 @@ var ts; ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer; function isCatchClauseVariableDeclaration(declaration) { return declaration && - declaration.kind === 209 && + declaration.kind === 211 && declaration.parent && - declaration.parent.kind === 242; + declaration.parent.kind === 244; } ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; function declarationNameToString(name) { @@ -3928,22 +4054,22 @@ var ts; function getErrorSpanForNode(sourceFile, node) { var errorNode = node; switch (node.kind) { - case 246: + case 248: var pos_1 = ts.skipTrivia(sourceFile.text, 0, false); if (pos_1 === sourceFile.text.length) { return ts.createTextSpan(0, 0); } return getSpanOfTokenAtPosition(sourceFile, pos_1); - case 209: - case 161: - case 212: - case 184: - case 213: - case 216: - case 215: - case 245: case 211: - case 171: + case 163: + case 214: + case 186: + case 215: + case 218: + case 217: + case 247: + case 213: + case 173: errorNode = node.name; break; } @@ -3965,11 +4091,11 @@ var ts; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { - return node.kind === 215 && isConst(node); + return node.kind === 217 && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; function walkUpBindingElementsAndPatterns(node) { - while (node && (node.kind === 161 || isBindingPattern(node))) { + while (node && (node.kind === 163 || isBindingPattern(node))) { node = node.parent; } return node; @@ -3977,14 +4103,14 @@ var ts; function getCombinedNodeFlags(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; - if (node.kind === 209) { + if (node.kind === 211) { node = node.parent; } - if (node && node.kind === 210) { + if (node && node.kind === 212) { flags |= node.flags; node = node.parent; } - if (node && node.kind === 191) { + if (node && node.kind === 193) { flags |= node.flags; } return flags; @@ -3999,7 +4125,7 @@ var ts; } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 193 && node.expression.kind === 9; + return node.kind === 195 && node.expression.kind === 9; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { @@ -4007,7 +4133,7 @@ var ts; } ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - var commentRanges = (node.kind === 136 || node.kind === 135) ? + var commentRanges = (node.kind === 138 || node.kind === 137) ? ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) : getLeadingCommentRangesOfNode(node, sourceFileOfNode); return ts.filter(commentRanges, isJsDocComment); @@ -4021,68 +4147,69 @@ var ts; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; ts.fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*/; function isTypeNode(node) { - if (149 <= node.kind && node.kind <= 158) { + if (151 <= node.kind && node.kind <= 160) { return true; } switch (node.kind) { - case 115: - case 126: + case 117: case 128: - case 118: - case 129: + case 130: + case 120: + case 131: return true; - case 101: - return node.parent.kind !== 175; + case 103: + return node.parent.kind !== 177; case 9: - return node.parent.kind === 136; - case 186: + return node.parent.kind === 138; + case 188: return !isExpressionWithTypeArgumentsInClassExtendsClause(node); - case 67: - if (node.parent.kind === 133 && node.parent.right === node) { + case 69: + if (node.parent.kind === 135 && node.parent.right === node) { node = node.parent; } - else if (node.parent.kind === 164 && node.parent.name === node) { + else if (node.parent.kind === 166 && node.parent.name === node) { node = node.parent; } - case 133: - case 164: - ts.Debug.assert(node.kind === 67 || node.kind === 133 || node.kind === 164, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + ts.Debug.assert(node.kind === 69 || node.kind === 135 || node.kind === 166, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + case 135: + case 166: + case 97: var parent_1 = node.parent; - if (parent_1.kind === 152) { + if (parent_1.kind === 154) { return false; } - if (149 <= parent_1.kind && parent_1.kind <= 158) { + if (151 <= parent_1.kind && parent_1.kind <= 160) { return true; } switch (parent_1.kind) { - case 186: + case 188: return !isExpressionWithTypeArgumentsInClassExtendsClause(parent_1); - case 135: + case 137: return node === parent_1.constraint; - case 139: - case 138: - case 136: - case 209: - return node === parent_1.type; - case 211: - case 171: - case 172: - case 142: case 141: case 140: - case 143: - case 144: + case 138: + case 211: return node === parent_1.type; + case 213: + case 173: + case 174: + case 144: + case 143: + case 142: case 145: case 146: + return node === parent_1.type; case 147: + case 148: + case 149: return node === parent_1.type; - case 169: + case 171: return node === parent_1.type; - case 166: - case 167: - return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; case 168: + case 169: + return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; + case 170: return false; } } @@ -4093,23 +4220,23 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 202: + case 204: return visitor(node); - case 218: - case 190: - case 194: - case 195: + case 220: + case 192: case 196: case 197: case 198: case 199: - case 203: - case 204: - case 239: - case 240: + case 200: + case 201: case 205: - case 207: + case 206: + case 241: case 242: + case 207: + case 209: + case 244: return ts.forEachChild(node, traverse); } } @@ -4119,23 +4246,23 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 182: + case 184: visitor(node); var operand = node.expression; if (operand) { traverse(operand); } + case 217: case 215: - case 213: + case 218: case 216: case 214: - case 212: - case 184: + case 186: return; default: if (isFunctionLike(node)) { var name_5 = node.name; - if (name_5 && name_5.kind === 134) { + if (name_5 && name_5.kind === 136) { traverse(name_5.expression); return; } @@ -4150,14 +4277,14 @@ var ts; function isVariableLike(node) { if (node) { switch (node.kind) { - case 161: - case 245: - case 136: - case 243: - case 139: + case 163: + case 247: case 138: - case 244: - case 209: + case 245: + case 141: + case 140: + case 246: + case 211: return true; } } @@ -4165,29 +4292,29 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - return node && (node.kind === 143 || node.kind === 144); + return node && (node.kind === 145 || node.kind === 146); } ts.isAccessor = isAccessor; function isClassLike(node) { - return node && (node.kind === 212 || node.kind === 184); + return node && (node.kind === 214 || node.kind === 186); } ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { - case 142: - case 171: - case 211: - case 172: - case 141: - case 140: - case 143: case 144: + case 173: + case 213: + case 174: + case 143: + case 142: case 145: case 146: case 147: - case 150: - case 151: + case 148: + case 149: + case 152: + case 153: return true; } } @@ -4196,24 +4323,24 @@ var ts; ts.isFunctionLike = isFunctionLike; function introducesArgumentsExoticObject(node) { switch (node.kind) { - case 141: - case 140: - case 142: case 143: + case 142: case 144: - case 211: - case 171: + case 145: + case 146: + case 213: + case 173: return true; } return false; } ts.introducesArgumentsExoticObject = introducesArgumentsExoticObject; function isFunctionBlock(node) { - return node && node.kind === 190 && isFunctionLike(node.parent); + return node && node.kind === 192 && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { - return node && node.kind === 141 && node.parent.kind === 163; + return node && node.kind === 143 && node.parent.kind === 165; } ts.isObjectLiteralMethod = isObjectLiteralMethod; function getContainingFunction(node) { @@ -4241,36 +4368,39 @@ var ts; return undefined; } switch (node.kind) { - case 134: + case 136: if (isClassLike(node.parent.parent)) { return node; } node = node.parent; break; - case 137: - if (node.parent.kind === 136 && isClassElement(node.parent.parent)) { + case 139: + if (node.parent.kind === 138 && isClassElement(node.parent.parent)) { node = node.parent.parent; } else if (isClassElement(node.parent)) { node = node.parent; } break; - case 172: + case 174: if (!includeArrowFunctions) { continue; } - case 211: - case 171: - case 216: - case 139: - case 138: + case 213: + case 173: + case 218: case 141: case 140: - case 142: case 143: + case 142: case 144: - case 215: - case 246: + case 145: + case 146: + case 147: + case 148: + case 149: + case 217: + case 248: return node; } } @@ -4282,33 +4412,33 @@ var ts; if (!node) return node; switch (node.kind) { - case 134: + case 136: if (isClassLike(node.parent.parent)) { return node; } node = node.parent; break; - case 137: - if (node.parent.kind === 136 && isClassElement(node.parent.parent)) { + case 139: + if (node.parent.kind === 138 && isClassElement(node.parent.parent)) { node = node.parent.parent; } else if (isClassElement(node.parent)) { node = node.parent; } break; - case 211: - case 171: - case 172: + case 213: + case 173: + case 174: if (!includeFunctions) { continue; } - case 139: - case 138: case 141: case 140: - case 142: case 143: + case 142: case 144: + case 145: + case 146: return node; } } @@ -4317,12 +4447,12 @@ var ts; function getEntityNameFromTypeNode(node) { if (node) { switch (node.kind) { - case 149: + case 151: return node.typeName; - case 186: + case 188: return node.expression; - case 67: - case 133: + case 69: + case 135: return node; } } @@ -4330,7 +4460,7 @@ var ts; } ts.getEntityNameFromTypeNode = getEntityNameFromTypeNode; function getInvokedExpression(node) { - if (node.kind === 168) { + if (node.kind === 170) { return node.tag; } return node.expression; @@ -4338,40 +4468,40 @@ var ts; ts.getInvokedExpression = getInvokedExpression; function nodeCanBeDecorated(node) { switch (node.kind) { - case 212: + case 214: return true; - case 139: - return node.parent.kind === 212; - case 136: - return node.parent.body && node.parent.parent.kind === 212; - case 143: - case 144: case 141: - return node.body && node.parent.kind === 212; + return node.parent.kind === 214; + case 138: + return node.parent.body && node.parent.parent.kind === 214; + case 145: + case 146: + case 143: + return node.body && node.parent.kind === 214; } return false; } ts.nodeCanBeDecorated = nodeCanBeDecorated; function nodeIsDecorated(node) { switch (node.kind) { - case 212: + case 214: if (node.decorators) { return true; } return false; - case 139: - case 136: - if (node.decorators) { - return true; - } - return false; - case 143: - if (node.body && node.decorators) { - return true; - } - return false; case 141: - case 144: + case 138: + if (node.decorators) { + return true; + } + return false; + case 145: + if (node.body && node.decorators) { + return true; + } + return false; + case 143: + case 146: if (node.body && node.decorators) { return true; } @@ -4382,10 +4512,10 @@ var ts; ts.nodeIsDecorated = nodeIsDecorated; function childIsDecorated(node) { switch (node.kind) { - case 212: + case 214: return ts.forEach(node.members, nodeOrChildIsDecorated); - case 141: - case 144: + case 143: + case 146: return ts.forEach(node.parameters, nodeIsDecorated); } return false; @@ -4395,95 +4525,105 @@ var ts; return nodeIsDecorated(node) || childIsDecorated(node); } ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated; + function isPropertyAccessExpression(node) { + return node.kind === 166; + } + ts.isPropertyAccessExpression = isPropertyAccessExpression; + function isElementAccessExpression(node) { + return node.kind === 167; + } + ts.isElementAccessExpression = isElementAccessExpression; function isExpression(node) { switch (node.kind) { case 95: case 93: - case 91: - case 97: - case 82: + case 99: + case 84: case 10: - case 162: - case 163: case 164: case 165: case 166: case 167: case 168: - case 187: case 169: case 170: + case 189: case 171: - case 184: case 172: - case 175: case 173: + case 186: case 174: case 177: - case 178: + case 175: + case 176: case 179: case 180: - case 183: case 181: - case 11: - case 185: - case 231: - case 232: case 182: + case 185: + case 183: + case 11: + case 187: + case 233: + case 234: + case 184: + case 178: return true; - case 133: - while (node.parent.kind === 133) { + case 135: + while (node.parent.kind === 135) { node = node.parent; } - return node.parent.kind === 152; - case 67: - if (node.parent.kind === 152) { + return node.parent.kind === 154; + case 69: + if (node.parent.kind === 154) { return true; } case 8: case 9: + case 97: var parent_2 = node.parent; switch (parent_2.kind) { - case 209: - case 136: - case 139: + case 211: case 138: + case 141: + case 140: + case 247: case 245: - case 243: - case 161: + case 163: return parent_2.initializer === node; - case 193: - case 194: case 195: case 196: - case 202: - case 203: - case 204: - case 239: - case 206: - case 204: - return parent_2.expression === node; case 197: + case 198: + case 204: + case 205: + case 206: + case 241: + case 208: + case 206: + return parent_2.expression === node; + case 199: var forStatement = parent_2; - return (forStatement.initializer === node && forStatement.initializer.kind !== 210) || + return (forStatement.initializer === node && forStatement.initializer.kind !== 212) || forStatement.condition === node || forStatement.incrementor === node; - case 198: - case 199: + case 200: + case 201: var forInStatement = parent_2; - return (forInStatement.initializer === node && forInStatement.initializer.kind !== 210) || + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 212) || forInStatement.expression === node; - case 169: - case 187: + case 171: + case 189: return node === parent_2.expression; - case 188: + case 190: return node === parent_2.expression; - case 134: + case 136: return node === parent_2.expression; - case 137: - case 238: + case 139: + case 240: + case 239: return true; - case 186: + case 188: return parent_2.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent_2); default: if (isExpression(parent_2)) { @@ -4494,6 +4634,10 @@ var ts; return false; } ts.isExpression = isExpression; + function isExternalModuleNameRelative(moduleName) { + return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + } + ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { var moduleState = ts.getModuleInstanceState(node); return moduleState === 1 || @@ -4501,7 +4645,7 @@ var ts; } ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 && node.moduleReference.kind === 230; + return node.kind === 221 && node.moduleReference.kind === 232; } ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration; function getExternalModuleImportEqualsDeclarationExpression(node) { @@ -4510,20 +4654,20 @@ var ts; } ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression; function isInternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 && node.moduleReference.kind !== 230; + return node.kind === 221 && node.moduleReference.kind !== 232; } ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration; function getExternalModuleName(node) { - if (node.kind === 220) { + if (node.kind === 222) { return node.moduleSpecifier; } - if (node.kind === 219) { + if (node.kind === 221) { var reference = node.moduleReference; - if (reference.kind === 230) { + if (reference.kind === 232) { return reference.expression; } } - if (node.kind === 226) { + if (node.kind === 228) { return node.moduleSpecifier; } } @@ -4531,13 +4675,13 @@ var ts; function hasQuestionToken(node) { if (node) { switch (node.kind) { - case 136: + case 138: + case 143: + case 142: + case 246: + case 245: case 141: case 140: - case 244: - case 243: - case 139: - case 138: return node.questionToken !== undefined; } } @@ -4545,9 +4689,9 @@ var ts; } ts.hasQuestionToken = hasQuestionToken; function isJSDocConstructSignature(node) { - return node.kind === 259 && + return node.kind === 261 && node.parameters.length > 0 && - node.parameters[0].type.kind === 261; + node.parameters[0].type.kind === 263; } ts.isJSDocConstructSignature = isJSDocConstructSignature; function getJSDocTag(node, kind) { @@ -4561,24 +4705,24 @@ var ts; } } function getJSDocTypeTag(node) { - return getJSDocTag(node, 267); + return getJSDocTag(node, 269); } ts.getJSDocTypeTag = getJSDocTypeTag; function getJSDocReturnTag(node) { - return getJSDocTag(node, 266); + return getJSDocTag(node, 268); } ts.getJSDocReturnTag = getJSDocReturnTag; function getJSDocTemplateTag(node) { - return getJSDocTag(node, 268); + return getJSDocTag(node, 270); } ts.getJSDocTemplateTag = getJSDocTemplateTag; function getCorrespondingJSDocParameterTag(parameter) { - if (parameter.name && parameter.name.kind === 67) { + if (parameter.name && parameter.name.kind === 69) { var parameterName = parameter.name.text; var docComment = parameter.parent.jsDocComment; if (docComment) { return ts.forEach(docComment.tags, function (t) { - if (t.kind === 265) { + if (t.kind === 267) { var parameterTag = t; var name_6 = parameterTag.preParameterName || parameterTag.postParameterName; if (name_6.text === parameterName) { @@ -4597,12 +4741,12 @@ var ts; function isRestParameter(node) { if (node) { if (node.parserContextFlags & 32) { - if (node.type && node.type.kind === 260) { + if (node.type && node.type.kind === 262) { return true; } var paramTag = getCorrespondingJSDocParameterTag(node); if (paramTag && paramTag.typeExpression) { - return paramTag.typeExpression.type.kind === 260; + return paramTag.typeExpression.type.kind === 262; } } return node.dotDotDotToken !== undefined; @@ -4623,7 +4767,7 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return !!node && (node.kind === 160 || node.kind === 159); + return !!node && (node.kind === 162 || node.kind === 161); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { @@ -4638,34 +4782,34 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 172: - case 161: - case 212: - case 184: - case 142: - case 215: - case 245: - case 228: - case 211: - case 171: - case 143: - case 221: - case 219: - case 224: + case 174: + case 163: + case 214: + case 186: + case 144: + case 217: + case 247: + case 230: case 213: + case 173: + case 145: + case 223: + case 221: + case 226: + case 215: + case 143: + case 142: + case 218: + case 224: + case 138: + case 245: case 141: case 140: + case 146: + case 246: case 216: - case 222: - case 136: - case 243: - case 139: - case 138: - case 144: - case 244: - case 214: - case 135: - case 209: + case 137: + case 211: return true; } return false; @@ -4673,25 +4817,25 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 201: - case 200: - case 208: - case 195: - case 193: - case 192: - case 198: - case 199: - case 197: - case 194: - case 205: - case 202: - case 204: - case 96: - case 207: - case 191: - case 196: case 203: - case 225: + case 202: + case 210: + case 197: + case 195: + case 194: + case 200: + case 201: + case 199: + case 196: + case 207: + case 204: + case 206: + case 98: + case 209: + case 193: + case 198: + case 205: + case 227: return true; default: return false; @@ -4700,13 +4844,13 @@ var ts; ts.isStatement = isStatement; function isClassElement(n) { switch (n.kind) { - case 142: - case 139: + case 144: case 141: case 143: - case 144: - case 140: - case 147: + case 145: + case 146: + case 142: + case 149: return true; default: return false; @@ -4714,11 +4858,11 @@ var ts; } ts.isClassElement = isClassElement; function isDeclarationName(name) { - if (name.kind !== 67 && name.kind !== 9 && name.kind !== 8) { + if (name.kind !== 69 && name.kind !== 9 && name.kind !== 8) { return false; } var parent = name.parent; - if (parent.kind === 224 || parent.kind === 228) { + if (parent.kind === 226 || parent.kind === 230) { if (parent.propertyName) { return true; } @@ -4732,54 +4876,54 @@ var ts; function isIdentifierName(node) { var parent = node.parent; switch (parent.kind) { - case 139: - case 138: case 141: case 140: case 143: - case 144: + case 142: + case 145: + case 146: + case 247: case 245: - case 243: - case 164: + case 166: return parent.name === node; - case 133: + case 135: if (parent.right === node) { - while (parent.kind === 133) { + while (parent.kind === 135) { parent = parent.parent; } - return parent.kind === 152; + return parent.kind === 154; } return false; - case 161: - case 224: + case 163: + case 226: return parent.propertyName === node; - case 228: + case 230: return true; } return false; } ts.isIdentifierName = isIdentifierName; function isAliasSymbolDeclaration(node) { - return node.kind === 219 || - node.kind === 221 && !!node.name || - node.kind === 222 || + return node.kind === 221 || + node.kind === 223 && !!node.name || node.kind === 224 || - node.kind === 228 || - node.kind === 225 && node.expression.kind === 67; + node.kind === 226 || + node.kind === 230 || + node.kind === 227 && node.expression.kind === 69; } ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration; function getClassExtendsHeritageClauseElement(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81); + var heritageClause = getHeritageClause(node.heritageClauses, 83); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 104); + var heritageClause = getHeritageClause(node.heritageClauses, 106); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; function getInterfaceBaseTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81); + var heritageClause = getHeritageClause(node.heritageClauses, 83); return heritageClause ? heritageClause.types : undefined; } ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes; @@ -4848,7 +4992,7 @@ var ts; } ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath; function isKeyword(token) { - return 68 <= token && token <= 132; + return 70 <= token && token <= 134; } ts.isKeyword = isKeyword; function isTrivia(token) { @@ -4861,19 +5005,19 @@ var ts; ts.isAsyncFunctionLike = isAsyncFunctionLike; function hasDynamicName(declaration) { return declaration.name && - declaration.name.kind === 134 && + declaration.name.kind === 136 && !isWellKnownSymbolSyntactically(declaration.name.expression); } ts.hasDynamicName = hasDynamicName; function isWellKnownSymbolSyntactically(node) { - return node.kind === 164 && isESSymbolIdentifier(node.expression); + return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression); } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 67 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8) { return name.text; } - if (name.kind === 134) { + if (name.kind === 136) { var nameExpression = name.expression; if (isWellKnownSymbolSyntactically(nameExpression)) { var rightHandSideName = nameExpression.name.text; @@ -4888,21 +5032,21 @@ var ts; } ts.getPropertyNameForKnownSymbolName = getPropertyNameForKnownSymbolName; function isESSymbolIdentifier(node) { - return node.kind === 67 && node.text === "Symbol"; + return node.kind === 69 && node.text === "Symbol"; } ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 113: - case 116: - case 72: - case 120: - case 75: - case 80: + case 115: + case 118: + case 74: + case 122: + case 77: + case 82: + case 112: case 110: - case 108: - case 109: case 111: + case 113: return true; } return false; @@ -4910,28 +5054,28 @@ var ts; ts.isModifier = isModifier; function isParameterDeclaration(node) { var root = getRootDeclaration(node); - return root.kind === 136; + return root.kind === 138; } ts.isParameterDeclaration = isParameterDeclaration; function getRootDeclaration(node) { - while (node.kind === 161) { + while (node.kind === 163) { node = node.parent.parent; } return node; } ts.getRootDeclaration = getRootDeclaration; function nodeStartsNewLexicalEnvironment(n) { - return isFunctionLike(n) || n.kind === 216 || n.kind === 246; + return isFunctionLike(n) || n.kind === 218 || n.kind === 248; } ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; function cloneEntityName(node) { - if (node.kind === 67) { - var clone_1 = createSynthesizedNode(67); + if (node.kind === 69) { + var clone_1 = createSynthesizedNode(69); clone_1.text = node.text; return clone_1; } else { - var clone_2 = createSynthesizedNode(133); + var clone_2 = createSynthesizedNode(135); clone_2.left = cloneEntityName(node.left); clone_2.left.parent = clone_2; clone_2.right = cloneEntityName(node.right); @@ -5174,7 +5318,7 @@ var ts; ts.getLineOfLocalPosition = getLineOfLocalPosition; function getFirstConstructorWithBody(node) { return ts.forEach(node.members, function (member) { - if (member.kind === 142 && nodeIsPresent(member.body)) { + if (member.kind === 144 && nodeIsPresent(member.body)) { return member; } }); @@ -5201,10 +5345,10 @@ var ts; var setAccessor; if (hasDynamicName(accessor)) { firstAccessor = accessor; - if (accessor.kind === 143) { + if (accessor.kind === 145) { getAccessor = accessor; } - else if (accessor.kind === 144) { + else if (accessor.kind === 146) { setAccessor = accessor; } else { @@ -5213,7 +5357,7 @@ var ts; } else { ts.forEach(declarations, function (member) { - if ((member.kind === 143 || member.kind === 144) + if ((member.kind === 145 || member.kind === 146) && (member.flags & 128) === (accessor.flags & 128)) { var memberName = getPropertyNameForPropertyNameNode(member.name); var accessorName = getPropertyNameForPropertyNameNode(accessor.name); @@ -5224,10 +5368,10 @@ var ts; else if (!secondAccessor) { secondAccessor = member; } - if (member.kind === 143 && !getAccessor) { + if (member.kind === 145 && !getAccessor) { getAccessor = member; } - if (member.kind === 144 && !setAccessor) { + if (member.kind === 146 && !setAccessor) { setAccessor = member; } } @@ -5333,16 +5477,16 @@ var ts; ts.writeCommentRange = writeCommentRange; function modifierToFlag(token) { switch (token) { - case 111: return 128; - case 110: return 16; - case 109: return 64; - case 108: return 32; - case 113: return 256; - case 80: return 1; - case 120: return 2; - case 72: return 32768; - case 75: return 1024; - case 116: return 512; + case 113: return 128; + case 112: return 16; + case 111: return 64; + case 110: return 32; + case 115: return 256; + case 82: return 1; + case 122: return 2; + case 74: return 32768; + case 77: return 1024; + case 118: return 512; } return 0; } @@ -5350,29 +5494,29 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 164: - case 165: - case 167: case 166: - case 231: - case 232: + case 167: + case 169: case 168: - case 162: + case 233: + case 234: case 170: - case 163: - case 184: - case 171: - case 67: + case 164: + case 172: + case 165: + case 186: + case 173: + case 69: case 10: case 8: case 9: case 11: - case 181: - case 82: - case 91: - case 95: - case 97: + case 183: + case 84: case 93: + case 97: + case 99: + case 95: return true; } } @@ -5380,12 +5524,12 @@ var ts; } ts.isLeftHandSideExpression = isLeftHandSideExpression; function isAssignmentOperator(token) { - return token >= 55 && token <= 66; + return token >= 56 && token <= 68; } ts.isAssignmentOperator = isAssignmentOperator; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { - return node.kind === 186 && - node.parent.token === 81 && + return node.kind === 188 && + node.parent.token === 83 && isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; @@ -5394,10 +5538,10 @@ var ts; } ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments; function isSupportedExpressionWithTypeArgumentsRest(node) { - if (node.kind === 67) { + if (node.kind === 69) { return true; } - else if (node.kind === 164) { + else if (isPropertyAccessExpression(node)) { return isSupportedExpressionWithTypeArgumentsRest(node.expression); } else { @@ -5405,16 +5549,16 @@ var ts; } } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 133 && node.parent.right === node) || - (node.parent.kind === 164 && node.parent.name === node); + return (node.parent.kind === 135 && node.parent.right === node) || + (node.parent.kind === 166 && node.parent.name === node); } ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess; function isEmptyObjectLiteralOrArrayLiteral(expression) { var kind = expression.kind; - if (kind === 163) { + if (kind === 165) { return expression.properties.length === 0; } - if (kind === 162) { + if (kind === 164) { return expression.elements.length === 0; } return false; @@ -5623,19 +5767,29 @@ var ts; } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function getTypeParameterOwner(d) { - if (d && d.kind === 135) { + if (d && d.kind === 137) { for (var current = d; current; current = current.parent) { - if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 213) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 215) { return current; } } } } ts.getTypeParameterOwner = getTypeParameterOwner; + function arrayStructurallyIsEqualTo(array1, array2) { + if (!array1 || !array2) { + return false; + } + if (array1.length !== array2.length) { + return false; + } + return ts.arrayIsEqualTo(array1.sort(), array2.sort()); + } + ts.arrayStructurallyIsEqualTo = arrayStructurallyIsEqualTo; })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(270); + var nodeConstructors = new Array(272); ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -5673,20 +5827,26 @@ var ts; var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; var cbNodes = cbNodeArray || cbNode; switch (node.kind) { - case 133: + case 135: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); - case 135: + case 137: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); - case 136: - case 139: + case 246: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.equalsToken) || + visitNode(cbNode, node.objectAssignmentInitializer); case 138: - case 243: - case 244: - case 209: - case 161: + case 141: + case 140: + case 245: + case 211: + case 163: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || @@ -5695,24 +5855,24 @@ var ts; visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); - case 150: - case 151: - case 145: - case 146: + case 152: + case 153: case 147: + case 148: + case 149: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 141: - case 140: - case 142: case 143: + case 142: case 144: - case 171: - case 211: - case 172: + case 145: + case 146: + case 173: + case 213: + case 174: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || @@ -5723,290 +5883,290 @@ var ts; visitNode(cbNode, node.type) || visitNode(cbNode, node.equalsGreaterThanToken) || visitNode(cbNode, node.body); - case 149: + case 151: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); - case 148: + case 150: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); - case 152: - return visitNode(cbNode, node.exprName); - case 153: - return visitNodes(cbNodes, node.members); case 154: - return visitNode(cbNode, node.elementType); + return visitNode(cbNode, node.exprName); case 155: - return visitNodes(cbNodes, node.elementTypes); + return visitNodes(cbNodes, node.members); case 156: + return visitNode(cbNode, node.elementType); case 157: - return visitNodes(cbNodes, node.types); + return visitNodes(cbNodes, node.elementTypes); case 158: - return visitNode(cbNode, node.type); case 159: + return visitNodes(cbNodes, node.types); case 160: - return visitNodes(cbNodes, node.elements); + return visitNode(cbNode, node.type); + case 161: case 162: return visitNodes(cbNodes, node.elements); - case 163: - return visitNodes(cbNodes, node.properties); case 164: + return visitNodes(cbNodes, node.elements); + case 165: + return visitNodes(cbNodes, node.properties); + case 166: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); - case 165: + case 167: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); - case 166: - case 167: + case 168: + case 169: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); - case 168: + case 170: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); - case 169: + case 171: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); - case 170: - return visitNode(cbNode, node.expression); - case 173: - return visitNode(cbNode, node.expression); - case 174: + case 172: return visitNode(cbNode, node.expression); case 175: return visitNode(cbNode, node.expression); - case 177: - return visitNode(cbNode, node.operand); - case 182: - return visitNode(cbNode, node.asteriskToken) || - visitNode(cbNode, node.expression); case 176: return visitNode(cbNode, node.expression); - case 178: - return visitNode(cbNode, node.operand); + case 177: + return visitNode(cbNode, node.expression); case 179: + return visitNode(cbNode, node.operand); + case 184: + return visitNode(cbNode, node.asteriskToken) || + visitNode(cbNode, node.expression); + case 178: + return visitNode(cbNode, node.expression); + case 180: + return visitNode(cbNode, node.operand); + case 181: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); - case 187: + case 189: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); - case 180: + case 182: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); - case 183: + case 185: return visitNode(cbNode, node.expression); - case 190: - case 217: + case 192: + case 219: return visitNodes(cbNodes, node.statements); - case 246: + case 248: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); - case 191: + case 193: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); - case 210: + case 212: return visitNodes(cbNodes, node.declarations); - case 193: + case 195: return visitNode(cbNode, node.expression); - case 194: + case 196: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); - case 195: + case 197: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); - case 196: + case 198: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 197: + case 199: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); - case 198: - return visitNode(cbNode, node.initializer) || - visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); - case 199: - return visitNode(cbNode, node.initializer) || - visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); case 200: - case 201: - return visitNode(cbNode, node.label); - case 202: - return visitNode(cbNode, node.expression); - case 203: - return visitNode(cbNode, node.expression) || + return visitNode(cbNode, node.initializer) || + visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 201: + return visitNode(cbNode, node.initializer) || + visitNode(cbNode, node.expression) || + visitNode(cbNode, node.statement); + case 202: + case 203: + return visitNode(cbNode, node.label); case 204: - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.caseBlock); - case 218: - return visitNodes(cbNodes, node.clauses); - case 239: - return visitNode(cbNode, node.expression) || - visitNodes(cbNodes, node.statements); - case 240: - return visitNodes(cbNodes, node.statements); + return visitNode(cbNode, node.expression); case 205: - return visitNode(cbNode, node.label) || + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 206: - return visitNode(cbNode, node.expression); + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.caseBlock); + case 220: + return visitNodes(cbNodes, node.clauses); + case 241: + return visitNode(cbNode, node.expression) || + visitNodes(cbNodes, node.statements); + case 242: + return visitNodes(cbNodes, node.statements); case 207: + return visitNode(cbNode, node.label) || + visitNode(cbNode, node.statement); + case 208: + return visitNode(cbNode, node.expression); + case 209: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); - case 242: + case 244: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); - case 137: + case 139: return visitNode(cbNode, node.expression); - case 212: - case 184: - return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNodes, node.typeParameters) || - visitNodes(cbNodes, node.heritageClauses) || - visitNodes(cbNodes, node.members); - case 213: - return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNodes, node.typeParameters) || - visitNodes(cbNodes, node.heritageClauses) || - visitNodes(cbNodes, node.members); case 214: + case 186: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || - visitNode(cbNode, node.type); + visitNodes(cbNodes, node.heritageClauses) || + visitNodes(cbNodes, node.members); case 215: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeParameters) || + visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 245: - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.initializer); case 216: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeParameters) || + visitNode(cbNode, node.type); + case 217: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.members); + case 247: + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.initializer); + case 218: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); - case 219: + case 221: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); - case 220: + case 222: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); - case 221: + case 223: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 222: + case 224: return visitNode(cbNode, node.name); - case 223: - case 227: + case 225: + case 229: return visitNodes(cbNodes, node.elements); - case 226: + case 228: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); - case 224: - case 228: + case 226: + case 230: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); - case 225: + case 227: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); - case 181: + case 183: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); - case 188: + case 190: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); - case 134: + case 136: return visitNode(cbNode, node.expression); - case 241: + case 243: return visitNodes(cbNodes, node.types); - case 186: + case 188: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); - case 230: + case 232: return visitNode(cbNode, node.expression); - case 229: - return visitNodes(cbNodes, node.decorators); case 231: + return visitNodes(cbNodes, node.decorators); + case 233: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); - case 232: - case 233: + case 234: + case 235: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); - case 236: + case 238: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); + case 239: + return visitNode(cbNode, node.expression); + case 240: + return visitNode(cbNode, node.expression); case 237: - return visitNode(cbNode, node.expression); - case 238: - return visitNode(cbNode, node.expression); - case 235: return visitNode(cbNode, node.tagName); - case 247: - return visitNode(cbNode, node.type); - case 251: - return visitNodes(cbNodes, node.types); - case 252: - return visitNodes(cbNodes, node.types); - case 250: - return visitNode(cbNode, node.elementType); - case 254: + case 249: return visitNode(cbNode, node.type); case 253: + return visitNodes(cbNodes, node.types); + case 254: + return visitNodes(cbNodes, node.types); + case 252: + return visitNode(cbNode, node.elementType); + case 256: return visitNode(cbNode, node.type); case 255: - return visitNodes(cbNodes, node.members); + return visitNode(cbNode, node.type); case 257: + return visitNodes(cbNodes, node.members); + case 259: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); - case 258: - return visitNode(cbNode, node.type); - case 259: - return visitNodes(cbNodes, node.parameters) || - visitNode(cbNode, node.type); case 260: return visitNode(cbNode, node.type); case 261: - return visitNode(cbNode, node.type); + return visitNodes(cbNodes, node.parameters) || + visitNode(cbNode, node.type); case 262: return visitNode(cbNode, node.type); - case 256: + case 263: + return visitNode(cbNode, node.type); + case 264: + return visitNode(cbNode, node.type); + case 258: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); - case 263: - return visitNodes(cbNodes, node.tags); case 265: + return visitNodes(cbNodes, node.tags); + case 267: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); - case 266: - return visitNode(cbNode, node.typeExpression); - case 267: - return visitNode(cbNode, node.typeExpression); case 268: + return visitNode(cbNode, node.typeExpression); + case 269: + return visitNode(cbNode, node.typeExpression); + case 270: return visitNodes(cbNodes, node.typeParameters); } } @@ -6102,9 +6262,9 @@ var ts; return; function visit(node) { switch (node.kind) { - case 191: - case 211: - case 136: + case 193: + case 213: + case 138: addJSDocComment(node); } forEachChild(node, visit); @@ -6138,7 +6298,7 @@ var ts; } Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - var sourceFile = createNode(246, 0); + var sourceFile = createNode(248, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; @@ -6297,16 +6457,16 @@ var ts; return speculationHelper(callback, false); } function isIdentifier() { - if (token === 67) { + if (token === 69) { return true; } - if (token === 112 && inYieldContext()) { + if (token === 114 && inYieldContext()) { return false; } - if (token === 117 && inAwaitContext()) { + if (token === 119 && inAwaitContext()) { return false; } - return token > 103; + return token > 105; } function parseExpected(kind, diagnosticMessage, shouldAdvance) { if (shouldAdvance === void 0) { shouldAdvance = true; } @@ -6402,15 +6562,15 @@ var ts; function createIdentifier(isIdentifier, diagnosticMessage) { identifierCount++; if (isIdentifier) { - var node = createNode(67); - if (token !== 67) { + var node = createNode(69); + if (token !== 69) { node.originalKeywordKind = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); } - return createMissingNode(67, false, diagnosticMessage || ts.Diagnostics.Identifier_expected); + return createMissingNode(69, false, diagnosticMessage || ts.Diagnostics.Identifier_expected); } function parseIdentifier(diagnosticMessage) { return createIdentifier(isIdentifier(), diagnosticMessage); @@ -6442,7 +6602,7 @@ var ts; return token === 9 || token === 8 || ts.tokenIsIdentifierOrKeyword(token); } function parseComputedPropertyName() { - var node = createNode(134); + var node = createNode(136); parseExpected(19); node.expression = allowInAnd(parseExpression); parseExpected(20); @@ -6452,20 +6612,27 @@ var ts; return token === t && tryParse(nextTokenCanFollowModifier); } function nextTokenCanFollowModifier() { - if (token === 72) { - return nextToken() === 79; + if (token === 74) { + return nextToken() === 81; } - if (token === 80) { + if (token === 82) { nextToken(); - if (token === 75) { + if (token === 77) { return lookAhead(nextTokenIsClassOrFunction); } return token !== 37 && token !== 15 && canFollowModifier(); } - if (token === 75) { + if (token === 77) { return nextTokenIsClassOrFunction(); } + if (token === 113) { + nextToken(); + return canFollowModifier(); + } nextToken(); + if (scanner.hasPrecedingLineBreak()) { + return false; + } return canFollowModifier(); } function parseAnyContextualModifier() { @@ -6479,7 +6646,7 @@ var ts; } function nextTokenIsClassOrFunction() { nextToken(); - return token === 71 || token === 85; + return token === 73 || token === 87; } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -6492,7 +6659,7 @@ var ts; case 3: return !(token === 23 && inErrorRecovery) && isStartOfStatement(); case 2: - return token === 69 || token === 75; + return token === 71 || token === 77; case 4: return isStartOfTypeMember(); case 5: @@ -6548,7 +6715,7 @@ var ts; ts.Debug.assert(token === 15); if (nextToken() === 16) { var next = nextToken(); - return next === 24 || next === 15 || next === 81 || next === 104; + return next === 24 || next === 15 || next === 83 || next === 106; } return true; } @@ -6561,8 +6728,8 @@ var ts; return ts.tokenIsIdentifierOrKeyword(token); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 104 || - token === 81) { + if (token === 106 || + token === 83) { return lookAhead(nextTokenIsStartOfExpression); } return false; @@ -6586,13 +6753,13 @@ var ts; case 21: return token === 16; case 3: - return token === 16 || token === 69 || token === 75; + return token === 16 || token === 71 || token === 77; case 7: - return token === 15 || token === 81 || token === 104; + return token === 15 || token === 83 || token === 106; case 8: return isVariableDeclaratorListTerminator(); case 17: - return token === 27 || token === 17 || token === 15 || token === 81 || token === 104; + return token === 27 || token === 17 || token === 15 || token === 83 || token === 106; case 11: return token === 18 || token === 23; case 15: @@ -6606,11 +6773,11 @@ var ts; case 20: return token === 15 || token === 16; case 13: - return token === 27 || token === 38; + return token === 27 || token === 39; case 14: return token === 25 && lookAhead(nextTokenIsSlash); case 22: - return token === 18 || token === 53 || token === 16; + return token === 18 || token === 54 || token === 16; case 23: return token === 27 || token === 16; case 25: @@ -6731,17 +6898,17 @@ var ts; function isReusableClassMember(node) { if (node) { switch (node.kind) { - case 142: - case 147: - case 143: case 144: - case 139: - case 189: - return true; + case 149: + case 145: + case 146: case 141: + case 191: + return true; + case 143: var methodDeclaration = node; - var nameIsConstructor = methodDeclaration.name.kind === 67 && - methodDeclaration.name.originalKeywordKind === 119; + var nameIsConstructor = methodDeclaration.name.kind === 69 && + methodDeclaration.name.originalKeywordKind === 121; return !nameIsConstructor; } } @@ -6750,8 +6917,8 @@ var ts; function isReusableSwitchClause(node) { if (node) { switch (node.kind) { - case 239: - case 240: + case 241: + case 242: return true; } } @@ -6760,65 +6927,65 @@ var ts; function isReusableStatement(node) { if (node) { switch (node.kind) { - case 211: - case 191: - case 190: - case 194: + case 213: case 193: - case 206: - case 202: - case 204: - case 201: - case 200: - case 198: - case 199: - case 197: - case 196: - case 203: case 192: - case 207: - case 205: + case 196: case 195: case 208: - case 220: - case 219: - case 226: - case 225: - case 216: - case 212: - case 213: - case 215: + case 204: + case 206: + case 203: + case 202: + case 200: + case 201: + case 199: + case 198: + case 205: + case 194: + case 209: + case 207: + case 197: + case 210: + case 222: + case 221: + case 228: + case 227: + case 218: case 214: + case 215: + case 217: + case 216: return true; } } return false; } function isReusableEnumMember(node) { - return node.kind === 245; + return node.kind === 247; } function isReusableTypeMember(node) { if (node) { switch (node.kind) { - case 146: + case 148: + case 142: + case 149: case 140: case 147: - case 138: - case 145: return true; } } return false; } function isReusableVariableDeclaration(node) { - if (node.kind !== 209) { + if (node.kind !== 211) { return false; } var variableDeclarator = node; return variableDeclarator.initializer === undefined; } function isReusableParameter(node) { - if (node.kind !== 136) { + if (node.kind !== 138) { return false; } var parameter = node; @@ -6918,7 +7085,7 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var entity = parseIdentifier(diagnosticMessage); while (parseOptional(21)) { - var node = createNode(133, entity.pos); + var node = createNode(135, entity.pos); node.left = entity; node.right = parseRightSideOfDot(allowReservedWords); entity = finishNode(node); @@ -6929,13 +7096,13 @@ var ts; if (scanner.hasPrecedingLineBreak() && ts.tokenIsIdentifierOrKeyword(token)) { var matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); if (matchesPattern) { - return createMissingNode(67, true, ts.Diagnostics.Identifier_expected); + return createMissingNode(69, true, ts.Diagnostics.Identifier_expected); } } return allowIdentifierNames ? parseIdentifierName() : parseIdentifier(); } function parseTemplateExpression() { - var template = createNode(181); + var template = createNode(183); template.head = parseLiteralNode(); ts.Debug.assert(template.head.kind === 12, "Template head has wrong token kind"); var templateSpans = []; @@ -6948,7 +7115,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(188); + var span = createNode(190); span.expression = allowInAnd(parseExpression); var literal; if (token === 16) { @@ -6983,14 +7150,14 @@ var ts; } function parseTypeReferenceOrTypePredicate() { var typeName = parseEntityName(false, ts.Diagnostics.Type_expected); - if (typeName.kind === 67 && token === 122 && !scanner.hasPrecedingLineBreak()) { + if (typeName.kind === 69 && token === 124 && !scanner.hasPrecedingLineBreak()) { nextToken(); - var node_1 = createNode(148, typeName.pos); + var node_1 = createNode(150, typeName.pos); node_1.parameterName = typeName; node_1.type = parseType(); return finishNode(node_1); } - var node = createNode(149, typeName.pos); + var node = createNode(151, typeName.pos); node.typeName = typeName; if (!scanner.hasPrecedingLineBreak() && token === 25) { node.typeArguments = parseBracketedList(18, parseType, 25, 27); @@ -6998,15 +7165,15 @@ var ts; return finishNode(node); } function parseTypeQuery() { - var node = createNode(152); - parseExpected(99); + var node = createNode(154); + parseExpected(101); node.exprName = parseEntityName(true); return finishNode(node); } function parseTypeParameter() { - var node = createNode(135); + var node = createNode(137); node.name = parseIdentifier(); - if (parseOptional(81)) { + if (parseOptional(83)) { if (isStartOfType() || !isStartOfExpression()) { node.constraint = parseType(); } @@ -7022,7 +7189,7 @@ var ts; } } function parseParameterType() { - if (parseOptional(53)) { + if (parseOptional(54)) { return token === 9 ? parseLiteralNode(true) : parseType(); @@ -7030,7 +7197,7 @@ var ts; return undefined; } function isStartOfParameter() { - return token === 22 || isIdentifierOrPattern() || ts.isModifier(token) || token === 54; + return token === 22 || isIdentifierOrPattern() || ts.isModifier(token) || token === 55; } function setModifiers(node, modifiers) { if (modifiers) { @@ -7039,7 +7206,7 @@ var ts; } } function parseParameter() { - var node = createNode(136); + var node = createNode(138); node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(22); @@ -7047,7 +7214,7 @@ var ts; if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(token)) { nextToken(); } - node.questionToken = parseOptionalToken(52); + node.questionToken = parseOptionalToken(53); node.type = parseParameterType(); node.initializer = parseBindingElementInitializer(true); return finishNode(node); @@ -7094,10 +7261,10 @@ var ts; } function parseSignatureMember(kind) { var node = createNode(kind); - if (kind === 146) { - parseExpected(90); + if (kind === 148) { + parseExpected(92); } - fillSignature(53, false, false, false, node); + fillSignature(54, false, false, false, node); parseTypeMemberSemicolon(); return finishNode(node); } @@ -7124,17 +7291,17 @@ var ts; else { nextToken(); } - if (token === 53 || token === 24) { + if (token === 54 || token === 24) { return true; } - if (token !== 52) { + if (token !== 53) { return false; } nextToken(); - return token === 53 || token === 24 || token === 20; + return token === 54 || token === 24 || token === 20; } function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) { - var node = createNode(147, fullStart); + var node = createNode(149, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(16, parseParameter, 19, 20); @@ -7145,17 +7312,17 @@ var ts; function parsePropertyOrMethodSignature() { var fullStart = scanner.getStartPos(); var name = parsePropertyName(); - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (token === 17 || token === 25) { - var method = createNode(140, fullStart); + var method = createNode(142, fullStart); method.name = name; method.questionToken = questionToken; - fillSignature(53, false, false, false, method); + fillSignature(54, false, false, false, method); parseTypeMemberSemicolon(); return finishNode(method); } else { - var property = createNode(138, fullStart); + var property = createNode(140, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -7189,22 +7356,22 @@ var ts; nextToken(); return token === 17 || token === 25 || - token === 52 || token === 53 || + token === 54 || canParseSemicolon(); } function parseTypeMember() { switch (token) { case 17: case 25: - return parseSignatureMember(145); + return parseSignatureMember(147); case 19: return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), undefined, undefined) : parsePropertyOrMethodSignature(); - case 90: + case 92: if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(146); + return parseSignatureMember(148); } case 9: case 8: @@ -7234,7 +7401,7 @@ var ts; return token === 17 || token === 25; } function parseTypeLiteral() { - var node = createNode(153); + var node = createNode(155); node.members = parseObjectTypeMembers(); return finishNode(node); } @@ -7250,12 +7417,12 @@ var ts; return members; } function parseTupleType() { - var node = createNode(155); + var node = createNode(157); node.elementTypes = parseBracketedList(19, parseType, 19, 20); return finishNode(node); } function parseParenthesizedType() { - var node = createNode(158); + var node = createNode(160); parseExpected(17); node.type = parseType(); parseExpected(18); @@ -7263,8 +7430,8 @@ var ts; } function parseFunctionOrConstructorType(kind) { var node = createNode(kind); - if (kind === 151) { - parseExpected(90); + if (kind === 153) { + parseExpected(92); } fillSignature(34, false, false, false, node); return finishNode(node); @@ -7275,16 +7442,17 @@ var ts; } function parseNonArrayType() { switch (token) { - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: + case 120: + case 131: var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReferenceOrTypePredicate(); - case 101: + case 103: + case 97: return parseTokenNode(); - case 99: + case 101: return parseTypeQuery(); case 15: return parseTypeLiteral(); @@ -7298,17 +7466,18 @@ var ts; } function isStartOfType() { switch (token) { - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: + case 120: + case 131: + case 103: + case 97: case 101: - case 99: case 15: case 19: case 25: - case 90: + case 92: return true; case 17: return lookAhead(isStartOfParenthesizedOrFunctionType); @@ -7324,7 +7493,7 @@ var ts; var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(19)) { parseExpected(20); - var node = createNode(154, type.pos); + var node = createNode(156, type.pos); node.elementType = type; type = finishNode(node); } @@ -7346,10 +7515,10 @@ var ts; return type; } function parseIntersectionTypeOrHigher() { - return parseUnionOrIntersectionType(157, parseArrayTypeOrHigher, 45); + return parseUnionOrIntersectionType(159, parseArrayTypeOrHigher, 46); } function parseUnionTypeOrHigher() { - return parseUnionOrIntersectionType(156, parseIntersectionTypeOrHigher, 46); + return parseUnionOrIntersectionType(158, parseIntersectionTypeOrHigher, 47); } function isStartOfFunctionType() { if (token === 25) { @@ -7364,8 +7533,8 @@ var ts; } if (isIdentifier() || ts.isModifier(token)) { nextToken(); - if (token === 53 || token === 24 || - token === 52 || token === 55 || + if (token === 54 || token === 24 || + token === 53 || token === 56 || isIdentifier() || ts.isModifier(token)) { return true; } @@ -7383,23 +7552,23 @@ var ts; } function parseTypeWorker() { if (isStartOfFunctionType()) { - return parseFunctionOrConstructorType(150); + return parseFunctionOrConstructorType(152); } - if (token === 90) { - return parseFunctionOrConstructorType(151); + if (token === 92) { + return parseFunctionOrConstructorType(153); } return parseUnionTypeOrHigher(); } function parseTypeAnnotation() { - return parseOptional(53) ? parseType() : undefined; + return parseOptional(54) ? parseType() : undefined; } function isStartOfLeftHandSideExpression() { switch (token) { + case 97: case 95: case 93: - case 91: - case 97: - case 82: + case 99: + case 84: case 8: case 9: case 11: @@ -7407,12 +7576,12 @@ var ts; case 17: case 19: case 15: - case 85: - case 71: - case 90: - case 38: - case 59: - case 67: + case 87: + case 73: + case 92: + case 39: + case 61: + case 69: return true; default: return isIdentifier(); @@ -7425,16 +7594,16 @@ var ts; switch (token) { case 35: case 36: + case 50: case 49: - case 48: - case 76: - case 99: + case 78: case 101: - case 40: + case 103: case 41: + case 42: case 25: - case 117: - case 112: + case 119: + case 114: return true; default: if (isBinaryOperator()) { @@ -7445,9 +7614,9 @@ var ts; } function isStartOfExpressionStatement() { return token !== 15 && - token !== 85 && - token !== 71 && - token !== 54 && + token !== 87 && + token !== 73 && + token !== 55 && isStartOfExpression(); } function allowInAndParseExpression() { @@ -7469,12 +7638,12 @@ var ts; return expr; } function parseInitializer(inParameter) { - if (token !== 55) { + if (token !== 56) { if (scanner.hasPrecedingLineBreak() || (inParameter && token === 15) || !isStartOfExpression()) { return undefined; } } - parseExpected(55); + parseExpected(56); return parseAssignmentExpressionOrHigher(); } function parseAssignmentExpressionOrHigher() { @@ -7486,7 +7655,7 @@ var ts; return arrowExpression; } var expr = parseBinaryExpressionOrHigher(0); - if (expr.kind === 67 && token === 34) { + if (expr.kind === 69 && token === 34) { return parseSimpleArrowFunctionExpression(expr); } if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) { @@ -7495,7 +7664,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 112) { + if (token === 114) { if (inYieldContext()) { return true; } @@ -7508,7 +7677,7 @@ var ts; return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression() { - var node = createNode(182); + var node = createNode(184); nextToken(); if (!scanner.hasPrecedingLineBreak() && (token === 37 || isStartOfExpression())) { @@ -7522,8 +7691,8 @@ var ts; } function parseSimpleArrowFunctionExpression(identifier) { ts.Debug.assert(token === 34, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - var node = createNode(172, identifier.pos); - var parameter = createNode(136, identifier.pos); + var node = createNode(174, identifier.pos); + var parameter = createNode(138, identifier.pos); parameter.name = identifier; finishNode(parameter); node.parameters = [parameter]; @@ -7553,7 +7722,7 @@ var ts; return finishNode(arrowFunction); } function isParenthesizedArrowFunctionExpression() { - if (token === 17 || token === 25 || token === 116) { + if (token === 17 || token === 25 || token === 118) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } if (token === 34) { @@ -7562,7 +7731,7 @@ var ts; return 0; } function isParenthesizedArrowFunctionExpressionWorker() { - if (token === 116) { + if (token === 118) { nextToken(); if (scanner.hasPrecedingLineBreak()) { return 0; @@ -7578,7 +7747,7 @@ var ts; var third = nextToken(); switch (third) { case 34: - case 53: + case 54: case 15: return 1; default: @@ -7594,7 +7763,7 @@ var ts; if (!isIdentifier()) { return 0; } - if (nextToken() === 53) { + if (nextToken() === 54) { return 1; } return 2; @@ -7607,10 +7776,10 @@ var ts; if (sourceFile.languageVariant === 1) { var isArrowFunctionInJsx = lookAhead(function () { var third = nextToken(); - if (third === 81) { + if (third === 83) { var fourth = nextToken(); switch (fourth) { - case 55: + case 56: case 27: return false; default: @@ -7634,10 +7803,10 @@ var ts; return parseParenthesizedArrowFunctionExpressionHead(false); } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) { - var node = createNode(172); + var node = createNode(174); setModifiers(node, parseModifiersForArrowFunction()); var isAsync = !!(node.flags & 512); - fillSignature(53, false, isAsync, !allowAmbiguity, node); + fillSignature(54, false, isAsync, !allowAmbiguity, node); if (!node.parameters) { return undefined; } @@ -7651,8 +7820,8 @@ var ts; return parseFunctionBlock(false, isAsync, false); } if (token !== 23 && - token !== 85 && - token !== 71 && + token !== 87 && + token !== 73 && isStartOfStatement() && !isStartOfExpressionStatement()) { return parseFunctionBlock(false, isAsync, true); @@ -7662,15 +7831,15 @@ var ts; : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher); } function parseConditionalExpressionRest(leftOperand) { - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (!questionToken) { return leftOperand; } - var node = createNode(180, leftOperand.pos); + var node = createNode(182, leftOperand.pos); node.condition = leftOperand; node.questionToken = questionToken; node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); - node.colonToken = parseExpectedToken(53, false, ts.Diagnostics._0_expected, ts.tokenToString(53)); + node.colonToken = parseExpectedToken(54, false, ts.Diagnostics._0_expected, ts.tokenToString(54)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -7679,19 +7848,22 @@ var ts; return parseBinaryExpressionRest(precedence, leftOperand); } function isInOrOfKeyword(t) { - return t === 88 || t === 132; + return t === 90 || t === 134; } function parseBinaryExpressionRest(precedence, leftOperand) { while (true) { reScanGreaterToken(); var newPrecedence = getBinaryOperatorPrecedence(); - if (newPrecedence <= precedence) { + var consumeCurrentOperator = token === 38 ? + newPrecedence >= precedence : + newPrecedence > precedence; + if (!consumeCurrentOperator) { break; } - if (token === 88 && inDisallowInContext()) { + if (token === 90 && inDisallowInContext()) { break; } - if (token === 114) { + if (token === 116) { if (scanner.hasPrecedingLineBreak()) { break; } @@ -7707,22 +7879,22 @@ var ts; return leftOperand; } function isBinaryOperator() { - if (inDisallowInContext() && token === 88) { + if (inDisallowInContext() && token === 90) { return false; } return getBinaryOperatorPrecedence() > 0; } function getBinaryOperatorPrecedence() { switch (token) { - case 51: + case 52: return 1; - case 50: + case 51: return 2; - case 46: - return 3; case 47: + return 3; + case 48: return 4; - case 45: + case 46: return 5; case 30: case 31: @@ -7733,64 +7905,66 @@ var ts; case 27: case 28: case 29: - case 89: - case 88: - case 114: + case 91: + case 90: + case 116: return 7; - case 42: case 43: case 44: + case 45: return 8; case 35: case 36: return 9; case 37: - case 38: case 39: + case 40: return 10; + case 38: + return 11; } return -1; } function makeBinaryExpression(left, operatorToken, right) { - var node = createNode(179, left.pos); + var node = createNode(181, left.pos); node.left = left; node.operatorToken = operatorToken; node.right = right; return finishNode(node); } function makeAsExpression(left, right) { - var node = createNode(187, left.pos); + var node = createNode(189, left.pos); node.expression = left; node.type = right; return finishNode(node); } function parsePrefixUnaryExpression() { - var node = createNode(177); + var node = createNode(179); node.operator = token; nextToken(); - node.operand = parseUnaryExpressionOrHigher(); + node.operand = parseSimpleUnaryExpression(); return finishNode(node); } function parseDeleteExpression() { - var node = createNode(173); + var node = createNode(175); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseTypeOfExpression() { - var node = createNode(174); + var node = createNode(176); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseVoidExpression() { - var node = createNode(175); + var node = createNode(177); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function isAwaitExpression() { - if (token === 117) { + if (token === 119) { if (inAwaitContext()) { return true; } @@ -7799,45 +7973,87 @@ var ts; return false; } function parseAwaitExpression() { - var node = createNode(176); + var node = createNode(178); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseUnaryExpressionOrHigher() { if (isAwaitExpression()) { return parseAwaitExpression(); } + if (isIncrementExpression()) { + var incrementExpression = parseIncrementExpression(); + return token === 38 ? + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : + incrementExpression; + } + var unaryOperator = token; + var simpleUnaryExpression = parseSimpleUnaryExpression(); + if (token === 38) { + var diagnostic; + var start = ts.skipTrivia(sourceText, simpleUnaryExpression.pos); + if (simpleUnaryExpression.kind === 171) { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses); + } + else { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, ts.tokenToString(unaryOperator)); + } + } + return simpleUnaryExpression; + } + function parseSimpleUnaryExpression() { switch (token) { case 35: case 36: + case 50: case 49: - case 48: - case 40: - case 41: return parsePrefixUnaryExpression(); - case 76: + case 78: return parseDeleteExpression(); - case 99: - return parseTypeOfExpression(); case 101: + return parseTypeOfExpression(); + case 103: return parseVoidExpression(); case 25: - if (sourceFile.languageVariant !== 1) { - return parseTypeAssertion(); - } - if (lookAhead(nextTokenIsIdentifierOrKeyword)) { - return parseJsxElementOrSelfClosingElement(true); - } + return parseTypeAssertion(); default: - return parsePostfixExpressionOrHigher(); + return parseIncrementExpression(); } } - function parsePostfixExpressionOrHigher() { + function isIncrementExpression() { + switch (token) { + case 35: + case 36: + case 50: + case 49: + case 78: + case 101: + case 103: + return false; + case 25: + if (sourceFile.languageVariant !== 1) { + return false; + } + default: + return true; + } + } + function parseIncrementExpression() { + if (token === 41 || token === 42) { + var node = createNode(179); + node.operator = token; + nextToken(); + node.operand = parseLeftHandSideExpressionOrHigher(); + return finishNode(node); + } + else if (sourceFile.languageVariant === 1 && token === 25 && lookAhead(nextTokenIsIdentifierOrKeyword)) { + return parseJsxElementOrSelfClosingElement(true); + } var expression = parseLeftHandSideExpressionOrHigher(); ts.Debug.assert(ts.isLeftHandSideExpression(expression)); - if ((token === 40 || token === 41) && !scanner.hasPrecedingLineBreak()) { - var node = createNode(178, expression.pos); + if ((token === 41 || token === 42) && !scanner.hasPrecedingLineBreak()) { + var node = createNode(180, expression.pos); node.operand = expression; node.operator = token; nextToken(); @@ -7846,7 +8062,7 @@ var ts; return expression; } function parseLeftHandSideExpressionOrHigher() { - var expression = token === 93 + var expression = token === 95 ? parseSuperExpression() : parseMemberExpressionOrHigher(); return parseCallExpressionRest(expression); @@ -7860,7 +8076,7 @@ var ts; if (token === 17 || token === 21 || token === 19) { return expression; } - var node = createNode(164, expression.pos); + var node = createNode(166, expression.pos); node.expression = expression; node.dotToken = parseExpectedToken(21, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); @@ -7868,26 +8084,26 @@ var ts; } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); - if (opening.kind === 233) { - var node = createNode(231, opening.pos); + if (opening.kind === 235) { + var node = createNode(233, opening.pos); node.openingElement = opening; node.children = parseJsxChildren(node.openingElement.tagName); node.closingElement = parseJsxClosingElement(inExpressionContext); return finishNode(node); } else { - ts.Debug.assert(opening.kind === 232); + ts.Debug.assert(opening.kind === 234); return opening; } } function parseJsxText() { - var node = createNode(234, scanner.getStartPos()); + var node = createNode(236, scanner.getStartPos()); token = scanner.scanJsxToken(); return finishNode(node); } function parseJsxChild() { switch (token) { - case 234: + case 236: return parseJsxText(); case 15: return parseJsxExpression(false); @@ -7923,11 +8139,11 @@ var ts; var attributes = parseList(13, parseJsxAttribute); var node; if (token === 27) { - node = createNode(233, fullStart); + node = createNode(235, fullStart); scanJsxText(); } else { - parseExpected(38); + parseExpected(39); if (inExpressionContext) { parseExpected(27); } @@ -7935,7 +8151,7 @@ var ts; parseExpected(27, undefined, false); scanJsxText(); } - node = createNode(232, fullStart); + node = createNode(234, fullStart); } node.tagName = tagName; node.attributes = attributes; @@ -7946,7 +8162,7 @@ var ts; var elementName = parseIdentifierName(); while (parseOptional(21)) { scanJsxIdentifier(); - var node = createNode(133, elementName.pos); + var node = createNode(135, elementName.pos); node.left = elementName; node.right = parseIdentifierName(); elementName = finishNode(node); @@ -7954,7 +8170,7 @@ var ts; return elementName; } function parseJsxExpression(inExpressionContext) { - var node = createNode(238); + var node = createNode(240); parseExpected(15); if (token !== 16) { node.expression = parseExpression(); @@ -7973,9 +8189,9 @@ var ts; return parseJsxSpreadAttribute(); } scanJsxIdentifier(); - var node = createNode(236); + var node = createNode(238); node.name = parseIdentifierName(); - if (parseOptional(55)) { + if (parseOptional(56)) { switch (token) { case 9: node.initializer = parseLiteralNode(); @@ -7988,7 +8204,7 @@ var ts; return finishNode(node); } function parseJsxSpreadAttribute() { - var node = createNode(237); + var node = createNode(239); parseExpected(15); parseExpected(22); node.expression = parseExpression(); @@ -7996,7 +8212,7 @@ var ts; return finishNode(node); } function parseJsxClosingElement(inExpressionContext) { - var node = createNode(235); + var node = createNode(237); parseExpected(26); node.tagName = parseJsxElementName(); if (inExpressionContext) { @@ -8009,18 +8225,18 @@ var ts; return finishNode(node); } function parseTypeAssertion() { - var node = createNode(169); + var node = createNode(171); parseExpected(25); node.type = parseType(); parseExpected(27); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseMemberExpressionRest(expression) { while (true) { var dotToken = parseOptionalToken(21); if (dotToken) { - var propertyAccess = createNode(164, expression.pos); + var propertyAccess = createNode(166, expression.pos); propertyAccess.expression = expression; propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(true); @@ -8028,7 +8244,7 @@ var ts; continue; } if (!inDecoratorContext() && parseOptional(19)) { - var indexedAccess = createNode(165, expression.pos); + var indexedAccess = createNode(167, expression.pos); indexedAccess.expression = expression; if (token !== 20) { indexedAccess.argumentExpression = allowInAnd(parseExpression); @@ -8042,7 +8258,7 @@ var ts; continue; } if (token === 11 || token === 12) { - var tagExpression = createNode(168, expression.pos); + var tagExpression = createNode(170, expression.pos); tagExpression.tag = expression; tagExpression.template = token === 11 ? parseLiteralNode() @@ -8061,7 +8277,7 @@ var ts; if (!typeArguments) { return expression; } - var callExpr = createNode(166, expression.pos); + var callExpr = createNode(168, expression.pos); callExpr.expression = expression; callExpr.typeArguments = typeArguments; callExpr.arguments = parseArgumentList(); @@ -8069,7 +8285,7 @@ var ts; continue; } else if (token === 17) { - var callExpr = createNode(166, expression.pos); + var callExpr = createNode(168, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); expression = finishNode(callExpr); @@ -8102,18 +8318,18 @@ var ts; case 21: case 18: case 20: - case 53: + case 54: case 23: - case 52: + case 53: case 30: case 32: case 31: case 33: - case 50: case 51: - case 47: - case 45: + case 52: + case 48: case 46: + case 47: case 16: case 1: return true; @@ -8129,11 +8345,11 @@ var ts; case 9: case 11: return parseLiteralNode(); + case 97: case 95: case 93: - case 91: - case 97: - case 82: + case 99: + case 84: return parseTokenNode(); case 17: return parseParenthesizedExpression(); @@ -8141,19 +8357,19 @@ var ts; return parseArrayLiteralExpression(); case 15: return parseObjectLiteralExpression(); - case 116: + case 118: if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { break; } return parseFunctionExpression(); - case 71: + case 73: return parseClassExpression(); - case 85: + case 87: return parseFunctionExpression(); - case 90: + case 92: return parseNewExpression(); - case 38: - case 59: + case 39: + case 61: if (reScanSlashToken() === 10) { return parseLiteralNode(); } @@ -8164,28 +8380,28 @@ var ts; return parseIdentifier(ts.Diagnostics.Expression_expected); } function parseParenthesizedExpression() { - var node = createNode(170); + var node = createNode(172); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); return finishNode(node); } function parseSpreadElement() { - var node = createNode(183); + var node = createNode(185); parseExpected(22); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); } function parseArgumentOrArrayLiteralElement() { return token === 22 ? parseSpreadElement() : - token === 24 ? createNode(185) : + token === 24 ? createNode(187) : parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression() { - var node = createNode(162); + var node = createNode(164); parseExpected(19); if (scanner.hasPrecedingLineBreak()) node.flags |= 2048; @@ -8194,11 +8410,11 @@ var ts; return finishNode(node); } function tryParseAccessorDeclaration(fullStart, decorators, modifiers) { - if (parseContextualModifier(121)) { - return parseAccessorDeclaration(143, fullStart, decorators, modifiers); + if (parseContextualModifier(123)) { + return parseAccessorDeclaration(145, fullStart, decorators, modifiers); } - else if (parseContextualModifier(127)) { - return parseAccessorDeclaration(144, fullStart, decorators, modifiers); + else if (parseContextualModifier(129)) { + return parseAccessorDeclaration(146, fullStart, decorators, modifiers); } return undefined; } @@ -8214,27 +8430,33 @@ var ts; var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (asteriskToken || token === 17 || token === 25) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } - if ((token === 24 || token === 16) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(244, fullStart); + var isShorthandPropertyAssignment = tokenIsIdentifier && (token === 24 || token === 16 || token === 56); + if (isShorthandPropertyAssignment) { + var shorthandDeclaration = createNode(246, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; + var equalsToken = parseOptionalToken(56); + if (equalsToken) { + shorthandDeclaration.equalsToken = equalsToken; + shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher); + } return finishNode(shorthandDeclaration); } else { - var propertyAssignment = createNode(243, fullStart); + var propertyAssignment = createNode(245, fullStart); propertyAssignment.name = propertyName; propertyAssignment.questionToken = questionToken; - parseExpected(53); + parseExpected(54); propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); return finishNode(propertyAssignment); } } function parseObjectLiteralExpression() { - var node = createNode(163); + var node = createNode(165); parseExpected(15); if (scanner.hasPrecedingLineBreak()) { node.flags |= 2048; @@ -8248,9 +8470,9 @@ var ts; if (saveDecoratorContext) { setDecoratorContext(false); } - var node = createNode(171); + var node = createNode(173); setModifiers(node, parseModifiers()); - parseExpected(85); + parseExpected(87); node.asteriskToken = parseOptionalToken(37); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512); @@ -8259,7 +8481,7 @@ var ts; isGenerator ? doInYieldContext(parseOptionalIdentifier) : isAsync ? doInAwaitContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - fillSignature(53, isGenerator, isAsync, false, node); + fillSignature(54, isGenerator, isAsync, false, node); node.body = parseFunctionBlock(isGenerator, isAsync, false); if (saveDecoratorContext) { setDecoratorContext(true); @@ -8270,8 +8492,8 @@ var ts; return isIdentifier() ? parseIdentifier() : undefined; } function parseNewExpression() { - var node = createNode(167); - parseExpected(90); + var node = createNode(169); + parseExpected(92); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); if (node.typeArguments || token === 17) { @@ -8280,7 +8502,7 @@ var ts; return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) { - var node = createNode(190); + var node = createNode(192); if (parseExpected(15, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(1, parseStatement); parseExpected(16); @@ -8308,25 +8530,25 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(192); + var node = createNode(194); parseExpected(23); return finishNode(node); } function parseIfStatement() { - var node = createNode(194); - parseExpected(86); + var node = createNode(196); + parseExpected(88); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); node.thenStatement = parseStatement(); - node.elseStatement = parseOptional(78) ? parseStatement() : undefined; + node.elseStatement = parseOptional(80) ? parseStatement() : undefined; return finishNode(node); } function parseDoStatement() { - var node = createNode(195); - parseExpected(77); + var node = createNode(197); + parseExpected(79); node.statement = parseStatement(); - parseExpected(102); + parseExpected(104); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); @@ -8334,8 +8556,8 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(196); - parseExpected(102); + var node = createNode(198); + parseExpected(104); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); @@ -8344,11 +8566,11 @@ var ts; } function parseForOrForInOrForOfStatement() { var pos = getNodePos(); - parseExpected(84); + parseExpected(86); parseExpected(17); var initializer = undefined; if (token !== 23) { - if (token === 100 || token === 106 || token === 72) { + if (token === 102 || token === 108 || token === 74) { initializer = parseVariableDeclarationList(true); } else { @@ -8356,22 +8578,22 @@ var ts; } } var forOrForInOrForOfStatement; - if (parseOptional(88)) { - var forInStatement = createNode(198, pos); + if (parseOptional(90)) { + var forInStatement = createNode(200, pos); forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(18); forOrForInOrForOfStatement = forInStatement; } - else if (parseOptional(132)) { - var forOfStatement = createNode(199, pos); + else if (parseOptional(134)) { + var forOfStatement = createNode(201, pos); forOfStatement.initializer = initializer; forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher); parseExpected(18); forOrForInOrForOfStatement = forOfStatement; } else { - var forStatement = createNode(197, pos); + var forStatement = createNode(199, pos); forStatement.initializer = initializer; parseExpected(23); if (token !== 23 && token !== 18) { @@ -8389,7 +8611,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 201 ? 68 : 73); + parseExpected(kind === 203 ? 70 : 75); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -8397,8 +8619,8 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(202); - parseExpected(92); + var node = createNode(204); + parseExpected(94); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); } @@ -8406,8 +8628,8 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(203); - parseExpected(103); + var node = createNode(205); + parseExpected(105); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); @@ -8415,30 +8637,30 @@ var ts; return finishNode(node); } function parseCaseClause() { - var node = createNode(239); - parseExpected(69); + var node = createNode(241); + parseExpected(71); node.expression = allowInAnd(parseExpression); - parseExpected(53); + parseExpected(54); node.statements = parseList(3, parseStatement); return finishNode(node); } function parseDefaultClause() { - var node = createNode(240); - parseExpected(75); - parseExpected(53); + var node = createNode(242); + parseExpected(77); + parseExpected(54); node.statements = parseList(3, parseStatement); return finishNode(node); } function parseCaseOrDefaultClause() { - return token === 69 ? parseCaseClause() : parseDefaultClause(); + return token === 71 ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(204); - parseExpected(94); + var node = createNode(206); + parseExpected(96); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); - var caseBlock = createNode(218, scanner.getStartPos()); + var caseBlock = createNode(220, scanner.getStartPos()); parseExpected(15); caseBlock.clauses = parseList(2, parseCaseOrDefaultClause); parseExpected(16); @@ -8446,26 +8668,26 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(206); - parseExpected(96); + var node = createNode(208); + parseExpected(98); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } function parseTryStatement() { - var node = createNode(207); - parseExpected(98); + var node = createNode(209); + parseExpected(100); node.tryBlock = parseBlock(false); - node.catchClause = token === 70 ? parseCatchClause() : undefined; - if (!node.catchClause || token === 83) { - parseExpected(83); + node.catchClause = token === 72 ? parseCatchClause() : undefined; + if (!node.catchClause || token === 85) { + parseExpected(85); node.finallyBlock = parseBlock(false); } return finishNode(node); } function parseCatchClause() { - var result = createNode(242); - parseExpected(70); + var result = createNode(244); + parseExpected(72); if (parseExpected(17)) { result.variableDeclaration = parseVariableDeclaration(); } @@ -8474,22 +8696,22 @@ var ts; return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(208); - parseExpected(74); + var node = createNode(210); + parseExpected(76); parseSemicolon(); return finishNode(node); } function parseExpressionOrLabeledStatement() { var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); - if (expression.kind === 67 && parseOptional(53)) { - var labeledStatement = createNode(205, fullStart); + if (expression.kind === 69 && parseOptional(54)) { + var labeledStatement = createNode(207, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(193, fullStart); + var expressionStatement = createNode(195, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); @@ -8501,7 +8723,7 @@ var ts; } function nextTokenIsFunctionKeywordOnSameLine() { nextToken(); - return token === 85 && !scanner.hasPrecedingLineBreak(); + return token === 87 && !scanner.hasPrecedingLineBreak(); } function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); @@ -8510,41 +8732,41 @@ var ts; function isDeclaration() { while (true) { switch (token) { - case 100: - case 106: - case 72: - case 85: - case 71: - case 79: + case 102: + case 108: + case 74: + case 87: + case 73: + case 81: return true; - case 105: - case 130: + case 107: + case 132: return nextTokenIsIdentifierOnSameLine(); - case 123: - case 124: + case 125: + case 126: return nextTokenIsIdentifierOrStringLiteralOnSameLine(); - case 116: - case 120: + case 115: + case 118: + case 122: + case 110: + case 111: + case 112: nextToken(); if (scanner.hasPrecedingLineBreak()) { return false; } continue; - case 87: + case 89: nextToken(); return token === 9 || token === 37 || token === 15 || ts.tokenIsIdentifierOrKeyword(token); - case 80: + case 82: nextToken(); - if (token === 55 || token === 37 || - token === 15 || token === 75) { + if (token === 56 || token === 37 || + token === 15 || token === 77) { return true; } continue; - case 110: - case 108: - case 109: - case 111: case 113: nextToken(); continue; @@ -8558,44 +8780,44 @@ var ts; } function isStartOfStatement() { switch (token) { - case 54: + case 55: case 23: case 15: - case 100: - case 106: - case 85: - case 71: - case 79: - case 86: - case 77: case 102: - case 84: + case 108: + case 87: case 73: - case 68: - case 92: - case 103: + case 81: + case 88: + case 79: + case 104: + case 86: + case 75: + case 70: case 94: + case 105: case 96: case 98: - case 74: - case 70: - case 83: - return true; + case 100: + case 76: case 72: - case 80: - case 87: - return isStartOfDeclaration(); - case 116: - case 120: - case 105: - case 123: - case 124: - case 130: + case 85: return true; + case 74: + case 82: + case 89: + return isStartOfDeclaration(); + case 118: + case 122: + case 107: + case 125: + case 126: + case 132: + return true; + case 112: case 110: - case 108: - case 109: case 111: + case 113: return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); default: return isStartOfExpression(); @@ -8614,60 +8836,60 @@ var ts; return parseEmptyStatement(); case 15: return parseBlock(false); - case 100: + case 102: return parseVariableStatement(scanner.getStartPos(), undefined, undefined); - case 106: + case 108: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined, undefined); } break; - case 85: - return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); - case 71: - return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); - case 86: - return parseIfStatement(); - case 77: - return parseDoStatement(); - case 102: - return parseWhileStatement(); - case 84: - return parseForOrForInOrForOfStatement(); - case 73: - return parseBreakOrContinueStatement(200); - case 68: - return parseBreakOrContinueStatement(201); - case 92: - return parseReturnStatement(); - case 103: - return parseWithStatement(); - case 94: - return parseSwitchStatement(); - case 96: - return parseThrowStatement(); - case 98: - case 70: - case 83: - return parseTryStatement(); - case 74: - return parseDebuggerStatement(); - case 54: - return parseDeclaration(); - case 116: - case 105: - case 130: - case 123: - case 124: - case 120: - case 72: - case 79: - case 80: case 87: - case 108: - case 109: + return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); + case 73: + return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); + case 88: + return parseIfStatement(); + case 79: + return parseDoStatement(); + case 104: + return parseWhileStatement(); + case 86: + return parseForOrForInOrForOfStatement(); + case 75: + return parseBreakOrContinueStatement(202); + case 70: + return parseBreakOrContinueStatement(203); + case 94: + return parseReturnStatement(); + case 105: + return parseWithStatement(); + case 96: + return parseSwitchStatement(); + case 98: + return parseThrowStatement(); + case 100: + case 72: + case 85: + return parseTryStatement(); + case 76: + return parseDebuggerStatement(); + case 55: + return parseDeclaration(); + case 118: + case 107: + case 132: + case 125: + case 126: + case 122: + case 74: + case 81: + case 82: + case 89: case 110: - case 113: case 111: + case 112: + case 115: + case 113: if (isStartOfDeclaration()) { return parseDeclaration(); } @@ -8680,33 +8902,33 @@ var ts; var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 100: - case 106: - case 72: + case 102: + case 108: + case 74: return parseVariableStatement(fullStart, decorators, modifiers); - case 85: - return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 71: - return parseClassDeclaration(fullStart, decorators, modifiers); - case 105: - return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 130: - return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 79: - return parseEnumDeclaration(fullStart, decorators, modifiers); - case 123: - case 124: - return parseModuleDeclaration(fullStart, decorators, modifiers); case 87: + return parseFunctionDeclaration(fullStart, decorators, modifiers); + case 73: + return parseClassDeclaration(fullStart, decorators, modifiers); + case 107: + return parseInterfaceDeclaration(fullStart, decorators, modifiers); + case 132: + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); + case 81: + return parseEnumDeclaration(fullStart, decorators, modifiers); + case 125: + case 126: + return parseModuleDeclaration(fullStart, decorators, modifiers); + case 89: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - case 80: + case 82: nextToken(); - return token === 75 || token === 55 ? + return token === 77 || token === 56 ? parseExportAssignment(fullStart, decorators, modifiers) : parseExportDeclaration(fullStart, decorators, modifiers); default: if (decorators || modifiers) { - var node = createMissingNode(229, true, ts.Diagnostics.Declaration_expected); + var node = createMissingNode(231, true, ts.Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; setModifiers(node, modifiers); @@ -8727,23 +8949,23 @@ var ts; } function parseArrayBindingElement() { if (token === 24) { - return createNode(185); + return createNode(187); } - var node = createNode(161); + var node = createNode(163); node.dotDotDotToken = parseOptionalToken(22); node.name = parseIdentifierOrPattern(); node.initializer = parseBindingElementInitializer(false); return finishNode(node); } function parseObjectBindingElement() { - var node = createNode(161); + var node = createNode(163); var tokenIsIdentifier = isIdentifier(); var propertyName = parsePropertyName(); - if (tokenIsIdentifier && token !== 53) { + if (tokenIsIdentifier && token !== 54) { node.name = propertyName; } else { - parseExpected(53); + parseExpected(54); node.propertyName = propertyName; node.name = parseIdentifierOrPattern(); } @@ -8751,14 +8973,14 @@ var ts; return finishNode(node); } function parseObjectBindingPattern() { - var node = createNode(159); + var node = createNode(161); parseExpected(15); node.elements = parseDelimitedList(9, parseObjectBindingElement); parseExpected(16); return finishNode(node); } function parseArrayBindingPattern() { - var node = createNode(160); + var node = createNode(162); parseExpected(19); node.elements = parseDelimitedList(10, parseArrayBindingElement); parseExpected(20); @@ -8777,7 +8999,7 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(209); + var node = createNode(211); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); if (!isInOrOfKeyword(token)) { @@ -8786,21 +9008,21 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(inForStatementInitializer) { - var node = createNode(210); + var node = createNode(212); switch (token) { - case 100: + case 102: break; - case 106: + case 108: node.flags |= 16384; break; - case 72: + case 74: node.flags |= 32768; break; default: ts.Debug.fail(); } nextToken(); - if (token === 132 && lookAhead(canFollowContextualOfKeyword)) { + if (token === 134 && lookAhead(canFollowContextualOfKeyword)) { node.declarations = createMissingList(); } else { @@ -8815,7 +9037,7 @@ var ts; return nextTokenIsIdentifier() && nextToken() === 18; } function parseVariableStatement(fullStart, decorators, modifiers) { - var node = createNode(191, fullStart); + var node = createNode(193, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(false); @@ -8823,29 +9045,29 @@ var ts; return finishNode(node); } function parseFunctionDeclaration(fullStart, decorators, modifiers) { - var node = createNode(211, fullStart); + var node = createNode(213, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(85); + parseExpected(87); node.asteriskToken = parseOptionalToken(37); node.name = node.flags & 1024 ? parseOptionalIdentifier() : parseIdentifier(); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512); - fillSignature(53, isGenerator, isAsync, false, node); + fillSignature(54, isGenerator, isAsync, false, node); node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, decorators, modifiers) { - var node = createNode(142, pos); + var node = createNode(144, pos); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(119); - fillSignature(53, false, false, false, node); + parseExpected(121); + fillSignature(54, false, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, false, ts.Diagnostics.or_expected); return finishNode(node); } function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { - var method = createNode(141, fullStart); + var method = createNode(143, fullStart); method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; @@ -8853,12 +9075,12 @@ var ts; method.questionToken = questionToken; var isGenerator = !!asteriskToken; var isAsync = !!(method.flags & 512); - fillSignature(53, isGenerator, isAsync, false, method); + fillSignature(54, isGenerator, isAsync, false, method); method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage); return finishNode(method); } function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) { - var property = createNode(139, fullStart); + var property = createNode(141, fullStart); property.decorators = decorators; setModifiers(property, modifiers); property.name = name; @@ -8873,7 +9095,7 @@ var ts; function parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers) { var asteriskToken = parseOptionalToken(37); var name = parsePropertyName(); - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (asteriskToken || token === 17 || token === 25) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } @@ -8889,16 +9111,16 @@ var ts; node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); - fillSignature(53, false, false, false, node); + fillSignature(54, false, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, false); return finishNode(node); } function isClassMemberModifier(idToken) { switch (idToken) { + case 112: case 110: - case 108: - case 109: case 111: + case 113: return true; default: return false; @@ -8906,7 +9128,7 @@ var ts; } function isClassMemberStart() { var idToken; - if (token === 54) { + if (token === 55) { return true; } while (ts.isModifier(token)) { @@ -8927,15 +9149,15 @@ var ts; return true; } if (idToken !== undefined) { - if (!ts.isKeyword(idToken) || idToken === 127 || idToken === 121) { + if (!ts.isKeyword(idToken) || idToken === 129 || idToken === 123) { return true; } switch (token) { case 17: case 25: + case 54: + case 56: case 53: - case 55: - case 52: return true; default: return canParseSemicolon(); @@ -8947,14 +9169,14 @@ var ts; var decorators; while (true) { var decoratorStart = getNodePos(); - if (!parseOptional(54)) { + if (!parseOptional(55)) { break; } if (!decorators) { decorators = []; decorators.pos = scanner.getStartPos(); } - var decorator = createNode(137, decoratorStart); + var decorator = createNode(139, decoratorStart); decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); decorators.push(finishNode(decorator)); } @@ -8988,7 +9210,7 @@ var ts; function parseModifiersForArrowFunction() { var flags = 0; var modifiers; - if (token === 116) { + if (token === 118) { var modifierStart = scanner.getStartPos(); var modifierKind = token; nextToken(); @@ -9003,7 +9225,7 @@ var ts; } function parseClassElement() { if (token === 23) { - var result = createNode(189); + var result = createNode(191); nextToken(); return finishNode(result); } @@ -9014,7 +9236,7 @@ var ts; if (accessor) { return accessor; } - if (token === 119) { + if (token === 121) { return parseConstructorDeclaration(fullStart, decorators, modifiers); } if (isIndexSignature()) { @@ -9028,23 +9250,23 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators || modifiers) { - var name_7 = createMissingNode(67, true, ts.Diagnostics.Declaration_expected); + var name_7 = createMissingNode(69, true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_7, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassExpression() { - return parseClassDeclarationOrExpression(scanner.getStartPos(), undefined, undefined, 184); + return parseClassDeclarationOrExpression(scanner.getStartPos(), undefined, undefined, 186); } function parseClassDeclaration(fullStart, decorators, modifiers) { - return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 212); + return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 214); } function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) { var node = createNode(kind, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(71); - node.name = parseOptionalIdentifier(); + parseExpected(73); + node.name = parseNameOfClassDeclarationOrExpression(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(15)) { @@ -9056,6 +9278,14 @@ var ts; } return finishNode(node); } + function parseNameOfClassDeclarationOrExpression() { + return isIdentifier() && !isImplementsClause() + ? parseIdentifier() + : undefined; + } + function isImplementsClause() { + return token === 106 && lookAhead(nextTokenIsIdentifierOrKeyword); + } function parseHeritageClauses(isClassHeritageClause) { if (isHeritageClause()) { return parseList(20, parseHeritageClause); @@ -9066,8 +9296,8 @@ var ts; return parseList(20, parseHeritageClause); } function parseHeritageClause() { - if (token === 81 || token === 104) { - var node = createNode(241); + if (token === 83 || token === 106) { + var node = createNode(243); node.token = token; nextToken(); node.types = parseDelimitedList(7, parseExpressionWithTypeArguments); @@ -9076,7 +9306,7 @@ var ts; return undefined; } function parseExpressionWithTypeArguments() { - var node = createNode(186); + var node = createNode(188); node.expression = parseLeftHandSideExpressionOrHigher(); if (token === 25) { node.typeArguments = parseBracketedList(18, parseType, 25, 27); @@ -9084,16 +9314,16 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 81 || token === 104; + return token === 83 || token === 106; } function parseClassMembers() { return parseList(5, parseClassElement); } function parseInterfaceDeclaration(fullStart, decorators, modifiers) { - var node = createNode(213, fullStart); + var node = createNode(215, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(105); + parseExpected(107); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -9101,28 +9331,28 @@ var ts; return finishNode(node); } function parseTypeAliasDeclaration(fullStart, decorators, modifiers) { - var node = createNode(214, fullStart); + var node = createNode(216, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(130); + parseExpected(132); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); - parseExpected(55); + parseExpected(56); node.type = parseType(); parseSemicolon(); return finishNode(node); } function parseEnumMember() { - var node = createNode(245, scanner.getStartPos()); + var node = createNode(247, scanner.getStartPos()); node.name = parsePropertyName(); node.initializer = allowInAnd(parseNonParameterInitializer); return finishNode(node); } function parseEnumDeclaration(fullStart, decorators, modifiers) { - var node = createNode(215, fullStart); + var node = createNode(217, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(79); + parseExpected(81); node.name = parseIdentifier(); if (parseExpected(15)) { node.members = parseDelimitedList(6, parseEnumMember); @@ -9134,7 +9364,7 @@ var ts; return finishNode(node); } function parseModuleBlock() { - var node = createNode(217, scanner.getStartPos()); + var node = createNode(219, scanner.getStartPos()); if (parseExpected(15)) { node.statements = parseList(1, parseStatement); parseExpected(16); @@ -9145,7 +9375,7 @@ var ts; return finishNode(node); } function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) { - var node = createNode(216, fullStart); + var node = createNode(218, fullStart); var namespaceFlag = flags & 131072; node.decorators = decorators; setModifiers(node, modifiers); @@ -9157,7 +9387,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) { - var node = createNode(216, fullStart); + var node = createNode(218, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(true); @@ -9166,11 +9396,11 @@ var ts; } function parseModuleDeclaration(fullStart, decorators, modifiers) { var flags = modifiers ? modifiers.flags : 0; - if (parseOptional(124)) { + if (parseOptional(126)) { flags |= 131072; } else { - parseExpected(123); + parseExpected(125); if (token === 9) { return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } @@ -9178,58 +9408,58 @@ var ts; return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags); } function isExternalModuleReference() { - return token === 125 && + return token === 127 && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { return nextToken() === 17; } function nextTokenIsSlash() { - return nextToken() === 38; + return nextToken() === 39; } function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 24 || - token === 131; + token === 133; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) { - parseExpected(87); + parseExpected(89); var afterImportPos = scanner.getStartPos(); var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 24 && token !== 131) { - var importEqualsDeclaration = createNode(219, fullStart); + if (token !== 24 && token !== 133) { + var importEqualsDeclaration = createNode(221, fullStart); importEqualsDeclaration.decorators = decorators; setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; - parseExpected(55); + parseExpected(56); importEqualsDeclaration.moduleReference = parseModuleReference(); parseSemicolon(); return finishNode(importEqualsDeclaration); } } - var importDeclaration = createNode(220, fullStart); + var importDeclaration = createNode(222, fullStart); importDeclaration.decorators = decorators; setModifiers(importDeclaration, modifiers); if (identifier || token === 37 || token === 15) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(131); + parseExpected(133); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); return finishNode(importDeclaration); } function parseImportClause(identifier, fullStart) { - var importClause = createNode(221, fullStart); + var importClause = createNode(223, fullStart); if (identifier) { importClause.name = identifier; } if (!importClause.name || parseOptional(24)) { - importClause.namedBindings = token === 37 ? parseNamespaceImport() : parseNamedImportsOrExports(223); + importClause.namedBindings = token === 37 ? parseNamespaceImport() : parseNamedImportsOrExports(225); } return finishNode(importClause); } @@ -9239,8 +9469,8 @@ var ts; : parseEntityName(false); } function parseExternalModuleReference() { - var node = createNode(230); - parseExpected(125); + var node = createNode(232); + parseExpected(127); parseExpected(17); node.expression = parseModuleSpecifier(); parseExpected(18); @@ -9254,22 +9484,22 @@ var ts; return result; } function parseNamespaceImport() { - var namespaceImport = createNode(222); + var namespaceImport = createNode(224); parseExpected(37); - parseExpected(114); + parseExpected(116); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } function parseNamedImportsOrExports(kind) { var node = createNode(kind); - node.elements = parseBracketedList(21, kind === 223 ? parseImportSpecifier : parseExportSpecifier, 15, 16); + node.elements = parseBracketedList(21, kind === 225 ? parseImportSpecifier : parseExportSpecifier, 15, 16); return finishNode(node); } function parseExportSpecifier() { - return parseImportOrExportSpecifier(228); + return parseImportOrExportSpecifier(230); } function parseImportSpecifier() { - return parseImportOrExportSpecifier(224); + return parseImportOrExportSpecifier(226); } function parseImportOrExportSpecifier(kind) { var node = createNode(kind); @@ -9277,9 +9507,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 114) { + if (token === 116) { node.propertyName = identifierName; - parseExpected(114); + parseExpected(116); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -9288,23 +9518,23 @@ var ts; else { node.name = identifierName; } - if (kind === 224 && checkIdentifierIsKeyword) { + if (kind === 226 && checkIdentifierIsKeyword) { parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected); } return finishNode(node); } function parseExportDeclaration(fullStart, decorators, modifiers) { - var node = createNode(226, fullStart); + var node = createNode(228, fullStart); node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(37)) { - parseExpected(131); + parseExpected(133); node.moduleSpecifier = parseModuleSpecifier(); } else { - node.exportClause = parseNamedImportsOrExports(227); - if (token === 131 || (token === 9 && !scanner.hasPrecedingLineBreak())) { - parseExpected(131); + node.exportClause = parseNamedImportsOrExports(229); + if (token === 133 || (token === 9 && !scanner.hasPrecedingLineBreak())) { + parseExpected(133); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -9312,14 +9542,14 @@ var ts; return finishNode(node); } function parseExportAssignment(fullStart, decorators, modifiers) { - var node = createNode(225, fullStart); + var node = createNode(227, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - if (parseOptional(55)) { + if (parseOptional(56)) { node.isExportEquals = true; } else { - parseExpected(75); + parseExpected(77); } node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); @@ -9382,10 +9612,10 @@ var ts; function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 - || node.kind === 219 && node.moduleReference.kind === 230 - || node.kind === 220 - || node.kind === 225 - || node.kind === 226 + || node.kind === 221 && node.moduleReference.kind === 232 + || node.kind === 222 + || node.kind === 227 + || node.kind === 228 ? node : undefined; }); @@ -9395,15 +9625,15 @@ var ts; function isJSDocType() { switch (token) { case 37: - case 52: + case 53: case 17: case 19: - case 48: + case 49: case 15: - case 85: + case 87: case 22: - case 90: - case 95: + case 92: + case 97: return true; } return ts.tokenIsIdentifierOrKeyword(token); @@ -9420,7 +9650,7 @@ var ts; function parseJSDocTypeExpression(start, length) { scanner.setText(sourceText, start, length); token = nextToken(); - var result = createNode(247); + var result = createNode(249); parseExpected(15); result.type = parseJSDocTopLevelType(); parseExpected(16); @@ -9430,13 +9660,13 @@ var ts; JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; function parseJSDocTopLevelType() { var type = parseJSDocType(); - if (token === 46) { - var unionType = createNode(251, type.pos); + if (token === 47) { + var unionType = createNode(253, type.pos); unionType.types = parseJSDocTypeList(type); type = finishNode(unionType); } - if (token === 55) { - var optionalType = createNode(258, type.pos); + if (token === 56) { + var optionalType = createNode(260, type.pos); nextToken(); optionalType.type = type; type = finishNode(optionalType); @@ -9447,20 +9677,20 @@ var ts; var type = parseBasicTypeExpression(); while (true) { if (token === 19) { - var arrayType = createNode(250, type.pos); + var arrayType = createNode(252, type.pos); arrayType.elementType = type; nextToken(); parseExpected(20); type = finishNode(arrayType); } - else if (token === 52) { - var nullableType = createNode(253, type.pos); + else if (token === 53) { + var nullableType = createNode(255, type.pos); nullableType.type = type; nextToken(); type = finishNode(nullableType); } - else if (token === 48) { - var nonNullableType = createNode(254, type.pos); + else if (token === 49) { + var nonNullableType = createNode(256, type.pos); nonNullableType.type = type; nextToken(); type = finishNode(nonNullableType); @@ -9475,80 +9705,80 @@ var ts; switch (token) { case 37: return parseJSDocAllType(); - case 52: + case 53: return parseJSDocUnknownOrNullableType(); case 17: return parseJSDocUnionType(); case 19: return parseJSDocTupleType(); - case 48: + case 49: return parseJSDocNonNullableType(); case 15: return parseJSDocRecordType(); - case 85: + case 87: return parseJSDocFunctionType(); case 22: return parseJSDocVariadicType(); - case 90: + case 92: return parseJSDocConstructorType(); - case 95: + case 97: return parseJSDocThisType(); - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: - case 101: + case 120: + case 131: + case 103: return parseTokenNode(); } return parseJSDocTypeReference(); } function parseJSDocThisType() { - var result = createNode(262); + var result = createNode(264); nextToken(); - parseExpected(53); + parseExpected(54); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocConstructorType() { - var result = createNode(261); + var result = createNode(263); nextToken(); - parseExpected(53); + parseExpected(54); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocVariadicType() { - var result = createNode(260); + var result = createNode(262); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocFunctionType() { - var result = createNode(259); + var result = createNode(261); nextToken(); parseExpected(17); result.parameters = parseDelimitedList(22, parseJSDocParameter); checkForTrailingComma(result.parameters); parseExpected(18); - if (token === 53) { + if (token === 54) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocParameter() { - var parameter = createNode(136); + var parameter = createNode(138); parameter.type = parseJSDocType(); return finishNode(parameter); } function parseJSDocOptionalType(type) { - var result = createNode(258, type.pos); + var result = createNode(260, type.pos); nextToken(); result.type = type; return finishNode(result); } function parseJSDocTypeReference() { - var result = createNode(257); + var result = createNode(259); result.name = parseSimplePropertyName(); while (parseOptional(21)) { if (token === 25) { @@ -9577,13 +9807,13 @@ var ts; } } function parseQualifiedName(left) { - var result = createNode(133, left.pos); + var result = createNode(135, left.pos); result.left = left; result.right = parseIdentifierName(); return finishNode(result); } function parseJSDocRecordType() { - var result = createNode(255); + var result = createNode(257); nextToken(); result.members = parseDelimitedList(24, parseJSDocRecordMember); checkForTrailingComma(result.members); @@ -9591,22 +9821,22 @@ var ts; return finishNode(result); } function parseJSDocRecordMember() { - var result = createNode(256); + var result = createNode(258); result.name = parseSimplePropertyName(); - if (token === 53) { + if (token === 54) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocNonNullableType() { - var result = createNode(254); + var result = createNode(256); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocTupleType() { - var result = createNode(252); + var result = createNode(254); nextToken(); result.types = parseDelimitedList(25, parseJSDocType); checkForTrailingComma(result.types); @@ -9620,7 +9850,7 @@ var ts; } } function parseJSDocUnionType() { - var result = createNode(251); + var result = createNode(253); nextToken(); result.types = parseJSDocTypeList(parseJSDocType()); parseExpected(18); @@ -9631,14 +9861,14 @@ var ts; var types = []; types.pos = firstType.pos; types.push(firstType); - while (parseOptional(46)) { + while (parseOptional(47)) { types.push(parseJSDocType()); } types.end = scanner.getStartPos(); return types; } function parseJSDocAllType() { - var result = createNode(248); + var result = createNode(250); nextToken(); return finishNode(result); } @@ -9649,13 +9879,13 @@ var ts; token === 16 || token === 18 || token === 27 || - token === 55 || - token === 46) { - var result = createNode(249, pos); + token === 56 || + token === 47) { + var result = createNode(251, pos); return finishNode(result); } else { - var result = createNode(253, pos); + var result = createNode(255, pos); result.type = parseJSDocType(); return finishNode(result); } @@ -9726,7 +9956,7 @@ var ts; if (!tags) { return undefined; } - var result = createNode(263, start); + var result = createNode(265, start); result.tags = tags; return finishNode(result, end); } @@ -9737,7 +9967,7 @@ var ts; } function parseTag() { ts.Debug.assert(content.charCodeAt(pos - 1) === 64); - var atToken = createNode(54, pos - 1); + var atToken = createNode(55, pos - 1); atToken.end = pos; var tagName = scanIdentifier(); if (!tagName) { @@ -9763,7 +9993,7 @@ var ts; return undefined; } function handleUnknownTag(atToken, tagName) { - var result = createNode(264, atToken.pos); + var result = createNode(266, atToken.pos); result.atToken = atToken; result.tagName = tagName; return finishNode(result, pos); @@ -9814,7 +10044,7 @@ var ts; if (!typeExpression) { typeExpression = tryParseTypeExpression(); } - var result = createNode(265, atToken.pos); + var result = createNode(267, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.preParameterName = preName; @@ -9824,27 +10054,27 @@ var ts; return finishNode(result, pos); } function handleReturnTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 266; })) { + if (ts.forEach(tags, function (t) { return t.kind === 268; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(266, atToken.pos); + var result = createNode(268, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTypeTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 267; })) { + if (ts.forEach(tags, function (t) { return t.kind === 269; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(267, atToken.pos); + var result = createNode(269, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTemplateTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 268; })) { + if (ts.forEach(tags, function (t) { return t.kind === 270; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } var typeParameters = []; @@ -9857,7 +10087,7 @@ var ts; parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(135, name_8.pos); + var typeParameter = createNode(137, name_8.pos); typeParameter.name = name_8; finishNode(typeParameter, pos); typeParameters.push(typeParameter); @@ -9868,7 +10098,7 @@ var ts; pos++; } typeParameters.end = pos; - var result = createNode(268, atToken.pos); + var result = createNode(270, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeParameters = typeParameters; @@ -9889,7 +10119,7 @@ var ts; if (startPos === pos) { return undefined; } - var result = createNode(67, startPos); + var result = createNode(69, startPos); result.text = content.substring(startPos, pos); return finishNode(result, pos); } @@ -9965,7 +10195,7 @@ var ts; switch (node.kind) { case 9: case 8: - case 67: + case 69: return true; } return false; @@ -10204,17 +10434,19 @@ var ts; var Type = ts.objectAllocator.getTypeConstructor(); var Signature = ts.objectAllocator.getSignatureConstructor(); var typeCount = 0; + var symbolCount = 0; var emptyArray = []; var emptySymbols = {}; var compilerOptions = host.getCompilerOptions(); var languageVersion = compilerOptions.target || 0; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 ? 5 : 0; var emitResolver = createResolver(); var undefinedSymbol = createSymbol(4 | 67108864, "undefined"); var argumentsSymbol = createSymbol(4 | 67108864, "arguments"); var checker = { getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); }, - getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); }, + getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount") + symbolCount; }, getTypeCount: function () { return typeCount; }, isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; }, @@ -10360,6 +10592,7 @@ var ts; diagnostics.add(diagnostic); } function createSymbol(flags, name) { + symbolCount++; return new Symbol(flags, name); } function getExcludedSymbolFlags(flags) { @@ -10488,10 +10721,10 @@ var ts; return nodeLinks[nodeId] || (nodeLinks[nodeId] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 246); + return ts.getAncestor(node, 248); } function isGlobalSourceFile(node) { - return node.kind === 246 && !ts.isExternalModule(node); + return node.kind === 248 && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -10508,17 +10741,54 @@ var ts; } } } - function isDefinedBefore(node1, node2) { - var file1 = ts.getSourceFileOfNode(node1); - var file2 = ts.getSourceFileOfNode(node2); - if (file1 === file2) { - return node1.pos <= node2.pos; + function isBlockScopedNameDeclaredBeforeUse(declaration, usage) { + var declarationFile = ts.getSourceFileOfNode(declaration); + var useFile = ts.getSourceFileOfNode(usage); + if (declarationFile !== useFile) { + if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) { + return true; + } + var sourceFiles = host.getSourceFiles(); + return ts.indexOf(sourceFiles, declarationFile) <= ts.indexOf(sourceFiles, useFile); } - if (!compilerOptions.outFile && !compilerOptions.out) { - return true; + if (declaration.pos <= usage.pos) { + return declaration.kind !== 211 || + !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage); + } + return isUsedInFunctionOrNonStaticProperty(declaration, usage); + function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + if (declaration.parent.parent.kind === 193 || + declaration.parent.parent.kind === 199) { + return isSameScopeDescendentOf(usage, declaration, container); + } + else if (declaration.parent.parent.kind === 201 || + declaration.parent.parent.kind === 200) { + var expression = declaration.parent.parent.expression; + return isSameScopeDescendentOf(usage, expression, container); + } + } + function isUsedInFunctionOrNonStaticProperty(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + var current = usage; + while (current) { + if (current === container) { + return false; + } + if (ts.isFunctionLike(current)) { + return true; + } + var initializerOfNonStaticProperty = current.parent && + current.parent.kind === 141 && + (current.parent.flags & 128) === 0 && + current.parent.initializer === current; + if (initializerOfNonStaticProperty) { + return true; + } + current = current.parent; + } + return false; } - var sourceFiles = host.getSourceFiles(); - return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2); } function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) { var result; @@ -10539,16 +10809,16 @@ var ts; } } switch (location.kind) { - case 246: + case 248: if (!ts.isExternalModule(location)) break; - case 216: + case 218: var moduleExports = getSymbolOfNode(location).exports; - if (location.kind === 246 || - (location.kind === 216 && location.name.kind === 9)) { + if (location.kind === 248 || + (location.kind === 218 && location.name.kind === 9)) { if (ts.hasProperty(moduleExports, name) && moduleExports[name].flags === 8388608 && - ts.getDeclarationOfKind(moduleExports[name], 228)) { + ts.getDeclarationOfKind(moduleExports[name], 230)) { break; } result = moduleExports["default"]; @@ -10562,13 +10832,13 @@ var ts; break loop; } break; - case 215: + case 217: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) { break loop; } break; - case 139: - case 138: + case 141: + case 140: if (ts.isClassLike(location.parent) && !(location.flags & 128)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { @@ -10578,9 +10848,9 @@ var ts; } } break; - case 212: - case 184: - case 213: + case 214: + case 186: + case 215: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) { if (lastLocation && lastLocation.flags & 128) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -10588,7 +10858,7 @@ var ts; } break loop; } - if (location.kind === 184 && meaning & 32) { + if (location.kind === 186 && meaning & 32) { var className = location.name; if (className && name === className.text) { result = location.symbol; @@ -10596,28 +10866,28 @@ var ts; } } break; - case 134: + case 136: grandparent = location.parent.parent; - if (ts.isClassLike(grandparent) || grandparent.kind === 213) { + if (ts.isClassLike(grandparent) || grandparent.kind === 215) { if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; - case 141: - case 140: - case 142: case 143: + case 142: case 144: - case 211: - case 172: + case 145: + case 146: + case 213: + case 174: if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } break; - case 171: + case 173: if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; @@ -10630,8 +10900,8 @@ var ts; } } break; - case 137: - if (location.parent && location.parent.kind === 136) { + case 139: + if (location.parent && location.parent.kind === 138) { location = location.parent; } if (location.parent && ts.isClassElement(location.parent)) { @@ -10657,8 +10927,11 @@ var ts; error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg)); return undefined; } - if (meaning & 2 && result.flags & 2) { - checkResolvedBlockScopedVariable(result, errorLocation); + if (meaning & 2) { + var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result); + if (exportOrLocalSymbol.flags & 2) { + checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); + } } } return result; @@ -10667,21 +10940,7 @@ var ts; ts.Debug.assert((result.flags & 2) !== 0); var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); - var isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation); - if (!isUsedBeforeDeclaration) { - var variableDeclaration = ts.getAncestor(declaration, 209); - var container = ts.getEnclosingBlockScopeContainer(variableDeclaration); - if (variableDeclaration.parent.parent.kind === 191 || - variableDeclaration.parent.parent.kind === 197) { - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container); - } - else if (variableDeclaration.parent.parent.kind === 199 || - variableDeclaration.parent.parent.kind === 198) { - var expression = variableDeclaration.parent.parent.expression; - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container); - } - } - if (isUsedBeforeDeclaration) { + if (!isBlockScopedNameDeclaredBeforeUse(ts.getAncestor(declaration, 211), errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); } } @@ -10698,10 +10957,10 @@ var ts; } function getAnyImportSyntax(node) { if (ts.isAliasSymbolDeclaration(node)) { - if (node.kind === 219) { + if (node.kind === 221) { return node; } - while (node && node.kind !== 220) { + while (node && node.kind !== 222) { node = node.parent; } return node; @@ -10711,7 +10970,7 @@ var ts; return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { - if (node.moduleReference.kind === 230) { + if (node.moduleReference.kind === 232) { return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node))); } return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); @@ -10800,17 +11059,17 @@ var ts; } function getTargetOfAliasDeclaration(node) { switch (node.kind) { - case 219: - return getTargetOfImportEqualsDeclaration(node); case 221: + return getTargetOfImportEqualsDeclaration(node); + case 223: return getTargetOfImportClause(node); - case 222: - return getTargetOfNamespaceImport(node); case 224: + return getTargetOfNamespaceImport(node); + case 226: return getTargetOfImportSpecifier(node); - case 228: + case 230: return getTargetOfExportSpecifier(node); - case 225: + case 227: return getTargetOfExportAssignment(node); } } @@ -10852,10 +11111,10 @@ var ts; if (!links.referenced) { links.referenced = true; var node = getDeclarationOfAliasSymbol(symbol); - if (node.kind === 225) { + if (node.kind === 227) { checkExpressionCached(node.expression); } - else if (node.kind === 228) { + else if (node.kind === 230) { checkExpressionCached(node.propertyName || node.name); } else if (ts.isInternalModuleImportEqualsDeclaration(node)) { @@ -10865,17 +11124,17 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 219); + importDeclaration = ts.getAncestor(entityName, 221); ts.Debug.assert(importDeclaration !== undefined); } - if (entityName.kind === 67 && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { + if (entityName.kind === 69 && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { entityName = entityName.parent; } - if (entityName.kind === 67 || entityName.parent.kind === 133) { + if (entityName.kind === 69 || entityName.parent.kind === 135) { return resolveEntityName(entityName, 1536); } else { - ts.Debug.assert(entityName.parent.kind === 219); + ts.Debug.assert(entityName.parent.kind === 221); return resolveEntityName(entityName, 107455 | 793056 | 1536); } } @@ -10887,16 +11146,16 @@ var ts; return undefined; } var symbol; - if (name.kind === 67) { + if (name.kind === 69) { var message = meaning === 1536 ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0; symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } } - else if (name.kind === 133 || name.kind === 164) { - var left = name.kind === 133 ? name.left : name.expression; - var right = name.kind === 133 ? name.right : name.name; + else if (name.kind === 135 || name.kind === 166) { + var left = name.kind === 135 ? name.left : name.expression; + var right = name.kind === 135 ? name.right : name.name; var namespace = resolveEntityName(left, 1536, ignoreErrors); if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { return undefined; @@ -10915,9 +11174,6 @@ var ts; ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here."); return symbol.flags & meaning ? symbol : resolveAlias(symbol); } - function isExternalModuleNameRelative(moduleName) { - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; - } function resolveExternalModuleName(location, moduleReferenceExpression) { if (moduleReferenceExpression.kind !== 9) { return; @@ -10928,7 +11184,7 @@ var ts; if (moduleName === undefined) { return; } - var isRelative = isExternalModuleNameRelative(moduleName); + var isRelative = ts.isExternalModuleNameRelative(moduleName); if (!isRelative) { var symbol = getSymbol(globals, "\"" + moduleName + "\"", 512); if (symbol) { @@ -11032,7 +11288,7 @@ var ts; var members = node.members; for (var _i = 0; _i < members.length; _i++) { var member = members[_i]; - if (member.kind === 142 && ts.nodeIsPresent(member.body)) { + if (member.kind === 144 && ts.nodeIsPresent(member.body)) { return member; } } @@ -11097,17 +11353,17 @@ var ts; } } switch (location_1.kind) { - case 246: + case 248: if (!ts.isExternalModule(location_1)) { break; } - case 216: + case 218: if (result = callback(getSymbolOfNode(location_1).exports)) { return result; } break; - case 212: - case 213: + case 214: + case 215: if (result = callback(getSymbolOfNode(location_1).members)) { return result; } @@ -11140,7 +11396,7 @@ var ts; return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 8388608 && symbolFromSymbolTable.name !== "export=" - && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228)) { + && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230)) { if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); @@ -11169,7 +11425,7 @@ var ts; if (symbolFromSymbolTable === symbol) { return true; } - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -11224,8 +11480,8 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 216 && declaration.name.kind === 9) || - (declaration.kind === 246 && ts.isExternalModule(declaration)); + return (declaration.kind === 218 && declaration.name.kind === 9) || + (declaration.kind === 248 && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -11257,11 +11513,11 @@ var ts; } function isEntityNameVisible(entityName, enclosingDeclaration) { var meaning; - if (entityName.parent.kind === 152) { + if (entityName.parent.kind === 154) { meaning = 107455 | 1048576; } - else if (entityName.kind === 133 || entityName.kind === 164 || - entityName.parent.kind === 219) { + else if (entityName.kind === 135 || entityName.kind === 166 || + entityName.parent.kind === 221) { meaning = 1536; } else { @@ -11312,10 +11568,10 @@ var ts; function getTypeAliasForTypeLiteral(type) { if (type.symbol && type.symbol.flags & 2048) { var node = type.symbol.declarations[0].parent; - while (node.kind === 158) { + while (node.kind === 160) { node = node.parent; } - if (node.kind === 214) { + if (node.kind === 216) { return getSymbolOfNode(node); } } @@ -11329,10 +11585,10 @@ var ts; return ts.declarationNameToString(declaration.name); } switch (declaration.kind) { - case 184: + case 186: return "(Anonymous class)"; - case 171: - case 172: + case 173: + case 174: return "(Anonymous function)"; } } @@ -11393,6 +11649,7 @@ var ts; } function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16; + var inObjectTypeLiteral = false; return writeType(type, globalFlags); function writeType(type, flags) { if (type.flags & 16777343) { @@ -11400,6 +11657,12 @@ var ts; ? "any" : type.intrinsicName); } + else if (type.flags & 33554432) { + if (inObjectTypeLiteral) { + writer.reportInaccessibleThisError(); + } + writer.writeKeyword("this"); + } else if (type.flags & 4096) { writeTypeReference(type, flags); } @@ -11438,9 +11701,9 @@ var ts; writeType(types[i], delimiter === 24 ? 0 : 64); } } - function writeSymbolTypeReference(symbol, typeArguments, pos, end) { - if (!isReservedMemberName(symbol.name)) { - buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056); + function writeSymbolTypeReference(symbol, typeArguments, pos, end, flags) { + if (symbol.flags & 32 || !isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056, 0, flags); } if (pos < end) { writePunctuation(writer, 25); @@ -11454,7 +11717,7 @@ var ts; } } function writeTypeReference(type, flags) { - var typeArguments = type.typeArguments; + var typeArguments = type.typeArguments || emptyArray; if (type.target === globalArrayType && !(flags & 1)) { writeType(typeArguments[0], 64); writePunctuation(writer, 19); @@ -11472,12 +11735,13 @@ var ts; i++; } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3); if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { - writeSymbolTypeReference(parent_3, typeArguments, start, i); + writeSymbolTypeReference(parent_3, typeArguments, start, i, flags); writePunctuation(writer, 21); } } } - writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); + var typeParameterCount = (type.target.typeParameters || emptyArray).length; + writeSymbolTypeReference(type.symbol, typeArguments, i, typeParameterCount, flags); } } function writeTupleType(type) { @@ -11489,7 +11753,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 17); } - writeTypeList(type.types, type.flags & 16384 ? 46 : 45); + writeTypeList(type.types, type.flags & 16384 ? 47 : 46); if (flags & 64) { writePunctuation(writer, 18); } @@ -11509,7 +11773,7 @@ var ts; buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); } else { - writeKeyword(writer, 115); + writeKeyword(writer, 117); } } else { @@ -11530,7 +11794,7 @@ var ts; var isNonLocalFunctionSymbol = !!(symbol.flags & 16) && (symbol.parent || ts.forEach(symbol.declarations, function (declaration) { - return declaration.parent.kind === 246 || declaration.parent.kind === 217; + return declaration.parent.kind === 248 || declaration.parent.kind === 219; })); if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { return !!(flags & 2) || @@ -11539,7 +11803,7 @@ var ts; } } function writeTypeofSymbol(type, typeFormatFlags) { - writeKeyword(writer, 99); + writeKeyword(writer, 101); writeSpace(writer); buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455, 0, typeFormatFlags); } @@ -11573,7 +11837,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 17); } - writeKeyword(writer, 90); + writeKeyword(writer, 92); writeSpace(writer); buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { @@ -11582,6 +11846,8 @@ var ts; return; } } + var saveInObjectTypeLiteral = inObjectTypeLiteral; + inObjectTypeLiteral = true; writePunctuation(writer, 15); writer.writeLine(); writer.increaseIndent(); @@ -11593,7 +11859,7 @@ var ts; } for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) { var signature = _c[_b]; - writeKeyword(writer, 90); + writeKeyword(writer, 92); writeSpace(writer); buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23); @@ -11602,11 +11868,11 @@ var ts; if (resolved.stringIndexType) { writePunctuation(writer, 19); writer.writeParameter(getIndexerParameterName(resolved, 0, "x")); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); - writeKeyword(writer, 128); + writeKeyword(writer, 130); writePunctuation(writer, 20); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); writeType(resolved.stringIndexType, 0); writePunctuation(writer, 23); @@ -11615,11 +11881,11 @@ var ts; if (resolved.numberIndexType) { writePunctuation(writer, 19); writer.writeParameter(getIndexerParameterName(resolved, 1, "x")); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); - writeKeyword(writer, 126); + writeKeyword(writer, 128); writePunctuation(writer, 20); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); writeType(resolved.numberIndexType, 0); writePunctuation(writer, 23); @@ -11634,7 +11900,7 @@ var ts; var signature = signatures[_f]; buildSymbolDisplay(p, writer); if (p.flags & 536870912) { - writePunctuation(writer, 52); + writePunctuation(writer, 53); } buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23); @@ -11644,9 +11910,9 @@ var ts; else { buildSymbolDisplay(p, writer); if (p.flags & 536870912) { - writePunctuation(writer, 52); + writePunctuation(writer, 53); } - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); writeType(t, 0); writePunctuation(writer, 23); @@ -11655,6 +11921,7 @@ var ts; } writer.decreaseIndent(); writePunctuation(writer, 16); + inObjectTypeLiteral = saveInObjectTypeLiteral; } } function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { @@ -11668,7 +11935,7 @@ var ts; var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); - writeKeyword(writer, 81); + writeKeyword(writer, 83); writeSpace(writer); buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } @@ -11680,9 +11947,9 @@ var ts; } appendSymbolNameOnly(p, writer); if (isOptionalParameter(parameterNode)) { - writePunctuation(writer, 52); + writePunctuation(writer, 53); } - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } @@ -11729,14 +11996,14 @@ var ts; writePunctuation(writer, 34); } else { - writePunctuation(writer, 53); + writePunctuation(writer, 54); } writeSpace(writer); var returnType; if (signature.typePredicate) { writer.writeParameter(signature.typePredicate.parameterName); writeSpace(writer); - writeKeyword(writer, 122); + writeKeyword(writer, 124); writeSpace(writer); returnType = signature.typePredicate.type; } @@ -11770,12 +12037,12 @@ var ts; function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 216) { + if (node.kind === 218) { if (node.name.kind === 9) { return node; } } - else if (node.kind === 246) { + else if (node.kind === 248) { return ts.isExternalModule(node) ? node : undefined; } } @@ -11818,59 +12085,59 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 161: + case 163: return isDeclarationVisible(node.parent.parent); - case 209: + case 211: if (ts.isBindingPattern(node.name) && !node.name.elements.length) { return false; } - case 216: - case 212: - case 213: + case 218: case 214: - case 211: case 215: - case 219: + case 216: + case 213: + case 217: + case 221: var parent_4 = getDeclarationContainer(node); if (!(ts.getCombinedNodeFlags(node) & 1) && - !(node.kind !== 219 && parent_4.kind !== 246 && ts.isInAmbientContext(parent_4))) { + !(node.kind !== 221 && parent_4.kind !== 248 && ts.isInAmbientContext(parent_4))) { return isGlobalSourceFile(parent_4); } return isDeclarationVisible(parent_4); - case 139: - case 138: - case 143: - case 144: case 141: case 140: + case 145: + case 146: + case 143: + case 142: if (node.flags & (32 | 64)) { return false; } - case 142: - case 146: - case 145: + case 144: + case 148: case 147: - case 136: - case 217: - case 150: - case 151: - case 153: case 149: - case 154: + case 138: + case 219: + case 152: + case 153: case 155: + case 151: case 156: case 157: case 158: + case 159: + case 160: return isDeclarationVisible(node.parent); - case 221: - case 222: + case 223: case 224: + case 226: return false; - case 135: - case 246: + case 137: + case 248: return true; - case 225: + case 227: return false; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); @@ -11886,10 +12153,10 @@ var ts; } function collectLinkedAliases(node) { var exportSymbol; - if (node.parent && node.parent.kind === 225) { + if (node.parent && node.parent.kind === 227) { exportSymbol = resolveName(node.parent, node.text, 107455 | 793056 | 1536 | 8388608, ts.Diagnostics.Cannot_find_name_0, node); } - else if (node.parent.kind === 228) { + else if (node.parent.kind === 230) { var exportSpecifier = node.parent; exportSymbol = exportSpecifier.parent.parent.moduleSpecifier ? getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) : @@ -11964,7 +12231,7 @@ var ts; } function getDeclarationContainer(node) { node = ts.getRootDeclaration(node); - return node.kind === 209 ? node.parent.parent.parent : node.parent; + return node.kind === 211 ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); @@ -11977,9 +12244,13 @@ var ts; function isTypeAny(type) { return type && (type.flags & 1) !== 0; } + function getTypeForBindingElementParent(node) { + var symbol = getSymbolOfNode(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + } function getTypeForBindingElement(declaration) { var pattern = declaration.parent; - var parentType = getTypeForVariableLikeDeclaration(pattern.parent); + var parentType = getTypeForBindingElementParent(pattern.parent); if (parentType === unknownType) { return unknownType; } @@ -11990,7 +12261,7 @@ var ts; return parentType; } var type; - if (pattern.kind === 159) { + if (pattern.kind === 161) { var name_10 = declaration.propertyName || declaration.name; type = getTypeOfPropertyOfType(parentType, name_10.text) || isNumericLiteralName(name_10.text) && getIndexTypeOfType(parentType, 1) || @@ -12024,10 +12295,10 @@ var ts; return type; } function getTypeForVariableLikeDeclaration(declaration) { - if (declaration.parent.parent.kind === 198) { + if (declaration.parent.parent.kind === 200) { return anyType; } - if (declaration.parent.parent.kind === 199) { + if (declaration.parent.parent.kind === 201) { return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -12036,10 +12307,10 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136) { + if (declaration.kind === 138) { var func = declaration.parent; - if (func.kind === 144 && !ts.hasDynamicName(func)) { - var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 143); + if (func.kind === 146 && !ts.hasDynamicName(func)) { + var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 145); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); } @@ -12052,7 +12323,7 @@ var ts; if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } - if (declaration.kind === 244) { + if (declaration.kind === 246) { return checkIdentifier(declaration.name); } if (ts.isBindingPattern(declaration.name)) { @@ -12090,7 +12361,7 @@ var ts; if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) { return languageVersion >= 2 ? createIterableType(anyType) : anyArrayType; } - var elementTypes = ts.map(elements, function (e) { return e.kind === 185 ? anyType : getTypeFromBindingElement(e, includePatternInType); }); + var elementTypes = ts.map(elements, function (e) { return e.kind === 187 ? anyType : getTypeFromBindingElement(e, includePatternInType); }); if (includePatternInType) { var result = createNewTupleType(elementTypes); result.pattern = pattern; @@ -12099,7 +12370,7 @@ var ts; return createTupleType(elementTypes); } function getTypeFromBindingPattern(pattern, includePatternInType) { - return pattern.kind === 159 + return pattern.kind === 161 ? getTypeFromObjectBindingPattern(pattern, includePatternInType) : getTypeFromArrayBindingPattern(pattern, includePatternInType); } @@ -12109,12 +12380,12 @@ var ts; if (reportErrors) { reportErrorsFromWidening(declaration, type); } - return declaration.kind !== 243 ? getWidenedType(type) : type; + return declaration.kind !== 245 ? getWidenedType(type) : type; } type = declaration.dotDotDotToken ? anyArrayType : anyType; if (reportErrors && compilerOptions.noImplicitAny) { var root = ts.getRootDeclaration(declaration); - if (!isPrivateWithinAmbient(root) && !(root.kind === 136 && isPrivateWithinAmbient(root.parent))) { + if (!isPrivateWithinAmbient(root) && !(root.kind === 138 && isPrivateWithinAmbient(root.parent))) { reportImplicitAnyError(declaration, type); } } @@ -12127,10 +12398,10 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.parent.kind === 242) { + if (declaration.parent.kind === 244) { return links.type = anyType; } - if (declaration.kind === 225) { + if (declaration.kind === 227) { return links.type = checkExpression(declaration.expression); } if (!pushTypeResolution(symbol, 0)) { @@ -12155,7 +12426,7 @@ var ts; } function getAnnotatedAccessorType(accessor) { if (accessor) { - if (accessor.kind === 143) { + if (accessor.kind === 145) { return accessor.type && getTypeFromTypeNode(accessor.type); } else { @@ -12171,8 +12442,8 @@ var ts; if (!pushTypeResolution(symbol, 0)) { return unknownType; } - var getter = ts.getDeclarationOfKind(symbol, 143); - var setter = ts.getDeclarationOfKind(symbol, 144); + var getter = ts.getDeclarationOfKind(symbol, 145); + var setter = ts.getDeclarationOfKind(symbol, 146); var type; var getterReturnType = getAnnotatedAccessorType(getter); if (getterReturnType) { @@ -12198,7 +12469,7 @@ var ts; if (!popTypeResolution()) { type = anyType; if (compilerOptions.noImplicitAny) { - var getter_1 = ts.getDeclarationOfKind(symbol, 143); + var getter_1 = ts.getDeclarationOfKind(symbol, 145); error(getter_1, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } } @@ -12287,9 +12558,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 212 || node.kind === 184 || - node.kind === 211 || node.kind === 171 || - node.kind === 141 || node.kind === 172) { + if (node.kind === 214 || node.kind === 186 || + node.kind === 213 || node.kind === 173 || + node.kind === 143 || node.kind === 174) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -12298,15 +12569,15 @@ var ts; } } function getOuterTypeParametersOfClassOrInterface(symbol) { - var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 213); + var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 215); return appendOuterTypeParameters(undefined, declaration); } function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) { var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 213 || node.kind === 212 || - node.kind === 184 || node.kind === 214) { + if (node.kind === 215 || node.kind === 214 || + node.kind === 186 || node.kind === 216) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -12411,7 +12682,7 @@ var ts; type.resolvedBaseTypes = []; for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) { var declaration = _a[_i]; - if (declaration.kind === 213 && ts.getInterfaceBaseTypeNodes(declaration)) { + if (declaration.kind === 215 && ts.getInterfaceBaseTypeNodes(declaration)) { for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) { var node = _c[_b]; var baseType = getTypeFromTypeNode(node); @@ -12432,6 +12703,29 @@ var ts; } } } + function isIndependentInterface(symbol) { + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var declaration = _a[_i]; + if (declaration.kind === 215) { + if (declaration.flags & 524288) { + return false; + } + var baseTypeNodes = ts.getInterfaceBaseTypeNodes(declaration); + if (baseTypeNodes) { + for (var _b = 0; _b < baseTypeNodes.length; _b++) { + var node = baseTypeNodes[_b]; + if (ts.isSupportedExpressionWithTypeArguments(node)) { + var baseSymbol = resolveEntityName(node.expression, 793056, true); + if (!baseSymbol || !(baseSymbol.flags & 64) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) { + return false; + } + } + } + } + } + } + return true; + } function getDeclaredTypeOfClassOrInterface(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { @@ -12439,7 +12733,7 @@ var ts; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); - if (outerTypeParameters || localTypeParameters) { + if (outerTypeParameters || localTypeParameters || kind === 1024 || !isIndependentInterface(symbol)) { type.flags |= 4096; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; @@ -12448,6 +12742,9 @@ var ts; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; + type.thisType = createType(512 | 33554432); + type.thisType.symbol = symbol; + type.thisType.constraint = getTypeWithThisArgument(type); } } return links.declaredType; @@ -12458,7 +12755,7 @@ var ts; if (!pushTypeResolution(symbol, 2)) { return unknownType; } - var declaration = ts.getDeclarationOfKind(symbol, 214); + var declaration = ts.getDeclarationOfKind(symbol, 216); var type = getTypeFromTypeNode(declaration.type); if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); @@ -12489,7 +12786,7 @@ var ts; if (!links.declaredType) { var type = createType(512); type.symbol = symbol; - if (!ts.getDeclarationOfKind(symbol, 135).constraint) { + if (!ts.getDeclarationOfKind(symbol, 137).constraint) { type.constraint = noConstraintType; } links.declaredType = type; @@ -12522,6 +12819,66 @@ var ts; } return unknownType; } + function isIndependentTypeReference(node) { + if (node.typeArguments) { + for (var _i = 0, _a = node.typeArguments; _i < _a.length; _i++) { + var typeNode = _a[_i]; + if (!isIndependentType(typeNode)) { + return false; + } + } + } + return true; + } + function isIndependentType(node) { + switch (node.kind) { + case 117: + case 130: + case 128: + case 120: + case 131: + case 103: + case 9: + return true; + case 156: + return isIndependentType(node.elementType); + case 151: + return isIndependentTypeReference(node); + } + return false; + } + function isIndependentVariableLikeDeclaration(node) { + return node.type && isIndependentType(node.type) || !node.type && !node.initializer; + } + function isIndependentFunctionLikeDeclaration(node) { + if (node.kind !== 144 && (!node.type || !isIndependentType(node.type))) { + return false; + } + for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) { + var parameter = _a[_i]; + if (!isIndependentVariableLikeDeclaration(parameter)) { + return false; + } + } + return true; + } + function isIndependentMember(symbol) { + if (symbol.declarations && symbol.declarations.length === 1) { + var declaration = symbol.declarations[0]; + if (declaration) { + switch (declaration.kind) { + case 141: + case 140: + return isIndependentVariableLikeDeclaration(declaration); + case 143: + case 142: + case 144: + return isIndependentFunctionLikeDeclaration(declaration); + } + } + } + return false; + } function createSymbolTable(symbols) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { @@ -12530,11 +12887,11 @@ var ts; } return result; } - function createInstantiatedSymbolTable(symbols, mapper) { + function createInstantiatedSymbolTable(symbols, mapper, mappingThisOnly) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { var symbol = symbols[_i]; - result[symbol.name] = instantiateSymbol(symbol, mapper); + result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper); } return result; } @@ -12565,44 +12922,54 @@ var ts; } return type; } - function resolveClassOrInterfaceMembers(type) { - var target = resolveDeclaredMembers(type); - var members = target.symbol.members; - var callSignatures = target.declaredCallSignatures; - var constructSignatures = target.declaredConstructSignatures; - var stringIndexType = target.declaredStringIndexType; - var numberIndexType = target.declaredNumberIndexType; - var baseTypes = getBaseTypes(target); + function getTypeWithThisArgument(type, thisArgument) { + if (type.flags & 4096) { + return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType])); + } + return type; + } + function resolveObjectTypeMembers(type, source, typeParameters, typeArguments) { + var mapper = identityMapper; + var members = source.symbol.members; + var callSignatures = source.declaredCallSignatures; + var constructSignatures = source.declaredConstructSignatures; + var stringIndexType = source.declaredStringIndexType; + var numberIndexType = source.declaredNumberIndexType; + if (!ts.rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { + mapper = createTypeMapper(typeParameters, typeArguments); + members = createInstantiatedSymbolTable(source.declaredProperties, mapper, typeParameters.length === 1); + callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); + constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); + stringIndexType = instantiateType(source.declaredStringIndexType, mapper); + numberIndexType = instantiateType(source.declaredNumberIndexType, mapper); + } + var baseTypes = getBaseTypes(source); if (baseTypes.length) { - members = createSymbolTable(target.declaredProperties); + if (members === source.symbol.members) { + members = createSymbolTable(source.declaredProperties); + } + var thisArgument = ts.lastOrUndefined(typeArguments); for (var _i = 0; _i < baseTypes.length; _i++) { var baseType = baseTypes[_i]; - addInheritedMembers(members, getPropertiesOfObjectType(baseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1)); - stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0); - numberIndexType = numberIndexType || getIndexTypeOfType(baseType, 1); + var instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType; + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); + callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0)); + constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1)); + stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0); + numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1); } } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } + function resolveClassOrInterfaceMembers(type) { + resolveObjectTypeMembers(type, resolveDeclaredMembers(type), emptyArray, emptyArray); + } function resolveTypeReferenceMembers(type) { - var target = resolveDeclaredMembers(type.target); - var mapper = createTypeMapper(target.typeParameters, type.typeArguments); - var members = createInstantiatedSymbolTable(target.declaredProperties, mapper); - var callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature); - var constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature); - var stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined; - var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; - ts.forEach(getBaseTypes(target), function (baseType) { - var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1)); - stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0); - numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1); - }); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + var source = resolveDeclaredMembers(type.target); + var typeParameters = ts.concatenate(source.typeParameters, [source.thisType]); + var typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ? + type.typeArguments : ts.concatenate(type.typeArguments, [type]); + resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); @@ -12651,7 +13018,8 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveStructuredTypeMembers(createArrayType(getUnionType(type.elementTypes, true))); + var arrayElementType = getUnionType(type.elementTypes, true); + var arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); @@ -12753,7 +13121,14 @@ var ts; var constructSignatures; var stringIndexType; var numberIndexType; - if (symbol.flags & 2048) { + if (type.target) { + members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, false); + callSignatures = instantiateList(getSignaturesOfType(type.target, 0), type.mapper, instantiateSignature); + constructSignatures = instantiateList(getSignaturesOfType(type.target, 1), type.mapper, instantiateSignature); + stringIndexType = instantiateType(getIndexTypeOfType(type.target, 0), type.mapper); + numberIndexType = instantiateType(getIndexTypeOfType(type.target, 1), type.mapper); + } + else if (symbol.flags & 2048) { members = symbol.members; callSignatures = getSignaturesOfSymbol(members["__call"]); constructSignatures = getSignaturesOfSymbol(members["__new"]); @@ -12789,7 +13164,10 @@ var ts; } function resolveStructuredTypeMembers(type) { if (!type.members) { - if (type.flags & (1024 | 2048)) { + if (type.flags & 4096) { + resolveTypeReferenceMembers(type); + } + else if (type.flags & (1024 | 2048)) { resolveClassOrInterfaceMembers(type); } else if (type.flags & 65536) { @@ -12804,9 +13182,6 @@ var ts; else if (type.flags & 32768) { resolveIntersectionTypeMembers(type); } - else { - resolveTypeReferenceMembers(type); - } } return type; } @@ -13013,7 +13388,7 @@ var ts; function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { - var classType = declaration.kind === 142 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; + var classType = declaration.kind === 144 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; @@ -13044,7 +13419,7 @@ var ts; } else if (declaration.type) { returnType = getTypeFromTypeNode(declaration.type); - if (declaration.type.kind === 148) { + if (declaration.type.kind === 150) { var typePredicateNode = declaration.type; typePredicate = { parameterName: typePredicateNode.parameterName ? typePredicateNode.parameterName.text : undefined, @@ -13054,8 +13429,8 @@ var ts; } } else { - if (declaration.kind === 143 && !ts.hasDynamicName(declaration)) { - var setter = ts.getDeclarationOfKind(declaration.symbol, 144); + if (declaration.kind === 145 && !ts.hasDynamicName(declaration)) { + var setter = ts.getDeclarationOfKind(declaration.symbol, 146); returnType = getAnnotatedAccessorType(setter); } if (!returnType && ts.nodeIsMissing(declaration.body)) { @@ -13073,19 +13448,19 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 150: - case 151: - case 211: - case 141: - case 140: + case 152: + case 153: + case 213: + case 143: case 142: + case 144: + case 147: + case 148: + case 149: case 145: case 146: - case 147: - case 143: - case 144: - case 171: - case 172: + case 173: + case 174: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -13155,7 +13530,7 @@ var ts; } function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { - var isConstructor = signature.declaration.kind === 142 || signature.declaration.kind === 146; + var isConstructor = signature.declaration.kind === 144 || signature.declaration.kind === 148; var type = createObjectType(65536 | 262144); type.members = emptySymbols; type.properties = emptyArray; @@ -13169,7 +13544,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 ? 126 : 128; + var syntaxKind = kind === 1 ? 128 : 130; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) { @@ -13198,30 +13573,33 @@ var ts; type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType; } else { - type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 135).constraint); + type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 137).constraint); } } return type.constraint === noConstraintType ? undefined : type.constraint; } function getParentSymbolOfTypeParameter(typeParameter) { - return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 135).parent); + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 137).parent); } function getTypeListId(types) { - switch (types.length) { - case 1: - return "" + types[0].id; - case 2: - return types[0].id + "," + types[1].id; - default: - var result = ""; - for (var i = 0; i < types.length; i++) { - if (i > 0) { - result += ","; + if (types) { + switch (types.length) { + case 1: + return "" + types[0].id; + case 2: + return types[0].id + "," + types[1].id; + default: + var result = ""; + for (var i = 0; i < types.length; i++) { + if (i > 0) { + result += ","; + } + result += types[i].id; } - result += types[i].id; - } - return result; + return result; + } } + return ""; } function getPropagatingFlagsOfTypes(types) { var result = 0; @@ -13235,7 +13613,7 @@ var ts; var id = getTypeListId(typeArguments); var type = target.instantiations[id]; if (!type) { - var flags = 4096 | getPropagatingFlagsOfTypes(typeArguments); + var flags = 4096 | (typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -13251,13 +13629,13 @@ var ts; while (!ts.forEach(typeParameterSymbol.declarations, function (d) { return d.parent === currentNode.parent; })) { currentNode = currentNode.parent; } - links.isIllegalTypeReferenceInConstraint = currentNode.kind === 135; + links.isIllegalTypeReferenceInConstraint = currentNode.kind === 137; return links.isIllegalTypeReferenceInConstraint; } function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) { var typeParameterSymbol; function check(n) { - if (n.kind === 149 && n.typeName.kind === 67) { + if (n.kind === 151 && n.typeName.kind === 69) { var links = getNodeLinks(n); if (links.isIllegalTypeReferenceInConstraint === undefined) { var symbol = resolveName(typeParameter, n.typeName.text, 793056, undefined, undefined); @@ -13324,7 +13702,7 @@ var ts; function getTypeFromTypeReference(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var typeNameOrExpression = node.kind === 149 ? node.typeName : + var typeNameOrExpression = node.kind === 151 ? node.typeName : ts.isSupportedExpressionWithTypeArguments(node) ? node.expression : undefined; var symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, 793056) || unknownSymbol; @@ -13350,9 +13728,9 @@ var ts; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; switch (declaration.kind) { - case 212: - case 213: + case 214: case 215: + case 217: return declaration; } } @@ -13402,17 +13780,17 @@ var ts; ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) : emptyObjectType; } - function createTypeFromGenericGlobalType(genericGlobalType, elementType) { - return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + function createTypeFromGenericGlobalType(genericGlobalType, typeArguments) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, typeArguments) : emptyObjectType; } function createIterableType(elementType) { - return createTypeFromGenericGlobalType(globalIterableType, elementType); + return createTypeFromGenericGlobalType(globalIterableType, [elementType]); } function createIterableIteratorType(elementType) { - return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); + return createTypeFromGenericGlobalType(globalIterableIteratorType, [elementType]); } function createArrayType(elementType) { - return createTypeFromGenericGlobalType(globalArrayType, elementType); + return createTypeFromGenericGlobalType(globalArrayType, [elementType]); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -13569,46 +13947,66 @@ var ts; } return links.resolvedType; } + function getThisType(node) { + var container = ts.getThisContainer(node, false); + var parent = container && container.parent; + if (parent && (ts.isClassLike(parent) || parent.kind === 215)) { + if (!(container.flags & 128)) { + return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType; + } + } + error(node, ts.Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface); + return unknownType; + } + function getTypeFromThisTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getThisType(node); + } + return links.resolvedType; + } function getTypeFromTypeNode(node) { switch (node.kind) { - case 115: + case 117: return anyType; - case 128: + case 130: return stringType; - case 126: + case 128: return numberType; - case 118: + case 120: return booleanType; - case 129: + case 131: return esSymbolType; - case 101: + case 103: return voidType; + case 97: + return getTypeFromThisTypeNode(node); case 9: return getTypeFromStringLiteral(node); - case 149: - return getTypeFromTypeReference(node); - case 148: - return booleanType; - case 186: - return getTypeFromTypeReference(node); - case 152: - return getTypeFromTypeQueryNode(node); - case 154: - return getTypeFromArrayTypeNode(node); - case 155: - return getTypeFromTupleTypeNode(node); - case 156: - return getTypeFromUnionTypeNode(node); - case 157: - return getTypeFromIntersectionTypeNode(node); - case 158: - return getTypeFromTypeNode(node.type); - case 150: case 151: + return getTypeFromTypeReference(node); + case 150: + return booleanType; + case 188: + return getTypeFromTypeReference(node); + case 154: + return getTypeFromTypeQueryNode(node); + case 156: + return getTypeFromArrayTypeNode(node); + case 157: + return getTypeFromTupleTypeNode(node); + case 158: + return getTypeFromUnionTypeNode(node); + case 159: + return getTypeFromIntersectionTypeNode(node); + case 160: + return getTypeFromTypeNode(node.type); + case 152: case 153: + case 155: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); - case 67: - case 133: + case 69: + case 135: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: @@ -13712,7 +14110,7 @@ var ts; type: instantiateType(signature.typePredicate.type, mapper) }; } - var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), signature.resolvedReturnType ? instantiateType(signature.resolvedReturnType, mapper) : undefined, freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -13744,21 +14142,13 @@ var ts; mapper.instantiations = []; } var result = createObjectType(65536 | 131072, type.symbol); - result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); - result.members = createSymbolTable(result.properties); - result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature); - result.constructSignatures = instantiateList(getSignaturesOfType(type, 1), mapper, instantiateSignature); - var stringIndexType = getIndexTypeOfType(type, 0); - var numberIndexType = getIndexTypeOfType(type, 1); - if (stringIndexType) - result.stringIndexType = instantiateType(stringIndexType, mapper); - if (numberIndexType) - result.numberIndexType = instantiateType(numberIndexType, mapper); + result.target = type; + result.mapper = mapper; mapper.instantiations[type.id] = result; return result; } function instantiateType(type, mapper) { - if (mapper !== identityMapper) { + if (type && mapper !== identityMapper) { if (type.flags & 512) { return mapper(type); } @@ -13782,27 +14172,27 @@ var ts; return type; } function isContextSensitive(node) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); switch (node.kind) { - case 171: - case 172: + case 173: + case 174: return isContextSensitiveFunctionLikeDeclaration(node); - case 163: + case 165: return ts.forEach(node.properties, isContextSensitive); - case 162: + case 164: return ts.forEach(node.elements, isContextSensitive); - case 180: + case 182: return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse); - case 179: - return node.operatorToken.kind === 51 && + case 181: + return node.operatorToken.kind === 52 && (isContextSensitive(node.left) || isContextSensitive(node.right)); - case 243: + case 245: return isContextSensitive(node.initializer); - case 141: - case 140: + case 143: + case 142: return isContextSensitiveFunctionLikeDeclaration(node); - case 170: + case 172: return isContextSensitive(node.expression); } return false; @@ -13955,7 +14345,7 @@ var ts; } else { if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) { - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, reportErrors)) { + if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } @@ -13977,7 +14367,7 @@ var ts; var result; if (source.flags & 80896 && target.flags & 80896) { if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) { - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, false)) { + if (result = typeArgumentsRelatedTo(source, target, false)) { return result; } } @@ -14087,9 +14477,14 @@ var ts; } return result; } - function typesRelatedTo(sources, targets, reportErrors) { + function typeArgumentsRelatedTo(source, target, reportErrors) { + var sources = source.typeArguments || emptyArray; + var targets = target.typeArguments || emptyArray; + if (sources.length !== targets.length && relation === identityRelation) { + return 0; + } var result = -1; - for (var i = 0, len = sources.length; i < len; i++) { + for (var i = 0; i < targets.length; i++) { var related = isRelatedTo(sources[i], targets[i], reportErrors); if (!related) { return 0; @@ -14740,22 +15135,22 @@ var ts; var typeAsString = typeToString(getWidenedType(type)); var diagnostic; switch (declaration.kind) { - case 139: - case 138: + case 141: + case 140: diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; - case 136: + case 138: diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; break; - case 211: - case 141: - case 140: + case 213: case 143: - case 144: - case 171: - case 172: + case 142: + case 145: + case 146: + case 173: + case 174: if (!declaration.name) { error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); return; @@ -14851,9 +15246,10 @@ var ts; } } else if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) { - var sourceTypes = source.typeArguments; - var targetTypes = target.typeArguments; - for (var i = 0; i < sourceTypes.length; i++) { + var sourceTypes = source.typeArguments || emptyArray; + var targetTypes = target.typeArguments || emptyArray; + var count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length; + for (var i = 0; i < count; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } @@ -15007,10 +15403,10 @@ var ts; function isInTypeQuery(node) { while (node) { switch (node.kind) { - case 152: + case 154: return true; - case 67: - case 133: + case 69: + case 135: node = node.parent; continue; default: @@ -15050,12 +15446,12 @@ var ts; } return links.assignmentChecks[symbol.id] = isAssignedIn(node); function isAssignedInBinaryExpression(node) { - if (node.operatorToken.kind >= 55 && node.operatorToken.kind <= 66) { + if (node.operatorToken.kind >= 56 && node.operatorToken.kind <= 68) { var n = node.left; - while (n.kind === 170) { + while (n.kind === 172) { n = n.expression; } - if (n.kind === 67 && getResolvedSymbol(n) === symbol) { + if (n.kind === 69 && getResolvedSymbol(n) === symbol) { return true; } } @@ -15069,55 +15465,55 @@ var ts; } function isAssignedIn(node) { switch (node.kind) { - case 179: + case 181: return isAssignedInBinaryExpression(node); - case 209: - case 161: - return isAssignedInVariableDeclaration(node); - case 159: - case 160: - case 162: + case 211: case 163: + return isAssignedInVariableDeclaration(node); + case 161: + case 162: case 164: case 165: case 166: case 167: + case 168: case 169: - case 187: - case 170: - case 177: - case 173: - case 176: - case 174: + case 171: + case 189: + case 172: + case 179: case 175: case 178: - case 182: + case 176: + case 177: case 180: - case 183: - case 190: - case 191: + case 184: + case 182: + case 185: + case 192: case 193: - case 194: case 195: case 196: case 197: case 198: case 199: - case 202: - case 203: + case 200: + case 201: case 204: - case 239: - case 240: case 205: case 206: - case 207: + case 241: case 242: - case 231: - case 232: - case 236: - case 237: + case 207: + case 208: + case 209: + case 244: case 233: + case 234: case 238: + case 239: + case 235: + case 240: return ts.forEachChild(node, isAssignedIn); } return false; @@ -15132,34 +15528,34 @@ var ts; node = node.parent; var narrowedType = type; switch (node.kind) { - case 194: + case 196: if (child !== node.expression) { narrowedType = narrowType(type, node.expression, child === node.thenStatement); } break; - case 180: + case 182: if (child !== node.condition) { narrowedType = narrowType(type, node.condition, child === node.whenTrue); } break; - case 179: + case 181: if (child === node.right) { - if (node.operatorToken.kind === 50) { + if (node.operatorToken.kind === 51) { narrowedType = narrowType(type, node.left, true); } - else if (node.operatorToken.kind === 51) { + else if (node.operatorToken.kind === 52) { narrowedType = narrowType(type, node.left, false); } } break; - case 246: - case 216: - case 211: - case 141: - case 140: + case 248: + case 218: + case 213: case 143: - case 144: case 142: + case 145: + case 146: + case 144: break loop; } if (narrowedType !== type) { @@ -15173,12 +15569,12 @@ var ts; } return type; function narrowTypeByEquality(type, expr, assumeTrue) { - if (expr.left.kind !== 174 || expr.right.kind !== 9) { + if (expr.left.kind !== 176 || expr.right.kind !== 9) { return type; } var left = expr.left; var right = expr.right; - if (left.expression.kind !== 67 || getResolvedSymbol(left.expression) !== symbol) { + if (left.expression.kind !== 69 || getResolvedSymbol(left.expression) !== symbol) { return type; } var typeInfo = primitiveTypeInfo[right.text]; @@ -15224,7 +15620,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 67 || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 69 || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -15288,27 +15684,27 @@ var ts; } function narrowType(type, expr, assumeTrue) { switch (expr.kind) { - case 166: + case 168: return narrowTypeByTypePredicate(type, expr, assumeTrue); - case 170: + case 172: return narrowType(type, expr.expression, assumeTrue); - case 179: + case 181: var operator = expr.operatorToken.kind; if (operator === 32 || operator === 33) { return narrowTypeByEquality(type, expr, assumeTrue); } - else if (operator === 50) { + else if (operator === 51) { return narrowTypeByAnd(type, expr, assumeTrue); } - else if (operator === 51) { + else if (operator === 52) { return narrowTypeByOr(type, expr, assumeTrue); } - else if (operator === 89) { + else if (operator === 91) { return narrowTypeByInstanceof(type, expr, assumeTrue); } break; - case 177: - if (expr.operator === 48) { + case 179: + if (expr.operator === 49) { return narrowType(type, expr.operand, !assumeTrue); } break; @@ -15320,7 +15716,7 @@ var ts; var symbol = getResolvedSymbol(node); if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); - if (container.kind === 172) { + if (container.kind === 174) { if (languageVersion < 2) { error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } @@ -15351,15 +15747,15 @@ var ts; function checkBlockScopedBindingCapturedInLoop(node, symbol) { if (languageVersion >= 2 || (symbol.flags & 2) === 0 || - symbol.valueDeclaration.parent.kind === 242) { + symbol.valueDeclaration.parent.kind === 244) { return; } var container = symbol.valueDeclaration; - while (container.kind !== 210) { + while (container.kind !== 212) { container = container.parent; } container = container.parent; - if (container.kind === 191) { + if (container.kind === 193) { container = container.parent; } var inFunction = isInsideFunction(node.parent, container); @@ -15377,7 +15773,7 @@ var ts; } function captureLexicalThis(node, container) { getNodeLinks(node).flags |= 2; - if (container.kind === 139 || container.kind === 142) { + if (container.kind === 141 || container.kind === 144) { var classNode = container.parent; getNodeLinks(classNode).flags |= 4; } @@ -15388,29 +15784,29 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 172) { + if (container.kind === 174) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = (languageVersion < 2); } switch (container.kind) { - case 216: + case 218: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body); break; - case 215: + case 217: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; - case 142: + case 144: if (isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments); } break; - case 139: - case 138: + case 141: + case 140: if (container.flags & 128) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; - case 134: + case 136: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; } @@ -15419,27 +15815,27 @@ var ts; } if (ts.isClassLike(container.parent)) { var symbol = getSymbolOfNode(container.parent); - return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); + return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol).thisType; } return anyType; } function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { - if (n.kind === 136) { + if (n.kind === 138) { return true; } } return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 166 && node.parent.expression === node; + var isCallExpression = node.parent.kind === 168 && node.parent.expression === node; var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; var container = ts.getSuperContainer(node, true); var needToCaptureLexicalThis = false; if (!isCallExpression) { - while (container && container.kind === 172) { + while (container && container.kind === 174) { container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = languageVersion < 2; } @@ -15465,7 +15861,7 @@ var ts; return unknownType; } if (!canUseSuperExpression) { - if (container && container.kind === 134) { + if (container && container.kind === 136) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { @@ -15476,7 +15872,7 @@ var ts; } return unknownType; } - if (container.kind === 142 && isInConstructorArgumentInitializer(node, container)) { + if (container.kind === 144 && isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments); return unknownType; } @@ -15488,24 +15884,24 @@ var ts; return false; } if (isCallExpression) { - return container.kind === 142; + return container.kind === 144; } else { if (container && ts.isClassLike(container.parent)) { if (container.flags & 128) { - return container.kind === 141 || - container.kind === 140 || - container.kind === 143 || - container.kind === 144; + return container.kind === 143 || + container.kind === 142 || + container.kind === 145 || + container.kind === 146; } else { - return container.kind === 141 || + return container.kind === 143 || + container.kind === 142 || + container.kind === 145 || + container.kind === 146 || + container.kind === 141 || container.kind === 140 || - container.kind === 143 || - container.kind === 144 || - container.kind === 139 || - container.kind === 138 || - container.kind === 142; + container.kind === 144; } } } @@ -15539,7 +15935,7 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136) { + if (declaration.kind === 138) { var type = getContextuallyTypedParameterType(declaration); if (type) { return type; @@ -15572,7 +15968,7 @@ var ts; } function isInParameterInitializerBeforeContainingFunction(node) { while (node.parent && !ts.isFunctionLike(node.parent)) { - if (node.parent.kind === 136 && node.parent.initializer === node) { + if (node.parent.kind === 138 && node.parent.initializer === node) { return true; } node = node.parent; @@ -15581,8 +15977,8 @@ var ts; } function getContextualReturnType(functionDecl) { if (functionDecl.type || - functionDecl.kind === 142 || - functionDecl.kind === 143 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 144))) { + functionDecl.kind === 144 || + functionDecl.kind === 145 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 146))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); } var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); @@ -15601,7 +15997,7 @@ var ts; return undefined; } function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { - if (template.parent.kind === 168) { + if (template.parent.kind === 170) { return getContextualTypeForArgument(template.parent, substitutionExpression); } return undefined; @@ -15609,12 +16005,12 @@ var ts; function getContextualTypeForBinaryOperand(node) { var binaryExpression = node.parent; var operator = binaryExpression.operatorToken.kind; - if (operator >= 55 && operator <= 66) { + if (operator >= 56 && operator <= 68) { if (node === binaryExpression.right) { return checkExpression(binaryExpression.left); } } - else if (operator === 51) { + else if (operator === 52) { var type = getContextualType(binaryExpression); if (!type && node === binaryExpression.right) { type = checkExpression(binaryExpression.left); @@ -15701,7 +16097,7 @@ var ts; return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined; } function getContextualTypeForJsxExpression(expr) { - if (expr.parent.kind === 236) { + if (expr.parent.kind === 238) { var attrib = expr.parent; var attrsType = getJsxElementAttributesType(attrib.parent); if (!attrsType || isTypeAny(attrsType)) { @@ -15711,7 +16107,7 @@ var ts; return getTypeOfPropertyOfType(attrsType, attrib.name.text); } } - if (expr.kind === 237) { + if (expr.kind === 239) { return getJsxElementAttributesType(expr.parent); } return undefined; @@ -15729,38 +16125,38 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 209: - case 136: - case 139: + case 211: case 138: - case 161: + case 141: + case 140: + case 163: return getContextualTypeForInitializerExpression(node); - case 172: - case 202: + case 174: + case 204: return getContextualTypeForReturnExpression(node); - case 182: + case 184: return getContextualTypeForYieldOperand(parent); - case 166: - case 167: - return getContextualTypeForArgument(parent, node); + case 168: case 169: - case 187: + return getContextualTypeForArgument(parent, node); + case 171: + case 189: return getTypeFromTypeNode(parent.type); - case 179: + case 181: return getContextualTypeForBinaryOperand(node); - case 243: + case 245: return getContextualTypeForObjectLiteralElement(parent); - case 162: + case 164: return getContextualTypeForElementExpression(node); - case 180: + case 182: return getContextualTypeForConditionalOperand(node); - case 188: - ts.Debug.assert(parent.parent.kind === 181); + case 190: + ts.Debug.assert(parent.parent.kind === 183); return getContextualTypeForSubstitutionExpression(parent.parent, node); - case 170: + case 172: return getContextualType(parent); - case 238: - case 237: + case 240: + case 239: return getContextualTypeForJsxExpression(parent); } return undefined; @@ -15775,7 +16171,7 @@ var ts; } } function isFunctionExpressionOrArrowFunction(node) { - return node.kind === 171 || node.kind === 172; + return node.kind === 173 || node.kind === 174; } function getContextualSignatureForFunctionLikeDeclaration(node) { return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node) @@ -15783,7 +16179,7 @@ var ts; : undefined; } function getContextualSignature(node) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); @@ -15823,13 +16219,13 @@ var ts; } function isAssignmentTarget(node) { var parent = node.parent; - if (parent.kind === 179 && parent.operatorToken.kind === 55 && parent.left === node) { + if (parent.kind === 181 && parent.operatorToken.kind === 56 && parent.left === node) { return true; } - if (parent.kind === 243) { + if (parent.kind === 245) { return isAssignmentTarget(parent.parent); } - if (parent.kind === 162) { + if (parent.kind === 164) { return isAssignmentTarget(parent); } return false; @@ -15839,8 +16235,8 @@ var ts; return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, false); } function hasDefaultValue(node) { - return (node.kind === 161 && !!node.initializer) || - (node.kind === 179 && node.operatorToken.kind === 55); + return (node.kind === 163 && !!node.initializer) || + (node.kind === 181 && node.operatorToken.kind === 56); } function checkArrayLiteral(node, contextualMapper) { var elements = node.elements; @@ -15849,7 +16245,7 @@ var ts; var inDestructuringPattern = isAssignmentTarget(node); for (var _i = 0; _i < elements.length; _i++) { var e = elements[_i]; - if (inDestructuringPattern && e.kind === 183) { + if (inDestructuringPattern && e.kind === 185) { var restArrayType = checkExpression(e.expression, contextualMapper); var restElementType = getIndexTypeOfType(restArrayType, 1) || (languageVersion >= 2 ? getElementTypeOfIterable(restArrayType, undefined) : undefined); @@ -15861,7 +16257,7 @@ var ts; var type = checkExpression(e, contextualMapper); elementTypes.push(type); } - hasSpreadElement = hasSpreadElement || e.kind === 183; + hasSpreadElement = hasSpreadElement || e.kind === 185; } if (!hasSpreadElement) { if (inDestructuringPattern && elementTypes.length) { @@ -15872,7 +16268,7 @@ var ts; var contextualType = getContextualType(node); if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { var pattern = contextualType.pattern; - if (pattern && (pattern.kind === 160 || pattern.kind === 162)) { + if (pattern && (pattern.kind === 162 || pattern.kind === 164)) { var patternElements = pattern.elements; for (var i = elementTypes.length; i < patternElements.length; i++) { var patternElement = patternElements[i]; @@ -15880,7 +16276,7 @@ var ts; elementTypes.push(contextualType.elementTypes[i]); } else { - if (patternElement.kind !== 185) { + if (patternElement.kind !== 187) { error(patternElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); } elementTypes.push(unknownType); @@ -15895,7 +16291,7 @@ var ts; return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType); } function isNumericName(name) { - return name.kind === 134 ? isNumericComputedName(name) : isNumericLiteralName(name.text); + return name.kind === 136 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132); @@ -15920,35 +16316,37 @@ var ts; return links.resolvedType; } function checkObjectLiteral(node, contextualMapper) { - checkGrammarObjectLiteralExpression(node); + var inDestructuringPattern = isAssignmentTarget(node); + checkGrammarObjectLiteralExpression(node, inDestructuringPattern); var propertiesTable = {}; var propertiesArray = []; var contextualType = getContextualType(node); var contextualTypeHasPattern = contextualType && contextualType.pattern && - (contextualType.pattern.kind === 159 || contextualType.pattern.kind === 163); - var inDestructuringPattern = isAssignmentTarget(node); + (contextualType.pattern.kind === 161 || contextualType.pattern.kind === 165); var typeFlags = 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var memberDecl = _a[_i]; var member = memberDecl.symbol; - if (memberDecl.kind === 243 || - memberDecl.kind === 244 || + if (memberDecl.kind === 245 || + memberDecl.kind === 246 || ts.isObjectLiteralMethod(memberDecl)) { var type = void 0; - if (memberDecl.kind === 243) { + if (memberDecl.kind === 245) { type = checkPropertyAssignment(memberDecl, contextualMapper); } - else if (memberDecl.kind === 141) { + else if (memberDecl.kind === 143) { type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - ts.Debug.assert(memberDecl.kind === 244); + ts.Debug.assert(memberDecl.kind === 246); type = checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 | 67108864 | member.flags, member.name); if (inDestructuringPattern) { - if (memberDecl.kind === 243 && hasDefaultValue(memberDecl.initializer)) { + var isOptional = (memberDecl.kind === 245 && hasDefaultValue(memberDecl.initializer)) || + (memberDecl.kind === 246 && memberDecl.objectAssignmentInitializer); + if (isOptional) { prop.flags |= 536870912; } } @@ -15971,7 +16369,7 @@ var ts; member = prop; } else { - ts.Debug.assert(memberDecl.kind === 143 || memberDecl.kind === 144); + ts.Debug.assert(memberDecl.kind === 145 || memberDecl.kind === 146); checkAccessorDeclaration(memberDecl); } if (!ts.hasDynamicName(memberDecl)) { @@ -16027,7 +16425,7 @@ var ts; if (lhs.kind !== rhs.kind) { return false; } - if (lhs.kind === 67) { + if (lhs.kind === 69) { return lhs.text === rhs.text; } return lhs.right.text === rhs.right.text && @@ -16044,17 +16442,17 @@ var ts; for (var _i = 0, _a = node.children; _i < _a.length; _i++) { var child = _a[_i]; switch (child.kind) { - case 238: + case 240: checkJsxExpression(child); break; - case 231: + case 233: checkJsxElement(child); break; - case 232: + case 234: checkJsxSelfClosingElement(child); break; default: - ts.Debug.assert(child.kind === 234); + ts.Debug.assert(child.kind === 236); } } return jsxElementType || anyType; @@ -16063,7 +16461,7 @@ var ts; return name.indexOf("-") < 0; } function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 133) { + if (tagName.kind === 135) { return false; } else { @@ -16164,12 +16562,14 @@ var ts; var valueSymbol = resolveJsxTagName(node); if (valueSymbol && valueSymbol !== unknownSymbol) { links.jsxFlags |= 4; - getSymbolLinks(valueSymbol).referenced = true; + if (valueSymbol.flags & 8388608) { + markAliasSymbolAsReferenced(valueSymbol); + } } return valueSymbol || unknownSymbol; } function resolveJsxTagName(node) { - if (node.tagName.kind === 67) { + if (node.tagName.kind === 69) { var tag = node.tagName; var sym = getResolvedSymbol(tag); return sym.exportSymbol || sym; @@ -16309,11 +16709,11 @@ var ts; var nameTable = {}; var sawSpreadedAny = false; for (var i = node.attributes.length - 1; i >= 0; i--) { - if (node.attributes[i].kind === 236) { + if (node.attributes[i].kind === 238) { checkJsxAttribute((node.attributes[i]), targetAttributesType, nameTable); } else { - ts.Debug.assert(node.attributes[i].kind === 237); + ts.Debug.assert(node.attributes[i].kind === 239); var spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable); if (isTypeAny(spreadType)) { sawSpreadedAny = true; @@ -16339,7 +16739,7 @@ var ts; } } function getDeclarationKindFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.kind : 139; + return s.valueDeclaration ? s.valueDeclaration.kind : 141; } function getDeclarationFlagsFromSymbol(s) { return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 ? 16 | 128 : 0; @@ -16347,11 +16747,11 @@ var ts; function checkClassPropertyAccess(node, left, type, prop) { var flags = getDeclarationFlagsFromSymbol(prop); var declaringClass = getDeclaredTypeOfSymbol(prop.parent); - if (left.kind === 93) { - var errorNode = node.kind === 164 ? + if (left.kind === 95) { + var errorNode = node.kind === 166 ? node.name : node.right; - if (getDeclarationKindFromSymbol(prop) !== 141) { + if (getDeclarationKindFromSymbol(prop) !== 143) { error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); return false; } @@ -16372,7 +16772,7 @@ var ts; } return true; } - if (left.kind === 93) { + if (left.kind === 95) { return true; } if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) { @@ -16382,6 +16782,9 @@ var ts; if (flags & 128) { return true; } + if (type.flags & 33554432) { + type = getConstraintOfTypeParameter(type); + } if (!(getTargetType(type).flags & (1024 | 2048) && hasBaseType(type, enclosingClass))) { error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass)); return false; @@ -16406,18 +16809,18 @@ var ts; var prop = getPropertyOfType(apparentType, right.text); if (!prop) { if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type.flags & 33554432 ? apparentType : type)); } return unknownType; } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32) { - checkClassPropertyAccess(node, left, type, prop); + checkClassPropertyAccess(node, left, apparentType, prop); } return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 164 + var left = node.kind === 166 ? node.expression : node.left; var type = checkExpression(left); @@ -16432,7 +16835,7 @@ var ts; function checkIndexedAccess(node) { if (!node.argumentExpression) { var sourceFile = getSourceFile(node); - if (node.parent.kind === 167 && node.parent.expression === node) { + if (node.parent.kind === 169 && node.parent.expression === node) { var start = ts.skipTrivia(sourceFile.text, node.expression.end); var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); @@ -16491,6 +16894,12 @@ var ts; if (indexArgumentExpression.kind === 9 || indexArgumentExpression.kind === 8) { return indexArgumentExpression.text; } + if (indexArgumentExpression.kind === 167 || indexArgumentExpression.kind === 166) { + var value = getConstantValue(indexArgumentExpression); + if (value !== undefined) { + return value.toString(); + } + } if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, false)) { var rightHandSideName = indexArgumentExpression.name.text; return ts.getPropertyNameForKnownSymbolName(rightHandSideName); @@ -16528,10 +16937,10 @@ var ts; return true; } function resolveUntypedCall(node) { - if (node.kind === 168) { + if (node.kind === 170) { checkExpression(node.template); } - else if (node.kind !== 137) { + else if (node.kind !== 139) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -16582,7 +16991,7 @@ var ts; function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg && arg.kind === 183) { + if (arg && arg.kind === 185) { return i; } } @@ -16594,11 +17003,11 @@ var ts; var callIsIncomplete; var isDecorator; var spreadArgIndex = -1; - if (node.kind === 168) { + if (node.kind === 170) { var tagExpression = node; adjustedArgCount = args.length; typeArguments = undefined; - if (tagExpression.template.kind === 181) { + if (tagExpression.template.kind === 183) { var templateExpression = tagExpression.template; var lastSpan = ts.lastOrUndefined(templateExpression.templateSpans); ts.Debug.assert(lastSpan !== undefined); @@ -16610,7 +17019,7 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } - else if (node.kind === 137) { + else if (node.kind === 139) { isDecorator = true; typeArguments = undefined; adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature); @@ -16618,7 +17027,7 @@ var ts; else { var callExpression = node; if (!callExpression.arguments) { - ts.Debug.assert(callExpression.kind === 167); + ts.Debug.assert(callExpression.kind === 169); return signature.minArgumentCount === 0; } adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length; @@ -16671,7 +17080,7 @@ var ts; var argCount = getEffectiveArgumentCount(node, args, signature); for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); - if (arg === undefined || arg.kind !== 185) { + if (arg === undefined || arg.kind !== 187) { var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); if (argType === undefined) { @@ -16718,7 +17127,7 @@ var ts; var argCount = getEffectiveArgumentCount(node, args, signature); for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); - if (arg === undefined || arg.kind !== 185) { + if (arg === undefined || arg.kind !== 187) { var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); if (argType === undefined) { @@ -16737,16 +17146,16 @@ var ts; } function getEffectiveCallArguments(node) { var args; - if (node.kind === 168) { + if (node.kind === 170) { var template = node.template; args = [undefined]; - if (template.kind === 181) { + if (template.kind === 183) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } - else if (node.kind === 137) { + else if (node.kind === 139) { return undefined; } else { @@ -16755,18 +17164,21 @@ var ts; return args; } function getEffectiveArgumentCount(node, args, signature) { - if (node.kind === 137) { + if (node.kind === 139) { switch (node.parent.kind) { - case 212: - case 184: + case 214: + case 186: return 1; - case 139: - return 2; case 141: + return 2; case 143: - case 144: + case 145: + case 146: + if (languageVersion === 0) { + return 2; + } return signature.parameters.length >= 3 ? 3 : 2; - case 136: + case 138: return 3; } } @@ -16776,20 +17188,20 @@ var ts; } function getEffectiveDecoratorFirstArgumentType(node) { switch (node.kind) { - case 212: - case 184: + case 214: + case 186: var classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); - case 136: + case 138: node = node.parent; - if (node.kind === 142) { + if (node.kind === 144) { var classSymbol_1 = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol_1); } - case 139: case 141: case 143: - case 144: + case 145: + case 146: return getParentTypeOfClassElement(node); default: ts.Debug.fail("Unsupported decorator target."); @@ -16798,25 +17210,25 @@ var ts; } function getEffectiveDecoratorSecondArgumentType(node) { switch (node.kind) { - case 212: + case 214: ts.Debug.fail("Class decorators should not have a second synthetic argument."); return unknownType; - case 136: + case 138: node = node.parent; - if (node.kind === 142) { + if (node.kind === 144) { return anyType; } - case 139: case 141: case 143: - case 144: + case 145: + case 146: var element = node; switch (element.name.kind) { - case 67: + case 69: case 8: case 9: return getStringLiteralType(element.name); - case 134: + case 136: var nameType = checkComputedPropertyName(element.name); if (allConstituentTypesHaveKind(nameType, 16777216)) { return nameType; @@ -16835,17 +17247,17 @@ var ts; } function getEffectiveDecoratorThirdArgumentType(node) { switch (node.kind) { - case 212: + case 214: ts.Debug.fail("Class decorators should not have a third synthetic argument."); return unknownType; - case 136: + case 138: return numberType; - case 139: + case 141: ts.Debug.fail("Property decorators should not have a third synthetic argument."); return unknownType; - case 141: case 143: - case 144: + case 145: + case 146: var propertyType = getTypeOfNode(node); return createTypedPropertyDescriptorType(propertyType); default: @@ -16867,26 +17279,26 @@ var ts; return unknownType; } function getEffectiveArgumentType(node, argIndex, arg) { - if (node.kind === 137) { + if (node.kind === 139) { return getEffectiveDecoratorArgumentType(node, argIndex); } - else if (argIndex === 0 && node.kind === 168) { + else if (argIndex === 0 && node.kind === 170) { return globalTemplateStringsArrayType; } return undefined; } function getEffectiveArgument(node, args, argIndex) { - if (node.kind === 137 || - (argIndex === 0 && node.kind === 168)) { + if (node.kind === 139 || + (argIndex === 0 && node.kind === 170)) { return undefined; } return args[argIndex]; } function getEffectiveArgumentErrorNode(node, argIndex, arg) { - if (node.kind === 137) { + if (node.kind === 139) { return node.expression; } - else if (argIndex === 0 && node.kind === 168) { + else if (argIndex === 0 && node.kind === 170) { return node.template; } else { @@ -16894,12 +17306,12 @@ var ts; } } function resolveCall(node, signatures, candidatesOutArray, headMessage) { - var isTaggedTemplate = node.kind === 168; - var isDecorator = node.kind === 137; + var isTaggedTemplate = node.kind === 170; + var isDecorator = node.kind === 139; var typeArguments; if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; - if (node.expression.kind !== 93) { + if (node.expression.kind !== 95) { ts.forEach(typeArguments, checkSourceElement); } } @@ -17037,7 +17449,7 @@ var ts; } } function resolveCallExpression(node, candidatesOutArray) { - if (node.expression.kind === 93) { + if (node.expression.kind === 95) { var superType = checkSuperExpression(node.expression); if (superType !== unknownType) { var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node)); @@ -17126,16 +17538,16 @@ var ts; } function getDiagnosticHeadMessageForDecoratorResolution(node) { switch (node.parent.kind) { - case 212: - case 184: + case 214: + case 186: return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; - case 136: + case 138: return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; - case 139: - return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; case 141: + return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; case 143: - case 144: + case 145: + case 146: return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; } } @@ -17163,16 +17575,16 @@ var ts; var links = getNodeLinks(node); if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - if (node.kind === 166) { + if (node.kind === 168) { links.resolvedSignature = resolveCallExpression(node, candidatesOutArray); } - else if (node.kind === 167) { + else if (node.kind === 169) { links.resolvedSignature = resolveNewExpression(node, candidatesOutArray); } - else if (node.kind === 168) { + else if (node.kind === 170) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } - else if (node.kind === 137) { + else if (node.kind === 139) { links.resolvedSignature = resolveDecorator(node, candidatesOutArray); } else { @@ -17184,15 +17596,15 @@ var ts; function checkCallExpression(node) { checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); var signature = getResolvedSignature(node); - if (node.expression.kind === 93) { + if (node.expression.kind === 95) { return voidType; } - if (node.kind === 167) { + if (node.kind === 169) { var declaration = signature.declaration; if (declaration && - declaration.kind !== 142 && - declaration.kind !== 146 && - declaration.kind !== 151) { + declaration.kind !== 144 && + declaration.kind !== 148 && + declaration.kind !== 153) { if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } @@ -17233,10 +17645,22 @@ var ts; assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } } + function assignBindingElementTypes(node) { + if (ts.isBindingPattern(node.name)) { + for (var _i = 0, _a = node.name.elements; _i < _a.length; _i++) { + var element = _a[_i]; + if (element.kind !== 187) { + getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element); + assignBindingElementTypes(element); + } + } + } + } function assignTypeToParameterAndFixTypeParameters(parameter, contextualType, mapper) { var links = getSymbolLinks(parameter); if (!links.type) { links.type = instantiateType(contextualType, mapper); + assignBindingElementTypes(parameter.valueDeclaration); } else if (isInferentialContext(mapper)) { inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper)); @@ -17257,7 +17681,7 @@ var ts; } var isAsync = ts.isAsyncFunctionLike(func); var type; - if (func.body.kind !== 190) { + if (func.body.kind !== 192) { type = checkExpressionCached(func.body, contextualMapper); if (isAsync) { type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); @@ -17361,7 +17785,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 206); + return (body.statements.length === 1) && (body.statements[0].kind === 208); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!produceDiagnostics) { @@ -17370,7 +17794,7 @@ var ts; if (returnType === voidType || isTypeAny(returnType)) { return; } - if (ts.nodeIsMissing(func.body) || func.body.kind !== 190) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 192) { return; } var bodyBlock = func.body; @@ -17383,9 +17807,9 @@ var ts; error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); - if (!hasGrammarError && node.kind === 171) { + if (!hasGrammarError && node.kind === 173) { checkGrammarForGenerator(node); } if (contextualMapper === identityMapper && isContextSensitive(node)) { @@ -17421,14 +17845,14 @@ var ts; } } } - if (produceDiagnostics && node.kind !== 141 && node.kind !== 140) { + if (produceDiagnostics && node.kind !== 143 && node.kind !== 142) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); } return type; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; @@ -17445,7 +17869,7 @@ var ts; if (!node.type) { getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - if (node.body.kind === 190) { + if (node.body.kind === 192) { checkSourceElement(node.body); } else { @@ -17477,17 +17901,17 @@ var ts; } function isReferenceOrErrorExpression(n) { switch (n.kind) { - case 67: { + case 69: { var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3) !== 0; } - case 164: { + case 166: { var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~8) !== 0; } - case 165: + case 167: return true; - case 170: + case 172: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -17495,12 +17919,12 @@ var ts; } function isConstVariableReference(n) { switch (n.kind) { - case 67: - case 164: { + case 69: + case 166: { var symbol = findSymbol(n); return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 32768) !== 0; } - case 165: { + case 167: { var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 9) { @@ -17510,7 +17934,7 @@ var ts; } return false; } - case 170: + case 172: return isConstVariableReference(n.expression); default: return false; @@ -17555,15 +17979,15 @@ var ts; switch (node.operator) { case 35: case 36: - case 49: + case 50: if (someConstituentTypeHasKind(operandType, 16777216)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; - case 48: + case 49: return booleanType; - case 40: case 41: + case 42: var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { checkReferenceExpression(node.operand, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); @@ -17618,21 +18042,21 @@ var ts; function isConstEnumSymbol(symbol) { return (symbol.flags & 128) !== 0; } - function checkInstanceOfExpression(node, leftType, rightType) { + function checkInstanceOfExpression(left, right, leftType, rightType) { if (allConstituentTypesHaveKind(leftType, 16777726)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); + error(right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } - function checkInExpression(node, leftType, rightType) { + function checkInExpression(left, right, leftType, rightType) { if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 16777216)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); + error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 | 512)) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; } @@ -17640,7 +18064,7 @@ var ts; var properties = node.properties; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; - if (p.kind === 243 || p.kind === 244) { + if (p.kind === 245 || p.kind === 246) { var name_13 = p.name; var type = isTypeAny(sourceType) ? sourceType @@ -17648,7 +18072,12 @@ var ts; isNumericLiteralName(name_13.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_13, type); + if (p.kind === 246) { + checkDestructuringAssignment(p, type); + } + else { + checkDestructuringAssignment(p.initializer || name_13, type); + } } else { error(name_13, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_13)); @@ -17665,8 +18094,8 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 185) { - if (e.kind !== 183) { + if (e.kind !== 187) { + if (e.kind !== 185) { var propName = "" + i; var type = isTypeAny(sourceType) ? sourceType @@ -17691,7 +18120,7 @@ var ts; } else { var restExpression = e.expression; - if (restExpression.kind === 179 && restExpression.operatorToken.kind === 55) { + if (restExpression.kind === 181 && restExpression.operatorToken.kind === 56) { error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer); } else { @@ -17703,15 +18132,26 @@ var ts; } return sourceType; } - function checkDestructuringAssignment(target, sourceType, contextualMapper) { - if (target.kind === 179 && target.operatorToken.kind === 55) { + function checkDestructuringAssignment(exprOrAssignment, sourceType, contextualMapper) { + var target; + if (exprOrAssignment.kind === 246) { + var prop = exprOrAssignment; + if (prop.objectAssignmentInitializer) { + checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper); + } + target = exprOrAssignment.name; + } + else { + target = exprOrAssignment; + } + if (target.kind === 181 && target.operatorToken.kind === 56) { checkBinaryExpression(target, contextualMapper); target = target.left; } - if (target.kind === 163) { + if (target.kind === 165) { return checkObjectLiteralAssignment(target, sourceType, contextualMapper); } - if (target.kind === 162) { + if (target.kind === 164) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } return checkReferenceAssignment(target, sourceType, contextualMapper); @@ -17724,33 +18164,38 @@ var ts; return sourceType; } function checkBinaryExpression(node, contextualMapper) { - var operator = node.operatorToken.kind; - if (operator === 55 && (node.left.kind === 163 || node.left.kind === 162)) { - return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); + return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node); + } + function checkBinaryLikeExpression(left, operatorToken, right, contextualMapper, errorNode) { + var operator = operatorToken.kind; + if (operator === 56 && (left.kind === 165 || left.kind === 164)) { + return checkDestructuringAssignment(left, checkExpression(right, contextualMapper), contextualMapper); } - var leftType = checkExpression(node.left, contextualMapper); - var rightType = checkExpression(node.right, contextualMapper); + var leftType = checkExpression(left, contextualMapper); + var rightType = checkExpression(right, contextualMapper); switch (operator) { case 37: - case 58: case 38: case 59: - case 39: case 60: - case 36: - case 57: - case 42: + case 39: case 61: - case 43: + case 40: case 62: - case 44: + case 36: + case 58: + case 43: case 63: - case 46: + case 44: + case 64: + case 45: case 65: case 47: + case 67: + case 48: + case 68: + case 46: case 66: - case 45: - case 64: if (leftType.flags & (32 | 64)) leftType = rightType; if (rightType.flags & (32 | 64)) @@ -17758,19 +18203,19 @@ var ts; var suggestedOperator; if ((leftType.flags & 8) && (rightType.flags & 8) && - (suggestedOperator = getSuggestedBooleanOperator(node.operatorToken.kind)) !== undefined) { - error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operatorToken.kind), ts.tokenToString(suggestedOperator)); + (suggestedOperator = getSuggestedBooleanOperator(operatorToken.kind)) !== undefined) { + error(errorNode || operatorToken, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(operatorToken.kind), ts.tokenToString(suggestedOperator)); } else { - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var leftOk = checkArithmeticOperandType(left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); if (leftOk && rightOk) { checkAssignmentOperator(numberType); } } return numberType; case 35: - case 56: + case 57: if (leftType.flags & (32 | 64)) leftType = rightType; if (rightType.flags & (32 | 64)) @@ -17794,7 +18239,7 @@ var ts; reportOperatorError(); return anyType; } - if (operator === 56) { + if (operator === 57) { checkAssignmentOperator(resultType); } return resultType; @@ -17813,23 +18258,23 @@ var ts; reportOperatorError(); } return booleanType; - case 89: - return checkInstanceOfExpression(node, leftType, rightType); - case 88: - return checkInExpression(node, leftType, rightType); - case 50: - return rightType; + case 91: + return checkInstanceOfExpression(left, right, leftType, rightType); + case 90: + return checkInExpression(left, right, leftType, rightType); case 51: + return rightType; + case 52: return getUnionType([leftType, rightType]); - case 55: + case 56: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); case 24: return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216) ? node.left : - someConstituentTypeHasKind(rightType, 16777216) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216) ? left : + someConstituentTypeHasKind(rightType, 16777216) ? right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -17839,29 +18284,29 @@ var ts; } function getSuggestedBooleanOperator(operator) { switch (operator) { - case 46: - case 65: - return 51; case 47: - case 66: + case 67: + return 52; + case 48: + case 68: return 33; - case 45: - case 64: - return 50; + case 46: + case 66: + return 51; default: return undefined; } } function checkAssignmentOperator(valueType) { - if (produceDiagnostics && operator >= 55 && operator <= 66) { - var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + if (produceDiagnostics && operator >= 56 && operator <= 68) { + var ok = checkReferenceExpression(left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); if (ok) { - checkTypeAssignableTo(valueType, leftType, node.left, undefined); + checkTypeAssignableTo(valueType, leftType, left, undefined); } } } function reportOperatorError() { - error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); + error(errorNode || operatorToken, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } function isYieldExpressionInClass(node) { @@ -17937,14 +18382,14 @@ var ts; return links.resolvedType; } function checkPropertyAssignment(node, contextualMapper) { - if (node.name.kind === 134) { + if (node.name.kind === 136) { checkComputedPropertyName(node.name); } return checkExpression(node.initializer, contextualMapper); } function checkObjectLiteralMethod(node, contextualMapper) { checkGrammarMethod(node); - if (node.name.kind === 134) { + if (node.name.kind === 136) { checkComputedPropertyName(node.name); } var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); @@ -17967,7 +18412,7 @@ var ts; } function checkExpression(node, contextualMapper) { var type; - if (node.kind === 133) { + if (node.kind === 135) { type = checkQualifiedName(node); } else { @@ -17975,9 +18420,9 @@ var ts; type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } if (isConstEnumObjectType(type)) { - var ok = (node.parent.kind === 164 && node.parent.expression === node) || - (node.parent.kind === 165 && node.parent.expression === node) || - ((node.kind === 67 || node.kind === 133) && isInRightSideOfImportOrExportAssignment(node)); + var ok = (node.parent.kind === 166 && node.parent.expression === node) || + (node.parent.kind === 167 && node.parent.expression === node) || + ((node.kind === 69 || node.kind === 135) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } @@ -17990,78 +18435,78 @@ var ts; } function checkExpressionWorker(node, contextualMapper) { switch (node.kind) { - case 67: + case 69: return checkIdentifier(node); - case 95: - return checkThisExpression(node); - case 93: - return checkSuperExpression(node); - case 91: - return nullType; case 97: - case 82: + return checkThisExpression(node); + case 95: + return checkSuperExpression(node); + case 93: + return nullType; + case 99: + case 84: return booleanType; case 8: return checkNumericLiteral(node); - case 181: + case 183: return checkTemplateExpression(node); case 9: case 11: return stringType; case 10: return globalRegExpType; - case 162: - return checkArrayLiteral(node, contextualMapper); - case 163: - return checkObjectLiteral(node, contextualMapper); case 164: - return checkPropertyAccessExpression(node); + return checkArrayLiteral(node, contextualMapper); case 165: - return checkIndexedAccess(node); + return checkObjectLiteral(node, contextualMapper); case 166: + return checkPropertyAccessExpression(node); case 167: - return checkCallExpression(node); + return checkIndexedAccess(node); case 168: - return checkTaggedTemplateExpression(node); - case 170: - return checkExpression(node.expression, contextualMapper); - case 184: - return checkClassExpression(node); - case 171: - case 172: - return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); - case 174: - return checkTypeOfExpression(node); case 169: - case 187: - return checkAssertion(node); + return checkCallExpression(node); + case 170: + return checkTaggedTemplateExpression(node); + case 172: + return checkExpression(node.expression, contextualMapper); + case 186: + return checkClassExpression(node); case 173: - return checkDeleteExpression(node); - case 175: - return checkVoidExpression(node); + case 174: + return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); case 176: - return checkAwaitExpression(node); + return checkTypeOfExpression(node); + case 171: + case 189: + return checkAssertion(node); + case 175: + return checkDeleteExpression(node); case 177: - return checkPrefixUnaryExpression(node); + return checkVoidExpression(node); case 178: - return checkPostfixUnaryExpression(node); + return checkAwaitExpression(node); case 179: - return checkBinaryExpression(node, contextualMapper); + return checkPrefixUnaryExpression(node); case 180: - return checkConditionalExpression(node, contextualMapper); - case 183: - return checkSpreadElementExpression(node, contextualMapper); - case 185: - return undefinedType; + return checkPostfixUnaryExpression(node); + case 181: + return checkBinaryExpression(node, contextualMapper); case 182: + return checkConditionalExpression(node, contextualMapper); + case 185: + return checkSpreadElementExpression(node, contextualMapper); + case 187: + return undefinedType; + case 184: return checkYieldExpression(node); - case 238: + case 240: return checkJsxExpression(node); - case 231: - return checkJsxElement(node); - case 232: - return checkJsxSelfClosingElement(node); case 233: + return checkJsxElement(node); + case 234: + return checkJsxSelfClosingElement(node); + case 235: ts.Debug.fail("Shouldn't ever directly check a JsxOpeningElement"); } return unknownType; @@ -18082,7 +18527,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & 112) { func = ts.getContainingFunction(node); - if (!(func.kind === 142 && ts.nodeIsPresent(func.body))) { + if (!(func.kind === 144 && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -18097,15 +18542,15 @@ var ts; if (!node.asteriskToken || !node.body) { return false; } - return node.kind === 141 || - node.kind === 211 || - node.kind === 171; + return node.kind === 143 || + node.kind === 213 || + node.kind === 173; } function getTypePredicateParameterIndex(parameterList, parameter) { if (parameterList) { for (var i = 0; i < parameterList.length; i++) { var param = parameterList[i]; - if (param.name.kind === 67 && + if (param.name.kind === 69 && param.name.text === parameter.text) { return i; } @@ -18115,30 +18560,30 @@ var ts; } function isInLegalTypePredicatePosition(node) { switch (node.parent.kind) { - case 172: - case 145: - case 211: - case 171: - case 150: - case 141: - case 140: + case 174: + case 147: + case 213: + case 173: + case 152: + case 143: + case 142: return node === node.parent.type; } return false; } function checkSignatureDeclaration(node) { - if (node.kind === 147) { + if (node.kind === 149) { checkGrammarIndexSignature(node); } - else if (node.kind === 150 || node.kind === 211 || node.kind === 151 || - node.kind === 145 || node.kind === 142 || - node.kind === 146) { + else if (node.kind === 152 || node.kind === 213 || node.kind === 153 || + node.kind === 147 || node.kind === 144 || + node.kind === 148) { checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { - if (node.type.kind === 148) { + if (node.type.kind === 150) { var typePredicate = getSignatureFromDeclaration(node).typePredicate; var typePredicateNode = node.type; if (isInLegalTypePredicatePosition(typePredicateNode)) { @@ -18157,19 +18602,19 @@ var ts; if (hasReportedError) { break; } - if (param.name.kind === 159 || - param.name.kind === 160) { + if (param.name.kind === 161 || + param.name.kind === 162) { (function checkBindingPattern(pattern) { for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.name.kind === 67 && + if (element.name.kind === 69 && element.name.text === typePredicate.parameterName) { error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName); hasReportedError = true; break; } - else if (element.name.kind === 160 || - element.name.kind === 159) { + else if (element.name.kind === 162 || + element.name.kind === 161) { checkBindingPattern(element.name); } } @@ -18193,10 +18638,10 @@ var ts; checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { - case 146: + case 148: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; - case 145: + case 147: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } @@ -18218,7 +18663,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 213) { + if (node.kind === 215) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -18233,7 +18678,7 @@ var ts; var declaration = decl; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 128: + case 130: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -18241,7 +18686,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 126: + case 128: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -18281,7 +18726,7 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 166 && n.expression.kind === 93; + return n.kind === 168 && n.expression.kind === 95; } function containsSuperCallAsComputedPropertyName(n) { return n.name && containsSuperCall(n.name); @@ -18299,15 +18744,15 @@ var ts; return ts.forEachChild(n, containsSuperCall); } function markThisReferencesAsErrors(n) { - if (n.kind === 95) { + if (n.kind === 97) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 171 && n.kind !== 211) { + else if (n.kind !== 173 && n.kind !== 213) { ts.forEachChild(n, markThisReferencesAsErrors); } } function isInstancePropertyWithInitializer(n) { - return n.kind === 139 && + return n.kind === 141 && !(n.flags & 128) && !!n.initializer; } @@ -18327,7 +18772,7 @@ var ts; var superCallStatement; for (var _i = 0; _i < statements.length; _i++) { var statement = statements[_i]; - if (statement.kind === 193 && isSuperCallExpression(statement.expression)) { + if (statement.kind === 195 && isSuperCallExpression(statement.expression)) { superCallStatement = statement; break; } @@ -18351,13 +18796,13 @@ var ts; function checkAccessorDeclaration(node) { if (produceDiagnostics) { checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (node.kind === 143) { + if (node.kind === 145) { if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } if (!ts.hasDynamicName(node)) { - var otherKind = node.kind === 143 ? 144 : 143; + var otherKind = node.kind === 145 ? 146 : 145; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { if (((node.flags & 112) !== (otherAccessor.flags & 112))) { @@ -18442,9 +18887,9 @@ var ts; return; } var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 213) { - ts.Debug.assert(signatureDeclarationNode.kind === 145 || signatureDeclarationNode.kind === 146); - var signatureKind = signatureDeclarationNode.kind === 145 ? 0 : 1; + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 215) { + ts.Debug.assert(signatureDeclarationNode.kind === 147 || signatureDeclarationNode.kind === 148); + var signatureKind = signatureDeclarationNode.kind === 147 ? 0 : 1; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); var containingType = getDeclaredTypeOfSymbol(containingSymbol); signaturesToCheck = getSignaturesOfType(containingType, signatureKind); @@ -18462,7 +18907,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = ts.getCombinedNodeFlags(n); - if (n.parent.kind !== 213 && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 215 && ts.isInAmbientContext(n)) { if (!(flags & 2)) { flags |= 1; } @@ -18538,7 +18983,7 @@ var ts; if (subsequentNode.kind === node.kind) { var errorNode_1 = subsequentNode.name || subsequentNode; if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) { - ts.Debug.assert(node.kind === 141 || node.kind === 140); + ts.Debug.assert(node.kind === 143 || node.kind === 142); ts.Debug.assert((node.flags & 128) !== (subsequentNode.flags & 128)); var diagnostic = node.flags & 128 ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static; error(errorNode_1, diagnostic); @@ -18570,11 +19015,11 @@ var ts; var current = declarations[_i]; var node = current; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 213 || node.parent.kind === 153 || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 215 || node.parent.kind === 155 || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 211 || node.kind === 141 || node.kind === 140 || node.kind === 142) { + if (node.kind === 213 || node.kind === 143 || node.kind === 142 || node.kind === 144) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -18687,16 +19132,16 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 213: + case 215: return 2097152; - case 216: + case 218: return d.name.kind === 9 || ts.getModuleInstanceState(d) !== 0 ? 4194304 | 1048576 : 4194304; - case 212: - case 215: + case 214: + case 217: return 2097152 | 1048576; - case 219: + case 221: var result = 0; var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); @@ -18707,7 +19152,8 @@ var ts; } } function checkNonThenableType(type, location, message) { - if (!(type.flags & 1) && isTypeAssignableTo(type, getGlobalThenableType())) { + type = getWidenedType(type); + if (!isTypeAny(type) && isTypeAssignableTo(type, getGlobalThenableType())) { if (location) { if (!message) { message = ts.Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member; @@ -18822,22 +19268,22 @@ var ts; var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); var errorInfo; switch (node.parent.kind) { - case 212: + case 214: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); expectedReturnType = getUnionType([classConstructorType, voidType]); break; - case 136: + case 138: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; - case 139: + case 141: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; - case 141: case 143: - case 144: + case 145: + case 146: var methodType = getTypeOfNode(node.parent); var descriptorType = createTypedPropertyDescriptorType(methodType); expectedReturnType = getUnionType([descriptorType, voidType]); @@ -18846,9 +19292,9 @@ var ts; checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo); } function checkTypeNodeAsExpression(node) { - if (node && node.kind === 149) { + if (node && node.kind === 151) { var root = getFirstIdentifier(node.typeName); - var meaning = root.parent.kind === 149 ? 793056 : 1536; + var meaning = root.parent.kind === 151 ? 793056 : 1536; var rootSymbol = resolveName(root, root.text, meaning | 8388608, undefined, undefined); if (rootSymbol && rootSymbol.flags & 8388608) { var aliasTarget = resolveAlias(rootSymbol); @@ -18860,19 +19306,19 @@ var ts; } function checkTypeAnnotationAsExpression(node) { switch (node.kind) { - case 139: - checkTypeNodeAsExpression(node.type); - break; - case 136: - checkTypeNodeAsExpression(node.type); - break; case 141: checkTypeNodeAsExpression(node.type); break; + case 138: + checkTypeNodeAsExpression(node.type); + break; case 143: checkTypeNodeAsExpression(node.type); break; - case 144: + case 145: + checkTypeNodeAsExpression(node.type); + break; + case 146: checkTypeNodeAsExpression(ts.getSetAccessorTypeAnnotationNode(node)); break; } @@ -18895,24 +19341,24 @@ var ts; } if (compilerOptions.emitDecoratorMetadata) { switch (node.kind) { - case 212: + case 214: var constructor = ts.getFirstConstructorWithBody(node); if (constructor) { checkParameterTypeAnnotationsAsExpressions(constructor); } break; - case 141: - checkParameterTypeAnnotationsAsExpressions(node); - case 144: case 143: - case 139: - case 136: + checkParameterTypeAnnotationsAsExpressions(node); + case 146: + case 145: + case 141: + case 138: checkTypeAnnotationAsExpression(node); break; } } emitDecorate = true; - if (node.kind === 136) { + if (node.kind === 138) { emitParam = true; } ts.forEach(node.decorators, checkDecorator); @@ -18930,12 +19376,9 @@ var ts; checkSignatureDeclaration(node); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { - if (!compilerOptions.experimentalAsyncFunctions) { - error(node, ts.Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning); - } emitAwaiter = true; } - if (node.name && node.name.kind === 134) { + if (node.name && node.name.kind === 136) { checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { @@ -18970,11 +19413,11 @@ var ts; } } function checkBlock(node) { - if (node.kind === 190) { + if (node.kind === 192) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); - if (ts.isFunctionBlock(node) || node.kind === 217) { + if (ts.isFunctionBlock(node) || node.kind === 219) { checkFunctionAndClassExpressionBodies(node); } } @@ -18992,19 +19435,19 @@ var ts; if (!(identifier && identifier.text === name)) { return false; } - if (node.kind === 139 || - node.kind === 138 || - node.kind === 141 || + if (node.kind === 141 || node.kind === 140 || node.kind === 143 || - node.kind === 144) { + node.kind === 142 || + node.kind === 145 || + node.kind === 146) { return false; } if (ts.isInAmbientContext(node)) { return false; } var root = ts.getRootDeclaration(node); - if (root.kind === 136 && ts.nodeIsMissing(root.parent.body)) { + if (root.kind === 138 && ts.nodeIsMissing(root.parent.body)) { return false; } return true; @@ -19018,7 +19461,7 @@ var ts; var current = node; while (current) { if (getNodeCheckFlags(current) & 4) { - var isDeclaration_1 = node.kind !== 67; + var isDeclaration_1 = node.kind !== 69; if (isDeclaration_1) { error(node.name, ts.Diagnostics.Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference); } @@ -19039,7 +19482,7 @@ var ts; return; } if (ts.getClassExtendsHeritageClauseElement(enclosingClass)) { - var isDeclaration_2 = node.kind !== 67; + var isDeclaration_2 = node.kind !== 69; if (isDeclaration_2) { error(node, ts.Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference); } @@ -19052,11 +19495,11 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 216 && ts.getModuleInstanceState(node) !== 1) { + if (node.kind === 218 && ts.getModuleInstanceState(node) !== 1) { return; } var parent = getDeclarationContainer(node); - if (parent.kind === 246 && ts.isExternalModule(parent)) { + if (parent.kind === 248 && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name)); } } @@ -19064,7 +19507,7 @@ var ts; if ((ts.getCombinedNodeFlags(node) & 49152) !== 0 || ts.isParameterDeclaration(node)) { return; } - if (node.kind === 209 && !node.initializer) { + if (node.kind === 211 && !node.initializer) { return; } var symbol = getSymbolOfNode(node); @@ -19074,15 +19517,15 @@ var ts; localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & 2) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 49152) { - var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 210); - var container = varDeclList.parent.kind === 191 && varDeclList.parent.parent + var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 212); + var container = varDeclList.parent.kind === 193 && varDeclList.parent.parent ? varDeclList.parent.parent : undefined; var namesShareScope = container && - (container.kind === 190 && ts.isFunctionLike(container.parent) || - container.kind === 217 || - container.kind === 216 || - container.kind === 246); + (container.kind === 192 && ts.isFunctionLike(container.parent) || + container.kind === 219 || + container.kind === 218 || + container.kind === 248); if (!namesShareScope) { var name_14 = symbolToString(localDeclarationSymbol); error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_14, name_14); @@ -19092,16 +19535,16 @@ var ts; } } function checkParameterInitializer(node) { - if (ts.getRootDeclaration(node).kind !== 136) { + if (ts.getRootDeclaration(node).kind !== 138) { return; } var func = ts.getContainingFunction(node); visit(node.initializer); function visit(n) { - if (n.kind === 67) { + if (n.kind === 69) { var referencedSymbol = getNodeLinks(n).resolvedSymbol; if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455) === referencedSymbol) { - if (referencedSymbol.valueDeclaration.kind === 136) { + if (referencedSymbol.valueDeclaration.kind === 138) { if (referencedSymbol.valueDeclaration === node) { error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name)); return; @@ -19121,7 +19564,7 @@ var ts; function checkVariableLikeDeclaration(node) { checkDecorators(node); checkSourceElement(node.type); - if (node.name.kind === 134) { + if (node.name.kind === 136) { checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); @@ -19130,7 +19573,7 @@ var ts; if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } - if (node.initializer && ts.getRootDeclaration(node).kind === 136 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { + if (node.initializer && ts.getRootDeclaration(node).kind === 138 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -19158,9 +19601,9 @@ var ts; checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } } - if (node.kind !== 139 && node.kind !== 138) { + if (node.kind !== 141 && node.kind !== 140) { checkExportsOnMergedDeclarations(node); - if (node.kind === 209 || node.kind === 161) { + if (node.kind === 211 || node.kind === 163) { checkVarDeclaredNamesNotShadowed(node); } checkCollisionWithCapturedSuperVariable(node, node.name); @@ -19181,7 +19624,7 @@ var ts; ts.forEach(node.declarationList.declarations, checkSourceElement); } function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) { - if (node.modifiers && node.parent.kind === 163) { + if (node.modifiers && node.parent.kind === 165) { if (ts.isAsyncFunctionLike(node)) { if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); @@ -19214,12 +19657,12 @@ var ts; } function checkForStatement(node) { if (!checkGrammarStatementInAmbientContext(node)) { - if (node.initializer && node.initializer.kind === 210) { + if (node.initializer && node.initializer.kind === 212) { checkGrammarVariableDeclarationList(node.initializer); } } if (node.initializer) { - if (node.initializer.kind === 210) { + if (node.initializer.kind === 212) { ts.forEach(node.initializer.declarations, checkVariableDeclaration); } else { @@ -19234,13 +19677,13 @@ var ts; } function checkForOfStatement(node) { checkGrammarForInOrForOfStatement(node); - if (node.initializer.kind === 210) { + if (node.initializer.kind === 212) { checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; var iteratedType = checkRightHandSideOfForOf(node.expression); - if (varExpr.kind === 162 || varExpr.kind === 163) { + if (varExpr.kind === 164 || varExpr.kind === 165) { checkDestructuringAssignment(varExpr, iteratedType || unknownType); } else { @@ -19255,7 +19698,7 @@ var ts; } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); - if (node.initializer.kind === 210) { + if (node.initializer.kind === 212) { var variable = node.initializer.declarations[0]; if (variable && ts.isBindingPattern(variable.name)) { error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); @@ -19265,7 +19708,7 @@ var ts; else { var varExpr = node.initializer; var leftType = checkExpression(varExpr); - if (varExpr.kind === 162 || varExpr.kind === 163) { + if (varExpr.kind === 164 || varExpr.kind === 165) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) { @@ -19427,7 +19870,7 @@ var ts; checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } function isGetAccessorWithAnnotatatedSetAccessor(node) { - return !!(node.kind === 143 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 144))); + return !!(node.kind === 145 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 146))); } function checkReturnStatement(node) { if (!checkGrammarStatementInAmbientContext(node)) { @@ -19445,10 +19888,10 @@ var ts; if (func.asteriskToken) { return; } - if (func.kind === 144) { + if (func.kind === 146) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else if (func.kind === 142) { + else if (func.kind === 144) { if (!isTypeAssignableTo(exprType, returnType)) { error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } @@ -19457,7 +19900,9 @@ var ts; if (ts.isAsyncFunctionLike(func)) { var promisedType = getPromisedType(returnType); var awaitedType = checkAwaitedType(exprType, node.expression, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); - checkTypeAssignableTo(awaitedType, promisedType, node.expression); + if (promisedType) { + checkTypeAssignableTo(awaitedType, promisedType, node.expression); + } } else { checkTypeAssignableTo(exprType, returnType, node.expression); @@ -19481,7 +19926,7 @@ var ts; var hasDuplicateDefaultClause = false; var expressionType = checkExpression(node.expression); ts.forEach(node.caseBlock.clauses, function (clause) { - if (clause.kind === 240 && !hasDuplicateDefaultClause) { + if (clause.kind === 242 && !hasDuplicateDefaultClause) { if (firstDefaultClause === undefined) { firstDefaultClause = clause; } @@ -19493,7 +19938,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (produceDiagnostics && clause.kind === 239) { + if (produceDiagnostics && clause.kind === 241) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); if (!isTypeAssignableTo(expressionType, caseType)) { @@ -19510,7 +19955,7 @@ var ts; if (ts.isFunctionLike(current)) { break; } - if (current.kind === 205 && current.label.text === node.label.text) { + if (current.kind === 207 && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -19536,7 +19981,7 @@ var ts; var catchClause = node.catchClause; if (catchClause) { if (catchClause.variableDeclaration) { - if (catchClause.variableDeclaration.name.kind !== 67) { + if (catchClause.variableDeclaration.name.kind !== 69) { grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); } else if (catchClause.variableDeclaration.type) { @@ -19604,7 +20049,7 @@ var ts; return; } var errorNode; - if (prop.valueDeclaration.name.kind === 134 || prop.parent === containingType.symbol) { + if (prop.valueDeclaration.name.kind === 136 || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { @@ -19674,6 +20119,7 @@ var ts; checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { @@ -19692,7 +20138,7 @@ var ts; } } } - checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32)) { var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments); @@ -19705,7 +20151,8 @@ var ts; } var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node); if (implementedTypeNodes) { - ts.forEach(implementedTypeNodes, function (typeRefNode) { + for (var _b = 0; _b < implementedTypeNodes.length; _b++) { + var typeRefNode = implementedTypeNodes[_b]; if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) { error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments); } @@ -19715,14 +20162,14 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096) ? t.target : t; if (declaredType.flags & (1024 | 2048)) { - checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(t, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); } } } - }); + } } if (produceDiagnostics) { checkIndexConstraints(type); @@ -19750,7 +20197,7 @@ var ts; if (derived === base) { var derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol); if (baseDeclarationFlags & 256 && (!derivedClassDecl || !(derivedClassDecl.flags & 256))) { - if (derivedClassDecl.kind === 184) { + if (derivedClassDecl.kind === 186) { error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, symbolToString(baseProperty), typeToString(baseType)); } else { @@ -19794,7 +20241,7 @@ var ts; } } function isAccessor(kind) { - return kind === 143 || kind === 144; + return kind === 145 || kind === 146; } function areTypeParametersIdentical(list1, list2) { if (!list1 && !list2) { @@ -19831,7 +20278,7 @@ var ts; var ok = true; for (var _i = 0; _i < baseTypes.length; _i++) { var base = baseTypes[_i]; - var properties = getPropertiesOfObjectType(base); + var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType)); for (var _a = 0; _a < properties.length; _a++) { var prop = properties[_a]; if (!ts.hasProperty(seen, prop.name)) { @@ -19860,7 +20307,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 213); + var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 215); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -19868,17 +20315,19 @@ var ts; } if (node === firstInterfaceDecl) { var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); if (checkInheritedPropertiesAreIdentical(type, node.name)) { - ts.forEach(getBaseTypes(type), function (baseType) { - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); - }); + for (var _i = 0, _a = getBaseTypes(type); _i < _a.length; _i++) { + var baseType = _a[_i]; + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); + } checkIndexConstraints(type); } } if (symbol && symbol.declarations) { - for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { - var declaration = _a[_i]; - if (declaration.kind === 212 && !ts.isInAmbientContext(declaration)) { + for (var _b = 0, _c = symbol.declarations; _b < _c.length; _b++) { + var declaration = _c[_b]; + if (declaration.kind === 214 && !ts.isInAmbientContext(declaration)) { error(node, ts.Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface); break; } @@ -19909,10 +20358,15 @@ var ts; var autoValue = 0; var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); - ts.forEach(node.members, function (member) { - if (member.name.kind !== 134 && isNumericLiteralName(member.name.text)) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.name.kind === 136) { + error(member.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); + } + else if (isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } + var previousEnumMemberIsNonConstant = autoValue === undefined; var initializer = member.initializer; if (initializer) { autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient); @@ -19920,10 +20374,13 @@ var ts; else if (ambient && !enumIsConst) { autoValue = undefined; } + else if (previousEnumMemberIsNonConstant) { + error(member.name, ts.Diagnostics.Enum_member_must_have_initializer); + } if (autoValue !== undefined) { getNodeLinks(member).enumMemberValue = autoValue++; } - }); + } nodeLinks.flags |= 8192; } function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) { @@ -19934,7 +20391,10 @@ var ts; if (enumIsConst) { error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); } - else if (!ambient) { + else if (ambient) { + error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression); + } + else { checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined); } } @@ -19950,7 +20410,7 @@ var ts; return value; function evalConstant(e) { switch (e.kind) { - case 177: + case 179: var value_1 = evalConstant(e.operand); if (value_1 === undefined) { return undefined; @@ -19958,10 +20418,10 @@ var ts; switch (e.operator) { case 35: return value_1; case 36: return -value_1; - case 49: return ~value_1; + case 50: return ~value_1; } return undefined; - case 179: + case 181: var left = evalConstant(e.left); if (left === undefined) { return undefined; @@ -19971,37 +20431,37 @@ var ts; return undefined; } switch (e.operatorToken.kind) { - case 46: return left | right; - case 45: return left & right; - case 43: return left >> right; - case 44: return left >>> right; - case 42: return left << right; - case 47: return left ^ right; + case 47: return left | right; + case 46: return left & right; + case 44: return left >> right; + case 45: return left >>> right; + case 43: return left << right; + case 48: return left ^ right; case 37: return left * right; - case 38: return left / right; + case 39: return left / right; case 35: return left + right; case 36: return left - right; - case 39: return left % right; + case 40: return left % right; } return undefined; case 8: return +e.text; - case 170: + case 172: return evalConstant(e.expression); - case 67: - case 165: - case 164: + case 69: + case 167: + case 166: var member = initializer.parent; var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); var enumType_1; var propertyName; - if (e.kind === 67) { + if (e.kind === 69) { enumType_1 = currentType; propertyName = e.text; } else { var expression; - if (e.kind === 165) { + if (e.kind === 167) { if (e.argumentExpression === undefined || e.argumentExpression.kind !== 9) { return undefined; @@ -20015,10 +20475,10 @@ var ts; } var current = expression; while (current) { - if (current.kind === 67) { + if (current.kind === 69) { break; } - else if (current.kind === 164) { + else if (current.kind === 166) { current = current.expression; } else { @@ -20041,7 +20501,7 @@ var ts; if (member === propertyDecl) { return undefined; } - if (!isDefinedBefore(propertyDecl, member)) { + if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) { reportError = false; error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums); return undefined; @@ -20055,7 +20515,7 @@ var ts; if (!produceDiagnostics) { return; } - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -20077,7 +20537,7 @@ var ts; } var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 215) { + if (declaration.kind !== 217) { return false; } var enumDeclaration = declaration; @@ -20100,8 +20560,8 @@ var ts; var declarations = symbol.declarations; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; - if ((declaration.kind === 212 || - (declaration.kind === 211 && ts.nodeIsPresent(declaration.body))) && + if ((declaration.kind === 214 || + (declaration.kind === 213 && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } @@ -20152,7 +20612,7 @@ var ts; error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged); } } - var mergedClass = ts.getDeclarationOfKind(symbol, 212); + var mergedClass = ts.getDeclarationOfKind(symbol, 214); if (mergedClass && inSameLexicalScope(node, mergedClass)) { getNodeLinks(node).flags |= 32768; @@ -20160,9 +20620,9 @@ var ts; } if (isAmbientExternalModule) { if (!isGlobalSourceFile(node.parent)) { - error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules); + error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces); } - if (isExternalModuleNameRelative(node.name.text)) { + if (ts.isExternalModuleNameRelative(node.name.text)) { error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name); } } @@ -20171,17 +20631,17 @@ var ts; } function getFirstIdentifier(node) { while (true) { - if (node.kind === 133) { + if (node.kind === 135) { node = node.left; } - else if (node.kind === 164) { + else if (node.kind === 166) { node = node.expression; } else { break; } } - ts.Debug.assert(node.kind === 67); + ts.Debug.assert(node.kind === 69); return node; } function checkExternalImportOrExportDeclaration(node) { @@ -20190,14 +20650,14 @@ var ts; error(moduleName, ts.Diagnostics.String_literal_expected); return false; } - var inAmbientExternalModule = node.parent.kind === 217 && node.parent.parent.name.kind === 9; - if (node.parent.kind !== 246 && !inAmbientExternalModule) { - error(moduleName, node.kind === 226 ? + var inAmbientExternalModule = node.parent.kind === 219 && node.parent.parent.name.kind === 9; + if (node.parent.kind !== 248 && !inAmbientExternalModule) { + error(moduleName, node.kind === 228 ? ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace : ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module); return false; } - if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) { + if (inAmbientExternalModule && ts.isExternalModuleNameRelative(moduleName.text)) { error(node, ts.Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name); return false; } @@ -20211,7 +20671,7 @@ var ts; (symbol.flags & 793056 ? 793056 : 0) | (symbol.flags & 1536 ? 1536 : 0); if (target.flags & excludedMeanings) { - var message = node.kind === 228 ? + var message = node.kind === 230 ? ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; error(node, message, symbolToString(symbol)); @@ -20237,7 +20697,7 @@ var ts; checkImportBinding(importClause); } if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222) { + if (importClause.namedBindings.kind === 224) { checkImportBinding(importClause.namedBindings); } else { @@ -20272,8 +20732,8 @@ var ts; } } else { - if (languageVersion >= 2 && !ts.isInAmbientContext(node)) { - grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + if (modulekind === 5 && !ts.isInAmbientContext(node)) { + grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead); } } } @@ -20288,8 +20748,8 @@ var ts; if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { if (node.exportClause) { ts.forEach(node.exportClause.elements, checkExportSpecifier); - var inAmbientExternalModule = node.parent.kind === 217 && node.parent.parent.name.kind === 9; - if (node.parent.kind !== 246 && !inAmbientExternalModule) { + var inAmbientExternalModule = node.parent.kind === 219 && node.parent.parent.name.kind === 9; + if (node.parent.kind !== 248 && !inAmbientExternalModule) { error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace); } } @@ -20302,7 +20762,7 @@ var ts; } } function checkGrammarModuleElementContext(node, errorMessage) { - if (node.parent.kind !== 246 && node.parent.kind !== 217 && node.parent.kind !== 216) { + if (node.parent.kind !== 248 && node.parent.kind !== 219 && node.parent.kind !== 218) { return grammarErrorOnFirstToken(node, errorMessage); } } @@ -20316,15 +20776,15 @@ var ts; if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) { return; } - var container = node.parent.kind === 246 ? node.parent : node.parent.parent; - if (container.kind === 216 && container.name.kind === 67) { + var container = node.parent.kind === 248 ? node.parent : node.parent.parent; + if (container.kind === 218 && container.name.kind === 69) { error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace); return; } if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - if (node.expression.kind === 67) { + if (node.expression.kind === 69) { markExportAsReferenced(node); } else { @@ -20332,19 +20792,19 @@ var ts; } checkExternalModuleExports(container); if (node.isExportEquals && !ts.isInAmbientContext(node)) { - if (languageVersion >= 2) { - grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + if (modulekind === 5) { + grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead); } - else if (compilerOptions.module === 4) { + else if (modulekind === 4) { grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); } } } function getModuleStatements(node) { - if (node.kind === 246) { + if (node.kind === 248) { return node.statements; } - if (node.kind === 216 && node.body.kind === 217) { + if (node.kind === 218 && node.body.kind === 219) { return node.body.statements; } return emptyArray; @@ -20381,183 +20841,182 @@ var ts; var kind = node.kind; if (cancellationToken) { switch (kind) { - case 216: - case 212: + case 218: + case 214: + case 215: case 213: - case 211: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { - case 135: + case 137: return checkTypeParameter(node); - case 136: - return checkParameter(node); - case 139: case 138: - return checkPropertyDeclaration(node); - case 150: - case 151: - case 145: - case 146: - return checkSignatureDeclaration(node); - case 147: - return checkSignatureDeclaration(node); + return checkParameter(node); case 141: case 140: - return checkMethodDeclaration(node); - case 142: - return checkConstructorDeclaration(node); - case 143: - case 144: - return checkAccessorDeclaration(node); - case 149: - return checkTypeReferenceNode(node); - case 148: - return checkTypePredicate(node); + return checkPropertyDeclaration(node); case 152: - return checkTypeQuery(node); case 153: - return checkTypeLiteral(node); + case 147: + case 148: + return checkSignatureDeclaration(node); + case 149: + return checkSignatureDeclaration(node); + case 143: + case 142: + return checkMethodDeclaration(node); + case 144: + return checkConstructorDeclaration(node); + case 145: + case 146: + return checkAccessorDeclaration(node); + case 151: + return checkTypeReferenceNode(node); + case 150: + return checkTypePredicate(node); case 154: - return checkArrayType(node); + return checkTypeQuery(node); case 155: - return checkTupleType(node); + return checkTypeLiteral(node); case 156: + return checkArrayType(node); case 157: - return checkUnionOrIntersectionType(node); + return checkTupleType(node); case 158: + case 159: + return checkUnionOrIntersectionType(node); + case 160: return checkSourceElement(node.type); - case 211: - return checkFunctionDeclaration(node); - case 190: - case 217: - return checkBlock(node); - case 191: - return checkVariableStatement(node); - case 193: - return checkExpressionStatement(node); - case 194: - return checkIfStatement(node); - case 195: - return checkDoStatement(node); - case 196: - return checkWhileStatement(node); - case 197: - return checkForStatement(node); - case 198: - return checkForInStatement(node); - case 199: - return checkForOfStatement(node); - case 200: - case 201: - return checkBreakOrContinueStatement(node); - case 202: - return checkReturnStatement(node); - case 203: - return checkWithStatement(node); - case 204: - return checkSwitchStatement(node); - case 205: - return checkLabeledStatement(node); - case 206: - return checkThrowStatement(node); - case 207: - return checkTryStatement(node); - case 209: - return checkVariableDeclaration(node); - case 161: - return checkBindingElement(node); - case 212: - return checkClassDeclaration(node); case 213: - return checkInterfaceDeclaration(node); - case 214: - return checkTypeAliasDeclaration(node); - case 215: - return checkEnumDeclaration(node); - case 216: - return checkModuleDeclaration(node); - case 220: - return checkImportDeclaration(node); - case 219: - return checkImportEqualsDeclaration(node); - case 226: - return checkExportDeclaration(node); - case 225: - return checkExportAssignment(node); + return checkFunctionDeclaration(node); case 192: - checkGrammarStatementInAmbientContext(node); - return; + case 219: + return checkBlock(node); + case 193: + return checkVariableStatement(node); + case 195: + return checkExpressionStatement(node); + case 196: + return checkIfStatement(node); + case 197: + return checkDoStatement(node); + case 198: + return checkWhileStatement(node); + case 199: + return checkForStatement(node); + case 200: + return checkForInStatement(node); + case 201: + return checkForOfStatement(node); + case 202: + case 203: + return checkBreakOrContinueStatement(node); + case 204: + return checkReturnStatement(node); + case 205: + return checkWithStatement(node); + case 206: + return checkSwitchStatement(node); + case 207: + return checkLabeledStatement(node); case 208: + return checkThrowStatement(node); + case 209: + return checkTryStatement(node); + case 211: + return checkVariableDeclaration(node); + case 163: + return checkBindingElement(node); + case 214: + return checkClassDeclaration(node); + case 215: + return checkInterfaceDeclaration(node); + case 216: + return checkTypeAliasDeclaration(node); + case 217: + return checkEnumDeclaration(node); + case 218: + return checkModuleDeclaration(node); + case 222: + return checkImportDeclaration(node); + case 221: + return checkImportEqualsDeclaration(node); + case 228: + return checkExportDeclaration(node); + case 227: + return checkExportAssignment(node); + case 194: checkGrammarStatementInAmbientContext(node); return; - case 229: + case 210: + checkGrammarStatementInAmbientContext(node); + return; + case 231: return checkMissingDeclaration(node); } } function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { - case 171: - case 172: + case 173: + case 174: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case 184: + case 186: ts.forEach(node.members, checkSourceElement); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; - case 141: - case 140: + case 143: + case 142: ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } break; - case 142: - case 143: case 144: - case 211: + case 145: + case 146: + case 213: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; - case 203: + case 205: checkFunctionAndClassExpressionBodies(node.expression); break; - case 137: - case 136: case 139: case 138: - case 159: - case 160: + case 141: + case 140: case 161: case 162: case 163: - case 243: case 164: case 165: + case 245: case 166: case 167: case 168: - case 181: - case 188: case 169: - case 187: case 170: - case 174: - case 175: + case 183: + case 190: + case 171: + case 189: + case 172: case 176: - case 173: case 177: case 178: + case 175: case 179: case 180: - case 183: + case 181: case 182: - case 190: - case 217: - case 191: + case 185: + case 184: + case 192: + case 219: case 193: - case 194: case 195: case 196: case 197: @@ -20566,29 +21025,31 @@ var ts; case 200: case 201: case 202: + case 203: case 204: - case 218: - case 239: - case 240: - case 205: case 206: - case 207: - case 242: - case 209: - case 210: - case 212: + case 220: case 241: - case 186: - case 215: - case 245: - case 225: - case 246: - case 238: - case 231: - case 232: - case 236: - case 237: + case 242: + case 207: + case 208: + case 209: + case 244: + case 211: + case 212: + case 214: + case 243: + case 188: + case 217: + case 247: + case 227: + case 248: + case 240: case 233: + case 234: + case 238: + case 239: + case 235: ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } @@ -20666,7 +21127,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 203 && node.parent.statement === node) { + if (node.parent.kind === 205 && node.parent.statement === node) { return true; } node = node.parent; @@ -20688,28 +21149,28 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 246: + case 248: if (!ts.isExternalModule(location)) { break; } - case 216: + case 218: copySymbols(getSymbolOfNode(location).exports, meaning & 8914931); break; - case 215: + case 217: copySymbols(getSymbolOfNode(location).exports, meaning & 8); break; - case 184: + case 186: var className = location.name; if (className) { copySymbol(location.symbol, meaning); } - case 212: - case 213: + case 214: + case 215: if (!(memberFlags & 128)) { copySymbols(getSymbolOfNode(location).members, meaning & 793056); } break; - case 171: + case 173: var funcName = location.name; if (funcName) { copySymbol(location.symbol, meaning); @@ -20742,42 +21203,42 @@ var ts; } } function isTypeDeclarationName(name) { - return name.kind === 67 && + return name.kind === 69 && isTypeDeclaration(name.parent) && name.parent.name === name; } function isTypeDeclaration(node) { switch (node.kind) { - case 135: - case 212: - case 213: + case 137: case 214: case 215: + case 216: + case 217: return true; } } function isTypeReferenceIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 133) { + while (node.parent && node.parent.kind === 135) { node = node.parent; } - return node.parent && node.parent.kind === 149; + return node.parent && node.parent.kind === 151; } function isHeritageClauseElementIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 164) { + while (node.parent && node.parent.kind === 166) { node = node.parent; } - return node.parent && node.parent.kind === 186; + return node.parent && node.parent.kind === 188; } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { - while (nodeOnRightSide.parent.kind === 133) { + while (nodeOnRightSide.parent.kind === 135) { nodeOnRightSide = nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 219) { + if (nodeOnRightSide.parent.kind === 221) { return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 225) { + if (nodeOnRightSide.parent.kind === 227) { return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; @@ -20789,10 +21250,10 @@ var ts; if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 225) { + if (entityName.parent.kind === 227) { return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608); } - if (entityName.kind !== 164) { + if (entityName.kind !== 166) { if (isInRightSideOfImportOrExportAssignment(entityName)) { return getSymbolOfPartOfRightHandSideOfImportEquals(entityName); } @@ -20801,31 +21262,40 @@ var ts; entityName = entityName.parent; } if (isHeritageClauseElementIdentifier(entityName)) { - var meaning = entityName.parent.kind === 186 ? 793056 : 1536; + var meaning = 0; + if (entityName.parent.kind === 188) { + meaning = 793056; + if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent)) { + meaning |= 107455; + } + } + else { + meaning = 1536; + } meaning |= 8388608; return resolveEntityName(entityName, meaning); } - else if ((entityName.parent.kind === 233) || - (entityName.parent.kind === 232) || - (entityName.parent.kind === 235)) { + else if ((entityName.parent.kind === 235) || + (entityName.parent.kind === 234) || + (entityName.parent.kind === 237)) { return getJsxElementTagSymbol(entityName.parent); } else if (ts.isExpression(entityName)) { if (ts.nodeIsMissing(entityName)) { return undefined; } - if (entityName.kind === 67) { + if (entityName.kind === 69) { var meaning = 107455 | 8388608; return resolveEntityName(entityName, meaning); } - else if (entityName.kind === 164) { + else if (entityName.kind === 166) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccessExpression(entityName); } return getNodeLinks(entityName).resolvedSymbol; } - else if (entityName.kind === 133) { + else if (entityName.kind === 135) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkQualifiedName(entityName); @@ -20834,14 +21304,14 @@ var ts; } } else if (isTypeReferenceIdentifier(entityName)) { - var meaning = entityName.parent.kind === 149 ? 793056 : 1536; + var meaning = entityName.parent.kind === 151 ? 793056 : 1536; meaning |= 8388608; return resolveEntityName(entityName, meaning); } - else if (entityName.parent.kind === 236) { + else if (entityName.parent.kind === 238) { return getJsxAttributePropertySymbol(entityName.parent); } - if (entityName.parent.kind === 148) { + if (entityName.parent.kind === 150) { return resolveEntityName(entityName, 1); } return undefined; @@ -20853,14 +21323,14 @@ var ts; if (ts.isDeclarationName(node)) { return getSymbolOfNode(node.parent); } - if (node.kind === 67) { + if (node.kind === 69) { if (isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 225 + return node.parent.kind === 227 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImportEquals(node); } - else if (node.parent.kind === 161 && - node.parent.parent.kind === 159 && + else if (node.parent.kind === 163 && + node.parent.parent.kind === 161 && node === node.parent.propertyName) { var typeOfPattern = getTypeOfNode(node.parent.parent); var propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, node.text); @@ -20870,29 +21340,29 @@ var ts; } } switch (node.kind) { - case 67: - case 164: - case 133: + case 69: + case 166: + case 135: return getSymbolOfEntityNameOrPropertyAccessExpression(node); + case 97: case 95: - case 93: - var type = checkExpression(node); + var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; - case 119: + case 121: var constructorDeclaration = node.parent; - if (constructorDeclaration && constructorDeclaration.kind === 142) { + if (constructorDeclaration && constructorDeclaration.kind === 144) { return constructorDeclaration.parent.symbol; } return undefined; case 9: if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || - ((node.parent.kind === 220 || node.parent.kind === 226) && + ((node.parent.kind === 222 || node.parent.kind === 228) && node.parent.moduleSpecifier === node)) { return resolveExternalModuleName(node, node); } case 8: - if (node.parent.kind === 165 && node.parent.argumentExpression === node) { + if (node.parent.kind === 167 && node.parent.argumentExpression === node) { var objectType = checkExpression(node.parent.expression); if (objectType === unknownType) return undefined; @@ -20906,7 +21376,7 @@ var ts; return undefined; } function getShorthandAssignmentValueSymbol(location) { - if (location && location.kind === 244) { + if (location && location.kind === 246) { return resolveEntityName(location.name, 107455); } return undefined; @@ -21006,11 +21476,11 @@ var ts; } var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { - if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 246) { + if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 248) { return parentSymbol.valueDeclaration; } for (var n = node.parent; n; n = n.parent) { - if ((n.kind === 216 || n.kind === 215) && getSymbolOfNode(n) === parentSymbol) { + if ((n.kind === 218 || n.kind === 217) && getSymbolOfNode(n) === parentSymbol) { return n; } } @@ -21023,11 +21493,11 @@ var ts; } function isStatementWithLocals(node) { switch (node.kind) { - case 190: - case 218: - case 197: - case 198: + case 192: + case 220: case 199: + case 200: + case 201: return true; } return false; @@ -21053,22 +21523,22 @@ var ts; } function isValueAliasDeclaration(node) { switch (node.kind) { - case 219: case 221: - case 222: + case 223: case 224: - case 228: - return isAliasResolvedToValue(getSymbolOfNode(node)); case 226: + case 230: + return isAliasResolvedToValue(getSymbolOfNode(node)); + case 228: var exportClause = node.exportClause; return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration); - case 225: - return node.expression && node.expression.kind === 67 ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; + case 227: + return node.expression && node.expression.kind === 69 ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; } return false; } function isTopLevelValueImportEqualsWithEntityName(node) { - if (node.parent.kind !== 246 || !ts.isInternalModuleImportEqualsDeclaration(node)) { + if (node.parent.kind !== 248 || !ts.isInternalModuleImportEqualsDeclaration(node)) { return false; } var isValue = isAliasResolvedToValue(getSymbolOfNode(node)); @@ -21116,7 +21586,7 @@ var ts; return getNodeLinks(node).enumMemberValue; } function getConstantValue(node) { - if (node.kind === 245) { + if (node.kind === 247) { return getEnumMemberValue(node); } var symbol = getNodeLinks(node).resolvedSymbol; @@ -21202,21 +21672,6 @@ var ts; var symbol = getReferencedValueSymbol(reference); return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } - function getBlockScopedVariableId(n) { - ts.Debug.assert(!ts.nodeIsSynthesized(n)); - var isVariableDeclarationOrBindingElement = n.parent.kind === 161 || (n.parent.kind === 209 && n.parent.name === n); - var symbol = (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) || - getNodeLinks(n).resolvedSymbol || - resolveName(n, n.text, 107455 | 8388608, undefined, undefined); - var isLetOrConst = symbol && - (symbol.flags & 2) && - symbol.valueDeclaration.parent.kind !== 242; - if (isLetOrConst) { - getSymbolLinks(symbol); - return symbol.id; - } - return undefined; - } function instantiateSingleCallFunctionType(functionType, typeArguments) { if (functionType === unknownType) { return unknownType; @@ -21248,7 +21703,6 @@ var ts; isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, collectLinkedAliases: collectLinkedAliases, - getBlockScopedVariableId: getBlockScopedVariableId, getReferencedValueDeclaration: getReferencedValueDeclaration, getTypeReferenceSerializationKind: getTypeReferenceSerializationKind, isOptionalParameter: isOptionalParameter @@ -21329,10 +21783,7 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here); } - else if (languageVersion < 1) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (node.kind === 143 || node.kind === 144) { + else if (node.kind === 145 || node.kind === 146) { var accessors = ts.getAllAccessorDeclarations(node.parent.members, node); if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name); @@ -21342,38 +21793,38 @@ var ts; } function checkGrammarModifiers(node) { switch (node.kind) { - case 143: + case 145: + case 146: case 144: - case 142: - case 139: - case 138: case 141: case 140: - case 147: - case 216: - case 220: - case 219: - case 226: - case 225: - case 136: + case 143: + case 142: + case 149: + case 218: + case 222: + case 221: + case 228: + case 227: + case 138: break; - case 211: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 116) && - node.parent.kind !== 217 && node.parent.kind !== 246) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); - } - break; - case 212: case 213: - case 191: - case 214: - if (node.modifiers && node.parent.kind !== 217 && node.parent.kind !== 246) { + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 118) && + node.parent.kind !== 219 && node.parent.kind !== 248) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; + case 214: case 215: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 72) && - node.parent.kind !== 217 && node.parent.kind !== 246) { + case 193: + case 216: + if (node.modifiers && node.parent.kind !== 219 && node.parent.kind !== 248) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; + case 217: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 74) && + node.parent.kind !== 219 && node.parent.kind !== 248) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; @@ -21388,14 +21839,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { + case 112: + case 111: case 110: - case 109: - case 108: var text = void 0; - if (modifier.kind === 110) { + if (modifier.kind === 112) { text = "public"; } - else if (modifier.kind === 109) { + else if (modifier.kind === 111) { text = "protected"; lastProtected = modifier; } @@ -21412,11 +21863,11 @@ var ts; else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); } - else if (node.parent.kind === 217 || node.parent.kind === 246) { + else if (node.parent.kind === 219 || node.parent.kind === 248) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); } else if (flags & 256) { - if (modifier.kind === 108) { + if (modifier.kind === 110) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract"); } else { @@ -21425,17 +21876,17 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 111: + case 113: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } - else if (node.parent.kind === 217 || node.parent.kind === 246) { + else if (node.parent.kind === 219 || node.parent.kind === 248) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } else if (flags & 256) { @@ -21444,7 +21895,7 @@ var ts; flags |= 128; lastStatic = modifier; break; - case 80: + case 82: if (flags & 1) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); } @@ -21457,42 +21908,42 @@ var ts; else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= 1; break; - case 120: + case 122: if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } - else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 217) { + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 219) { return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= 2; lastDeclare = modifier; break; - case 113: + case 115: if (flags & 256) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract"); } - if (node.kind !== 212) { - if (node.kind !== 141) { + if (node.kind !== 214) { + if (node.kind !== 143) { return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration); } - if (!(node.parent.kind === 212 && node.parent.flags & 256)) { + if (!(node.parent.kind === 214 && node.parent.flags & 256)) { return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); } if (flags & 128) { @@ -21504,14 +21955,14 @@ var ts; } flags |= 256; break; - case 116: + case 118: if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async"); } else if (flags & 2 || ts.isInAmbientContext(node.parent)) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); } flags |= 512; @@ -21519,7 +21970,7 @@ var ts; break; } } - if (node.kind === 142) { + if (node.kind === 144) { if (flags & 128) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); } @@ -21537,10 +21988,10 @@ var ts; } return; } - else if ((node.kind === 220 || node.kind === 219) && flags & 2) { + else if ((node.kind === 222 || node.kind === 221) && flags & 2) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 136 && (flags & 112) && ts.isBindingPattern(node.name)) { + else if (node.kind === 138 && (flags & 112) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } if (flags & 512) { @@ -21552,10 +22003,10 @@ var ts; return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher); } switch (node.kind) { - case 141: - case 211: - case 171: - case 172: + case 143: + case 213: + case 173: + case 174: if (!node.asteriskToken) { return false; } @@ -21620,7 +22071,7 @@ var ts; checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } function checkGrammarArrowFunction(node, file) { - if (node.kind === 172) { + if (node.kind === 174) { var arrowFunction = node; var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line; var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line; @@ -21655,7 +22106,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 128 && parameter.type.kind !== 126) { + if (parameter.type.kind !== 130 && parameter.type.kind !== 128) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -21687,7 +22138,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var _i = 0; _i < args.length; _i++) { var arg = args[_i]; - if (arg.kind === 185) { + if (arg.kind === 187) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -21714,7 +22165,7 @@ var ts; if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81) { + if (heritageClause.token === 83) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } @@ -21727,7 +22178,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104); + ts.Debug.assert(heritageClause.token === 106); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -21742,14 +22193,14 @@ var ts; if (node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81) { + if (heritageClause.token === 83) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104); + ts.Debug.assert(heritageClause.token === 106); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -21758,19 +22209,19 @@ var ts; return false; } function checkGrammarComputedPropertyName(node) { - if (node.kind !== 134) { + if (node.kind !== 136) { return false; } var computedPropertyName = node; - if (computedPropertyName.expression.kind === 179 && computedPropertyName.expression.operatorToken.kind === 24) { + if (computedPropertyName.expression.kind === 181 && computedPropertyName.expression.operatorToken.kind === 24) { return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - ts.Debug.assert(node.kind === 211 || - node.kind === 171 || - node.kind === 141); + ts.Debug.assert(node.kind === 213 || + node.kind === 173 || + node.kind === 143); if (ts.isInAmbientContext(node)) { return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); } @@ -21787,7 +22238,7 @@ var ts; return grammarErrorOnNode(questionToken, message); } } - function checkGrammarObjectLiteralExpression(node) { + function checkGrammarObjectLiteralExpression(node, inDestructuring) { var seen = {}; var Property = 1; var GetAccessor = 2; @@ -21796,26 +22247,29 @@ var ts; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; var name_16 = prop.name; - if (prop.kind === 185 || - name_16.kind === 134) { + if (prop.kind === 187 || + name_16.kind === 136) { checkGrammarComputedPropertyName(name_16); continue; } + if (prop.kind === 246 && !inDestructuring && prop.objectAssignmentInitializer) { + return grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment); + } var currentKind = void 0; - if (prop.kind === 243 || prop.kind === 244) { + if (prop.kind === 245 || prop.kind === 246) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); if (name_16.kind === 8) { checkGrammarNumericLiteral(name_16); } currentKind = Property; } - else if (prop.kind === 141) { + else if (prop.kind === 143) { currentKind = Property; } - else if (prop.kind === 143) { + else if (prop.kind === 145) { currentKind = GetAccessor; } - else if (prop.kind === 144) { + else if (prop.kind === 146) { currentKind = SetAccesor; } else { @@ -21847,7 +22301,7 @@ var ts; var seen = {}; for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) { var attr = _a[_i]; - if (attr.kind === 237) { + if (attr.kind === 239) { continue; } var jsxAttr = attr; @@ -21859,7 +22313,7 @@ var ts; return grammarErrorOnNode(name_17, ts.Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name); } var initializer = jsxAttr.initializer; - if (initializer && initializer.kind === 238 && !initializer.expression) { + if (initializer && initializer.kind === 240 && !initializer.expression) { return grammarErrorOnNode(jsxAttr.initializer, ts.Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression); } } @@ -21868,24 +22322,24 @@ var ts; if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) { return true; } - if (forInOrOfStatement.initializer.kind === 210) { + if (forInOrOfStatement.initializer.kind === 212) { var variableList = forInOrOfStatement.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { - var diagnostic = forInOrOfStatement.kind === 198 + var diagnostic = forInOrOfStatement.kind === 200 ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic); } var firstDeclaration = variableList.declarations[0]; if (firstDeclaration.initializer) { - var diagnostic = forInOrOfStatement.kind === 198 + var diagnostic = forInOrOfStatement.kind === 200 ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; return grammarErrorOnNode(firstDeclaration.name, diagnostic); } if (firstDeclaration.type) { - var diagnostic = forInOrOfStatement.kind === 198 + var diagnostic = forInOrOfStatement.kind === 200 ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; return grammarErrorOnNode(firstDeclaration, diagnostic); @@ -21908,10 +22362,10 @@ var ts; else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } - else if (kind === 143 && accessor.parameters.length) { + else if (kind === 145 && accessor.parameters.length) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); } - else if (kind === 144) { + else if (kind === 146) { if (accessor.type) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); } @@ -21936,7 +22390,7 @@ var ts; } } function checkGrammarForNonSymbolComputedProperty(node, message) { - if (node.kind === 134 && !ts.isWellKnownSymbolSyntactically(node.expression)) { + if (node.kind === 136 && !ts.isWellKnownSymbolSyntactically(node.expression)) { return grammarErrorOnNode(node, message); } } @@ -21946,7 +22400,7 @@ var ts; checkGrammarForGenerator(node)) { return true; } - if (node.parent.kind === 163) { + if (node.parent.kind === 165) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -21965,22 +22419,22 @@ var ts; return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol); } } - else if (node.parent.kind === 213) { + else if (node.parent.kind === 215) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol); } - else if (node.parent.kind === 153) { + else if (node.parent.kind === 155) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol); } } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { + case 199: + case 200: + case 201: case 197: case 198: - case 199: - case 195: - case 196: return true; - case 205: + case 207: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -21992,9 +22446,9 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 205: + case 207: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 200 + var isMisplacedContinueLabel = node.kind === 202 && !isIterationStatement(current.statement, true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); @@ -22002,8 +22456,8 @@ var ts; return false; } break; - case 204: - if (node.kind === 201 && !node.label) { + case 206: + if (node.kind === 203 && !node.label) { return false; } break; @@ -22016,13 +22470,13 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 201 + var message = node.kind === 203 ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 201 + var message = node.kind === 203 ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); @@ -22034,7 +22488,7 @@ var ts; if (node !== ts.lastOrUndefined(elements)) { return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); } - if (node.name.kind === 160 || node.name.kind === 159) { + if (node.name.kind === 162 || node.name.kind === 161) { return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); } if (node.initializer) { @@ -22043,7 +22497,7 @@ var ts; } } function checkGrammarVariableDeclaration(node) { - if (node.parent.parent.kind !== 198 && node.parent.parent.kind !== 199) { + if (node.parent.parent.kind !== 200 && node.parent.parent.kind !== 201) { if (ts.isInAmbientContext(node)) { if (node.initializer) { var equalsTokenLength = "=".length; @@ -22063,7 +22517,7 @@ var ts; return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name); } function checkGrammarNameInLetOrConstDeclarations(name) { - if (name.kind === 67) { + if (name.kind === 69) { if (name.text === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } @@ -22072,7 +22526,7 @@ var ts; var elements = name.elements; for (var _i = 0; _i < elements.length; _i++) { var element = elements[_i]; - if (element.kind !== 185) { + if (element.kind !== 187) { checkGrammarNameInLetOrConstDeclarations(element.name); } } @@ -22089,15 +22543,15 @@ var ts; } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 194: - case 195: case 196: - case 203: case 197: case 198: - case 199: - return false; case 205: + case 199: + case 200: + case 201: + return false; + case 207: return allowLetAndConstDeclarations(parent.parent); } return true; @@ -22113,7 +22567,7 @@ var ts; } } function isIntegerLiteral(expression) { - if (expression.kind === 177) { + if (expression.kind === 179) { var unaryExpression = expression; if (unaryExpression.operator === 35 || unaryExpression.operator === 36) { expression = unaryExpression.operand; @@ -22124,32 +22578,6 @@ var ts; } return false; } - function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 32768) !== 0; - var hasError = false; - if (!enumIsConst) { - var inConstantEnumMemberSection = true; - var inAmbientContext = ts.isInAmbientContext(enumDecl); - for (var _i = 0, _a = enumDecl.members; _i < _a.length; _i++) { - var node = _a[_i]; - if (node.name.kind === 134) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); - } - else if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer)) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; - } - } - else if (node.initializer) { - inConstantEnumMemberSection = isIntegerLiteral(node.initializer); - } - else if (!inConstantEnumMemberSection) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; - } - } - } - return hasError; - } function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } @@ -22175,7 +22603,7 @@ var ts; } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 && + return node.kind === 69 && (node.text === "eval" || node.text === "arguments"); } function checkGrammarConstructorTypeParameters(node) { @@ -22195,12 +22623,12 @@ var ts; return true; } } - else if (node.parent.kind === 213) { + else if (node.parent.kind === 215) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } } - else if (node.parent.kind === 153) { + else if (node.parent.kind === 155) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } @@ -22210,11 +22638,11 @@ var ts; } } function checkGrammarTopLevelElementForRequiredDeclareModifier(node) { - if (node.kind === 213 || - node.kind === 220 || - node.kind === 219 || - node.kind === 226 || - node.kind === 225 || + if (node.kind === 215 || + node.kind === 222 || + node.kind === 221 || + node.kind === 228 || + node.kind === 227 || (node.flags & 2) || (node.flags & (1 | 1024))) { return false; @@ -22224,7 +22652,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var decl = _a[_i]; - if (ts.isDeclaration(decl) || decl.kind === 191) { + if (ts.isDeclaration(decl) || decl.kind === 193) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -22243,7 +22671,7 @@ var ts; if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } - if (node.parent.kind === 190 || node.parent.kind === 217 || node.parent.kind === 246) { + if (node.parent.kind === 192 || node.parent.kind === 219 || node.parent.kind === 248) { var links_1 = getNodeLinks(node.parent); if (!links_1.hasReportedStatementInAmbientContext) { return links_1.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); @@ -22290,6 +22718,7 @@ var ts; var enclosingDeclaration; var currentSourceFile; var reportedDeclarationError = false; + var errorNameNode; var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments; var emit = compilerOptions.stripInternal ? stripInternal : emitNode; var moduleElementDeclarationEmitInfo = []; @@ -22315,7 +22744,7 @@ var ts; var oldWriter = writer; ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) { if (aliasEmitInfo.isVisible) { - ts.Debug.assert(aliasEmitInfo.node.kind === 220); + ts.Debug.assert(aliasEmitInfo.node.kind === 222); createAndSetNewTextWriterWithSymbolWriter(); ts.Debug.assert(aliasEmitInfo.indent === 0); writeImportDeclaration(aliasEmitInfo.node); @@ -22366,6 +22795,7 @@ var ts; function createAndSetNewTextWriterWithSymbolWriter() { var writer = ts.createTextWriter(newLine); writer.trackSymbol = trackSymbol; + writer.reportInaccessibleThisError = reportInaccessibleThisError; writer.writeKeyword = writer.write; writer.writeOperator = writer.write; writer.writePunctuation = writer.write; @@ -22388,10 +22818,10 @@ var ts; var oldWriter = writer; ts.forEach(nodes, function (declaration) { var nodeToCheck; - if (declaration.kind === 209) { + if (declaration.kind === 211) { nodeToCheck = declaration.parent.parent; } - else if (declaration.kind === 223 || declaration.kind === 224 || declaration.kind === 221) { + else if (declaration.kind === 225 || declaration.kind === 226 || declaration.kind === 223) { ts.Debug.fail("We should be getting ImportDeclaration instead to write"); } else { @@ -22402,7 +22832,7 @@ var ts; moduleElementEmitInfo = ts.forEach(asynchronousSubModuleDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; }); } if (moduleElementEmitInfo) { - if (moduleElementEmitInfo.node.kind === 220) { + if (moduleElementEmitInfo.node.kind === 222) { moduleElementEmitInfo.isVisible = true; } else { @@ -22410,12 +22840,12 @@ var ts; for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { increaseIndent(); } - if (nodeToCheck.kind === 216) { + if (nodeToCheck.kind === 218) { ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); asynchronousSubModuleDeclarationEmitInfo = []; } writeModuleElement(nodeToCheck); - if (nodeToCheck.kind === 216) { + if (nodeToCheck.kind === 218) { moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; asynchronousSubModuleDeclarationEmitInfo = undefined; } @@ -22447,6 +22877,11 @@ var ts; function trackSymbol(symbol, enclosingDeclaration, meaning) { handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); } + function reportInaccessibleThisError() { + if (errorNameNode) { + diagnostics.push(ts.createDiagnosticForNode(errorNameNode, ts.Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, ts.declarationNameToString(errorNameNode))); + } + } function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; write(": "); @@ -22454,7 +22889,9 @@ var ts; emitType(type); } else { + errorNameNode = declaration.name; resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2, writer); + errorNameNode = undefined; } } function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { @@ -22464,7 +22901,9 @@ var ts; emitType(signature.type); } else { + errorNameNode = signature.name; resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2, writer); + errorNameNode = undefined; } } function emitLines(nodes) { @@ -22502,62 +22941,63 @@ var ts; } function emitType(type) { switch (type.kind) { - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: - case 101: + case 120: + case 131: + case 103: + case 97: case 9: return writeTextOfNode(currentSourceFile, type); - case 186: + case 188: return emitExpressionWithTypeArguments(type); - case 149: - return emitTypeReference(type); - case 152: - return emitTypeQuery(type); - case 154: - return emitArrayType(type); - case 155: - return emitTupleType(type); - case 156: - return emitUnionType(type); - case 157: - return emitIntersectionType(type); - case 158: - return emitParenType(type); - case 150: case 151: - return emitSignatureDeclarationWithJsDocComments(type); + return emitTypeReference(type); + case 154: + return emitTypeQuery(type); + case 156: + return emitArrayType(type); + case 157: + return emitTupleType(type); + case 158: + return emitUnionType(type); + case 159: + return emitIntersectionType(type); + case 160: + return emitParenType(type); + case 152: case 153: + return emitSignatureDeclarationWithJsDocComments(type); + case 155: return emitTypeLiteral(type); - case 67: + case 69: return emitEntityName(type); - case 133: + case 135: return emitEntityName(type); - case 148: + case 150: return emitTypePredicate(type); } function writeEntityName(entityName) { - if (entityName.kind === 67) { + if (entityName.kind === 69) { writeTextOfNode(currentSourceFile, entityName); } else { - var left = entityName.kind === 133 ? entityName.left : entityName.expression; - var right = entityName.kind === 133 ? entityName.right : entityName.name; + var left = entityName.kind === 135 ? entityName.left : entityName.expression; + var right = entityName.kind === 135 ? entityName.right : entityName.name; writeEntityName(left); write("."); writeTextOfNode(currentSourceFile, right); } } function emitEntityName(entityName) { - var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 219 ? entityName.parent : enclosingDeclaration); + var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 221 ? entityName.parent : enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); } function emitExpressionWithTypeArguments(node) { if (ts.isSupportedExpressionWithTypeArguments(node)) { - ts.Debug.assert(node.expression.kind === 67 || node.expression.kind === 164); + ts.Debug.assert(node.expression.kind === 69 || node.expression.kind === 166); emitEntityName(node.expression); if (node.typeArguments) { write("<"); @@ -22633,7 +23073,7 @@ var ts; } } function emitExportAssignment(node) { - if (node.expression.kind === 67) { + if (node.expression.kind === 69) { write(node.isExportEquals ? "export = " : "export default "); writeTextOfNode(currentSourceFile, node.expression); } @@ -22651,7 +23091,7 @@ var ts; } write(";"); writeLine(); - if (node.expression.kind === 67) { + if (node.expression.kind === 69) { var nodes = resolver.collectLinkedAliases(node.expression); writeAsynchronousModuleElements(nodes); } @@ -22669,10 +23109,10 @@ var ts; if (isModuleElementVisible) { writeModuleElement(node); } - else if (node.kind === 219 || - (node.parent.kind === 246 && ts.isExternalModule(currentSourceFile))) { + else if (node.kind === 221 || + (node.parent.kind === 248 && ts.isExternalModule(currentSourceFile))) { var isVisible; - if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 246) { + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 248) { asynchronousSubModuleDeclarationEmitInfo.push({ node: node, outputPos: writer.getTextPos(), @@ -22681,7 +23121,7 @@ var ts; }); } else { - if (node.kind === 220) { + if (node.kind === 222) { var importDeclaration = node; if (importDeclaration.importClause) { isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || @@ -22699,23 +23139,23 @@ var ts; } function writeModuleElement(node) { switch (node.kind) { - case 211: - return writeFunctionDeclaration(node); - case 191: - return writeVariableStatement(node); case 213: - return writeInterfaceDeclaration(node); - case 212: - return writeClassDeclaration(node); - case 214: - return writeTypeAliasDeclaration(node); + return writeFunctionDeclaration(node); + case 193: + return writeVariableStatement(node); case 215: - return writeEnumDeclaration(node); + return writeInterfaceDeclaration(node); + case 214: + return writeClassDeclaration(node); case 216: + return writeTypeAliasDeclaration(node); + case 217: + return writeEnumDeclaration(node); + case 218: return writeModuleDeclaration(node); - case 219: + case 221: return writeImportEqualsDeclaration(node); - case 220: + case 222: return writeImportDeclaration(node); default: ts.Debug.fail("Unknown symbol kind"); @@ -22729,7 +23169,7 @@ var ts; if (node.flags & 1024) { write("default "); } - else if (node.kind !== 213) { + else if (node.kind !== 215) { write("declare "); } } @@ -22776,7 +23216,7 @@ var ts; } function isVisibleNamedBinding(namedBindings) { if (namedBindings) { - if (namedBindings.kind === 222) { + if (namedBindings.kind === 224) { return resolver.isDeclarationVisible(namedBindings); } else { @@ -22802,7 +23242,7 @@ var ts; if (currentWriterPos !== writer.getTextPos()) { write(", "); } - if (node.importClause.namedBindings.kind === 222) { + if (node.importClause.namedBindings.kind === 224) { write("* as "); writeTextOfNode(currentSourceFile, node.importClause.namedBindings.name); } @@ -22858,7 +23298,7 @@ var ts; write("module "); } writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 217) { + while (node.body.kind !== 219) { node = node.body; write("."); writeTextOfNode(currentSourceFile, node.name); @@ -22923,7 +23363,7 @@ var ts; writeLine(); } function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 141 && (node.parent.flags & 32); + return node.parent.kind === 143 && (node.parent.flags & 32); } function emitTypeParameters(typeParameters) { function emitTypeParameter(node) { @@ -22933,15 +23373,15 @@ var ts; writeTextOfNode(currentSourceFile, node.name); if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); - if (node.parent.kind === 150 || - node.parent.kind === 151 || - (node.parent.parent && node.parent.parent.kind === 153)) { - ts.Debug.assert(node.parent.kind === 141 || - node.parent.kind === 140 || - node.parent.kind === 150 || - node.parent.kind === 151 || - node.parent.kind === 145 || - node.parent.kind === 146); + if (node.parent.kind === 152 || + node.parent.kind === 153 || + (node.parent.parent && node.parent.parent.kind === 155)) { + ts.Debug.assert(node.parent.kind === 143 || + node.parent.kind === 142 || + node.parent.kind === 152 || + node.parent.kind === 153 || + node.parent.kind === 147 || + node.parent.kind === 148); emitType(node.constraint); } else { @@ -22951,31 +23391,31 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 212: + case 214: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 213: + case 215: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; - case 146: + case 148: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 145: + case 147: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 141: - case 140: + case 143: + case 142: if (node.parent.flags & 128) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212) { + else if (node.parent.parent.kind === 214) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 211: + case 213: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -23003,12 +23443,12 @@ var ts; if (ts.isSupportedExpressionWithTypeArguments(node)) { emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); } - else if (!isImplementsList && node.expression.kind === 91) { + else if (!isImplementsList && node.expression.kind === 93) { write("null"); } function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.parent.kind === 212) { + if (node.parent.parent.kind === 214) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; @@ -23088,16 +23528,16 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 209 || resolver.isDeclarationVisible(node)) { + if (node.kind !== 211 || resolver.isDeclarationVisible(node)) { if (ts.isBindingPattern(node.name)) { emitBindingPattern(node.name); } else { writeTextOfNode(currentSourceFile, node.name); - if ((node.kind === 139 || node.kind === 138) && ts.hasQuestionToken(node)) { + if ((node.kind === 141 || node.kind === 140) && ts.hasQuestionToken(node)) { write("?"); } - if ((node.kind === 139 || node.kind === 138) && node.parent.kind === 153) { + if ((node.kind === 141 || node.kind === 140) && node.parent.kind === 155) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & 32)) { @@ -23106,14 +23546,14 @@ var ts; } } function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { - if (node.kind === 209) { + if (node.kind === 211) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } - else if (node.kind === 139 || node.kind === 138) { + else if (node.kind === 141 || node.kind === 140) { if (node.flags & 128) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? @@ -23121,7 +23561,7 @@ var ts; ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -23147,7 +23587,7 @@ var ts; var elements = []; for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.kind !== 185) { + if (element.kind !== 187) { elements.push(element); } } @@ -23213,7 +23653,7 @@ var ts; accessorWithTypeAnnotation = node; var type = getTypeAnnotationFromAccessor(node); if (!type) { - var anotherAccessor = node.kind === 143 ? accessors.setAccessor : accessors.getAccessor; + var anotherAccessor = node.kind === 145 ? accessors.setAccessor : accessors.getAccessor; type = getTypeAnnotationFromAccessor(anotherAccessor); if (type) { accessorWithTypeAnnotation = anotherAccessor; @@ -23226,7 +23666,7 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 143 + return accessor.kind === 145 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type @@ -23235,7 +23675,7 @@ var ts; } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 144) { + if (accessorWithTypeAnnotation.kind === 146) { if (accessorWithTypeAnnotation.parent.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : @@ -23281,17 +23721,17 @@ var ts; } if (!resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); - if (node.kind === 211) { + if (node.kind === 213) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === 141) { + else if (node.kind === 143) { emitClassMemberDeclarationFlags(node); } - if (node.kind === 211) { + if (node.kind === 213) { write("function "); writeTextOfNode(currentSourceFile, node.name); } - else if (node.kind === 142) { + else if (node.kind === 144) { write("constructor"); } else { @@ -23308,11 +23748,11 @@ var ts; emitSignatureDeclaration(node); } function emitSignatureDeclaration(node) { - if (node.kind === 146 || node.kind === 151) { + if (node.kind === 148 || node.kind === 153) { write("new "); } emitTypeParameters(node.typeParameters); - if (node.kind === 147) { + if (node.kind === 149) { write("["); } else { @@ -23321,20 +23761,20 @@ var ts; var prevEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = node; emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 147) { + if (node.kind === 149) { write("]"); } else { write(")"); } - var isFunctionTypeOrConstructorType = node.kind === 150 || node.kind === 151; - if (isFunctionTypeOrConstructorType || node.parent.kind === 153) { + var isFunctionTypeOrConstructorType = node.kind === 152 || node.kind === 153; + if (isFunctionTypeOrConstructorType || node.parent.kind === 155) { if (node.type) { write(isFunctionTypeOrConstructorType ? " => " : ": "); emitType(node.type); } } - else if (node.kind !== 142 && !(node.flags & 32)) { + else if (node.kind !== 144 && !(node.flags & 32)) { writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); } enclosingDeclaration = prevEnclosingDeclaration; @@ -23345,23 +23785,23 @@ var ts; function getReturnTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.kind) { - case 146: + case 148: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 145: + case 147: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 147: + case 149: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 141: - case 140: + case 143: + case 142: if (node.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? @@ -23369,7 +23809,7 @@ var ts; ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -23382,7 +23822,7 @@ var ts; ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 211: + case 213: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -23414,9 +23854,9 @@ var ts; write("?"); } decreaseIndent(); - if (node.parent.kind === 150 || - node.parent.kind === 151 || - node.parent.parent.kind === 153) { + if (node.parent.kind === 152 || + node.parent.kind === 153 || + node.parent.parent.kind === 155) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.parent.flags & 32)) { @@ -23432,22 +23872,22 @@ var ts; } function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { switch (node.parent.kind) { - case 142: + case 144: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - case 146: + case 148: return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - case 145: + case 147: return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - case 141: - case 140: + case 143: + case 142: if (node.parent.flags & 128) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? @@ -23455,7 +23895,7 @@ var ts; ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212) { + else if (node.parent.parent.kind === 214) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -23467,7 +23907,7 @@ var ts; ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } - case 211: + case 213: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -23478,12 +23918,12 @@ var ts; } } function emitBindingPattern(bindingPattern) { - if (bindingPattern.kind === 159) { + if (bindingPattern.kind === 161) { write("{"); emitCommaList(bindingPattern.elements, emitBindingElement); write("}"); } - else if (bindingPattern.kind === 160) { + else if (bindingPattern.kind === 162) { write("["); var elements = bindingPattern.elements; emitCommaList(elements, emitBindingElement); @@ -23502,10 +23942,10 @@ var ts; typeName: bindingElement.name } : undefined; } - if (bindingElement.kind === 185) { + if (bindingElement.kind === 187) { write(" "); } - else if (bindingElement.kind === 161) { + else if (bindingElement.kind === 163) { if (bindingElement.propertyName) { writeTextOfNode(currentSourceFile, bindingElement.propertyName); write(": "); @@ -23515,7 +23955,7 @@ var ts; emitBindingPattern(bindingElement.name); } else { - ts.Debug.assert(bindingElement.name.kind === 67); + ts.Debug.assert(bindingElement.name.kind === 69); if (bindingElement.dotDotDotToken) { write("..."); } @@ -23527,39 +23967,39 @@ var ts; } function emitNode(node) { switch (node.kind) { - case 211: - case 216: - case 219: case 213: - case 212: - case 214: + case 218: + case 221: case 215: + case 214: + case 216: + case 217: return emitModuleElement(node, isModuleElementVisible(node)); - case 191: + case 193: return emitModuleElement(node, isVariableStatementVisible(node)); - case 220: + case 222: return emitModuleElement(node, !node.importClause); - case 226: + case 228: return emitExportDeclaration(node); + case 144: + case 143: case 142: + return writeFunctionDeclaration(node); + case 148: + case 147: + case 149: + return emitSignatureDeclarationWithJsDocComments(node); + case 145: + case 146: + return emitAccessorDeclaration(node); case 141: case 140: - return writeFunctionDeclaration(node); - case 146: - case 145: - case 147: - return emitSignatureDeclarationWithJsDocComments(node); - case 143: - case 144: - return emitAccessorDeclaration(node); - case 139: - case 138: return emitPropertyDeclaration(node); - case 245: + case 247: return emitEnumMemberDeclaration(node); - case 225: + case 227: return emitExportAssignment(node); - case 246: + case 248: return emitSourceFile(node); } } @@ -23602,5471 +24042,6 @@ var ts; return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; - function emitFiles(resolver, host, targetSourceFile) { - var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; - var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; - var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; - var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; - var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; - var compilerOptions = host.getCompilerOptions(); - var languageVersion = compilerOptions.target || 0; - var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; - var diagnostics = []; - var newLine = host.getNewLine(); - var jsxDesugaring = host.getCompilerOptions().jsx !== 1; - var shouldEmitJsx = function (s) { return (s.languageVariant === 1 && !jsxDesugaring); }; - if (targetSourceFile === undefined) { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, sourceFile); - } - }); - if (compilerOptions.outFile || compilerOptions.out) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - else { - if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, targetSourceFile); - } - else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); - return { - emitSkipped: false, - diagnostics: diagnostics, - sourceMaps: sourceMapDataList - }; - function isNodeDescendentOf(node, ancestor) { - while (node) { - if (node === ancestor) - return true; - node = node.parent; - } - return false; - } - function isUniqueLocalName(name, container) { - for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && ts.hasProperty(node.locals, name)) { - if (node.locals[name].flags & (107455 | 1048576 | 8388608)) { - return false; - } - } - } - return true; - } - function emitJavaScript(jsFilePath, root) { - var writer = ts.createTextWriter(newLine); - var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; - var currentSourceFile; - var exportFunctionForFile; - var generatedNameSet = {}; - var nodeToGeneratedName = []; - var computedPropertyNamesToGeneratedNames; - var extendsEmitted = false; - var decorateEmitted = false; - var paramEmitted = false; - var awaiterEmitted = false; - var tempFlags = 0; - var tempVariables; - var tempParameters; - var externalImports; - var exportSpecifiers; - var exportEquals; - var hasExportStars; - var writeEmittedFiles = writeJavaScriptFile; - var detachedCommentsInfo; - var writeComment = ts.writeCommentRange; - var emit = emitNodeWithCommentsAndWithoutSourcemap; - var emitStart = function (node) { }; - var emitEnd = function (node) { }; - var emitToken = emitTokenText; - var scopeEmitStart = function (scopeDeclaration, scopeName) { }; - var scopeEmitEnd = function () { }; - var sourceMapData; - var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; - if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { - initializeEmitterWithSourceMaps(); - } - if (root) { - emitSourceFile(root); - } - else { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - emitSourceFile(sourceFile); - } - }); - } - writeLine(); - writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); - return; - function emitSourceFile(sourceFile) { - currentSourceFile = sourceFile; - exportFunctionForFile = undefined; - emit(sourceFile); - } - function isUniqueName(name) { - return !resolver.hasGlobalName(name) && - !ts.hasProperty(currentSourceFile.identifiers, name) && - !ts.hasProperty(generatedNameSet, name); - } - function makeTempVariableName(flags) { - if (flags && !(tempFlags & flags)) { - var name_19 = flags === 268435456 ? "_i" : "_n"; - if (isUniqueName(name_19)) { - tempFlags |= flags; - return name_19; - } - } - while (true) { - var count = tempFlags & 268435455; - tempFlags++; - if (count !== 8 && count !== 13) { - var name_20 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_20)) { - return name_20; - } - } - } - } - function makeUniqueName(baseName) { - if (baseName.charCodeAt(baseName.length - 1) !== 95) { - baseName += "_"; - } - var i = 1; - while (true) { - var generatedName = baseName + i; - if (isUniqueName(generatedName)) { - return generatedNameSet[generatedName] = generatedName; - } - i++; - } - } - function generateNameForModuleOrEnum(node) { - var name = node.name.text; - return isUniqueLocalName(name, node) ? name : makeUniqueName(name); - } - function generateNameForImportOrExportDeclaration(node) { - var expr = ts.getExternalModuleName(node); - var baseName = expr.kind === 9 ? - ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; - return makeUniqueName(baseName); - } - function generateNameForExportDefault() { - return makeUniqueName("default"); - } - function generateNameForClassExpression() { - return makeUniqueName("class"); - } - function generateNameForNode(node) { - switch (node.kind) { - case 67: - return makeUniqueName(node.text); - case 216: - case 215: - return generateNameForModuleOrEnum(node); - case 220: - case 226: - return generateNameForImportOrExportDeclaration(node); - case 211: - case 212: - case 225: - return generateNameForExportDefault(); - case 184: - return generateNameForClassExpression(); - } - } - function getGeneratedNameForNode(node) { - var id = ts.getNodeId(node); - return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); - } - function initializeEmitterWithSourceMaps() { - var sourceMapDir; - var sourceMapSourceIndex = -1; - var sourceMapNameIndexMap = {}; - var sourceMapNameIndices = []; - function getSourceMapNameIndex() { - return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; - } - var lastRecordedSourceMapSpan; - var lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; - var lastEncodedNameIndex = 0; - function encodeLastRecordedSourceMapSpan() { - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { - return; - } - var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; - if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { - if (sourceMapData.sourceMapMappings) { - sourceMapData.sourceMapMappings += ","; - } - } - else { - for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { - sourceMapData.sourceMapMappings += ";"; - } - prevEncodedEmittedColumn = 1; - } - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); - if (lastRecordedSourceMapSpan.nameIndex >= 0) { - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); - lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; - } - lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; - sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); - function base64VLQFormatEncode(inValue) { - function base64FormatEncode(inValue) { - if (inValue < 64) { - return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); - } - throw TypeError(inValue + ": not a 64 based value"); - } - if (inValue < 0) { - inValue = ((-inValue) << 1) + 1; - } - else { - inValue = inValue << 1; - } - var encodedStr = ""; - do { - var currentDigit = inValue & 31; - inValue = inValue >> 5; - if (inValue > 0) { - currentDigit = currentDigit | 32; - } - encodedStr = encodedStr + base64FormatEncode(currentDigit); - } while (inValue > 0); - return encodedStr; - } - } - function recordSourceMapSpan(pos) { - var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); - sourceLinePos.line++; - sourceLinePos.character++; - var emittedLine = writer.getLine(); - var emittedColumn = writer.getColumn(); - if (!lastRecordedSourceMapSpan || - lastRecordedSourceMapSpan.emittedLine !== emittedLine || - lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || - (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { - encodeLastRecordedSourceMapSpan(); - lastRecordedSourceMapSpan = { - emittedLine: emittedLine, - emittedColumn: emittedColumn, - sourceLine: sourceLinePos.line, - sourceColumn: sourceLinePos.character, - nameIndex: getSourceMapNameIndex(), - sourceIndex: sourceMapSourceIndex - }; - } - else { - lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; - lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; - lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; - } - } - function recordEmitNodeStartSpan(node) { - recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); - } - function recordEmitNodeEndSpan(node) { - recordSourceMapSpan(node.end); - } - function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); - var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; - } - function recordNewSourceFileStart(node) { - var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, true)); - sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; - sourceMapData.inputSourceFileNames.push(node.fileName); - if (compilerOptions.inlineSources) { - if (!sourceMapData.sourceMapSourcesContent) { - sourceMapData.sourceMapSourcesContent = []; - } - sourceMapData.sourceMapSourcesContent.push(node.text); - } - } - function recordScopeNameOfNode(node, scopeName) { - function recordScopeNameIndex(scopeNameIndex) { - sourceMapNameIndices.push(scopeNameIndex); - } - function recordScopeNameStart(scopeName) { - var scopeNameIndex = -1; - if (scopeName) { - var parentIndex = getSourceMapNameIndex(); - if (parentIndex !== -1) { - var name_21 = node.name; - if (!name_21 || name_21.kind !== 134) { - scopeName = "." + scopeName; - } - scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; - } - scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); - if (scopeNameIndex === undefined) { - scopeNameIndex = sourceMapData.sourceMapNames.length; - sourceMapData.sourceMapNames.push(scopeName); - sourceMapNameIndexMap[scopeName] = scopeNameIndex; - } - } - recordScopeNameIndex(scopeNameIndex); - } - if (scopeName) { - recordScopeNameStart(scopeName); - } - else if (node.kind === 211 || - node.kind === 171 || - node.kind === 141 || - node.kind === 140 || - node.kind === 143 || - node.kind === 144 || - node.kind === 216 || - node.kind === 212 || - node.kind === 215) { - if (node.name) { - var name_22 = node.name; - scopeName = name_22.kind === 134 - ? ts.getTextOfNode(name_22) - : node.name.text; - } - recordScopeNameStart(scopeName); - } - else { - recordScopeNameIndex(getSourceMapNameIndex()); - } - } - function recordScopeNameEnd() { - sourceMapNameIndices.pop(); - } - ; - function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { - recordSourceMapSpan(comment.pos); - ts.writeCommentRange(currentSourceFile, writer, comment, newLine); - recordSourceMapSpan(comment.end); - } - function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { - if (typeof JSON !== "undefined") { - var map_1 = { - version: version, - file: file, - sourceRoot: sourceRoot, - sources: sources, - names: names, - mappings: mappings - }; - if (sourcesContent !== undefined) { - map_1.sourcesContent = sourcesContent; - } - return JSON.stringify(map_1); - } - return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; - function serializeStringArray(list) { - var output = ""; - for (var i = 0, n = list.length; i < n; i++) { - if (i) { - output += ","; - } - output += "\"" + ts.escapeString(list[i]) + "\""; - } - return output; - } - } - function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { - encodeLastRecordedSourceMapSpan(); - var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); - sourceMapDataList.push(sourceMapData); - var sourceMapUrl; - if (compilerOptions.inlineSourceMap) { - var base64SourceMapText = ts.convertToBase64(sourceMapText); - sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; - } - else { - ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, false); - sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; - } - writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); - } - var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); - sourceMapData = { - sourceMapFilePath: jsFilePath + ".map", - jsSourceMappingURL: sourceMapJsFile + ".map", - sourceMapFile: sourceMapJsFile, - sourceMapSourceRoot: compilerOptions.sourceRoot || "", - sourceMapSources: [], - inputSourceFileNames: [], - sourceMapNames: [], - sourceMapMappings: "", - sourceMapSourcesContent: undefined, - sourceMapDecodedMappings: [] - }; - sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); - if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47) { - sourceMapData.sourceMapSourceRoot += ts.directorySeparator; - } - if (compilerOptions.mapRoot) { - sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); - if (root) { - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); - } - if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { - sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true); - } - else { - sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); - } - } - else { - sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); - } - function emitNodeWithSourceMap(node) { - if (node) { - if (ts.nodeIsSynthesized(node)) { - return emitNodeWithoutSourceMap(node); - } - if (node.kind !== 246) { - recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMap(node); - recordEmitNodeEndSpan(node); - } - else { - recordNewSourceFileStart(node); - emitNodeWithoutSourceMap(node); - } - } - } - function emitNodeWithCommentsAndWithSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; - emit = emitNodeWithCommentsAndWithSourcemap; - emitStart = recordEmitNodeStartSpan; - emitEnd = recordEmitNodeEndSpan; - emitToken = writeTextWithSpanRecord; - scopeEmitStart = recordScopeNameOfNode; - scopeEmitEnd = recordScopeNameEnd; - writeComment = writeCommentRangeWithMap; - } - function writeJavaScriptFile(emitOutput, writeByteOrderMark) { - ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); - } - function createTempVariable(flags) { - var result = ts.createSynthesizedNode(67); - result.text = makeTempVariableName(flags); - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; - } - tempVariables.push(name); - } - function createAndRecordTempVariable(flags) { - var temp = createTempVariable(flags); - recordTempDeclaration(temp); - return temp; - } - function emitTempDeclarations(newLine) { - if (tempVariables) { - if (newLine) { - writeLine(); - } - else { - write(" "); - } - write("var "); - emitCommaList(tempVariables); - write(";"); - } - } - function emitTokenText(tokenKind, startPos, emitFn) { - var tokenString = ts.tokenToString(tokenKind); - if (emitFn) { - emitFn(); - } - else { - write(tokenString); - } - return startPos + tokenString.length; - } - function emitOptional(prefix, node) { - if (node) { - write(prefix); - emit(node); - } - } - function emitParenthesizedIf(node, parenthesized) { - if (parenthesized) { - write("("); - } - emit(node); - if (parenthesized) { - write(")"); - } - } - function emitTrailingCommaIfPresent(nodeList) { - if (nodeList.hasTrailingComma) { - write(","); - } - } - function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { - ts.Debug.assert(nodes.length > 0); - increaseIndent(); - if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - for (var i = 0, n = nodes.length; i < n; i++) { - if (i) { - if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { - write(", "); - } - else { - write(","); - writeLine(); - } - } - emit(nodes[i]); - } - if (nodes.hasTrailingComma && allowTrailingComma) { - write(","); - } - decreaseIndent(); - if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - } - function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { - if (!emitNode) { - emitNode = emit; - } - for (var i = 0; i < count; i++) { - if (multiLine) { - if (i || leadingComma) { - write(","); - } - writeLine(); - } - else { - if (i || leadingComma) { - write(", "); - } - } - var node = nodes[start + i]; - emitTrailingCommentsOfPosition(node.pos); - emitNode(node); - leadingComma = true; - } - if (trailingComma) { - write(","); - } - if (multiLine && !noTrailingNewLine) { - writeLine(); - } - return count; - } - function emitCommaList(nodes) { - if (nodes) { - emitList(nodes, 0, nodes.length, false, false); - } - } - function emitLines(nodes) { - emitLinesStartingAt(nodes, 0); - } - function emitLinesStartingAt(nodes, startIndex) { - for (var i = startIndex; i < nodes.length; i++) { - writeLine(); - emit(nodes[i]); - } - } - function isBinaryOrOctalIntegerLiteral(node, text) { - if (node.kind === 8 && text.length > 1) { - switch (text.charCodeAt(1)) { - case 98: - case 66: - case 111: - case 79: - return true; - } - } - return false; - } - function emitLiteral(node) { - var text = getLiteralText(node); - if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 || ts.isTemplateLiteralKind(node.kind))) { - writer.writeLiteral(text); - } - else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { - write(node.text); - } - else { - write(text); - } - } - function getLiteralText(node) { - if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { - return getQuotedEscapedLiteralText("\"", node.text, "\""); - } - if (node.parent) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - } - switch (node.kind) { - case 9: - return getQuotedEscapedLiteralText("\"", node.text, "\""); - case 11: - return getQuotedEscapedLiteralText("`", node.text, "`"); - case 12: - return getQuotedEscapedLiteralText("`", node.text, "${"); - case 13: - return getQuotedEscapedLiteralText("}", node.text, "${"); - case 14: - return getQuotedEscapedLiteralText("}", node.text, "`"); - case 8: - return node.text; - } - ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); - } - function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { - return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; - } - function emitDownlevelRawTemplateLiteral(node) { - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - var isLast = node.kind === 11 || node.kind === 14; - text = text.substring(1, text.length - (isLast ? 1 : 2)); - text = text.replace(/\r\n?/g, "\n"); - text = ts.escapeString(text); - write("\"" + text + "\""); - } - function emitDownlevelTaggedTemplateArray(node, literalEmitter) { - write("["); - if (node.template.kind === 11) { - literalEmitter(node.template); - } - else { - literalEmitter(node.template.head); - ts.forEach(node.template.templateSpans, function (child) { - write(", "); - literalEmitter(child.literal); - }); - } - write("]"); - } - function emitDownlevelTaggedTemplate(node) { - var tempVariable = createAndRecordTempVariable(0); - write("("); - emit(tempVariable); - write(" = "); - emitDownlevelTaggedTemplateArray(node, emit); - write(", "); - emit(tempVariable); - write(".raw = "); - emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); - write(", "); - emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); - write("("); - emit(tempVariable); - if (node.template.kind === 181) { - ts.forEach(node.template.templateSpans, function (templateSpan) { - write(", "); - var needsParens = templateSpan.expression.kind === 179 - && templateSpan.expression.operatorToken.kind === 24; - emitParenthesizedIf(templateSpan.expression, needsParens); - }); - } - write("))"); - } - function emitTemplateExpression(node) { - if (languageVersion >= 2) { - ts.forEachChild(node, emit); - return; - } - var emitOuterParens = ts.isExpression(node.parent) - && templateNeedsParens(node, node.parent); - if (emitOuterParens) { - write("("); - } - var headEmitted = false; - if (shouldEmitTemplateHead()) { - emitLiteral(node.head); - headEmitted = true; - } - for (var i = 0, n = node.templateSpans.length; i < n; i++) { - var templateSpan = node.templateSpans[i]; - var needsParens = templateSpan.expression.kind !== 170 - && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; - if (i > 0 || headEmitted) { - write(" + "); - } - emitParenthesizedIf(templateSpan.expression, needsParens); - if (templateSpan.literal.text.length !== 0) { - write(" + "); - emitLiteral(templateSpan.literal); - } - } - if (emitOuterParens) { - write(")"); - } - function shouldEmitTemplateHead() { - ts.Debug.assert(node.templateSpans.length !== 0); - return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; - } - function templateNeedsParens(template, parent) { - switch (parent.kind) { - case 166: - case 167: - return parent.expression === template; - case 168: - case 170: - return false; - default: - return comparePrecedenceToBinaryPlus(parent) !== -1; - } - } - function comparePrecedenceToBinaryPlus(expression) { - switch (expression.kind) { - case 179: - switch (expression.operatorToken.kind) { - case 37: - case 38: - case 39: - return 1; - case 35: - case 36: - return 0; - default: - return -1; - } - case 182: - case 180: - return -1; - default: - return 1; - } - } - } - function emitTemplateSpan(span) { - emit(span.expression); - emit(span.literal); - } - function jsxEmitReact(node) { - function emitTagName(name) { - if (name.kind === 67 && ts.isIntrinsicJsxName(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - function emitAttributeName(name) { - if (/[A-Za-z_]+[\w*]/.test(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - function emitJsxAttribute(node) { - emitAttributeName(node.name); - write(": "); - if (node.initializer) { - emit(node.initializer); - } - else { - write("true"); - } - } - function emitJsxElement(openingNode, children) { - var syntheticReactRef = ts.createSynthesizedNode(67); - syntheticReactRef.text = 'React'; - syntheticReactRef.parent = openingNode; - emitLeadingComments(openingNode); - emitExpressionIdentifier(syntheticReactRef); - write(".createElement("); - emitTagName(openingNode.tagName); - write(", "); - if (openingNode.attributes.length === 0) { - write("null"); - } - else { - var attrs = openingNode.attributes; - if (ts.forEach(attrs, function (attr) { return attr.kind === 237; })) { - emitExpressionIdentifier(syntheticReactRef); - write(".__spread("); - var haveOpenedObjectLiteral = false; - for (var i_1 = 0; i_1 < attrs.length; i_1++) { - if (attrs[i_1].kind === 237) { - if (i_1 === 0) { - write("{}, "); - } - if (haveOpenedObjectLiteral) { - write("}"); - haveOpenedObjectLiteral = false; - } - if (i_1 > 0) { - write(", "); - } - emit(attrs[i_1].expression); - } - else { - ts.Debug.assert(attrs[i_1].kind === 236); - if (haveOpenedObjectLiteral) { - write(", "); - } - else { - haveOpenedObjectLiteral = true; - if (i_1 > 0) { - write(", "); - } - write("{"); - } - emitJsxAttribute(attrs[i_1]); - } - } - if (haveOpenedObjectLiteral) - write("}"); - write(")"); - } - else { - write("{"); - for (var i = 0; i < attrs.length; i++) { - if (i > 0) { - write(", "); - } - emitJsxAttribute(attrs[i]); - } - write("}"); - } - } - if (children) { - for (var i = 0; i < children.length; i++) { - if (children[i].kind === 238 && !(children[i].expression)) { - continue; - } - if (children[i].kind === 234) { - var text = getTextToEmit(children[i]); - if (text !== undefined) { - write(", \""); - write(text); - write("\""); - } - } - else { - write(", "); - emit(children[i]); - } - } - } - write(")"); - emitTrailingComments(openingNode); - } - if (node.kind === 231) { - emitJsxElement(node.openingElement, node.children); - } - else { - ts.Debug.assert(node.kind === 232); - emitJsxElement(node); - } - } - function jsxEmitPreserve(node) { - function emitJsxAttribute(node) { - emit(node.name); - if (node.initializer) { - write("="); - emit(node.initializer); - } - } - function emitJsxSpreadAttribute(node) { - write("{..."); - emit(node.expression); - write("}"); - } - function emitAttributes(attribs) { - for (var i = 0, n = attribs.length; i < n; i++) { - if (i > 0) { - write(" "); - } - if (attribs[i].kind === 237) { - emitJsxSpreadAttribute(attribs[i]); - } - else { - ts.Debug.assert(attribs[i].kind === 236); - emitJsxAttribute(attribs[i]); - } - } - } - function emitJsxOpeningOrSelfClosingElement(node) { - write("<"); - emit(node.tagName); - if (node.attributes.length > 0 || (node.kind === 232)) { - write(" "); - } - emitAttributes(node.attributes); - if (node.kind === 232) { - write("/>"); - } - else { - write(">"); - } - } - function emitJsxClosingElement(node) { - write(""); - } - function emitJsxElement(node) { - emitJsxOpeningOrSelfClosingElement(node.openingElement); - for (var i = 0, n = node.children.length; i < n; i++) { - emit(node.children[i]); - } - emitJsxClosingElement(node.closingElement); - } - if (node.kind === 231) { - emitJsxElement(node); - } - else { - ts.Debug.assert(node.kind === 232); - emitJsxOpeningOrSelfClosingElement(node); - } - } - function emitExpressionForPropertyName(node) { - ts.Debug.assert(node.kind !== 161); - if (node.kind === 9) { - emitLiteral(node); - } - else if (node.kind === 134) { - if (ts.nodeIsDecorated(node.parent)) { - if (!computedPropertyNamesToGeneratedNames) { - computedPropertyNamesToGeneratedNames = []; - } - var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; - if (generatedName) { - write(generatedName); - return; - } - generatedName = createAndRecordTempVariable(0).text; - computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; - write(generatedName); - write(" = "); - } - emit(node.expression); - } - else { - write("\""); - if (node.kind === 8) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - write("\""); - } - } - function isExpressionIdentifier(node) { - var parent = node.parent; - switch (parent.kind) { - case 162: - case 179: - case 166: - case 239: - case 134: - case 180: - case 137: - case 173: - case 195: - case 165: - case 225: - case 193: - case 186: - case 197: - case 198: - case 199: - case 194: - case 232: - case 233: - case 237: - case 238: - case 167: - case 170: - case 178: - case 177: - case 202: - case 244: - case 183: - case 204: - case 168: - case 188: - case 206: - case 169: - case 174: - case 175: - case 196: - case 203: - case 182: - return true; - case 161: - case 245: - case 136: - case 243: - case 139: - case 209: - return parent.initializer === node; - case 164: - return parent.expression === node; - case 172: - case 171: - return parent.body === node; - case 219: - return parent.moduleReference === node; - case 133: - return parent.left === node; - } - return false; - } - function emitExpressionIdentifier(node) { - if (resolver.getNodeCheckFlags(node) & 2048) { - write("_arguments"); - return; - } - var container = resolver.getReferencedExportContainer(node); - if (container) { - if (container.kind === 246) { - if (languageVersion < 2 && compilerOptions.module !== 4) { - write("exports."); - } - } - else { - write(getGeneratedNameForNode(container)); - write("."); - } - } - else if (languageVersion < 2) { - var declaration = resolver.getReferencedImportDeclaration(node); - if (declaration) { - if (declaration.kind === 221) { - write(getGeneratedNameForNode(declaration.parent)); - write(languageVersion === 0 ? "[\"default\"]" : ".default"); - return; - } - else if (declaration.kind === 224) { - write(getGeneratedNameForNode(declaration.parent.parent.parent)); - var name = declaration.propertyName || declaration.name; - var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name); - if (languageVersion === 0 && identifier === "default") { - write("[\"default\"]"); - } - else { - write("."); - write(identifier); - } - return; - } - } - declaration = resolver.getReferencedNestedRedeclaration(node); - if (declaration) { - write(getGeneratedNameForNode(declaration.name)); - return; - } - } - if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function isNameOfNestedRedeclaration(node) { - if (languageVersion < 2) { - var parent_6 = node.parent; - switch (parent_6.kind) { - case 161: - case 212: - case 215: - case 209: - return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); - } - } - return false; - } - function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (isExpressionIdentifier(node)) { - emitExpressionIdentifier(node); - } - else if (isNameOfNestedRedeclaration(node)) { - write(getGeneratedNameForNode(node)); - } - else if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function emitThis(node) { - if (resolver.getNodeCheckFlags(node) & 2) { - write("_this"); - } - else { - write("this"); - } - } - function emitSuper(node) { - if (languageVersion >= 2) { - write("super"); - } - else { - var flags = resolver.getNodeCheckFlags(node); - if (flags & 256) { - write("_super.prototype"); - } - else { - write("_super"); - } - } - } - function emitObjectBindingPattern(node) { - write("{ "); - var elements = node.elements; - emitList(elements, 0, elements.length, false, elements.hasTrailingComma); - write(" }"); - } - function emitArrayBindingPattern(node) { - write("["); - var elements = node.elements; - emitList(elements, 0, elements.length, false, elements.hasTrailingComma); - write("]"); - } - function emitBindingElement(node) { - if (node.propertyName) { - emit(node.propertyName); - write(": "); - } - if (node.dotDotDotToken) { - write("..."); - } - if (ts.isBindingPattern(node.name)) { - emit(node.name); - } - else { - emitModuleMemberName(node); - } - emitOptional(" = ", node.initializer); - } - function emitSpreadElementExpression(node) { - write("..."); - emit(node.expression); - } - function emitYieldExpression(node) { - write(ts.tokenToString(112)); - if (node.asteriskToken) { - write("*"); - } - if (node.expression) { - write(" "); - emit(node.expression); - } - } - function emitAwaitExpression(node) { - var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); - if (needsParenthesis) { - write("("); - } - write(ts.tokenToString(112)); - write(" "); - emit(node.expression); - if (needsParenthesis) { - write(")"); - } - } - function needsParenthesisForAwaitExpressionAsYield(node) { - if (node.parent.kind === 179 && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { - return true; - } - else if (node.parent.kind === 180 && node.parent.condition === node) { - return true; - } - return false; - } - function needsParenthesisForPropertyAccessOrInvocation(node) { - switch (node.kind) { - case 67: - case 162: - case 164: - case 165: - case 166: - case 170: - return false; - } - return true; - } - function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { - var pos = 0; - var group = 0; - var length = elements.length; - while (pos < length) { - if (group === 1 && useConcat) { - write(".concat("); - } - else if (group > 0) { - write(", "); - } - var e = elements[pos]; - if (e.kind === 183) { - e = e.expression; - emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); - pos++; - if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 162) { - write(".slice()"); - } - } - else { - var i = pos; - while (i < length && elements[i].kind !== 183) { - i++; - } - write("["); - if (multiLine) { - increaseIndent(); - } - emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); - if (multiLine) { - decreaseIndent(); - } - write("]"); - pos = i; - } - group++; - } - if (group > 1) { - if (useConcat) { - write(")"); - } - } - } - function isSpreadElementExpression(node) { - return node.kind === 183; - } - function emitArrayLiteral(node) { - var elements = node.elements; - if (elements.length === 0) { - write("[]"); - } - else if (languageVersion >= 2 || !ts.forEach(elements, isSpreadElementExpression)) { - write("["); - emitLinePreservingList(node, node.elements, elements.hasTrailingComma, false); - write("]"); - } - else { - emitListWithSpread(elements, true, (node.flags & 2048) !== 0, elements.hasTrailingComma, true); - } - } - function emitObjectLiteralBody(node, numElements) { - if (numElements === 0) { - write("{}"); - return; - } - write("{"); - if (numElements > 0) { - var properties = node.properties; - if (numElements === properties.length) { - emitLinePreservingList(node, properties, languageVersion >= 1, true); - } - else { - var multiLine = (node.flags & 2048) !== 0; - if (!multiLine) { - write(" "); - } - else { - increaseIndent(); - } - emitList(properties, 0, numElements, multiLine, false); - if (!multiLine) { - write(" "); - } - else { - decreaseIndent(); - } - } - } - write("}"); - } - function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { - var multiLine = (node.flags & 2048) !== 0; - var properties = node.properties; - write("("); - if (multiLine) { - increaseIndent(); - } - var tempVar = createAndRecordTempVariable(0); - emit(tempVar); - write(" = "); - emitObjectLiteralBody(node, firstComputedPropertyIndex); - for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { - writeComma(); - var property = properties[i]; - emitStart(property); - if (property.kind === 143 || property.kind === 144) { - var accessors = ts.getAllAccessorDeclarations(node.properties, property); - if (property !== accessors.firstAccessor) { - continue; - } - write("Object.defineProperty("); - emit(tempVar); - write(", "); - emitStart(node.name); - emitExpressionForPropertyName(property.name); - emitEnd(property.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("})"); - emitEnd(property); - } - else { - emitLeadingComments(property); - emitStart(property.name); - emit(tempVar); - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - if (property.kind === 243) { - emit(property.initializer); - } - else if (property.kind === 244) { - emitExpressionIdentifier(property.name); - } - else if (property.kind === 141) { - emitFunctionDeclaration(property); - } - else { - ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); - } - } - emitEnd(property); - } - writeComma(); - emit(tempVar); - if (multiLine) { - decreaseIndent(); - writeLine(); - } - write(")"); - function writeComma() { - if (multiLine) { - write(","); - writeLine(); - } - else { - write(", "); - } - } - } - function emitObjectLiteral(node) { - var properties = node.properties; - if (languageVersion < 2) { - var numProperties = properties.length; - var numInitialNonComputedProperties = numProperties; - for (var i = 0, n = properties.length; i < n; i++) { - if (properties[i].name.kind === 134) { - numInitialNonComputedProperties = i; - break; - } - } - var hasComputedProperty = numInitialNonComputedProperties !== properties.length; - if (hasComputedProperty) { - emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); - return; - } - } - emitObjectLiteralBody(node, properties.length); - } - function createBinaryExpression(left, operator, right, startsOnNewLine) { - var result = ts.createSynthesizedNode(179, startsOnNewLine); - result.operatorToken = ts.createSynthesizedNode(operator); - result.left = left; - result.right = right; - return result; - } - function createPropertyAccessExpression(expression, name) { - var result = ts.createSynthesizedNode(164); - result.expression = parenthesizeForAccess(expression); - result.dotToken = ts.createSynthesizedNode(21); - result.name = name; - return result; - } - function createElementAccessExpression(expression, argumentExpression) { - var result = ts.createSynthesizedNode(165); - result.expression = parenthesizeForAccess(expression); - result.argumentExpression = argumentExpression; - return result; - } - function parenthesizeForAccess(expr) { - while (expr.kind === 169 || expr.kind === 187) { - expr = expr.expression; - } - if (ts.isLeftHandSideExpression(expr) && - expr.kind !== 167 && - expr.kind !== 8) { - return expr; - } - var node = ts.createSynthesizedNode(170); - node.expression = expr; - return node; - } - function emitComputedPropertyName(node) { - write("["); - emitExpressionForPropertyName(node); - write("]"); - } - function emitMethod(node) { - if (languageVersion >= 2 && node.asteriskToken) { - write("*"); - } - emit(node.name); - if (languageVersion < 2) { - write(": function "); - } - emitSignatureAndBody(node); - } - function emitPropertyAssignment(node) { - emit(node.name); - write(": "); - emitTrailingCommentsOfPosition(node.initializer.pos); - emit(node.initializer); - } - function isNamespaceExportReference(node) { - var container = resolver.getReferencedExportContainer(node); - return container && container.kind !== 246; - } - function emitShorthandPropertyAssignment(node) { - writeTextOfNode(currentSourceFile, node.name); - if (languageVersion < 2 || isNamespaceExportReference(node.name)) { - write(": "); - emit(node.name); - } - } - function tryEmitConstantValue(node) { - var constantValue = tryGetConstEnumValue(node); - if (constantValue !== undefined) { - write(constantValue.toString()); - if (!compilerOptions.removeComments) { - var propertyName = node.kind === 164 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); - write(" /* " + propertyName + " */"); - } - return true; - } - return false; - } - function tryGetConstEnumValue(node) { - if (compilerOptions.isolatedModules) { - return undefined; - } - return node.kind === 164 || node.kind === 165 - ? resolver.getConstantValue(node) - : undefined; - } - function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { - var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); - var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); - if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { - increaseIndent(); - writeLine(); - return true; - } - else { - if (valueToWriteWhenNotIndenting) { - write(valueToWriteWhenNotIndenting); - } - return false; - } - } - function emitPropertyAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); - var shouldEmitSpace; - if (!indentedBeforeDot) { - if (node.expression.kind === 8) { - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); - shouldEmitSpace = text.indexOf(ts.tokenToString(21)) < 0; - } - else { - var constantValue = tryGetConstEnumValue(node.expression); - shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; - } - } - if (shouldEmitSpace) { - write(" ."); - } - else { - write("."); - } - var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); - emit(node.name); - decreaseIndentIf(indentedBeforeDot, indentedAfterDot); - } - function emitQualifiedName(node) { - emit(node.left); - write("."); - emit(node.right); - } - function emitQualifiedNameAsExpression(node, useFallback) { - if (node.left.kind === 67) { - emitEntityNameAsExpression(node.left, useFallback); - } - else if (useFallback) { - var temp = createAndRecordTempVariable(0); - write("("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(node.left, true); - write(") && "); - emitNodeWithoutSourceMap(temp); - } - else { - emitEntityNameAsExpression(node.left, false); - } - write("."); - emit(node.right); - } - function emitEntityNameAsExpression(node, useFallback) { - switch (node.kind) { - case 67: - if (useFallback) { - write("typeof "); - emitExpressionIdentifier(node); - write(" !== 'undefined' && "); - } - emitExpressionIdentifier(node); - break; - case 133: - emitQualifiedNameAsExpression(node, useFallback); - break; - } - } - function emitIndexedAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("["); - emit(node.argumentExpression); - write("]"); - } - function hasSpreadElement(elements) { - return ts.forEach(elements, function (e) { return e.kind === 183; }); - } - function skipParentheses(node) { - while (node.kind === 170 || node.kind === 169 || node.kind === 187) { - node = node.expression; - } - return node; - } - function emitCallTarget(node) { - if (node.kind === 67 || node.kind === 95 || node.kind === 93) { - emit(node); - return node; - } - var temp = createAndRecordTempVariable(0); - write("("); - emit(temp); - write(" = "); - emit(node); - write(")"); - return temp; - } - function emitCallWithSpread(node) { - var target; - var expr = skipParentheses(node.expression); - if (expr.kind === 164) { - target = emitCallTarget(expr.expression); - write("."); - emit(expr.name); - } - else if (expr.kind === 165) { - target = emitCallTarget(expr.expression); - write("["); - emit(expr.argumentExpression); - write("]"); - } - else if (expr.kind === 93) { - target = expr; - write("_super"); - } - else { - emit(node.expression); - } - write(".apply("); - if (target) { - if (target.kind === 93) { - emitThis(target); - } - else { - emit(target); - } - } - else { - write("void 0"); - } - write(", "); - emitListWithSpread(node.arguments, false, false, false, true); - write(")"); - } - function emitCallExpression(node) { - if (languageVersion < 2 && hasSpreadElement(node.arguments)) { - emitCallWithSpread(node); - return; - } - var superCall = false; - if (node.expression.kind === 93) { - emitSuper(node.expression); - superCall = true; - } - else { - emit(node.expression); - superCall = node.expression.kind === 164 && node.expression.expression.kind === 93; - } - if (superCall && languageVersion < 2) { - write(".call("); - emitThis(node.expression); - if (node.arguments.length) { - write(", "); - emitCommaList(node.arguments); - } - write(")"); - } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitNewExpression(node) { - write("new "); - if (languageVersion === 1 && - node.arguments && - hasSpreadElement(node.arguments)) { - write("("); - var target = emitCallTarget(node.expression); - write(".bind.apply("); - emit(target); - write(", [void 0].concat("); - emitListWithSpread(node.arguments, false, false, false, false); - write(")))"); - write("()"); - } - else { - emit(node.expression); - if (node.arguments) { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - } - function emitTaggedTemplateExpression(node) { - if (languageVersion >= 2) { - emit(node.tag); - write(" "); - emit(node.template); - } - else { - emitDownlevelTaggedTemplate(node); - } - } - function emitParenExpression(node) { - if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 172) { - if (node.expression.kind === 169 || node.expression.kind === 187) { - var operand = node.expression.expression; - while (operand.kind === 169 || operand.kind === 187) { - operand = operand.expression; - } - if (operand.kind !== 177 && - operand.kind !== 175 && - operand.kind !== 174 && - operand.kind !== 173 && - operand.kind !== 178 && - operand.kind !== 167 && - !(operand.kind === 166 && node.parent.kind === 167) && - !(operand.kind === 171 && node.parent.kind === 166) && - !(operand.kind === 8 && node.parent.kind === 164)) { - emit(operand); - return; - } - } - } - write("("); - emit(node.expression); - write(")"); - } - function emitDeleteExpression(node) { - write(ts.tokenToString(76)); - write(" "); - emit(node.expression); - } - function emitVoidExpression(node) { - write(ts.tokenToString(101)); - write(" "); - emit(node.expression); - } - function emitTypeOfExpression(node) { - write(ts.tokenToString(99)); - write(" "); - emit(node.expression); - } - function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { - if (!isCurrentFileSystemExternalModule() || node.kind !== 67 || ts.nodeIsSynthesized(node)) { - return false; - } - var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 209 || node.parent.kind === 161); - var targetDeclaration = isVariableDeclarationOrBindingElement - ? node.parent - : resolver.getReferencedValueDeclaration(node); - return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, true); - } - function emitPrefixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - } - write(ts.tokenToString(node.operator)); - if (node.operand.kind === 177) { - var operand = node.operand; - if (node.operator === 35 && (operand.operator === 35 || operand.operator === 40)) { - write(" "); - } - else if (node.operator === 36 && (operand.operator === 36 || operand.operator === 41)) { - write(" "); - } - } - emit(node.operand); - if (exportChanged) { - write(")"); - } - } - function emitPostfixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - write("(" + exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - write(ts.tokenToString(node.operator)); - emit(node.operand); - if (node.operator === 40) { - write(") - 1)"); - } - else { - write(") + 1)"); - } - } - else { - emit(node.operand); - write(ts.tokenToString(node.operator)); - } - } - function shouldHoistDeclarationInSystemJsModule(node) { - return isSourceFileLevelDeclarationInSystemJsModule(node, false); - } - function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { - if (!node || languageVersion >= 2 || !isCurrentFileSystemExternalModule()) { - return false; - } - var current = node; - while (current) { - if (current.kind === 246) { - return !isExported || ((ts.getCombinedNodeFlags(node) & 1) !== 0); - } - else if (ts.isFunctionLike(current) || current.kind === 217) { - return false; - } - else { - current = current.parent; - } - } - } - function emitBinaryExpression(node) { - if (languageVersion < 2 && node.operatorToken.kind === 55 && - (node.left.kind === 163 || node.left.kind === 162)) { - emitDestructuring(node, node.parent.kind === 193); - } - else { - var exportChanged = node.operatorToken.kind >= 55 && - node.operatorToken.kind <= 66 && - isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.left); - write("\", "); - } - emit(node.left); - var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 ? " " : undefined); - write(ts.tokenToString(node.operatorToken.kind)); - var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); - emit(node.right); - decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); - if (exportChanged) { - write(")"); - } - } - } - function synthesizedNodeStartsOnNewLine(node) { - return ts.nodeIsSynthesized(node) && node.startsOnNewLine; - } - function emitConditionalExpression(node) { - emit(node.condition); - var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); - write("?"); - var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); - emit(node.whenTrue); - decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); - var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); - write(":"); - var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); - emit(node.whenFalse); - decreaseIndentIf(indentedBeforeColon, indentedAfterColon); - } - function decreaseIndentIf(value1, value2) { - if (value1) { - decreaseIndent(); - } - if (value2) { - decreaseIndent(); - } - } - function isSingleLineEmptyBlock(node) { - if (node && node.kind === 190) { - var block = node; - return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); - } - } - function emitBlock(node) { - if (isSingleLineEmptyBlock(node)) { - emitToken(15, node.pos); - write(" "); - emitToken(16, node.statements.end); - return; - } - emitToken(15, node.pos); - increaseIndent(); - scopeEmitStart(node.parent); - if (node.kind === 217) { - ts.Debug.assert(node.parent.kind === 216); - emitCaptureThisForNodeIfNecessary(node.parent); - } - emitLines(node.statements); - if (node.kind === 217) { - emitTempDeclarations(true); - } - decreaseIndent(); - writeLine(); - emitToken(16, node.statements.end); - scopeEmitEnd(); - } - function emitEmbeddedStatement(node) { - if (node.kind === 190) { - write(" "); - emit(node); - } - else { - increaseIndent(); - writeLine(); - emit(node); - decreaseIndent(); - } - } - function emitExpressionStatement(node) { - emitParenthesizedIf(node.expression, node.expression.kind === 172); - write(";"); - } - function emitIfStatement(node) { - var endPos = emitToken(86, node.pos); - write(" "); - endPos = emitToken(17, endPos); - emit(node.expression); - emitToken(18, node.expression.end); - emitEmbeddedStatement(node.thenStatement); - if (node.elseStatement) { - writeLine(); - emitToken(78, node.thenStatement.end); - if (node.elseStatement.kind === 194) { - write(" "); - emit(node.elseStatement); - } - else { - emitEmbeddedStatement(node.elseStatement); - } - } - } - function emitDoStatement(node) { - write("do"); - emitEmbeddedStatement(node.statement); - if (node.statement.kind === 190) { - write(" "); - } - else { - writeLine(); - } - write("while ("); - emit(node.expression); - write(");"); - } - function emitWhileStatement(node) { - write("while ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function tryEmitStartOfVariableDeclarationList(decl, startPos) { - if (shouldHoistVariable(decl, true)) { - return false; - } - var tokenKind = 100; - if (decl && languageVersion >= 2) { - if (ts.isLet(decl)) { - tokenKind = 106; - } - else if (ts.isConst(decl)) { - tokenKind = 72; - } - } - if (startPos !== undefined) { - emitToken(tokenKind, startPos); - write(" "); - } - else { - switch (tokenKind) { - case 100: - write("var "); - break; - case 106: - write("let "); - break; - case 72: - write("const "); - break; - } - } - return true; - } - function emitVariableDeclarationListSkippingUninitializedEntries(list) { - var started = false; - for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { - var decl = _b[_a]; - if (!decl.initializer) { - continue; - } - if (!started) { - started = true; - } - else { - write(", "); - } - emit(decl); - } - return started; - } - function emitForStatement(node) { - var endPos = emitToken(84, node.pos); - write(" "); - endPos = emitToken(17, endPos); - if (node.initializer && node.initializer.kind === 210) { - var variableDeclarationList = node.initializer; - var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - if (startIsEmitted) { - emitCommaList(variableDeclarationList.declarations); - } - else { - emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); - } - } - else if (node.initializer) { - emit(node.initializer); - } - write(";"); - emitOptional(" ", node.condition); - write(";"); - emitOptional(" ", node.incrementor); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForInOrForOfStatement(node) { - if (languageVersion < 2 && node.kind === 199) { - return emitDownLevelForOfStatement(node); - } - var endPos = emitToken(84, node.pos); - write(" "); - endPos = emitToken(17, endPos); - if (node.initializer.kind === 210) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - emit(variableDeclarationList.declarations[0]); - } - } - else { - emit(node.initializer); - } - if (node.kind === 198) { - write(" in "); - } - else { - write(" of "); - } - emit(node.expression); - emitToken(18, node.expression.end); - emitEmbeddedStatement(node.statement); - } - function emitDownLevelForOfStatement(node) { - var endPos = emitToken(84, node.pos); - write(" "); - endPos = emitToken(17, endPos); - var rhsIsIdentifier = node.expression.kind === 67; - var counter = createTempVariable(268435456); - var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0); - emitStart(node.expression); - write("var "); - emitNodeWithoutSourceMap(counter); - write(" = 0"); - emitEnd(node.expression); - if (!rhsIsIdentifier) { - write(", "); - emitStart(node.expression); - emitNodeWithoutSourceMap(rhsReference); - write(" = "); - emitNodeWithoutSourceMap(node.expression); - emitEnd(node.expression); - } - write("; "); - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write(" < "); - emitNodeWithCommentsAndWithoutSourcemap(rhsReference); - write(".length"); - emitEnd(node.initializer); - write("; "); - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write("++"); - emitEnd(node.initializer); - emitToken(18, node.expression.end); - write(" {"); - writeLine(); - increaseIndent(); - var rhsIterationValue = createElementAccessExpression(rhsReference, counter); - emitStart(node.initializer); - if (node.initializer.kind === 210) { - write("var "); - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length > 0) { - var declaration = variableDeclarationList.declarations[0]; - if (ts.isBindingPattern(declaration.name)) { - emitDestructuring(declaration, false, rhsIterationValue); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(declaration); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - emitNodeWithoutSourceMap(createTempVariable(0)); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - var assignmentExpression = createBinaryExpression(node.initializer, 55, rhsIterationValue, false); - if (node.initializer.kind === 162 || node.initializer.kind === 163) { - emitDestructuring(assignmentExpression, true, undefined); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); - } - } - emitEnd(node.initializer); - write(";"); - if (node.statement.kind === 190) { - emitLines(node.statement.statements); - } - else { - writeLine(); - emit(node.statement); - } - writeLine(); - decreaseIndent(); - write("}"); - } - function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 201 ? 68 : 73, node.pos); - emitOptional(" ", node.label); - write(";"); - } - function emitReturnStatement(node) { - emitToken(92, node.pos); - emitOptional(" ", node.expression); - write(";"); - } - function emitWithStatement(node) { - write("with ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitSwitchStatement(node) { - var endPos = emitToken(94, node.pos); - write(" "); - emitToken(17, endPos); - emit(node.expression); - endPos = emitToken(18, node.expression.end); - write(" "); - emitCaseBlock(node.caseBlock, endPos); - } - function emitCaseBlock(node, startPos) { - emitToken(15, startPos); - increaseIndent(); - emitLines(node.clauses); - decreaseIndent(); - writeLine(); - emitToken(16, node.clauses.end); - } - function nodeStartPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function nodeEndPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, node2.end); - } - function nodeEndIsOnSameLineAsNodeStart(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function emitCaseOrDefaultClause(node) { - if (node.kind === 239) { - write("case "); - emit(node.expression); - write(":"); - } - else { - write("default:"); - } - if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { - write(" "); - emit(node.statements[0]); - } - else { - increaseIndent(); - emitLines(node.statements); - decreaseIndent(); - } - } - function emitThrowStatement(node) { - write("throw "); - emit(node.expression); - write(";"); - } - function emitTryStatement(node) { - write("try "); - emit(node.tryBlock); - emit(node.catchClause); - if (node.finallyBlock) { - writeLine(); - write("finally "); - emit(node.finallyBlock); - } - } - function emitCatchClause(node) { - writeLine(); - var endPos = emitToken(70, node.pos); - write(" "); - emitToken(17, endPos); - emit(node.variableDeclaration); - emitToken(18, node.variableDeclaration ? node.variableDeclaration.end : endPos); - write(" "); - emitBlock(node.block); - } - function emitDebuggerStatement(node) { - emitToken(74, node.pos); - write(";"); - } - function emitLabelledStatement(node) { - emit(node.label); - write(": "); - emit(node.statement); - } - function getContainingModule(node) { - do { - node = node.parent; - } while (node && node.kind !== 216); - return node; - } - function emitContainingModuleName(node) { - var container = getContainingModule(node); - write(container ? getGeneratedNameForNode(container) : "exports"); - } - function emitModuleMemberName(node) { - emitStart(node.name); - if (ts.getCombinedNodeFlags(node) & 1) { - var container = getContainingModule(node); - if (container) { - write(getGeneratedNameForNode(container)); - write("."); - } - else if (languageVersion < 2 && compilerOptions.module !== 4) { - write("exports."); - } - } - emitNodeWithCommentsAndWithoutSourcemap(node.name); - emitEnd(node.name); - } - function createVoidZero() { - var zero = ts.createSynthesizedNode(8); - zero.text = "0"; - var result = ts.createSynthesizedNode(175); - result.expression = zero; - return result; - } - function emitEs6ExportDefaultCompat(node) { - if (node.parent.kind === 246) { - ts.Debug.assert(!!(node.flags & 1024) || node.kind === 225); - if (compilerOptions.module === 1 || compilerOptions.module === 2 || compilerOptions.module === 3) { - if (!currentSourceFile.symbol.exports["___esModule"]) { - if (languageVersion === 1) { - write("Object.defineProperty(exports, \"__esModule\", { value: true });"); - writeLine(); - } - else if (languageVersion === 0) { - write("exports.__esModule = true;"); - writeLine(); - } - } - } - } - } - function emitExportMemberAssignment(node) { - if (node.flags & 1) { - writeLine(); - emitStart(node); - if (compilerOptions.module === 4 && node.parent === currentSourceFile) { - write(exportFunctionForFile + "(\""); - if (node.flags & 1024) { - write("default"); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - write("\", "); - emitDeclarationName(node); - write(")"); - } - else { - if (node.flags & 1024) { - emitEs6ExportDefaultCompat(node); - if (languageVersion === 0) { - write("exports[\"default\"]"); - } - else { - write("exports.default"); - } - } - else { - emitModuleMemberName(node); - } - write(" = "); - emitDeclarationName(node); - } - emitEnd(node); - write(";"); - } - } - function emitExportMemberAssignments(name) { - if (compilerOptions.module === 4) { - return; - } - if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { - for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { - var specifier = _b[_a]; - writeLine(); - emitStart(specifier.name); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - emitEnd(specifier.name); - write(" = "); - emitExpressionIdentifier(name); - write(";"); - } - } - } - function emitExportSpecifierInSystemModule(specifier) { - ts.Debug.assert(compilerOptions.module === 4); - if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { - return; - } - writeLine(); - emitStart(specifier.name); - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write("\", "); - emitExpressionIdentifier(specifier.propertyName || specifier.name); - write(")"); - emitEnd(specifier.name); - write(";"); - } - function emitDestructuring(root, isAssignmentExpressionStatement, value) { - var emitCount = 0; - var canDefineTempVariablesInPlace = false; - if (root.kind === 209) { - var isExported = ts.getCombinedNodeFlags(root) & 1; - var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); - canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; - } - else if (root.kind === 136) { - canDefineTempVariablesInPlace = true; - } - if (root.kind === 179) { - emitAssignmentExpression(root); - } - else { - ts.Debug.assert(!isAssignmentExpressionStatement); - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 209 || name.parent.kind === 161); - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(name); - write("\", "); - } - if (isVariableDeclarationOrBindingElement) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - if (exportChanged) { - write(")"); - } - } - function ensureIdentifier(expr, reuseIdentifierExpressions) { - if (expr.kind === 67 && reuseIdentifierExpressions) { - return expr; - } - var identifier = createTempVariable(0); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - return identifier; - } - function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value, true); - var equals = ts.createSynthesizedNode(179); - equals.left = value; - equals.operatorToken = ts.createSynthesizedNode(32); - equals.right = createVoidZero(); - return createConditionalExpression(equals, defaultValue, value); - } - function createConditionalExpression(condition, whenTrue, whenFalse) { - var cond = ts.createSynthesizedNode(180); - cond.condition = condition; - cond.questionToken = ts.createSynthesizedNode(52); - cond.whenTrue = whenTrue; - cond.colonToken = ts.createSynthesizedNode(53); - cond.whenFalse = whenFalse; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createSynthesizedNode(8); - node.text = "" + value; - return node; - } - function createPropertyAccessForDestructuringProperty(object, propName) { - var syntheticName = ts.createSynthesizedNode(propName.kind); - syntheticName.text = propName.text; - if (syntheticName.kind !== 67) { - return createElementAccessExpression(object, syntheticName); - } - return createPropertyAccessExpression(object, syntheticName); - } - function createSliceCall(value, sliceIndex) { - var call = ts.createSynthesizedNode(166); - var sliceIdentifier = ts.createSynthesizedNode(67); - sliceIdentifier.text = "slice"; - call.expression = createPropertyAccessExpression(value, sliceIdentifier); - call.arguments = ts.createSynthesizedNodeArray(); - call.arguments[0] = createNumericLiteral(sliceIndex); - return call; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - value = ensureIdentifier(value, true); - } - for (var _a = 0; _a < properties.length; _a++) { - var p = properties[_a]; - if (p.kind === 243 || p.kind === 244) { - var propName = p.name; - emitDestructuringAssignment(p.initializer || propName, createPropertyAccessForDestructuringProperty(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value, true); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 185) { - if (e.kind !== 183) { - emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === elements.length - 1) { - emitDestructuringAssignment(e.expression, createSliceCall(value, i)); - } - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 179 && target.operatorToken.kind === 55) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 163) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 162) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { - emit(value); - } - else if (isAssignmentExpressionStatement) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 170) { - write("("); - } - value = ensureIdentifier(value, true); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 170) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - var numElements = elements.length; - if (numElements !== 1) { - value = ensureIdentifier(value, numElements !== 0); - } - for (var i = 0; i < numElements; i++) { - var element = elements[i]; - if (pattern.kind === 159) { - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); - } - else if (element.kind !== 185) { - if (!element.dotDotDotToken) { - emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === numElements - 1) { - emitBindingElement(element, createSliceCall(value, i)); - } - } - } - } - else { - emitAssignment(target.name, value); - } - } - } - function emitVariableDeclaration(node) { - if (ts.isBindingPattern(node.name)) { - if (languageVersion < 2) { - emitDestructuring(node, false); - } - else { - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - else { - var initializer = node.initializer; - if (!initializer && languageVersion < 2) { - var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384) && - (getCombinedFlagsForIdentifier(node.name) & 16384); - if (isUninitializedLet && - node.parent.parent.kind !== 198 && - node.parent.parent.kind !== 199) { - initializer = createVoidZero(); - } - } - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(node.name); - write("\", "); - } - emitModuleMemberName(node); - emitOptional(" = ", initializer); - if (exportChanged) { - write(")"); - } - } - } - function emitExportVariableAssignments(node) { - if (node.kind === 185) { - return; - } - var name = node.name; - if (name.kind === 67) { - emitExportMemberAssignments(name); - } - else if (ts.isBindingPattern(name)) { - ts.forEach(name.elements, emitExportVariableAssignments); - } - } - function getCombinedFlagsForIdentifier(node) { - if (!node.parent || (node.parent.kind !== 209 && node.parent.kind !== 161)) { - return 0; - } - return ts.getCombinedNodeFlags(node.parent); - } - function isES6ExportedDeclaration(node) { - return !!(node.flags & 1) && - languageVersion >= 2 && - node.parent.kind === 246; - } - function emitVariableStatement(node) { - var startIsEmitted = false; - if (node.flags & 1) { - if (isES6ExportedDeclaration(node)) { - write("export "); - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - } - else { - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - if (startIsEmitted) { - emitCommaList(node.declarationList.declarations); - write(";"); - } - else { - var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); - if (atLeastOneItem) { - write(";"); - } - } - if (languageVersion < 2 && node.parent === currentSourceFile) { - ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); - } - } - function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { - if (!(node.flags & 1)) { - return true; - } - if (isES6ExportedDeclaration(node)) { - return true; - } - for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { - var declaration = _b[_a]; - if (declaration.initializer) { - return true; - } - } - return false; - } - function emitParameter(node) { - if (languageVersion < 2) { - if (ts.isBindingPattern(node.name)) { - var name_23 = createTempVariable(0); - if (!tempParameters) { - tempParameters = []; - } - tempParameters.push(name_23); - emit(name_23); - } - else { - emit(node.name); - } - } - else { - if (node.dotDotDotToken) { - write("..."); - } - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - function emitDefaultValueAssignments(node) { - if (languageVersion < 2) { - var tempIndex = 0; - ts.forEach(node.parameters, function (parameter) { - if (parameter.dotDotDotToken) { - return; - } - var paramName = parameter.name, initializer = parameter.initializer; - if (ts.isBindingPattern(paramName)) { - var hasBindingElements = paramName.elements.length > 0; - if (hasBindingElements || initializer) { - writeLine(); - write("var "); - if (hasBindingElements) { - emitDestructuring(parameter, false, tempParameters[tempIndex]); - } - else { - emit(tempParameters[tempIndex]); - write(" = "); - emit(initializer); - } - write(";"); - tempIndex++; - } - } - else if (initializer) { - writeLine(); - emitStart(parameter); - write("if ("); - emitNodeWithoutSourceMap(paramName); - write(" === void 0)"); - emitEnd(parameter); - write(" { "); - emitStart(parameter); - emitNodeWithCommentsAndWithoutSourcemap(paramName); - write(" = "); - emitNodeWithCommentsAndWithoutSourcemap(initializer); - emitEnd(parameter); - write("; }"); - } - }); - } - } - function emitRestParameter(node) { - if (languageVersion < 2 && ts.hasRestParameter(node)) { - var restIndex = node.parameters.length - 1; - var restParam = node.parameters[restIndex]; - if (ts.isBindingPattern(restParam.name)) { - return; - } - var tempName = createTempVariable(268435456).text; - writeLine(); - emitLeadingComments(restParam); - emitStart(restParam); - write("var "); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write(" = [];"); - emitEnd(restParam); - emitTrailingComments(restParam); - writeLine(); - write("for ("); - emitStart(restParam); - write("var " + tempName + " = " + restIndex + ";"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + " < arguments.length;"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + "++"); - emitEnd(restParam); - write(") {"); - increaseIndent(); - writeLine(); - emitStart(restParam); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); - emitEnd(restParam); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitAccessor(node) { - write(node.kind === 143 ? "get " : "set "); - emit(node.name); - emitSignatureAndBody(node); - } - function shouldEmitAsArrowFunction(node) { - return node.kind === 172 && languageVersion >= 2; - } - function emitDeclarationName(node) { - if (node.name) { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - else { - write(getGeneratedNameForNode(node)); - } - } - function shouldEmitFunctionName(node) { - if (node.kind === 171) { - return !!node.name; - } - if (node.kind === 211) { - return !!node.name || languageVersion < 2; - } - } - function emitFunctionDeclaration(node) { - if (ts.nodeIsMissing(node.body)) { - return emitCommentsOnNotEmittedNode(node); - } - if (node.kind !== 141 && node.kind !== 140 && - node.parent && node.parent.kind !== 243 && - node.parent.kind !== 166) { - emitLeadingComments(node); - } - emitStart(node); - if (!shouldEmitAsArrowFunction(node)) { - if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024) { - write("default "); - } - } - write("function"); - if (languageVersion >= 2 && node.asteriskToken) { - write("*"); - } - write(" "); - } - if (shouldEmitFunctionName(node)) { - emitDeclarationName(node); - } - emitSignatureAndBody(node); - if (languageVersion < 2 && node.kind === 211 && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - emitEnd(node); - if (node.kind !== 141 && node.kind !== 140) { - emitTrailingComments(node); - } - } - function emitCaptureThisForNodeIfNecessary(node) { - if (resolver.getNodeCheckFlags(node) & 4) { - writeLine(); - emitStart(node); - write("var _this = this;"); - emitEnd(node); - } - } - function emitSignatureParameters(node) { - increaseIndent(); - write("("); - if (node) { - var parameters = node.parameters; - var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0; - emitList(parameters, 0, parameters.length - omitCount, false, false); - } - write(")"); - decreaseIndent(); - } - function emitSignatureParametersForArrow(node) { - if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { - emit(node.parameters[0]); - return; - } - emitSignatureParameters(node); - } - function emitAsyncFunctionBodyForES6(node) { - var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); - var isArrowFunction = node.kind === 172; - var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096) !== 0; - var args; - if (!isArrowFunction) { - write(" {"); - increaseIndent(); - writeLine(); - write("return"); - } - write(" __awaiter(this"); - if (hasLexicalArguments) { - write(", arguments"); - } - else { - write(", void 0"); - } - if (promiseConstructor) { - write(", "); - emitNodeWithoutSourceMap(promiseConstructor); - } - else { - write(", Promise"); - } - if (hasLexicalArguments) { - write(", function* (_arguments)"); - } - else { - write(", function* ()"); - } - emitFunctionBody(node); - write(")"); - if (!isArrowFunction) { - write(";"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitFunctionBody(node) { - if (!node.body) { - write(" { }"); - } - else { - if (node.body.kind === 190) { - emitBlockFunctionBody(node, node.body); - } - else { - emitExpressionFunctionBody(node, node.body); - } - } - } - function emitSignatureAndBody(node) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - if (shouldEmitAsArrowFunction(node)) { - emitSignatureParametersForArrow(node); - write(" =>"); - } - else { - emitSignatureParameters(node); - } - var isAsync = ts.isAsyncFunctionLike(node); - if (isAsync && languageVersion === 2) { - emitAsyncFunctionBodyForES6(node); - } - else { - emitFunctionBody(node); - } - if (!isES6ExportedDeclaration(node)) { - emitExportMemberAssignment(node); - } - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function emitFunctionBodyPreamble(node) { - emitCaptureThisForNodeIfNecessary(node); - emitDefaultValueAssignments(node); - emitRestParameter(node); - } - function emitExpressionFunctionBody(node, body) { - if (languageVersion < 2 || node.flags & 512) { - emitDownLevelExpressionFunctionBody(node, body); - return; - } - write(" "); - var current = body; - while (current.kind === 169) { - current = current.expression; - } - emitParenthesizedIf(body, current.kind === 163); - } - function emitDownLevelExpressionFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - increaseIndent(); - var outPos = writer.getTextPos(); - emitDetachedComments(node.body); - emitFunctionBodyPreamble(node); - var preambleEmitted = writer.getTextPos() !== outPos; - decreaseIndent(); - if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { - write(" "); - emitStart(body); - write("return "); - emit(body); - emitEnd(body); - write(";"); - emitTempDeclarations(false); - write(" "); - } - else { - increaseIndent(); - writeLine(); - emitLeadingComments(node.body); - write("return "); - emit(body); - write(";"); - emitTrailingComments(node.body); - emitTempDeclarations(true); - decreaseIndent(); - writeLine(); - } - emitStart(node.body); - write("}"); - emitEnd(node.body); - scopeEmitEnd(); - } - function emitBlockFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - var initialTextPos = writer.getTextPos(); - increaseIndent(); - emitDetachedComments(body.statements); - var startIndex = emitDirectivePrologues(body.statements, true); - emitFunctionBodyPreamble(node); - decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== initialTextPos; - if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { - for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { - var statement = _b[_a]; - write(" "); - emit(statement); - } - emitTempDeclarations(false); - write(" "); - emitLeadingCommentsOfPosition(body.statements.end); - } - else { - increaseIndent(); - emitLinesStartingAt(body.statements, startIndex); - emitTempDeclarations(true); - writeLine(); - emitLeadingCommentsOfPosition(body.statements.end); - decreaseIndent(); - } - emitToken(16, body.statements.end); - scopeEmitEnd(); - } - function findInitialSuperCall(ctor) { - if (ctor.body) { - var statement = ctor.body.statements[0]; - if (statement && statement.kind === 193) { - var expr = statement.expression; - if (expr && expr.kind === 166) { - var func = expr.expression; - if (func && func.kind === 93) { - return statement; - } - } - } - } - } - function emitParameterPropertyAssignments(node) { - ts.forEach(node.parameters, function (param) { - if (param.flags & 112) { - writeLine(); - emitStart(param); - emitStart(param.name); - write("this."); - emitNodeWithoutSourceMap(param.name); - emitEnd(param.name); - write(" = "); - emit(param.name); - write(";"); - emitEnd(param); - } - }); - } - function emitMemberAccessForPropertyName(memberName) { - if (memberName.kind === 9 || memberName.kind === 8) { - write("["); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - write("]"); - } - else if (memberName.kind === 134) { - emitComputedPropertyName(memberName); - } - else { - write("."); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - } - } - function getInitializedProperties(node, isStatic) { - var properties = []; - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if (member.kind === 139 && isStatic === ((member.flags & 128) !== 0) && member.initializer) { - properties.push(member); - } - } - return properties; - } - function emitPropertyDeclarations(node, properties) { - for (var _a = 0; _a < properties.length; _a++) { - var property = properties[_a]; - emitPropertyDeclaration(node, property); - } - } - function emitPropertyDeclaration(node, property, receiver, isExpression) { - writeLine(); - emitLeadingComments(property); - emitStart(property); - emitStart(property.name); - if (receiver) { - emit(receiver); - } - else { - if (property.flags & 128) { - emitDeclarationName(node); - } - else { - write("this"); - } - } - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - emit(property.initializer); - if (!isExpression) { - write(";"); - } - emitEnd(property); - emitTrailingComments(property); - } - function emitMemberFunctionsForES5AndLower(node) { - ts.forEach(node.members, function (member) { - if (member.kind === 189) { - writeLine(); - write(";"); - } - else if (member.kind === 141 || node.kind === 140) { - if (!member.body) { - return emitCommentsOnNotEmittedNode(member); - } - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - emitClassMemberPrefix(node, member); - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emitFunctionDeclaration(member); - emitEnd(member); - write(";"); - emitTrailingComments(member); - } - else if (member.kind === 143 || member.kind === 144) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member === accessors.firstAccessor) { - writeLine(); - emitStart(member); - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("});"); - emitEnd(member); - } - } - }); - } - function emitMemberFunctionsForES6AndHigher(node) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if ((member.kind === 141 || node.kind === 140) && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - else if (member.kind === 141 || - member.kind === 143 || - member.kind === 144) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - if (member.flags & 128) { - write("static "); - } - if (member.kind === 143) { - write("get "); - } - else if (member.kind === 144) { - write("set "); - } - if (member.asteriskToken) { - write("*"); - } - emit(member.name); - emitSignatureAndBody(member); - emitEnd(member); - emitTrailingComments(member); - } - else if (member.kind === 189) { - writeLine(); - write(";"); - } - } - } - function emitConstructor(node, baseTypeElement) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - emitConstructorWorker(node, baseTypeElement); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function emitConstructorWorker(node, baseTypeElement) { - var hasInstancePropertyWithInitializer = false; - ts.forEach(node.members, function (member) { - if (member.kind === 142 && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - if (member.kind === 139 && member.initializer && (member.flags & 128) === 0) { - hasInstancePropertyWithInitializer = true; - } - }); - var ctor = ts.getFirstConstructorWithBody(node); - if (languageVersion >= 2 && !ctor && !hasInstancePropertyWithInitializer) { - return; - } - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - if (languageVersion < 2) { - write("function "); - emitDeclarationName(node); - emitSignatureParameters(ctor); - } - else { - write("constructor"); - if (ctor) { - emitSignatureParameters(ctor); - } - else { - if (baseTypeElement) { - write("(...args)"); - } - else { - write("()"); - } - } - } - var startIndex = 0; - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - startIndex = emitDirectivePrologues(ctor.body.statements, true); - emitDetachedComments(ctor.body.statements); - } - emitCaptureThisForNodeIfNecessary(node); - var superCall; - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeElement) { - superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeElement) { - writeLine(); - emitStart(baseTypeElement); - if (languageVersion < 2) { - write("_super.apply(this, arguments);"); - } - else { - write("super(...args);"); - } - emitEnd(baseTypeElement); - } - } - emitPropertyDeclarations(node, getInitializedProperties(node, false)); - if (ctor) { - var statements = ctor.body.statements; - if (superCall) { - statements = statements.slice(1); - } - emitLinesStartingAt(statements, startIndex); - } - emitTempDeclarations(true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition(ctor.body.statements.end); - } - decreaseIndent(); - emitToken(16, ctor ? ctor.body.statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - } - function emitClassExpression(node) { - return emitClassLikeDeclaration(node); - } - function emitClassDeclaration(node) { - return emitClassLikeDeclaration(node); - } - function emitClassLikeDeclaration(node) { - if (languageVersion < 2) { - emitClassLikeDeclarationBelowES6(node); - } - else { - emitClassLikeDeclarationForES6AndHigher(node); - } - } - function emitClassLikeDeclarationForES6AndHigher(node) { - var thisNodeIsDecorated = ts.nodeIsDecorated(node); - if (node.kind === 212) { - if (thisNodeIsDecorated) { - if (isES6ExportedDeclaration(node) && !(node.flags & 1024)) { - write("export "); - } - write("let "); - emitDeclarationName(node); - write(" = "); - } - else if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024) { - write("default "); - } - } - } - var staticProperties = getInitializedProperties(node, true); - var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 184; - var tempVariable; - if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0); - write("("); - increaseIndent(); - emit(tempVariable); - write(" = "); - } - write("class"); - if ((node.name || !(node.flags & 1024)) && !thisNodeIsDecorated) { - write(" "); - emitDeclarationName(node); - } - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write(" extends "); - emit(baseTypeNode.expression); - } - write(" {"); - increaseIndent(); - scopeEmitStart(node); - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES6AndHigher(node); - decreaseIndent(); - writeLine(); - emitToken(16, node.members.end); - scopeEmitEnd(); - if (thisNodeIsDecorated) { - write(";"); - } - if (isClassExpressionWithStaticProperties) { - for (var _a = 0; _a < staticProperties.length; _a++) { - var property = staticProperties[_a]; - write(","); - writeLine(); - emitPropertyDeclaration(node, property, tempVariable, true); - } - write(","); - writeLine(); - emit(tempVariable); - decreaseIndent(); - write(")"); - } - else { - writeLine(); - emitPropertyDeclarations(node, staticProperties); - emitDecoratorsOfClass(node); - } - if (!isES6ExportedDeclaration(node) && (node.flags & 1)) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emitDeclarationName(node); - emitEnd(node); - write(";"); - } - else if (isES6ExportedDeclaration(node) && (node.flags & 1024) && thisNodeIsDecorated) { - writeLine(); - write("export default "); - emitDeclarationName(node); - write(";"); - } - } - function emitClassLikeDeclarationBelowES6(node) { - if (node.kind === 212) { - if (!shouldHoistDeclarationInSystemJsModule(node)) { - write("var "); - } - emitDeclarationName(node); - write(" = "); - } - write("(function ("); - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write("_super"); - } - write(") {"); - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - computedPropertyNamesToGeneratedNames = undefined; - increaseIndent(); - scopeEmitStart(node); - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("__extends("); - emitDeclarationName(node); - write(", _super);"); - emitEnd(baseTypeNode); - } - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES5AndLower(node); - emitPropertyDeclarations(node, getInitializedProperties(node, true)); - writeLine(); - emitDecoratorsOfClass(node); - writeLine(); - emitToken(16, node.members.end, function () { - write("return "); - emitDeclarationName(node); - }); - write(";"); - emitTempDeclarations(true); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; - decreaseIndent(); - writeLine(); - emitToken(16, node.members.end); - scopeEmitEnd(); - emitStart(node); - write(")("); - if (baseTypeNode) { - emit(baseTypeNode.expression); - } - write(")"); - if (node.kind === 212) { - write(";"); - } - emitEnd(node); - if (node.kind === 212) { - emitExportMemberAssignment(node); - } - if (languageVersion < 2 && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - } - function emitClassMemberPrefix(node, member) { - emitDeclarationName(node); - if (!(member.flags & 128)) { - write(".prototype"); - } - } - function emitDecoratorsOfClass(node) { - emitDecoratorsOfMembers(node, 0); - emitDecoratorsOfMembers(node, 128); - emitDecoratorsOfConstructor(node); - } - function emitDecoratorsOfConstructor(node) { - var decorators = node.decorators; - var constructor = ts.getFirstConstructorWithBody(node); - var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); - if (!decorators && !hasDecoratedParameters) { - return; - } - writeLine(); - emitStart(node); - emitDeclarationName(node); - write(" = __decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(constructor, argumentsWritten > 0); - emitSerializedTypeMetadata(node, argumentsWritten >= 0); - decreaseIndent(); - writeLine(); - write("], "); - emitDeclarationName(node); - write(");"); - emitEnd(node); - writeLine(); - } - function emitDecoratorsOfMembers(node, staticFlag) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if ((member.flags & 128) !== staticFlag) { - continue; - } - if (!ts.nodeCanBeDecorated(member)) { - continue; - } - if (!ts.nodeOrChildIsDecorated(member)) { - continue; - } - var decorators = void 0; - var functionLikeMember = void 0; - if (ts.isAccessor(member)) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member !== accessors.firstAccessor) { - continue; - } - decorators = accessors.firstAccessor.decorators; - if (!decorators && accessors.secondAccessor) { - decorators = accessors.secondAccessor.decorators; - } - functionLikeMember = accessors.setAccessor; - } - else { - decorators = member.decorators; - if (member.kind === 141) { - functionLikeMember = member; - } - } - writeLine(); - emitStart(member); - if (member.kind !== 139) { - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(","); - increaseIndent(); - writeLine(); - } - write("__decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); - emitSerializedTypeMetadata(member, argumentsWritten > 0); - decreaseIndent(); - writeLine(); - write("], "); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - if (member.kind !== 139) { - write(", Object.getOwnPropertyDescriptor("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write("))"); - decreaseIndent(); - } - write(");"); - emitEnd(member); - writeLine(); - } - } - function emitDecoratorsOfParameters(node, leadingComma) { - var argumentsWritten = 0; - if (node) { - var parameterIndex = 0; - for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { - var parameter = _b[_a]; - if (ts.nodeIsDecorated(parameter)) { - var decorators = parameter.decorators; - argumentsWritten += emitList(decorators, 0, decorators.length, true, false, leadingComma, true, function (decorator) { - emitStart(decorator); - write("__param(" + parameterIndex + ", "); - emit(decorator.expression); - write(")"); - emitEnd(decorator); - }); - leadingComma = true; - } - ++parameterIndex; - } - } - return argumentsWritten; - } - function shouldEmitTypeMetadata(node) { - switch (node.kind) { - case 141: - case 143: - case 144: - case 139: - return true; - } - return false; - } - function shouldEmitReturnTypeMetadata(node) { - switch (node.kind) { - case 141: - return true; - } - return false; - } - function shouldEmitParamTypesMetadata(node) { - switch (node.kind) { - case 212: - case 141: - case 144: - return true; - } - return false; - } - function emitSerializedTypeOfNode(node) { - switch (node.kind) { - case 212: - write("Function"); - return; - case 139: - emitSerializedTypeNode(node.type); - return; - case 136: - emitSerializedTypeNode(node.type); - return; - case 143: - emitSerializedTypeNode(node.type); - return; - case 144: - emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); - return; - } - if (ts.isFunctionLike(node)) { - write("Function"); - return; - } - write("void 0"); - } - function emitSerializedTypeNode(node) { - if (node) { - switch (node.kind) { - case 101: - write("void 0"); - return; - case 158: - emitSerializedTypeNode(node.type); - return; - case 150: - case 151: - write("Function"); - return; - case 154: - case 155: - write("Array"); - return; - case 148: - case 118: - write("Boolean"); - return; - case 128: - case 9: - write("String"); - return; - case 126: - write("Number"); - return; - case 129: - write("Symbol"); - return; - case 149: - emitSerializedTypeReferenceNode(node); - return; - case 152: - case 153: - case 156: - case 157: - case 115: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; - } - } - write("Object"); - } - function emitSerializedTypeReferenceNode(node) { - var location = node.parent; - while (ts.isDeclaration(location) || ts.isTypeNode(location)) { - location = location.parent; - } - var typeName = ts.cloneEntityName(node.typeName); - typeName.parent = location; - var result = resolver.getTypeReferenceSerializationKind(typeName); - switch (result) { - case ts.TypeReferenceSerializationKind.Unknown: - var temp = createAndRecordTempVariable(0); - write("(typeof ("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(typeName, true); - write(") === 'function' && "); - emitNodeWithoutSourceMap(temp); - write(") || Object"); - break; - case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - emitEntityNameAsExpression(typeName, false); - break; - case ts.TypeReferenceSerializationKind.VoidType: - write("void 0"); - break; - case ts.TypeReferenceSerializationKind.BooleanType: - write("Boolean"); - break; - case ts.TypeReferenceSerializationKind.NumberLikeType: - write("Number"); - break; - case ts.TypeReferenceSerializationKind.StringLikeType: - write("String"); - break; - case ts.TypeReferenceSerializationKind.ArrayLikeType: - write("Array"); - break; - case ts.TypeReferenceSerializationKind.ESSymbolType: - if (languageVersion < 2) { - write("typeof Symbol === 'function' ? Symbol : Object"); - } - else { - write("Symbol"); - } - break; - case ts.TypeReferenceSerializationKind.TypeWithCallSignature: - write("Function"); - break; - case ts.TypeReferenceSerializationKind.ObjectType: - write("Object"); - break; - } - } - function emitSerializedParameterTypesOfNode(node) { - if (node) { - var valueDeclaration; - if (node.kind === 212) { - valueDeclaration = ts.getFirstConstructorWithBody(node); - } - else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { - valueDeclaration = node; - } - if (valueDeclaration) { - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; - if (parameterCount > 0) { - for (var i = 0; i < parameterCount; i++) { - if (i > 0) { - write(", "); - } - if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; - if (parameterType.kind === 154) { - parameterType = parameterType.elementType; - } - else if (parameterType.kind === 149 && parameterType.typeArguments && parameterType.typeArguments.length === 1) { - parameterType = parameterType.typeArguments[0]; - } - else { - parameterType = undefined; - } - emitSerializedTypeNode(parameterType); - } - else { - emitSerializedTypeOfNode(parameters[i]); - } - } - } - } - } - } - function emitSerializedReturnTypeOfNode(node) { - if (node && ts.isFunctionLike(node) && node.type) { - emitSerializedTypeNode(node.type); - return; - } - write("void 0"); - } - function emitSerializedTypeMetadata(node, writeComma) { - var argumentsWritten = 0; - if (compilerOptions.emitDecoratorMetadata) { - if (shouldEmitTypeMetadata(node)) { - if (writeComma) { - write(", "); - } - writeLine(); - write("__metadata('design:type', "); - emitSerializedTypeOfNode(node); - write(")"); - argumentsWritten++; - } - if (shouldEmitParamTypesMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:paramtypes', ["); - emitSerializedParameterTypesOfNode(node); - write("])"); - argumentsWritten++; - } - if (shouldEmitReturnTypeMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:returntype', "); - emitSerializedReturnTypeOfNode(node); - write(")"); - argumentsWritten++; - } - } - return argumentsWritten; - } - function emitInterfaceDeclaration(node) { - emitCommentsOnNotEmittedNode(node); - } - function shouldEmitEnumDeclaration(node) { - var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; - } - function emitEnumDeclaration(node) { - if (!shouldEmitEnumDeclaration(node)) { - return; - } - if (!shouldHoistDeclarationInSystemJsModule(node)) { - if (!(node.flags & 1) || isES6ExportedDeclaration(node)) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - emitEnd(node); - write(";"); - } - } - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") {"); - increaseIndent(); - scopeEmitStart(node); - emitLines(node.members); - decreaseIndent(); - writeLine(); - emitToken(16, node.members.end); - scopeEmitEnd(); - write(")("); - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) { - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } - if (languageVersion < 2 && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 && (node.flags & 1)) { - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - function emitEnumMember(node) { - var enumParent = node.parent; - emitStart(node); - write(getGeneratedNameForNode(enumParent)); - write("["); - write(getGeneratedNameForNode(enumParent)); - write("["); - emitExpressionForPropertyName(node.name); - write("] = "); - writeEnumMemberDeclarationValue(node); - write("] = "); - emitExpressionForPropertyName(node.name); - emitEnd(node); - write(";"); - } - function writeEnumMemberDeclarationValue(member) { - var value = resolver.getConstantValue(member); - if (value !== undefined) { - write(value.toString()); - return; - } - else if (member.initializer) { - emit(member.initializer); - } - else { - write("undefined"); - } - } - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 216) { - var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); - } - function isModuleMergedWithES6Class(node) { - return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 32768); - } - function emitModuleDeclaration(node) { - var shouldEmit = shouldEmitModuleDeclaration(node); - if (!shouldEmit) { - return emitCommentsOnNotEmittedNode(node); - } - var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); - var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); - if (emitVarForModule) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - } - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") "); - if (node.body.kind === 217) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - tempFlags = 0; - tempVariables = undefined; - emit(node.body); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - } - else { - write("{"); - increaseIndent(); - scopeEmitStart(node); - emitCaptureThisForNodeIfNecessary(node); - writeLine(); - emit(node.body); - decreaseIndent(); - writeLine(); - var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; - emitToken(16, moduleBlock.statements.end); - scopeEmitEnd(); - } - write(")("); - if ((node.flags & 1) && !isES6ExportedDeclaration(node)) { - emit(node.name); - write(" = "); - } - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.name.kind === 67 && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 && (node.flags & 1)) { - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - function tryRenameExternalModule(moduleName) { - if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { - return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; - } - return undefined; - } - function emitRequire(moduleName) { - if (moduleName.kind === 9) { - write("require("); - var text = tryRenameExternalModule(moduleName); - if (text) { - write(text); - } - else { - emitStart(moduleName); - emitLiteral(moduleName); - emitEnd(moduleName); - } - emitToken(18, moduleName.end); - } - else { - write("require()"); - } - } - function getNamespaceDeclarationNode(node) { - if (node.kind === 219) { - return node; - } - var importClause = node.importClause; - if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 222) { - return importClause.namedBindings; - } - } - function isDefaultImport(node) { - return node.kind === 220 && node.importClause && !!node.importClause.name; - } - function emitExportImportAssignments(node) { - if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - emitExportMemberAssignments(node.name); - } - ts.forEachChild(node, emitExportImportAssignments); - } - function emitImportDeclaration(node) { - if (languageVersion < 2) { - return emitExternalImportDeclaration(node); - } - if (node.importClause) { - var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); - var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, true); - if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { - write("import "); - emitStart(node.importClause); - if (shouldEmitDefaultBindings) { - emit(node.importClause.name); - if (shouldEmitNamedBindings) { - write(", "); - } - } - if (shouldEmitNamedBindings) { - emitLeadingComments(node.importClause.namedBindings); - emitStart(node.importClause.namedBindings); - if (node.importClause.namedBindings.kind === 222) { - write("* as "); - emit(node.importClause.namedBindings.name); - } - else { - write("{ "); - emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); - write(" }"); - } - emitEnd(node.importClause.namedBindings); - emitTrailingComments(node.importClause.namedBindings); - } - emitEnd(node.importClause); - write(" from "); - emit(node.moduleSpecifier); - write(";"); - } - } - else { - write("import "); - emit(node.moduleSpecifier); - write(";"); - } - } - function emitExternalImportDeclaration(node) { - if (ts.contains(externalImports, node)) { - var isExportedImport = node.kind === 219 && (node.flags & 1) !== 0; - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (compilerOptions.module !== 2) { - emitLeadingComments(node); - emitStart(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - if (!isExportedImport) - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - } - else { - var isNakedImport = 220 && !node.importClause; - if (!isNakedImport) { - write("var "); - write(getGeneratedNameForNode(node)); - write(" = "); - } - } - emitRequire(ts.getExternalModuleName(node)); - if (namespaceDeclaration && isDefaultImport(node)) { - write(", "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - else { - if (isExportedImport) { - emitModuleMemberName(namespaceDeclaration); - write(" = "); - emit(namespaceDeclaration.name); - write(";"); - } - else if (namespaceDeclaration && isDefaultImport(node)) { - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - write(";"); - } - emitExportImportAssignments(node); - } - } - } - function emitImportEqualsDeclaration(node) { - if (ts.isExternalModuleImportEqualsDeclaration(node)) { - emitExternalImportDeclaration(node); - return; - } - if (resolver.isReferencedAliasDeclaration(node) || - (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { - emitLeadingComments(node); - emitStart(node); - var variableDeclarationIsHoisted = shouldHoistVariable(node, true); - var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, true); - if (!variableDeclarationIsHoisted) { - ts.Debug.assert(!isExported); - if (isES6ExportedDeclaration(node)) { - write("export "); - write("var "); - } - else if (!(node.flags & 1)) { - write("var "); - } - } - if (isExported) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.name); - write("\", "); - } - emitModuleMemberName(node); - write(" = "); - emit(node.moduleReference); - if (isExported) { - write(")"); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - } - function emitExportDeclaration(node) { - ts.Debug.assert(compilerOptions.module !== 4); - if (languageVersion < 2) { - if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { - emitStart(node); - var generatedName = getGeneratedNameForNode(node); - if (node.exportClause) { - if (compilerOptions.module !== 2) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(ts.getExternalModuleName(node)); - write(";"); - } - for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { - var specifier = _b[_a]; - if (resolver.isValueAliasDeclaration(specifier)) { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - } - } - } - else { - writeLine(); - write("__export("); - if (compilerOptions.module !== 2) { - emitRequire(ts.getExternalModuleName(node)); - } - else { - write(generatedName); - } - write(");"); - } - emitEnd(node); - } - } - else { - if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { - write("export "); - if (node.exportClause) { - write("{ "); - emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); - write(" }"); - } - else { - write("*"); - } - if (node.moduleSpecifier) { - write(" from "); - emit(node.moduleSpecifier); - } - write(";"); - } - } - } - function emitExportOrImportSpecifierList(specifiers, shouldEmit) { - ts.Debug.assert(languageVersion >= 2); - var needsComma = false; - for (var _a = 0; _a < specifiers.length; _a++) { - var specifier = specifiers[_a]; - if (shouldEmit(specifier)) { - if (needsComma) { - write(", "); - } - if (specifier.propertyName) { - emit(specifier.propertyName); - write(" as "); - } - emit(specifier.name); - needsComma = true; - } - } - } - function emitExportAssignment(node) { - if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - if (languageVersion >= 2) { - writeLine(); - emitStart(node); - write("export default "); - var expression = node.expression; - emit(expression); - if (expression.kind !== 211 && - expression.kind !== 212) { - write(";"); - } - emitEnd(node); - } - else { - writeLine(); - emitStart(node); - if (compilerOptions.module === 4) { - write(exportFunctionForFile + "(\"default\","); - emit(node.expression); - write(")"); - } - else { - emitEs6ExportDefaultCompat(node); - emitContainingModuleName(node); - if (languageVersion === 0) { - write("[\"default\"] = "); - } - else { - write(".default = "); - } - emit(node.expression); - } - write(";"); - emitEnd(node); - } - } - } - function collectExternalModuleInfo(sourceFile) { - externalImports = []; - exportSpecifiers = {}; - exportEquals = undefined; - hasExportStars = false; - for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { - var node = _b[_a]; - switch (node.kind) { - case 220: - if (!node.importClause || - resolver.isReferencedAliasDeclaration(node.importClause, true)) { - externalImports.push(node); - } - break; - case 219: - if (node.moduleReference.kind === 230 && resolver.isReferencedAliasDeclaration(node)) { - externalImports.push(node); - } - break; - case 226: - if (node.moduleSpecifier) { - if (!node.exportClause) { - externalImports.push(node); - hasExportStars = true; - } - else if (resolver.isValueAliasDeclaration(node)) { - externalImports.push(node); - } - } - else { - for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { - var specifier = _d[_c]; - var name_24 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); - } - } - break; - case 225: - if (node.isExportEquals && !exportEquals) { - exportEquals = node; - } - break; - } - } - } - function emitExportStarHelper() { - if (hasExportStars) { - writeLine(); - write("function __export(m) {"); - increaseIndent(); - writeLine(); - write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function getLocalNameForExternalImport(node) { - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); - } - if (node.kind === 220 && node.importClause) { - return getGeneratedNameForNode(node); - } - if (node.kind === 226 && node.moduleSpecifier) { - return getGeneratedNameForNode(node); - } - } - function getExternalModuleNameText(importNode) { - var moduleName = ts.getExternalModuleName(importNode); - if (moduleName.kind === 9) { - return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); - } - return undefined; - } - function emitVariableDeclarationsForImports() { - if (externalImports.length === 0) { - return; - } - writeLine(); - var started = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var importNode = externalImports[_a]; - var skipNode = importNode.kind === 226 || - (importNode.kind === 220 && !importNode.importClause); - if (skipNode) { - continue; - } - if (!started) { - write("var "); - started = true; - } - else { - write(", "); - } - write(getLocalNameForExternalImport(importNode)); - } - if (started) { - write(";"); - } - } - function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { - if (!hasExportStars) { - return undefined; - } - if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { - var hasExportDeclarationWithExportClause = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var externalImport = externalImports[_a]; - if (externalImport.kind === 226 && externalImport.exportClause) { - hasExportDeclarationWithExportClause = true; - break; - } - } - if (!hasExportDeclarationWithExportClause) { - return emitExportStarFunction(undefined); - } - } - var exportedNamesStorageRef = makeUniqueName("exportedNames"); - writeLine(); - write("var " + exportedNamesStorageRef + " = {"); - increaseIndent(); - var started = false; - if (exportedDeclarations) { - for (var i = 0; i < exportedDeclarations.length; ++i) { - writeExportedName(exportedDeclarations[i]); - } - } - if (exportSpecifiers) { - for (var n in exportSpecifiers) { - for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { - var specifier = _c[_b]; - writeExportedName(specifier.name); - } - } - } - for (var _d = 0; _d < externalImports.length; _d++) { - var externalImport = externalImports[_d]; - if (externalImport.kind !== 226) { - continue; - } - var exportDecl = externalImport; - if (!exportDecl.exportClause) { - continue; - } - for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { - var element = _f[_e]; - writeExportedName(element.name || element.propertyName); - } - } - decreaseIndent(); - writeLine(); - write("};"); - return emitExportStarFunction(exportedNamesStorageRef); - function emitExportStarFunction(localNames) { - var exportStarFunction = makeUniqueName("exportStar"); - writeLine(); - write("function " + exportStarFunction + "(m) {"); - increaseIndent(); - writeLine(); - write("var exports = {};"); - writeLine(); - write("for(var n in m) {"); - increaseIndent(); - writeLine(); - write("if (n !== \"default\""); - if (localNames) { - write("&& !" + localNames + ".hasOwnProperty(n)"); - } - write(") exports[n] = m[n];"); - decreaseIndent(); - writeLine(); - write("}"); - writeLine(); - write(exportFunctionForFile + "(exports);"); - decreaseIndent(); - writeLine(); - write("}"); - return exportStarFunction; - } - function writeExportedName(node) { - if (node.kind !== 67 && node.flags & 1024) { - return; - } - if (started) { - write(","); - } - else { - started = true; - } - writeLine(); - write("'"); - if (node.kind === 67) { - emitNodeWithCommentsAndWithoutSourcemap(node); - } - else { - emitDeclarationName(node); - } - write("': true"); - } - } - function processTopLevelVariableAndFunctionDeclarations(node) { - var hoistedVars; - var hoistedFunctionDeclarations; - var exportedDeclarations; - visit(node); - if (hoistedVars) { - writeLine(); - write("var "); - var seen = {}; - for (var i = 0; i < hoistedVars.length; ++i) { - var local = hoistedVars[i]; - var name_25 = local.kind === 67 - ? local - : local.name; - if (name_25) { - var text = ts.unescapeIdentifier(name_25.text); - if (ts.hasProperty(seen, text)) { - continue; - } - else { - seen[text] = text; - } - } - if (i !== 0) { - write(", "); - } - if (local.kind === 212 || local.kind === 216 || local.kind === 215) { - emitDeclarationName(local); - } - else { - emit(local); - } - var flags = ts.getCombinedNodeFlags(local.kind === 67 ? local.parent : local); - if (flags & 1) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(local); - } - } - write(";"); - } - if (hoistedFunctionDeclarations) { - for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { - var f = hoistedFunctionDeclarations[_a]; - writeLine(); - emit(f); - if (f.flags & 1) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(f); - } - } - } - return exportedDeclarations; - function visit(node) { - if (node.flags & 2) { - return; - } - if (node.kind === 211) { - if (!hoistedFunctionDeclarations) { - hoistedFunctionDeclarations = []; - } - hoistedFunctionDeclarations.push(node); - return; - } - if (node.kind === 212) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - return; - } - if (node.kind === 215) { - if (shouldEmitEnumDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 216) { - if (shouldEmitModuleDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 209 || node.kind === 161) { - if (shouldHoistVariable(node, false)) { - var name_26 = node.name; - if (name_26.kind === 67) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(name_26); - } - else { - ts.forEachChild(name_26, visit); - } - } - return; - } - if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node.name); - return; - } - if (ts.isBindingPattern(node)) { - ts.forEach(node.elements, visit); - return; - } - if (!ts.isDeclaration(node)) { - ts.forEachChild(node, visit); - } - } - } - function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { - if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { - return false; - } - return (ts.getCombinedNodeFlags(node) & 49152) === 0 || - ts.getEnclosingBlockScopeContainer(node).kind === 246; - } - function isCurrentFileSystemExternalModule() { - return compilerOptions.module === 4 && ts.isExternalModule(currentSourceFile); - } - function emitSystemModuleBody(node, dependencyGroups, startIndex) { - emitVariableDeclarationsForImports(); - writeLine(); - var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); - var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); - writeLine(); - write("return {"); - increaseIndent(); - writeLine(); - emitSetters(exportStarFunction, dependencyGroups); - writeLine(); - emitExecute(node, startIndex); - decreaseIndent(); - writeLine(); - write("}"); - emitTempDeclarations(true); - } - function emitSetters(exportStarFunction, dependencyGroups) { - write("setters:["); - for (var i = 0; i < dependencyGroups.length; ++i) { - if (i !== 0) { - write(","); - } - writeLine(); - increaseIndent(); - var group = dependencyGroups[i]; - var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); - write("function (" + parameterName + ") {"); - increaseIndent(); - for (var _a = 0; _a < group.length; _a++) { - var entry = group[_a]; - var importVariableName = getLocalNameForExternalImport(entry) || ""; - switch (entry.kind) { - case 220: - if (!entry.importClause) { - break; - } - case 219: - ts.Debug.assert(importVariableName !== ""); - writeLine(); - write(importVariableName + " = " + parameterName + ";"); - writeLine(); - break; - case 226: - ts.Debug.assert(importVariableName !== ""); - if (entry.exportClause) { - writeLine(); - write(exportFunctionForFile + "({"); - writeLine(); - increaseIndent(); - for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { - if (i_2 !== 0) { - write(","); - writeLine(); - } - var e = entry.exportClause.elements[i_2]; - write("\""); - emitNodeWithCommentsAndWithoutSourcemap(e.name); - write("\": " + parameterName + "[\""); - emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); - write("\"]"); - } - decreaseIndent(); - writeLine(); - write("});"); - } - else { - writeLine(); - write(exportStarFunction + "(" + parameterName + ");"); - } - writeLine(); - break; - } - } - decreaseIndent(); - write("}"); - decreaseIndent(); - } - write("],"); - } - function emitExecute(node, startIndex) { - write("execute: function() {"); - increaseIndent(); - writeLine(); - for (var i = startIndex; i < node.statements.length; ++i) { - var statement = node.statements[i]; - switch (statement.kind) { - case 211: - case 220: - continue; - case 226: - if (!statement.moduleSpecifier) { - for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { - var element = _b[_a]; - emitExportSpecifierInSystemModule(element); - } - } - continue; - case 219: - if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { - continue; - } - default: - writeLine(); - emit(statement); - } - } - decreaseIndent(); - writeLine(); - write("}"); - } - function emitSystemModule(node, startIndex) { - collectExternalModuleInfo(node); - ts.Debug.assert(!exportFunctionForFile); - exportFunctionForFile = makeUniqueName("exports"); - writeLine(); - write("System.register("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - write("["); - var groupIndices = {}; - var dependencyGroups = []; - for (var i = 0; i < externalImports.length; ++i) { - var text = getExternalModuleNameText(externalImports[i]); - if (ts.hasProperty(groupIndices, text)) { - var groupIndex = groupIndices[text]; - dependencyGroups[groupIndex].push(externalImports[i]); - continue; - } - else { - groupIndices[text] = dependencyGroups.length; - dependencyGroups.push([externalImports[i]]); - } - if (i !== 0) { - write(", "); - } - write(text); - } - write("], function(" + exportFunctionForFile + ") {"); - writeLine(); - increaseIndent(); - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitSystemModuleBody(node, dependencyGroups, startIndex); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitAMDDependencies(node, includeNonAmdDependencies) { - var aliasedModuleNames = []; - var unaliasedModuleNames = []; - var importAliasNames = []; - for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { - var amdDependency = _b[_a]; - if (amdDependency.name) { - aliasedModuleNames.push("\"" + amdDependency.path + "\""); - importAliasNames.push(amdDependency.name); - } - else { - unaliasedModuleNames.push("\"" + amdDependency.path + "\""); - } - } - for (var _c = 0; _c < externalImports.length; _c++) { - var importNode = externalImports[_c]; - var externalModuleName = getExternalModuleNameText(importNode); - var importAliasName = getLocalNameForExternalImport(importNode); - if (includeNonAmdDependencies && importAliasName) { - aliasedModuleNames.push(externalModuleName); - importAliasNames.push(importAliasName); - } - else { - unaliasedModuleNames.push(externalModuleName); - } - } - write("[\"require\", \"exports\""); - if (aliasedModuleNames.length) { - write(", "); - write(aliasedModuleNames.join(", ")); - } - if (unaliasedModuleNames.length) { - write(", "); - write(unaliasedModuleNames.join(", ")); - } - write("], function (require, exports"); - if (importAliasNames.length) { - write(", "); - write(importAliasNames.join(", ")); - } - } - function emitAMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - writeLine(); - write("define("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - emitAMDDependencies(node, true); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - emitExportEquals(true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitCommonJSModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - emitExportEquals(false); - } - function emitUMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - writeLines("(function (deps, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define(deps, factory);\n }\n})("); - emitAMDDependencies(node, false); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - emitExportEquals(true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitES6Module(node, startIndex) { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - } - function emitExportEquals(emitAsReturn) { - if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { - writeLine(); - emitStart(exportEquals); - write(emitAsReturn ? "return " : "module.exports = "); - emit(exportEquals.expression); - write(";"); - emitEnd(exportEquals); - } - } - function emitJsxElement(node) { - switch (compilerOptions.jsx) { - case 2: - jsxEmitReact(node); - break; - case 1: - default: - jsxEmitPreserve(node); - break; - } - } - function trimReactWhitespaceAndApplyEntities(node) { - var result = undefined; - var text = ts.getTextOfNode(node, true); - var firstNonWhitespace = 0; - var lastNonWhitespace = -1; - for (var i = 0; i < text.length; i++) { - var c = text.charCodeAt(i); - if (ts.isLineBreak(c)) { - if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { - var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - firstNonWhitespace = -1; - } - else if (!ts.isWhiteSpace(c)) { - lastNonWhitespace = i; - if (firstNonWhitespace === -1) { - firstNonWhitespace = i; - } - } - } - if (firstNonWhitespace !== -1) { - var part = text.substr(firstNonWhitespace); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - if (result) { - result = result.replace(/&(\w+);/g, function (s, m) { - if (entities[m] !== undefined) { - return String.fromCharCode(entities[m]); - } - else { - return s; - } - }); - } - return result; - } - function getTextToEmit(node) { - switch (compilerOptions.jsx) { - case 2: - var text = trimReactWhitespaceAndApplyEntities(node); - if (text === undefined || text.length === 0) { - return undefined; - } - else { - return text; - } - case 1: - default: - return ts.getTextOfNode(node, true); - } - } - function emitJsxText(node) { - switch (compilerOptions.jsx) { - case 2: - write("\""); - write(trimReactWhitespaceAndApplyEntities(node)); - write("\""); - break; - case 1: - default: - writer.writeLiteral(ts.getTextOfNode(node, true)); - break; - } - } - function emitJsxExpression(node) { - if (node.expression) { - switch (compilerOptions.jsx) { - case 1: - default: - write("{"); - emit(node.expression); - write("}"); - break; - case 2: - emit(node.expression); - break; - } - } - } - function emitDirectivePrologues(statements, startWithNewLine) { - for (var i = 0; i < statements.length; ++i) { - if (ts.isPrologueDirective(statements[i])) { - if (startWithNewLine || i > 0) { - writeLine(); - } - emit(statements[i]); - } - else { - return i; - } - } - return statements.length; - } - function writeLines(text) { - var lines = text.split(/\r\n|\r|\n/g); - for (var i = 0; i < lines.length; ++i) { - var line = lines[i]; - if (line.length) { - writeLine(); - write(line); - } - } - } - function emitEmitHelpers(node) { - if (!compilerOptions.noEmitHelpers) { - if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) { - writeLines(extendsHelper); - extendsEmitted = true; - } - if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16) { - writeLines(decorateHelper); - if (compilerOptions.emitDecoratorMetadata) { - writeLines(metadataHelper); - } - decorateEmitted = true; - } - if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32) { - writeLines(paramHelper); - paramEmitted = true; - } - if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64) { - writeLines(awaiterHelper); - awaiterEmitted = true; - } - } - } - function emitSourceFileNode(node) { - writeLine(); - emitShebang(); - emitDetachedComments(node); - var startIndex = emitDirectivePrologues(node.statements, false); - if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { - if (languageVersion >= 2) { - emitES6Module(node, startIndex); - } - else if (compilerOptions.module === 2) { - emitAMDModule(node, startIndex); - } - else if (compilerOptions.module === 4) { - emitSystemModule(node, startIndex); - } - else if (compilerOptions.module === 3) { - emitUMDModule(node, startIndex); - } - else { - emitCommonJSModule(node, startIndex); - } - } - else { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - } - emitLeadingComments(node.endOfFileToken); - } - function emitNodeWithCommentsAndWithoutSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); - } - function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { - if (node) { - if (node.flags & 2) { - return emitCommentsOnNotEmittedNode(node); - } - if (isSpecializedCommentHandling(node)) { - return emitNodeWithoutSourceMap(node); - } - var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); - if (emitComments_1) { - emitLeadingComments(node); - } - emitNodeConsideringSourcemap(node); - if (emitComments_1) { - emitTrailingComments(node); - } - } - } - function emitNodeWithoutSourceMap(node) { - if (node) { - emitJavaScriptWorker(node); - } - } - function isSpecializedCommentHandling(node) { - switch (node.kind) { - case 213: - case 211: - case 220: - case 219: - case 214: - case 225: - return true; - } - } - function shouldEmitLeadingAndTrailingComments(node) { - switch (node.kind) { - case 191: - return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); - case 216: - return shouldEmitModuleDeclaration(node); - case 215: - return shouldEmitEnumDeclaration(node); - } - ts.Debug.assert(!isSpecializedCommentHandling(node)); - if (node.kind !== 190 && - node.parent && - node.parent.kind === 172 && - node.parent.body === node && - compilerOptions.target <= 1) { - return false; - } - return true; - } - function emitJavaScriptWorker(node) { - switch (node.kind) { - case 67: - return emitIdentifier(node); - case 136: - return emitParameter(node); - case 141: - case 140: - return emitMethod(node); - case 143: - case 144: - return emitAccessor(node); - case 95: - return emitThis(node); - case 93: - return emitSuper(node); - case 91: - return write("null"); - case 97: - return write("true"); - case 82: - return write("false"); - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - return emitLiteral(node); - case 181: - return emitTemplateExpression(node); - case 188: - return emitTemplateSpan(node); - case 231: - case 232: - return emitJsxElement(node); - case 234: - return emitJsxText(node); - case 238: - return emitJsxExpression(node); - case 133: - return emitQualifiedName(node); - case 159: - return emitObjectBindingPattern(node); - case 160: - return emitArrayBindingPattern(node); - case 161: - return emitBindingElement(node); - case 162: - return emitArrayLiteral(node); - case 163: - return emitObjectLiteral(node); - case 243: - return emitPropertyAssignment(node); - case 244: - return emitShorthandPropertyAssignment(node); - case 134: - return emitComputedPropertyName(node); - case 164: - return emitPropertyAccess(node); - case 165: - return emitIndexedAccess(node); - case 166: - return emitCallExpression(node); - case 167: - return emitNewExpression(node); - case 168: - return emitTaggedTemplateExpression(node); - case 169: - return emit(node.expression); - case 187: - return emit(node.expression); - case 170: - return emitParenExpression(node); - case 211: - case 171: - case 172: - return emitFunctionDeclaration(node); - case 173: - return emitDeleteExpression(node); - case 174: - return emitTypeOfExpression(node); - case 175: - return emitVoidExpression(node); - case 176: - return emitAwaitExpression(node); - case 177: - return emitPrefixUnaryExpression(node); - case 178: - return emitPostfixUnaryExpression(node); - case 179: - return emitBinaryExpression(node); - case 180: - return emitConditionalExpression(node); - case 183: - return emitSpreadElementExpression(node); - case 182: - return emitYieldExpression(node); - case 185: - return; - case 190: - case 217: - return emitBlock(node); - case 191: - return emitVariableStatement(node); - case 192: - return write(";"); - case 193: - return emitExpressionStatement(node); - case 194: - return emitIfStatement(node); - case 195: - return emitDoStatement(node); - case 196: - return emitWhileStatement(node); - case 197: - return emitForStatement(node); - case 199: - case 198: - return emitForInOrForOfStatement(node); - case 200: - case 201: - return emitBreakOrContinueStatement(node); - case 202: - return emitReturnStatement(node); - case 203: - return emitWithStatement(node); - case 204: - return emitSwitchStatement(node); - case 239: - case 240: - return emitCaseOrDefaultClause(node); - case 205: - return emitLabelledStatement(node); - case 206: - return emitThrowStatement(node); - case 207: - return emitTryStatement(node); - case 242: - return emitCatchClause(node); - case 208: - return emitDebuggerStatement(node); - case 209: - return emitVariableDeclaration(node); - case 184: - return emitClassExpression(node); - case 212: - return emitClassDeclaration(node); - case 213: - return emitInterfaceDeclaration(node); - case 215: - return emitEnumDeclaration(node); - case 245: - return emitEnumMember(node); - case 216: - return emitModuleDeclaration(node); - case 220: - return emitImportDeclaration(node); - case 219: - return emitImportEqualsDeclaration(node); - case 226: - return emitExportDeclaration(node); - case 225: - return emitExportAssignment(node); - case 246: - return emitSourceFileNode(node); - } - } - function hasDetachedComments(pos) { - return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; - } - function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); - if (detachedCommentsInfo.length - 1) { - detachedCommentsInfo.pop(); - } - else { - detachedCommentsInfo = undefined; - } - return leadingComments; - } - function isPinnedComments(comment) { - return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 33; - } - function isTripleSlashComment(comment) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 47) { - var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); - return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || - textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? - true : false; - } - return false; - } - function getLeadingCommentsToEmit(node) { - if (node.parent) { - if (node.parent.kind === 246 || node.pos !== node.parent.pos) { - if (hasDetachedComments(node.pos)) { - return getLeadingCommentsWithoutDetachedComments(); - } - else { - return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - } - } - } - function getTrailingCommentsToEmit(node) { - if (node.parent) { - if (node.parent.kind === 246 || node.end !== node.parent.end) { - return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - } - } - } - function emitCommentsOnNotEmittedNode(node) { - emitLeadingCommentsWorker(node, false); - } - function emitLeadingComments(node) { - return emitLeadingCommentsWorker(node, true); - } - function emitLeadingCommentsWorker(node, isEmittedNode) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (isEmittedNode) { - leadingComments = getLeadingCommentsToEmit(node); - } - else { - if (node.pos === 0) { - leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); - } - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitTrailingComments(node) { - if (compilerOptions.removeComments) { - return; - } - var trailingComments = getTrailingCommentsToEmit(node); - ts.emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); - } - function emitTrailingCommentsOfPosition(pos) { - if (compilerOptions.removeComments) { - return; - } - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); - ts.emitComments(currentSourceFile, writer, trailingComments, true, newLine, writeComment); - } - function emitLeadingCommentsOfPositionWorker(pos) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (hasDetachedComments(pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); - ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitDetachedComments(node) { - var leadingComments; - if (compilerOptions.removeComments) { - if (node.pos === 0) { - leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); - } - } - else { - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); - } - if (leadingComments) { - var detachedComments = []; - var lastComment; - ts.forEach(leadingComments, function (comment) { - if (lastComment) { - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); - var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); - if (commentLine >= lastCommentLine + 2) { - return detachedComments; - } - } - detachedComments.push(comment); - lastComment = comment; - }); - if (detachedComments.length) { - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); - var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - if (nodeLine >= lastCommentLine + 2) { - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - ts.emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); - var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; - if (detachedCommentsInfo) { - detachedCommentsInfo.push(currentDetachedCommentInfo); - } - else { - detachedCommentsInfo = [currentDetachedCommentInfo]; - } - } - } - } - } - function emitShebang() { - var shebang = ts.getShebang(currentSourceFile.text); - if (shebang) { - write(shebang); - } - } - } - function emitFile(jsFilePath, sourceFile) { - emitJavaScript(jsFilePath, sourceFile); - if (compilerOptions.declaration) { - ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); - } - } - } - ts.emitFiles = emitFiles; var entities = { "quot": 0x0022, "amp": 0x0026, @@ -29322,6 +24297,5552 @@ var ts; "hearts": 0x2665, "diams": 0x2666 }; + function emitFiles(resolver, host, targetSourceFile) { + var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; + var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};"; + var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; + var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; + var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; + var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 ? 5 : 0; + var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; + var diagnostics = []; + var newLine = host.getNewLine(); + var jsxDesugaring = host.getCompilerOptions().jsx !== 1; + var shouldEmitJsx = function (s) { return (s.languageVariant === 1 && !jsxDesugaring); }; + if (targetSourceFile === undefined) { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, sourceFile); + } + }); + if (compilerOptions.outFile || compilerOptions.out) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + else { + if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); + return { + emitSkipped: false, + diagnostics: diagnostics, + sourceMaps: sourceMapDataList + }; + function isNodeDescendentOf(node, ancestor) { + while (node) { + if (node === ancestor) + return true; + node = node.parent; + } + return false; + } + function isUniqueLocalName(name, container) { + for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + if (node.locals && ts.hasProperty(node.locals, name)) { + if (node.locals[name].flags & (107455 | 1048576 | 8388608)) { + return false; + } + } + } + return true; + } + function emitJavaScript(jsFilePath, root) { + var writer = ts.createTextWriter(newLine); + var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; + var currentSourceFile; + var exportFunctionForFile; + var generatedNameSet = {}; + var nodeToGeneratedName = []; + var computedPropertyNamesToGeneratedNames; + var extendsEmitted = false; + var decorateEmitted = false; + var paramEmitted = false; + var awaiterEmitted = false; + var tempFlags = 0; + var tempVariables; + var tempParameters; + var externalImports; + var exportSpecifiers; + var exportEquals; + var hasExportStars; + var writeEmittedFiles = writeJavaScriptFile; + var detachedCommentsInfo; + var writeComment = ts.writeCommentRange; + var emit = emitNodeWithCommentsAndWithoutSourcemap; + var emitStart = function (node) { }; + var emitEnd = function (node) { }; + var emitToken = emitTokenText; + var scopeEmitStart = function (scopeDeclaration, scopeName) { }; + var scopeEmitEnd = function () { }; + var sourceMapData; + var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; + var moduleEmitDelegates = (_a = {}, + _a[5] = emitES6Module, + _a[2] = emitAMDModule, + _a[4] = emitSystemModule, + _a[3] = emitUMDModule, + _a[1] = emitCommonJSModule, + _a + ); + if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { + initializeEmitterWithSourceMaps(); + } + if (root) { + emitSourceFile(root); + } + else { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + emitSourceFile(sourceFile); + } + }); + } + writeLine(); + writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); + return; + function emitSourceFile(sourceFile) { + currentSourceFile = sourceFile; + exportFunctionForFile = undefined; + emit(sourceFile); + } + function isUniqueName(name) { + return !resolver.hasGlobalName(name) && + !ts.hasProperty(currentSourceFile.identifiers, name) && + !ts.hasProperty(generatedNameSet, name); + } + function makeTempVariableName(flags) { + if (flags && !(tempFlags & flags)) { + var name_19 = flags === 268435456 ? "_i" : "_n"; + if (isUniqueName(name_19)) { + tempFlags |= flags; + return name_19; + } + } + while (true) { + var count = tempFlags & 268435455; + tempFlags++; + if (count !== 8 && count !== 13) { + var name_20 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_20)) { + return name_20; + } + } + } + } + function makeUniqueName(baseName) { + if (baseName.charCodeAt(baseName.length - 1) !== 95) { + baseName += "_"; + } + var i = 1; + while (true) { + var generatedName = baseName + i; + if (isUniqueName(generatedName)) { + return generatedNameSet[generatedName] = generatedName; + } + i++; + } + } + function generateNameForModuleOrEnum(node) { + var name = node.name.text; + return isUniqueLocalName(name, node) ? name : makeUniqueName(name); + } + function generateNameForImportOrExportDeclaration(node) { + var expr = ts.getExternalModuleName(node); + var baseName = expr.kind === 9 ? + ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; + return makeUniqueName(baseName); + } + function generateNameForExportDefault() { + return makeUniqueName("default"); + } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } + function generateNameForNode(node) { + switch (node.kind) { + case 69: + return makeUniqueName(node.text); + case 218: + case 217: + return generateNameForModuleOrEnum(node); + case 222: + case 228: + return generateNameForImportOrExportDeclaration(node); + case 213: + case 214: + case 227: + return generateNameForExportDefault(); + case 186: + return generateNameForClassExpression(); + } + } + function getGeneratedNameForNode(node) { + var id = ts.getNodeId(node); + return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); + } + function initializeEmitterWithSourceMaps() { + var sourceMapDir; + var sourceMapSourceIndex = -1; + var sourceMapNameIndexMap = {}; + var sourceMapNameIndices = []; + function getSourceMapNameIndex() { + return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; + } + var lastRecordedSourceMapSpan; + var lastEncodedSourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; + var lastEncodedNameIndex = 0; + function encodeLastRecordedSourceMapSpan() { + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { + return; + } + var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; + if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { + if (sourceMapData.sourceMapMappings) { + sourceMapData.sourceMapMappings += ","; + } + } + else { + for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { + sourceMapData.sourceMapMappings += ";"; + } + prevEncodedEmittedColumn = 1; + } + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); + if (lastRecordedSourceMapSpan.nameIndex >= 0) { + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); + lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; + } + lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; + sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); + function base64VLQFormatEncode(inValue) { + function base64FormatEncode(inValue) { + if (inValue < 64) { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); + } + throw TypeError(inValue + ": not a 64 based value"); + } + if (inValue < 0) { + inValue = ((-inValue) << 1) + 1; + } + else { + inValue = inValue << 1; + } + var encodedStr = ""; + do { + var currentDigit = inValue & 31; + inValue = inValue >> 5; + if (inValue > 0) { + currentDigit = currentDigit | 32; + } + encodedStr = encodedStr + base64FormatEncode(currentDigit); + } while (inValue > 0); + return encodedStr; + } + } + function recordSourceMapSpan(pos) { + var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); + sourceLinePos.line++; + sourceLinePos.character++; + var emittedLine = writer.getLine(); + var emittedColumn = writer.getColumn(); + if (!lastRecordedSourceMapSpan || + lastRecordedSourceMapSpan.emittedLine !== emittedLine || + lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || + (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + encodeLastRecordedSourceMapSpan(); + lastRecordedSourceMapSpan = { + emittedLine: emittedLine, + emittedColumn: emittedColumn, + sourceLine: sourceLinePos.line, + sourceColumn: sourceLinePos.character, + nameIndex: getSourceMapNameIndex(), + sourceIndex: sourceMapSourceIndex + }; + } + else { + lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; + lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; + lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; + } + } + function recordEmitNodeStartSpan(node) { + recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); + } + function recordEmitNodeEndSpan(node) { + recordSourceMapSpan(node.end); + } + function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + function recordNewSourceFileStart(node) { + var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, true)); + sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; + sourceMapData.inputSourceFileNames.push(node.fileName); + if (compilerOptions.inlineSources) { + if (!sourceMapData.sourceMapSourcesContent) { + sourceMapData.sourceMapSourcesContent = []; + } + sourceMapData.sourceMapSourcesContent.push(node.text); + } + } + function recordScopeNameOfNode(node, scopeName) { + function recordScopeNameIndex(scopeNameIndex) { + sourceMapNameIndices.push(scopeNameIndex); + } + function recordScopeNameStart(scopeName) { + var scopeNameIndex = -1; + if (scopeName) { + var parentIndex = getSourceMapNameIndex(); + if (parentIndex !== -1) { + var name_21 = node.name; + if (!name_21 || name_21.kind !== 136) { + scopeName = "." + scopeName; + } + scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; + } + scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); + if (scopeNameIndex === undefined) { + scopeNameIndex = sourceMapData.sourceMapNames.length; + sourceMapData.sourceMapNames.push(scopeName); + sourceMapNameIndexMap[scopeName] = scopeNameIndex; + } + } + recordScopeNameIndex(scopeNameIndex); + } + if (scopeName) { + recordScopeNameStart(scopeName); + } + else if (node.kind === 213 || + node.kind === 173 || + node.kind === 143 || + node.kind === 142 || + node.kind === 145 || + node.kind === 146 || + node.kind === 218 || + node.kind === 214 || + node.kind === 217) { + if (node.name) { + var name_22 = node.name; + scopeName = name_22.kind === 136 + ? ts.getTextOfNode(name_22) + : node.name.text; + } + recordScopeNameStart(scopeName); + } + else { + recordScopeNameIndex(getSourceMapNameIndex()); + } + } + function recordScopeNameEnd() { + sourceMapNameIndices.pop(); + } + ; + function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { + recordSourceMapSpan(comment.pos); + ts.writeCommentRange(currentSourceFile, writer, comment, newLine); + recordSourceMapSpan(comment.end); + } + function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { + if (typeof JSON !== "undefined") { + var map_1 = { + version: version, + file: file, + sourceRoot: sourceRoot, + sources: sources, + names: names, + mappings: mappings + }; + if (sourcesContent !== undefined) { + map_1.sourcesContent = sourcesContent; + } + return JSON.stringify(map_1); + } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; + function serializeStringArray(list) { + var output = ""; + for (var i = 0, n = list.length; i < n; i++) { + if (i) { + output += ","; + } + output += "\"" + ts.escapeString(list[i]) + "\""; + } + return output; + } + } + function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { + encodeLastRecordedSourceMapSpan(); + var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); + sourceMapDataList.push(sourceMapData); + var sourceMapUrl; + if (compilerOptions.inlineSourceMap) { + var base64SourceMapText = ts.convertToBase64(sourceMapText); + sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; + } + else { + ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, false); + sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; + } + writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); + } + var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); + sourceMapData = { + sourceMapFilePath: jsFilePath + ".map", + jsSourceMappingURL: sourceMapJsFile + ".map", + sourceMapFile: sourceMapJsFile, + sourceMapSourceRoot: compilerOptions.sourceRoot || "", + sourceMapSources: [], + inputSourceFileNames: [], + sourceMapNames: [], + sourceMapMappings: "", + sourceMapSourcesContent: undefined, + sourceMapDecodedMappings: [] + }; + sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); + if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47) { + sourceMapData.sourceMapSourceRoot += ts.directorySeparator; + } + if (compilerOptions.mapRoot) { + sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); + if (root) { + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); + } + if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { + sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true); + } + else { + sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); + } + } + else { + sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); + } + function emitNodeWithSourceMap(node) { + if (node) { + if (ts.nodeIsSynthesized(node)) { + return emitNodeWithoutSourceMap(node); + } + if (node.kind !== 248) { + recordEmitNodeStartSpan(node); + emitNodeWithoutSourceMap(node); + recordEmitNodeEndSpan(node); + } + else { + recordNewSourceFileStart(node); + emitNodeWithoutSourceMap(node); + } + } + } + function emitNodeWithCommentsAndWithSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); + } + writeEmittedFiles = writeJavaScriptAndSourceMapFile; + emit = emitNodeWithCommentsAndWithSourcemap; + emitStart = recordEmitNodeStartSpan; + emitEnd = recordEmitNodeEndSpan; + emitToken = writeTextWithSpanRecord; + scopeEmitStart = recordScopeNameOfNode; + scopeEmitEnd = recordScopeNameEnd; + writeComment = writeCommentRangeWithMap; + } + function writeJavaScriptFile(emitOutput, writeByteOrderMark) { + ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); + } + function createTempVariable(flags) { + var result = ts.createSynthesizedNode(69); + result.text = makeTempVariableName(flags); + return result; + } + function recordTempDeclaration(name) { + if (!tempVariables) { + tempVariables = []; + } + tempVariables.push(name); + } + function createAndRecordTempVariable(flags) { + var temp = createTempVariable(flags); + recordTempDeclaration(temp); + return temp; + } + function emitTempDeclarations(newLine) { + if (tempVariables) { + if (newLine) { + writeLine(); + } + else { + write(" "); + } + write("var "); + emitCommaList(tempVariables); + write(";"); + } + } + function emitTokenText(tokenKind, startPos, emitFn) { + var tokenString = ts.tokenToString(tokenKind); + if (emitFn) { + emitFn(); + } + else { + write(tokenString); + } + return startPos + tokenString.length; + } + function emitOptional(prefix, node) { + if (node) { + write(prefix); + emit(node); + } + } + function emitParenthesizedIf(node, parenthesized) { + if (parenthesized) { + write("("); + } + emit(node); + if (parenthesized) { + write(")"); + } + } + function emitTrailingCommaIfPresent(nodeList) { + if (nodeList.hasTrailingComma) { + write(","); + } + } + function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { + ts.Debug.assert(nodes.length > 0); + increaseIndent(); + if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + for (var i = 0, n = nodes.length; i < n; i++) { + if (i) { + if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { + write(", "); + } + else { + write(","); + writeLine(); + } + } + emit(nodes[i]); + } + if (nodes.hasTrailingComma && allowTrailingComma) { + write(","); + } + decreaseIndent(); + if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + } + function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { + if (!emitNode) { + emitNode = emit; + } + for (var i = 0; i < count; i++) { + if (multiLine) { + if (i || leadingComma) { + write(","); + } + writeLine(); + } + else { + if (i || leadingComma) { + write(", "); + } + } + var node = nodes[start + i]; + emitTrailingCommentsOfPosition(node.pos); + emitNode(node); + leadingComma = true; + } + if (trailingComma) { + write(","); + } + if (multiLine && !noTrailingNewLine) { + writeLine(); + } + return count; + } + function emitCommaList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, false, false); + } + } + function emitLines(nodes) { + emitLinesStartingAt(nodes, 0); + } + function emitLinesStartingAt(nodes, startIndex) { + for (var i = startIndex; i < nodes.length; i++) { + writeLine(); + emit(nodes[i]); + } + } + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 8 && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98: + case 66: + case 111: + case 79: + return true; + } + } + return false; + } + function emitLiteral(node) { + var text = getLiteralText(node); + if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 || ts.isTemplateLiteralKind(node.kind))) { + writer.writeLiteral(text); + } + else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { + write(node.text); + } + else { + write(text); + } + } + function getLiteralText(node) { + if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText("\"", node.text, "\""); + } + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + switch (node.kind) { + case 9: + return getQuotedEscapedLiteralText("\"", node.text, "\""); + case 11: + return getQuotedEscapedLiteralText("`", node.text, "`"); + case 12: + return getQuotedEscapedLiteralText("`", node.text, "${"); + case 13: + return getQuotedEscapedLiteralText("}", node.text, "${"); + case 14: + return getQuotedEscapedLiteralText("}", node.text, "`"); + case 8: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + var isLast = node.kind === 11 || node.kind === 14; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write("\"" + text + "\""); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 11) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(0); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + if (node.template.kind === 183) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 181 + && templateSpan.expression.operatorToken.kind === 24; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); + } + function emitTemplateExpression(node) { + if (languageVersion >= 2) { + ts.forEachChild(node, emit); + return; + } + var emitOuterParens = ts.isExpression(node.parent) + && templateNeedsParens(node, node.parent); + if (emitOuterParens) { + write("("); + } + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + for (var i = 0, n = node.templateSpans.length; i < n; i++) { + var templateSpan = node.templateSpans[i]; + var needsParens = templateSpan.expression.kind !== 172 + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; + if (i > 0 || headEmitted) { + write(" + "); + } + emitParenthesizedIf(templateSpan.expression, needsParens); + if (templateSpan.literal.text.length !== 0) { + write(" + "); + emitLiteral(templateSpan.literal); + } + } + if (emitOuterParens) { + write(")"); + } + function shouldEmitTemplateHead() { + ts.Debug.assert(node.templateSpans.length !== 0); + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template, parent) { + switch (parent.kind) { + case 168: + case 169: + return parent.expression === template; + case 170: + case 172: + return false; + default: + return comparePrecedenceToBinaryPlus(parent) !== -1; + } + } + function comparePrecedenceToBinaryPlus(expression) { + switch (expression.kind) { + case 181: + switch (expression.operatorToken.kind) { + case 37: + case 39: + case 40: + return 1; + case 35: + case 36: + return 0; + default: + return -1; + } + case 184: + case 182: + return -1; + default: + return 1; + } + } + } + function emitTemplateSpan(span) { + emit(span.expression); + emit(span.literal); + } + function jsxEmitReact(node) { + function emitTagName(name) { + if (name.kind === 69 && ts.isIntrinsicJsxName(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + function emitAttributeName(name) { + if (/[A-Za-z_]+[\w*]/.test(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + function emitJsxAttribute(node) { + emitAttributeName(node.name); + write(": "); + if (node.initializer) { + emit(node.initializer); + } + else { + write("true"); + } + } + function emitJsxElement(openingNode, children) { + var syntheticReactRef = ts.createSynthesizedNode(69); + syntheticReactRef.text = "React"; + syntheticReactRef.parent = openingNode; + emitLeadingComments(openingNode); + emitExpressionIdentifier(syntheticReactRef); + write(".createElement("); + emitTagName(openingNode.tagName); + write(", "); + if (openingNode.attributes.length === 0) { + write("null"); + } + else { + var attrs = openingNode.attributes; + if (ts.forEach(attrs, function (attr) { return attr.kind === 239; })) { + emitExpressionIdentifier(syntheticReactRef); + write(".__spread("); + var haveOpenedObjectLiteral = false; + for (var i_1 = 0; i_1 < attrs.length; i_1++) { + if (attrs[i_1].kind === 239) { + if (i_1 === 0) { + write("{}, "); + } + if (haveOpenedObjectLiteral) { + write("}"); + haveOpenedObjectLiteral = false; + } + if (i_1 > 0) { + write(", "); + } + emit(attrs[i_1].expression); + } + else { + ts.Debug.assert(attrs[i_1].kind === 238); + if (haveOpenedObjectLiteral) { + write(", "); + } + else { + haveOpenedObjectLiteral = true; + if (i_1 > 0) { + write(", "); + } + write("{"); + } + emitJsxAttribute(attrs[i_1]); + } + } + if (haveOpenedObjectLiteral) + write("}"); + write(")"); + } + else { + write("{"); + for (var i = 0; i < attrs.length; i++) { + if (i > 0) { + write(", "); + } + emitJsxAttribute(attrs[i]); + } + write("}"); + } + } + if (children) { + for (var i = 0; i < children.length; i++) { + if (children[i].kind === 240 && !(children[i].expression)) { + continue; + } + if (children[i].kind === 236) { + var text = getTextToEmit(children[i]); + if (text !== undefined) { + write(", \""); + write(text); + write("\""); + } + } + else { + write(", "); + emit(children[i]); + } + } + } + write(")"); + emitTrailingComments(openingNode); + } + if (node.kind === 233) { + emitJsxElement(node.openingElement, node.children); + } + else { + ts.Debug.assert(node.kind === 234); + emitJsxElement(node); + } + } + function jsxEmitPreserve(node) { + function emitJsxAttribute(node) { + emit(node.name); + if (node.initializer) { + write("="); + emit(node.initializer); + } + } + function emitJsxSpreadAttribute(node) { + write("{..."); + emit(node.expression); + write("}"); + } + function emitAttributes(attribs) { + for (var i = 0, n = attribs.length; i < n; i++) { + if (i > 0) { + write(" "); + } + if (attribs[i].kind === 239) { + emitJsxSpreadAttribute(attribs[i]); + } + else { + ts.Debug.assert(attribs[i].kind === 238); + emitJsxAttribute(attribs[i]); + } + } + } + function emitJsxOpeningOrSelfClosingElement(node) { + write("<"); + emit(node.tagName); + if (node.attributes.length > 0 || (node.kind === 234)) { + write(" "); + } + emitAttributes(node.attributes); + if (node.kind === 234) { + write("/>"); + } + else { + write(">"); + } + } + function emitJsxClosingElement(node) { + write(""); + } + function emitJsxElement(node) { + emitJsxOpeningOrSelfClosingElement(node.openingElement); + for (var i = 0, n = node.children.length; i < n; i++) { + emit(node.children[i]); + } + emitJsxClosingElement(node.closingElement); + } + if (node.kind === 233) { + emitJsxElement(node); + } + else { + ts.Debug.assert(node.kind === 234); + emitJsxOpeningOrSelfClosingElement(node); + } + } + function emitExpressionForPropertyName(node) { + ts.Debug.assert(node.kind !== 163); + if (node.kind === 9) { + emitLiteral(node); + } + else if (node.kind === 136) { + if (ts.nodeIsDecorated(node.parent)) { + if (!computedPropertyNamesToGeneratedNames) { + computedPropertyNamesToGeneratedNames = []; + } + var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; + if (generatedName) { + write(generatedName); + return; + } + generatedName = createAndRecordTempVariable(0).text; + computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; + write(generatedName); + write(" = "); + } + emit(node.expression); + } + else { + write("\""); + if (node.kind === 8) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + write("\""); + } + } + function isExpressionIdentifier(node) { + var parent = node.parent; + switch (parent.kind) { + case 164: + case 189: + case 181: + case 168: + case 241: + case 136: + case 182: + case 139: + case 175: + case 197: + case 167: + case 227: + case 195: + case 188: + case 199: + case 200: + case 201: + case 196: + case 234: + case 235: + case 239: + case 240: + case 169: + case 172: + case 180: + case 179: + case 204: + case 246: + case 185: + case 206: + case 170: + case 190: + case 208: + case 171: + case 176: + case 177: + case 198: + case 205: + case 184: + return true; + case 163: + case 247: + case 138: + case 245: + case 141: + case 211: + return parent.initializer === node; + case 166: + return parent.expression === node; + case 174: + case 173: + return parent.body === node; + case 221: + return parent.moduleReference === node; + case 135: + return parent.left === node; + } + return false; + } + function emitExpressionIdentifier(node) { + if (resolver.getNodeCheckFlags(node) & 2048) { + write("_arguments"); + return; + } + var container = resolver.getReferencedExportContainer(node); + if (container) { + if (container.kind === 248) { + if (modulekind !== 5 && modulekind !== 4) { + write("exports."); + } + } + else { + write(getGeneratedNameForNode(container)); + write("."); + } + } + else if (modulekind !== 5) { + var declaration = resolver.getReferencedImportDeclaration(node); + if (declaration) { + if (declaration.kind === 223) { + write(getGeneratedNameForNode(declaration.parent)); + write(languageVersion === 0 ? "[\"default\"]" : ".default"); + return; + } + else if (declaration.kind === 226) { + write(getGeneratedNameForNode(declaration.parent.parent.parent)); + var name_23 = declaration.propertyName || declaration.name; + var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name_23); + if (languageVersion === 0 && identifier === "default") { + write("[\"default\"]"); + } + else { + write("."); + write(identifier); + } + return; + } + } + declaration = resolver.getReferencedNestedRedeclaration(node); + if (declaration) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } + if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function isNameOfNestedRedeclaration(node) { + if (languageVersion < 2) { + var parent_6 = node.parent; + switch (parent_6.kind) { + case 163: + case 214: + case 217: + case 211: + return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); + } + } + return false; + } + function emitIdentifier(node) { + if (!node.parent) { + write(node.text); + } + else if (isExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else if (isNameOfNestedRedeclaration(node)) { + write(getGeneratedNameForNode(node)); + } + else if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function emitThis(node) { + if (resolver.getNodeCheckFlags(node) & 2) { + write("_this"); + } + else { + write("this"); + } + } + function emitSuper(node) { + if (languageVersion >= 2) { + write("super"); + } + else { + var flags = resolver.getNodeCheckFlags(node); + if (flags & 256) { + write("_super.prototype"); + } + else { + write("_super"); + } + } + } + function emitObjectBindingPattern(node) { + write("{ "); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write(" }"); + } + function emitArrayBindingPattern(node) { + write("["); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write("]"); + } + function emitBindingElement(node) { + if (node.propertyName) { + emit(node.propertyName); + write(": "); + } + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + emit(node.name); + } + else { + emitModuleMemberName(node); + } + emitOptional(" = ", node.initializer); + } + function emitSpreadElementExpression(node) { + write("..."); + emit(node.expression); + } + function emitYieldExpression(node) { + write(ts.tokenToString(114)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } + function emitAwaitExpression(node) { + var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); + if (needsParenthesis) { + write("("); + } + write(ts.tokenToString(114)); + write(" "); + emit(node.expression); + if (needsParenthesis) { + write(")"); + } + } + function needsParenthesisForAwaitExpressionAsYield(node) { + if (node.parent.kind === 181 && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { + return true; + } + else if (node.parent.kind === 182 && node.parent.condition === node) { + return true; + } + return false; + } + function needsParenthesisForPropertyAccessOrInvocation(node) { + switch (node.kind) { + case 69: + case 164: + case 166: + case 167: + case 168: + case 172: + return false; + } + return true; + } + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { + var pos = 0; + var group = 0; + var length = elements.length; + while (pos < length) { + if (group === 1 && useConcat) { + write(".concat("); + } + else if (group > 0) { + write(", "); + } + var e = elements[pos]; + if (e.kind === 185) { + e = e.expression; + emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); + pos++; + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 164) { + write(".slice()"); + } + } + else { + var i = pos; + while (i < length && elements[i].kind !== 185) { + i++; + } + write("["); + if (multiLine) { + increaseIndent(); + } + emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); + if (multiLine) { + decreaseIndent(); + } + write("]"); + pos = i; + } + group++; + } + if (group > 1) { + if (useConcat) { + write(")"); + } + } + } + function isSpreadElementExpression(node) { + return node.kind === 185; + } + function emitArrayLiteral(node) { + var elements = node.elements; + if (elements.length === 0) { + write("[]"); + } + else if (languageVersion >= 2 || !ts.forEach(elements, isSpreadElementExpression)) { + write("["); + emitLinePreservingList(node, node.elements, elements.hasTrailingComma, false); + write("]"); + } + else { + emitListWithSpread(elements, true, (node.flags & 2048) !== 0, elements.hasTrailingComma, true); + } + } + function emitObjectLiteralBody(node, numElements) { + if (numElements === 0) { + write("{}"); + return; + } + write("{"); + if (numElements > 0) { + var properties = node.properties; + if (numElements === properties.length) { + emitLinePreservingList(node, properties, languageVersion >= 1, true); + } + else { + var multiLine = (node.flags & 2048) !== 0; + if (!multiLine) { + write(" "); + } + else { + increaseIndent(); + } + emitList(properties, 0, numElements, multiLine, false); + if (!multiLine) { + write(" "); + } + else { + decreaseIndent(); + } + } + } + write("}"); + } + function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { + var multiLine = (node.flags & 2048) !== 0; + var properties = node.properties; + write("("); + if (multiLine) { + increaseIndent(); + } + var tempVar = createAndRecordTempVariable(0); + emit(tempVar); + write(" = "); + emitObjectLiteralBody(node, firstComputedPropertyIndex); + for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { + writeComma(); + var property = properties[i]; + emitStart(property); + if (property.kind === 145 || property.kind === 146) { + var accessors = ts.getAllAccessorDeclarations(node.properties, property); + if (property !== accessors.firstAccessor) { + continue; + } + write("Object.defineProperty("); + emit(tempVar); + write(", "); + emitStart(node.name); + emitExpressionForPropertyName(property.name); + emitEnd(property.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("})"); + emitEnd(property); + } + else { + emitLeadingComments(property); + emitStart(property.name); + emit(tempVar); + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + if (property.kind === 245) { + emit(property.initializer); + } + else if (property.kind === 246) { + emitExpressionIdentifier(property.name); + } + else if (property.kind === 143) { + emitFunctionDeclaration(property); + } + else { + ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); + } + } + emitEnd(property); + } + writeComma(); + emit(tempVar); + if (multiLine) { + decreaseIndent(); + writeLine(); + } + write(")"); + function writeComma() { + if (multiLine) { + write(","); + writeLine(); + } + else { + write(", "); + } + } + } + function emitObjectLiteral(node) { + var properties = node.properties; + if (languageVersion < 2) { + var numProperties = properties.length; + var numInitialNonComputedProperties = numProperties; + for (var i = 0, n = properties.length; i < n; i++) { + if (properties[i].name.kind === 136) { + numInitialNonComputedProperties = i; + break; + } + } + var hasComputedProperty = numInitialNonComputedProperties !== properties.length; + if (hasComputedProperty) { + emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); + return; + } + } + emitObjectLiteralBody(node, properties.length); + } + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(181, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); + result.left = left; + result.right = right; + return result; + } + function createPropertyAccessExpression(expression, name) { + var result = ts.createSynthesizedNode(166); + result.expression = parenthesizeForAccess(expression); + result.dotToken = ts.createSynthesizedNode(21); + result.name = name; + return result; + } + function createElementAccessExpression(expression, argumentExpression) { + var result = ts.createSynthesizedNode(167); + result.expression = parenthesizeForAccess(expression); + result.argumentExpression = argumentExpression; + return result; + } + function parenthesizeForAccess(expr) { + while (expr.kind === 171 || expr.kind === 189) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 169 && + expr.kind !== 8) { + return expr; + } + var node = ts.createSynthesizedNode(172); + node.expression = expr; + return node; + } + function emitComputedPropertyName(node) { + write("["); + emitExpressionForPropertyName(node); + write("]"); + } + function emitMethod(node) { + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } + emit(node.name); + if (languageVersion < 2) { + write(": function "); + } + emitSignatureAndBody(node); + } + function emitPropertyAssignment(node) { + emit(node.name); + write(": "); + emitTrailingCommentsOfPosition(node.initializer.pos); + emit(node.initializer); + } + function isNamespaceExportReference(node) { + var container = resolver.getReferencedExportContainer(node); + return container && container.kind !== 248; + } + function emitShorthandPropertyAssignment(node) { + writeTextOfNode(currentSourceFile, node.name); + if (languageVersion < 2 || isNamespaceExportReference(node.name)) { + write(": "); + emit(node.name); + } + if (languageVersion >= 2 && node.objectAssignmentInitializer) { + write(" = "); + emit(node.objectAssignmentInitializer); + } + } + function tryEmitConstantValue(node) { + var constantValue = tryGetConstEnumValue(node); + if (constantValue !== undefined) { + write(constantValue.toString()); + if (!compilerOptions.removeComments) { + var propertyName = node.kind === 166 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + write(" /* " + propertyName + " */"); + } + return true; + } + return false; + } + function tryGetConstEnumValue(node) { + if (compilerOptions.isolatedModules) { + return undefined; + } + return node.kind === 166 || node.kind === 167 + ? resolver.getConstantValue(node) + : undefined; + } + function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { + var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + else { + if (valueToWriteWhenNotIndenting) { + write(valueToWriteWhenNotIndenting); + } + return false; + } + } + function emitPropertyAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); + var shouldEmitSpace; + if (!indentedBeforeDot) { + if (node.expression.kind === 8) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); + shouldEmitSpace = text.indexOf(ts.tokenToString(21)) < 0; + } + else { + var constantValue = tryGetConstEnumValue(node.expression); + shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; + } + } + if (shouldEmitSpace) { + write(" ."); + } + else { + write("."); + } + var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); + emit(node.name); + decreaseIndentIf(indentedBeforeDot, indentedAfterDot); + } + function emitQualifiedName(node) { + emit(node.left); + write("."); + emit(node.right); + } + function emitQualifiedNameAsExpression(node, useFallback) { + if (node.left.kind === 69) { + emitEntityNameAsExpression(node.left, useFallback); + } + else if (useFallback) { + var temp = createAndRecordTempVariable(0); + write("("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(node.left, true); + write(") && "); + emitNodeWithoutSourceMap(temp); + } + else { + emitEntityNameAsExpression(node.left, false); + } + write("."); + emit(node.right); + } + function emitEntityNameAsExpression(node, useFallback) { + switch (node.kind) { + case 69: + if (useFallback) { + write("typeof "); + emitExpressionIdentifier(node); + write(" !== 'undefined' && "); + } + emitExpressionIdentifier(node); + break; + case 135: + emitQualifiedNameAsExpression(node, useFallback); + break; + } + } + function emitIndexedAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("["); + emit(node.argumentExpression); + write("]"); + } + function hasSpreadElement(elements) { + return ts.forEach(elements, function (e) { return e.kind === 185; }); + } + function skipParentheses(node) { + while (node.kind === 172 || node.kind === 171 || node.kind === 189) { + node = node.expression; + } + return node; + } + function emitCallTarget(node) { + if (node.kind === 69 || node.kind === 97 || node.kind === 95) { + emit(node); + return node; + } + var temp = createAndRecordTempVariable(0); + write("("); + emit(temp); + write(" = "); + emit(node); + write(")"); + return temp; + } + function emitCallWithSpread(node) { + var target; + var expr = skipParentheses(node.expression); + if (expr.kind === 166) { + target = emitCallTarget(expr.expression); + write("."); + emit(expr.name); + } + else if (expr.kind === 167) { + target = emitCallTarget(expr.expression); + write("["); + emit(expr.argumentExpression); + write("]"); + } + else if (expr.kind === 95) { + target = expr; + write("_super"); + } + else { + emit(node.expression); + } + write(".apply("); + if (target) { + if (target.kind === 95) { + emitThis(target); + } + else { + emit(target); + } + } + else { + write("void 0"); + } + write(", "); + emitListWithSpread(node.arguments, false, false, false, true); + write(")"); + } + function emitCallExpression(node) { + if (languageVersion < 2 && hasSpreadElement(node.arguments)) { + emitCallWithSpread(node); + return; + } + var superCall = false; + if (node.expression.kind === 95) { + emitSuper(node.expression); + superCall = true; + } + else { + emit(node.expression); + superCall = node.expression.kind === 166 && node.expression.expression.kind === 95; + } + if (superCall && languageVersion < 2) { + write(".call("); + emitThis(node.expression); + if (node.arguments.length) { + write(", "); + emitCommaList(node.arguments); + } + write(")"); + } + else { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitNewExpression(node) { + write("new "); + if (languageVersion === 1 && + node.arguments && + hasSpreadElement(node.arguments)) { + write("("); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, false, false, false, false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + } + function emitTaggedTemplateExpression(node) { + if (languageVersion >= 2) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } + } + function emitParenExpression(node) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 174) { + if (node.expression.kind === 171 || node.expression.kind === 189) { + var operand = node.expression.expression; + while (operand.kind === 171 || operand.kind === 189) { + operand = operand.expression; + } + if (operand.kind !== 179 && + operand.kind !== 177 && + operand.kind !== 176 && + operand.kind !== 175 && + operand.kind !== 180 && + operand.kind !== 169 && + !(operand.kind === 168 && node.parent.kind === 169) && + !(operand.kind === 173 && node.parent.kind === 168) && + !(operand.kind === 8 && node.parent.kind === 166)) { + emit(operand); + return; + } + } + } + write("("); + emit(node.expression); + write(")"); + } + function emitDeleteExpression(node) { + write(ts.tokenToString(78)); + write(" "); + emit(node.expression); + } + function emitVoidExpression(node) { + write(ts.tokenToString(103)); + write(" "); + emit(node.expression); + } + function emitTypeOfExpression(node) { + write(ts.tokenToString(101)); + write(" "); + emit(node.expression); + } + function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { + if (!isCurrentFileSystemExternalModule() || node.kind !== 69 || ts.nodeIsSynthesized(node)) { + return false; + } + var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 211 || node.parent.kind === 163); + var targetDeclaration = isVariableDeclarationOrBindingElement + ? node.parent + : resolver.getReferencedValueDeclaration(node); + return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, true); + } + function emitPrefixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + } + write(ts.tokenToString(node.operator)); + if (node.operand.kind === 179) { + var operand = node.operand; + if (node.operator === 35 && (operand.operator === 35 || operand.operator === 41)) { + write(" "); + } + else if (node.operator === 36 && (operand.operator === 36 || operand.operator === 42)) { + write(" "); + } + } + emit(node.operand); + if (exportChanged) { + write(")"); + } + } + function emitPostfixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + write("(" + exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + write(ts.tokenToString(node.operator)); + emit(node.operand); + if (node.operator === 41) { + write(") - 1)"); + } + else { + write(") + 1)"); + } + } + else { + emit(node.operand); + write(ts.tokenToString(node.operator)); + } + } + function shouldHoistDeclarationInSystemJsModule(node) { + return isSourceFileLevelDeclarationInSystemJsModule(node, false); + } + function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { + if (!node || languageVersion >= 2 || !isCurrentFileSystemExternalModule()) { + return false; + } + var current = node; + while (current) { + if (current.kind === 248) { + return !isExported || ((ts.getCombinedNodeFlags(node) & 1) !== 0); + } + else if (ts.isFunctionLike(current) || current.kind === 219) { + return false; + } + else { + current = current.parent; + } + } + } + function emitExponentiationOperator(node) { + var leftHandSideExpression = node.left; + if (node.operatorToken.kind === 60) { + var synthesizedLHS; + var shouldEmitParentheses = false; + if (ts.isElementAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(167, false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, false, false); + synthesizedLHS.expression = identifier; + if (leftHandSideExpression.argumentExpression.kind !== 8 && + leftHandSideExpression.argumentExpression.kind !== 9) { + var tempArgumentExpression = createAndRecordTempVariable(268435456); + synthesizedLHS.argumentExpression = tempArgumentExpression; + emitAssignment(tempArgumentExpression, leftHandSideExpression.argumentExpression, true); + } + else { + synthesizedLHS.argumentExpression = leftHandSideExpression.argumentExpression; + } + write(", "); + } + else if (ts.isPropertyAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(166, false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, false, false); + synthesizedLHS.expression = identifier; + synthesizedLHS.dotToken = leftHandSideExpression.dotToken; + synthesizedLHS.name = leftHandSideExpression.name; + write(", "); + } + emit(synthesizedLHS || leftHandSideExpression); + write(" = "); + write("Math.pow("); + emit(synthesizedLHS || leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + if (shouldEmitParentheses) { + write(")"); + } + } + else { + write("Math.pow("); + emit(leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + } + } + function emitBinaryExpression(node) { + if (languageVersion < 2 && node.operatorToken.kind === 56 && + (node.left.kind === 165 || node.left.kind === 164)) { + emitDestructuring(node, node.parent.kind === 195); + } + else { + var exportChanged = node.operatorToken.kind >= 56 && + node.operatorToken.kind <= 68 && + isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.left); + write("\", "); + } + if (node.operatorToken.kind === 38 || node.operatorToken.kind === 60) { + emitExponentiationOperator(node); + } + else { + emit(node.left); + var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 ? " " : undefined); + write(ts.tokenToString(node.operatorToken.kind)); + var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); + emit(node.right); + decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); + } + if (exportChanged) { + write(")"); + } + } + } + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; + } + function emitConditionalExpression(node) { + emit(node.condition); + var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); + write("?"); + var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); + emit(node.whenTrue); + decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); + var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); + write(":"); + var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); + emit(node.whenFalse); + decreaseIndentIf(indentedBeforeColon, indentedAfterColon); + } + function decreaseIndentIf(value1, value2) { + if (value1) { + decreaseIndent(); + } + if (value2) { + decreaseIndent(); + } + } + function isSingleLineEmptyBlock(node) { + if (node && node.kind === 192) { + var block = node; + return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); + } + } + function emitBlock(node) { + if (isSingleLineEmptyBlock(node)) { + emitToken(15, node.pos); + write(" "); + emitToken(16, node.statements.end); + return; + } + emitToken(15, node.pos); + increaseIndent(); + scopeEmitStart(node.parent); + if (node.kind === 219) { + ts.Debug.assert(node.parent.kind === 218); + emitCaptureThisForNodeIfNecessary(node.parent); + } + emitLines(node.statements); + if (node.kind === 219) { + emitTempDeclarations(true); + } + decreaseIndent(); + writeLine(); + emitToken(16, node.statements.end); + scopeEmitEnd(); + } + function emitEmbeddedStatement(node) { + if (node.kind === 192) { + write(" "); + emit(node); + } + else { + increaseIndent(); + writeLine(); + emit(node); + decreaseIndent(); + } + } + function emitExpressionStatement(node) { + emitParenthesizedIf(node.expression, node.expression.kind === 174); + write(";"); + } + function emitIfStatement(node) { + var endPos = emitToken(88, node.pos); + write(" "); + endPos = emitToken(17, endPos); + emit(node.expression); + emitToken(18, node.expression.end); + emitEmbeddedStatement(node.thenStatement); + if (node.elseStatement) { + writeLine(); + emitToken(80, node.thenStatement.end); + if (node.elseStatement.kind === 196) { + write(" "); + emit(node.elseStatement); + } + else { + emitEmbeddedStatement(node.elseStatement); + } + } + } + function emitDoStatement(node) { + write("do"); + emitEmbeddedStatement(node.statement); + if (node.statement.kind === 192) { + write(" "); + } + else { + writeLine(); + } + write("while ("); + emit(node.expression); + write(");"); + } + function emitWhileStatement(node) { + write("while ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function tryEmitStartOfVariableDeclarationList(decl, startPos) { + if (shouldHoistVariable(decl, true)) { + return false; + } + var tokenKind = 102; + if (decl && languageVersion >= 2) { + if (ts.isLet(decl)) { + tokenKind = 108; + } + else if (ts.isConst(decl)) { + tokenKind = 74; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + write(" "); + } + else { + switch (tokenKind) { + case 102: + write("var "); + break; + case 108: + write("let "); + break; + case 74: + write("const "); + break; + } + } + return true; + } + function emitVariableDeclarationListSkippingUninitializedEntries(list) { + var started = false; + for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { + var decl = _b[_a]; + if (!decl.initializer) { + continue; + } + if (!started) { + started = true; + } + else { + write(", "); + } + emit(decl); + } + return started; + } + function emitForStatement(node) { + var endPos = emitToken(86, node.pos); + write(" "); + endPos = emitToken(17, endPos); + if (node.initializer && node.initializer.kind === 212) { + var variableDeclarationList = node.initializer; + var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + if (startIsEmitted) { + emitCommaList(variableDeclarationList.declarations); + } + else { + emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); + } + } + else if (node.initializer) { + emit(node.initializer); + } + write(";"); + emitOptional(" ", node.condition); + write(";"); + emitOptional(" ", node.incrementor); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForInOrForOfStatement(node) { + if (languageVersion < 2 && node.kind === 201) { + return emitDownLevelForOfStatement(node); + } + var endPos = emitToken(86, node.pos); + write(" "); + endPos = emitToken(17, endPos); + if (node.initializer.kind === 212) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + emit(variableDeclarationList.declarations[0]); + } + } + else { + emit(node.initializer); + } + if (node.kind === 200) { + write(" in "); + } + else { + write(" of "); + } + emit(node.expression); + emitToken(18, node.expression.end); + emitEmbeddedStatement(node.statement); + } + function emitDownLevelForOfStatement(node) { + var endPos = emitToken(86, node.pos); + write(" "); + endPos = emitToken(17, endPos); + var rhsIsIdentifier = node.expression.kind === 69; + var counter = createTempVariable(268435456); + var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0); + emitStart(node.expression); + write("var "); + emitNodeWithoutSourceMap(counter); + write(" = 0"); + emitEnd(node.expression); + if (!rhsIsIdentifier) { + write(", "); + emitStart(node.expression); + emitNodeWithoutSourceMap(rhsReference); + write(" = "); + emitNodeWithoutSourceMap(node.expression); + emitEnd(node.expression); + } + write("; "); + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write(" < "); + emitNodeWithCommentsAndWithoutSourcemap(rhsReference); + write(".length"); + emitEnd(node.initializer); + write("; "); + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write("++"); + emitEnd(node.initializer); + emitToken(18, node.expression.end); + write(" {"); + writeLine(); + increaseIndent(); + var rhsIterationValue = createElementAccessExpression(rhsReference, counter); + emitStart(node.initializer); + if (node.initializer.kind === 212) { + write("var "); + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length > 0) { + var declaration = variableDeclarationList.declarations[0]; + if (ts.isBindingPattern(declaration.name)) { + emitDestructuring(declaration, false, rhsIterationValue); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(declaration); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + emitNodeWithoutSourceMap(createTempVariable(0)); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + var assignmentExpression = createBinaryExpression(node.initializer, 56, rhsIterationValue, false); + if (node.initializer.kind === 164 || node.initializer.kind === 165) { + emitDestructuring(assignmentExpression, true, undefined); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); + } + } + emitEnd(node.initializer); + write(";"); + if (node.statement.kind === 192) { + emitLines(node.statement.statements); + } + else { + writeLine(); + emit(node.statement); + } + writeLine(); + decreaseIndent(); + write("}"); + } + function emitBreakOrContinueStatement(node) { + emitToken(node.kind === 203 ? 70 : 75, node.pos); + emitOptional(" ", node.label); + write(";"); + } + function emitReturnStatement(node) { + emitToken(94, node.pos); + emitOptional(" ", node.expression); + write(";"); + } + function emitWithStatement(node) { + write("with ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitSwitchStatement(node) { + var endPos = emitToken(96, node.pos); + write(" "); + emitToken(17, endPos); + emit(node.expression); + endPos = emitToken(18, node.expression.end); + write(" "); + emitCaseBlock(node.caseBlock, endPos); + } + function emitCaseBlock(node, startPos) { + emitToken(15, startPos); + increaseIndent(); + emitLines(node.clauses); + decreaseIndent(); + writeLine(); + emitToken(16, node.clauses.end); + } + function nodeStartPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function nodeEndPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, node2.end); + } + function nodeEndIsOnSameLineAsNodeStart(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function emitCaseOrDefaultClause(node) { + if (node.kind === 241) { + write("case "); + emit(node.expression); + write(":"); + } + else { + write("default:"); + } + if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { + write(" "); + emit(node.statements[0]); + } + else { + increaseIndent(); + emitLines(node.statements); + decreaseIndent(); + } + } + function emitThrowStatement(node) { + write("throw "); + emit(node.expression); + write(";"); + } + function emitTryStatement(node) { + write("try "); + emit(node.tryBlock); + emit(node.catchClause); + if (node.finallyBlock) { + writeLine(); + write("finally "); + emit(node.finallyBlock); + } + } + function emitCatchClause(node) { + writeLine(); + var endPos = emitToken(72, node.pos); + write(" "); + emitToken(17, endPos); + emit(node.variableDeclaration); + emitToken(18, node.variableDeclaration ? node.variableDeclaration.end : endPos); + write(" "); + emitBlock(node.block); + } + function emitDebuggerStatement(node) { + emitToken(76, node.pos); + write(";"); + } + function emitLabelledStatement(node) { + emit(node.label); + write(": "); + emit(node.statement); + } + function getContainingModule(node) { + do { + node = node.parent; + } while (node && node.kind !== 218); + return node; + } + function emitContainingModuleName(node) { + var container = getContainingModule(node); + write(container ? getGeneratedNameForNode(container) : "exports"); + } + function emitModuleMemberName(node) { + emitStart(node.name); + if (ts.getCombinedNodeFlags(node) & 1) { + var container = getContainingModule(node); + if (container) { + write(getGeneratedNameForNode(container)); + write("."); + } + else if (modulekind !== 5 && modulekind !== 4) { + write("exports."); + } + } + emitNodeWithCommentsAndWithoutSourcemap(node.name); + emitEnd(node.name); + } + function createVoidZero() { + var zero = ts.createSynthesizedNode(8); + zero.text = "0"; + var result = ts.createSynthesizedNode(177); + result.expression = zero; + return result; + } + function emitEs6ExportDefaultCompat(node) { + if (node.parent.kind === 248) { + ts.Debug.assert(!!(node.flags & 1024) || node.kind === 227); + if (modulekind === 1 || modulekind === 2 || modulekind === 3) { + if (!currentSourceFile.symbol.exports["___esModule"]) { + if (languageVersion === 1) { + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else if (languageVersion === 0) { + write("exports.__esModule = true;"); + writeLine(); + } + } + } + } + } + function emitExportMemberAssignment(node) { + if (node.flags & 1) { + writeLine(); + emitStart(node); + if (modulekind === 4 && node.parent === currentSourceFile) { + write(exportFunctionForFile + "(\""); + if (node.flags & 1024) { + write("default"); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + write("\", "); + emitDeclarationName(node); + write(")"); + } + else { + if (node.flags & 1024) { + emitEs6ExportDefaultCompat(node); + if (languageVersion === 0) { + write("exports[\"default\"]"); + } + else { + write("exports.default"); + } + } + else { + emitModuleMemberName(node); + } + write(" = "); + emitDeclarationName(node); + } + emitEnd(node); + write(";"); + } + } + function emitExportMemberAssignments(name) { + if (modulekind === 4) { + return; + } + if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { + var specifier = _b[_a]; + writeLine(); + emitStart(specifier.name); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + emitEnd(specifier.name); + write(" = "); + emitExpressionIdentifier(name); + write(";"); + } + } + } + function emitExportSpecifierInSystemModule(specifier) { + ts.Debug.assert(modulekind === 4); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } + writeLine(); + emitStart(specifier.name); + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write("\", "); + emitExpressionIdentifier(specifier.propertyName || specifier.name); + write(")"); + emitEnd(specifier.name); + write(";"); + } + function emitAssignment(name, value, shouldEmitCommaBeforeAssignment) { + if (shouldEmitCommaBeforeAssignment) { + write(", "); + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(name); + write("\", "); + } + var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 211 || name.parent.kind === 163); + if (isVariableDeclarationOrBindingElement) { + emitModuleMemberName(name.parent); + } + else { + emit(name); + } + write(" = "); + emit(value); + if (exportChanged) { + write(")"); + } + } + function emitTempVariableAssignment(expression, canDefineTempVariablesInPlace, shouldEmitCommaBeforeAssignment) { + var identifier = createTempVariable(0); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expression, shouldEmitCommaBeforeAssignment); + return identifier; + } + function emitDestructuring(root, isAssignmentExpressionStatement, value) { + var emitCount = 0; + var canDefineTempVariablesInPlace = false; + if (root.kind === 211) { + var isExported = ts.getCombinedNodeFlags(root) & 1; + var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); + canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; + } + else if (root.kind === 138) { + canDefineTempVariablesInPlace = true; + } + if (root.kind === 181) { + emitAssignmentExpression(root); + } + else { + ts.Debug.assert(!isAssignmentExpressionStatement); + emitBindingElement(root, value); + } + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 69 && reuseIdentifierExpressions) { + return expr; + } + var identifier = emitTempVariableAssignment(expr, canDefineTempVariablesInPlace, emitCount > 0); + emitCount++; + return identifier; + } + function createDefaultValueCheck(value, defaultValue) { + value = ensureIdentifier(value, true); + var equals = ts.createSynthesizedNode(181); + equals.left = value; + equals.operatorToken = ts.createSynthesizedNode(32); + equals.right = createVoidZero(); + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(182); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(53); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(54); + cond.whenFalse = whenFalse; + return cond; + } + function createNumericLiteral(value) { + var node = ts.createSynthesizedNode(8); + node.text = "" + value; + return node; + } + function createPropertyAccessForDestructuringProperty(object, propName) { + var syntheticName = ts.createSynthesizedNode(propName.kind); + syntheticName.text = propName.text; + if (syntheticName.kind !== 69) { + return createElementAccessExpression(object, syntheticName); + } + return createPropertyAccessExpression(object, syntheticName); + } + function createSliceCall(value, sliceIndex) { + var call = ts.createSynthesizedNode(168); + var sliceIdentifier = ts.createSynthesizedNode(69); + sliceIdentifier.text = "slice"; + call.expression = createPropertyAccessExpression(value, sliceIdentifier); + call.arguments = ts.createSynthesizedNodeArray(); + call.arguments[0] = createNumericLiteral(sliceIndex); + return call; + } + function emitObjectLiteralAssignment(target, value) { + var properties = target.properties; + if (properties.length !== 1) { + value = ensureIdentifier(value, true); + } + for (var _a = 0; _a < properties.length; _a++) { + var p = properties[_a]; + if (p.kind === 245 || p.kind === 246) { + var propName = p.name; + var target_1 = p.kind === 246 ? p : p.initializer || propName; + emitDestructuringAssignment(target_1, createPropertyAccessForDestructuringProperty(value, propName)); + } + } + } + function emitArrayLiteralAssignment(target, value) { + var elements = target.elements; + if (elements.length !== 1) { + value = ensureIdentifier(value, true); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 187) { + if (e.kind !== 185) { + emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === elements.length - 1) { + emitDestructuringAssignment(e.expression, createSliceCall(value, i)); + } + } + } + } + function emitDestructuringAssignment(target, value) { + if (target.kind === 246) { + if (target.objectAssignmentInitializer) { + value = createDefaultValueCheck(value, target.objectAssignmentInitializer); + } + target = target.name; + } + else if (target.kind === 181 && target.operatorToken.kind === 56) { + value = createDefaultValueCheck(value, target.right); + target = target.left; + } + if (target.kind === 165) { + emitObjectLiteralAssignment(target, value); + } + else if (target.kind === 164) { + emitArrayLiteralAssignment(target, value); + } + else { + emitAssignment(target, value, emitCount > 0); + emitCount++; + } + } + function emitAssignmentExpression(root) { + var target = root.left; + var value = root.right; + if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { + emit(value); + } + else if (isAssignmentExpressionStatement) { + emitDestructuringAssignment(target, value); + } + else { + if (root.parent.kind !== 172) { + write("("); + } + value = ensureIdentifier(value, true); + emitDestructuringAssignment(target, value); + write(", "); + emit(value); + if (root.parent.kind !== 172) { + write(")"); + } + } + } + function emitBindingElement(target, value) { + if (target.initializer) { + value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; + } + else if (!value) { + value = createVoidZero(); + } + if (ts.isBindingPattern(target.name)) { + var pattern = target.name; + var elements = pattern.elements; + var numElements = elements.length; + if (numElements !== 1) { + value = ensureIdentifier(value, numElements !== 0); + } + for (var i = 0; i < numElements; i++) { + var element = elements[i]; + if (pattern.kind === 161) { + var propName = element.propertyName || element.name; + emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); + } + else if (element.kind !== 187) { + if (!element.dotDotDotToken) { + emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === numElements - 1) { + emitBindingElement(element, createSliceCall(value, i)); + } + } + } + } + else { + emitAssignment(target.name, value, emitCount > 0); + emitCount++; + } + } + } + function emitVariableDeclaration(node) { + if (ts.isBindingPattern(node.name)) { + if (languageVersion < 2) { + emitDestructuring(node, false); + } + else { + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + else { + var initializer = node.initializer; + if (!initializer && languageVersion < 2) { + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384) && + (getCombinedFlagsForIdentifier(node.name) & 16384); + if (isUninitializedLet && + node.parent.parent.kind !== 200 && + node.parent.parent.kind !== 201) { + initializer = createVoidZero(); + } + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(node.name); + write("\", "); + } + emitModuleMemberName(node); + emitOptional(" = ", initializer); + if (exportChanged) { + write(")"); + } + } + } + function emitExportVariableAssignments(node) { + if (node.kind === 187) { + return; + } + var name = node.name; + if (name.kind === 69) { + emitExportMemberAssignments(name); + } + else if (ts.isBindingPattern(name)) { + ts.forEach(name.elements, emitExportVariableAssignments); + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 211 && node.parent.kind !== 163)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function isES6ExportedDeclaration(node) { + return !!(node.flags & 1) && + modulekind === 5 && + node.parent.kind === 248; + } + function emitVariableStatement(node) { + var startIsEmitted = false; + if (node.flags & 1) { + if (isES6ExportedDeclaration(node)) { + write("export "); + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + } + else { + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + if (startIsEmitted) { + emitCommaList(node.declarationList.declarations); + write(";"); + } + else { + var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); + if (atLeastOneItem) { + write(";"); + } + } + if (modulekind !== 5 && node.parent === currentSourceFile) { + ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); + } + } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + if (!(node.flags & 1)) { + return true; + } + if (isES6ExportedDeclaration(node)) { + return true; + } + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } + function emitParameter(node) { + if (languageVersion < 2) { + if (ts.isBindingPattern(node.name)) { + var name_24 = createTempVariable(0); + if (!tempParameters) { + tempParameters = []; + } + tempParameters.push(name_24); + emit(name_24); + } + else { + emit(node.name); + } + } + else { + if (node.dotDotDotToken) { + write("..."); + } + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + function emitDefaultValueAssignments(node) { + if (languageVersion < 2) { + var tempIndex = 0; + ts.forEach(node.parameters, function (parameter) { + if (parameter.dotDotDotToken) { + return; + } + var paramName = parameter.name, initializer = parameter.initializer; + if (ts.isBindingPattern(paramName)) { + var hasBindingElements = paramName.elements.length > 0; + if (hasBindingElements || initializer) { + writeLine(); + write("var "); + if (hasBindingElements) { + emitDestructuring(parameter, false, tempParameters[tempIndex]); + } + else { + emit(tempParameters[tempIndex]); + write(" = "); + emit(initializer); + } + write(";"); + tempIndex++; + } + } + else if (initializer) { + writeLine(); + emitStart(parameter); + write("if ("); + emitNodeWithoutSourceMap(paramName); + write(" === void 0)"); + emitEnd(parameter); + write(" { "); + emitStart(parameter); + emitNodeWithCommentsAndWithoutSourcemap(paramName); + write(" = "); + emitNodeWithCommentsAndWithoutSourcemap(initializer); + emitEnd(parameter); + write("; }"); + } + }); + } + } + function emitRestParameter(node) { + if (languageVersion < 2 && ts.hasRestParameter(node)) { + var restIndex = node.parameters.length - 1; + var restParam = node.parameters[restIndex]; + if (ts.isBindingPattern(restParam.name)) { + return; + } + var tempName = createTempVariable(268435456).text; + writeLine(); + emitLeadingComments(restParam); + emitStart(restParam); + write("var "); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write(" = [];"); + emitEnd(restParam); + emitTrailingComments(restParam); + writeLine(); + write("for ("); + emitStart(restParam); + write("var " + tempName + " = " + restIndex + ";"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + " < arguments.length;"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + "++"); + emitEnd(restParam); + write(") {"); + increaseIndent(); + writeLine(); + emitStart(restParam); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); + emitEnd(restParam); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitAccessor(node) { + write(node.kind === 145 ? "get " : "set "); + emit(node.name); + emitSignatureAndBody(node); + } + function shouldEmitAsArrowFunction(node) { + return node.kind === 174 && languageVersion >= 2; + } + function emitDeclarationName(node) { + if (node.name) { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + else { + write(getGeneratedNameForNode(node)); + } + } + function shouldEmitFunctionName(node) { + if (node.kind === 173) { + return !!node.name; + } + if (node.kind === 213) { + return !!node.name || languageVersion < 2; + } + } + function emitFunctionDeclaration(node) { + if (ts.nodeIsMissing(node.body)) { + return emitCommentsOnNotEmittedNode(node); + } + if (node.kind !== 143 && node.kind !== 142 && + node.parent && node.parent.kind !== 245 && + node.parent.kind !== 168) { + emitLeadingComments(node); + } + emitStart(node); + if (!shouldEmitAsArrowFunction(node)) { + if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024) { + write("default "); + } + } + write("function"); + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } + write(" "); + } + if (shouldEmitFunctionName(node)) { + emitDeclarationName(node); + } + emitSignatureAndBody(node); + if (modulekind !== 5 && node.kind === 213 && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + emitEnd(node); + if (node.kind !== 143 && node.kind !== 142) { + emitTrailingComments(node); + } + } + function emitCaptureThisForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 4) { + writeLine(); + emitStart(node); + write("var _this = this;"); + emitEnd(node); + } + } + function emitSignatureParameters(node) { + increaseIndent(); + write("("); + if (node) { + var parameters = node.parameters; + var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0; + emitList(parameters, 0, parameters.length - omitCount, false, false); + } + write(")"); + decreaseIndent(); + } + function emitSignatureParametersForArrow(node) { + if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { + emit(node.parameters[0]); + return; + } + emitSignatureParameters(node); + } + function emitAsyncFunctionBodyForES6(node) { + var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); + var isArrowFunction = node.kind === 174; + var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096) !== 0; + var args; + if (!isArrowFunction) { + write(" {"); + increaseIndent(); + writeLine(); + write("return"); + } + write(" __awaiter(this"); + if (hasLexicalArguments) { + write(", arguments"); + } + else { + write(", void 0"); + } + if (promiseConstructor) { + write(", "); + emitNodeWithoutSourceMap(promiseConstructor); + } + else { + write(", Promise"); + } + if (hasLexicalArguments) { + write(", function* (_arguments)"); + } + else { + write(", function* ()"); + } + emitFunctionBody(node); + write(")"); + if (!isArrowFunction) { + write(";"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitFunctionBody(node) { + if (!node.body) { + write(" { }"); + } + else { + if (node.body.kind === 192) { + emitBlockFunctionBody(node, node.body); + } + else { + emitExpressionFunctionBody(node, node.body); + } + } + } + function emitSignatureAndBody(node) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + if (shouldEmitAsArrowFunction(node)) { + emitSignatureParametersForArrow(node); + write(" =>"); + } + else { + emitSignatureParameters(node); + } + var isAsync = ts.isAsyncFunctionLike(node); + if (isAsync && languageVersion === 2) { + emitAsyncFunctionBodyForES6(node); + } + else { + emitFunctionBody(node); + } + if (!isES6ExportedDeclaration(node)) { + emitExportMemberAssignment(node); + } + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function emitFunctionBodyPreamble(node) { + emitCaptureThisForNodeIfNecessary(node); + emitDefaultValueAssignments(node); + emitRestParameter(node); + } + function emitExpressionFunctionBody(node, body) { + if (languageVersion < 2 || node.flags & 512) { + emitDownLevelExpressionFunctionBody(node, body); + return; + } + write(" "); + var current = body; + while (current.kind === 171) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 165); + } + function emitDownLevelExpressionFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + increaseIndent(); + var outPos = writer.getTextPos(); + emitDetachedComments(node.body); + emitFunctionBodyPreamble(node); + var preambleEmitted = writer.getTextPos() !== outPos; + decreaseIndent(); + if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { + write(" "); + emitStart(body); + write("return "); + emit(body); + emitEnd(body); + write(";"); + emitTempDeclarations(false); + write(" "); + } + else { + increaseIndent(); + writeLine(); + emitLeadingComments(node.body); + write("return "); + emit(body); + write(";"); + emitTrailingComments(node.body); + emitTempDeclarations(true); + decreaseIndent(); + writeLine(); + } + emitStart(node.body); + write("}"); + emitEnd(node.body); + scopeEmitEnd(); + } + function emitBlockFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + var initialTextPos = writer.getTextPos(); + increaseIndent(); + emitDetachedComments(body.statements); + var startIndex = emitDirectivePrologues(body.statements, true); + emitFunctionBodyPreamble(node); + decreaseIndent(); + var preambleEmitted = writer.getTextPos() !== initialTextPos; + if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { + for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { + var statement = _b[_a]; + write(" "); + emit(statement); + } + emitTempDeclarations(false); + write(" "); + emitLeadingCommentsOfPosition(body.statements.end); + } + else { + increaseIndent(); + emitLinesStartingAt(body.statements, startIndex); + emitTempDeclarations(true); + writeLine(); + emitLeadingCommentsOfPosition(body.statements.end); + decreaseIndent(); + } + emitToken(16, body.statements.end); + scopeEmitEnd(); + } + function findInitialSuperCall(ctor) { + if (ctor.body) { + var statement = ctor.body.statements[0]; + if (statement && statement.kind === 195) { + var expr = statement.expression; + if (expr && expr.kind === 168) { + var func = expr.expression; + if (func && func.kind === 95) { + return statement; + } + } + } + } + } + function emitParameterPropertyAssignments(node) { + ts.forEach(node.parameters, function (param) { + if (param.flags & 112) { + writeLine(); + emitStart(param); + emitStart(param.name); + write("this."); + emitNodeWithoutSourceMap(param.name); + emitEnd(param.name); + write(" = "); + emit(param.name); + write(";"); + emitEnd(param); + } + }); + } + function emitMemberAccessForPropertyName(memberName) { + if (memberName.kind === 9 || memberName.kind === 8) { + write("["); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + write("]"); + } + else if (memberName.kind === 136) { + emitComputedPropertyName(memberName); + } + else { + write("."); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + } + } + function getInitializedProperties(node, isStatic) { + var properties = []; + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if (member.kind === 141 && isStatic === ((member.flags & 128) !== 0) && member.initializer) { + properties.push(member); + } + } + return properties; + } + function emitPropertyDeclarations(node, properties) { + for (var _a = 0; _a < properties.length; _a++) { + var property = properties[_a]; + emitPropertyDeclaration(node, property); + } + } + function emitPropertyDeclaration(node, property, receiver, isExpression) { + writeLine(); + emitLeadingComments(property); + emitStart(property); + emitStart(property.name); + if (receiver) { + emit(receiver); + } + else { + if (property.flags & 128) { + emitDeclarationName(node); + } + else { + write("this"); + } + } + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + emit(property.initializer); + if (!isExpression) { + write(";"); + } + emitEnd(property); + emitTrailingComments(property); + } + function emitMemberFunctionsForES5AndLower(node) { + ts.forEach(node.members, function (member) { + if (member.kind === 191) { + writeLine(); + write(";"); + } + else if (member.kind === 143 || node.kind === 142) { + if (!member.body) { + return emitCommentsOnNotEmittedNode(member); + } + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + emitClassMemberPrefix(node, member); + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emitFunctionDeclaration(member); + emitEnd(member); + write(";"); + emitTrailingComments(member); + } + else if (member.kind === 145 || member.kind === 146) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor) { + writeLine(); + emitStart(member); + write("Object.defineProperty("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("});"); + emitEnd(member); + } + } + }); + } + function emitMemberFunctionsForES6AndHigher(node) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if ((member.kind === 143 || node.kind === 142) && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + else if (member.kind === 143 || + member.kind === 145 || + member.kind === 146) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + if (member.flags & 128) { + write("static "); + } + if (member.kind === 145) { + write("get "); + } + else if (member.kind === 146) { + write("set "); + } + if (member.asteriskToken) { + write("*"); + } + emit(member.name); + emitSignatureAndBody(member); + emitEnd(member); + emitTrailingComments(member); + } + else if (member.kind === 191) { + writeLine(); + write(";"); + } + } + } + function emitConstructor(node, baseTypeElement) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + emitConstructorWorker(node, baseTypeElement); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function emitConstructorWorker(node, baseTypeElement) { + var hasInstancePropertyWithInitializer = false; + ts.forEach(node.members, function (member) { + if (member.kind === 144 && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + if (member.kind === 141 && member.initializer && (member.flags & 128) === 0) { + hasInstancePropertyWithInitializer = true; + } + }); + var ctor = ts.getFirstConstructorWithBody(node); + if (languageVersion >= 2 && !ctor && !hasInstancePropertyWithInitializer) { + return; + } + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + if (languageVersion < 2) { + write("function "); + emitDeclarationName(node); + emitSignatureParameters(ctor); + } + else { + write("constructor"); + if (ctor) { + emitSignatureParameters(ctor); + } + else { + if (baseTypeElement) { + write("(...args)"); + } + else { + write("()"); + } + } + } + var startIndex = 0; + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + startIndex = emitDirectivePrologues(ctor.body.statements, true); + emitDetachedComments(ctor.body.statements); + } + emitCaptureThisForNodeIfNecessary(node); + var superCall; + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeElement) { + superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeElement) { + writeLine(); + emitStart(baseTypeElement); + if (languageVersion < 2) { + write("_super.apply(this, arguments);"); + } + else { + write("super(...args);"); + } + emitEnd(baseTypeElement); + } + } + emitPropertyDeclarations(node, getInitializedProperties(node, false)); + if (ctor) { + var statements = ctor.body.statements; + if (superCall) { + statements = statements.slice(1); + } + emitLinesStartingAt(statements, startIndex); + } + emitTempDeclarations(true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition(ctor.body.statements.end); + } + decreaseIndent(); + emitToken(16, ctor ? ctor.body.statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + } + function emitClassExpression(node) { + return emitClassLikeDeclaration(node); + } + function emitClassDeclaration(node) { + return emitClassLikeDeclaration(node); + } + function emitClassLikeDeclaration(node) { + if (languageVersion < 2) { + emitClassLikeDeclarationBelowES6(node); + } + else { + emitClassLikeDeclarationForES6AndHigher(node); + } + if (modulekind !== 5 && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + } + function emitClassLikeDeclarationForES6AndHigher(node) { + var thisNodeIsDecorated = ts.nodeIsDecorated(node); + if (node.kind === 214) { + if (thisNodeIsDecorated) { + if (isES6ExportedDeclaration(node) && !(node.flags & 1024)) { + write("export "); + } + write("let "); + emitDeclarationName(node); + write(" = "); + } + else if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024) { + write("default "); + } + } + } + var staticProperties = getInitializedProperties(node, true); + var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 186; + var tempVariable; + if (isClassExpressionWithStaticProperties) { + tempVariable = createAndRecordTempVariable(0); + write("("); + increaseIndent(); + emit(tempVariable); + write(" = "); + } + write("class"); + if ((node.name || (node.flags & 1024 && staticProperties.length > 0)) && !thisNodeIsDecorated) { + write(" "); + emitDeclarationName(node); + } + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write(" extends "); + emit(baseTypeNode.expression); + } + write(" {"); + increaseIndent(); + scopeEmitStart(node); + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES6AndHigher(node); + decreaseIndent(); + writeLine(); + emitToken(16, node.members.end); + scopeEmitEnd(); + if (thisNodeIsDecorated) { + write(";"); + } + if (isClassExpressionWithStaticProperties) { + for (var _a = 0; _a < staticProperties.length; _a++) { + var property = staticProperties[_a]; + write(","); + writeLine(); + emitPropertyDeclaration(node, property, tempVariable, true); + } + write(","); + writeLine(); + emit(tempVariable); + decreaseIndent(); + write(")"); + } + else { + writeLine(); + emitPropertyDeclarations(node, staticProperties); + emitDecoratorsOfClass(node); + } + if (!isES6ExportedDeclaration(node) && (node.flags & 1)) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } + else if (isES6ExportedDeclaration(node) && (node.flags & 1024) && thisNodeIsDecorated) { + writeLine(); + write("export default "); + emitDeclarationName(node); + write(";"); + } + } + function emitClassLikeDeclarationBelowES6(node) { + if (node.kind === 214) { + if (!shouldHoistDeclarationInSystemJsModule(node)) { + write("var "); + } + emitDeclarationName(node); + write(" = "); + } + write("(function ("); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write("_super"); + } + write(") {"); + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + computedPropertyNamesToGeneratedNames = undefined; + increaseIndent(); + scopeEmitStart(node); + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("__extends("); + emitDeclarationName(node); + write(", _super);"); + emitEnd(baseTypeNode); + } + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES5AndLower(node); + emitPropertyDeclarations(node, getInitializedProperties(node, true)); + writeLine(); + emitDecoratorsOfClass(node); + writeLine(); + emitToken(16, node.members.end, function () { + write("return "); + emitDeclarationName(node); + }); + write(";"); + emitTempDeclarations(true); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; + decreaseIndent(); + writeLine(); + emitToken(16, node.members.end); + scopeEmitEnd(); + emitStart(node); + write(")("); + if (baseTypeNode) { + emit(baseTypeNode.expression); + } + write(")"); + if (node.kind === 214) { + write(";"); + } + emitEnd(node); + if (node.kind === 214) { + emitExportMemberAssignment(node); + } + } + function emitClassMemberPrefix(node, member) { + emitDeclarationName(node); + if (!(member.flags & 128)) { + write(".prototype"); + } + } + function emitDecoratorsOfClass(node) { + emitDecoratorsOfMembers(node, 0); + emitDecoratorsOfMembers(node, 128); + emitDecoratorsOfConstructor(node); + } + function emitDecoratorsOfConstructor(node) { + var decorators = node.decorators; + var constructor = ts.getFirstConstructorWithBody(node); + var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); + if (!decorators && !hasDecoratedParameters) { + return; + } + writeLine(); + emitStart(node); + emitDeclarationName(node); + write(" = __decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(constructor, argumentsWritten > 0); + emitSerializedTypeMetadata(node, argumentsWritten >= 0); + decreaseIndent(); + writeLine(); + write("], "); + emitDeclarationName(node); + write(");"); + emitEnd(node); + writeLine(); + } + function emitDecoratorsOfMembers(node, staticFlag) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if ((member.flags & 128) !== staticFlag) { + continue; + } + if (!ts.nodeCanBeDecorated(member)) { + continue; + } + if (!ts.nodeOrChildIsDecorated(member)) { + continue; + } + var decorators = void 0; + var functionLikeMember = void 0; + if (ts.isAccessor(member)) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member !== accessors.firstAccessor) { + continue; + } + decorators = accessors.firstAccessor.decorators; + if (!decorators && accessors.secondAccessor) { + decorators = accessors.secondAccessor.decorators; + } + functionLikeMember = accessors.setAccessor; + } + else { + decorators = member.decorators; + if (member.kind === 143) { + functionLikeMember = member; + } + } + writeLine(); + emitStart(member); + write("__decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); + emitSerializedTypeMetadata(member, argumentsWritten > 0); + decreaseIndent(); + writeLine(); + write("], "); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + if (languageVersion > 0) { + if (member.kind !== 141) { + write(", null"); + } + else { + write(", void 0"); + } + } + write(");"); + emitEnd(member); + writeLine(); + } + } + function emitDecoratorsOfParameters(node, leadingComma) { + var argumentsWritten = 0; + if (node) { + var parameterIndex = 0; + for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { + var parameter = _b[_a]; + if (ts.nodeIsDecorated(parameter)) { + var decorators = parameter.decorators; + argumentsWritten += emitList(decorators, 0, decorators.length, true, false, leadingComma, true, function (decorator) { + emitStart(decorator); + write("__param(" + parameterIndex + ", "); + emit(decorator.expression); + write(")"); + emitEnd(decorator); + }); + leadingComma = true; + } + ++parameterIndex; + } + } + return argumentsWritten; + } + function shouldEmitTypeMetadata(node) { + switch (node.kind) { + case 143: + case 145: + case 146: + case 141: + return true; + } + return false; + } + function shouldEmitReturnTypeMetadata(node) { + switch (node.kind) { + case 143: + return true; + } + return false; + } + function shouldEmitParamTypesMetadata(node) { + switch (node.kind) { + case 214: + case 143: + case 146: + return true; + } + return false; + } + function emitSerializedTypeOfNode(node) { + switch (node.kind) { + case 214: + write("Function"); + return; + case 141: + emitSerializedTypeNode(node.type); + return; + case 138: + emitSerializedTypeNode(node.type); + return; + case 145: + emitSerializedTypeNode(node.type); + return; + case 146: + emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); + return; + } + if (ts.isFunctionLike(node)) { + write("Function"); + return; + } + write("void 0"); + } + function emitSerializedTypeNode(node) { + if (node) { + switch (node.kind) { + case 103: + write("void 0"); + return; + case 160: + emitSerializedTypeNode(node.type); + return; + case 152: + case 153: + write("Function"); + return; + case 156: + case 157: + write("Array"); + return; + case 150: + case 120: + write("Boolean"); + return; + case 130: + case 9: + write("String"); + return; + case 128: + write("Number"); + return; + case 131: + write("Symbol"); + return; + case 151: + emitSerializedTypeReferenceNode(node); + return; + case 154: + case 155: + case 158: + case 159: + case 117: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } + } + write("Object"); + } + function emitSerializedTypeReferenceNode(node) { + var location = node.parent; + while (ts.isDeclaration(location) || ts.isTypeNode(location)) { + location = location.parent; + } + var typeName = ts.cloneEntityName(node.typeName); + typeName.parent = location; + var result = resolver.getTypeReferenceSerializationKind(typeName); + switch (result) { + case ts.TypeReferenceSerializationKind.Unknown: + var temp = createAndRecordTempVariable(0); + write("(typeof ("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(typeName, true); + write(") === 'function' && "); + emitNodeWithoutSourceMap(temp); + write(") || Object"); + break; + case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: + emitEntityNameAsExpression(typeName, false); + break; + case ts.TypeReferenceSerializationKind.VoidType: + write("void 0"); + break; + case ts.TypeReferenceSerializationKind.BooleanType: + write("Boolean"); + break; + case ts.TypeReferenceSerializationKind.NumberLikeType: + write("Number"); + break; + case ts.TypeReferenceSerializationKind.StringLikeType: + write("String"); + break; + case ts.TypeReferenceSerializationKind.ArrayLikeType: + write("Array"); + break; + case ts.TypeReferenceSerializationKind.ESSymbolType: + if (languageVersion < 2) { + write("typeof Symbol === 'function' ? Symbol : Object"); + } + else { + write("Symbol"); + } + break; + case ts.TypeReferenceSerializationKind.TypeWithCallSignature: + write("Function"); + break; + case ts.TypeReferenceSerializationKind.ObjectType: + write("Object"); + break; + } + } + function emitSerializedParameterTypesOfNode(node) { + if (node) { + var valueDeclaration; + if (node.kind === 214) { + valueDeclaration = ts.getFirstConstructorWithBody(node); + } + else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { + valueDeclaration = node; + } + if (valueDeclaration) { + var parameters = valueDeclaration.parameters; + var parameterCount = parameters.length; + if (parameterCount > 0) { + for (var i = 0; i < parameterCount; i++) { + if (i > 0) { + write(", "); + } + if (parameters[i].dotDotDotToken) { + var parameterType = parameters[i].type; + if (parameterType.kind === 156) { + parameterType = parameterType.elementType; + } + else if (parameterType.kind === 151 && parameterType.typeArguments && parameterType.typeArguments.length === 1) { + parameterType = parameterType.typeArguments[0]; + } + else { + parameterType = undefined; + } + emitSerializedTypeNode(parameterType); + } + else { + emitSerializedTypeOfNode(parameters[i]); + } + } + } + } + } + } + function emitSerializedReturnTypeOfNode(node) { + if (node && ts.isFunctionLike(node) && node.type) { + emitSerializedTypeNode(node.type); + return; + } + write("void 0"); + } + function emitSerializedTypeMetadata(node, writeComma) { + var argumentsWritten = 0; + if (compilerOptions.emitDecoratorMetadata) { + if (shouldEmitTypeMetadata(node)) { + if (writeComma) { + write(", "); + } + writeLine(); + write("__metadata('design:type', "); + emitSerializedTypeOfNode(node); + write(")"); + argumentsWritten++; + } + if (shouldEmitParamTypesMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:paramtypes', ["); + emitSerializedParameterTypesOfNode(node); + write("])"); + argumentsWritten++; + } + if (shouldEmitReturnTypeMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:returntype', "); + emitSerializedReturnTypeOfNode(node); + write(")"); + argumentsWritten++; + } + } + return argumentsWritten; + } + function emitInterfaceDeclaration(node) { + emitCommentsOnNotEmittedNode(node); + } + function shouldEmitEnumDeclaration(node) { + var isConstEnum = ts.isConst(node); + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; + } + function emitEnumDeclaration(node) { + if (!shouldEmitEnumDeclaration(node)) { + return; + } + if (!shouldHoistDeclarationInSystemJsModule(node)) { + if (!(node.flags & 1) || isES6ExportedDeclaration(node)) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + emitEnd(node); + write(";"); + } + } + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") {"); + increaseIndent(); + scopeEmitStart(node); + emitLines(node.members); + decreaseIndent(); + writeLine(); + emitToken(16, node.members.end); + scopeEmitEnd(); + write(")("); + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) { + writeLine(); + emitStart(node); + write("var "); + emit(node.name); + write(" = "); + emitModuleMemberName(node); + emitEnd(node); + write(";"); + } + if (modulekind !== 5 && node.parent === currentSourceFile) { + if (modulekind === 4 && (node.flags & 1)) { + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + function emitEnumMember(node) { + var enumParent = node.parent; + emitStart(node); + write(getGeneratedNameForNode(enumParent)); + write("["); + write(getGeneratedNameForNode(enumParent)); + write("["); + emitExpressionForPropertyName(node.name); + write("] = "); + writeEnumMemberDeclarationValue(node); + write("] = "); + emitExpressionForPropertyName(node.name); + emitEnd(node); + write(";"); + } + function writeEnumMemberDeclarationValue(member) { + var value = resolver.getConstantValue(member); + if (value !== undefined) { + write(value.toString()); + return; + } + else if (member.initializer) { + emit(member.initializer); + } + else { + write("undefined"); + } + } + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { + if (moduleDeclaration.body.kind === 218) { + var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + function shouldEmitModuleDeclaration(node) { + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); + } + function isModuleMergedWithES6Class(node) { + return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 32768); + } + function emitModuleDeclaration(node) { + var shouldEmit = shouldEmitModuleDeclaration(node); + if (!shouldEmit) { + return emitCommentsOnNotEmittedNode(node); + } + var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); + var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); + if (emitVarForModule) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); + } + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") "); + if (node.body.kind === 219) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + tempFlags = 0; + tempVariables = undefined; + emit(node.body); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + } + else { + write("{"); + increaseIndent(); + scopeEmitStart(node); + emitCaptureThisForNodeIfNecessary(node); + writeLine(); + emit(node.body); + decreaseIndent(); + writeLine(); + var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; + emitToken(16, moduleBlock.statements.end); + scopeEmitEnd(); + } + write(")("); + if ((node.flags & 1) && !isES6ExportedDeclaration(node)) { + emit(node.name); + write(" = "); + } + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.name.kind === 69 && node.parent === currentSourceFile) { + if (modulekind === 4 && (node.flags & 1)) { + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + function tryRenameExternalModule(moduleName) { + if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { + return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; + } + return undefined; + } + function emitRequire(moduleName) { + if (moduleName.kind === 9) { + write("require("); + var text = tryRenameExternalModule(moduleName); + if (text) { + write(text); + } + else { + emitStart(moduleName); + emitLiteral(moduleName); + emitEnd(moduleName); + } + emitToken(18, moduleName.end); + } + else { + write("require()"); + } + } + function getNamespaceDeclarationNode(node) { + if (node.kind === 221) { + return node; + } + var importClause = node.importClause; + if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 224) { + return importClause.namedBindings; + } + } + function isDefaultImport(node) { + return node.kind === 222 && node.importClause && !!node.importClause.name; + } + function emitExportImportAssignments(node) { + if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + emitExportMemberAssignments(node.name); + } + ts.forEachChild(node, emitExportImportAssignments); + } + function emitImportDeclaration(node) { + if (modulekind !== 5) { + return emitExternalImportDeclaration(node); + } + if (node.importClause) { + var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); + var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, true); + if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { + write("import "); + emitStart(node.importClause); + if (shouldEmitDefaultBindings) { + emit(node.importClause.name); + if (shouldEmitNamedBindings) { + write(", "); + } + } + if (shouldEmitNamedBindings) { + emitLeadingComments(node.importClause.namedBindings); + emitStart(node.importClause.namedBindings); + if (node.importClause.namedBindings.kind === 224) { + write("* as "); + emit(node.importClause.namedBindings.name); + } + else { + write("{ "); + emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); + write(" }"); + } + emitEnd(node.importClause.namedBindings); + emitTrailingComments(node.importClause.namedBindings); + } + emitEnd(node.importClause); + write(" from "); + emit(node.moduleSpecifier); + write(";"); + } + } + else { + write("import "); + emit(node.moduleSpecifier); + write(";"); + } + } + function emitExternalImportDeclaration(node) { + if (ts.contains(externalImports, node)) { + var isExportedImport = node.kind === 221 && (node.flags & 1) !== 0; + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (modulekind !== 2) { + emitLeadingComments(node); + emitStart(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + if (!isExportedImport) + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + } + else { + var isNakedImport = 222 && !node.importClause; + if (!isNakedImport) { + write("var "); + write(getGeneratedNameForNode(node)); + write(" = "); + } + } + emitRequire(ts.getExternalModuleName(node)); + if (namespaceDeclaration && isDefaultImport(node)) { + write(", "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + else { + if (isExportedImport) { + emitModuleMemberName(namespaceDeclaration); + write(" = "); + emit(namespaceDeclaration.name); + write(";"); + } + else if (namespaceDeclaration && isDefaultImport(node)) { + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + write(";"); + } + emitExportImportAssignments(node); + } + } + } + function emitImportEqualsDeclaration(node) { + if (ts.isExternalModuleImportEqualsDeclaration(node)) { + emitExternalImportDeclaration(node); + return; + } + if (resolver.isReferencedAliasDeclaration(node) || + (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { + emitLeadingComments(node); + emitStart(node); + var variableDeclarationIsHoisted = shouldHoistVariable(node, true); + var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, true); + if (!variableDeclarationIsHoisted) { + ts.Debug.assert(!isExported); + if (isES6ExportedDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & 1)) { + write("var "); + } + } + if (isExported) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.name); + write("\", "); + } + emitModuleMemberName(node); + write(" = "); + emit(node.moduleReference); + if (isExported) { + write(")"); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + } + function emitExportDeclaration(node) { + ts.Debug.assert(modulekind !== 4); + if (modulekind !== 5) { + if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { + emitStart(node); + var generatedName = getGeneratedNameForNode(node); + if (node.exportClause) { + if (modulekind !== 2) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(ts.getExternalModuleName(node)); + write(";"); + } + for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { + var specifier = _b[_a]; + if (resolver.isValueAliasDeclaration(specifier)) { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + } + } + } + else { + writeLine(); + write("__export("); + if (modulekind !== 2) { + emitRequire(ts.getExternalModuleName(node)); + } + else { + write(generatedName); + } + write(");"); + } + emitEnd(node); + } + } + else { + if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { + write("export "); + if (node.exportClause) { + write("{ "); + emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + emit(node.moduleSpecifier); + } + write(";"); + } + } + } + function emitExportOrImportSpecifierList(specifiers, shouldEmit) { + ts.Debug.assert(modulekind === 5); + var needsComma = false; + for (var _a = 0; _a < specifiers.length; _a++) { + var specifier = specifiers[_a]; + if (shouldEmit(specifier)) { + if (needsComma) { + write(", "); + } + if (specifier.propertyName) { + emit(specifier.propertyName); + write(" as "); + } + emit(specifier.name); + needsComma = true; + } + } + } + function emitExportAssignment(node) { + if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { + if (modulekind === 5) { + writeLine(); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== 213 && + expression.kind !== 214) { + write(";"); + } + emitEnd(node); + } + else { + writeLine(); + emitStart(node); + if (modulekind === 4) { + write(exportFunctionForFile + "(\"default\","); + emit(node.expression); + write(")"); + } + else { + emitEs6ExportDefaultCompat(node); + emitContainingModuleName(node); + if (languageVersion === 0) { + write("[\"default\"] = "); + } + else { + write(".default = "); + } + emit(node.expression); + } + write(";"); + emitEnd(node); + } + } + } + function collectExternalModuleInfo(sourceFile) { + externalImports = []; + exportSpecifiers = {}; + exportEquals = undefined; + hasExportStars = false; + for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { + var node = _b[_a]; + switch (node.kind) { + case 222: + if (!node.importClause || + resolver.isReferencedAliasDeclaration(node.importClause, true)) { + externalImports.push(node); + } + break; + case 221: + if (node.moduleReference.kind === 232 && resolver.isReferencedAliasDeclaration(node)) { + externalImports.push(node); + } + break; + case 228: + if (node.moduleSpecifier) { + if (!node.exportClause) { + externalImports.push(node); + hasExportStars = true; + } + else if (resolver.isValueAliasDeclaration(node)) { + externalImports.push(node); + } + } + else { + for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { + var specifier = _d[_c]; + var name_25 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_25] || (exportSpecifiers[name_25] = [])).push(specifier); + } + } + break; + case 227: + if (node.isExportEquals && !exportEquals) { + exportEquals = node; + } + break; + } + } + } + function emitExportStarHelper() { + if (hasExportStars) { + writeLine(); + write("function __export(m) {"); + increaseIndent(); + writeLine(); + write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function getLocalNameForExternalImport(node) { + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); + } + if (node.kind === 222 && node.importClause) { + return getGeneratedNameForNode(node); + } + if (node.kind === 228 && node.moduleSpecifier) { + return getGeneratedNameForNode(node); + } + } + function getExternalModuleNameText(importNode) { + var moduleName = ts.getExternalModuleName(importNode); + if (moduleName.kind === 9) { + return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); + } + return undefined; + } + function emitVariableDeclarationsForImports() { + if (externalImports.length === 0) { + return; + } + writeLine(); + var started = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var importNode = externalImports[_a]; + var skipNode = importNode.kind === 228 || + (importNode.kind === 222 && !importNode.importClause); + if (skipNode) { + continue; + } + if (!started) { + write("var "); + started = true; + } + else { + write(", "); + } + write(getLocalNameForExternalImport(importNode)); + } + if (started) { + write(";"); + } + } + function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { + if (!hasExportStars) { + return undefined; + } + if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { + var hasExportDeclarationWithExportClause = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var externalImport = externalImports[_a]; + if (externalImport.kind === 228 && externalImport.exportClause) { + hasExportDeclarationWithExportClause = true; + break; + } + } + if (!hasExportDeclarationWithExportClause) { + return emitExportStarFunction(undefined); + } + } + var exportedNamesStorageRef = makeUniqueName("exportedNames"); + writeLine(); + write("var " + exportedNamesStorageRef + " = {"); + increaseIndent(); + var started = false; + if (exportedDeclarations) { + for (var i = 0; i < exportedDeclarations.length; ++i) { + writeExportedName(exportedDeclarations[i]); + } + } + if (exportSpecifiers) { + for (var n in exportSpecifiers) { + for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { + var specifier = _c[_b]; + writeExportedName(specifier.name); + } + } + } + for (var _d = 0; _d < externalImports.length; _d++) { + var externalImport = externalImports[_d]; + if (externalImport.kind !== 228) { + continue; + } + var exportDecl = externalImport; + if (!exportDecl.exportClause) { + continue; + } + for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { + var element = _f[_e]; + writeExportedName(element.name || element.propertyName); + } + } + decreaseIndent(); + writeLine(); + write("};"); + return emitExportStarFunction(exportedNamesStorageRef); + function emitExportStarFunction(localNames) { + var exportStarFunction = makeUniqueName("exportStar"); + writeLine(); + write("function " + exportStarFunction + "(m) {"); + increaseIndent(); + writeLine(); + write("var exports = {};"); + writeLine(); + write("for(var n in m) {"); + increaseIndent(); + writeLine(); + write("if (n !== \"default\""); + if (localNames) { + write("&& !" + localNames + ".hasOwnProperty(n)"); + } + write(") exports[n] = m[n];"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write(exportFunctionForFile + "(exports);"); + decreaseIndent(); + writeLine(); + write("}"); + return exportStarFunction; + } + function writeExportedName(node) { + if (node.kind !== 69 && node.flags & 1024) { + return; + } + if (started) { + write(","); + } + else { + started = true; + } + writeLine(); + write("'"); + if (node.kind === 69) { + emitNodeWithCommentsAndWithoutSourcemap(node); + } + else { + emitDeclarationName(node); + } + write("': true"); + } + } + function processTopLevelVariableAndFunctionDeclarations(node) { + var hoistedVars; + var hoistedFunctionDeclarations; + var exportedDeclarations; + visit(node); + if (hoistedVars) { + writeLine(); + write("var "); + var seen = {}; + for (var i = 0; i < hoistedVars.length; ++i) { + var local = hoistedVars[i]; + var name_26 = local.kind === 69 + ? local + : local.name; + if (name_26) { + var text = ts.unescapeIdentifier(name_26.text); + if (ts.hasProperty(seen, text)) { + continue; + } + else { + seen[text] = text; + } + } + if (i !== 0) { + write(", "); + } + if (local.kind === 214 || local.kind === 218 || local.kind === 217) { + emitDeclarationName(local); + } + else { + emit(local); + } + var flags = ts.getCombinedNodeFlags(local.kind === 69 ? local.parent : local); + if (flags & 1) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(local); + } + } + write(";"); + } + if (hoistedFunctionDeclarations) { + for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { + var f = hoistedFunctionDeclarations[_a]; + writeLine(); + emit(f); + if (f.flags & 1) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(f); + } + } + } + return exportedDeclarations; + function visit(node) { + if (node.flags & 2) { + return; + } + if (node.kind === 213) { + if (!hoistedFunctionDeclarations) { + hoistedFunctionDeclarations = []; + } + hoistedFunctionDeclarations.push(node); + return; + } + if (node.kind === 214) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + return; + } + if (node.kind === 217) { + if (shouldEmitEnumDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 218) { + if (shouldEmitModuleDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 211 || node.kind === 163) { + if (shouldHoistVariable(node, false)) { + var name_27 = node.name; + if (name_27.kind === 69) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(name_27); + } + else { + ts.forEachChild(name_27, visit); + } + } + return; + } + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node.name); + return; + } + if (ts.isBindingPattern(node)) { + ts.forEach(node.elements, visit); + return; + } + if (!ts.isDeclaration(node)) { + ts.forEachChild(node, visit); + } + } + } + function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { + if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { + return false; + } + return (ts.getCombinedNodeFlags(node) & 49152) === 0 || + ts.getEnclosingBlockScopeContainer(node).kind === 248; + } + function isCurrentFileSystemExternalModule() { + return modulekind === 4 && ts.isExternalModule(currentSourceFile); + } + function emitSystemModuleBody(node, dependencyGroups, startIndex) { + emitVariableDeclarationsForImports(); + writeLine(); + var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); + var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); + writeLine(); + write("return {"); + increaseIndent(); + writeLine(); + emitSetters(exportStarFunction, dependencyGroups); + writeLine(); + emitExecute(node, startIndex); + decreaseIndent(); + writeLine(); + write("}"); + emitTempDeclarations(true); + } + function emitSetters(exportStarFunction, dependencyGroups) { + write("setters:["); + for (var i = 0; i < dependencyGroups.length; ++i) { + if (i !== 0) { + write(","); + } + writeLine(); + increaseIndent(); + var group = dependencyGroups[i]; + var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); + write("function (" + parameterName + ") {"); + increaseIndent(); + for (var _a = 0; _a < group.length; _a++) { + var entry = group[_a]; + var importVariableName = getLocalNameForExternalImport(entry) || ""; + switch (entry.kind) { + case 222: + if (!entry.importClause) { + break; + } + case 221: + ts.Debug.assert(importVariableName !== ""); + writeLine(); + write(importVariableName + " = " + parameterName + ";"); + writeLine(); + break; + case 228: + ts.Debug.assert(importVariableName !== ""); + if (entry.exportClause) { + writeLine(); + write(exportFunctionForFile + "({"); + writeLine(); + increaseIndent(); + for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { + if (i_2 !== 0) { + write(","); + writeLine(); + } + var e = entry.exportClause.elements[i_2]; + write("\""); + emitNodeWithCommentsAndWithoutSourcemap(e.name); + write("\": " + parameterName + "[\""); + emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); + write("\"]"); + } + decreaseIndent(); + writeLine(); + write("});"); + } + else { + writeLine(); + write(exportStarFunction + "(" + parameterName + ");"); + } + writeLine(); + break; + } + } + decreaseIndent(); + write("}"); + decreaseIndent(); + } + write("],"); + } + function emitExecute(node, startIndex) { + write("execute: function() {"); + increaseIndent(); + writeLine(); + for (var i = startIndex; i < node.statements.length; ++i) { + var statement = node.statements[i]; + switch (statement.kind) { + case 213: + case 222: + continue; + case 228: + if (!statement.moduleSpecifier) { + for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { + var element = _b[_a]; + emitExportSpecifierInSystemModule(element); + } + } + continue; + case 221: + if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { + continue; + } + default: + writeLine(); + emit(statement); + } + } + decreaseIndent(); + writeLine(); + write("}"); + } + function emitSystemModule(node) { + collectExternalModuleInfo(node); + ts.Debug.assert(!exportFunctionForFile); + exportFunctionForFile = makeUniqueName("exports"); + writeLine(); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); + var groupIndices = {}; + var dependencyGroups = []; + for (var i = 0; i < externalImports.length; ++i) { + var text = getExternalModuleNameText(externalImports[i]); + if (ts.hasProperty(groupIndices, text)) { + var groupIndex = groupIndices[text]; + dependencyGroups[groupIndex].push(externalImports[i]); + continue; + } + else { + groupIndices[text] = dependencyGroups.length; + dependencyGroups.push([externalImports[i]]); + } + if (i !== 0) { + write(", "); + } + write(text); + } + write("], function(" + exportFunctionForFile + ") {"); + writeLine(); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, true); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitSystemModuleBody(node, dependencyGroups, startIndex); + decreaseIndent(); + writeLine(); + write("});"); + } + function getAMDDependencyNames(node, includeNonAmdDependencies) { + var aliasedModuleNames = []; + var unaliasedModuleNames = []; + var importAliasNames = []; + for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { + var amdDependency = _b[_a]; + if (amdDependency.name) { + aliasedModuleNames.push("\"" + amdDependency.path + "\""); + importAliasNames.push(amdDependency.name); + } + else { + unaliasedModuleNames.push("\"" + amdDependency.path + "\""); + } + } + for (var _c = 0; _c < externalImports.length; _c++) { + var importNode = externalImports[_c]; + var externalModuleName = getExternalModuleNameText(importNode); + var importAliasName = getLocalNameForExternalImport(importNode); + if (includeNonAmdDependencies && importAliasName) { + aliasedModuleNames.push(externalModuleName); + importAliasNames.push(importAliasName); + } + else { + unaliasedModuleNames.push(externalModuleName); + } + } + return { aliasedModuleNames: aliasedModuleNames, unaliasedModuleNames: unaliasedModuleNames, importAliasNames: importAliasNames }; + } + function emitAMDDependencies(node, includeNonAmdDependencies) { + var dependencyNames = getAMDDependencyNames(node, includeNonAmdDependencies); + emitAMDDependencyList(dependencyNames); + write(", "); + emitAMDFactoryHeader(dependencyNames); + } + function emitAMDDependencyList(_a) { + var aliasedModuleNames = _a.aliasedModuleNames, unaliasedModuleNames = _a.unaliasedModuleNames; + write("[\"require\", \"exports\""); + if (aliasedModuleNames.length) { + write(", "); + write(aliasedModuleNames.join(", ")); + } + if (unaliasedModuleNames.length) { + write(", "); + write(unaliasedModuleNames.join(", ")); + } + write("]"); + } + function emitAMDFactoryHeader(_a) { + var importAliasNames = _a.importAliasNames; + write("function (require, exports"); + if (importAliasNames.length) { + write(", "); + write(importAliasNames.join(", ")); + } + write(") {"); + } + function emitAMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + writeLine(); + write("define("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + emitAMDDependencies(node, true); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + emitExportEquals(true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitCommonJSModule(node) { + var startIndex = emitDirectivePrologues(node.statements, false); + emitEmitHelpers(node); + collectExternalModuleInfo(node); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + emitExportEquals(false); + } + function emitUMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + var dependencyNames = getAMDDependencyNames(node, false); + writeLines("(function (factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define("); + emitAMDDependencyList(dependencyNames); + write(", factory);"); + writeLines(" }\n})("); + emitAMDFactoryHeader(dependencyNames); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + emitExportEquals(true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitES6Module(node) { + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + var startIndex = emitDirectivePrologues(node.statements, false); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + } + function emitExportEquals(emitAsReturn) { + if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { + writeLine(); + emitStart(exportEquals); + write(emitAsReturn ? "return " : "module.exports = "); + emit(exportEquals.expression); + write(";"); + emitEnd(exportEquals); + } + } + function emitJsxElement(node) { + switch (compilerOptions.jsx) { + case 2: + jsxEmitReact(node); + break; + case 1: + default: + jsxEmitPreserve(node); + break; + } + } + function trimReactWhitespaceAndApplyEntities(node) { + var result = undefined; + var text = ts.getTextOfNode(node, true); + var firstNonWhitespace = 0; + var lastNonWhitespace = -1; + for (var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + if (ts.isLineBreak(c)) { + if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { + var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + firstNonWhitespace = -1; + } + else if (!ts.isWhiteSpace(c)) { + lastNonWhitespace = i; + if (firstNonWhitespace === -1) { + firstNonWhitespace = i; + } + } + } + if (firstNonWhitespace !== -1) { + var part = text.substr(firstNonWhitespace); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + if (result) { + result = result.replace(/&(\w+);/g, function (s, m) { + if (entities[m] !== undefined) { + return String.fromCharCode(entities[m]); + } + else { + return s; + } + }); + } + return result; + } + function getTextToEmit(node) { + switch (compilerOptions.jsx) { + case 2: + var text = trimReactWhitespaceAndApplyEntities(node); + if (text === undefined || text.length === 0) { + return undefined; + } + else { + return text; + } + case 1: + default: + return ts.getTextOfNode(node, true); + } + } + function emitJsxText(node) { + switch (compilerOptions.jsx) { + case 2: + write("\""); + write(trimReactWhitespaceAndApplyEntities(node)); + write("\""); + break; + case 1: + default: + writer.writeLiteral(ts.getTextOfNode(node, true)); + break; + } + } + function emitJsxExpression(node) { + if (node.expression) { + switch (compilerOptions.jsx) { + case 1: + default: + write("{"); + emit(node.expression); + write("}"); + break; + case 2: + emit(node.expression); + break; + } + } + } + function emitDirectivePrologues(statements, startWithNewLine) { + for (var i = 0; i < statements.length; ++i) { + if (ts.isPrologueDirective(statements[i])) { + if (startWithNewLine || i > 0) { + writeLine(); + } + emit(statements[i]); + } + else { + return i; + } + } + return statements.length; + } + function writeLines(text) { + var lines = text.split(/\r\n|\r|\n/g); + for (var i = 0; i < lines.length; ++i) { + var line = lines[i]; + if (line.length) { + writeLine(); + write(line); + } + } + } + function emitEmitHelpers(node) { + if (!compilerOptions.noEmitHelpers) { + if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) { + writeLines(extendsHelper); + extendsEmitted = true; + } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16) { + writeLines(decorateHelper); + if (compilerOptions.emitDecoratorMetadata) { + writeLines(metadataHelper); + } + decorateEmitted = true; + } + if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32) { + writeLines(paramHelper); + paramEmitted = true; + } + if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64) { + writeLines(awaiterHelper); + awaiterEmitted = true; + } + } + } + function emitSourceFileNode(node) { + writeLine(); + emitShebang(); + emitDetachedComments(node); + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { + var emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[1]; + emitModule(node); + } + else { + var startIndex = emitDirectivePrologues(node.statements, false); + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + } + emitLeadingComments(node.endOfFileToken); + } + function emitNodeWithCommentsAndWithoutSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); + } + function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { + if (node) { + if (node.flags & 2) { + return emitCommentsOnNotEmittedNode(node); + } + if (isSpecializedCommentHandling(node)) { + return emitNodeWithoutSourceMap(node); + } + var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); + if (emitComments_1) { + emitLeadingComments(node); + } + emitNodeConsideringSourcemap(node); + if (emitComments_1) { + emitTrailingComments(node); + } + } + } + function emitNodeWithoutSourceMap(node) { + if (node) { + emitJavaScriptWorker(node); + } + } + function isSpecializedCommentHandling(node) { + switch (node.kind) { + case 215: + case 213: + case 222: + case 221: + case 216: + case 227: + return true; + } + } + function shouldEmitLeadingAndTrailingComments(node) { + switch (node.kind) { + case 193: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); + case 218: + return shouldEmitModuleDeclaration(node); + case 217: + return shouldEmitEnumDeclaration(node); + } + ts.Debug.assert(!isSpecializedCommentHandling(node)); + if (node.kind !== 192 && + node.parent && + node.parent.kind === 174 && + node.parent.body === node && + compilerOptions.target <= 1) { + return false; + } + return true; + } + function emitJavaScriptWorker(node) { + switch (node.kind) { + case 69: + return emitIdentifier(node); + case 138: + return emitParameter(node); + case 143: + case 142: + return emitMethod(node); + case 145: + case 146: + return emitAccessor(node); + case 97: + return emitThis(node); + case 95: + return emitSuper(node); + case 93: + return write("null"); + case 99: + return write("true"); + case 84: + return write("false"); + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + return emitLiteral(node); + case 183: + return emitTemplateExpression(node); + case 190: + return emitTemplateSpan(node); + case 233: + case 234: + return emitJsxElement(node); + case 236: + return emitJsxText(node); + case 240: + return emitJsxExpression(node); + case 135: + return emitQualifiedName(node); + case 161: + return emitObjectBindingPattern(node); + case 162: + return emitArrayBindingPattern(node); + case 163: + return emitBindingElement(node); + case 164: + return emitArrayLiteral(node); + case 165: + return emitObjectLiteral(node); + case 245: + return emitPropertyAssignment(node); + case 246: + return emitShorthandPropertyAssignment(node); + case 136: + return emitComputedPropertyName(node); + case 166: + return emitPropertyAccess(node); + case 167: + return emitIndexedAccess(node); + case 168: + return emitCallExpression(node); + case 169: + return emitNewExpression(node); + case 170: + return emitTaggedTemplateExpression(node); + case 171: + return emit(node.expression); + case 189: + return emit(node.expression); + case 172: + return emitParenExpression(node); + case 213: + case 173: + case 174: + return emitFunctionDeclaration(node); + case 175: + return emitDeleteExpression(node); + case 176: + return emitTypeOfExpression(node); + case 177: + return emitVoidExpression(node); + case 178: + return emitAwaitExpression(node); + case 179: + return emitPrefixUnaryExpression(node); + case 180: + return emitPostfixUnaryExpression(node); + case 181: + return emitBinaryExpression(node); + case 182: + return emitConditionalExpression(node); + case 185: + return emitSpreadElementExpression(node); + case 184: + return emitYieldExpression(node); + case 187: + return; + case 192: + case 219: + return emitBlock(node); + case 193: + return emitVariableStatement(node); + case 194: + return write(";"); + case 195: + return emitExpressionStatement(node); + case 196: + return emitIfStatement(node); + case 197: + return emitDoStatement(node); + case 198: + return emitWhileStatement(node); + case 199: + return emitForStatement(node); + case 201: + case 200: + return emitForInOrForOfStatement(node); + case 202: + case 203: + return emitBreakOrContinueStatement(node); + case 204: + return emitReturnStatement(node); + case 205: + return emitWithStatement(node); + case 206: + return emitSwitchStatement(node); + case 241: + case 242: + return emitCaseOrDefaultClause(node); + case 207: + return emitLabelledStatement(node); + case 208: + return emitThrowStatement(node); + case 209: + return emitTryStatement(node); + case 244: + return emitCatchClause(node); + case 210: + return emitDebuggerStatement(node); + case 211: + return emitVariableDeclaration(node); + case 186: + return emitClassExpression(node); + case 214: + return emitClassDeclaration(node); + case 215: + return emitInterfaceDeclaration(node); + case 217: + return emitEnumDeclaration(node); + case 247: + return emitEnumMember(node); + case 218: + return emitModuleDeclaration(node); + case 222: + return emitImportDeclaration(node); + case 221: + return emitImportEqualsDeclaration(node); + case 228: + return emitExportDeclaration(node); + case 227: + return emitExportAssignment(node); + case 248: + return emitSourceFileNode(node); + } + } + function hasDetachedComments(pos) { + return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; + } + function getLeadingCommentsWithoutDetachedComments() { + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); + if (detachedCommentsInfo.length - 1) { + detachedCommentsInfo.pop(); + } + else { + detachedCommentsInfo = undefined; + } + return leadingComments; + } + function isPinnedComments(comment) { + return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 33; + } + function isTripleSlashComment(comment) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 47) { + var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); + return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || + textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? + true : false; + } + return false; + } + function getLeadingCommentsToEmit(node) { + if (node.parent) { + if (node.parent.kind === 248 || node.pos !== node.parent.pos) { + if (hasDetachedComments(node.pos)) { + return getLeadingCommentsWithoutDetachedComments(); + } + else { + return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + } + } + } + function getTrailingCommentsToEmit(node) { + if (node.parent) { + if (node.parent.kind === 248 || node.end !== node.parent.end) { + return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + } + } + } + function emitCommentsOnNotEmittedNode(node) { + emitLeadingCommentsWorker(node, false); + } + function emitLeadingComments(node) { + return emitLeadingCommentsWorker(node, true); + } + function emitLeadingCommentsWorker(node, isEmittedNode) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (isEmittedNode) { + leadingComments = getLeadingCommentsToEmit(node); + } + else { + if (node.pos === 0) { + leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); + } + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitTrailingComments(node) { + if (compilerOptions.removeComments) { + return; + } + var trailingComments = getTrailingCommentsToEmit(node); + ts.emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + } + function emitTrailingCommentsOfPosition(pos) { + if (compilerOptions.removeComments) { + return; + } + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); + ts.emitComments(currentSourceFile, writer, trailingComments, true, newLine, writeComment); + } + function emitLeadingCommentsOfPositionWorker(pos) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (hasDetachedComments(pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitDetachedComments(node) { + var leadingComments; + if (compilerOptions.removeComments) { + if (node.pos === 0) { + leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); + } + } + else { + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); + } + if (leadingComments) { + var detachedComments = []; + var lastComment; + ts.forEach(leadingComments, function (comment) { + if (lastComment) { + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); + var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); + if (commentLine >= lastCommentLine + 2) { + return detachedComments; + } + } + detachedComments.push(comment); + lastComment = comment; + }); + if (detachedComments.length) { + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); + var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); + if (nodeLine >= lastCommentLine + 2) { + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + ts.emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); + var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; + if (detachedCommentsInfo) { + detachedCommentsInfo.push(currentDetachedCommentInfo); + } + else { + detachedCommentsInfo = [currentDetachedCommentInfo]; + } + } + } + } + } + function emitShebang() { + var shebang = ts.getShebang(currentSourceFile.text); + if (shebang) { + write(shebang); + } + } + var _a; + } + function emitFile(jsFilePath, sourceFile) { + emitJavaScript(jsFilePath, sourceFile); + if (compilerOptions.declaration) { + ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); + } + } + } + ts.emitFiles = emitFiles; })(ts || (ts = {})); var ts; (function (ts) { @@ -29330,7 +29851,7 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; var emptyArray = []; - ts.version = "1.7.0"; + ts.version = "1.8.0"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -29368,11 +29889,11 @@ var ts; if (ts.getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { var failedLookupLocations = []; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); - var resolvedFileName = loadNodeModuleFromFile(candidate, false, failedLookupLocations, host); + var resolvedFileName = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (resolvedFileName) { return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } - resolvedFileName = loadNodeModuleFromDirectory(candidate, false, failedLookupLocations, host); + resolvedFileName = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); return resolvedFileName ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; @@ -29382,13 +29903,8 @@ var ts; } } ts.nodeModuleNameResolver = nodeModuleNameResolver; - function loadNodeModuleFromFile(candidate, loadOnlyDts, failedLookupLocation, host) { - if (loadOnlyDts) { - return tryLoad(".d.ts"); - } - else { - return ts.forEach(ts.supportedExtensions, tryLoad); - } + function loadNodeModuleFromFile(candidate, failedLookupLocation, host) { + return ts.forEach(ts.moduleFileExtensions, tryLoad); function tryLoad(ext) { var fileName = ts.fileExtensionIs(candidate, ext) ? candidate : candidate + ext; if (host.fileExists(fileName)) { @@ -29400,7 +29916,7 @@ var ts; } } } - function loadNodeModuleFromDirectory(candidate, loadOnlyDts, failedLookupLocation, host) { + function loadNodeModuleFromDirectory(candidate, failedLookupLocation, host) { var packageJsonPath = ts.combinePaths(candidate, "package.json"); if (host.fileExists(packageJsonPath)) { var jsonContent; @@ -29412,7 +29928,7 @@ var ts; jsonContent = { typings: undefined }; } if (jsonContent.typings) { - var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), loadOnlyDts, failedLookupLocation, host); + var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), failedLookupLocation, host); if (result) { return result; } @@ -29421,7 +29937,7 @@ var ts; else { failedLookupLocation.push(packageJsonPath); } - return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host); + return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), failedLookupLocation, host); } function loadModuleFromNodeModules(moduleName, directory, host) { var failedLookupLocations = []; @@ -29431,11 +29947,11 @@ var ts; if (baseName !== "node_modules") { var nodeModulesFolder = ts.combinePaths(directory, "node_modules"); var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); - var result = loadNodeModuleFromFile(candidate, true, failedLookupLocations, host); + var result = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } - result = loadNodeModuleFromDirectory(candidate, true, failedLookupLocations, host); + result = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } @@ -29453,7 +29969,7 @@ var ts; return i === 0 || (i === 1 && name.charCodeAt(0) === 46); } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { - if (moduleName.indexOf('!') != -1) { + if (moduleName.indexOf("!") != -1) { return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); @@ -29762,7 +30278,7 @@ var ts; return emitResult; } function getSourceFile(fileName) { - return filesByName.get(fileName); + return filesByName.get(fileName) || filesByName.get(ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory())); } function getDiagnosticsHelper(sourceFile, getDiagnostics, cancellationToken) { if (sourceFile) { @@ -29851,10 +30367,14 @@ var ts; var imports; for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var node = _a[_i]; + collect(node, true); + } + file.imports = imports || emptyArray; + function collect(node, allowRelativeModuleNames) { switch (node.kind) { - case 220: - case 219: - case 226: + case 222: + case 221: + case 228: var moduleNameExpr = ts.getExternalModuleName(node); if (!moduleNameExpr || moduleNameExpr.kind !== 9) { break; @@ -29862,24 +30382,19 @@ var ts; if (!moduleNameExpr.text) { break; } - (imports || (imports = [])).push(moduleNameExpr); + if (allowRelativeModuleNames || !ts.isExternalModuleNameRelative(moduleNameExpr.text)) { + (imports || (imports = [])).push(moduleNameExpr); + } break; - case 216: + case 218: if (node.name.kind === 9 && (node.flags & 2 || ts.isDeclarationFile(file))) { ts.forEachChild(node.body, function (node) { - if (ts.isExternalModuleImportEqualsDeclaration(node) && - ts.getExternalModuleImportEqualsDeclarationExpression(node).kind === 9) { - var moduleName = ts.getExternalModuleImportEqualsDeclarationExpression(node); - if (moduleName) { - (imports || (imports = [])).push(moduleName); - } - } + collect(node, false); }); } break; } } - file.imports = imports || emptyArray; } function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { var diagnosticArgument; @@ -29922,48 +30437,46 @@ var ts; } } function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { - var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (filesByName.contains(canonicalName)) { - return getSourceFileFromCache(fileName, canonicalName, false); + if (filesByName.contains(fileName)) { + return getSourceFileFromCache(fileName, false); } - else { - var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); - var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (filesByName.contains(canonicalAbsolutePath)) { - return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); - } - var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { - if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - else { - fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - }); - filesByName.set(canonicalName, file); - if (file) { - skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; - filesByName.set(canonicalAbsolutePath, file); - var basePath = ts.getDirectoryPath(fileName); - if (!options.noResolve) { - processReferencedFiles(file, basePath); - } - processImportedModules(file, basePath); - if (isDefaultLib) { - file.isDefaultLib = true; - files.unshift(file); - } - else { - files.push(file); - } - } - return file; + var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); + if (filesByName.contains(normalizedAbsolutePath)) { + var file_1 = getSourceFileFromCache(normalizedAbsolutePath, true); + filesByName.set(fileName, file_1); + return file_1; } - function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName.get(canonicalName); + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + else { + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + }); + filesByName.set(fileName, file); + if (file) { + skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; + filesByName.set(normalizedAbsolutePath, file); + var basePath = ts.getDirectoryPath(fileName); + if (!options.noResolve) { + processReferencedFiles(file, basePath); + } + processImportedModules(file, basePath); + if (isDefaultLib) { + file.isDefaultLib = true; + files.unshift(file); + } + else { + files.push(file); + } + } + return file; + function getSourceFileFromCache(fileName, useAbsolutePath) { + var file = filesByName.get(fileName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; - if (canonicalName !== sourceFileName) { + if (ts.normalizeSlashes(fileName) !== ts.normalizeSlashes(sourceFileName)) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } @@ -30124,8 +30637,8 @@ var ts; var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } - if (options.module && languageVersion >= 2) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + if (options.module === 5 && languageVersion < 2) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower)); } if (options.outDir || options.sourceRoot || @@ -30159,10 +30672,6 @@ var ts; !options.experimentalDecorators) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } - if (options.experimentalAsyncFunctions && - options.target !== 2) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); - } } } ts.createProgram = createProgram; @@ -30239,11 +30748,13 @@ var ts; "commonjs": 1, "amd": 2, "system": 4, - "umd": 3 + "umd": 3, + "es6": 5, + "es2015": 5 }, - description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd, + description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6, paramType: ts.Diagnostics.KIND, - error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd + error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 }, { name: "newLine", @@ -30367,7 +30878,12 @@ var ts; { name: "target", shortName: "t", - type: { "es3": 0, "es5": 1, "es6": 2 }, + type: { + "es3": 0, + "es5": 1, + "es6": 2, + "es2015": 2 + }, description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: ts.Diagnostics.VERSION, error: ts.Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6 @@ -30384,11 +30900,6 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, - { - name: "experimentalAsyncFunctions", - type: "boolean", - description: ts.Diagnostics.Enables_experimental_support_for_ES7_async_functions - }, { name: "experimentalDecorators", type: "boolean", @@ -30529,10 +31040,10 @@ var ts; catch (e) { return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; } - return parseConfigFileText(fileName, text); + return parseConfigFileTextToJson(fileName, text); } ts.readConfigFile = readConfigFile; - function parseConfigFileText(fileName, jsonText) { + function parseConfigFileTextToJson(fileName, jsonText) { try { return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; } @@ -30540,8 +31051,8 @@ var ts; return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; } } - ts.parseConfigFileText = parseConfigFileText; - function parseConfigFile(json, host, basePath) { + ts.parseConfigFileTextToJson = parseConfigFileTextToJson; + function parseJsonConfigFileContent(json, host, basePath) { var errors = []; return { options: getCompilerOptions(), @@ -30575,6 +31086,9 @@ var ts; } if (opt.isFilePath) { value = ts.normalizePath(ts.combinePaths(basePath, value)); + if (value === "") { + value = "."; + } } options[opt.name] = value; } @@ -30603,27 +31117,27 @@ var ts; var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; var sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)); for (var i = 0; i < sysFiles.length; i++) { - var name_27 = sysFiles[i]; - if (ts.fileExtensionIs(name_27, ".d.ts")) { - var baseName = name_27.substr(0, name_27.length - ".d.ts".length); + var name_28 = sysFiles[i]; + if (ts.fileExtensionIs(name_28, ".d.ts")) { + var baseName = name_28.substr(0, name_28.length - ".d.ts".length); if (!ts.contains(sysFiles, baseName + ".tsx") && !ts.contains(sysFiles, baseName + ".ts")) { - fileNames.push(name_27); + fileNames.push(name_28); } } - else if (ts.fileExtensionIs(name_27, ".ts")) { - if (!ts.contains(sysFiles, name_27 + "x")) { - fileNames.push(name_27); + else if (ts.fileExtensionIs(name_28, ".ts")) { + if (!ts.contains(sysFiles, name_28 + "x")) { + fileNames.push(name_28); } } else { - fileNames.push(name_27); + fileNames.push(name_28); } } } return fileNames; } } - ts.parseConfigFile = parseConfigFile; + ts.parseJsonConfigFileContent = parseJsonConfigFileContent; })(ts || (ts = {})); var ts; (function (ts) { @@ -30700,6 +31214,15 @@ var ts; reportDiagnostic(diagnostics[i]); } } + function reportWatchDiagnostic(diagnostic) { + var output = new Date().toLocaleTimeString() + " - "; + if (diagnostic.file) { + var loc = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + output += diagnostic.file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + "): "; + } + output += "" + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine; + ts.sys.write(output); + } function padLeft(s, length) { while (s.length < length) { s = " " + s; @@ -30727,13 +31250,16 @@ var ts; function executeCommandLine(args) { var commandLine = ts.parseCommandLine(args); var configFileName; + var cachedConfigFileText; var configFileWatcher; + var directoryWatcher; var cachedProgram; var rootFileNames; var compilerOptions; var compilerHost; var hostGetSourceFile; - var timerHandle; + var timerHandleForRecompilation; + var timerHandleForDirectoryChanges; if (commandLine.options.locale) { if (!isJSONSupported()) { reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--locale")); @@ -30786,22 +31312,38 @@ var ts; if (configFileName) { configFileWatcher = ts.sys.watchFile(configFileName, configFileChanged); } + if (ts.sys.watchDirectory && configFileName) { + var directory = ts.getDirectoryPath(configFileName); + directoryWatcher = ts.sys.watchDirectory(directory == "" ? "." : directory, watchedDirectoryChanged, true); + } } performCompilation(); + function parseConfigFile() { + if (!cachedConfigFileText) { + try { + cachedConfigFileText = ts.sys.readFile(configFileName); + } + catch (e) { + var error = ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, configFileName, e.message); + reportWatchDiagnostic(error); + ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); + return; + } + } + var result = ts.parseConfigFileTextToJson(configFileName, cachedConfigFileText); + var configObject = result.config; + var configParseResult = ts.parseJsonConfigFileContent(configObject, ts.sys, ts.getDirectoryPath(configFileName)); + if (configParseResult.errors.length > 0) { + reportDiagnostics(configParseResult.errors); + ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); + return; + } + return configParseResult; + } function performCompilation() { if (!cachedProgram) { if (configFileName) { - var result = ts.readConfigFile(configFileName, ts.sys.readFile); - if (result.error) { - reportDiagnostic(result.error); - return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); - } - var configObject = result.config; - var configParseResult = ts.parseConfigFile(configObject, ts.sys, ts.getDirectoryPath(configFileName)); - if (configParseResult.errors.length > 0) { - reportDiagnostics(configParseResult.errors); - return ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); - } + var configParseResult = parseConfigFile(); rootFileNames = configParseResult.fileNames; compilerOptions = ts.extend(commandLine.options, configParseResult.options); } @@ -30818,7 +31360,7 @@ var ts; return ts.sys.exit(compileResult.exitStatus); } setCachedProgram(compileResult.program); - reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes)); + reportWatchDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes)); } function getSourceFile(fileName, languageVersion, onError) { if (cachedProgram) { @@ -30829,7 +31371,7 @@ var ts; } var sourceFile = hostGetSourceFile(fileName, languageVersion, onError); if (sourceFile && compilerOptions.watch) { - sourceFile.fileWatcher = ts.sys.watchFile(sourceFile.fileName, function () { return sourceFileChanged(sourceFile); }); + sourceFile.fileWatcher = ts.sys.watchFile(sourceFile.fileName, function (fileName, removed) { return sourceFileChanged(sourceFile, removed); }); } return sourceFile; } @@ -30847,24 +31389,52 @@ var ts; } cachedProgram = program; } - function sourceFileChanged(sourceFile) { + function sourceFileChanged(sourceFile, removed) { sourceFile.fileWatcher.close(); sourceFile.fileWatcher = undefined; - startTimer(); + if (removed) { + var index = rootFileNames.indexOf(sourceFile.fileName); + if (index >= 0) { + rootFileNames.splice(index, 1); + } + } + startTimerForRecompilation(); } function configFileChanged() { setCachedProgram(undefined); - startTimer(); + cachedConfigFileText = undefined; + startTimerForRecompilation(); } - function startTimer() { - if (timerHandle) { - clearTimeout(timerHandle); + function watchedDirectoryChanged(fileName) { + if (fileName && !ts.isSupportedSourceFileName(fileName)) { + return; } - timerHandle = setTimeout(recompile, 250); + startTimerForHandlingDirectoryChanges(); + } + function startTimerForHandlingDirectoryChanges() { + if (timerHandleForDirectoryChanges) { + clearTimeout(timerHandleForDirectoryChanges); + } + timerHandleForDirectoryChanges = setTimeout(directoryChangeHandler, 250); + } + function directoryChangeHandler() { + var parsedCommandLine = parseConfigFile(); + var newFileNames = ts.map(parsedCommandLine.fileNames, compilerHost.getCanonicalFileName); + var canonicalRootFileNames = ts.map(rootFileNames, compilerHost.getCanonicalFileName); + if (!ts.arrayStructurallyIsEqualTo(newFileNames, canonicalRootFileNames)) { + setCachedProgram(undefined); + startTimerForRecompilation(); + } + } + function startTimerForRecompilation() { + if (timerHandleForRecompilation) { + clearTimeout(timerHandleForRecompilation); + } + timerHandleForRecompilation = setTimeout(recompile, 250); } function recompile() { - timerHandle = undefined; - reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation)); + timerHandleForRecompilation = undefined; + reportWatchDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation)); performCompilation(); } } @@ -30992,7 +31562,7 @@ var ts; } function writeConfigFile(options, fileNames) { var currentDirectory = ts.sys.getCurrentDirectory(); - var file = ts.combinePaths(currentDirectory, 'tsconfig.json'); + var file = ts.combinePaths(currentDirectory, "tsconfig.json"); if (ts.sys.fileExists(file)) { reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file)); } @@ -31012,10 +31582,10 @@ var ts; function serializeCompilerOptions(options) { var result = {}; var optionsNameMap = ts.getOptionNameMap().optionNameMap; - for (var name_28 in options) { - if (ts.hasProperty(options, name_28)) { - var value = options[name_28]; - switch (name_28) { + for (var name_29 in options) { + if (ts.hasProperty(options, name_29)) { + var value = options[name_29]; + switch (name_29) { case "init": case "watch": case "version": @@ -31023,17 +31593,17 @@ var ts; case "project": break; default: - var optionDefinition = optionsNameMap[name_28.toLowerCase()]; + var optionDefinition = optionsNameMap[name_29.toLowerCase()]; if (optionDefinition) { if (typeof optionDefinition.type === "string") { - result[name_28] = value; + result[name_29] = value; } else { var typeMap = optionDefinition.type; for (var key in typeMap) { if (ts.hasProperty(typeMap, key)) { if (typeMap[key] === value) - result[name_28] = key; + result[name_29] = key; } } } diff --git a/lib/tsserver.js b/lib/tsserver.js index 82199e1222d..2832b8b535a 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -410,8 +410,11 @@ var ts; } ts.chainDiagnosticMessages = chainDiagnosticMessages; function concatenateDiagnosticMessageChains(headChain, tailChain) { - Debug.assert(!headChain.next); - headChain.next = tailChain; + var lastChain = headChain; + while (lastChain.next) { + lastChain = lastChain.next; + } + lastChain.next = tailChain; return headChain; } ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains; @@ -627,6 +630,9 @@ var ts; } ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl; function getBaseFileName(path) { + if (!path) { + return undefined; + } var i = path.lastIndexOf(ts.directorySeparator); return i < 0 ? path : path.substring(i + 1); } @@ -650,6 +656,20 @@ var ts; } ts.fileExtensionIs = fileExtensionIs; ts.supportedExtensions = [".ts", ".tsx", ".d.ts"]; + ts.moduleFileExtensions = ts.supportedExtensions; + function isSupportedSourceFileName(fileName) { + if (!fileName) { + return false; + } + for (var _i = 0; _i < ts.supportedExtensions.length; _i++) { + var extension = ts.supportedExtensions[_i]; + if (fileExtensionIs(fileName, extension)) { + return true; + } + } + return false; + } + ts.isSupportedSourceFileName = isSupportedSourceFileName; var extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"]; function removeFileExtension(path) { for (var _i = 0; _i < extensionsToRemove.length; _i++) { @@ -726,6 +746,16 @@ var ts; } Debug.fail = fail; })(Debug = ts.Debug || (ts.Debug = {})); + function copyListRemovingItem(item, list) { + var copiedList = []; + for (var i = 0, len = list.length; i < len; i++) { + if (list[i] !== item) { + copiedList.push(list[i]); + } + } + return copiedList; + } + ts.copyListRemovingItem = copyListRemovingItem; })(ts || (ts = {})); var ts; (function (ts) { @@ -864,6 +894,76 @@ var ts; var _fs = require("fs"); var _path = require("path"); var _os = require("os"); + function createWatchedFileSet(interval, chunkSize) { + if (interval === void 0) { interval = 2500; } + if (chunkSize === void 0) { chunkSize = 30; } + var watchedFiles = []; + var nextFileToCheck = 0; + var watchTimer; + function getModifiedTime(fileName) { + return _fs.statSync(fileName).mtime; + } + function poll(checkedIndex) { + var watchedFile = watchedFiles[checkedIndex]; + if (!watchedFile) { + return; + } + _fs.stat(watchedFile.fileName, function (err, stats) { + if (err) { + watchedFile.callback(watchedFile.fileName); + } + else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) { + watchedFile.mtime = getModifiedTime(watchedFile.fileName); + watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0); + } + }); + } + function startWatchTimer() { + watchTimer = setInterval(function () { + var count = 0; + var nextToCheck = nextFileToCheck; + var firstCheck = -1; + while ((count < chunkSize) && (nextToCheck !== firstCheck)) { + poll(nextToCheck); + if (firstCheck < 0) { + firstCheck = nextToCheck; + } + nextToCheck++; + if (nextToCheck === watchedFiles.length) { + nextToCheck = 0; + } + count++; + } + nextFileToCheck = nextToCheck; + }, interval); + } + function addFile(fileName, callback) { + var file = { + fileName: fileName, + callback: callback, + mtime: getModifiedTime(fileName) + }; + watchedFiles.push(file); + if (watchedFiles.length === 1) { + startWatchTimer(); + } + return file; + } + function removeFile(file) { + watchedFiles = ts.copyListRemovingItem(file, watchedFiles); + } + return { + getModifiedTime: getModifiedTime, + poll: poll, + startWatchTimer: startWatchTimer, + addFile: addFile, + removeFile: removeFile + }; + } + var watchedFileSet = createWatchedFileSet(); + function isNode4OrLater() { + return parseInt(process.version.charAt(1)) >= 4; + } var platform = _os.platform(); var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; function readFile(fileName, encoding) { @@ -944,16 +1044,21 @@ var ts; readFile: readFile, writeFile: writeFile, watchFile: function (fileName, callback) { - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); - return { - close: function () { _fs.unwatchFile(fileName, fileChanged); } - }; - function fileChanged(curr, prev) { - if (+curr.mtime <= +prev.mtime) { - return; - } - callback(fileName); + if (isNode4OrLater()) { + return _fs.watch(fileName, function (eventName, relativeFileName) { return callback(fileName); }); } + var watchedFile = watchedFileSet.addFile(fileName, callback); + return { + close: function () { return watchedFileSet.removeFile(watchedFile); } + }; + }, + watchDirectory: function (path, callback, recursive) { + return _fs.watch(path, { persisten: true, recursive: !!recursive }, function (eventName, relativeFileName) { + if (eventName === "rename") { + callback(!relativeFileName ? relativeFileName : ts.normalizePath(ts.combinePaths(path, relativeFileName))); + } + ; + }); }, resolvePath: function (path) { return _path.resolve(path); @@ -1050,7 +1155,7 @@ var ts; Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." }, _0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: { code: 1062, category: ts.DiagnosticCategory.Error, key: "{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method." }, An_export_assignment_cannot_be_used_in_a_namespace: { code: 1063, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a namespace." }, - Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: ts.DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." }, + In_ambient_enum_declarations_member_initializer_must_be_constant_expression: { code: 1066, category: ts.DiagnosticCategory.Error, key: "In ambient enum declarations member initializer must be constant expression." }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: ts.DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." }, @@ -1138,7 +1243,7 @@ var ts; Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." }, A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." }, - An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, + An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1183, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, @@ -1156,10 +1261,9 @@ var ts; An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: ts.DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, - Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, - Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, - Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." }, - Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead." }, + Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead." }, + Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'es6' when targeting 'ES5' or lower." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, @@ -1188,10 +1292,6 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, - Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning: { code: 1236, category: ts.DiagnosticCategory.Error, key: "Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning." }, - with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, - await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, - Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, @@ -1202,6 +1302,10 @@ var ts; _0_modifier_cannot_be_used_with_1_modifier: { code: 1243, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." }, Abstract_methods_can_only_appear_within_an_abstract_class: { code: 1244, category: ts.DiagnosticCategory.Error, key: "Abstract methods can only appear within an abstract class." }, Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: { code: 1245, category: ts.DiagnosticCategory.Error, key: "Method '{0}' cannot have an implementation because it is marked abstract." }, + with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, + await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, + Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, + can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment: { code: 1312, category: ts.DiagnosticCategory.Error, key: "'=' can only be used in an object literal property inside a destructuring assignment." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -1326,7 +1430,7 @@ var ts; In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element: { code: 2432, category: ts.DiagnosticCategory.Error, key: "In an enum with multiple declarations, only one declaration can omit an initializer for its first enum element." }, A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged: { code: 2433, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be in a different file from a class or function with which it is merged" }, A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: { code: 2434, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be located prior to a class or function with which it is merged" }, - Ambient_modules_cannot_be_nested_in_other_modules: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules." }, + Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules or namespaces." }, Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." }, Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: 2437, category: ts.DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" }, Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" }, @@ -1414,6 +1518,9 @@ var ts; yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: ts.DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: ts.DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: ts.DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value." }, + A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface: { code: 2526, category: ts.DiagnosticCategory.Error, key: "A 'this' type is available only in a non-static member of a class or interface." }, + The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary: { code: 2527, category: ts.DiagnosticCategory.Error, key: "The inferred type of '{0}' references an inaccessible 'this' type. A type annotation is necessary." }, + A_module_cannot_have_multiple_default_exports: { code: 2528, category: ts.DiagnosticCategory.Error, key: "A module cannot have multiple default exports." }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: ts.DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: ts.DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, @@ -1514,7 +1621,7 @@ var ts; Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: ts.DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." }, Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." }, Option_0_cannot_be_specified_with_option_1: { code: 5053, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." }, - A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5053, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, + A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5054, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -1526,7 +1633,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, - Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" }, + Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -1547,7 +1654,7 @@ var ts; Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." }, + Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'." }, Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: ts.DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: ts.DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, @@ -1568,7 +1675,6 @@ var ts; Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, - Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, @@ -1615,81 +1721,83 @@ var ts; Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: ts.DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." }, JSX_attribute_expected: { code: 17003, category: ts.DiagnosticCategory.Error, key: "JSX attribute expected." }, Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: ts.DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." }, - A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" } + A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }, + An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17006, category: ts.DiagnosticCategory.Error, key: "An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, + A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." } }; })(ts || (ts = {})); var ts; (function (ts) { function tokenIsIdentifierOrKeyword(token) { - return token >= 67; + return token >= 69; } ts.tokenIsIdentifierOrKeyword = tokenIsIdentifierOrKeyword; var textToToken = { - "abstract": 113, - "any": 115, - "as": 114, - "boolean": 118, - "break": 68, - "case": 69, - "catch": 70, - "class": 71, - "continue": 73, - "const": 72, - "constructor": 119, - "debugger": 74, - "declare": 120, - "default": 75, - "delete": 76, - "do": 77, - "else": 78, - "enum": 79, - "export": 80, - "extends": 81, - "false": 82, - "finally": 83, - "for": 84, - "from": 131, - "function": 85, - "get": 121, - "if": 86, - "implements": 104, - "import": 87, - "in": 88, - "instanceof": 89, - "interface": 105, - "is": 122, - "let": 106, - "module": 123, - "namespace": 124, - "new": 90, - "null": 91, - "number": 126, - "package": 107, - "private": 108, - "protected": 109, - "public": 110, - "require": 125, - "return": 92, - "set": 127, - "static": 111, - "string": 128, - "super": 93, - "switch": 94, - "symbol": 129, - "this": 95, - "throw": 96, - "true": 97, - "try": 98, - "type": 130, - "typeof": 99, - "var": 100, - "void": 101, - "while": 102, - "with": 103, - "yield": 112, - "async": 116, - "await": 117, - "of": 132, + "abstract": 115, + "any": 117, + "as": 116, + "boolean": 120, + "break": 70, + "case": 71, + "catch": 72, + "class": 73, + "continue": 75, + "const": 74, + "constructor": 121, + "debugger": 76, + "declare": 122, + "default": 77, + "delete": 78, + "do": 79, + "else": 80, + "enum": 81, + "export": 82, + "extends": 83, + "false": 84, + "finally": 85, + "for": 86, + "from": 133, + "function": 87, + "get": 123, + "if": 88, + "implements": 106, + "import": 89, + "in": 90, + "instanceof": 91, + "interface": 107, + "is": 124, + "let": 108, + "module": 125, + "namespace": 126, + "new": 92, + "null": 93, + "number": 128, + "package": 109, + "private": 110, + "protected": 111, + "public": 112, + "require": 127, + "return": 94, + "set": 129, + "static": 113, + "string": 130, + "super": 95, + "switch": 96, + "symbol": 131, + "this": 97, + "throw": 98, + "true": 99, + "try": 100, + "type": 132, + "typeof": 101, + "var": 102, + "void": 103, + "while": 104, + "with": 105, + "yield": 114, + "async": 118, + "await": 119, + "of": 134, "{": 15, "}": 16, "(": 17, @@ -1711,37 +1819,39 @@ var ts; "=>": 34, "+": 35, "-": 36, + "**": 38, "*": 37, - "/": 38, - "%": 39, - "++": 40, - "--": 41, - "<<": 42, + "/": 39, + "%": 40, + "++": 41, + "--": 42, + "<<": 43, ">": 43, - ">>>": 44, - "&": 45, - "|": 46, - "^": 47, - "!": 48, - "~": 49, - "&&": 50, - "||": 51, - "?": 52, - ":": 53, - "=": 55, - "+=": 56, - "-=": 57, - "*=": 58, - "/=": 59, - "%=": 60, - "<<=": 61, - ">>=": 62, - ">>>=": 63, - "&=": 64, - "|=": 65, - "^=": 66, - "@": 54 + ">>": 44, + ">>>": 45, + "&": 46, + "|": 47, + "^": 48, + "!": 49, + "~": 50, + "&&": 51, + "||": 52, + "?": 53, + ":": 54, + "=": 56, + "+=": 57, + "-=": 58, + "*=": 59, + "**=": 60, + "/=": 61, + "%=": 62, + "<<=": 63, + ">>=": 64, + ">>>=": 65, + "&=": 66, + "|=": 67, + "^=": 68, + "@": 55 }; var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,]; @@ -2143,8 +2253,8 @@ var ts; getTokenValue: function () { return tokenValue; }, hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, - isIdentifier: function () { return token === 67 || token > 103; }, - isReservedWord: function () { return token >= 68 && token <= 103; }, + isIdentifier: function () { return token === 69 || token > 105; }, + isReservedWord: function () { return token >= 70 && token <= 105; }, isUnterminated: function () { return tokenIsUnterminated; }, reScanGreaterToken: reScanGreaterToken, reScanSlashToken: reScanSlashToken, @@ -2166,16 +2276,6 @@ var ts; onError(message, length || 0); } } - function isIdentifierStart(ch) { - return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || - ch === 36 || ch === 95 || - ch > 127 && isUnicodeIdentifierStart(ch, languageVersion); - } - function isIdentifierPart(ch) { - return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || - ch >= 48 && ch <= 57 || ch === 36 || ch === 95 || - ch > 127 && isUnicodeIdentifierPart(ch, languageVersion); - } function scanNumber() { var start = pos; while (isDigit(text.charCodeAt(pos))) @@ -2430,12 +2530,12 @@ var ts; var start = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (isIdentifierPart(ch)) { + if (isIdentifierPart(ch, languageVersion)) { pos++; } else if (ch === 92) { ch = peekUnicodeEscape(); - if (!(ch >= 0 && isIdentifierPart(ch))) { + if (!(ch >= 0 && isIdentifierPart(ch, languageVersion))) { break; } result += text.substring(start, pos); @@ -2458,7 +2558,7 @@ var ts; return token = textToToken[tokenValue]; } } - return token = 67; + return token = 69; } function scanBinaryOrOctalDigits(base) { ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8"); @@ -2537,7 +2637,7 @@ var ts; } return pos += 2, token = 31; } - return pos++, token = 48; + return pos++, token = 49; case 34: case 39: tokenValue = scanString(); @@ -2546,42 +2646,48 @@ var ts; return token = scanTemplateAndSetTokenValue(); case 37: if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 60; + return pos += 2, token = 62; } - return pos++, token = 39; + return pos++, token = 40; case 38: if (text.charCodeAt(pos + 1) === 38) { - return pos += 2, token = 50; + return pos += 2, token = 51; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 64; + return pos += 2, token = 66; } - return pos++, token = 45; + return pos++, token = 46; case 40: return pos++, token = 17; case 41: return pos++, token = 18; case 42: if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 58; + return pos += 2, token = 59; + } + if (text.charCodeAt(pos + 1) === 42) { + if (text.charCodeAt(pos + 2) === 61) { + return pos += 3, token = 60; + } + return pos += 2, token = 38; } return pos++, token = 37; case 43: if (text.charCodeAt(pos + 1) === 43) { - return pos += 2, token = 40; + return pos += 2, token = 41; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 56; + return pos += 2, token = 57; } return pos++, token = 35; case 44: return pos++, token = 24; case 45: if (text.charCodeAt(pos + 1) === 45) { - return pos += 2, token = 41; + return pos += 2, token = 42; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 57; + return pos += 2, token = 58; } return pos++, token = 36; case 46: @@ -2636,9 +2742,9 @@ var ts; } } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 59; + return pos += 2, token = 61; } - return pos++, token = 38; + return pos++, token = 39; case 48: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) { pos += 2; @@ -2686,7 +2792,7 @@ var ts; tokenValue = "" + scanNumber(); return token = 8; case 58: - return pos++, token = 53; + return pos++, token = 54; case 59: return pos++, token = 23; case 60: @@ -2701,14 +2807,16 @@ var ts; } if (text.charCodeAt(pos + 1) === 60) { if (text.charCodeAt(pos + 2) === 61) { - return pos += 3, token = 61; + return pos += 3, token = 63; } - return pos += 2, token = 42; + return pos += 2, token = 43; } if (text.charCodeAt(pos + 1) === 61) { return pos += 2, token = 28; } - if (text.charCodeAt(pos + 1) === 47 && languageVariant === 1) { + if (languageVariant === 1 && + text.charCodeAt(pos + 1) === 47 && + text.charCodeAt(pos + 2) !== 42) { return pos += 2, token = 26; } return pos++, token = 25; @@ -2731,7 +2839,7 @@ var ts; if (text.charCodeAt(pos + 1) === 62) { return pos += 2, token = 34; } - return pos++, token = 55; + return pos++, token = 56; case 62: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -2744,35 +2852,35 @@ var ts; } return pos++, token = 27; case 63: - return pos++, token = 52; + return pos++, token = 53; case 91: return pos++, token = 19; case 93: return pos++, token = 20; case 94: if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 66; + return pos += 2, token = 68; } - return pos++, token = 47; + return pos++, token = 48; case 123: return pos++, token = 15; case 124: if (text.charCodeAt(pos + 1) === 124) { - return pos += 2, token = 51; + return pos += 2, token = 52; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 65; + return pos += 2, token = 67; } - return pos++, token = 46; + return pos++, token = 47; case 125: return pos++, token = 16; case 126: - return pos++, token = 49; + return pos++, token = 50; case 64: - return pos++, token = 54; + return pos++, token = 55; case 92: var cookedChar = peekUnicodeEscape(); - if (cookedChar >= 0 && isIdentifierStart(cookedChar)) { + if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); @@ -2780,9 +2888,9 @@ var ts; error(ts.Diagnostics.Invalid_character); return pos++, token = 0; default: - if (isIdentifierStart(ch)) { + if (isIdentifierStart(ch, languageVersion)) { pos++; - while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos))) + while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92) { @@ -2809,14 +2917,14 @@ var ts; if (text.charCodeAt(pos) === 62) { if (text.charCodeAt(pos + 1) === 62) { if (text.charCodeAt(pos + 2) === 61) { - return pos += 3, token = 63; + return pos += 3, token = 65; } - return pos += 2, token = 44; + return pos += 2, token = 45; } if (text.charCodeAt(pos + 1) === 61) { - return pos += 2, token = 62; + return pos += 2, token = 64; } - return pos++, token = 43; + return pos++, token = 44; } if (text.charCodeAt(pos) === 61) { return pos++, token = 29; @@ -2825,7 +2933,7 @@ var ts; return token; } function reScanSlashToken() { - if (token === 38 || token === 59) { + if (token === 39 || token === 61) { var p = tokenPos + 1; var inEscape = false; var inCharacterClass = false; @@ -2859,7 +2967,7 @@ var ts; } p++; } - while (p < end && isIdentifierPart(text.charCodeAt(p))) { + while (p < end && isIdentifierPart(text.charCodeAt(p), languageVersion)) { p++; } pos = p; @@ -2902,14 +3010,14 @@ var ts; break; } } - return token = 234; + return token = 236; } function scanJsxIdentifier() { if (tokenIsIdentifierOrKeyword(token)) { var firstCharPosition = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (ch === 45 || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) { + if (ch === 45 || ((firstCharPosition === pos) ? isIdentifierStart(ch, languageVersion) : isIdentifierPart(ch, languageVersion))) { pos++; } else { @@ -3044,11 +3152,13 @@ var ts; "commonjs": 1, "amd": 2, "system": 4, - "umd": 3 + "umd": 3, + "es6": 5, + "es2015": 5 }, - description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd, + description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6, paramType: ts.Diagnostics.KIND, - error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd + error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 }, { name: "newLine", @@ -3172,7 +3282,12 @@ var ts; { name: "target", shortName: "t", - type: { "es3": 0, "es5": 1, "es6": 2 }, + type: { + "es3": 0, + "es5": 1, + "es6": 2, + "es2015": 2 + }, description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: ts.Diagnostics.VERSION, error: ts.Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6 @@ -3189,11 +3304,6 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, - { - name: "experimentalAsyncFunctions", - type: "boolean", - description: ts.Diagnostics.Enables_experimental_support_for_ES7_async_functions - }, { name: "experimentalDecorators", type: "boolean", @@ -3334,10 +3444,10 @@ var ts; catch (e) { return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; } - return parseConfigFileText(fileName, text); + return parseConfigFileTextToJson(fileName, text); } ts.readConfigFile = readConfigFile; - function parseConfigFileText(fileName, jsonText) { + function parseConfigFileTextToJson(fileName, jsonText) { try { return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; } @@ -3345,8 +3455,8 @@ var ts; return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; } } - ts.parseConfigFileText = parseConfigFileText; - function parseConfigFile(json, host, basePath) { + ts.parseConfigFileTextToJson = parseConfigFileTextToJson; + function parseJsonConfigFileContent(json, host, basePath) { var errors = []; return { options: getCompilerOptions(), @@ -3380,6 +3490,9 @@ var ts; } if (opt.isFilePath) { value = ts.normalizePath(ts.combinePaths(basePath, value)); + if (value === "") { + value = "."; + } } options[opt.name] = value; } @@ -3428,7 +3541,7 @@ var ts; return fileNames; } } - ts.parseConfigFile = parseConfigFile; + ts.parseJsonConfigFileContent = parseJsonConfigFileContent; })(ts || (ts = {})); var ts; (function (ts) { @@ -3463,7 +3576,8 @@ var ts; increaseIndent: function () { }, decreaseIndent: function () { }, clear: function () { return str = ""; }, - trackSymbol: function () { } + trackSymbol: function () { }, + reportInaccessibleThisError: function () { } }; } return stringWriters.pop(); @@ -3525,7 +3639,7 @@ var ts; } } function getSourceFileOfNode(node) { - while (node && node.kind !== 246) { + while (node && node.kind !== 248) { node = node.parent; } return node; @@ -3616,15 +3730,15 @@ var ts; return current; } switch (current.kind) { - case 246: + case 248: + case 220: + case 244: case 218: - case 242: - case 216: - case 197: - case 198: case 199: + case 200: + case 201: return current; - case 190: + case 192: if (!isFunctionLike(current.parent)) { return current; } @@ -3635,9 +3749,9 @@ var ts; ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer; function isCatchClauseVariableDeclaration(declaration) { return declaration && - declaration.kind === 209 && + declaration.kind === 211 && declaration.parent && - declaration.parent.kind === 242; + declaration.parent.kind === 244; } ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; function declarationNameToString(name) { @@ -3673,22 +3787,22 @@ var ts; function getErrorSpanForNode(sourceFile, node) { var errorNode = node; switch (node.kind) { - case 246: + case 248: var pos_1 = ts.skipTrivia(sourceFile.text, 0, false); if (pos_1 === sourceFile.text.length) { return ts.createTextSpan(0, 0); } return getSpanOfTokenAtPosition(sourceFile, pos_1); - case 209: - case 161: - case 212: - case 184: - case 213: - case 216: - case 215: - case 245: case 211: - case 171: + case 163: + case 214: + case 186: + case 215: + case 218: + case 217: + case 247: + case 213: + case 173: errorNode = node.name; break; } @@ -3710,11 +3824,11 @@ var ts; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { - return node.kind === 215 && isConst(node); + return node.kind === 217 && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; function walkUpBindingElementsAndPatterns(node) { - while (node && (node.kind === 161 || isBindingPattern(node))) { + while (node && (node.kind === 163 || isBindingPattern(node))) { node = node.parent; } return node; @@ -3722,14 +3836,14 @@ var ts; function getCombinedNodeFlags(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; - if (node.kind === 209) { + if (node.kind === 211) { node = node.parent; } - if (node && node.kind === 210) { + if (node && node.kind === 212) { flags |= node.flags; node = node.parent; } - if (node && node.kind === 191) { + if (node && node.kind === 193) { flags |= node.flags; } return flags; @@ -3744,7 +3858,7 @@ var ts; } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 193 && node.expression.kind === 9; + return node.kind === 195 && node.expression.kind === 9; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { @@ -3752,7 +3866,7 @@ var ts; } ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - var commentRanges = (node.kind === 136 || node.kind === 135) ? + var commentRanges = (node.kind === 138 || node.kind === 137) ? ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) : getLeadingCommentRangesOfNode(node, sourceFileOfNode); return ts.filter(commentRanges, isJsDocComment); @@ -3766,68 +3880,69 @@ var ts; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; ts.fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*/; function isTypeNode(node) { - if (149 <= node.kind && node.kind <= 158) { + if (151 <= node.kind && node.kind <= 160) { return true; } switch (node.kind) { - case 115: - case 126: + case 117: case 128: - case 118: - case 129: + case 130: + case 120: + case 131: return true; - case 101: - return node.parent.kind !== 175; + case 103: + return node.parent.kind !== 177; case 9: - return node.parent.kind === 136; - case 186: + return node.parent.kind === 138; + case 188: return !isExpressionWithTypeArgumentsInClassExtendsClause(node); - case 67: - if (node.parent.kind === 133 && node.parent.right === node) { + case 69: + if (node.parent.kind === 135 && node.parent.right === node) { node = node.parent; } - else if (node.parent.kind === 164 && node.parent.name === node) { + else if (node.parent.kind === 166 && node.parent.name === node) { node = node.parent; } - case 133: - case 164: - ts.Debug.assert(node.kind === 67 || node.kind === 133 || node.kind === 164, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + ts.Debug.assert(node.kind === 69 || node.kind === 135 || node.kind === 166, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + case 135: + case 166: + case 97: var parent_1 = node.parent; - if (parent_1.kind === 152) { + if (parent_1.kind === 154) { return false; } - if (149 <= parent_1.kind && parent_1.kind <= 158) { + if (151 <= parent_1.kind && parent_1.kind <= 160) { return true; } switch (parent_1.kind) { - case 186: + case 188: return !isExpressionWithTypeArgumentsInClassExtendsClause(parent_1); - case 135: + case 137: return node === parent_1.constraint; - case 139: - case 138: - case 136: - case 209: - return node === parent_1.type; - case 211: - case 171: - case 172: - case 142: case 141: case 140: - case 143: - case 144: + case 138: + case 211: return node === parent_1.type; + case 213: + case 173: + case 174: + case 144: + case 143: + case 142: case 145: case 146: + return node === parent_1.type; case 147: + case 148: + case 149: return node === parent_1.type; - case 169: + case 171: return node === parent_1.type; - case 166: - case 167: - return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; case 168: + case 169: + return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; + case 170: return false; } } @@ -3838,23 +3953,23 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 202: + case 204: return visitor(node); - case 218: - case 190: - case 194: - case 195: + case 220: + case 192: case 196: case 197: case 198: case 199: - case 203: - case 204: - case 239: - case 240: + case 200: + case 201: case 205: - case 207: + case 206: + case 241: case 242: + case 207: + case 209: + case 244: return ts.forEachChild(node, traverse); } } @@ -3864,23 +3979,23 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 182: + case 184: visitor(node); var operand = node.expression; if (operand) { traverse(operand); } + case 217: case 215: - case 213: + case 218: case 216: case 214: - case 212: - case 184: + case 186: return; default: if (isFunctionLike(node)) { var name_6 = node.name; - if (name_6 && name_6.kind === 134) { + if (name_6 && name_6.kind === 136) { traverse(name_6.expression); return; } @@ -3895,14 +4010,14 @@ var ts; function isVariableLike(node) { if (node) { switch (node.kind) { - case 161: - case 245: - case 136: - case 243: - case 139: + case 163: + case 247: case 138: - case 244: - case 209: + case 245: + case 141: + case 140: + case 246: + case 211: return true; } } @@ -3910,29 +4025,29 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - return node && (node.kind === 143 || node.kind === 144); + return node && (node.kind === 145 || node.kind === 146); } ts.isAccessor = isAccessor; function isClassLike(node) { - return node && (node.kind === 212 || node.kind === 184); + return node && (node.kind === 214 || node.kind === 186); } ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { - case 142: - case 171: - case 211: - case 172: - case 141: - case 140: - case 143: case 144: + case 173: + case 213: + case 174: + case 143: + case 142: case 145: case 146: case 147: - case 150: - case 151: + case 148: + case 149: + case 152: + case 153: return true; } } @@ -3941,24 +4056,24 @@ var ts; ts.isFunctionLike = isFunctionLike; function introducesArgumentsExoticObject(node) { switch (node.kind) { - case 141: - case 140: - case 142: case 143: + case 142: case 144: - case 211: - case 171: + case 145: + case 146: + case 213: + case 173: return true; } return false; } ts.introducesArgumentsExoticObject = introducesArgumentsExoticObject; function isFunctionBlock(node) { - return node && node.kind === 190 && isFunctionLike(node.parent); + return node && node.kind === 192 && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { - return node && node.kind === 141 && node.parent.kind === 163; + return node && node.kind === 143 && node.parent.kind === 165; } ts.isObjectLiteralMethod = isObjectLiteralMethod; function getContainingFunction(node) { @@ -3986,36 +4101,39 @@ var ts; return undefined; } switch (node.kind) { - case 134: + case 136: if (isClassLike(node.parent.parent)) { return node; } node = node.parent; break; - case 137: - if (node.parent.kind === 136 && isClassElement(node.parent.parent)) { + case 139: + if (node.parent.kind === 138 && isClassElement(node.parent.parent)) { node = node.parent.parent; } else if (isClassElement(node.parent)) { node = node.parent; } break; - case 172: + case 174: if (!includeArrowFunctions) { continue; } - case 211: - case 171: - case 216: - case 139: - case 138: + case 213: + case 173: + case 218: case 141: case 140: - case 142: case 143: + case 142: case 144: - case 215: - case 246: + case 145: + case 146: + case 147: + case 148: + case 149: + case 217: + case 248: return node; } } @@ -4027,33 +4145,33 @@ var ts; if (!node) return node; switch (node.kind) { - case 134: + case 136: if (isClassLike(node.parent.parent)) { return node; } node = node.parent; break; - case 137: - if (node.parent.kind === 136 && isClassElement(node.parent.parent)) { + case 139: + if (node.parent.kind === 138 && isClassElement(node.parent.parent)) { node = node.parent.parent; } else if (isClassElement(node.parent)) { node = node.parent; } break; - case 211: - case 171: - case 172: + case 213: + case 173: + case 174: if (!includeFunctions) { continue; } - case 139: - case 138: case 141: case 140: - case 142: case 143: + case 142: case 144: + case 145: + case 146: return node; } } @@ -4062,12 +4180,12 @@ var ts; function getEntityNameFromTypeNode(node) { if (node) { switch (node.kind) { - case 149: + case 151: return node.typeName; - case 186: + case 188: return node.expression; - case 67: - case 133: + case 69: + case 135: return node; } } @@ -4075,7 +4193,7 @@ var ts; } ts.getEntityNameFromTypeNode = getEntityNameFromTypeNode; function getInvokedExpression(node) { - if (node.kind === 168) { + if (node.kind === 170) { return node.tag; } return node.expression; @@ -4083,40 +4201,40 @@ var ts; ts.getInvokedExpression = getInvokedExpression; function nodeCanBeDecorated(node) { switch (node.kind) { - case 212: + case 214: return true; - case 139: - return node.parent.kind === 212; - case 136: - return node.parent.body && node.parent.parent.kind === 212; - case 143: - case 144: case 141: - return node.body && node.parent.kind === 212; + return node.parent.kind === 214; + case 138: + return node.parent.body && node.parent.parent.kind === 214; + case 145: + case 146: + case 143: + return node.body && node.parent.kind === 214; } return false; } ts.nodeCanBeDecorated = nodeCanBeDecorated; function nodeIsDecorated(node) { switch (node.kind) { - case 212: + case 214: if (node.decorators) { return true; } return false; - case 139: - case 136: - if (node.decorators) { - return true; - } - return false; - case 143: - if (node.body && node.decorators) { - return true; - } - return false; case 141: - case 144: + case 138: + if (node.decorators) { + return true; + } + return false; + case 145: + if (node.body && node.decorators) { + return true; + } + return false; + case 143: + case 146: if (node.body && node.decorators) { return true; } @@ -4127,10 +4245,10 @@ var ts; ts.nodeIsDecorated = nodeIsDecorated; function childIsDecorated(node) { switch (node.kind) { - case 212: + case 214: return ts.forEach(node.members, nodeOrChildIsDecorated); - case 141: - case 144: + case 143: + case 146: return ts.forEach(node.parameters, nodeIsDecorated); } return false; @@ -4140,95 +4258,105 @@ var ts; return nodeIsDecorated(node) || childIsDecorated(node); } ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated; + function isPropertyAccessExpression(node) { + return node.kind === 166; + } + ts.isPropertyAccessExpression = isPropertyAccessExpression; + function isElementAccessExpression(node) { + return node.kind === 167; + } + ts.isElementAccessExpression = isElementAccessExpression; function isExpression(node) { switch (node.kind) { case 95: case 93: - case 91: - case 97: - case 82: + case 99: + case 84: case 10: - case 162: - case 163: case 164: case 165: case 166: case 167: case 168: - case 187: case 169: case 170: + case 189: case 171: - case 184: case 172: - case 175: case 173: + case 186: case 174: case 177: - case 178: + case 175: + case 176: case 179: case 180: - case 183: case 181: - case 11: - case 185: - case 231: - case 232: case 182: + case 185: + case 183: + case 11: + case 187: + case 233: + case 234: + case 184: + case 178: return true; - case 133: - while (node.parent.kind === 133) { + case 135: + while (node.parent.kind === 135) { node = node.parent; } - return node.parent.kind === 152; - case 67: - if (node.parent.kind === 152) { + return node.parent.kind === 154; + case 69: + if (node.parent.kind === 154) { return true; } case 8: case 9: + case 97: var parent_2 = node.parent; switch (parent_2.kind) { - case 209: - case 136: - case 139: + case 211: case 138: + case 141: + case 140: + case 247: case 245: - case 243: - case 161: + case 163: return parent_2.initializer === node; - case 193: - case 194: case 195: case 196: - case 202: - case 203: - case 204: - case 239: - case 206: - case 204: - return parent_2.expression === node; case 197: + case 198: + case 204: + case 205: + case 206: + case 241: + case 208: + case 206: + return parent_2.expression === node; + case 199: var forStatement = parent_2; - return (forStatement.initializer === node && forStatement.initializer.kind !== 210) || + return (forStatement.initializer === node && forStatement.initializer.kind !== 212) || forStatement.condition === node || forStatement.incrementor === node; - case 198: - case 199: + case 200: + case 201: var forInStatement = parent_2; - return (forInStatement.initializer === node && forInStatement.initializer.kind !== 210) || + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 212) || forInStatement.expression === node; - case 169: - case 187: + case 171: + case 189: return node === parent_2.expression; - case 188: + case 190: return node === parent_2.expression; - case 134: + case 136: return node === parent_2.expression; - case 137: - case 238: + case 139: + case 240: + case 239: return true; - case 186: + case 188: return parent_2.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent_2); default: if (isExpression(parent_2)) { @@ -4239,6 +4367,10 @@ var ts; return false; } ts.isExpression = isExpression; + function isExternalModuleNameRelative(moduleName) { + return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + } + ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { var moduleState = ts.getModuleInstanceState(node); return moduleState === 1 || @@ -4246,7 +4378,7 @@ var ts; } ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 && node.moduleReference.kind === 230; + return node.kind === 221 && node.moduleReference.kind === 232; } ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration; function getExternalModuleImportEqualsDeclarationExpression(node) { @@ -4255,20 +4387,20 @@ var ts; } ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression; function isInternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 && node.moduleReference.kind !== 230; + return node.kind === 221 && node.moduleReference.kind !== 232; } ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration; function getExternalModuleName(node) { - if (node.kind === 220) { + if (node.kind === 222) { return node.moduleSpecifier; } - if (node.kind === 219) { + if (node.kind === 221) { var reference = node.moduleReference; - if (reference.kind === 230) { + if (reference.kind === 232) { return reference.expression; } } - if (node.kind === 226) { + if (node.kind === 228) { return node.moduleSpecifier; } } @@ -4276,13 +4408,13 @@ var ts; function hasQuestionToken(node) { if (node) { switch (node.kind) { - case 136: + case 138: + case 143: + case 142: + case 246: + case 245: case 141: case 140: - case 244: - case 243: - case 139: - case 138: return node.questionToken !== undefined; } } @@ -4290,9 +4422,9 @@ var ts; } ts.hasQuestionToken = hasQuestionToken; function isJSDocConstructSignature(node) { - return node.kind === 259 && + return node.kind === 261 && node.parameters.length > 0 && - node.parameters[0].type.kind === 261; + node.parameters[0].type.kind === 263; } ts.isJSDocConstructSignature = isJSDocConstructSignature; function getJSDocTag(node, kind) { @@ -4306,24 +4438,24 @@ var ts; } } function getJSDocTypeTag(node) { - return getJSDocTag(node, 267); + return getJSDocTag(node, 269); } ts.getJSDocTypeTag = getJSDocTypeTag; function getJSDocReturnTag(node) { - return getJSDocTag(node, 266); + return getJSDocTag(node, 268); } ts.getJSDocReturnTag = getJSDocReturnTag; function getJSDocTemplateTag(node) { - return getJSDocTag(node, 268); + return getJSDocTag(node, 270); } ts.getJSDocTemplateTag = getJSDocTemplateTag; function getCorrespondingJSDocParameterTag(parameter) { - if (parameter.name && parameter.name.kind === 67) { + if (parameter.name && parameter.name.kind === 69) { var parameterName = parameter.name.text; var docComment = parameter.parent.jsDocComment; if (docComment) { return ts.forEach(docComment.tags, function (t) { - if (t.kind === 265) { + if (t.kind === 267) { var parameterTag = t; var name_7 = parameterTag.preParameterName || parameterTag.postParameterName; if (name_7.text === parameterName) { @@ -4342,12 +4474,12 @@ var ts; function isRestParameter(node) { if (node) { if (node.parserContextFlags & 32) { - if (node.type && node.type.kind === 260) { + if (node.type && node.type.kind === 262) { return true; } var paramTag = getCorrespondingJSDocParameterTag(node); if (paramTag && paramTag.typeExpression) { - return paramTag.typeExpression.type.kind === 260; + return paramTag.typeExpression.type.kind === 262; } } return node.dotDotDotToken !== undefined; @@ -4368,7 +4500,7 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return !!node && (node.kind === 160 || node.kind === 159); + return !!node && (node.kind === 162 || node.kind === 161); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { @@ -4383,34 +4515,34 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 172: - case 161: - case 212: - case 184: - case 142: - case 215: - case 245: - case 228: - case 211: - case 171: - case 143: - case 221: - case 219: - case 224: + case 174: + case 163: + case 214: + case 186: + case 144: + case 217: + case 247: + case 230: case 213: + case 173: + case 145: + case 223: + case 221: + case 226: + case 215: + case 143: + case 142: + case 218: + case 224: + case 138: + case 245: case 141: case 140: + case 146: + case 246: case 216: - case 222: - case 136: - case 243: - case 139: - case 138: - case 144: - case 244: - case 214: - case 135: - case 209: + case 137: + case 211: return true; } return false; @@ -4418,25 +4550,25 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 201: - case 200: - case 208: - case 195: - case 193: - case 192: - case 198: - case 199: - case 197: - case 194: - case 205: - case 202: - case 204: - case 96: - case 207: - case 191: - case 196: case 203: - case 225: + case 202: + case 210: + case 197: + case 195: + case 194: + case 200: + case 201: + case 199: + case 196: + case 207: + case 204: + case 206: + case 98: + case 209: + case 193: + case 198: + case 205: + case 227: return true; default: return false; @@ -4445,13 +4577,13 @@ var ts; ts.isStatement = isStatement; function isClassElement(n) { switch (n.kind) { - case 142: - case 139: + case 144: case 141: case 143: - case 144: - case 140: - case 147: + case 145: + case 146: + case 142: + case 149: return true; default: return false; @@ -4459,11 +4591,11 @@ var ts; } ts.isClassElement = isClassElement; function isDeclarationName(name) { - if (name.kind !== 67 && name.kind !== 9 && name.kind !== 8) { + if (name.kind !== 69 && name.kind !== 9 && name.kind !== 8) { return false; } var parent = name.parent; - if (parent.kind === 224 || parent.kind === 228) { + if (parent.kind === 226 || parent.kind === 230) { if (parent.propertyName) { return true; } @@ -4477,54 +4609,54 @@ var ts; function isIdentifierName(node) { var parent = node.parent; switch (parent.kind) { - case 139: - case 138: case 141: case 140: case 143: - case 144: + case 142: + case 145: + case 146: + case 247: case 245: - case 243: - case 164: + case 166: return parent.name === node; - case 133: + case 135: if (parent.right === node) { - while (parent.kind === 133) { + while (parent.kind === 135) { parent = parent.parent; } - return parent.kind === 152; + return parent.kind === 154; } return false; - case 161: - case 224: + case 163: + case 226: return parent.propertyName === node; - case 228: + case 230: return true; } return false; } ts.isIdentifierName = isIdentifierName; function isAliasSymbolDeclaration(node) { - return node.kind === 219 || - node.kind === 221 && !!node.name || - node.kind === 222 || + return node.kind === 221 || + node.kind === 223 && !!node.name || node.kind === 224 || - node.kind === 228 || - node.kind === 225 && node.expression.kind === 67; + node.kind === 226 || + node.kind === 230 || + node.kind === 227 && node.expression.kind === 69; } ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration; function getClassExtendsHeritageClauseElement(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81); + var heritageClause = getHeritageClause(node.heritageClauses, 83); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 104); + var heritageClause = getHeritageClause(node.heritageClauses, 106); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; function getInterfaceBaseTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81); + var heritageClause = getHeritageClause(node.heritageClauses, 83); return heritageClause ? heritageClause.types : undefined; } ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes; @@ -4593,7 +4725,7 @@ var ts; } ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath; function isKeyword(token) { - return 68 <= token && token <= 132; + return 70 <= token && token <= 134; } ts.isKeyword = isKeyword; function isTrivia(token) { @@ -4606,19 +4738,19 @@ var ts; ts.isAsyncFunctionLike = isAsyncFunctionLike; function hasDynamicName(declaration) { return declaration.name && - declaration.name.kind === 134 && + declaration.name.kind === 136 && !isWellKnownSymbolSyntactically(declaration.name.expression); } ts.hasDynamicName = hasDynamicName; function isWellKnownSymbolSyntactically(node) { - return node.kind === 164 && isESSymbolIdentifier(node.expression); + return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression); } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 67 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8) { return name.text; } - if (name.kind === 134) { + if (name.kind === 136) { var nameExpression = name.expression; if (isWellKnownSymbolSyntactically(nameExpression)) { var rightHandSideName = nameExpression.name.text; @@ -4633,21 +4765,21 @@ var ts; } ts.getPropertyNameForKnownSymbolName = getPropertyNameForKnownSymbolName; function isESSymbolIdentifier(node) { - return node.kind === 67 && node.text === "Symbol"; + return node.kind === 69 && node.text === "Symbol"; } ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 113: - case 116: - case 72: - case 120: - case 75: - case 80: + case 115: + case 118: + case 74: + case 122: + case 77: + case 82: + case 112: case 110: - case 108: - case 109: case 111: + case 113: return true; } return false; @@ -4655,28 +4787,28 @@ var ts; ts.isModifier = isModifier; function isParameterDeclaration(node) { var root = getRootDeclaration(node); - return root.kind === 136; + return root.kind === 138; } ts.isParameterDeclaration = isParameterDeclaration; function getRootDeclaration(node) { - while (node.kind === 161) { + while (node.kind === 163) { node = node.parent.parent; } return node; } ts.getRootDeclaration = getRootDeclaration; function nodeStartsNewLexicalEnvironment(n) { - return isFunctionLike(n) || n.kind === 216 || n.kind === 246; + return isFunctionLike(n) || n.kind === 218 || n.kind === 248; } ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; function cloneEntityName(node) { - if (node.kind === 67) { - var clone_1 = createSynthesizedNode(67); + if (node.kind === 69) { + var clone_1 = createSynthesizedNode(69); clone_1.text = node.text; return clone_1; } else { - var clone_2 = createSynthesizedNode(133); + var clone_2 = createSynthesizedNode(135); clone_2.left = cloneEntityName(node.left); clone_2.left.parent = clone_2; clone_2.right = cloneEntityName(node.right); @@ -4919,7 +5051,7 @@ var ts; ts.getLineOfLocalPosition = getLineOfLocalPosition; function getFirstConstructorWithBody(node) { return ts.forEach(node.members, function (member) { - if (member.kind === 142 && nodeIsPresent(member.body)) { + if (member.kind === 144 && nodeIsPresent(member.body)) { return member; } }); @@ -4946,10 +5078,10 @@ var ts; var setAccessor; if (hasDynamicName(accessor)) { firstAccessor = accessor; - if (accessor.kind === 143) { + if (accessor.kind === 145) { getAccessor = accessor; } - else if (accessor.kind === 144) { + else if (accessor.kind === 146) { setAccessor = accessor; } else { @@ -4958,7 +5090,7 @@ var ts; } else { ts.forEach(declarations, function (member) { - if ((member.kind === 143 || member.kind === 144) + if ((member.kind === 145 || member.kind === 146) && (member.flags & 128) === (accessor.flags & 128)) { var memberName = getPropertyNameForPropertyNameNode(member.name); var accessorName = getPropertyNameForPropertyNameNode(accessor.name); @@ -4969,10 +5101,10 @@ var ts; else if (!secondAccessor) { secondAccessor = member; } - if (member.kind === 143 && !getAccessor) { + if (member.kind === 145 && !getAccessor) { getAccessor = member; } - if (member.kind === 144 && !setAccessor) { + if (member.kind === 146 && !setAccessor) { setAccessor = member; } } @@ -5078,16 +5210,16 @@ var ts; ts.writeCommentRange = writeCommentRange; function modifierToFlag(token) { switch (token) { - case 111: return 128; - case 110: return 16; - case 109: return 64; - case 108: return 32; - case 113: return 256; - case 80: return 1; - case 120: return 2; - case 72: return 32768; - case 75: return 1024; - case 116: return 512; + case 113: return 128; + case 112: return 16; + case 111: return 64; + case 110: return 32; + case 115: return 256; + case 82: return 1; + case 122: return 2; + case 74: return 32768; + case 77: return 1024; + case 118: return 512; } return 0; } @@ -5095,29 +5227,29 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 164: - case 165: - case 167: case 166: - case 231: - case 232: + case 167: + case 169: case 168: - case 162: + case 233: + case 234: case 170: - case 163: - case 184: - case 171: - case 67: + case 164: + case 172: + case 165: + case 186: + case 173: + case 69: case 10: case 8: case 9: case 11: - case 181: - case 82: - case 91: - case 95: - case 97: + case 183: + case 84: case 93: + case 97: + case 99: + case 95: return true; } } @@ -5125,12 +5257,12 @@ var ts; } ts.isLeftHandSideExpression = isLeftHandSideExpression; function isAssignmentOperator(token) { - return token >= 55 && token <= 66; + return token >= 56 && token <= 68; } ts.isAssignmentOperator = isAssignmentOperator; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { - return node.kind === 186 && - node.parent.token === 81 && + return node.kind === 188 && + node.parent.token === 83 && isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; @@ -5139,10 +5271,10 @@ var ts; } ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments; function isSupportedExpressionWithTypeArgumentsRest(node) { - if (node.kind === 67) { + if (node.kind === 69) { return true; } - else if (node.kind === 164) { + else if (isPropertyAccessExpression(node)) { return isSupportedExpressionWithTypeArgumentsRest(node.expression); } else { @@ -5150,16 +5282,16 @@ var ts; } } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 133 && node.parent.right === node) || - (node.parent.kind === 164 && node.parent.name === node); + return (node.parent.kind === 135 && node.parent.right === node) || + (node.parent.kind === 166 && node.parent.name === node); } ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess; function isEmptyObjectLiteralOrArrayLiteral(expression) { var kind = expression.kind; - if (kind === 163) { + if (kind === 165) { return expression.properties.length === 0; } - if (kind === 162) { + if (kind === 164) { return expression.elements.length === 0; } return false; @@ -5368,19 +5500,29 @@ var ts; } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function getTypeParameterOwner(d) { - if (d && d.kind === 135) { + if (d && d.kind === 137) { for (var current = d; current; current = current.parent) { - if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 213) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 215) { return current; } } } } ts.getTypeParameterOwner = getTypeParameterOwner; + function arrayStructurallyIsEqualTo(array1, array2) { + if (!array1 || !array2) { + return false; + } + if (array1.length !== array2.length) { + return false; + } + return ts.arrayIsEqualTo(array1.sort(), array2.sort()); + } + ts.arrayStructurallyIsEqualTo = arrayStructurallyIsEqualTo; })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(270); + var nodeConstructors = new Array(272); ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -5418,20 +5560,26 @@ var ts; var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; var cbNodes = cbNodeArray || cbNode; switch (node.kind) { - case 133: + case 135: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); - case 135: + case 137: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); - case 136: - case 139: + case 246: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.equalsToken) || + visitNode(cbNode, node.objectAssignmentInitializer); case 138: - case 243: - case 244: - case 209: - case 161: + case 141: + case 140: + case 245: + case 211: + case 163: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || @@ -5440,24 +5588,24 @@ var ts; visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); - case 150: - case 151: - case 145: - case 146: + case 152: + case 153: case 147: + case 148: + case 149: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 141: - case 140: - case 142: case 143: + case 142: case 144: - case 171: - case 211: - case 172: + case 145: + case 146: + case 173: + case 213: + case 174: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || @@ -5468,290 +5616,290 @@ var ts; visitNode(cbNode, node.type) || visitNode(cbNode, node.equalsGreaterThanToken) || visitNode(cbNode, node.body); - case 149: + case 151: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); - case 148: + case 150: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); - case 152: - return visitNode(cbNode, node.exprName); - case 153: - return visitNodes(cbNodes, node.members); case 154: - return visitNode(cbNode, node.elementType); + return visitNode(cbNode, node.exprName); case 155: - return visitNodes(cbNodes, node.elementTypes); + return visitNodes(cbNodes, node.members); case 156: + return visitNode(cbNode, node.elementType); case 157: - return visitNodes(cbNodes, node.types); + return visitNodes(cbNodes, node.elementTypes); case 158: - return visitNode(cbNode, node.type); case 159: + return visitNodes(cbNodes, node.types); case 160: - return visitNodes(cbNodes, node.elements); + return visitNode(cbNode, node.type); + case 161: case 162: return visitNodes(cbNodes, node.elements); - case 163: - return visitNodes(cbNodes, node.properties); case 164: + return visitNodes(cbNodes, node.elements); + case 165: + return visitNodes(cbNodes, node.properties); + case 166: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); - case 165: + case 167: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); - case 166: - case 167: + case 168: + case 169: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); - case 168: + case 170: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); - case 169: + case 171: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); - case 170: - return visitNode(cbNode, node.expression); - case 173: - return visitNode(cbNode, node.expression); - case 174: + case 172: return visitNode(cbNode, node.expression); case 175: return visitNode(cbNode, node.expression); - case 177: - return visitNode(cbNode, node.operand); - case 182: - return visitNode(cbNode, node.asteriskToken) || - visitNode(cbNode, node.expression); case 176: return visitNode(cbNode, node.expression); - case 178: - return visitNode(cbNode, node.operand); + case 177: + return visitNode(cbNode, node.expression); case 179: + return visitNode(cbNode, node.operand); + case 184: + return visitNode(cbNode, node.asteriskToken) || + visitNode(cbNode, node.expression); + case 178: + return visitNode(cbNode, node.expression); + case 180: + return visitNode(cbNode, node.operand); + case 181: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); - case 187: + case 189: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); - case 180: + case 182: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); - case 183: + case 185: return visitNode(cbNode, node.expression); - case 190: - case 217: + case 192: + case 219: return visitNodes(cbNodes, node.statements); - case 246: + case 248: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); - case 191: + case 193: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); - case 210: + case 212: return visitNodes(cbNodes, node.declarations); - case 193: + case 195: return visitNode(cbNode, node.expression); - case 194: + case 196: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); - case 195: + case 197: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); - case 196: + case 198: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 197: + case 199: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); - case 198: - return visitNode(cbNode, node.initializer) || - visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); - case 199: - return visitNode(cbNode, node.initializer) || - visitNode(cbNode, node.expression) || - visitNode(cbNode, node.statement); case 200: - case 201: - return visitNode(cbNode, node.label); - case 202: - return visitNode(cbNode, node.expression); - case 203: - return visitNode(cbNode, node.expression) || + return visitNode(cbNode, node.initializer) || + visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); + case 201: + return visitNode(cbNode, node.initializer) || + visitNode(cbNode, node.expression) || + visitNode(cbNode, node.statement); + case 202: + case 203: + return visitNode(cbNode, node.label); case 204: - return visitNode(cbNode, node.expression) || - visitNode(cbNode, node.caseBlock); - case 218: - return visitNodes(cbNodes, node.clauses); - case 239: - return visitNode(cbNode, node.expression) || - visitNodes(cbNodes, node.statements); - case 240: - return visitNodes(cbNodes, node.statements); + return visitNode(cbNode, node.expression); case 205: - return visitNode(cbNode, node.label) || + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 206: - return visitNode(cbNode, node.expression); + return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.caseBlock); + case 220: + return visitNodes(cbNodes, node.clauses); + case 241: + return visitNode(cbNode, node.expression) || + visitNodes(cbNodes, node.statements); + case 242: + return visitNodes(cbNodes, node.statements); case 207: + return visitNode(cbNode, node.label) || + visitNode(cbNode, node.statement); + case 208: + return visitNode(cbNode, node.expression); + case 209: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); - case 242: + case 244: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); - case 137: + case 139: return visitNode(cbNode, node.expression); - case 212: - case 184: - return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNodes, node.typeParameters) || - visitNodes(cbNodes, node.heritageClauses) || - visitNodes(cbNodes, node.members); - case 213: - return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.name) || - visitNodes(cbNodes, node.typeParameters) || - visitNodes(cbNodes, node.heritageClauses) || - visitNodes(cbNodes, node.members); case 214: + case 186: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || - visitNode(cbNode, node.type); + visitNodes(cbNodes, node.heritageClauses) || + visitNodes(cbNodes, node.members); case 215: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeParameters) || + visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 245: - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.initializer); case 216: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeParameters) || + visitNode(cbNode, node.type); + case 217: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.members); + case 247: + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.initializer); + case 218: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); - case 219: + case 221: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); - case 220: + case 222: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); - case 221: + case 223: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 222: + case 224: return visitNode(cbNode, node.name); - case 223: - case 227: + case 225: + case 229: return visitNodes(cbNodes, node.elements); - case 226: + case 228: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); - case 224: - case 228: + case 226: + case 230: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); - case 225: + case 227: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); - case 181: + case 183: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); - case 188: + case 190: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); - case 134: + case 136: return visitNode(cbNode, node.expression); - case 241: + case 243: return visitNodes(cbNodes, node.types); - case 186: + case 188: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); - case 230: + case 232: return visitNode(cbNode, node.expression); - case 229: - return visitNodes(cbNodes, node.decorators); case 231: + return visitNodes(cbNodes, node.decorators); + case 233: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); - case 232: - case 233: + case 234: + case 235: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); - case 236: + case 238: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); + case 239: + return visitNode(cbNode, node.expression); + case 240: + return visitNode(cbNode, node.expression); case 237: - return visitNode(cbNode, node.expression); - case 238: - return visitNode(cbNode, node.expression); - case 235: return visitNode(cbNode, node.tagName); - case 247: - return visitNode(cbNode, node.type); - case 251: - return visitNodes(cbNodes, node.types); - case 252: - return visitNodes(cbNodes, node.types); - case 250: - return visitNode(cbNode, node.elementType); - case 254: + case 249: return visitNode(cbNode, node.type); case 253: + return visitNodes(cbNodes, node.types); + case 254: + return visitNodes(cbNodes, node.types); + case 252: + return visitNode(cbNode, node.elementType); + case 256: return visitNode(cbNode, node.type); case 255: - return visitNodes(cbNodes, node.members); + return visitNode(cbNode, node.type); case 257: + return visitNodes(cbNodes, node.members); + case 259: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); - case 258: - return visitNode(cbNode, node.type); - case 259: - return visitNodes(cbNodes, node.parameters) || - visitNode(cbNode, node.type); case 260: return visitNode(cbNode, node.type); case 261: - return visitNode(cbNode, node.type); + return visitNodes(cbNodes, node.parameters) || + visitNode(cbNode, node.type); case 262: return visitNode(cbNode, node.type); - case 256: + case 263: + return visitNode(cbNode, node.type); + case 264: + return visitNode(cbNode, node.type); + case 258: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); - case 263: - return visitNodes(cbNodes, node.tags); case 265: + return visitNodes(cbNodes, node.tags); + case 267: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); - case 266: - return visitNode(cbNode, node.typeExpression); - case 267: - return visitNode(cbNode, node.typeExpression); case 268: + return visitNode(cbNode, node.typeExpression); + case 269: + return visitNode(cbNode, node.typeExpression); + case 270: return visitNodes(cbNodes, node.typeParameters); } } @@ -5847,9 +5995,9 @@ var ts; return; function visit(node) { switch (node.kind) { - case 191: - case 211: - case 136: + case 193: + case 213: + case 138: addJSDocComment(node); } forEachChild(node, visit); @@ -5883,7 +6031,7 @@ var ts; } Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - var sourceFile = createNode(246, 0); + var sourceFile = createNode(248, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; @@ -6042,16 +6190,16 @@ var ts; return speculationHelper(callback, false); } function isIdentifier() { - if (token === 67) { + if (token === 69) { return true; } - if (token === 112 && inYieldContext()) { + if (token === 114 && inYieldContext()) { return false; } - if (token === 117 && inAwaitContext()) { + if (token === 119 && inAwaitContext()) { return false; } - return token > 103; + return token > 105; } function parseExpected(kind, diagnosticMessage, shouldAdvance) { if (shouldAdvance === void 0) { shouldAdvance = true; } @@ -6147,15 +6295,15 @@ var ts; function createIdentifier(isIdentifier, diagnosticMessage) { identifierCount++; if (isIdentifier) { - var node = createNode(67); - if (token !== 67) { + var node = createNode(69); + if (token !== 69) { node.originalKeywordKind = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); } - return createMissingNode(67, false, diagnosticMessage || ts.Diagnostics.Identifier_expected); + return createMissingNode(69, false, diagnosticMessage || ts.Diagnostics.Identifier_expected); } function parseIdentifier(diagnosticMessage) { return createIdentifier(isIdentifier(), diagnosticMessage); @@ -6187,7 +6335,7 @@ var ts; return token === 9 || token === 8 || ts.tokenIsIdentifierOrKeyword(token); } function parseComputedPropertyName() { - var node = createNode(134); + var node = createNode(136); parseExpected(19); node.expression = allowInAnd(parseExpression); parseExpected(20); @@ -6197,20 +6345,27 @@ var ts; return token === t && tryParse(nextTokenCanFollowModifier); } function nextTokenCanFollowModifier() { - if (token === 72) { - return nextToken() === 79; + if (token === 74) { + return nextToken() === 81; } - if (token === 80) { + if (token === 82) { nextToken(); - if (token === 75) { + if (token === 77) { return lookAhead(nextTokenIsClassOrFunction); } return token !== 37 && token !== 15 && canFollowModifier(); } - if (token === 75) { + if (token === 77) { return nextTokenIsClassOrFunction(); } + if (token === 113) { + nextToken(); + return canFollowModifier(); + } nextToken(); + if (scanner.hasPrecedingLineBreak()) { + return false; + } return canFollowModifier(); } function parseAnyContextualModifier() { @@ -6224,7 +6379,7 @@ var ts; } function nextTokenIsClassOrFunction() { nextToken(); - return token === 71 || token === 85; + return token === 73 || token === 87; } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -6237,7 +6392,7 @@ var ts; case 3: return !(token === 23 && inErrorRecovery) && isStartOfStatement(); case 2: - return token === 69 || token === 75; + return token === 71 || token === 77; case 4: return isStartOfTypeMember(); case 5: @@ -6293,7 +6448,7 @@ var ts; ts.Debug.assert(token === 15); if (nextToken() === 16) { var next = nextToken(); - return next === 24 || next === 15 || next === 81 || next === 104; + return next === 24 || next === 15 || next === 83 || next === 106; } return true; } @@ -6306,8 +6461,8 @@ var ts; return ts.tokenIsIdentifierOrKeyword(token); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 104 || - token === 81) { + if (token === 106 || + token === 83) { return lookAhead(nextTokenIsStartOfExpression); } return false; @@ -6331,13 +6486,13 @@ var ts; case 21: return token === 16; case 3: - return token === 16 || token === 69 || token === 75; + return token === 16 || token === 71 || token === 77; case 7: - return token === 15 || token === 81 || token === 104; + return token === 15 || token === 83 || token === 106; case 8: return isVariableDeclaratorListTerminator(); case 17: - return token === 27 || token === 17 || token === 15 || token === 81 || token === 104; + return token === 27 || token === 17 || token === 15 || token === 83 || token === 106; case 11: return token === 18 || token === 23; case 15: @@ -6351,11 +6506,11 @@ var ts; case 20: return token === 15 || token === 16; case 13: - return token === 27 || token === 38; + return token === 27 || token === 39; case 14: return token === 25 && lookAhead(nextTokenIsSlash); case 22: - return token === 18 || token === 53 || token === 16; + return token === 18 || token === 54 || token === 16; case 23: return token === 27 || token === 16; case 25: @@ -6476,17 +6631,17 @@ var ts; function isReusableClassMember(node) { if (node) { switch (node.kind) { - case 142: - case 147: - case 143: case 144: - case 139: - case 189: - return true; + case 149: + case 145: + case 146: case 141: + case 191: + return true; + case 143: var methodDeclaration = node; - var nameIsConstructor = methodDeclaration.name.kind === 67 && - methodDeclaration.name.originalKeywordKind === 119; + var nameIsConstructor = methodDeclaration.name.kind === 69 && + methodDeclaration.name.originalKeywordKind === 121; return !nameIsConstructor; } } @@ -6495,8 +6650,8 @@ var ts; function isReusableSwitchClause(node) { if (node) { switch (node.kind) { - case 239: - case 240: + case 241: + case 242: return true; } } @@ -6505,65 +6660,65 @@ var ts; function isReusableStatement(node) { if (node) { switch (node.kind) { - case 211: - case 191: - case 190: - case 194: + case 213: case 193: - case 206: - case 202: - case 204: - case 201: - case 200: - case 198: - case 199: - case 197: - case 196: - case 203: case 192: - case 207: - case 205: + case 196: case 195: case 208: - case 220: - case 219: - case 226: - case 225: - case 216: - case 212: - case 213: - case 215: + case 204: + case 206: + case 203: + case 202: + case 200: + case 201: + case 199: + case 198: + case 205: + case 194: + case 209: + case 207: + case 197: + case 210: + case 222: + case 221: + case 228: + case 227: + case 218: case 214: + case 215: + case 217: + case 216: return true; } } return false; } function isReusableEnumMember(node) { - return node.kind === 245; + return node.kind === 247; } function isReusableTypeMember(node) { if (node) { switch (node.kind) { - case 146: + case 148: + case 142: + case 149: case 140: case 147: - case 138: - case 145: return true; } } return false; } function isReusableVariableDeclaration(node) { - if (node.kind !== 209) { + if (node.kind !== 211) { return false; } var variableDeclarator = node; return variableDeclarator.initializer === undefined; } function isReusableParameter(node) { - if (node.kind !== 136) { + if (node.kind !== 138) { return false; } var parameter = node; @@ -6663,7 +6818,7 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var entity = parseIdentifier(diagnosticMessage); while (parseOptional(21)) { - var node = createNode(133, entity.pos); + var node = createNode(135, entity.pos); node.left = entity; node.right = parseRightSideOfDot(allowReservedWords); entity = finishNode(node); @@ -6674,13 +6829,13 @@ var ts; if (scanner.hasPrecedingLineBreak() && ts.tokenIsIdentifierOrKeyword(token)) { var matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); if (matchesPattern) { - return createMissingNode(67, true, ts.Diagnostics.Identifier_expected); + return createMissingNode(69, true, ts.Diagnostics.Identifier_expected); } } return allowIdentifierNames ? parseIdentifierName() : parseIdentifier(); } function parseTemplateExpression() { - var template = createNode(181); + var template = createNode(183); template.head = parseLiteralNode(); ts.Debug.assert(template.head.kind === 12, "Template head has wrong token kind"); var templateSpans = []; @@ -6693,7 +6848,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(188); + var span = createNode(190); span.expression = allowInAnd(parseExpression); var literal; if (token === 16) { @@ -6728,14 +6883,14 @@ var ts; } function parseTypeReferenceOrTypePredicate() { var typeName = parseEntityName(false, ts.Diagnostics.Type_expected); - if (typeName.kind === 67 && token === 122 && !scanner.hasPrecedingLineBreak()) { + if (typeName.kind === 69 && token === 124 && !scanner.hasPrecedingLineBreak()) { nextToken(); - var node_1 = createNode(148, typeName.pos); + var node_1 = createNode(150, typeName.pos); node_1.parameterName = typeName; node_1.type = parseType(); return finishNode(node_1); } - var node = createNode(149, typeName.pos); + var node = createNode(151, typeName.pos); node.typeName = typeName; if (!scanner.hasPrecedingLineBreak() && token === 25) { node.typeArguments = parseBracketedList(18, parseType, 25, 27); @@ -6743,15 +6898,15 @@ var ts; return finishNode(node); } function parseTypeQuery() { - var node = createNode(152); - parseExpected(99); + var node = createNode(154); + parseExpected(101); node.exprName = parseEntityName(true); return finishNode(node); } function parseTypeParameter() { - var node = createNode(135); + var node = createNode(137); node.name = parseIdentifier(); - if (parseOptional(81)) { + if (parseOptional(83)) { if (isStartOfType() || !isStartOfExpression()) { node.constraint = parseType(); } @@ -6767,7 +6922,7 @@ var ts; } } function parseParameterType() { - if (parseOptional(53)) { + if (parseOptional(54)) { return token === 9 ? parseLiteralNode(true) : parseType(); @@ -6775,7 +6930,7 @@ var ts; return undefined; } function isStartOfParameter() { - return token === 22 || isIdentifierOrPattern() || ts.isModifier(token) || token === 54; + return token === 22 || isIdentifierOrPattern() || ts.isModifier(token) || token === 55; } function setModifiers(node, modifiers) { if (modifiers) { @@ -6784,7 +6939,7 @@ var ts; } } function parseParameter() { - var node = createNode(136); + var node = createNode(138); node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(22); @@ -6792,7 +6947,7 @@ var ts; if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(token)) { nextToken(); } - node.questionToken = parseOptionalToken(52); + node.questionToken = parseOptionalToken(53); node.type = parseParameterType(); node.initializer = parseBindingElementInitializer(true); return finishNode(node); @@ -6839,10 +6994,10 @@ var ts; } function parseSignatureMember(kind) { var node = createNode(kind); - if (kind === 146) { - parseExpected(90); + if (kind === 148) { + parseExpected(92); } - fillSignature(53, false, false, false, node); + fillSignature(54, false, false, false, node); parseTypeMemberSemicolon(); return finishNode(node); } @@ -6869,17 +7024,17 @@ var ts; else { nextToken(); } - if (token === 53 || token === 24) { + if (token === 54 || token === 24) { return true; } - if (token !== 52) { + if (token !== 53) { return false; } nextToken(); - return token === 53 || token === 24 || token === 20; + return token === 54 || token === 24 || token === 20; } function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) { - var node = createNode(147, fullStart); + var node = createNode(149, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(16, parseParameter, 19, 20); @@ -6890,17 +7045,17 @@ var ts; function parsePropertyOrMethodSignature() { var fullStart = scanner.getStartPos(); var name = parsePropertyName(); - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (token === 17 || token === 25) { - var method = createNode(140, fullStart); + var method = createNode(142, fullStart); method.name = name; method.questionToken = questionToken; - fillSignature(53, false, false, false, method); + fillSignature(54, false, false, false, method); parseTypeMemberSemicolon(); return finishNode(method); } else { - var property = createNode(138, fullStart); + var property = createNode(140, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -6934,22 +7089,22 @@ var ts; nextToken(); return token === 17 || token === 25 || - token === 52 || token === 53 || + token === 54 || canParseSemicolon(); } function parseTypeMember() { switch (token) { case 17: case 25: - return parseSignatureMember(145); + return parseSignatureMember(147); case 19: return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), undefined, undefined) : parsePropertyOrMethodSignature(); - case 90: + case 92: if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(146); + return parseSignatureMember(148); } case 9: case 8: @@ -6979,7 +7134,7 @@ var ts; return token === 17 || token === 25; } function parseTypeLiteral() { - var node = createNode(153); + var node = createNode(155); node.members = parseObjectTypeMembers(); return finishNode(node); } @@ -6995,12 +7150,12 @@ var ts; return members; } function parseTupleType() { - var node = createNode(155); + var node = createNode(157); node.elementTypes = parseBracketedList(19, parseType, 19, 20); return finishNode(node); } function parseParenthesizedType() { - var node = createNode(158); + var node = createNode(160); parseExpected(17); node.type = parseType(); parseExpected(18); @@ -7008,8 +7163,8 @@ var ts; } function parseFunctionOrConstructorType(kind) { var node = createNode(kind); - if (kind === 151) { - parseExpected(90); + if (kind === 153) { + parseExpected(92); } fillSignature(34, false, false, false, node); return finishNode(node); @@ -7020,16 +7175,17 @@ var ts; } function parseNonArrayType() { switch (token) { - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: + case 120: + case 131: var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReferenceOrTypePredicate(); - case 101: + case 103: + case 97: return parseTokenNode(); - case 99: + case 101: return parseTypeQuery(); case 15: return parseTypeLiteral(); @@ -7043,17 +7199,18 @@ var ts; } function isStartOfType() { switch (token) { - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: + case 120: + case 131: + case 103: + case 97: case 101: - case 99: case 15: case 19: case 25: - case 90: + case 92: return true; case 17: return lookAhead(isStartOfParenthesizedOrFunctionType); @@ -7069,7 +7226,7 @@ var ts; var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(19)) { parseExpected(20); - var node = createNode(154, type.pos); + var node = createNode(156, type.pos); node.elementType = type; type = finishNode(node); } @@ -7091,10 +7248,10 @@ var ts; return type; } function parseIntersectionTypeOrHigher() { - return parseUnionOrIntersectionType(157, parseArrayTypeOrHigher, 45); + return parseUnionOrIntersectionType(159, parseArrayTypeOrHigher, 46); } function parseUnionTypeOrHigher() { - return parseUnionOrIntersectionType(156, parseIntersectionTypeOrHigher, 46); + return parseUnionOrIntersectionType(158, parseIntersectionTypeOrHigher, 47); } function isStartOfFunctionType() { if (token === 25) { @@ -7109,8 +7266,8 @@ var ts; } if (isIdentifier() || ts.isModifier(token)) { nextToken(); - if (token === 53 || token === 24 || - token === 52 || token === 55 || + if (token === 54 || token === 24 || + token === 53 || token === 56 || isIdentifier() || ts.isModifier(token)) { return true; } @@ -7128,23 +7285,23 @@ var ts; } function parseTypeWorker() { if (isStartOfFunctionType()) { - return parseFunctionOrConstructorType(150); + return parseFunctionOrConstructorType(152); } - if (token === 90) { - return parseFunctionOrConstructorType(151); + if (token === 92) { + return parseFunctionOrConstructorType(153); } return parseUnionTypeOrHigher(); } function parseTypeAnnotation() { - return parseOptional(53) ? parseType() : undefined; + return parseOptional(54) ? parseType() : undefined; } function isStartOfLeftHandSideExpression() { switch (token) { + case 97: case 95: case 93: - case 91: - case 97: - case 82: + case 99: + case 84: case 8: case 9: case 11: @@ -7152,12 +7309,12 @@ var ts; case 17: case 19: case 15: - case 85: - case 71: - case 90: - case 38: - case 59: - case 67: + case 87: + case 73: + case 92: + case 39: + case 61: + case 69: return true; default: return isIdentifier(); @@ -7170,16 +7327,16 @@ var ts; switch (token) { case 35: case 36: + case 50: case 49: - case 48: - case 76: - case 99: + case 78: case 101: - case 40: + case 103: case 41: + case 42: case 25: - case 117: - case 112: + case 119: + case 114: return true; default: if (isBinaryOperator()) { @@ -7190,9 +7347,9 @@ var ts; } function isStartOfExpressionStatement() { return token !== 15 && - token !== 85 && - token !== 71 && - token !== 54 && + token !== 87 && + token !== 73 && + token !== 55 && isStartOfExpression(); } function allowInAndParseExpression() { @@ -7214,12 +7371,12 @@ var ts; return expr; } function parseInitializer(inParameter) { - if (token !== 55) { + if (token !== 56) { if (scanner.hasPrecedingLineBreak() || (inParameter && token === 15) || !isStartOfExpression()) { return undefined; } } - parseExpected(55); + parseExpected(56); return parseAssignmentExpressionOrHigher(); } function parseAssignmentExpressionOrHigher() { @@ -7231,7 +7388,7 @@ var ts; return arrowExpression; } var expr = parseBinaryExpressionOrHigher(0); - if (expr.kind === 67 && token === 34) { + if (expr.kind === 69 && token === 34) { return parseSimpleArrowFunctionExpression(expr); } if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) { @@ -7240,7 +7397,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 112) { + if (token === 114) { if (inYieldContext()) { return true; } @@ -7253,7 +7410,7 @@ var ts; return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression() { - var node = createNode(182); + var node = createNode(184); nextToken(); if (!scanner.hasPrecedingLineBreak() && (token === 37 || isStartOfExpression())) { @@ -7267,8 +7424,8 @@ var ts; } function parseSimpleArrowFunctionExpression(identifier) { ts.Debug.assert(token === 34, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - var node = createNode(172, identifier.pos); - var parameter = createNode(136, identifier.pos); + var node = createNode(174, identifier.pos); + var parameter = createNode(138, identifier.pos); parameter.name = identifier; finishNode(parameter); node.parameters = [parameter]; @@ -7298,7 +7455,7 @@ var ts; return finishNode(arrowFunction); } function isParenthesizedArrowFunctionExpression() { - if (token === 17 || token === 25 || token === 116) { + if (token === 17 || token === 25 || token === 118) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } if (token === 34) { @@ -7307,7 +7464,7 @@ var ts; return 0; } function isParenthesizedArrowFunctionExpressionWorker() { - if (token === 116) { + if (token === 118) { nextToken(); if (scanner.hasPrecedingLineBreak()) { return 0; @@ -7323,7 +7480,7 @@ var ts; var third = nextToken(); switch (third) { case 34: - case 53: + case 54: case 15: return 1; default: @@ -7339,7 +7496,7 @@ var ts; if (!isIdentifier()) { return 0; } - if (nextToken() === 53) { + if (nextToken() === 54) { return 1; } return 2; @@ -7352,10 +7509,10 @@ var ts; if (sourceFile.languageVariant === 1) { var isArrowFunctionInJsx = lookAhead(function () { var third = nextToken(); - if (third === 81) { + if (third === 83) { var fourth = nextToken(); switch (fourth) { - case 55: + case 56: case 27: return false; default: @@ -7379,10 +7536,10 @@ var ts; return parseParenthesizedArrowFunctionExpressionHead(false); } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) { - var node = createNode(172); + var node = createNode(174); setModifiers(node, parseModifiersForArrowFunction()); var isAsync = !!(node.flags & 512); - fillSignature(53, false, isAsync, !allowAmbiguity, node); + fillSignature(54, false, isAsync, !allowAmbiguity, node); if (!node.parameters) { return undefined; } @@ -7396,8 +7553,8 @@ var ts; return parseFunctionBlock(false, isAsync, false); } if (token !== 23 && - token !== 85 && - token !== 71 && + token !== 87 && + token !== 73 && isStartOfStatement() && !isStartOfExpressionStatement()) { return parseFunctionBlock(false, isAsync, true); @@ -7407,15 +7564,15 @@ var ts; : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher); } function parseConditionalExpressionRest(leftOperand) { - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (!questionToken) { return leftOperand; } - var node = createNode(180, leftOperand.pos); + var node = createNode(182, leftOperand.pos); node.condition = leftOperand; node.questionToken = questionToken; node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); - node.colonToken = parseExpectedToken(53, false, ts.Diagnostics._0_expected, ts.tokenToString(53)); + node.colonToken = parseExpectedToken(54, false, ts.Diagnostics._0_expected, ts.tokenToString(54)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -7424,19 +7581,22 @@ var ts; return parseBinaryExpressionRest(precedence, leftOperand); } function isInOrOfKeyword(t) { - return t === 88 || t === 132; + return t === 90 || t === 134; } function parseBinaryExpressionRest(precedence, leftOperand) { while (true) { reScanGreaterToken(); var newPrecedence = getBinaryOperatorPrecedence(); - if (newPrecedence <= precedence) { + var consumeCurrentOperator = token === 38 ? + newPrecedence >= precedence : + newPrecedence > precedence; + if (!consumeCurrentOperator) { break; } - if (token === 88 && inDisallowInContext()) { + if (token === 90 && inDisallowInContext()) { break; } - if (token === 114) { + if (token === 116) { if (scanner.hasPrecedingLineBreak()) { break; } @@ -7452,22 +7612,22 @@ var ts; return leftOperand; } function isBinaryOperator() { - if (inDisallowInContext() && token === 88) { + if (inDisallowInContext() && token === 90) { return false; } return getBinaryOperatorPrecedence() > 0; } function getBinaryOperatorPrecedence() { switch (token) { - case 51: + case 52: return 1; - case 50: + case 51: return 2; - case 46: - return 3; case 47: + return 3; + case 48: return 4; - case 45: + case 46: return 5; case 30: case 31: @@ -7478,64 +7638,66 @@ var ts; case 27: case 28: case 29: - case 89: - case 88: - case 114: + case 91: + case 90: + case 116: return 7; - case 42: case 43: case 44: + case 45: return 8; case 35: case 36: return 9; case 37: - case 38: case 39: + case 40: return 10; + case 38: + return 11; } return -1; } function makeBinaryExpression(left, operatorToken, right) { - var node = createNode(179, left.pos); + var node = createNode(181, left.pos); node.left = left; node.operatorToken = operatorToken; node.right = right; return finishNode(node); } function makeAsExpression(left, right) { - var node = createNode(187, left.pos); + var node = createNode(189, left.pos); node.expression = left; node.type = right; return finishNode(node); } function parsePrefixUnaryExpression() { - var node = createNode(177); + var node = createNode(179); node.operator = token; nextToken(); - node.operand = parseUnaryExpressionOrHigher(); + node.operand = parseSimpleUnaryExpression(); return finishNode(node); } function parseDeleteExpression() { - var node = createNode(173); + var node = createNode(175); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseTypeOfExpression() { - var node = createNode(174); + var node = createNode(176); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseVoidExpression() { - var node = createNode(175); + var node = createNode(177); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function isAwaitExpression() { - if (token === 117) { + if (token === 119) { if (inAwaitContext()) { return true; } @@ -7544,45 +7706,87 @@ var ts; return false; } function parseAwaitExpression() { - var node = createNode(176); + var node = createNode(178); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseUnaryExpressionOrHigher() { if (isAwaitExpression()) { return parseAwaitExpression(); } + if (isIncrementExpression()) { + var incrementExpression = parseIncrementExpression(); + return token === 38 ? + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : + incrementExpression; + } + var unaryOperator = token; + var simpleUnaryExpression = parseSimpleUnaryExpression(); + if (token === 38) { + var diagnostic; + var start = ts.skipTrivia(sourceText, simpleUnaryExpression.pos); + if (simpleUnaryExpression.kind === 171) { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses); + } + else { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, ts.tokenToString(unaryOperator)); + } + } + return simpleUnaryExpression; + } + function parseSimpleUnaryExpression() { switch (token) { case 35: case 36: + case 50: case 49: - case 48: - case 40: - case 41: return parsePrefixUnaryExpression(); - case 76: + case 78: return parseDeleteExpression(); - case 99: - return parseTypeOfExpression(); case 101: + return parseTypeOfExpression(); + case 103: return parseVoidExpression(); case 25: - if (sourceFile.languageVariant !== 1) { - return parseTypeAssertion(); - } - if (lookAhead(nextTokenIsIdentifierOrKeyword)) { - return parseJsxElementOrSelfClosingElement(true); - } + return parseTypeAssertion(); default: - return parsePostfixExpressionOrHigher(); + return parseIncrementExpression(); } } - function parsePostfixExpressionOrHigher() { + function isIncrementExpression() { + switch (token) { + case 35: + case 36: + case 50: + case 49: + case 78: + case 101: + case 103: + return false; + case 25: + if (sourceFile.languageVariant !== 1) { + return false; + } + default: + return true; + } + } + function parseIncrementExpression() { + if (token === 41 || token === 42) { + var node = createNode(179); + node.operator = token; + nextToken(); + node.operand = parseLeftHandSideExpressionOrHigher(); + return finishNode(node); + } + else if (sourceFile.languageVariant === 1 && token === 25 && lookAhead(nextTokenIsIdentifierOrKeyword)) { + return parseJsxElementOrSelfClosingElement(true); + } var expression = parseLeftHandSideExpressionOrHigher(); ts.Debug.assert(ts.isLeftHandSideExpression(expression)); - if ((token === 40 || token === 41) && !scanner.hasPrecedingLineBreak()) { - var node = createNode(178, expression.pos); + if ((token === 41 || token === 42) && !scanner.hasPrecedingLineBreak()) { + var node = createNode(180, expression.pos); node.operand = expression; node.operator = token; nextToken(); @@ -7591,7 +7795,7 @@ var ts; return expression; } function parseLeftHandSideExpressionOrHigher() { - var expression = token === 93 + var expression = token === 95 ? parseSuperExpression() : parseMemberExpressionOrHigher(); return parseCallExpressionRest(expression); @@ -7605,7 +7809,7 @@ var ts; if (token === 17 || token === 21 || token === 19) { return expression; } - var node = createNode(164, expression.pos); + var node = createNode(166, expression.pos); node.expression = expression; node.dotToken = parseExpectedToken(21, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); @@ -7613,26 +7817,26 @@ var ts; } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); - if (opening.kind === 233) { - var node = createNode(231, opening.pos); + if (opening.kind === 235) { + var node = createNode(233, opening.pos); node.openingElement = opening; node.children = parseJsxChildren(node.openingElement.tagName); node.closingElement = parseJsxClosingElement(inExpressionContext); return finishNode(node); } else { - ts.Debug.assert(opening.kind === 232); + ts.Debug.assert(opening.kind === 234); return opening; } } function parseJsxText() { - var node = createNode(234, scanner.getStartPos()); + var node = createNode(236, scanner.getStartPos()); token = scanner.scanJsxToken(); return finishNode(node); } function parseJsxChild() { switch (token) { - case 234: + case 236: return parseJsxText(); case 15: return parseJsxExpression(false); @@ -7668,11 +7872,11 @@ var ts; var attributes = parseList(13, parseJsxAttribute); var node; if (token === 27) { - node = createNode(233, fullStart); + node = createNode(235, fullStart); scanJsxText(); } else { - parseExpected(38); + parseExpected(39); if (inExpressionContext) { parseExpected(27); } @@ -7680,7 +7884,7 @@ var ts; parseExpected(27, undefined, false); scanJsxText(); } - node = createNode(232, fullStart); + node = createNode(234, fullStart); } node.tagName = tagName; node.attributes = attributes; @@ -7691,7 +7895,7 @@ var ts; var elementName = parseIdentifierName(); while (parseOptional(21)) { scanJsxIdentifier(); - var node = createNode(133, elementName.pos); + var node = createNode(135, elementName.pos); node.left = elementName; node.right = parseIdentifierName(); elementName = finishNode(node); @@ -7699,7 +7903,7 @@ var ts; return elementName; } function parseJsxExpression(inExpressionContext) { - var node = createNode(238); + var node = createNode(240); parseExpected(15); if (token !== 16) { node.expression = parseExpression(); @@ -7718,9 +7922,9 @@ var ts; return parseJsxSpreadAttribute(); } scanJsxIdentifier(); - var node = createNode(236); + var node = createNode(238); node.name = parseIdentifierName(); - if (parseOptional(55)) { + if (parseOptional(56)) { switch (token) { case 9: node.initializer = parseLiteralNode(); @@ -7733,7 +7937,7 @@ var ts; return finishNode(node); } function parseJsxSpreadAttribute() { - var node = createNode(237); + var node = createNode(239); parseExpected(15); parseExpected(22); node.expression = parseExpression(); @@ -7741,7 +7945,7 @@ var ts; return finishNode(node); } function parseJsxClosingElement(inExpressionContext) { - var node = createNode(235); + var node = createNode(237); parseExpected(26); node.tagName = parseJsxElementName(); if (inExpressionContext) { @@ -7754,18 +7958,18 @@ var ts; return finishNode(node); } function parseTypeAssertion() { - var node = createNode(169); + var node = createNode(171); parseExpected(25); node.type = parseType(); parseExpected(27); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseMemberExpressionRest(expression) { while (true) { var dotToken = parseOptionalToken(21); if (dotToken) { - var propertyAccess = createNode(164, expression.pos); + var propertyAccess = createNode(166, expression.pos); propertyAccess.expression = expression; propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(true); @@ -7773,7 +7977,7 @@ var ts; continue; } if (!inDecoratorContext() && parseOptional(19)) { - var indexedAccess = createNode(165, expression.pos); + var indexedAccess = createNode(167, expression.pos); indexedAccess.expression = expression; if (token !== 20) { indexedAccess.argumentExpression = allowInAnd(parseExpression); @@ -7787,7 +7991,7 @@ var ts; continue; } if (token === 11 || token === 12) { - var tagExpression = createNode(168, expression.pos); + var tagExpression = createNode(170, expression.pos); tagExpression.tag = expression; tagExpression.template = token === 11 ? parseLiteralNode() @@ -7806,7 +8010,7 @@ var ts; if (!typeArguments) { return expression; } - var callExpr = createNode(166, expression.pos); + var callExpr = createNode(168, expression.pos); callExpr.expression = expression; callExpr.typeArguments = typeArguments; callExpr.arguments = parseArgumentList(); @@ -7814,7 +8018,7 @@ var ts; continue; } else if (token === 17) { - var callExpr = createNode(166, expression.pos); + var callExpr = createNode(168, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); expression = finishNode(callExpr); @@ -7847,18 +8051,18 @@ var ts; case 21: case 18: case 20: - case 53: + case 54: case 23: - case 52: + case 53: case 30: case 32: case 31: case 33: - case 50: case 51: - case 47: - case 45: + case 52: + case 48: case 46: + case 47: case 16: case 1: return true; @@ -7874,11 +8078,11 @@ var ts; case 9: case 11: return parseLiteralNode(); + case 97: case 95: case 93: - case 91: - case 97: - case 82: + case 99: + case 84: return parseTokenNode(); case 17: return parseParenthesizedExpression(); @@ -7886,19 +8090,19 @@ var ts; return parseArrayLiteralExpression(); case 15: return parseObjectLiteralExpression(); - case 116: + case 118: if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { break; } return parseFunctionExpression(); - case 71: + case 73: return parseClassExpression(); - case 85: + case 87: return parseFunctionExpression(); - case 90: + case 92: return parseNewExpression(); - case 38: - case 59: + case 39: + case 61: if (reScanSlashToken() === 10) { return parseLiteralNode(); } @@ -7909,28 +8113,28 @@ var ts; return parseIdentifier(ts.Diagnostics.Expression_expected); } function parseParenthesizedExpression() { - var node = createNode(170); + var node = createNode(172); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); return finishNode(node); } function parseSpreadElement() { - var node = createNode(183); + var node = createNode(185); parseExpected(22); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); } function parseArgumentOrArrayLiteralElement() { return token === 22 ? parseSpreadElement() : - token === 24 ? createNode(185) : + token === 24 ? createNode(187) : parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression() { - var node = createNode(162); + var node = createNode(164); parseExpected(19); if (scanner.hasPrecedingLineBreak()) node.flags |= 2048; @@ -7939,11 +8143,11 @@ var ts; return finishNode(node); } function tryParseAccessorDeclaration(fullStart, decorators, modifiers) { - if (parseContextualModifier(121)) { - return parseAccessorDeclaration(143, fullStart, decorators, modifiers); + if (parseContextualModifier(123)) { + return parseAccessorDeclaration(145, fullStart, decorators, modifiers); } - else if (parseContextualModifier(127)) { - return parseAccessorDeclaration(144, fullStart, decorators, modifiers); + else if (parseContextualModifier(129)) { + return parseAccessorDeclaration(146, fullStart, decorators, modifiers); } return undefined; } @@ -7959,27 +8163,33 @@ var ts; var tokenIsIdentifier = isIdentifier(); var nameToken = token; var propertyName = parsePropertyName(); - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (asteriskToken || token === 17 || token === 25) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } - if ((token === 24 || token === 16) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(244, fullStart); + var isShorthandPropertyAssignment = tokenIsIdentifier && (token === 24 || token === 16 || token === 56); + if (isShorthandPropertyAssignment) { + var shorthandDeclaration = createNode(246, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; + var equalsToken = parseOptionalToken(56); + if (equalsToken) { + shorthandDeclaration.equalsToken = equalsToken; + shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher); + } return finishNode(shorthandDeclaration); } else { - var propertyAssignment = createNode(243, fullStart); + var propertyAssignment = createNode(245, fullStart); propertyAssignment.name = propertyName; propertyAssignment.questionToken = questionToken; - parseExpected(53); + parseExpected(54); propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); return finishNode(propertyAssignment); } } function parseObjectLiteralExpression() { - var node = createNode(163); + var node = createNode(165); parseExpected(15); if (scanner.hasPrecedingLineBreak()) { node.flags |= 2048; @@ -7993,9 +8203,9 @@ var ts; if (saveDecoratorContext) { setDecoratorContext(false); } - var node = createNode(171); + var node = createNode(173); setModifiers(node, parseModifiers()); - parseExpected(85); + parseExpected(87); node.asteriskToken = parseOptionalToken(37); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512); @@ -8004,7 +8214,7 @@ var ts; isGenerator ? doInYieldContext(parseOptionalIdentifier) : isAsync ? doInAwaitContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - fillSignature(53, isGenerator, isAsync, false, node); + fillSignature(54, isGenerator, isAsync, false, node); node.body = parseFunctionBlock(isGenerator, isAsync, false); if (saveDecoratorContext) { setDecoratorContext(true); @@ -8015,8 +8225,8 @@ var ts; return isIdentifier() ? parseIdentifier() : undefined; } function parseNewExpression() { - var node = createNode(167); - parseExpected(90); + var node = createNode(169); + parseExpected(92); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); if (node.typeArguments || token === 17) { @@ -8025,7 +8235,7 @@ var ts; return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) { - var node = createNode(190); + var node = createNode(192); if (parseExpected(15, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(1, parseStatement); parseExpected(16); @@ -8053,25 +8263,25 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(192); + var node = createNode(194); parseExpected(23); return finishNode(node); } function parseIfStatement() { - var node = createNode(194); - parseExpected(86); + var node = createNode(196); + parseExpected(88); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); node.thenStatement = parseStatement(); - node.elseStatement = parseOptional(78) ? parseStatement() : undefined; + node.elseStatement = parseOptional(80) ? parseStatement() : undefined; return finishNode(node); } function parseDoStatement() { - var node = createNode(195); - parseExpected(77); + var node = createNode(197); + parseExpected(79); node.statement = parseStatement(); - parseExpected(102); + parseExpected(104); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); @@ -8079,8 +8289,8 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(196); - parseExpected(102); + var node = createNode(198); + parseExpected(104); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); @@ -8089,11 +8299,11 @@ var ts; } function parseForOrForInOrForOfStatement() { var pos = getNodePos(); - parseExpected(84); + parseExpected(86); parseExpected(17); var initializer = undefined; if (token !== 23) { - if (token === 100 || token === 106 || token === 72) { + if (token === 102 || token === 108 || token === 74) { initializer = parseVariableDeclarationList(true); } else { @@ -8101,22 +8311,22 @@ var ts; } } var forOrForInOrForOfStatement; - if (parseOptional(88)) { - var forInStatement = createNode(198, pos); + if (parseOptional(90)) { + var forInStatement = createNode(200, pos); forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(18); forOrForInOrForOfStatement = forInStatement; } - else if (parseOptional(132)) { - var forOfStatement = createNode(199, pos); + else if (parseOptional(134)) { + var forOfStatement = createNode(201, pos); forOfStatement.initializer = initializer; forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher); parseExpected(18); forOrForInOrForOfStatement = forOfStatement; } else { - var forStatement = createNode(197, pos); + var forStatement = createNode(199, pos); forStatement.initializer = initializer; parseExpected(23); if (token !== 23 && token !== 18) { @@ -8134,7 +8344,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 201 ? 68 : 73); + parseExpected(kind === 203 ? 70 : 75); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -8142,8 +8352,8 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(202); - parseExpected(92); + var node = createNode(204); + parseExpected(94); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); } @@ -8151,8 +8361,8 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(203); - parseExpected(103); + var node = createNode(205); + parseExpected(105); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); @@ -8160,30 +8370,30 @@ var ts; return finishNode(node); } function parseCaseClause() { - var node = createNode(239); - parseExpected(69); + var node = createNode(241); + parseExpected(71); node.expression = allowInAnd(parseExpression); - parseExpected(53); + parseExpected(54); node.statements = parseList(3, parseStatement); return finishNode(node); } function parseDefaultClause() { - var node = createNode(240); - parseExpected(75); - parseExpected(53); + var node = createNode(242); + parseExpected(77); + parseExpected(54); node.statements = parseList(3, parseStatement); return finishNode(node); } function parseCaseOrDefaultClause() { - return token === 69 ? parseCaseClause() : parseDefaultClause(); + return token === 71 ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(204); - parseExpected(94); + var node = createNode(206); + parseExpected(96); parseExpected(17); node.expression = allowInAnd(parseExpression); parseExpected(18); - var caseBlock = createNode(218, scanner.getStartPos()); + var caseBlock = createNode(220, scanner.getStartPos()); parseExpected(15); caseBlock.clauses = parseList(2, parseCaseOrDefaultClause); parseExpected(16); @@ -8191,26 +8401,26 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(206); - parseExpected(96); + var node = createNode(208); + parseExpected(98); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } function parseTryStatement() { - var node = createNode(207); - parseExpected(98); + var node = createNode(209); + parseExpected(100); node.tryBlock = parseBlock(false); - node.catchClause = token === 70 ? parseCatchClause() : undefined; - if (!node.catchClause || token === 83) { - parseExpected(83); + node.catchClause = token === 72 ? parseCatchClause() : undefined; + if (!node.catchClause || token === 85) { + parseExpected(85); node.finallyBlock = parseBlock(false); } return finishNode(node); } function parseCatchClause() { - var result = createNode(242); - parseExpected(70); + var result = createNode(244); + parseExpected(72); if (parseExpected(17)) { result.variableDeclaration = parseVariableDeclaration(); } @@ -8219,22 +8429,22 @@ var ts; return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(208); - parseExpected(74); + var node = createNode(210); + parseExpected(76); parseSemicolon(); return finishNode(node); } function parseExpressionOrLabeledStatement() { var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); - if (expression.kind === 67 && parseOptional(53)) { - var labeledStatement = createNode(205, fullStart); + if (expression.kind === 69 && parseOptional(54)) { + var labeledStatement = createNode(207, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(193, fullStart); + var expressionStatement = createNode(195, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); @@ -8246,7 +8456,7 @@ var ts; } function nextTokenIsFunctionKeywordOnSameLine() { nextToken(); - return token === 85 && !scanner.hasPrecedingLineBreak(); + return token === 87 && !scanner.hasPrecedingLineBreak(); } function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); @@ -8255,41 +8465,41 @@ var ts; function isDeclaration() { while (true) { switch (token) { - case 100: - case 106: - case 72: - case 85: - case 71: - case 79: + case 102: + case 108: + case 74: + case 87: + case 73: + case 81: return true; - case 105: - case 130: + case 107: + case 132: return nextTokenIsIdentifierOnSameLine(); - case 123: - case 124: + case 125: + case 126: return nextTokenIsIdentifierOrStringLiteralOnSameLine(); - case 116: - case 120: + case 115: + case 118: + case 122: + case 110: + case 111: + case 112: nextToken(); if (scanner.hasPrecedingLineBreak()) { return false; } continue; - case 87: + case 89: nextToken(); return token === 9 || token === 37 || token === 15 || ts.tokenIsIdentifierOrKeyword(token); - case 80: + case 82: nextToken(); - if (token === 55 || token === 37 || - token === 15 || token === 75) { + if (token === 56 || token === 37 || + token === 15 || token === 77) { return true; } continue; - case 110: - case 108: - case 109: - case 111: case 113: nextToken(); continue; @@ -8303,44 +8513,44 @@ var ts; } function isStartOfStatement() { switch (token) { - case 54: + case 55: case 23: case 15: - case 100: - case 106: - case 85: - case 71: - case 79: - case 86: - case 77: case 102: - case 84: + case 108: + case 87: case 73: - case 68: - case 92: - case 103: + case 81: + case 88: + case 79: + case 104: + case 86: + case 75: + case 70: case 94: + case 105: case 96: case 98: - case 74: - case 70: - case 83: - return true; + case 100: + case 76: case 72: - case 80: - case 87: - return isStartOfDeclaration(); - case 116: - case 120: - case 105: - case 123: - case 124: - case 130: + case 85: return true; + case 74: + case 82: + case 89: + return isStartOfDeclaration(); + case 118: + case 122: + case 107: + case 125: + case 126: + case 132: + return true; + case 112: case 110: - case 108: - case 109: case 111: + case 113: return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); default: return isStartOfExpression(); @@ -8359,60 +8569,60 @@ var ts; return parseEmptyStatement(); case 15: return parseBlock(false); - case 100: + case 102: return parseVariableStatement(scanner.getStartPos(), undefined, undefined); - case 106: + case 108: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined, undefined); } break; - case 85: - return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); - case 71: - return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); - case 86: - return parseIfStatement(); - case 77: - return parseDoStatement(); - case 102: - return parseWhileStatement(); - case 84: - return parseForOrForInOrForOfStatement(); - case 73: - return parseBreakOrContinueStatement(200); - case 68: - return parseBreakOrContinueStatement(201); - case 92: - return parseReturnStatement(); - case 103: - return parseWithStatement(); - case 94: - return parseSwitchStatement(); - case 96: - return parseThrowStatement(); - case 98: - case 70: - case 83: - return parseTryStatement(); - case 74: - return parseDebuggerStatement(); - case 54: - return parseDeclaration(); - case 116: - case 105: - case 130: - case 123: - case 124: - case 120: - case 72: - case 79: - case 80: case 87: - case 108: - case 109: + return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); + case 73: + return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); + case 88: + return parseIfStatement(); + case 79: + return parseDoStatement(); + case 104: + return parseWhileStatement(); + case 86: + return parseForOrForInOrForOfStatement(); + case 75: + return parseBreakOrContinueStatement(202); + case 70: + return parseBreakOrContinueStatement(203); + case 94: + return parseReturnStatement(); + case 105: + return parseWithStatement(); + case 96: + return parseSwitchStatement(); + case 98: + return parseThrowStatement(); + case 100: + case 72: + case 85: + return parseTryStatement(); + case 76: + return parseDebuggerStatement(); + case 55: + return parseDeclaration(); + case 118: + case 107: + case 132: + case 125: + case 126: + case 122: + case 74: + case 81: + case 82: + case 89: case 110: - case 113: case 111: + case 112: + case 115: + case 113: if (isStartOfDeclaration()) { return parseDeclaration(); } @@ -8425,33 +8635,33 @@ var ts; var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 100: - case 106: - case 72: + case 102: + case 108: + case 74: return parseVariableStatement(fullStart, decorators, modifiers); - case 85: - return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 71: - return parseClassDeclaration(fullStart, decorators, modifiers); - case 105: - return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 130: - return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 79: - return parseEnumDeclaration(fullStart, decorators, modifiers); - case 123: - case 124: - return parseModuleDeclaration(fullStart, decorators, modifiers); case 87: + return parseFunctionDeclaration(fullStart, decorators, modifiers); + case 73: + return parseClassDeclaration(fullStart, decorators, modifiers); + case 107: + return parseInterfaceDeclaration(fullStart, decorators, modifiers); + case 132: + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); + case 81: + return parseEnumDeclaration(fullStart, decorators, modifiers); + case 125: + case 126: + return parseModuleDeclaration(fullStart, decorators, modifiers); + case 89: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - case 80: + case 82: nextToken(); - return token === 75 || token === 55 ? + return token === 77 || token === 56 ? parseExportAssignment(fullStart, decorators, modifiers) : parseExportDeclaration(fullStart, decorators, modifiers); default: if (decorators || modifiers) { - var node = createMissingNode(229, true, ts.Diagnostics.Declaration_expected); + var node = createMissingNode(231, true, ts.Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; setModifiers(node, modifiers); @@ -8472,23 +8682,23 @@ var ts; } function parseArrayBindingElement() { if (token === 24) { - return createNode(185); + return createNode(187); } - var node = createNode(161); + var node = createNode(163); node.dotDotDotToken = parseOptionalToken(22); node.name = parseIdentifierOrPattern(); node.initializer = parseBindingElementInitializer(false); return finishNode(node); } function parseObjectBindingElement() { - var node = createNode(161); + var node = createNode(163); var tokenIsIdentifier = isIdentifier(); var propertyName = parsePropertyName(); - if (tokenIsIdentifier && token !== 53) { + if (tokenIsIdentifier && token !== 54) { node.name = propertyName; } else { - parseExpected(53); + parseExpected(54); node.propertyName = propertyName; node.name = parseIdentifierOrPattern(); } @@ -8496,14 +8706,14 @@ var ts; return finishNode(node); } function parseObjectBindingPattern() { - var node = createNode(159); + var node = createNode(161); parseExpected(15); node.elements = parseDelimitedList(9, parseObjectBindingElement); parseExpected(16); return finishNode(node); } function parseArrayBindingPattern() { - var node = createNode(160); + var node = createNode(162); parseExpected(19); node.elements = parseDelimitedList(10, parseArrayBindingElement); parseExpected(20); @@ -8522,7 +8732,7 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(209); + var node = createNode(211); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); if (!isInOrOfKeyword(token)) { @@ -8531,21 +8741,21 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(inForStatementInitializer) { - var node = createNode(210); + var node = createNode(212); switch (token) { - case 100: + case 102: break; - case 106: + case 108: node.flags |= 16384; break; - case 72: + case 74: node.flags |= 32768; break; default: ts.Debug.fail(); } nextToken(); - if (token === 132 && lookAhead(canFollowContextualOfKeyword)) { + if (token === 134 && lookAhead(canFollowContextualOfKeyword)) { node.declarations = createMissingList(); } else { @@ -8560,7 +8770,7 @@ var ts; return nextTokenIsIdentifier() && nextToken() === 18; } function parseVariableStatement(fullStart, decorators, modifiers) { - var node = createNode(191, fullStart); + var node = createNode(193, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(false); @@ -8568,29 +8778,29 @@ var ts; return finishNode(node); } function parseFunctionDeclaration(fullStart, decorators, modifiers) { - var node = createNode(211, fullStart); + var node = createNode(213, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(85); + parseExpected(87); node.asteriskToken = parseOptionalToken(37); node.name = node.flags & 1024 ? parseOptionalIdentifier() : parseIdentifier(); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512); - fillSignature(53, isGenerator, isAsync, false, node); + fillSignature(54, isGenerator, isAsync, false, node); node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, decorators, modifiers) { - var node = createNode(142, pos); + var node = createNode(144, pos); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(119); - fillSignature(53, false, false, false, node); + parseExpected(121); + fillSignature(54, false, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, false, ts.Diagnostics.or_expected); return finishNode(node); } function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { - var method = createNode(141, fullStart); + var method = createNode(143, fullStart); method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; @@ -8598,12 +8808,12 @@ var ts; method.questionToken = questionToken; var isGenerator = !!asteriskToken; var isAsync = !!(method.flags & 512); - fillSignature(53, isGenerator, isAsync, false, method); + fillSignature(54, isGenerator, isAsync, false, method); method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage); return finishNode(method); } function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) { - var property = createNode(139, fullStart); + var property = createNode(141, fullStart); property.decorators = decorators; setModifiers(property, modifiers); property.name = name; @@ -8618,7 +8828,7 @@ var ts; function parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers) { var asteriskToken = parseOptionalToken(37); var name = parsePropertyName(); - var questionToken = parseOptionalToken(52); + var questionToken = parseOptionalToken(53); if (asteriskToken || token === 17 || token === 25) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } @@ -8634,16 +8844,16 @@ var ts; node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); - fillSignature(53, false, false, false, node); + fillSignature(54, false, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, false); return finishNode(node); } function isClassMemberModifier(idToken) { switch (idToken) { + case 112: case 110: - case 108: - case 109: case 111: + case 113: return true; default: return false; @@ -8651,7 +8861,7 @@ var ts; } function isClassMemberStart() { var idToken; - if (token === 54) { + if (token === 55) { return true; } while (ts.isModifier(token)) { @@ -8672,15 +8882,15 @@ var ts; return true; } if (idToken !== undefined) { - if (!ts.isKeyword(idToken) || idToken === 127 || idToken === 121) { + if (!ts.isKeyword(idToken) || idToken === 129 || idToken === 123) { return true; } switch (token) { case 17: case 25: + case 54: + case 56: case 53: - case 55: - case 52: return true; default: return canParseSemicolon(); @@ -8692,14 +8902,14 @@ var ts; var decorators; while (true) { var decoratorStart = getNodePos(); - if (!parseOptional(54)) { + if (!parseOptional(55)) { break; } if (!decorators) { decorators = []; decorators.pos = scanner.getStartPos(); } - var decorator = createNode(137, decoratorStart); + var decorator = createNode(139, decoratorStart); decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); decorators.push(finishNode(decorator)); } @@ -8733,7 +8943,7 @@ var ts; function parseModifiersForArrowFunction() { var flags = 0; var modifiers; - if (token === 116) { + if (token === 118) { var modifierStart = scanner.getStartPos(); var modifierKind = token; nextToken(); @@ -8748,7 +8958,7 @@ var ts; } function parseClassElement() { if (token === 23) { - var result = createNode(189); + var result = createNode(191); nextToken(); return finishNode(result); } @@ -8759,7 +8969,7 @@ var ts; if (accessor) { return accessor; } - if (token === 119) { + if (token === 121) { return parseConstructorDeclaration(fullStart, decorators, modifiers); } if (isIndexSignature()) { @@ -8773,23 +8983,23 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators || modifiers) { - var name_8 = createMissingNode(67, true, ts.Diagnostics.Declaration_expected); + var name_8 = createMissingNode(69, true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_8, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassExpression() { - return parseClassDeclarationOrExpression(scanner.getStartPos(), undefined, undefined, 184); + return parseClassDeclarationOrExpression(scanner.getStartPos(), undefined, undefined, 186); } function parseClassDeclaration(fullStart, decorators, modifiers) { - return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 212); + return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 214); } function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) { var node = createNode(kind, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(71); - node.name = parseOptionalIdentifier(); + parseExpected(73); + node.name = parseNameOfClassDeclarationOrExpression(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(15)) { @@ -8801,6 +9011,14 @@ var ts; } return finishNode(node); } + function parseNameOfClassDeclarationOrExpression() { + return isIdentifier() && !isImplementsClause() + ? parseIdentifier() + : undefined; + } + function isImplementsClause() { + return token === 106 && lookAhead(nextTokenIsIdentifierOrKeyword); + } function parseHeritageClauses(isClassHeritageClause) { if (isHeritageClause()) { return parseList(20, parseHeritageClause); @@ -8811,8 +9029,8 @@ var ts; return parseList(20, parseHeritageClause); } function parseHeritageClause() { - if (token === 81 || token === 104) { - var node = createNode(241); + if (token === 83 || token === 106) { + var node = createNode(243); node.token = token; nextToken(); node.types = parseDelimitedList(7, parseExpressionWithTypeArguments); @@ -8821,7 +9039,7 @@ var ts; return undefined; } function parseExpressionWithTypeArguments() { - var node = createNode(186); + var node = createNode(188); node.expression = parseLeftHandSideExpressionOrHigher(); if (token === 25) { node.typeArguments = parseBracketedList(18, parseType, 25, 27); @@ -8829,16 +9047,16 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 81 || token === 104; + return token === 83 || token === 106; } function parseClassMembers() { return parseList(5, parseClassElement); } function parseInterfaceDeclaration(fullStart, decorators, modifiers) { - var node = createNode(213, fullStart); + var node = createNode(215, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(105); + parseExpected(107); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -8846,28 +9064,28 @@ var ts; return finishNode(node); } function parseTypeAliasDeclaration(fullStart, decorators, modifiers) { - var node = createNode(214, fullStart); + var node = createNode(216, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(130); + parseExpected(132); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); - parseExpected(55); + parseExpected(56); node.type = parseType(); parseSemicolon(); return finishNode(node); } function parseEnumMember() { - var node = createNode(245, scanner.getStartPos()); + var node = createNode(247, scanner.getStartPos()); node.name = parsePropertyName(); node.initializer = allowInAnd(parseNonParameterInitializer); return finishNode(node); } function parseEnumDeclaration(fullStart, decorators, modifiers) { - var node = createNode(215, fullStart); + var node = createNode(217, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(79); + parseExpected(81); node.name = parseIdentifier(); if (parseExpected(15)) { node.members = parseDelimitedList(6, parseEnumMember); @@ -8879,7 +9097,7 @@ var ts; return finishNode(node); } function parseModuleBlock() { - var node = createNode(217, scanner.getStartPos()); + var node = createNode(219, scanner.getStartPos()); if (parseExpected(15)) { node.statements = parseList(1, parseStatement); parseExpected(16); @@ -8890,7 +9108,7 @@ var ts; return finishNode(node); } function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) { - var node = createNode(216, fullStart); + var node = createNode(218, fullStart); var namespaceFlag = flags & 131072; node.decorators = decorators; setModifiers(node, modifiers); @@ -8902,7 +9120,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) { - var node = createNode(216, fullStart); + var node = createNode(218, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(true); @@ -8911,11 +9129,11 @@ var ts; } function parseModuleDeclaration(fullStart, decorators, modifiers) { var flags = modifiers ? modifiers.flags : 0; - if (parseOptional(124)) { + if (parseOptional(126)) { flags |= 131072; } else { - parseExpected(123); + parseExpected(125); if (token === 9) { return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } @@ -8923,58 +9141,58 @@ var ts; return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags); } function isExternalModuleReference() { - return token === 125 && + return token === 127 && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { return nextToken() === 17; } function nextTokenIsSlash() { - return nextToken() === 38; + return nextToken() === 39; } function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 24 || - token === 131; + token === 133; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) { - parseExpected(87); + parseExpected(89); var afterImportPos = scanner.getStartPos(); var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 24 && token !== 131) { - var importEqualsDeclaration = createNode(219, fullStart); + if (token !== 24 && token !== 133) { + var importEqualsDeclaration = createNode(221, fullStart); importEqualsDeclaration.decorators = decorators; setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; - parseExpected(55); + parseExpected(56); importEqualsDeclaration.moduleReference = parseModuleReference(); parseSemicolon(); return finishNode(importEqualsDeclaration); } } - var importDeclaration = createNode(220, fullStart); + var importDeclaration = createNode(222, fullStart); importDeclaration.decorators = decorators; setModifiers(importDeclaration, modifiers); if (identifier || token === 37 || token === 15) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(131); + parseExpected(133); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); return finishNode(importDeclaration); } function parseImportClause(identifier, fullStart) { - var importClause = createNode(221, fullStart); + var importClause = createNode(223, fullStart); if (identifier) { importClause.name = identifier; } if (!importClause.name || parseOptional(24)) { - importClause.namedBindings = token === 37 ? parseNamespaceImport() : parseNamedImportsOrExports(223); + importClause.namedBindings = token === 37 ? parseNamespaceImport() : parseNamedImportsOrExports(225); } return finishNode(importClause); } @@ -8984,8 +9202,8 @@ var ts; : parseEntityName(false); } function parseExternalModuleReference() { - var node = createNode(230); - parseExpected(125); + var node = createNode(232); + parseExpected(127); parseExpected(17); node.expression = parseModuleSpecifier(); parseExpected(18); @@ -8999,22 +9217,22 @@ var ts; return result; } function parseNamespaceImport() { - var namespaceImport = createNode(222); + var namespaceImport = createNode(224); parseExpected(37); - parseExpected(114); + parseExpected(116); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } function parseNamedImportsOrExports(kind) { var node = createNode(kind); - node.elements = parseBracketedList(21, kind === 223 ? parseImportSpecifier : parseExportSpecifier, 15, 16); + node.elements = parseBracketedList(21, kind === 225 ? parseImportSpecifier : parseExportSpecifier, 15, 16); return finishNode(node); } function parseExportSpecifier() { - return parseImportOrExportSpecifier(228); + return parseImportOrExportSpecifier(230); } function parseImportSpecifier() { - return parseImportOrExportSpecifier(224); + return parseImportOrExportSpecifier(226); } function parseImportOrExportSpecifier(kind) { var node = createNode(kind); @@ -9022,9 +9240,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 114) { + if (token === 116) { node.propertyName = identifierName; - parseExpected(114); + parseExpected(116); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -9033,23 +9251,23 @@ var ts; else { node.name = identifierName; } - if (kind === 224 && checkIdentifierIsKeyword) { + if (kind === 226 && checkIdentifierIsKeyword) { parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected); } return finishNode(node); } function parseExportDeclaration(fullStart, decorators, modifiers) { - var node = createNode(226, fullStart); + var node = createNode(228, fullStart); node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(37)) { - parseExpected(131); + parseExpected(133); node.moduleSpecifier = parseModuleSpecifier(); } else { - node.exportClause = parseNamedImportsOrExports(227); - if (token === 131 || (token === 9 && !scanner.hasPrecedingLineBreak())) { - parseExpected(131); + node.exportClause = parseNamedImportsOrExports(229); + if (token === 133 || (token === 9 && !scanner.hasPrecedingLineBreak())) { + parseExpected(133); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -9057,14 +9275,14 @@ var ts; return finishNode(node); } function parseExportAssignment(fullStart, decorators, modifiers) { - var node = createNode(225, fullStart); + var node = createNode(227, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - if (parseOptional(55)) { + if (parseOptional(56)) { node.isExportEquals = true; } else { - parseExpected(75); + parseExpected(77); } node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); @@ -9127,10 +9345,10 @@ var ts; function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 - || node.kind === 219 && node.moduleReference.kind === 230 - || node.kind === 220 - || node.kind === 225 - || node.kind === 226 + || node.kind === 221 && node.moduleReference.kind === 232 + || node.kind === 222 + || node.kind === 227 + || node.kind === 228 ? node : undefined; }); @@ -9140,15 +9358,15 @@ var ts; function isJSDocType() { switch (token) { case 37: - case 52: + case 53: case 17: case 19: - case 48: + case 49: case 15: - case 85: + case 87: case 22: - case 90: - case 95: + case 92: + case 97: return true; } return ts.tokenIsIdentifierOrKeyword(token); @@ -9165,7 +9383,7 @@ var ts; function parseJSDocTypeExpression(start, length) { scanner.setText(sourceText, start, length); token = nextToken(); - var result = createNode(247); + var result = createNode(249); parseExpected(15); result.type = parseJSDocTopLevelType(); parseExpected(16); @@ -9175,13 +9393,13 @@ var ts; JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; function parseJSDocTopLevelType() { var type = parseJSDocType(); - if (token === 46) { - var unionType = createNode(251, type.pos); + if (token === 47) { + var unionType = createNode(253, type.pos); unionType.types = parseJSDocTypeList(type); type = finishNode(unionType); } - if (token === 55) { - var optionalType = createNode(258, type.pos); + if (token === 56) { + var optionalType = createNode(260, type.pos); nextToken(); optionalType.type = type; type = finishNode(optionalType); @@ -9192,20 +9410,20 @@ var ts; var type = parseBasicTypeExpression(); while (true) { if (token === 19) { - var arrayType = createNode(250, type.pos); + var arrayType = createNode(252, type.pos); arrayType.elementType = type; nextToken(); parseExpected(20); type = finishNode(arrayType); } - else if (token === 52) { - var nullableType = createNode(253, type.pos); + else if (token === 53) { + var nullableType = createNode(255, type.pos); nullableType.type = type; nextToken(); type = finishNode(nullableType); } - else if (token === 48) { - var nonNullableType = createNode(254, type.pos); + else if (token === 49) { + var nonNullableType = createNode(256, type.pos); nonNullableType.type = type; nextToken(); type = finishNode(nonNullableType); @@ -9220,80 +9438,80 @@ var ts; switch (token) { case 37: return parseJSDocAllType(); - case 52: + case 53: return parseJSDocUnknownOrNullableType(); case 17: return parseJSDocUnionType(); case 19: return parseJSDocTupleType(); - case 48: + case 49: return parseJSDocNonNullableType(); case 15: return parseJSDocRecordType(); - case 85: + case 87: return parseJSDocFunctionType(); case 22: return parseJSDocVariadicType(); - case 90: + case 92: return parseJSDocConstructorType(); - case 95: + case 97: return parseJSDocThisType(); - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: - case 101: + case 120: + case 131: + case 103: return parseTokenNode(); } return parseJSDocTypeReference(); } function parseJSDocThisType() { - var result = createNode(262); + var result = createNode(264); nextToken(); - parseExpected(53); + parseExpected(54); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocConstructorType() { - var result = createNode(261); + var result = createNode(263); nextToken(); - parseExpected(53); + parseExpected(54); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocVariadicType() { - var result = createNode(260); + var result = createNode(262); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocFunctionType() { - var result = createNode(259); + var result = createNode(261); nextToken(); parseExpected(17); result.parameters = parseDelimitedList(22, parseJSDocParameter); checkForTrailingComma(result.parameters); parseExpected(18); - if (token === 53) { + if (token === 54) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocParameter() { - var parameter = createNode(136); + var parameter = createNode(138); parameter.type = parseJSDocType(); return finishNode(parameter); } function parseJSDocOptionalType(type) { - var result = createNode(258, type.pos); + var result = createNode(260, type.pos); nextToken(); result.type = type; return finishNode(result); } function parseJSDocTypeReference() { - var result = createNode(257); + var result = createNode(259); result.name = parseSimplePropertyName(); while (parseOptional(21)) { if (token === 25) { @@ -9322,13 +9540,13 @@ var ts; } } function parseQualifiedName(left) { - var result = createNode(133, left.pos); + var result = createNode(135, left.pos); result.left = left; result.right = parseIdentifierName(); return finishNode(result); } function parseJSDocRecordType() { - var result = createNode(255); + var result = createNode(257); nextToken(); result.members = parseDelimitedList(24, parseJSDocRecordMember); checkForTrailingComma(result.members); @@ -9336,22 +9554,22 @@ var ts; return finishNode(result); } function parseJSDocRecordMember() { - var result = createNode(256); + var result = createNode(258); result.name = parseSimplePropertyName(); - if (token === 53) { + if (token === 54) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocNonNullableType() { - var result = createNode(254); + var result = createNode(256); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocTupleType() { - var result = createNode(252); + var result = createNode(254); nextToken(); result.types = parseDelimitedList(25, parseJSDocType); checkForTrailingComma(result.types); @@ -9365,7 +9583,7 @@ var ts; } } function parseJSDocUnionType() { - var result = createNode(251); + var result = createNode(253); nextToken(); result.types = parseJSDocTypeList(parseJSDocType()); parseExpected(18); @@ -9376,14 +9594,14 @@ var ts; var types = []; types.pos = firstType.pos; types.push(firstType); - while (parseOptional(46)) { + while (parseOptional(47)) { types.push(parseJSDocType()); } types.end = scanner.getStartPos(); return types; } function parseJSDocAllType() { - var result = createNode(248); + var result = createNode(250); nextToken(); return finishNode(result); } @@ -9394,13 +9612,13 @@ var ts; token === 16 || token === 18 || token === 27 || - token === 55 || - token === 46) { - var result = createNode(249, pos); + token === 56 || + token === 47) { + var result = createNode(251, pos); return finishNode(result); } else { - var result = createNode(253, pos); + var result = createNode(255, pos); result.type = parseJSDocType(); return finishNode(result); } @@ -9471,7 +9689,7 @@ var ts; if (!tags) { return undefined; } - var result = createNode(263, start); + var result = createNode(265, start); result.tags = tags; return finishNode(result, end); } @@ -9482,7 +9700,7 @@ var ts; } function parseTag() { ts.Debug.assert(content.charCodeAt(pos - 1) === 64); - var atToken = createNode(54, pos - 1); + var atToken = createNode(55, pos - 1); atToken.end = pos; var tagName = scanIdentifier(); if (!tagName) { @@ -9508,7 +9726,7 @@ var ts; return undefined; } function handleUnknownTag(atToken, tagName) { - var result = createNode(264, atToken.pos); + var result = createNode(266, atToken.pos); result.atToken = atToken; result.tagName = tagName; return finishNode(result, pos); @@ -9559,7 +9777,7 @@ var ts; if (!typeExpression) { typeExpression = tryParseTypeExpression(); } - var result = createNode(265, atToken.pos); + var result = createNode(267, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.preParameterName = preName; @@ -9569,27 +9787,27 @@ var ts; return finishNode(result, pos); } function handleReturnTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 266; })) { + if (ts.forEach(tags, function (t) { return t.kind === 268; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(266, atToken.pos); + var result = createNode(268, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTypeTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 267; })) { + if (ts.forEach(tags, function (t) { return t.kind === 269; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(267, atToken.pos); + var result = createNode(269, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTemplateTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 268; })) { + if (ts.forEach(tags, function (t) { return t.kind === 270; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } var typeParameters = []; @@ -9602,7 +9820,7 @@ var ts; parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(135, name_9.pos); + var typeParameter = createNode(137, name_9.pos); typeParameter.name = name_9; finishNode(typeParameter, pos); typeParameters.push(typeParameter); @@ -9613,7 +9831,7 @@ var ts; pos++; } typeParameters.end = pos; - var result = createNode(268, atToken.pos); + var result = createNode(270, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeParameters = typeParameters; @@ -9634,7 +9852,7 @@ var ts; if (startPos === pos) { return undefined; } - var result = createNode(67, startPos); + var result = createNode(69, startPos); result.text = content.substring(startPos, pos); return finishNode(result, pos); } @@ -9710,7 +9928,7 @@ var ts; switch (node.kind) { case 9: case 8: - case 67: + case 69: return true; } return false; @@ -9928,16 +10146,16 @@ var ts; (function (ts) { ts.bindTime = 0; function getModuleInstanceState(node) { - if (node.kind === 213 || node.kind === 214) { + if (node.kind === 215 || node.kind === 216) { return 0; } else if (ts.isConstEnumDeclaration(node)) { return 2; } - else if ((node.kind === 220 || node.kind === 219) && !(node.flags & 1)) { + else if ((node.kind === 222 || node.kind === 221) && !(node.flags & 1)) { return 0; } - else if (node.kind === 217) { + else if (node.kind === 219) { var state = 0; ts.forEachChild(node, function (n) { switch (getModuleInstanceState(n)) { @@ -9953,7 +10171,7 @@ var ts; }); return state; } - else if (node.kind === 216) { + else if (node.kind === 218) { return getModuleInstanceState(node.body); } else { @@ -9972,6 +10190,7 @@ var ts; var container; var blockScopeContainer; var lastContainer; + var seenThisKeyword; var inStrictMode = !!file.externalModuleIndicator; var symbolCount = 0; var Symbol = ts.objectAllocator.getSymbolConstructor(); @@ -10005,10 +10224,10 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 216 && node.name.kind === 9) { + if (node.kind === 218 && node.name.kind === 9) { return "\"" + node.name.text + "\""; } - if (node.name.kind === 134) { + if (node.name.kind === 136) { var nameExpression = node.name.expression; ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression)); return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text); @@ -10016,22 +10235,22 @@ var ts; return node.name.text; } switch (node.kind) { - case 142: + case 144: return "__constructor"; - case 150: - case 145: - return "__call"; - case 151: - case 146: - return "__new"; + case 152: case 147: + return "__call"; + case 153: + case 148: + return "__new"; + case 149: return "__index"; - case 226: + case 228: return "__export"; - case 225: + case 227: return node.isExportEquals ? "export=" : "default"; - case 211: - case 212: + case 213: + case 214: return node.flags & 1024 ? "default" : undefined; } } @@ -10040,7 +10259,8 @@ var ts; } function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); - var name = node.flags & 1024 && parent ? "default" : getDeclarationName(node); + var isDefaultExport = node.flags & 1024; + var name = isDefaultExport && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { symbol = ts.hasProperty(symbolTable, name) @@ -10056,6 +10276,11 @@ var ts; var message = symbol.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + ts.forEach(symbol.declarations, function (declaration) { + if (declaration.flags & 1024) { + message = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + } + }); ts.forEach(symbol.declarations, function (declaration) { file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); @@ -10073,7 +10298,7 @@ var ts; function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1; if (symbolFlags & 8388608) { - if (node.kind === 228 || (node.kind === 219 && hasExportModifier)) { + if (node.kind === 230 || (node.kind === 221 && hasExportModifier)) { return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { @@ -10112,44 +10337,51 @@ var ts; blockScopeContainer = node; blockScopeContainer.locals = undefined; } - ts.forEachChild(node, bind); + if (node.kind === 215) { + seenThisKeyword = false; + ts.forEachChild(node, bind); + node.flags = seenThisKeyword ? node.flags | 524288 : node.flags & ~524288; + } + else { + ts.forEachChild(node, bind); + } container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } function getContainerFlags(node) { switch (node.kind) { - case 184: - case 212: - case 213: + case 186: + case 214: case 215: - case 153: - case 163: + case 217: + case 155: + case 165: return 1; + case 147: + case 148: + case 149: + case 143: + case 142: + case 213: + case 144: case 145: case 146: - case 147: - case 141: - case 140: - case 211: - case 142: - case 143: - case 144: - case 150: - case 151: - case 171: - case 172: - case 216: - case 246: - case 214: - return 5; - case 242: - case 197: - case 198: - case 199: + case 152: + case 153: + case 173: + case 174: case 218: + case 248: + case 216: + return 5; + case 244: + case 199: + case 200: + case 201: + case 220: return 2; - case 190: + case 192: return ts.isFunctionLike(node.parent) ? 0 : 2; } return 0; @@ -10165,33 +10397,33 @@ var ts; } function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) { switch (container.kind) { - case 216: + case 218: return declareModuleMember(node, symbolFlags, symbolExcludes); - case 246: + case 248: return declareSourceFileMember(node, symbolFlags, symbolExcludes); - case 184: - case 212: + case 186: + case 214: return declareClassMember(node, symbolFlags, symbolExcludes); - case 215: + case 217: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); - case 153: - case 163: - case 213: + case 155: + case 165: + case 215: return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); - case 150: - case 151: + case 152: + case 153: + case 147: + case 148: + case 149: + case 143: + case 142: + case 144: case 145: case 146: - case 147: - case 141: - case 140: - case 142: - case 143: - case 144: - case 211: - case 171: - case 172: - case 214: + case 213: + case 173: + case 174: + case 216: return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } @@ -10215,11 +10447,11 @@ var ts; return false; } function hasExportDeclarations(node) { - var body = node.kind === 246 ? node : node.body; - if (body.kind === 246 || body.kind === 217) { + var body = node.kind === 248 ? node : node.body; + if (body.kind === 248 || body.kind === 219) { for (var _i = 0, _a = body.statements; _i < _a.length; _i++) { var stat = _a[_i]; - if (stat.kind === 226 || stat.kind === 225) { + if (stat.kind === 228 || stat.kind === 227) { return true; } } @@ -10274,11 +10506,11 @@ var ts; var seen = {}; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - if (prop.name.kind !== 67) { + if (prop.name.kind !== 69) { continue; } var identifier = prop.name; - var currentKind = prop.kind === 243 || prop.kind === 244 || prop.kind === 141 + var currentKind = prop.kind === 245 || prop.kind === 246 || prop.kind === 143 ? 1 : 2; var existingKind = seen[identifier.text]; @@ -10300,10 +10532,10 @@ var ts; } function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { - case 216: + case 218: declareModuleMember(node, symbolFlags, symbolExcludes); break; - case 246: + case 248: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolFlags, symbolExcludes); break; @@ -10321,8 +10553,8 @@ var ts; } function checkStrictModeIdentifier(node) { if (inStrictMode && - node.originalKeywordKind >= 104 && - node.originalKeywordKind <= 112 && + node.originalKeywordKind >= 106 && + node.originalKeywordKind <= 114 && !ts.isIdentifierName(node)) { if (!file.parseDiagnostics.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); @@ -10349,17 +10581,17 @@ var ts; } } function checkStrictModeDeleteExpression(node) { - if (inStrictMode && node.expression.kind === 67) { + if (inStrictMode && node.expression.kind === 69) { var span = ts.getErrorSpanForNode(file, node.expression); file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode)); } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 && + return node.kind === 69 && (node.text === "eval" || node.text === "arguments"); } function checkStrictModeEvalOrArguments(contextNode, name) { - if (name && name.kind === 67) { + if (name && name.kind === 69) { var identifier = name; if (isEvalOrArgumentsIdentifier(identifier)) { var span = ts.getErrorSpanForNode(file, name); @@ -10393,7 +10625,7 @@ var ts; } function checkStrictModePrefixUnaryExpression(node) { if (inStrictMode) { - if (node.operator === 40 || node.operator === 41) { + if (node.operator === 41 || node.operator === 42) { checkStrictModeEvalOrArguments(node, node.operand); } } @@ -10422,17 +10654,17 @@ var ts; } function updateStrictMode(node) { switch (node.kind) { - case 246: - case 217: + case 248: + case 219: updateStrictModeStatementList(node.statements); return; - case 190: + case 192: if (ts.isFunctionLike(node.parent)) { updateStrictModeStatementList(node.statements); } return; - case 212: - case 184: + case 214: + case 186: inStrictMode = true; return; } @@ -10455,88 +10687,91 @@ var ts; } function bindWorker(node) { switch (node.kind) { - case 67: + case 69: return checkStrictModeIdentifier(node); - case 179: + case 181: return checkStrictModeBinaryExpression(node); - case 242: + case 244: return checkStrictModeCatchClause(node); - case 173: + case 175: return checkStrictModeDeleteExpression(node); case 8: return checkStrictModeNumericLiteral(node); - case 178: + case 180: return checkStrictModePostfixUnaryExpression(node); - case 177: + case 179: return checkStrictModePrefixUnaryExpression(node); - case 203: + case 205: return checkStrictModeWithStatement(node); - case 135: + case 97: + seenThisKeyword = true; + return; + case 137: return declareSymbolAndAddToSymbolTable(node, 262144, 530912); - case 136: - return bindParameter(node); - case 209: - case 161: - return bindVariableDeclarationOrBindingElement(node); - case 139: case 138: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); - case 243: - case 244: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); - case 245: - return bindPropertyOrMethodOrAccessor(node, 8, 107455); - case 145: - case 146: - case 147: - return declareSymbolAndAddToSymbolTable(node, 131072, 0); + return bindParameter(node); + case 211: + case 163: + return bindVariableDeclarationOrBindingElement(node); case 141: case 140: + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + case 245: + case 246: + return bindPropertyOrMethodOrAccessor(node, 4, 107455); + case 247: + return bindPropertyOrMethodOrAccessor(node, 8, 107455); + case 147: + case 148: + case 149: + return declareSymbolAndAddToSymbolTable(node, 131072, 0); + case 143: + case 142: return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); - case 211: + case 213: checkStrictModeFunctionName(node); return declareSymbolAndAddToSymbolTable(node, 16, 106927); - case 142: - return declareSymbolAndAddToSymbolTable(node, 16384, 0); - case 143: - return bindPropertyOrMethodOrAccessor(node, 32768, 41919); case 144: + return declareSymbolAndAddToSymbolTable(node, 16384, 0); + case 145: + return bindPropertyOrMethodOrAccessor(node, 32768, 41919); + case 146: return bindPropertyOrMethodOrAccessor(node, 65536, 74687); - case 150: - case 151: - return bindFunctionOrConstructorType(node); + case 152: case 153: + return bindFunctionOrConstructorType(node); + case 155: return bindAnonymousDeclaration(node, 2048, "__type"); - case 163: + case 165: return bindObjectLiteralExpression(node); - case 171: - case 172: + case 173: + case 174: checkStrictModeFunctionName(node); var bindingName = node.name ? node.name.text : "__function"; return bindAnonymousDeclaration(node, 16, bindingName); - case 184: - case 212: - return bindClassLikeDeclaration(node); - case 213: - return bindBlockScopedDeclaration(node, 64, 792960); + case 186: case 214: - return bindBlockScopedDeclaration(node, 524288, 793056); + return bindClassLikeDeclaration(node); case 215: - return bindEnumDeclaration(node); + return bindBlockScopedDeclaration(node, 64, 792960); case 216: + return bindBlockScopedDeclaration(node, 524288, 793056); + case 217: + return bindEnumDeclaration(node); + case 218: return bindModuleDeclaration(node); - case 219: - case 222: - case 224: - case 228: - return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 221: - return bindImportClause(node); + case 224: case 226: + case 230: + return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); + case 223: + return bindImportClause(node); + case 228: return bindExportDeclaration(node); - case 225: + case 227: return bindExportAssignment(node); - case 246: + case 248: return bindSourceFileIfExternalModule(); } } @@ -10550,7 +10785,7 @@ var ts; if (!container.symbol || !container.symbol.exports) { bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } - else if (node.expression.kind === 67) { + else if (node.expression.kind === 69) { declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); } else { @@ -10571,7 +10806,7 @@ var ts; } } function bindClassLikeDeclaration(node) { - if (node.kind === 212) { + if (node.kind === 214) { bindBlockScopedDeclaration(node, 32, 899519); } else { @@ -10624,7 +10859,7 @@ var ts; declareSymbolAndAddToSymbolTable(node, 1, 107455); } if (node.flags & 112 && - node.parent.kind === 142 && + node.parent.kind === 144 && ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); @@ -10662,17 +10897,19 @@ var ts; var Type = ts.objectAllocator.getTypeConstructor(); var Signature = ts.objectAllocator.getSignatureConstructor(); var typeCount = 0; + var symbolCount = 0; var emptyArray = []; var emptySymbols = {}; var compilerOptions = host.getCompilerOptions(); var languageVersion = compilerOptions.target || 0; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 ? 5 : 0; var emitResolver = createResolver(); var undefinedSymbol = createSymbol(4 | 67108864, "undefined"); var argumentsSymbol = createSymbol(4 | 67108864, "arguments"); var checker = { getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); }, - getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); }, + getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount") + symbolCount; }, getTypeCount: function () { return typeCount; }, isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; }, @@ -10818,6 +11055,7 @@ var ts; diagnostics.add(diagnostic); } function createSymbol(flags, name) { + symbolCount++; return new Symbol(flags, name); } function getExcludedSymbolFlags(flags) { @@ -10946,10 +11184,10 @@ var ts; return nodeLinks[nodeId] || (nodeLinks[nodeId] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 246); + return ts.getAncestor(node, 248); } function isGlobalSourceFile(node) { - return node.kind === 246 && !ts.isExternalModule(node); + return node.kind === 248 && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -10966,17 +11204,54 @@ var ts; } } } - function isDefinedBefore(node1, node2) { - var file1 = ts.getSourceFileOfNode(node1); - var file2 = ts.getSourceFileOfNode(node2); - if (file1 === file2) { - return node1.pos <= node2.pos; + function isBlockScopedNameDeclaredBeforeUse(declaration, usage) { + var declarationFile = ts.getSourceFileOfNode(declaration); + var useFile = ts.getSourceFileOfNode(usage); + if (declarationFile !== useFile) { + if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) { + return true; + } + var sourceFiles = host.getSourceFiles(); + return ts.indexOf(sourceFiles, declarationFile) <= ts.indexOf(sourceFiles, useFile); } - if (!compilerOptions.outFile && !compilerOptions.out) { - return true; + if (declaration.pos <= usage.pos) { + return declaration.kind !== 211 || + !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage); + } + return isUsedInFunctionOrNonStaticProperty(declaration, usage); + function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + if (declaration.parent.parent.kind === 193 || + declaration.parent.parent.kind === 199) { + return isSameScopeDescendentOf(usage, declaration, container); + } + else if (declaration.parent.parent.kind === 201 || + declaration.parent.parent.kind === 200) { + var expression = declaration.parent.parent.expression; + return isSameScopeDescendentOf(usage, expression, container); + } + } + function isUsedInFunctionOrNonStaticProperty(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + var current = usage; + while (current) { + if (current === container) { + return false; + } + if (ts.isFunctionLike(current)) { + return true; + } + var initializerOfNonStaticProperty = current.parent && + current.parent.kind === 141 && + (current.parent.flags & 128) === 0 && + current.parent.initializer === current; + if (initializerOfNonStaticProperty) { + return true; + } + current = current.parent; + } + return false; } - var sourceFiles = host.getSourceFiles(); - return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2); } function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) { var result; @@ -10997,16 +11272,16 @@ var ts; } } switch (location.kind) { - case 246: + case 248: if (!ts.isExternalModule(location)) break; - case 216: + case 218: var moduleExports = getSymbolOfNode(location).exports; - if (location.kind === 246 || - (location.kind === 216 && location.name.kind === 9)) { + if (location.kind === 248 || + (location.kind === 218 && location.name.kind === 9)) { if (ts.hasProperty(moduleExports, name) && moduleExports[name].flags === 8388608 && - ts.getDeclarationOfKind(moduleExports[name], 228)) { + ts.getDeclarationOfKind(moduleExports[name], 230)) { break; } result = moduleExports["default"]; @@ -11020,13 +11295,13 @@ var ts; break loop; } break; - case 215: + case 217: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) { break loop; } break; - case 139: - case 138: + case 141: + case 140: if (ts.isClassLike(location.parent) && !(location.flags & 128)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { @@ -11036,9 +11311,9 @@ var ts; } } break; - case 212: - case 184: - case 213: + case 214: + case 186: + case 215: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) { if (lastLocation && lastLocation.flags & 128) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -11046,7 +11321,7 @@ var ts; } break loop; } - if (location.kind === 184 && meaning & 32) { + if (location.kind === 186 && meaning & 32) { var className = location.name; if (className && name === className.text) { result = location.symbol; @@ -11054,28 +11329,28 @@ var ts; } } break; - case 134: + case 136: grandparent = location.parent.parent; - if (ts.isClassLike(grandparent) || grandparent.kind === 213) { + if (ts.isClassLike(grandparent) || grandparent.kind === 215) { if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; - case 141: - case 140: - case 142: case 143: + case 142: case 144: - case 211: - case 172: + case 145: + case 146: + case 213: + case 174: if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } break; - case 171: + case 173: if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; @@ -11088,8 +11363,8 @@ var ts; } } break; - case 137: - if (location.parent && location.parent.kind === 136) { + case 139: + if (location.parent && location.parent.kind === 138) { location = location.parent; } if (location.parent && ts.isClassElement(location.parent)) { @@ -11115,8 +11390,11 @@ var ts; error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg)); return undefined; } - if (meaning & 2 && result.flags & 2) { - checkResolvedBlockScopedVariable(result, errorLocation); + if (meaning & 2) { + var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result); + if (exportOrLocalSymbol.flags & 2) { + checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); + } } } return result; @@ -11125,21 +11403,7 @@ var ts; ts.Debug.assert((result.flags & 2) !== 0); var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); - var isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation); - if (!isUsedBeforeDeclaration) { - var variableDeclaration = ts.getAncestor(declaration, 209); - var container = ts.getEnclosingBlockScopeContainer(variableDeclaration); - if (variableDeclaration.parent.parent.kind === 191 || - variableDeclaration.parent.parent.kind === 197) { - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container); - } - else if (variableDeclaration.parent.parent.kind === 199 || - variableDeclaration.parent.parent.kind === 198) { - var expression = variableDeclaration.parent.parent.expression; - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container); - } - } - if (isUsedBeforeDeclaration) { + if (!isBlockScopedNameDeclaredBeforeUse(ts.getAncestor(declaration, 211), errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); } } @@ -11156,10 +11420,10 @@ var ts; } function getAnyImportSyntax(node) { if (ts.isAliasSymbolDeclaration(node)) { - if (node.kind === 219) { + if (node.kind === 221) { return node; } - while (node && node.kind !== 220) { + while (node && node.kind !== 222) { node = node.parent; } return node; @@ -11169,7 +11433,7 @@ var ts; return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { - if (node.moduleReference.kind === 230) { + if (node.moduleReference.kind === 232) { return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node))); } return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); @@ -11258,17 +11522,17 @@ var ts; } function getTargetOfAliasDeclaration(node) { switch (node.kind) { - case 219: - return getTargetOfImportEqualsDeclaration(node); case 221: + return getTargetOfImportEqualsDeclaration(node); + case 223: return getTargetOfImportClause(node); - case 222: - return getTargetOfNamespaceImport(node); case 224: + return getTargetOfNamespaceImport(node); + case 226: return getTargetOfImportSpecifier(node); - case 228: + case 230: return getTargetOfExportSpecifier(node); - case 225: + case 227: return getTargetOfExportAssignment(node); } } @@ -11310,10 +11574,10 @@ var ts; if (!links.referenced) { links.referenced = true; var node = getDeclarationOfAliasSymbol(symbol); - if (node.kind === 225) { + if (node.kind === 227) { checkExpressionCached(node.expression); } - else if (node.kind === 228) { + else if (node.kind === 230) { checkExpressionCached(node.propertyName || node.name); } else if (ts.isInternalModuleImportEqualsDeclaration(node)) { @@ -11323,17 +11587,17 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 219); + importDeclaration = ts.getAncestor(entityName, 221); ts.Debug.assert(importDeclaration !== undefined); } - if (entityName.kind === 67 && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { + if (entityName.kind === 69 && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { entityName = entityName.parent; } - if (entityName.kind === 67 || entityName.parent.kind === 133) { + if (entityName.kind === 69 || entityName.parent.kind === 135) { return resolveEntityName(entityName, 1536); } else { - ts.Debug.assert(entityName.parent.kind === 219); + ts.Debug.assert(entityName.parent.kind === 221); return resolveEntityName(entityName, 107455 | 793056 | 1536); } } @@ -11345,16 +11609,16 @@ var ts; return undefined; } var symbol; - if (name.kind === 67) { + if (name.kind === 69) { var message = meaning === 1536 ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0; symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } } - else if (name.kind === 133 || name.kind === 164) { - var left = name.kind === 133 ? name.left : name.expression; - var right = name.kind === 133 ? name.right : name.name; + else if (name.kind === 135 || name.kind === 166) { + var left = name.kind === 135 ? name.left : name.expression; + var right = name.kind === 135 ? name.right : name.name; var namespace = resolveEntityName(left, 1536, ignoreErrors); if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { return undefined; @@ -11373,9 +11637,6 @@ var ts; ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here."); return symbol.flags & meaning ? symbol : resolveAlias(symbol); } - function isExternalModuleNameRelative(moduleName) { - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; - } function resolveExternalModuleName(location, moduleReferenceExpression) { if (moduleReferenceExpression.kind !== 9) { return; @@ -11386,7 +11647,7 @@ var ts; if (moduleName === undefined) { return; } - var isRelative = isExternalModuleNameRelative(moduleName); + var isRelative = ts.isExternalModuleNameRelative(moduleName); if (!isRelative) { var symbol = getSymbol(globals, "\"" + moduleName + "\"", 512); if (symbol) { @@ -11490,7 +11751,7 @@ var ts; var members = node.members; for (var _i = 0; _i < members.length; _i++) { var member = members[_i]; - if (member.kind === 142 && ts.nodeIsPresent(member.body)) { + if (member.kind === 144 && ts.nodeIsPresent(member.body)) { return member; } } @@ -11555,17 +11816,17 @@ var ts; } } switch (location_1.kind) { - case 246: + case 248: if (!ts.isExternalModule(location_1)) { break; } - case 216: + case 218: if (result = callback(getSymbolOfNode(location_1).exports)) { return result; } break; - case 212: - case 213: + case 214: + case 215: if (result = callback(getSymbolOfNode(location_1).members)) { return result; } @@ -11598,7 +11859,7 @@ var ts; return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 8388608 && symbolFromSymbolTable.name !== "export=" - && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228)) { + && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230)) { if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); @@ -11627,7 +11888,7 @@ var ts; if (symbolFromSymbolTable === symbol) { return true; } - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -11682,8 +11943,8 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 216 && declaration.name.kind === 9) || - (declaration.kind === 246 && ts.isExternalModule(declaration)); + return (declaration.kind === 218 && declaration.name.kind === 9) || + (declaration.kind === 248 && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -11715,11 +11976,11 @@ var ts; } function isEntityNameVisible(entityName, enclosingDeclaration) { var meaning; - if (entityName.parent.kind === 152) { + if (entityName.parent.kind === 154) { meaning = 107455 | 1048576; } - else if (entityName.kind === 133 || entityName.kind === 164 || - entityName.parent.kind === 219) { + else if (entityName.kind === 135 || entityName.kind === 166 || + entityName.parent.kind === 221) { meaning = 1536; } else { @@ -11770,10 +12031,10 @@ var ts; function getTypeAliasForTypeLiteral(type) { if (type.symbol && type.symbol.flags & 2048) { var node = type.symbol.declarations[0].parent; - while (node.kind === 158) { + while (node.kind === 160) { node = node.parent; } - if (node.kind === 214) { + if (node.kind === 216) { return getSymbolOfNode(node); } } @@ -11787,10 +12048,10 @@ var ts; return ts.declarationNameToString(declaration.name); } switch (declaration.kind) { - case 184: + case 186: return "(Anonymous class)"; - case 171: - case 172: + case 173: + case 174: return "(Anonymous function)"; } } @@ -11851,6 +12112,7 @@ var ts; } function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16; + var inObjectTypeLiteral = false; return writeType(type, globalFlags); function writeType(type, flags) { if (type.flags & 16777343) { @@ -11858,6 +12120,12 @@ var ts; ? "any" : type.intrinsicName); } + else if (type.flags & 33554432) { + if (inObjectTypeLiteral) { + writer.reportInaccessibleThisError(); + } + writer.writeKeyword("this"); + } else if (type.flags & 4096) { writeTypeReference(type, flags); } @@ -11896,9 +12164,9 @@ var ts; writeType(types[i], delimiter === 24 ? 0 : 64); } } - function writeSymbolTypeReference(symbol, typeArguments, pos, end) { - if (!isReservedMemberName(symbol.name)) { - buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056); + function writeSymbolTypeReference(symbol, typeArguments, pos, end, flags) { + if (symbol.flags & 32 || !isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056, 0, flags); } if (pos < end) { writePunctuation(writer, 25); @@ -11912,7 +12180,7 @@ var ts; } } function writeTypeReference(type, flags) { - var typeArguments = type.typeArguments; + var typeArguments = type.typeArguments || emptyArray; if (type.target === globalArrayType && !(flags & 1)) { writeType(typeArguments[0], 64); writePunctuation(writer, 19); @@ -11930,12 +12198,13 @@ var ts; i++; } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3); if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { - writeSymbolTypeReference(parent_3, typeArguments, start, i); + writeSymbolTypeReference(parent_3, typeArguments, start, i, flags); writePunctuation(writer, 21); } } } - writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); + var typeParameterCount = (type.target.typeParameters || emptyArray).length; + writeSymbolTypeReference(type.symbol, typeArguments, i, typeParameterCount, flags); } } function writeTupleType(type) { @@ -11947,7 +12216,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 17); } - writeTypeList(type.types, type.flags & 16384 ? 46 : 45); + writeTypeList(type.types, type.flags & 16384 ? 47 : 46); if (flags & 64) { writePunctuation(writer, 18); } @@ -11967,7 +12236,7 @@ var ts; buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); } else { - writeKeyword(writer, 115); + writeKeyword(writer, 117); } } else { @@ -11988,7 +12257,7 @@ var ts; var isNonLocalFunctionSymbol = !!(symbol.flags & 16) && (symbol.parent || ts.forEach(symbol.declarations, function (declaration) { - return declaration.parent.kind === 246 || declaration.parent.kind === 217; + return declaration.parent.kind === 248 || declaration.parent.kind === 219; })); if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { return !!(flags & 2) || @@ -11997,7 +12266,7 @@ var ts; } } function writeTypeofSymbol(type, typeFormatFlags) { - writeKeyword(writer, 99); + writeKeyword(writer, 101); writeSpace(writer); buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455, 0, typeFormatFlags); } @@ -12031,7 +12300,7 @@ var ts; if (flags & 64) { writePunctuation(writer, 17); } - writeKeyword(writer, 90); + writeKeyword(writer, 92); writeSpace(writer); buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8, symbolStack); if (flags & 64) { @@ -12040,6 +12309,8 @@ var ts; return; } } + var saveInObjectTypeLiteral = inObjectTypeLiteral; + inObjectTypeLiteral = true; writePunctuation(writer, 15); writer.writeLine(); writer.increaseIndent(); @@ -12051,7 +12322,7 @@ var ts; } for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) { var signature = _c[_b]; - writeKeyword(writer, 90); + writeKeyword(writer, 92); writeSpace(writer); buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23); @@ -12060,11 +12331,11 @@ var ts; if (resolved.stringIndexType) { writePunctuation(writer, 19); writer.writeParameter(getIndexerParameterName(resolved, 0, "x")); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); - writeKeyword(writer, 128); + writeKeyword(writer, 130); writePunctuation(writer, 20); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); writeType(resolved.stringIndexType, 0); writePunctuation(writer, 23); @@ -12073,11 +12344,11 @@ var ts; if (resolved.numberIndexType) { writePunctuation(writer, 19); writer.writeParameter(getIndexerParameterName(resolved, 1, "x")); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); - writeKeyword(writer, 126); + writeKeyword(writer, 128); writePunctuation(writer, 20); - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); writeType(resolved.numberIndexType, 0); writePunctuation(writer, 23); @@ -12092,7 +12363,7 @@ var ts; var signature = signatures[_f]; buildSymbolDisplay(p, writer); if (p.flags & 536870912) { - writePunctuation(writer, 52); + writePunctuation(writer, 53); } buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23); @@ -12102,9 +12373,9 @@ var ts; else { buildSymbolDisplay(p, writer); if (p.flags & 536870912) { - writePunctuation(writer, 52); + writePunctuation(writer, 53); } - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); writeType(t, 0); writePunctuation(writer, 23); @@ -12113,6 +12384,7 @@ var ts; } writer.decreaseIndent(); writePunctuation(writer, 16); + inObjectTypeLiteral = saveInObjectTypeLiteral; } } function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { @@ -12126,7 +12398,7 @@ var ts; var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); - writeKeyword(writer, 81); + writeKeyword(writer, 83); writeSpace(writer); buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } @@ -12138,9 +12410,9 @@ var ts; } appendSymbolNameOnly(p, writer); if (isOptionalParameter(parameterNode)) { - writePunctuation(writer, 52); + writePunctuation(writer, 53); } - writePunctuation(writer, 53); + writePunctuation(writer, 54); writeSpace(writer); buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } @@ -12187,14 +12459,14 @@ var ts; writePunctuation(writer, 34); } else { - writePunctuation(writer, 53); + writePunctuation(writer, 54); } writeSpace(writer); var returnType; if (signature.typePredicate) { writer.writeParameter(signature.typePredicate.parameterName); writeSpace(writer); - writeKeyword(writer, 122); + writeKeyword(writer, 124); writeSpace(writer); returnType = signature.typePredicate.type; } @@ -12228,12 +12500,12 @@ var ts; function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 216) { + if (node.kind === 218) { if (node.name.kind === 9) { return node; } } - else if (node.kind === 246) { + else if (node.kind === 248) { return ts.isExternalModule(node) ? node : undefined; } } @@ -12276,59 +12548,59 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 161: + case 163: return isDeclarationVisible(node.parent.parent); - case 209: + case 211: if (ts.isBindingPattern(node.name) && !node.name.elements.length) { return false; } - case 216: - case 212: - case 213: + case 218: case 214: - case 211: case 215: - case 219: + case 216: + case 213: + case 217: + case 221: var parent_4 = getDeclarationContainer(node); if (!(ts.getCombinedNodeFlags(node) & 1) && - !(node.kind !== 219 && parent_4.kind !== 246 && ts.isInAmbientContext(parent_4))) { + !(node.kind !== 221 && parent_4.kind !== 248 && ts.isInAmbientContext(parent_4))) { return isGlobalSourceFile(parent_4); } return isDeclarationVisible(parent_4); - case 139: - case 138: - case 143: - case 144: case 141: case 140: + case 145: + case 146: + case 143: + case 142: if (node.flags & (32 | 64)) { return false; } - case 142: - case 146: - case 145: + case 144: + case 148: case 147: - case 136: - case 217: - case 150: - case 151: - case 153: case 149: - case 154: + case 138: + case 219: + case 152: + case 153: case 155: + case 151: case 156: case 157: case 158: + case 159: + case 160: return isDeclarationVisible(node.parent); - case 221: - case 222: + case 223: case 224: + case 226: return false; - case 135: - case 246: + case 137: + case 248: return true; - case 225: + case 227: return false; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); @@ -12344,10 +12616,10 @@ var ts; } function collectLinkedAliases(node) { var exportSymbol; - if (node.parent && node.parent.kind === 225) { + if (node.parent && node.parent.kind === 227) { exportSymbol = resolveName(node.parent, node.text, 107455 | 793056 | 1536 | 8388608, ts.Diagnostics.Cannot_find_name_0, node); } - else if (node.parent.kind === 228) { + else if (node.parent.kind === 230) { var exportSpecifier = node.parent; exportSymbol = exportSpecifier.parent.parent.moduleSpecifier ? getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) : @@ -12422,7 +12694,7 @@ var ts; } function getDeclarationContainer(node) { node = ts.getRootDeclaration(node); - return node.kind === 209 ? node.parent.parent.parent : node.parent; + return node.kind === 211 ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); @@ -12435,9 +12707,13 @@ var ts; function isTypeAny(type) { return type && (type.flags & 1) !== 0; } + function getTypeForBindingElementParent(node) { + var symbol = getSymbolOfNode(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + } function getTypeForBindingElement(declaration) { var pattern = declaration.parent; - var parentType = getTypeForVariableLikeDeclaration(pattern.parent); + var parentType = getTypeForBindingElementParent(pattern.parent); if (parentType === unknownType) { return unknownType; } @@ -12448,7 +12724,7 @@ var ts; return parentType; } var type; - if (pattern.kind === 159) { + if (pattern.kind === 161) { var name_11 = declaration.propertyName || declaration.name; type = getTypeOfPropertyOfType(parentType, name_11.text) || isNumericLiteralName(name_11.text) && getIndexTypeOfType(parentType, 1) || @@ -12482,10 +12758,10 @@ var ts; return type; } function getTypeForVariableLikeDeclaration(declaration) { - if (declaration.parent.parent.kind === 198) { + if (declaration.parent.parent.kind === 200) { return anyType; } - if (declaration.parent.parent.kind === 199) { + if (declaration.parent.parent.kind === 201) { return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -12494,10 +12770,10 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136) { + if (declaration.kind === 138) { var func = declaration.parent; - if (func.kind === 144 && !ts.hasDynamicName(func)) { - var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 143); + if (func.kind === 146 && !ts.hasDynamicName(func)) { + var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 145); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); } @@ -12510,7 +12786,7 @@ var ts; if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } - if (declaration.kind === 244) { + if (declaration.kind === 246) { return checkIdentifier(declaration.name); } if (ts.isBindingPattern(declaration.name)) { @@ -12548,7 +12824,7 @@ var ts; if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) { return languageVersion >= 2 ? createIterableType(anyType) : anyArrayType; } - var elementTypes = ts.map(elements, function (e) { return e.kind === 185 ? anyType : getTypeFromBindingElement(e, includePatternInType); }); + var elementTypes = ts.map(elements, function (e) { return e.kind === 187 ? anyType : getTypeFromBindingElement(e, includePatternInType); }); if (includePatternInType) { var result = createNewTupleType(elementTypes); result.pattern = pattern; @@ -12557,7 +12833,7 @@ var ts; return createTupleType(elementTypes); } function getTypeFromBindingPattern(pattern, includePatternInType) { - return pattern.kind === 159 + return pattern.kind === 161 ? getTypeFromObjectBindingPattern(pattern, includePatternInType) : getTypeFromArrayBindingPattern(pattern, includePatternInType); } @@ -12567,12 +12843,12 @@ var ts; if (reportErrors) { reportErrorsFromWidening(declaration, type); } - return declaration.kind !== 243 ? getWidenedType(type) : type; + return declaration.kind !== 245 ? getWidenedType(type) : type; } type = declaration.dotDotDotToken ? anyArrayType : anyType; if (reportErrors && compilerOptions.noImplicitAny) { var root = ts.getRootDeclaration(declaration); - if (!isPrivateWithinAmbient(root) && !(root.kind === 136 && isPrivateWithinAmbient(root.parent))) { + if (!isPrivateWithinAmbient(root) && !(root.kind === 138 && isPrivateWithinAmbient(root.parent))) { reportImplicitAnyError(declaration, type); } } @@ -12585,10 +12861,10 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.parent.kind === 242) { + if (declaration.parent.kind === 244) { return links.type = anyType; } - if (declaration.kind === 225) { + if (declaration.kind === 227) { return links.type = checkExpression(declaration.expression); } if (!pushTypeResolution(symbol, 0)) { @@ -12613,7 +12889,7 @@ var ts; } function getAnnotatedAccessorType(accessor) { if (accessor) { - if (accessor.kind === 143) { + if (accessor.kind === 145) { return accessor.type && getTypeFromTypeNode(accessor.type); } else { @@ -12629,8 +12905,8 @@ var ts; if (!pushTypeResolution(symbol, 0)) { return unknownType; } - var getter = ts.getDeclarationOfKind(symbol, 143); - var setter = ts.getDeclarationOfKind(symbol, 144); + var getter = ts.getDeclarationOfKind(symbol, 145); + var setter = ts.getDeclarationOfKind(symbol, 146); var type; var getterReturnType = getAnnotatedAccessorType(getter); if (getterReturnType) { @@ -12656,7 +12932,7 @@ var ts; if (!popTypeResolution()) { type = anyType; if (compilerOptions.noImplicitAny) { - var getter_1 = ts.getDeclarationOfKind(symbol, 143); + var getter_1 = ts.getDeclarationOfKind(symbol, 145); error(getter_1, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } } @@ -12745,9 +13021,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 212 || node.kind === 184 || - node.kind === 211 || node.kind === 171 || - node.kind === 141 || node.kind === 172) { + if (node.kind === 214 || node.kind === 186 || + node.kind === 213 || node.kind === 173 || + node.kind === 143 || node.kind === 174) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -12756,15 +13032,15 @@ var ts; } } function getOuterTypeParametersOfClassOrInterface(symbol) { - var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 213); + var declaration = symbol.flags & 32 ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 215); return appendOuterTypeParameters(undefined, declaration); } function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) { var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 213 || node.kind === 212 || - node.kind === 184 || node.kind === 214) { + if (node.kind === 215 || node.kind === 214 || + node.kind === 186 || node.kind === 216) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -12869,7 +13145,7 @@ var ts; type.resolvedBaseTypes = []; for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) { var declaration = _a[_i]; - if (declaration.kind === 213 && ts.getInterfaceBaseTypeNodes(declaration)) { + if (declaration.kind === 215 && ts.getInterfaceBaseTypeNodes(declaration)) { for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) { var node = _c[_b]; var baseType = getTypeFromTypeNode(node); @@ -12890,6 +13166,29 @@ var ts; } } } + function isIndependentInterface(symbol) { + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var declaration = _a[_i]; + if (declaration.kind === 215) { + if (declaration.flags & 524288) { + return false; + } + var baseTypeNodes = ts.getInterfaceBaseTypeNodes(declaration); + if (baseTypeNodes) { + for (var _b = 0; _b < baseTypeNodes.length; _b++) { + var node = baseTypeNodes[_b]; + if (ts.isSupportedExpressionWithTypeArguments(node)) { + var baseSymbol = resolveEntityName(node.expression, 793056, true); + if (!baseSymbol || !(baseSymbol.flags & 64) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) { + return false; + } + } + } + } + } + } + return true; + } function getDeclaredTypeOfClassOrInterface(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { @@ -12897,7 +13196,7 @@ var ts; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); - if (outerTypeParameters || localTypeParameters) { + if (outerTypeParameters || localTypeParameters || kind === 1024 || !isIndependentInterface(symbol)) { type.flags |= 4096; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; @@ -12906,6 +13205,9 @@ var ts; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; + type.thisType = createType(512 | 33554432); + type.thisType.symbol = symbol; + type.thisType.constraint = getTypeWithThisArgument(type); } } return links.declaredType; @@ -12916,7 +13218,7 @@ var ts; if (!pushTypeResolution(symbol, 2)) { return unknownType; } - var declaration = ts.getDeclarationOfKind(symbol, 214); + var declaration = ts.getDeclarationOfKind(symbol, 216); var type = getTypeFromTypeNode(declaration.type); if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); @@ -12947,7 +13249,7 @@ var ts; if (!links.declaredType) { var type = createType(512); type.symbol = symbol; - if (!ts.getDeclarationOfKind(symbol, 135).constraint) { + if (!ts.getDeclarationOfKind(symbol, 137).constraint) { type.constraint = noConstraintType; } links.declaredType = type; @@ -12980,6 +13282,66 @@ var ts; } return unknownType; } + function isIndependentTypeReference(node) { + if (node.typeArguments) { + for (var _i = 0, _a = node.typeArguments; _i < _a.length; _i++) { + var typeNode = _a[_i]; + if (!isIndependentType(typeNode)) { + return false; + } + } + } + return true; + } + function isIndependentType(node) { + switch (node.kind) { + case 117: + case 130: + case 128: + case 120: + case 131: + case 103: + case 9: + return true; + case 156: + return isIndependentType(node.elementType); + case 151: + return isIndependentTypeReference(node); + } + return false; + } + function isIndependentVariableLikeDeclaration(node) { + return node.type && isIndependentType(node.type) || !node.type && !node.initializer; + } + function isIndependentFunctionLikeDeclaration(node) { + if (node.kind !== 144 && (!node.type || !isIndependentType(node.type))) { + return false; + } + for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) { + var parameter = _a[_i]; + if (!isIndependentVariableLikeDeclaration(parameter)) { + return false; + } + } + return true; + } + function isIndependentMember(symbol) { + if (symbol.declarations && symbol.declarations.length === 1) { + var declaration = symbol.declarations[0]; + if (declaration) { + switch (declaration.kind) { + case 141: + case 140: + return isIndependentVariableLikeDeclaration(declaration); + case 143: + case 142: + case 144: + return isIndependentFunctionLikeDeclaration(declaration); + } + } + } + return false; + } function createSymbolTable(symbols) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { @@ -12988,11 +13350,11 @@ var ts; } return result; } - function createInstantiatedSymbolTable(symbols, mapper) { + function createInstantiatedSymbolTable(symbols, mapper, mappingThisOnly) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { var symbol = symbols[_i]; - result[symbol.name] = instantiateSymbol(symbol, mapper); + result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper); } return result; } @@ -13023,44 +13385,54 @@ var ts; } return type; } - function resolveClassOrInterfaceMembers(type) { - var target = resolveDeclaredMembers(type); - var members = target.symbol.members; - var callSignatures = target.declaredCallSignatures; - var constructSignatures = target.declaredConstructSignatures; - var stringIndexType = target.declaredStringIndexType; - var numberIndexType = target.declaredNumberIndexType; - var baseTypes = getBaseTypes(target); + function getTypeWithThisArgument(type, thisArgument) { + if (type.flags & 4096) { + return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType])); + } + return type; + } + function resolveObjectTypeMembers(type, source, typeParameters, typeArguments) { + var mapper = identityMapper; + var members = source.symbol.members; + var callSignatures = source.declaredCallSignatures; + var constructSignatures = source.declaredConstructSignatures; + var stringIndexType = source.declaredStringIndexType; + var numberIndexType = source.declaredNumberIndexType; + if (!ts.rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { + mapper = createTypeMapper(typeParameters, typeArguments); + members = createInstantiatedSymbolTable(source.declaredProperties, mapper, typeParameters.length === 1); + callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); + constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); + stringIndexType = instantiateType(source.declaredStringIndexType, mapper); + numberIndexType = instantiateType(source.declaredNumberIndexType, mapper); + } + var baseTypes = getBaseTypes(source); if (baseTypes.length) { - members = createSymbolTable(target.declaredProperties); + if (members === source.symbol.members) { + members = createSymbolTable(source.declaredProperties); + } + var thisArgument = ts.lastOrUndefined(typeArguments); for (var _i = 0; _i < baseTypes.length; _i++) { var baseType = baseTypes[_i]; - addInheritedMembers(members, getPropertiesOfObjectType(baseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1)); - stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0); - numberIndexType = numberIndexType || getIndexTypeOfType(baseType, 1); + var instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType; + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); + callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0)); + constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1)); + stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0); + numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1); } } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } + function resolveClassOrInterfaceMembers(type) { + resolveObjectTypeMembers(type, resolveDeclaredMembers(type), emptyArray, emptyArray); + } function resolveTypeReferenceMembers(type) { - var target = resolveDeclaredMembers(type.target); - var mapper = createTypeMapper(target.typeParameters, type.typeArguments); - var members = createInstantiatedSymbolTable(target.declaredProperties, mapper); - var callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature); - var constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature); - var stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined; - var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; - ts.forEach(getBaseTypes(target), function (baseType) { - var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1)); - stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0); - numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1); - }); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + var source = resolveDeclaredMembers(type.target); + var typeParameters = ts.concatenate(source.typeParameters, [source.thisType]); + var typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ? + type.typeArguments : ts.concatenate(type.typeArguments, [type]); + resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); @@ -13109,7 +13481,8 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveStructuredTypeMembers(createArrayType(getUnionType(type.elementTypes, true))); + var arrayElementType = getUnionType(type.elementTypes, true); + var arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); @@ -13211,7 +13584,14 @@ var ts; var constructSignatures; var stringIndexType; var numberIndexType; - if (symbol.flags & 2048) { + if (type.target) { + members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, false); + callSignatures = instantiateList(getSignaturesOfType(type.target, 0), type.mapper, instantiateSignature); + constructSignatures = instantiateList(getSignaturesOfType(type.target, 1), type.mapper, instantiateSignature); + stringIndexType = instantiateType(getIndexTypeOfType(type.target, 0), type.mapper); + numberIndexType = instantiateType(getIndexTypeOfType(type.target, 1), type.mapper); + } + else if (symbol.flags & 2048) { members = symbol.members; callSignatures = getSignaturesOfSymbol(members["__call"]); constructSignatures = getSignaturesOfSymbol(members["__new"]); @@ -13247,7 +13627,10 @@ var ts; } function resolveStructuredTypeMembers(type) { if (!type.members) { - if (type.flags & (1024 | 2048)) { + if (type.flags & 4096) { + resolveTypeReferenceMembers(type); + } + else if (type.flags & (1024 | 2048)) { resolveClassOrInterfaceMembers(type); } else if (type.flags & 65536) { @@ -13262,9 +13645,6 @@ var ts; else if (type.flags & 32768) { resolveIntersectionTypeMembers(type); } - else { - resolveTypeReferenceMembers(type); - } } return type; } @@ -13471,7 +13851,7 @@ var ts; function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { - var classType = declaration.kind === 142 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; + var classType = declaration.kind === 144 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; @@ -13502,7 +13882,7 @@ var ts; } else if (declaration.type) { returnType = getTypeFromTypeNode(declaration.type); - if (declaration.type.kind === 148) { + if (declaration.type.kind === 150) { var typePredicateNode = declaration.type; typePredicate = { parameterName: typePredicateNode.parameterName ? typePredicateNode.parameterName.text : undefined, @@ -13512,8 +13892,8 @@ var ts; } } else { - if (declaration.kind === 143 && !ts.hasDynamicName(declaration)) { - var setter = ts.getDeclarationOfKind(declaration.symbol, 144); + if (declaration.kind === 145 && !ts.hasDynamicName(declaration)) { + var setter = ts.getDeclarationOfKind(declaration.symbol, 146); returnType = getAnnotatedAccessorType(setter); } if (!returnType && ts.nodeIsMissing(declaration.body)) { @@ -13531,19 +13911,19 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 150: - case 151: - case 211: - case 141: - case 140: + case 152: + case 153: + case 213: + case 143: case 142: + case 144: + case 147: + case 148: + case 149: case 145: case 146: - case 147: - case 143: - case 144: - case 171: - case 172: + case 173: + case 174: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -13613,7 +13993,7 @@ var ts; } function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { - var isConstructor = signature.declaration.kind === 142 || signature.declaration.kind === 146; + var isConstructor = signature.declaration.kind === 144 || signature.declaration.kind === 148; var type = createObjectType(65536 | 262144); type.members = emptySymbols; type.properties = emptyArray; @@ -13627,7 +14007,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 ? 126 : 128; + var syntaxKind = kind === 1 ? 128 : 130; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) { @@ -13656,30 +14036,33 @@ var ts; type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType; } else { - type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 135).constraint); + type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 137).constraint); } } return type.constraint === noConstraintType ? undefined : type.constraint; } function getParentSymbolOfTypeParameter(typeParameter) { - return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 135).parent); + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 137).parent); } function getTypeListId(types) { - switch (types.length) { - case 1: - return "" + types[0].id; - case 2: - return types[0].id + "," + types[1].id; - default: - var result = ""; - for (var i = 0; i < types.length; i++) { - if (i > 0) { - result += ","; + if (types) { + switch (types.length) { + case 1: + return "" + types[0].id; + case 2: + return types[0].id + "," + types[1].id; + default: + var result = ""; + for (var i = 0; i < types.length; i++) { + if (i > 0) { + result += ","; + } + result += types[i].id; } - result += types[i].id; - } - return result; + return result; + } } + return ""; } function getPropagatingFlagsOfTypes(types) { var result = 0; @@ -13693,7 +14076,7 @@ var ts; var id = getTypeListId(typeArguments); var type = target.instantiations[id]; if (!type) { - var flags = 4096 | getPropagatingFlagsOfTypes(typeArguments); + var flags = 4096 | (typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -13709,13 +14092,13 @@ var ts; while (!ts.forEach(typeParameterSymbol.declarations, function (d) { return d.parent === currentNode.parent; })) { currentNode = currentNode.parent; } - links.isIllegalTypeReferenceInConstraint = currentNode.kind === 135; + links.isIllegalTypeReferenceInConstraint = currentNode.kind === 137; return links.isIllegalTypeReferenceInConstraint; } function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) { var typeParameterSymbol; function check(n) { - if (n.kind === 149 && n.typeName.kind === 67) { + if (n.kind === 151 && n.typeName.kind === 69) { var links = getNodeLinks(n); if (links.isIllegalTypeReferenceInConstraint === undefined) { var symbol = resolveName(typeParameter, n.typeName.text, 793056, undefined, undefined); @@ -13782,7 +14165,7 @@ var ts; function getTypeFromTypeReference(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var typeNameOrExpression = node.kind === 149 ? node.typeName : + var typeNameOrExpression = node.kind === 151 ? node.typeName : ts.isSupportedExpressionWithTypeArguments(node) ? node.expression : undefined; var symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, 793056) || unknownSymbol; @@ -13808,9 +14191,9 @@ var ts; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; switch (declaration.kind) { - case 212: - case 213: + case 214: case 215: + case 217: return declaration; } } @@ -13860,17 +14243,17 @@ var ts; ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) : emptyObjectType; } - function createTypeFromGenericGlobalType(genericGlobalType, elementType) { - return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + function createTypeFromGenericGlobalType(genericGlobalType, typeArguments) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, typeArguments) : emptyObjectType; } function createIterableType(elementType) { - return createTypeFromGenericGlobalType(globalIterableType, elementType); + return createTypeFromGenericGlobalType(globalIterableType, [elementType]); } function createIterableIteratorType(elementType) { - return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); + return createTypeFromGenericGlobalType(globalIterableIteratorType, [elementType]); } function createArrayType(elementType) { - return createTypeFromGenericGlobalType(globalArrayType, elementType); + return createTypeFromGenericGlobalType(globalArrayType, [elementType]); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -14027,46 +14410,66 @@ var ts; } return links.resolvedType; } + function getThisType(node) { + var container = ts.getThisContainer(node, false); + var parent = container && container.parent; + if (parent && (ts.isClassLike(parent) || parent.kind === 215)) { + if (!(container.flags & 128)) { + return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType; + } + } + error(node, ts.Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface); + return unknownType; + } + function getTypeFromThisTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getThisType(node); + } + return links.resolvedType; + } function getTypeFromTypeNode(node) { switch (node.kind) { - case 115: + case 117: return anyType; - case 128: + case 130: return stringType; - case 126: + case 128: return numberType; - case 118: + case 120: return booleanType; - case 129: + case 131: return esSymbolType; - case 101: + case 103: return voidType; + case 97: + return getTypeFromThisTypeNode(node); case 9: return getTypeFromStringLiteral(node); - case 149: - return getTypeFromTypeReference(node); - case 148: - return booleanType; - case 186: - return getTypeFromTypeReference(node); - case 152: - return getTypeFromTypeQueryNode(node); - case 154: - return getTypeFromArrayTypeNode(node); - case 155: - return getTypeFromTupleTypeNode(node); - case 156: - return getTypeFromUnionTypeNode(node); - case 157: - return getTypeFromIntersectionTypeNode(node); - case 158: - return getTypeFromTypeNode(node.type); - case 150: case 151: + return getTypeFromTypeReference(node); + case 150: + return booleanType; + case 188: + return getTypeFromTypeReference(node); + case 154: + return getTypeFromTypeQueryNode(node); + case 156: + return getTypeFromArrayTypeNode(node); + case 157: + return getTypeFromTupleTypeNode(node); + case 158: + return getTypeFromUnionTypeNode(node); + case 159: + return getTypeFromIntersectionTypeNode(node); + case 160: + return getTypeFromTypeNode(node.type); + case 152: case 153: + case 155: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); - case 67: - case 133: + case 69: + case 135: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: @@ -14170,7 +14573,7 @@ var ts; type: instantiateType(signature.typePredicate.type, mapper) }; } - var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), signature.resolvedReturnType ? instantiateType(signature.resolvedReturnType, mapper) : undefined, freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -14202,21 +14605,13 @@ var ts; mapper.instantiations = []; } var result = createObjectType(65536 | 131072, type.symbol); - result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); - result.members = createSymbolTable(result.properties); - result.callSignatures = instantiateList(getSignaturesOfType(type, 0), mapper, instantiateSignature); - result.constructSignatures = instantiateList(getSignaturesOfType(type, 1), mapper, instantiateSignature); - var stringIndexType = getIndexTypeOfType(type, 0); - var numberIndexType = getIndexTypeOfType(type, 1); - if (stringIndexType) - result.stringIndexType = instantiateType(stringIndexType, mapper); - if (numberIndexType) - result.numberIndexType = instantiateType(numberIndexType, mapper); + result.target = type; + result.mapper = mapper; mapper.instantiations[type.id] = result; return result; } function instantiateType(type, mapper) { - if (mapper !== identityMapper) { + if (type && mapper !== identityMapper) { if (type.flags & 512) { return mapper(type); } @@ -14240,27 +14635,27 @@ var ts; return type; } function isContextSensitive(node) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); switch (node.kind) { - case 171: - case 172: + case 173: + case 174: return isContextSensitiveFunctionLikeDeclaration(node); - case 163: + case 165: return ts.forEach(node.properties, isContextSensitive); - case 162: + case 164: return ts.forEach(node.elements, isContextSensitive); - case 180: + case 182: return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse); - case 179: - return node.operatorToken.kind === 51 && + case 181: + return node.operatorToken.kind === 52 && (isContextSensitive(node.left) || isContextSensitive(node.right)); - case 243: + case 245: return isContextSensitive(node.initializer); - case 141: - case 140: + case 143: + case 142: return isContextSensitiveFunctionLikeDeclaration(node); - case 170: + case 172: return isContextSensitive(node.expression); } return false; @@ -14413,7 +14808,7 @@ var ts; } else { if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) { - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, reportErrors)) { + if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } @@ -14435,7 +14830,7 @@ var ts; var result; if (source.flags & 80896 && target.flags & 80896) { if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) { - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, false)) { + if (result = typeArgumentsRelatedTo(source, target, false)) { return result; } } @@ -14545,9 +14940,14 @@ var ts; } return result; } - function typesRelatedTo(sources, targets, reportErrors) { + function typeArgumentsRelatedTo(source, target, reportErrors) { + var sources = source.typeArguments || emptyArray; + var targets = target.typeArguments || emptyArray; + if (sources.length !== targets.length && relation === identityRelation) { + return 0; + } var result = -1; - for (var i = 0, len = sources.length; i < len; i++) { + for (var i = 0; i < targets.length; i++) { var related = isRelatedTo(sources[i], targets[i], reportErrors); if (!related) { return 0; @@ -15198,22 +15598,22 @@ var ts; var typeAsString = typeToString(getWidenedType(type)); var diagnostic; switch (declaration.kind) { - case 139: - case 138: + case 141: + case 140: diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; - case 136: + case 138: diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; break; - case 211: - case 141: - case 140: + case 213: case 143: - case 144: - case 171: - case 172: + case 142: + case 145: + case 146: + case 173: + case 174: if (!declaration.name) { error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); return; @@ -15309,9 +15709,10 @@ var ts; } } else if (source.flags & 4096 && target.flags & 4096 && source.target === target.target) { - var sourceTypes = source.typeArguments; - var targetTypes = target.typeArguments; - for (var i = 0; i < sourceTypes.length; i++) { + var sourceTypes = source.typeArguments || emptyArray; + var targetTypes = target.typeArguments || emptyArray; + var count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length; + for (var i = 0; i < count; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } @@ -15465,10 +15866,10 @@ var ts; function isInTypeQuery(node) { while (node) { switch (node.kind) { - case 152: + case 154: return true; - case 67: - case 133: + case 69: + case 135: node = node.parent; continue; default: @@ -15508,12 +15909,12 @@ var ts; } return links.assignmentChecks[symbol.id] = isAssignedIn(node); function isAssignedInBinaryExpression(node) { - if (node.operatorToken.kind >= 55 && node.operatorToken.kind <= 66) { + if (node.operatorToken.kind >= 56 && node.operatorToken.kind <= 68) { var n = node.left; - while (n.kind === 170) { + while (n.kind === 172) { n = n.expression; } - if (n.kind === 67 && getResolvedSymbol(n) === symbol) { + if (n.kind === 69 && getResolvedSymbol(n) === symbol) { return true; } } @@ -15527,55 +15928,55 @@ var ts; } function isAssignedIn(node) { switch (node.kind) { - case 179: + case 181: return isAssignedInBinaryExpression(node); - case 209: - case 161: - return isAssignedInVariableDeclaration(node); - case 159: - case 160: - case 162: + case 211: case 163: + return isAssignedInVariableDeclaration(node); + case 161: + case 162: case 164: case 165: case 166: case 167: + case 168: case 169: - case 187: - case 170: - case 177: - case 173: - case 176: - case 174: + case 171: + case 189: + case 172: + case 179: case 175: case 178: - case 182: + case 176: + case 177: case 180: - case 183: - case 190: - case 191: + case 184: + case 182: + case 185: + case 192: case 193: - case 194: case 195: case 196: case 197: case 198: case 199: - case 202: - case 203: + case 200: + case 201: case 204: - case 239: - case 240: case 205: case 206: - case 207: + case 241: case 242: - case 231: - case 232: - case 236: - case 237: + case 207: + case 208: + case 209: + case 244: case 233: + case 234: case 238: + case 239: + case 235: + case 240: return ts.forEachChild(node, isAssignedIn); } return false; @@ -15590,34 +15991,34 @@ var ts; node = node.parent; var narrowedType = type; switch (node.kind) { - case 194: + case 196: if (child !== node.expression) { narrowedType = narrowType(type, node.expression, child === node.thenStatement); } break; - case 180: + case 182: if (child !== node.condition) { narrowedType = narrowType(type, node.condition, child === node.whenTrue); } break; - case 179: + case 181: if (child === node.right) { - if (node.operatorToken.kind === 50) { + if (node.operatorToken.kind === 51) { narrowedType = narrowType(type, node.left, true); } - else if (node.operatorToken.kind === 51) { + else if (node.operatorToken.kind === 52) { narrowedType = narrowType(type, node.left, false); } } break; - case 246: - case 216: - case 211: - case 141: - case 140: + case 248: + case 218: + case 213: case 143: - case 144: case 142: + case 145: + case 146: + case 144: break loop; } if (narrowedType !== type) { @@ -15631,12 +16032,12 @@ var ts; } return type; function narrowTypeByEquality(type, expr, assumeTrue) { - if (expr.left.kind !== 174 || expr.right.kind !== 9) { + if (expr.left.kind !== 176 || expr.right.kind !== 9) { return type; } var left = expr.left; var right = expr.right; - if (left.expression.kind !== 67 || getResolvedSymbol(left.expression) !== symbol) { + if (left.expression.kind !== 69 || getResolvedSymbol(left.expression) !== symbol) { return type; } var typeInfo = primitiveTypeInfo[right.text]; @@ -15682,7 +16083,7 @@ var ts; } } function narrowTypeByInstanceof(type, expr, assumeTrue) { - if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 67 || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 69 || getResolvedSymbol(expr.left) !== symbol) { return type; } var rightType = checkExpression(expr.right); @@ -15746,27 +16147,27 @@ var ts; } function narrowType(type, expr, assumeTrue) { switch (expr.kind) { - case 166: + case 168: return narrowTypeByTypePredicate(type, expr, assumeTrue); - case 170: + case 172: return narrowType(type, expr.expression, assumeTrue); - case 179: + case 181: var operator = expr.operatorToken.kind; if (operator === 32 || operator === 33) { return narrowTypeByEquality(type, expr, assumeTrue); } - else if (operator === 50) { + else if (operator === 51) { return narrowTypeByAnd(type, expr, assumeTrue); } - else if (operator === 51) { + else if (operator === 52) { return narrowTypeByOr(type, expr, assumeTrue); } - else if (operator === 89) { + else if (operator === 91) { return narrowTypeByInstanceof(type, expr, assumeTrue); } break; - case 177: - if (expr.operator === 48) { + case 179: + if (expr.operator === 49) { return narrowType(type, expr.operand, !assumeTrue); } break; @@ -15778,7 +16179,7 @@ var ts; var symbol = getResolvedSymbol(node); if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); - if (container.kind === 172) { + if (container.kind === 174) { if (languageVersion < 2) { error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } @@ -15809,15 +16210,15 @@ var ts; function checkBlockScopedBindingCapturedInLoop(node, symbol) { if (languageVersion >= 2 || (symbol.flags & 2) === 0 || - symbol.valueDeclaration.parent.kind === 242) { + symbol.valueDeclaration.parent.kind === 244) { return; } var container = symbol.valueDeclaration; - while (container.kind !== 210) { + while (container.kind !== 212) { container = container.parent; } container = container.parent; - if (container.kind === 191) { + if (container.kind === 193) { container = container.parent; } var inFunction = isInsideFunction(node.parent, container); @@ -15835,7 +16236,7 @@ var ts; } function captureLexicalThis(node, container) { getNodeLinks(node).flags |= 2; - if (container.kind === 139 || container.kind === 142) { + if (container.kind === 141 || container.kind === 144) { var classNode = container.parent; getNodeLinks(classNode).flags |= 4; } @@ -15846,29 +16247,29 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 172) { + if (container.kind === 174) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = (languageVersion < 2); } switch (container.kind) { - case 216: + case 218: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body); break; - case 215: + case 217: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; - case 142: + case 144: if (isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments); } break; - case 139: - case 138: + case 141: + case 140: if (container.flags & 128) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; - case 134: + case 136: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; } @@ -15877,27 +16278,27 @@ var ts; } if (ts.isClassLike(container.parent)) { var symbol = getSymbolOfNode(container.parent); - return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); + return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol).thisType; } return anyType; } function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { - if (n.kind === 136) { + if (n.kind === 138) { return true; } } return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 166 && node.parent.expression === node; + var isCallExpression = node.parent.kind === 168 && node.parent.expression === node; var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; var container = ts.getSuperContainer(node, true); var needToCaptureLexicalThis = false; if (!isCallExpression) { - while (container && container.kind === 172) { + while (container && container.kind === 174) { container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = languageVersion < 2; } @@ -15923,7 +16324,7 @@ var ts; return unknownType; } if (!canUseSuperExpression) { - if (container && container.kind === 134) { + if (container && container.kind === 136) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { @@ -15934,7 +16335,7 @@ var ts; } return unknownType; } - if (container.kind === 142 && isInConstructorArgumentInitializer(node, container)) { + if (container.kind === 144 && isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments); return unknownType; } @@ -15946,24 +16347,24 @@ var ts; return false; } if (isCallExpression) { - return container.kind === 142; + return container.kind === 144; } else { if (container && ts.isClassLike(container.parent)) { if (container.flags & 128) { - return container.kind === 141 || - container.kind === 140 || - container.kind === 143 || - container.kind === 144; + return container.kind === 143 || + container.kind === 142 || + container.kind === 145 || + container.kind === 146; } else { - return container.kind === 141 || + return container.kind === 143 || + container.kind === 142 || + container.kind === 145 || + container.kind === 146 || + container.kind === 141 || container.kind === 140 || - container.kind === 143 || - container.kind === 144 || - container.kind === 139 || - container.kind === 138 || - container.kind === 142; + container.kind === 144; } } } @@ -15997,7 +16398,7 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136) { + if (declaration.kind === 138) { var type = getContextuallyTypedParameterType(declaration); if (type) { return type; @@ -16030,7 +16431,7 @@ var ts; } function isInParameterInitializerBeforeContainingFunction(node) { while (node.parent && !ts.isFunctionLike(node.parent)) { - if (node.parent.kind === 136 && node.parent.initializer === node) { + if (node.parent.kind === 138 && node.parent.initializer === node) { return true; } node = node.parent; @@ -16039,8 +16440,8 @@ var ts; } function getContextualReturnType(functionDecl) { if (functionDecl.type || - functionDecl.kind === 142 || - functionDecl.kind === 143 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 144))) { + functionDecl.kind === 144 || + functionDecl.kind === 145 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 146))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); } var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); @@ -16059,7 +16460,7 @@ var ts; return undefined; } function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { - if (template.parent.kind === 168) { + if (template.parent.kind === 170) { return getContextualTypeForArgument(template.parent, substitutionExpression); } return undefined; @@ -16067,12 +16468,12 @@ var ts; function getContextualTypeForBinaryOperand(node) { var binaryExpression = node.parent; var operator = binaryExpression.operatorToken.kind; - if (operator >= 55 && operator <= 66) { + if (operator >= 56 && operator <= 68) { if (node === binaryExpression.right) { return checkExpression(binaryExpression.left); } } - else if (operator === 51) { + else if (operator === 52) { var type = getContextualType(binaryExpression); if (!type && node === binaryExpression.right) { type = checkExpression(binaryExpression.left); @@ -16159,7 +16560,7 @@ var ts; return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined; } function getContextualTypeForJsxExpression(expr) { - if (expr.parent.kind === 236) { + if (expr.parent.kind === 238) { var attrib = expr.parent; var attrsType = getJsxElementAttributesType(attrib.parent); if (!attrsType || isTypeAny(attrsType)) { @@ -16169,7 +16570,7 @@ var ts; return getTypeOfPropertyOfType(attrsType, attrib.name.text); } } - if (expr.kind === 237) { + if (expr.kind === 239) { return getJsxElementAttributesType(expr.parent); } return undefined; @@ -16187,38 +16588,38 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 209: - case 136: - case 139: + case 211: case 138: - case 161: + case 141: + case 140: + case 163: return getContextualTypeForInitializerExpression(node); - case 172: - case 202: + case 174: + case 204: return getContextualTypeForReturnExpression(node); - case 182: + case 184: return getContextualTypeForYieldOperand(parent); - case 166: - case 167: - return getContextualTypeForArgument(parent, node); + case 168: case 169: - case 187: + return getContextualTypeForArgument(parent, node); + case 171: + case 189: return getTypeFromTypeNode(parent.type); - case 179: + case 181: return getContextualTypeForBinaryOperand(node); - case 243: + case 245: return getContextualTypeForObjectLiteralElement(parent); - case 162: + case 164: return getContextualTypeForElementExpression(node); - case 180: + case 182: return getContextualTypeForConditionalOperand(node); - case 188: - ts.Debug.assert(parent.parent.kind === 181); + case 190: + ts.Debug.assert(parent.parent.kind === 183); return getContextualTypeForSubstitutionExpression(parent.parent, node); - case 170: + case 172: return getContextualType(parent); - case 238: - case 237: + case 240: + case 239: return getContextualTypeForJsxExpression(parent); } return undefined; @@ -16233,7 +16634,7 @@ var ts; } } function isFunctionExpressionOrArrowFunction(node) { - return node.kind === 171 || node.kind === 172; + return node.kind === 173 || node.kind === 174; } function getContextualSignatureForFunctionLikeDeclaration(node) { return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node) @@ -16241,7 +16642,7 @@ var ts; : undefined; } function getContextualSignature(node) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); @@ -16281,13 +16682,13 @@ var ts; } function isAssignmentTarget(node) { var parent = node.parent; - if (parent.kind === 179 && parent.operatorToken.kind === 55 && parent.left === node) { + if (parent.kind === 181 && parent.operatorToken.kind === 56 && parent.left === node) { return true; } - if (parent.kind === 243) { + if (parent.kind === 245) { return isAssignmentTarget(parent.parent); } - if (parent.kind === 162) { + if (parent.kind === 164) { return isAssignmentTarget(parent); } return false; @@ -16297,8 +16698,8 @@ var ts; return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, false); } function hasDefaultValue(node) { - return (node.kind === 161 && !!node.initializer) || - (node.kind === 179 && node.operatorToken.kind === 55); + return (node.kind === 163 && !!node.initializer) || + (node.kind === 181 && node.operatorToken.kind === 56); } function checkArrayLiteral(node, contextualMapper) { var elements = node.elements; @@ -16307,7 +16708,7 @@ var ts; var inDestructuringPattern = isAssignmentTarget(node); for (var _i = 0; _i < elements.length; _i++) { var e = elements[_i]; - if (inDestructuringPattern && e.kind === 183) { + if (inDestructuringPattern && e.kind === 185) { var restArrayType = checkExpression(e.expression, contextualMapper); var restElementType = getIndexTypeOfType(restArrayType, 1) || (languageVersion >= 2 ? getElementTypeOfIterable(restArrayType, undefined) : undefined); @@ -16319,7 +16720,7 @@ var ts; var type = checkExpression(e, contextualMapper); elementTypes.push(type); } - hasSpreadElement = hasSpreadElement || e.kind === 183; + hasSpreadElement = hasSpreadElement || e.kind === 185; } if (!hasSpreadElement) { if (inDestructuringPattern && elementTypes.length) { @@ -16330,7 +16731,7 @@ var ts; var contextualType = getContextualType(node); if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { var pattern = contextualType.pattern; - if (pattern && (pattern.kind === 160 || pattern.kind === 162)) { + if (pattern && (pattern.kind === 162 || pattern.kind === 164)) { var patternElements = pattern.elements; for (var i = elementTypes.length; i < patternElements.length; i++) { var patternElement = patternElements[i]; @@ -16338,7 +16739,7 @@ var ts; elementTypes.push(contextualType.elementTypes[i]); } else { - if (patternElement.kind !== 185) { + if (patternElement.kind !== 187) { error(patternElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); } elementTypes.push(unknownType); @@ -16353,7 +16754,7 @@ var ts; return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType); } function isNumericName(name) { - return name.kind === 134 ? isNumericComputedName(name) : isNumericLiteralName(name.text); + return name.kind === 136 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132); @@ -16378,35 +16779,37 @@ var ts; return links.resolvedType; } function checkObjectLiteral(node, contextualMapper) { - checkGrammarObjectLiteralExpression(node); + var inDestructuringPattern = isAssignmentTarget(node); + checkGrammarObjectLiteralExpression(node, inDestructuringPattern); var propertiesTable = {}; var propertiesArray = []; var contextualType = getContextualType(node); var contextualTypeHasPattern = contextualType && contextualType.pattern && - (contextualType.pattern.kind === 159 || contextualType.pattern.kind === 163); - var inDestructuringPattern = isAssignmentTarget(node); + (contextualType.pattern.kind === 161 || contextualType.pattern.kind === 165); var typeFlags = 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var memberDecl = _a[_i]; var member = memberDecl.symbol; - if (memberDecl.kind === 243 || - memberDecl.kind === 244 || + if (memberDecl.kind === 245 || + memberDecl.kind === 246 || ts.isObjectLiteralMethod(memberDecl)) { var type = void 0; - if (memberDecl.kind === 243) { + if (memberDecl.kind === 245) { type = checkPropertyAssignment(memberDecl, contextualMapper); } - else if (memberDecl.kind === 141) { + else if (memberDecl.kind === 143) { type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - ts.Debug.assert(memberDecl.kind === 244); + ts.Debug.assert(memberDecl.kind === 246); type = checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 | 67108864 | member.flags, member.name); if (inDestructuringPattern) { - if (memberDecl.kind === 243 && hasDefaultValue(memberDecl.initializer)) { + var isOptional = (memberDecl.kind === 245 && hasDefaultValue(memberDecl.initializer)) || + (memberDecl.kind === 246 && memberDecl.objectAssignmentInitializer); + if (isOptional) { prop.flags |= 536870912; } } @@ -16429,7 +16832,7 @@ var ts; member = prop; } else { - ts.Debug.assert(memberDecl.kind === 143 || memberDecl.kind === 144); + ts.Debug.assert(memberDecl.kind === 145 || memberDecl.kind === 146); checkAccessorDeclaration(memberDecl); } if (!ts.hasDynamicName(memberDecl)) { @@ -16485,7 +16888,7 @@ var ts; if (lhs.kind !== rhs.kind) { return false; } - if (lhs.kind === 67) { + if (lhs.kind === 69) { return lhs.text === rhs.text; } return lhs.right.text === rhs.right.text && @@ -16502,17 +16905,17 @@ var ts; for (var _i = 0, _a = node.children; _i < _a.length; _i++) { var child = _a[_i]; switch (child.kind) { - case 238: + case 240: checkJsxExpression(child); break; - case 231: + case 233: checkJsxElement(child); break; - case 232: + case 234: checkJsxSelfClosingElement(child); break; default: - ts.Debug.assert(child.kind === 234); + ts.Debug.assert(child.kind === 236); } } return jsxElementType || anyType; @@ -16521,7 +16924,7 @@ var ts; return name.indexOf("-") < 0; } function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 133) { + if (tagName.kind === 135) { return false; } else { @@ -16622,12 +17025,14 @@ var ts; var valueSymbol = resolveJsxTagName(node); if (valueSymbol && valueSymbol !== unknownSymbol) { links.jsxFlags |= 4; - getSymbolLinks(valueSymbol).referenced = true; + if (valueSymbol.flags & 8388608) { + markAliasSymbolAsReferenced(valueSymbol); + } } return valueSymbol || unknownSymbol; } function resolveJsxTagName(node) { - if (node.tagName.kind === 67) { + if (node.tagName.kind === 69) { var tag = node.tagName; var sym = getResolvedSymbol(tag); return sym.exportSymbol || sym; @@ -16767,11 +17172,11 @@ var ts; var nameTable = {}; var sawSpreadedAny = false; for (var i = node.attributes.length - 1; i >= 0; i--) { - if (node.attributes[i].kind === 236) { + if (node.attributes[i].kind === 238) { checkJsxAttribute((node.attributes[i]), targetAttributesType, nameTable); } else { - ts.Debug.assert(node.attributes[i].kind === 237); + ts.Debug.assert(node.attributes[i].kind === 239); var spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable); if (isTypeAny(spreadType)) { sawSpreadedAny = true; @@ -16797,7 +17202,7 @@ var ts; } } function getDeclarationKindFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.kind : 139; + return s.valueDeclaration ? s.valueDeclaration.kind : 141; } function getDeclarationFlagsFromSymbol(s) { return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 ? 16 | 128 : 0; @@ -16805,11 +17210,11 @@ var ts; function checkClassPropertyAccess(node, left, type, prop) { var flags = getDeclarationFlagsFromSymbol(prop); var declaringClass = getDeclaredTypeOfSymbol(prop.parent); - if (left.kind === 93) { - var errorNode = node.kind === 164 ? + if (left.kind === 95) { + var errorNode = node.kind === 166 ? node.name : node.right; - if (getDeclarationKindFromSymbol(prop) !== 141) { + if (getDeclarationKindFromSymbol(prop) !== 143) { error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); return false; } @@ -16830,7 +17235,7 @@ var ts; } return true; } - if (left.kind === 93) { + if (left.kind === 95) { return true; } if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) { @@ -16840,6 +17245,9 @@ var ts; if (flags & 128) { return true; } + if (type.flags & 33554432) { + type = getConstraintOfTypeParameter(type); + } if (!(getTargetType(type).flags & (1024 | 2048) && hasBaseType(type, enclosingClass))) { error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass)); return false; @@ -16864,18 +17272,18 @@ var ts; var prop = getPropertyOfType(apparentType, right.text); if (!prop) { if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type.flags & 33554432 ? apparentType : type)); } return unknownType; } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32) { - checkClassPropertyAccess(node, left, type, prop); + checkClassPropertyAccess(node, left, apparentType, prop); } return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 164 + var left = node.kind === 166 ? node.expression : node.left; var type = checkExpression(left); @@ -16890,7 +17298,7 @@ var ts; function checkIndexedAccess(node) { if (!node.argumentExpression) { var sourceFile = getSourceFile(node); - if (node.parent.kind === 167 && node.parent.expression === node) { + if (node.parent.kind === 169 && node.parent.expression === node) { var start = ts.skipTrivia(sourceFile.text, node.expression.end); var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); @@ -16949,6 +17357,12 @@ var ts; if (indexArgumentExpression.kind === 9 || indexArgumentExpression.kind === 8) { return indexArgumentExpression.text; } + if (indexArgumentExpression.kind === 167 || indexArgumentExpression.kind === 166) { + var value = getConstantValue(indexArgumentExpression); + if (value !== undefined) { + return value.toString(); + } + } if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, false)) { var rightHandSideName = indexArgumentExpression.name.text; return ts.getPropertyNameForKnownSymbolName(rightHandSideName); @@ -16986,10 +17400,10 @@ var ts; return true; } function resolveUntypedCall(node) { - if (node.kind === 168) { + if (node.kind === 170) { checkExpression(node.template); } - else if (node.kind !== 137) { + else if (node.kind !== 139) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -17040,7 +17454,7 @@ var ts; function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg && arg.kind === 183) { + if (arg && arg.kind === 185) { return i; } } @@ -17052,11 +17466,11 @@ var ts; var callIsIncomplete; var isDecorator; var spreadArgIndex = -1; - if (node.kind === 168) { + if (node.kind === 170) { var tagExpression = node; adjustedArgCount = args.length; typeArguments = undefined; - if (tagExpression.template.kind === 181) { + if (tagExpression.template.kind === 183) { var templateExpression = tagExpression.template; var lastSpan = ts.lastOrUndefined(templateExpression.templateSpans); ts.Debug.assert(lastSpan !== undefined); @@ -17068,7 +17482,7 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } - else if (node.kind === 137) { + else if (node.kind === 139) { isDecorator = true; typeArguments = undefined; adjustedArgCount = getEffectiveArgumentCount(node, undefined, signature); @@ -17076,7 +17490,7 @@ var ts; else { var callExpression = node; if (!callExpression.arguments) { - ts.Debug.assert(callExpression.kind === 167); + ts.Debug.assert(callExpression.kind === 169); return signature.minArgumentCount === 0; } adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length; @@ -17129,7 +17543,7 @@ var ts; var argCount = getEffectiveArgumentCount(node, args, signature); for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); - if (arg === undefined || arg.kind !== 185) { + if (arg === undefined || arg.kind !== 187) { var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); if (argType === undefined) { @@ -17176,7 +17590,7 @@ var ts; var argCount = getEffectiveArgumentCount(node, args, signature); for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); - if (arg === undefined || arg.kind !== 185) { + if (arg === undefined || arg.kind !== 187) { var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); if (argType === undefined) { @@ -17195,16 +17609,16 @@ var ts; } function getEffectiveCallArguments(node) { var args; - if (node.kind === 168) { + if (node.kind === 170) { var template = node.template; args = [undefined]; - if (template.kind === 181) { + if (template.kind === 183) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } - else if (node.kind === 137) { + else if (node.kind === 139) { return undefined; } else { @@ -17213,18 +17627,21 @@ var ts; return args; } function getEffectiveArgumentCount(node, args, signature) { - if (node.kind === 137) { + if (node.kind === 139) { switch (node.parent.kind) { - case 212: - case 184: + case 214: + case 186: return 1; - case 139: - return 2; case 141: + return 2; case 143: - case 144: + case 145: + case 146: + if (languageVersion === 0) { + return 2; + } return signature.parameters.length >= 3 ? 3 : 2; - case 136: + case 138: return 3; } } @@ -17234,20 +17651,20 @@ var ts; } function getEffectiveDecoratorFirstArgumentType(node) { switch (node.kind) { - case 212: - case 184: + case 214: + case 186: var classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); - case 136: + case 138: node = node.parent; - if (node.kind === 142) { + if (node.kind === 144) { var classSymbol_1 = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol_1); } - case 139: case 141: case 143: - case 144: + case 145: + case 146: return getParentTypeOfClassElement(node); default: ts.Debug.fail("Unsupported decorator target."); @@ -17256,25 +17673,25 @@ var ts; } function getEffectiveDecoratorSecondArgumentType(node) { switch (node.kind) { - case 212: + case 214: ts.Debug.fail("Class decorators should not have a second synthetic argument."); return unknownType; - case 136: + case 138: node = node.parent; - if (node.kind === 142) { + if (node.kind === 144) { return anyType; } - case 139: case 141: case 143: - case 144: + case 145: + case 146: var element = node; switch (element.name.kind) { - case 67: + case 69: case 8: case 9: return getStringLiteralType(element.name); - case 134: + case 136: var nameType = checkComputedPropertyName(element.name); if (allConstituentTypesHaveKind(nameType, 16777216)) { return nameType; @@ -17293,17 +17710,17 @@ var ts; } function getEffectiveDecoratorThirdArgumentType(node) { switch (node.kind) { - case 212: + case 214: ts.Debug.fail("Class decorators should not have a third synthetic argument."); return unknownType; - case 136: + case 138: return numberType; - case 139: + case 141: ts.Debug.fail("Property decorators should not have a third synthetic argument."); return unknownType; - case 141: case 143: - case 144: + case 145: + case 146: var propertyType = getTypeOfNode(node); return createTypedPropertyDescriptorType(propertyType); default: @@ -17325,26 +17742,26 @@ var ts; return unknownType; } function getEffectiveArgumentType(node, argIndex, arg) { - if (node.kind === 137) { + if (node.kind === 139) { return getEffectiveDecoratorArgumentType(node, argIndex); } - else if (argIndex === 0 && node.kind === 168) { + else if (argIndex === 0 && node.kind === 170) { return globalTemplateStringsArrayType; } return undefined; } function getEffectiveArgument(node, args, argIndex) { - if (node.kind === 137 || - (argIndex === 0 && node.kind === 168)) { + if (node.kind === 139 || + (argIndex === 0 && node.kind === 170)) { return undefined; } return args[argIndex]; } function getEffectiveArgumentErrorNode(node, argIndex, arg) { - if (node.kind === 137) { + if (node.kind === 139) { return node.expression; } - else if (argIndex === 0 && node.kind === 168) { + else if (argIndex === 0 && node.kind === 170) { return node.template; } else { @@ -17352,12 +17769,12 @@ var ts; } } function resolveCall(node, signatures, candidatesOutArray, headMessage) { - var isTaggedTemplate = node.kind === 168; - var isDecorator = node.kind === 137; + var isTaggedTemplate = node.kind === 170; + var isDecorator = node.kind === 139; var typeArguments; if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; - if (node.expression.kind !== 93) { + if (node.expression.kind !== 95) { ts.forEach(typeArguments, checkSourceElement); } } @@ -17495,7 +17912,7 @@ var ts; } } function resolveCallExpression(node, candidatesOutArray) { - if (node.expression.kind === 93) { + if (node.expression.kind === 95) { var superType = checkSuperExpression(node.expression); if (superType !== unknownType) { var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node)); @@ -17584,16 +18001,16 @@ var ts; } function getDiagnosticHeadMessageForDecoratorResolution(node) { switch (node.parent.kind) { - case 212: - case 184: + case 214: + case 186: return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; - case 136: + case 138: return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; - case 139: - return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; case 141: + return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; case 143: - case 144: + case 145: + case 146: return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; } } @@ -17621,16 +18038,16 @@ var ts; var links = getNodeLinks(node); if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - if (node.kind === 166) { + if (node.kind === 168) { links.resolvedSignature = resolveCallExpression(node, candidatesOutArray); } - else if (node.kind === 167) { + else if (node.kind === 169) { links.resolvedSignature = resolveNewExpression(node, candidatesOutArray); } - else if (node.kind === 168) { + else if (node.kind === 170) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } - else if (node.kind === 137) { + else if (node.kind === 139) { links.resolvedSignature = resolveDecorator(node, candidatesOutArray); } else { @@ -17642,15 +18059,15 @@ var ts; function checkCallExpression(node) { checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); var signature = getResolvedSignature(node); - if (node.expression.kind === 93) { + if (node.expression.kind === 95) { return voidType; } - if (node.kind === 167) { + if (node.kind === 169) { var declaration = signature.declaration; if (declaration && - declaration.kind !== 142 && - declaration.kind !== 146 && - declaration.kind !== 151) { + declaration.kind !== 144 && + declaration.kind !== 148 && + declaration.kind !== 153) { if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } @@ -17691,10 +18108,22 @@ var ts; assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } } + function assignBindingElementTypes(node) { + if (ts.isBindingPattern(node.name)) { + for (var _i = 0, _a = node.name.elements; _i < _a.length; _i++) { + var element = _a[_i]; + if (element.kind !== 187) { + getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element); + assignBindingElementTypes(element); + } + } + } + } function assignTypeToParameterAndFixTypeParameters(parameter, contextualType, mapper) { var links = getSymbolLinks(parameter); if (!links.type) { links.type = instantiateType(contextualType, mapper); + assignBindingElementTypes(parameter.valueDeclaration); } else if (isInferentialContext(mapper)) { inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper)); @@ -17715,7 +18144,7 @@ var ts; } var isAsync = ts.isAsyncFunctionLike(func); var type; - if (func.body.kind !== 190) { + if (func.body.kind !== 192) { type = checkExpressionCached(func.body, contextualMapper); if (isAsync) { type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); @@ -17819,7 +18248,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 206); + return (body.statements.length === 1) && (body.statements[0].kind === 208); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!produceDiagnostics) { @@ -17828,7 +18257,7 @@ var ts; if (returnType === voidType || isTypeAny(returnType)) { return; } - if (ts.nodeIsMissing(func.body) || func.body.kind !== 190) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 192) { return; } var bodyBlock = func.body; @@ -17841,9 +18270,9 @@ var ts; error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); - if (!hasGrammarError && node.kind === 171) { + if (!hasGrammarError && node.kind === 173) { checkGrammarForGenerator(node); } if (contextualMapper === identityMapper && isContextSensitive(node)) { @@ -17879,14 +18308,14 @@ var ts; } } } - if (produceDiagnostics && node.kind !== 141 && node.kind !== 140) { + if (produceDiagnostics && node.kind !== 143 && node.kind !== 142) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); } return type; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { - ts.Debug.assert(node.kind !== 141 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 || ts.isObjectLiteralMethod(node)); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; @@ -17903,7 +18332,7 @@ var ts; if (!node.type) { getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - if (node.body.kind === 190) { + if (node.body.kind === 192) { checkSourceElement(node.body); } else { @@ -17935,17 +18364,17 @@ var ts; } function isReferenceOrErrorExpression(n) { switch (n.kind) { - case 67: { + case 69: { var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3) !== 0; } - case 164: { + case 166: { var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~8) !== 0; } - case 165: + case 167: return true; - case 170: + case 172: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -17953,12 +18382,12 @@ var ts; } function isConstVariableReference(n) { switch (n.kind) { - case 67: - case 164: { + case 69: + case 166: { var symbol = findSymbol(n); return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 32768) !== 0; } - case 165: { + case 167: { var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 9) { @@ -17968,7 +18397,7 @@ var ts; } return false; } - case 170: + case 172: return isConstVariableReference(n.expression); default: return false; @@ -18013,15 +18442,15 @@ var ts; switch (node.operator) { case 35: case 36: - case 49: + case 50: if (someConstituentTypeHasKind(operandType, 16777216)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; - case 48: + case 49: return booleanType; - case 40: case 41: + case 42: var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { checkReferenceExpression(node.operand, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); @@ -18076,21 +18505,21 @@ var ts; function isConstEnumSymbol(symbol) { return (symbol.flags & 128) !== 0; } - function checkInstanceOfExpression(node, leftType, rightType) { + function checkInstanceOfExpression(left, right, leftType, rightType) { if (allConstituentTypesHaveKind(leftType, 16777726)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); + error(right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } - function checkInExpression(node, leftType, rightType) { + function checkInExpression(left, right, leftType, rightType) { if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 | 132 | 16777216)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); + error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 | 512)) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; } @@ -18098,7 +18527,7 @@ var ts; var properties = node.properties; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; - if (p.kind === 243 || p.kind === 244) { + if (p.kind === 245 || p.kind === 246) { var name_14 = p.name; var type = isTypeAny(sourceType) ? sourceType @@ -18106,7 +18535,12 @@ var ts; isNumericLiteralName(name_14.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_14, type); + if (p.kind === 246) { + checkDestructuringAssignment(p, type); + } + else { + checkDestructuringAssignment(p.initializer || name_14, type); + } } else { error(name_14, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_14)); @@ -18123,8 +18557,8 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 185) { - if (e.kind !== 183) { + if (e.kind !== 187) { + if (e.kind !== 185) { var propName = "" + i; var type = isTypeAny(sourceType) ? sourceType @@ -18149,7 +18583,7 @@ var ts; } else { var restExpression = e.expression; - if (restExpression.kind === 179 && restExpression.operatorToken.kind === 55) { + if (restExpression.kind === 181 && restExpression.operatorToken.kind === 56) { error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer); } else { @@ -18161,15 +18595,26 @@ var ts; } return sourceType; } - function checkDestructuringAssignment(target, sourceType, contextualMapper) { - if (target.kind === 179 && target.operatorToken.kind === 55) { + function checkDestructuringAssignment(exprOrAssignment, sourceType, contextualMapper) { + var target; + if (exprOrAssignment.kind === 246) { + var prop = exprOrAssignment; + if (prop.objectAssignmentInitializer) { + checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper); + } + target = exprOrAssignment.name; + } + else { + target = exprOrAssignment; + } + if (target.kind === 181 && target.operatorToken.kind === 56) { checkBinaryExpression(target, contextualMapper); target = target.left; } - if (target.kind === 163) { + if (target.kind === 165) { return checkObjectLiteralAssignment(target, sourceType, contextualMapper); } - if (target.kind === 162) { + if (target.kind === 164) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } return checkReferenceAssignment(target, sourceType, contextualMapper); @@ -18182,33 +18627,38 @@ var ts; return sourceType; } function checkBinaryExpression(node, contextualMapper) { - var operator = node.operatorToken.kind; - if (operator === 55 && (node.left.kind === 163 || node.left.kind === 162)) { - return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); + return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node); + } + function checkBinaryLikeExpression(left, operatorToken, right, contextualMapper, errorNode) { + var operator = operatorToken.kind; + if (operator === 56 && (left.kind === 165 || left.kind === 164)) { + return checkDestructuringAssignment(left, checkExpression(right, contextualMapper), contextualMapper); } - var leftType = checkExpression(node.left, contextualMapper); - var rightType = checkExpression(node.right, contextualMapper); + var leftType = checkExpression(left, contextualMapper); + var rightType = checkExpression(right, contextualMapper); switch (operator) { case 37: - case 58: case 38: case 59: - case 39: case 60: - case 36: - case 57: - case 42: + case 39: case 61: - case 43: + case 40: case 62: - case 44: + case 36: + case 58: + case 43: case 63: - case 46: + case 44: + case 64: + case 45: case 65: case 47: + case 67: + case 48: + case 68: + case 46: case 66: - case 45: - case 64: if (leftType.flags & (32 | 64)) leftType = rightType; if (rightType.flags & (32 | 64)) @@ -18216,19 +18666,19 @@ var ts; var suggestedOperator; if ((leftType.flags & 8) && (rightType.flags & 8) && - (suggestedOperator = getSuggestedBooleanOperator(node.operatorToken.kind)) !== undefined) { - error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operatorToken.kind), ts.tokenToString(suggestedOperator)); + (suggestedOperator = getSuggestedBooleanOperator(operatorToken.kind)) !== undefined) { + error(errorNode || operatorToken, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(operatorToken.kind), ts.tokenToString(suggestedOperator)); } else { - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var leftOk = checkArithmeticOperandType(left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); if (leftOk && rightOk) { checkAssignmentOperator(numberType); } } return numberType; case 35: - case 56: + case 57: if (leftType.flags & (32 | 64)) leftType = rightType; if (rightType.flags & (32 | 64)) @@ -18252,7 +18702,7 @@ var ts; reportOperatorError(); return anyType; } - if (operator === 56) { + if (operator === 57) { checkAssignmentOperator(resultType); } return resultType; @@ -18271,23 +18721,23 @@ var ts; reportOperatorError(); } return booleanType; - case 89: - return checkInstanceOfExpression(node, leftType, rightType); - case 88: - return checkInExpression(node, leftType, rightType); - case 50: - return rightType; + case 91: + return checkInstanceOfExpression(left, right, leftType, rightType); + case 90: + return checkInExpression(left, right, leftType, rightType); case 51: + return rightType; + case 52: return getUnionType([leftType, rightType]); - case 55: + case 56: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); case 24: return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216) ? node.left : - someConstituentTypeHasKind(rightType, 16777216) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216) ? left : + someConstituentTypeHasKind(rightType, 16777216) ? right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -18297,29 +18747,29 @@ var ts; } function getSuggestedBooleanOperator(operator) { switch (operator) { - case 46: - case 65: - return 51; case 47: - case 66: + case 67: + return 52; + case 48: + case 68: return 33; - case 45: - case 64: - return 50; + case 46: + case 66: + return 51; default: return undefined; } } function checkAssignmentOperator(valueType) { - if (produceDiagnostics && operator >= 55 && operator <= 66) { - var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + if (produceDiagnostics && operator >= 56 && operator <= 68) { + var ok = checkReferenceExpression(left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); if (ok) { - checkTypeAssignableTo(valueType, leftType, node.left, undefined); + checkTypeAssignableTo(valueType, leftType, left, undefined); } } } function reportOperatorError() { - error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); + error(errorNode || operatorToken, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } function isYieldExpressionInClass(node) { @@ -18395,14 +18845,14 @@ var ts; return links.resolvedType; } function checkPropertyAssignment(node, contextualMapper) { - if (node.name.kind === 134) { + if (node.name.kind === 136) { checkComputedPropertyName(node.name); } return checkExpression(node.initializer, contextualMapper); } function checkObjectLiteralMethod(node, contextualMapper) { checkGrammarMethod(node); - if (node.name.kind === 134) { + if (node.name.kind === 136) { checkComputedPropertyName(node.name); } var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); @@ -18425,7 +18875,7 @@ var ts; } function checkExpression(node, contextualMapper) { var type; - if (node.kind === 133) { + if (node.kind === 135) { type = checkQualifiedName(node); } else { @@ -18433,9 +18883,9 @@ var ts; type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } if (isConstEnumObjectType(type)) { - var ok = (node.parent.kind === 164 && node.parent.expression === node) || - (node.parent.kind === 165 && node.parent.expression === node) || - ((node.kind === 67 || node.kind === 133) && isInRightSideOfImportOrExportAssignment(node)); + var ok = (node.parent.kind === 166 && node.parent.expression === node) || + (node.parent.kind === 167 && node.parent.expression === node) || + ((node.kind === 69 || node.kind === 135) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } @@ -18448,78 +18898,78 @@ var ts; } function checkExpressionWorker(node, contextualMapper) { switch (node.kind) { - case 67: + case 69: return checkIdentifier(node); - case 95: - return checkThisExpression(node); - case 93: - return checkSuperExpression(node); - case 91: - return nullType; case 97: - case 82: + return checkThisExpression(node); + case 95: + return checkSuperExpression(node); + case 93: + return nullType; + case 99: + case 84: return booleanType; case 8: return checkNumericLiteral(node); - case 181: + case 183: return checkTemplateExpression(node); case 9: case 11: return stringType; case 10: return globalRegExpType; - case 162: - return checkArrayLiteral(node, contextualMapper); - case 163: - return checkObjectLiteral(node, contextualMapper); case 164: - return checkPropertyAccessExpression(node); + return checkArrayLiteral(node, contextualMapper); case 165: - return checkIndexedAccess(node); + return checkObjectLiteral(node, contextualMapper); case 166: + return checkPropertyAccessExpression(node); case 167: - return checkCallExpression(node); + return checkIndexedAccess(node); case 168: - return checkTaggedTemplateExpression(node); - case 170: - return checkExpression(node.expression, contextualMapper); - case 184: - return checkClassExpression(node); - case 171: - case 172: - return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); - case 174: - return checkTypeOfExpression(node); case 169: - case 187: - return checkAssertion(node); + return checkCallExpression(node); + case 170: + return checkTaggedTemplateExpression(node); + case 172: + return checkExpression(node.expression, contextualMapper); + case 186: + return checkClassExpression(node); case 173: - return checkDeleteExpression(node); - case 175: - return checkVoidExpression(node); + case 174: + return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); case 176: - return checkAwaitExpression(node); + return checkTypeOfExpression(node); + case 171: + case 189: + return checkAssertion(node); + case 175: + return checkDeleteExpression(node); case 177: - return checkPrefixUnaryExpression(node); + return checkVoidExpression(node); case 178: - return checkPostfixUnaryExpression(node); + return checkAwaitExpression(node); case 179: - return checkBinaryExpression(node, contextualMapper); + return checkPrefixUnaryExpression(node); case 180: - return checkConditionalExpression(node, contextualMapper); - case 183: - return checkSpreadElementExpression(node, contextualMapper); - case 185: - return undefinedType; + return checkPostfixUnaryExpression(node); + case 181: + return checkBinaryExpression(node, contextualMapper); case 182: + return checkConditionalExpression(node, contextualMapper); + case 185: + return checkSpreadElementExpression(node, contextualMapper); + case 187: + return undefinedType; + case 184: return checkYieldExpression(node); - case 238: + case 240: return checkJsxExpression(node); - case 231: - return checkJsxElement(node); - case 232: - return checkJsxSelfClosingElement(node); case 233: + return checkJsxElement(node); + case 234: + return checkJsxSelfClosingElement(node); + case 235: ts.Debug.fail("Shouldn't ever directly check a JsxOpeningElement"); } return unknownType; @@ -18540,7 +18990,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & 112) { func = ts.getContainingFunction(node); - if (!(func.kind === 142 && ts.nodeIsPresent(func.body))) { + if (!(func.kind === 144 && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -18555,15 +19005,15 @@ var ts; if (!node.asteriskToken || !node.body) { return false; } - return node.kind === 141 || - node.kind === 211 || - node.kind === 171; + return node.kind === 143 || + node.kind === 213 || + node.kind === 173; } function getTypePredicateParameterIndex(parameterList, parameter) { if (parameterList) { for (var i = 0; i < parameterList.length; i++) { var param = parameterList[i]; - if (param.name.kind === 67 && + if (param.name.kind === 69 && param.name.text === parameter.text) { return i; } @@ -18573,30 +19023,30 @@ var ts; } function isInLegalTypePredicatePosition(node) { switch (node.parent.kind) { - case 172: - case 145: - case 211: - case 171: - case 150: - case 141: - case 140: + case 174: + case 147: + case 213: + case 173: + case 152: + case 143: + case 142: return node === node.parent.type; } return false; } function checkSignatureDeclaration(node) { - if (node.kind === 147) { + if (node.kind === 149) { checkGrammarIndexSignature(node); } - else if (node.kind === 150 || node.kind === 211 || node.kind === 151 || - node.kind === 145 || node.kind === 142 || - node.kind === 146) { + else if (node.kind === 152 || node.kind === 213 || node.kind === 153 || + node.kind === 147 || node.kind === 144 || + node.kind === 148) { checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { - if (node.type.kind === 148) { + if (node.type.kind === 150) { var typePredicate = getSignatureFromDeclaration(node).typePredicate; var typePredicateNode = node.type; if (isInLegalTypePredicatePosition(typePredicateNode)) { @@ -18615,19 +19065,19 @@ var ts; if (hasReportedError) { break; } - if (param.name.kind === 159 || - param.name.kind === 160) { + if (param.name.kind === 161 || + param.name.kind === 162) { (function checkBindingPattern(pattern) { for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.name.kind === 67 && + if (element.name.kind === 69 && element.name.text === typePredicate.parameterName) { error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName); hasReportedError = true; break; } - else if (element.name.kind === 160 || - element.name.kind === 159) { + else if (element.name.kind === 162 || + element.name.kind === 161) { checkBindingPattern(element.name); } } @@ -18651,10 +19101,10 @@ var ts; checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { - case 146: + case 148: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; - case 145: + case 147: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } @@ -18676,7 +19126,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 213) { + if (node.kind === 215) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -18691,7 +19141,7 @@ var ts; var declaration = decl; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 128: + case 130: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -18699,7 +19149,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 126: + case 128: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -18739,7 +19189,7 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 166 && n.expression.kind === 93; + return n.kind === 168 && n.expression.kind === 95; } function containsSuperCallAsComputedPropertyName(n) { return n.name && containsSuperCall(n.name); @@ -18757,15 +19207,15 @@ var ts; return ts.forEachChild(n, containsSuperCall); } function markThisReferencesAsErrors(n) { - if (n.kind === 95) { + if (n.kind === 97) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 171 && n.kind !== 211) { + else if (n.kind !== 173 && n.kind !== 213) { ts.forEachChild(n, markThisReferencesAsErrors); } } function isInstancePropertyWithInitializer(n) { - return n.kind === 139 && + return n.kind === 141 && !(n.flags & 128) && !!n.initializer; } @@ -18785,7 +19235,7 @@ var ts; var superCallStatement; for (var _i = 0; _i < statements.length; _i++) { var statement = statements[_i]; - if (statement.kind === 193 && isSuperCallExpression(statement.expression)) { + if (statement.kind === 195 && isSuperCallExpression(statement.expression)) { superCallStatement = statement; break; } @@ -18809,13 +19259,13 @@ var ts; function checkAccessorDeclaration(node) { if (produceDiagnostics) { checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (node.kind === 143) { + if (node.kind === 145) { if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } if (!ts.hasDynamicName(node)) { - var otherKind = node.kind === 143 ? 144 : 143; + var otherKind = node.kind === 145 ? 146 : 145; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { if (((node.flags & 112) !== (otherAccessor.flags & 112))) { @@ -18900,9 +19350,9 @@ var ts; return; } var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 213) { - ts.Debug.assert(signatureDeclarationNode.kind === 145 || signatureDeclarationNode.kind === 146); - var signatureKind = signatureDeclarationNode.kind === 145 ? 0 : 1; + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 215) { + ts.Debug.assert(signatureDeclarationNode.kind === 147 || signatureDeclarationNode.kind === 148); + var signatureKind = signatureDeclarationNode.kind === 147 ? 0 : 1; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); var containingType = getDeclaredTypeOfSymbol(containingSymbol); signaturesToCheck = getSignaturesOfType(containingType, signatureKind); @@ -18920,7 +19370,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = ts.getCombinedNodeFlags(n); - if (n.parent.kind !== 213 && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 215 && ts.isInAmbientContext(n)) { if (!(flags & 2)) { flags |= 1; } @@ -18996,7 +19446,7 @@ var ts; if (subsequentNode.kind === node.kind) { var errorNode_1 = subsequentNode.name || subsequentNode; if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) { - ts.Debug.assert(node.kind === 141 || node.kind === 140); + ts.Debug.assert(node.kind === 143 || node.kind === 142); ts.Debug.assert((node.flags & 128) !== (subsequentNode.flags & 128)); var diagnostic = node.flags & 128 ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static; error(errorNode_1, diagnostic); @@ -19028,11 +19478,11 @@ var ts; var current = declarations[_i]; var node = current; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 213 || node.parent.kind === 153 || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 215 || node.parent.kind === 155 || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 211 || node.kind === 141 || node.kind === 140 || node.kind === 142) { + if (node.kind === 213 || node.kind === 143 || node.kind === 142 || node.kind === 144) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -19145,16 +19595,16 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 213: + case 215: return 2097152; - case 216: + case 218: return d.name.kind === 9 || ts.getModuleInstanceState(d) !== 0 ? 4194304 | 1048576 : 4194304; - case 212: - case 215: + case 214: + case 217: return 2097152 | 1048576; - case 219: + case 221: var result = 0; var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); @@ -19165,7 +19615,8 @@ var ts; } } function checkNonThenableType(type, location, message) { - if (!(type.flags & 1) && isTypeAssignableTo(type, getGlobalThenableType())) { + type = getWidenedType(type); + if (!isTypeAny(type) && isTypeAssignableTo(type, getGlobalThenableType())) { if (location) { if (!message) { message = ts.Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member; @@ -19280,22 +19731,22 @@ var ts; var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); var errorInfo; switch (node.parent.kind) { - case 212: + case 214: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); expectedReturnType = getUnionType([classConstructorType, voidType]); break; - case 136: + case 138: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; - case 139: + case 141: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; - case 141: case 143: - case 144: + case 145: + case 146: var methodType = getTypeOfNode(node.parent); var descriptorType = createTypedPropertyDescriptorType(methodType); expectedReturnType = getUnionType([descriptorType, voidType]); @@ -19304,9 +19755,9 @@ var ts; checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, errorInfo); } function checkTypeNodeAsExpression(node) { - if (node && node.kind === 149) { + if (node && node.kind === 151) { var root = getFirstIdentifier(node.typeName); - var meaning = root.parent.kind === 149 ? 793056 : 1536; + var meaning = root.parent.kind === 151 ? 793056 : 1536; var rootSymbol = resolveName(root, root.text, meaning | 8388608, undefined, undefined); if (rootSymbol && rootSymbol.flags & 8388608) { var aliasTarget = resolveAlias(rootSymbol); @@ -19318,19 +19769,19 @@ var ts; } function checkTypeAnnotationAsExpression(node) { switch (node.kind) { - case 139: - checkTypeNodeAsExpression(node.type); - break; - case 136: - checkTypeNodeAsExpression(node.type); - break; case 141: checkTypeNodeAsExpression(node.type); break; + case 138: + checkTypeNodeAsExpression(node.type); + break; case 143: checkTypeNodeAsExpression(node.type); break; - case 144: + case 145: + checkTypeNodeAsExpression(node.type); + break; + case 146: checkTypeNodeAsExpression(ts.getSetAccessorTypeAnnotationNode(node)); break; } @@ -19353,24 +19804,24 @@ var ts; } if (compilerOptions.emitDecoratorMetadata) { switch (node.kind) { - case 212: + case 214: var constructor = ts.getFirstConstructorWithBody(node); if (constructor) { checkParameterTypeAnnotationsAsExpressions(constructor); } break; - case 141: - checkParameterTypeAnnotationsAsExpressions(node); - case 144: case 143: - case 139: - case 136: + checkParameterTypeAnnotationsAsExpressions(node); + case 146: + case 145: + case 141: + case 138: checkTypeAnnotationAsExpression(node); break; } } emitDecorate = true; - if (node.kind === 136) { + if (node.kind === 138) { emitParam = true; } ts.forEach(node.decorators, checkDecorator); @@ -19388,12 +19839,9 @@ var ts; checkSignatureDeclaration(node); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { - if (!compilerOptions.experimentalAsyncFunctions) { - error(node, ts.Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning); - } emitAwaiter = true; } - if (node.name && node.name.kind === 134) { + if (node.name && node.name.kind === 136) { checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { @@ -19428,11 +19876,11 @@ var ts; } } function checkBlock(node) { - if (node.kind === 190) { + if (node.kind === 192) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); - if (ts.isFunctionBlock(node) || node.kind === 217) { + if (ts.isFunctionBlock(node) || node.kind === 219) { checkFunctionAndClassExpressionBodies(node); } } @@ -19450,19 +19898,19 @@ var ts; if (!(identifier && identifier.text === name)) { return false; } - if (node.kind === 139 || - node.kind === 138 || - node.kind === 141 || + if (node.kind === 141 || node.kind === 140 || node.kind === 143 || - node.kind === 144) { + node.kind === 142 || + node.kind === 145 || + node.kind === 146) { return false; } if (ts.isInAmbientContext(node)) { return false; } var root = ts.getRootDeclaration(node); - if (root.kind === 136 && ts.nodeIsMissing(root.parent.body)) { + if (root.kind === 138 && ts.nodeIsMissing(root.parent.body)) { return false; } return true; @@ -19476,7 +19924,7 @@ var ts; var current = node; while (current) { if (getNodeCheckFlags(current) & 4) { - var isDeclaration_1 = node.kind !== 67; + var isDeclaration_1 = node.kind !== 69; if (isDeclaration_1) { error(node.name, ts.Diagnostics.Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference); } @@ -19497,7 +19945,7 @@ var ts; return; } if (ts.getClassExtendsHeritageClauseElement(enclosingClass)) { - var isDeclaration_2 = node.kind !== 67; + var isDeclaration_2 = node.kind !== 69; if (isDeclaration_2) { error(node, ts.Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference); } @@ -19510,11 +19958,11 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 216 && ts.getModuleInstanceState(node) !== 1) { + if (node.kind === 218 && ts.getModuleInstanceState(node) !== 1) { return; } var parent = getDeclarationContainer(node); - if (parent.kind === 246 && ts.isExternalModule(parent)) { + if (parent.kind === 248 && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name)); } } @@ -19522,7 +19970,7 @@ var ts; if ((ts.getCombinedNodeFlags(node) & 49152) !== 0 || ts.isParameterDeclaration(node)) { return; } - if (node.kind === 209 && !node.initializer) { + if (node.kind === 211 && !node.initializer) { return; } var symbol = getSymbolOfNode(node); @@ -19532,15 +19980,15 @@ var ts; localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & 2) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 49152) { - var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 210); - var container = varDeclList.parent.kind === 191 && varDeclList.parent.parent + var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 212); + var container = varDeclList.parent.kind === 193 && varDeclList.parent.parent ? varDeclList.parent.parent : undefined; var namesShareScope = container && - (container.kind === 190 && ts.isFunctionLike(container.parent) || - container.kind === 217 || - container.kind === 216 || - container.kind === 246); + (container.kind === 192 && ts.isFunctionLike(container.parent) || + container.kind === 219 || + container.kind === 218 || + container.kind === 248); if (!namesShareScope) { var name_15 = symbolToString(localDeclarationSymbol); error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_15, name_15); @@ -19550,16 +19998,16 @@ var ts; } } function checkParameterInitializer(node) { - if (ts.getRootDeclaration(node).kind !== 136) { + if (ts.getRootDeclaration(node).kind !== 138) { return; } var func = ts.getContainingFunction(node); visit(node.initializer); function visit(n) { - if (n.kind === 67) { + if (n.kind === 69) { var referencedSymbol = getNodeLinks(n).resolvedSymbol; if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455) === referencedSymbol) { - if (referencedSymbol.valueDeclaration.kind === 136) { + if (referencedSymbol.valueDeclaration.kind === 138) { if (referencedSymbol.valueDeclaration === node) { error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name)); return; @@ -19579,7 +20027,7 @@ var ts; function checkVariableLikeDeclaration(node) { checkDecorators(node); checkSourceElement(node.type); - if (node.name.kind === 134) { + if (node.name.kind === 136) { checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); @@ -19588,7 +20036,7 @@ var ts; if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } - if (node.initializer && ts.getRootDeclaration(node).kind === 136 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { + if (node.initializer && ts.getRootDeclaration(node).kind === 138 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -19616,9 +20064,9 @@ var ts; checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } } - if (node.kind !== 139 && node.kind !== 138) { + if (node.kind !== 141 && node.kind !== 140) { checkExportsOnMergedDeclarations(node); - if (node.kind === 209 || node.kind === 161) { + if (node.kind === 211 || node.kind === 163) { checkVarDeclaredNamesNotShadowed(node); } checkCollisionWithCapturedSuperVariable(node, node.name); @@ -19639,7 +20087,7 @@ var ts; ts.forEach(node.declarationList.declarations, checkSourceElement); } function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) { - if (node.modifiers && node.parent.kind === 163) { + if (node.modifiers && node.parent.kind === 165) { if (ts.isAsyncFunctionLike(node)) { if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); @@ -19672,12 +20120,12 @@ var ts; } function checkForStatement(node) { if (!checkGrammarStatementInAmbientContext(node)) { - if (node.initializer && node.initializer.kind === 210) { + if (node.initializer && node.initializer.kind === 212) { checkGrammarVariableDeclarationList(node.initializer); } } if (node.initializer) { - if (node.initializer.kind === 210) { + if (node.initializer.kind === 212) { ts.forEach(node.initializer.declarations, checkVariableDeclaration); } else { @@ -19692,13 +20140,13 @@ var ts; } function checkForOfStatement(node) { checkGrammarForInOrForOfStatement(node); - if (node.initializer.kind === 210) { + if (node.initializer.kind === 212) { checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; var iteratedType = checkRightHandSideOfForOf(node.expression); - if (varExpr.kind === 162 || varExpr.kind === 163) { + if (varExpr.kind === 164 || varExpr.kind === 165) { checkDestructuringAssignment(varExpr, iteratedType || unknownType); } else { @@ -19713,7 +20161,7 @@ var ts; } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); - if (node.initializer.kind === 210) { + if (node.initializer.kind === 212) { var variable = node.initializer.declarations[0]; if (variable && ts.isBindingPattern(variable.name)) { error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); @@ -19723,7 +20171,7 @@ var ts; else { var varExpr = node.initializer; var leftType = checkExpression(varExpr); - if (varExpr.kind === 162 || varExpr.kind === 163) { + if (varExpr.kind === 164 || varExpr.kind === 165) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258)) { @@ -19885,7 +20333,7 @@ var ts; checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } function isGetAccessorWithAnnotatatedSetAccessor(node) { - return !!(node.kind === 143 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 144))); + return !!(node.kind === 145 && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 146))); } function checkReturnStatement(node) { if (!checkGrammarStatementInAmbientContext(node)) { @@ -19903,10 +20351,10 @@ var ts; if (func.asteriskToken) { return; } - if (func.kind === 144) { + if (func.kind === 146) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else if (func.kind === 142) { + else if (func.kind === 144) { if (!isTypeAssignableTo(exprType, returnType)) { error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } @@ -19915,7 +20363,9 @@ var ts; if (ts.isAsyncFunctionLike(func)) { var promisedType = getPromisedType(returnType); var awaitedType = checkAwaitedType(exprType, node.expression, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); - checkTypeAssignableTo(awaitedType, promisedType, node.expression); + if (promisedType) { + checkTypeAssignableTo(awaitedType, promisedType, node.expression); + } } else { checkTypeAssignableTo(exprType, returnType, node.expression); @@ -19939,7 +20389,7 @@ var ts; var hasDuplicateDefaultClause = false; var expressionType = checkExpression(node.expression); ts.forEach(node.caseBlock.clauses, function (clause) { - if (clause.kind === 240 && !hasDuplicateDefaultClause) { + if (clause.kind === 242 && !hasDuplicateDefaultClause) { if (firstDefaultClause === undefined) { firstDefaultClause = clause; } @@ -19951,7 +20401,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (produceDiagnostics && clause.kind === 239) { + if (produceDiagnostics && clause.kind === 241) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); if (!isTypeAssignableTo(expressionType, caseType)) { @@ -19968,7 +20418,7 @@ var ts; if (ts.isFunctionLike(current)) { break; } - if (current.kind === 205 && current.label.text === node.label.text) { + if (current.kind === 207 && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -19994,7 +20444,7 @@ var ts; var catchClause = node.catchClause; if (catchClause) { if (catchClause.variableDeclaration) { - if (catchClause.variableDeclaration.name.kind !== 67) { + if (catchClause.variableDeclaration.name.kind !== 69) { grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); } else if (catchClause.variableDeclaration.type) { @@ -20062,7 +20512,7 @@ var ts; return; } var errorNode; - if (prop.valueDeclaration.name.kind === 134 || prop.parent === containingType.symbol) { + if (prop.valueDeclaration.name.kind === 136 || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { @@ -20132,6 +20582,7 @@ var ts; checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { @@ -20150,7 +20601,7 @@ var ts; } } } - checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32)) { var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments); @@ -20163,7 +20614,8 @@ var ts; } var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node); if (implementedTypeNodes) { - ts.forEach(implementedTypeNodes, function (typeRefNode) { + for (var _b = 0; _b < implementedTypeNodes.length; _b++) { + var typeRefNode = implementedTypeNodes[_b]; if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) { error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments); } @@ -20173,14 +20625,14 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096) ? t.target : t; if (declaredType.flags & (1024 | 2048)) { - checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(t, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); } } } - }); + } } if (produceDiagnostics) { checkIndexConstraints(type); @@ -20208,7 +20660,7 @@ var ts; if (derived === base) { var derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol); if (baseDeclarationFlags & 256 && (!derivedClassDecl || !(derivedClassDecl.flags & 256))) { - if (derivedClassDecl.kind === 184) { + if (derivedClassDecl.kind === 186) { error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, symbolToString(baseProperty), typeToString(baseType)); } else { @@ -20252,7 +20704,7 @@ var ts; } } function isAccessor(kind) { - return kind === 143 || kind === 144; + return kind === 145 || kind === 146; } function areTypeParametersIdentical(list1, list2) { if (!list1 && !list2) { @@ -20289,7 +20741,7 @@ var ts; var ok = true; for (var _i = 0; _i < baseTypes.length; _i++) { var base = baseTypes[_i]; - var properties = getPropertiesOfObjectType(base); + var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType)); for (var _a = 0; _a < properties.length; _a++) { var prop = properties[_a]; if (!ts.hasProperty(seen, prop.name)) { @@ -20318,7 +20770,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 213); + var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 215); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -20326,17 +20778,19 @@ var ts; } if (node === firstInterfaceDecl) { var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); if (checkInheritedPropertiesAreIdentical(type, node.name)) { - ts.forEach(getBaseTypes(type), function (baseType) { - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); - }); + for (var _i = 0, _a = getBaseTypes(type); _i < _a.length; _i++) { + var baseType = _a[_i]; + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); + } checkIndexConstraints(type); } } if (symbol && symbol.declarations) { - for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { - var declaration = _a[_i]; - if (declaration.kind === 212 && !ts.isInAmbientContext(declaration)) { + for (var _b = 0, _c = symbol.declarations; _b < _c.length; _b++) { + var declaration = _c[_b]; + if (declaration.kind === 214 && !ts.isInAmbientContext(declaration)) { error(node, ts.Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface); break; } @@ -20367,10 +20821,15 @@ var ts; var autoValue = 0; var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); - ts.forEach(node.members, function (member) { - if (member.name.kind !== 134 && isNumericLiteralName(member.name.text)) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.name.kind === 136) { + error(member.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); + } + else if (isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } + var previousEnumMemberIsNonConstant = autoValue === undefined; var initializer = member.initializer; if (initializer) { autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient); @@ -20378,10 +20837,13 @@ var ts; else if (ambient && !enumIsConst) { autoValue = undefined; } + else if (previousEnumMemberIsNonConstant) { + error(member.name, ts.Diagnostics.Enum_member_must_have_initializer); + } if (autoValue !== undefined) { getNodeLinks(member).enumMemberValue = autoValue++; } - }); + } nodeLinks.flags |= 8192; } function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) { @@ -20392,7 +20854,10 @@ var ts; if (enumIsConst) { error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); } - else if (!ambient) { + else if (ambient) { + error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression); + } + else { checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, undefined); } } @@ -20408,7 +20873,7 @@ var ts; return value; function evalConstant(e) { switch (e.kind) { - case 177: + case 179: var value_1 = evalConstant(e.operand); if (value_1 === undefined) { return undefined; @@ -20416,10 +20881,10 @@ var ts; switch (e.operator) { case 35: return value_1; case 36: return -value_1; - case 49: return ~value_1; + case 50: return ~value_1; } return undefined; - case 179: + case 181: var left = evalConstant(e.left); if (left === undefined) { return undefined; @@ -20429,37 +20894,37 @@ var ts; return undefined; } switch (e.operatorToken.kind) { - case 46: return left | right; - case 45: return left & right; - case 43: return left >> right; - case 44: return left >>> right; - case 42: return left << right; - case 47: return left ^ right; + case 47: return left | right; + case 46: return left & right; + case 44: return left >> right; + case 45: return left >>> right; + case 43: return left << right; + case 48: return left ^ right; case 37: return left * right; - case 38: return left / right; + case 39: return left / right; case 35: return left + right; case 36: return left - right; - case 39: return left % right; + case 40: return left % right; } return undefined; case 8: return +e.text; - case 170: + case 172: return evalConstant(e.expression); - case 67: - case 165: - case 164: + case 69: + case 167: + case 166: var member = initializer.parent; var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); var enumType_1; var propertyName; - if (e.kind === 67) { + if (e.kind === 69) { enumType_1 = currentType; propertyName = e.text; } else { var expression; - if (e.kind === 165) { + if (e.kind === 167) { if (e.argumentExpression === undefined || e.argumentExpression.kind !== 9) { return undefined; @@ -20473,10 +20938,10 @@ var ts; } var current = expression; while (current) { - if (current.kind === 67) { + if (current.kind === 69) { break; } - else if (current.kind === 164) { + else if (current.kind === 166) { current = current.expression; } else { @@ -20499,7 +20964,7 @@ var ts; if (member === propertyDecl) { return undefined; } - if (!isDefinedBefore(propertyDecl, member)) { + if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) { reportError = false; error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums); return undefined; @@ -20513,7 +20978,7 @@ var ts; if (!produceDiagnostics) { return; } - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -20535,7 +21000,7 @@ var ts; } var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 215) { + if (declaration.kind !== 217) { return false; } var enumDeclaration = declaration; @@ -20558,8 +21023,8 @@ var ts; var declarations = symbol.declarations; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; - if ((declaration.kind === 212 || - (declaration.kind === 211 && ts.nodeIsPresent(declaration.body))) && + if ((declaration.kind === 214 || + (declaration.kind === 213 && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } @@ -20610,7 +21075,7 @@ var ts; error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged); } } - var mergedClass = ts.getDeclarationOfKind(symbol, 212); + var mergedClass = ts.getDeclarationOfKind(symbol, 214); if (mergedClass && inSameLexicalScope(node, mergedClass)) { getNodeLinks(node).flags |= 32768; @@ -20618,9 +21083,9 @@ var ts; } if (isAmbientExternalModule) { if (!isGlobalSourceFile(node.parent)) { - error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules); + error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces); } - if (isExternalModuleNameRelative(node.name.text)) { + if (ts.isExternalModuleNameRelative(node.name.text)) { error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name); } } @@ -20629,17 +21094,17 @@ var ts; } function getFirstIdentifier(node) { while (true) { - if (node.kind === 133) { + if (node.kind === 135) { node = node.left; } - else if (node.kind === 164) { + else if (node.kind === 166) { node = node.expression; } else { break; } } - ts.Debug.assert(node.kind === 67); + ts.Debug.assert(node.kind === 69); return node; } function checkExternalImportOrExportDeclaration(node) { @@ -20648,14 +21113,14 @@ var ts; error(moduleName, ts.Diagnostics.String_literal_expected); return false; } - var inAmbientExternalModule = node.parent.kind === 217 && node.parent.parent.name.kind === 9; - if (node.parent.kind !== 246 && !inAmbientExternalModule) { - error(moduleName, node.kind === 226 ? + var inAmbientExternalModule = node.parent.kind === 219 && node.parent.parent.name.kind === 9; + if (node.parent.kind !== 248 && !inAmbientExternalModule) { + error(moduleName, node.kind === 228 ? ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace : ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module); return false; } - if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) { + if (inAmbientExternalModule && ts.isExternalModuleNameRelative(moduleName.text)) { error(node, ts.Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name); return false; } @@ -20669,7 +21134,7 @@ var ts; (symbol.flags & 793056 ? 793056 : 0) | (symbol.flags & 1536 ? 1536 : 0); if (target.flags & excludedMeanings) { - var message = node.kind === 228 ? + var message = node.kind === 230 ? ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; error(node, message, symbolToString(symbol)); @@ -20695,7 +21160,7 @@ var ts; checkImportBinding(importClause); } if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222) { + if (importClause.namedBindings.kind === 224) { checkImportBinding(importClause.namedBindings); } else { @@ -20730,8 +21195,8 @@ var ts; } } else { - if (languageVersion >= 2 && !ts.isInAmbientContext(node)) { - grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + if (modulekind === 5 && !ts.isInAmbientContext(node)) { + grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead); } } } @@ -20746,8 +21211,8 @@ var ts; if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { if (node.exportClause) { ts.forEach(node.exportClause.elements, checkExportSpecifier); - var inAmbientExternalModule = node.parent.kind === 217 && node.parent.parent.name.kind === 9; - if (node.parent.kind !== 246 && !inAmbientExternalModule) { + var inAmbientExternalModule = node.parent.kind === 219 && node.parent.parent.name.kind === 9; + if (node.parent.kind !== 248 && !inAmbientExternalModule) { error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace); } } @@ -20760,7 +21225,7 @@ var ts; } } function checkGrammarModuleElementContext(node, errorMessage) { - if (node.parent.kind !== 246 && node.parent.kind !== 217 && node.parent.kind !== 216) { + if (node.parent.kind !== 248 && node.parent.kind !== 219 && node.parent.kind !== 218) { return grammarErrorOnFirstToken(node, errorMessage); } } @@ -20774,15 +21239,15 @@ var ts; if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) { return; } - var container = node.parent.kind === 246 ? node.parent : node.parent.parent; - if (container.kind === 216 && container.name.kind === 67) { + var container = node.parent.kind === 248 ? node.parent : node.parent.parent; + if (container.kind === 218 && container.name.kind === 69) { error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace); return; } if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - if (node.expression.kind === 67) { + if (node.expression.kind === 69) { markExportAsReferenced(node); } else { @@ -20790,19 +21255,19 @@ var ts; } checkExternalModuleExports(container); if (node.isExportEquals && !ts.isInAmbientContext(node)) { - if (languageVersion >= 2) { - grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + if (modulekind === 5) { + grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead); } - else if (compilerOptions.module === 4) { + else if (modulekind === 4) { grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); } } } function getModuleStatements(node) { - if (node.kind === 246) { + if (node.kind === 248) { return node.statements; } - if (node.kind === 216 && node.body.kind === 217) { + if (node.kind === 218 && node.body.kind === 219) { return node.body.statements; } return emptyArray; @@ -20839,183 +21304,182 @@ var ts; var kind = node.kind; if (cancellationToken) { switch (kind) { - case 216: - case 212: + case 218: + case 214: + case 215: case 213: - case 211: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { - case 135: + case 137: return checkTypeParameter(node); - case 136: - return checkParameter(node); - case 139: case 138: - return checkPropertyDeclaration(node); - case 150: - case 151: - case 145: - case 146: - return checkSignatureDeclaration(node); - case 147: - return checkSignatureDeclaration(node); + return checkParameter(node); case 141: case 140: - return checkMethodDeclaration(node); - case 142: - return checkConstructorDeclaration(node); - case 143: - case 144: - return checkAccessorDeclaration(node); - case 149: - return checkTypeReferenceNode(node); - case 148: - return checkTypePredicate(node); + return checkPropertyDeclaration(node); case 152: - return checkTypeQuery(node); case 153: - return checkTypeLiteral(node); + case 147: + case 148: + return checkSignatureDeclaration(node); + case 149: + return checkSignatureDeclaration(node); + case 143: + case 142: + return checkMethodDeclaration(node); + case 144: + return checkConstructorDeclaration(node); + case 145: + case 146: + return checkAccessorDeclaration(node); + case 151: + return checkTypeReferenceNode(node); + case 150: + return checkTypePredicate(node); case 154: - return checkArrayType(node); + return checkTypeQuery(node); case 155: - return checkTupleType(node); + return checkTypeLiteral(node); case 156: + return checkArrayType(node); case 157: - return checkUnionOrIntersectionType(node); + return checkTupleType(node); case 158: + case 159: + return checkUnionOrIntersectionType(node); + case 160: return checkSourceElement(node.type); - case 211: - return checkFunctionDeclaration(node); - case 190: - case 217: - return checkBlock(node); - case 191: - return checkVariableStatement(node); - case 193: - return checkExpressionStatement(node); - case 194: - return checkIfStatement(node); - case 195: - return checkDoStatement(node); - case 196: - return checkWhileStatement(node); - case 197: - return checkForStatement(node); - case 198: - return checkForInStatement(node); - case 199: - return checkForOfStatement(node); - case 200: - case 201: - return checkBreakOrContinueStatement(node); - case 202: - return checkReturnStatement(node); - case 203: - return checkWithStatement(node); - case 204: - return checkSwitchStatement(node); - case 205: - return checkLabeledStatement(node); - case 206: - return checkThrowStatement(node); - case 207: - return checkTryStatement(node); - case 209: - return checkVariableDeclaration(node); - case 161: - return checkBindingElement(node); - case 212: - return checkClassDeclaration(node); case 213: - return checkInterfaceDeclaration(node); - case 214: - return checkTypeAliasDeclaration(node); - case 215: - return checkEnumDeclaration(node); - case 216: - return checkModuleDeclaration(node); - case 220: - return checkImportDeclaration(node); - case 219: - return checkImportEqualsDeclaration(node); - case 226: - return checkExportDeclaration(node); - case 225: - return checkExportAssignment(node); + return checkFunctionDeclaration(node); case 192: - checkGrammarStatementInAmbientContext(node); - return; + case 219: + return checkBlock(node); + case 193: + return checkVariableStatement(node); + case 195: + return checkExpressionStatement(node); + case 196: + return checkIfStatement(node); + case 197: + return checkDoStatement(node); + case 198: + return checkWhileStatement(node); + case 199: + return checkForStatement(node); + case 200: + return checkForInStatement(node); + case 201: + return checkForOfStatement(node); + case 202: + case 203: + return checkBreakOrContinueStatement(node); + case 204: + return checkReturnStatement(node); + case 205: + return checkWithStatement(node); + case 206: + return checkSwitchStatement(node); + case 207: + return checkLabeledStatement(node); case 208: + return checkThrowStatement(node); + case 209: + return checkTryStatement(node); + case 211: + return checkVariableDeclaration(node); + case 163: + return checkBindingElement(node); + case 214: + return checkClassDeclaration(node); + case 215: + return checkInterfaceDeclaration(node); + case 216: + return checkTypeAliasDeclaration(node); + case 217: + return checkEnumDeclaration(node); + case 218: + return checkModuleDeclaration(node); + case 222: + return checkImportDeclaration(node); + case 221: + return checkImportEqualsDeclaration(node); + case 228: + return checkExportDeclaration(node); + case 227: + return checkExportAssignment(node); + case 194: checkGrammarStatementInAmbientContext(node); return; - case 229: + case 210: + checkGrammarStatementInAmbientContext(node); + return; + case 231: return checkMissingDeclaration(node); } } function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { - case 171: - case 172: + case 173: + case 174: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case 184: + case 186: ts.forEach(node.members, checkSourceElement); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; - case 141: - case 140: + case 143: + case 142: ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } break; - case 142: - case 143: case 144: - case 211: + case 145: + case 146: + case 213: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; - case 203: + case 205: checkFunctionAndClassExpressionBodies(node.expression); break; - case 137: - case 136: case 139: case 138: - case 159: - case 160: + case 141: + case 140: case 161: case 162: case 163: - case 243: case 164: case 165: + case 245: case 166: case 167: case 168: - case 181: - case 188: case 169: - case 187: case 170: - case 174: - case 175: + case 183: + case 190: + case 171: + case 189: + case 172: case 176: - case 173: case 177: case 178: + case 175: case 179: case 180: - case 183: + case 181: case 182: - case 190: - case 217: - case 191: + case 185: + case 184: + case 192: + case 219: case 193: - case 194: case 195: case 196: case 197: @@ -21024,29 +21488,31 @@ var ts; case 200: case 201: case 202: + case 203: case 204: - case 218: - case 239: - case 240: - case 205: case 206: - case 207: - case 242: - case 209: - case 210: - case 212: + case 220: case 241: - case 186: - case 215: - case 245: - case 225: - case 246: - case 238: - case 231: - case 232: - case 236: - case 237: + case 242: + case 207: + case 208: + case 209: + case 244: + case 211: + case 212: + case 214: + case 243: + case 188: + case 217: + case 247: + case 227: + case 248: + case 240: case 233: + case 234: + case 238: + case 239: + case 235: ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } @@ -21124,7 +21590,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 203 && node.parent.statement === node) { + if (node.parent.kind === 205 && node.parent.statement === node) { return true; } node = node.parent; @@ -21146,28 +21612,28 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 246: + case 248: if (!ts.isExternalModule(location)) { break; } - case 216: + case 218: copySymbols(getSymbolOfNode(location).exports, meaning & 8914931); break; - case 215: + case 217: copySymbols(getSymbolOfNode(location).exports, meaning & 8); break; - case 184: + case 186: var className = location.name; if (className) { copySymbol(location.symbol, meaning); } - case 212: - case 213: + case 214: + case 215: if (!(memberFlags & 128)) { copySymbols(getSymbolOfNode(location).members, meaning & 793056); } break; - case 171: + case 173: var funcName = location.name; if (funcName) { copySymbol(location.symbol, meaning); @@ -21200,42 +21666,42 @@ var ts; } } function isTypeDeclarationName(name) { - return name.kind === 67 && + return name.kind === 69 && isTypeDeclaration(name.parent) && name.parent.name === name; } function isTypeDeclaration(node) { switch (node.kind) { - case 135: - case 212: - case 213: + case 137: case 214: case 215: + case 216: + case 217: return true; } } function isTypeReferenceIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 133) { + while (node.parent && node.parent.kind === 135) { node = node.parent; } - return node.parent && node.parent.kind === 149; + return node.parent && node.parent.kind === 151; } function isHeritageClauseElementIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 164) { + while (node.parent && node.parent.kind === 166) { node = node.parent; } - return node.parent && node.parent.kind === 186; + return node.parent && node.parent.kind === 188; } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { - while (nodeOnRightSide.parent.kind === 133) { + while (nodeOnRightSide.parent.kind === 135) { nodeOnRightSide = nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 219) { + if (nodeOnRightSide.parent.kind === 221) { return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 225) { + if (nodeOnRightSide.parent.kind === 227) { return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; @@ -21247,10 +21713,10 @@ var ts; if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 225) { + if (entityName.parent.kind === 227) { return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608); } - if (entityName.kind !== 164) { + if (entityName.kind !== 166) { if (isInRightSideOfImportOrExportAssignment(entityName)) { return getSymbolOfPartOfRightHandSideOfImportEquals(entityName); } @@ -21259,31 +21725,40 @@ var ts; entityName = entityName.parent; } if (isHeritageClauseElementIdentifier(entityName)) { - var meaning = entityName.parent.kind === 186 ? 793056 : 1536; + var meaning = 0; + if (entityName.parent.kind === 188) { + meaning = 793056; + if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent)) { + meaning |= 107455; + } + } + else { + meaning = 1536; + } meaning |= 8388608; return resolveEntityName(entityName, meaning); } - else if ((entityName.parent.kind === 233) || - (entityName.parent.kind === 232) || - (entityName.parent.kind === 235)) { + else if ((entityName.parent.kind === 235) || + (entityName.parent.kind === 234) || + (entityName.parent.kind === 237)) { return getJsxElementTagSymbol(entityName.parent); } else if (ts.isExpression(entityName)) { if (ts.nodeIsMissing(entityName)) { return undefined; } - if (entityName.kind === 67) { + if (entityName.kind === 69) { var meaning = 107455 | 8388608; return resolveEntityName(entityName, meaning); } - else if (entityName.kind === 164) { + else if (entityName.kind === 166) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccessExpression(entityName); } return getNodeLinks(entityName).resolvedSymbol; } - else if (entityName.kind === 133) { + else if (entityName.kind === 135) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkQualifiedName(entityName); @@ -21292,14 +21767,14 @@ var ts; } } else if (isTypeReferenceIdentifier(entityName)) { - var meaning = entityName.parent.kind === 149 ? 793056 : 1536; + var meaning = entityName.parent.kind === 151 ? 793056 : 1536; meaning |= 8388608; return resolveEntityName(entityName, meaning); } - else if (entityName.parent.kind === 236) { + else if (entityName.parent.kind === 238) { return getJsxAttributePropertySymbol(entityName.parent); } - if (entityName.parent.kind === 148) { + if (entityName.parent.kind === 150) { return resolveEntityName(entityName, 1); } return undefined; @@ -21311,14 +21786,14 @@ var ts; if (ts.isDeclarationName(node)) { return getSymbolOfNode(node.parent); } - if (node.kind === 67) { + if (node.kind === 69) { if (isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 225 + return node.parent.kind === 227 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImportEquals(node); } - else if (node.parent.kind === 161 && - node.parent.parent.kind === 159 && + else if (node.parent.kind === 163 && + node.parent.parent.kind === 161 && node === node.parent.propertyName) { var typeOfPattern = getTypeOfNode(node.parent.parent); var propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, node.text); @@ -21328,29 +21803,29 @@ var ts; } } switch (node.kind) { - case 67: - case 164: - case 133: + case 69: + case 166: + case 135: return getSymbolOfEntityNameOrPropertyAccessExpression(node); + case 97: case 95: - case 93: - var type = checkExpression(node); + var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; - case 119: + case 121: var constructorDeclaration = node.parent; - if (constructorDeclaration && constructorDeclaration.kind === 142) { + if (constructorDeclaration && constructorDeclaration.kind === 144) { return constructorDeclaration.parent.symbol; } return undefined; case 9: if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || - ((node.parent.kind === 220 || node.parent.kind === 226) && + ((node.parent.kind === 222 || node.parent.kind === 228) && node.parent.moduleSpecifier === node)) { return resolveExternalModuleName(node, node); } case 8: - if (node.parent.kind === 165 && node.parent.argumentExpression === node) { + if (node.parent.kind === 167 && node.parent.argumentExpression === node) { var objectType = checkExpression(node.parent.expression); if (objectType === unknownType) return undefined; @@ -21364,7 +21839,7 @@ var ts; return undefined; } function getShorthandAssignmentValueSymbol(location) { - if (location && location.kind === 244) { + if (location && location.kind === 246) { return resolveEntityName(location.name, 107455); } return undefined; @@ -21464,11 +21939,11 @@ var ts; } var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { - if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 246) { + if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 248) { return parentSymbol.valueDeclaration; } for (var n = node.parent; n; n = n.parent) { - if ((n.kind === 216 || n.kind === 215) && getSymbolOfNode(n) === parentSymbol) { + if ((n.kind === 218 || n.kind === 217) && getSymbolOfNode(n) === parentSymbol) { return n; } } @@ -21481,11 +21956,11 @@ var ts; } function isStatementWithLocals(node) { switch (node.kind) { - case 190: - case 218: - case 197: - case 198: + case 192: + case 220: case 199: + case 200: + case 201: return true; } return false; @@ -21511,22 +21986,22 @@ var ts; } function isValueAliasDeclaration(node) { switch (node.kind) { - case 219: case 221: - case 222: + case 223: case 224: - case 228: - return isAliasResolvedToValue(getSymbolOfNode(node)); case 226: + case 230: + return isAliasResolvedToValue(getSymbolOfNode(node)); + case 228: var exportClause = node.exportClause; return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration); - case 225: - return node.expression && node.expression.kind === 67 ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; + case 227: + return node.expression && node.expression.kind === 69 ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; } return false; } function isTopLevelValueImportEqualsWithEntityName(node) { - if (node.parent.kind !== 246 || !ts.isInternalModuleImportEqualsDeclaration(node)) { + if (node.parent.kind !== 248 || !ts.isInternalModuleImportEqualsDeclaration(node)) { return false; } var isValue = isAliasResolvedToValue(getSymbolOfNode(node)); @@ -21574,7 +22049,7 @@ var ts; return getNodeLinks(node).enumMemberValue; } function getConstantValue(node) { - if (node.kind === 245) { + if (node.kind === 247) { return getEnumMemberValue(node); } var symbol = getNodeLinks(node).resolvedSymbol; @@ -21660,21 +22135,6 @@ var ts; var symbol = getReferencedValueSymbol(reference); return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } - function getBlockScopedVariableId(n) { - ts.Debug.assert(!ts.nodeIsSynthesized(n)); - var isVariableDeclarationOrBindingElement = n.parent.kind === 161 || (n.parent.kind === 209 && n.parent.name === n); - var symbol = (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) || - getNodeLinks(n).resolvedSymbol || - resolveName(n, n.text, 107455 | 8388608, undefined, undefined); - var isLetOrConst = symbol && - (symbol.flags & 2) && - symbol.valueDeclaration.parent.kind !== 242; - if (isLetOrConst) { - getSymbolLinks(symbol); - return symbol.id; - } - return undefined; - } function instantiateSingleCallFunctionType(functionType, typeArguments) { if (functionType === unknownType) { return unknownType; @@ -21706,7 +22166,6 @@ var ts; isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, collectLinkedAliases: collectLinkedAliases, - getBlockScopedVariableId: getBlockScopedVariableId, getReferencedValueDeclaration: getReferencedValueDeclaration, getTypeReferenceSerializationKind: getTypeReferenceSerializationKind, isOptionalParameter: isOptionalParameter @@ -21787,10 +22246,7 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here); } - else if (languageVersion < 1) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (node.kind === 143 || node.kind === 144) { + else if (node.kind === 145 || node.kind === 146) { var accessors = ts.getAllAccessorDeclarations(node.parent.members, node); if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name); @@ -21800,38 +22256,38 @@ var ts; } function checkGrammarModifiers(node) { switch (node.kind) { - case 143: + case 145: + case 146: case 144: - case 142: - case 139: - case 138: case 141: case 140: - case 147: - case 216: - case 220: - case 219: - case 226: - case 225: - case 136: + case 143: + case 142: + case 149: + case 218: + case 222: + case 221: + case 228: + case 227: + case 138: break; - case 211: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 116) && - node.parent.kind !== 217 && node.parent.kind !== 246) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); - } - break; - case 212: case 213: - case 191: - case 214: - if (node.modifiers && node.parent.kind !== 217 && node.parent.kind !== 246) { + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 118) && + node.parent.kind !== 219 && node.parent.kind !== 248) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; + case 214: case 215: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 72) && - node.parent.kind !== 217 && node.parent.kind !== 246) { + case 193: + case 216: + if (node.modifiers && node.parent.kind !== 219 && node.parent.kind !== 248) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; + case 217: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 74) && + node.parent.kind !== 219 && node.parent.kind !== 248) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; @@ -21846,14 +22302,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { + case 112: + case 111: case 110: - case 109: - case 108: var text = void 0; - if (modifier.kind === 110) { + if (modifier.kind === 112) { text = "public"; } - else if (modifier.kind === 109) { + else if (modifier.kind === 111) { text = "protected"; lastProtected = modifier; } @@ -21870,11 +22326,11 @@ var ts; else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); } - else if (node.parent.kind === 217 || node.parent.kind === 246) { + else if (node.parent.kind === 219 || node.parent.kind === 248) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); } else if (flags & 256) { - if (modifier.kind === 108) { + if (modifier.kind === 110) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract"); } else { @@ -21883,17 +22339,17 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 111: + case 113: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } - else if (node.parent.kind === 217 || node.parent.kind === 246) { + else if (node.parent.kind === 219 || node.parent.kind === 248) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } else if (flags & 256) { @@ -21902,7 +22358,7 @@ var ts; flags |= 128; lastStatic = modifier; break; - case 80: + case 82: if (flags & 1) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); } @@ -21915,42 +22371,42 @@ var ts; else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= 1; break; - case 120: + case 122: if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } else if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } - else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 217) { + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 219) { return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= 2; lastDeclare = modifier; break; - case 113: + case 115: if (flags & 256) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract"); } - if (node.kind !== 212) { - if (node.kind !== 141) { + if (node.kind !== 214) { + if (node.kind !== 143) { return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration); } - if (!(node.parent.kind === 212 && node.parent.flags & 256)) { + if (!(node.parent.kind === 214 && node.parent.flags & 256)) { return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); } if (flags & 128) { @@ -21962,14 +22418,14 @@ var ts; } flags |= 256; break; - case 116: + case 118: if (flags & 512) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async"); } else if (flags & 2 || ts.isInAmbientContext(node.parent)) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.kind === 136) { + else if (node.kind === 138) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); } flags |= 512; @@ -21977,7 +22433,7 @@ var ts; break; } } - if (node.kind === 142) { + if (node.kind === 144) { if (flags & 128) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); } @@ -21995,10 +22451,10 @@ var ts; } return; } - else if ((node.kind === 220 || node.kind === 219) && flags & 2) { + else if ((node.kind === 222 || node.kind === 221) && flags & 2) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 136 && (flags & 112) && ts.isBindingPattern(node.name)) { + else if (node.kind === 138 && (flags & 112) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } if (flags & 512) { @@ -22010,10 +22466,10 @@ var ts; return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher); } switch (node.kind) { - case 141: - case 211: - case 171: - case 172: + case 143: + case 213: + case 173: + case 174: if (!node.asteriskToken) { return false; } @@ -22078,7 +22534,7 @@ var ts; checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } function checkGrammarArrowFunction(node, file) { - if (node.kind === 172) { + if (node.kind === 174) { var arrowFunction = node; var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line; var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line; @@ -22113,7 +22569,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 128 && parameter.type.kind !== 126) { + if (parameter.type.kind !== 130 && parameter.type.kind !== 128) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -22145,7 +22601,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var _i = 0; _i < args.length; _i++) { var arg = args[_i]; - if (arg.kind === 185) { + if (arg.kind === 187) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -22172,7 +22628,7 @@ var ts; if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81) { + if (heritageClause.token === 83) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } @@ -22185,7 +22641,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104); + ts.Debug.assert(heritageClause.token === 106); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -22200,14 +22656,14 @@ var ts; if (node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81) { + if (heritageClause.token === 83) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104); + ts.Debug.assert(heritageClause.token === 106); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -22216,19 +22672,19 @@ var ts; return false; } function checkGrammarComputedPropertyName(node) { - if (node.kind !== 134) { + if (node.kind !== 136) { return false; } var computedPropertyName = node; - if (computedPropertyName.expression.kind === 179 && computedPropertyName.expression.operatorToken.kind === 24) { + if (computedPropertyName.expression.kind === 181 && computedPropertyName.expression.operatorToken.kind === 24) { return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - ts.Debug.assert(node.kind === 211 || - node.kind === 171 || - node.kind === 141); + ts.Debug.assert(node.kind === 213 || + node.kind === 173 || + node.kind === 143); if (ts.isInAmbientContext(node)) { return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); } @@ -22245,7 +22701,7 @@ var ts; return grammarErrorOnNode(questionToken, message); } } - function checkGrammarObjectLiteralExpression(node) { + function checkGrammarObjectLiteralExpression(node, inDestructuring) { var seen = {}; var Property = 1; var GetAccessor = 2; @@ -22254,26 +22710,29 @@ var ts; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; var name_17 = prop.name; - if (prop.kind === 185 || - name_17.kind === 134) { + if (prop.kind === 187 || + name_17.kind === 136) { checkGrammarComputedPropertyName(name_17); continue; } + if (prop.kind === 246 && !inDestructuring && prop.objectAssignmentInitializer) { + return grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment); + } var currentKind = void 0; - if (prop.kind === 243 || prop.kind === 244) { + if (prop.kind === 245 || prop.kind === 246) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); if (name_17.kind === 8) { checkGrammarNumericLiteral(name_17); } currentKind = Property; } - else if (prop.kind === 141) { + else if (prop.kind === 143) { currentKind = Property; } - else if (prop.kind === 143) { + else if (prop.kind === 145) { currentKind = GetAccessor; } - else if (prop.kind === 144) { + else if (prop.kind === 146) { currentKind = SetAccesor; } else { @@ -22305,7 +22764,7 @@ var ts; var seen = {}; for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) { var attr = _a[_i]; - if (attr.kind === 237) { + if (attr.kind === 239) { continue; } var jsxAttr = attr; @@ -22317,7 +22776,7 @@ var ts; return grammarErrorOnNode(name_18, ts.Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name); } var initializer = jsxAttr.initializer; - if (initializer && initializer.kind === 238 && !initializer.expression) { + if (initializer && initializer.kind === 240 && !initializer.expression) { return grammarErrorOnNode(jsxAttr.initializer, ts.Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression); } } @@ -22326,24 +22785,24 @@ var ts; if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) { return true; } - if (forInOrOfStatement.initializer.kind === 210) { + if (forInOrOfStatement.initializer.kind === 212) { var variableList = forInOrOfStatement.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { - var diagnostic = forInOrOfStatement.kind === 198 + var diagnostic = forInOrOfStatement.kind === 200 ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic); } var firstDeclaration = variableList.declarations[0]; if (firstDeclaration.initializer) { - var diagnostic = forInOrOfStatement.kind === 198 + var diagnostic = forInOrOfStatement.kind === 200 ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; return grammarErrorOnNode(firstDeclaration.name, diagnostic); } if (firstDeclaration.type) { - var diagnostic = forInOrOfStatement.kind === 198 + var diagnostic = forInOrOfStatement.kind === 200 ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; return grammarErrorOnNode(firstDeclaration, diagnostic); @@ -22366,10 +22825,10 @@ var ts; else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } - else if (kind === 143 && accessor.parameters.length) { + else if (kind === 145 && accessor.parameters.length) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); } - else if (kind === 144) { + else if (kind === 146) { if (accessor.type) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); } @@ -22394,7 +22853,7 @@ var ts; } } function checkGrammarForNonSymbolComputedProperty(node, message) { - if (node.kind === 134 && !ts.isWellKnownSymbolSyntactically(node.expression)) { + if (node.kind === 136 && !ts.isWellKnownSymbolSyntactically(node.expression)) { return grammarErrorOnNode(node, message); } } @@ -22404,7 +22863,7 @@ var ts; checkGrammarForGenerator(node)) { return true; } - if (node.parent.kind === 163) { + if (node.parent.kind === 165) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -22423,22 +22882,22 @@ var ts; return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol); } } - else if (node.parent.kind === 213) { + else if (node.parent.kind === 215) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol); } - else if (node.parent.kind === 153) { + else if (node.parent.kind === 155) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol); } } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { + case 199: + case 200: + case 201: case 197: case 198: - case 199: - case 195: - case 196: return true; - case 205: + case 207: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -22450,9 +22909,9 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 205: + case 207: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 200 + var isMisplacedContinueLabel = node.kind === 202 && !isIterationStatement(current.statement, true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); @@ -22460,8 +22919,8 @@ var ts; return false; } break; - case 204: - if (node.kind === 201 && !node.label) { + case 206: + if (node.kind === 203 && !node.label) { return false; } break; @@ -22474,13 +22933,13 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 201 + var message = node.kind === 203 ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 201 + var message = node.kind === 203 ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); @@ -22492,7 +22951,7 @@ var ts; if (node !== ts.lastOrUndefined(elements)) { return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); } - if (node.name.kind === 160 || node.name.kind === 159) { + if (node.name.kind === 162 || node.name.kind === 161) { return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); } if (node.initializer) { @@ -22501,7 +22960,7 @@ var ts; } } function checkGrammarVariableDeclaration(node) { - if (node.parent.parent.kind !== 198 && node.parent.parent.kind !== 199) { + if (node.parent.parent.kind !== 200 && node.parent.parent.kind !== 201) { if (ts.isInAmbientContext(node)) { if (node.initializer) { var equalsTokenLength = "=".length; @@ -22521,7 +22980,7 @@ var ts; return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name); } function checkGrammarNameInLetOrConstDeclarations(name) { - if (name.kind === 67) { + if (name.kind === 69) { if (name.text === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } @@ -22530,7 +22989,7 @@ var ts; var elements = name.elements; for (var _i = 0; _i < elements.length; _i++) { var element = elements[_i]; - if (element.kind !== 185) { + if (element.kind !== 187) { checkGrammarNameInLetOrConstDeclarations(element.name); } } @@ -22547,15 +23006,15 @@ var ts; } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 194: - case 195: case 196: - case 203: case 197: case 198: - case 199: - return false; case 205: + case 199: + case 200: + case 201: + return false; + case 207: return allowLetAndConstDeclarations(parent.parent); } return true; @@ -22571,7 +23030,7 @@ var ts; } } function isIntegerLiteral(expression) { - if (expression.kind === 177) { + if (expression.kind === 179) { var unaryExpression = expression; if (unaryExpression.operator === 35 || unaryExpression.operator === 36) { expression = unaryExpression.operand; @@ -22582,32 +23041,6 @@ var ts; } return false; } - function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 32768) !== 0; - var hasError = false; - if (!enumIsConst) { - var inConstantEnumMemberSection = true; - var inAmbientContext = ts.isInAmbientContext(enumDecl); - for (var _i = 0, _a = enumDecl.members; _i < _a.length; _i++) { - var node = _a[_i]; - if (node.name.kind === 134) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); - } - else if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer)) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; - } - } - else if (node.initializer) { - inConstantEnumMemberSection = isIntegerLiteral(node.initializer); - } - else if (!inConstantEnumMemberSection) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; - } - } - } - return hasError; - } function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } @@ -22633,7 +23066,7 @@ var ts; } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 && + return node.kind === 69 && (node.text === "eval" || node.text === "arguments"); } function checkGrammarConstructorTypeParameters(node) { @@ -22653,12 +23086,12 @@ var ts; return true; } } - else if (node.parent.kind === 213) { + else if (node.parent.kind === 215) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } } - else if (node.parent.kind === 153) { + else if (node.parent.kind === 155) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } @@ -22668,11 +23101,11 @@ var ts; } } function checkGrammarTopLevelElementForRequiredDeclareModifier(node) { - if (node.kind === 213 || - node.kind === 220 || - node.kind === 219 || - node.kind === 226 || - node.kind === 225 || + if (node.kind === 215 || + node.kind === 222 || + node.kind === 221 || + node.kind === 228 || + node.kind === 227 || (node.flags & 2) || (node.flags & (1 | 1024))) { return false; @@ -22682,7 +23115,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var decl = _a[_i]; - if (ts.isDeclaration(decl) || decl.kind === 191) { + if (ts.isDeclaration(decl) || decl.kind === 193) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -22701,7 +23134,7 @@ var ts; if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } - if (node.parent.kind === 190 || node.parent.kind === 217 || node.parent.kind === 246) { + if (node.parent.kind === 192 || node.parent.kind === 219 || node.parent.kind === 248) { var links_1 = getNodeLinks(node.parent); if (!links_1.hasReportedStatementInAmbientContext) { return links_1.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); @@ -22748,6 +23181,7 @@ var ts; var enclosingDeclaration; var currentSourceFile; var reportedDeclarationError = false; + var errorNameNode; var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments; var emit = compilerOptions.stripInternal ? stripInternal : emitNode; var moduleElementDeclarationEmitInfo = []; @@ -22773,7 +23207,7 @@ var ts; var oldWriter = writer; ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) { if (aliasEmitInfo.isVisible) { - ts.Debug.assert(aliasEmitInfo.node.kind === 220); + ts.Debug.assert(aliasEmitInfo.node.kind === 222); createAndSetNewTextWriterWithSymbolWriter(); ts.Debug.assert(aliasEmitInfo.indent === 0); writeImportDeclaration(aliasEmitInfo.node); @@ -22824,6 +23258,7 @@ var ts; function createAndSetNewTextWriterWithSymbolWriter() { var writer = ts.createTextWriter(newLine); writer.trackSymbol = trackSymbol; + writer.reportInaccessibleThisError = reportInaccessibleThisError; writer.writeKeyword = writer.write; writer.writeOperator = writer.write; writer.writePunctuation = writer.write; @@ -22846,10 +23281,10 @@ var ts; var oldWriter = writer; ts.forEach(nodes, function (declaration) { var nodeToCheck; - if (declaration.kind === 209) { + if (declaration.kind === 211) { nodeToCheck = declaration.parent.parent; } - else if (declaration.kind === 223 || declaration.kind === 224 || declaration.kind === 221) { + else if (declaration.kind === 225 || declaration.kind === 226 || declaration.kind === 223) { ts.Debug.fail("We should be getting ImportDeclaration instead to write"); } else { @@ -22860,7 +23295,7 @@ var ts; moduleElementEmitInfo = ts.forEach(asynchronousSubModuleDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; }); } if (moduleElementEmitInfo) { - if (moduleElementEmitInfo.node.kind === 220) { + if (moduleElementEmitInfo.node.kind === 222) { moduleElementEmitInfo.isVisible = true; } else { @@ -22868,12 +23303,12 @@ var ts; for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { increaseIndent(); } - if (nodeToCheck.kind === 216) { + if (nodeToCheck.kind === 218) { ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); asynchronousSubModuleDeclarationEmitInfo = []; } writeModuleElement(nodeToCheck); - if (nodeToCheck.kind === 216) { + if (nodeToCheck.kind === 218) { moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; asynchronousSubModuleDeclarationEmitInfo = undefined; } @@ -22905,6 +23340,11 @@ var ts; function trackSymbol(symbol, enclosingDeclaration, meaning) { handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); } + function reportInaccessibleThisError() { + if (errorNameNode) { + diagnostics.push(ts.createDiagnosticForNode(errorNameNode, ts.Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, ts.declarationNameToString(errorNameNode))); + } + } function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; write(": "); @@ -22912,7 +23352,9 @@ var ts; emitType(type); } else { + errorNameNode = declaration.name; resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2, writer); + errorNameNode = undefined; } } function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { @@ -22922,7 +23364,9 @@ var ts; emitType(signature.type); } else { + errorNameNode = signature.name; resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2, writer); + errorNameNode = undefined; } } function emitLines(nodes) { @@ -22960,62 +23404,63 @@ var ts; } function emitType(type) { switch (type.kind) { - case 115: + case 117: + case 130: case 128: - case 126: - case 118: - case 129: - case 101: + case 120: + case 131: + case 103: + case 97: case 9: return writeTextOfNode(currentSourceFile, type); - case 186: + case 188: return emitExpressionWithTypeArguments(type); - case 149: - return emitTypeReference(type); - case 152: - return emitTypeQuery(type); - case 154: - return emitArrayType(type); - case 155: - return emitTupleType(type); - case 156: - return emitUnionType(type); - case 157: - return emitIntersectionType(type); - case 158: - return emitParenType(type); - case 150: case 151: - return emitSignatureDeclarationWithJsDocComments(type); + return emitTypeReference(type); + case 154: + return emitTypeQuery(type); + case 156: + return emitArrayType(type); + case 157: + return emitTupleType(type); + case 158: + return emitUnionType(type); + case 159: + return emitIntersectionType(type); + case 160: + return emitParenType(type); + case 152: case 153: + return emitSignatureDeclarationWithJsDocComments(type); + case 155: return emitTypeLiteral(type); - case 67: + case 69: return emitEntityName(type); - case 133: + case 135: return emitEntityName(type); - case 148: + case 150: return emitTypePredicate(type); } function writeEntityName(entityName) { - if (entityName.kind === 67) { + if (entityName.kind === 69) { writeTextOfNode(currentSourceFile, entityName); } else { - var left = entityName.kind === 133 ? entityName.left : entityName.expression; - var right = entityName.kind === 133 ? entityName.right : entityName.name; + var left = entityName.kind === 135 ? entityName.left : entityName.expression; + var right = entityName.kind === 135 ? entityName.right : entityName.name; writeEntityName(left); write("."); writeTextOfNode(currentSourceFile, right); } } function emitEntityName(entityName) { - var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 219 ? entityName.parent : enclosingDeclaration); + var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 221 ? entityName.parent : enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); } function emitExpressionWithTypeArguments(node) { if (ts.isSupportedExpressionWithTypeArguments(node)) { - ts.Debug.assert(node.expression.kind === 67 || node.expression.kind === 164); + ts.Debug.assert(node.expression.kind === 69 || node.expression.kind === 166); emitEntityName(node.expression); if (node.typeArguments) { write("<"); @@ -23091,7 +23536,7 @@ var ts; } } function emitExportAssignment(node) { - if (node.expression.kind === 67) { + if (node.expression.kind === 69) { write(node.isExportEquals ? "export = " : "export default "); writeTextOfNode(currentSourceFile, node.expression); } @@ -23109,7 +23554,7 @@ var ts; } write(";"); writeLine(); - if (node.expression.kind === 67) { + if (node.expression.kind === 69) { var nodes = resolver.collectLinkedAliases(node.expression); writeAsynchronousModuleElements(nodes); } @@ -23127,10 +23572,10 @@ var ts; if (isModuleElementVisible) { writeModuleElement(node); } - else if (node.kind === 219 || - (node.parent.kind === 246 && ts.isExternalModule(currentSourceFile))) { + else if (node.kind === 221 || + (node.parent.kind === 248 && ts.isExternalModule(currentSourceFile))) { var isVisible; - if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 246) { + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 248) { asynchronousSubModuleDeclarationEmitInfo.push({ node: node, outputPos: writer.getTextPos(), @@ -23139,7 +23584,7 @@ var ts; }); } else { - if (node.kind === 220) { + if (node.kind === 222) { var importDeclaration = node; if (importDeclaration.importClause) { isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || @@ -23157,23 +23602,23 @@ var ts; } function writeModuleElement(node) { switch (node.kind) { - case 211: - return writeFunctionDeclaration(node); - case 191: - return writeVariableStatement(node); case 213: - return writeInterfaceDeclaration(node); - case 212: - return writeClassDeclaration(node); - case 214: - return writeTypeAliasDeclaration(node); + return writeFunctionDeclaration(node); + case 193: + return writeVariableStatement(node); case 215: - return writeEnumDeclaration(node); + return writeInterfaceDeclaration(node); + case 214: + return writeClassDeclaration(node); case 216: + return writeTypeAliasDeclaration(node); + case 217: + return writeEnumDeclaration(node); + case 218: return writeModuleDeclaration(node); - case 219: + case 221: return writeImportEqualsDeclaration(node); - case 220: + case 222: return writeImportDeclaration(node); default: ts.Debug.fail("Unknown symbol kind"); @@ -23187,7 +23632,7 @@ var ts; if (node.flags & 1024) { write("default "); } - else if (node.kind !== 213) { + else if (node.kind !== 215) { write("declare "); } } @@ -23234,7 +23679,7 @@ var ts; } function isVisibleNamedBinding(namedBindings) { if (namedBindings) { - if (namedBindings.kind === 222) { + if (namedBindings.kind === 224) { return resolver.isDeclarationVisible(namedBindings); } else { @@ -23260,7 +23705,7 @@ var ts; if (currentWriterPos !== writer.getTextPos()) { write(", "); } - if (node.importClause.namedBindings.kind === 222) { + if (node.importClause.namedBindings.kind === 224) { write("* as "); writeTextOfNode(currentSourceFile, node.importClause.namedBindings.name); } @@ -23316,7 +23761,7 @@ var ts; write("module "); } writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 217) { + while (node.body.kind !== 219) { node = node.body; write("."); writeTextOfNode(currentSourceFile, node.name); @@ -23381,7 +23826,7 @@ var ts; writeLine(); } function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 141 && (node.parent.flags & 32); + return node.parent.kind === 143 && (node.parent.flags & 32); } function emitTypeParameters(typeParameters) { function emitTypeParameter(node) { @@ -23391,15 +23836,15 @@ var ts; writeTextOfNode(currentSourceFile, node.name); if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); - if (node.parent.kind === 150 || - node.parent.kind === 151 || - (node.parent.parent && node.parent.parent.kind === 153)) { - ts.Debug.assert(node.parent.kind === 141 || - node.parent.kind === 140 || - node.parent.kind === 150 || - node.parent.kind === 151 || - node.parent.kind === 145 || - node.parent.kind === 146); + if (node.parent.kind === 152 || + node.parent.kind === 153 || + (node.parent.parent && node.parent.parent.kind === 155)) { + ts.Debug.assert(node.parent.kind === 143 || + node.parent.kind === 142 || + node.parent.kind === 152 || + node.parent.kind === 153 || + node.parent.kind === 147 || + node.parent.kind === 148); emitType(node.constraint); } else { @@ -23409,31 +23854,31 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 212: + case 214: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 213: + case 215: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; - case 146: + case 148: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 145: + case 147: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 141: - case 140: + case 143: + case 142: if (node.parent.flags & 128) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212) { + else if (node.parent.parent.kind === 214) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 211: + case 213: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -23461,12 +23906,12 @@ var ts; if (ts.isSupportedExpressionWithTypeArguments(node)) { emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); } - else if (!isImplementsList && node.expression.kind === 91) { + else if (!isImplementsList && node.expression.kind === 93) { write("null"); } function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.parent.kind === 212) { + if (node.parent.parent.kind === 214) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; @@ -23546,16 +23991,16 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 209 || resolver.isDeclarationVisible(node)) { + if (node.kind !== 211 || resolver.isDeclarationVisible(node)) { if (ts.isBindingPattern(node.name)) { emitBindingPattern(node.name); } else { writeTextOfNode(currentSourceFile, node.name); - if ((node.kind === 139 || node.kind === 138) && ts.hasQuestionToken(node)) { + if ((node.kind === 141 || node.kind === 140) && ts.hasQuestionToken(node)) { write("?"); } - if ((node.kind === 139 || node.kind === 138) && node.parent.kind === 153) { + if ((node.kind === 141 || node.kind === 140) && node.parent.kind === 155) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & 32)) { @@ -23564,14 +24009,14 @@ var ts; } } function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { - if (node.kind === 209) { + if (node.kind === 211) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } - else if (node.kind === 139 || node.kind === 138) { + else if (node.kind === 141 || node.kind === 140) { if (node.flags & 128) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? @@ -23579,7 +24024,7 @@ var ts; ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -23605,7 +24050,7 @@ var ts; var elements = []; for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.kind !== 185) { + if (element.kind !== 187) { elements.push(element); } } @@ -23671,7 +24116,7 @@ var ts; accessorWithTypeAnnotation = node; var type = getTypeAnnotationFromAccessor(node); if (!type) { - var anotherAccessor = node.kind === 143 ? accessors.setAccessor : accessors.getAccessor; + var anotherAccessor = node.kind === 145 ? accessors.setAccessor : accessors.getAccessor; type = getTypeAnnotationFromAccessor(anotherAccessor); if (type) { accessorWithTypeAnnotation = anotherAccessor; @@ -23684,7 +24129,7 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 143 + return accessor.kind === 145 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type @@ -23693,7 +24138,7 @@ var ts; } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 144) { + if (accessorWithTypeAnnotation.kind === 146) { if (accessorWithTypeAnnotation.parent.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : @@ -23739,17 +24184,17 @@ var ts; } if (!resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); - if (node.kind === 211) { + if (node.kind === 213) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === 141) { + else if (node.kind === 143) { emitClassMemberDeclarationFlags(node); } - if (node.kind === 211) { + if (node.kind === 213) { write("function "); writeTextOfNode(currentSourceFile, node.name); } - else if (node.kind === 142) { + else if (node.kind === 144) { write("constructor"); } else { @@ -23766,11 +24211,11 @@ var ts; emitSignatureDeclaration(node); } function emitSignatureDeclaration(node) { - if (node.kind === 146 || node.kind === 151) { + if (node.kind === 148 || node.kind === 153) { write("new "); } emitTypeParameters(node.typeParameters); - if (node.kind === 147) { + if (node.kind === 149) { write("["); } else { @@ -23779,20 +24224,20 @@ var ts; var prevEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = node; emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 147) { + if (node.kind === 149) { write("]"); } else { write(")"); } - var isFunctionTypeOrConstructorType = node.kind === 150 || node.kind === 151; - if (isFunctionTypeOrConstructorType || node.parent.kind === 153) { + var isFunctionTypeOrConstructorType = node.kind === 152 || node.kind === 153; + if (isFunctionTypeOrConstructorType || node.parent.kind === 155) { if (node.type) { write(isFunctionTypeOrConstructorType ? " => " : ": "); emitType(node.type); } } - else if (node.kind !== 142 && !(node.flags & 32)) { + else if (node.kind !== 144 && !(node.flags & 32)) { writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); } enclosingDeclaration = prevEnclosingDeclaration; @@ -23803,23 +24248,23 @@ var ts; function getReturnTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.kind) { - case 146: + case 148: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 145: + case 147: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 147: + case 149: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 141: - case 140: + case 143: + case 142: if (node.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? @@ -23827,7 +24272,7 @@ var ts; ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 212) { + else if (node.parent.kind === 214) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -23840,7 +24285,7 @@ var ts; ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 211: + case 213: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -23872,9 +24317,9 @@ var ts; write("?"); } decreaseIndent(); - if (node.parent.kind === 150 || - node.parent.kind === 151 || - node.parent.parent.kind === 153) { + if (node.parent.kind === 152 || + node.parent.kind === 153 || + node.parent.parent.kind === 155) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.parent.flags & 32)) { @@ -23890,22 +24335,22 @@ var ts; } function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { switch (node.parent.kind) { - case 142: + case 144: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - case 146: + case 148: return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - case 145: + case 147: return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - case 141: - case 140: + case 143: + case 142: if (node.parent.flags & 128) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? @@ -23913,7 +24358,7 @@ var ts; ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212) { + else if (node.parent.parent.kind === 214) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -23925,7 +24370,7 @@ var ts; ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } - case 211: + case 213: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -23936,12 +24381,12 @@ var ts; } } function emitBindingPattern(bindingPattern) { - if (bindingPattern.kind === 159) { + if (bindingPattern.kind === 161) { write("{"); emitCommaList(bindingPattern.elements, emitBindingElement); write("}"); } - else if (bindingPattern.kind === 160) { + else if (bindingPattern.kind === 162) { write("["); var elements = bindingPattern.elements; emitCommaList(elements, emitBindingElement); @@ -23960,10 +24405,10 @@ var ts; typeName: bindingElement.name } : undefined; } - if (bindingElement.kind === 185) { + if (bindingElement.kind === 187) { write(" "); } - else if (bindingElement.kind === 161) { + else if (bindingElement.kind === 163) { if (bindingElement.propertyName) { writeTextOfNode(currentSourceFile, bindingElement.propertyName); write(": "); @@ -23973,7 +24418,7 @@ var ts; emitBindingPattern(bindingElement.name); } else { - ts.Debug.assert(bindingElement.name.kind === 67); + ts.Debug.assert(bindingElement.name.kind === 69); if (bindingElement.dotDotDotToken) { write("..."); } @@ -23985,39 +24430,39 @@ var ts; } function emitNode(node) { switch (node.kind) { - case 211: - case 216: - case 219: case 213: - case 212: - case 214: + case 218: + case 221: case 215: + case 214: + case 216: + case 217: return emitModuleElement(node, isModuleElementVisible(node)); - case 191: + case 193: return emitModuleElement(node, isVariableStatementVisible(node)); - case 220: + case 222: return emitModuleElement(node, !node.importClause); - case 226: + case 228: return emitExportDeclaration(node); + case 144: + case 143: case 142: + return writeFunctionDeclaration(node); + case 148: + case 147: + case 149: + return emitSignatureDeclarationWithJsDocComments(node); + case 145: + case 146: + return emitAccessorDeclaration(node); case 141: case 140: - return writeFunctionDeclaration(node); - case 146: - case 145: - case 147: - return emitSignatureDeclarationWithJsDocComments(node); - case 143: - case 144: - return emitAccessorDeclaration(node); - case 139: - case 138: return emitPropertyDeclaration(node); - case 245: + case 247: return emitEnumMemberDeclaration(node); - case 225: + case 227: return emitExportAssignment(node); - case 246: + case 248: return emitSourceFile(node); } } @@ -24060,5471 +24505,6 @@ var ts; return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; - function emitFiles(resolver, host, targetSourceFile) { - var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; - var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; - var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; - var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; - var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; - var compilerOptions = host.getCompilerOptions(); - var languageVersion = compilerOptions.target || 0; - var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; - var diagnostics = []; - var newLine = host.getNewLine(); - var jsxDesugaring = host.getCompilerOptions().jsx !== 1; - var shouldEmitJsx = function (s) { return (s.languageVariant === 1 && !jsxDesugaring); }; - if (targetSourceFile === undefined) { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, sourceFile); - } - }); - if (compilerOptions.outFile || compilerOptions.out) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - else { - if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, targetSourceFile); - } - else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); - return { - emitSkipped: false, - diagnostics: diagnostics, - sourceMaps: sourceMapDataList - }; - function isNodeDescendentOf(node, ancestor) { - while (node) { - if (node === ancestor) - return true; - node = node.parent; - } - return false; - } - function isUniqueLocalName(name, container) { - for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && ts.hasProperty(node.locals, name)) { - if (node.locals[name].flags & (107455 | 1048576 | 8388608)) { - return false; - } - } - } - return true; - } - function emitJavaScript(jsFilePath, root) { - var writer = ts.createTextWriter(newLine); - var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; - var currentSourceFile; - var exportFunctionForFile; - var generatedNameSet = {}; - var nodeToGeneratedName = []; - var computedPropertyNamesToGeneratedNames; - var extendsEmitted = false; - var decorateEmitted = false; - var paramEmitted = false; - var awaiterEmitted = false; - var tempFlags = 0; - var tempVariables; - var tempParameters; - var externalImports; - var exportSpecifiers; - var exportEquals; - var hasExportStars; - var writeEmittedFiles = writeJavaScriptFile; - var detachedCommentsInfo; - var writeComment = ts.writeCommentRange; - var emit = emitNodeWithCommentsAndWithoutSourcemap; - var emitStart = function (node) { }; - var emitEnd = function (node) { }; - var emitToken = emitTokenText; - var scopeEmitStart = function (scopeDeclaration, scopeName) { }; - var scopeEmitEnd = function () { }; - var sourceMapData; - var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; - if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { - initializeEmitterWithSourceMaps(); - } - if (root) { - emitSourceFile(root); - } - else { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - emitSourceFile(sourceFile); - } - }); - } - writeLine(); - writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); - return; - function emitSourceFile(sourceFile) { - currentSourceFile = sourceFile; - exportFunctionForFile = undefined; - emit(sourceFile); - } - function isUniqueName(name) { - return !resolver.hasGlobalName(name) && - !ts.hasProperty(currentSourceFile.identifiers, name) && - !ts.hasProperty(generatedNameSet, name); - } - function makeTempVariableName(flags) { - if (flags && !(tempFlags & flags)) { - var name_20 = flags === 268435456 ? "_i" : "_n"; - if (isUniqueName(name_20)) { - tempFlags |= flags; - return name_20; - } - } - while (true) { - var count = tempFlags & 268435455; - tempFlags++; - if (count !== 8 && count !== 13) { - var name_21 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_21)) { - return name_21; - } - } - } - } - function makeUniqueName(baseName) { - if (baseName.charCodeAt(baseName.length - 1) !== 95) { - baseName += "_"; - } - var i = 1; - while (true) { - var generatedName = baseName + i; - if (isUniqueName(generatedName)) { - return generatedNameSet[generatedName] = generatedName; - } - i++; - } - } - function generateNameForModuleOrEnum(node) { - var name = node.name.text; - return isUniqueLocalName(name, node) ? name : makeUniqueName(name); - } - function generateNameForImportOrExportDeclaration(node) { - var expr = ts.getExternalModuleName(node); - var baseName = expr.kind === 9 ? - ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; - return makeUniqueName(baseName); - } - function generateNameForExportDefault() { - return makeUniqueName("default"); - } - function generateNameForClassExpression() { - return makeUniqueName("class"); - } - function generateNameForNode(node) { - switch (node.kind) { - case 67: - return makeUniqueName(node.text); - case 216: - case 215: - return generateNameForModuleOrEnum(node); - case 220: - case 226: - return generateNameForImportOrExportDeclaration(node); - case 211: - case 212: - case 225: - return generateNameForExportDefault(); - case 184: - return generateNameForClassExpression(); - } - } - function getGeneratedNameForNode(node) { - var id = ts.getNodeId(node); - return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); - } - function initializeEmitterWithSourceMaps() { - var sourceMapDir; - var sourceMapSourceIndex = -1; - var sourceMapNameIndexMap = {}; - var sourceMapNameIndices = []; - function getSourceMapNameIndex() { - return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; - } - var lastRecordedSourceMapSpan; - var lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; - var lastEncodedNameIndex = 0; - function encodeLastRecordedSourceMapSpan() { - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { - return; - } - var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; - if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { - if (sourceMapData.sourceMapMappings) { - sourceMapData.sourceMapMappings += ","; - } - } - else { - for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { - sourceMapData.sourceMapMappings += ";"; - } - prevEncodedEmittedColumn = 1; - } - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); - if (lastRecordedSourceMapSpan.nameIndex >= 0) { - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); - lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; - } - lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; - sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); - function base64VLQFormatEncode(inValue) { - function base64FormatEncode(inValue) { - if (inValue < 64) { - return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); - } - throw TypeError(inValue + ": not a 64 based value"); - } - if (inValue < 0) { - inValue = ((-inValue) << 1) + 1; - } - else { - inValue = inValue << 1; - } - var encodedStr = ""; - do { - var currentDigit = inValue & 31; - inValue = inValue >> 5; - if (inValue > 0) { - currentDigit = currentDigit | 32; - } - encodedStr = encodedStr + base64FormatEncode(currentDigit); - } while (inValue > 0); - return encodedStr; - } - } - function recordSourceMapSpan(pos) { - var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); - sourceLinePos.line++; - sourceLinePos.character++; - var emittedLine = writer.getLine(); - var emittedColumn = writer.getColumn(); - if (!lastRecordedSourceMapSpan || - lastRecordedSourceMapSpan.emittedLine !== emittedLine || - lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || - (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { - encodeLastRecordedSourceMapSpan(); - lastRecordedSourceMapSpan = { - emittedLine: emittedLine, - emittedColumn: emittedColumn, - sourceLine: sourceLinePos.line, - sourceColumn: sourceLinePos.character, - nameIndex: getSourceMapNameIndex(), - sourceIndex: sourceMapSourceIndex - }; - } - else { - lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; - lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; - lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; - } - } - function recordEmitNodeStartSpan(node) { - recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); - } - function recordEmitNodeEndSpan(node) { - recordSourceMapSpan(node.end); - } - function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); - var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; - } - function recordNewSourceFileStart(node) { - var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, true)); - sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; - sourceMapData.inputSourceFileNames.push(node.fileName); - if (compilerOptions.inlineSources) { - if (!sourceMapData.sourceMapSourcesContent) { - sourceMapData.sourceMapSourcesContent = []; - } - sourceMapData.sourceMapSourcesContent.push(node.text); - } - } - function recordScopeNameOfNode(node, scopeName) { - function recordScopeNameIndex(scopeNameIndex) { - sourceMapNameIndices.push(scopeNameIndex); - } - function recordScopeNameStart(scopeName) { - var scopeNameIndex = -1; - if (scopeName) { - var parentIndex = getSourceMapNameIndex(); - if (parentIndex !== -1) { - var name_22 = node.name; - if (!name_22 || name_22.kind !== 134) { - scopeName = "." + scopeName; - } - scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; - } - scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); - if (scopeNameIndex === undefined) { - scopeNameIndex = sourceMapData.sourceMapNames.length; - sourceMapData.sourceMapNames.push(scopeName); - sourceMapNameIndexMap[scopeName] = scopeNameIndex; - } - } - recordScopeNameIndex(scopeNameIndex); - } - if (scopeName) { - recordScopeNameStart(scopeName); - } - else if (node.kind === 211 || - node.kind === 171 || - node.kind === 141 || - node.kind === 140 || - node.kind === 143 || - node.kind === 144 || - node.kind === 216 || - node.kind === 212 || - node.kind === 215) { - if (node.name) { - var name_23 = node.name; - scopeName = name_23.kind === 134 - ? ts.getTextOfNode(name_23) - : node.name.text; - } - recordScopeNameStart(scopeName); - } - else { - recordScopeNameIndex(getSourceMapNameIndex()); - } - } - function recordScopeNameEnd() { - sourceMapNameIndices.pop(); - } - ; - function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { - recordSourceMapSpan(comment.pos); - ts.writeCommentRange(currentSourceFile, writer, comment, newLine); - recordSourceMapSpan(comment.end); - } - function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { - if (typeof JSON !== "undefined") { - var map_2 = { - version: version, - file: file, - sourceRoot: sourceRoot, - sources: sources, - names: names, - mappings: mappings - }; - if (sourcesContent !== undefined) { - map_2.sourcesContent = sourcesContent; - } - return JSON.stringify(map_2); - } - return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; - function serializeStringArray(list) { - var output = ""; - for (var i = 0, n = list.length; i < n; i++) { - if (i) { - output += ","; - } - output += "\"" + ts.escapeString(list[i]) + "\""; - } - return output; - } - } - function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { - encodeLastRecordedSourceMapSpan(); - var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); - sourceMapDataList.push(sourceMapData); - var sourceMapUrl; - if (compilerOptions.inlineSourceMap) { - var base64SourceMapText = ts.convertToBase64(sourceMapText); - sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; - } - else { - ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, false); - sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; - } - writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); - } - var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); - sourceMapData = { - sourceMapFilePath: jsFilePath + ".map", - jsSourceMappingURL: sourceMapJsFile + ".map", - sourceMapFile: sourceMapJsFile, - sourceMapSourceRoot: compilerOptions.sourceRoot || "", - sourceMapSources: [], - inputSourceFileNames: [], - sourceMapNames: [], - sourceMapMappings: "", - sourceMapSourcesContent: undefined, - sourceMapDecodedMappings: [] - }; - sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); - if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47) { - sourceMapData.sourceMapSourceRoot += ts.directorySeparator; - } - if (compilerOptions.mapRoot) { - sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); - if (root) { - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); - } - if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { - sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true); - } - else { - sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); - } - } - else { - sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); - } - function emitNodeWithSourceMap(node) { - if (node) { - if (ts.nodeIsSynthesized(node)) { - return emitNodeWithoutSourceMap(node); - } - if (node.kind !== 246) { - recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMap(node); - recordEmitNodeEndSpan(node); - } - else { - recordNewSourceFileStart(node); - emitNodeWithoutSourceMap(node); - } - } - } - function emitNodeWithCommentsAndWithSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; - emit = emitNodeWithCommentsAndWithSourcemap; - emitStart = recordEmitNodeStartSpan; - emitEnd = recordEmitNodeEndSpan; - emitToken = writeTextWithSpanRecord; - scopeEmitStart = recordScopeNameOfNode; - scopeEmitEnd = recordScopeNameEnd; - writeComment = writeCommentRangeWithMap; - } - function writeJavaScriptFile(emitOutput, writeByteOrderMark) { - ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); - } - function createTempVariable(flags) { - var result = ts.createSynthesizedNode(67); - result.text = makeTempVariableName(flags); - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; - } - tempVariables.push(name); - } - function createAndRecordTempVariable(flags) { - var temp = createTempVariable(flags); - recordTempDeclaration(temp); - return temp; - } - function emitTempDeclarations(newLine) { - if (tempVariables) { - if (newLine) { - writeLine(); - } - else { - write(" "); - } - write("var "); - emitCommaList(tempVariables); - write(";"); - } - } - function emitTokenText(tokenKind, startPos, emitFn) { - var tokenString = ts.tokenToString(tokenKind); - if (emitFn) { - emitFn(); - } - else { - write(tokenString); - } - return startPos + tokenString.length; - } - function emitOptional(prefix, node) { - if (node) { - write(prefix); - emit(node); - } - } - function emitParenthesizedIf(node, parenthesized) { - if (parenthesized) { - write("("); - } - emit(node); - if (parenthesized) { - write(")"); - } - } - function emitTrailingCommaIfPresent(nodeList) { - if (nodeList.hasTrailingComma) { - write(","); - } - } - function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { - ts.Debug.assert(nodes.length > 0); - increaseIndent(); - if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - for (var i = 0, n = nodes.length; i < n; i++) { - if (i) { - if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { - write(", "); - } - else { - write(","); - writeLine(); - } - } - emit(nodes[i]); - } - if (nodes.hasTrailingComma && allowTrailingComma) { - write(","); - } - decreaseIndent(); - if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - } - function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { - if (!emitNode) { - emitNode = emit; - } - for (var i = 0; i < count; i++) { - if (multiLine) { - if (i || leadingComma) { - write(","); - } - writeLine(); - } - else { - if (i || leadingComma) { - write(", "); - } - } - var node = nodes[start + i]; - emitTrailingCommentsOfPosition(node.pos); - emitNode(node); - leadingComma = true; - } - if (trailingComma) { - write(","); - } - if (multiLine && !noTrailingNewLine) { - writeLine(); - } - return count; - } - function emitCommaList(nodes) { - if (nodes) { - emitList(nodes, 0, nodes.length, false, false); - } - } - function emitLines(nodes) { - emitLinesStartingAt(nodes, 0); - } - function emitLinesStartingAt(nodes, startIndex) { - for (var i = startIndex; i < nodes.length; i++) { - writeLine(); - emit(nodes[i]); - } - } - function isBinaryOrOctalIntegerLiteral(node, text) { - if (node.kind === 8 && text.length > 1) { - switch (text.charCodeAt(1)) { - case 98: - case 66: - case 111: - case 79: - return true; - } - } - return false; - } - function emitLiteral(node) { - var text = getLiteralText(node); - if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 || ts.isTemplateLiteralKind(node.kind))) { - writer.writeLiteral(text); - } - else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { - write(node.text); - } - else { - write(text); - } - } - function getLiteralText(node) { - if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { - return getQuotedEscapedLiteralText("\"", node.text, "\""); - } - if (node.parent) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - } - switch (node.kind) { - case 9: - return getQuotedEscapedLiteralText("\"", node.text, "\""); - case 11: - return getQuotedEscapedLiteralText("`", node.text, "`"); - case 12: - return getQuotedEscapedLiteralText("`", node.text, "${"); - case 13: - return getQuotedEscapedLiteralText("}", node.text, "${"); - case 14: - return getQuotedEscapedLiteralText("}", node.text, "`"); - case 8: - return node.text; - } - ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); - } - function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { - return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; - } - function emitDownlevelRawTemplateLiteral(node) { - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - var isLast = node.kind === 11 || node.kind === 14; - text = text.substring(1, text.length - (isLast ? 1 : 2)); - text = text.replace(/\r\n?/g, "\n"); - text = ts.escapeString(text); - write("\"" + text + "\""); - } - function emitDownlevelTaggedTemplateArray(node, literalEmitter) { - write("["); - if (node.template.kind === 11) { - literalEmitter(node.template); - } - else { - literalEmitter(node.template.head); - ts.forEach(node.template.templateSpans, function (child) { - write(", "); - literalEmitter(child.literal); - }); - } - write("]"); - } - function emitDownlevelTaggedTemplate(node) { - var tempVariable = createAndRecordTempVariable(0); - write("("); - emit(tempVariable); - write(" = "); - emitDownlevelTaggedTemplateArray(node, emit); - write(", "); - emit(tempVariable); - write(".raw = "); - emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); - write(", "); - emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); - write("("); - emit(tempVariable); - if (node.template.kind === 181) { - ts.forEach(node.template.templateSpans, function (templateSpan) { - write(", "); - var needsParens = templateSpan.expression.kind === 179 - && templateSpan.expression.operatorToken.kind === 24; - emitParenthesizedIf(templateSpan.expression, needsParens); - }); - } - write("))"); - } - function emitTemplateExpression(node) { - if (languageVersion >= 2) { - ts.forEachChild(node, emit); - return; - } - var emitOuterParens = ts.isExpression(node.parent) - && templateNeedsParens(node, node.parent); - if (emitOuterParens) { - write("("); - } - var headEmitted = false; - if (shouldEmitTemplateHead()) { - emitLiteral(node.head); - headEmitted = true; - } - for (var i = 0, n = node.templateSpans.length; i < n; i++) { - var templateSpan = node.templateSpans[i]; - var needsParens = templateSpan.expression.kind !== 170 - && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; - if (i > 0 || headEmitted) { - write(" + "); - } - emitParenthesizedIf(templateSpan.expression, needsParens); - if (templateSpan.literal.text.length !== 0) { - write(" + "); - emitLiteral(templateSpan.literal); - } - } - if (emitOuterParens) { - write(")"); - } - function shouldEmitTemplateHead() { - ts.Debug.assert(node.templateSpans.length !== 0); - return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; - } - function templateNeedsParens(template, parent) { - switch (parent.kind) { - case 166: - case 167: - return parent.expression === template; - case 168: - case 170: - return false; - default: - return comparePrecedenceToBinaryPlus(parent) !== -1; - } - } - function comparePrecedenceToBinaryPlus(expression) { - switch (expression.kind) { - case 179: - switch (expression.operatorToken.kind) { - case 37: - case 38: - case 39: - return 1; - case 35: - case 36: - return 0; - default: - return -1; - } - case 182: - case 180: - return -1; - default: - return 1; - } - } - } - function emitTemplateSpan(span) { - emit(span.expression); - emit(span.literal); - } - function jsxEmitReact(node) { - function emitTagName(name) { - if (name.kind === 67 && ts.isIntrinsicJsxName(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - function emitAttributeName(name) { - if (/[A-Za-z_]+[\w*]/.test(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - function emitJsxAttribute(node) { - emitAttributeName(node.name); - write(": "); - if (node.initializer) { - emit(node.initializer); - } - else { - write("true"); - } - } - function emitJsxElement(openingNode, children) { - var syntheticReactRef = ts.createSynthesizedNode(67); - syntheticReactRef.text = 'React'; - syntheticReactRef.parent = openingNode; - emitLeadingComments(openingNode); - emitExpressionIdentifier(syntheticReactRef); - write(".createElement("); - emitTagName(openingNode.tagName); - write(", "); - if (openingNode.attributes.length === 0) { - write("null"); - } - else { - var attrs = openingNode.attributes; - if (ts.forEach(attrs, function (attr) { return attr.kind === 237; })) { - emitExpressionIdentifier(syntheticReactRef); - write(".__spread("); - var haveOpenedObjectLiteral = false; - for (var i_1 = 0; i_1 < attrs.length; i_1++) { - if (attrs[i_1].kind === 237) { - if (i_1 === 0) { - write("{}, "); - } - if (haveOpenedObjectLiteral) { - write("}"); - haveOpenedObjectLiteral = false; - } - if (i_1 > 0) { - write(", "); - } - emit(attrs[i_1].expression); - } - else { - ts.Debug.assert(attrs[i_1].kind === 236); - if (haveOpenedObjectLiteral) { - write(", "); - } - else { - haveOpenedObjectLiteral = true; - if (i_1 > 0) { - write(", "); - } - write("{"); - } - emitJsxAttribute(attrs[i_1]); - } - } - if (haveOpenedObjectLiteral) - write("}"); - write(")"); - } - else { - write("{"); - for (var i = 0; i < attrs.length; i++) { - if (i > 0) { - write(", "); - } - emitJsxAttribute(attrs[i]); - } - write("}"); - } - } - if (children) { - for (var i = 0; i < children.length; i++) { - if (children[i].kind === 238 && !(children[i].expression)) { - continue; - } - if (children[i].kind === 234) { - var text = getTextToEmit(children[i]); - if (text !== undefined) { - write(", \""); - write(text); - write("\""); - } - } - else { - write(", "); - emit(children[i]); - } - } - } - write(")"); - emitTrailingComments(openingNode); - } - if (node.kind === 231) { - emitJsxElement(node.openingElement, node.children); - } - else { - ts.Debug.assert(node.kind === 232); - emitJsxElement(node); - } - } - function jsxEmitPreserve(node) { - function emitJsxAttribute(node) { - emit(node.name); - if (node.initializer) { - write("="); - emit(node.initializer); - } - } - function emitJsxSpreadAttribute(node) { - write("{..."); - emit(node.expression); - write("}"); - } - function emitAttributes(attribs) { - for (var i = 0, n = attribs.length; i < n; i++) { - if (i > 0) { - write(" "); - } - if (attribs[i].kind === 237) { - emitJsxSpreadAttribute(attribs[i]); - } - else { - ts.Debug.assert(attribs[i].kind === 236); - emitJsxAttribute(attribs[i]); - } - } - } - function emitJsxOpeningOrSelfClosingElement(node) { - write("<"); - emit(node.tagName); - if (node.attributes.length > 0 || (node.kind === 232)) { - write(" "); - } - emitAttributes(node.attributes); - if (node.kind === 232) { - write("/>"); - } - else { - write(">"); - } - } - function emitJsxClosingElement(node) { - write(""); - } - function emitJsxElement(node) { - emitJsxOpeningOrSelfClosingElement(node.openingElement); - for (var i = 0, n = node.children.length; i < n; i++) { - emit(node.children[i]); - } - emitJsxClosingElement(node.closingElement); - } - if (node.kind === 231) { - emitJsxElement(node); - } - else { - ts.Debug.assert(node.kind === 232); - emitJsxOpeningOrSelfClosingElement(node); - } - } - function emitExpressionForPropertyName(node) { - ts.Debug.assert(node.kind !== 161); - if (node.kind === 9) { - emitLiteral(node); - } - else if (node.kind === 134) { - if (ts.nodeIsDecorated(node.parent)) { - if (!computedPropertyNamesToGeneratedNames) { - computedPropertyNamesToGeneratedNames = []; - } - var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; - if (generatedName) { - write(generatedName); - return; - } - generatedName = createAndRecordTempVariable(0).text; - computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; - write(generatedName); - write(" = "); - } - emit(node.expression); - } - else { - write("\""); - if (node.kind === 8) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - write("\""); - } - } - function isExpressionIdentifier(node) { - var parent = node.parent; - switch (parent.kind) { - case 162: - case 179: - case 166: - case 239: - case 134: - case 180: - case 137: - case 173: - case 195: - case 165: - case 225: - case 193: - case 186: - case 197: - case 198: - case 199: - case 194: - case 232: - case 233: - case 237: - case 238: - case 167: - case 170: - case 178: - case 177: - case 202: - case 244: - case 183: - case 204: - case 168: - case 188: - case 206: - case 169: - case 174: - case 175: - case 196: - case 203: - case 182: - return true; - case 161: - case 245: - case 136: - case 243: - case 139: - case 209: - return parent.initializer === node; - case 164: - return parent.expression === node; - case 172: - case 171: - return parent.body === node; - case 219: - return parent.moduleReference === node; - case 133: - return parent.left === node; - } - return false; - } - function emitExpressionIdentifier(node) { - if (resolver.getNodeCheckFlags(node) & 2048) { - write("_arguments"); - return; - } - var container = resolver.getReferencedExportContainer(node); - if (container) { - if (container.kind === 246) { - if (languageVersion < 2 && compilerOptions.module !== 4) { - write("exports."); - } - } - else { - write(getGeneratedNameForNode(container)); - write("."); - } - } - else if (languageVersion < 2) { - var declaration = resolver.getReferencedImportDeclaration(node); - if (declaration) { - if (declaration.kind === 221) { - write(getGeneratedNameForNode(declaration.parent)); - write(languageVersion === 0 ? "[\"default\"]" : ".default"); - return; - } - else if (declaration.kind === 224) { - write(getGeneratedNameForNode(declaration.parent.parent.parent)); - var name = declaration.propertyName || declaration.name; - var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name); - if (languageVersion === 0 && identifier === "default") { - write("[\"default\"]"); - } - else { - write("."); - write(identifier); - } - return; - } - } - declaration = resolver.getReferencedNestedRedeclaration(node); - if (declaration) { - write(getGeneratedNameForNode(declaration.name)); - return; - } - } - if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function isNameOfNestedRedeclaration(node) { - if (languageVersion < 2) { - var parent_6 = node.parent; - switch (parent_6.kind) { - case 161: - case 212: - case 215: - case 209: - return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); - } - } - return false; - } - function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (isExpressionIdentifier(node)) { - emitExpressionIdentifier(node); - } - else if (isNameOfNestedRedeclaration(node)) { - write(getGeneratedNameForNode(node)); - } - else if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function emitThis(node) { - if (resolver.getNodeCheckFlags(node) & 2) { - write("_this"); - } - else { - write("this"); - } - } - function emitSuper(node) { - if (languageVersion >= 2) { - write("super"); - } - else { - var flags = resolver.getNodeCheckFlags(node); - if (flags & 256) { - write("_super.prototype"); - } - else { - write("_super"); - } - } - } - function emitObjectBindingPattern(node) { - write("{ "); - var elements = node.elements; - emitList(elements, 0, elements.length, false, elements.hasTrailingComma); - write(" }"); - } - function emitArrayBindingPattern(node) { - write("["); - var elements = node.elements; - emitList(elements, 0, elements.length, false, elements.hasTrailingComma); - write("]"); - } - function emitBindingElement(node) { - if (node.propertyName) { - emit(node.propertyName); - write(": "); - } - if (node.dotDotDotToken) { - write("..."); - } - if (ts.isBindingPattern(node.name)) { - emit(node.name); - } - else { - emitModuleMemberName(node); - } - emitOptional(" = ", node.initializer); - } - function emitSpreadElementExpression(node) { - write("..."); - emit(node.expression); - } - function emitYieldExpression(node) { - write(ts.tokenToString(112)); - if (node.asteriskToken) { - write("*"); - } - if (node.expression) { - write(" "); - emit(node.expression); - } - } - function emitAwaitExpression(node) { - var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); - if (needsParenthesis) { - write("("); - } - write(ts.tokenToString(112)); - write(" "); - emit(node.expression); - if (needsParenthesis) { - write(")"); - } - } - function needsParenthesisForAwaitExpressionAsYield(node) { - if (node.parent.kind === 179 && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { - return true; - } - else if (node.parent.kind === 180 && node.parent.condition === node) { - return true; - } - return false; - } - function needsParenthesisForPropertyAccessOrInvocation(node) { - switch (node.kind) { - case 67: - case 162: - case 164: - case 165: - case 166: - case 170: - return false; - } - return true; - } - function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { - var pos = 0; - var group = 0; - var length = elements.length; - while (pos < length) { - if (group === 1 && useConcat) { - write(".concat("); - } - else if (group > 0) { - write(", "); - } - var e = elements[pos]; - if (e.kind === 183) { - e = e.expression; - emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); - pos++; - if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 162) { - write(".slice()"); - } - } - else { - var i = pos; - while (i < length && elements[i].kind !== 183) { - i++; - } - write("["); - if (multiLine) { - increaseIndent(); - } - emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); - if (multiLine) { - decreaseIndent(); - } - write("]"); - pos = i; - } - group++; - } - if (group > 1) { - if (useConcat) { - write(")"); - } - } - } - function isSpreadElementExpression(node) { - return node.kind === 183; - } - function emitArrayLiteral(node) { - var elements = node.elements; - if (elements.length === 0) { - write("[]"); - } - else if (languageVersion >= 2 || !ts.forEach(elements, isSpreadElementExpression)) { - write("["); - emitLinePreservingList(node, node.elements, elements.hasTrailingComma, false); - write("]"); - } - else { - emitListWithSpread(elements, true, (node.flags & 2048) !== 0, elements.hasTrailingComma, true); - } - } - function emitObjectLiteralBody(node, numElements) { - if (numElements === 0) { - write("{}"); - return; - } - write("{"); - if (numElements > 0) { - var properties = node.properties; - if (numElements === properties.length) { - emitLinePreservingList(node, properties, languageVersion >= 1, true); - } - else { - var multiLine = (node.flags & 2048) !== 0; - if (!multiLine) { - write(" "); - } - else { - increaseIndent(); - } - emitList(properties, 0, numElements, multiLine, false); - if (!multiLine) { - write(" "); - } - else { - decreaseIndent(); - } - } - } - write("}"); - } - function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { - var multiLine = (node.flags & 2048) !== 0; - var properties = node.properties; - write("("); - if (multiLine) { - increaseIndent(); - } - var tempVar = createAndRecordTempVariable(0); - emit(tempVar); - write(" = "); - emitObjectLiteralBody(node, firstComputedPropertyIndex); - for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { - writeComma(); - var property = properties[i]; - emitStart(property); - if (property.kind === 143 || property.kind === 144) { - var accessors = ts.getAllAccessorDeclarations(node.properties, property); - if (property !== accessors.firstAccessor) { - continue; - } - write("Object.defineProperty("); - emit(tempVar); - write(", "); - emitStart(node.name); - emitExpressionForPropertyName(property.name); - emitEnd(property.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("})"); - emitEnd(property); - } - else { - emitLeadingComments(property); - emitStart(property.name); - emit(tempVar); - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - if (property.kind === 243) { - emit(property.initializer); - } - else if (property.kind === 244) { - emitExpressionIdentifier(property.name); - } - else if (property.kind === 141) { - emitFunctionDeclaration(property); - } - else { - ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); - } - } - emitEnd(property); - } - writeComma(); - emit(tempVar); - if (multiLine) { - decreaseIndent(); - writeLine(); - } - write(")"); - function writeComma() { - if (multiLine) { - write(","); - writeLine(); - } - else { - write(", "); - } - } - } - function emitObjectLiteral(node) { - var properties = node.properties; - if (languageVersion < 2) { - var numProperties = properties.length; - var numInitialNonComputedProperties = numProperties; - for (var i = 0, n = properties.length; i < n; i++) { - if (properties[i].name.kind === 134) { - numInitialNonComputedProperties = i; - break; - } - } - var hasComputedProperty = numInitialNonComputedProperties !== properties.length; - if (hasComputedProperty) { - emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); - return; - } - } - emitObjectLiteralBody(node, properties.length); - } - function createBinaryExpression(left, operator, right, startsOnNewLine) { - var result = ts.createSynthesizedNode(179, startsOnNewLine); - result.operatorToken = ts.createSynthesizedNode(operator); - result.left = left; - result.right = right; - return result; - } - function createPropertyAccessExpression(expression, name) { - var result = ts.createSynthesizedNode(164); - result.expression = parenthesizeForAccess(expression); - result.dotToken = ts.createSynthesizedNode(21); - result.name = name; - return result; - } - function createElementAccessExpression(expression, argumentExpression) { - var result = ts.createSynthesizedNode(165); - result.expression = parenthesizeForAccess(expression); - result.argumentExpression = argumentExpression; - return result; - } - function parenthesizeForAccess(expr) { - while (expr.kind === 169 || expr.kind === 187) { - expr = expr.expression; - } - if (ts.isLeftHandSideExpression(expr) && - expr.kind !== 167 && - expr.kind !== 8) { - return expr; - } - var node = ts.createSynthesizedNode(170); - node.expression = expr; - return node; - } - function emitComputedPropertyName(node) { - write("["); - emitExpressionForPropertyName(node); - write("]"); - } - function emitMethod(node) { - if (languageVersion >= 2 && node.asteriskToken) { - write("*"); - } - emit(node.name); - if (languageVersion < 2) { - write(": function "); - } - emitSignatureAndBody(node); - } - function emitPropertyAssignment(node) { - emit(node.name); - write(": "); - emitTrailingCommentsOfPosition(node.initializer.pos); - emit(node.initializer); - } - function isNamespaceExportReference(node) { - var container = resolver.getReferencedExportContainer(node); - return container && container.kind !== 246; - } - function emitShorthandPropertyAssignment(node) { - writeTextOfNode(currentSourceFile, node.name); - if (languageVersion < 2 || isNamespaceExportReference(node.name)) { - write(": "); - emit(node.name); - } - } - function tryEmitConstantValue(node) { - var constantValue = tryGetConstEnumValue(node); - if (constantValue !== undefined) { - write(constantValue.toString()); - if (!compilerOptions.removeComments) { - var propertyName = node.kind === 164 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); - write(" /* " + propertyName + " */"); - } - return true; - } - return false; - } - function tryGetConstEnumValue(node) { - if (compilerOptions.isolatedModules) { - return undefined; - } - return node.kind === 164 || node.kind === 165 - ? resolver.getConstantValue(node) - : undefined; - } - function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { - var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); - var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); - if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { - increaseIndent(); - writeLine(); - return true; - } - else { - if (valueToWriteWhenNotIndenting) { - write(valueToWriteWhenNotIndenting); - } - return false; - } - } - function emitPropertyAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); - var shouldEmitSpace; - if (!indentedBeforeDot) { - if (node.expression.kind === 8) { - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); - shouldEmitSpace = text.indexOf(ts.tokenToString(21)) < 0; - } - else { - var constantValue = tryGetConstEnumValue(node.expression); - shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; - } - } - if (shouldEmitSpace) { - write(" ."); - } - else { - write("."); - } - var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); - emit(node.name); - decreaseIndentIf(indentedBeforeDot, indentedAfterDot); - } - function emitQualifiedName(node) { - emit(node.left); - write("."); - emit(node.right); - } - function emitQualifiedNameAsExpression(node, useFallback) { - if (node.left.kind === 67) { - emitEntityNameAsExpression(node.left, useFallback); - } - else if (useFallback) { - var temp = createAndRecordTempVariable(0); - write("("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(node.left, true); - write(") && "); - emitNodeWithoutSourceMap(temp); - } - else { - emitEntityNameAsExpression(node.left, false); - } - write("."); - emit(node.right); - } - function emitEntityNameAsExpression(node, useFallback) { - switch (node.kind) { - case 67: - if (useFallback) { - write("typeof "); - emitExpressionIdentifier(node); - write(" !== 'undefined' && "); - } - emitExpressionIdentifier(node); - break; - case 133: - emitQualifiedNameAsExpression(node, useFallback); - break; - } - } - function emitIndexedAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("["); - emit(node.argumentExpression); - write("]"); - } - function hasSpreadElement(elements) { - return ts.forEach(elements, function (e) { return e.kind === 183; }); - } - function skipParentheses(node) { - while (node.kind === 170 || node.kind === 169 || node.kind === 187) { - node = node.expression; - } - return node; - } - function emitCallTarget(node) { - if (node.kind === 67 || node.kind === 95 || node.kind === 93) { - emit(node); - return node; - } - var temp = createAndRecordTempVariable(0); - write("("); - emit(temp); - write(" = "); - emit(node); - write(")"); - return temp; - } - function emitCallWithSpread(node) { - var target; - var expr = skipParentheses(node.expression); - if (expr.kind === 164) { - target = emitCallTarget(expr.expression); - write("."); - emit(expr.name); - } - else if (expr.kind === 165) { - target = emitCallTarget(expr.expression); - write("["); - emit(expr.argumentExpression); - write("]"); - } - else if (expr.kind === 93) { - target = expr; - write("_super"); - } - else { - emit(node.expression); - } - write(".apply("); - if (target) { - if (target.kind === 93) { - emitThis(target); - } - else { - emit(target); - } - } - else { - write("void 0"); - } - write(", "); - emitListWithSpread(node.arguments, false, false, false, true); - write(")"); - } - function emitCallExpression(node) { - if (languageVersion < 2 && hasSpreadElement(node.arguments)) { - emitCallWithSpread(node); - return; - } - var superCall = false; - if (node.expression.kind === 93) { - emitSuper(node.expression); - superCall = true; - } - else { - emit(node.expression); - superCall = node.expression.kind === 164 && node.expression.expression.kind === 93; - } - if (superCall && languageVersion < 2) { - write(".call("); - emitThis(node.expression); - if (node.arguments.length) { - write(", "); - emitCommaList(node.arguments); - } - write(")"); - } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitNewExpression(node) { - write("new "); - if (languageVersion === 1 && - node.arguments && - hasSpreadElement(node.arguments)) { - write("("); - var target = emitCallTarget(node.expression); - write(".bind.apply("); - emit(target); - write(", [void 0].concat("); - emitListWithSpread(node.arguments, false, false, false, false); - write(")))"); - write("()"); - } - else { - emit(node.expression); - if (node.arguments) { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - } - function emitTaggedTemplateExpression(node) { - if (languageVersion >= 2) { - emit(node.tag); - write(" "); - emit(node.template); - } - else { - emitDownlevelTaggedTemplate(node); - } - } - function emitParenExpression(node) { - if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 172) { - if (node.expression.kind === 169 || node.expression.kind === 187) { - var operand = node.expression.expression; - while (operand.kind === 169 || operand.kind === 187) { - operand = operand.expression; - } - if (operand.kind !== 177 && - operand.kind !== 175 && - operand.kind !== 174 && - operand.kind !== 173 && - operand.kind !== 178 && - operand.kind !== 167 && - !(operand.kind === 166 && node.parent.kind === 167) && - !(operand.kind === 171 && node.parent.kind === 166) && - !(operand.kind === 8 && node.parent.kind === 164)) { - emit(operand); - return; - } - } - } - write("("); - emit(node.expression); - write(")"); - } - function emitDeleteExpression(node) { - write(ts.tokenToString(76)); - write(" "); - emit(node.expression); - } - function emitVoidExpression(node) { - write(ts.tokenToString(101)); - write(" "); - emit(node.expression); - } - function emitTypeOfExpression(node) { - write(ts.tokenToString(99)); - write(" "); - emit(node.expression); - } - function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { - if (!isCurrentFileSystemExternalModule() || node.kind !== 67 || ts.nodeIsSynthesized(node)) { - return false; - } - var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 209 || node.parent.kind === 161); - var targetDeclaration = isVariableDeclarationOrBindingElement - ? node.parent - : resolver.getReferencedValueDeclaration(node); - return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, true); - } - function emitPrefixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - } - write(ts.tokenToString(node.operator)); - if (node.operand.kind === 177) { - var operand = node.operand; - if (node.operator === 35 && (operand.operator === 35 || operand.operator === 40)) { - write(" "); - } - else if (node.operator === 36 && (operand.operator === 36 || operand.operator === 41)) { - write(" "); - } - } - emit(node.operand); - if (exportChanged) { - write(")"); - } - } - function emitPostfixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - write("(" + exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - write(ts.tokenToString(node.operator)); - emit(node.operand); - if (node.operator === 40) { - write(") - 1)"); - } - else { - write(") + 1)"); - } - } - else { - emit(node.operand); - write(ts.tokenToString(node.operator)); - } - } - function shouldHoistDeclarationInSystemJsModule(node) { - return isSourceFileLevelDeclarationInSystemJsModule(node, false); - } - function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { - if (!node || languageVersion >= 2 || !isCurrentFileSystemExternalModule()) { - return false; - } - var current = node; - while (current) { - if (current.kind === 246) { - return !isExported || ((ts.getCombinedNodeFlags(node) & 1) !== 0); - } - else if (ts.isFunctionLike(current) || current.kind === 217) { - return false; - } - else { - current = current.parent; - } - } - } - function emitBinaryExpression(node) { - if (languageVersion < 2 && node.operatorToken.kind === 55 && - (node.left.kind === 163 || node.left.kind === 162)) { - emitDestructuring(node, node.parent.kind === 193); - } - else { - var exportChanged = node.operatorToken.kind >= 55 && - node.operatorToken.kind <= 66 && - isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.left); - write("\", "); - } - emit(node.left); - var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 ? " " : undefined); - write(ts.tokenToString(node.operatorToken.kind)); - var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); - emit(node.right); - decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); - if (exportChanged) { - write(")"); - } - } - } - function synthesizedNodeStartsOnNewLine(node) { - return ts.nodeIsSynthesized(node) && node.startsOnNewLine; - } - function emitConditionalExpression(node) { - emit(node.condition); - var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); - write("?"); - var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); - emit(node.whenTrue); - decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); - var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); - write(":"); - var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); - emit(node.whenFalse); - decreaseIndentIf(indentedBeforeColon, indentedAfterColon); - } - function decreaseIndentIf(value1, value2) { - if (value1) { - decreaseIndent(); - } - if (value2) { - decreaseIndent(); - } - } - function isSingleLineEmptyBlock(node) { - if (node && node.kind === 190) { - var block = node; - return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); - } - } - function emitBlock(node) { - if (isSingleLineEmptyBlock(node)) { - emitToken(15, node.pos); - write(" "); - emitToken(16, node.statements.end); - return; - } - emitToken(15, node.pos); - increaseIndent(); - scopeEmitStart(node.parent); - if (node.kind === 217) { - ts.Debug.assert(node.parent.kind === 216); - emitCaptureThisForNodeIfNecessary(node.parent); - } - emitLines(node.statements); - if (node.kind === 217) { - emitTempDeclarations(true); - } - decreaseIndent(); - writeLine(); - emitToken(16, node.statements.end); - scopeEmitEnd(); - } - function emitEmbeddedStatement(node) { - if (node.kind === 190) { - write(" "); - emit(node); - } - else { - increaseIndent(); - writeLine(); - emit(node); - decreaseIndent(); - } - } - function emitExpressionStatement(node) { - emitParenthesizedIf(node.expression, node.expression.kind === 172); - write(";"); - } - function emitIfStatement(node) { - var endPos = emitToken(86, node.pos); - write(" "); - endPos = emitToken(17, endPos); - emit(node.expression); - emitToken(18, node.expression.end); - emitEmbeddedStatement(node.thenStatement); - if (node.elseStatement) { - writeLine(); - emitToken(78, node.thenStatement.end); - if (node.elseStatement.kind === 194) { - write(" "); - emit(node.elseStatement); - } - else { - emitEmbeddedStatement(node.elseStatement); - } - } - } - function emitDoStatement(node) { - write("do"); - emitEmbeddedStatement(node.statement); - if (node.statement.kind === 190) { - write(" "); - } - else { - writeLine(); - } - write("while ("); - emit(node.expression); - write(");"); - } - function emitWhileStatement(node) { - write("while ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function tryEmitStartOfVariableDeclarationList(decl, startPos) { - if (shouldHoistVariable(decl, true)) { - return false; - } - var tokenKind = 100; - if (decl && languageVersion >= 2) { - if (ts.isLet(decl)) { - tokenKind = 106; - } - else if (ts.isConst(decl)) { - tokenKind = 72; - } - } - if (startPos !== undefined) { - emitToken(tokenKind, startPos); - write(" "); - } - else { - switch (tokenKind) { - case 100: - write("var "); - break; - case 106: - write("let "); - break; - case 72: - write("const "); - break; - } - } - return true; - } - function emitVariableDeclarationListSkippingUninitializedEntries(list) { - var started = false; - for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { - var decl = _b[_a]; - if (!decl.initializer) { - continue; - } - if (!started) { - started = true; - } - else { - write(", "); - } - emit(decl); - } - return started; - } - function emitForStatement(node) { - var endPos = emitToken(84, node.pos); - write(" "); - endPos = emitToken(17, endPos); - if (node.initializer && node.initializer.kind === 210) { - var variableDeclarationList = node.initializer; - var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - if (startIsEmitted) { - emitCommaList(variableDeclarationList.declarations); - } - else { - emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); - } - } - else if (node.initializer) { - emit(node.initializer); - } - write(";"); - emitOptional(" ", node.condition); - write(";"); - emitOptional(" ", node.incrementor); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForInOrForOfStatement(node) { - if (languageVersion < 2 && node.kind === 199) { - return emitDownLevelForOfStatement(node); - } - var endPos = emitToken(84, node.pos); - write(" "); - endPos = emitToken(17, endPos); - if (node.initializer.kind === 210) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - emit(variableDeclarationList.declarations[0]); - } - } - else { - emit(node.initializer); - } - if (node.kind === 198) { - write(" in "); - } - else { - write(" of "); - } - emit(node.expression); - emitToken(18, node.expression.end); - emitEmbeddedStatement(node.statement); - } - function emitDownLevelForOfStatement(node) { - var endPos = emitToken(84, node.pos); - write(" "); - endPos = emitToken(17, endPos); - var rhsIsIdentifier = node.expression.kind === 67; - var counter = createTempVariable(268435456); - var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0); - emitStart(node.expression); - write("var "); - emitNodeWithoutSourceMap(counter); - write(" = 0"); - emitEnd(node.expression); - if (!rhsIsIdentifier) { - write(", "); - emitStart(node.expression); - emitNodeWithoutSourceMap(rhsReference); - write(" = "); - emitNodeWithoutSourceMap(node.expression); - emitEnd(node.expression); - } - write("; "); - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write(" < "); - emitNodeWithCommentsAndWithoutSourcemap(rhsReference); - write(".length"); - emitEnd(node.initializer); - write("; "); - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write("++"); - emitEnd(node.initializer); - emitToken(18, node.expression.end); - write(" {"); - writeLine(); - increaseIndent(); - var rhsIterationValue = createElementAccessExpression(rhsReference, counter); - emitStart(node.initializer); - if (node.initializer.kind === 210) { - write("var "); - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length > 0) { - var declaration = variableDeclarationList.declarations[0]; - if (ts.isBindingPattern(declaration.name)) { - emitDestructuring(declaration, false, rhsIterationValue); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(declaration); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - emitNodeWithoutSourceMap(createTempVariable(0)); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - var assignmentExpression = createBinaryExpression(node.initializer, 55, rhsIterationValue, false); - if (node.initializer.kind === 162 || node.initializer.kind === 163) { - emitDestructuring(assignmentExpression, true, undefined); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); - } - } - emitEnd(node.initializer); - write(";"); - if (node.statement.kind === 190) { - emitLines(node.statement.statements); - } - else { - writeLine(); - emit(node.statement); - } - writeLine(); - decreaseIndent(); - write("}"); - } - function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 201 ? 68 : 73, node.pos); - emitOptional(" ", node.label); - write(";"); - } - function emitReturnStatement(node) { - emitToken(92, node.pos); - emitOptional(" ", node.expression); - write(";"); - } - function emitWithStatement(node) { - write("with ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitSwitchStatement(node) { - var endPos = emitToken(94, node.pos); - write(" "); - emitToken(17, endPos); - emit(node.expression); - endPos = emitToken(18, node.expression.end); - write(" "); - emitCaseBlock(node.caseBlock, endPos); - } - function emitCaseBlock(node, startPos) { - emitToken(15, startPos); - increaseIndent(); - emitLines(node.clauses); - decreaseIndent(); - writeLine(); - emitToken(16, node.clauses.end); - } - function nodeStartPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function nodeEndPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, node2.end); - } - function nodeEndIsOnSameLineAsNodeStart(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function emitCaseOrDefaultClause(node) { - if (node.kind === 239) { - write("case "); - emit(node.expression); - write(":"); - } - else { - write("default:"); - } - if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { - write(" "); - emit(node.statements[0]); - } - else { - increaseIndent(); - emitLines(node.statements); - decreaseIndent(); - } - } - function emitThrowStatement(node) { - write("throw "); - emit(node.expression); - write(";"); - } - function emitTryStatement(node) { - write("try "); - emit(node.tryBlock); - emit(node.catchClause); - if (node.finallyBlock) { - writeLine(); - write("finally "); - emit(node.finallyBlock); - } - } - function emitCatchClause(node) { - writeLine(); - var endPos = emitToken(70, node.pos); - write(" "); - emitToken(17, endPos); - emit(node.variableDeclaration); - emitToken(18, node.variableDeclaration ? node.variableDeclaration.end : endPos); - write(" "); - emitBlock(node.block); - } - function emitDebuggerStatement(node) { - emitToken(74, node.pos); - write(";"); - } - function emitLabelledStatement(node) { - emit(node.label); - write(": "); - emit(node.statement); - } - function getContainingModule(node) { - do { - node = node.parent; - } while (node && node.kind !== 216); - return node; - } - function emitContainingModuleName(node) { - var container = getContainingModule(node); - write(container ? getGeneratedNameForNode(container) : "exports"); - } - function emitModuleMemberName(node) { - emitStart(node.name); - if (ts.getCombinedNodeFlags(node) & 1) { - var container = getContainingModule(node); - if (container) { - write(getGeneratedNameForNode(container)); - write("."); - } - else if (languageVersion < 2 && compilerOptions.module !== 4) { - write("exports."); - } - } - emitNodeWithCommentsAndWithoutSourcemap(node.name); - emitEnd(node.name); - } - function createVoidZero() { - var zero = ts.createSynthesizedNode(8); - zero.text = "0"; - var result = ts.createSynthesizedNode(175); - result.expression = zero; - return result; - } - function emitEs6ExportDefaultCompat(node) { - if (node.parent.kind === 246) { - ts.Debug.assert(!!(node.flags & 1024) || node.kind === 225); - if (compilerOptions.module === 1 || compilerOptions.module === 2 || compilerOptions.module === 3) { - if (!currentSourceFile.symbol.exports["___esModule"]) { - if (languageVersion === 1) { - write("Object.defineProperty(exports, \"__esModule\", { value: true });"); - writeLine(); - } - else if (languageVersion === 0) { - write("exports.__esModule = true;"); - writeLine(); - } - } - } - } - } - function emitExportMemberAssignment(node) { - if (node.flags & 1) { - writeLine(); - emitStart(node); - if (compilerOptions.module === 4 && node.parent === currentSourceFile) { - write(exportFunctionForFile + "(\""); - if (node.flags & 1024) { - write("default"); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - write("\", "); - emitDeclarationName(node); - write(")"); - } - else { - if (node.flags & 1024) { - emitEs6ExportDefaultCompat(node); - if (languageVersion === 0) { - write("exports[\"default\"]"); - } - else { - write("exports.default"); - } - } - else { - emitModuleMemberName(node); - } - write(" = "); - emitDeclarationName(node); - } - emitEnd(node); - write(";"); - } - } - function emitExportMemberAssignments(name) { - if (compilerOptions.module === 4) { - return; - } - if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { - for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { - var specifier = _b[_a]; - writeLine(); - emitStart(specifier.name); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - emitEnd(specifier.name); - write(" = "); - emitExpressionIdentifier(name); - write(";"); - } - } - } - function emitExportSpecifierInSystemModule(specifier) { - ts.Debug.assert(compilerOptions.module === 4); - if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { - return; - } - writeLine(); - emitStart(specifier.name); - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write("\", "); - emitExpressionIdentifier(specifier.propertyName || specifier.name); - write(")"); - emitEnd(specifier.name); - write(";"); - } - function emitDestructuring(root, isAssignmentExpressionStatement, value) { - var emitCount = 0; - var canDefineTempVariablesInPlace = false; - if (root.kind === 209) { - var isExported = ts.getCombinedNodeFlags(root) & 1; - var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); - canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; - } - else if (root.kind === 136) { - canDefineTempVariablesInPlace = true; - } - if (root.kind === 179) { - emitAssignmentExpression(root); - } - else { - ts.Debug.assert(!isAssignmentExpressionStatement); - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 209 || name.parent.kind === 161); - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(name); - write("\", "); - } - if (isVariableDeclarationOrBindingElement) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - if (exportChanged) { - write(")"); - } - } - function ensureIdentifier(expr, reuseIdentifierExpressions) { - if (expr.kind === 67 && reuseIdentifierExpressions) { - return expr; - } - var identifier = createTempVariable(0); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - return identifier; - } - function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value, true); - var equals = ts.createSynthesizedNode(179); - equals.left = value; - equals.operatorToken = ts.createSynthesizedNode(32); - equals.right = createVoidZero(); - return createConditionalExpression(equals, defaultValue, value); - } - function createConditionalExpression(condition, whenTrue, whenFalse) { - var cond = ts.createSynthesizedNode(180); - cond.condition = condition; - cond.questionToken = ts.createSynthesizedNode(52); - cond.whenTrue = whenTrue; - cond.colonToken = ts.createSynthesizedNode(53); - cond.whenFalse = whenFalse; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createSynthesizedNode(8); - node.text = "" + value; - return node; - } - function createPropertyAccessForDestructuringProperty(object, propName) { - var syntheticName = ts.createSynthesizedNode(propName.kind); - syntheticName.text = propName.text; - if (syntheticName.kind !== 67) { - return createElementAccessExpression(object, syntheticName); - } - return createPropertyAccessExpression(object, syntheticName); - } - function createSliceCall(value, sliceIndex) { - var call = ts.createSynthesizedNode(166); - var sliceIdentifier = ts.createSynthesizedNode(67); - sliceIdentifier.text = "slice"; - call.expression = createPropertyAccessExpression(value, sliceIdentifier); - call.arguments = ts.createSynthesizedNodeArray(); - call.arguments[0] = createNumericLiteral(sliceIndex); - return call; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - value = ensureIdentifier(value, true); - } - for (var _a = 0; _a < properties.length; _a++) { - var p = properties[_a]; - if (p.kind === 243 || p.kind === 244) { - var propName = p.name; - emitDestructuringAssignment(p.initializer || propName, createPropertyAccessForDestructuringProperty(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value, true); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 185) { - if (e.kind !== 183) { - emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === elements.length - 1) { - emitDestructuringAssignment(e.expression, createSliceCall(value, i)); - } - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 179 && target.operatorToken.kind === 55) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 163) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 162) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { - emit(value); - } - else if (isAssignmentExpressionStatement) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 170) { - write("("); - } - value = ensureIdentifier(value, true); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 170) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - var numElements = elements.length; - if (numElements !== 1) { - value = ensureIdentifier(value, numElements !== 0); - } - for (var i = 0; i < numElements; i++) { - var element = elements[i]; - if (pattern.kind === 159) { - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); - } - else if (element.kind !== 185) { - if (!element.dotDotDotToken) { - emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === numElements - 1) { - emitBindingElement(element, createSliceCall(value, i)); - } - } - } - } - else { - emitAssignment(target.name, value); - } - } - } - function emitVariableDeclaration(node) { - if (ts.isBindingPattern(node.name)) { - if (languageVersion < 2) { - emitDestructuring(node, false); - } - else { - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - else { - var initializer = node.initializer; - if (!initializer && languageVersion < 2) { - var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384) && - (getCombinedFlagsForIdentifier(node.name) & 16384); - if (isUninitializedLet && - node.parent.parent.kind !== 198 && - node.parent.parent.kind !== 199) { - initializer = createVoidZero(); - } - } - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(node.name); - write("\", "); - } - emitModuleMemberName(node); - emitOptional(" = ", initializer); - if (exportChanged) { - write(")"); - } - } - } - function emitExportVariableAssignments(node) { - if (node.kind === 185) { - return; - } - var name = node.name; - if (name.kind === 67) { - emitExportMemberAssignments(name); - } - else if (ts.isBindingPattern(name)) { - ts.forEach(name.elements, emitExportVariableAssignments); - } - } - function getCombinedFlagsForIdentifier(node) { - if (!node.parent || (node.parent.kind !== 209 && node.parent.kind !== 161)) { - return 0; - } - return ts.getCombinedNodeFlags(node.parent); - } - function isES6ExportedDeclaration(node) { - return !!(node.flags & 1) && - languageVersion >= 2 && - node.parent.kind === 246; - } - function emitVariableStatement(node) { - var startIsEmitted = false; - if (node.flags & 1) { - if (isES6ExportedDeclaration(node)) { - write("export "); - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - } - else { - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - if (startIsEmitted) { - emitCommaList(node.declarationList.declarations); - write(";"); - } - else { - var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); - if (atLeastOneItem) { - write(";"); - } - } - if (languageVersion < 2 && node.parent === currentSourceFile) { - ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); - } - } - function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { - if (!(node.flags & 1)) { - return true; - } - if (isES6ExportedDeclaration(node)) { - return true; - } - for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { - var declaration = _b[_a]; - if (declaration.initializer) { - return true; - } - } - return false; - } - function emitParameter(node) { - if (languageVersion < 2) { - if (ts.isBindingPattern(node.name)) { - var name_24 = createTempVariable(0); - if (!tempParameters) { - tempParameters = []; - } - tempParameters.push(name_24); - emit(name_24); - } - else { - emit(node.name); - } - } - else { - if (node.dotDotDotToken) { - write("..."); - } - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - function emitDefaultValueAssignments(node) { - if (languageVersion < 2) { - var tempIndex = 0; - ts.forEach(node.parameters, function (parameter) { - if (parameter.dotDotDotToken) { - return; - } - var paramName = parameter.name, initializer = parameter.initializer; - if (ts.isBindingPattern(paramName)) { - var hasBindingElements = paramName.elements.length > 0; - if (hasBindingElements || initializer) { - writeLine(); - write("var "); - if (hasBindingElements) { - emitDestructuring(parameter, false, tempParameters[tempIndex]); - } - else { - emit(tempParameters[tempIndex]); - write(" = "); - emit(initializer); - } - write(";"); - tempIndex++; - } - } - else if (initializer) { - writeLine(); - emitStart(parameter); - write("if ("); - emitNodeWithoutSourceMap(paramName); - write(" === void 0)"); - emitEnd(parameter); - write(" { "); - emitStart(parameter); - emitNodeWithCommentsAndWithoutSourcemap(paramName); - write(" = "); - emitNodeWithCommentsAndWithoutSourcemap(initializer); - emitEnd(parameter); - write("; }"); - } - }); - } - } - function emitRestParameter(node) { - if (languageVersion < 2 && ts.hasRestParameter(node)) { - var restIndex = node.parameters.length - 1; - var restParam = node.parameters[restIndex]; - if (ts.isBindingPattern(restParam.name)) { - return; - } - var tempName = createTempVariable(268435456).text; - writeLine(); - emitLeadingComments(restParam); - emitStart(restParam); - write("var "); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write(" = [];"); - emitEnd(restParam); - emitTrailingComments(restParam); - writeLine(); - write("for ("); - emitStart(restParam); - write("var " + tempName + " = " + restIndex + ";"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + " < arguments.length;"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + "++"); - emitEnd(restParam); - write(") {"); - increaseIndent(); - writeLine(); - emitStart(restParam); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); - emitEnd(restParam); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitAccessor(node) { - write(node.kind === 143 ? "get " : "set "); - emit(node.name); - emitSignatureAndBody(node); - } - function shouldEmitAsArrowFunction(node) { - return node.kind === 172 && languageVersion >= 2; - } - function emitDeclarationName(node) { - if (node.name) { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - else { - write(getGeneratedNameForNode(node)); - } - } - function shouldEmitFunctionName(node) { - if (node.kind === 171) { - return !!node.name; - } - if (node.kind === 211) { - return !!node.name || languageVersion < 2; - } - } - function emitFunctionDeclaration(node) { - if (ts.nodeIsMissing(node.body)) { - return emitCommentsOnNotEmittedNode(node); - } - if (node.kind !== 141 && node.kind !== 140 && - node.parent && node.parent.kind !== 243 && - node.parent.kind !== 166) { - emitLeadingComments(node); - } - emitStart(node); - if (!shouldEmitAsArrowFunction(node)) { - if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024) { - write("default "); - } - } - write("function"); - if (languageVersion >= 2 && node.asteriskToken) { - write("*"); - } - write(" "); - } - if (shouldEmitFunctionName(node)) { - emitDeclarationName(node); - } - emitSignatureAndBody(node); - if (languageVersion < 2 && node.kind === 211 && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - emitEnd(node); - if (node.kind !== 141 && node.kind !== 140) { - emitTrailingComments(node); - } - } - function emitCaptureThisForNodeIfNecessary(node) { - if (resolver.getNodeCheckFlags(node) & 4) { - writeLine(); - emitStart(node); - write("var _this = this;"); - emitEnd(node); - } - } - function emitSignatureParameters(node) { - increaseIndent(); - write("("); - if (node) { - var parameters = node.parameters; - var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0; - emitList(parameters, 0, parameters.length - omitCount, false, false); - } - write(")"); - decreaseIndent(); - } - function emitSignatureParametersForArrow(node) { - if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { - emit(node.parameters[0]); - return; - } - emitSignatureParameters(node); - } - function emitAsyncFunctionBodyForES6(node) { - var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); - var isArrowFunction = node.kind === 172; - var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096) !== 0; - var args; - if (!isArrowFunction) { - write(" {"); - increaseIndent(); - writeLine(); - write("return"); - } - write(" __awaiter(this"); - if (hasLexicalArguments) { - write(", arguments"); - } - else { - write(", void 0"); - } - if (promiseConstructor) { - write(", "); - emitNodeWithoutSourceMap(promiseConstructor); - } - else { - write(", Promise"); - } - if (hasLexicalArguments) { - write(", function* (_arguments)"); - } - else { - write(", function* ()"); - } - emitFunctionBody(node); - write(")"); - if (!isArrowFunction) { - write(";"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitFunctionBody(node) { - if (!node.body) { - write(" { }"); - } - else { - if (node.body.kind === 190) { - emitBlockFunctionBody(node, node.body); - } - else { - emitExpressionFunctionBody(node, node.body); - } - } - } - function emitSignatureAndBody(node) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - if (shouldEmitAsArrowFunction(node)) { - emitSignatureParametersForArrow(node); - write(" =>"); - } - else { - emitSignatureParameters(node); - } - var isAsync = ts.isAsyncFunctionLike(node); - if (isAsync && languageVersion === 2) { - emitAsyncFunctionBodyForES6(node); - } - else { - emitFunctionBody(node); - } - if (!isES6ExportedDeclaration(node)) { - emitExportMemberAssignment(node); - } - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function emitFunctionBodyPreamble(node) { - emitCaptureThisForNodeIfNecessary(node); - emitDefaultValueAssignments(node); - emitRestParameter(node); - } - function emitExpressionFunctionBody(node, body) { - if (languageVersion < 2 || node.flags & 512) { - emitDownLevelExpressionFunctionBody(node, body); - return; - } - write(" "); - var current = body; - while (current.kind === 169) { - current = current.expression; - } - emitParenthesizedIf(body, current.kind === 163); - } - function emitDownLevelExpressionFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - increaseIndent(); - var outPos = writer.getTextPos(); - emitDetachedComments(node.body); - emitFunctionBodyPreamble(node); - var preambleEmitted = writer.getTextPos() !== outPos; - decreaseIndent(); - if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { - write(" "); - emitStart(body); - write("return "); - emit(body); - emitEnd(body); - write(";"); - emitTempDeclarations(false); - write(" "); - } - else { - increaseIndent(); - writeLine(); - emitLeadingComments(node.body); - write("return "); - emit(body); - write(";"); - emitTrailingComments(node.body); - emitTempDeclarations(true); - decreaseIndent(); - writeLine(); - } - emitStart(node.body); - write("}"); - emitEnd(node.body); - scopeEmitEnd(); - } - function emitBlockFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - var initialTextPos = writer.getTextPos(); - increaseIndent(); - emitDetachedComments(body.statements); - var startIndex = emitDirectivePrologues(body.statements, true); - emitFunctionBodyPreamble(node); - decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== initialTextPos; - if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { - for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { - var statement = _b[_a]; - write(" "); - emit(statement); - } - emitTempDeclarations(false); - write(" "); - emitLeadingCommentsOfPosition(body.statements.end); - } - else { - increaseIndent(); - emitLinesStartingAt(body.statements, startIndex); - emitTempDeclarations(true); - writeLine(); - emitLeadingCommentsOfPosition(body.statements.end); - decreaseIndent(); - } - emitToken(16, body.statements.end); - scopeEmitEnd(); - } - function findInitialSuperCall(ctor) { - if (ctor.body) { - var statement = ctor.body.statements[0]; - if (statement && statement.kind === 193) { - var expr = statement.expression; - if (expr && expr.kind === 166) { - var func = expr.expression; - if (func && func.kind === 93) { - return statement; - } - } - } - } - } - function emitParameterPropertyAssignments(node) { - ts.forEach(node.parameters, function (param) { - if (param.flags & 112) { - writeLine(); - emitStart(param); - emitStart(param.name); - write("this."); - emitNodeWithoutSourceMap(param.name); - emitEnd(param.name); - write(" = "); - emit(param.name); - write(";"); - emitEnd(param); - } - }); - } - function emitMemberAccessForPropertyName(memberName) { - if (memberName.kind === 9 || memberName.kind === 8) { - write("["); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - write("]"); - } - else if (memberName.kind === 134) { - emitComputedPropertyName(memberName); - } - else { - write("."); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - } - } - function getInitializedProperties(node, isStatic) { - var properties = []; - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if (member.kind === 139 && isStatic === ((member.flags & 128) !== 0) && member.initializer) { - properties.push(member); - } - } - return properties; - } - function emitPropertyDeclarations(node, properties) { - for (var _a = 0; _a < properties.length; _a++) { - var property = properties[_a]; - emitPropertyDeclaration(node, property); - } - } - function emitPropertyDeclaration(node, property, receiver, isExpression) { - writeLine(); - emitLeadingComments(property); - emitStart(property); - emitStart(property.name); - if (receiver) { - emit(receiver); - } - else { - if (property.flags & 128) { - emitDeclarationName(node); - } - else { - write("this"); - } - } - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - emit(property.initializer); - if (!isExpression) { - write(";"); - } - emitEnd(property); - emitTrailingComments(property); - } - function emitMemberFunctionsForES5AndLower(node) { - ts.forEach(node.members, function (member) { - if (member.kind === 189) { - writeLine(); - write(";"); - } - else if (member.kind === 141 || node.kind === 140) { - if (!member.body) { - return emitCommentsOnNotEmittedNode(member); - } - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - emitClassMemberPrefix(node, member); - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emitFunctionDeclaration(member); - emitEnd(member); - write(";"); - emitTrailingComments(member); - } - else if (member.kind === 143 || member.kind === 144) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member === accessors.firstAccessor) { - writeLine(); - emitStart(member); - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("});"); - emitEnd(member); - } - } - }); - } - function emitMemberFunctionsForES6AndHigher(node) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if ((member.kind === 141 || node.kind === 140) && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - else if (member.kind === 141 || - member.kind === 143 || - member.kind === 144) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - if (member.flags & 128) { - write("static "); - } - if (member.kind === 143) { - write("get "); - } - else if (member.kind === 144) { - write("set "); - } - if (member.asteriskToken) { - write("*"); - } - emit(member.name); - emitSignatureAndBody(member); - emitEnd(member); - emitTrailingComments(member); - } - else if (member.kind === 189) { - writeLine(); - write(";"); - } - } - } - function emitConstructor(node, baseTypeElement) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - emitConstructorWorker(node, baseTypeElement); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function emitConstructorWorker(node, baseTypeElement) { - var hasInstancePropertyWithInitializer = false; - ts.forEach(node.members, function (member) { - if (member.kind === 142 && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - if (member.kind === 139 && member.initializer && (member.flags & 128) === 0) { - hasInstancePropertyWithInitializer = true; - } - }); - var ctor = ts.getFirstConstructorWithBody(node); - if (languageVersion >= 2 && !ctor && !hasInstancePropertyWithInitializer) { - return; - } - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - if (languageVersion < 2) { - write("function "); - emitDeclarationName(node); - emitSignatureParameters(ctor); - } - else { - write("constructor"); - if (ctor) { - emitSignatureParameters(ctor); - } - else { - if (baseTypeElement) { - write("(...args)"); - } - else { - write("()"); - } - } - } - var startIndex = 0; - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - startIndex = emitDirectivePrologues(ctor.body.statements, true); - emitDetachedComments(ctor.body.statements); - } - emitCaptureThisForNodeIfNecessary(node); - var superCall; - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeElement) { - superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeElement) { - writeLine(); - emitStart(baseTypeElement); - if (languageVersion < 2) { - write("_super.apply(this, arguments);"); - } - else { - write("super(...args);"); - } - emitEnd(baseTypeElement); - } - } - emitPropertyDeclarations(node, getInitializedProperties(node, false)); - if (ctor) { - var statements = ctor.body.statements; - if (superCall) { - statements = statements.slice(1); - } - emitLinesStartingAt(statements, startIndex); - } - emitTempDeclarations(true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition(ctor.body.statements.end); - } - decreaseIndent(); - emitToken(16, ctor ? ctor.body.statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - } - function emitClassExpression(node) { - return emitClassLikeDeclaration(node); - } - function emitClassDeclaration(node) { - return emitClassLikeDeclaration(node); - } - function emitClassLikeDeclaration(node) { - if (languageVersion < 2) { - emitClassLikeDeclarationBelowES6(node); - } - else { - emitClassLikeDeclarationForES6AndHigher(node); - } - } - function emitClassLikeDeclarationForES6AndHigher(node) { - var thisNodeIsDecorated = ts.nodeIsDecorated(node); - if (node.kind === 212) { - if (thisNodeIsDecorated) { - if (isES6ExportedDeclaration(node) && !(node.flags & 1024)) { - write("export "); - } - write("let "); - emitDeclarationName(node); - write(" = "); - } - else if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024) { - write("default "); - } - } - } - var staticProperties = getInitializedProperties(node, true); - var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 184; - var tempVariable; - if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0); - write("("); - increaseIndent(); - emit(tempVariable); - write(" = "); - } - write("class"); - if ((node.name || !(node.flags & 1024)) && !thisNodeIsDecorated) { - write(" "); - emitDeclarationName(node); - } - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write(" extends "); - emit(baseTypeNode.expression); - } - write(" {"); - increaseIndent(); - scopeEmitStart(node); - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES6AndHigher(node); - decreaseIndent(); - writeLine(); - emitToken(16, node.members.end); - scopeEmitEnd(); - if (thisNodeIsDecorated) { - write(";"); - } - if (isClassExpressionWithStaticProperties) { - for (var _a = 0; _a < staticProperties.length; _a++) { - var property = staticProperties[_a]; - write(","); - writeLine(); - emitPropertyDeclaration(node, property, tempVariable, true); - } - write(","); - writeLine(); - emit(tempVariable); - decreaseIndent(); - write(")"); - } - else { - writeLine(); - emitPropertyDeclarations(node, staticProperties); - emitDecoratorsOfClass(node); - } - if (!isES6ExportedDeclaration(node) && (node.flags & 1)) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emitDeclarationName(node); - emitEnd(node); - write(";"); - } - else if (isES6ExportedDeclaration(node) && (node.flags & 1024) && thisNodeIsDecorated) { - writeLine(); - write("export default "); - emitDeclarationName(node); - write(";"); - } - } - function emitClassLikeDeclarationBelowES6(node) { - if (node.kind === 212) { - if (!shouldHoistDeclarationInSystemJsModule(node)) { - write("var "); - } - emitDeclarationName(node); - write(" = "); - } - write("(function ("); - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write("_super"); - } - write(") {"); - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - computedPropertyNamesToGeneratedNames = undefined; - increaseIndent(); - scopeEmitStart(node); - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("__extends("); - emitDeclarationName(node); - write(", _super);"); - emitEnd(baseTypeNode); - } - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES5AndLower(node); - emitPropertyDeclarations(node, getInitializedProperties(node, true)); - writeLine(); - emitDecoratorsOfClass(node); - writeLine(); - emitToken(16, node.members.end, function () { - write("return "); - emitDeclarationName(node); - }); - write(";"); - emitTempDeclarations(true); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; - decreaseIndent(); - writeLine(); - emitToken(16, node.members.end); - scopeEmitEnd(); - emitStart(node); - write(")("); - if (baseTypeNode) { - emit(baseTypeNode.expression); - } - write(")"); - if (node.kind === 212) { - write(";"); - } - emitEnd(node); - if (node.kind === 212) { - emitExportMemberAssignment(node); - } - if (languageVersion < 2 && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - } - function emitClassMemberPrefix(node, member) { - emitDeclarationName(node); - if (!(member.flags & 128)) { - write(".prototype"); - } - } - function emitDecoratorsOfClass(node) { - emitDecoratorsOfMembers(node, 0); - emitDecoratorsOfMembers(node, 128); - emitDecoratorsOfConstructor(node); - } - function emitDecoratorsOfConstructor(node) { - var decorators = node.decorators; - var constructor = ts.getFirstConstructorWithBody(node); - var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); - if (!decorators && !hasDecoratedParameters) { - return; - } - writeLine(); - emitStart(node); - emitDeclarationName(node); - write(" = __decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(constructor, argumentsWritten > 0); - emitSerializedTypeMetadata(node, argumentsWritten >= 0); - decreaseIndent(); - writeLine(); - write("], "); - emitDeclarationName(node); - write(");"); - emitEnd(node); - writeLine(); - } - function emitDecoratorsOfMembers(node, staticFlag) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if ((member.flags & 128) !== staticFlag) { - continue; - } - if (!ts.nodeCanBeDecorated(member)) { - continue; - } - if (!ts.nodeOrChildIsDecorated(member)) { - continue; - } - var decorators = void 0; - var functionLikeMember = void 0; - if (ts.isAccessor(member)) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member !== accessors.firstAccessor) { - continue; - } - decorators = accessors.firstAccessor.decorators; - if (!decorators && accessors.secondAccessor) { - decorators = accessors.secondAccessor.decorators; - } - functionLikeMember = accessors.setAccessor; - } - else { - decorators = member.decorators; - if (member.kind === 141) { - functionLikeMember = member; - } - } - writeLine(); - emitStart(member); - if (member.kind !== 139) { - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(","); - increaseIndent(); - writeLine(); - } - write("__decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); - emitSerializedTypeMetadata(member, argumentsWritten > 0); - decreaseIndent(); - writeLine(); - write("], "); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - if (member.kind !== 139) { - write(", Object.getOwnPropertyDescriptor("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write("))"); - decreaseIndent(); - } - write(");"); - emitEnd(member); - writeLine(); - } - } - function emitDecoratorsOfParameters(node, leadingComma) { - var argumentsWritten = 0; - if (node) { - var parameterIndex = 0; - for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { - var parameter = _b[_a]; - if (ts.nodeIsDecorated(parameter)) { - var decorators = parameter.decorators; - argumentsWritten += emitList(decorators, 0, decorators.length, true, false, leadingComma, true, function (decorator) { - emitStart(decorator); - write("__param(" + parameterIndex + ", "); - emit(decorator.expression); - write(")"); - emitEnd(decorator); - }); - leadingComma = true; - } - ++parameterIndex; - } - } - return argumentsWritten; - } - function shouldEmitTypeMetadata(node) { - switch (node.kind) { - case 141: - case 143: - case 144: - case 139: - return true; - } - return false; - } - function shouldEmitReturnTypeMetadata(node) { - switch (node.kind) { - case 141: - return true; - } - return false; - } - function shouldEmitParamTypesMetadata(node) { - switch (node.kind) { - case 212: - case 141: - case 144: - return true; - } - return false; - } - function emitSerializedTypeOfNode(node) { - switch (node.kind) { - case 212: - write("Function"); - return; - case 139: - emitSerializedTypeNode(node.type); - return; - case 136: - emitSerializedTypeNode(node.type); - return; - case 143: - emitSerializedTypeNode(node.type); - return; - case 144: - emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); - return; - } - if (ts.isFunctionLike(node)) { - write("Function"); - return; - } - write("void 0"); - } - function emitSerializedTypeNode(node) { - if (node) { - switch (node.kind) { - case 101: - write("void 0"); - return; - case 158: - emitSerializedTypeNode(node.type); - return; - case 150: - case 151: - write("Function"); - return; - case 154: - case 155: - write("Array"); - return; - case 148: - case 118: - write("Boolean"); - return; - case 128: - case 9: - write("String"); - return; - case 126: - write("Number"); - return; - case 129: - write("Symbol"); - return; - case 149: - emitSerializedTypeReferenceNode(node); - return; - case 152: - case 153: - case 156: - case 157: - case 115: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; - } - } - write("Object"); - } - function emitSerializedTypeReferenceNode(node) { - var location = node.parent; - while (ts.isDeclaration(location) || ts.isTypeNode(location)) { - location = location.parent; - } - var typeName = ts.cloneEntityName(node.typeName); - typeName.parent = location; - var result = resolver.getTypeReferenceSerializationKind(typeName); - switch (result) { - case ts.TypeReferenceSerializationKind.Unknown: - var temp = createAndRecordTempVariable(0); - write("(typeof ("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(typeName, true); - write(") === 'function' && "); - emitNodeWithoutSourceMap(temp); - write(") || Object"); - break; - case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - emitEntityNameAsExpression(typeName, false); - break; - case ts.TypeReferenceSerializationKind.VoidType: - write("void 0"); - break; - case ts.TypeReferenceSerializationKind.BooleanType: - write("Boolean"); - break; - case ts.TypeReferenceSerializationKind.NumberLikeType: - write("Number"); - break; - case ts.TypeReferenceSerializationKind.StringLikeType: - write("String"); - break; - case ts.TypeReferenceSerializationKind.ArrayLikeType: - write("Array"); - break; - case ts.TypeReferenceSerializationKind.ESSymbolType: - if (languageVersion < 2) { - write("typeof Symbol === 'function' ? Symbol : Object"); - } - else { - write("Symbol"); - } - break; - case ts.TypeReferenceSerializationKind.TypeWithCallSignature: - write("Function"); - break; - case ts.TypeReferenceSerializationKind.ObjectType: - write("Object"); - break; - } - } - function emitSerializedParameterTypesOfNode(node) { - if (node) { - var valueDeclaration; - if (node.kind === 212) { - valueDeclaration = ts.getFirstConstructorWithBody(node); - } - else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { - valueDeclaration = node; - } - if (valueDeclaration) { - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; - if (parameterCount > 0) { - for (var i = 0; i < parameterCount; i++) { - if (i > 0) { - write(", "); - } - if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; - if (parameterType.kind === 154) { - parameterType = parameterType.elementType; - } - else if (parameterType.kind === 149 && parameterType.typeArguments && parameterType.typeArguments.length === 1) { - parameterType = parameterType.typeArguments[0]; - } - else { - parameterType = undefined; - } - emitSerializedTypeNode(parameterType); - } - else { - emitSerializedTypeOfNode(parameters[i]); - } - } - } - } - } - } - function emitSerializedReturnTypeOfNode(node) { - if (node && ts.isFunctionLike(node) && node.type) { - emitSerializedTypeNode(node.type); - return; - } - write("void 0"); - } - function emitSerializedTypeMetadata(node, writeComma) { - var argumentsWritten = 0; - if (compilerOptions.emitDecoratorMetadata) { - if (shouldEmitTypeMetadata(node)) { - if (writeComma) { - write(", "); - } - writeLine(); - write("__metadata('design:type', "); - emitSerializedTypeOfNode(node); - write(")"); - argumentsWritten++; - } - if (shouldEmitParamTypesMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:paramtypes', ["); - emitSerializedParameterTypesOfNode(node); - write("])"); - argumentsWritten++; - } - if (shouldEmitReturnTypeMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:returntype', "); - emitSerializedReturnTypeOfNode(node); - write(")"); - argumentsWritten++; - } - } - return argumentsWritten; - } - function emitInterfaceDeclaration(node) { - emitCommentsOnNotEmittedNode(node); - } - function shouldEmitEnumDeclaration(node) { - var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; - } - function emitEnumDeclaration(node) { - if (!shouldEmitEnumDeclaration(node)) { - return; - } - if (!shouldHoistDeclarationInSystemJsModule(node)) { - if (!(node.flags & 1) || isES6ExportedDeclaration(node)) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - emitEnd(node); - write(";"); - } - } - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") {"); - increaseIndent(); - scopeEmitStart(node); - emitLines(node.members); - decreaseIndent(); - writeLine(); - emitToken(16, node.members.end); - scopeEmitEnd(); - write(")("); - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) { - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } - if (languageVersion < 2 && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 && (node.flags & 1)) { - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - function emitEnumMember(node) { - var enumParent = node.parent; - emitStart(node); - write(getGeneratedNameForNode(enumParent)); - write("["); - write(getGeneratedNameForNode(enumParent)); - write("["); - emitExpressionForPropertyName(node.name); - write("] = "); - writeEnumMemberDeclarationValue(node); - write("] = "); - emitExpressionForPropertyName(node.name); - emitEnd(node); - write(";"); - } - function writeEnumMemberDeclarationValue(member) { - var value = resolver.getConstantValue(member); - if (value !== undefined) { - write(value.toString()); - return; - } - else if (member.initializer) { - emit(member.initializer); - } - else { - write("undefined"); - } - } - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 216) { - var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); - } - function isModuleMergedWithES6Class(node) { - return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 32768); - } - function emitModuleDeclaration(node) { - var shouldEmit = shouldEmitModuleDeclaration(node); - if (!shouldEmit) { - return emitCommentsOnNotEmittedNode(node); - } - var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); - var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); - if (emitVarForModule) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - } - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") "); - if (node.body.kind === 217) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - tempFlags = 0; - tempVariables = undefined; - emit(node.body); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - } - else { - write("{"); - increaseIndent(); - scopeEmitStart(node); - emitCaptureThisForNodeIfNecessary(node); - writeLine(); - emit(node.body); - decreaseIndent(); - writeLine(); - var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; - emitToken(16, moduleBlock.statements.end); - scopeEmitEnd(); - } - write(")("); - if ((node.flags & 1) && !isES6ExportedDeclaration(node)) { - emit(node.name); - write(" = "); - } - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.name.kind === 67 && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 && (node.flags & 1)) { - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - function tryRenameExternalModule(moduleName) { - if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { - return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; - } - return undefined; - } - function emitRequire(moduleName) { - if (moduleName.kind === 9) { - write("require("); - var text = tryRenameExternalModule(moduleName); - if (text) { - write(text); - } - else { - emitStart(moduleName); - emitLiteral(moduleName); - emitEnd(moduleName); - } - emitToken(18, moduleName.end); - } - else { - write("require()"); - } - } - function getNamespaceDeclarationNode(node) { - if (node.kind === 219) { - return node; - } - var importClause = node.importClause; - if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 222) { - return importClause.namedBindings; - } - } - function isDefaultImport(node) { - return node.kind === 220 && node.importClause && !!node.importClause.name; - } - function emitExportImportAssignments(node) { - if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - emitExportMemberAssignments(node.name); - } - ts.forEachChild(node, emitExportImportAssignments); - } - function emitImportDeclaration(node) { - if (languageVersion < 2) { - return emitExternalImportDeclaration(node); - } - if (node.importClause) { - var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); - var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, true); - if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { - write("import "); - emitStart(node.importClause); - if (shouldEmitDefaultBindings) { - emit(node.importClause.name); - if (shouldEmitNamedBindings) { - write(", "); - } - } - if (shouldEmitNamedBindings) { - emitLeadingComments(node.importClause.namedBindings); - emitStart(node.importClause.namedBindings); - if (node.importClause.namedBindings.kind === 222) { - write("* as "); - emit(node.importClause.namedBindings.name); - } - else { - write("{ "); - emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); - write(" }"); - } - emitEnd(node.importClause.namedBindings); - emitTrailingComments(node.importClause.namedBindings); - } - emitEnd(node.importClause); - write(" from "); - emit(node.moduleSpecifier); - write(";"); - } - } - else { - write("import "); - emit(node.moduleSpecifier); - write(";"); - } - } - function emitExternalImportDeclaration(node) { - if (ts.contains(externalImports, node)) { - var isExportedImport = node.kind === 219 && (node.flags & 1) !== 0; - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (compilerOptions.module !== 2) { - emitLeadingComments(node); - emitStart(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - if (!isExportedImport) - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - } - else { - var isNakedImport = 220 && !node.importClause; - if (!isNakedImport) { - write("var "); - write(getGeneratedNameForNode(node)); - write(" = "); - } - } - emitRequire(ts.getExternalModuleName(node)); - if (namespaceDeclaration && isDefaultImport(node)) { - write(", "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - else { - if (isExportedImport) { - emitModuleMemberName(namespaceDeclaration); - write(" = "); - emit(namespaceDeclaration.name); - write(";"); - } - else if (namespaceDeclaration && isDefaultImport(node)) { - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - write(";"); - } - emitExportImportAssignments(node); - } - } - } - function emitImportEqualsDeclaration(node) { - if (ts.isExternalModuleImportEqualsDeclaration(node)) { - emitExternalImportDeclaration(node); - return; - } - if (resolver.isReferencedAliasDeclaration(node) || - (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { - emitLeadingComments(node); - emitStart(node); - var variableDeclarationIsHoisted = shouldHoistVariable(node, true); - var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, true); - if (!variableDeclarationIsHoisted) { - ts.Debug.assert(!isExported); - if (isES6ExportedDeclaration(node)) { - write("export "); - write("var "); - } - else if (!(node.flags & 1)) { - write("var "); - } - } - if (isExported) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.name); - write("\", "); - } - emitModuleMemberName(node); - write(" = "); - emit(node.moduleReference); - if (isExported) { - write(")"); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - } - function emitExportDeclaration(node) { - ts.Debug.assert(compilerOptions.module !== 4); - if (languageVersion < 2) { - if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { - emitStart(node); - var generatedName = getGeneratedNameForNode(node); - if (node.exportClause) { - if (compilerOptions.module !== 2) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(ts.getExternalModuleName(node)); - write(";"); - } - for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { - var specifier = _b[_a]; - if (resolver.isValueAliasDeclaration(specifier)) { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - } - } - } - else { - writeLine(); - write("__export("); - if (compilerOptions.module !== 2) { - emitRequire(ts.getExternalModuleName(node)); - } - else { - write(generatedName); - } - write(");"); - } - emitEnd(node); - } - } - else { - if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { - write("export "); - if (node.exportClause) { - write("{ "); - emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); - write(" }"); - } - else { - write("*"); - } - if (node.moduleSpecifier) { - write(" from "); - emit(node.moduleSpecifier); - } - write(";"); - } - } - } - function emitExportOrImportSpecifierList(specifiers, shouldEmit) { - ts.Debug.assert(languageVersion >= 2); - var needsComma = false; - for (var _a = 0; _a < specifiers.length; _a++) { - var specifier = specifiers[_a]; - if (shouldEmit(specifier)) { - if (needsComma) { - write(", "); - } - if (specifier.propertyName) { - emit(specifier.propertyName); - write(" as "); - } - emit(specifier.name); - needsComma = true; - } - } - } - function emitExportAssignment(node) { - if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - if (languageVersion >= 2) { - writeLine(); - emitStart(node); - write("export default "); - var expression = node.expression; - emit(expression); - if (expression.kind !== 211 && - expression.kind !== 212) { - write(";"); - } - emitEnd(node); - } - else { - writeLine(); - emitStart(node); - if (compilerOptions.module === 4) { - write(exportFunctionForFile + "(\"default\","); - emit(node.expression); - write(")"); - } - else { - emitEs6ExportDefaultCompat(node); - emitContainingModuleName(node); - if (languageVersion === 0) { - write("[\"default\"] = "); - } - else { - write(".default = "); - } - emit(node.expression); - } - write(";"); - emitEnd(node); - } - } - } - function collectExternalModuleInfo(sourceFile) { - externalImports = []; - exportSpecifiers = {}; - exportEquals = undefined; - hasExportStars = false; - for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { - var node = _b[_a]; - switch (node.kind) { - case 220: - if (!node.importClause || - resolver.isReferencedAliasDeclaration(node.importClause, true)) { - externalImports.push(node); - } - break; - case 219: - if (node.moduleReference.kind === 230 && resolver.isReferencedAliasDeclaration(node)) { - externalImports.push(node); - } - break; - case 226: - if (node.moduleSpecifier) { - if (!node.exportClause) { - externalImports.push(node); - hasExportStars = true; - } - else if (resolver.isValueAliasDeclaration(node)) { - externalImports.push(node); - } - } - else { - for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { - var specifier = _d[_c]; - var name_25 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_25] || (exportSpecifiers[name_25] = [])).push(specifier); - } - } - break; - case 225: - if (node.isExportEquals && !exportEquals) { - exportEquals = node; - } - break; - } - } - } - function emitExportStarHelper() { - if (hasExportStars) { - writeLine(); - write("function __export(m) {"); - increaseIndent(); - writeLine(); - write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function getLocalNameForExternalImport(node) { - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); - } - if (node.kind === 220 && node.importClause) { - return getGeneratedNameForNode(node); - } - if (node.kind === 226 && node.moduleSpecifier) { - return getGeneratedNameForNode(node); - } - } - function getExternalModuleNameText(importNode) { - var moduleName = ts.getExternalModuleName(importNode); - if (moduleName.kind === 9) { - return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); - } - return undefined; - } - function emitVariableDeclarationsForImports() { - if (externalImports.length === 0) { - return; - } - writeLine(); - var started = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var importNode = externalImports[_a]; - var skipNode = importNode.kind === 226 || - (importNode.kind === 220 && !importNode.importClause); - if (skipNode) { - continue; - } - if (!started) { - write("var "); - started = true; - } - else { - write(", "); - } - write(getLocalNameForExternalImport(importNode)); - } - if (started) { - write(";"); - } - } - function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { - if (!hasExportStars) { - return undefined; - } - if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { - var hasExportDeclarationWithExportClause = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var externalImport = externalImports[_a]; - if (externalImport.kind === 226 && externalImport.exportClause) { - hasExportDeclarationWithExportClause = true; - break; - } - } - if (!hasExportDeclarationWithExportClause) { - return emitExportStarFunction(undefined); - } - } - var exportedNamesStorageRef = makeUniqueName("exportedNames"); - writeLine(); - write("var " + exportedNamesStorageRef + " = {"); - increaseIndent(); - var started = false; - if (exportedDeclarations) { - for (var i = 0; i < exportedDeclarations.length; ++i) { - writeExportedName(exportedDeclarations[i]); - } - } - if (exportSpecifiers) { - for (var n in exportSpecifiers) { - for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { - var specifier = _c[_b]; - writeExportedName(specifier.name); - } - } - } - for (var _d = 0; _d < externalImports.length; _d++) { - var externalImport = externalImports[_d]; - if (externalImport.kind !== 226) { - continue; - } - var exportDecl = externalImport; - if (!exportDecl.exportClause) { - continue; - } - for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { - var element = _f[_e]; - writeExportedName(element.name || element.propertyName); - } - } - decreaseIndent(); - writeLine(); - write("};"); - return emitExportStarFunction(exportedNamesStorageRef); - function emitExportStarFunction(localNames) { - var exportStarFunction = makeUniqueName("exportStar"); - writeLine(); - write("function " + exportStarFunction + "(m) {"); - increaseIndent(); - writeLine(); - write("var exports = {};"); - writeLine(); - write("for(var n in m) {"); - increaseIndent(); - writeLine(); - write("if (n !== \"default\""); - if (localNames) { - write("&& !" + localNames + ".hasOwnProperty(n)"); - } - write(") exports[n] = m[n];"); - decreaseIndent(); - writeLine(); - write("}"); - writeLine(); - write(exportFunctionForFile + "(exports);"); - decreaseIndent(); - writeLine(); - write("}"); - return exportStarFunction; - } - function writeExportedName(node) { - if (node.kind !== 67 && node.flags & 1024) { - return; - } - if (started) { - write(","); - } - else { - started = true; - } - writeLine(); - write("'"); - if (node.kind === 67) { - emitNodeWithCommentsAndWithoutSourcemap(node); - } - else { - emitDeclarationName(node); - } - write("': true"); - } - } - function processTopLevelVariableAndFunctionDeclarations(node) { - var hoistedVars; - var hoistedFunctionDeclarations; - var exportedDeclarations; - visit(node); - if (hoistedVars) { - writeLine(); - write("var "); - var seen = {}; - for (var i = 0; i < hoistedVars.length; ++i) { - var local = hoistedVars[i]; - var name_26 = local.kind === 67 - ? local - : local.name; - if (name_26) { - var text = ts.unescapeIdentifier(name_26.text); - if (ts.hasProperty(seen, text)) { - continue; - } - else { - seen[text] = text; - } - } - if (i !== 0) { - write(", "); - } - if (local.kind === 212 || local.kind === 216 || local.kind === 215) { - emitDeclarationName(local); - } - else { - emit(local); - } - var flags = ts.getCombinedNodeFlags(local.kind === 67 ? local.parent : local); - if (flags & 1) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(local); - } - } - write(";"); - } - if (hoistedFunctionDeclarations) { - for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { - var f = hoistedFunctionDeclarations[_a]; - writeLine(); - emit(f); - if (f.flags & 1) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(f); - } - } - } - return exportedDeclarations; - function visit(node) { - if (node.flags & 2) { - return; - } - if (node.kind === 211) { - if (!hoistedFunctionDeclarations) { - hoistedFunctionDeclarations = []; - } - hoistedFunctionDeclarations.push(node); - return; - } - if (node.kind === 212) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - return; - } - if (node.kind === 215) { - if (shouldEmitEnumDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 216) { - if (shouldEmitModuleDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 209 || node.kind === 161) { - if (shouldHoistVariable(node, false)) { - var name_27 = node.name; - if (name_27.kind === 67) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(name_27); - } - else { - ts.forEachChild(name_27, visit); - } - } - return; - } - if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node.name); - return; - } - if (ts.isBindingPattern(node)) { - ts.forEach(node.elements, visit); - return; - } - if (!ts.isDeclaration(node)) { - ts.forEachChild(node, visit); - } - } - } - function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { - if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { - return false; - } - return (ts.getCombinedNodeFlags(node) & 49152) === 0 || - ts.getEnclosingBlockScopeContainer(node).kind === 246; - } - function isCurrentFileSystemExternalModule() { - return compilerOptions.module === 4 && ts.isExternalModule(currentSourceFile); - } - function emitSystemModuleBody(node, dependencyGroups, startIndex) { - emitVariableDeclarationsForImports(); - writeLine(); - var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); - var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); - writeLine(); - write("return {"); - increaseIndent(); - writeLine(); - emitSetters(exportStarFunction, dependencyGroups); - writeLine(); - emitExecute(node, startIndex); - decreaseIndent(); - writeLine(); - write("}"); - emitTempDeclarations(true); - } - function emitSetters(exportStarFunction, dependencyGroups) { - write("setters:["); - for (var i = 0; i < dependencyGroups.length; ++i) { - if (i !== 0) { - write(","); - } - writeLine(); - increaseIndent(); - var group = dependencyGroups[i]; - var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); - write("function (" + parameterName + ") {"); - increaseIndent(); - for (var _a = 0; _a < group.length; _a++) { - var entry = group[_a]; - var importVariableName = getLocalNameForExternalImport(entry) || ""; - switch (entry.kind) { - case 220: - if (!entry.importClause) { - break; - } - case 219: - ts.Debug.assert(importVariableName !== ""); - writeLine(); - write(importVariableName + " = " + parameterName + ";"); - writeLine(); - break; - case 226: - ts.Debug.assert(importVariableName !== ""); - if (entry.exportClause) { - writeLine(); - write(exportFunctionForFile + "({"); - writeLine(); - increaseIndent(); - for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { - if (i_2 !== 0) { - write(","); - writeLine(); - } - var e = entry.exportClause.elements[i_2]; - write("\""); - emitNodeWithCommentsAndWithoutSourcemap(e.name); - write("\": " + parameterName + "[\""); - emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); - write("\"]"); - } - decreaseIndent(); - writeLine(); - write("});"); - } - else { - writeLine(); - write(exportStarFunction + "(" + parameterName + ");"); - } - writeLine(); - break; - } - } - decreaseIndent(); - write("}"); - decreaseIndent(); - } - write("],"); - } - function emitExecute(node, startIndex) { - write("execute: function() {"); - increaseIndent(); - writeLine(); - for (var i = startIndex; i < node.statements.length; ++i) { - var statement = node.statements[i]; - switch (statement.kind) { - case 211: - case 220: - continue; - case 226: - if (!statement.moduleSpecifier) { - for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { - var element = _b[_a]; - emitExportSpecifierInSystemModule(element); - } - } - continue; - case 219: - if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { - continue; - } - default: - writeLine(); - emit(statement); - } - } - decreaseIndent(); - writeLine(); - write("}"); - } - function emitSystemModule(node, startIndex) { - collectExternalModuleInfo(node); - ts.Debug.assert(!exportFunctionForFile); - exportFunctionForFile = makeUniqueName("exports"); - writeLine(); - write("System.register("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - write("["); - var groupIndices = {}; - var dependencyGroups = []; - for (var i = 0; i < externalImports.length; ++i) { - var text = getExternalModuleNameText(externalImports[i]); - if (ts.hasProperty(groupIndices, text)) { - var groupIndex = groupIndices[text]; - dependencyGroups[groupIndex].push(externalImports[i]); - continue; - } - else { - groupIndices[text] = dependencyGroups.length; - dependencyGroups.push([externalImports[i]]); - } - if (i !== 0) { - write(", "); - } - write(text); - } - write("], function(" + exportFunctionForFile + ") {"); - writeLine(); - increaseIndent(); - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitSystemModuleBody(node, dependencyGroups, startIndex); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitAMDDependencies(node, includeNonAmdDependencies) { - var aliasedModuleNames = []; - var unaliasedModuleNames = []; - var importAliasNames = []; - for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { - var amdDependency = _b[_a]; - if (amdDependency.name) { - aliasedModuleNames.push("\"" + amdDependency.path + "\""); - importAliasNames.push(amdDependency.name); - } - else { - unaliasedModuleNames.push("\"" + amdDependency.path + "\""); - } - } - for (var _c = 0; _c < externalImports.length; _c++) { - var importNode = externalImports[_c]; - var externalModuleName = getExternalModuleNameText(importNode); - var importAliasName = getLocalNameForExternalImport(importNode); - if (includeNonAmdDependencies && importAliasName) { - aliasedModuleNames.push(externalModuleName); - importAliasNames.push(importAliasName); - } - else { - unaliasedModuleNames.push(externalModuleName); - } - } - write("[\"require\", \"exports\""); - if (aliasedModuleNames.length) { - write(", "); - write(aliasedModuleNames.join(", ")); - } - if (unaliasedModuleNames.length) { - write(", "); - write(unaliasedModuleNames.join(", ")); - } - write("], function (require, exports"); - if (importAliasNames.length) { - write(", "); - write(importAliasNames.join(", ")); - } - } - function emitAMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - writeLine(); - write("define("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - emitAMDDependencies(node, true); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - emitExportEquals(true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitCommonJSModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - emitExportEquals(false); - } - function emitUMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - writeLines("(function (deps, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define(deps, factory);\n }\n})("); - emitAMDDependencies(node, false); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - emitExportEquals(true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitES6Module(node, startIndex) { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - } - function emitExportEquals(emitAsReturn) { - if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { - writeLine(); - emitStart(exportEquals); - write(emitAsReturn ? "return " : "module.exports = "); - emit(exportEquals.expression); - write(";"); - emitEnd(exportEquals); - } - } - function emitJsxElement(node) { - switch (compilerOptions.jsx) { - case 2: - jsxEmitReact(node); - break; - case 1: - default: - jsxEmitPreserve(node); - break; - } - } - function trimReactWhitespaceAndApplyEntities(node) { - var result = undefined; - var text = ts.getTextOfNode(node, true); - var firstNonWhitespace = 0; - var lastNonWhitespace = -1; - for (var i = 0; i < text.length; i++) { - var c = text.charCodeAt(i); - if (ts.isLineBreak(c)) { - if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { - var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - firstNonWhitespace = -1; - } - else if (!ts.isWhiteSpace(c)) { - lastNonWhitespace = i; - if (firstNonWhitespace === -1) { - firstNonWhitespace = i; - } - } - } - if (firstNonWhitespace !== -1) { - var part = text.substr(firstNonWhitespace); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - if (result) { - result = result.replace(/&(\w+);/g, function (s, m) { - if (entities[m] !== undefined) { - return String.fromCharCode(entities[m]); - } - else { - return s; - } - }); - } - return result; - } - function getTextToEmit(node) { - switch (compilerOptions.jsx) { - case 2: - var text = trimReactWhitespaceAndApplyEntities(node); - if (text === undefined || text.length === 0) { - return undefined; - } - else { - return text; - } - case 1: - default: - return ts.getTextOfNode(node, true); - } - } - function emitJsxText(node) { - switch (compilerOptions.jsx) { - case 2: - write("\""); - write(trimReactWhitespaceAndApplyEntities(node)); - write("\""); - break; - case 1: - default: - writer.writeLiteral(ts.getTextOfNode(node, true)); - break; - } - } - function emitJsxExpression(node) { - if (node.expression) { - switch (compilerOptions.jsx) { - case 1: - default: - write("{"); - emit(node.expression); - write("}"); - break; - case 2: - emit(node.expression); - break; - } - } - } - function emitDirectivePrologues(statements, startWithNewLine) { - for (var i = 0; i < statements.length; ++i) { - if (ts.isPrologueDirective(statements[i])) { - if (startWithNewLine || i > 0) { - writeLine(); - } - emit(statements[i]); - } - else { - return i; - } - } - return statements.length; - } - function writeLines(text) { - var lines = text.split(/\r\n|\r|\n/g); - for (var i = 0; i < lines.length; ++i) { - var line = lines[i]; - if (line.length) { - writeLine(); - write(line); - } - } - } - function emitEmitHelpers(node) { - if (!compilerOptions.noEmitHelpers) { - if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) { - writeLines(extendsHelper); - extendsEmitted = true; - } - if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16) { - writeLines(decorateHelper); - if (compilerOptions.emitDecoratorMetadata) { - writeLines(metadataHelper); - } - decorateEmitted = true; - } - if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32) { - writeLines(paramHelper); - paramEmitted = true; - } - if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64) { - writeLines(awaiterHelper); - awaiterEmitted = true; - } - } - } - function emitSourceFileNode(node) { - writeLine(); - emitShebang(); - emitDetachedComments(node); - var startIndex = emitDirectivePrologues(node.statements, false); - if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { - if (languageVersion >= 2) { - emitES6Module(node, startIndex); - } - else if (compilerOptions.module === 2) { - emitAMDModule(node, startIndex); - } - else if (compilerOptions.module === 4) { - emitSystemModule(node, startIndex); - } - else if (compilerOptions.module === 3) { - emitUMDModule(node, startIndex); - } - else { - emitCommonJSModule(node, startIndex); - } - } - else { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(true); - } - emitLeadingComments(node.endOfFileToken); - } - function emitNodeWithCommentsAndWithoutSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); - } - function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { - if (node) { - if (node.flags & 2) { - return emitCommentsOnNotEmittedNode(node); - } - if (isSpecializedCommentHandling(node)) { - return emitNodeWithoutSourceMap(node); - } - var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); - if (emitComments_1) { - emitLeadingComments(node); - } - emitNodeConsideringSourcemap(node); - if (emitComments_1) { - emitTrailingComments(node); - } - } - } - function emitNodeWithoutSourceMap(node) { - if (node) { - emitJavaScriptWorker(node); - } - } - function isSpecializedCommentHandling(node) { - switch (node.kind) { - case 213: - case 211: - case 220: - case 219: - case 214: - case 225: - return true; - } - } - function shouldEmitLeadingAndTrailingComments(node) { - switch (node.kind) { - case 191: - return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); - case 216: - return shouldEmitModuleDeclaration(node); - case 215: - return shouldEmitEnumDeclaration(node); - } - ts.Debug.assert(!isSpecializedCommentHandling(node)); - if (node.kind !== 190 && - node.parent && - node.parent.kind === 172 && - node.parent.body === node && - compilerOptions.target <= 1) { - return false; - } - return true; - } - function emitJavaScriptWorker(node) { - switch (node.kind) { - case 67: - return emitIdentifier(node); - case 136: - return emitParameter(node); - case 141: - case 140: - return emitMethod(node); - case 143: - case 144: - return emitAccessor(node); - case 95: - return emitThis(node); - case 93: - return emitSuper(node); - case 91: - return write("null"); - case 97: - return write("true"); - case 82: - return write("false"); - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - return emitLiteral(node); - case 181: - return emitTemplateExpression(node); - case 188: - return emitTemplateSpan(node); - case 231: - case 232: - return emitJsxElement(node); - case 234: - return emitJsxText(node); - case 238: - return emitJsxExpression(node); - case 133: - return emitQualifiedName(node); - case 159: - return emitObjectBindingPattern(node); - case 160: - return emitArrayBindingPattern(node); - case 161: - return emitBindingElement(node); - case 162: - return emitArrayLiteral(node); - case 163: - return emitObjectLiteral(node); - case 243: - return emitPropertyAssignment(node); - case 244: - return emitShorthandPropertyAssignment(node); - case 134: - return emitComputedPropertyName(node); - case 164: - return emitPropertyAccess(node); - case 165: - return emitIndexedAccess(node); - case 166: - return emitCallExpression(node); - case 167: - return emitNewExpression(node); - case 168: - return emitTaggedTemplateExpression(node); - case 169: - return emit(node.expression); - case 187: - return emit(node.expression); - case 170: - return emitParenExpression(node); - case 211: - case 171: - case 172: - return emitFunctionDeclaration(node); - case 173: - return emitDeleteExpression(node); - case 174: - return emitTypeOfExpression(node); - case 175: - return emitVoidExpression(node); - case 176: - return emitAwaitExpression(node); - case 177: - return emitPrefixUnaryExpression(node); - case 178: - return emitPostfixUnaryExpression(node); - case 179: - return emitBinaryExpression(node); - case 180: - return emitConditionalExpression(node); - case 183: - return emitSpreadElementExpression(node); - case 182: - return emitYieldExpression(node); - case 185: - return; - case 190: - case 217: - return emitBlock(node); - case 191: - return emitVariableStatement(node); - case 192: - return write(";"); - case 193: - return emitExpressionStatement(node); - case 194: - return emitIfStatement(node); - case 195: - return emitDoStatement(node); - case 196: - return emitWhileStatement(node); - case 197: - return emitForStatement(node); - case 199: - case 198: - return emitForInOrForOfStatement(node); - case 200: - case 201: - return emitBreakOrContinueStatement(node); - case 202: - return emitReturnStatement(node); - case 203: - return emitWithStatement(node); - case 204: - return emitSwitchStatement(node); - case 239: - case 240: - return emitCaseOrDefaultClause(node); - case 205: - return emitLabelledStatement(node); - case 206: - return emitThrowStatement(node); - case 207: - return emitTryStatement(node); - case 242: - return emitCatchClause(node); - case 208: - return emitDebuggerStatement(node); - case 209: - return emitVariableDeclaration(node); - case 184: - return emitClassExpression(node); - case 212: - return emitClassDeclaration(node); - case 213: - return emitInterfaceDeclaration(node); - case 215: - return emitEnumDeclaration(node); - case 245: - return emitEnumMember(node); - case 216: - return emitModuleDeclaration(node); - case 220: - return emitImportDeclaration(node); - case 219: - return emitImportEqualsDeclaration(node); - case 226: - return emitExportDeclaration(node); - case 225: - return emitExportAssignment(node); - case 246: - return emitSourceFileNode(node); - } - } - function hasDetachedComments(pos) { - return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; - } - function getLeadingCommentsWithoutDetachedComments() { - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); - if (detachedCommentsInfo.length - 1) { - detachedCommentsInfo.pop(); - } - else { - detachedCommentsInfo = undefined; - } - return leadingComments; - } - function isPinnedComments(comment) { - return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 33; - } - function isTripleSlashComment(comment) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 47) { - var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); - return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || - textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? - true : false; - } - return false; - } - function getLeadingCommentsToEmit(node) { - if (node.parent) { - if (node.parent.kind === 246 || node.pos !== node.parent.pos) { - if (hasDetachedComments(node.pos)) { - return getLeadingCommentsWithoutDetachedComments(); - } - else { - return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - } - } - } - function getTrailingCommentsToEmit(node) { - if (node.parent) { - if (node.parent.kind === 246 || node.end !== node.parent.end) { - return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - } - } - } - function emitCommentsOnNotEmittedNode(node) { - emitLeadingCommentsWorker(node, false); - } - function emitLeadingComments(node) { - return emitLeadingCommentsWorker(node, true); - } - function emitLeadingCommentsWorker(node, isEmittedNode) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (isEmittedNode) { - leadingComments = getLeadingCommentsToEmit(node); - } - else { - if (node.pos === 0) { - leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); - } - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitTrailingComments(node) { - if (compilerOptions.removeComments) { - return; - } - var trailingComments = getTrailingCommentsToEmit(node); - ts.emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); - } - function emitTrailingCommentsOfPosition(pos) { - if (compilerOptions.removeComments) { - return; - } - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); - ts.emitComments(currentSourceFile, writer, trailingComments, true, newLine, writeComment); - } - function emitLeadingCommentsOfPositionWorker(pos) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (hasDetachedComments(pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); - ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); - } - function emitDetachedComments(node) { - var leadingComments; - if (compilerOptions.removeComments) { - if (node.pos === 0) { - leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); - } - } - else { - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); - } - if (leadingComments) { - var detachedComments = []; - var lastComment; - ts.forEach(leadingComments, function (comment) { - if (lastComment) { - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); - var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); - if (commentLine >= lastCommentLine + 2) { - return detachedComments; - } - } - detachedComments.push(comment); - lastComment = comment; - }); - if (detachedComments.length) { - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); - var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - if (nodeLine >= lastCommentLine + 2) { - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - ts.emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); - var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; - if (detachedCommentsInfo) { - detachedCommentsInfo.push(currentDetachedCommentInfo); - } - else { - detachedCommentsInfo = [currentDetachedCommentInfo]; - } - } - } - } - } - function emitShebang() { - var shebang = ts.getShebang(currentSourceFile.text); - if (shebang) { - write(shebang); - } - } - } - function emitFile(jsFilePath, sourceFile) { - emitJavaScript(jsFilePath, sourceFile); - if (compilerOptions.declaration) { - ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); - } - } - } - ts.emitFiles = emitFiles; var entities = { "quot": 0x0022, "amp": 0x0026, @@ -29780,6 +24760,5552 @@ var ts; "hearts": 0x2665, "diams": 0x2666 }; + function emitFiles(resolver, host, targetSourceFile) { + var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; + var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};"; + var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; + var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; + var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; + var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 ? 5 : 0; + var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; + var diagnostics = []; + var newLine = host.getNewLine(); + var jsxDesugaring = host.getCompilerOptions().jsx !== 1; + var shouldEmitJsx = function (s) { return (s.languageVariant === 1 && !jsxDesugaring); }; + if (targetSourceFile === undefined) { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, sourceFile); + } + }); + if (compilerOptions.outFile || compilerOptions.out) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + else { + if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); + return { + emitSkipped: false, + diagnostics: diagnostics, + sourceMaps: sourceMapDataList + }; + function isNodeDescendentOf(node, ancestor) { + while (node) { + if (node === ancestor) + return true; + node = node.parent; + } + return false; + } + function isUniqueLocalName(name, container) { + for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + if (node.locals && ts.hasProperty(node.locals, name)) { + if (node.locals[name].flags & (107455 | 1048576 | 8388608)) { + return false; + } + } + } + return true; + } + function emitJavaScript(jsFilePath, root) { + var writer = ts.createTextWriter(newLine); + var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; + var currentSourceFile; + var exportFunctionForFile; + var generatedNameSet = {}; + var nodeToGeneratedName = []; + var computedPropertyNamesToGeneratedNames; + var extendsEmitted = false; + var decorateEmitted = false; + var paramEmitted = false; + var awaiterEmitted = false; + var tempFlags = 0; + var tempVariables; + var tempParameters; + var externalImports; + var exportSpecifiers; + var exportEquals; + var hasExportStars; + var writeEmittedFiles = writeJavaScriptFile; + var detachedCommentsInfo; + var writeComment = ts.writeCommentRange; + var emit = emitNodeWithCommentsAndWithoutSourcemap; + var emitStart = function (node) { }; + var emitEnd = function (node) { }; + var emitToken = emitTokenText; + var scopeEmitStart = function (scopeDeclaration, scopeName) { }; + var scopeEmitEnd = function () { }; + var sourceMapData; + var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; + var moduleEmitDelegates = (_a = {}, + _a[5] = emitES6Module, + _a[2] = emitAMDModule, + _a[4] = emitSystemModule, + _a[3] = emitUMDModule, + _a[1] = emitCommonJSModule, + _a + ); + if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { + initializeEmitterWithSourceMaps(); + } + if (root) { + emitSourceFile(root); + } + else { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + emitSourceFile(sourceFile); + } + }); + } + writeLine(); + writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); + return; + function emitSourceFile(sourceFile) { + currentSourceFile = sourceFile; + exportFunctionForFile = undefined; + emit(sourceFile); + } + function isUniqueName(name) { + return !resolver.hasGlobalName(name) && + !ts.hasProperty(currentSourceFile.identifiers, name) && + !ts.hasProperty(generatedNameSet, name); + } + function makeTempVariableName(flags) { + if (flags && !(tempFlags & flags)) { + var name_20 = flags === 268435456 ? "_i" : "_n"; + if (isUniqueName(name_20)) { + tempFlags |= flags; + return name_20; + } + } + while (true) { + var count = tempFlags & 268435455; + tempFlags++; + if (count !== 8 && count !== 13) { + var name_21 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_21)) { + return name_21; + } + } + } + } + function makeUniqueName(baseName) { + if (baseName.charCodeAt(baseName.length - 1) !== 95) { + baseName += "_"; + } + var i = 1; + while (true) { + var generatedName = baseName + i; + if (isUniqueName(generatedName)) { + return generatedNameSet[generatedName] = generatedName; + } + i++; + } + } + function generateNameForModuleOrEnum(node) { + var name = node.name.text; + return isUniqueLocalName(name, node) ? name : makeUniqueName(name); + } + function generateNameForImportOrExportDeclaration(node) { + var expr = ts.getExternalModuleName(node); + var baseName = expr.kind === 9 ? + ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; + return makeUniqueName(baseName); + } + function generateNameForExportDefault() { + return makeUniqueName("default"); + } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } + function generateNameForNode(node) { + switch (node.kind) { + case 69: + return makeUniqueName(node.text); + case 218: + case 217: + return generateNameForModuleOrEnum(node); + case 222: + case 228: + return generateNameForImportOrExportDeclaration(node); + case 213: + case 214: + case 227: + return generateNameForExportDefault(); + case 186: + return generateNameForClassExpression(); + } + } + function getGeneratedNameForNode(node) { + var id = ts.getNodeId(node); + return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); + } + function initializeEmitterWithSourceMaps() { + var sourceMapDir; + var sourceMapSourceIndex = -1; + var sourceMapNameIndexMap = {}; + var sourceMapNameIndices = []; + function getSourceMapNameIndex() { + return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; + } + var lastRecordedSourceMapSpan; + var lastEncodedSourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; + var lastEncodedNameIndex = 0; + function encodeLastRecordedSourceMapSpan() { + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { + return; + } + var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; + if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { + if (sourceMapData.sourceMapMappings) { + sourceMapData.sourceMapMappings += ","; + } + } + else { + for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { + sourceMapData.sourceMapMappings += ";"; + } + prevEncodedEmittedColumn = 1; + } + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); + if (lastRecordedSourceMapSpan.nameIndex >= 0) { + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); + lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; + } + lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; + sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); + function base64VLQFormatEncode(inValue) { + function base64FormatEncode(inValue) { + if (inValue < 64) { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); + } + throw TypeError(inValue + ": not a 64 based value"); + } + if (inValue < 0) { + inValue = ((-inValue) << 1) + 1; + } + else { + inValue = inValue << 1; + } + var encodedStr = ""; + do { + var currentDigit = inValue & 31; + inValue = inValue >> 5; + if (inValue > 0) { + currentDigit = currentDigit | 32; + } + encodedStr = encodedStr + base64FormatEncode(currentDigit); + } while (inValue > 0); + return encodedStr; + } + } + function recordSourceMapSpan(pos) { + var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); + sourceLinePos.line++; + sourceLinePos.character++; + var emittedLine = writer.getLine(); + var emittedColumn = writer.getColumn(); + if (!lastRecordedSourceMapSpan || + lastRecordedSourceMapSpan.emittedLine !== emittedLine || + lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || + (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + encodeLastRecordedSourceMapSpan(); + lastRecordedSourceMapSpan = { + emittedLine: emittedLine, + emittedColumn: emittedColumn, + sourceLine: sourceLinePos.line, + sourceColumn: sourceLinePos.character, + nameIndex: getSourceMapNameIndex(), + sourceIndex: sourceMapSourceIndex + }; + } + else { + lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; + lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; + lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; + } + } + function recordEmitNodeStartSpan(node) { + recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); + } + function recordEmitNodeEndSpan(node) { + recordSourceMapSpan(node.end); + } + function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + function recordNewSourceFileStart(node) { + var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, true)); + sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; + sourceMapData.inputSourceFileNames.push(node.fileName); + if (compilerOptions.inlineSources) { + if (!sourceMapData.sourceMapSourcesContent) { + sourceMapData.sourceMapSourcesContent = []; + } + sourceMapData.sourceMapSourcesContent.push(node.text); + } + } + function recordScopeNameOfNode(node, scopeName) { + function recordScopeNameIndex(scopeNameIndex) { + sourceMapNameIndices.push(scopeNameIndex); + } + function recordScopeNameStart(scopeName) { + var scopeNameIndex = -1; + if (scopeName) { + var parentIndex = getSourceMapNameIndex(); + if (parentIndex !== -1) { + var name_22 = node.name; + if (!name_22 || name_22.kind !== 136) { + scopeName = "." + scopeName; + } + scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; + } + scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); + if (scopeNameIndex === undefined) { + scopeNameIndex = sourceMapData.sourceMapNames.length; + sourceMapData.sourceMapNames.push(scopeName); + sourceMapNameIndexMap[scopeName] = scopeNameIndex; + } + } + recordScopeNameIndex(scopeNameIndex); + } + if (scopeName) { + recordScopeNameStart(scopeName); + } + else if (node.kind === 213 || + node.kind === 173 || + node.kind === 143 || + node.kind === 142 || + node.kind === 145 || + node.kind === 146 || + node.kind === 218 || + node.kind === 214 || + node.kind === 217) { + if (node.name) { + var name_23 = node.name; + scopeName = name_23.kind === 136 + ? ts.getTextOfNode(name_23) + : node.name.text; + } + recordScopeNameStart(scopeName); + } + else { + recordScopeNameIndex(getSourceMapNameIndex()); + } + } + function recordScopeNameEnd() { + sourceMapNameIndices.pop(); + } + ; + function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { + recordSourceMapSpan(comment.pos); + ts.writeCommentRange(currentSourceFile, writer, comment, newLine); + recordSourceMapSpan(comment.end); + } + function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { + if (typeof JSON !== "undefined") { + var map_2 = { + version: version, + file: file, + sourceRoot: sourceRoot, + sources: sources, + names: names, + mappings: mappings + }; + if (sourcesContent !== undefined) { + map_2.sourcesContent = sourcesContent; + } + return JSON.stringify(map_2); + } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; + function serializeStringArray(list) { + var output = ""; + for (var i = 0, n = list.length; i < n; i++) { + if (i) { + output += ","; + } + output += "\"" + ts.escapeString(list[i]) + "\""; + } + return output; + } + } + function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { + encodeLastRecordedSourceMapSpan(); + var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); + sourceMapDataList.push(sourceMapData); + var sourceMapUrl; + if (compilerOptions.inlineSourceMap) { + var base64SourceMapText = ts.convertToBase64(sourceMapText); + sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; + } + else { + ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, false); + sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; + } + writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); + } + var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); + sourceMapData = { + sourceMapFilePath: jsFilePath + ".map", + jsSourceMappingURL: sourceMapJsFile + ".map", + sourceMapFile: sourceMapJsFile, + sourceMapSourceRoot: compilerOptions.sourceRoot || "", + sourceMapSources: [], + inputSourceFileNames: [], + sourceMapNames: [], + sourceMapMappings: "", + sourceMapSourcesContent: undefined, + sourceMapDecodedMappings: [] + }; + sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); + if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47) { + sourceMapData.sourceMapSourceRoot += ts.directorySeparator; + } + if (compilerOptions.mapRoot) { + sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); + if (root) { + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); + } + if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { + sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), host.getCurrentDirectory(), host.getCanonicalFileName, true); + } + else { + sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); + } + } + else { + sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); + } + function emitNodeWithSourceMap(node) { + if (node) { + if (ts.nodeIsSynthesized(node)) { + return emitNodeWithoutSourceMap(node); + } + if (node.kind !== 248) { + recordEmitNodeStartSpan(node); + emitNodeWithoutSourceMap(node); + recordEmitNodeEndSpan(node); + } + else { + recordNewSourceFileStart(node); + emitNodeWithoutSourceMap(node); + } + } + } + function emitNodeWithCommentsAndWithSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); + } + writeEmittedFiles = writeJavaScriptAndSourceMapFile; + emit = emitNodeWithCommentsAndWithSourcemap; + emitStart = recordEmitNodeStartSpan; + emitEnd = recordEmitNodeEndSpan; + emitToken = writeTextWithSpanRecord; + scopeEmitStart = recordScopeNameOfNode; + scopeEmitEnd = recordScopeNameEnd; + writeComment = writeCommentRangeWithMap; + } + function writeJavaScriptFile(emitOutput, writeByteOrderMark) { + ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); + } + function createTempVariable(flags) { + var result = ts.createSynthesizedNode(69); + result.text = makeTempVariableName(flags); + return result; + } + function recordTempDeclaration(name) { + if (!tempVariables) { + tempVariables = []; + } + tempVariables.push(name); + } + function createAndRecordTempVariable(flags) { + var temp = createTempVariable(flags); + recordTempDeclaration(temp); + return temp; + } + function emitTempDeclarations(newLine) { + if (tempVariables) { + if (newLine) { + writeLine(); + } + else { + write(" "); + } + write("var "); + emitCommaList(tempVariables); + write(";"); + } + } + function emitTokenText(tokenKind, startPos, emitFn) { + var tokenString = ts.tokenToString(tokenKind); + if (emitFn) { + emitFn(); + } + else { + write(tokenString); + } + return startPos + tokenString.length; + } + function emitOptional(prefix, node) { + if (node) { + write(prefix); + emit(node); + } + } + function emitParenthesizedIf(node, parenthesized) { + if (parenthesized) { + write("("); + } + emit(node); + if (parenthesized) { + write(")"); + } + } + function emitTrailingCommaIfPresent(nodeList) { + if (nodeList.hasTrailingComma) { + write(","); + } + } + function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { + ts.Debug.assert(nodes.length > 0); + increaseIndent(); + if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + for (var i = 0, n = nodes.length; i < n; i++) { + if (i) { + if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { + write(", "); + } + else { + write(","); + writeLine(); + } + } + emit(nodes[i]); + } + if (nodes.hasTrailingComma && allowTrailingComma) { + write(","); + } + decreaseIndent(); + if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + } + function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { + if (!emitNode) { + emitNode = emit; + } + for (var i = 0; i < count; i++) { + if (multiLine) { + if (i || leadingComma) { + write(","); + } + writeLine(); + } + else { + if (i || leadingComma) { + write(", "); + } + } + var node = nodes[start + i]; + emitTrailingCommentsOfPosition(node.pos); + emitNode(node); + leadingComma = true; + } + if (trailingComma) { + write(","); + } + if (multiLine && !noTrailingNewLine) { + writeLine(); + } + return count; + } + function emitCommaList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, false, false); + } + } + function emitLines(nodes) { + emitLinesStartingAt(nodes, 0); + } + function emitLinesStartingAt(nodes, startIndex) { + for (var i = startIndex; i < nodes.length; i++) { + writeLine(); + emit(nodes[i]); + } + } + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 8 && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98: + case 66: + case 111: + case 79: + return true; + } + } + return false; + } + function emitLiteral(node) { + var text = getLiteralText(node); + if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 || ts.isTemplateLiteralKind(node.kind))) { + writer.writeLiteral(text); + } + else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { + write(node.text); + } + else { + write(text); + } + } + function getLiteralText(node) { + if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText("\"", node.text, "\""); + } + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + switch (node.kind) { + case 9: + return getQuotedEscapedLiteralText("\"", node.text, "\""); + case 11: + return getQuotedEscapedLiteralText("`", node.text, "`"); + case 12: + return getQuotedEscapedLiteralText("`", node.text, "${"); + case 13: + return getQuotedEscapedLiteralText("}", node.text, "${"); + case 14: + return getQuotedEscapedLiteralText("}", node.text, "`"); + case 8: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + var isLast = node.kind === 11 || node.kind === 14; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write("\"" + text + "\""); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 11) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(0); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + if (node.template.kind === 183) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 181 + && templateSpan.expression.operatorToken.kind === 24; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); + } + function emitTemplateExpression(node) { + if (languageVersion >= 2) { + ts.forEachChild(node, emit); + return; + } + var emitOuterParens = ts.isExpression(node.parent) + && templateNeedsParens(node, node.parent); + if (emitOuterParens) { + write("("); + } + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + for (var i = 0, n = node.templateSpans.length; i < n; i++) { + var templateSpan = node.templateSpans[i]; + var needsParens = templateSpan.expression.kind !== 172 + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; + if (i > 0 || headEmitted) { + write(" + "); + } + emitParenthesizedIf(templateSpan.expression, needsParens); + if (templateSpan.literal.text.length !== 0) { + write(" + "); + emitLiteral(templateSpan.literal); + } + } + if (emitOuterParens) { + write(")"); + } + function shouldEmitTemplateHead() { + ts.Debug.assert(node.templateSpans.length !== 0); + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template, parent) { + switch (parent.kind) { + case 168: + case 169: + return parent.expression === template; + case 170: + case 172: + return false; + default: + return comparePrecedenceToBinaryPlus(parent) !== -1; + } + } + function comparePrecedenceToBinaryPlus(expression) { + switch (expression.kind) { + case 181: + switch (expression.operatorToken.kind) { + case 37: + case 39: + case 40: + return 1; + case 35: + case 36: + return 0; + default: + return -1; + } + case 184: + case 182: + return -1; + default: + return 1; + } + } + } + function emitTemplateSpan(span) { + emit(span.expression); + emit(span.literal); + } + function jsxEmitReact(node) { + function emitTagName(name) { + if (name.kind === 69 && ts.isIntrinsicJsxName(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + function emitAttributeName(name) { + if (/[A-Za-z_]+[\w*]/.test(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + function emitJsxAttribute(node) { + emitAttributeName(node.name); + write(": "); + if (node.initializer) { + emit(node.initializer); + } + else { + write("true"); + } + } + function emitJsxElement(openingNode, children) { + var syntheticReactRef = ts.createSynthesizedNode(69); + syntheticReactRef.text = "React"; + syntheticReactRef.parent = openingNode; + emitLeadingComments(openingNode); + emitExpressionIdentifier(syntheticReactRef); + write(".createElement("); + emitTagName(openingNode.tagName); + write(", "); + if (openingNode.attributes.length === 0) { + write("null"); + } + else { + var attrs = openingNode.attributes; + if (ts.forEach(attrs, function (attr) { return attr.kind === 239; })) { + emitExpressionIdentifier(syntheticReactRef); + write(".__spread("); + var haveOpenedObjectLiteral = false; + for (var i_1 = 0; i_1 < attrs.length; i_1++) { + if (attrs[i_1].kind === 239) { + if (i_1 === 0) { + write("{}, "); + } + if (haveOpenedObjectLiteral) { + write("}"); + haveOpenedObjectLiteral = false; + } + if (i_1 > 0) { + write(", "); + } + emit(attrs[i_1].expression); + } + else { + ts.Debug.assert(attrs[i_1].kind === 238); + if (haveOpenedObjectLiteral) { + write(", "); + } + else { + haveOpenedObjectLiteral = true; + if (i_1 > 0) { + write(", "); + } + write("{"); + } + emitJsxAttribute(attrs[i_1]); + } + } + if (haveOpenedObjectLiteral) + write("}"); + write(")"); + } + else { + write("{"); + for (var i = 0; i < attrs.length; i++) { + if (i > 0) { + write(", "); + } + emitJsxAttribute(attrs[i]); + } + write("}"); + } + } + if (children) { + for (var i = 0; i < children.length; i++) { + if (children[i].kind === 240 && !(children[i].expression)) { + continue; + } + if (children[i].kind === 236) { + var text = getTextToEmit(children[i]); + if (text !== undefined) { + write(", \""); + write(text); + write("\""); + } + } + else { + write(", "); + emit(children[i]); + } + } + } + write(")"); + emitTrailingComments(openingNode); + } + if (node.kind === 233) { + emitJsxElement(node.openingElement, node.children); + } + else { + ts.Debug.assert(node.kind === 234); + emitJsxElement(node); + } + } + function jsxEmitPreserve(node) { + function emitJsxAttribute(node) { + emit(node.name); + if (node.initializer) { + write("="); + emit(node.initializer); + } + } + function emitJsxSpreadAttribute(node) { + write("{..."); + emit(node.expression); + write("}"); + } + function emitAttributes(attribs) { + for (var i = 0, n = attribs.length; i < n; i++) { + if (i > 0) { + write(" "); + } + if (attribs[i].kind === 239) { + emitJsxSpreadAttribute(attribs[i]); + } + else { + ts.Debug.assert(attribs[i].kind === 238); + emitJsxAttribute(attribs[i]); + } + } + } + function emitJsxOpeningOrSelfClosingElement(node) { + write("<"); + emit(node.tagName); + if (node.attributes.length > 0 || (node.kind === 234)) { + write(" "); + } + emitAttributes(node.attributes); + if (node.kind === 234) { + write("/>"); + } + else { + write(">"); + } + } + function emitJsxClosingElement(node) { + write(""); + } + function emitJsxElement(node) { + emitJsxOpeningOrSelfClosingElement(node.openingElement); + for (var i = 0, n = node.children.length; i < n; i++) { + emit(node.children[i]); + } + emitJsxClosingElement(node.closingElement); + } + if (node.kind === 233) { + emitJsxElement(node); + } + else { + ts.Debug.assert(node.kind === 234); + emitJsxOpeningOrSelfClosingElement(node); + } + } + function emitExpressionForPropertyName(node) { + ts.Debug.assert(node.kind !== 163); + if (node.kind === 9) { + emitLiteral(node); + } + else if (node.kind === 136) { + if (ts.nodeIsDecorated(node.parent)) { + if (!computedPropertyNamesToGeneratedNames) { + computedPropertyNamesToGeneratedNames = []; + } + var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; + if (generatedName) { + write(generatedName); + return; + } + generatedName = createAndRecordTempVariable(0).text; + computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; + write(generatedName); + write(" = "); + } + emit(node.expression); + } + else { + write("\""); + if (node.kind === 8) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + write("\""); + } + } + function isExpressionIdentifier(node) { + var parent = node.parent; + switch (parent.kind) { + case 164: + case 189: + case 181: + case 168: + case 241: + case 136: + case 182: + case 139: + case 175: + case 197: + case 167: + case 227: + case 195: + case 188: + case 199: + case 200: + case 201: + case 196: + case 234: + case 235: + case 239: + case 240: + case 169: + case 172: + case 180: + case 179: + case 204: + case 246: + case 185: + case 206: + case 170: + case 190: + case 208: + case 171: + case 176: + case 177: + case 198: + case 205: + case 184: + return true; + case 163: + case 247: + case 138: + case 245: + case 141: + case 211: + return parent.initializer === node; + case 166: + return parent.expression === node; + case 174: + case 173: + return parent.body === node; + case 221: + return parent.moduleReference === node; + case 135: + return parent.left === node; + } + return false; + } + function emitExpressionIdentifier(node) { + if (resolver.getNodeCheckFlags(node) & 2048) { + write("_arguments"); + return; + } + var container = resolver.getReferencedExportContainer(node); + if (container) { + if (container.kind === 248) { + if (modulekind !== 5 && modulekind !== 4) { + write("exports."); + } + } + else { + write(getGeneratedNameForNode(container)); + write("."); + } + } + else if (modulekind !== 5) { + var declaration = resolver.getReferencedImportDeclaration(node); + if (declaration) { + if (declaration.kind === 223) { + write(getGeneratedNameForNode(declaration.parent)); + write(languageVersion === 0 ? "[\"default\"]" : ".default"); + return; + } + else if (declaration.kind === 226) { + write(getGeneratedNameForNode(declaration.parent.parent.parent)); + var name_24 = declaration.propertyName || declaration.name; + var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name_24); + if (languageVersion === 0 && identifier === "default") { + write("[\"default\"]"); + } + else { + write("."); + write(identifier); + } + return; + } + } + declaration = resolver.getReferencedNestedRedeclaration(node); + if (declaration) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } + if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function isNameOfNestedRedeclaration(node) { + if (languageVersion < 2) { + var parent_6 = node.parent; + switch (parent_6.kind) { + case 163: + case 214: + case 217: + case 211: + return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); + } + } + return false; + } + function emitIdentifier(node) { + if (!node.parent) { + write(node.text); + } + else if (isExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else if (isNameOfNestedRedeclaration(node)) { + write(getGeneratedNameForNode(node)); + } + else if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function emitThis(node) { + if (resolver.getNodeCheckFlags(node) & 2) { + write("_this"); + } + else { + write("this"); + } + } + function emitSuper(node) { + if (languageVersion >= 2) { + write("super"); + } + else { + var flags = resolver.getNodeCheckFlags(node); + if (flags & 256) { + write("_super.prototype"); + } + else { + write("_super"); + } + } + } + function emitObjectBindingPattern(node) { + write("{ "); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write(" }"); + } + function emitArrayBindingPattern(node) { + write("["); + var elements = node.elements; + emitList(elements, 0, elements.length, false, elements.hasTrailingComma); + write("]"); + } + function emitBindingElement(node) { + if (node.propertyName) { + emit(node.propertyName); + write(": "); + } + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + emit(node.name); + } + else { + emitModuleMemberName(node); + } + emitOptional(" = ", node.initializer); + } + function emitSpreadElementExpression(node) { + write("..."); + emit(node.expression); + } + function emitYieldExpression(node) { + write(ts.tokenToString(114)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } + function emitAwaitExpression(node) { + var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); + if (needsParenthesis) { + write("("); + } + write(ts.tokenToString(114)); + write(" "); + emit(node.expression); + if (needsParenthesis) { + write(")"); + } + } + function needsParenthesisForAwaitExpressionAsYield(node) { + if (node.parent.kind === 181 && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { + return true; + } + else if (node.parent.kind === 182 && node.parent.condition === node) { + return true; + } + return false; + } + function needsParenthesisForPropertyAccessOrInvocation(node) { + switch (node.kind) { + case 69: + case 164: + case 166: + case 167: + case 168: + case 172: + return false; + } + return true; + } + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { + var pos = 0; + var group = 0; + var length = elements.length; + while (pos < length) { + if (group === 1 && useConcat) { + write(".concat("); + } + else if (group > 0) { + write(", "); + } + var e = elements[pos]; + if (e.kind === 185) { + e = e.expression; + emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); + pos++; + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 164) { + write(".slice()"); + } + } + else { + var i = pos; + while (i < length && elements[i].kind !== 185) { + i++; + } + write("["); + if (multiLine) { + increaseIndent(); + } + emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); + if (multiLine) { + decreaseIndent(); + } + write("]"); + pos = i; + } + group++; + } + if (group > 1) { + if (useConcat) { + write(")"); + } + } + } + function isSpreadElementExpression(node) { + return node.kind === 185; + } + function emitArrayLiteral(node) { + var elements = node.elements; + if (elements.length === 0) { + write("[]"); + } + else if (languageVersion >= 2 || !ts.forEach(elements, isSpreadElementExpression)) { + write("["); + emitLinePreservingList(node, node.elements, elements.hasTrailingComma, false); + write("]"); + } + else { + emitListWithSpread(elements, true, (node.flags & 2048) !== 0, elements.hasTrailingComma, true); + } + } + function emitObjectLiteralBody(node, numElements) { + if (numElements === 0) { + write("{}"); + return; + } + write("{"); + if (numElements > 0) { + var properties = node.properties; + if (numElements === properties.length) { + emitLinePreservingList(node, properties, languageVersion >= 1, true); + } + else { + var multiLine = (node.flags & 2048) !== 0; + if (!multiLine) { + write(" "); + } + else { + increaseIndent(); + } + emitList(properties, 0, numElements, multiLine, false); + if (!multiLine) { + write(" "); + } + else { + decreaseIndent(); + } + } + } + write("}"); + } + function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { + var multiLine = (node.flags & 2048) !== 0; + var properties = node.properties; + write("("); + if (multiLine) { + increaseIndent(); + } + var tempVar = createAndRecordTempVariable(0); + emit(tempVar); + write(" = "); + emitObjectLiteralBody(node, firstComputedPropertyIndex); + for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { + writeComma(); + var property = properties[i]; + emitStart(property); + if (property.kind === 145 || property.kind === 146) { + var accessors = ts.getAllAccessorDeclarations(node.properties, property); + if (property !== accessors.firstAccessor) { + continue; + } + write("Object.defineProperty("); + emit(tempVar); + write(", "); + emitStart(node.name); + emitExpressionForPropertyName(property.name); + emitEnd(property.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("})"); + emitEnd(property); + } + else { + emitLeadingComments(property); + emitStart(property.name); + emit(tempVar); + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + if (property.kind === 245) { + emit(property.initializer); + } + else if (property.kind === 246) { + emitExpressionIdentifier(property.name); + } + else if (property.kind === 143) { + emitFunctionDeclaration(property); + } + else { + ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); + } + } + emitEnd(property); + } + writeComma(); + emit(tempVar); + if (multiLine) { + decreaseIndent(); + writeLine(); + } + write(")"); + function writeComma() { + if (multiLine) { + write(","); + writeLine(); + } + else { + write(", "); + } + } + } + function emitObjectLiteral(node) { + var properties = node.properties; + if (languageVersion < 2) { + var numProperties = properties.length; + var numInitialNonComputedProperties = numProperties; + for (var i = 0, n = properties.length; i < n; i++) { + if (properties[i].name.kind === 136) { + numInitialNonComputedProperties = i; + break; + } + } + var hasComputedProperty = numInitialNonComputedProperties !== properties.length; + if (hasComputedProperty) { + emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); + return; + } + } + emitObjectLiteralBody(node, properties.length); + } + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(181, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); + result.left = left; + result.right = right; + return result; + } + function createPropertyAccessExpression(expression, name) { + var result = ts.createSynthesizedNode(166); + result.expression = parenthesizeForAccess(expression); + result.dotToken = ts.createSynthesizedNode(21); + result.name = name; + return result; + } + function createElementAccessExpression(expression, argumentExpression) { + var result = ts.createSynthesizedNode(167); + result.expression = parenthesizeForAccess(expression); + result.argumentExpression = argumentExpression; + return result; + } + function parenthesizeForAccess(expr) { + while (expr.kind === 171 || expr.kind === 189) { + expr = expr.expression; + } + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 169 && + expr.kind !== 8) { + return expr; + } + var node = ts.createSynthesizedNode(172); + node.expression = expr; + return node; + } + function emitComputedPropertyName(node) { + write("["); + emitExpressionForPropertyName(node); + write("]"); + } + function emitMethod(node) { + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } + emit(node.name); + if (languageVersion < 2) { + write(": function "); + } + emitSignatureAndBody(node); + } + function emitPropertyAssignment(node) { + emit(node.name); + write(": "); + emitTrailingCommentsOfPosition(node.initializer.pos); + emit(node.initializer); + } + function isNamespaceExportReference(node) { + var container = resolver.getReferencedExportContainer(node); + return container && container.kind !== 248; + } + function emitShorthandPropertyAssignment(node) { + writeTextOfNode(currentSourceFile, node.name); + if (languageVersion < 2 || isNamespaceExportReference(node.name)) { + write(": "); + emit(node.name); + } + if (languageVersion >= 2 && node.objectAssignmentInitializer) { + write(" = "); + emit(node.objectAssignmentInitializer); + } + } + function tryEmitConstantValue(node) { + var constantValue = tryGetConstEnumValue(node); + if (constantValue !== undefined) { + write(constantValue.toString()); + if (!compilerOptions.removeComments) { + var propertyName = node.kind === 166 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + write(" /* " + propertyName + " */"); + } + return true; + } + return false; + } + function tryGetConstEnumValue(node) { + if (compilerOptions.isolatedModules) { + return undefined; + } + return node.kind === 166 || node.kind === 167 + ? resolver.getConstantValue(node) + : undefined; + } + function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { + var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + else { + if (valueToWriteWhenNotIndenting) { + write(valueToWriteWhenNotIndenting); + } + return false; + } + } + function emitPropertyAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); + var shouldEmitSpace; + if (!indentedBeforeDot) { + if (node.expression.kind === 8) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); + shouldEmitSpace = text.indexOf(ts.tokenToString(21)) < 0; + } + else { + var constantValue = tryGetConstEnumValue(node.expression); + shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; + } + } + if (shouldEmitSpace) { + write(" ."); + } + else { + write("."); + } + var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); + emit(node.name); + decreaseIndentIf(indentedBeforeDot, indentedAfterDot); + } + function emitQualifiedName(node) { + emit(node.left); + write("."); + emit(node.right); + } + function emitQualifiedNameAsExpression(node, useFallback) { + if (node.left.kind === 69) { + emitEntityNameAsExpression(node.left, useFallback); + } + else if (useFallback) { + var temp = createAndRecordTempVariable(0); + write("("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(node.left, true); + write(") && "); + emitNodeWithoutSourceMap(temp); + } + else { + emitEntityNameAsExpression(node.left, false); + } + write("."); + emit(node.right); + } + function emitEntityNameAsExpression(node, useFallback) { + switch (node.kind) { + case 69: + if (useFallback) { + write("typeof "); + emitExpressionIdentifier(node); + write(" !== 'undefined' && "); + } + emitExpressionIdentifier(node); + break; + case 135: + emitQualifiedNameAsExpression(node, useFallback); + break; + } + } + function emitIndexedAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("["); + emit(node.argumentExpression); + write("]"); + } + function hasSpreadElement(elements) { + return ts.forEach(elements, function (e) { return e.kind === 185; }); + } + function skipParentheses(node) { + while (node.kind === 172 || node.kind === 171 || node.kind === 189) { + node = node.expression; + } + return node; + } + function emitCallTarget(node) { + if (node.kind === 69 || node.kind === 97 || node.kind === 95) { + emit(node); + return node; + } + var temp = createAndRecordTempVariable(0); + write("("); + emit(temp); + write(" = "); + emit(node); + write(")"); + return temp; + } + function emitCallWithSpread(node) { + var target; + var expr = skipParentheses(node.expression); + if (expr.kind === 166) { + target = emitCallTarget(expr.expression); + write("."); + emit(expr.name); + } + else if (expr.kind === 167) { + target = emitCallTarget(expr.expression); + write("["); + emit(expr.argumentExpression); + write("]"); + } + else if (expr.kind === 95) { + target = expr; + write("_super"); + } + else { + emit(node.expression); + } + write(".apply("); + if (target) { + if (target.kind === 95) { + emitThis(target); + } + else { + emit(target); + } + } + else { + write("void 0"); + } + write(", "); + emitListWithSpread(node.arguments, false, false, false, true); + write(")"); + } + function emitCallExpression(node) { + if (languageVersion < 2 && hasSpreadElement(node.arguments)) { + emitCallWithSpread(node); + return; + } + var superCall = false; + if (node.expression.kind === 95) { + emitSuper(node.expression); + superCall = true; + } + else { + emit(node.expression); + superCall = node.expression.kind === 166 && node.expression.expression.kind === 95; + } + if (superCall && languageVersion < 2) { + write(".call("); + emitThis(node.expression); + if (node.arguments.length) { + write(", "); + emitCommaList(node.arguments); + } + write(")"); + } + else { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitNewExpression(node) { + write("new "); + if (languageVersion === 1 && + node.arguments && + hasSpreadElement(node.arguments)) { + write("("); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, false, false, false, false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + } + function emitTaggedTemplateExpression(node) { + if (languageVersion >= 2) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } + } + function emitParenExpression(node) { + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 174) { + if (node.expression.kind === 171 || node.expression.kind === 189) { + var operand = node.expression.expression; + while (operand.kind === 171 || operand.kind === 189) { + operand = operand.expression; + } + if (operand.kind !== 179 && + operand.kind !== 177 && + operand.kind !== 176 && + operand.kind !== 175 && + operand.kind !== 180 && + operand.kind !== 169 && + !(operand.kind === 168 && node.parent.kind === 169) && + !(operand.kind === 173 && node.parent.kind === 168) && + !(operand.kind === 8 && node.parent.kind === 166)) { + emit(operand); + return; + } + } + } + write("("); + emit(node.expression); + write(")"); + } + function emitDeleteExpression(node) { + write(ts.tokenToString(78)); + write(" "); + emit(node.expression); + } + function emitVoidExpression(node) { + write(ts.tokenToString(103)); + write(" "); + emit(node.expression); + } + function emitTypeOfExpression(node) { + write(ts.tokenToString(101)); + write(" "); + emit(node.expression); + } + function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { + if (!isCurrentFileSystemExternalModule() || node.kind !== 69 || ts.nodeIsSynthesized(node)) { + return false; + } + var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 211 || node.parent.kind === 163); + var targetDeclaration = isVariableDeclarationOrBindingElement + ? node.parent + : resolver.getReferencedValueDeclaration(node); + return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, true); + } + function emitPrefixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + } + write(ts.tokenToString(node.operator)); + if (node.operand.kind === 179) { + var operand = node.operand; + if (node.operator === 35 && (operand.operator === 35 || operand.operator === 41)) { + write(" "); + } + else if (node.operator === 36 && (operand.operator === 36 || operand.operator === 42)) { + write(" "); + } + } + emit(node.operand); + if (exportChanged) { + write(")"); + } + } + function emitPostfixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + write("(" + exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + write(ts.tokenToString(node.operator)); + emit(node.operand); + if (node.operator === 41) { + write(") - 1)"); + } + else { + write(") + 1)"); + } + } + else { + emit(node.operand); + write(ts.tokenToString(node.operator)); + } + } + function shouldHoistDeclarationInSystemJsModule(node) { + return isSourceFileLevelDeclarationInSystemJsModule(node, false); + } + function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { + if (!node || languageVersion >= 2 || !isCurrentFileSystemExternalModule()) { + return false; + } + var current = node; + while (current) { + if (current.kind === 248) { + return !isExported || ((ts.getCombinedNodeFlags(node) & 1) !== 0); + } + else if (ts.isFunctionLike(current) || current.kind === 219) { + return false; + } + else { + current = current.parent; + } + } + } + function emitExponentiationOperator(node) { + var leftHandSideExpression = node.left; + if (node.operatorToken.kind === 60) { + var synthesizedLHS; + var shouldEmitParentheses = false; + if (ts.isElementAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(167, false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, false, false); + synthesizedLHS.expression = identifier; + if (leftHandSideExpression.argumentExpression.kind !== 8 && + leftHandSideExpression.argumentExpression.kind !== 9) { + var tempArgumentExpression = createAndRecordTempVariable(268435456); + synthesizedLHS.argumentExpression = tempArgumentExpression; + emitAssignment(tempArgumentExpression, leftHandSideExpression.argumentExpression, true); + } + else { + synthesizedLHS.argumentExpression = leftHandSideExpression.argumentExpression; + } + write(", "); + } + else if (ts.isPropertyAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(166, false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, false, false); + synthesizedLHS.expression = identifier; + synthesizedLHS.dotToken = leftHandSideExpression.dotToken; + synthesizedLHS.name = leftHandSideExpression.name; + write(", "); + } + emit(synthesizedLHS || leftHandSideExpression); + write(" = "); + write("Math.pow("); + emit(synthesizedLHS || leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + if (shouldEmitParentheses) { + write(")"); + } + } + else { + write("Math.pow("); + emit(leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + } + } + function emitBinaryExpression(node) { + if (languageVersion < 2 && node.operatorToken.kind === 56 && + (node.left.kind === 165 || node.left.kind === 164)) { + emitDestructuring(node, node.parent.kind === 195); + } + else { + var exportChanged = node.operatorToken.kind >= 56 && + node.operatorToken.kind <= 68 && + isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.left); + write("\", "); + } + if (node.operatorToken.kind === 38 || node.operatorToken.kind === 60) { + emitExponentiationOperator(node); + } + else { + emit(node.left); + var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 ? " " : undefined); + write(ts.tokenToString(node.operatorToken.kind)); + var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); + emit(node.right); + decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); + } + if (exportChanged) { + write(")"); + } + } + } + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; + } + function emitConditionalExpression(node) { + emit(node.condition); + var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); + write("?"); + var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); + emit(node.whenTrue); + decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); + var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); + write(":"); + var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); + emit(node.whenFalse); + decreaseIndentIf(indentedBeforeColon, indentedAfterColon); + } + function decreaseIndentIf(value1, value2) { + if (value1) { + decreaseIndent(); + } + if (value2) { + decreaseIndent(); + } + } + function isSingleLineEmptyBlock(node) { + if (node && node.kind === 192) { + var block = node; + return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); + } + } + function emitBlock(node) { + if (isSingleLineEmptyBlock(node)) { + emitToken(15, node.pos); + write(" "); + emitToken(16, node.statements.end); + return; + } + emitToken(15, node.pos); + increaseIndent(); + scopeEmitStart(node.parent); + if (node.kind === 219) { + ts.Debug.assert(node.parent.kind === 218); + emitCaptureThisForNodeIfNecessary(node.parent); + } + emitLines(node.statements); + if (node.kind === 219) { + emitTempDeclarations(true); + } + decreaseIndent(); + writeLine(); + emitToken(16, node.statements.end); + scopeEmitEnd(); + } + function emitEmbeddedStatement(node) { + if (node.kind === 192) { + write(" "); + emit(node); + } + else { + increaseIndent(); + writeLine(); + emit(node); + decreaseIndent(); + } + } + function emitExpressionStatement(node) { + emitParenthesizedIf(node.expression, node.expression.kind === 174); + write(";"); + } + function emitIfStatement(node) { + var endPos = emitToken(88, node.pos); + write(" "); + endPos = emitToken(17, endPos); + emit(node.expression); + emitToken(18, node.expression.end); + emitEmbeddedStatement(node.thenStatement); + if (node.elseStatement) { + writeLine(); + emitToken(80, node.thenStatement.end); + if (node.elseStatement.kind === 196) { + write(" "); + emit(node.elseStatement); + } + else { + emitEmbeddedStatement(node.elseStatement); + } + } + } + function emitDoStatement(node) { + write("do"); + emitEmbeddedStatement(node.statement); + if (node.statement.kind === 192) { + write(" "); + } + else { + writeLine(); + } + write("while ("); + emit(node.expression); + write(");"); + } + function emitWhileStatement(node) { + write("while ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function tryEmitStartOfVariableDeclarationList(decl, startPos) { + if (shouldHoistVariable(decl, true)) { + return false; + } + var tokenKind = 102; + if (decl && languageVersion >= 2) { + if (ts.isLet(decl)) { + tokenKind = 108; + } + else if (ts.isConst(decl)) { + tokenKind = 74; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + write(" "); + } + else { + switch (tokenKind) { + case 102: + write("var "); + break; + case 108: + write("let "); + break; + case 74: + write("const "); + break; + } + } + return true; + } + function emitVariableDeclarationListSkippingUninitializedEntries(list) { + var started = false; + for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { + var decl = _b[_a]; + if (!decl.initializer) { + continue; + } + if (!started) { + started = true; + } + else { + write(", "); + } + emit(decl); + } + return started; + } + function emitForStatement(node) { + var endPos = emitToken(86, node.pos); + write(" "); + endPos = emitToken(17, endPos); + if (node.initializer && node.initializer.kind === 212) { + var variableDeclarationList = node.initializer; + var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + if (startIsEmitted) { + emitCommaList(variableDeclarationList.declarations); + } + else { + emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); + } + } + else if (node.initializer) { + emit(node.initializer); + } + write(";"); + emitOptional(" ", node.condition); + write(";"); + emitOptional(" ", node.incrementor); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForInOrForOfStatement(node) { + if (languageVersion < 2 && node.kind === 201) { + return emitDownLevelForOfStatement(node); + } + var endPos = emitToken(86, node.pos); + write(" "); + endPos = emitToken(17, endPos); + if (node.initializer.kind === 212) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + emit(variableDeclarationList.declarations[0]); + } + } + else { + emit(node.initializer); + } + if (node.kind === 200) { + write(" in "); + } + else { + write(" of "); + } + emit(node.expression); + emitToken(18, node.expression.end); + emitEmbeddedStatement(node.statement); + } + function emitDownLevelForOfStatement(node) { + var endPos = emitToken(86, node.pos); + write(" "); + endPos = emitToken(17, endPos); + var rhsIsIdentifier = node.expression.kind === 69; + var counter = createTempVariable(268435456); + var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0); + emitStart(node.expression); + write("var "); + emitNodeWithoutSourceMap(counter); + write(" = 0"); + emitEnd(node.expression); + if (!rhsIsIdentifier) { + write(", "); + emitStart(node.expression); + emitNodeWithoutSourceMap(rhsReference); + write(" = "); + emitNodeWithoutSourceMap(node.expression); + emitEnd(node.expression); + } + write("; "); + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write(" < "); + emitNodeWithCommentsAndWithoutSourcemap(rhsReference); + write(".length"); + emitEnd(node.initializer); + write("; "); + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write("++"); + emitEnd(node.initializer); + emitToken(18, node.expression.end); + write(" {"); + writeLine(); + increaseIndent(); + var rhsIterationValue = createElementAccessExpression(rhsReference, counter); + emitStart(node.initializer); + if (node.initializer.kind === 212) { + write("var "); + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length > 0) { + var declaration = variableDeclarationList.declarations[0]; + if (ts.isBindingPattern(declaration.name)) { + emitDestructuring(declaration, false, rhsIterationValue); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(declaration); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + emitNodeWithoutSourceMap(createTempVariable(0)); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + var assignmentExpression = createBinaryExpression(node.initializer, 56, rhsIterationValue, false); + if (node.initializer.kind === 164 || node.initializer.kind === 165) { + emitDestructuring(assignmentExpression, true, undefined); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); + } + } + emitEnd(node.initializer); + write(";"); + if (node.statement.kind === 192) { + emitLines(node.statement.statements); + } + else { + writeLine(); + emit(node.statement); + } + writeLine(); + decreaseIndent(); + write("}"); + } + function emitBreakOrContinueStatement(node) { + emitToken(node.kind === 203 ? 70 : 75, node.pos); + emitOptional(" ", node.label); + write(";"); + } + function emitReturnStatement(node) { + emitToken(94, node.pos); + emitOptional(" ", node.expression); + write(";"); + } + function emitWithStatement(node) { + write("with ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitSwitchStatement(node) { + var endPos = emitToken(96, node.pos); + write(" "); + emitToken(17, endPos); + emit(node.expression); + endPos = emitToken(18, node.expression.end); + write(" "); + emitCaseBlock(node.caseBlock, endPos); + } + function emitCaseBlock(node, startPos) { + emitToken(15, startPos); + increaseIndent(); + emitLines(node.clauses); + decreaseIndent(); + writeLine(); + emitToken(16, node.clauses.end); + } + function nodeStartPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function nodeEndPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, node2.end); + } + function nodeEndIsOnSameLineAsNodeStart(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function emitCaseOrDefaultClause(node) { + if (node.kind === 241) { + write("case "); + emit(node.expression); + write(":"); + } + else { + write("default:"); + } + if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { + write(" "); + emit(node.statements[0]); + } + else { + increaseIndent(); + emitLines(node.statements); + decreaseIndent(); + } + } + function emitThrowStatement(node) { + write("throw "); + emit(node.expression); + write(";"); + } + function emitTryStatement(node) { + write("try "); + emit(node.tryBlock); + emit(node.catchClause); + if (node.finallyBlock) { + writeLine(); + write("finally "); + emit(node.finallyBlock); + } + } + function emitCatchClause(node) { + writeLine(); + var endPos = emitToken(72, node.pos); + write(" "); + emitToken(17, endPos); + emit(node.variableDeclaration); + emitToken(18, node.variableDeclaration ? node.variableDeclaration.end : endPos); + write(" "); + emitBlock(node.block); + } + function emitDebuggerStatement(node) { + emitToken(76, node.pos); + write(";"); + } + function emitLabelledStatement(node) { + emit(node.label); + write(": "); + emit(node.statement); + } + function getContainingModule(node) { + do { + node = node.parent; + } while (node && node.kind !== 218); + return node; + } + function emitContainingModuleName(node) { + var container = getContainingModule(node); + write(container ? getGeneratedNameForNode(container) : "exports"); + } + function emitModuleMemberName(node) { + emitStart(node.name); + if (ts.getCombinedNodeFlags(node) & 1) { + var container = getContainingModule(node); + if (container) { + write(getGeneratedNameForNode(container)); + write("."); + } + else if (modulekind !== 5 && modulekind !== 4) { + write("exports."); + } + } + emitNodeWithCommentsAndWithoutSourcemap(node.name); + emitEnd(node.name); + } + function createVoidZero() { + var zero = ts.createSynthesizedNode(8); + zero.text = "0"; + var result = ts.createSynthesizedNode(177); + result.expression = zero; + return result; + } + function emitEs6ExportDefaultCompat(node) { + if (node.parent.kind === 248) { + ts.Debug.assert(!!(node.flags & 1024) || node.kind === 227); + if (modulekind === 1 || modulekind === 2 || modulekind === 3) { + if (!currentSourceFile.symbol.exports["___esModule"]) { + if (languageVersion === 1) { + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else if (languageVersion === 0) { + write("exports.__esModule = true;"); + writeLine(); + } + } + } + } + } + function emitExportMemberAssignment(node) { + if (node.flags & 1) { + writeLine(); + emitStart(node); + if (modulekind === 4 && node.parent === currentSourceFile) { + write(exportFunctionForFile + "(\""); + if (node.flags & 1024) { + write("default"); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + write("\", "); + emitDeclarationName(node); + write(")"); + } + else { + if (node.flags & 1024) { + emitEs6ExportDefaultCompat(node); + if (languageVersion === 0) { + write("exports[\"default\"]"); + } + else { + write("exports.default"); + } + } + else { + emitModuleMemberName(node); + } + write(" = "); + emitDeclarationName(node); + } + emitEnd(node); + write(";"); + } + } + function emitExportMemberAssignments(name) { + if (modulekind === 4) { + return; + } + if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { + var specifier = _b[_a]; + writeLine(); + emitStart(specifier.name); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + emitEnd(specifier.name); + write(" = "); + emitExpressionIdentifier(name); + write(";"); + } + } + } + function emitExportSpecifierInSystemModule(specifier) { + ts.Debug.assert(modulekind === 4); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } + writeLine(); + emitStart(specifier.name); + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write("\", "); + emitExpressionIdentifier(specifier.propertyName || specifier.name); + write(")"); + emitEnd(specifier.name); + write(";"); + } + function emitAssignment(name, value, shouldEmitCommaBeforeAssignment) { + if (shouldEmitCommaBeforeAssignment) { + write(", "); + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(name); + write("\", "); + } + var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 211 || name.parent.kind === 163); + if (isVariableDeclarationOrBindingElement) { + emitModuleMemberName(name.parent); + } + else { + emit(name); + } + write(" = "); + emit(value); + if (exportChanged) { + write(")"); + } + } + function emitTempVariableAssignment(expression, canDefineTempVariablesInPlace, shouldEmitCommaBeforeAssignment) { + var identifier = createTempVariable(0); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expression, shouldEmitCommaBeforeAssignment); + return identifier; + } + function emitDestructuring(root, isAssignmentExpressionStatement, value) { + var emitCount = 0; + var canDefineTempVariablesInPlace = false; + if (root.kind === 211) { + var isExported = ts.getCombinedNodeFlags(root) & 1; + var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); + canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; + } + else if (root.kind === 138) { + canDefineTempVariablesInPlace = true; + } + if (root.kind === 181) { + emitAssignmentExpression(root); + } + else { + ts.Debug.assert(!isAssignmentExpressionStatement); + emitBindingElement(root, value); + } + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 69 && reuseIdentifierExpressions) { + return expr; + } + var identifier = emitTempVariableAssignment(expr, canDefineTempVariablesInPlace, emitCount > 0); + emitCount++; + return identifier; + } + function createDefaultValueCheck(value, defaultValue) { + value = ensureIdentifier(value, true); + var equals = ts.createSynthesizedNode(181); + equals.left = value; + equals.operatorToken = ts.createSynthesizedNode(32); + equals.right = createVoidZero(); + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(182); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(53); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(54); + cond.whenFalse = whenFalse; + return cond; + } + function createNumericLiteral(value) { + var node = ts.createSynthesizedNode(8); + node.text = "" + value; + return node; + } + function createPropertyAccessForDestructuringProperty(object, propName) { + var syntheticName = ts.createSynthesizedNode(propName.kind); + syntheticName.text = propName.text; + if (syntheticName.kind !== 69) { + return createElementAccessExpression(object, syntheticName); + } + return createPropertyAccessExpression(object, syntheticName); + } + function createSliceCall(value, sliceIndex) { + var call = ts.createSynthesizedNode(168); + var sliceIdentifier = ts.createSynthesizedNode(69); + sliceIdentifier.text = "slice"; + call.expression = createPropertyAccessExpression(value, sliceIdentifier); + call.arguments = ts.createSynthesizedNodeArray(); + call.arguments[0] = createNumericLiteral(sliceIndex); + return call; + } + function emitObjectLiteralAssignment(target, value) { + var properties = target.properties; + if (properties.length !== 1) { + value = ensureIdentifier(value, true); + } + for (var _a = 0; _a < properties.length; _a++) { + var p = properties[_a]; + if (p.kind === 245 || p.kind === 246) { + var propName = p.name; + var target_1 = p.kind === 246 ? p : p.initializer || propName; + emitDestructuringAssignment(target_1, createPropertyAccessForDestructuringProperty(value, propName)); + } + } + } + function emitArrayLiteralAssignment(target, value) { + var elements = target.elements; + if (elements.length !== 1) { + value = ensureIdentifier(value, true); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 187) { + if (e.kind !== 185) { + emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === elements.length - 1) { + emitDestructuringAssignment(e.expression, createSliceCall(value, i)); + } + } + } + } + function emitDestructuringAssignment(target, value) { + if (target.kind === 246) { + if (target.objectAssignmentInitializer) { + value = createDefaultValueCheck(value, target.objectAssignmentInitializer); + } + target = target.name; + } + else if (target.kind === 181 && target.operatorToken.kind === 56) { + value = createDefaultValueCheck(value, target.right); + target = target.left; + } + if (target.kind === 165) { + emitObjectLiteralAssignment(target, value); + } + else if (target.kind === 164) { + emitArrayLiteralAssignment(target, value); + } + else { + emitAssignment(target, value, emitCount > 0); + emitCount++; + } + } + function emitAssignmentExpression(root) { + var target = root.left; + var value = root.right; + if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { + emit(value); + } + else if (isAssignmentExpressionStatement) { + emitDestructuringAssignment(target, value); + } + else { + if (root.parent.kind !== 172) { + write("("); + } + value = ensureIdentifier(value, true); + emitDestructuringAssignment(target, value); + write(", "); + emit(value); + if (root.parent.kind !== 172) { + write(")"); + } + } + } + function emitBindingElement(target, value) { + if (target.initializer) { + value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; + } + else if (!value) { + value = createVoidZero(); + } + if (ts.isBindingPattern(target.name)) { + var pattern = target.name; + var elements = pattern.elements; + var numElements = elements.length; + if (numElements !== 1) { + value = ensureIdentifier(value, numElements !== 0); + } + for (var i = 0; i < numElements; i++) { + var element = elements[i]; + if (pattern.kind === 161) { + var propName = element.propertyName || element.name; + emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); + } + else if (element.kind !== 187) { + if (!element.dotDotDotToken) { + emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === numElements - 1) { + emitBindingElement(element, createSliceCall(value, i)); + } + } + } + } + else { + emitAssignment(target.name, value, emitCount > 0); + emitCount++; + } + } + } + function emitVariableDeclaration(node) { + if (ts.isBindingPattern(node.name)) { + if (languageVersion < 2) { + emitDestructuring(node, false); + } + else { + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + else { + var initializer = node.initializer; + if (!initializer && languageVersion < 2) { + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384) && + (getCombinedFlagsForIdentifier(node.name) & 16384); + if (isUninitializedLet && + node.parent.parent.kind !== 200 && + node.parent.parent.kind !== 201) { + initializer = createVoidZero(); + } + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(node.name); + write("\", "); + } + emitModuleMemberName(node); + emitOptional(" = ", initializer); + if (exportChanged) { + write(")"); + } + } + } + function emitExportVariableAssignments(node) { + if (node.kind === 187) { + return; + } + var name = node.name; + if (name.kind === 69) { + emitExportMemberAssignments(name); + } + else if (ts.isBindingPattern(name)) { + ts.forEach(name.elements, emitExportVariableAssignments); + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 211 && node.parent.kind !== 163)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function isES6ExportedDeclaration(node) { + return !!(node.flags & 1) && + modulekind === 5 && + node.parent.kind === 248; + } + function emitVariableStatement(node) { + var startIsEmitted = false; + if (node.flags & 1) { + if (isES6ExportedDeclaration(node)) { + write("export "); + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + } + else { + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + if (startIsEmitted) { + emitCommaList(node.declarationList.declarations); + write(";"); + } + else { + var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); + if (atLeastOneItem) { + write(";"); + } + } + if (modulekind !== 5 && node.parent === currentSourceFile) { + ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); + } + } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + if (!(node.flags & 1)) { + return true; + } + if (isES6ExportedDeclaration(node)) { + return true; + } + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } + function emitParameter(node) { + if (languageVersion < 2) { + if (ts.isBindingPattern(node.name)) { + var name_25 = createTempVariable(0); + if (!tempParameters) { + tempParameters = []; + } + tempParameters.push(name_25); + emit(name_25); + } + else { + emit(node.name); + } + } + else { + if (node.dotDotDotToken) { + write("..."); + } + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + function emitDefaultValueAssignments(node) { + if (languageVersion < 2) { + var tempIndex = 0; + ts.forEach(node.parameters, function (parameter) { + if (parameter.dotDotDotToken) { + return; + } + var paramName = parameter.name, initializer = parameter.initializer; + if (ts.isBindingPattern(paramName)) { + var hasBindingElements = paramName.elements.length > 0; + if (hasBindingElements || initializer) { + writeLine(); + write("var "); + if (hasBindingElements) { + emitDestructuring(parameter, false, tempParameters[tempIndex]); + } + else { + emit(tempParameters[tempIndex]); + write(" = "); + emit(initializer); + } + write(";"); + tempIndex++; + } + } + else if (initializer) { + writeLine(); + emitStart(parameter); + write("if ("); + emitNodeWithoutSourceMap(paramName); + write(" === void 0)"); + emitEnd(parameter); + write(" { "); + emitStart(parameter); + emitNodeWithCommentsAndWithoutSourcemap(paramName); + write(" = "); + emitNodeWithCommentsAndWithoutSourcemap(initializer); + emitEnd(parameter); + write("; }"); + } + }); + } + } + function emitRestParameter(node) { + if (languageVersion < 2 && ts.hasRestParameter(node)) { + var restIndex = node.parameters.length - 1; + var restParam = node.parameters[restIndex]; + if (ts.isBindingPattern(restParam.name)) { + return; + } + var tempName = createTempVariable(268435456).text; + writeLine(); + emitLeadingComments(restParam); + emitStart(restParam); + write("var "); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write(" = [];"); + emitEnd(restParam); + emitTrailingComments(restParam); + writeLine(); + write("for ("); + emitStart(restParam); + write("var " + tempName + " = " + restIndex + ";"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + " < arguments.length;"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + "++"); + emitEnd(restParam); + write(") {"); + increaseIndent(); + writeLine(); + emitStart(restParam); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); + emitEnd(restParam); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitAccessor(node) { + write(node.kind === 145 ? "get " : "set "); + emit(node.name); + emitSignatureAndBody(node); + } + function shouldEmitAsArrowFunction(node) { + return node.kind === 174 && languageVersion >= 2; + } + function emitDeclarationName(node) { + if (node.name) { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + else { + write(getGeneratedNameForNode(node)); + } + } + function shouldEmitFunctionName(node) { + if (node.kind === 173) { + return !!node.name; + } + if (node.kind === 213) { + return !!node.name || languageVersion < 2; + } + } + function emitFunctionDeclaration(node) { + if (ts.nodeIsMissing(node.body)) { + return emitCommentsOnNotEmittedNode(node); + } + if (node.kind !== 143 && node.kind !== 142 && + node.parent && node.parent.kind !== 245 && + node.parent.kind !== 168) { + emitLeadingComments(node); + } + emitStart(node); + if (!shouldEmitAsArrowFunction(node)) { + if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024) { + write("default "); + } + } + write("function"); + if (languageVersion >= 2 && node.asteriskToken) { + write("*"); + } + write(" "); + } + if (shouldEmitFunctionName(node)) { + emitDeclarationName(node); + } + emitSignatureAndBody(node); + if (modulekind !== 5 && node.kind === 213 && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + emitEnd(node); + if (node.kind !== 143 && node.kind !== 142) { + emitTrailingComments(node); + } + } + function emitCaptureThisForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 4) { + writeLine(); + emitStart(node); + write("var _this = this;"); + emitEnd(node); + } + } + function emitSignatureParameters(node) { + increaseIndent(); + write("("); + if (node) { + var parameters = node.parameters; + var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0; + emitList(parameters, 0, parameters.length - omitCount, false, false); + } + write(")"); + decreaseIndent(); + } + function emitSignatureParametersForArrow(node) { + if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { + emit(node.parameters[0]); + return; + } + emitSignatureParameters(node); + } + function emitAsyncFunctionBodyForES6(node) { + var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); + var isArrowFunction = node.kind === 174; + var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096) !== 0; + var args; + if (!isArrowFunction) { + write(" {"); + increaseIndent(); + writeLine(); + write("return"); + } + write(" __awaiter(this"); + if (hasLexicalArguments) { + write(", arguments"); + } + else { + write(", void 0"); + } + if (promiseConstructor) { + write(", "); + emitNodeWithoutSourceMap(promiseConstructor); + } + else { + write(", Promise"); + } + if (hasLexicalArguments) { + write(", function* (_arguments)"); + } + else { + write(", function* ()"); + } + emitFunctionBody(node); + write(")"); + if (!isArrowFunction) { + write(";"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitFunctionBody(node) { + if (!node.body) { + write(" { }"); + } + else { + if (node.body.kind === 192) { + emitBlockFunctionBody(node, node.body); + } + else { + emitExpressionFunctionBody(node, node.body); + } + } + } + function emitSignatureAndBody(node) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + if (shouldEmitAsArrowFunction(node)) { + emitSignatureParametersForArrow(node); + write(" =>"); + } + else { + emitSignatureParameters(node); + } + var isAsync = ts.isAsyncFunctionLike(node); + if (isAsync && languageVersion === 2) { + emitAsyncFunctionBodyForES6(node); + } + else { + emitFunctionBody(node); + } + if (!isES6ExportedDeclaration(node)) { + emitExportMemberAssignment(node); + } + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function emitFunctionBodyPreamble(node) { + emitCaptureThisForNodeIfNecessary(node); + emitDefaultValueAssignments(node); + emitRestParameter(node); + } + function emitExpressionFunctionBody(node, body) { + if (languageVersion < 2 || node.flags & 512) { + emitDownLevelExpressionFunctionBody(node, body); + return; + } + write(" "); + var current = body; + while (current.kind === 171) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 165); + } + function emitDownLevelExpressionFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + increaseIndent(); + var outPos = writer.getTextPos(); + emitDetachedComments(node.body); + emitFunctionBodyPreamble(node); + var preambleEmitted = writer.getTextPos() !== outPos; + decreaseIndent(); + if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { + write(" "); + emitStart(body); + write("return "); + emit(body); + emitEnd(body); + write(";"); + emitTempDeclarations(false); + write(" "); + } + else { + increaseIndent(); + writeLine(); + emitLeadingComments(node.body); + write("return "); + emit(body); + write(";"); + emitTrailingComments(node.body); + emitTempDeclarations(true); + decreaseIndent(); + writeLine(); + } + emitStart(node.body); + write("}"); + emitEnd(node.body); + scopeEmitEnd(); + } + function emitBlockFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + var initialTextPos = writer.getTextPos(); + increaseIndent(); + emitDetachedComments(body.statements); + var startIndex = emitDirectivePrologues(body.statements, true); + emitFunctionBodyPreamble(node); + decreaseIndent(); + var preambleEmitted = writer.getTextPos() !== initialTextPos; + if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { + for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { + var statement = _b[_a]; + write(" "); + emit(statement); + } + emitTempDeclarations(false); + write(" "); + emitLeadingCommentsOfPosition(body.statements.end); + } + else { + increaseIndent(); + emitLinesStartingAt(body.statements, startIndex); + emitTempDeclarations(true); + writeLine(); + emitLeadingCommentsOfPosition(body.statements.end); + decreaseIndent(); + } + emitToken(16, body.statements.end); + scopeEmitEnd(); + } + function findInitialSuperCall(ctor) { + if (ctor.body) { + var statement = ctor.body.statements[0]; + if (statement && statement.kind === 195) { + var expr = statement.expression; + if (expr && expr.kind === 168) { + var func = expr.expression; + if (func && func.kind === 95) { + return statement; + } + } + } + } + } + function emitParameterPropertyAssignments(node) { + ts.forEach(node.parameters, function (param) { + if (param.flags & 112) { + writeLine(); + emitStart(param); + emitStart(param.name); + write("this."); + emitNodeWithoutSourceMap(param.name); + emitEnd(param.name); + write(" = "); + emit(param.name); + write(";"); + emitEnd(param); + } + }); + } + function emitMemberAccessForPropertyName(memberName) { + if (memberName.kind === 9 || memberName.kind === 8) { + write("["); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + write("]"); + } + else if (memberName.kind === 136) { + emitComputedPropertyName(memberName); + } + else { + write("."); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + } + } + function getInitializedProperties(node, isStatic) { + var properties = []; + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if (member.kind === 141 && isStatic === ((member.flags & 128) !== 0) && member.initializer) { + properties.push(member); + } + } + return properties; + } + function emitPropertyDeclarations(node, properties) { + for (var _a = 0; _a < properties.length; _a++) { + var property = properties[_a]; + emitPropertyDeclaration(node, property); + } + } + function emitPropertyDeclaration(node, property, receiver, isExpression) { + writeLine(); + emitLeadingComments(property); + emitStart(property); + emitStart(property.name); + if (receiver) { + emit(receiver); + } + else { + if (property.flags & 128) { + emitDeclarationName(node); + } + else { + write("this"); + } + } + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + emit(property.initializer); + if (!isExpression) { + write(";"); + } + emitEnd(property); + emitTrailingComments(property); + } + function emitMemberFunctionsForES5AndLower(node) { + ts.forEach(node.members, function (member) { + if (member.kind === 191) { + writeLine(); + write(";"); + } + else if (member.kind === 143 || node.kind === 142) { + if (!member.body) { + return emitCommentsOnNotEmittedNode(member); + } + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + emitClassMemberPrefix(node, member); + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emitFunctionDeclaration(member); + emitEnd(member); + write(";"); + emitTrailingComments(member); + } + else if (member.kind === 145 || member.kind === 146) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor) { + writeLine(); + emitStart(member); + write("Object.defineProperty("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("});"); + emitEnd(member); + } + } + }); + } + function emitMemberFunctionsForES6AndHigher(node) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if ((member.kind === 143 || node.kind === 142) && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + else if (member.kind === 143 || + member.kind === 145 || + member.kind === 146) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + if (member.flags & 128) { + write("static "); + } + if (member.kind === 145) { + write("get "); + } + else if (member.kind === 146) { + write("set "); + } + if (member.asteriskToken) { + write("*"); + } + emit(member.name); + emitSignatureAndBody(member); + emitEnd(member); + emitTrailingComments(member); + } + else if (member.kind === 191) { + writeLine(); + write(";"); + } + } + } + function emitConstructor(node, baseTypeElement) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + emitConstructorWorker(node, baseTypeElement); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function emitConstructorWorker(node, baseTypeElement) { + var hasInstancePropertyWithInitializer = false; + ts.forEach(node.members, function (member) { + if (member.kind === 144 && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + if (member.kind === 141 && member.initializer && (member.flags & 128) === 0) { + hasInstancePropertyWithInitializer = true; + } + }); + var ctor = ts.getFirstConstructorWithBody(node); + if (languageVersion >= 2 && !ctor && !hasInstancePropertyWithInitializer) { + return; + } + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + if (languageVersion < 2) { + write("function "); + emitDeclarationName(node); + emitSignatureParameters(ctor); + } + else { + write("constructor"); + if (ctor) { + emitSignatureParameters(ctor); + } + else { + if (baseTypeElement) { + write("(...args)"); + } + else { + write("()"); + } + } + } + var startIndex = 0; + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + startIndex = emitDirectivePrologues(ctor.body.statements, true); + emitDetachedComments(ctor.body.statements); + } + emitCaptureThisForNodeIfNecessary(node); + var superCall; + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeElement) { + superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeElement) { + writeLine(); + emitStart(baseTypeElement); + if (languageVersion < 2) { + write("_super.apply(this, arguments);"); + } + else { + write("super(...args);"); + } + emitEnd(baseTypeElement); + } + } + emitPropertyDeclarations(node, getInitializedProperties(node, false)); + if (ctor) { + var statements = ctor.body.statements; + if (superCall) { + statements = statements.slice(1); + } + emitLinesStartingAt(statements, startIndex); + } + emitTempDeclarations(true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition(ctor.body.statements.end); + } + decreaseIndent(); + emitToken(16, ctor ? ctor.body.statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + } + function emitClassExpression(node) { + return emitClassLikeDeclaration(node); + } + function emitClassDeclaration(node) { + return emitClassLikeDeclaration(node); + } + function emitClassLikeDeclaration(node) { + if (languageVersion < 2) { + emitClassLikeDeclarationBelowES6(node); + } + else { + emitClassLikeDeclarationForES6AndHigher(node); + } + if (modulekind !== 5 && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + } + function emitClassLikeDeclarationForES6AndHigher(node) { + var thisNodeIsDecorated = ts.nodeIsDecorated(node); + if (node.kind === 214) { + if (thisNodeIsDecorated) { + if (isES6ExportedDeclaration(node) && !(node.flags & 1024)) { + write("export "); + } + write("let "); + emitDeclarationName(node); + write(" = "); + } + else if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024) { + write("default "); + } + } + } + var staticProperties = getInitializedProperties(node, true); + var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 186; + var tempVariable; + if (isClassExpressionWithStaticProperties) { + tempVariable = createAndRecordTempVariable(0); + write("("); + increaseIndent(); + emit(tempVariable); + write(" = "); + } + write("class"); + if ((node.name || (node.flags & 1024 && staticProperties.length > 0)) && !thisNodeIsDecorated) { + write(" "); + emitDeclarationName(node); + } + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write(" extends "); + emit(baseTypeNode.expression); + } + write(" {"); + increaseIndent(); + scopeEmitStart(node); + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES6AndHigher(node); + decreaseIndent(); + writeLine(); + emitToken(16, node.members.end); + scopeEmitEnd(); + if (thisNodeIsDecorated) { + write(";"); + } + if (isClassExpressionWithStaticProperties) { + for (var _a = 0; _a < staticProperties.length; _a++) { + var property = staticProperties[_a]; + write(","); + writeLine(); + emitPropertyDeclaration(node, property, tempVariable, true); + } + write(","); + writeLine(); + emit(tempVariable); + decreaseIndent(); + write(")"); + } + else { + writeLine(); + emitPropertyDeclarations(node, staticProperties); + emitDecoratorsOfClass(node); + } + if (!isES6ExportedDeclaration(node) && (node.flags & 1)) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } + else if (isES6ExportedDeclaration(node) && (node.flags & 1024) && thisNodeIsDecorated) { + writeLine(); + write("export default "); + emitDeclarationName(node); + write(";"); + } + } + function emitClassLikeDeclarationBelowES6(node) { + if (node.kind === 214) { + if (!shouldHoistDeclarationInSystemJsModule(node)) { + write("var "); + } + emitDeclarationName(node); + write(" = "); + } + write("(function ("); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write("_super"); + } + write(") {"); + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + computedPropertyNamesToGeneratedNames = undefined; + increaseIndent(); + scopeEmitStart(node); + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("__extends("); + emitDeclarationName(node); + write(", _super);"); + emitEnd(baseTypeNode); + } + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES5AndLower(node); + emitPropertyDeclarations(node, getInitializedProperties(node, true)); + writeLine(); + emitDecoratorsOfClass(node); + writeLine(); + emitToken(16, node.members.end, function () { + write("return "); + emitDeclarationName(node); + }); + write(";"); + emitTempDeclarations(true); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; + decreaseIndent(); + writeLine(); + emitToken(16, node.members.end); + scopeEmitEnd(); + emitStart(node); + write(")("); + if (baseTypeNode) { + emit(baseTypeNode.expression); + } + write(")"); + if (node.kind === 214) { + write(";"); + } + emitEnd(node); + if (node.kind === 214) { + emitExportMemberAssignment(node); + } + } + function emitClassMemberPrefix(node, member) { + emitDeclarationName(node); + if (!(member.flags & 128)) { + write(".prototype"); + } + } + function emitDecoratorsOfClass(node) { + emitDecoratorsOfMembers(node, 0); + emitDecoratorsOfMembers(node, 128); + emitDecoratorsOfConstructor(node); + } + function emitDecoratorsOfConstructor(node) { + var decorators = node.decorators; + var constructor = ts.getFirstConstructorWithBody(node); + var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); + if (!decorators && !hasDecoratedParameters) { + return; + } + writeLine(); + emitStart(node); + emitDeclarationName(node); + write(" = __decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(constructor, argumentsWritten > 0); + emitSerializedTypeMetadata(node, argumentsWritten >= 0); + decreaseIndent(); + writeLine(); + write("], "); + emitDeclarationName(node); + write(");"); + emitEnd(node); + writeLine(); + } + function emitDecoratorsOfMembers(node, staticFlag) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if ((member.flags & 128) !== staticFlag) { + continue; + } + if (!ts.nodeCanBeDecorated(member)) { + continue; + } + if (!ts.nodeOrChildIsDecorated(member)) { + continue; + } + var decorators = void 0; + var functionLikeMember = void 0; + if (ts.isAccessor(member)) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member !== accessors.firstAccessor) { + continue; + } + decorators = accessors.firstAccessor.decorators; + if (!decorators && accessors.secondAccessor) { + decorators = accessors.secondAccessor.decorators; + } + functionLikeMember = accessors.setAccessor; + } + else { + decorators = member.decorators; + if (member.kind === 143) { + functionLikeMember = member; + } + } + writeLine(); + emitStart(member); + write("__decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, true, false, false, true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); + emitSerializedTypeMetadata(member, argumentsWritten > 0); + decreaseIndent(); + writeLine(); + write("], "); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + if (languageVersion > 0) { + if (member.kind !== 141) { + write(", null"); + } + else { + write(", void 0"); + } + } + write(");"); + emitEnd(member); + writeLine(); + } + } + function emitDecoratorsOfParameters(node, leadingComma) { + var argumentsWritten = 0; + if (node) { + var parameterIndex = 0; + for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { + var parameter = _b[_a]; + if (ts.nodeIsDecorated(parameter)) { + var decorators = parameter.decorators; + argumentsWritten += emitList(decorators, 0, decorators.length, true, false, leadingComma, true, function (decorator) { + emitStart(decorator); + write("__param(" + parameterIndex + ", "); + emit(decorator.expression); + write(")"); + emitEnd(decorator); + }); + leadingComma = true; + } + ++parameterIndex; + } + } + return argumentsWritten; + } + function shouldEmitTypeMetadata(node) { + switch (node.kind) { + case 143: + case 145: + case 146: + case 141: + return true; + } + return false; + } + function shouldEmitReturnTypeMetadata(node) { + switch (node.kind) { + case 143: + return true; + } + return false; + } + function shouldEmitParamTypesMetadata(node) { + switch (node.kind) { + case 214: + case 143: + case 146: + return true; + } + return false; + } + function emitSerializedTypeOfNode(node) { + switch (node.kind) { + case 214: + write("Function"); + return; + case 141: + emitSerializedTypeNode(node.type); + return; + case 138: + emitSerializedTypeNode(node.type); + return; + case 145: + emitSerializedTypeNode(node.type); + return; + case 146: + emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); + return; + } + if (ts.isFunctionLike(node)) { + write("Function"); + return; + } + write("void 0"); + } + function emitSerializedTypeNode(node) { + if (node) { + switch (node.kind) { + case 103: + write("void 0"); + return; + case 160: + emitSerializedTypeNode(node.type); + return; + case 152: + case 153: + write("Function"); + return; + case 156: + case 157: + write("Array"); + return; + case 150: + case 120: + write("Boolean"); + return; + case 130: + case 9: + write("String"); + return; + case 128: + write("Number"); + return; + case 131: + write("Symbol"); + return; + case 151: + emitSerializedTypeReferenceNode(node); + return; + case 154: + case 155: + case 158: + case 159: + case 117: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } + } + write("Object"); + } + function emitSerializedTypeReferenceNode(node) { + var location = node.parent; + while (ts.isDeclaration(location) || ts.isTypeNode(location)) { + location = location.parent; + } + var typeName = ts.cloneEntityName(node.typeName); + typeName.parent = location; + var result = resolver.getTypeReferenceSerializationKind(typeName); + switch (result) { + case ts.TypeReferenceSerializationKind.Unknown: + var temp = createAndRecordTempVariable(0); + write("(typeof ("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(typeName, true); + write(") === 'function' && "); + emitNodeWithoutSourceMap(temp); + write(") || Object"); + break; + case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: + emitEntityNameAsExpression(typeName, false); + break; + case ts.TypeReferenceSerializationKind.VoidType: + write("void 0"); + break; + case ts.TypeReferenceSerializationKind.BooleanType: + write("Boolean"); + break; + case ts.TypeReferenceSerializationKind.NumberLikeType: + write("Number"); + break; + case ts.TypeReferenceSerializationKind.StringLikeType: + write("String"); + break; + case ts.TypeReferenceSerializationKind.ArrayLikeType: + write("Array"); + break; + case ts.TypeReferenceSerializationKind.ESSymbolType: + if (languageVersion < 2) { + write("typeof Symbol === 'function' ? Symbol : Object"); + } + else { + write("Symbol"); + } + break; + case ts.TypeReferenceSerializationKind.TypeWithCallSignature: + write("Function"); + break; + case ts.TypeReferenceSerializationKind.ObjectType: + write("Object"); + break; + } + } + function emitSerializedParameterTypesOfNode(node) { + if (node) { + var valueDeclaration; + if (node.kind === 214) { + valueDeclaration = ts.getFirstConstructorWithBody(node); + } + else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { + valueDeclaration = node; + } + if (valueDeclaration) { + var parameters = valueDeclaration.parameters; + var parameterCount = parameters.length; + if (parameterCount > 0) { + for (var i = 0; i < parameterCount; i++) { + if (i > 0) { + write(", "); + } + if (parameters[i].dotDotDotToken) { + var parameterType = parameters[i].type; + if (parameterType.kind === 156) { + parameterType = parameterType.elementType; + } + else if (parameterType.kind === 151 && parameterType.typeArguments && parameterType.typeArguments.length === 1) { + parameterType = parameterType.typeArguments[0]; + } + else { + parameterType = undefined; + } + emitSerializedTypeNode(parameterType); + } + else { + emitSerializedTypeOfNode(parameters[i]); + } + } + } + } + } + } + function emitSerializedReturnTypeOfNode(node) { + if (node && ts.isFunctionLike(node) && node.type) { + emitSerializedTypeNode(node.type); + return; + } + write("void 0"); + } + function emitSerializedTypeMetadata(node, writeComma) { + var argumentsWritten = 0; + if (compilerOptions.emitDecoratorMetadata) { + if (shouldEmitTypeMetadata(node)) { + if (writeComma) { + write(", "); + } + writeLine(); + write("__metadata('design:type', "); + emitSerializedTypeOfNode(node); + write(")"); + argumentsWritten++; + } + if (shouldEmitParamTypesMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:paramtypes', ["); + emitSerializedParameterTypesOfNode(node); + write("])"); + argumentsWritten++; + } + if (shouldEmitReturnTypeMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:returntype', "); + emitSerializedReturnTypeOfNode(node); + write(")"); + argumentsWritten++; + } + } + return argumentsWritten; + } + function emitInterfaceDeclaration(node) { + emitCommentsOnNotEmittedNode(node); + } + function shouldEmitEnumDeclaration(node) { + var isConstEnum = ts.isConst(node); + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; + } + function emitEnumDeclaration(node) { + if (!shouldEmitEnumDeclaration(node)) { + return; + } + if (!shouldHoistDeclarationInSystemJsModule(node)) { + if (!(node.flags & 1) || isES6ExportedDeclaration(node)) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + emitEnd(node); + write(";"); + } + } + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") {"); + increaseIndent(); + scopeEmitStart(node); + emitLines(node.members); + decreaseIndent(); + writeLine(); + emitToken(16, node.members.end); + scopeEmitEnd(); + write(")("); + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.flags & 1 && !shouldHoistDeclarationInSystemJsModule(node)) { + writeLine(); + emitStart(node); + write("var "); + emit(node.name); + write(" = "); + emitModuleMemberName(node); + emitEnd(node); + write(";"); + } + if (modulekind !== 5 && node.parent === currentSourceFile) { + if (modulekind === 4 && (node.flags & 1)) { + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + function emitEnumMember(node) { + var enumParent = node.parent; + emitStart(node); + write(getGeneratedNameForNode(enumParent)); + write("["); + write(getGeneratedNameForNode(enumParent)); + write("["); + emitExpressionForPropertyName(node.name); + write("] = "); + writeEnumMemberDeclarationValue(node); + write("] = "); + emitExpressionForPropertyName(node.name); + emitEnd(node); + write(";"); + } + function writeEnumMemberDeclarationValue(member) { + var value = resolver.getConstantValue(member); + if (value !== undefined) { + write(value.toString()); + return; + } + else if (member.initializer) { + emit(member.initializer); + } + else { + write("undefined"); + } + } + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { + if (moduleDeclaration.body.kind === 218) { + var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + function shouldEmitModuleDeclaration(node) { + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); + } + function isModuleMergedWithES6Class(node) { + return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 32768); + } + function emitModuleDeclaration(node) { + var shouldEmit = shouldEmitModuleDeclaration(node); + if (!shouldEmit) { + return emitCommentsOnNotEmittedNode(node); + } + var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); + var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); + if (emitVarForModule) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); + } + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") "); + if (node.body.kind === 219) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + tempFlags = 0; + tempVariables = undefined; + emit(node.body); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + } + else { + write("{"); + increaseIndent(); + scopeEmitStart(node); + emitCaptureThisForNodeIfNecessary(node); + writeLine(); + emit(node.body); + decreaseIndent(); + writeLine(); + var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; + emitToken(16, moduleBlock.statements.end); + scopeEmitEnd(); + } + write(")("); + if ((node.flags & 1) && !isES6ExportedDeclaration(node)) { + emit(node.name); + write(" = "); + } + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.name.kind === 69 && node.parent === currentSourceFile) { + if (modulekind === 4 && (node.flags & 1)) { + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + function tryRenameExternalModule(moduleName) { + if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { + return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; + } + return undefined; + } + function emitRequire(moduleName) { + if (moduleName.kind === 9) { + write("require("); + var text = tryRenameExternalModule(moduleName); + if (text) { + write(text); + } + else { + emitStart(moduleName); + emitLiteral(moduleName); + emitEnd(moduleName); + } + emitToken(18, moduleName.end); + } + else { + write("require()"); + } + } + function getNamespaceDeclarationNode(node) { + if (node.kind === 221) { + return node; + } + var importClause = node.importClause; + if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 224) { + return importClause.namedBindings; + } + } + function isDefaultImport(node) { + return node.kind === 222 && node.importClause && !!node.importClause.name; + } + function emitExportImportAssignments(node) { + if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + emitExportMemberAssignments(node.name); + } + ts.forEachChild(node, emitExportImportAssignments); + } + function emitImportDeclaration(node) { + if (modulekind !== 5) { + return emitExternalImportDeclaration(node); + } + if (node.importClause) { + var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); + var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, true); + if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { + write("import "); + emitStart(node.importClause); + if (shouldEmitDefaultBindings) { + emit(node.importClause.name); + if (shouldEmitNamedBindings) { + write(", "); + } + } + if (shouldEmitNamedBindings) { + emitLeadingComments(node.importClause.namedBindings); + emitStart(node.importClause.namedBindings); + if (node.importClause.namedBindings.kind === 224) { + write("* as "); + emit(node.importClause.namedBindings.name); + } + else { + write("{ "); + emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); + write(" }"); + } + emitEnd(node.importClause.namedBindings); + emitTrailingComments(node.importClause.namedBindings); + } + emitEnd(node.importClause); + write(" from "); + emit(node.moduleSpecifier); + write(";"); + } + } + else { + write("import "); + emit(node.moduleSpecifier); + write(";"); + } + } + function emitExternalImportDeclaration(node) { + if (ts.contains(externalImports, node)) { + var isExportedImport = node.kind === 221 && (node.flags & 1) !== 0; + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (modulekind !== 2) { + emitLeadingComments(node); + emitStart(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + if (!isExportedImport) + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + } + else { + var isNakedImport = 222 && !node.importClause; + if (!isNakedImport) { + write("var "); + write(getGeneratedNameForNode(node)); + write(" = "); + } + } + emitRequire(ts.getExternalModuleName(node)); + if (namespaceDeclaration && isDefaultImport(node)) { + write(", "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + else { + if (isExportedImport) { + emitModuleMemberName(namespaceDeclaration); + write(" = "); + emit(namespaceDeclaration.name); + write(";"); + } + else if (namespaceDeclaration && isDefaultImport(node)) { + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + write(";"); + } + emitExportImportAssignments(node); + } + } + } + function emitImportEqualsDeclaration(node) { + if (ts.isExternalModuleImportEqualsDeclaration(node)) { + emitExternalImportDeclaration(node); + return; + } + if (resolver.isReferencedAliasDeclaration(node) || + (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { + emitLeadingComments(node); + emitStart(node); + var variableDeclarationIsHoisted = shouldHoistVariable(node, true); + var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, true); + if (!variableDeclarationIsHoisted) { + ts.Debug.assert(!isExported); + if (isES6ExportedDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & 1)) { + write("var "); + } + } + if (isExported) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.name); + write("\", "); + } + emitModuleMemberName(node); + write(" = "); + emit(node.moduleReference); + if (isExported) { + write(")"); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + } + function emitExportDeclaration(node) { + ts.Debug.assert(modulekind !== 4); + if (modulekind !== 5) { + if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { + emitStart(node); + var generatedName = getGeneratedNameForNode(node); + if (node.exportClause) { + if (modulekind !== 2) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(ts.getExternalModuleName(node)); + write(";"); + } + for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { + var specifier = _b[_a]; + if (resolver.isValueAliasDeclaration(specifier)) { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + } + } + } + else { + writeLine(); + write("__export("); + if (modulekind !== 2) { + emitRequire(ts.getExternalModuleName(node)); + } + else { + write(generatedName); + } + write(");"); + } + emitEnd(node); + } + } + else { + if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { + write("export "); + if (node.exportClause) { + write("{ "); + emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + emit(node.moduleSpecifier); + } + write(";"); + } + } + } + function emitExportOrImportSpecifierList(specifiers, shouldEmit) { + ts.Debug.assert(modulekind === 5); + var needsComma = false; + for (var _a = 0; _a < specifiers.length; _a++) { + var specifier = specifiers[_a]; + if (shouldEmit(specifier)) { + if (needsComma) { + write(", "); + } + if (specifier.propertyName) { + emit(specifier.propertyName); + write(" as "); + } + emit(specifier.name); + needsComma = true; + } + } + } + function emitExportAssignment(node) { + if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { + if (modulekind === 5) { + writeLine(); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== 213 && + expression.kind !== 214) { + write(";"); + } + emitEnd(node); + } + else { + writeLine(); + emitStart(node); + if (modulekind === 4) { + write(exportFunctionForFile + "(\"default\","); + emit(node.expression); + write(")"); + } + else { + emitEs6ExportDefaultCompat(node); + emitContainingModuleName(node); + if (languageVersion === 0) { + write("[\"default\"] = "); + } + else { + write(".default = "); + } + emit(node.expression); + } + write(";"); + emitEnd(node); + } + } + } + function collectExternalModuleInfo(sourceFile) { + externalImports = []; + exportSpecifiers = {}; + exportEquals = undefined; + hasExportStars = false; + for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { + var node = _b[_a]; + switch (node.kind) { + case 222: + if (!node.importClause || + resolver.isReferencedAliasDeclaration(node.importClause, true)) { + externalImports.push(node); + } + break; + case 221: + if (node.moduleReference.kind === 232 && resolver.isReferencedAliasDeclaration(node)) { + externalImports.push(node); + } + break; + case 228: + if (node.moduleSpecifier) { + if (!node.exportClause) { + externalImports.push(node); + hasExportStars = true; + } + else if (resolver.isValueAliasDeclaration(node)) { + externalImports.push(node); + } + } + else { + for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { + var specifier = _d[_c]; + var name_26 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_26] || (exportSpecifiers[name_26] = [])).push(specifier); + } + } + break; + case 227: + if (node.isExportEquals && !exportEquals) { + exportEquals = node; + } + break; + } + } + } + function emitExportStarHelper() { + if (hasExportStars) { + writeLine(); + write("function __export(m) {"); + increaseIndent(); + writeLine(); + write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function getLocalNameForExternalImport(node) { + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); + } + if (node.kind === 222 && node.importClause) { + return getGeneratedNameForNode(node); + } + if (node.kind === 228 && node.moduleSpecifier) { + return getGeneratedNameForNode(node); + } + } + function getExternalModuleNameText(importNode) { + var moduleName = ts.getExternalModuleName(importNode); + if (moduleName.kind === 9) { + return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); + } + return undefined; + } + function emitVariableDeclarationsForImports() { + if (externalImports.length === 0) { + return; + } + writeLine(); + var started = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var importNode = externalImports[_a]; + var skipNode = importNode.kind === 228 || + (importNode.kind === 222 && !importNode.importClause); + if (skipNode) { + continue; + } + if (!started) { + write("var "); + started = true; + } + else { + write(", "); + } + write(getLocalNameForExternalImport(importNode)); + } + if (started) { + write(";"); + } + } + function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { + if (!hasExportStars) { + return undefined; + } + if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { + var hasExportDeclarationWithExportClause = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var externalImport = externalImports[_a]; + if (externalImport.kind === 228 && externalImport.exportClause) { + hasExportDeclarationWithExportClause = true; + break; + } + } + if (!hasExportDeclarationWithExportClause) { + return emitExportStarFunction(undefined); + } + } + var exportedNamesStorageRef = makeUniqueName("exportedNames"); + writeLine(); + write("var " + exportedNamesStorageRef + " = {"); + increaseIndent(); + var started = false; + if (exportedDeclarations) { + for (var i = 0; i < exportedDeclarations.length; ++i) { + writeExportedName(exportedDeclarations[i]); + } + } + if (exportSpecifiers) { + for (var n in exportSpecifiers) { + for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { + var specifier = _c[_b]; + writeExportedName(specifier.name); + } + } + } + for (var _d = 0; _d < externalImports.length; _d++) { + var externalImport = externalImports[_d]; + if (externalImport.kind !== 228) { + continue; + } + var exportDecl = externalImport; + if (!exportDecl.exportClause) { + continue; + } + for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { + var element = _f[_e]; + writeExportedName(element.name || element.propertyName); + } + } + decreaseIndent(); + writeLine(); + write("};"); + return emitExportStarFunction(exportedNamesStorageRef); + function emitExportStarFunction(localNames) { + var exportStarFunction = makeUniqueName("exportStar"); + writeLine(); + write("function " + exportStarFunction + "(m) {"); + increaseIndent(); + writeLine(); + write("var exports = {};"); + writeLine(); + write("for(var n in m) {"); + increaseIndent(); + writeLine(); + write("if (n !== \"default\""); + if (localNames) { + write("&& !" + localNames + ".hasOwnProperty(n)"); + } + write(") exports[n] = m[n];"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write(exportFunctionForFile + "(exports);"); + decreaseIndent(); + writeLine(); + write("}"); + return exportStarFunction; + } + function writeExportedName(node) { + if (node.kind !== 69 && node.flags & 1024) { + return; + } + if (started) { + write(","); + } + else { + started = true; + } + writeLine(); + write("'"); + if (node.kind === 69) { + emitNodeWithCommentsAndWithoutSourcemap(node); + } + else { + emitDeclarationName(node); + } + write("': true"); + } + } + function processTopLevelVariableAndFunctionDeclarations(node) { + var hoistedVars; + var hoistedFunctionDeclarations; + var exportedDeclarations; + visit(node); + if (hoistedVars) { + writeLine(); + write("var "); + var seen = {}; + for (var i = 0; i < hoistedVars.length; ++i) { + var local = hoistedVars[i]; + var name_27 = local.kind === 69 + ? local + : local.name; + if (name_27) { + var text = ts.unescapeIdentifier(name_27.text); + if (ts.hasProperty(seen, text)) { + continue; + } + else { + seen[text] = text; + } + } + if (i !== 0) { + write(", "); + } + if (local.kind === 214 || local.kind === 218 || local.kind === 217) { + emitDeclarationName(local); + } + else { + emit(local); + } + var flags = ts.getCombinedNodeFlags(local.kind === 69 ? local.parent : local); + if (flags & 1) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(local); + } + } + write(";"); + } + if (hoistedFunctionDeclarations) { + for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { + var f = hoistedFunctionDeclarations[_a]; + writeLine(); + emit(f); + if (f.flags & 1) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(f); + } + } + } + return exportedDeclarations; + function visit(node) { + if (node.flags & 2) { + return; + } + if (node.kind === 213) { + if (!hoistedFunctionDeclarations) { + hoistedFunctionDeclarations = []; + } + hoistedFunctionDeclarations.push(node); + return; + } + if (node.kind === 214) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + return; + } + if (node.kind === 217) { + if (shouldEmitEnumDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 218) { + if (shouldEmitModuleDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 211 || node.kind === 163) { + if (shouldHoistVariable(node, false)) { + var name_28 = node.name; + if (name_28.kind === 69) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(name_28); + } + else { + ts.forEachChild(name_28, visit); + } + } + return; + } + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node.name); + return; + } + if (ts.isBindingPattern(node)) { + ts.forEach(node.elements, visit); + return; + } + if (!ts.isDeclaration(node)) { + ts.forEachChild(node, visit); + } + } + } + function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { + if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { + return false; + } + return (ts.getCombinedNodeFlags(node) & 49152) === 0 || + ts.getEnclosingBlockScopeContainer(node).kind === 248; + } + function isCurrentFileSystemExternalModule() { + return modulekind === 4 && ts.isExternalModule(currentSourceFile); + } + function emitSystemModuleBody(node, dependencyGroups, startIndex) { + emitVariableDeclarationsForImports(); + writeLine(); + var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); + var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); + writeLine(); + write("return {"); + increaseIndent(); + writeLine(); + emitSetters(exportStarFunction, dependencyGroups); + writeLine(); + emitExecute(node, startIndex); + decreaseIndent(); + writeLine(); + write("}"); + emitTempDeclarations(true); + } + function emitSetters(exportStarFunction, dependencyGroups) { + write("setters:["); + for (var i = 0; i < dependencyGroups.length; ++i) { + if (i !== 0) { + write(","); + } + writeLine(); + increaseIndent(); + var group = dependencyGroups[i]; + var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); + write("function (" + parameterName + ") {"); + increaseIndent(); + for (var _a = 0; _a < group.length; _a++) { + var entry = group[_a]; + var importVariableName = getLocalNameForExternalImport(entry) || ""; + switch (entry.kind) { + case 222: + if (!entry.importClause) { + break; + } + case 221: + ts.Debug.assert(importVariableName !== ""); + writeLine(); + write(importVariableName + " = " + parameterName + ";"); + writeLine(); + break; + case 228: + ts.Debug.assert(importVariableName !== ""); + if (entry.exportClause) { + writeLine(); + write(exportFunctionForFile + "({"); + writeLine(); + increaseIndent(); + for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { + if (i_2 !== 0) { + write(","); + writeLine(); + } + var e = entry.exportClause.elements[i_2]; + write("\""); + emitNodeWithCommentsAndWithoutSourcemap(e.name); + write("\": " + parameterName + "[\""); + emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); + write("\"]"); + } + decreaseIndent(); + writeLine(); + write("});"); + } + else { + writeLine(); + write(exportStarFunction + "(" + parameterName + ");"); + } + writeLine(); + break; + } + } + decreaseIndent(); + write("}"); + decreaseIndent(); + } + write("],"); + } + function emitExecute(node, startIndex) { + write("execute: function() {"); + increaseIndent(); + writeLine(); + for (var i = startIndex; i < node.statements.length; ++i) { + var statement = node.statements[i]; + switch (statement.kind) { + case 213: + case 222: + continue; + case 228: + if (!statement.moduleSpecifier) { + for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { + var element = _b[_a]; + emitExportSpecifierInSystemModule(element); + } + } + continue; + case 221: + if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { + continue; + } + default: + writeLine(); + emit(statement); + } + } + decreaseIndent(); + writeLine(); + write("}"); + } + function emitSystemModule(node) { + collectExternalModuleInfo(node); + ts.Debug.assert(!exportFunctionForFile); + exportFunctionForFile = makeUniqueName("exports"); + writeLine(); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); + var groupIndices = {}; + var dependencyGroups = []; + for (var i = 0; i < externalImports.length; ++i) { + var text = getExternalModuleNameText(externalImports[i]); + if (ts.hasProperty(groupIndices, text)) { + var groupIndex = groupIndices[text]; + dependencyGroups[groupIndex].push(externalImports[i]); + continue; + } + else { + groupIndices[text] = dependencyGroups.length; + dependencyGroups.push([externalImports[i]]); + } + if (i !== 0) { + write(", "); + } + write(text); + } + write("], function(" + exportFunctionForFile + ") {"); + writeLine(); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, true); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitSystemModuleBody(node, dependencyGroups, startIndex); + decreaseIndent(); + writeLine(); + write("});"); + } + function getAMDDependencyNames(node, includeNonAmdDependencies) { + var aliasedModuleNames = []; + var unaliasedModuleNames = []; + var importAliasNames = []; + for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { + var amdDependency = _b[_a]; + if (amdDependency.name) { + aliasedModuleNames.push("\"" + amdDependency.path + "\""); + importAliasNames.push(amdDependency.name); + } + else { + unaliasedModuleNames.push("\"" + amdDependency.path + "\""); + } + } + for (var _c = 0; _c < externalImports.length; _c++) { + var importNode = externalImports[_c]; + var externalModuleName = getExternalModuleNameText(importNode); + var importAliasName = getLocalNameForExternalImport(importNode); + if (includeNonAmdDependencies && importAliasName) { + aliasedModuleNames.push(externalModuleName); + importAliasNames.push(importAliasName); + } + else { + unaliasedModuleNames.push(externalModuleName); + } + } + return { aliasedModuleNames: aliasedModuleNames, unaliasedModuleNames: unaliasedModuleNames, importAliasNames: importAliasNames }; + } + function emitAMDDependencies(node, includeNonAmdDependencies) { + var dependencyNames = getAMDDependencyNames(node, includeNonAmdDependencies); + emitAMDDependencyList(dependencyNames); + write(", "); + emitAMDFactoryHeader(dependencyNames); + } + function emitAMDDependencyList(_a) { + var aliasedModuleNames = _a.aliasedModuleNames, unaliasedModuleNames = _a.unaliasedModuleNames; + write("[\"require\", \"exports\""); + if (aliasedModuleNames.length) { + write(", "); + write(aliasedModuleNames.join(", ")); + } + if (unaliasedModuleNames.length) { + write(", "); + write(unaliasedModuleNames.join(", ")); + } + write("]"); + } + function emitAMDFactoryHeader(_a) { + var importAliasNames = _a.importAliasNames; + write("function (require, exports"); + if (importAliasNames.length) { + write(", "); + write(importAliasNames.join(", ")); + } + write(") {"); + } + function emitAMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + writeLine(); + write("define("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + emitAMDDependencies(node, true); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + emitExportEquals(true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitCommonJSModule(node) { + var startIndex = emitDirectivePrologues(node.statements, false); + emitEmitHelpers(node); + collectExternalModuleInfo(node); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + emitExportEquals(false); + } + function emitUMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + var dependencyNames = getAMDDependencyNames(node, false); + writeLines("(function (factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define("); + emitAMDDependencyList(dependencyNames); + write(", factory);"); + writeLines(" }\n})("); + emitAMDFactoryHeader(dependencyNames); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + emitExportEquals(true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitES6Module(node) { + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + var startIndex = emitDirectivePrologues(node.statements, false); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + } + function emitExportEquals(emitAsReturn) { + if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { + writeLine(); + emitStart(exportEquals); + write(emitAsReturn ? "return " : "module.exports = "); + emit(exportEquals.expression); + write(";"); + emitEnd(exportEquals); + } + } + function emitJsxElement(node) { + switch (compilerOptions.jsx) { + case 2: + jsxEmitReact(node); + break; + case 1: + default: + jsxEmitPreserve(node); + break; + } + } + function trimReactWhitespaceAndApplyEntities(node) { + var result = undefined; + var text = ts.getTextOfNode(node, true); + var firstNonWhitespace = 0; + var lastNonWhitespace = -1; + for (var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + if (ts.isLineBreak(c)) { + if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { + var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + firstNonWhitespace = -1; + } + else if (!ts.isWhiteSpace(c)) { + lastNonWhitespace = i; + if (firstNonWhitespace === -1) { + firstNonWhitespace = i; + } + } + } + if (firstNonWhitespace !== -1) { + var part = text.substr(firstNonWhitespace); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + if (result) { + result = result.replace(/&(\w+);/g, function (s, m) { + if (entities[m] !== undefined) { + return String.fromCharCode(entities[m]); + } + else { + return s; + } + }); + } + return result; + } + function getTextToEmit(node) { + switch (compilerOptions.jsx) { + case 2: + var text = trimReactWhitespaceAndApplyEntities(node); + if (text === undefined || text.length === 0) { + return undefined; + } + else { + return text; + } + case 1: + default: + return ts.getTextOfNode(node, true); + } + } + function emitJsxText(node) { + switch (compilerOptions.jsx) { + case 2: + write("\""); + write(trimReactWhitespaceAndApplyEntities(node)); + write("\""); + break; + case 1: + default: + writer.writeLiteral(ts.getTextOfNode(node, true)); + break; + } + } + function emitJsxExpression(node) { + if (node.expression) { + switch (compilerOptions.jsx) { + case 1: + default: + write("{"); + emit(node.expression); + write("}"); + break; + case 2: + emit(node.expression); + break; + } + } + } + function emitDirectivePrologues(statements, startWithNewLine) { + for (var i = 0; i < statements.length; ++i) { + if (ts.isPrologueDirective(statements[i])) { + if (startWithNewLine || i > 0) { + writeLine(); + } + emit(statements[i]); + } + else { + return i; + } + } + return statements.length; + } + function writeLines(text) { + var lines = text.split(/\r\n|\r|\n/g); + for (var i = 0; i < lines.length; ++i) { + var line = lines[i]; + if (line.length) { + writeLine(); + write(line); + } + } + } + function emitEmitHelpers(node) { + if (!compilerOptions.noEmitHelpers) { + if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) { + writeLines(extendsHelper); + extendsEmitted = true; + } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16) { + writeLines(decorateHelper); + if (compilerOptions.emitDecoratorMetadata) { + writeLines(metadataHelper); + } + decorateEmitted = true; + } + if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32) { + writeLines(paramHelper); + paramEmitted = true; + } + if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64) { + writeLines(awaiterHelper); + awaiterEmitted = true; + } + } + } + function emitSourceFileNode(node) { + writeLine(); + emitShebang(); + emitDetachedComments(node); + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { + var emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[1]; + emitModule(node); + } + else { + var startIndex = emitDirectivePrologues(node.statements, false); + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(true); + } + emitLeadingComments(node.endOfFileToken); + } + function emitNodeWithCommentsAndWithoutSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); + } + function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { + if (node) { + if (node.flags & 2) { + return emitCommentsOnNotEmittedNode(node); + } + if (isSpecializedCommentHandling(node)) { + return emitNodeWithoutSourceMap(node); + } + var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); + if (emitComments_1) { + emitLeadingComments(node); + } + emitNodeConsideringSourcemap(node); + if (emitComments_1) { + emitTrailingComments(node); + } + } + } + function emitNodeWithoutSourceMap(node) { + if (node) { + emitJavaScriptWorker(node); + } + } + function isSpecializedCommentHandling(node) { + switch (node.kind) { + case 215: + case 213: + case 222: + case 221: + case 216: + case 227: + return true; + } + } + function shouldEmitLeadingAndTrailingComments(node) { + switch (node.kind) { + case 193: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); + case 218: + return shouldEmitModuleDeclaration(node); + case 217: + return shouldEmitEnumDeclaration(node); + } + ts.Debug.assert(!isSpecializedCommentHandling(node)); + if (node.kind !== 192 && + node.parent && + node.parent.kind === 174 && + node.parent.body === node && + compilerOptions.target <= 1) { + return false; + } + return true; + } + function emitJavaScriptWorker(node) { + switch (node.kind) { + case 69: + return emitIdentifier(node); + case 138: + return emitParameter(node); + case 143: + case 142: + return emitMethod(node); + case 145: + case 146: + return emitAccessor(node); + case 97: + return emitThis(node); + case 95: + return emitSuper(node); + case 93: + return write("null"); + case 99: + return write("true"); + case 84: + return write("false"); + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + return emitLiteral(node); + case 183: + return emitTemplateExpression(node); + case 190: + return emitTemplateSpan(node); + case 233: + case 234: + return emitJsxElement(node); + case 236: + return emitJsxText(node); + case 240: + return emitJsxExpression(node); + case 135: + return emitQualifiedName(node); + case 161: + return emitObjectBindingPattern(node); + case 162: + return emitArrayBindingPattern(node); + case 163: + return emitBindingElement(node); + case 164: + return emitArrayLiteral(node); + case 165: + return emitObjectLiteral(node); + case 245: + return emitPropertyAssignment(node); + case 246: + return emitShorthandPropertyAssignment(node); + case 136: + return emitComputedPropertyName(node); + case 166: + return emitPropertyAccess(node); + case 167: + return emitIndexedAccess(node); + case 168: + return emitCallExpression(node); + case 169: + return emitNewExpression(node); + case 170: + return emitTaggedTemplateExpression(node); + case 171: + return emit(node.expression); + case 189: + return emit(node.expression); + case 172: + return emitParenExpression(node); + case 213: + case 173: + case 174: + return emitFunctionDeclaration(node); + case 175: + return emitDeleteExpression(node); + case 176: + return emitTypeOfExpression(node); + case 177: + return emitVoidExpression(node); + case 178: + return emitAwaitExpression(node); + case 179: + return emitPrefixUnaryExpression(node); + case 180: + return emitPostfixUnaryExpression(node); + case 181: + return emitBinaryExpression(node); + case 182: + return emitConditionalExpression(node); + case 185: + return emitSpreadElementExpression(node); + case 184: + return emitYieldExpression(node); + case 187: + return; + case 192: + case 219: + return emitBlock(node); + case 193: + return emitVariableStatement(node); + case 194: + return write(";"); + case 195: + return emitExpressionStatement(node); + case 196: + return emitIfStatement(node); + case 197: + return emitDoStatement(node); + case 198: + return emitWhileStatement(node); + case 199: + return emitForStatement(node); + case 201: + case 200: + return emitForInOrForOfStatement(node); + case 202: + case 203: + return emitBreakOrContinueStatement(node); + case 204: + return emitReturnStatement(node); + case 205: + return emitWithStatement(node); + case 206: + return emitSwitchStatement(node); + case 241: + case 242: + return emitCaseOrDefaultClause(node); + case 207: + return emitLabelledStatement(node); + case 208: + return emitThrowStatement(node); + case 209: + return emitTryStatement(node); + case 244: + return emitCatchClause(node); + case 210: + return emitDebuggerStatement(node); + case 211: + return emitVariableDeclaration(node); + case 186: + return emitClassExpression(node); + case 214: + return emitClassDeclaration(node); + case 215: + return emitInterfaceDeclaration(node); + case 217: + return emitEnumDeclaration(node); + case 247: + return emitEnumMember(node); + case 218: + return emitModuleDeclaration(node); + case 222: + return emitImportDeclaration(node); + case 221: + return emitImportEqualsDeclaration(node); + case 228: + return emitExportDeclaration(node); + case 227: + return emitExportAssignment(node); + case 248: + return emitSourceFileNode(node); + } + } + function hasDetachedComments(pos) { + return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; + } + function getLeadingCommentsWithoutDetachedComments() { + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); + if (detachedCommentsInfo.length - 1) { + detachedCommentsInfo.pop(); + } + else { + detachedCommentsInfo = undefined; + } + return leadingComments; + } + function isPinnedComments(comment) { + return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 33; + } + function isTripleSlashComment(comment) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 47) { + var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); + return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || + textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? + true : false; + } + return false; + } + function getLeadingCommentsToEmit(node) { + if (node.parent) { + if (node.parent.kind === 248 || node.pos !== node.parent.pos) { + if (hasDetachedComments(node.pos)) { + return getLeadingCommentsWithoutDetachedComments(); + } + else { + return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + } + } + } + function getTrailingCommentsToEmit(node) { + if (node.parent) { + if (node.parent.kind === 248 || node.end !== node.parent.end) { + return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + } + } + } + function emitCommentsOnNotEmittedNode(node) { + emitLeadingCommentsWorker(node, false); + } + function emitLeadingComments(node) { + return emitLeadingCommentsWorker(node, true); + } + function emitLeadingCommentsWorker(node, isEmittedNode) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (isEmittedNode) { + leadingComments = getLeadingCommentsToEmit(node); + } + else { + if (node.pos === 0) { + leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); + } + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitTrailingComments(node) { + if (compilerOptions.removeComments) { + return; + } + var trailingComments = getTrailingCommentsToEmit(node); + ts.emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + } + function emitTrailingCommentsOfPosition(pos) { + if (compilerOptions.removeComments) { + return; + } + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); + ts.emitComments(currentSourceFile, writer, trailingComments, true, newLine, writeComment); + } + function emitLeadingCommentsOfPositionWorker(pos) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (hasDetachedComments(pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + ts.emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); + } + function emitDetachedComments(node) { + var leadingComments; + if (compilerOptions.removeComments) { + if (node.pos === 0) { + leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); + } + } + else { + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); + } + if (leadingComments) { + var detachedComments = []; + var lastComment; + ts.forEach(leadingComments, function (comment) { + if (lastComment) { + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); + var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); + if (commentLine >= lastCommentLine + 2) { + return detachedComments; + } + } + detachedComments.push(comment); + lastComment = comment; + }); + if (detachedComments.length) { + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); + var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); + if (nodeLine >= lastCommentLine + 2) { + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + ts.emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment); + var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; + if (detachedCommentsInfo) { + detachedCommentsInfo.push(currentDetachedCommentInfo); + } + else { + detachedCommentsInfo = [currentDetachedCommentInfo]; + } + } + } + } + } + function emitShebang() { + var shebang = ts.getShebang(currentSourceFile.text); + if (shebang) { + write(shebang); + } + } + var _a; + } + function emitFile(jsFilePath, sourceFile) { + emitJavaScript(jsFilePath, sourceFile); + if (compilerOptions.declaration) { + ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); + } + } + } + ts.emitFiles = emitFiles; })(ts || (ts = {})); var ts; (function (ts) { @@ -29788,7 +30314,7 @@ var ts; ts.ioReadTime = 0; ts.ioWriteTime = 0; var emptyArray = []; - ts.version = "1.7.0"; + ts.version = "1.8.0"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -29826,11 +30352,11 @@ var ts; if (ts.getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { var failedLookupLocations = []; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); - var resolvedFileName = loadNodeModuleFromFile(candidate, false, failedLookupLocations, host); + var resolvedFileName = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (resolvedFileName) { return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } - resolvedFileName = loadNodeModuleFromDirectory(candidate, false, failedLookupLocations, host); + resolvedFileName = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); return resolvedFileName ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; @@ -29840,13 +30366,8 @@ var ts; } } ts.nodeModuleNameResolver = nodeModuleNameResolver; - function loadNodeModuleFromFile(candidate, loadOnlyDts, failedLookupLocation, host) { - if (loadOnlyDts) { - return tryLoad(".d.ts"); - } - else { - return ts.forEach(ts.supportedExtensions, tryLoad); - } + function loadNodeModuleFromFile(candidate, failedLookupLocation, host) { + return ts.forEach(ts.moduleFileExtensions, tryLoad); function tryLoad(ext) { var fileName = ts.fileExtensionIs(candidate, ext) ? candidate : candidate + ext; if (host.fileExists(fileName)) { @@ -29858,7 +30379,7 @@ var ts; } } } - function loadNodeModuleFromDirectory(candidate, loadOnlyDts, failedLookupLocation, host) { + function loadNodeModuleFromDirectory(candidate, failedLookupLocation, host) { var packageJsonPath = ts.combinePaths(candidate, "package.json"); if (host.fileExists(packageJsonPath)) { var jsonContent; @@ -29870,7 +30391,7 @@ var ts; jsonContent = { typings: undefined }; } if (jsonContent.typings) { - var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), loadOnlyDts, failedLookupLocation, host); + var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), failedLookupLocation, host); if (result) { return result; } @@ -29879,7 +30400,7 @@ var ts; else { failedLookupLocation.push(packageJsonPath); } - return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host); + return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), failedLookupLocation, host); } function loadModuleFromNodeModules(moduleName, directory, host) { var failedLookupLocations = []; @@ -29889,11 +30410,11 @@ var ts; if (baseName !== "node_modules") { var nodeModulesFolder = ts.combinePaths(directory, "node_modules"); var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); - var result = loadNodeModuleFromFile(candidate, true, failedLookupLocations, host); + var result = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } - result = loadNodeModuleFromDirectory(candidate, true, failedLookupLocations, host); + result = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } @@ -29911,7 +30432,7 @@ var ts; return i === 0 || (i === 1 && name.charCodeAt(0) === 46); } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { - if (moduleName.indexOf('!') != -1) { + if (moduleName.indexOf("!") != -1) { return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); @@ -30220,7 +30741,7 @@ var ts; return emitResult; } function getSourceFile(fileName) { - return filesByName.get(fileName); + return filesByName.get(fileName) || filesByName.get(ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory())); } function getDiagnosticsHelper(sourceFile, getDiagnostics, cancellationToken) { if (sourceFile) { @@ -30309,10 +30830,14 @@ var ts; var imports; for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var node = _a[_i]; + collect(node, true); + } + file.imports = imports || emptyArray; + function collect(node, allowRelativeModuleNames) { switch (node.kind) { - case 220: - case 219: - case 226: + case 222: + case 221: + case 228: var moduleNameExpr = ts.getExternalModuleName(node); if (!moduleNameExpr || moduleNameExpr.kind !== 9) { break; @@ -30320,24 +30845,19 @@ var ts; if (!moduleNameExpr.text) { break; } - (imports || (imports = [])).push(moduleNameExpr); + if (allowRelativeModuleNames || !ts.isExternalModuleNameRelative(moduleNameExpr.text)) { + (imports || (imports = [])).push(moduleNameExpr); + } break; - case 216: + case 218: if (node.name.kind === 9 && (node.flags & 2 || ts.isDeclarationFile(file))) { ts.forEachChild(node.body, function (node) { - if (ts.isExternalModuleImportEqualsDeclaration(node) && - ts.getExternalModuleImportEqualsDeclarationExpression(node).kind === 9) { - var moduleName = ts.getExternalModuleImportEqualsDeclarationExpression(node); - if (moduleName) { - (imports || (imports = [])).push(moduleName); - } - } + collect(node, false); }); } break; } } - file.imports = imports || emptyArray; } function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { var diagnosticArgument; @@ -30380,48 +30900,46 @@ var ts; } } function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { - var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (filesByName.contains(canonicalName)) { - return getSourceFileFromCache(fileName, canonicalName, false); + if (filesByName.contains(fileName)) { + return getSourceFileFromCache(fileName, false); } - else { - var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); - var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (filesByName.contains(canonicalAbsolutePath)) { - return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); - } - var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { - if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - else { - fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - }); - filesByName.set(canonicalName, file); - if (file) { - skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; - filesByName.set(canonicalAbsolutePath, file); - var basePath = ts.getDirectoryPath(fileName); - if (!options.noResolve) { - processReferencedFiles(file, basePath); - } - processImportedModules(file, basePath); - if (isDefaultLib) { - file.isDefaultLib = true; - files.unshift(file); - } - else { - files.push(file); - } - } - return file; + var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); + if (filesByName.contains(normalizedAbsolutePath)) { + var file_1 = getSourceFileFromCache(normalizedAbsolutePath, true); + filesByName.set(fileName, file_1); + return file_1; } - function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName.get(canonicalName); + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + else { + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + }); + filesByName.set(fileName, file); + if (file) { + skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; + filesByName.set(normalizedAbsolutePath, file); + var basePath = ts.getDirectoryPath(fileName); + if (!options.noResolve) { + processReferencedFiles(file, basePath); + } + processImportedModules(file, basePath); + if (isDefaultLib) { + file.isDefaultLib = true; + files.unshift(file); + } + else { + files.push(file); + } + } + return file; + function getSourceFileFromCache(fileName, useAbsolutePath) { + var file = filesByName.get(fileName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; - if (canonicalName !== sourceFileName) { + if (ts.normalizeSlashes(fileName) !== ts.normalizeSlashes(sourceFileName)) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } @@ -30582,8 +31100,8 @@ var ts; var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } - if (options.module && languageVersion >= 2) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + if (options.module === 5 && languageVersion < 2) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower)); } if (options.outDir || options.sourceRoot || @@ -30617,10 +31135,6 @@ var ts; !options.experimentalDecorators) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } - if (options.experimentalAsyncFunctions && - options.target !== 2) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); - } } } ts.createProgram = createProgram; @@ -30663,98 +31177,98 @@ var ts; function spanInNode(node) { if (node) { if (ts.isExpression(node)) { - if (node.parent.kind === 195) { + if (node.parent.kind === 197) { return spanInPreviousNode(node); } - if (node.parent.kind === 197) { + if (node.parent.kind === 199) { return textSpan(node); } - if (node.parent.kind === 179 && node.parent.operatorToken.kind === 24) { + if (node.parent.kind === 181 && node.parent.operatorToken.kind === 24) { return textSpan(node); } - if (node.parent.kind === 172 && node.parent.body === node) { + if (node.parent.kind === 174 && node.parent.body === node) { return textSpan(node); } } switch (node.kind) { - case 191: + case 193: return spanInVariableDeclaration(node.declarationList.declarations[0]); - case 209: - case 139: - case 138: - return spanInVariableDeclaration(node); - case 136: - return spanInParameterDeclaration(node); case 211: case 141: case 140: + return spanInVariableDeclaration(node); + case 138: + return spanInParameterDeclaration(node); + case 213: case 143: - case 144: case 142: - case 171: - case 172: + case 145: + case 146: + case 144: + case 173: + case 174: return spanInFunctionDeclaration(node); - case 190: + case 192: if (ts.isFunctionBlock(node)) { return spanInFunctionBlock(node); } - case 217: + case 219: return spanInBlock(node); - case 242: + case 244: return spanInBlock(node.block); - case 193: + case 195: return textSpan(node.expression); - case 202: + case 204: return textSpan(node.getChildAt(0), node.expression); + case 198: + return textSpan(node, ts.findNextToken(node.expression, node)); + case 197: + return spanInNode(node.statement); + case 210: + return textSpan(node.getChildAt(0)); case 196: return textSpan(node, ts.findNextToken(node.expression, node)); - case 195: - return spanInNode(node.statement); - case 208: - return textSpan(node.getChildAt(0)); - case 194: - return textSpan(node, ts.findNextToken(node.expression, node)); - case 205: - return spanInNode(node.statement); - case 201: - case 200: - return textSpan(node.getChildAt(0), node.label); - case 197: - return spanInForStatement(node); - case 198: - case 199: - return textSpan(node, ts.findNextToken(node.expression, node)); - case 204: - return textSpan(node, ts.findNextToken(node.expression, node)); - case 239: - case 240: - return spanInNode(node.statements[0]); case 207: - return spanInBlock(node.tryBlock); + return spanInNode(node.statement); + case 203: + case 202: + return textSpan(node.getChildAt(0), node.label); + case 199: + return spanInForStatement(node); + case 200: + case 201: + return textSpan(node, ts.findNextToken(node.expression, node)); case 206: + return textSpan(node, ts.findNextToken(node.expression, node)); + case 241: + case 242: + return spanInNode(node.statements[0]); + case 209: + return spanInBlock(node.tryBlock); + case 208: return textSpan(node, node.expression); - case 225: + case 227: return textSpan(node, node.expression); - case 219: + case 221: return textSpan(node, node.moduleReference); - case 220: + case 222: return textSpan(node, node.moduleSpecifier); - case 226: + case 228: return textSpan(node, node.moduleSpecifier); - case 216: + case 218: if (ts.getModuleInstanceState(node) !== 1) { return undefined; } - case 212: - case 215: - case 245: - case 166: - case 167: - return textSpan(node); - case 203: - return spanInNode(node.statement); - case 213: case 214: + case 217: + case 247: + case 168: + case 169: + return textSpan(node); + case 205: + return spanInNode(node.statement); + case 215: + case 216: return undefined; case 23: case 1: @@ -30769,22 +31283,22 @@ var ts; return spanInOpenParenToken(node); case 18: return spanInCloseParenToken(node); - case 53: + case 54: return spanInColonToken(node); case 27: case 25: return spanInGreaterThanOrLessThanToken(node); - case 102: + case 104: return spanInWhileKeyword(node); - case 78: - case 70: - case 83: + case 80: + case 72: + case 85: return spanInNextNode(node); default: - if (node.parent.kind === 243 && node.parent.name === node) { + if (node.parent.kind === 245 && node.parent.name === node) { return spanInNode(node.parent.initializer); } - if (node.parent.kind === 169 && node.parent.type === node) { + if (node.parent.kind === 171 && node.parent.type === node) { return spanInNode(node.parent.expression); } if (ts.isFunctionLike(node.parent) && node.parent.type === node) { @@ -30794,12 +31308,12 @@ var ts; } } function spanInVariableDeclaration(variableDeclaration) { - if (variableDeclaration.parent.parent.kind === 198 || - variableDeclaration.parent.parent.kind === 199) { + if (variableDeclaration.parent.parent.kind === 200 || + variableDeclaration.parent.parent.kind === 201) { return spanInNode(variableDeclaration.parent.parent); } - var isParentVariableStatement = variableDeclaration.parent.parent.kind === 191; - var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 197 && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); + var isParentVariableStatement = variableDeclaration.parent.parent.kind === 193; + var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 199 && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); var declarations = isParentVariableStatement ? variableDeclaration.parent.parent.declarationList.declarations : isDeclarationOfForStatement @@ -30845,7 +31359,7 @@ var ts; } function canFunctionHaveSpanInWholeDeclaration(functionDeclaration) { return !!(functionDeclaration.flags & 1) || - (functionDeclaration.parent.kind === 212 && functionDeclaration.kind !== 142); + (functionDeclaration.parent.kind === 214 && functionDeclaration.kind !== 144); } function spanInFunctionDeclaration(functionDeclaration) { if (!functionDeclaration.body) { @@ -30865,23 +31379,23 @@ var ts; } function spanInBlock(block) { switch (block.parent.kind) { - case 216: + case 218: if (ts.getModuleInstanceState(block.parent) !== 1) { return undefined; } - case 196: - case 194: case 198: - case 199: + case 196: + case 200: + case 201: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); - case 197: + case 199: return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]); } return spanInNode(block.statements[0]); } function spanInForStatement(forStatement) { if (forStatement.initializer) { - if (forStatement.initializer.kind === 210) { + if (forStatement.initializer.kind === 212) { var variableDeclarationList = forStatement.initializer; if (variableDeclarationList.declarations.length > 0) { return spanInNode(variableDeclarationList.declarations[0]); @@ -30900,34 +31414,34 @@ var ts; } function spanInOpenBraceToken(node) { switch (node.parent.kind) { - case 215: + case 217: var enumDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); - case 212: + case 214: var classDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); - case 218: + case 220: return spanInNodeIfStartsOnSameLine(node.parent.parent, node.parent.clauses[0]); } return spanInNode(node.parent); } function spanInCloseBraceToken(node) { switch (node.parent.kind) { - case 217: + case 219: if (ts.getModuleInstanceState(node.parent.parent) !== 1) { return undefined; } - case 215: - case 212: + case 217: + case 214: return textSpan(node); - case 190: + case 192: if (ts.isFunctionBlock(node.parent)) { return textSpan(node); } - case 242: + case 244: return spanInNode(ts.lastOrUndefined(node.parent.statements)); ; - case 218: + case 220: var caseBlock = node.parent; var lastClause = ts.lastOrUndefined(caseBlock.clauses); if (lastClause) { @@ -30939,24 +31453,24 @@ var ts; } } function spanInOpenParenToken(node) { - if (node.parent.kind === 195) { + if (node.parent.kind === 197) { return spanInPreviousNode(node); } return spanInNode(node.parent); } function spanInCloseParenToken(node) { switch (node.parent.kind) { - case 171: - case 211: - case 172: - case 141: - case 140: + case 173: + case 213: + case 174: case 143: - case 144: case 142: - case 196: - case 195: + case 145: + case 146: + case 144: + case 198: case 197: + case 199: return spanInPreviousNode(node); default: return spanInNode(node.parent); @@ -30964,19 +31478,19 @@ var ts; return spanInNode(node.parent); } function spanInColonToken(node) { - if (ts.isFunctionLike(node.parent) || node.parent.kind === 243) { + if (ts.isFunctionLike(node.parent) || node.parent.kind === 245) { return spanInPreviousNode(node); } return spanInNode(node.parent); } function spanInGreaterThanOrLessThanToken(node) { - if (node.parent.kind === 169) { + if (node.parent.kind === 171) { return spanInNode(node.parent.expression); } return spanInNode(node.parent); } function spanInWhileKeyword(node) { - if (node.parent.kind === 195) { + if (node.parent.kind === 197) { return textSpan(node, ts.findNextToken(node.parent.expression, node.parent)); } return spanInNode(node.parent); @@ -31054,7 +31568,7 @@ var ts; } } function autoCollapse(node) { - return ts.isFunctionBlock(node) && node.parent.kind !== 172; + return ts.isFunctionBlock(node) && node.parent.kind !== 174; } var depth = 0; var maxDepth = 20; @@ -31066,30 +31580,30 @@ var ts; addOutliningForLeadingCommentsForNode(n); } switch (n.kind) { - case 190: + case 192: if (!ts.isFunctionBlock(n)) { var parent_7 = n.parent; var openBrace = ts.findChildOfKind(n, 15, sourceFile); var closeBrace = ts.findChildOfKind(n, 16, sourceFile); - if (parent_7.kind === 195 || - parent_7.kind === 198 || + if (parent_7.kind === 197 || + parent_7.kind === 200 || + parent_7.kind === 201 || parent_7.kind === 199 || - parent_7.kind === 197 || - parent_7.kind === 194 || parent_7.kind === 196 || - parent_7.kind === 203 || - parent_7.kind === 242) { + parent_7.kind === 198 || + parent_7.kind === 205 || + parent_7.kind === 244) { addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_7.kind === 207) { + if (parent_7.kind === 209) { var tryStatement = parent_7; if (tryStatement.tryBlock === n) { addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { - var finallyKeyword = ts.findChildOfKind(tryStatement, 83, sourceFile); + var finallyKeyword = ts.findChildOfKind(tryStatement, 85, sourceFile); if (finallyKeyword) { addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n)); break; @@ -31105,23 +31619,23 @@ var ts; }); break; } - case 217: { + case 219: { var openBrace = ts.findChildOfKind(n, 15, sourceFile); var closeBrace = ts.findChildOfKind(n, 16, sourceFile); addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); break; } - case 212: - case 213: + case 214: case 215: - case 163: - case 218: { + case 217: + case 165: + case 220: { var openBrace = ts.findChildOfKind(n, 15, sourceFile); var closeBrace = ts.findChildOfKind(n, 16, sourceFile); addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); break; } - case 162: + case 164: var openBracket = ts.findChildOfKind(n, 19, sourceFile); var closeBracket = ts.findChildOfKind(n, 20, sourceFile); addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); @@ -31147,10 +31661,10 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_28 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_28); + for (var name_29 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_29); if (declarations) { - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_28); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_29); if (!matches) { continue; } @@ -31161,14 +31675,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_28); + matches = patternMatcher.getMatches(containers, name_29); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_28, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_29, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -31191,7 +31705,7 @@ var ts; } function getTextOfIdentifierOrLiteral(node) { if (node) { - if (node.kind === 67 || + if (node.kind === 69 || node.kind === 9 || node.kind === 8) { return node.text; @@ -31205,7 +31719,7 @@ var ts; if (text !== undefined) { containers.unshift(text); } - else if (declaration.name.kind === 134) { + else if (declaration.name.kind === 136) { return tryAddComputedPropertyName(declaration.name.expression, containers, true); } else { @@ -31222,7 +31736,7 @@ var ts; } return true; } - if (expression.kind === 164) { + if (expression.kind === 166) { var propertyAccess = expression; if (includeLastPortion) { containers.unshift(propertyAccess.name.text); @@ -31233,7 +31747,7 @@ var ts; } function getContainers(declaration) { var containers = []; - if (declaration.name.kind === 134) { + if (declaration.name.kind === 136) { if (!tryAddComputedPropertyName(declaration.name.expression, containers, false)) { return undefined; } @@ -31296,14 +31810,14 @@ var ts; var current = node.parent; while (current) { switch (current.kind) { - case 216: + case 218: do { current = current.parent; - } while (current.kind === 216); - case 212: + } while (current.kind === 218); + case 214: + case 217: case 215: case 213: - case 211: indent++; } current = current.parent; @@ -31314,26 +31828,26 @@ var ts; var childNodes = []; function visit(node) { switch (node.kind) { - case 191: + case 193: ts.forEach(node.declarationList.declarations, visit); break; - case 159: - case 160: + case 161: + case 162: ts.forEach(node.elements, visit); break; - case 226: + case 228: if (node.exportClause) { ts.forEach(node.exportClause.elements, visit); } break; - case 220: + case 222: var importClause = node.importClause; if (importClause) { if (importClause.name) { childNodes.push(importClause); } if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222) { + if (importClause.namedBindings.kind === 224) { childNodes.push(importClause.namedBindings); } else { @@ -31342,20 +31856,20 @@ var ts; } } break; - case 161: - case 209: + case 163: + case 211: if (ts.isBindingPattern(node.name)) { visit(node.name); break; } - case 212: + case 214: + case 217: case 215: + case 218: case 213: - case 216: - case 211: - case 219: - case 224: - case 228: + case 221: + case 226: + case 230: childNodes.push(node); break; } @@ -31390,17 +31904,17 @@ var ts; for (var _i = 0; _i < nodes.length; _i++) { var node = nodes[_i]; switch (node.kind) { - case 212: + case 214: + case 217: case 215: - case 213: topLevelNodes.push(node); break; - case 216: + case 218: var moduleDeclaration = node; topLevelNodes.push(node); addTopLevelNodes(getInnermostModule(moduleDeclaration).body.statements, topLevelNodes); break; - case 211: + case 213: var functionDeclaration = node; if (isTopLevelFunctionDeclaration(functionDeclaration)) { topLevelNodes.push(node); @@ -31411,9 +31925,9 @@ var ts; } } function isTopLevelFunctionDeclaration(functionDeclaration) { - if (functionDeclaration.kind === 211) { - if (functionDeclaration.body && functionDeclaration.body.kind === 190) { - if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 211 && !isEmpty(s.name.text); })) { + if (functionDeclaration.kind === 213) { + if (functionDeclaration.body && functionDeclaration.body.kind === 192) { + if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 213 && !isEmpty(s.name.text); })) { return true; } if (!ts.isFunctionBlock(functionDeclaration.parent)) { @@ -31466,7 +31980,7 @@ var ts; } function createChildItem(node) { switch (node.kind) { - case 136: + case 138: if (ts.isBindingPattern(node.name)) { break; } @@ -31474,34 +31988,34 @@ var ts; return undefined; } return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 143: + case 142: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); + case 145: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberGetAccessorElement); + case 146: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); + case 149: + return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 247: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 147: + return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); + case 148: + return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); case 141: case 140: - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); - case 143: - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberGetAccessorElement); - case 144: - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); - case 147: - return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); - case 245: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 145: - return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); - case 146: - return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); - case 139: - case 138: - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 211: + case 213: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); - case 209: - case 161: + case 211: + case 163: var variableDeclarationNode; - var name_29; - if (node.kind === 161) { - name_29 = node.name; + var name_30; + if (node.kind === 163) { + name_30 = node.name; variableDeclarationNode = node; - while (variableDeclarationNode && variableDeclarationNode.kind !== 209) { + while (variableDeclarationNode && variableDeclarationNode.kind !== 211) { variableDeclarationNode = variableDeclarationNode.parent; } ts.Debug.assert(variableDeclarationNode !== undefined); @@ -31509,24 +32023,24 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_29 = node.name; + name_30 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.variableElement); } - case 142: + case 144: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); - case 228: - case 224: - case 219: + case 230: + case 226: case 221: - case 222: + case 223: + case 224: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.alias); } return undefined; @@ -31556,17 +32070,17 @@ var ts; } function createTopLevelItem(node) { switch (node.kind) { - case 246: + case 248: return createSourceFileItem(node); - case 212: + case 214: return createClassItem(node); - case 215: + case 217: return createEnumItem(node); - case 213: + case 215: return createIterfaceItem(node); - case 216: + case 218: return createModuleItem(node); - case 211: + case 213: return createFunctionItem(node); } return undefined; @@ -31576,7 +32090,7 @@ var ts; } var result = []; result.push(moduleDeclaration.name.text); - while (moduleDeclaration.body && moduleDeclaration.body.kind === 216) { + while (moduleDeclaration.body && moduleDeclaration.body.kind === 218) { moduleDeclaration = moduleDeclaration.body; result.push(moduleDeclaration.name.text); } @@ -31588,7 +32102,7 @@ var ts; return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } function createFunctionItem(node) { - if (node.body && node.body.kind === 190) { + if (node.body && node.body.kind === 192) { var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem); return getNavigationBarItem(!node.name ? "default" : node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } @@ -31609,7 +32123,7 @@ var ts; var childItems; if (node.members) { var constructor = ts.forEach(node.members, function (member) { - return member.kind === 142 && member; + return member.kind === 144 && member; }); var nodes = removeDynamicallyNamedProperties(node); if (constructor) { @@ -31630,19 +32144,19 @@ var ts; } } function removeComputedProperties(node) { - return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 134; }); + return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 136; }); } function removeDynamicallyNamedProperties(node) { return ts.filter(node.members, function (member) { return !ts.hasDynamicName(member); }); } function getInnermostModule(node) { - while (node.body.kind === 216) { + while (node.body.kind === 218) { node = node.body; } return node; } function getNodeSpan(node) { - return node.kind === 246 + return node.kind === 248 ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } @@ -32132,14 +32646,14 @@ var ts; } return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); function createJavaScriptSignatureHelpItems(argumentInfo) { - if (argumentInfo.invocation.kind !== 166) { + if (argumentInfo.invocation.kind !== 168) { return undefined; } var callExpression = argumentInfo.invocation; var expression = callExpression.expression; - var name = expression.kind === 67 + var name = expression.kind === 69 ? expression - : expression.kind === 164 + : expression.kind === 166 ? expression.name : undefined; if (!name || !name.text) { @@ -32168,7 +32682,7 @@ var ts; } } function getImmediatelyContainingArgumentInfo(node) { - if (node.parent.kind === 166 || node.parent.kind === 167) { + if (node.parent.kind === 168 || node.parent.kind === 169) { var callExpression = node.parent; if (node.kind === 25 || node.kind === 17) { @@ -32199,23 +32713,23 @@ var ts; }; } } - else if (node.kind === 11 && node.parent.kind === 168) { + else if (node.kind === 11 && node.parent.kind === 170) { if (ts.isInsideTemplateLiteral(node, position)) { return getArgumentListInfoForTemplate(node.parent, 0); } } - else if (node.kind === 12 && node.parent.parent.kind === 168) { + else if (node.kind === 12 && node.parent.parent.kind === 170) { var templateExpression = node.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 181); + ts.Debug.assert(templateExpression.kind === 183); var argumentIndex = ts.isInsideTemplateLiteral(node, position) ? 0 : 1; return getArgumentListInfoForTemplate(tagExpression, argumentIndex); } - else if (node.parent.kind === 188 && node.parent.parent.parent.kind === 168) { + else if (node.parent.kind === 190 && node.parent.parent.parent.kind === 170) { var templateSpan = node.parent; var templateExpression = templateSpan.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 181); + ts.Debug.assert(templateExpression.kind === 183); if (node.kind === 14 && !ts.isInsideTemplateLiteral(node, position)) { return undefined; } @@ -32279,7 +32793,7 @@ var ts; var template = taggedTemplate.template; var applicableSpanStart = template.getStart(); var applicableSpanEnd = template.getEnd(); - if (template.kind === 181) { + if (template.kind === 183) { var lastSpan = ts.lastOrUndefined(template.templateSpans); if (lastSpan.literal.getFullWidth() === 0) { applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, false); @@ -32288,7 +32802,7 @@ var ts; return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); } function getContainingArgumentInfo(node) { - for (var n = node; n.kind !== 246; n = n.parent) { + for (var n = node; n.kind !== 248; n = n.parent) { if (ts.isFunctionBlock(n)) { return undefined; } @@ -32468,39 +32982,39 @@ var ts; return false; } switch (n.kind) { - case 212: - case 213: + case 214: case 215: - case 163: - case 159: - case 153: - case 190: case 217: - case 218: + case 165: + case 161: + case 155: + case 192: + case 219: + case 220: return nodeEndsWith(n, 16, sourceFile); - case 242: + case 244: return isCompletedNode(n.block, sourceFile); - case 167: + case 169: if (!n.arguments) { return true; } - case 166: - case 170: - case 158: - return nodeEndsWith(n, 18, sourceFile); - case 150: - case 151: - return isCompletedNode(n.type, sourceFile); - case 142: - case 143: - case 144: - case 211: - case 171: - case 141: - case 140: - case 146: - case 145: + case 168: case 172: + case 160: + return nodeEndsWith(n, 18, sourceFile); + case 152: + case 153: + return isCompletedNode(n.type, sourceFile); + case 144: + case 145: + case 146: + case 213: + case 173: + case 143: + case 142: + case 148: + case 147: + case 174: if (n.body) { return isCompletedNode(n.body, sourceFile); } @@ -32508,61 +33022,62 @@ var ts; return isCompletedNode(n.type, sourceFile); } return hasChildOfKind(n, 18, sourceFile); - case 216: + case 218: return n.body && isCompletedNode(n.body, sourceFile); - case 194: + case 196: if (n.elseStatement) { return isCompletedNode(n.elseStatement, sourceFile); } return isCompletedNode(n.thenStatement, sourceFile); - case 193: - return isCompletedNode(n.expression, sourceFile); + case 195: + return isCompletedNode(n.expression, sourceFile) || + hasChildOfKind(n, 23); + case 164: case 162: - case 160: - case 165: - case 134: - case 155: + case 167: + case 136: + case 157: return nodeEndsWith(n, 20, sourceFile); - case 147: + case 149: if (n.type) { return isCompletedNode(n.type, sourceFile); } return hasChildOfKind(n, 20, sourceFile); - case 239: - case 240: + case 241: + case 242: return false; - case 197: - case 198: case 199: - case 196: + case 200: + case 201: + case 198: return isCompletedNode(n.statement, sourceFile); - case 195: - var hasWhileKeyword = findChildOfKind(n, 102, sourceFile); + case 197: + var hasWhileKeyword = findChildOfKind(n, 104, sourceFile); if (hasWhileKeyword) { return nodeEndsWith(n, 18, sourceFile); } return isCompletedNode(n.statement, sourceFile); - case 152: + case 154: return isCompletedNode(n.exprName, sourceFile); - case 174: - case 173: + case 176: case 175: - case 182: - case 183: + case 177: + case 184: + case 185: var unaryWordExpression = n; return isCompletedNode(unaryWordExpression.expression, sourceFile); - case 168: + case 170: return isCompletedNode(n.template, sourceFile); - case 181: + case 183: var lastSpan = ts.lastOrUndefined(n.templateSpans); return isCompletedNode(lastSpan, sourceFile); - case 188: + case 190: return ts.nodeIsPresent(n.literal); - case 177: - return isCompletedNode(n.operand, sourceFile); case 179: + return isCompletedNode(n.operand, sourceFile); + case 181: return isCompletedNode(n.right, sourceFile); - case 180: + case 182: return isCompletedNode(n.whenFalse, sourceFile); default: return true; @@ -32605,7 +33120,7 @@ var ts; ts.findChildOfKind = findChildOfKind; function findContainingList(node) { var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { - if (c.kind === 269 && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 271 && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -32685,7 +33200,7 @@ var ts; function findPrecedingToken(position, sourceFile, startNode) { return find(startNode || sourceFile); function findRightmostToken(n) { - if (isToken(n) || n.kind === 234) { + if (isToken(n) || n.kind === 236) { return n; } var children = n.getChildren(); @@ -32693,16 +33208,16 @@ var ts; return candidate && findRightmostToken(candidate); } function find(n) { - if (isToken(n) || n.kind === 234) { + if (isToken(n) || n.kind === 236) { return n; } var children = n.getChildren(); for (var i = 0, len = children.length; i < len; i++) { var child = children[i]; - if (position < child.end && (nodeHasTokens(child) || child.kind === 234)) { + if (position < child.end && (nodeHasTokens(child) || child.kind === 236)) { var start = child.getStart(sourceFile); var lookInPreviousChild = (start >= position) || - (child.kind === 234 && start === child.end); + (child.kind === 236 && start === child.end); if (lookInPreviousChild) { var candidate = findRightmostChildNodeWithTokens(children, i); return candidate && findRightmostToken(candidate); @@ -32712,7 +33227,7 @@ var ts; } } } - ts.Debug.assert(startNode !== undefined || n.kind === 246); + ts.Debug.assert(startNode !== undefined || n.kind === 248); if (children.length) { var candidate = findRightmostChildNodeWithTokens(children, children.length); return candidate && findRightmostToken(candidate); @@ -32764,9 +33279,9 @@ var ts; var node = ts.getTokenAtPosition(sourceFile, position); if (isToken(node)) { switch (node.kind) { - case 100: - case 106: - case 72: + case 102: + case 108: + case 74: node = node.parent === undefined ? undefined : node.parent.parent; break; default: @@ -32812,21 +33327,21 @@ var ts; } ts.getNodeModifiers = getNodeModifiers; function getTypeArgumentOrTypeParameterList(node) { - if (node.kind === 149 || node.kind === 166) { + if (node.kind === 151 || node.kind === 168) { return node.typeArguments; } - if (ts.isFunctionLike(node) || node.kind === 212 || node.kind === 213) { + if (ts.isFunctionLike(node) || node.kind === 214 || node.kind === 215) { return node.typeParameters; } return undefined; } ts.getTypeArgumentOrTypeParameterList = getTypeArgumentOrTypeParameterList; function isToken(n) { - return n.kind >= 0 && n.kind <= 132; + return n.kind >= 0 && n.kind <= 134; } ts.isToken = isToken; function isWord(kind) { - return kind === 67 || ts.isKeyword(kind); + return kind === 69 || ts.isKeyword(kind); } ts.isWord = isWord; function isPropertyName(kind) { @@ -32836,8 +33351,17 @@ var ts; return kind === 2 || kind === 3; } ts.isComment = isComment; + function isStringOrRegularExpressionOrTemplateLiteral(kind) { + if (kind === 9 + || kind === 10 + || ts.isTemplateLiteralKind(kind)) { + return true; + } + return false; + } + ts.isStringOrRegularExpressionOrTemplateLiteral = isStringOrRegularExpressionOrTemplateLiteral; function isPunctuation(kind) { - return 15 <= kind && kind <= 66; + return 15 <= kind && kind <= 68; } ts.isPunctuation = isPunctuation; function isInsideTemplateLiteral(node, position) { @@ -32847,9 +33371,9 @@ var ts; ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function isAccessibilityModifier(kind) { switch (kind) { + case 112: case 110: - case 108: - case 109: + case 111: return true; } return false; @@ -32875,7 +33399,7 @@ var ts; var ts; (function (ts) { function isFirstDeclarationOfSymbolParameter(symbol) { - return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 136; + return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 138; } ts.isFirstDeclarationOfSymbolParameter = isFirstDeclarationOfSymbolParameter; var displayPartWriter = getDisplayPartWriter(); @@ -32897,7 +33421,8 @@ var ts; increaseIndent: function () { indent++; }, decreaseIndent: function () { indent--; }, clear: resetWriter, - trackSymbol: function () { } + trackSymbol: function () { }, + reportInaccessibleThisError: function () { } }; function writeIndent() { if (lineStart) { @@ -33055,7 +33580,7 @@ var ts; ts.getDeclaredName = getDeclaredName; function isImportOrExportSpecifierName(location) { return location.parent && - (location.parent.kind === 224 || location.parent.kind === 228) && + (location.parent.kind === 226 || location.parent.kind === 230) && location.parent.propertyName === location; } ts.isImportOrExportSpecifierName = isImportOrExportSpecifierName; @@ -33075,8 +33600,12 @@ var ts; (function (ts) { var formatting; (function (formatting) { - var scanner = ts.createScanner(2, false); + var standardScanner = ts.createScanner(2, false, 0); + var jsxScanner = ts.createScanner(2, false, 1); + var scanner; function getFormattingScanner(sourceFile, startPos, endPos) { + ts.Debug.assert(scanner === undefined); + scanner = sourceFile.languageVariant === 1 ? jsxScanner : standardScanner; scanner.setText(sourceFile.text); scanner.setTextPos(startPos); var wasNewLine = true; @@ -33091,11 +33620,14 @@ var ts; isOnToken: isOnToken, lastTrailingTriviaWasNewLine: function () { return wasNewLine; }, close: function () { + ts.Debug.assert(scanner !== undefined); lastTokenInfo = undefined; scanner.setText(undefined); + scanner = undefined; } }; function advance() { + ts.Debug.assert(scanner !== undefined); lastTokenInfo = undefined; var isStarted = scanner.getStartPos() !== startPos; if (isStarted) { @@ -33137,10 +33669,10 @@ var ts; if (node) { switch (node.kind) { case 29: - case 62: - case 63: + case 64: + case 65: + case 45: case 44: - case 43: return true; } } @@ -33149,11 +33681,11 @@ var ts; function shouldRescanJsxIdentifier(node) { if (node.parent) { switch (node.parent.kind) { - case 236: - case 233: + case 238: case 235: - case 232: - return node.kind === 67; + case 237: + case 234: + return node.kind === 69; } } return false; @@ -33166,9 +33698,10 @@ var ts; container.kind === 14; } function startsWithSlashToken(t) { - return t === 38 || t === 59; + return t === 39 || t === 61; } function readTokenInfo(n) { + ts.Debug.assert(scanner !== undefined); if (!isOnToken()) { return { leadingTrivia: leadingTrivia, @@ -33208,7 +33741,7 @@ var ts; currentToken = scanner.reScanTemplateToken(); lastScanAction = 3; } - else if (expectedScanAction === 4 && currentToken === 67) { + else if (expectedScanAction === 4 && currentToken === 69) { currentToken = scanner.scanJsxIdentifier(); lastScanAction = 4; } @@ -33250,6 +33783,7 @@ var ts; return fixTokenKind(lastTokenInfo, n); } function isOnToken() { + ts.Debug.assert(scanner !== undefined); var current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken(); var startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos(); return startPos < endPos && current !== 1 && !ts.isTrivia(current); @@ -33462,15 +33996,15 @@ var ts; this.IgnoreBeforeComment = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.Comments), formatting.RuleOperation.create1(1)); this.IgnoreAfterLineComment = new formatting.Rule(formatting.RuleDescriptor.create3(2, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create1(1)); this.NoSpaceBeforeSemicolon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceBeforeColon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 53), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8)); - this.NoSpaceBeforeQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8)); - this.SpaceAfterColon = new formatting.Rule(formatting.RuleDescriptor.create3(53, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 2)); - this.SpaceAfterQuestionMarkInConditionalOperator = new formatting.Rule(formatting.RuleDescriptor.create3(52, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsConditionalOperatorContext), 2)); - this.NoSpaceAfterQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create3(52, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceBeforeColon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 54), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8)); + this.NoSpaceBeforeQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 53), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8)); + this.SpaceAfterColon = new formatting.Rule(formatting.RuleDescriptor.create3(54, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 2)); + this.SpaceAfterQuestionMarkInConditionalOperator = new formatting.Rule(formatting.RuleDescriptor.create3(53, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsConditionalOperatorContext), 2)); + this.NoSpaceAfterQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create3(53, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceAfterSemicolon = new formatting.Rule(formatting.RuleDescriptor.create3(23, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.SpaceAfterCloseBrace = new formatting.Rule(formatting.RuleDescriptor.create3(16, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsAfterCodeBlockContext), 2)); - this.SpaceBetweenCloseBraceAndElse = new formatting.Rule(formatting.RuleDescriptor.create1(16, 78), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceBetweenCloseBraceAndWhile = new formatting.Rule(formatting.RuleDescriptor.create1(16, 102), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBetweenCloseBraceAndElse = new formatting.Rule(formatting.RuleDescriptor.create1(16, 80), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBetweenCloseBraceAndWhile = new formatting.Rule(formatting.RuleDescriptor.create1(16, 104), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterCloseBrace = new formatting.Rule(formatting.RuleDescriptor.create3(16, formatting.Shared.TokenRange.FromTokens([18, 20, 24, 23])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.NoSpaceBeforeDot = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 21), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.NoSpaceAfterDot = new formatting.Rule(formatting.RuleDescriptor.create3(21, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); @@ -33478,9 +34012,9 @@ var ts; this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(20, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), 8)); this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67, 3, 71]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69, 3, 73]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); - this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18, 3, 77, 98, 83, 78]); + this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18, 3, 79, 100, 85, 80]); this.SpaceBeforeOpenBraceInControl = new formatting.Rule(formatting.RuleDescriptor.create2(this.ControlOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); this.SpaceAfterOpenBrace = new formatting.Rule(formatting.RuleDescriptor.create3(15, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSingleLineBlockContext), 2)); this.SpaceBeforeCloseBrace = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSingleLineBlockContext), 2)); @@ -33488,37 +34022,37 @@ var ts; this.NewLineAfterOpenBraceInBlockContext = new formatting.Rule(formatting.RuleDescriptor.create3(15, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsMultilineBlockContext), 4)); this.NewLineBeforeCloseBraceInBlockContext = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.AnyIncludingMultilineComments, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsMultilineBlockContext), 4)); this.NoSpaceAfterUnaryPrefixOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.UnaryPrefixOperators, formatting.Shared.TokenRange.UnaryPrefixExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8)); - this.NoSpaceAfterUnaryPreincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(40, formatting.Shared.TokenRange.UnaryPreincrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceAfterUnaryPredecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(41, formatting.Shared.TokenRange.UnaryPredecrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceBeforeUnaryPostincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostincrementExpressions, 40), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceBeforeUnaryPostdecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostdecrementExpressions, 41), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterPostincrementWhenFollowedByAdd = new formatting.Rule(formatting.RuleDescriptor.create1(40, 35), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); + this.NoSpaceAfterUnaryPreincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(41, formatting.Shared.TokenRange.UnaryPreincrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceAfterUnaryPredecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(42, formatting.Shared.TokenRange.UnaryPredecrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceBeforeUnaryPostincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostincrementExpressions, 41), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceBeforeUnaryPostdecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostdecrementExpressions, 42), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceAfterPostincrementWhenFollowedByAdd = new formatting.Rule(formatting.RuleDescriptor.create1(41, 35), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterAddWhenFollowedByUnaryPlus = new formatting.Rule(formatting.RuleDescriptor.create1(35, 35), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); - this.SpaceAfterAddWhenFollowedByPreincrement = new formatting.Rule(formatting.RuleDescriptor.create1(35, 40), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); - this.SpaceAfterPostdecrementWhenFollowedBySubtract = new formatting.Rule(formatting.RuleDescriptor.create1(41, 36), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); + this.SpaceAfterAddWhenFollowedByPreincrement = new formatting.Rule(formatting.RuleDescriptor.create1(35, 41), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); + this.SpaceAfterPostdecrementWhenFollowedBySubtract = new formatting.Rule(formatting.RuleDescriptor.create1(42, 36), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterSubtractWhenFollowedByUnaryMinus = new formatting.Rule(formatting.RuleDescriptor.create1(36, 36), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); - this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(36, 41), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); + this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(36, 42), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 24), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([100, 96, 90, 76, 92, 99, 117]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([106, 72]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); + this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([102, 98, 92, 78, 94, 101, 119]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([108, 74]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8)); - this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(85, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(87, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8)); - this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(101, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), 2)); - this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(92, 23), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([18, 77, 78, 69]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2)); - this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([98, 83]), 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([121, 127]), 67), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(103, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), 2)); + this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(94, 23), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([18, 79, 80, 71]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2)); + this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([100, 85]), 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([123, 129]), 69), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); - this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(119, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([123, 125]), 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([113, 71, 120, 75, 79, 80, 81, 121, 104, 87, 105, 123, 124, 108, 110, 109, 127, 111, 130]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([81, 104])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(121, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([125, 127]), 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115, 73, 122, 77, 81, 82, 83, 123, 106, 89, 107, 125, 126, 110, 112, 111, 129, 113, 132]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83, 106])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(34, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(22, 67), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceAfterOptionalParameters = new formatting.Rule(formatting.RuleDescriptor.create3(52, formatting.Shared.TokenRange.FromTokens([18, 24])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8)); + this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(22, 69), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceAfterOptionalParameters = new formatting.Rule(formatting.RuleDescriptor.create3(53, formatting.Shared.TokenRange.FromTokens([18, 24])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8)); this.NoSpaceBeforeOpenAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.TypeNames, 25), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8)); this.NoSpaceBetweenCloseParenAndAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create1(18, 25), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8)); this.NoSpaceAfterOpenAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create3(25, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8)); @@ -33526,15 +34060,18 @@ var ts; this.NoSpaceAfterCloseAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create3(27, formatting.Shared.TokenRange.FromTokens([17, 19, 27, 24])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8)); this.NoSpaceAfterTypeAssertion = new formatting.Rule(formatting.RuleDescriptor.create3(27, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeAssertionContext), 8)); this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(15, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), 8)); - this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 54), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(54, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([113, 67, 80, 75, 71, 111, 110, 108, 109, 121, 127, 19, 37])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2)); - this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(85, 37), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8)); - this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(37, formatting.Shared.TokenRange.FromTokens([67, 17])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2)); - this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(112, 37), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8)); - this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([112, 37]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2)); - this.SpaceBetweenAsyncAndFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(116, 85), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(67, formatting.Shared.TokenRange.FromTokens([11, 12])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 55), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(55, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([115, 69, 82, 77, 73, 113, 112, 110, 111, 123, 129, 19, 37])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2)); + this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(87, 37), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8)); + this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(37, formatting.Shared.TokenRange.FromTokens([69, 17])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2)); + this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(114, 37), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8)); + this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([114, 37]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2)); + this.SpaceBetweenAsyncAndOpenParen = new formatting.Rule(formatting.RuleDescriptor.create1(118, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsArrowFunctionContext, Rules.IsSameLineTokenContext), 2)); + this.SpaceBetweenAsyncAndFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(118, 87), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(69, formatting.Shared.TokenRange.FromTokens([11, 12])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.NoSpaceAfterTemplateHeadAndMiddle = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([12, 13]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceBeforeTemplateMiddleAndTail = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([13, 14])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.HighPriorityCommonRules = [ this.IgnoreBeforeComment, this.IgnoreAfterLineComment, @@ -33560,8 +34097,8 @@ var ts; this.NoSpaceBeforeOpenParenInFuncCall, this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, this.SpaceAfterVoidOperator, - this.SpaceBetweenAsyncAndFunctionKeyword, - this.SpaceBetweenTagAndTemplateString, + this.SpaceBetweenAsyncAndOpenParen, this.SpaceBetweenAsyncAndFunctionKeyword, + this.SpaceBetweenTagAndTemplateString, this.NoSpaceAfterTemplateHeadAndMiddle, this.NoSpaceBeforeTemplateMiddleAndTail, this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, this.SpaceAfterModuleName, @@ -33613,46 +34150,46 @@ var ts; this.NoSpaceBetweenBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(19, 20), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.NoSpaceAfterOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.NoSpaceBeforeCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 20), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(85, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); - this.NoSpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(85, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 8)); + this.SpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(87, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.NoSpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(87, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 8)); } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_30 in o) { - if (o[name_30] === rule) { - return name_30; + for (var name_31 in o) { + if (o[name_31] === rule) { + return name_31; } } throw new Error("Unknown rule"); }; Rules.IsForContext = function (context) { - return context.contextNode.kind === 197; + return context.contextNode.kind === 199; }; Rules.IsNotForContext = function (context) { return !Rules.IsForContext(context); }; Rules.IsBinaryOpContext = function (context) { switch (context.contextNode.kind) { - case 179: - case 180: - case 187: - case 148: - case 156: - case 157: + case 181: + case 182: + case 189: + case 150: + case 158: + case 159: return true; - case 161: - case 214: - case 219: - case 209: - case 136: - case 245: - case 139: + case 163: + case 216: + case 221: + case 211: case 138: - return context.currentTokenSpan.kind === 55 || context.nextTokenSpan.kind === 55; - case 198: - return context.currentTokenSpan.kind === 88 || context.nextTokenSpan.kind === 88; - case 199: - return context.currentTokenSpan.kind === 132 || context.nextTokenSpan.kind === 132; + case 247: + case 141: + case 140: + return context.currentTokenSpan.kind === 56 || context.nextTokenSpan.kind === 56; + case 200: + return context.currentTokenSpan.kind === 90 || context.nextTokenSpan.kind === 90; + case 201: + return context.currentTokenSpan.kind === 134 || context.nextTokenSpan.kind === 134; } return false; }; @@ -33660,7 +34197,7 @@ var ts; return !Rules.IsBinaryOpContext(context); }; Rules.IsConditionalOperatorContext = function (context) { - return context.contextNode.kind === 180; + return context.contextNode.kind === 182; }; Rules.IsSameLineTokenOrBeforeMultilineBlockContext = function (context) { return context.TokensAreOnSameLine() || Rules.IsBeforeMultilineBlockContext(context); @@ -33685,86 +34222,86 @@ var ts; return true; } switch (node.kind) { - case 190: - case 218: - case 163: - case 217: + case 192: + case 220: + case 165: + case 219: return true; } return false; }; Rules.IsFunctionDeclContext = function (context) { switch (context.contextNode.kind) { - case 211: - case 141: - case 140: - case 143: - case 144: - case 145: - case 171: - case 142: - case 172: case 213: + case 143: + case 142: + case 145: + case 146: + case 147: + case 173: + case 144: + case 174: + case 215: return true; } return false; }; Rules.IsFunctionDeclarationOrFunctionExpressionContext = function (context) { - return context.contextNode.kind === 211 || context.contextNode.kind === 171; + return context.contextNode.kind === 213 || context.contextNode.kind === 173; }; Rules.IsTypeScriptDeclWithBlockContext = function (context) { return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode); }; Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) { switch (node.kind) { - case 212: - case 184: - case 213: + case 214: + case 186: case 215: - case 153: - case 216: + case 217: + case 155: + case 218: return true; } return false; }; Rules.IsAfterCodeBlockContext = function (context) { switch (context.currentTokenParent.kind) { - case 212: - case 216: - case 215: - case 190: - case 242: + case 214: + case 218: case 217: - case 204: + case 192: + case 244: + case 219: + case 206: return true; } return false; }; Rules.IsControlDeclContext = function (context) { switch (context.contextNode.kind) { - case 194: - case 204: - case 197: - case 198: - case 199: case 196: - case 207: - case 195: - case 203: - case 242: + case 206: + case 199: + case 200: + case 201: + case 198: + case 209: + case 197: + case 205: + case 244: return true; default: return false; } }; Rules.IsObjectContext = function (context) { - return context.contextNode.kind === 163; + return context.contextNode.kind === 165; }; Rules.IsFunctionCallContext = function (context) { - return context.contextNode.kind === 166; + return context.contextNode.kind === 168; }; Rules.IsNewContext = function (context) { - return context.contextNode.kind === 167; + return context.contextNode.kind === 169; }; Rules.IsFunctionCallOrNewContext = function (context) { return Rules.IsFunctionCallContext(context) || Rules.IsNewContext(context); @@ -33772,6 +34309,9 @@ var ts; Rules.IsPreviousTokenNotComma = function (context) { return context.currentTokenSpan.kind !== 24; }; + Rules.IsArrowFunctionContext = function (context) { + return context.contextNode.kind === 174; + }; Rules.IsSameLineTokenContext = function (context) { return context.TokensAreOnSameLine(); }; @@ -33788,41 +34328,41 @@ var ts; while (ts.isExpression(node)) { node = node.parent; } - return node.kind === 137; + return node.kind === 139; }; Rules.IsStartOfVariableDeclarationList = function (context) { - return context.currentTokenParent.kind === 210 && + return context.currentTokenParent.kind === 212 && context.currentTokenParent.getStart(context.sourceFile) === context.currentTokenSpan.pos; }; Rules.IsNotFormatOnEnter = function (context) { return context.formattingRequestKind !== 2; }; Rules.IsModuleDeclContext = function (context) { - return context.contextNode.kind === 216; + return context.contextNode.kind === 218; }; Rules.IsObjectTypeContext = function (context) { - return context.contextNode.kind === 153; + return context.contextNode.kind === 155; }; Rules.IsTypeArgumentOrParameterOrAssertion = function (token, parent) { if (token.kind !== 25 && token.kind !== 27) { return false; } switch (parent.kind) { - case 149: - case 169: - case 212: - case 184: - case 213: - case 211: + case 151: case 171: - case 172: - case 141: - case 140: - case 145: - case 146: - case 166: - case 167: + case 214: case 186: + case 215: + case 213: + case 173: + case 174: + case 143: + case 142: + case 147: + case 148: + case 168: + case 169: + case 188: return true; default: return false; @@ -33833,13 +34373,13 @@ var ts; Rules.IsTypeArgumentOrParameterOrAssertion(context.nextTokenSpan, context.nextTokenParent); }; Rules.IsTypeAssertionContext = function (context) { - return context.contextNode.kind === 169; + return context.contextNode.kind === 171; }; Rules.IsVoidOpContext = function (context) { - return context.currentTokenSpan.kind === 101 && context.currentTokenParent.kind === 175; + return context.currentTokenSpan.kind === 103 && context.currentTokenParent.kind === 177; }; Rules.IsYieldOrYieldStarWithOperand = function (context) { - return context.contextNode.kind === 182 && context.contextNode.expression !== undefined; + return context.contextNode.kind === 184 && context.contextNode.expression !== undefined; }; return Rules; })(); @@ -33861,7 +34401,7 @@ var ts; return result; }; RulesMap.prototype.Initialize = function (rules) { - this.mapRowLength = 132 + 1; + this.mapRowLength = 134 + 1; this.map = new Array(this.mapRowLength * this.mapRowLength); var rulesBucketConstructionStateList = new Array(this.map.length); this.FillRules(rules, rulesBucketConstructionStateList); @@ -34037,7 +34577,7 @@ var ts; } TokenAllAccess.prototype.GetTokens = function () { var result = []; - for (var token = 0; token <= 132; token++) { + for (var token = 0; token <= 134; token++) { result.push(token); } return result; @@ -34079,17 +34619,17 @@ var ts; }; TokenRange.Any = TokenRange.AllTokens(); TokenRange.AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([3])); - TokenRange.Keywords = TokenRange.FromRange(68, 132); - TokenRange.BinaryOperators = TokenRange.FromRange(25, 66); - TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([88, 89, 132, 114, 122]); - TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([40, 41, 49, 48]); - TokenRange.UnaryPrefixExpressions = TokenRange.FromTokens([8, 67, 17, 19, 15, 95, 90]); - TokenRange.UnaryPreincrementExpressions = TokenRange.FromTokens([67, 17, 95, 90]); - TokenRange.UnaryPostincrementExpressions = TokenRange.FromTokens([67, 18, 20, 90]); - TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([67, 17, 95, 90]); - TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([67, 18, 20, 90]); + TokenRange.Keywords = TokenRange.FromRange(70, 134); + TokenRange.BinaryOperators = TokenRange.FromRange(25, 68); + TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([90, 91, 134, 116, 124]); + TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([41, 42, 50, 49]); + TokenRange.UnaryPrefixExpressions = TokenRange.FromTokens([8, 69, 17, 19, 15, 97, 92]); + TokenRange.UnaryPreincrementExpressions = TokenRange.FromTokens([69, 17, 97, 92]); + TokenRange.UnaryPostincrementExpressions = TokenRange.FromTokens([69, 18, 20, 92]); + TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([69, 17, 97, 92]); + TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([69, 18, 20, 92]); TokenRange.Comments = TokenRange.FromTokens([2, 3]); - TokenRange.TypeNames = TokenRange.FromTokens([67, 126, 128, 118, 129, 101, 115]); + TokenRange.TypeNames = TokenRange.FromTokens([69, 128, 130, 120, 131, 103, 117]); return TokenRange; })(); Shared.TokenRange = TokenRange; @@ -34260,17 +34800,17 @@ var ts; } function isListElement(parent, node) { switch (parent.kind) { - case 212: - case 213: + case 214: + case 215: return ts.rangeContainsRange(parent.members, node); - case 216: + case 218: var body = parent.body; - return body && body.kind === 190 && ts.rangeContainsRange(body.statements, node); - case 246: - case 190: - case 217: + return body && body.kind === 192 && ts.rangeContainsRange(body.statements, node); + case 248: + case 192: + case 219: return ts.rangeContainsRange(parent.statements, node); - case 242: + case 244: return ts.rangeContainsRange(parent.block.statements, node); } return false; @@ -34395,9 +34935,9 @@ var ts; if (indentation === -1) { if (isSomeBlock(node.kind)) { if (isSomeBlock(parent.kind) || - parent.kind === 246 || - parent.kind === 239 || - parent.kind === 240) { + parent.kind === 248 || + parent.kind === 241 || + parent.kind === 242) { indentation = parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(); } else { @@ -34430,18 +34970,18 @@ var ts; return node.modifiers[0].kind; } switch (node.kind) { - case 212: return 71; - case 213: return 105; - case 211: return 85; - case 215: return 215; - case 143: return 121; - case 144: return 127; - case 141: + case 214: return 73; + case 215: return 107; + case 213: return 87; + case 217: return 217; + case 145: return 123; + case 146: return 129; + case 143: if (node.asteriskToken) { return 37; } - case 139: - case 136: + case 141: + case 138: return node.name.kind; } } @@ -34469,9 +35009,9 @@ var ts; case 20: case 17: case 18: - case 78: - case 102: - case 54: + case 80: + case 104: + case 55: return indentation; default: return nodeStartLine !== line ? indentation + delta : indentation; @@ -34551,7 +35091,7 @@ var ts; consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation); return inheritedIndentation; } - var effectiveParentStartLine = child.kind === 137 ? childStartLine : undecoratedParentStartLine; + var effectiveParentStartLine = child.kind === 139 ? childStartLine : undecoratedParentStartLine; var childIndentation = computeIndentation(child, childStartLine, childIndentationAmount, node, parentDynamicIndentation, effectiveParentStartLine); processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta); childContextNode = node; @@ -34783,7 +35323,7 @@ var ts; for (var line = line1; line < line2; ++line) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); - if (range && ts.isComment(range.kind) && range.pos <= lineEndPosition && range.end > lineEndPosition) { + if (range && (ts.isComment(range.kind) || ts.isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) { continue; } var pos = lineEndPosition; @@ -34842,20 +35382,20 @@ var ts; } function isSomeBlock(kind) { switch (kind) { - case 190: - case 217: + case 192: + case 219: return true; } return false; } function getOpenTokenForList(node, list) { switch (node.kind) { + case 144: + case 213: + case 173: + case 143: case 142: - case 211: - case 171: - case 141: - case 140: - case 172: + case 174: if (node.typeParameters === list) { return 25; } @@ -34863,8 +35403,8 @@ var ts; return 17; } break; - case 166: - case 167: + case 168: + case 169: if (node.typeArguments === list) { return 25; } @@ -34872,7 +35412,7 @@ var ts; return 17; } break; - case 149: + case 151: if (node.typeArguments === list) { return 25; } @@ -34949,21 +35489,31 @@ var ts; if (position > sourceFile.text.length) { return 0; } + if (options.IndentStyle === ts.IndentStyle.None) { + return 0; + } var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { return 0; } - var precedingTokenIsLiteral = precedingToken.kind === 9 || - precedingToken.kind === 10 || - precedingToken.kind === 11 || - precedingToken.kind === 12 || - precedingToken.kind === 13 || - precedingToken.kind === 14; + var precedingTokenIsLiteral = ts.isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind); if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } var lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line; - if (precedingToken.kind === 24 && precedingToken.parent.kind !== 179) { + if (options.IndentStyle === ts.IndentStyle.Block) { + var current_1 = position; + while (current_1 > 0) { + var char = sourceFile.text.charCodeAt(current_1); + if (!ts.isWhiteSpace(char) && !ts.isLineBreak(char)) { + break; + } + current_1--; + } + var lineStart = ts.getLineStartPositionForPosition(current_1, sourceFile); + return SmartIndenter.findFirstNonWhitespaceColumn(lineStart, current_1, sourceFile, options); + } + if (precedingToken.kind === 24 && precedingToken.parent.kind !== 181) { var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options); if (actualIndentation !== -1) { return actualIndentation; @@ -35061,7 +35611,7 @@ var ts; } function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) { var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && - (parent.kind === 246 || !parentAndChildShareLine); + (parent.kind === 248 || !parentAndChildShareLine); if (!useActualIndentation) { return -1; } @@ -35085,8 +35635,8 @@ var ts; return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); } function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) { - if (parent.kind === 194 && parent.elseStatement === child) { - var elseKeyword = ts.findChildOfKind(parent, 78, sourceFile); + if (parent.kind === 196 && parent.elseStatement === child) { + var elseKeyword = ts.findChildOfKind(parent, 80, sourceFile); ts.Debug.assert(elseKeyword !== undefined); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; return elseKeywordStartLine === childStartLine; @@ -35097,23 +35647,23 @@ var ts; function getContainingList(node, sourceFile) { if (node.parent) { switch (node.parent.kind) { - case 149: + case 151: if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, node.getStart(sourceFile), node.getEnd())) { return node.parent.typeArguments; } break; - case 163: + case 165: return node.parent.properties; - case 162: + case 164: return node.parent.elements; - case 211: - case 171: - case 172: - case 141: - case 140: - case 145: - case 146: { + case 213: + case 173: + case 174: + case 143: + case 142: + case 147: + case 148: { var start = node.getStart(sourceFile); if (node.parent.typeParameters && ts.rangeContainsStartEnd(node.parent.typeParameters, start, node.getEnd())) { @@ -35124,8 +35674,8 @@ var ts; } break; } - case 167: - case 166: { + case 169: + case 168: { var start = node.getStart(sourceFile); if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, start, node.getEnd())) { @@ -35153,8 +35703,8 @@ var ts; if (node.kind === 18) { return -1; } - if (node.parent && (node.parent.kind === 166 || - node.parent.kind === 167) && + if (node.parent && (node.parent.kind === 168 || + node.parent.kind === 169) && node.parent.expression !== node) { var fullCallOrNewExpression = node.parent.expression; var startingExpression = getStartingExpression(fullCallOrNewExpression); @@ -35172,10 +35722,10 @@ var ts; function getStartingExpression(node) { while (true) { switch (node.kind) { + case 168: + case 169: case 166: case 167: - case 164: - case 165: node = node.expression; break; default: @@ -35230,42 +35780,43 @@ var ts; SmartIndenter.findFirstNonWhitespaceColumn = findFirstNonWhitespaceColumn; function nodeContentIsAlwaysIndented(kind) { switch (kind) { - case 212: - case 184: - case 213: - case 215: + case 195: case 214: - case 162: - case 190: + case 186: + case 215: case 217: - case 163: - case 153: - case 155: - case 218: - case 240: - case 239: - case 170: + case 216: case 164: + case 192: + case 219: + case 165: + case 155: + case 157: + case 220: + case 242: + case 241: + case 172: case 166: - case 167: - case 191: - case 209: - case 225: - case 202: - case 180: - case 160: - case 159: - case 231: - case 232: - case 140: - case 145: - case 146: - case 136: - case 150: - case 151: - case 158: case 168: - case 176: + case 169: + case 193: + case 211: + case 227: + case 204: + case 182: + case 162: + case 161: + case 233: + case 234: + case 142: + case 147: + case 148: + case 138: + case 152: + case 153: + case 160: + case 170: + case 178: return true; } return false; @@ -35275,20 +35826,20 @@ var ts; return true; } switch (parent) { - case 195: - case 196: - case 198: - case 199: case 197: - case 194: - case 211: - case 171: - case 141: - case 172: - case 142: + case 198: + case 200: + case 201: + case 199: + case 196: + case 213: + case 173: case 143: + case 174: case 144: - return child !== 190; + case 145: + case 146: + return child !== 192; default: return false; } @@ -35417,7 +35968,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(269, nodes.pos, nodes.end, 4096, this); + var list = createNode(271, nodes.pos, nodes.end, 4096, this); list._children = []; var pos = nodes.pos; for (var _i = 0; _i < nodes.length; _i++) { @@ -35436,7 +35987,7 @@ var ts; NodeObject.prototype.createChildren = function (sourceFile) { var _this = this; var children; - if (this.kind >= 133) { + if (this.kind >= 135) { scanner.setText((sourceFile || this.getSourceFile()).text); children = []; var pos = this.pos; @@ -35483,7 +36034,7 @@ var ts; return undefined; } var child = children[0]; - return child.kind < 133 ? child : child.getFirstToken(sourceFile); + return child.kind < 135 ? child : child.getFirstToken(sourceFile); }; NodeObject.prototype.getLastToken = function (sourceFile) { var children = this.getChildren(sourceFile); @@ -35491,7 +36042,7 @@ var ts; if (!child) { return undefined; } - return child.kind < 133 ? child : child.getLastToken(sourceFile); + return child.kind < 135 ? child : child.getLastToken(sourceFile); }; return NodeObject; })(); @@ -35533,7 +36084,7 @@ var ts; ts.forEach(declarations, function (declaration, indexOfDeclaration) { if (ts.indexOf(declarations, declaration) === indexOfDeclaration) { var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); - if (canUseParsedParamTagComments && declaration.kind === 136) { + if (canUseParsedParamTagComments && declaration.kind === 138) { ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedParamJsDocComment) { @@ -35541,13 +36092,13 @@ var ts; } }); } - if (declaration.kind === 216 && declaration.body.kind === 216) { + if (declaration.kind === 218 && declaration.body.kind === 218) { return; } - while (declaration.kind === 216 && declaration.parent.kind === 216) { + while (declaration.kind === 218 && declaration.parent.kind === 218) { declaration = declaration.parent; } - ts.forEach(getJsDocCommentTextRange(declaration.kind === 209 ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + ts.forEach(getJsDocCommentTextRange(declaration.kind === 211 ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { ts.addRange(jsDocCommentParts, cleanedJsDocComment); @@ -35857,9 +36408,9 @@ var ts; if (result_2 !== undefined) { return result_2; } - if (declaration.name.kind === 134) { + if (declaration.name.kind === 136) { var expr = declaration.name.expression; - if (expr.kind === 164) { + if (expr.kind === 166) { return expr.name.text; } return getTextOfIdentifierOrLiteral(expr); @@ -35869,7 +36420,7 @@ var ts; } function getTextOfIdentifierOrLiteral(node) { if (node) { - if (node.kind === 67 || + if (node.kind === 69 || node.kind === 9 || node.kind === 8) { return node.text; @@ -35879,9 +36430,9 @@ var ts; } function visit(node) { switch (node.kind) { - case 211: - case 141: - case 140: + case 213: + case 143: + case 142: var functionDeclaration = node; var declarationName = getDeclarationName(functionDeclaration); if (declarationName) { @@ -35898,62 +36449,62 @@ var ts; ts.forEachChild(node, visit); } break; - case 212: - case 213: case 214: case 215: case 216: - case 219: - case 228: - case 224: - case 219: - case 221: - case 222: - case 143: - case 144: - case 153: - addDeclaration(node); - case 142: - case 191: - case 210: - case 159: - case 160: case 217: + case 218: + case 221: + case 230: + case 226: + case 221: + case 223: + case 224: + case 145: + case 146: + case 155: + addDeclaration(node); + case 144: + case 193: + case 212: + case 161: + case 162: + case 219: ts.forEachChild(node, visit); break; - case 190: + case 192: if (ts.isFunctionBlock(node)) { ts.forEachChild(node, visit); } break; - case 136: + case 138: if (!(node.flags & 112)) { break; } - case 209: - case 161: + case 211: + case 163: if (ts.isBindingPattern(node.name)) { ts.forEachChild(node.name, visit); break; } - case 245: - case 139: - case 138: + case 247: + case 141: + case 140: addDeclaration(node); break; - case 226: + case 228: if (node.exportClause) { ts.forEach(node.exportClause.elements, visit); } break; - case 220: + case 222: var importClause = node.importClause; if (importClause) { if (importClause.name) { addDeclaration(importClause); } if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222) { + if (importClause.namedBindings.kind === 224) { addDeclaration(importClause.namedBindings); } else { @@ -35980,6 +36531,12 @@ var ts; HighlightSpanKind.reference = "reference"; HighlightSpanKind.writtenReference = "writtenReference"; })(HighlightSpanKind = ts.HighlightSpanKind || (ts.HighlightSpanKind = {})); + (function (IndentStyle) { + IndentStyle[IndentStyle["None"] = 0] = "None"; + IndentStyle[IndentStyle["Block"] = 1] = "Block"; + IndentStyle[IndentStyle["Smart"] = 2] = "Smart"; + })(ts.IndentStyle || (ts.IndentStyle = {})); + var IndentStyle = ts.IndentStyle; (function (SymbolDisplayPartKind) { SymbolDisplayPartKind[SymbolDisplayPartKind["aliasName"] = 0] = "aliasName"; SymbolDisplayPartKind[SymbolDisplayPartKind["className"] = 1] = "className"; @@ -36095,14 +36652,14 @@ var ts; return false; } return ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 171) { + if (declaration.kind === 173) { return true; } - if (declaration.kind !== 209 && declaration.kind !== 211) { + if (declaration.kind !== 211 && declaration.kind !== 213) { return false; } for (var parent_8 = declaration.parent; !ts.isFunctionBlock(parent_8); parent_8 = parent_8.parent) { - if (parent_8.kind === 246 || parent_8.kind === 217) { + if (parent_8.kind === 248 || parent_8.kind === 219) { return false; } } @@ -36213,7 +36770,7 @@ var ts; options.allowNonTsExtensions = true; options.noLib = true; options.noResolve = true; - var inputFileName = transpileOptions.fileName || "module.ts"; + var inputFileName = transpileOptions.fileName || (options.jsx ? "module.tsx" : "module.ts"); var sourceFile = ts.createSourceFile(inputFileName, input, options.target); if (transpileOptions.moduleName) { sourceFile.moduleName = transpileOptions.moduleName; @@ -36433,9 +36990,9 @@ var ts; scanner.setText(sourceText); var token = scanner.scan(); while (token !== 1) { - if (token === 120) { + if (token === 122) { token = scanner.scan(); - if (token === 123) { + if (token === 125) { token = scanner.scan(); if (token === 9) { recordAmbientExternalModule(); @@ -36443,25 +37000,25 @@ var ts; } } } - else if (token === 87) { + else if (token === 89) { token = scanner.scan(); if (token === 9) { recordModuleName(); continue; } else { - if (token === 67 || ts.isKeyword(token)) { + if (token === 69 || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 131) { + if (token === 133) { token = scanner.scan(); if (token === 9) { recordModuleName(); continue; } } - else if (token === 55) { + else if (token === 56) { token = scanner.scan(); - if (token === 125) { + if (token === 127) { token = scanner.scan(); if (token === 17) { token = scanner.scan(); @@ -36486,7 +37043,7 @@ var ts; } if (token === 16) { token = scanner.scan(); - if (token === 131) { + if (token === 133) { token = scanner.scan(); if (token === 9) { recordModuleName(); @@ -36496,11 +37053,11 @@ var ts; } else if (token === 37) { token = scanner.scan(); - if (token === 114) { + if (token === 116) { token = scanner.scan(); - if (token === 67 || ts.isKeyword(token)) { + if (token === 69 || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 131) { + if (token === 133) { token = scanner.scan(); if (token === 9) { recordModuleName(); @@ -36511,7 +37068,7 @@ var ts; } } } - else if (token === 80) { + else if (token === 82) { token = scanner.scan(); if (token === 15) { token = scanner.scan(); @@ -36520,7 +37077,7 @@ var ts; } if (token === 16) { token = scanner.scan(); - if (token === 131) { + if (token === 133) { token = scanner.scan(); if (token === 9) { recordModuleName(); @@ -36530,20 +37087,20 @@ var ts; } else if (token === 37) { token = scanner.scan(); - if (token === 131) { + if (token === 133) { token = scanner.scan(); if (token === 9) { recordModuleName(); } } } - else if (token === 87) { + else if (token === 89) { token = scanner.scan(); - if (token === 67 || ts.isKeyword(token)) { + if (token === 69 || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 55) { + if (token === 56) { token = scanner.scan(); - if (token === 125) { + if (token === 127) { token = scanner.scan(); if (token === 17) { token = scanner.scan(); @@ -36569,7 +37126,7 @@ var ts; ts.preProcessFile = preProcessFile; function getTargetLabel(referenceNode, labelName) { while (referenceNode) { - if (referenceNode.kind === 205 && referenceNode.label.text === labelName) { + if (referenceNode.kind === 207 && referenceNode.label.text === labelName) { return referenceNode.label; } referenceNode = referenceNode.parent; @@ -36577,17 +37134,17 @@ var ts; return undefined; } function isJumpStatementTarget(node) { - return node.kind === 67 && - (node.parent.kind === 201 || node.parent.kind === 200) && + return node.kind === 69 && + (node.parent.kind === 203 || node.parent.kind === 202) && node.parent.label === node; } function isLabelOfLabeledStatement(node) { - return node.kind === 67 && - node.parent.kind === 205 && + return node.kind === 69 && + node.parent.kind === 207 && node.parent.label === node; } function isLabeledBy(node, labelName) { - for (var owner = node.parent; owner.kind === 205; owner = owner.parent) { + for (var owner = node.parent; owner.kind === 207; owner = owner.parent) { if (owner.label.text === labelName) { return true; } @@ -36598,48 +37155,48 @@ var ts; return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } function isRightSideOfQualifiedName(node) { - return node.parent.kind === 133 && node.parent.right === node; + return node.parent.kind === 135 && node.parent.right === node; } function isRightSideOfPropertyAccess(node) { - return node && node.parent && node.parent.kind === 164 && node.parent.name === node; + return node && node.parent && node.parent.kind === 166 && node.parent.name === node; } function isCallExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 166 && node.parent.expression === node; + return node && node.parent && node.parent.kind === 168 && node.parent.expression === node; } function isNewExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 167 && node.parent.expression === node; + return node && node.parent && node.parent.kind === 169 && node.parent.expression === node; } function isNameOfModuleDeclaration(node) { - return node.parent.kind === 216 && node.parent.name === node; + return node.parent.kind === 218 && node.parent.name === node; } function isNameOfFunctionDeclaration(node) { - return node.kind === 67 && + return node.kind === 69 && ts.isFunctionLike(node.parent) && node.parent.name === node; } function isNameOfPropertyAssignment(node) { - return (node.kind === 67 || node.kind === 9 || node.kind === 8) && - (node.parent.kind === 243 || node.parent.kind === 244) && node.parent.name === node; + return (node.kind === 69 || node.kind === 9 || node.kind === 8) && + (node.parent.kind === 245 || node.parent.kind === 246) && node.parent.name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node) { if (node.kind === 9 || node.kind === 8) { switch (node.parent.kind) { - case 139: - case 138: - case 243: - case 245: case 141: case 140: + case 245: + case 247: case 143: - case 144: - case 216: + case 142: + case 145: + case 146: + case 218: return node.parent.name === node; - case 165: + case 167: return node.parent.argumentExpression === node; } } @@ -36677,7 +37234,7 @@ var ts; } } var keywordCompletions = []; - for (var i = 68; i <= 132; i++) { + for (var i = 70; i <= 134; i++) { keywordCompletions.push({ name: ts.tokenToString(i), kind: ScriptElementKind.keyword, @@ -36692,17 +37249,17 @@ var ts; return undefined; } switch (node.kind) { - case 246: - case 141: - case 140: - case 211: - case 171: + case 248: case 143: - case 144: - case 212: + case 142: case 213: + case 173: + case 145: + case 146: + case 214: case 215: - case 216: + case 217: + case 218: return node; } } @@ -36710,38 +37267,38 @@ var ts; ts.getContainerNode = getContainerNode; function getNodeKind(node) { switch (node.kind) { - case 216: return ScriptElementKind.moduleElement; - case 212: return ScriptElementKind.classElement; - case 213: return ScriptElementKind.interfaceElement; - case 214: return ScriptElementKind.typeElement; - case 215: return ScriptElementKind.enumElement; - case 209: + case 218: return ScriptElementKind.moduleElement; + case 214: return ScriptElementKind.classElement; + case 215: return ScriptElementKind.interfaceElement; + case 216: return ScriptElementKind.typeElement; + case 217: return ScriptElementKind.enumElement; + case 211: return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; - case 211: return ScriptElementKind.functionElement; - case 143: return ScriptElementKind.memberGetAccessorElement; - case 144: return ScriptElementKind.memberSetAccessorElement; + case 213: return ScriptElementKind.functionElement; + case 145: return ScriptElementKind.memberGetAccessorElement; + case 146: return ScriptElementKind.memberSetAccessorElement; + case 143: + case 142: + return ScriptElementKind.memberFunctionElement; case 141: case 140: - return ScriptElementKind.memberFunctionElement; - case 139: - case 138: return ScriptElementKind.memberVariableElement; - case 147: return ScriptElementKind.indexSignatureElement; - case 146: return ScriptElementKind.constructSignatureElement; - case 145: return ScriptElementKind.callSignatureElement; - case 142: return ScriptElementKind.constructorImplementationElement; - case 135: return ScriptElementKind.typeParameterElement; - case 245: return ScriptElementKind.variableElement; - case 136: return (node.flags & 112) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; - case 219: - case 224: + case 149: return ScriptElementKind.indexSignatureElement; + case 148: return ScriptElementKind.constructSignatureElement; + case 147: return ScriptElementKind.callSignatureElement; + case 144: return ScriptElementKind.constructorImplementationElement; + case 137: return ScriptElementKind.typeParameterElement; + case 247: return ScriptElementKind.variableElement; + case 138: return (node.flags & 112) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; case 221: - case 228: - case 222: + case 226: + case 223: + case 230: + case 224: return ScriptElementKind.alias; } return ScriptElementKind.unknown; @@ -36923,44 +37480,44 @@ var ts; return false; } switch (node.kind) { - case 219: + case 221: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.import_can_only_be_used_in_a_ts_file)); return true; - case 225: + case 227: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.export_can_only_be_used_in_a_ts_file)); return true; - case 212: + case 214: var classDeclaration = node; if (checkModifiers(classDeclaration.modifiers) || checkTypeParameters(classDeclaration.typeParameters)) { return true; } break; - case 241: + case 243: var heritageClause = node; - if (heritageClause.token === 104) { + if (heritageClause.token === 106) { diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); return true; } break; - case 213: + case 215: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file)); return true; - case 216: + case 218: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.module_declarations_can_only_be_used_in_a_ts_file)); return true; - case 214: + case 216: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.type_aliases_can_only_be_used_in_a_ts_file)); return true; - case 141: - case 140: - case 142: case 143: + case 142: case 144: - case 171: - case 211: - case 172: - case 211: + case 145: + case 146: + case 173: + case 213: + case 174: + case 213: var functionDeclaration = node; if (checkModifiers(functionDeclaration.modifiers) || checkTypeParameters(functionDeclaration.typeParameters) || @@ -36968,20 +37525,20 @@ var ts; return true; } break; - case 191: + case 193: var variableStatement = node; if (checkModifiers(variableStatement.modifiers)) { return true; } break; - case 209: + case 211: var variableDeclaration = node; if (checkTypeAnnotation(variableDeclaration.type)) { return true; } break; - case 166: - case 167: + case 168: + case 169: var expression = node; if (expression.typeArguments && expression.typeArguments.length > 0) { var start = expression.typeArguments.pos; @@ -36989,7 +37546,7 @@ var ts; return true; } break; - case 136: + case 138: var parameter = node; if (parameter.modifiers) { var start = parameter.modifiers.pos; @@ -37005,17 +37562,17 @@ var ts; return true; } break; - case 139: + case 141: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.property_declarations_can_only_be_used_in_a_ts_file)); return true; - case 215: + case 217: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file)); return true; - case 169: + case 171: var typeAssertionExpression = node; diagnostics.push(ts.createDiagnosticForNode(typeAssertionExpression.type, ts.Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file)); return true; - case 137: + case 139: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.decorators_can_only_be_used_in_a_ts_file)); return true; } @@ -37041,17 +37598,17 @@ var ts; for (var _i = 0; _i < modifiers.length; _i++) { var modifier = modifiers[_i]; switch (modifier.kind) { + case 112: case 110: - case 108: - case 109: - case 120: + case 111: + case 122: diagnostics.push(ts.createDiagnosticForNode(modifier, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, ts.tokenToString(modifier.kind))); return true; - case 111: - case 80: - case 72: - case 75: case 113: + case 82: + case 74: + case 77: + case 115: } } } @@ -37115,9 +37672,9 @@ var ts; isJsDocTagName = true; } switch (tag.kind) { + case 269: case 267: - case 265: - case 266: + case 268: var tagWithExpression = tag; if (tagWithExpression.typeExpression) { insideJsDocTagExpression = tagWithExpression.typeExpression.pos < position && position < tagWithExpression.typeExpression.end; @@ -37145,6 +37702,7 @@ var ts; var node = currentToken; var isRightOfDot = false; var isRightOfOpenTag = false; + var isStartingCloseTag = false; var location = ts.getTouchingPropertyName(sourceFile, position); if (contextToken) { if (isCompletionListBlocker(contextToken)) { @@ -37153,11 +37711,11 @@ var ts; } var parent_9 = contextToken.parent, kind = contextToken.kind; if (kind === 21) { - if (parent_9.kind === 164) { + if (parent_9.kind === 166) { node = contextToken.parent.expression; isRightOfDot = true; } - else if (parent_9.kind === 133) { + else if (parent_9.kind === 135) { node = contextToken.parent.left; isRightOfDot = true; } @@ -37165,9 +37723,14 @@ var ts; return undefined; } } - else if (kind === 25 && sourceFile.languageVariant === 1) { - isRightOfOpenTag = true; - location = contextToken; + else if (sourceFile.languageVariant === 1) { + if (kind === 25) { + isRightOfOpenTag = true; + location = contextToken; + } + else if (kind === 39 && contextToken.parent.kind === 237) { + isStartingCloseTag = true; + } } } var semanticStart = new Date().getTime(); @@ -37188,6 +37751,12 @@ var ts; isMemberCompletion = true; isNewIdentifierLocation = false; } + else if (isStartingCloseTag) { + var tagName = contextToken.parent.parent.openingElement.tagName; + symbols = [typeChecker.getSymbolAtLocation(tagName)]; + isMemberCompletion = true; + isNewIdentifierLocation = false; + } else { if (!tryGetGlobalSymbols()) { return undefined; @@ -37198,7 +37767,7 @@ var ts; function getTypeScriptMemberSymbols() { isMemberCompletion = true; isNewIdentifierLocation = false; - if (node.kind === 67 || node.kind === 133 || node.kind === 164) { + if (node.kind === 69 || node.kind === 135 || node.kind === 166) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol && symbol.flags & 8388608) { symbol = typeChecker.getAliasedSymbol(symbol); @@ -37244,7 +37813,7 @@ var ts; } if (jsxContainer = tryGetContainingJsxElement(contextToken)) { var attrsType; - if ((jsxContainer.kind === 232) || (jsxContainer.kind === 233)) { + if ((jsxContainer.kind === 234) || (jsxContainer.kind === 235)) { attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); if (attrsType) { symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), jsxContainer.attributes); @@ -37278,49 +37847,64 @@ var ts; var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || isSolelyIdentifierDefinitionLocation(contextToken) || - isDotOfNumericLiteral(contextToken); + isDotOfNumericLiteral(contextToken) || + isInJsxText(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } + function isInJsxText(contextToken) { + if (contextToken.kind === 236) { + return true; + } + if (contextToken.kind === 27 && contextToken.parent) { + if (contextToken.parent.kind === 235) { + return true; + } + if (contextToken.parent.kind === 237 || contextToken.parent.kind === 234) { + return contextToken.parent.parent && contextToken.parent.parent.kind === 233; + } + } + return false; + } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 24: - return containingNodeKind === 166 - || containingNodeKind === 142 - || containingNodeKind === 167 - || containingNodeKind === 162 - || containingNodeKind === 179 - || containingNodeKind === 150; + return containingNodeKind === 168 + || containingNodeKind === 144 + || containingNodeKind === 169 + || containingNodeKind === 164 + || containingNodeKind === 181 + || containingNodeKind === 152; case 17: - return containingNodeKind === 166 - || containingNodeKind === 142 - || containingNodeKind === 167 - || containingNodeKind === 170 - || containingNodeKind === 158; + return containingNodeKind === 168 + || containingNodeKind === 144 + || containingNodeKind === 169 + || containingNodeKind === 172 + || containingNodeKind === 160; case 19: - return containingNodeKind === 162 - || containingNodeKind === 147 - || containingNodeKind === 134; - case 123: - case 124: + return containingNodeKind === 164 + || containingNodeKind === 149 + || containingNodeKind === 136; + case 125: + case 126: return true; case 21: - return containingNodeKind === 216; + return containingNodeKind === 218; case 15: - return containingNodeKind === 212; - case 55: - return containingNodeKind === 209 - || containingNodeKind === 179; + return containingNodeKind === 214; + case 56: + return containingNodeKind === 211 + || containingNodeKind === 181; case 12: - return containingNodeKind === 181; + return containingNodeKind === 183; case 13: - return containingNodeKind === 188; + return containingNodeKind === 190; + case 112: case 110: - case 108: - case 109: - return containingNodeKind === 139; + case 111: + return containingNodeKind === 141; } switch (previousToken.getText()) { case "public": @@ -37351,12 +37935,12 @@ var ts; isMemberCompletion = true; var typeForObject; var existingMembers; - if (objectLikeContainer.kind === 163) { + if (objectLikeContainer.kind === 165) { isNewIdentifierLocation = true; typeForObject = typeChecker.getContextualType(objectLikeContainer); existingMembers = objectLikeContainer.properties; } - else if (objectLikeContainer.kind === 159) { + else if (objectLikeContainer.kind === 161) { isNewIdentifierLocation = false; var rootDeclaration = ts.getRootDeclaration(objectLikeContainer.parent); if (ts.isVariableLike(rootDeclaration)) { @@ -37382,9 +37966,9 @@ var ts; return true; } function tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports) { - var declarationKind = namedImportsOrExports.kind === 223 ? - 220 : - 226; + var declarationKind = namedImportsOrExports.kind === 225 ? + 222 : + 228; var importOrExportDeclaration = ts.getAncestor(namedImportsOrExports, declarationKind); var moduleSpecifier = importOrExportDeclaration.moduleSpecifier; if (!moduleSpecifier) { @@ -37406,7 +37990,7 @@ var ts; case 15: case 24: var parent_10 = contextToken.parent; - if (parent_10 && (parent_10.kind === 163 || parent_10.kind === 159)) { + if (parent_10 && (parent_10.kind === 165 || parent_10.kind === 161)) { return parent_10; } break; @@ -37420,8 +38004,8 @@ var ts; case 15: case 24: switch (contextToken.parent.kind) { - case 223: - case 227: + case 225: + case 229: return contextToken.parent; } } @@ -37433,27 +38017,30 @@ var ts; var parent_11 = contextToken.parent; switch (contextToken.kind) { case 26: - case 38: - case 67: - case 236: - case 237: - if (parent_11 && (parent_11.kind === 232 || parent_11.kind === 233)) { + case 39: + case 69: + case 238: + case 239: + if (parent_11 && (parent_11.kind === 234 || parent_11.kind === 235)) { return parent_11; } + else if (parent_11.kind === 238) { + return parent_11.parent; + } break; case 9: - if (parent_11 && ((parent_11.kind === 236) || (parent_11.kind === 237))) { + if (parent_11 && ((parent_11.kind === 238) || (parent_11.kind === 239))) { return parent_11.parent; } break; case 16: if (parent_11 && - parent_11.kind === 238 && + parent_11.kind === 240 && parent_11.parent && - (parent_11.parent.kind === 236)) { + (parent_11.parent.kind === 238)) { return parent_11.parent.parent; } - if (parent_11 && parent_11.kind === 237) { + if (parent_11 && parent_11.kind === 239) { return parent_11.parent; } break; @@ -37463,16 +38050,16 @@ var ts; } function isFunction(kind) { switch (kind) { - case 171: - case 172: - case 211: - case 141: - case 140: + case 173: + case 174: + case 213: case 143: - case 144: + case 142: case 145: case 146: case 147: + case 148: + case 149: return true; } return false; @@ -37481,77 +38068,83 @@ var ts; var containingNodeKind = contextToken.parent.kind; switch (contextToken.kind) { case 24: - return containingNodeKind === 209 || - containingNodeKind === 210 || - containingNodeKind === 191 || - containingNodeKind === 215 || - isFunction(containingNodeKind) || + return containingNodeKind === 211 || containingNodeKind === 212 || - containingNodeKind === 184 || - containingNodeKind === 213 || - containingNodeKind === 160 || - containingNodeKind === 214; + containingNodeKind === 193 || + containingNodeKind === 217 || + isFunction(containingNodeKind) || + containingNodeKind === 214 || + containingNodeKind === 186 || + containingNodeKind === 215 || + containingNodeKind === 162 || + containingNodeKind === 216; case 21: - return containingNodeKind === 160; - case 53: - return containingNodeKind === 161; + return containingNodeKind === 162; + case 54: + return containingNodeKind === 163; case 19: - return containingNodeKind === 160; + return containingNodeKind === 162; case 17: - return containingNodeKind === 242 || + return containingNodeKind === 244 || isFunction(containingNodeKind); case 15: - return containingNodeKind === 215 || - containingNodeKind === 213 || - containingNodeKind === 153; + return containingNodeKind === 217 || + containingNodeKind === 215 || + containingNodeKind === 155; case 23: - return containingNodeKind === 138 && + return containingNodeKind === 140 && contextToken.parent && contextToken.parent.parent && - (contextToken.parent.parent.kind === 213 || - contextToken.parent.parent.kind === 153); + (contextToken.parent.parent.kind === 215 || + contextToken.parent.parent.kind === 155); case 25: - return containingNodeKind === 212 || - containingNodeKind === 184 || - containingNodeKind === 213 || - containingNodeKind === 214 || + return containingNodeKind === 214 || + containingNodeKind === 186 || + containingNodeKind === 215 || + containingNodeKind === 216 || isFunction(containingNodeKind); - case 111: - return containingNodeKind === 139; + case 113: + return containingNodeKind === 141; case 22: - return containingNodeKind === 136 || + return containingNodeKind === 138 || (contextToken.parent && contextToken.parent.parent && - contextToken.parent.parent.kind === 160); - case 110: - case 108: - case 109: - return containingNodeKind === 136; - case 114: - containingNodeKind === 224 || - containingNodeKind === 228 || - containingNodeKind === 222; - case 71: - case 79: - case 105: - case 85: - case 100: - case 121: - case 127: - case 87: - case 106: - case 72: + contextToken.parent.parent.kind === 162); case 112: - case 130: + case 110: + case 111: + return containingNodeKind === 138; + case 116: + return containingNodeKind === 226 || + containingNodeKind === 230 || + containingNodeKind === 224; + case 73: + case 81: + case 107: + case 87: + case 102: + case 123: + case 129: + case 89: + case 108: + case 74: + case 114: + case 132: return true; } switch (contextToken.getText()) { + case "abstract": + case "async": case "class": - case "interface": + case "const": + case "declare": case "enum": case "function": - case "var": - case "static": + case "interface": case "let": - case "const": + case "private": + case "protected": + case "public": + case "static": + case "var": case "yield": return true; } @@ -37571,8 +38164,8 @@ var ts; if (element.getStart() <= position && position <= element.getEnd()) { continue; } - var name_31 = element.propertyName || element.name; - exisingImportsOrExports[name_31.text] = true; + var name_32 = element.propertyName || element.name; + exisingImportsOrExports[name_32.text] = true; } if (ts.isEmpty(exisingImportsOrExports)) { return exportsOfModule; @@ -37586,16 +38179,16 @@ var ts; var existingMemberNames = {}; for (var _i = 0; _i < existingMembers.length; _i++) { var m = existingMembers[_i]; - if (m.kind !== 243 && - m.kind !== 244 && - m.kind !== 161) { + if (m.kind !== 245 && + m.kind !== 246 && + m.kind !== 163) { continue; } if (m.getStart() <= position && position <= m.getEnd()) { continue; } var existingName = void 0; - if (m.kind === 161 && m.propertyName) { + if (m.kind === 163 && m.propertyName) { existingName = m.propertyName.text; } else { @@ -37612,7 +38205,7 @@ var ts; if (attr.getStart() <= position && position <= attr.getEnd()) { continue; } - if (attr.kind === 236) { + if (attr.kind === 238) { seenNames[attr.name.text] = true; } } @@ -37651,10 +38244,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_32 in nameTable) { - if (!allNames[name_32]) { - allNames[name_32] = name_32; - var displayName = getCompletionEntryDisplayName(name_32, target, true); + for (var name_33 in nameTable) { + if (!allNames[name_33]) { + allNames[name_33] = name_33; + var displayName = getCompletionEntryDisplayName(name_33, target, true); if (displayName) { var entry = { name: displayName, @@ -37745,7 +38338,7 @@ var ts; function getSymbolKind(symbol, location) { var flags = symbol.getFlags(); if (flags & 32) - return ts.getDeclarationOfKind(symbol, 184) ? + return ts.getDeclarationOfKind(symbol, 186) ? ScriptElementKind.localClassElement : ScriptElementKind.classElement; if (flags & 384) return ScriptElementKind.enumElement; @@ -37841,14 +38434,14 @@ var ts; var signature; type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (type) { - if (location.parent && location.parent.kind === 164) { + if (location.parent && location.parent.kind === 166) { var right = location.parent.name; if (right === location || (right && right.getFullWidth() === 0)) { location = location.parent; } } var callExpression; - if (location.kind === 166 || location.kind === 167) { + if (location.kind === 168 || location.kind === 169) { callExpression = location; } else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { @@ -37860,9 +38453,9 @@ var ts; if (!signature && candidateSignatures.length) { signature = candidateSignatures[0]; } - var useConstructSignatures = callExpression.kind === 167 || callExpression.expression.kind === 93; + var useConstructSignatures = callExpression.kind === 169 || callExpression.expression.kind === 95; var allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); - if (!ts.contains(allSignatures, signature.target || signature)) { + if (!ts.contains(allSignatures, signature.target) && !ts.contains(allSignatures, signature)) { signature = allSignatures.length ? allSignatures[0] : undefined; } if (signature) { @@ -37875,7 +38468,7 @@ var ts; pushTypePart(symbolKind); displayParts.push(ts.spacePart()); if (useConstructSignatures) { - displayParts.push(ts.keywordPart(90)); + displayParts.push(ts.keywordPart(92)); displayParts.push(ts.spacePart()); } addFullSymbolName(symbol); @@ -37890,10 +38483,10 @@ var ts; case ScriptElementKind.letElement: case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: - displayParts.push(ts.punctuationPart(53)); + displayParts.push(ts.punctuationPart(54)); displayParts.push(ts.spacePart()); if (useConstructSignatures) { - displayParts.push(ts.keywordPart(90)); + displayParts.push(ts.keywordPart(92)); displayParts.push(ts.spacePart()); } if (!(type.flags & 65536)) { @@ -37908,21 +38501,21 @@ var ts; } } else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304)) || - (location.kind === 119 && location.parent.kind === 142)) { + (location.kind === 121 && location.parent.kind === 144)) { var functionDeclaration = location.parent; - var allSignatures = functionDeclaration.kind === 142 ? type.getConstructSignatures() : type.getCallSignatures(); + var allSignatures = functionDeclaration.kind === 144 ? type.getConstructSignatures() : type.getCallSignatures(); if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } else { signature = allSignatures[0]; } - if (functionDeclaration.kind === 142) { + if (functionDeclaration.kind === 144) { symbolKind = ScriptElementKind.constructorImplementationElement; addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); } else { - addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 145 && + addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 147 && !(type.symbol.flags & 2048 || type.symbol.flags & 4096) ? type.symbol : symbol, symbolKind); } addSignatureDisplayParts(signature, allSignatures); @@ -37931,11 +38524,11 @@ var ts; } } if (symbolFlags & 32 && !hasAddedSymbolInfo) { - if (ts.getDeclarationOfKind(symbol, 184)) { + if (ts.getDeclarationOfKind(symbol, 186)) { pushTypePart(ScriptElementKind.localClassElement); } else { - displayParts.push(ts.keywordPart(71)); + displayParts.push(ts.keywordPart(73)); } displayParts.push(ts.spacePart()); addFullSymbolName(symbol); @@ -37943,37 +38536,37 @@ var ts; } if ((symbolFlags & 64) && (semanticMeaning & 2)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(105)); + displayParts.push(ts.keywordPart(107)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if (symbolFlags & 524288) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(130)); + displayParts.push(ts.keywordPart(132)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55)); + displayParts.push(ts.operatorPart(56)); displayParts.push(ts.spacePart()); ts.addRange(displayParts, ts.typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & 384) { addNewLineIfDisplayPartsExist(); if (ts.forEach(symbol.declarations, ts.isConstEnumDeclaration)) { - displayParts.push(ts.keywordPart(72)); + displayParts.push(ts.keywordPart(74)); displayParts.push(ts.spacePart()); } - displayParts.push(ts.keywordPart(79)); + displayParts.push(ts.keywordPart(81)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } if (symbolFlags & 1536) { addNewLineIfDisplayPartsExist(); - var declaration = ts.getDeclarationOfKind(symbol, 216); - var isNamespace = declaration && declaration.name && declaration.name.kind === 67; - displayParts.push(ts.keywordPart(isNamespace ? 124 : 123)); + var declaration = ts.getDeclarationOfKind(symbol, 218); + var isNamespace = declaration && declaration.name && declaration.name.kind === 69; + displayParts.push(ts.keywordPart(isNamespace ? 126 : 125)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } @@ -37985,7 +38578,7 @@ var ts; displayParts.push(ts.spacePart()); addFullSymbolName(symbol); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(88)); + displayParts.push(ts.keywordPart(90)); displayParts.push(ts.spacePart()); if (symbol.parent) { addFullSymbolName(symbol.parent, enclosingDeclaration); @@ -37994,20 +38587,20 @@ var ts; else { var container = ts.getContainingFunction(location); if (container) { - var signatureDeclaration = ts.getDeclarationOfKind(symbol, 135).parent; + var signatureDeclaration = ts.getDeclarationOfKind(symbol, 137).parent; var signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration); - if (signatureDeclaration.kind === 146) { - displayParts.push(ts.keywordPart(90)); + if (signatureDeclaration.kind === 148) { + displayParts.push(ts.keywordPart(92)); displayParts.push(ts.spacePart()); } - else if (signatureDeclaration.kind !== 145 && signatureDeclaration.name) { + else if (signatureDeclaration.kind !== 147 && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } ts.addRange(displayParts, ts.signatureToDisplayParts(typeChecker, signature, sourceFile, 32)); } else { - var declaration = ts.getDeclarationOfKind(symbol, 135).parent; - displayParts.push(ts.keywordPart(130)); + var declaration = ts.getDeclarationOfKind(symbol, 137).parent; + displayParts.push(ts.keywordPart(132)); displayParts.push(ts.spacePart()); addFullSymbolName(declaration.symbol); writeTypeParametersOfSymbol(declaration.symbol, sourceFile); @@ -38017,11 +38610,11 @@ var ts; if (symbolFlags & 8) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); var declaration = symbol.declarations[0]; - if (declaration.kind === 245) { + if (declaration.kind === 247) { var constantValue = typeChecker.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55)); + displayParts.push(ts.operatorPart(56)); displayParts.push(ts.spacePart()); displayParts.push(ts.displayPart(constantValue.toString(), SymbolDisplayPartKind.numericLiteral)); } @@ -38029,17 +38622,17 @@ var ts; } if (symbolFlags & 8388608) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(87)); + displayParts.push(ts.keywordPart(89)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 219) { + if (declaration.kind === 221) { var importEqualsDeclaration = declaration; if (ts.isExternalModuleImportEqualsDeclaration(importEqualsDeclaration)) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55)); + displayParts.push(ts.operatorPart(56)); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(125)); + displayParts.push(ts.keywordPart(127)); displayParts.push(ts.punctuationPart(17)); displayParts.push(ts.displayPart(ts.getTextOfNode(ts.getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), SymbolDisplayPartKind.stringLiteral)); displayParts.push(ts.punctuationPart(18)); @@ -38048,7 +38641,7 @@ var ts; var internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55)); + displayParts.push(ts.operatorPart(56)); displayParts.push(ts.spacePart()); addFullSymbolName(internalAliasSymbol, enclosingDeclaration); } @@ -38064,7 +38657,7 @@ var ts; if (symbolKind === ScriptElementKind.memberVariableElement || symbolFlags & 3 || symbolKind === ScriptElementKind.localVariableElement) { - displayParts.push(ts.punctuationPart(53)); + displayParts.push(ts.punctuationPart(54)); displayParts.push(ts.spacePart()); if (type.symbol && type.symbol.flags & 262144) { var typeParameterParts = ts.mapToDisplayParts(function (writer) { @@ -38162,11 +38755,11 @@ var ts; var symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) { switch (node.kind) { - case 67: - case 164: - case 133: + case 69: + case 166: + case 135: + case 97: case 95: - case 93: var type = typeChecker.getTypeAtLocation(node); if (type) { return { @@ -38215,7 +38808,7 @@ var ts; } return result; function tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) { - if (isNewExpressionTarget(location) || location.kind === 119) { + if (isNewExpressionTarget(location) || location.kind === 121) { if (symbol.flags & 32) { for (var _i = 0, _a = symbol.getDeclarations(); _i < _a.length; _i++) { var declaration = _a[_i]; @@ -38238,8 +38831,8 @@ var ts; var declarations = []; var definition; ts.forEach(signatureDeclarations, function (d) { - if ((selectConstructors && d.kind === 142) || - (!selectConstructors && (d.kind === 211 || d.kind === 141 || d.kind === 140))) { + if ((selectConstructors && d.kind === 144) || + (!selectConstructors && (d.kind === 213 || d.kind === 143 || d.kind === 142))) { declarations.push(d); if (d.body) definition = d; @@ -38290,11 +38883,11 @@ var ts; } if (symbol.flags & 8388608) { var declaration = symbol.declarations[0]; - if (node.kind === 67 && node.parent === declaration) { + if (node.kind === 69 && node.parent === declaration) { symbol = typeChecker.getAliasedSymbol(symbol); } } - if (node.parent.kind === 244) { + if (node.parent.kind === 246) { var shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); if (!shorthandSymbol) { return []; @@ -38365,9 +38958,9 @@ var ts; }; } function getSemanticDocumentHighlights(node) { - if (node.kind === 67 || + if (node.kind === 69 || + node.kind === 97 || node.kind === 95 || - node.kind === 93 || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { var referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, false, false); @@ -38416,77 +39009,77 @@ var ts; function getHighlightSpans(node) { if (node) { switch (node.kind) { - case 86: - case 78: - if (hasKind(node.parent, 194)) { + case 88: + case 80: + if (hasKind(node.parent, 196)) { return getIfElseOccurrences(node.parent); } break; - case 92: - if (hasKind(node.parent, 202)) { - return getReturnOccurrences(node.parent); - } - break; - case 96: - if (hasKind(node.parent, 206)) { - return getThrowOccurrences(node.parent); - } - break; - case 70: - if (hasKind(parent(parent(node)), 207)) { - return getTryCatchFinallyOccurrences(node.parent.parent); - } - break; - case 98: - case 83: - if (hasKind(parent(node), 207)) { - return getTryCatchFinallyOccurrences(node.parent); - } - break; case 94: if (hasKind(node.parent, 204)) { + return getReturnOccurrences(node.parent); + } + break; + case 98: + if (hasKind(node.parent, 208)) { + return getThrowOccurrences(node.parent); + } + break; + case 72: + if (hasKind(parent(parent(node)), 209)) { + return getTryCatchFinallyOccurrences(node.parent.parent); + } + break; + case 100: + case 85: + if (hasKind(parent(node), 209)) { + return getTryCatchFinallyOccurrences(node.parent); + } + break; + case 96: + if (hasKind(node.parent, 206)) { return getSwitchCaseDefaultOccurrences(node.parent); } break; - case 69: - case 75: - if (hasKind(parent(parent(parent(node))), 204)) { + case 71: + case 77: + if (hasKind(parent(parent(parent(node))), 206)) { return getSwitchCaseDefaultOccurrences(node.parent.parent.parent); } break; - case 68: - case 73: - if (hasKind(node.parent, 201) || hasKind(node.parent, 200)) { + case 70: + case 75: + if (hasKind(node.parent, 203) || hasKind(node.parent, 202)) { return getBreakOrContinueStatementOccurrences(node.parent); } break; - case 84: - if (hasKind(node.parent, 197) || - hasKind(node.parent, 198) || - hasKind(node.parent, 199)) { + case 86: + if (hasKind(node.parent, 199) || + hasKind(node.parent, 200) || + hasKind(node.parent, 201)) { return getLoopBreakContinueOccurrences(node.parent); } break; - case 102: - case 77: - if (hasKind(node.parent, 196) || hasKind(node.parent, 195)) { + case 104: + case 79: + if (hasKind(node.parent, 198) || hasKind(node.parent, 197)) { return getLoopBreakContinueOccurrences(node.parent); } break; - case 119: - if (hasKind(node.parent, 142)) { - return getConstructorOccurrences(node.parent); - } - break; case 121: - case 127: - if (hasKind(node.parent, 143) || hasKind(node.parent, 144)) { + if (hasKind(node.parent, 144)) { + return getConstructorOccurrences(node.parent); + } + break; + case 123: + case 129: + if (hasKind(node.parent, 145) || hasKind(node.parent, 146)) { return getGetAndSetOccurrences(node.parent); } break; default: if (ts.isModifier(node.kind) && node.parent && - (ts.isDeclaration(node.parent) || node.parent.kind === 191)) { + (ts.isDeclaration(node.parent) || node.parent.kind === 193)) { return getModifierOccurrences(node.kind, node.parent); } } @@ -38498,10 +39091,10 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 206) { + if (node.kind === 208) { statementAccumulator.push(node); } - else if (node.kind === 207) { + else if (node.kind === 209) { var tryStatement = node; if (tryStatement.catchClause) { aggregate(tryStatement.catchClause); @@ -38523,10 +39116,10 @@ var ts; var child = throwStatement; while (child.parent) { var parent_12 = child.parent; - if (ts.isFunctionBlock(parent_12) || parent_12.kind === 246) { + if (ts.isFunctionBlock(parent_12) || parent_12.kind === 248) { return parent_12; } - if (parent_12.kind === 207) { + if (parent_12.kind === 209) { var tryStatement = parent_12; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; @@ -38541,7 +39134,7 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 201 || node.kind === 200) { + if (node.kind === 203 || node.kind === 202) { statementAccumulator.push(node); } else if (!ts.isFunctionLike(node)) { @@ -38557,15 +39150,15 @@ var ts; function getBreakOrContinueOwner(statement) { for (var node_2 = statement.parent; node_2; node_2 = node_2.parent) { switch (node_2.kind) { - case 204: - if (statement.kind === 200) { + case 206: + if (statement.kind === 202) { continue; } - case 197: - case 198: case 199: - case 196: - case 195: + case 200: + case 201: + case 198: + case 197: if (!statement.label || isLabeledBy(node_2, statement.label.text)) { return node_2; } @@ -38582,24 +39175,24 @@ var ts; function getModifierOccurrences(modifier, declaration) { var container = declaration.parent; if (ts.isAccessibilityModifier(modifier)) { - if (!(container.kind === 212 || - container.kind === 184 || - (declaration.kind === 136 && hasKind(container, 142)))) { - return undefined; - } - } - else if (modifier === 111) { - if (!(container.kind === 212 || container.kind === 184)) { - return undefined; - } - } - else if (modifier === 80 || modifier === 120) { - if (!(container.kind === 217 || container.kind === 246)) { + if (!(container.kind === 214 || + container.kind === 186 || + (declaration.kind === 138 && hasKind(container, 144)))) { return undefined; } } else if (modifier === 113) { - if (!(container.kind === 212 || declaration.kind === 212)) { + if (!(container.kind === 214 || container.kind === 186)) { + return undefined; + } + } + else if (modifier === 82 || modifier === 122) { + if (!(container.kind === 219 || container.kind === 248)) { + return undefined; + } + } + else if (modifier === 115) { + if (!(container.kind === 214 || declaration.kind === 214)) { return undefined; } } @@ -38610,8 +39203,8 @@ var ts; var modifierFlag = getFlagFromModifier(modifier); var nodes; switch (container.kind) { - case 217: - case 246: + case 219: + case 248: if (modifierFlag & 256) { nodes = declaration.members.concat(declaration); } @@ -38619,15 +39212,15 @@ var ts; nodes = container.statements; } break; - case 142: + case 144: nodes = container.parameters.concat(container.parent.members); break; - case 212: - case 184: + case 214: + case 186: nodes = container.members; if (modifierFlag & 112) { var constructor = ts.forEach(container.members, function (member) { - return member.kind === 142 && member; + return member.kind === 144 && member; }); if (constructor) { nodes = nodes.concat(constructor.parameters); @@ -38648,19 +39241,19 @@ var ts; return ts.map(keywords, getHighlightSpanForNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 110: + case 112: return 16; - case 108: + case 110: return 32; - case 109: - return 64; case 111: - return 128; - case 80: - return 1; - case 120: - return 2; + return 64; case 113: + return 128; + case 82: + return 1; + case 122: + return 2; + case 115: return 256; default: ts.Debug.fail(); @@ -38680,13 +39273,13 @@ var ts; } function getGetAndSetOccurrences(accessorDeclaration) { var keywords = []; - tryPushAccessorKeyword(accessorDeclaration.symbol, 143); - tryPushAccessorKeyword(accessorDeclaration.symbol, 144); + tryPushAccessorKeyword(accessorDeclaration.symbol, 145); + tryPushAccessorKeyword(accessorDeclaration.symbol, 146); return ts.map(keywords, getHighlightSpanForNode); function tryPushAccessorKeyword(accessorSymbol, accessorKind) { var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { - ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 121, 127); }); + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 123, 129); }); } } } @@ -38695,18 +39288,18 @@ var ts; var keywords = []; ts.forEach(declarations, function (declaration) { ts.forEach(declaration.getChildren(), function (token) { - return pushKeywordIf(keywords, token, 119); + return pushKeywordIf(keywords, token, 121); }); }); return ts.map(keywords, getHighlightSpanForNode); } function getLoopBreakContinueOccurrences(loopNode) { var keywords = []; - if (pushKeywordIf(keywords, loopNode.getFirstToken(), 84, 102, 77)) { - if (loopNode.kind === 195) { + if (pushKeywordIf(keywords, loopNode.getFirstToken(), 86, 104, 79)) { + if (loopNode.kind === 197) { var loopTokens = loopNode.getChildren(); for (var i = loopTokens.length - 1; i >= 0; i--) { - if (pushKeywordIf(keywords, loopTokens[i], 102)) { + if (pushKeywordIf(keywords, loopTokens[i], 104)) { break; } } @@ -38715,7 +39308,7 @@ var ts; var breaksAndContinues = aggregateAllBreakAndContinueStatements(loopNode.statement); ts.forEach(breaksAndContinues, function (statement) { if (ownsBreakOrContinueStatement(loopNode, statement)) { - pushKeywordIf(keywords, statement.getFirstToken(), 68, 73); + pushKeywordIf(keywords, statement.getFirstToken(), 70, 75); } }); return ts.map(keywords, getHighlightSpanForNode); @@ -38724,13 +39317,13 @@ var ts; var owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { + case 199: + case 200: + case 201: case 197: case 198: - case 199: - case 195: - case 196: return getLoopBreakContinueOccurrences(owner); - case 204: + case 206: return getSwitchCaseDefaultOccurrences(owner); } } @@ -38738,13 +39331,13 @@ var ts; } function getSwitchCaseDefaultOccurrences(switchStatement) { var keywords = []; - pushKeywordIf(keywords, switchStatement.getFirstToken(), 94); + pushKeywordIf(keywords, switchStatement.getFirstToken(), 96); ts.forEach(switchStatement.caseBlock.clauses, function (clause) { - pushKeywordIf(keywords, clause.getFirstToken(), 69, 75); + pushKeywordIf(keywords, clause.getFirstToken(), 71, 77); var breaksAndContinues = aggregateAllBreakAndContinueStatements(clause); ts.forEach(breaksAndContinues, function (statement) { if (ownsBreakOrContinueStatement(switchStatement, statement)) { - pushKeywordIf(keywords, statement.getFirstToken(), 68); + pushKeywordIf(keywords, statement.getFirstToken(), 70); } }); }); @@ -38752,13 +39345,13 @@ var ts; } function getTryCatchFinallyOccurrences(tryStatement) { var keywords = []; - pushKeywordIf(keywords, tryStatement.getFirstToken(), 98); + pushKeywordIf(keywords, tryStatement.getFirstToken(), 100); if (tryStatement.catchClause) { - pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), 70); + pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), 72); } if (tryStatement.finallyBlock) { - var finallyKeyword = ts.findChildOfKind(tryStatement, 83, sourceFile); - pushKeywordIf(keywords, finallyKeyword, 83); + var finallyKeyword = ts.findChildOfKind(tryStatement, 85, sourceFile); + pushKeywordIf(keywords, finallyKeyword, 85); } return ts.map(keywords, getHighlightSpanForNode); } @@ -38769,50 +39362,50 @@ var ts; } var keywords = []; ts.forEach(aggregateOwnedThrowStatements(owner), function (throwStatement) { - pushKeywordIf(keywords, throwStatement.getFirstToken(), 96); + pushKeywordIf(keywords, throwStatement.getFirstToken(), 98); }); if (ts.isFunctionBlock(owner)) { ts.forEachReturnStatement(owner, function (returnStatement) { - pushKeywordIf(keywords, returnStatement.getFirstToken(), 92); + pushKeywordIf(keywords, returnStatement.getFirstToken(), 94); }); } return ts.map(keywords, getHighlightSpanForNode); } function getReturnOccurrences(returnStatement) { var func = ts.getContainingFunction(returnStatement); - if (!(func && hasKind(func.body, 190))) { + if (!(func && hasKind(func.body, 192))) { return undefined; } var keywords = []; ts.forEachReturnStatement(func.body, function (returnStatement) { - pushKeywordIf(keywords, returnStatement.getFirstToken(), 92); + pushKeywordIf(keywords, returnStatement.getFirstToken(), 94); }); ts.forEach(aggregateOwnedThrowStatements(func.body), function (throwStatement) { - pushKeywordIf(keywords, throwStatement.getFirstToken(), 96); + pushKeywordIf(keywords, throwStatement.getFirstToken(), 98); }); return ts.map(keywords, getHighlightSpanForNode); } function getIfElseOccurrences(ifStatement) { var keywords = []; - while (hasKind(ifStatement.parent, 194) && ifStatement.parent.elseStatement === ifStatement) { + while (hasKind(ifStatement.parent, 196) && ifStatement.parent.elseStatement === ifStatement) { ifStatement = ifStatement.parent; } while (ifStatement) { var children = ifStatement.getChildren(); - pushKeywordIf(keywords, children[0], 86); + pushKeywordIf(keywords, children[0], 88); for (var i = children.length - 1; i >= 0; i--) { - if (pushKeywordIf(keywords, children[i], 78)) { + if (pushKeywordIf(keywords, children[i], 80)) { break; } } - if (!hasKind(ifStatement.elseStatement, 194)) { + if (!hasKind(ifStatement.elseStatement, 196)) { break; } ifStatement = ifStatement.elseStatement; } var result = []; for (var i = 0; i < keywords.length; i++) { - if (keywords[i].kind === 78 && i < keywords.length - 1) { + if (keywords[i].kind === 80 && i < keywords.length - 1) { var elseKeyword = keywords[i]; var ifKeyword = keywords[i + 1]; var shouldCombindElseAndIf = true; @@ -38890,12 +39483,12 @@ var ts; if (!node) { return undefined; } - if (node.kind !== 67 && + if (node.kind !== 69 && !isLiteralNameOfPropertyDeclarationOrIndexAccess(node) && !isNameOfExternalModuleImportOrDeclaration(node)) { return undefined; } - ts.Debug.assert(node.kind === 67 || node.kind === 8 || node.kind === 9); + ts.Debug.assert(node.kind === 69 || node.kind === 8 || node.kind === 9); return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNode(node, sourceFiles, findInStrings, findInComments) { @@ -38909,10 +39502,10 @@ var ts; return getLabelReferencesInNode(node.parent, node); } } - if (node.kind === 95) { + if (node.kind === 97) { return getReferencesForThisKeyword(node, sourceFiles); } - if (node.kind === 93) { + if (node.kind === 95) { return getReferencesForSuperKeyword(node); } var symbol = typeChecker.getSymbolAtLocation(node); @@ -38963,7 +39556,7 @@ var ts; } function isImportOrExportSpecifierImportSymbol(symbol) { return (symbol.flags & 8388608) && ts.forEach(symbol.declarations, function (declaration) { - return declaration.kind === 224 || declaration.kind === 228; + return declaration.kind === 226 || declaration.kind === 230; }); } function getInternedName(symbol, location, declarations) { @@ -38976,13 +39569,13 @@ var ts; } function getSymbolScope(symbol) { var valueDeclaration = symbol.valueDeclaration; - if (valueDeclaration && (valueDeclaration.kind === 171 || valueDeclaration.kind === 184)) { + if (valueDeclaration && (valueDeclaration.kind === 173 || valueDeclaration.kind === 186)) { return valueDeclaration; } if (symbol.flags & (4 | 8192)) { var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32) ? d : undefined; }); if (privateDeclaration) { - return ts.getAncestor(privateDeclaration, 212); + return ts.getAncestor(privateDeclaration, 214); } } if (symbol.flags & 8388608) { @@ -39003,7 +39596,7 @@ var ts; if (scope && scope !== container) { return undefined; } - if (container.kind === 246 && !ts.isExternalModule(container)) { + if (container.kind === 248 && !ts.isExternalModule(container)) { return undefined; } scope = container; @@ -39062,7 +39655,7 @@ var ts; function isValidReferencePosition(node, searchSymbolName) { if (node) { switch (node.kind) { - case 67: + case 69: return node.getWidth() === searchSymbolName.length; case 9: if (isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || @@ -39150,13 +39743,13 @@ var ts; } var staticFlag = 128; switch (searchSpaceNode.kind) { - case 139: - case 138: case 141: case 140: - case 142: case 143: + case 142: case 144: + case 145: + case 146: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; break; @@ -39169,7 +39762,7 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || node.kind !== 93) { + if (!node || node.kind !== 95) { return; } var container = ts.getSuperContainer(node, false); @@ -39184,32 +39777,32 @@ var ts; var searchSpaceNode = ts.getThisContainer(thisOrSuperKeyword, false); var staticFlag = 128; switch (searchSpaceNode.kind) { - case 141: - case 140: + case 143: + case 142: if (ts.isObjectLiteralMethod(searchSpaceNode)) { break; } - case 139: - case 138: - case 142: - case 143: + case 141: + case 140: case 144: + case 145: + case 146: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; break; - case 246: + case 248: if (ts.isExternalModule(searchSpaceNode)) { return undefined; } - case 211: - case 171: + case 213: + case 173: break; default: return undefined; } var references = []; var possiblePositions; - if (searchSpaceNode.kind === 246) { + if (searchSpaceNode.kind === 248) { ts.forEach(sourceFiles, function (sourceFile) { possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, references); @@ -39235,31 +39828,31 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || node.kind !== 95) { + if (!node || node.kind !== 97) { return; } var container = ts.getThisContainer(node, false); switch (searchSpaceNode.kind) { - case 171: - case 211: + case 173: + case 213: if (searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 141: - case 140: + case 143: + case 142: if (ts.isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 184: - case 212: + case 186: + case 214: if (container.parent && searchSpaceNode.symbol === container.parent.symbol && (container.flags & 128) === staticFlag) { result.push(getReferenceEntryFromNode(node)); } break; - case 246: - if (container.kind === 246 && !ts.isExternalModule(container)) { + case 248: + if (container.kind === 248 && !ts.isExternalModule(container)) { result.push(getReferenceEntryFromNode(node)); } break; @@ -39294,11 +39887,11 @@ var ts; function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) { if (symbol && symbol.flags & (32 | 64)) { ts.forEach(symbol.getDeclarations(), function (declaration) { - if (declaration.kind === 212) { + if (declaration.kind === 214) { getPropertySymbolFromTypeReference(ts.getClassExtendsHeritageClauseElement(declaration)); ts.forEach(ts.getClassImplementsHeritageClauseElements(declaration), getPropertySymbolFromTypeReference); } - else if (declaration.kind === 213) { + else if (declaration.kind === 215) { ts.forEach(ts.getInterfaceBaseTypeNodes(declaration), getPropertySymbolFromTypeReference); } }); @@ -39348,17 +39941,17 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_33 = node.text; + var name_34 = node.text; if (contextualType) { if (contextualType.flags & 16384) { - var unionProperty = contextualType.getProperty(name_33); + var unionProperty = contextualType.getProperty(name_34); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_33); + var symbol = t.getProperty(name_34); if (symbol) { result_4.push(symbol); } @@ -39367,7 +39960,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_33); + var symbol_1 = contextualType.getProperty(name_34); if (symbol_1) { return [symbol_1]; } @@ -39407,17 +40000,17 @@ var ts; }; } function isWriteAccess(node) { - if (node.kind === 67 && ts.isDeclarationName(node)) { + if (node.kind === 69 && ts.isDeclarationName(node)) { return true; } var parent = node.parent; if (parent) { - if (parent.kind === 178 || parent.kind === 177) { + if (parent.kind === 180 || parent.kind === 179) { return true; } - else if (parent.kind === 179 && parent.left === node) { + else if (parent.kind === 181 && parent.left === node) { var operator = parent.operatorToken.kind; - return 55 <= operator && operator <= 66; + return 56 <= operator && operator <= 68; } } return false; @@ -39448,33 +40041,33 @@ var ts; } function getMeaningFromDeclaration(node) { switch (node.kind) { - case 136: - case 209: - case 161: - case 139: case 138: - case 243: - case 244: - case 245: + case 211: + case 163: case 141: case 140: - case 142: + case 245: + case 246: + case 247: case 143: + case 142: case 144: - case 211: - case 171: - case 172: - case 242: - return 1; - case 135: + case 145: + case 146: case 213: - case 214: - case 153: - return 2; - case 212: + case 173: + case 174: + case 244: + return 1; + case 137: case 215: - return 1 | 2; case 216: + case 155: + return 2; + case 214: + case 217: + return 1 | 2; + case 218: if (node.name.kind === 9) { return 4 | 1; } @@ -39484,14 +40077,14 @@ var ts; else { return 4; } - case 223: - case 224: - case 219: - case 220: case 225: case 226: + case 221: + case 222: + case 227: + case 228: return 1 | 2 | 4; - case 246: + case 248: return 4 | 1; } return 1 | 2 | 4; @@ -39501,8 +40094,9 @@ var ts; if (ts.isRightSideOfQualifiedNameOrPropertyAccess(node)) { node = node.parent; } - return node.parent.kind === 149 || - (node.parent.kind === 186 && !ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent)); + return node.parent.kind === 151 || + (node.parent.kind === 188 && !ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent)) || + node.kind === 97 && !ts.isExpression(node); } function isNamespaceReference(node) { return isQualifiedNameNamespaceReference(node) || isPropertyAccessNamespaceReference(node); @@ -39510,47 +40104,47 @@ var ts; function isPropertyAccessNamespaceReference(node) { var root = node; var isLastClause = true; - if (root.parent.kind === 164) { - while (root.parent && root.parent.kind === 164) { + if (root.parent.kind === 166) { + while (root.parent && root.parent.kind === 166) { root = root.parent; } isLastClause = root.name === node; } - if (!isLastClause && root.parent.kind === 186 && root.parent.parent.kind === 241) { + if (!isLastClause && root.parent.kind === 188 && root.parent.parent.kind === 243) { var decl = root.parent.parent.parent; - return (decl.kind === 212 && root.parent.parent.token === 104) || - (decl.kind === 213 && root.parent.parent.token === 81); + return (decl.kind === 214 && root.parent.parent.token === 106) || + (decl.kind === 215 && root.parent.parent.token === 83); } return false; } function isQualifiedNameNamespaceReference(node) { var root = node; var isLastClause = true; - if (root.parent.kind === 133) { - while (root.parent && root.parent.kind === 133) { + if (root.parent.kind === 135) { + while (root.parent && root.parent.kind === 135) { root = root.parent; } isLastClause = root.right === node; } - return root.parent.kind === 149 && !isLastClause; + return root.parent.kind === 151 && !isLastClause; } function isInRightSideOfImport(node) { - while (node.parent.kind === 133) { + while (node.parent.kind === 135) { node = node.parent; } return ts.isInternalModuleImportEqualsDeclaration(node.parent) && node.parent.moduleReference === node; } function getMeaningFromRightHandSideOfImportEquals(node) { - ts.Debug.assert(node.kind === 67); - if (node.parent.kind === 133 && + ts.Debug.assert(node.kind === 69); + if (node.parent.kind === 135 && node.parent.right === node && - node.parent.parent.kind === 219) { + node.parent.parent.kind === 221) { return 1 | 2 | 4; } return 4; } function getMeaningFromLocation(node) { - if (node.parent.kind === 225) { + if (node.parent.kind === 227) { return 1 | 2 | 4; } else if (isInRightSideOfImport(node)) { @@ -39584,15 +40178,15 @@ var ts; return; } switch (node.kind) { - case 164: - case 133: + case 166: + case 135: case 9: - case 82: - case 97: - case 91: + case 84: + case 99: case 93: case 95: - case 67: + case 97: + case 69: break; default: return; @@ -39603,7 +40197,7 @@ var ts; nodeForStartPos = nodeForStartPos.parent; } else if (isNameOfModuleDeclaration(nodeForStartPos)) { - if (nodeForStartPos.parent.parent.kind === 216 && + if (nodeForStartPos.parent.parent.kind === 218 && nodeForStartPos.parent.parent.body === nodeForStartPos.parent) { nodeForStartPos = nodeForStartPos.parent.parent.name; } @@ -39630,10 +40224,10 @@ var ts; } function checkForClassificationCancellation(kind) { switch (kind) { - case 216: - case 212: + case 218: + case 214: + case 215: case 213: - case 211: cancellationToken.throwIfCancellationRequested(); } } @@ -39681,7 +40275,7 @@ var ts; return undefined; function hasValueSideModule(symbol) { return ts.forEach(symbol.declarations, function (declaration) { - return declaration.kind === 216 && + return declaration.kind === 218 && ts.getModuleInstanceState(declaration) === 1; }); } @@ -39690,7 +40284,7 @@ var ts; if (node && ts.textSpanIntersectsWith(span, node.getFullStart(), node.getFullWidth())) { var kind = node.kind; checkForClassificationCancellation(kind); - if (kind === 67 && !ts.nodeIsMissing(node)) { + if (kind === 69 && !ts.nodeIsMissing(node)) { var identifier = node; if (classifiableNames[identifier.text]) { var symbol = typeChecker.getSymbolAtLocation(node); @@ -39814,16 +40408,16 @@ var ts; pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, 18); pos = tag.tagName.end; switch (tag.kind) { - case 265: + case 267: processJSDocParameterTag(tag); break; - case 268: + case 270: processJSDocTemplateTag(tag); break; - case 267: + case 269: processElement(tag.typeExpression); break; - case 266: + case 268: processElement(tag.typeExpression); break; } @@ -39903,17 +40497,17 @@ var ts; } if (ts.isPunctuation(tokenKind)) { if (token) { - if (tokenKind === 55) { - if (token.parent.kind === 209 || - token.parent.kind === 139 || - token.parent.kind === 136) { + if (tokenKind === 56) { + if (token.parent.kind === 211 || + token.parent.kind === 141 || + token.parent.kind === 138) { return 5; } } - if (token.parent.kind === 179 || - token.parent.kind === 177 || - token.parent.kind === 178 || - token.parent.kind === 180) { + if (token.parent.kind === 181 || + token.parent.kind === 179 || + token.parent.kind === 180 || + token.parent.kind === 182) { return 5; } } @@ -39931,35 +40525,35 @@ var ts; else if (ts.isTemplateLiteralKind(tokenKind)) { return 6; } - else if (tokenKind === 67) { + else if (tokenKind === 69) { if (token) { switch (token.parent.kind) { - case 212: + case 214: if (token.parent.name === token) { return 11; } return; - case 135: + case 137: if (token.parent.name === token) { return 15; } return; - case 213: + case 215: if (token.parent.name === token) { return 13; } return; - case 215: + case 217: if (token.parent.name === token) { return 12; } return; - case 216: + case 218: if (token.parent.name === token) { return 14; } return; - case 136: + case 138: if (token.parent.name === token) { return 17; } @@ -40073,19 +40667,40 @@ var ts; if (!tokenAtPos || tokenStart < position) { return undefined; } - var containingFunction = ts.getAncestor(tokenAtPos, 211); - if (!containingFunction || containingFunction.getStart() < position) { + var commentOwner; + findOwner: for (commentOwner = tokenAtPos; commentOwner; commentOwner = commentOwner.parent) { + switch (commentOwner.kind) { + case 213: + case 143: + case 144: + case 214: + case 193: + break findOwner; + case 248: + return undefined; + case 218: + if (commentOwner.parent.kind === 218) { + return undefined; + } + break findOwner; + } + } + if (!commentOwner || commentOwner.getStart() < position) { return undefined; } - var parameters = containingFunction.parameters; + var parameters = getParametersForJsDocOwningNode(commentOwner); var posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position); var lineStart = sourceFile.getLineStarts()[posLineAndChar.line]; var indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character); var newLine = host.getNewLine ? host.getNewLine() : "\r\n"; - var docParams = parameters.reduce(function (prev, cur, index) { - return prev + - indentationStr + " * @param " + (cur.name.kind === 67 ? cur.name.text : "param" + index) + newLine; - }, ""); + var docParams = ""; + for (var i = 0, numParams = parameters.length; i < numParams; i++) { + var currentName = parameters[i].name; + var paramName = currentName.kind === 69 ? + currentName.text : + "param" + i; + docParams += indentationStr + " * @param " + paramName + newLine; + } var preamble = "/**" + newLine + indentationStr + " * "; var result = preamble + newLine + @@ -40094,6 +40709,38 @@ var ts; (tokenStart === position ? newLine + indentationStr : ""); return { newText: result, caretOffset: preamble.length }; } + function getParametersForJsDocOwningNode(commentOwner) { + if (ts.isFunctionLike(commentOwner)) { + return commentOwner.parameters; + } + if (commentOwner.kind === 193) { + var varStatement = commentOwner; + var varDeclarations = varStatement.declarationList.declarations; + if (varDeclarations.length === 1 && varDeclarations[0].initializer) { + return getParametersFromRightHandSideOfAssignment(varDeclarations[0].initializer); + } + } + return emptyArray; + } + function getParametersFromRightHandSideOfAssignment(rightHandSide) { + while (rightHandSide.kind === 172) { + rightHandSide = rightHandSide.expression; + } + switch (rightHandSide.kind) { + case 173: + case 174: + return rightHandSide.parameters; + case 186: + for (var _i = 0, _a = rightHandSide.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 144) { + return member.parameters; + } + } + break; + } + return emptyArray; + } function getTodoComments(fileName, descriptors) { synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); @@ -40158,7 +40805,7 @@ var ts; var sourceFile = getValidSourceFile(fileName); var typeChecker = program.getTypeChecker(); var node = ts.getTouchingWord(sourceFile, position); - if (node && node.kind === 67) { + if (node && node.kind === 69) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { var declarations = symbol.getDeclarations(); @@ -40256,13 +40903,13 @@ var ts; sourceFile.nameTable = nameTable; function walk(node) { switch (node.kind) { - case 67: + case 69: nameTable[node.text] = node.text; break; case 9: case 8: if (ts.isDeclarationName(node) || - node.parent.kind === 230 || + node.parent.kind === 232 || isArgumentOfElementAccessExpression(node)) { nameTable[node.text] = node.text; } @@ -40275,31 +40922,31 @@ var ts; function isArgumentOfElementAccessExpression(node) { return node && node.parent && - node.parent.kind === 165 && + node.parent.kind === 167 && node.parent.argumentExpression === node; } function createClassifier() { var scanner = ts.createScanner(2, false); var noRegexTable = []; - noRegexTable[67] = true; + noRegexTable[69] = true; noRegexTable[9] = true; noRegexTable[8] = true; noRegexTable[10] = true; - noRegexTable[95] = true; - noRegexTable[40] = true; + noRegexTable[97] = true; noRegexTable[41] = true; + noRegexTable[42] = true; noRegexTable[18] = true; noRegexTable[20] = true; noRegexTable[16] = true; - noRegexTable[97] = true; - noRegexTable[82] = true; + noRegexTable[99] = true; + noRegexTable[84] = true; var templateStack = []; function canFollow(keyword1, keyword2) { if (ts.isAccessibilityModifier(keyword1)) { - if (keyword2 === 121 || - keyword2 === 127 || - keyword2 === 119 || - keyword2 === 111) { + if (keyword2 === 123 || + keyword2 === 129 || + keyword2 === 121 || + keyword2 === 113) { return true; } return false; @@ -40394,31 +41041,31 @@ var ts; do { token = scanner.scan(); if (!ts.isTrivia(token)) { - if ((token === 38 || token === 59) && !noRegexTable[lastNonTriviaToken]) { + if ((token === 39 || token === 61) && !noRegexTable[lastNonTriviaToken]) { if (scanner.reScanSlashToken() === 10) { token = 10; } } else if (lastNonTriviaToken === 21 && isKeyword(token)) { - token = 67; + token = 69; } else if (isKeyword(lastNonTriviaToken) && isKeyword(token) && !canFollow(lastNonTriviaToken, token)) { - token = 67; + token = 69; } - else if (lastNonTriviaToken === 67 && + else if (lastNonTriviaToken === 69 && token === 25) { angleBracketStack++; } else if (token === 27 && angleBracketStack > 0) { angleBracketStack--; } - else if (token === 115 || + else if (token === 117 || + token === 130 || token === 128 || - token === 126 || - token === 118 || - token === 129) { + token === 120 || + token === 131) { if (angleBracketStack > 0 && !syntacticClassifierAbsent) { - token = 67; + token = 69; } } else if (token === 12) { @@ -40516,40 +41163,41 @@ var ts; function isBinaryExpressionOperatorToken(token) { switch (token) { case 37: - case 38: case 39: + case 40: case 35: case 36: - case 42: case 43: case 44: + case 45: case 25: case 27: case 28: case 29: - case 89: - case 88: + case 91: + case 90: + case 116: case 30: case 31: case 32: case 33: - case 45: - case 47: case 46: - case 50: + case 48: + case 47: case 51: - case 65: - case 64: + case 52: + case 67: case 66: - case 61: - case 62: + case 68: case 63: - case 56: + case 64: + case 65: case 57: case 58: case 59: - case 60: - case 55: + case 61: + case 62: + case 56: case 24: return true; default: @@ -40560,17 +41208,17 @@ var ts; switch (token) { case 35: case 36: + case 50: case 49: - case 48: - case 40: case 41: + case 42: return true; default: return false; } } function isKeyword(token) { - return token >= 68 && token <= 132; + return token >= 70 && token <= 134; } function classFromKind(token) { if (isKeyword(token)) { @@ -40579,7 +41227,7 @@ var ts; else if (isBinaryExpressionOperatorToken(token) || isPrefixUnaryExpressionOperatorToken(token)) { return 5; } - else if (token >= 15 && token <= 66) { + else if (token >= 15 && token <= 68) { return 10; } switch (token) { @@ -40596,7 +41244,7 @@ var ts; case 5: case 4: return 8; - case 67: + case 69: default: if (ts.isTemplateLiteralKind(token)) { return 6; @@ -40622,7 +41270,7 @@ var ts; getNodeConstructor: function (kind) { function Node() { } - var proto = kind === 246 ? new SourceFileObject() : new NodeObject(); + var proto = kind === 248 ? new SourceFileObject() : new NodeObject(); proto.kind = kind; proto.pos = -1; proto.end = -1; @@ -40654,6 +41302,22 @@ var ts; return spaceCache[n]; } server.generateSpaces = generateSpaces; + function generateIndentString(n, editorOptions) { + if (editorOptions.ConvertTabsToSpaces) { + return generateSpaces(n); + } + else { + var result = ""; + for (var i = 0; i < Math.floor(n / editorOptions.TabSize); i++) { + result += "\t"; + } + for (var i = 0; i < n % editorOptions.TabSize; i++) { + result += " "; + } + return result; + } + } + server.generateIndentString = generateIndentString; function compareNumber(a, b) { if (a < b) { return -1; @@ -41265,28 +41929,27 @@ var ts; IndentSize: formatOptions.IndentSize, TabSize: formatOptions.TabSize, NewLineCharacter: "\n", - ConvertTabsToSpaces: formatOptions.ConvertTabsToSpaces + ConvertTabsToSpaces: formatOptions.ConvertTabsToSpaces, + IndentStyle: ts.IndentStyle.Smart }; - var indentPosition = compilerService.languageService.getIndentationAtPosition(file, position, editorOptions); + var preferredIndent = compilerService.languageService.getIndentationAtPosition(file, position, editorOptions); + var hasIndent = 0; for (var i = 0, len = lineText.length; i < len; i++) { if (lineText.charAt(i) == " ") { - indentPosition--; + hasIndent++; } else if (lineText.charAt(i) == "\t") { - indentPosition -= editorOptions.IndentSize; + hasIndent += editorOptions.TabSize; } else { break; } } - if (indentPosition > 0) { - var spaces = generateSpaces(indentPosition); - edits.push({ span: ts.createTextSpanFromBounds(position, position), newText: spaces }); - } - else if (indentPosition < 0) { + if (preferredIndent !== hasIndent) { + var firstNoWhiteSpacePosition = lineInfo.offset + i; edits.push({ - span: ts.createTextSpanFromBounds(position, position - indentPosition), - newText: "" + span: ts.createTextSpanFromBounds(lineInfo.offset, firstNoWhiteSpacePosition), + newText: generateIndentString(preferredIndent, editorOptions) }); } } @@ -41418,6 +42081,9 @@ var ts; } }; Session.prototype.closeClientFile = function (fileName) { + if (!fileName) { + return; + } var file = ts.normalizePath(fileName); this.projectService.closeClientFile(file); }; @@ -41774,6 +42440,7 @@ var ts; if (scriptInfo) { this.filenameToScript[info.fileName] = undefined; this.roots = copyListRemovingItem(info, this.roots); + this.resolvedModuleNames.remove(info.fileName); } }; LSHost.prototype.saveTo = function (filename, tmpfilename) { @@ -41867,6 +42534,7 @@ var ts; function Project(projectService, projectOptions) { this.projectService = projectService; this.projectOptions = projectOptions; + this.directoriesWatchedForTsconfig = []; this.filenameToSourceFile = {}; this.updateGraphSeq = 0; this.openRefCount = 0; @@ -41882,6 +42550,9 @@ var ts; Project.prototype.openReferencedFile = function (filename) { return this.projectService.openFile(filename, false); }; + Project.prototype.getRootFiles = function () { + return this.compilerService.host.roots.map(function (info) { return info.fileName; }); + }; Project.prototype.getFileNames = function () { var sourceFiles = this.program.getSourceFiles(); return sourceFiles.map(function (sourceFile) { return sourceFile.fileName; }); @@ -41924,11 +42595,9 @@ var ts; return this.projectFilename; }; Project.prototype.addRoot = function (info) { - info.defaultProject = this; this.compilerService.host.addRoot(info); }; Project.prototype.removeRoot = function (info) { - info.defaultProject = undefined; this.compilerService.host.removeRoot(info); }; Project.prototype.filesToString = function () { @@ -41965,6 +42634,9 @@ var ts; this.configuredProjects = []; this.openFilesReferenced = []; this.openFileRootsConfigured = []; + this.directoryWatchersForTsconfig = {}; + this.directoryWatchersRefCount = {}; + this.timerForDetectingProjectFilelistChanges = {}; this.addDefaultHostConfiguration(); } ProjectService.prototype.addDefaultHostConfiguration = function () { @@ -41996,8 +42668,54 @@ var ts; } } }; + ProjectService.prototype.directoryWatchedForSourceFilesChanged = function (project, fileName) { + if (fileName && !ts.isSupportedSourceFileName(fileName)) { + return; + } + this.log("Detected source file changes: " + fileName); + this.startTimerForDetectingProjectFilelistChanges(project); + }; + ProjectService.prototype.startTimerForDetectingProjectFilelistChanges = function (project) { + var _this = this; + if (this.timerForDetectingProjectFilelistChanges[project.projectFilename]) { + clearTimeout(this.timerForDetectingProjectFilelistChanges[project.projectFilename]); + } + this.timerForDetectingProjectFilelistChanges[project.projectFilename] = setTimeout(function () { return _this.handleProjectFilelistChanges(project); }, 250); + }; + ProjectService.prototype.handleProjectFilelistChanges = function (project) { + var _this = this; + var _a = this.configFileToProjectOptions(project.projectFilename), succeeded = _a.succeeded, projectOptions = _a.projectOptions, error = _a.error; + var newRootFiles = projectOptions.files.map((function (f) { return _this.getCanonicalFileName(f); })); + var currentRootFiles = project.getRootFiles().map((function (f) { return _this.getCanonicalFileName(f); })); + if (!ts.arrayStructurallyIsEqualTo(currentRootFiles, newRootFiles)) { + this.updateConfiguredProject(project); + this.updateProjectStructure(); + } + }; + ProjectService.prototype.directoryWatchedForTsconfigChanged = function (fileName) { + var _this = this; + if (ts.getBaseFileName(fileName) != "tsconfig.json") { + this.log(fileName + " is not tsconfig.json"); + return; + } + this.log("Detected newly added tsconfig file: " + fileName); + var _a = this.configFileToProjectOptions(fileName), succeeded = _a.succeeded, projectOptions = _a.projectOptions, error = _a.error; + var rootFilesInTsconfig = projectOptions.files.map(function (f) { return _this.getCanonicalFileName(f); }); + var openFileRoots = this.openFileRoots.map(function (s) { return _this.getCanonicalFileName(s.fileName); }); + for (var _i = 0; _i < openFileRoots.length; _i++) { + var openFileRoot = openFileRoots[_i]; + if (rootFilesInTsconfig.indexOf(openFileRoot) >= 0) { + this.reloadProjects(); + return; + } + } + }; + ProjectService.prototype.getCanonicalFileName = function (fileName) { + var name = this.host.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); + return ts.normalizePath(name); + }; ProjectService.prototype.watchedProjectConfigFileChanged = function (project) { - this.log("Config File Changed: " + project.projectFilename); + this.log("Config file changed: " + project.projectFilename); this.updateConfiguredProject(project); this.updateProjectStructure(); }; @@ -42028,11 +42746,28 @@ var ts; this.psLogger.close(); }; ProjectService.prototype.createInferredProject = function (root) { - var iproj = new Project(this); - iproj.addRoot(root); - iproj.finishGraph(); - this.inferredProjects.push(iproj); - return iproj; + var _this = this; + var project = new Project(this); + project.addRoot(root); + var currentPath = ts.getDirectoryPath(root.fileName); + var parentPath = ts.getDirectoryPath(currentPath); + while (currentPath != parentPath) { + if (!project.projectService.directoryWatchersForTsconfig[currentPath]) { + this.log("Add watcher for: " + currentPath); + project.projectService.directoryWatchersForTsconfig[currentPath] = + this.host.watchDirectory(currentPath, function (fileName) { return _this.directoryWatchedForTsconfigChanged(fileName); }); + project.projectService.directoryWatchersRefCount[currentPath] = 1; + } + else { + project.projectService.directoryWatchersRefCount[currentPath] += 1; + } + project.directoriesWatchedForTsconfig.push(currentPath); + currentPath = parentPath; + parentPath = ts.getDirectoryPath(parentPath); + } + project.finishGraph(); + this.inferredProjects.push(project); + return project; }; ProjectService.prototype.fileDeletedInFilesystem = function (info) { this.psLogger.info(info.fileName + " deleted"); @@ -42043,6 +42778,9 @@ var ts; if (!info.isOpen) { this.filenameToScriptInfo[info.fileName] = undefined; var referencingProjects = this.findReferencingProjects(info); + if (info.defaultProject) { + info.defaultProject.removeRoot(info); + } for (var i = 0, len = referencingProjects.length; i < len; i++) { referencingProjects[i].removeReferencedFile(info); } @@ -42070,12 +42808,27 @@ var ts; } this.configuredProjects = configuredProjects; }; - ProjectService.prototype.removeConfiguredProject = function (project) { - project.projectFileWatcher.close(); - this.configuredProjects = copyListRemovingItem(project, this.configuredProjects); + ProjectService.prototype.removeProject = function (project) { + this.log("remove project: " + project.getRootFiles().toString()); + if (project.isConfiguredProject()) { + project.projectFileWatcher.close(); + project.directoryWatcher.close(); + this.configuredProjects = copyListRemovingItem(project, this.configuredProjects); + } + else { + for (var _i = 0, _a = project.directoriesWatchedForTsconfig; _i < _a.length; _i++) { + var directory = _a[_i]; + if (!(--project.projectService.directoryWatchersRefCount[directory])) { + this.log("Close directory watcher for: " + directory); + project.projectService.directoryWatchersForTsconfig[directory].close(); + delete project.projectService.directoryWatchersForTsconfig[directory]; + } + } + this.inferredProjects = copyListRemovingItem(project, this.inferredProjects); + } var fileNames = project.getFileNames(); - for (var _i = 0; _i < fileNames.length; _i++) { - var fileName = fileNames[_i]; + for (var _b = 0; _b < fileNames.length; _b++) { + var fileName = fileNames[_b]; var info = this.getScriptInfo(fileName); if (info.defaultProject == project) { info.defaultProject = undefined; @@ -42108,8 +42861,7 @@ var ts; for (var i = 0, len = this.openFileRoots.length; i < len; i++) { var r = this.openFileRoots[i]; if (info.defaultProject.getSourceFile(r)) { - this.inferredProjects = - copyListRemovingItem(r.defaultProject, this.inferredProjects); + this.removeProject(r.defaultProject); this.openFilesReferenced.push(r); r.defaultProject = info.defaultProject; } @@ -42124,6 +42876,7 @@ var ts; this.updateConfiguredProjectList(); }; ProjectService.prototype.closeOpenFile = function (info) { + info.svc.reloadFromFile(info.fileName); var openFileRoots = []; var removedProject; for (var i = 0, len = this.openFileRoots.length; i < len; i++) { @@ -42150,17 +42903,12 @@ var ts; this.openFileRootsConfigured = openFileRootsConfigured; } if (removedProject) { - if (removedProject.isConfiguredProject()) { - this.configuredProjects = copyListRemovingItem(removedProject, this.configuredProjects); - } - else { - this.inferredProjects = copyListRemovingItem(removedProject, this.inferredProjects); - } + this.removeProject(removedProject); var openFilesReferenced = []; var orphanFiles = []; for (var i = 0, len = this.openFilesReferenced.length; i < len; i++) { var f = this.openFilesReferenced[i]; - if (f.defaultProject === removedProject) { + if (f.defaultProject === removedProject || !f.defaultProject) { f.defaultProject = undefined; orphanFiles.push(f); } @@ -42201,6 +42949,7 @@ var ts; return referencingProjects; }; ProjectService.prototype.reloadProjects = function () { + this.log("reload projects."); for (var _i = 0, _a = this.openFileRoots; _i < _a.length; _i++) { var info = _a[_i]; this.openOrUpdateConfiguredProjectForFile(info.fileName); @@ -42242,13 +42991,21 @@ var ts; var rootFile = this.openFileRoots[i]; var rootedProject = rootFile.defaultProject; var referencingProjects = this.findReferencingProjects(rootFile, rootedProject); - if (referencingProjects.length === 0) { - rootFile.defaultProject = rootedProject; - openFileRoots.push(rootFile); + if (rootFile.defaultProject && rootFile.defaultProject.isConfiguredProject()) { + if (!rootedProject.isConfiguredProject()) { + this.removeProject(rootedProject); + } + this.openFileRootsConfigured.push(rootFile); } else { - this.inferredProjects = copyListRemovingItem(rootedProject, this.inferredProjects); - this.openFilesReferenced.push(rootFile); + if (referencingProjects.length === 0) { + rootFile.defaultProject = rootedProject; + openFileRoots.push(rootFile); + } + else { + this.removeProject(rootedProject); + this.openFilesReferenced.push(rootFile); + } } } this.openFileRoots = openFileRoots; @@ -42419,12 +43176,12 @@ var ts; configFilename = ts.normalizePath(configFilename); var dirPath = ts.getDirectoryPath(configFilename); var contents = this.host.readFile(configFilename); - var rawConfig = ts.parseConfigFileText(configFilename, contents); + var rawConfig = ts.parseConfigFileTextToJson(configFilename, contents); if (rawConfig.error) { return { succeeded: false, error: rawConfig.error }; } else { - var parsedCommandLine = ts.parseConfigFile(rawConfig.config, this.host, dirPath); + var parsedCommandLine = ts.parseJsonConfigFileContent(rawConfig.config, this.host, dirPath); if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) { return { succeeded: false, error: { errorMsg: "tsconfig option errors" } }; } @@ -42447,26 +43204,28 @@ var ts; return error; } else { - var proj = this.createProject(configFilename, projectOptions); - for (var i = 0, len = projectOptions.files.length; i < len; i++) { - var rootFilename = projectOptions.files[i]; + var project = this.createProject(configFilename, projectOptions); + for (var _i = 0, _b = projectOptions.files; _i < _b.length; _i++) { + var rootFilename = _b[_i]; if (this.host.fileExists(rootFilename)) { var info = this.openFile(rootFilename, clientFileName == rootFilename); - proj.addRoot(info); + project.addRoot(info); } else { return { errorMsg: "specified file " + rootFilename + " not found" }; } } - proj.finishGraph(); - proj.projectFileWatcher = this.host.watchFile(configFilename, function (_) { return _this.watchedProjectConfigFileChanged(proj); }); - return { success: true, project: proj }; + project.finishGraph(); + project.projectFileWatcher = this.host.watchFile(configFilename, function (_) { return _this.watchedProjectConfigFileChanged(project); }); + this.log("Add recursive watcher for: " + ts.getDirectoryPath(configFilename)); + project.directoryWatcher = this.host.watchDirectory(ts.getDirectoryPath(configFilename), function (path) { return _this.directoryWatchedForSourceFilesChanged(project, path); }, true); + return { success: true, project: project }; } }; ProjectService.prototype.updateConfiguredProject = function (project) { if (!this.host.fileExists(project.projectFilename)) { this.log("Config file deleted"); - this.removeConfiguredProject(project); + this.removeProject(project); } else { var _a = this.configFileToProjectOptions(project.projectFilename), succeeded = _a.succeeded, projectOptions = _a.projectOptions, error = _a.error; @@ -42481,7 +43240,9 @@ var ts; for (var _i = 0; _i < fileNamesToRemove.length; _i++) { var fileName = fileNamesToRemove[_i]; var info = this.getScriptInfo(fileName); - project.removeRoot(info); + if (info) { + project.removeRoot(info); + } } for (var _b = 0; _b < fileNamesToAdd.length; _b++) { var fileName = fileNamesToAdd[_b]; @@ -42542,6 +43303,7 @@ var ts; TabSize: 4, NewLineCharacter: ts.sys ? ts.sys.newLine : '\n', ConvertTabsToSpaces: true, + IndentStyle: ts.IndentStyle.Smart, InsertSpaceAfterCommaDelimiter: true, InsertSpaceAfterSemicolonInForStatements: true, InsertSpaceBeforeAndAfterBinaryOperators: true, @@ -43457,79 +44219,6 @@ var ts; }; return Logger; })(); - var WatchedFileSet = (function () { - function WatchedFileSet(interval, chunkSize) { - if (interval === void 0) { interval = 2500; } - if (chunkSize === void 0) { chunkSize = 30; } - this.interval = interval; - this.chunkSize = chunkSize; - this.watchedFiles = []; - this.nextFileToCheck = 0; - } - WatchedFileSet.copyListRemovingItem = function (item, list) { - var copiedList = []; - for (var i = 0, len = list.length; i < len; i++) { - if (list[i] != item) { - copiedList.push(list[i]); - } - } - return copiedList; - }; - WatchedFileSet.getModifiedTime = function (fileName) { - return fs.statSync(fileName).mtime; - }; - WatchedFileSet.prototype.poll = function (checkedIndex) { - var watchedFile = this.watchedFiles[checkedIndex]; - if (!watchedFile) { - return; - } - fs.stat(watchedFile.fileName, function (err, stats) { - if (err) { - watchedFile.callback(watchedFile.fileName); - } - else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) { - watchedFile.mtime = WatchedFileSet.getModifiedTime(watchedFile.fileName); - watchedFile.callback(watchedFile.fileName); - } - }); - }; - WatchedFileSet.prototype.startWatchTimer = function () { - var _this = this; - this.watchTimer = setInterval(function () { - var count = 0; - var nextToCheck = _this.nextFileToCheck; - var firstCheck = -1; - while ((count < _this.chunkSize) && (nextToCheck !== firstCheck)) { - _this.poll(nextToCheck); - if (firstCheck < 0) { - firstCheck = nextToCheck; - } - nextToCheck++; - if (nextToCheck === _this.watchedFiles.length) { - nextToCheck = 0; - } - count++; - } - _this.nextFileToCheck = nextToCheck; - }, this.interval); - }; - WatchedFileSet.prototype.addFile = function (fileName, callback) { - var file = { - fileName: fileName, - callback: callback, - mtime: WatchedFileSet.getModifiedTime(fileName) - }; - this.watchedFiles.push(file); - if (this.watchedFiles.length === 1) { - this.startWatchTimer(); - } - return file; - }; - WatchedFileSet.prototype.removeFile = function (file) { - this.watchedFiles = WatchedFileSet.copyListRemovingItem(file, this.watchedFiles); - }; - return WatchedFileSet; - })(); var IOSession = (function (_super) { __extends(IOSession, _super); function IOSession(host, logger) { @@ -43590,13 +44279,6 @@ var ts; return new Logger(fileName, detailLevel); } var logger = createLoggerFromEnv(); - var watchedFileSet = new WatchedFileSet(); - ts.sys.watchFile = function (fileName, callback) { - var watchedFile = watchedFileSet.addFile(fileName, callback); - return { - close: function () { return watchedFileSet.removeFile(watchedFile); } - }; - }; var ioSession = new IOSession(ts.sys, logger); process.on('uncaughtException', function (err) { ioSession.logError(err, "unknown"); @@ -44163,7 +44845,7 @@ var ts; var _this = this; return this.forwardJSONCall("getTSConfigFileInfo('" + fileName + "')", function () { var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - var result = ts.parseConfigFileText(fileName, text); + var result = ts.parseConfigFileTextToJson(fileName, text); if (result.error) { return { options: {}, @@ -44171,7 +44853,7 @@ var ts; errors: [realizeDiagnostic(result.error, '\r\n')] }; } - var configFile = ts.parseConfigFile(result.config, _this.host, ts.getDirectoryPath(ts.normalizeSlashes(fileName))); + var configFile = ts.parseJsonConfigFileContent(result.config, _this.host, ts.getDirectoryPath(ts.normalizeSlashes(fileName))); return { options: configFile.options, files: configFile.fileNames, diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 2cd3a663fce..5998cd26ad5 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -68,253 +68,255 @@ declare namespace ts { PlusToken = 35, MinusToken = 36, AsteriskToken = 37, - SlashToken = 38, - PercentToken = 39, - PlusPlusToken = 40, - MinusMinusToken = 41, - LessThanLessThanToken = 42, - GreaterThanGreaterThanToken = 43, - GreaterThanGreaterThanGreaterThanToken = 44, - AmpersandToken = 45, - BarToken = 46, - CaretToken = 47, - ExclamationToken = 48, - TildeToken = 49, - AmpersandAmpersandToken = 50, - BarBarToken = 51, - QuestionToken = 52, - ColonToken = 53, - AtToken = 54, - EqualsToken = 55, - PlusEqualsToken = 56, - MinusEqualsToken = 57, - AsteriskEqualsToken = 58, - SlashEqualsToken = 59, - PercentEqualsToken = 60, - LessThanLessThanEqualsToken = 61, - GreaterThanGreaterThanEqualsToken = 62, - GreaterThanGreaterThanGreaterThanEqualsToken = 63, - AmpersandEqualsToken = 64, - BarEqualsToken = 65, - CaretEqualsToken = 66, - Identifier = 67, - BreakKeyword = 68, - CaseKeyword = 69, - CatchKeyword = 70, - ClassKeyword = 71, - ConstKeyword = 72, - ContinueKeyword = 73, - DebuggerKeyword = 74, - DefaultKeyword = 75, - DeleteKeyword = 76, - DoKeyword = 77, - ElseKeyword = 78, - EnumKeyword = 79, - ExportKeyword = 80, - ExtendsKeyword = 81, - FalseKeyword = 82, - FinallyKeyword = 83, - ForKeyword = 84, - FunctionKeyword = 85, - IfKeyword = 86, - ImportKeyword = 87, - InKeyword = 88, - InstanceOfKeyword = 89, - NewKeyword = 90, - NullKeyword = 91, - ReturnKeyword = 92, - SuperKeyword = 93, - SwitchKeyword = 94, - ThisKeyword = 95, - ThrowKeyword = 96, - TrueKeyword = 97, - TryKeyword = 98, - TypeOfKeyword = 99, - VarKeyword = 100, - VoidKeyword = 101, - WhileKeyword = 102, - WithKeyword = 103, - ImplementsKeyword = 104, - InterfaceKeyword = 105, - LetKeyword = 106, - PackageKeyword = 107, - PrivateKeyword = 108, - ProtectedKeyword = 109, - PublicKeyword = 110, - StaticKeyword = 111, - YieldKeyword = 112, - AbstractKeyword = 113, - AsKeyword = 114, - AnyKeyword = 115, - AsyncKeyword = 116, - AwaitKeyword = 117, - BooleanKeyword = 118, - ConstructorKeyword = 119, - DeclareKeyword = 120, - GetKeyword = 121, - IsKeyword = 122, - ModuleKeyword = 123, - NamespaceKeyword = 124, - RequireKeyword = 125, - NumberKeyword = 126, - SetKeyword = 127, - StringKeyword = 128, - SymbolKeyword = 129, - TypeKeyword = 130, - FromKeyword = 131, - OfKeyword = 132, - QualifiedName = 133, - ComputedPropertyName = 134, - TypeParameter = 135, - Parameter = 136, - Decorator = 137, - PropertySignature = 138, - PropertyDeclaration = 139, - MethodSignature = 140, - MethodDeclaration = 141, - Constructor = 142, - GetAccessor = 143, - SetAccessor = 144, - CallSignature = 145, - ConstructSignature = 146, - IndexSignature = 147, - TypePredicate = 148, - TypeReference = 149, - FunctionType = 150, - ConstructorType = 151, - TypeQuery = 152, - TypeLiteral = 153, - ArrayType = 154, - TupleType = 155, - UnionType = 156, - IntersectionType = 157, - ParenthesizedType = 158, - ObjectBindingPattern = 159, - ArrayBindingPattern = 160, - BindingElement = 161, - ArrayLiteralExpression = 162, - ObjectLiteralExpression = 163, - PropertyAccessExpression = 164, - ElementAccessExpression = 165, - CallExpression = 166, - NewExpression = 167, - TaggedTemplateExpression = 168, - TypeAssertionExpression = 169, - ParenthesizedExpression = 170, - FunctionExpression = 171, - ArrowFunction = 172, - DeleteExpression = 173, - TypeOfExpression = 174, - VoidExpression = 175, - AwaitExpression = 176, - PrefixUnaryExpression = 177, - PostfixUnaryExpression = 178, - BinaryExpression = 179, - ConditionalExpression = 180, - TemplateExpression = 181, - YieldExpression = 182, - SpreadElementExpression = 183, - ClassExpression = 184, - OmittedExpression = 185, - ExpressionWithTypeArguments = 186, - AsExpression = 187, - TemplateSpan = 188, - SemicolonClassElement = 189, - Block = 190, - VariableStatement = 191, - EmptyStatement = 192, - ExpressionStatement = 193, - IfStatement = 194, - DoStatement = 195, - WhileStatement = 196, - ForStatement = 197, - ForInStatement = 198, - ForOfStatement = 199, - ContinueStatement = 200, - BreakStatement = 201, - ReturnStatement = 202, - WithStatement = 203, - SwitchStatement = 204, - LabeledStatement = 205, - ThrowStatement = 206, - TryStatement = 207, - DebuggerStatement = 208, - VariableDeclaration = 209, - VariableDeclarationList = 210, - FunctionDeclaration = 211, - ClassDeclaration = 212, - InterfaceDeclaration = 213, - TypeAliasDeclaration = 214, - EnumDeclaration = 215, - ModuleDeclaration = 216, - ModuleBlock = 217, - CaseBlock = 218, - ImportEqualsDeclaration = 219, - ImportDeclaration = 220, - ImportClause = 221, - NamespaceImport = 222, - NamedImports = 223, - ImportSpecifier = 224, - ExportAssignment = 225, - ExportDeclaration = 226, - NamedExports = 227, - ExportSpecifier = 228, - MissingDeclaration = 229, - ExternalModuleReference = 230, - JsxElement = 231, - JsxSelfClosingElement = 232, - JsxOpeningElement = 233, - JsxText = 234, - JsxClosingElement = 235, - JsxAttribute = 236, - JsxSpreadAttribute = 237, - JsxExpression = 238, - CaseClause = 239, - DefaultClause = 240, - HeritageClause = 241, - CatchClause = 242, - PropertyAssignment = 243, - ShorthandPropertyAssignment = 244, - EnumMember = 245, - SourceFile = 246, - JSDocTypeExpression = 247, - JSDocAllType = 248, - JSDocUnknownType = 249, - JSDocArrayType = 250, - JSDocUnionType = 251, - JSDocTupleType = 252, - JSDocNullableType = 253, - JSDocNonNullableType = 254, - JSDocRecordType = 255, - JSDocRecordMember = 256, - JSDocTypeReference = 257, - JSDocOptionalType = 258, - JSDocFunctionType = 259, - JSDocVariadicType = 260, - JSDocConstructorType = 261, - JSDocThisType = 262, - JSDocComment = 263, - JSDocTag = 264, - JSDocParameterTag = 265, - JSDocReturnTag = 266, - JSDocTypeTag = 267, - JSDocTemplateTag = 268, - SyntaxList = 269, - Count = 270, - FirstAssignment = 55, - LastAssignment = 66, - FirstReservedWord = 68, - LastReservedWord = 103, - FirstKeyword = 68, - LastKeyword = 132, - FirstFutureReservedWord = 104, - LastFutureReservedWord = 112, - FirstTypeNode = 149, - LastTypeNode = 158, + AsteriskAsteriskToken = 38, + SlashToken = 39, + PercentToken = 40, + PlusPlusToken = 41, + MinusMinusToken = 42, + LessThanLessThanToken = 43, + GreaterThanGreaterThanToken = 44, + GreaterThanGreaterThanGreaterThanToken = 45, + AmpersandToken = 46, + BarToken = 47, + CaretToken = 48, + ExclamationToken = 49, + TildeToken = 50, + AmpersandAmpersandToken = 51, + BarBarToken = 52, + QuestionToken = 53, + ColonToken = 54, + AtToken = 55, + EqualsToken = 56, + PlusEqualsToken = 57, + MinusEqualsToken = 58, + AsteriskEqualsToken = 59, + AsteriskAsteriskEqualsToken = 60, + SlashEqualsToken = 61, + PercentEqualsToken = 62, + LessThanLessThanEqualsToken = 63, + GreaterThanGreaterThanEqualsToken = 64, + GreaterThanGreaterThanGreaterThanEqualsToken = 65, + AmpersandEqualsToken = 66, + BarEqualsToken = 67, + CaretEqualsToken = 68, + Identifier = 69, + BreakKeyword = 70, + CaseKeyword = 71, + CatchKeyword = 72, + ClassKeyword = 73, + ConstKeyword = 74, + ContinueKeyword = 75, + DebuggerKeyword = 76, + DefaultKeyword = 77, + DeleteKeyword = 78, + DoKeyword = 79, + ElseKeyword = 80, + EnumKeyword = 81, + ExportKeyword = 82, + ExtendsKeyword = 83, + FalseKeyword = 84, + FinallyKeyword = 85, + ForKeyword = 86, + FunctionKeyword = 87, + IfKeyword = 88, + ImportKeyword = 89, + InKeyword = 90, + InstanceOfKeyword = 91, + NewKeyword = 92, + NullKeyword = 93, + ReturnKeyword = 94, + SuperKeyword = 95, + SwitchKeyword = 96, + ThisKeyword = 97, + ThrowKeyword = 98, + TrueKeyword = 99, + TryKeyword = 100, + TypeOfKeyword = 101, + VarKeyword = 102, + VoidKeyword = 103, + WhileKeyword = 104, + WithKeyword = 105, + ImplementsKeyword = 106, + InterfaceKeyword = 107, + LetKeyword = 108, + PackageKeyword = 109, + PrivateKeyword = 110, + ProtectedKeyword = 111, + PublicKeyword = 112, + StaticKeyword = 113, + YieldKeyword = 114, + AbstractKeyword = 115, + AsKeyword = 116, + AnyKeyword = 117, + AsyncKeyword = 118, + AwaitKeyword = 119, + BooleanKeyword = 120, + ConstructorKeyword = 121, + DeclareKeyword = 122, + GetKeyword = 123, + IsKeyword = 124, + ModuleKeyword = 125, + NamespaceKeyword = 126, + RequireKeyword = 127, + NumberKeyword = 128, + SetKeyword = 129, + StringKeyword = 130, + SymbolKeyword = 131, + TypeKeyword = 132, + FromKeyword = 133, + OfKeyword = 134, + QualifiedName = 135, + ComputedPropertyName = 136, + TypeParameter = 137, + Parameter = 138, + Decorator = 139, + PropertySignature = 140, + PropertyDeclaration = 141, + MethodSignature = 142, + MethodDeclaration = 143, + Constructor = 144, + GetAccessor = 145, + SetAccessor = 146, + CallSignature = 147, + ConstructSignature = 148, + IndexSignature = 149, + TypePredicate = 150, + TypeReference = 151, + FunctionType = 152, + ConstructorType = 153, + TypeQuery = 154, + TypeLiteral = 155, + ArrayType = 156, + TupleType = 157, + UnionType = 158, + IntersectionType = 159, + ParenthesizedType = 160, + ObjectBindingPattern = 161, + ArrayBindingPattern = 162, + BindingElement = 163, + ArrayLiteralExpression = 164, + ObjectLiteralExpression = 165, + PropertyAccessExpression = 166, + ElementAccessExpression = 167, + CallExpression = 168, + NewExpression = 169, + TaggedTemplateExpression = 170, + TypeAssertionExpression = 171, + ParenthesizedExpression = 172, + FunctionExpression = 173, + ArrowFunction = 174, + DeleteExpression = 175, + TypeOfExpression = 176, + VoidExpression = 177, + AwaitExpression = 178, + PrefixUnaryExpression = 179, + PostfixUnaryExpression = 180, + BinaryExpression = 181, + ConditionalExpression = 182, + TemplateExpression = 183, + YieldExpression = 184, + SpreadElementExpression = 185, + ClassExpression = 186, + OmittedExpression = 187, + ExpressionWithTypeArguments = 188, + AsExpression = 189, + TemplateSpan = 190, + SemicolonClassElement = 191, + Block = 192, + VariableStatement = 193, + EmptyStatement = 194, + ExpressionStatement = 195, + IfStatement = 196, + DoStatement = 197, + WhileStatement = 198, + ForStatement = 199, + ForInStatement = 200, + ForOfStatement = 201, + ContinueStatement = 202, + BreakStatement = 203, + ReturnStatement = 204, + WithStatement = 205, + SwitchStatement = 206, + LabeledStatement = 207, + ThrowStatement = 208, + TryStatement = 209, + DebuggerStatement = 210, + VariableDeclaration = 211, + VariableDeclarationList = 212, + FunctionDeclaration = 213, + ClassDeclaration = 214, + InterfaceDeclaration = 215, + TypeAliasDeclaration = 216, + EnumDeclaration = 217, + ModuleDeclaration = 218, + ModuleBlock = 219, + CaseBlock = 220, + ImportEqualsDeclaration = 221, + ImportDeclaration = 222, + ImportClause = 223, + NamespaceImport = 224, + NamedImports = 225, + ImportSpecifier = 226, + ExportAssignment = 227, + ExportDeclaration = 228, + NamedExports = 229, + ExportSpecifier = 230, + MissingDeclaration = 231, + ExternalModuleReference = 232, + JsxElement = 233, + JsxSelfClosingElement = 234, + JsxOpeningElement = 235, + JsxText = 236, + JsxClosingElement = 237, + JsxAttribute = 238, + JsxSpreadAttribute = 239, + JsxExpression = 240, + CaseClause = 241, + DefaultClause = 242, + HeritageClause = 243, + CatchClause = 244, + PropertyAssignment = 245, + ShorthandPropertyAssignment = 246, + EnumMember = 247, + SourceFile = 248, + JSDocTypeExpression = 249, + JSDocAllType = 250, + JSDocUnknownType = 251, + JSDocArrayType = 252, + JSDocUnionType = 253, + JSDocTupleType = 254, + JSDocNullableType = 255, + JSDocNonNullableType = 256, + JSDocRecordType = 257, + JSDocRecordMember = 258, + JSDocTypeReference = 259, + JSDocOptionalType = 260, + JSDocFunctionType = 261, + JSDocVariadicType = 262, + JSDocConstructorType = 263, + JSDocThisType = 264, + JSDocComment = 265, + JSDocTag = 266, + JSDocParameterTag = 267, + JSDocReturnTag = 268, + JSDocTypeTag = 269, + JSDocTemplateTag = 270, + SyntaxList = 271, + Count = 272, + FirstAssignment = 56, + LastAssignment = 68, + FirstReservedWord = 70, + LastReservedWord = 105, + FirstKeyword = 70, + LastKeyword = 134, + FirstFutureReservedWord = 106, + LastFutureReservedWord = 114, + FirstTypeNode = 151, + LastTypeNode = 160, FirstPunctuation = 15, - LastPunctuation = 66, + LastPunctuation = 68, FirstToken = 0, - LastToken = 132, + LastToken = 134, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -322,8 +324,8 @@ declare namespace ts { FirstTemplateToken = 11, LastTemplateToken = 14, FirstBinaryOperator = 25, - LastBinaryOperator = 66, - FirstNode = 133, + LastBinaryOperator = 68, + FirstNode = 135, } const enum NodeFlags { Export = 1, @@ -343,6 +345,7 @@ declare namespace ts { OctalLiteral = 65536, Namespace = 131072, ExportContext = 262144, + ContainsThis = 524288, Modifier = 2035, AccessibilityModifier = 112, BlockScoped = 49152, @@ -438,6 +441,8 @@ declare namespace ts { interface ShorthandPropertyAssignment extends ObjectLiteralElement { name: Identifier; questionToken?: Node; + equalsToken?: Node; + objectAssignmentInitializer?: Expression; } interface VariableLikeDeclaration extends Declaration { propertyName?: Identifier; @@ -530,18 +535,21 @@ declare namespace ts { interface UnaryExpression extends Expression { _unaryExpressionBrand: any; } - interface PrefixUnaryExpression extends UnaryExpression { + interface IncrementExpression extends UnaryExpression { + _incrementExpressionBrand: any; + } + interface PrefixUnaryExpression extends IncrementExpression { operator: SyntaxKind; operand: UnaryExpression; } - interface PostfixUnaryExpression extends PostfixExpression { + interface PostfixUnaryExpression extends IncrementExpression { operand: LeftHandSideExpression; operator: SyntaxKind; } interface PostfixExpression extends UnaryExpression { _postfixExpressionBrand: any; } - interface LeftHandSideExpression extends PostfixExpression { + interface LeftHandSideExpression extends IncrementExpression { _leftHandSideExpressionBrand: any; } interface MemberExpression extends LeftHandSideExpression { @@ -1082,6 +1090,7 @@ declare namespace ts { decreaseIndent(): void; clear(): void; trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; + reportInaccessibleThisError(): void; } const enum TypeFormatFlags { None = 0, @@ -1202,6 +1211,7 @@ declare namespace ts { Instantiated = 131072, ObjectLiteral = 524288, ESSymbol = 16777216, + ThisType = 33554432, StringLike = 258, NumberLike = 132, ObjectType = 80896, @@ -1223,6 +1233,7 @@ declare namespace ts { typeParameters: TypeParameter[]; outerTypeParameters: TypeParameter[]; localTypeParameters: TypeParameter[]; + thisType: TypeParameter; } interface InterfaceTypeWithDeclaredMembers extends InterfaceType { declaredProperties: Symbol[]; @@ -1337,7 +1348,6 @@ declare namespace ts { watch?: boolean; isolatedModules?: boolean; experimentalDecorators?: boolean; - experimentalAsyncFunctions?: boolean; emitDecoratorMetadata?: boolean; moduleResolution?: ModuleResolutionKind; [option: string]: string | number | boolean; @@ -1348,6 +1358,8 @@ declare namespace ts { AMD = 2, UMD = 3, System = 4, + ES6 = 5, + ES2015 = 5, } const enum JsxEmit { None = 0, @@ -1366,6 +1378,7 @@ declare namespace ts { ES3 = 0, ES5 = 1, ES6 = 2, + ES2015 = 2, Latest = 2, } const enum LanguageVariant { @@ -1417,7 +1430,8 @@ declare namespace ts { write(s: string): void; readFile(path: string, encoding?: string): string; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - watchFile?(path: string, callback: (path: string) => void): FileWatcher; + watchFile?(path: string, callback: (path: string, removed?: boolean) => void): FileWatcher; + watchDirectory?(path: string, callback: (path: string) => void, recursive?: boolean): FileWatcher; resolvePath(path: string): string; fileExists(path: string): boolean; directoryExists(path: string): boolean; @@ -1507,6 +1521,7 @@ declare namespace ts { */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; function getTypeParameterOwner(d: Declaration): Declaration; + function arrayStructurallyIsEqualTo(array1: Array, array2: Array): boolean; } declare namespace ts { function getNodeConstructor(kind: SyntaxKind): new () => Node; @@ -1542,7 +1557,7 @@ declare namespace ts { * @param fileName The path to the config file * @param jsonText The text of the config file */ - function parseConfigFileText(fileName: string, jsonText: string): { + function parseConfigFileTextToJson(fileName: string, jsonText: string): { config?: any; error?: Diagnostic; }; @@ -1552,7 +1567,7 @@ declare namespace ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine; + function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine; } declare namespace ts { /** The version of the language service API */ @@ -1775,6 +1790,12 @@ declare namespace ts { TabSize: number; NewLineCharacter: string; ConvertTabsToSpaces: boolean; + IndentStyle: IndentStyle; + } + enum IndentStyle { + None = 0, + Block = 1, + Smart = 2, } interface FormatCodeOptions extends EditorOptions { InsertSpaceAfterCommaDelimiter: boolean; diff --git a/lib/typescript.js b/lib/typescript.js index a1f9651570e..7f9c5c293ad 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -62,279 +62,281 @@ var ts; SyntaxKind[SyntaxKind["PlusToken"] = 35] = "PlusToken"; SyntaxKind[SyntaxKind["MinusToken"] = 36] = "MinusToken"; SyntaxKind[SyntaxKind["AsteriskToken"] = 37] = "AsteriskToken"; - SyntaxKind[SyntaxKind["SlashToken"] = 38] = "SlashToken"; - SyntaxKind[SyntaxKind["PercentToken"] = 39] = "PercentToken"; - SyntaxKind[SyntaxKind["PlusPlusToken"] = 40] = "PlusPlusToken"; - SyntaxKind[SyntaxKind["MinusMinusToken"] = 41] = "MinusMinusToken"; - SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 42] = "LessThanLessThanToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 43] = "GreaterThanGreaterThanToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 44] = "GreaterThanGreaterThanGreaterThanToken"; - SyntaxKind[SyntaxKind["AmpersandToken"] = 45] = "AmpersandToken"; - SyntaxKind[SyntaxKind["BarToken"] = 46] = "BarToken"; - SyntaxKind[SyntaxKind["CaretToken"] = 47] = "CaretToken"; - SyntaxKind[SyntaxKind["ExclamationToken"] = 48] = "ExclamationToken"; - SyntaxKind[SyntaxKind["TildeToken"] = 49] = "TildeToken"; - SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 50] = "AmpersandAmpersandToken"; - SyntaxKind[SyntaxKind["BarBarToken"] = 51] = "BarBarToken"; - SyntaxKind[SyntaxKind["QuestionToken"] = 52] = "QuestionToken"; - SyntaxKind[SyntaxKind["ColonToken"] = 53] = "ColonToken"; - SyntaxKind[SyntaxKind["AtToken"] = 54] = "AtToken"; + SyntaxKind[SyntaxKind["AsteriskAsteriskToken"] = 38] = "AsteriskAsteriskToken"; + SyntaxKind[SyntaxKind["SlashToken"] = 39] = "SlashToken"; + SyntaxKind[SyntaxKind["PercentToken"] = 40] = "PercentToken"; + SyntaxKind[SyntaxKind["PlusPlusToken"] = 41] = "PlusPlusToken"; + SyntaxKind[SyntaxKind["MinusMinusToken"] = 42] = "MinusMinusToken"; + SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 43] = "LessThanLessThanToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 44] = "GreaterThanGreaterThanToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 45] = "GreaterThanGreaterThanGreaterThanToken"; + SyntaxKind[SyntaxKind["AmpersandToken"] = 46] = "AmpersandToken"; + SyntaxKind[SyntaxKind["BarToken"] = 47] = "BarToken"; + SyntaxKind[SyntaxKind["CaretToken"] = 48] = "CaretToken"; + SyntaxKind[SyntaxKind["ExclamationToken"] = 49] = "ExclamationToken"; + SyntaxKind[SyntaxKind["TildeToken"] = 50] = "TildeToken"; + SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 51] = "AmpersandAmpersandToken"; + SyntaxKind[SyntaxKind["BarBarToken"] = 52] = "BarBarToken"; + SyntaxKind[SyntaxKind["QuestionToken"] = 53] = "QuestionToken"; + SyntaxKind[SyntaxKind["ColonToken"] = 54] = "ColonToken"; + SyntaxKind[SyntaxKind["AtToken"] = 55] = "AtToken"; // Assignments - SyntaxKind[SyntaxKind["EqualsToken"] = 55] = "EqualsToken"; - SyntaxKind[SyntaxKind["PlusEqualsToken"] = 56] = "PlusEqualsToken"; - SyntaxKind[SyntaxKind["MinusEqualsToken"] = 57] = "MinusEqualsToken"; - SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 58] = "AsteriskEqualsToken"; - SyntaxKind[SyntaxKind["SlashEqualsToken"] = 59] = "SlashEqualsToken"; - SyntaxKind[SyntaxKind["PercentEqualsToken"] = 60] = "PercentEqualsToken"; - SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 61] = "LessThanLessThanEqualsToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 62] = "GreaterThanGreaterThanEqualsToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 63] = "GreaterThanGreaterThanGreaterThanEqualsToken"; - SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 64] = "AmpersandEqualsToken"; - SyntaxKind[SyntaxKind["BarEqualsToken"] = 65] = "BarEqualsToken"; - SyntaxKind[SyntaxKind["CaretEqualsToken"] = 66] = "CaretEqualsToken"; + SyntaxKind[SyntaxKind["EqualsToken"] = 56] = "EqualsToken"; + SyntaxKind[SyntaxKind["PlusEqualsToken"] = 57] = "PlusEqualsToken"; + SyntaxKind[SyntaxKind["MinusEqualsToken"] = 58] = "MinusEqualsToken"; + SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 59] = "AsteriskEqualsToken"; + SyntaxKind[SyntaxKind["AsteriskAsteriskEqualsToken"] = 60] = "AsteriskAsteriskEqualsToken"; + SyntaxKind[SyntaxKind["SlashEqualsToken"] = 61] = "SlashEqualsToken"; + SyntaxKind[SyntaxKind["PercentEqualsToken"] = 62] = "PercentEqualsToken"; + SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 63] = "LessThanLessThanEqualsToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 64] = "GreaterThanGreaterThanEqualsToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 65] = "GreaterThanGreaterThanGreaterThanEqualsToken"; + SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 66] = "AmpersandEqualsToken"; + SyntaxKind[SyntaxKind["BarEqualsToken"] = 67] = "BarEqualsToken"; + SyntaxKind[SyntaxKind["CaretEqualsToken"] = 68] = "CaretEqualsToken"; // Identifiers - SyntaxKind[SyntaxKind["Identifier"] = 67] = "Identifier"; + SyntaxKind[SyntaxKind["Identifier"] = 69] = "Identifier"; // Reserved words - SyntaxKind[SyntaxKind["BreakKeyword"] = 68] = "BreakKeyword"; - SyntaxKind[SyntaxKind["CaseKeyword"] = 69] = "CaseKeyword"; - SyntaxKind[SyntaxKind["CatchKeyword"] = 70] = "CatchKeyword"; - SyntaxKind[SyntaxKind["ClassKeyword"] = 71] = "ClassKeyword"; - SyntaxKind[SyntaxKind["ConstKeyword"] = 72] = "ConstKeyword"; - SyntaxKind[SyntaxKind["ContinueKeyword"] = 73] = "ContinueKeyword"; - SyntaxKind[SyntaxKind["DebuggerKeyword"] = 74] = "DebuggerKeyword"; - SyntaxKind[SyntaxKind["DefaultKeyword"] = 75] = "DefaultKeyword"; - SyntaxKind[SyntaxKind["DeleteKeyword"] = 76] = "DeleteKeyword"; - SyntaxKind[SyntaxKind["DoKeyword"] = 77] = "DoKeyword"; - SyntaxKind[SyntaxKind["ElseKeyword"] = 78] = "ElseKeyword"; - SyntaxKind[SyntaxKind["EnumKeyword"] = 79] = "EnumKeyword"; - SyntaxKind[SyntaxKind["ExportKeyword"] = 80] = "ExportKeyword"; - SyntaxKind[SyntaxKind["ExtendsKeyword"] = 81] = "ExtendsKeyword"; - SyntaxKind[SyntaxKind["FalseKeyword"] = 82] = "FalseKeyword"; - SyntaxKind[SyntaxKind["FinallyKeyword"] = 83] = "FinallyKeyword"; - SyntaxKind[SyntaxKind["ForKeyword"] = 84] = "ForKeyword"; - SyntaxKind[SyntaxKind["FunctionKeyword"] = 85] = "FunctionKeyword"; - SyntaxKind[SyntaxKind["IfKeyword"] = 86] = "IfKeyword"; - SyntaxKind[SyntaxKind["ImportKeyword"] = 87] = "ImportKeyword"; - SyntaxKind[SyntaxKind["InKeyword"] = 88] = "InKeyword"; - SyntaxKind[SyntaxKind["InstanceOfKeyword"] = 89] = "InstanceOfKeyword"; - SyntaxKind[SyntaxKind["NewKeyword"] = 90] = "NewKeyword"; - SyntaxKind[SyntaxKind["NullKeyword"] = 91] = "NullKeyword"; - SyntaxKind[SyntaxKind["ReturnKeyword"] = 92] = "ReturnKeyword"; - SyntaxKind[SyntaxKind["SuperKeyword"] = 93] = "SuperKeyword"; - SyntaxKind[SyntaxKind["SwitchKeyword"] = 94] = "SwitchKeyword"; - SyntaxKind[SyntaxKind["ThisKeyword"] = 95] = "ThisKeyword"; - SyntaxKind[SyntaxKind["ThrowKeyword"] = 96] = "ThrowKeyword"; - SyntaxKind[SyntaxKind["TrueKeyword"] = 97] = "TrueKeyword"; - SyntaxKind[SyntaxKind["TryKeyword"] = 98] = "TryKeyword"; - SyntaxKind[SyntaxKind["TypeOfKeyword"] = 99] = "TypeOfKeyword"; - SyntaxKind[SyntaxKind["VarKeyword"] = 100] = "VarKeyword"; - SyntaxKind[SyntaxKind["VoidKeyword"] = 101] = "VoidKeyword"; - SyntaxKind[SyntaxKind["WhileKeyword"] = 102] = "WhileKeyword"; - SyntaxKind[SyntaxKind["WithKeyword"] = 103] = "WithKeyword"; + SyntaxKind[SyntaxKind["BreakKeyword"] = 70] = "BreakKeyword"; + SyntaxKind[SyntaxKind["CaseKeyword"] = 71] = "CaseKeyword"; + SyntaxKind[SyntaxKind["CatchKeyword"] = 72] = "CatchKeyword"; + SyntaxKind[SyntaxKind["ClassKeyword"] = 73] = "ClassKeyword"; + SyntaxKind[SyntaxKind["ConstKeyword"] = 74] = "ConstKeyword"; + SyntaxKind[SyntaxKind["ContinueKeyword"] = 75] = "ContinueKeyword"; + SyntaxKind[SyntaxKind["DebuggerKeyword"] = 76] = "DebuggerKeyword"; + SyntaxKind[SyntaxKind["DefaultKeyword"] = 77] = "DefaultKeyword"; + SyntaxKind[SyntaxKind["DeleteKeyword"] = 78] = "DeleteKeyword"; + SyntaxKind[SyntaxKind["DoKeyword"] = 79] = "DoKeyword"; + SyntaxKind[SyntaxKind["ElseKeyword"] = 80] = "ElseKeyword"; + SyntaxKind[SyntaxKind["EnumKeyword"] = 81] = "EnumKeyword"; + SyntaxKind[SyntaxKind["ExportKeyword"] = 82] = "ExportKeyword"; + SyntaxKind[SyntaxKind["ExtendsKeyword"] = 83] = "ExtendsKeyword"; + SyntaxKind[SyntaxKind["FalseKeyword"] = 84] = "FalseKeyword"; + SyntaxKind[SyntaxKind["FinallyKeyword"] = 85] = "FinallyKeyword"; + SyntaxKind[SyntaxKind["ForKeyword"] = 86] = "ForKeyword"; + SyntaxKind[SyntaxKind["FunctionKeyword"] = 87] = "FunctionKeyword"; + SyntaxKind[SyntaxKind["IfKeyword"] = 88] = "IfKeyword"; + SyntaxKind[SyntaxKind["ImportKeyword"] = 89] = "ImportKeyword"; + SyntaxKind[SyntaxKind["InKeyword"] = 90] = "InKeyword"; + SyntaxKind[SyntaxKind["InstanceOfKeyword"] = 91] = "InstanceOfKeyword"; + SyntaxKind[SyntaxKind["NewKeyword"] = 92] = "NewKeyword"; + SyntaxKind[SyntaxKind["NullKeyword"] = 93] = "NullKeyword"; + SyntaxKind[SyntaxKind["ReturnKeyword"] = 94] = "ReturnKeyword"; + SyntaxKind[SyntaxKind["SuperKeyword"] = 95] = "SuperKeyword"; + SyntaxKind[SyntaxKind["SwitchKeyword"] = 96] = "SwitchKeyword"; + SyntaxKind[SyntaxKind["ThisKeyword"] = 97] = "ThisKeyword"; + SyntaxKind[SyntaxKind["ThrowKeyword"] = 98] = "ThrowKeyword"; + SyntaxKind[SyntaxKind["TrueKeyword"] = 99] = "TrueKeyword"; + SyntaxKind[SyntaxKind["TryKeyword"] = 100] = "TryKeyword"; + SyntaxKind[SyntaxKind["TypeOfKeyword"] = 101] = "TypeOfKeyword"; + SyntaxKind[SyntaxKind["VarKeyword"] = 102] = "VarKeyword"; + SyntaxKind[SyntaxKind["VoidKeyword"] = 103] = "VoidKeyword"; + SyntaxKind[SyntaxKind["WhileKeyword"] = 104] = "WhileKeyword"; + SyntaxKind[SyntaxKind["WithKeyword"] = 105] = "WithKeyword"; // Strict mode reserved words - SyntaxKind[SyntaxKind["ImplementsKeyword"] = 104] = "ImplementsKeyword"; - SyntaxKind[SyntaxKind["InterfaceKeyword"] = 105] = "InterfaceKeyword"; - SyntaxKind[SyntaxKind["LetKeyword"] = 106] = "LetKeyword"; - SyntaxKind[SyntaxKind["PackageKeyword"] = 107] = "PackageKeyword"; - SyntaxKind[SyntaxKind["PrivateKeyword"] = 108] = "PrivateKeyword"; - SyntaxKind[SyntaxKind["ProtectedKeyword"] = 109] = "ProtectedKeyword"; - SyntaxKind[SyntaxKind["PublicKeyword"] = 110] = "PublicKeyword"; - SyntaxKind[SyntaxKind["StaticKeyword"] = 111] = "StaticKeyword"; - SyntaxKind[SyntaxKind["YieldKeyword"] = 112] = "YieldKeyword"; + SyntaxKind[SyntaxKind["ImplementsKeyword"] = 106] = "ImplementsKeyword"; + SyntaxKind[SyntaxKind["InterfaceKeyword"] = 107] = "InterfaceKeyword"; + SyntaxKind[SyntaxKind["LetKeyword"] = 108] = "LetKeyword"; + SyntaxKind[SyntaxKind["PackageKeyword"] = 109] = "PackageKeyword"; + SyntaxKind[SyntaxKind["PrivateKeyword"] = 110] = "PrivateKeyword"; + SyntaxKind[SyntaxKind["ProtectedKeyword"] = 111] = "ProtectedKeyword"; + SyntaxKind[SyntaxKind["PublicKeyword"] = 112] = "PublicKeyword"; + SyntaxKind[SyntaxKind["StaticKeyword"] = 113] = "StaticKeyword"; + SyntaxKind[SyntaxKind["YieldKeyword"] = 114] = "YieldKeyword"; // Contextual keywords - SyntaxKind[SyntaxKind["AbstractKeyword"] = 113] = "AbstractKeyword"; - SyntaxKind[SyntaxKind["AsKeyword"] = 114] = "AsKeyword"; - SyntaxKind[SyntaxKind["AnyKeyword"] = 115] = "AnyKeyword"; - SyntaxKind[SyntaxKind["AsyncKeyword"] = 116] = "AsyncKeyword"; - SyntaxKind[SyntaxKind["AwaitKeyword"] = 117] = "AwaitKeyword"; - SyntaxKind[SyntaxKind["BooleanKeyword"] = 118] = "BooleanKeyword"; - SyntaxKind[SyntaxKind["ConstructorKeyword"] = 119] = "ConstructorKeyword"; - SyntaxKind[SyntaxKind["DeclareKeyword"] = 120] = "DeclareKeyword"; - SyntaxKind[SyntaxKind["GetKeyword"] = 121] = "GetKeyword"; - SyntaxKind[SyntaxKind["IsKeyword"] = 122] = "IsKeyword"; - SyntaxKind[SyntaxKind["ModuleKeyword"] = 123] = "ModuleKeyword"; - SyntaxKind[SyntaxKind["NamespaceKeyword"] = 124] = "NamespaceKeyword"; - SyntaxKind[SyntaxKind["RequireKeyword"] = 125] = "RequireKeyword"; - SyntaxKind[SyntaxKind["NumberKeyword"] = 126] = "NumberKeyword"; - SyntaxKind[SyntaxKind["SetKeyword"] = 127] = "SetKeyword"; - SyntaxKind[SyntaxKind["StringKeyword"] = 128] = "StringKeyword"; - SyntaxKind[SyntaxKind["SymbolKeyword"] = 129] = "SymbolKeyword"; - SyntaxKind[SyntaxKind["TypeKeyword"] = 130] = "TypeKeyword"; - SyntaxKind[SyntaxKind["FromKeyword"] = 131] = "FromKeyword"; - SyntaxKind[SyntaxKind["OfKeyword"] = 132] = "OfKeyword"; + SyntaxKind[SyntaxKind["AbstractKeyword"] = 115] = "AbstractKeyword"; + SyntaxKind[SyntaxKind["AsKeyword"] = 116] = "AsKeyword"; + SyntaxKind[SyntaxKind["AnyKeyword"] = 117] = "AnyKeyword"; + SyntaxKind[SyntaxKind["AsyncKeyword"] = 118] = "AsyncKeyword"; + SyntaxKind[SyntaxKind["AwaitKeyword"] = 119] = "AwaitKeyword"; + SyntaxKind[SyntaxKind["BooleanKeyword"] = 120] = "BooleanKeyword"; + SyntaxKind[SyntaxKind["ConstructorKeyword"] = 121] = "ConstructorKeyword"; + SyntaxKind[SyntaxKind["DeclareKeyword"] = 122] = "DeclareKeyword"; + SyntaxKind[SyntaxKind["GetKeyword"] = 123] = "GetKeyword"; + SyntaxKind[SyntaxKind["IsKeyword"] = 124] = "IsKeyword"; + SyntaxKind[SyntaxKind["ModuleKeyword"] = 125] = "ModuleKeyword"; + SyntaxKind[SyntaxKind["NamespaceKeyword"] = 126] = "NamespaceKeyword"; + SyntaxKind[SyntaxKind["RequireKeyword"] = 127] = "RequireKeyword"; + SyntaxKind[SyntaxKind["NumberKeyword"] = 128] = "NumberKeyword"; + SyntaxKind[SyntaxKind["SetKeyword"] = 129] = "SetKeyword"; + SyntaxKind[SyntaxKind["StringKeyword"] = 130] = "StringKeyword"; + SyntaxKind[SyntaxKind["SymbolKeyword"] = 131] = "SymbolKeyword"; + SyntaxKind[SyntaxKind["TypeKeyword"] = 132] = "TypeKeyword"; + SyntaxKind[SyntaxKind["FromKeyword"] = 133] = "FromKeyword"; + SyntaxKind[SyntaxKind["OfKeyword"] = 134] = "OfKeyword"; // Parse tree nodes // Names - SyntaxKind[SyntaxKind["QualifiedName"] = 133] = "QualifiedName"; - SyntaxKind[SyntaxKind["ComputedPropertyName"] = 134] = "ComputedPropertyName"; + SyntaxKind[SyntaxKind["QualifiedName"] = 135] = "QualifiedName"; + SyntaxKind[SyntaxKind["ComputedPropertyName"] = 136] = "ComputedPropertyName"; // Signature elements - SyntaxKind[SyntaxKind["TypeParameter"] = 135] = "TypeParameter"; - SyntaxKind[SyntaxKind["Parameter"] = 136] = "Parameter"; - SyntaxKind[SyntaxKind["Decorator"] = 137] = "Decorator"; + SyntaxKind[SyntaxKind["TypeParameter"] = 137] = "TypeParameter"; + SyntaxKind[SyntaxKind["Parameter"] = 138] = "Parameter"; + SyntaxKind[SyntaxKind["Decorator"] = 139] = "Decorator"; // TypeMember - SyntaxKind[SyntaxKind["PropertySignature"] = 138] = "PropertySignature"; - SyntaxKind[SyntaxKind["PropertyDeclaration"] = 139] = "PropertyDeclaration"; - SyntaxKind[SyntaxKind["MethodSignature"] = 140] = "MethodSignature"; - SyntaxKind[SyntaxKind["MethodDeclaration"] = 141] = "MethodDeclaration"; - SyntaxKind[SyntaxKind["Constructor"] = 142] = "Constructor"; - SyntaxKind[SyntaxKind["GetAccessor"] = 143] = "GetAccessor"; - SyntaxKind[SyntaxKind["SetAccessor"] = 144] = "SetAccessor"; - SyntaxKind[SyntaxKind["CallSignature"] = 145] = "CallSignature"; - SyntaxKind[SyntaxKind["ConstructSignature"] = 146] = "ConstructSignature"; - SyntaxKind[SyntaxKind["IndexSignature"] = 147] = "IndexSignature"; + SyntaxKind[SyntaxKind["PropertySignature"] = 140] = "PropertySignature"; + SyntaxKind[SyntaxKind["PropertyDeclaration"] = 141] = "PropertyDeclaration"; + SyntaxKind[SyntaxKind["MethodSignature"] = 142] = "MethodSignature"; + SyntaxKind[SyntaxKind["MethodDeclaration"] = 143] = "MethodDeclaration"; + SyntaxKind[SyntaxKind["Constructor"] = 144] = "Constructor"; + SyntaxKind[SyntaxKind["GetAccessor"] = 145] = "GetAccessor"; + SyntaxKind[SyntaxKind["SetAccessor"] = 146] = "SetAccessor"; + SyntaxKind[SyntaxKind["CallSignature"] = 147] = "CallSignature"; + SyntaxKind[SyntaxKind["ConstructSignature"] = 148] = "ConstructSignature"; + SyntaxKind[SyntaxKind["IndexSignature"] = 149] = "IndexSignature"; // Type - SyntaxKind[SyntaxKind["TypePredicate"] = 148] = "TypePredicate"; - SyntaxKind[SyntaxKind["TypeReference"] = 149] = "TypeReference"; - SyntaxKind[SyntaxKind["FunctionType"] = 150] = "FunctionType"; - SyntaxKind[SyntaxKind["ConstructorType"] = 151] = "ConstructorType"; - SyntaxKind[SyntaxKind["TypeQuery"] = 152] = "TypeQuery"; - SyntaxKind[SyntaxKind["TypeLiteral"] = 153] = "TypeLiteral"; - SyntaxKind[SyntaxKind["ArrayType"] = 154] = "ArrayType"; - SyntaxKind[SyntaxKind["TupleType"] = 155] = "TupleType"; - SyntaxKind[SyntaxKind["UnionType"] = 156] = "UnionType"; - SyntaxKind[SyntaxKind["IntersectionType"] = 157] = "IntersectionType"; - SyntaxKind[SyntaxKind["ParenthesizedType"] = 158] = "ParenthesizedType"; + SyntaxKind[SyntaxKind["TypePredicate"] = 150] = "TypePredicate"; + SyntaxKind[SyntaxKind["TypeReference"] = 151] = "TypeReference"; + SyntaxKind[SyntaxKind["FunctionType"] = 152] = "FunctionType"; + SyntaxKind[SyntaxKind["ConstructorType"] = 153] = "ConstructorType"; + SyntaxKind[SyntaxKind["TypeQuery"] = 154] = "TypeQuery"; + SyntaxKind[SyntaxKind["TypeLiteral"] = 155] = "TypeLiteral"; + SyntaxKind[SyntaxKind["ArrayType"] = 156] = "ArrayType"; + SyntaxKind[SyntaxKind["TupleType"] = 157] = "TupleType"; + SyntaxKind[SyntaxKind["UnionType"] = 158] = "UnionType"; + SyntaxKind[SyntaxKind["IntersectionType"] = 159] = "IntersectionType"; + SyntaxKind[SyntaxKind["ParenthesizedType"] = 160] = "ParenthesizedType"; // Binding patterns - SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 159] = "ObjectBindingPattern"; - SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 160] = "ArrayBindingPattern"; - SyntaxKind[SyntaxKind["BindingElement"] = 161] = "BindingElement"; + SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 161] = "ObjectBindingPattern"; + SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 162] = "ArrayBindingPattern"; + SyntaxKind[SyntaxKind["BindingElement"] = 163] = "BindingElement"; // Expression - SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 162] = "ArrayLiteralExpression"; - SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 163] = "ObjectLiteralExpression"; - SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 164] = "PropertyAccessExpression"; - SyntaxKind[SyntaxKind["ElementAccessExpression"] = 165] = "ElementAccessExpression"; - SyntaxKind[SyntaxKind["CallExpression"] = 166] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 167] = "NewExpression"; - SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 168] = "TaggedTemplateExpression"; - SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 169] = "TypeAssertionExpression"; - SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 170] = "ParenthesizedExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 171] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 172] = "ArrowFunction"; - SyntaxKind[SyntaxKind["DeleteExpression"] = 173] = "DeleteExpression"; - SyntaxKind[SyntaxKind["TypeOfExpression"] = 174] = "TypeOfExpression"; - SyntaxKind[SyntaxKind["VoidExpression"] = 175] = "VoidExpression"; - SyntaxKind[SyntaxKind["AwaitExpression"] = 176] = "AwaitExpression"; - SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 177] = "PrefixUnaryExpression"; - SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 178] = "PostfixUnaryExpression"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 179] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 180] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["TemplateExpression"] = 181] = "TemplateExpression"; - SyntaxKind[SyntaxKind["YieldExpression"] = 182] = "YieldExpression"; - SyntaxKind[SyntaxKind["SpreadElementExpression"] = 183] = "SpreadElementExpression"; - SyntaxKind[SyntaxKind["ClassExpression"] = 184] = "ClassExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 185] = "OmittedExpression"; - SyntaxKind[SyntaxKind["ExpressionWithTypeArguments"] = 186] = "ExpressionWithTypeArguments"; - SyntaxKind[SyntaxKind["AsExpression"] = 187] = "AsExpression"; + SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 164] = "ArrayLiteralExpression"; + SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 165] = "ObjectLiteralExpression"; + SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 166] = "PropertyAccessExpression"; + SyntaxKind[SyntaxKind["ElementAccessExpression"] = 167] = "ElementAccessExpression"; + SyntaxKind[SyntaxKind["CallExpression"] = 168] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 169] = "NewExpression"; + SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 170] = "TaggedTemplateExpression"; + SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 171] = "TypeAssertionExpression"; + SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 172] = "ParenthesizedExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 173] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 174] = "ArrowFunction"; + SyntaxKind[SyntaxKind["DeleteExpression"] = 175] = "DeleteExpression"; + SyntaxKind[SyntaxKind["TypeOfExpression"] = 176] = "TypeOfExpression"; + SyntaxKind[SyntaxKind["VoidExpression"] = 177] = "VoidExpression"; + SyntaxKind[SyntaxKind["AwaitExpression"] = 178] = "AwaitExpression"; + SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 179] = "PrefixUnaryExpression"; + SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 180] = "PostfixUnaryExpression"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 181] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 182] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["TemplateExpression"] = 183] = "TemplateExpression"; + SyntaxKind[SyntaxKind["YieldExpression"] = 184] = "YieldExpression"; + SyntaxKind[SyntaxKind["SpreadElementExpression"] = 185] = "SpreadElementExpression"; + SyntaxKind[SyntaxKind["ClassExpression"] = 186] = "ClassExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 187] = "OmittedExpression"; + SyntaxKind[SyntaxKind["ExpressionWithTypeArguments"] = 188] = "ExpressionWithTypeArguments"; + SyntaxKind[SyntaxKind["AsExpression"] = 189] = "AsExpression"; // Misc - SyntaxKind[SyntaxKind["TemplateSpan"] = 188] = "TemplateSpan"; - SyntaxKind[SyntaxKind["SemicolonClassElement"] = 189] = "SemicolonClassElement"; + SyntaxKind[SyntaxKind["TemplateSpan"] = 190] = "TemplateSpan"; + SyntaxKind[SyntaxKind["SemicolonClassElement"] = 191] = "SemicolonClassElement"; // Element - SyntaxKind[SyntaxKind["Block"] = 190] = "Block"; - SyntaxKind[SyntaxKind["VariableStatement"] = 191] = "VariableStatement"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 192] = "EmptyStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 193] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 194] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 195] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 196] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 197] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 198] = "ForInStatement"; - SyntaxKind[SyntaxKind["ForOfStatement"] = 199] = "ForOfStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 200] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 201] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 202] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 203] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 204] = "SwitchStatement"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 205] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 206] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 207] = "TryStatement"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 208] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 209] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["VariableDeclarationList"] = 210] = "VariableDeclarationList"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 211] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 212] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 213] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 214] = "TypeAliasDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 215] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 216] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 217] = "ModuleBlock"; - SyntaxKind[SyntaxKind["CaseBlock"] = 218] = "CaseBlock"; - SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 219] = "ImportEqualsDeclaration"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 220] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ImportClause"] = 221] = "ImportClause"; - SyntaxKind[SyntaxKind["NamespaceImport"] = 222] = "NamespaceImport"; - SyntaxKind[SyntaxKind["NamedImports"] = 223] = "NamedImports"; - SyntaxKind[SyntaxKind["ImportSpecifier"] = 224] = "ImportSpecifier"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 225] = "ExportAssignment"; - SyntaxKind[SyntaxKind["ExportDeclaration"] = 226] = "ExportDeclaration"; - SyntaxKind[SyntaxKind["NamedExports"] = 227] = "NamedExports"; - SyntaxKind[SyntaxKind["ExportSpecifier"] = 228] = "ExportSpecifier"; - SyntaxKind[SyntaxKind["MissingDeclaration"] = 229] = "MissingDeclaration"; + SyntaxKind[SyntaxKind["Block"] = 192] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 193] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 194] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 195] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 196] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 197] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 198] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 199] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 200] = "ForInStatement"; + SyntaxKind[SyntaxKind["ForOfStatement"] = 201] = "ForOfStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 202] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 203] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 204] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 205] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 206] = "SwitchStatement"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 207] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 208] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 209] = "TryStatement"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 210] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 211] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["VariableDeclarationList"] = 212] = "VariableDeclarationList"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 213] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 214] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 215] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 216] = "TypeAliasDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 217] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 218] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 219] = "ModuleBlock"; + SyntaxKind[SyntaxKind["CaseBlock"] = 220] = "CaseBlock"; + SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 221] = "ImportEqualsDeclaration"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 222] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ImportClause"] = 223] = "ImportClause"; + SyntaxKind[SyntaxKind["NamespaceImport"] = 224] = "NamespaceImport"; + SyntaxKind[SyntaxKind["NamedImports"] = 225] = "NamedImports"; + SyntaxKind[SyntaxKind["ImportSpecifier"] = 226] = "ImportSpecifier"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 227] = "ExportAssignment"; + SyntaxKind[SyntaxKind["ExportDeclaration"] = 228] = "ExportDeclaration"; + SyntaxKind[SyntaxKind["NamedExports"] = 229] = "NamedExports"; + SyntaxKind[SyntaxKind["ExportSpecifier"] = 230] = "ExportSpecifier"; + SyntaxKind[SyntaxKind["MissingDeclaration"] = 231] = "MissingDeclaration"; // Module references - SyntaxKind[SyntaxKind["ExternalModuleReference"] = 230] = "ExternalModuleReference"; + SyntaxKind[SyntaxKind["ExternalModuleReference"] = 232] = "ExternalModuleReference"; // JSX - SyntaxKind[SyntaxKind["JsxElement"] = 231] = "JsxElement"; - SyntaxKind[SyntaxKind["JsxSelfClosingElement"] = 232] = "JsxSelfClosingElement"; - SyntaxKind[SyntaxKind["JsxOpeningElement"] = 233] = "JsxOpeningElement"; - SyntaxKind[SyntaxKind["JsxText"] = 234] = "JsxText"; - SyntaxKind[SyntaxKind["JsxClosingElement"] = 235] = "JsxClosingElement"; - SyntaxKind[SyntaxKind["JsxAttribute"] = 236] = "JsxAttribute"; - SyntaxKind[SyntaxKind["JsxSpreadAttribute"] = 237] = "JsxSpreadAttribute"; - SyntaxKind[SyntaxKind["JsxExpression"] = 238] = "JsxExpression"; + SyntaxKind[SyntaxKind["JsxElement"] = 233] = "JsxElement"; + SyntaxKind[SyntaxKind["JsxSelfClosingElement"] = 234] = "JsxSelfClosingElement"; + SyntaxKind[SyntaxKind["JsxOpeningElement"] = 235] = "JsxOpeningElement"; + SyntaxKind[SyntaxKind["JsxText"] = 236] = "JsxText"; + SyntaxKind[SyntaxKind["JsxClosingElement"] = 237] = "JsxClosingElement"; + SyntaxKind[SyntaxKind["JsxAttribute"] = 238] = "JsxAttribute"; + SyntaxKind[SyntaxKind["JsxSpreadAttribute"] = 239] = "JsxSpreadAttribute"; + SyntaxKind[SyntaxKind["JsxExpression"] = 240] = "JsxExpression"; // Clauses - SyntaxKind[SyntaxKind["CaseClause"] = 239] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 240] = "DefaultClause"; - SyntaxKind[SyntaxKind["HeritageClause"] = 241] = "HeritageClause"; - SyntaxKind[SyntaxKind["CatchClause"] = 242] = "CatchClause"; + SyntaxKind[SyntaxKind["CaseClause"] = 241] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 242] = "DefaultClause"; + SyntaxKind[SyntaxKind["HeritageClause"] = 243] = "HeritageClause"; + SyntaxKind[SyntaxKind["CatchClause"] = 244] = "CatchClause"; // Property assignments - SyntaxKind[SyntaxKind["PropertyAssignment"] = 243] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 244] = "ShorthandPropertyAssignment"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 245] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 246] = "ShorthandPropertyAssignment"; // Enum - SyntaxKind[SyntaxKind["EnumMember"] = 245] = "EnumMember"; + SyntaxKind[SyntaxKind["EnumMember"] = 247] = "EnumMember"; // Top-level nodes - SyntaxKind[SyntaxKind["SourceFile"] = 246] = "SourceFile"; + SyntaxKind[SyntaxKind["SourceFile"] = 248] = "SourceFile"; // JSDoc nodes. - SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 247] = "JSDocTypeExpression"; + SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 249] = "JSDocTypeExpression"; // The * type. - SyntaxKind[SyntaxKind["JSDocAllType"] = 248] = "JSDocAllType"; + SyntaxKind[SyntaxKind["JSDocAllType"] = 250] = "JSDocAllType"; // The ? type. - SyntaxKind[SyntaxKind["JSDocUnknownType"] = 249] = "JSDocUnknownType"; - SyntaxKind[SyntaxKind["JSDocArrayType"] = 250] = "JSDocArrayType"; - SyntaxKind[SyntaxKind["JSDocUnionType"] = 251] = "JSDocUnionType"; - SyntaxKind[SyntaxKind["JSDocTupleType"] = 252] = "JSDocTupleType"; - SyntaxKind[SyntaxKind["JSDocNullableType"] = 253] = "JSDocNullableType"; - SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 254] = "JSDocNonNullableType"; - SyntaxKind[SyntaxKind["JSDocRecordType"] = 255] = "JSDocRecordType"; - SyntaxKind[SyntaxKind["JSDocRecordMember"] = 256] = "JSDocRecordMember"; - SyntaxKind[SyntaxKind["JSDocTypeReference"] = 257] = "JSDocTypeReference"; - SyntaxKind[SyntaxKind["JSDocOptionalType"] = 258] = "JSDocOptionalType"; - SyntaxKind[SyntaxKind["JSDocFunctionType"] = 259] = "JSDocFunctionType"; - SyntaxKind[SyntaxKind["JSDocVariadicType"] = 260] = "JSDocVariadicType"; - SyntaxKind[SyntaxKind["JSDocConstructorType"] = 261] = "JSDocConstructorType"; - SyntaxKind[SyntaxKind["JSDocThisType"] = 262] = "JSDocThisType"; - SyntaxKind[SyntaxKind["JSDocComment"] = 263] = "JSDocComment"; - SyntaxKind[SyntaxKind["JSDocTag"] = 264] = "JSDocTag"; - SyntaxKind[SyntaxKind["JSDocParameterTag"] = 265] = "JSDocParameterTag"; - SyntaxKind[SyntaxKind["JSDocReturnTag"] = 266] = "JSDocReturnTag"; - SyntaxKind[SyntaxKind["JSDocTypeTag"] = 267] = "JSDocTypeTag"; - SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 268] = "JSDocTemplateTag"; + SyntaxKind[SyntaxKind["JSDocUnknownType"] = 251] = "JSDocUnknownType"; + SyntaxKind[SyntaxKind["JSDocArrayType"] = 252] = "JSDocArrayType"; + SyntaxKind[SyntaxKind["JSDocUnionType"] = 253] = "JSDocUnionType"; + SyntaxKind[SyntaxKind["JSDocTupleType"] = 254] = "JSDocTupleType"; + SyntaxKind[SyntaxKind["JSDocNullableType"] = 255] = "JSDocNullableType"; + SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 256] = "JSDocNonNullableType"; + SyntaxKind[SyntaxKind["JSDocRecordType"] = 257] = "JSDocRecordType"; + SyntaxKind[SyntaxKind["JSDocRecordMember"] = 258] = "JSDocRecordMember"; + SyntaxKind[SyntaxKind["JSDocTypeReference"] = 259] = "JSDocTypeReference"; + SyntaxKind[SyntaxKind["JSDocOptionalType"] = 260] = "JSDocOptionalType"; + SyntaxKind[SyntaxKind["JSDocFunctionType"] = 261] = "JSDocFunctionType"; + SyntaxKind[SyntaxKind["JSDocVariadicType"] = 262] = "JSDocVariadicType"; + SyntaxKind[SyntaxKind["JSDocConstructorType"] = 263] = "JSDocConstructorType"; + SyntaxKind[SyntaxKind["JSDocThisType"] = 264] = "JSDocThisType"; + SyntaxKind[SyntaxKind["JSDocComment"] = 265] = "JSDocComment"; + SyntaxKind[SyntaxKind["JSDocTag"] = 266] = "JSDocTag"; + SyntaxKind[SyntaxKind["JSDocParameterTag"] = 267] = "JSDocParameterTag"; + SyntaxKind[SyntaxKind["JSDocReturnTag"] = 268] = "JSDocReturnTag"; + SyntaxKind[SyntaxKind["JSDocTypeTag"] = 269] = "JSDocTypeTag"; + SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 270] = "JSDocTemplateTag"; // Synthesized list - SyntaxKind[SyntaxKind["SyntaxList"] = 269] = "SyntaxList"; + SyntaxKind[SyntaxKind["SyntaxList"] = 271] = "SyntaxList"; // Enum value count - SyntaxKind[SyntaxKind["Count"] = 270] = "Count"; + SyntaxKind[SyntaxKind["Count"] = 272] = "Count"; // Markers - SyntaxKind[SyntaxKind["FirstAssignment"] = 55] = "FirstAssignment"; - SyntaxKind[SyntaxKind["LastAssignment"] = 66] = "LastAssignment"; - SyntaxKind[SyntaxKind["FirstReservedWord"] = 68] = "FirstReservedWord"; - SyntaxKind[SyntaxKind["LastReservedWord"] = 103] = "LastReservedWord"; - SyntaxKind[SyntaxKind["FirstKeyword"] = 68] = "FirstKeyword"; - SyntaxKind[SyntaxKind["LastKeyword"] = 132] = "LastKeyword"; - SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 104] = "FirstFutureReservedWord"; - SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 112] = "LastFutureReservedWord"; - SyntaxKind[SyntaxKind["FirstTypeNode"] = 149] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = 158] = "LastTypeNode"; + SyntaxKind[SyntaxKind["FirstAssignment"] = 56] = "FirstAssignment"; + SyntaxKind[SyntaxKind["LastAssignment"] = 68] = "LastAssignment"; + SyntaxKind[SyntaxKind["FirstReservedWord"] = 70] = "FirstReservedWord"; + SyntaxKind[SyntaxKind["LastReservedWord"] = 105] = "LastReservedWord"; + SyntaxKind[SyntaxKind["FirstKeyword"] = 70] = "FirstKeyword"; + SyntaxKind[SyntaxKind["LastKeyword"] = 134] = "LastKeyword"; + SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 106] = "FirstFutureReservedWord"; + SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 114] = "LastFutureReservedWord"; + SyntaxKind[SyntaxKind["FirstTypeNode"] = 151] = "FirstTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = 160] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 15] = "FirstPunctuation"; - SyntaxKind[SyntaxKind["LastPunctuation"] = 66] = "LastPunctuation"; + SyntaxKind[SyntaxKind["LastPunctuation"] = 68] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = 0] = "FirstToken"; - SyntaxKind[SyntaxKind["LastToken"] = 132] = "LastToken"; + SyntaxKind[SyntaxKind["LastToken"] = 134] = "LastToken"; SyntaxKind[SyntaxKind["FirstTriviaToken"] = 2] = "FirstTriviaToken"; SyntaxKind[SyntaxKind["LastTriviaToken"] = 7] = "LastTriviaToken"; SyntaxKind[SyntaxKind["FirstLiteralToken"] = 8] = "FirstLiteralToken"; @@ -342,8 +344,8 @@ var ts; SyntaxKind[SyntaxKind["FirstTemplateToken"] = 11] = "FirstTemplateToken"; SyntaxKind[SyntaxKind["LastTemplateToken"] = 14] = "LastTemplateToken"; SyntaxKind[SyntaxKind["FirstBinaryOperator"] = 25] = "FirstBinaryOperator"; - SyntaxKind[SyntaxKind["LastBinaryOperator"] = 66] = "LastBinaryOperator"; - SyntaxKind[SyntaxKind["FirstNode"] = 133] = "FirstNode"; + SyntaxKind[SyntaxKind["LastBinaryOperator"] = 68] = "LastBinaryOperator"; + SyntaxKind[SyntaxKind["FirstNode"] = 135] = "FirstNode"; })(ts.SyntaxKind || (ts.SyntaxKind = {})); var SyntaxKind = ts.SyntaxKind; (function (NodeFlags) { @@ -364,6 +366,7 @@ var ts; NodeFlags[NodeFlags["OctalLiteral"] = 65536] = "OctalLiteral"; NodeFlags[NodeFlags["Namespace"] = 131072] = "Namespace"; NodeFlags[NodeFlags["ExportContext"] = 262144] = "ExportContext"; + NodeFlags[NodeFlags["ContainsThis"] = 524288] = "ContainsThis"; NodeFlags[NodeFlags["Modifier"] = 2035] = "Modifier"; NodeFlags[NodeFlags["AccessibilityModifier"] = 112] = "AccessibilityModifier"; NodeFlags[NodeFlags["BlockScoped"] = 49152] = "BlockScoped"; @@ -613,6 +616,7 @@ var ts; /* @internal */ TypeFlags[TypeFlags["ContainsAnyFunctionType"] = 8388608] = "ContainsAnyFunctionType"; TypeFlags[TypeFlags["ESSymbol"] = 16777216] = "ESSymbol"; + TypeFlags[TypeFlags["ThisType"] = 33554432] = "ThisType"; /* @internal */ TypeFlags[TypeFlags["Intrinsic"] = 16777343] = "Intrinsic"; /* @internal */ @@ -655,6 +659,8 @@ var ts; ModuleKind[ModuleKind["AMD"] = 2] = "AMD"; ModuleKind[ModuleKind["UMD"] = 3] = "UMD"; ModuleKind[ModuleKind["System"] = 4] = "System"; + ModuleKind[ModuleKind["ES6"] = 5] = "ES6"; + ModuleKind[ModuleKind["ES2015"] = 5] = "ES2015"; })(ts.ModuleKind || (ts.ModuleKind = {})); var ModuleKind = ts.ModuleKind; (function (JsxEmit) { @@ -672,6 +678,7 @@ var ts; ScriptTarget[ScriptTarget["ES3"] = 0] = "ES3"; ScriptTarget[ScriptTarget["ES5"] = 1] = "ES5"; ScriptTarget[ScriptTarget["ES6"] = 2] = "ES6"; + ScriptTarget[ScriptTarget["ES2015"] = 2] = "ES2015"; ScriptTarget[ScriptTarget["Latest"] = 2] = "Latest"; })(ts.ScriptTarget || (ts.ScriptTarget = {})); var ScriptTarget = ts.ScriptTarget; @@ -1221,8 +1228,11 @@ var ts; } ts.chainDiagnosticMessages = chainDiagnosticMessages; function concatenateDiagnosticMessageChains(headChain, tailChain) { - Debug.assert(!headChain.next); - headChain.next = tailChain; + var lastChain = headChain; + while (lastChain.next) { + lastChain = lastChain.next; + } + lastChain.next = tailChain; return headChain; } ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains; @@ -1470,6 +1480,9 @@ var ts; } ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl; function getBaseFileName(path) { + if (!path) { + return undefined; + } var i = path.lastIndexOf(ts.directorySeparator); return i < 0 ? path : path.substring(i + 1); } @@ -1496,6 +1509,25 @@ var ts; * List of supported extensions in order of file resolution precedence. */ ts.supportedExtensions = [".ts", ".tsx", ".d.ts"]; + /** + * List of extensions that will be used to look for external modules. + * This list is kept separate from supportedExtensions to for cases when we'll allow to include .js files in compilation, + * but still would like to load only TypeScript files as modules + */ + ts.moduleFileExtensions = ts.supportedExtensions; + function isSupportedSourceFileName(fileName) { + if (!fileName) { + return false; + } + for (var _i = 0; _i < ts.supportedExtensions.length; _i++) { + var extension = ts.supportedExtensions[_i]; + if (fileExtensionIs(fileName, extension)) { + return true; + } + } + return false; + } + ts.isSupportedSourceFileName = isSupportedSourceFileName; var extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"]; function removeFileExtension(path) { for (var _i = 0; _i < extensionsToRemove.length; _i++) { @@ -1579,6 +1611,16 @@ var ts; } Debug.fail = fail; })(Debug = ts.Debug || (ts.Debug = {})); + function copyListRemovingItem(item, list) { + var copiedList = []; + for (var i = 0, len = list.length; i < len; i++) { + if (list[i] !== item) { + copiedList.push(list[i]); + } + } + return copiedList; + } + ts.copyListRemovingItem = copyListRemovingItem; })(ts || (ts = {})); /// var ts; @@ -1725,6 +1767,94 @@ var ts; var _fs = require("fs"); var _path = require("path"); var _os = require("os"); + // average async stat takes about 30 microseconds + // set chunk size to do 30 files in < 1 millisecond + function createWatchedFileSet(interval, chunkSize) { + if (interval === void 0) { interval = 2500; } + if (chunkSize === void 0) { chunkSize = 30; } + var watchedFiles = []; + var nextFileToCheck = 0; + var watchTimer; + function getModifiedTime(fileName) { + return _fs.statSync(fileName).mtime; + } + function poll(checkedIndex) { + var watchedFile = watchedFiles[checkedIndex]; + if (!watchedFile) { + return; + } + _fs.stat(watchedFile.fileName, function (err, stats) { + if (err) { + watchedFile.callback(watchedFile.fileName); + } + else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) { + watchedFile.mtime = getModifiedTime(watchedFile.fileName); + watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0); + } + }); + } + // this implementation uses polling and + // stat due to inconsistencies of fs.watch + // and efficiency of stat on modern filesystems + function startWatchTimer() { + watchTimer = setInterval(function () { + var count = 0; + var nextToCheck = nextFileToCheck; + var firstCheck = -1; + while ((count < chunkSize) && (nextToCheck !== firstCheck)) { + poll(nextToCheck); + if (firstCheck < 0) { + firstCheck = nextToCheck; + } + nextToCheck++; + if (nextToCheck === watchedFiles.length) { + nextToCheck = 0; + } + count++; + } + nextFileToCheck = nextToCheck; + }, interval); + } + function addFile(fileName, callback) { + var file = { + fileName: fileName, + callback: callback, + mtime: getModifiedTime(fileName) + }; + watchedFiles.push(file); + if (watchedFiles.length === 1) { + startWatchTimer(); + } + return file; + } + function removeFile(file) { + watchedFiles = ts.copyListRemovingItem(file, watchedFiles); + } + return { + getModifiedTime: getModifiedTime, + poll: poll, + startWatchTimer: startWatchTimer, + addFile: addFile, + removeFile: removeFile + }; + } + // REVIEW: for now this implementation uses polling. + // The advantage of polling is that it works reliably + // on all os and with network mounted files. + // For 90 referenced files, the average time to detect + // changes is 2*msInterval (by default 5 seconds). + // The overhead of this is .04 percent (1/2500) with + // average pause of < 1 millisecond (and max + // pause less than 1.5 milliseconds); question is + // do we anticipate reference sets in the 100s and + // do we care about waiting 10-20 seconds to detect + // changes for large reference sets? If so, do we want + // to increase the chunk size or decrease the interval + // time dynamically to match the large reference set? + var watchedFileSet = createWatchedFileSet(); + function isNode4OrLater() { + return parseInt(process.version.charAt(1)) >= 4; + } var platform = _os.platform(); // win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; @@ -1813,17 +1943,32 @@ var ts; readFile: readFile, writeFile: writeFile, watchFile: function (fileName, callback) { - // watchFile polls a file every 250ms, picking up file notifications. - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); - return { - close: function () { _fs.unwatchFile(fileName, fileChanged); } - }; - function fileChanged(curr, prev) { - if (+curr.mtime <= +prev.mtime) { - return; - } - callback(fileName); + // Node 4.0 stablized the `fs.watch` function on Windows which avoids polling + // and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649 + // and https://github.com/Microsoft/TypeScript/issues/4643), therefore + // if the current node.js version is newer than 4, use `fs.watch` instead. + if (isNode4OrLater()) { + // Note: in node the callback of fs.watch is given only the relative file name as a parameter + return _fs.watch(fileName, function (eventName, relativeFileName) { return callback(fileName); }); } + var watchedFile = watchedFileSet.addFile(fileName, callback); + return { + close: function () { return watchedFileSet.removeFile(watchedFile); } + }; + }, + watchDirectory: function (path, callback, recursive) { + // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows + // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643) + return _fs.watch(path, { persisten: true, recursive: !!recursive }, function (eventName, relativeFileName) { + // In watchDirectory we only care about adding and removing files (when event name is + // "rename"); changes made within files are handled by corresponding fileWatchers (when + // event name is "change") + if (eventName === "rename") { + // When deleting a file, the passed baseFileName is null + callback(!relativeFileName ? relativeFileName : ts.normalizePath(ts.combinePaths(path, relativeFileName))); + } + ; + }); }, resolvePath: function (path) { return _path.resolve(path); @@ -1925,7 +2070,7 @@ var ts; Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." }, _0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: { code: 1062, category: ts.DiagnosticCategory.Error, key: "{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method." }, An_export_assignment_cannot_be_used_in_a_namespace: { code: 1063, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a namespace." }, - Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: ts.DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." }, + In_ambient_enum_declarations_member_initializer_must_be_constant_expression: { code: 1066, category: ts.DiagnosticCategory.Error, key: "In ambient enum declarations member initializer must be constant expression." }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: ts.DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." }, @@ -2013,7 +2158,7 @@ var ts; Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." }, A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." }, - An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, + An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1183, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, @@ -2031,10 +2176,9 @@ var ts; An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: ts.DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, - Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, - Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, - Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." }, - Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead." }, + Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead." }, + Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'es6' when targeting 'ES5' or lower." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, @@ -2063,10 +2207,6 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, - Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning: { code: 1236, category: ts.DiagnosticCategory.Error, key: "Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning." }, - with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, - await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, - Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, @@ -2077,6 +2217,10 @@ var ts; _0_modifier_cannot_be_used_with_1_modifier: { code: 1243, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." }, Abstract_methods_can_only_appear_within_an_abstract_class: { code: 1244, category: ts.DiagnosticCategory.Error, key: "Abstract methods can only appear within an abstract class." }, Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: { code: 1245, category: ts.DiagnosticCategory.Error, key: "Method '{0}' cannot have an implementation because it is marked abstract." }, + with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, + await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, + Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, + can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment: { code: 1312, category: ts.DiagnosticCategory.Error, key: "'=' can only be used in an object literal property inside a destructuring assignment." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -2201,7 +2345,7 @@ var ts; In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element: { code: 2432, category: ts.DiagnosticCategory.Error, key: "In an enum with multiple declarations, only one declaration can omit an initializer for its first enum element." }, A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged: { code: 2433, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be in a different file from a class or function with which it is merged" }, A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: { code: 2434, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be located prior to a class or function with which it is merged" }, - Ambient_modules_cannot_be_nested_in_other_modules: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules." }, + Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules or namespaces." }, Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." }, Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: 2437, category: ts.DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" }, Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" }, @@ -2289,6 +2433,9 @@ var ts; yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: ts.DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: ts.DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: ts.DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value." }, + A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface: { code: 2526, category: ts.DiagnosticCategory.Error, key: "A 'this' type is available only in a non-static member of a class or interface." }, + The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary: { code: 2527, category: ts.DiagnosticCategory.Error, key: "The inferred type of '{0}' references an inaccessible 'this' type. A type annotation is necessary." }, + A_module_cannot_have_multiple_default_exports: { code: 2528, category: ts.DiagnosticCategory.Error, key: "A module cannot have multiple default exports." }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: ts.DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: ts.DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, @@ -2389,7 +2536,7 @@ var ts; Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: ts.DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." }, Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." }, Option_0_cannot_be_specified_with_option_1: { code: 5053, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." }, - A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5053, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, + A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5054, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -2401,7 +2548,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, - Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" }, + Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -2422,7 +2569,7 @@ var ts; Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." }, + Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'." }, Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: ts.DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: ts.DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, @@ -2443,7 +2590,6 @@ var ts; Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, - Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, @@ -2490,7 +2636,9 @@ var ts; Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: ts.DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." }, JSX_attribute_expected: { code: 17003, category: ts.DiagnosticCategory.Error, key: "JSX attribute expected." }, Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: ts.DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." }, - A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" } + A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }, + An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17006, category: ts.DiagnosticCategory.Error, key: "An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, + A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." } }; })(ts || (ts = {})); /// @@ -2499,75 +2647,75 @@ var ts; (function (ts) { /* @internal */ function tokenIsIdentifierOrKeyword(token) { - return token >= 67 /* Identifier */; + return token >= 69 /* Identifier */; } ts.tokenIsIdentifierOrKeyword = tokenIsIdentifierOrKeyword; var textToToken = { - "abstract": 113 /* AbstractKeyword */, - "any": 115 /* AnyKeyword */, - "as": 114 /* AsKeyword */, - "boolean": 118 /* BooleanKeyword */, - "break": 68 /* BreakKeyword */, - "case": 69 /* CaseKeyword */, - "catch": 70 /* CatchKeyword */, - "class": 71 /* ClassKeyword */, - "continue": 73 /* ContinueKeyword */, - "const": 72 /* ConstKeyword */, - "constructor": 119 /* ConstructorKeyword */, - "debugger": 74 /* DebuggerKeyword */, - "declare": 120 /* DeclareKeyword */, - "default": 75 /* DefaultKeyword */, - "delete": 76 /* DeleteKeyword */, - "do": 77 /* DoKeyword */, - "else": 78 /* ElseKeyword */, - "enum": 79 /* EnumKeyword */, - "export": 80 /* ExportKeyword */, - "extends": 81 /* ExtendsKeyword */, - "false": 82 /* FalseKeyword */, - "finally": 83 /* FinallyKeyword */, - "for": 84 /* ForKeyword */, - "from": 131 /* FromKeyword */, - "function": 85 /* FunctionKeyword */, - "get": 121 /* GetKeyword */, - "if": 86 /* IfKeyword */, - "implements": 104 /* ImplementsKeyword */, - "import": 87 /* ImportKeyword */, - "in": 88 /* InKeyword */, - "instanceof": 89 /* InstanceOfKeyword */, - "interface": 105 /* InterfaceKeyword */, - "is": 122 /* IsKeyword */, - "let": 106 /* LetKeyword */, - "module": 123 /* ModuleKeyword */, - "namespace": 124 /* NamespaceKeyword */, - "new": 90 /* NewKeyword */, - "null": 91 /* NullKeyword */, - "number": 126 /* NumberKeyword */, - "package": 107 /* PackageKeyword */, - "private": 108 /* PrivateKeyword */, - "protected": 109 /* ProtectedKeyword */, - "public": 110 /* PublicKeyword */, - "require": 125 /* RequireKeyword */, - "return": 92 /* ReturnKeyword */, - "set": 127 /* SetKeyword */, - "static": 111 /* StaticKeyword */, - "string": 128 /* StringKeyword */, - "super": 93 /* SuperKeyword */, - "switch": 94 /* SwitchKeyword */, - "symbol": 129 /* SymbolKeyword */, - "this": 95 /* ThisKeyword */, - "throw": 96 /* ThrowKeyword */, - "true": 97 /* TrueKeyword */, - "try": 98 /* TryKeyword */, - "type": 130 /* TypeKeyword */, - "typeof": 99 /* TypeOfKeyword */, - "var": 100 /* VarKeyword */, - "void": 101 /* VoidKeyword */, - "while": 102 /* WhileKeyword */, - "with": 103 /* WithKeyword */, - "yield": 112 /* YieldKeyword */, - "async": 116 /* AsyncKeyword */, - "await": 117 /* AwaitKeyword */, - "of": 132 /* OfKeyword */, + "abstract": 115 /* AbstractKeyword */, + "any": 117 /* AnyKeyword */, + "as": 116 /* AsKeyword */, + "boolean": 120 /* BooleanKeyword */, + "break": 70 /* BreakKeyword */, + "case": 71 /* CaseKeyword */, + "catch": 72 /* CatchKeyword */, + "class": 73 /* ClassKeyword */, + "continue": 75 /* ContinueKeyword */, + "const": 74 /* ConstKeyword */, + "constructor": 121 /* ConstructorKeyword */, + "debugger": 76 /* DebuggerKeyword */, + "declare": 122 /* DeclareKeyword */, + "default": 77 /* DefaultKeyword */, + "delete": 78 /* DeleteKeyword */, + "do": 79 /* DoKeyword */, + "else": 80 /* ElseKeyword */, + "enum": 81 /* EnumKeyword */, + "export": 82 /* ExportKeyword */, + "extends": 83 /* ExtendsKeyword */, + "false": 84 /* FalseKeyword */, + "finally": 85 /* FinallyKeyword */, + "for": 86 /* ForKeyword */, + "from": 133 /* FromKeyword */, + "function": 87 /* FunctionKeyword */, + "get": 123 /* GetKeyword */, + "if": 88 /* IfKeyword */, + "implements": 106 /* ImplementsKeyword */, + "import": 89 /* ImportKeyword */, + "in": 90 /* InKeyword */, + "instanceof": 91 /* InstanceOfKeyword */, + "interface": 107 /* InterfaceKeyword */, + "is": 124 /* IsKeyword */, + "let": 108 /* LetKeyword */, + "module": 125 /* ModuleKeyword */, + "namespace": 126 /* NamespaceKeyword */, + "new": 92 /* NewKeyword */, + "null": 93 /* NullKeyword */, + "number": 128 /* NumberKeyword */, + "package": 109 /* PackageKeyword */, + "private": 110 /* PrivateKeyword */, + "protected": 111 /* ProtectedKeyword */, + "public": 112 /* PublicKeyword */, + "require": 127 /* RequireKeyword */, + "return": 94 /* ReturnKeyword */, + "set": 129 /* SetKeyword */, + "static": 113 /* StaticKeyword */, + "string": 130 /* StringKeyword */, + "super": 95 /* SuperKeyword */, + "switch": 96 /* SwitchKeyword */, + "symbol": 131 /* SymbolKeyword */, + "this": 97 /* ThisKeyword */, + "throw": 98 /* ThrowKeyword */, + "true": 99 /* TrueKeyword */, + "try": 100 /* TryKeyword */, + "type": 132 /* TypeKeyword */, + "typeof": 101 /* TypeOfKeyword */, + "var": 102 /* VarKeyword */, + "void": 103 /* VoidKeyword */, + "while": 104 /* WhileKeyword */, + "with": 105 /* WithKeyword */, + "yield": 114 /* YieldKeyword */, + "async": 118 /* AsyncKeyword */, + "await": 119 /* AwaitKeyword */, + "of": 134 /* OfKeyword */, "{": 15 /* OpenBraceToken */, "}": 16 /* CloseBraceToken */, "(": 17 /* OpenParenToken */, @@ -2589,37 +2737,39 @@ var ts; "=>": 34 /* EqualsGreaterThanToken */, "+": 35 /* PlusToken */, "-": 36 /* MinusToken */, + "**": 38 /* AsteriskAsteriskToken */, "*": 37 /* AsteriskToken */, - "/": 38 /* SlashToken */, - "%": 39 /* PercentToken */, - "++": 40 /* PlusPlusToken */, - "--": 41 /* MinusMinusToken */, - "<<": 42 /* LessThanLessThanToken */, + "/": 39 /* SlashToken */, + "%": 40 /* PercentToken */, + "++": 41 /* PlusPlusToken */, + "--": 42 /* MinusMinusToken */, + "<<": 43 /* LessThanLessThanToken */, ">": 43 /* GreaterThanGreaterThanToken */, - ">>>": 44 /* GreaterThanGreaterThanGreaterThanToken */, - "&": 45 /* AmpersandToken */, - "|": 46 /* BarToken */, - "^": 47 /* CaretToken */, - "!": 48 /* ExclamationToken */, - "~": 49 /* TildeToken */, - "&&": 50 /* AmpersandAmpersandToken */, - "||": 51 /* BarBarToken */, - "?": 52 /* QuestionToken */, - ":": 53 /* ColonToken */, - "=": 55 /* EqualsToken */, - "+=": 56 /* PlusEqualsToken */, - "-=": 57 /* MinusEqualsToken */, - "*=": 58 /* AsteriskEqualsToken */, - "/=": 59 /* SlashEqualsToken */, - "%=": 60 /* PercentEqualsToken */, - "<<=": 61 /* LessThanLessThanEqualsToken */, - ">>=": 62 /* GreaterThanGreaterThanEqualsToken */, - ">>>=": 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */, - "&=": 64 /* AmpersandEqualsToken */, - "|=": 65 /* BarEqualsToken */, - "^=": 66 /* CaretEqualsToken */, - "@": 54 /* AtToken */ + ">>": 44 /* GreaterThanGreaterThanToken */, + ">>>": 45 /* GreaterThanGreaterThanGreaterThanToken */, + "&": 46 /* AmpersandToken */, + "|": 47 /* BarToken */, + "^": 48 /* CaretToken */, + "!": 49 /* ExclamationToken */, + "~": 50 /* TildeToken */, + "&&": 51 /* AmpersandAmpersandToken */, + "||": 52 /* BarBarToken */, + "?": 53 /* QuestionToken */, + ":": 54 /* ColonToken */, + "=": 56 /* EqualsToken */, + "+=": 57 /* PlusEqualsToken */, + "-=": 58 /* MinusEqualsToken */, + "*=": 59 /* AsteriskEqualsToken */, + "**=": 60 /* AsteriskAsteriskEqualsToken */, + "/=": 61 /* SlashEqualsToken */, + "%=": 62 /* PercentEqualsToken */, + "<<=": 63 /* LessThanLessThanEqualsToken */, + ">>=": 64 /* GreaterThanGreaterThanEqualsToken */, + ">>>=": 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */, + "&=": 66 /* AmpersandEqualsToken */, + "|=": 67 /* BarEqualsToken */, + "^=": 68 /* CaretEqualsToken */, + "@": 55 /* AtToken */ }; /* As per ECMAScript Language Specification 3th Edition, Section 7.6: Identifiers @@ -3123,8 +3273,8 @@ var ts; getTokenValue: function () { return tokenValue; }, hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, - isIdentifier: function () { return token === 67 /* Identifier */ || token > 103 /* LastReservedWord */; }, - isReservedWord: function () { return token >= 68 /* FirstReservedWord */ && token <= 103 /* LastReservedWord */; }, + isIdentifier: function () { return token === 69 /* Identifier */ || token > 105 /* LastReservedWord */; }, + isReservedWord: function () { return token >= 70 /* FirstReservedWord */ && token <= 105 /* LastReservedWord */; }, isUnterminated: function () { return tokenIsUnterminated; }, reScanGreaterToken: reScanGreaterToken, reScanSlashToken: reScanSlashToken, @@ -3146,16 +3296,6 @@ var ts; onError(message, length || 0); } } - function isIdentifierStart(ch) { - return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || - ch === 36 /* $ */ || ch === 95 /* _ */ || - ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); - } - function isIdentifierPart(ch) { - return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || - ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || - ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion); - } function scanNumber() { var start = pos; while (isDigit(text.charCodeAt(pos))) @@ -3438,12 +3578,12 @@ var ts; var start = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (isIdentifierPart(ch)) { + if (isIdentifierPart(ch, languageVersion)) { pos++; } else if (ch === 92 /* backslash */) { ch = peekUnicodeEscape(); - if (!(ch >= 0 && isIdentifierPart(ch))) { + if (!(ch >= 0 && isIdentifierPart(ch, languageVersion))) { break; } result += text.substring(start, pos); @@ -3468,7 +3608,7 @@ var ts; return token = textToToken[tokenValue]; } } - return token = 67 /* Identifier */; + return token = 69 /* Identifier */; } function scanBinaryOrOctalDigits(base) { ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8"); @@ -3552,7 +3692,7 @@ var ts; } return pos += 2, token = 31 /* ExclamationEqualsToken */; } - return pos++, token = 48 /* ExclamationToken */; + return pos++, token = 49 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); @@ -3561,42 +3701,48 @@ var ts; return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 60 /* PercentEqualsToken */; + return pos += 2, token = 62 /* PercentEqualsToken */; } - return pos++, token = 39 /* PercentToken */; + return pos++, token = 40 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { - return pos += 2, token = 50 /* AmpersandAmpersandToken */; + return pos += 2, token = 51 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 64 /* AmpersandEqualsToken */; + return pos += 2, token = 66 /* AmpersandEqualsToken */; } - return pos++, token = 45 /* AmpersandToken */; + return pos++, token = 46 /* AmpersandToken */; case 40 /* openParen */: return pos++, token = 17 /* OpenParenToken */; case 41 /* closeParen */: return pos++, token = 18 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 58 /* AsteriskEqualsToken */; + return pos += 2, token = 59 /* AsteriskEqualsToken */; + } + if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { + if (text.charCodeAt(pos + 2) === 61 /* equals */) { + return pos += 3, token = 60 /* AsteriskAsteriskEqualsToken */; + } + return pos += 2, token = 38 /* AsteriskAsteriskToken */; } return pos++, token = 37 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { - return pos += 2, token = 40 /* PlusPlusToken */; + return pos += 2, token = 41 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 56 /* PlusEqualsToken */; + return pos += 2, token = 57 /* PlusEqualsToken */; } return pos++, token = 35 /* PlusToken */; case 44 /* comma */: return pos++, token = 24 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { - return pos += 2, token = 41 /* MinusMinusToken */; + return pos += 2, token = 42 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 57 /* MinusEqualsToken */; + return pos += 2, token = 58 /* MinusEqualsToken */; } return pos++, token = 36 /* MinusToken */; case 46 /* dot */: @@ -3653,9 +3799,9 @@ var ts; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 59 /* SlashEqualsToken */; + return pos += 2, token = 61 /* SlashEqualsToken */; } - return pos++, token = 38 /* SlashToken */; + return pos++, token = 39 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; @@ -3707,7 +3853,7 @@ var ts; tokenValue = "" + scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: - return pos++, token = 53 /* ColonToken */; + return pos++, token = 54 /* ColonToken */; case 59 /* semicolon */: return pos++, token = 23 /* SemicolonToken */; case 60 /* lessThan */: @@ -3722,14 +3868,16 @@ var ts; } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { - return pos += 3, token = 61 /* LessThanLessThanEqualsToken */; + return pos += 3, token = 63 /* LessThanLessThanEqualsToken */; } - return pos += 2, token = 42 /* LessThanLessThanToken */; + return pos += 2, token = 43 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 28 /* LessThanEqualsToken */; } - if (text.charCodeAt(pos + 1) === 47 /* slash */ && languageVariant === 1 /* JSX */) { + if (languageVariant === 1 /* JSX */ && + text.charCodeAt(pos + 1) === 47 /* slash */ && + text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 26 /* LessThanSlashToken */; } return pos++, token = 25 /* LessThanToken */; @@ -3752,7 +3900,7 @@ var ts; if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 34 /* EqualsGreaterThanToken */; } - return pos++, token = 55 /* EqualsToken */; + return pos++, token = 56 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -3765,35 +3913,35 @@ var ts; } return pos++, token = 27 /* GreaterThanToken */; case 63 /* question */: - return pos++, token = 52 /* QuestionToken */; + return pos++, token = 53 /* QuestionToken */; case 91 /* openBracket */: return pos++, token = 19 /* OpenBracketToken */; case 93 /* closeBracket */: return pos++, token = 20 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 66 /* CaretEqualsToken */; + return pos += 2, token = 68 /* CaretEqualsToken */; } - return pos++, token = 47 /* CaretToken */; + return pos++, token = 48 /* CaretToken */; case 123 /* openBrace */: return pos++, token = 15 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { - return pos += 2, token = 51 /* BarBarToken */; + return pos += 2, token = 52 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 65 /* BarEqualsToken */; + return pos += 2, token = 67 /* BarEqualsToken */; } - return pos++, token = 46 /* BarToken */; + return pos++, token = 47 /* BarToken */; case 125 /* closeBrace */: return pos++, token = 16 /* CloseBraceToken */; case 126 /* tilde */: - return pos++, token = 49 /* TildeToken */; + return pos++, token = 50 /* TildeToken */; case 64 /* at */: - return pos++, token = 54 /* AtToken */; + return pos++, token = 55 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); - if (cookedChar >= 0 && isIdentifierStart(cookedChar)) { + if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); @@ -3801,9 +3949,9 @@ var ts; error(ts.Diagnostics.Invalid_character); return pos++, token = 0 /* Unknown */; default: - if (isIdentifierStart(ch)) { + if (isIdentifierStart(ch, languageVersion)) { pos++; - while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos))) + while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { @@ -3830,14 +3978,14 @@ var ts; if (text.charCodeAt(pos) === 62 /* greaterThan */) { if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { - return pos += 3, token = 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */; + return pos += 3, token = 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */; } - return pos += 2, token = 44 /* GreaterThanGreaterThanGreaterThanToken */; + return pos += 2, token = 45 /* GreaterThanGreaterThanGreaterThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 62 /* GreaterThanGreaterThanEqualsToken */; + return pos += 2, token = 64 /* GreaterThanGreaterThanEqualsToken */; } - return pos++, token = 43 /* GreaterThanGreaterThanToken */; + return pos++, token = 44 /* GreaterThanGreaterThanToken */; } if (text.charCodeAt(pos) === 61 /* equals */) { return pos++, token = 29 /* GreaterThanEqualsToken */; @@ -3846,7 +3994,7 @@ var ts; return token; } function reScanSlashToken() { - if (token === 38 /* SlashToken */ || token === 59 /* SlashEqualsToken */) { + if (token === 39 /* SlashToken */ || token === 61 /* SlashEqualsToken */) { var p = tokenPos + 1; var inEscape = false; var inCharacterClass = false; @@ -3886,7 +4034,7 @@ var ts; } p++; } - while (p < end && isIdentifierPart(text.charCodeAt(p))) { + while (p < end && isIdentifierPart(text.charCodeAt(p), languageVersion)) { p++; } pos = p; @@ -3932,7 +4080,7 @@ var ts; break; } } - return token = 234 /* JsxText */; + return token = 236 /* JsxText */; } // Scans a JSX identifier; these differ from normal identifiers in that // they allow dashes @@ -3941,7 +4089,7 @@ var ts; var firstCharPosition = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (ch === 45 /* minus */ || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) { + if (ch === 45 /* minus */ || ((firstCharPosition === pos) ? isIdentifierStart(ch, languageVersion) : isIdentifierPart(ch, languageVersion))) { pos++; } else { @@ -4020,16 +4168,16 @@ var ts; function getModuleInstanceState(node) { // A module is uninstantiated if it contains only // 1. interface declarations, type alias declarations - if (node.kind === 213 /* InterfaceDeclaration */ || node.kind === 214 /* TypeAliasDeclaration */) { + if (node.kind === 215 /* InterfaceDeclaration */ || node.kind === 216 /* TypeAliasDeclaration */) { return 0 /* NonInstantiated */; } else if (ts.isConstEnumDeclaration(node)) { return 2 /* ConstEnumOnly */; } - else if ((node.kind === 220 /* ImportDeclaration */ || node.kind === 219 /* ImportEqualsDeclaration */) && !(node.flags & 1 /* Export */)) { + else if ((node.kind === 222 /* ImportDeclaration */ || node.kind === 221 /* ImportEqualsDeclaration */) && !(node.flags & 1 /* Export */)) { return 0 /* NonInstantiated */; } - else if (node.kind === 217 /* ModuleBlock */) { + else if (node.kind === 219 /* ModuleBlock */) { var state = 0 /* NonInstantiated */; ts.forEachChild(node, function (n) { switch (getModuleInstanceState(n)) { @@ -4048,7 +4196,7 @@ var ts; }); return state; } - else if (node.kind === 216 /* ModuleDeclaration */) { + else if (node.kind === 218 /* ModuleDeclaration */) { return getModuleInstanceState(node.body); } else { @@ -4088,6 +4236,7 @@ var ts; var container; var blockScopeContainer; var lastContainer; + var seenThisKeyword; // If this file is an external module, then it is automatically in strict-mode according to // ES6. If it is not an external module, then we'll determine if it is in strict mode or // not depending on if we see "use strict" in certain places (or if we hit a class/namespace). @@ -4126,10 +4275,10 @@ var ts; // unless it is a well known Symbol. function getDeclarationName(node) { if (node.name) { - if (node.kind === 216 /* ModuleDeclaration */ && node.name.kind === 9 /* StringLiteral */) { + if (node.kind === 218 /* ModuleDeclaration */ && node.name.kind === 9 /* StringLiteral */) { return "\"" + node.name.text + "\""; } - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { var nameExpression = node.name.expression; ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression)); return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text); @@ -4137,22 +4286,22 @@ var ts; return node.name.text; } switch (node.kind) { - case 142 /* Constructor */: + case 144 /* Constructor */: return "__constructor"; - case 150 /* FunctionType */: - case 145 /* CallSignature */: + case 152 /* FunctionType */: + case 147 /* CallSignature */: return "__call"; - case 151 /* ConstructorType */: - case 146 /* ConstructSignature */: + case 153 /* ConstructorType */: + case 148 /* ConstructSignature */: return "__new"; - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: return "__index"; - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return "__export"; - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return node.isExportEquals ? "export=" : "default"; - case 211 /* FunctionDeclaration */: - case 212 /* ClassDeclaration */: + case 213 /* FunctionDeclaration */: + case 214 /* ClassDeclaration */: return node.flags & 1024 /* Default */ ? "default" : undefined; } } @@ -4169,8 +4318,9 @@ var ts; */ function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); + var isDefaultExport = node.flags & 1024 /* Default */; // The exported symbol for an export default function/class node is always named "default" - var name = node.flags & 1024 /* Default */ && parent ? "default" : getDeclarationName(node); + var name = isDefaultExport && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { // Check and see if the symbol table already has a symbol with this name. If not, @@ -4206,6 +4356,11 @@ var ts; var message = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + ts.forEach(symbol.declarations, function (declaration) { + if (declaration.flags & 1024 /* Default */) { + message = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + } + }); ts.forEach(symbol.declarations, function (declaration) { file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); @@ -4223,7 +4378,7 @@ var ts; function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1 /* Export */; if (symbolFlags & 8388608 /* Alias */) { - if (node.kind === 228 /* ExportSpecifier */ || (node.kind === 219 /* ImportEqualsDeclaration */ && hasExportModifier)) { + if (node.kind === 230 /* ExportSpecifier */ || (node.kind === 221 /* ImportEqualsDeclaration */ && hasExportModifier)) { return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { @@ -4297,44 +4452,51 @@ var ts; blockScopeContainer = node; blockScopeContainer.locals = undefined; } - ts.forEachChild(node, bind); + if (node.kind === 215 /* InterfaceDeclaration */) { + seenThisKeyword = false; + ts.forEachChild(node, bind); + node.flags = seenThisKeyword ? node.flags | 524288 /* ContainsThis */ : node.flags & ~524288 /* ContainsThis */; + } + else { + ts.forEachChild(node, bind); + } container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } function getContainerFlags(node) { switch (node.kind) { - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 153 /* TypeLiteral */: - case 163 /* ObjectLiteralExpression */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 155 /* TypeLiteral */: + case 165 /* ObjectLiteralExpression */: return 1 /* IsContainer */; - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 211 /* FunctionDeclaration */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 216 /* ModuleDeclaration */: - case 246 /* SourceFile */: - case 214 /* TypeAliasDeclaration */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 218 /* ModuleDeclaration */: + case 248 /* SourceFile */: + case 216 /* TypeAliasDeclaration */: return 5 /* IsContainerWithLocals */; - case 242 /* CatchClause */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 218 /* CaseBlock */: + case 244 /* CatchClause */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 220 /* CaseBlock */: return 2 /* IsBlockScopedContainer */; - case 190 /* Block */: + case 192 /* Block */: // do not treat blocks directly inside a function as a block-scoped-container. // Locals that reside in this block should go to the function locals. Othewise 'x' // would not appear to be a redeclaration of a block scoped local in the following @@ -4371,38 +4533,38 @@ var ts; // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); - case 153 /* TypeLiteral */: - case 163 /* ObjectLiteralExpression */: - case 213 /* InterfaceDeclaration */: + case 155 /* TypeLiteral */: + case 165 /* ObjectLiteralExpression */: + case 215 /* InterfaceDeclaration */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 214 /* TypeAliasDeclaration */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 216 /* TypeAliasDeclaration */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath @@ -4432,11 +4594,11 @@ var ts; return false; } function hasExportDeclarations(node) { - var body = node.kind === 246 /* SourceFile */ ? node : node.body; - if (body.kind === 246 /* SourceFile */ || body.kind === 217 /* ModuleBlock */) { + var body = node.kind === 248 /* SourceFile */ ? node : node.body; + if (body.kind === 248 /* SourceFile */ || body.kind === 219 /* ModuleBlock */) { for (var _i = 0, _a = body.statements; _i < _a.length; _i++) { var stat = _a[_i]; - if (stat.kind === 226 /* ExportDeclaration */ || stat.kind === 225 /* ExportAssignment */) { + if (stat.kind === 228 /* ExportDeclaration */ || stat.kind === 227 /* ExportAssignment */) { return true; } } @@ -4508,7 +4670,7 @@ var ts; var seen = {}; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - if (prop.name.kind !== 67 /* Identifier */) { + if (prop.name.kind !== 69 /* Identifier */) { continue; } var identifier = prop.name; @@ -4520,7 +4682,7 @@ var ts; // c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true. // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields - var currentKind = prop.kind === 243 /* PropertyAssignment */ || prop.kind === 244 /* ShorthandPropertyAssignment */ || prop.kind === 141 /* MethodDeclaration */ + var currentKind = prop.kind === 245 /* PropertyAssignment */ || prop.kind === 246 /* ShorthandPropertyAssignment */ || prop.kind === 143 /* MethodDeclaration */ ? 1 /* Property */ : 2 /* Accessor */; var existingKind = seen[identifier.text]; @@ -4542,10 +4704,10 @@ var ts; } function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: declareModuleMember(node, symbolFlags, symbolExcludes); break; - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolFlags, symbolExcludes); break; @@ -4566,8 +4728,8 @@ var ts; // check for reserved words used as identifiers in strict mode code. function checkStrictModeIdentifier(node) { if (inStrictMode && - node.originalKeywordKind >= 104 /* FirstFutureReservedWord */ && - node.originalKeywordKind <= 112 /* LastFutureReservedWord */ && + node.originalKeywordKind >= 106 /* FirstFutureReservedWord */ && + node.originalKeywordKind <= 114 /* LastFutureReservedWord */ && !ts.isIdentifierName(node)) { // Report error only if there are no parse errors in file if (!file.parseDiagnostics.length) { @@ -4602,7 +4764,7 @@ var ts; } function checkStrictModeDeleteExpression(node) { // Grammar checking - if (inStrictMode && node.expression.kind === 67 /* Identifier */) { + if (inStrictMode && node.expression.kind === 69 /* Identifier */) { // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its // UnaryExpression is a direct reference to a variable, function argument, or function name var span = ts.getErrorSpanForNode(file, node.expression); @@ -4610,11 +4772,11 @@ var ts; } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 /* Identifier */ && + return node.kind === 69 /* Identifier */ && (node.text === "eval" || node.text === "arguments"); } function checkStrictModeEvalOrArguments(contextNode, name) { - if (name && name.kind === 67 /* Identifier */) { + if (name && name.kind === 69 /* Identifier */) { var identifier = name; if (isEvalOrArgumentsIdentifier(identifier)) { // We check first if the name is inside class declaration or class expression; if so give explicit message @@ -4658,7 +4820,7 @@ var ts; function checkStrictModePrefixUnaryExpression(node) { // Grammar checking if (inStrictMode) { - if (node.operator === 40 /* PlusPlusToken */ || node.operator === 41 /* MinusMinusToken */) { + if (node.operator === 41 /* PlusPlusToken */ || node.operator === 42 /* MinusMinusToken */) { checkStrictModeEvalOrArguments(node, node.operand); } } @@ -4702,17 +4864,17 @@ var ts; } function updateStrictMode(node) { switch (node.kind) { - case 246 /* SourceFile */: - case 217 /* ModuleBlock */: + case 248 /* SourceFile */: + case 219 /* ModuleBlock */: updateStrictModeStatementList(node.statements); return; - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionLike(node.parent)) { updateStrictModeStatementList(node.statements); } return; - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return; @@ -4739,92 +4901,95 @@ var ts; } function bindWorker(node) { switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: return checkStrictModeIdentifier(node); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return checkStrictModeBinaryExpression(node); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return checkStrictModeCatchClause(node); - case 173 /* DeleteExpression */: + case 175 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); - case 178 /* PostfixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); - case 203 /* WithStatement */: + case 205 /* WithStatement */: return checkStrictModeWithStatement(node); - case 135 /* TypeParameter */: + case 97 /* ThisKeyword */: + seenThisKeyword = true; + return; + case 137 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */); - case 136 /* Parameter */: + case 138 /* Parameter */: return bindParameter(node); - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); - case 243 /* PropertyAssignment */: - case 244 /* ShorthandPropertyAssignment */: + case 245 /* PropertyAssignment */: + case 246 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: checkStrictModeFunctionName(node); return declareSymbolAndAddToSymbolTable(node, 16 /* Function */, 106927 /* FunctionExcludes */); - case 142 /* Constructor */: + case 144 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); - case 144 /* SetAccessor */: + case 146 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return bindFunctionOrConstructorType(node); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: checkStrictModeFunctionName(node); var bindingName = node.name ? node.name.text : "__function"; return bindAnonymousDeclaration(node, 16 /* Function */, bindingName); - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: return bindClassLikeDeclaration(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792960 /* InterfaceExcludes */); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return bindEnumDeclaration(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return bindModuleDeclaration(node); - case 219 /* ImportEqualsDeclaration */: - case 222 /* NamespaceImport */: - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 224 /* NamespaceImport */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); - case 221 /* ImportClause */: + case 223 /* ImportClause */: return bindImportClause(node); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return bindExportDeclaration(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return bindExportAssignment(node); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return bindSourceFileIfExternalModule(); } } @@ -4839,7 +5004,7 @@ var ts; // Export assignment in some sort of block construct bindAnonymousDeclaration(node, 8388608 /* Alias */, getDeclarationName(node)); } - else if (node.expression.kind === 67 /* Identifier */) { + else if (node.expression.kind === 69 /* Identifier */) { // An export default clause with an identifier exports all meanings of that identifier declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } @@ -4864,7 +5029,7 @@ var ts; } } function bindClassLikeDeclaration(node) { - if (node.kind === 212 /* ClassDeclaration */) { + if (node.kind === 214 /* ClassDeclaration */) { bindBlockScopedDeclaration(node, 32 /* Class */, 899519 /* ClassExcludes */); } else { @@ -4940,7 +5105,7 @@ var ts; // If this is a property-parameter, then also declare the property symbol into the // containing class. if (node.flags & 112 /* AccessibilityModifier */ && - node.parent.kind === 142 /* Constructor */ && + node.parent.kind === 144 /* Constructor */ && ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); @@ -4992,7 +5157,8 @@ var ts; increaseIndent: function () { }, decreaseIndent: function () { }, clear: function () { return str = ""; }, - trackSymbol: function () { } + trackSymbol: function () { }, + reportInaccessibleThisError: function () { } }; } return stringWriters.pop(); @@ -5062,7 +5228,7 @@ var ts; } } function getSourceFileOfNode(node) { - while (node && node.kind !== 246 /* SourceFile */) { + while (node && node.kind !== 248 /* SourceFile */) { node = node.parent; } return node; @@ -5174,15 +5340,15 @@ var ts; return current; } switch (current.kind) { - case 246 /* SourceFile */: - case 218 /* CaseBlock */: - case 242 /* CatchClause */: - case 216 /* ModuleDeclaration */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 248 /* SourceFile */: + case 220 /* CaseBlock */: + case 244 /* CatchClause */: + case 218 /* ModuleDeclaration */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return current; - case 190 /* Block */: + case 192 /* Block */: // function block is not considered block-scope container // see comment in binder.ts: bind(...), case for SyntaxKind.Block if (!isFunctionLike(current.parent)) { @@ -5195,9 +5361,9 @@ var ts; ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer; function isCatchClauseVariableDeclaration(declaration) { return declaration && - declaration.kind === 209 /* VariableDeclaration */ && + declaration.kind === 211 /* VariableDeclaration */ && declaration.parent && - declaration.parent.kind === 242 /* CatchClause */; + declaration.parent.kind === 244 /* CatchClause */; } ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; // Return display name of an identifier @@ -5236,7 +5402,7 @@ var ts; function getErrorSpanForNode(sourceFile, node) { var errorNode = node; switch (node.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: var pos_1 = ts.skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false); if (pos_1 === sourceFile.text.length) { // file is empty - return span for the beginning of the file @@ -5245,16 +5411,16 @@ var ts; return getSpanOfTokenAtPosition(sourceFile, pos_1); // This list is a work in progress. Add missing node kinds to improve their error // spans. - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 216 /* ModuleDeclaration */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 218 /* ModuleDeclaration */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: errorNode = node.name; break; } @@ -5278,11 +5444,11 @@ var ts; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { - return node.kind === 215 /* EnumDeclaration */ && isConst(node); + return node.kind === 217 /* EnumDeclaration */ && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; function walkUpBindingElementsAndPatterns(node) { - while (node && (node.kind === 161 /* BindingElement */ || isBindingPattern(node))) { + while (node && (node.kind === 163 /* BindingElement */ || isBindingPattern(node))) { node = node.parent; } return node; @@ -5297,14 +5463,14 @@ var ts; function getCombinedNodeFlags(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; - if (node.kind === 209 /* VariableDeclaration */) { + if (node.kind === 211 /* VariableDeclaration */) { node = node.parent; } - if (node && node.kind === 210 /* VariableDeclarationList */) { + if (node && node.kind === 212 /* VariableDeclarationList */) { flags |= node.flags; node = node.parent; } - if (node && node.kind === 191 /* VariableStatement */) { + if (node && node.kind === 193 /* VariableStatement */) { flags |= node.flags; } return flags; @@ -5319,7 +5485,7 @@ var ts; } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 193 /* ExpressionStatement */ && node.expression.kind === 9 /* StringLiteral */; + return node.kind === 195 /* ExpressionStatement */ && node.expression.kind === 9 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { @@ -5327,7 +5493,7 @@ var ts; } ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - var commentRanges = (node.kind === 136 /* Parameter */ || node.kind === 135 /* TypeParameter */) ? + var commentRanges = (node.kind === 138 /* Parameter */ || node.kind === 137 /* TypeParameter */) ? ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) : getLeadingCommentRangesOfNode(node, sourceFileOfNode); return ts.filter(commentRanges, isJsDocComment); @@ -5342,40 +5508,40 @@ var ts; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; ts.fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*/; function isTypeNode(node) { - if (149 /* FirstTypeNode */ <= node.kind && node.kind <= 158 /* LastTypeNode */) { + if (151 /* FirstTypeNode */ <= node.kind && node.kind <= 160 /* LastTypeNode */) { return true; } switch (node.kind) { - case 115 /* AnyKeyword */: - case 126 /* NumberKeyword */: - case 128 /* StringKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: + case 117 /* AnyKeyword */: + case 128 /* NumberKeyword */: + case 130 /* StringKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: return true; - case 101 /* VoidKeyword */: - return node.parent.kind !== 175 /* VoidExpression */; + case 103 /* VoidKeyword */: + return node.parent.kind !== 177 /* VoidExpression */; case 9 /* StringLiteral */: // Specialized signatures can have string literals as their parameters' type names - return node.parent.kind === 136 /* Parameter */; - case 186 /* ExpressionWithTypeArguments */: + return node.parent.kind === 138 /* Parameter */; + case 188 /* ExpressionWithTypeArguments */: return !isExpressionWithTypeArgumentsInClassExtendsClause(node); // Identifiers and qualified names may be type nodes, depending on their context. Climb // above them to find the lowest container - case 67 /* Identifier */: + case 69 /* Identifier */: // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. - if (node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node) { + if (node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node) { node = node.parent; } - else if (node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node) { + else if (node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.name === node) { node = node.parent; } - // fall through - case 133 /* QualifiedName */: - case 164 /* PropertyAccessExpression */: // At this point, node is either a qualified name or an identifier - ts.Debug.assert(node.kind === 67 /* Identifier */ || node.kind === 133 /* QualifiedName */ || node.kind === 164 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + ts.Debug.assert(node.kind === 69 /* Identifier */ || node.kind === 135 /* QualifiedName */ || node.kind === 166 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + case 135 /* QualifiedName */: + case 166 /* PropertyAccessExpression */: + case 97 /* ThisKeyword */: var parent_1 = node.parent; - if (parent_1.kind === 152 /* TypeQuery */) { + if (parent_1.kind === 154 /* TypeQuery */) { return false; } // Do not recursively call isTypeNode on the parent. In the example: @@ -5384,38 +5550,38 @@ var ts; // // Calling isTypeNode would consider the qualified name A.B a type node. Only C or // A.B.C is a type node. - if (149 /* FirstTypeNode */ <= parent_1.kind && parent_1.kind <= 158 /* LastTypeNode */) { + if (151 /* FirstTypeNode */ <= parent_1.kind && parent_1.kind <= 160 /* LastTypeNode */) { return true; } switch (parent_1.kind) { - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return !isExpressionWithTypeArgumentsInClassExtendsClause(parent_1); - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: return node === parent_1.constraint; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 136 /* Parameter */: - case 209 /* VariableDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 138 /* Parameter */: + case 211 /* VariableDeclaration */: return node === parent_1.type; - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 142 /* Constructor */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 144 /* Constructor */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return node === parent_1.type; - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return node === parent_1.type; - case 169 /* TypeAssertionExpression */: + case 171 /* TypeAssertionExpression */: return node === parent_1.type; - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. return false; } @@ -5429,23 +5595,23 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: return visitor(node); - case 218 /* CaseBlock */: - case 190 /* Block */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 203 /* WithStatement */: - case 204 /* SwitchStatement */: - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - case 205 /* LabeledStatement */: - case 207 /* TryStatement */: - case 242 /* CatchClause */: + case 220 /* CaseBlock */: + case 192 /* Block */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 205 /* WithStatement */: + case 206 /* SwitchStatement */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + case 207 /* LabeledStatement */: + case 209 /* TryStatement */: + case 244 /* CatchClause */: return ts.forEachChild(node, traverse); } } @@ -5455,18 +5621,18 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: visitor(node); var operand = node.expression; if (operand) { traverse(operand); } - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: - case 216 /* ModuleDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: + case 218 /* ModuleDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // These are not allowed inside a generator now, but eventually they may be allowed // as local types. Regardless, any yield statements contained within them should be // skipped in this traversal. @@ -5474,7 +5640,7 @@ var ts; default: if (isFunctionLike(node)) { var name_5 = node.name; - if (name_5 && name_5.kind === 134 /* ComputedPropertyName */) { + if (name_5 && name_5.kind === 136 /* ComputedPropertyName */) { // Note that we will not include methods/accessors of a class because they would require // first descending into the class. This is by design. traverse(name_5.expression); @@ -5493,14 +5659,14 @@ var ts; function isVariableLike(node) { if (node) { switch (node.kind) { - case 161 /* BindingElement */: - case 245 /* EnumMember */: - case 136 /* Parameter */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 244 /* ShorthandPropertyAssignment */: - case 209 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 247 /* EnumMember */: + case 138 /* Parameter */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 246 /* ShorthandPropertyAssignment */: + case 211 /* VariableDeclaration */: return true; } } @@ -5508,29 +5674,29 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - return node && (node.kind === 143 /* GetAccessor */ || node.kind === 144 /* SetAccessor */); + return node && (node.kind === 145 /* GetAccessor */ || node.kind === 146 /* SetAccessor */); } ts.isAccessor = isAccessor; function isClassLike(node) { - return node && (node.kind === 212 /* ClassDeclaration */ || node.kind === 184 /* ClassExpression */); + return node && (node.kind === 214 /* ClassDeclaration */ || node.kind === 186 /* ClassExpression */); } ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { - case 142 /* Constructor */: - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 144 /* Constructor */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return true; } } @@ -5539,24 +5705,24 @@ var ts; ts.isFunctionLike = isFunctionLike; function introducesArgumentsExoticObject(node) { switch (node.kind) { - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: return true; } return false; } ts.introducesArgumentsExoticObject = introducesArgumentsExoticObject; function isFunctionBlock(node) { - return node && node.kind === 190 /* Block */ && isFunctionLike(node.parent); + return node && node.kind === 192 /* Block */ && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { - return node && node.kind === 141 /* MethodDeclaration */ && node.parent.kind === 163 /* ObjectLiteralExpression */; + return node && node.kind === 143 /* MethodDeclaration */ && node.parent.kind === 165 /* ObjectLiteralExpression */; } ts.isObjectLiteralMethod = isObjectLiteralMethod; function getContainingFunction(node) { @@ -5584,7 +5750,7 @@ var ts; return undefined; } switch (node.kind) { - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: // If the grandparent node is an object literal (as opposed to a class), // then the computed property is not a 'this' container. // A computed property name in a class needs to be a this container @@ -5599,9 +5765,9 @@ var ts; // the *body* of the container. node = node.parent; break; - case 137 /* Decorator */: + case 139 /* Decorator */: // Decorators are always applied outside of the body of a class or method. - if (node.parent.kind === 136 /* Parameter */ && isClassElement(node.parent.parent)) { + if (node.parent.kind === 138 /* Parameter */ && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. node = node.parent.parent; @@ -5612,23 +5778,26 @@ var ts; node = node.parent; } break; - case 172 /* ArrowFunction */: + case 174 /* ArrowFunction */: if (!includeArrowFunctions) { continue; } // Fall through - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 216 /* ModuleDeclaration */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 215 /* EnumDeclaration */: - case 246 /* SourceFile */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 218 /* ModuleDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 217 /* EnumDeclaration */: + case 248 /* SourceFile */: return node; } } @@ -5640,7 +5809,7 @@ var ts; if (!node) return node; switch (node.kind) { - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: // If the grandparent node is an object literal (as opposed to a class), // then the computed property is not a 'super' container. // A computed property name in a class needs to be a super container @@ -5655,9 +5824,9 @@ var ts; // the *body* of the container. node = node.parent; break; - case 137 /* Decorator */: + case 139 /* Decorator */: // Decorators are always applied outside of the body of a class or method. - if (node.parent.kind === 136 /* Parameter */ && isClassElement(node.parent.parent)) { + if (node.parent.kind === 138 /* Parameter */ && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. node = node.parent.parent; @@ -5668,19 +5837,19 @@ var ts; node = node.parent; } break; - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: if (!includeFunctions) { continue; } - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return node; } } @@ -5689,12 +5858,12 @@ var ts; function getEntityNameFromTypeNode(node) { if (node) { switch (node.kind) { - case 149 /* TypeReference */: + case 151 /* TypeReference */: return node.typeName; - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return node.expression; - case 67 /* Identifier */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 135 /* QualifiedName */: return node; } } @@ -5702,7 +5871,7 @@ var ts; } ts.getEntityNameFromTypeNode = getEntityNameFromTypeNode; function getInvokedExpression(node) { - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { return node.tag; } // Will either be a CallExpression, NewExpression, or Decorator. @@ -5711,44 +5880,44 @@ var ts; ts.getInvokedExpression = getInvokedExpression; function nodeCanBeDecorated(node) { switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: // classes are valid targets return true; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: // property declarations are valid if their parent is a class declaration. - return node.parent.kind === 212 /* ClassDeclaration */; - case 136 /* Parameter */: + return node.parent.kind === 214 /* ClassDeclaration */; + case 138 /* Parameter */: // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target; - return node.parent.body && node.parent.parent.kind === 212 /* ClassDeclaration */; - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 141 /* MethodDeclaration */: + return node.parent.body && node.parent.parent.kind === 214 /* ClassDeclaration */; + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 143 /* MethodDeclaration */: // if this method has a body and its parent is a class declaration, this is a valid target. - return node.body && node.parent.kind === 212 /* ClassDeclaration */; + return node.body && node.parent.kind === 214 /* ClassDeclaration */; } return false; } ts.nodeCanBeDecorated = nodeCanBeDecorated; function nodeIsDecorated(node) { switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: if (node.decorators) { return true; } return false; - case 139 /* PropertyDeclaration */: - case 136 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 138 /* Parameter */: if (node.decorators) { return true; } return false; - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: if (node.body && node.decorators) { return true; } return false; - case 141 /* MethodDeclaration */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 146 /* SetAccessor */: if (node.body && node.decorators) { return true; } @@ -5759,10 +5928,10 @@ var ts; ts.nodeIsDecorated = nodeIsDecorated; function childIsDecorated(node) { switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return ts.forEach(node.members, nodeOrChildIsDecorated); - case 141 /* MethodDeclaration */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 146 /* SetAccessor */: return ts.forEach(node.parameters, nodeIsDecorated); } return false; @@ -5772,96 +5941,106 @@ var ts; return nodeIsDecorated(node) || childIsDecorated(node); } ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated; + function isPropertyAccessExpression(node) { + return node.kind === 166 /* PropertyAccessExpression */; + } + ts.isPropertyAccessExpression = isPropertyAccessExpression; + function isElementAccessExpression(node) { + return node.kind === 167 /* ElementAccessExpression */; + } + ts.isElementAccessExpression = isElementAccessExpression; function isExpression(node) { switch (node.kind) { - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - case 91 /* NullKeyword */: - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 95 /* SuperKeyword */: + case 93 /* NullKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: case 10 /* RegularExpressionLiteral */: - case 162 /* ArrayLiteralExpression */: - case 163 /* ObjectLiteralExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 168 /* TaggedTemplateExpression */: - case 187 /* AsExpression */: - case 169 /* TypeAssertionExpression */: - case 170 /* ParenthesizedExpression */: - case 171 /* FunctionExpression */: - case 184 /* ClassExpression */: - case 172 /* ArrowFunction */: - case 175 /* VoidExpression */: - case 173 /* DeleteExpression */: - case 174 /* TypeOfExpression */: - case 177 /* PrefixUnaryExpression */: - case 178 /* PostfixUnaryExpression */: - case 179 /* BinaryExpression */: - case 180 /* ConditionalExpression */: - case 183 /* SpreadElementExpression */: - case 181 /* TemplateExpression */: + case 164 /* ArrayLiteralExpression */: + case 165 /* ObjectLiteralExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 170 /* TaggedTemplateExpression */: + case 189 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 172 /* ParenthesizedExpression */: + case 173 /* FunctionExpression */: + case 186 /* ClassExpression */: + case 174 /* ArrowFunction */: + case 177 /* VoidExpression */: + case 175 /* DeleteExpression */: + case 176 /* TypeOfExpression */: + case 179 /* PrefixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: + case 181 /* BinaryExpression */: + case 182 /* ConditionalExpression */: + case 185 /* SpreadElementExpression */: + case 183 /* TemplateExpression */: case 11 /* NoSubstitutionTemplateLiteral */: - case 185 /* OmittedExpression */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 182 /* YieldExpression */: + case 187 /* OmittedExpression */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 184 /* YieldExpression */: + case 178 /* AwaitExpression */: return true; - case 133 /* QualifiedName */: - while (node.parent.kind === 133 /* QualifiedName */) { + case 135 /* QualifiedName */: + while (node.parent.kind === 135 /* QualifiedName */) { node = node.parent; } - return node.parent.kind === 152 /* TypeQuery */; - case 67 /* Identifier */: - if (node.parent.kind === 152 /* TypeQuery */) { + return node.parent.kind === 154 /* TypeQuery */; + case 69 /* Identifier */: + if (node.parent.kind === 154 /* TypeQuery */) { return true; } // fall through case 8 /* NumericLiteral */: case 9 /* StringLiteral */: + case 97 /* ThisKeyword */: var parent_2 = node.parent; switch (parent_2.kind) { - case 209 /* VariableDeclaration */: - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 245 /* EnumMember */: - case 243 /* PropertyAssignment */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 247 /* EnumMember */: + case 245 /* PropertyAssignment */: + case 163 /* BindingElement */: return parent_2.initializer === node; - case 193 /* ExpressionStatement */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 202 /* ReturnStatement */: - case 203 /* WithStatement */: - case 204 /* SwitchStatement */: - case 239 /* CaseClause */: - case 206 /* ThrowStatement */: - case 204 /* SwitchStatement */: + case 195 /* ExpressionStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 204 /* ReturnStatement */: + case 205 /* WithStatement */: + case 206 /* SwitchStatement */: + case 241 /* CaseClause */: + case 208 /* ThrowStatement */: + case 206 /* SwitchStatement */: return parent_2.expression === node; - case 197 /* ForStatement */: + case 199 /* ForStatement */: var forStatement = parent_2; - return (forStatement.initializer === node && forStatement.initializer.kind !== 210 /* VariableDeclarationList */) || + return (forStatement.initializer === node && forStatement.initializer.kind !== 212 /* VariableDeclarationList */) || forStatement.condition === node || forStatement.incrementor === node; - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: var forInStatement = parent_2; - return (forInStatement.initializer === node && forInStatement.initializer.kind !== 210 /* VariableDeclarationList */) || + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 212 /* VariableDeclarationList */) || forInStatement.expression === node; - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: return node === parent_2.expression; - case 188 /* TemplateSpan */: + case 190 /* TemplateSpan */: return node === parent_2.expression; - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: return node === parent_2.expression; - case 137 /* Decorator */: - case 238 /* JsxExpression */: + case 139 /* Decorator */: + case 240 /* JsxExpression */: + case 239 /* JsxSpreadAttribute */: return true; - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return parent_2.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent_2); default: if (isExpression(parent_2)) { @@ -5872,6 +6051,12 @@ var ts; return false; } ts.isExpression = isExpression; + function isExternalModuleNameRelative(moduleName) { + // TypeScript 1.0 spec (April 2014): 11.2.1 + // An external module name is "relative" if the first term is "." or "..". + return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + } + ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { var moduleState = ts.getModuleInstanceState(node); return moduleState === 1 /* Instantiated */ || @@ -5879,7 +6064,7 @@ var ts; } ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 230 /* ExternalModuleReference */; + return node.kind === 221 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 232 /* ExternalModuleReference */; } ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration; function getExternalModuleImportEqualsDeclarationExpression(node) { @@ -5888,20 +6073,20 @@ var ts; } ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression; function isInternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 230 /* ExternalModuleReference */; + return node.kind === 221 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 232 /* ExternalModuleReference */; } ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration; function getExternalModuleName(node) { - if (node.kind === 220 /* ImportDeclaration */) { + if (node.kind === 222 /* ImportDeclaration */) { return node.moduleSpecifier; } - if (node.kind === 219 /* ImportEqualsDeclaration */) { + if (node.kind === 221 /* ImportEqualsDeclaration */) { var reference = node.moduleReference; - if (reference.kind === 230 /* ExternalModuleReference */) { + if (reference.kind === 232 /* ExternalModuleReference */) { return reference.expression; } } - if (node.kind === 226 /* ExportDeclaration */) { + if (node.kind === 228 /* ExportDeclaration */) { return node.moduleSpecifier; } } @@ -5909,13 +6094,13 @@ var ts; function hasQuestionToken(node) { if (node) { switch (node.kind) { - case 136 /* Parameter */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 244 /* ShorthandPropertyAssignment */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 138 /* Parameter */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 246 /* ShorthandPropertyAssignment */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return node.questionToken !== undefined; } } @@ -5923,9 +6108,9 @@ var ts; } ts.hasQuestionToken = hasQuestionToken; function isJSDocConstructSignature(node) { - return node.kind === 259 /* JSDocFunctionType */ && + return node.kind === 261 /* JSDocFunctionType */ && node.parameters.length > 0 && - node.parameters[0].type.kind === 261 /* JSDocConstructorType */; + node.parameters[0].type.kind === 263 /* JSDocConstructorType */; } ts.isJSDocConstructSignature = isJSDocConstructSignature; function getJSDocTag(node, kind) { @@ -5939,26 +6124,26 @@ var ts; } } function getJSDocTypeTag(node) { - return getJSDocTag(node, 267 /* JSDocTypeTag */); + return getJSDocTag(node, 269 /* JSDocTypeTag */); } ts.getJSDocTypeTag = getJSDocTypeTag; function getJSDocReturnTag(node) { - return getJSDocTag(node, 266 /* JSDocReturnTag */); + return getJSDocTag(node, 268 /* JSDocReturnTag */); } ts.getJSDocReturnTag = getJSDocReturnTag; function getJSDocTemplateTag(node) { - return getJSDocTag(node, 268 /* JSDocTemplateTag */); + return getJSDocTag(node, 270 /* JSDocTemplateTag */); } ts.getJSDocTemplateTag = getJSDocTemplateTag; function getCorrespondingJSDocParameterTag(parameter) { - if (parameter.name && parameter.name.kind === 67 /* Identifier */) { + if (parameter.name && parameter.name.kind === 69 /* Identifier */) { // If it's a parameter, see if the parent has a jsdoc comment with an @param // annotation. var parameterName = parameter.name.text; var docComment = parameter.parent.jsDocComment; if (docComment) { return ts.forEach(docComment.tags, function (t) { - if (t.kind === 265 /* JSDocParameterTag */) { + if (t.kind === 267 /* JSDocParameterTag */) { var parameterTag = t; var name_6 = parameterTag.preParameterName || parameterTag.postParameterName; if (name_6.text === parameterName) { @@ -5977,12 +6162,12 @@ var ts; function isRestParameter(node) { if (node) { if (node.parserContextFlags & 32 /* JavaScriptFile */) { - if (node.type && node.type.kind === 260 /* JSDocVariadicType */) { + if (node.type && node.type.kind === 262 /* JSDocVariadicType */) { return true; } var paramTag = getCorrespondingJSDocParameterTag(node); if (paramTag && paramTag.typeExpression) { - return paramTag.typeExpression.type.kind === 260 /* JSDocVariadicType */; + return paramTag.typeExpression.type.kind === 262 /* JSDocVariadicType */; } } return node.dotDotDotToken !== undefined; @@ -6003,7 +6188,7 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return !!node && (node.kind === 160 /* ArrayBindingPattern */ || node.kind === 159 /* ObjectBindingPattern */); + return !!node && (node.kind === 162 /* ArrayBindingPattern */ || node.kind === 161 /* ObjectBindingPattern */); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { @@ -6018,34 +6203,34 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 172 /* ArrowFunction */: - case 161 /* BindingElement */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 142 /* Constructor */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 228 /* ExportSpecifier */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 143 /* GetAccessor */: - case 221 /* ImportClause */: - case 219 /* ImportEqualsDeclaration */: - case 224 /* ImportSpecifier */: - case 213 /* InterfaceDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 216 /* ModuleDeclaration */: - case 222 /* NamespaceImport */: - case 136 /* Parameter */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 144 /* SetAccessor */: - case 244 /* ShorthandPropertyAssignment */: - case 214 /* TypeAliasDeclaration */: - case 135 /* TypeParameter */: - case 209 /* VariableDeclaration */: + case 174 /* ArrowFunction */: + case 163 /* BindingElement */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 144 /* Constructor */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 230 /* ExportSpecifier */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 145 /* GetAccessor */: + case 223 /* ImportClause */: + case 221 /* ImportEqualsDeclaration */: + case 226 /* ImportSpecifier */: + case 215 /* InterfaceDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 218 /* ModuleDeclaration */: + case 224 /* NamespaceImport */: + case 138 /* Parameter */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 146 /* SetAccessor */: + case 246 /* ShorthandPropertyAssignment */: + case 216 /* TypeAliasDeclaration */: + case 137 /* TypeParameter */: + case 211 /* VariableDeclaration */: return true; } return false; @@ -6053,25 +6238,25 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 201 /* BreakStatement */: - case 200 /* ContinueStatement */: - case 208 /* DebuggerStatement */: - case 195 /* DoStatement */: - case 193 /* ExpressionStatement */: - case 192 /* EmptyStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 197 /* ForStatement */: - case 194 /* IfStatement */: - case 205 /* LabeledStatement */: - case 202 /* ReturnStatement */: - case 204 /* SwitchStatement */: - case 96 /* ThrowKeyword */: - case 207 /* TryStatement */: - case 191 /* VariableStatement */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 225 /* ExportAssignment */: + case 203 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 210 /* DebuggerStatement */: + case 197 /* DoStatement */: + case 195 /* ExpressionStatement */: + case 194 /* EmptyStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 199 /* ForStatement */: + case 196 /* IfStatement */: + case 207 /* LabeledStatement */: + case 204 /* ReturnStatement */: + case 206 /* SwitchStatement */: + case 98 /* ThrowKeyword */: + case 209 /* TryStatement */: + case 193 /* VariableStatement */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 227 /* ExportAssignment */: return true; default: return false; @@ -6080,13 +6265,13 @@ var ts; ts.isStatement = isStatement; function isClassElement(n) { switch (n.kind) { - case 142 /* Constructor */: - case 139 /* PropertyDeclaration */: - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 140 /* MethodSignature */: - case 147 /* IndexSignature */: + case 144 /* Constructor */: + case 141 /* PropertyDeclaration */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 142 /* MethodSignature */: + case 149 /* IndexSignature */: return true; default: return false; @@ -6095,11 +6280,11 @@ var ts; ts.isClassElement = isClassElement; // True if the given identifier, string literal, or number literal is the name of a declaration node function isDeclarationName(name) { - if (name.kind !== 67 /* Identifier */ && name.kind !== 9 /* StringLiteral */ && name.kind !== 8 /* NumericLiteral */) { + if (name.kind !== 69 /* Identifier */ && name.kind !== 9 /* StringLiteral */ && name.kind !== 8 /* NumericLiteral */) { return false; } var parent = name.parent; - if (parent.kind === 224 /* ImportSpecifier */ || parent.kind === 228 /* ExportSpecifier */) { + if (parent.kind === 226 /* ImportSpecifier */ || parent.kind === 230 /* ExportSpecifier */) { if (parent.propertyName) { return true; } @@ -6114,31 +6299,31 @@ var ts; function isIdentifierName(node) { var parent = node.parent; switch (parent.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 245 /* EnumMember */: - case 243 /* PropertyAssignment */: - case 164 /* PropertyAccessExpression */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 247 /* EnumMember */: + case 245 /* PropertyAssignment */: + case 166 /* PropertyAccessExpression */: // Name in member declaration or property name in property access return parent.name === node; - case 133 /* QualifiedName */: + case 135 /* QualifiedName */: // Name on right hand side of dot in a type query if (parent.right === node) { - while (parent.kind === 133 /* QualifiedName */) { + while (parent.kind === 135 /* QualifiedName */) { parent = parent.parent; } - return parent.kind === 152 /* TypeQuery */; + return parent.kind === 154 /* TypeQuery */; } return false; - case 161 /* BindingElement */: - case 224 /* ImportSpecifier */: + case 163 /* BindingElement */: + case 226 /* ImportSpecifier */: // Property name in binding element or import specifier return parent.propertyName === node; - case 228 /* ExportSpecifier */: + case 230 /* ExportSpecifier */: // Any name in an export specifier return true; } @@ -6154,26 +6339,26 @@ var ts; // export = ... // export default ... function isAliasSymbolDeclaration(node) { - return node.kind === 219 /* ImportEqualsDeclaration */ || - node.kind === 221 /* ImportClause */ && !!node.name || - node.kind === 222 /* NamespaceImport */ || - node.kind === 224 /* ImportSpecifier */ || - node.kind === 228 /* ExportSpecifier */ || - node.kind === 225 /* ExportAssignment */ && node.expression.kind === 67 /* Identifier */; + return node.kind === 221 /* ImportEqualsDeclaration */ || + node.kind === 223 /* ImportClause */ && !!node.name || + node.kind === 224 /* NamespaceImport */ || + node.kind === 226 /* ImportSpecifier */ || + node.kind === 230 /* ExportSpecifier */ || + node.kind === 227 /* ExportAssignment */ && node.expression.kind === 69 /* Identifier */; } ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration; function getClassExtendsHeritageClauseElement(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81 /* ExtendsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 83 /* ExtendsKeyword */); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 104 /* ImplementsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 106 /* ImplementsKeyword */); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; function getInterfaceBaseTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81 /* ExtendsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 83 /* ExtendsKeyword */); return heritageClause ? heritageClause.types : undefined; } ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes; @@ -6242,7 +6427,7 @@ var ts; } ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath; function isKeyword(token) { - return 68 /* FirstKeyword */ <= token && token <= 132 /* LastKeyword */; + return 70 /* FirstKeyword */ <= token && token <= 134 /* LastKeyword */; } ts.isKeyword = isKeyword; function isTrivia(token) { @@ -6262,7 +6447,7 @@ var ts; */ function hasDynamicName(declaration) { return declaration.name && - declaration.name.kind === 134 /* ComputedPropertyName */ && + declaration.name.kind === 136 /* ComputedPropertyName */ && !isWellKnownSymbolSyntactically(declaration.name.expression); } ts.hasDynamicName = hasDynamicName; @@ -6272,14 +6457,14 @@ var ts; * where Symbol is literally the word "Symbol", and name is any identifierName */ function isWellKnownSymbolSyntactically(node) { - return node.kind === 164 /* PropertyAccessExpression */ && isESSymbolIdentifier(node.expression); + return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression); } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 67 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { + if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { return name.text; } - if (name.kind === 134 /* ComputedPropertyName */) { + if (name.kind === 136 /* ComputedPropertyName */) { var nameExpression = name.expression; if (isWellKnownSymbolSyntactically(nameExpression)) { var rightHandSideName = nameExpression.name.text; @@ -6297,21 +6482,21 @@ var ts; * Includes the word "Symbol" with unicode escapes */ function isESSymbolIdentifier(node) { - return node.kind === 67 /* Identifier */ && node.text === "Symbol"; + return node.kind === 69 /* Identifier */ && node.text === "Symbol"; } ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 113 /* AbstractKeyword */: - case 116 /* AsyncKeyword */: - case 72 /* ConstKeyword */: - case 120 /* DeclareKeyword */: - case 75 /* DefaultKeyword */: - case 80 /* ExportKeyword */: - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: + case 115 /* AbstractKeyword */: + case 118 /* AsyncKeyword */: + case 74 /* ConstKeyword */: + case 122 /* DeclareKeyword */: + case 77 /* DefaultKeyword */: + case 82 /* ExportKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 113 /* StaticKeyword */: return true; } return false; @@ -6319,28 +6504,28 @@ var ts; ts.isModifier = isModifier; function isParameterDeclaration(node) { var root = getRootDeclaration(node); - return root.kind === 136 /* Parameter */; + return root.kind === 138 /* Parameter */; } ts.isParameterDeclaration = isParameterDeclaration; function getRootDeclaration(node) { - while (node.kind === 161 /* BindingElement */) { + while (node.kind === 163 /* BindingElement */) { node = node.parent.parent; } return node; } ts.getRootDeclaration = getRootDeclaration; function nodeStartsNewLexicalEnvironment(n) { - return isFunctionLike(n) || n.kind === 216 /* ModuleDeclaration */ || n.kind === 246 /* SourceFile */; + return isFunctionLike(n) || n.kind === 218 /* ModuleDeclaration */ || n.kind === 248 /* SourceFile */; } ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; function cloneEntityName(node) { - if (node.kind === 67 /* Identifier */) { - var clone_1 = createSynthesizedNode(67 /* Identifier */); + if (node.kind === 69 /* Identifier */) { + var clone_1 = createSynthesizedNode(69 /* Identifier */); clone_1.text = node.text; return clone_1; } else { - var clone_2 = createSynthesizedNode(133 /* QualifiedName */); + var clone_2 = createSynthesizedNode(135 /* QualifiedName */); clone_2.left = cloneEntityName(node.left); clone_2.left.parent = clone_2; clone_2.right = cloneEntityName(node.right); @@ -6595,7 +6780,7 @@ var ts; ts.getLineOfLocalPosition = getLineOfLocalPosition; function getFirstConstructorWithBody(node) { return ts.forEach(node.members, function (member) { - if (member.kind === 142 /* Constructor */ && nodeIsPresent(member.body)) { + if (member.kind === 144 /* Constructor */ && nodeIsPresent(member.body)) { return member; } }); @@ -6624,10 +6809,10 @@ var ts; var setAccessor; if (hasDynamicName(accessor)) { firstAccessor = accessor; - if (accessor.kind === 143 /* GetAccessor */) { + if (accessor.kind === 145 /* GetAccessor */) { getAccessor = accessor; } - else if (accessor.kind === 144 /* SetAccessor */) { + else if (accessor.kind === 146 /* SetAccessor */) { setAccessor = accessor; } else { @@ -6636,7 +6821,7 @@ var ts; } else { ts.forEach(declarations, function (member) { - if ((member.kind === 143 /* GetAccessor */ || member.kind === 144 /* SetAccessor */) + if ((member.kind === 145 /* GetAccessor */ || member.kind === 146 /* SetAccessor */) && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) { var memberName = getPropertyNameForPropertyNameNode(member.name); var accessorName = getPropertyNameForPropertyNameNode(accessor.name); @@ -6647,10 +6832,10 @@ var ts; else if (!secondAccessor) { secondAccessor = member; } - if (member.kind === 143 /* GetAccessor */ && !getAccessor) { + if (member.kind === 145 /* GetAccessor */ && !getAccessor) { getAccessor = member; } - if (member.kind === 144 /* SetAccessor */ && !setAccessor) { + if (member.kind === 146 /* SetAccessor */ && !setAccessor) { setAccessor = member; } } @@ -6783,16 +6968,16 @@ var ts; ts.writeCommentRange = writeCommentRange; function modifierToFlag(token) { switch (token) { - case 111 /* StaticKeyword */: return 128 /* Static */; - case 110 /* PublicKeyword */: return 16 /* Public */; - case 109 /* ProtectedKeyword */: return 64 /* Protected */; - case 108 /* PrivateKeyword */: return 32 /* Private */; - case 113 /* AbstractKeyword */: return 256 /* Abstract */; - case 80 /* ExportKeyword */: return 1 /* Export */; - case 120 /* DeclareKeyword */: return 2 /* Ambient */; - case 72 /* ConstKeyword */: return 32768 /* Const */; - case 75 /* DefaultKeyword */: return 1024 /* Default */; - case 116 /* AsyncKeyword */: return 512 /* Async */; + case 113 /* StaticKeyword */: return 128 /* Static */; + case 112 /* PublicKeyword */: return 16 /* Public */; + case 111 /* ProtectedKeyword */: return 64 /* Protected */; + case 110 /* PrivateKeyword */: return 32 /* Private */; + case 115 /* AbstractKeyword */: return 256 /* Abstract */; + case 82 /* ExportKeyword */: return 1 /* Export */; + case 122 /* DeclareKeyword */: return 2 /* Ambient */; + case 74 /* ConstKeyword */: return 32768 /* Const */; + case 77 /* DefaultKeyword */: return 1024 /* Default */; + case 118 /* AsyncKeyword */: return 512 /* Async */; } return 0; } @@ -6800,29 +6985,29 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 167 /* NewExpression */: - case 166 /* CallExpression */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 168 /* TaggedTemplateExpression */: - case 162 /* ArrayLiteralExpression */: - case 170 /* ParenthesizedExpression */: - case 163 /* ObjectLiteralExpression */: - case 184 /* ClassExpression */: - case 171 /* FunctionExpression */: - case 67 /* Identifier */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 169 /* NewExpression */: + case 168 /* CallExpression */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 170 /* TaggedTemplateExpression */: + case 164 /* ArrayLiteralExpression */: + case 172 /* ParenthesizedExpression */: + case 165 /* ObjectLiteralExpression */: + case 186 /* ClassExpression */: + case 173 /* FunctionExpression */: + case 69 /* Identifier */: case 10 /* RegularExpressionLiteral */: case 8 /* NumericLiteral */: case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: - case 181 /* TemplateExpression */: - case 82 /* FalseKeyword */: - case 91 /* NullKeyword */: - case 95 /* ThisKeyword */: - case 97 /* TrueKeyword */: - case 93 /* SuperKeyword */: + case 183 /* TemplateExpression */: + case 84 /* FalseKeyword */: + case 93 /* NullKeyword */: + case 97 /* ThisKeyword */: + case 99 /* TrueKeyword */: + case 95 /* SuperKeyword */: return true; } } @@ -6830,12 +7015,12 @@ var ts; } ts.isLeftHandSideExpression = isLeftHandSideExpression; function isAssignmentOperator(token) { - return token >= 55 /* FirstAssignment */ && token <= 66 /* LastAssignment */; + return token >= 56 /* FirstAssignment */ && token <= 68 /* LastAssignment */; } ts.isAssignmentOperator = isAssignmentOperator; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { - return node.kind === 186 /* ExpressionWithTypeArguments */ && - node.parent.token === 81 /* ExtendsKeyword */ && + return node.kind === 188 /* ExpressionWithTypeArguments */ && + node.parent.token === 83 /* ExtendsKeyword */ && isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; @@ -6846,10 +7031,10 @@ var ts; } ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments; function isSupportedExpressionWithTypeArgumentsRest(node) { - if (node.kind === 67 /* Identifier */) { + if (node.kind === 69 /* Identifier */) { return true; } - else if (node.kind === 164 /* PropertyAccessExpression */) { + else if (isPropertyAccessExpression(node)) { return isSupportedExpressionWithTypeArgumentsRest(node.expression); } else { @@ -6857,16 +7042,16 @@ var ts; } } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node) || - (node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node); + return (node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node) || + (node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.name === node); } ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess; function isEmptyObjectLiteralOrArrayLiteral(expression) { var kind = expression.kind; - if (kind === 163 /* ObjectLiteralExpression */) { + if (kind === 165 /* ObjectLiteralExpression */) { return expression.properties.length === 0; } - if (kind === 162 /* ArrayLiteralExpression */) { + if (kind === 164 /* ArrayLiteralExpression */) { return expression.elements.length === 0; } return false; @@ -7178,21 +7363,31 @@ var ts; } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function getTypeParameterOwner(d) { - if (d && d.kind === 135 /* TypeParameter */) { + if (d && d.kind === 137 /* TypeParameter */) { for (var current = d; current; current = current.parent) { - if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 213 /* InterfaceDeclaration */) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 215 /* InterfaceDeclaration */) { return current; } } } } ts.getTypeParameterOwner = getTypeParameterOwner; + function arrayStructurallyIsEqualTo(array1, array2) { + if (!array1 || !array2) { + return false; + } + if (array1.length !== array2.length) { + return false; + } + return ts.arrayIsEqualTo(array1.sort(), array2.sort()); + } + ts.arrayStructurallyIsEqualTo = arrayStructurallyIsEqualTo; })(ts || (ts = {})); /// /// var ts; (function (ts) { - var nodeConstructors = new Array(270 /* Count */); + var nodeConstructors = new Array(272 /* Count */); /* @internal */ ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -7237,20 +7432,26 @@ var ts; var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; var cbNodes = cbNodeArray || cbNode; switch (node.kind) { - case 133 /* QualifiedName */: + case 135 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 243 /* PropertyAssignment */: - case 244 /* ShorthandPropertyAssignment */: - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 246 /* ShorthandPropertyAssignment */: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.equalsToken) || + visitNode(cbNode, node.objectAssignmentInitializer); + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 245 /* PropertyAssignment */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || @@ -7259,24 +7460,24 @@ var ts; visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || @@ -7287,290 +7488,290 @@ var ts; visitNode(cbNode, node.type) || visitNode(cbNode, node.equalsGreaterThanToken) || visitNode(cbNode, node.body); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return visitNode(cbNode, node.exprName); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return visitNodes(cbNodes, node.members); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return visitNode(cbNode, node.elementType); - case 155 /* TupleType */: + case 157 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); - case 156 /* UnionType */: - case 157 /* IntersectionType */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: return visitNodes(cbNodes, node.types); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return visitNode(cbNode, node.type); - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); - case 164 /* PropertyAccessExpression */: + case 166 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); - case 165 /* ElementAccessExpression */: + case 167 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); - case 169 /* TypeAssertionExpression */: + case 171 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); - case 173 /* DeleteExpression */: + case 175 /* DeleteExpression */: return visitNode(cbNode, node.expression); - case 174 /* TypeOfExpression */: + case 176 /* TypeOfExpression */: return visitNode(cbNode, node.expression); - case 175 /* VoidExpression */: + case 177 /* VoidExpression */: return visitNode(cbNode, node.expression); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); - case 176 /* AwaitExpression */: + case 178 /* AwaitExpression */: return visitNode(cbNode, node.expression); - case 178 /* PostfixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); - case 187 /* AsExpression */: + case 189 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); - case 183 /* SpreadElementExpression */: + case 185 /* SpreadElementExpression */: return visitNode(cbNode, node.expression); - case 190 /* Block */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); - case 210 /* VariableDeclarationList */: + case 212 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); - case 193 /* ExpressionStatement */: + case 195 /* ExpressionStatement */: return visitNode(cbNode, node.expression); - case 194 /* IfStatement */: + case 196 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); - case 195 /* DoStatement */: + case 197 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); - case 196 /* WhileStatement */: + case 198 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 197 /* ForStatement */: + case 199 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); - case 198 /* ForInStatement */: + case 200 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 199 /* ForOfStatement */: + case 201 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: return visitNode(cbNode, node.label); - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: return visitNode(cbNode, node.expression); - case 203 /* WithStatement */: + case 205 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); - case 218 /* CaseBlock */: + case 220 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); - case 239 /* CaseClause */: + case 241 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); - case 240 /* DefaultClause */: + case 242 /* DefaultClause */: return visitNodes(cbNodes, node.statements); - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); - case 206 /* ThrowStatement */: + case 208 /* ThrowStatement */: return visitNode(cbNode, node.expression); - case 207 /* TryStatement */: + case 209 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); - case 137 /* Decorator */: + case 139 /* Decorator */: return visitNode(cbNode, node.expression); - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); - case 221 /* ImportClause */: + case 223 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 222 /* NamespaceImport */: + case 224 /* NamespaceImport */: return visitNode(cbNode, node.name); - case 223 /* NamedImports */: - case 227 /* NamedExports */: + case 225 /* NamedImports */: + case 229 /* NamedExports */: return visitNodes(cbNodes, node.elements); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); - case 181 /* TemplateExpression */: + case 183 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); - case 188 /* TemplateSpan */: + case 190 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); - case 241 /* HeritageClause */: + case 243 /* HeritageClause */: return visitNodes(cbNodes, node.types); - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); - case 230 /* ExternalModuleReference */: + case 232 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); - case 229 /* MissingDeclaration */: + case 231 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); - case 231 /* JsxElement */: + case 233 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); - case 232 /* JsxSelfClosingElement */: - case 233 /* JsxOpeningElement */: + case 234 /* JsxSelfClosingElement */: + case 235 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); - case 236 /* JsxAttribute */: + case 238 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); - case 237 /* JsxSpreadAttribute */: + case 239 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); - case 238 /* JsxExpression */: + case 240 /* JsxExpression */: return visitNode(cbNode, node.expression); - case 235 /* JsxClosingElement */: + case 237 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); - case 247 /* JSDocTypeExpression */: + case 249 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); - case 251 /* JSDocUnionType */: + case 253 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); - case 252 /* JSDocTupleType */: + case 254 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); - case 250 /* JSDocArrayType */: + case 252 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); - case 254 /* JSDocNonNullableType */: + case 256 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); - case 253 /* JSDocNullableType */: + case 255 /* JSDocNullableType */: return visitNode(cbNode, node.type); - case 255 /* JSDocRecordType */: + case 257 /* JSDocRecordType */: return visitNodes(cbNodes, node.members); - case 257 /* JSDocTypeReference */: + case 259 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); - case 258 /* JSDocOptionalType */: + case 260 /* JSDocOptionalType */: return visitNode(cbNode, node.type); - case 259 /* JSDocFunctionType */: + case 261 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 260 /* JSDocVariadicType */: + case 262 /* JSDocVariadicType */: return visitNode(cbNode, node.type); - case 261 /* JSDocConstructorType */: + case 263 /* JSDocConstructorType */: return visitNode(cbNode, node.type); - case 262 /* JSDocThisType */: + case 264 /* JSDocThisType */: return visitNode(cbNode, node.type); - case 256 /* JSDocRecordMember */: + case 258 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); - case 263 /* JSDocComment */: + case 265 /* JSDocComment */: return visitNodes(cbNodes, node.tags); - case 265 /* JSDocParameterTag */: + case 267 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); - case 266 /* JSDocReturnTag */: + case 268 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); - case 267 /* JSDocTypeTag */: + case 269 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); - case 268 /* JSDocTemplateTag */: + case 270 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); } } @@ -7765,9 +7966,9 @@ var ts; // Add additional cases as necessary depending on how we see JSDoc comments used // in the wild. switch (node.kind) { - case 191 /* VariableStatement */: - case 211 /* FunctionDeclaration */: - case 136 /* Parameter */: + case 193 /* VariableStatement */: + case 213 /* FunctionDeclaration */: + case 138 /* Parameter */: addJSDocComment(node); } forEachChild(node, visit); @@ -7808,7 +8009,7 @@ var ts; } Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - var sourceFile = createNode(246 /* SourceFile */, /*pos*/ 0); + var sourceFile = createNode(248 /* SourceFile */, /*pos*/ 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; @@ -7972,7 +8173,7 @@ var ts; var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; // Note: it is not actually necessary to save/restore the context flags here. That's - // because the saving/restorating of these flags happens naturally through the recursive + // because the saving/restoring of these flags happens naturally through the recursive // descent nature of our parser. However, we still store this here just so we can // assert that that invariant holds. var saveContextFlags = contextFlags; @@ -8007,20 +8208,20 @@ var ts; } // Ignore strict mode flag because we will report an error in type checker instead. function isIdentifier() { - if (token === 67 /* Identifier */) { + if (token === 69 /* Identifier */) { return true; } // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. - if (token === 112 /* YieldKeyword */ && inYieldContext()) { + if (token === 114 /* YieldKeyword */ && inYieldContext()) { return false; } // If we have a 'await' keyword, and we're in the [Await] context, then 'await' is // considered a keyword and is not an identifier. - if (token === 117 /* AwaitKeyword */ && inAwaitContext()) { + if (token === 119 /* AwaitKeyword */ && inAwaitContext()) { return false; } - return token > 103 /* LastReservedWord */; + return token > 105 /* LastReservedWord */; } function parseExpected(kind, diagnosticMessage, shouldAdvance) { if (shouldAdvance === void 0) { shouldAdvance = true; } @@ -8126,16 +8327,16 @@ var ts; function createIdentifier(isIdentifier, diagnosticMessage) { identifierCount++; if (isIdentifier) { - var node = createNode(67 /* Identifier */); + var node = createNode(69 /* Identifier */); // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker - if (token !== 67 /* Identifier */) { + if (token !== 69 /* Identifier */) { node.originalKeywordKind = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); } - return createMissingNode(67 /* Identifier */, /*reportAtCurrentPosition*/ false, diagnosticMessage || ts.Diagnostics.Identifier_expected); + return createMissingNode(69 /* Identifier */, /*reportAtCurrentPosition*/ false, diagnosticMessage || ts.Diagnostics.Identifier_expected); } function parseIdentifier(diagnosticMessage) { return createIdentifier(isIdentifier(), diagnosticMessage); @@ -8170,7 +8371,7 @@ var ts; // PropertyName [Yield]: // LiteralPropertyName // ComputedPropertyName[?Yield] - var node = createNode(134 /* ComputedPropertyName */); + var node = createNode(136 /* ComputedPropertyName */); parseExpected(19 /* OpenBracketToken */); // We parse any expression (including a comma expression). But the grammar // says that only an assignment expression is allowed, so the grammar checker @@ -8183,21 +8384,28 @@ var ts; return token === t && tryParse(nextTokenCanFollowModifier); } function nextTokenCanFollowModifier() { - if (token === 72 /* ConstKeyword */) { + if (token === 74 /* ConstKeyword */) { // 'const' is only a modifier if followed by 'enum'. - return nextToken() === 79 /* EnumKeyword */; + return nextToken() === 81 /* EnumKeyword */; } - if (token === 80 /* ExportKeyword */) { + if (token === 82 /* ExportKeyword */) { nextToken(); - if (token === 75 /* DefaultKeyword */) { + if (token === 77 /* DefaultKeyword */) { return lookAhead(nextTokenIsClassOrFunction); } return token !== 37 /* AsteriskToken */ && token !== 15 /* OpenBraceToken */ && canFollowModifier(); } - if (token === 75 /* DefaultKeyword */) { + if (token === 77 /* DefaultKeyword */) { return nextTokenIsClassOrFunction(); } + if (token === 113 /* StaticKeyword */) { + nextToken(); + return canFollowModifier(); + } nextToken(); + if (scanner.hasPrecedingLineBreak()) { + return false; + } return canFollowModifier(); } function parseAnyContextualModifier() { @@ -8211,7 +8419,7 @@ var ts; } function nextTokenIsClassOrFunction() { nextToken(); - return token === 71 /* ClassKeyword */ || token === 85 /* FunctionKeyword */; + return token === 73 /* ClassKeyword */ || token === 87 /* FunctionKeyword */; } // True if positioned at the start of a list element function isListElement(parsingContext, inErrorRecovery) { @@ -8231,7 +8439,7 @@ var ts; // outer module. We just want to consume and move on. return !(token === 23 /* SemicolonToken */ && inErrorRecovery) && isStartOfStatement(); case 2 /* SwitchClauses */: - return token === 69 /* CaseKeyword */ || token === 75 /* DefaultKeyword */; + return token === 71 /* CaseKeyword */ || token === 77 /* DefaultKeyword */; case 4 /* TypeMembers */: return isStartOfTypeMember(); case 5 /* ClassMembers */: @@ -8305,7 +8513,7 @@ var ts; // extends {} extends // extends {} implements var next = nextToken(); - return next === 24 /* CommaToken */ || next === 15 /* OpenBraceToken */ || next === 81 /* ExtendsKeyword */ || next === 104 /* ImplementsKeyword */; + return next === 24 /* CommaToken */ || next === 15 /* OpenBraceToken */ || next === 83 /* ExtendsKeyword */ || next === 106 /* ImplementsKeyword */; } return true; } @@ -8318,8 +8526,8 @@ var ts; return ts.tokenIsIdentifierOrKeyword(token); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 104 /* ImplementsKeyword */ || - token === 81 /* ExtendsKeyword */) { + if (token === 106 /* ImplementsKeyword */ || + token === 83 /* ExtendsKeyword */) { return lookAhead(nextTokenIsStartOfExpression); } return false; @@ -8345,14 +8553,14 @@ var ts; case 21 /* ImportOrExportSpecifiers */: return token === 16 /* CloseBraceToken */; case 3 /* SwitchClauseStatements */: - return token === 16 /* CloseBraceToken */ || token === 69 /* CaseKeyword */ || token === 75 /* DefaultKeyword */; + return token === 16 /* CloseBraceToken */ || token === 71 /* CaseKeyword */ || token === 77 /* DefaultKeyword */; case 7 /* HeritageClauseElement */: - return token === 15 /* OpenBraceToken */ || token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */; + return token === 15 /* OpenBraceToken */ || token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */; case 8 /* VariableDeclarations */: return isVariableDeclaratorListTerminator(); case 17 /* TypeParameters */: // Tokens other than '>' are here for better error recovery - return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */ || token === 15 /* OpenBraceToken */ || token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */; + return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */ || token === 15 /* OpenBraceToken */ || token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */; case 11 /* ArgumentExpressions */: // Tokens other than ')' are here for better error recovery return token === 18 /* CloseParenToken */ || token === 23 /* SemicolonToken */; @@ -8369,11 +8577,11 @@ var ts; case 20 /* HeritageClauses */: return token === 15 /* OpenBraceToken */ || token === 16 /* CloseBraceToken */; case 13 /* JsxAttributes */: - return token === 27 /* GreaterThanToken */ || token === 38 /* SlashToken */; + return token === 27 /* GreaterThanToken */ || token === 39 /* SlashToken */; case 14 /* JsxChildren */: return token === 25 /* LessThanToken */ && lookAhead(nextTokenIsSlash); case 22 /* JSDocFunctionParameters */: - return token === 18 /* CloseParenToken */ || token === 53 /* ColonToken */ || token === 16 /* CloseBraceToken */; + return token === 18 /* CloseParenToken */ || token === 54 /* ColonToken */ || token === 16 /* CloseBraceToken */; case 23 /* JSDocTypeArguments */: return token === 27 /* GreaterThanToken */ || token === 16 /* CloseBraceToken */; case 25 /* JSDocTupleTypes */: @@ -8561,20 +8769,20 @@ var ts; function isReusableClassMember(node) { if (node) { switch (node.kind) { - case 142 /* Constructor */: - case 147 /* IndexSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 139 /* PropertyDeclaration */: - case 189 /* SemicolonClassElement */: + case 144 /* Constructor */: + case 149 /* IndexSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 191 /* SemicolonClassElement */: return true; - case 141 /* MethodDeclaration */: + case 143 /* MethodDeclaration */: // Method declarations are not necessarily reusable. An object-literal // may have a method calls "constructor(...)" and we must reparse that // into an actual .ConstructorDeclaration. var methodDeclaration = node; - var nameIsConstructor = methodDeclaration.name.kind === 67 /* Identifier */ && - methodDeclaration.name.originalKeywordKind === 119 /* ConstructorKeyword */; + var nameIsConstructor = methodDeclaration.name.kind === 69 /* Identifier */ && + methodDeclaration.name.originalKeywordKind === 121 /* ConstructorKeyword */; return !nameIsConstructor; } } @@ -8583,8 +8791,8 @@ var ts; function isReusableSwitchClause(node) { if (node) { switch (node.kind) { - case 239 /* CaseClause */: - case 240 /* DefaultClause */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: return true; } } @@ -8593,58 +8801,58 @@ var ts; function isReusableStatement(node) { if (node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: - case 191 /* VariableStatement */: - case 190 /* Block */: - case 194 /* IfStatement */: - case 193 /* ExpressionStatement */: - case 206 /* ThrowStatement */: - case 202 /* ReturnStatement */: - case 204 /* SwitchStatement */: - case 201 /* BreakStatement */: - case 200 /* ContinueStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 197 /* ForStatement */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 192 /* EmptyStatement */: - case 207 /* TryStatement */: - case 205 /* LabeledStatement */: - case 195 /* DoStatement */: - case 208 /* DebuggerStatement */: - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 226 /* ExportDeclaration */: - case 225 /* ExportAssignment */: - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 214 /* TypeAliasDeclaration */: + case 213 /* FunctionDeclaration */: + case 193 /* VariableStatement */: + case 192 /* Block */: + case 196 /* IfStatement */: + case 195 /* ExpressionStatement */: + case 208 /* ThrowStatement */: + case 204 /* ReturnStatement */: + case 206 /* SwitchStatement */: + case 203 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 199 /* ForStatement */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 194 /* EmptyStatement */: + case 209 /* TryStatement */: + case 207 /* LabeledStatement */: + case 197 /* DoStatement */: + case 210 /* DebuggerStatement */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 228 /* ExportDeclaration */: + case 227 /* ExportAssignment */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 216 /* TypeAliasDeclaration */: return true; } } return false; } function isReusableEnumMember(node) { - return node.kind === 245 /* EnumMember */; + return node.kind === 247 /* EnumMember */; } function isReusableTypeMember(node) { if (node) { switch (node.kind) { - case 146 /* ConstructSignature */: - case 140 /* MethodSignature */: - case 147 /* IndexSignature */: - case 138 /* PropertySignature */: - case 145 /* CallSignature */: + case 148 /* ConstructSignature */: + case 142 /* MethodSignature */: + case 149 /* IndexSignature */: + case 140 /* PropertySignature */: + case 147 /* CallSignature */: return true; } } return false; } function isReusableVariableDeclaration(node) { - if (node.kind !== 209 /* VariableDeclaration */) { + if (node.kind !== 211 /* VariableDeclaration */) { return false; } // Very subtle incremental parsing bug. Consider the following code: @@ -8665,7 +8873,7 @@ var ts; return variableDeclarator.initializer === undefined; } function isReusableParameter(node) { - if (node.kind !== 136 /* Parameter */) { + if (node.kind !== 138 /* Parameter */) { return false; } // See the comment in isReusableVariableDeclaration for why we do this. @@ -8782,7 +8990,7 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var entity = parseIdentifier(diagnosticMessage); while (parseOptional(21 /* DotToken */)) { - var node = createNode(133 /* QualifiedName */, entity.pos); + var node = createNode(135 /* QualifiedName */, entity.pos); node.left = entity; node.right = parseRightSideOfDot(allowReservedWords); entity = finishNode(node); @@ -8815,13 +9023,13 @@ var ts; // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually // be an identifier and the error would be quite confusing. - return createMissingNode(67 /* Identifier */, /*reportAtCurrentToken*/ true, ts.Diagnostics.Identifier_expected); + return createMissingNode(69 /* Identifier */, /*reportAtCurrentToken*/ true, ts.Diagnostics.Identifier_expected); } } return allowIdentifierNames ? parseIdentifierName() : parseIdentifier(); } function parseTemplateExpression() { - var template = createNode(181 /* TemplateExpression */); + var template = createNode(183 /* TemplateExpression */); template.head = parseLiteralNode(); ts.Debug.assert(template.head.kind === 12 /* TemplateHead */, "Template head has wrong token kind"); var templateSpans = []; @@ -8834,7 +9042,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(188 /* TemplateSpan */); + var span = createNode(190 /* TemplateSpan */); span.expression = allowInAnd(parseExpression); var literal; if (token === 16 /* CloseBraceToken */) { @@ -8876,14 +9084,14 @@ var ts; // TYPES function parseTypeReferenceOrTypePredicate() { var typeName = parseEntityName(/*allowReservedWords*/ false, ts.Diagnostics.Type_expected); - if (typeName.kind === 67 /* Identifier */ && token === 122 /* IsKeyword */ && !scanner.hasPrecedingLineBreak()) { + if (typeName.kind === 69 /* Identifier */ && token === 124 /* IsKeyword */ && !scanner.hasPrecedingLineBreak()) { nextToken(); - var node_1 = createNode(148 /* TypePredicate */, typeName.pos); + var node_1 = createNode(150 /* TypePredicate */, typeName.pos); node_1.parameterName = typeName; node_1.type = parseType(); return finishNode(node_1); } - var node = createNode(149 /* TypeReference */, typeName.pos); + var node = createNode(151 /* TypeReference */, typeName.pos); node.typeName = typeName; if (!scanner.hasPrecedingLineBreak() && token === 25 /* LessThanToken */) { node.typeArguments = parseBracketedList(18 /* TypeArguments */, parseType, 25 /* LessThanToken */, 27 /* GreaterThanToken */); @@ -8891,15 +9099,15 @@ var ts; return finishNode(node); } function parseTypeQuery() { - var node = createNode(152 /* TypeQuery */); - parseExpected(99 /* TypeOfKeyword */); + var node = createNode(154 /* TypeQuery */); + parseExpected(101 /* TypeOfKeyword */); node.exprName = parseEntityName(/*allowReservedWords*/ true); return finishNode(node); } function parseTypeParameter() { - var node = createNode(135 /* TypeParameter */); + var node = createNode(137 /* TypeParameter */); node.name = parseIdentifier(); - if (parseOptional(81 /* ExtendsKeyword */)) { + if (parseOptional(83 /* ExtendsKeyword */)) { // It's not uncommon for people to write improper constraints to a generic. If the // user writes a constraint that is an expression and not an actual type, then parse // it out as an expression (so we can recover well), but report that a type is needed @@ -8926,7 +9134,7 @@ var ts; } } function parseParameterType() { - if (parseOptional(53 /* ColonToken */)) { + if (parseOptional(54 /* ColonToken */)) { return token === 9 /* StringLiteral */ ? parseLiteralNode(/*internName*/ true) : parseType(); @@ -8934,7 +9142,7 @@ var ts; return undefined; } function isStartOfParameter() { - return token === 22 /* DotDotDotToken */ || isIdentifierOrPattern() || ts.isModifier(token) || token === 54 /* AtToken */; + return token === 22 /* DotDotDotToken */ || isIdentifierOrPattern() || ts.isModifier(token) || token === 55 /* AtToken */; } function setModifiers(node, modifiers) { if (modifiers) { @@ -8943,7 +9151,7 @@ var ts; } } function parseParameter() { - var node = createNode(136 /* Parameter */); + var node = createNode(138 /* Parameter */); node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(22 /* DotDotDotToken */); @@ -8961,7 +9169,7 @@ var ts; // to avoid this we'll advance cursor to the next token. nextToken(); } - node.questionToken = parseOptionalToken(52 /* QuestionToken */); + node.questionToken = parseOptionalToken(53 /* QuestionToken */); node.type = parseParameterType(); node.initializer = parseBindingElementInitializer(/*inParameter*/ true); // Do not check for initializers in an ambient context for parameters. This is not @@ -9037,10 +9245,10 @@ var ts; } function parseSignatureMember(kind) { var node = createNode(kind); - if (kind === 146 /* ConstructSignature */) { - parseExpected(90 /* NewKeyword */); + if (kind === 148 /* ConstructSignature */) { + parseExpected(92 /* NewKeyword */); } - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); parseTypeMemberSemicolon(); return finishNode(node); } @@ -9087,21 +9295,21 @@ var ts; // A colon signifies a well formed indexer // A comma should be a badly formed indexer because comma expressions are not allowed // in computed properties. - if (token === 53 /* ColonToken */ || token === 24 /* CommaToken */) { + if (token === 54 /* ColonToken */ || token === 24 /* CommaToken */) { return true; } // Question mark could be an indexer with an optional property, // or it could be a conditional expression in a computed property. - if (token !== 52 /* QuestionToken */) { + if (token !== 53 /* QuestionToken */) { return false; } // If any of the following tokens are after the question mark, it cannot // be a conditional expression, so treat it as an indexer. nextToken(); - return token === 53 /* ColonToken */ || token === 24 /* CommaToken */ || token === 20 /* CloseBracketToken */; + return token === 54 /* ColonToken */ || token === 24 /* CommaToken */ || token === 20 /* CloseBracketToken */; } function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) { - var node = createNode(147 /* IndexSignature */, fullStart); + var node = createNode(149 /* IndexSignature */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(16 /* Parameters */, parseParameter, 19 /* OpenBracketToken */, 20 /* CloseBracketToken */); @@ -9112,19 +9320,19 @@ var ts; function parsePropertyOrMethodSignature() { var fullStart = scanner.getStartPos(); var name = parsePropertyName(); - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) { - var method = createNode(140 /* MethodSignature */, fullStart); + var method = createNode(142 /* MethodSignature */, fullStart); method.name = name; method.questionToken = questionToken; // Method signatues don't exist in expression contexts. So they have neither // [Yield] nor [Await] - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method); parseTypeMemberSemicolon(); return finishNode(method); } else { - var property = createNode(138 /* PropertySignature */, fullStart); + var property = createNode(140 /* PropertySignature */, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -9158,23 +9366,23 @@ var ts; nextToken(); return token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */ || - token === 52 /* QuestionToken */ || - token === 53 /* ColonToken */ || + token === 53 /* QuestionToken */ || + token === 54 /* ColonToken */ || canParseSemicolon(); } function parseTypeMember() { switch (token) { case 17 /* OpenParenToken */: case 25 /* LessThanToken */: - return parseSignatureMember(145 /* CallSignature */); + return parseSignatureMember(147 /* CallSignature */); case 19 /* OpenBracketToken */: // Indexer or computed property return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined) : parsePropertyOrMethodSignature(); - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(146 /* ConstructSignature */); + return parseSignatureMember(148 /* ConstructSignature */); } // fall through. case 9 /* StringLiteral */: @@ -9211,7 +9419,7 @@ var ts; return token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */; } function parseTypeLiteral() { - var node = createNode(153 /* TypeLiteral */); + var node = createNode(155 /* TypeLiteral */); node.members = parseObjectTypeMembers(); return finishNode(node); } @@ -9227,12 +9435,12 @@ var ts; return members; } function parseTupleType() { - var node = createNode(155 /* TupleType */); + var node = createNode(157 /* TupleType */); node.elementTypes = parseBracketedList(19 /* TupleElementTypes */, parseType, 19 /* OpenBracketToken */, 20 /* CloseBracketToken */); return finishNode(node); } function parseParenthesizedType() { - var node = createNode(158 /* ParenthesizedType */); + var node = createNode(160 /* ParenthesizedType */); parseExpected(17 /* OpenParenToken */); node.type = parseType(); parseExpected(18 /* CloseParenToken */); @@ -9240,8 +9448,8 @@ var ts; } function parseFunctionOrConstructorType(kind) { var node = createNode(kind); - if (kind === 151 /* ConstructorType */) { - parseExpected(90 /* NewKeyword */); + if (kind === 153 /* ConstructorType */) { + parseExpected(92 /* NewKeyword */); } fillSignature(34 /* EqualsGreaterThanToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); return finishNode(node); @@ -9252,17 +9460,18 @@ var ts; } function parseNonArrayType() { switch (token) { - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: // If these are followed by a dot, then parse these out as a dotted type reference instead. var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReferenceOrTypePredicate(); - case 101 /* VoidKeyword */: + case 103 /* VoidKeyword */: + case 97 /* ThisKeyword */: return parseTokenNode(); - case 99 /* TypeOfKeyword */: + case 101 /* TypeOfKeyword */: return parseTypeQuery(); case 15 /* OpenBraceToken */: return parseTypeLiteral(); @@ -9276,17 +9485,18 @@ var ts; } function isStartOfType() { switch (token) { - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: - case 101 /* VoidKeyword */: - case 99 /* TypeOfKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: + case 97 /* ThisKeyword */: + case 101 /* TypeOfKeyword */: case 15 /* OpenBraceToken */: case 19 /* OpenBracketToken */: case 25 /* LessThanToken */: - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: return true; case 17 /* OpenParenToken */: // Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier, @@ -9304,7 +9514,7 @@ var ts; var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(19 /* OpenBracketToken */)) { parseExpected(20 /* CloseBracketToken */); - var node = createNode(154 /* ArrayType */, type.pos); + var node = createNode(156 /* ArrayType */, type.pos); node.elementType = type; type = finishNode(node); } @@ -9326,10 +9536,10 @@ var ts; return type; } function parseIntersectionTypeOrHigher() { - return parseUnionOrIntersectionType(157 /* IntersectionType */, parseArrayTypeOrHigher, 45 /* AmpersandToken */); + return parseUnionOrIntersectionType(159 /* IntersectionType */, parseArrayTypeOrHigher, 46 /* AmpersandToken */); } function parseUnionTypeOrHigher() { - return parseUnionOrIntersectionType(156 /* UnionType */, parseIntersectionTypeOrHigher, 46 /* BarToken */); + return parseUnionOrIntersectionType(158 /* UnionType */, parseIntersectionTypeOrHigher, 47 /* BarToken */); } function isStartOfFunctionType() { if (token === 25 /* LessThanToken */) { @@ -9346,8 +9556,8 @@ var ts; } if (isIdentifier() || ts.isModifier(token)) { nextToken(); - if (token === 53 /* ColonToken */ || token === 24 /* CommaToken */ || - token === 52 /* QuestionToken */ || token === 55 /* EqualsToken */ || + if (token === 54 /* ColonToken */ || token === 24 /* CommaToken */ || + token === 53 /* QuestionToken */ || token === 56 /* EqualsToken */ || isIdentifier() || ts.isModifier(token)) { // ( id : // ( id , @@ -9373,24 +9583,24 @@ var ts; } function parseTypeWorker() { if (isStartOfFunctionType()) { - return parseFunctionOrConstructorType(150 /* FunctionType */); + return parseFunctionOrConstructorType(152 /* FunctionType */); } - if (token === 90 /* NewKeyword */) { - return parseFunctionOrConstructorType(151 /* ConstructorType */); + if (token === 92 /* NewKeyword */) { + return parseFunctionOrConstructorType(153 /* ConstructorType */); } return parseUnionTypeOrHigher(); } function parseTypeAnnotation() { - return parseOptional(53 /* ColonToken */) ? parseType() : undefined; + return parseOptional(54 /* ColonToken */) ? parseType() : undefined; } // EXPRESSIONS function isStartOfLeftHandSideExpression() { switch (token) { - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - case 91 /* NullKeyword */: - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: + case 93 /* NullKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: case 8 /* NumericLiteral */: case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: @@ -9398,12 +9608,12 @@ var ts; case 17 /* OpenParenToken */: case 19 /* OpenBracketToken */: case 15 /* OpenBraceToken */: - case 85 /* FunctionKeyword */: - case 71 /* ClassKeyword */: - case 90 /* NewKeyword */: - case 38 /* SlashToken */: - case 59 /* SlashEqualsToken */: - case 67 /* Identifier */: + case 87 /* FunctionKeyword */: + case 73 /* ClassKeyword */: + case 92 /* NewKeyword */: + case 39 /* SlashToken */: + case 61 /* SlashEqualsToken */: + case 69 /* Identifier */: return true; default: return isIdentifier(); @@ -9416,16 +9626,16 @@ var ts; switch (token) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: - case 48 /* ExclamationToken */: - case 76 /* DeleteKeyword */: - case 99 /* TypeOfKeyword */: - case 101 /* VoidKeyword */: - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: + case 78 /* DeleteKeyword */: + case 101 /* TypeOfKeyword */: + case 103 /* VoidKeyword */: + case 41 /* PlusPlusToken */: + case 42 /* MinusMinusToken */: case 25 /* LessThanToken */: - case 117 /* AwaitKeyword */: - case 112 /* YieldKeyword */: + case 119 /* AwaitKeyword */: + case 114 /* YieldKeyword */: // Yield/await always starts an expression. Either it is an identifier (in which case // it is definitely an expression). Or it's a keyword (either because we're in // a generator or async function, or in strict mode (or both)) and it started a yield or await expression. @@ -9444,9 +9654,9 @@ var ts; function isStartOfExpressionStatement() { // As per the grammar, none of '{' or 'function' or 'class' can start an expression statement. return token !== 15 /* OpenBraceToken */ && - token !== 85 /* FunctionKeyword */ && - token !== 71 /* ClassKeyword */ && - token !== 54 /* AtToken */ && + token !== 87 /* FunctionKeyword */ && + token !== 73 /* ClassKeyword */ && + token !== 55 /* AtToken */ && isStartOfExpression(); } function allowInAndParseExpression() { @@ -9472,7 +9682,7 @@ var ts; return expr; } function parseInitializer(inParameter) { - if (token !== 55 /* EqualsToken */) { + if (token !== 56 /* EqualsToken */) { // It's not uncommon during typing for the user to miss writing the '=' token. Check if // there is no newline after the last token and if we're on an expression. If so, parse // this as an equals-value clause with a missing equals. @@ -9489,7 +9699,7 @@ var ts; } // Initializer[In, Yield] : // = AssignmentExpression[?In, ?Yield] - parseExpected(55 /* EqualsToken */); + parseExpected(56 /* EqualsToken */); return parseAssignmentExpressionOrHigher(); } function parseAssignmentExpressionOrHigher() { @@ -9527,7 +9737,7 @@ var ts; // To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single // identifier and the current token is an arrow. - if (expr.kind === 67 /* Identifier */ && token === 34 /* EqualsGreaterThanToken */) { + if (expr.kind === 69 /* Identifier */ && token === 34 /* EqualsGreaterThanToken */) { return parseSimpleArrowFunctionExpression(expr); } // Now see if we might be in cases '2' or '3'. @@ -9543,7 +9753,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 112 /* YieldKeyword */) { + if (token === 114 /* YieldKeyword */) { // If we have a 'yield' keyword, and htis is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { @@ -9572,7 +9782,7 @@ var ts; return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression() { - var node = createNode(182 /* YieldExpression */); + var node = createNode(184 /* YieldExpression */); // YieldExpression[In] : // yield // yield [no LineTerminator here] [Lexical goal InputElementRegExp]AssignmentExpression[?In, Yield] @@ -9592,8 +9802,8 @@ var ts; } function parseSimpleArrowFunctionExpression(identifier) { ts.Debug.assert(token === 34 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - var node = createNode(172 /* ArrowFunction */, identifier.pos); - var parameter = createNode(136 /* Parameter */, identifier.pos); + var node = createNode(174 /* ArrowFunction */, identifier.pos); + var parameter = createNode(138 /* Parameter */, identifier.pos); parameter.name = identifier; finishNode(parameter); node.parameters = [parameter]; @@ -9635,7 +9845,7 @@ var ts; // Unknown -> There *might* be a parenthesized arrow function here. // Speculatively look ahead to be sure, and rollback if not. function isParenthesizedArrowFunctionExpression() { - if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */ || token === 116 /* AsyncKeyword */) { + if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */ || token === 118 /* AsyncKeyword */) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } if (token === 34 /* EqualsGreaterThanToken */) { @@ -9648,7 +9858,7 @@ var ts; return 0 /* False */; } function isParenthesizedArrowFunctionExpressionWorker() { - if (token === 116 /* AsyncKeyword */) { + if (token === 118 /* AsyncKeyword */) { nextToken(); if (scanner.hasPrecedingLineBreak()) { return 0 /* False */; @@ -9668,7 +9878,7 @@ var ts; var third = nextToken(); switch (third) { case 34 /* EqualsGreaterThanToken */: - case 53 /* ColonToken */: + case 54 /* ColonToken */: case 15 /* OpenBraceToken */: return 1 /* True */; default: @@ -9699,7 +9909,7 @@ var ts; } // If we have something like "(a:", then we must have a // type-annotated parameter in an arrow function expression. - if (nextToken() === 53 /* ColonToken */) { + if (nextToken() === 54 /* ColonToken */) { return 1 /* True */; } // This *could* be a parenthesized arrow function. @@ -9717,10 +9927,10 @@ var ts; if (sourceFile.languageVariant === 1 /* JSX */) { var isArrowFunctionInJsx = lookAhead(function () { var third = nextToken(); - if (third === 81 /* ExtendsKeyword */) { + if (third === 83 /* ExtendsKeyword */) { var fourth = nextToken(); switch (fourth) { - case 55 /* EqualsToken */: + case 56 /* EqualsToken */: case 27 /* GreaterThanToken */: return false; default: @@ -9745,7 +9955,7 @@ var ts; return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false); } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) { - var node = createNode(172 /* ArrowFunction */); + var node = createNode(174 /* ArrowFunction */); setModifiers(node, parseModifiersForArrowFunction()); var isAsync = !!(node.flags & 512 /* Async */); // Arrow functions are never generators. @@ -9755,7 +9965,7 @@ var ts; // a => (b => c) // And think that "(b =>" was actually a parenthesized arrow function with a missing // close paren. - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node); // If we couldn't get parameters, we definitely could not parse out an arrow function. if (!node.parameters) { return undefined; @@ -9779,8 +9989,8 @@ var ts; return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); } if (token !== 23 /* SemicolonToken */ && - token !== 85 /* FunctionKeyword */ && - token !== 71 /* ClassKeyword */ && + token !== 87 /* FunctionKeyword */ && + token !== 73 /* ClassKeyword */ && isStartOfStatement() && !isStartOfExpressionStatement()) { // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) @@ -9805,17 +10015,17 @@ var ts; } function parseConditionalExpressionRest(leftOperand) { // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher. - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (!questionToken) { return leftOperand; } // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and // we do not that for the 'whenFalse' part. - var node = createNode(180 /* ConditionalExpression */, leftOperand.pos); + var node = createNode(182 /* ConditionalExpression */, leftOperand.pos); node.condition = leftOperand; node.questionToken = questionToken; node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); - node.colonToken = parseExpectedToken(53 /* ColonToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(53 /* ColonToken */)); + node.colonToken = parseExpectedToken(54 /* ColonToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(54 /* ColonToken */)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -9824,7 +10034,7 @@ var ts; return parseBinaryExpressionRest(precedence, leftOperand); } function isInOrOfKeyword(t) { - return t === 88 /* InKeyword */ || t === 132 /* OfKeyword */; + return t === 90 /* InKeyword */ || t === 134 /* OfKeyword */; } function parseBinaryExpressionRest(precedence, leftOperand) { while (true) { @@ -9833,13 +10043,36 @@ var ts; reScanGreaterToken(); var newPrecedence = getBinaryOperatorPrecedence(); // Check the precedence to see if we should "take" this operator - if (newPrecedence <= precedence) { + // - For left associative operator (all operator but **), consume the operator, + // recursively call the function below, and parse binaryExpression as a rightOperand + // of the caller if the new precendence of the operator is greater then or equal to the current precendence. + // For example: + // a - b - c; + // ^token; leftOperand = b. Return b to the caller as a rightOperand + // a * b - c + // ^token; leftOperand = b. Return b to the caller as a rightOperand + // a - b * c; + // ^token; leftOperand = b. Return b * c to the caller as a rightOperand + // - For right associative operator (**), consume the operator, recursively call the function + // and parse binaryExpression as a rightOperand of the caller if the new precendence of + // the operator is strictly grater than the current precendence + // For example: + // a ** b ** c; + // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand + // a - b ** c; + // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand + // a ** b - c + // ^token; leftOperand = b. Return b to the caller as a rightOperand + var consumeCurrentOperator = token === 38 /* AsteriskAsteriskToken */ ? + newPrecedence >= precedence : + newPrecedence > precedence; + if (!consumeCurrentOperator) { break; } - if (token === 88 /* InKeyword */ && inDisallowInContext()) { + if (token === 90 /* InKeyword */ && inDisallowInContext()) { break; } - if (token === 114 /* AsKeyword */) { + if (token === 116 /* AsKeyword */) { // Make sure we *do* perform ASI for constructs like this: // var x = foo // as (Bar) @@ -9860,22 +10093,22 @@ var ts; return leftOperand; } function isBinaryOperator() { - if (inDisallowInContext() && token === 88 /* InKeyword */) { + if (inDisallowInContext() && token === 90 /* InKeyword */) { return false; } return getBinaryOperatorPrecedence() > 0; } function getBinaryOperatorPrecedence() { switch (token) { - case 51 /* BarBarToken */: + case 52 /* BarBarToken */: return 1; - case 50 /* AmpersandAmpersandToken */: + case 51 /* AmpersandAmpersandToken */: return 2; - case 46 /* BarToken */: + case 47 /* BarToken */: return 3; - case 47 /* CaretToken */: + case 48 /* CaretToken */: return 4; - case 45 /* AmpersandToken */: + case 46 /* AmpersandToken */: return 5; case 30 /* EqualsEqualsToken */: case 31 /* ExclamationEqualsToken */: @@ -9886,66 +10119,68 @@ var ts; case 27 /* GreaterThanToken */: case 28 /* LessThanEqualsToken */: case 29 /* GreaterThanEqualsToken */: - case 89 /* InstanceOfKeyword */: - case 88 /* InKeyword */: - case 114 /* AsKeyword */: + case 91 /* InstanceOfKeyword */: + case 90 /* InKeyword */: + case 116 /* AsKeyword */: return 7; - case 42 /* LessThanLessThanToken */: - case 43 /* GreaterThanGreaterThanToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: + case 43 /* LessThanLessThanToken */: + case 44 /* GreaterThanGreaterThanToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: return 8; case 35 /* PlusToken */: case 36 /* MinusToken */: return 9; case 37 /* AsteriskToken */: - case 38 /* SlashToken */: - case 39 /* PercentToken */: + case 39 /* SlashToken */: + case 40 /* PercentToken */: return 10; + case 38 /* AsteriskAsteriskToken */: + return 11; } // -1 is lower than all other precedences. Returning it will cause binary expression // parsing to stop. return -1; } function makeBinaryExpression(left, operatorToken, right) { - var node = createNode(179 /* BinaryExpression */, left.pos); + var node = createNode(181 /* BinaryExpression */, left.pos); node.left = left; node.operatorToken = operatorToken; node.right = right; return finishNode(node); } function makeAsExpression(left, right) { - var node = createNode(187 /* AsExpression */, left.pos); + var node = createNode(189 /* AsExpression */, left.pos); node.expression = left; node.type = right; return finishNode(node); } function parsePrefixUnaryExpression() { - var node = createNode(177 /* PrefixUnaryExpression */); + var node = createNode(179 /* PrefixUnaryExpression */); node.operator = token; nextToken(); - node.operand = parseUnaryExpressionOrHigher(); + node.operand = parseSimpleUnaryExpression(); return finishNode(node); } function parseDeleteExpression() { - var node = createNode(173 /* DeleteExpression */); + var node = createNode(175 /* DeleteExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseTypeOfExpression() { - var node = createNode(174 /* TypeOfExpression */); + var node = createNode(176 /* TypeOfExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseVoidExpression() { - var node = createNode(175 /* VoidExpression */); + var node = createNode(177 /* VoidExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function isAwaitExpression() { - if (token === 117 /* AwaitKeyword */) { + if (token === 119 /* AwaitKeyword */) { if (inAwaitContext()) { return true; } @@ -9955,46 +10190,137 @@ var ts; return false; } function parseAwaitExpression() { - var node = createNode(176 /* AwaitExpression */); + var node = createNode(178 /* AwaitExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } + /** + * Parse ES7 unary expression and await expression + * + * ES7 UnaryExpression: + * 1) SimpleUnaryExpression[?yield] + * 2) IncrementExpression[?yield] ** UnaryExpression[?yield] + */ function parseUnaryExpressionOrHigher() { if (isAwaitExpression()) { return parseAwaitExpression(); } + if (isIncrementExpression()) { + var incrementExpression = parseIncrementExpression(); + return token === 38 /* AsteriskAsteriskToken */ ? + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : + incrementExpression; + } + var unaryOperator = token; + var simpleUnaryExpression = parseSimpleUnaryExpression(); + if (token === 38 /* AsteriskAsteriskToken */) { + var diagnostic; + var start = ts.skipTrivia(sourceText, simpleUnaryExpression.pos); + if (simpleUnaryExpression.kind === 171 /* TypeAssertionExpression */) { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses); + } + else { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, ts.tokenToString(unaryOperator)); + } + } + return simpleUnaryExpression; + } + /** + * Parse ES7 simple-unary expression or higher: + * + * ES7 SimpleUnaryExpression: + * 1) IncrementExpression[?yield] + * 2) delete UnaryExpression[?yield] + * 3) void UnaryExpression[?yield] + * 4) typeof UnaryExpression[?yield] + * 5) + UnaryExpression[?yield] + * 6) - UnaryExpression[?yield] + * 7) ~ UnaryExpression[?yield] + * 8) ! UnaryExpression[?yield] + */ + function parseSimpleUnaryExpression() { switch (token) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: - case 48 /* ExclamationToken */: - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: return parsePrefixUnaryExpression(); - case 76 /* DeleteKeyword */: + case 78 /* DeleteKeyword */: return parseDeleteExpression(); - case 99 /* TypeOfKeyword */: + case 101 /* TypeOfKeyword */: return parseTypeOfExpression(); - case 101 /* VoidKeyword */: + case 103 /* VoidKeyword */: return parseVoidExpression(); case 25 /* LessThanToken */: - if (sourceFile.languageVariant !== 1 /* JSX */) { - return parseTypeAssertion(); - } - if (lookAhead(nextTokenIsIdentifierOrKeyword)) { - return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true); - } - // Fall through + // This is modified UnaryExpression grammar in TypeScript + // UnaryExpression (modified): + // < type > UnaryExpression + return parseTypeAssertion(); default: - return parsePostfixExpressionOrHigher(); + return parseIncrementExpression(); } } - function parsePostfixExpressionOrHigher() { + /** + * Check if the current token can possibly be an ES7 increment expression. + * + * ES7 IncrementExpression: + * LeftHandSideExpression[?Yield] + * LeftHandSideExpression[?Yield][no LineTerminator here]++ + * LeftHandSideExpression[?Yield][no LineTerminator here]-- + * ++LeftHandSideExpression[?Yield] + * --LeftHandSideExpression[?Yield] + */ + function isIncrementExpression() { + // This function is called inside parseUnaryExpression to decide + // whether to call parseSimpleUnaryExpression or call parseIncrmentExpression directly + switch (token) { + case 35 /* PlusToken */: + case 36 /* MinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: + case 78 /* DeleteKeyword */: + case 101 /* TypeOfKeyword */: + case 103 /* VoidKeyword */: + return false; + case 25 /* LessThanToken */: + // If we are not in JSX context, we are parsing TypeAssertion which is an UnaryExpression + if (sourceFile.languageVariant !== 1 /* JSX */) { + return false; + } + // We are in JSX context and the token is part of JSXElement. + // Fall through + default: + return true; + } + } + /** + * Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression. + * + * ES7 IncrementExpression[yield]: + * 1) LeftHandSideExpression[?yield] + * 2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++ + * 3) LeftHandSideExpression[?yield] [[no LineTerminator here]]-- + * 4) ++LeftHandSideExpression[?yield] + * 5) --LeftHandSideExpression[?yield] + * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression + */ + function parseIncrementExpression() { + if (token === 41 /* PlusPlusToken */ || token === 42 /* MinusMinusToken */) { + var node = createNode(179 /* PrefixUnaryExpression */); + node.operator = token; + nextToken(); + node.operand = parseLeftHandSideExpressionOrHigher(); + return finishNode(node); + } + else if (sourceFile.languageVariant === 1 /* JSX */ && token === 25 /* LessThanToken */ && lookAhead(nextTokenIsIdentifierOrKeyword)) { + // JSXElement is part of primaryExpression + return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true); + } var expression = parseLeftHandSideExpressionOrHigher(); ts.Debug.assert(ts.isLeftHandSideExpression(expression)); - if ((token === 40 /* PlusPlusToken */ || token === 41 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) { - var node = createNode(178 /* PostfixUnaryExpression */, expression.pos); + if ((token === 41 /* PlusPlusToken */ || token === 42 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) { + var node = createNode(180 /* PostfixUnaryExpression */, expression.pos); node.operand = expression; node.operator = token; nextToken(); @@ -10033,7 +10359,7 @@ var ts; // the last two CallExpression productions. Or we have a MemberExpression which either // completes the LeftHandSideExpression, or starts the beginning of the first four // CallExpression productions. - var expression = token === 93 /* SuperKeyword */ + var expression = token === 95 /* SuperKeyword */ ? parseSuperExpression() : parseMemberExpressionOrHigher(); // Now, we *may* be complete. However, we might have consumed the start of a @@ -10098,7 +10424,7 @@ var ts; } // If we have seen "super" it must be followed by '(' or '.'. // If it wasn't then just try to parse out a '.' and report an error. - var node = createNode(164 /* PropertyAccessExpression */, expression.pos); + var node = createNode(166 /* PropertyAccessExpression */, expression.pos); node.expression = expression; node.dotToken = parseExpectedToken(21 /* DotToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); @@ -10106,27 +10432,27 @@ var ts; } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); - if (opening.kind === 233 /* JsxOpeningElement */) { - var node = createNode(231 /* JsxElement */, opening.pos); + if (opening.kind === 235 /* JsxOpeningElement */) { + var node = createNode(233 /* JsxElement */, opening.pos); node.openingElement = opening; node.children = parseJsxChildren(node.openingElement.tagName); node.closingElement = parseJsxClosingElement(inExpressionContext); return finishNode(node); } else { - ts.Debug.assert(opening.kind === 232 /* JsxSelfClosingElement */); + ts.Debug.assert(opening.kind === 234 /* JsxSelfClosingElement */); // Nothing else to do for self-closing elements return opening; } } function parseJsxText() { - var node = createNode(234 /* JsxText */, scanner.getStartPos()); + var node = createNode(236 /* JsxText */, scanner.getStartPos()); token = scanner.scanJsxToken(); return finishNode(node); } function parseJsxChild() { switch (token) { - case 234 /* JsxText */: + case 236 /* JsxText */: return parseJsxText(); case 15 /* OpenBraceToken */: return parseJsxExpression(/*inExpressionContext*/ false); @@ -10165,11 +10491,11 @@ var ts; // Closing tag, so scan the immediately-following text with the JSX scanning instead // of regular scanning to avoid treating illegal characters (e.g. '#') as immediate // scanning errors - node = createNode(233 /* JsxOpeningElement */, fullStart); + node = createNode(235 /* JsxOpeningElement */, fullStart); scanJsxText(); } else { - parseExpected(38 /* SlashToken */); + parseExpected(39 /* SlashToken */); if (inExpressionContext) { parseExpected(27 /* GreaterThanToken */); } @@ -10177,7 +10503,7 @@ var ts; parseExpected(27 /* GreaterThanToken */, /*diagnostic*/ undefined, /*advance*/ false); scanJsxText(); } - node = createNode(232 /* JsxSelfClosingElement */, fullStart); + node = createNode(234 /* JsxSelfClosingElement */, fullStart); } node.tagName = tagName; node.attributes = attributes; @@ -10188,7 +10514,7 @@ var ts; var elementName = parseIdentifierName(); while (parseOptional(21 /* DotToken */)) { scanJsxIdentifier(); - var node = createNode(133 /* QualifiedName */, elementName.pos); + var node = createNode(135 /* QualifiedName */, elementName.pos); node.left = elementName; node.right = parseIdentifierName(); elementName = finishNode(node); @@ -10196,7 +10522,7 @@ var ts; return elementName; } function parseJsxExpression(inExpressionContext) { - var node = createNode(238 /* JsxExpression */); + var node = createNode(240 /* JsxExpression */); parseExpected(15 /* OpenBraceToken */); if (token !== 16 /* CloseBraceToken */) { node.expression = parseExpression(); @@ -10215,9 +10541,9 @@ var ts; return parseJsxSpreadAttribute(); } scanJsxIdentifier(); - var node = createNode(236 /* JsxAttribute */); + var node = createNode(238 /* JsxAttribute */); node.name = parseIdentifierName(); - if (parseOptional(55 /* EqualsToken */)) { + if (parseOptional(56 /* EqualsToken */)) { switch (token) { case 9 /* StringLiteral */: node.initializer = parseLiteralNode(); @@ -10230,7 +10556,7 @@ var ts; return finishNode(node); } function parseJsxSpreadAttribute() { - var node = createNode(237 /* JsxSpreadAttribute */); + var node = createNode(239 /* JsxSpreadAttribute */); parseExpected(15 /* OpenBraceToken */); parseExpected(22 /* DotDotDotToken */); node.expression = parseExpression(); @@ -10238,7 +10564,7 @@ var ts; return finishNode(node); } function parseJsxClosingElement(inExpressionContext) { - var node = createNode(235 /* JsxClosingElement */); + var node = createNode(237 /* JsxClosingElement */); parseExpected(26 /* LessThanSlashToken */); node.tagName = parseJsxElementName(); if (inExpressionContext) { @@ -10251,18 +10577,18 @@ var ts; return finishNode(node); } function parseTypeAssertion() { - var node = createNode(169 /* TypeAssertionExpression */); + var node = createNode(171 /* TypeAssertionExpression */); parseExpected(25 /* LessThanToken */); node.type = parseType(); parseExpected(27 /* GreaterThanToken */); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseMemberExpressionRest(expression) { while (true) { var dotToken = parseOptionalToken(21 /* DotToken */); if (dotToken) { - var propertyAccess = createNode(164 /* PropertyAccessExpression */, expression.pos); + var propertyAccess = createNode(166 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); @@ -10271,7 +10597,7 @@ var ts; } // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName if (!inDecoratorContext() && parseOptional(19 /* OpenBracketToken */)) { - var indexedAccess = createNode(165 /* ElementAccessExpression */, expression.pos); + var indexedAccess = createNode(167 /* ElementAccessExpression */, expression.pos); indexedAccess.expression = expression; // It's not uncommon for a user to write: "new Type[]". // Check for that common pattern and report a better error message. @@ -10287,7 +10613,7 @@ var ts; continue; } if (token === 11 /* NoSubstitutionTemplateLiteral */ || token === 12 /* TemplateHead */) { - var tagExpression = createNode(168 /* TaggedTemplateExpression */, expression.pos); + var tagExpression = createNode(170 /* TaggedTemplateExpression */, expression.pos); tagExpression.tag = expression; tagExpression.template = token === 11 /* NoSubstitutionTemplateLiteral */ ? parseLiteralNode() @@ -10310,7 +10636,7 @@ var ts; if (!typeArguments) { return expression; } - var callExpr = createNode(166 /* CallExpression */, expression.pos); + var callExpr = createNode(168 /* CallExpression */, expression.pos); callExpr.expression = expression; callExpr.typeArguments = typeArguments; callExpr.arguments = parseArgumentList(); @@ -10318,7 +10644,7 @@ var ts; continue; } else if (token === 17 /* OpenParenToken */) { - var callExpr = createNode(166 /* CallExpression */, expression.pos); + var callExpr = createNode(168 /* CallExpression */, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); expression = finishNode(callExpr); @@ -10356,18 +10682,18 @@ var ts; case 21 /* DotToken */: // foo. case 18 /* CloseParenToken */: // foo) case 20 /* CloseBracketToken */: // foo] - case 53 /* ColonToken */: // foo: + case 54 /* ColonToken */: // foo: case 23 /* SemicolonToken */: // foo; - case 52 /* QuestionToken */: // foo? + case 53 /* QuestionToken */: // foo? case 30 /* EqualsEqualsToken */: // foo == case 32 /* EqualsEqualsEqualsToken */: // foo === case 31 /* ExclamationEqualsToken */: // foo != case 33 /* ExclamationEqualsEqualsToken */: // foo !== - case 50 /* AmpersandAmpersandToken */: // foo && - case 51 /* BarBarToken */: // foo || - case 47 /* CaretToken */: // foo ^ - case 45 /* AmpersandToken */: // foo & - case 46 /* BarToken */: // foo | + case 51 /* AmpersandAmpersandToken */: // foo && + case 52 /* BarBarToken */: // foo || + case 48 /* CaretToken */: // foo ^ + case 46 /* AmpersandToken */: // foo & + case 47 /* BarToken */: // foo | case 16 /* CloseBraceToken */: // foo } case 1 /* EndOfFileToken */: // these cases can't legally follow a type arg list. However, they're not legal @@ -10390,11 +10716,11 @@ var ts; case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: return parseLiteralNode(); - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - case 91 /* NullKeyword */: - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: + case 93 /* NullKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: return parseTokenNode(); case 17 /* OpenParenToken */: return parseParenthesizedExpression(); @@ -10402,7 +10728,7 @@ var ts; return parseArrayLiteralExpression(); case 15 /* OpenBraceToken */: return parseObjectLiteralExpression(); - case 116 /* AsyncKeyword */: + case 118 /* AsyncKeyword */: // Async arrow functions are parsed earlier in parseAssignmentExpressionOrHigher. // If we encounter `async [no LineTerminator here] function` then this is an async // function; otherwise, its an identifier. @@ -10410,14 +10736,14 @@ var ts; break; } return parseFunctionExpression(); - case 71 /* ClassKeyword */: + case 73 /* ClassKeyword */: return parseClassExpression(); - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseFunctionExpression(); - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: return parseNewExpression(); - case 38 /* SlashToken */: - case 59 /* SlashEqualsToken */: + case 39 /* SlashToken */: + case 61 /* SlashEqualsToken */: if (reScanSlashToken() === 10 /* RegularExpressionLiteral */) { return parseLiteralNode(); } @@ -10428,28 +10754,28 @@ var ts; return parseIdentifier(ts.Diagnostics.Expression_expected); } function parseParenthesizedExpression() { - var node = createNode(170 /* ParenthesizedExpression */); + var node = createNode(172 /* ParenthesizedExpression */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); return finishNode(node); } function parseSpreadElement() { - var node = createNode(183 /* SpreadElementExpression */); + var node = createNode(185 /* SpreadElementExpression */); parseExpected(22 /* DotDotDotToken */); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); } function parseArgumentOrArrayLiteralElement() { return token === 22 /* DotDotDotToken */ ? parseSpreadElement() : - token === 24 /* CommaToken */ ? createNode(185 /* OmittedExpression */) : + token === 24 /* CommaToken */ ? createNode(187 /* OmittedExpression */) : parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression() { - var node = createNode(162 /* ArrayLiteralExpression */); + var node = createNode(164 /* ArrayLiteralExpression */); parseExpected(19 /* OpenBracketToken */); if (scanner.hasPrecedingLineBreak()) node.flags |= 2048 /* MultiLine */; @@ -10458,11 +10784,11 @@ var ts; return finishNode(node); } function tryParseAccessorDeclaration(fullStart, decorators, modifiers) { - if (parseContextualModifier(121 /* GetKeyword */)) { - return parseAccessorDeclaration(143 /* GetAccessor */, fullStart, decorators, modifiers); + if (parseContextualModifier(123 /* GetKeyword */)) { + return parseAccessorDeclaration(145 /* GetAccessor */, fullStart, decorators, modifiers); } - else if (parseContextualModifier(127 /* SetKeyword */)) { - return parseAccessorDeclaration(144 /* SetAccessor */, fullStart, decorators, modifiers); + else if (parseContextualModifier(129 /* SetKeyword */)) { + return parseAccessorDeclaration(146 /* SetAccessor */, fullStart, decorators, modifiers); } return undefined; } @@ -10479,28 +10805,38 @@ var ts; var nameToken = token; var propertyName = parsePropertyName(); // Disallowing of optional property assignments happens in the grammar checker. - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (asteriskToken || token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } - // Parse to check if it is short-hand property assignment or normal property assignment - if ((token === 24 /* CommaToken */ || token === 16 /* CloseBraceToken */) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(244 /* ShorthandPropertyAssignment */, fullStart); + // check if it is short-hand property assignment or normal property assignment + // NOTE: if token is EqualsToken it is interpreted as CoverInitializedName production + // CoverInitializedName[Yield] : + // IdentifierReference[?Yield] Initializer[In, ?Yield] + // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern + var isShorthandPropertyAssignment = tokenIsIdentifier && (token === 24 /* CommaToken */ || token === 16 /* CloseBraceToken */ || token === 56 /* EqualsToken */); + if (isShorthandPropertyAssignment) { + var shorthandDeclaration = createNode(246 /* ShorthandPropertyAssignment */, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; + var equalsToken = parseOptionalToken(56 /* EqualsToken */); + if (equalsToken) { + shorthandDeclaration.equalsToken = equalsToken; + shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher); + } return finishNode(shorthandDeclaration); } else { - var propertyAssignment = createNode(243 /* PropertyAssignment */, fullStart); + var propertyAssignment = createNode(245 /* PropertyAssignment */, fullStart); propertyAssignment.name = propertyName; propertyAssignment.questionToken = questionToken; - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); return finishNode(propertyAssignment); } } function parseObjectLiteralExpression() { - var node = createNode(163 /* ObjectLiteralExpression */); + var node = createNode(165 /* ObjectLiteralExpression */); parseExpected(15 /* OpenBraceToken */); if (scanner.hasPrecedingLineBreak()) { node.flags |= 2048 /* MultiLine */; @@ -10519,9 +10855,9 @@ var ts; if (saveDecoratorContext) { setDecoratorContext(false); } - var node = createNode(171 /* FunctionExpression */); + var node = createNode(173 /* FunctionExpression */); setModifiers(node, parseModifiers()); - parseExpected(85 /* FunctionKeyword */); + parseExpected(87 /* FunctionKeyword */); node.asteriskToken = parseOptionalToken(37 /* AsteriskToken */); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512 /* Async */); @@ -10530,7 +10866,7 @@ var ts; isGenerator ? doInYieldContext(parseOptionalIdentifier) : isAsync ? doInAwaitContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); if (saveDecoratorContext) { setDecoratorContext(true); @@ -10541,8 +10877,8 @@ var ts; return isIdentifier() ? parseIdentifier() : undefined; } function parseNewExpression() { - var node = createNode(167 /* NewExpression */); - parseExpected(90 /* NewKeyword */); + var node = createNode(169 /* NewExpression */); + parseExpected(92 /* NewKeyword */); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); if (node.typeArguments || token === 17 /* OpenParenToken */) { @@ -10552,7 +10888,7 @@ var ts; } // STATEMENTS function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) { - var node = createNode(190 /* Block */); + var node = createNode(192 /* Block */); if (parseExpected(15 /* OpenBraceToken */, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(1 /* BlockStatements */, parseStatement); parseExpected(16 /* CloseBraceToken */); @@ -10582,25 +10918,25 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(192 /* EmptyStatement */); + var node = createNode(194 /* EmptyStatement */); parseExpected(23 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(194 /* IfStatement */); - parseExpected(86 /* IfKeyword */); + var node = createNode(196 /* IfStatement */); + parseExpected(88 /* IfKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); node.thenStatement = parseStatement(); - node.elseStatement = parseOptional(78 /* ElseKeyword */) ? parseStatement() : undefined; + node.elseStatement = parseOptional(80 /* ElseKeyword */) ? parseStatement() : undefined; return finishNode(node); } function parseDoStatement() { - var node = createNode(195 /* DoStatement */); - parseExpected(77 /* DoKeyword */); + var node = createNode(197 /* DoStatement */); + parseExpected(79 /* DoKeyword */); node.statement = parseStatement(); - parseExpected(102 /* WhileKeyword */); + parseExpected(104 /* WhileKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); @@ -10612,8 +10948,8 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(196 /* WhileStatement */); - parseExpected(102 /* WhileKeyword */); + var node = createNode(198 /* WhileStatement */); + parseExpected(104 /* WhileKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); @@ -10622,11 +10958,11 @@ var ts; } function parseForOrForInOrForOfStatement() { var pos = getNodePos(); - parseExpected(84 /* ForKeyword */); + parseExpected(86 /* ForKeyword */); parseExpected(17 /* OpenParenToken */); var initializer = undefined; if (token !== 23 /* SemicolonToken */) { - if (token === 100 /* VarKeyword */ || token === 106 /* LetKeyword */ || token === 72 /* ConstKeyword */) { + if (token === 102 /* VarKeyword */ || token === 108 /* LetKeyword */ || token === 74 /* ConstKeyword */) { initializer = parseVariableDeclarationList(/*inForStatementInitializer*/ true); } else { @@ -10634,22 +10970,22 @@ var ts; } } var forOrForInOrForOfStatement; - if (parseOptional(88 /* InKeyword */)) { - var forInStatement = createNode(198 /* ForInStatement */, pos); + if (parseOptional(90 /* InKeyword */)) { + var forInStatement = createNode(200 /* ForInStatement */, pos); forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); forOrForInOrForOfStatement = forInStatement; } - else if (parseOptional(132 /* OfKeyword */)) { - var forOfStatement = createNode(199 /* ForOfStatement */, pos); + else if (parseOptional(134 /* OfKeyword */)) { + var forOfStatement = createNode(201 /* ForOfStatement */, pos); forOfStatement.initializer = initializer; forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher); parseExpected(18 /* CloseParenToken */); forOrForInOrForOfStatement = forOfStatement; } else { - var forStatement = createNode(197 /* ForStatement */, pos); + var forStatement = createNode(199 /* ForStatement */, pos); forStatement.initializer = initializer; parseExpected(23 /* SemicolonToken */); if (token !== 23 /* SemicolonToken */ && token !== 18 /* CloseParenToken */) { @@ -10667,7 +11003,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 201 /* BreakStatement */ ? 68 /* BreakKeyword */ : 73 /* ContinueKeyword */); + parseExpected(kind === 203 /* BreakStatement */ ? 70 /* BreakKeyword */ : 75 /* ContinueKeyword */); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -10675,8 +11011,8 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(202 /* ReturnStatement */); - parseExpected(92 /* ReturnKeyword */); + var node = createNode(204 /* ReturnStatement */); + parseExpected(94 /* ReturnKeyword */); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); } @@ -10684,8 +11020,8 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(203 /* WithStatement */); - parseExpected(103 /* WithKeyword */); + var node = createNode(205 /* WithStatement */); + parseExpected(105 /* WithKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); @@ -10693,30 +11029,30 @@ var ts; return finishNode(node); } function parseCaseClause() { - var node = createNode(239 /* CaseClause */); - parseExpected(69 /* CaseKeyword */); + var node = createNode(241 /* CaseClause */); + parseExpected(71 /* CaseKeyword */); node.expression = allowInAnd(parseExpression); - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); node.statements = parseList(3 /* SwitchClauseStatements */, parseStatement); return finishNode(node); } function parseDefaultClause() { - var node = createNode(240 /* DefaultClause */); - parseExpected(75 /* DefaultKeyword */); - parseExpected(53 /* ColonToken */); + var node = createNode(242 /* DefaultClause */); + parseExpected(77 /* DefaultKeyword */); + parseExpected(54 /* ColonToken */); node.statements = parseList(3 /* SwitchClauseStatements */, parseStatement); return finishNode(node); } function parseCaseOrDefaultClause() { - return token === 69 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); + return token === 71 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(204 /* SwitchStatement */); - parseExpected(94 /* SwitchKeyword */); + var node = createNode(206 /* SwitchStatement */); + parseExpected(96 /* SwitchKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); - var caseBlock = createNode(218 /* CaseBlock */, scanner.getStartPos()); + var caseBlock = createNode(220 /* CaseBlock */, scanner.getStartPos()); parseExpected(15 /* OpenBraceToken */); caseBlock.clauses = parseList(2 /* SwitchClauses */, parseCaseOrDefaultClause); parseExpected(16 /* CloseBraceToken */); @@ -10731,29 +11067,29 @@ var ts; // directly as that might consume an expression on the following line. // We just return 'undefined' in that case. The actual error will be reported in the // grammar walker. - var node = createNode(206 /* ThrowStatement */); - parseExpected(96 /* ThrowKeyword */); + var node = createNode(208 /* ThrowStatement */); + parseExpected(98 /* ThrowKeyword */); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } // TODO: Review for error recovery function parseTryStatement() { - var node = createNode(207 /* TryStatement */); - parseExpected(98 /* TryKeyword */); + var node = createNode(209 /* TryStatement */); + parseExpected(100 /* TryKeyword */); node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); - node.catchClause = token === 70 /* CatchKeyword */ ? parseCatchClause() : undefined; + node.catchClause = token === 72 /* CatchKeyword */ ? parseCatchClause() : undefined; // If we don't have a catch clause, then we must have a finally clause. Try to parse // one out no matter what. - if (!node.catchClause || token === 83 /* FinallyKeyword */) { - parseExpected(83 /* FinallyKeyword */); + if (!node.catchClause || token === 85 /* FinallyKeyword */) { + parseExpected(85 /* FinallyKeyword */); node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); } return finishNode(node); } function parseCatchClause() { - var result = createNode(242 /* CatchClause */); - parseExpected(70 /* CatchKeyword */); + var result = createNode(244 /* CatchClause */); + parseExpected(72 /* CatchKeyword */); if (parseExpected(17 /* OpenParenToken */)) { result.variableDeclaration = parseVariableDeclaration(); } @@ -10762,8 +11098,8 @@ var ts; return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(208 /* DebuggerStatement */); - parseExpected(74 /* DebuggerKeyword */); + var node = createNode(210 /* DebuggerStatement */); + parseExpected(76 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); } @@ -10773,14 +11109,14 @@ var ts; // a colon. var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); - if (expression.kind === 67 /* Identifier */ && parseOptional(53 /* ColonToken */)) { - var labeledStatement = createNode(205 /* LabeledStatement */, fullStart); + if (expression.kind === 69 /* Identifier */ && parseOptional(54 /* ColonToken */)) { + var labeledStatement = createNode(207 /* LabeledStatement */, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(193 /* ExpressionStatement */, fullStart); + var expressionStatement = createNode(195 /* ExpressionStatement */, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); @@ -10792,7 +11128,7 @@ var ts; } function nextTokenIsFunctionKeywordOnSameLine() { nextToken(); - return token === 85 /* FunctionKeyword */ && !scanner.hasPrecedingLineBreak(); + return token === 87 /* FunctionKeyword */ && !scanner.hasPrecedingLineBreak(); } function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); @@ -10801,12 +11137,12 @@ var ts; function isDeclaration() { while (true) { switch (token) { - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: - case 85 /* FunctionKeyword */: - case 71 /* ClassKeyword */: - case 79 /* EnumKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: + case 87 /* FunctionKeyword */: + case 73 /* ClassKeyword */: + case 81 /* EnumKeyword */: return true; // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; // however, an identifier cannot be followed by another identifier on the same line. This is what we @@ -10829,36 +11165,36 @@ var ts; // I {} // // could be legal, it would add complexity for very little gain. - case 105 /* InterfaceKeyword */: - case 130 /* TypeKeyword */: + case 107 /* InterfaceKeyword */: + case 132 /* TypeKeyword */: return nextTokenIsIdentifierOnSameLine(); - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: return nextTokenIsIdentifierOrStringLiteralOnSameLine(); - case 116 /* AsyncKeyword */: - case 120 /* DeclareKeyword */: + case 115 /* AbstractKeyword */: + case 118 /* AsyncKeyword */: + case 122 /* DeclareKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 112 /* PublicKeyword */: nextToken(); // ASI takes effect for this modifier. if (scanner.hasPrecedingLineBreak()) { return false; } continue; - case 87 /* ImportKeyword */: + case 89 /* ImportKeyword */: nextToken(); return token === 9 /* StringLiteral */ || token === 37 /* AsteriskToken */ || token === 15 /* OpenBraceToken */ || ts.tokenIsIdentifierOrKeyword(token); - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: nextToken(); - if (token === 55 /* EqualsToken */ || token === 37 /* AsteriskToken */ || - token === 15 /* OpenBraceToken */ || token === 75 /* DefaultKeyword */) { + if (token === 56 /* EqualsToken */ || token === 37 /* AsteriskToken */ || + token === 15 /* OpenBraceToken */ || token === 77 /* DefaultKeyword */) { return true; } continue; - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: - case 113 /* AbstractKeyword */: + case 113 /* StaticKeyword */: nextToken(); continue; default: @@ -10871,47 +11207,47 @@ var ts; } function isStartOfStatement() { switch (token) { - case 54 /* AtToken */: + case 55 /* AtToken */: case 23 /* SemicolonToken */: case 15 /* OpenBraceToken */: - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 85 /* FunctionKeyword */: - case 71 /* ClassKeyword */: - case 79 /* EnumKeyword */: - case 86 /* IfKeyword */: - case 77 /* DoKeyword */: - case 102 /* WhileKeyword */: - case 84 /* ForKeyword */: - case 73 /* ContinueKeyword */: - case 68 /* BreakKeyword */: - case 92 /* ReturnKeyword */: - case 103 /* WithKeyword */: - case 94 /* SwitchKeyword */: - case 96 /* ThrowKeyword */: - case 98 /* TryKeyword */: - case 74 /* DebuggerKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 87 /* FunctionKeyword */: + case 73 /* ClassKeyword */: + case 81 /* EnumKeyword */: + case 88 /* IfKeyword */: + case 79 /* DoKeyword */: + case 104 /* WhileKeyword */: + case 86 /* ForKeyword */: + case 75 /* ContinueKeyword */: + case 70 /* BreakKeyword */: + case 94 /* ReturnKeyword */: + case 105 /* WithKeyword */: + case 96 /* SwitchKeyword */: + case 98 /* ThrowKeyword */: + case 100 /* TryKeyword */: + case 76 /* DebuggerKeyword */: // 'catch' and 'finally' do not actually indicate that the code is part of a statement, // however, we say they are here so that we may gracefully parse them and error later. - case 70 /* CatchKeyword */: - case 83 /* FinallyKeyword */: + case 72 /* CatchKeyword */: + case 85 /* FinallyKeyword */: return true; - case 72 /* ConstKeyword */: - case 80 /* ExportKeyword */: - case 87 /* ImportKeyword */: + case 74 /* ConstKeyword */: + case 82 /* ExportKeyword */: + case 89 /* ImportKeyword */: return isStartOfDeclaration(); - case 116 /* AsyncKeyword */: - case 120 /* DeclareKeyword */: - case 105 /* InterfaceKeyword */: - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: - case 130 /* TypeKeyword */: + case 118 /* AsyncKeyword */: + case 122 /* DeclareKeyword */: + case 107 /* InterfaceKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: + case 132 /* TypeKeyword */: // When these don't start a declaration, they're an identifier in an expression statement return true; - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 113 /* StaticKeyword */: // When these don't start a declaration, they may be the start of a class member if an identifier // immediately follows. Otherwise they're an identifier in an expression statement. return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); @@ -10934,61 +11270,61 @@ var ts; return parseEmptyStatement(); case 15 /* OpenBraceToken */: return parseBlock(/*ignoreMissingOpenBrace*/ false); - case 100 /* VarKeyword */: + case 102 /* VarKeyword */: return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); - case 106 /* LetKeyword */: + case 108 /* LetKeyword */: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); } break; - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); - case 71 /* ClassKeyword */: + case 73 /* ClassKeyword */: return parseClassDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); - case 86 /* IfKeyword */: + case 88 /* IfKeyword */: return parseIfStatement(); - case 77 /* DoKeyword */: + case 79 /* DoKeyword */: return parseDoStatement(); - case 102 /* WhileKeyword */: + case 104 /* WhileKeyword */: return parseWhileStatement(); - case 84 /* ForKeyword */: + case 86 /* ForKeyword */: return parseForOrForInOrForOfStatement(); - case 73 /* ContinueKeyword */: - return parseBreakOrContinueStatement(200 /* ContinueStatement */); - case 68 /* BreakKeyword */: - return parseBreakOrContinueStatement(201 /* BreakStatement */); - case 92 /* ReturnKeyword */: + case 75 /* ContinueKeyword */: + return parseBreakOrContinueStatement(202 /* ContinueStatement */); + case 70 /* BreakKeyword */: + return parseBreakOrContinueStatement(203 /* BreakStatement */); + case 94 /* ReturnKeyword */: return parseReturnStatement(); - case 103 /* WithKeyword */: + case 105 /* WithKeyword */: return parseWithStatement(); - case 94 /* SwitchKeyword */: + case 96 /* SwitchKeyword */: return parseSwitchStatement(); - case 96 /* ThrowKeyword */: + case 98 /* ThrowKeyword */: return parseThrowStatement(); - case 98 /* TryKeyword */: + case 100 /* TryKeyword */: // Include 'catch' and 'finally' for error recovery. - case 70 /* CatchKeyword */: - case 83 /* FinallyKeyword */: + case 72 /* CatchKeyword */: + case 85 /* FinallyKeyword */: return parseTryStatement(); - case 74 /* DebuggerKeyword */: + case 76 /* DebuggerKeyword */: return parseDebuggerStatement(); - case 54 /* AtToken */: + case 55 /* AtToken */: return parseDeclaration(); - case 116 /* AsyncKeyword */: - case 105 /* InterfaceKeyword */: - case 130 /* TypeKeyword */: - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: - case 120 /* DeclareKeyword */: - case 72 /* ConstKeyword */: - case 79 /* EnumKeyword */: - case 80 /* ExportKeyword */: - case 87 /* ImportKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 110 /* PublicKeyword */: - case 113 /* AbstractKeyword */: - case 111 /* StaticKeyword */: + case 118 /* AsyncKeyword */: + case 107 /* InterfaceKeyword */: + case 132 /* TypeKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: + case 122 /* DeclareKeyword */: + case 74 /* ConstKeyword */: + case 81 /* EnumKeyword */: + case 82 /* ExportKeyword */: + case 89 /* ImportKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 112 /* PublicKeyword */: + case 115 /* AbstractKeyword */: + case 113 /* StaticKeyword */: if (isStartOfDeclaration()) { return parseDeclaration(); } @@ -11001,35 +11337,35 @@ var ts; var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: return parseVariableStatement(fullStart, decorators, modifiers); - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 71 /* ClassKeyword */: + case 73 /* ClassKeyword */: return parseClassDeclaration(fullStart, decorators, modifiers); - case 105 /* InterfaceKeyword */: + case 107 /* InterfaceKeyword */: return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 130 /* TypeKeyword */: + case 132 /* TypeKeyword */: return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 79 /* EnumKeyword */: + case 81 /* EnumKeyword */: return parseEnumDeclaration(fullStart, decorators, modifiers); - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: return parseModuleDeclaration(fullStart, decorators, modifiers); - case 87 /* ImportKeyword */: + case 89 /* ImportKeyword */: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: nextToken(); - return token === 75 /* DefaultKeyword */ || token === 55 /* EqualsToken */ ? + return token === 77 /* DefaultKeyword */ || token === 56 /* EqualsToken */ ? parseExportAssignment(fullStart, decorators, modifiers) : parseExportDeclaration(fullStart, decorators, modifiers); default: if (decorators || modifiers) { // We reached this point because we encountered decorators and/or modifiers and assumed a declaration // would follow. For recovery and error reporting purposes, return an incomplete declaration. - var node = createMissingNode(229 /* MissingDeclaration */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); + var node = createMissingNode(231 /* MissingDeclaration */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; setModifiers(node, modifiers); @@ -11051,24 +11387,24 @@ var ts; // DECLARATIONS function parseArrayBindingElement() { if (token === 24 /* CommaToken */) { - return createNode(185 /* OmittedExpression */); + return createNode(187 /* OmittedExpression */); } - var node = createNode(161 /* BindingElement */); + var node = createNode(163 /* BindingElement */); node.dotDotDotToken = parseOptionalToken(22 /* DotDotDotToken */); node.name = parseIdentifierOrPattern(); node.initializer = parseBindingElementInitializer(/*inParameter*/ false); return finishNode(node); } function parseObjectBindingElement() { - var node = createNode(161 /* BindingElement */); + var node = createNode(163 /* BindingElement */); // TODO(andersh): Handle computed properties var tokenIsIdentifier = isIdentifier(); var propertyName = parsePropertyName(); - if (tokenIsIdentifier && token !== 53 /* ColonToken */) { + if (tokenIsIdentifier && token !== 54 /* ColonToken */) { node.name = propertyName; } else { - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); node.propertyName = propertyName; node.name = parseIdentifierOrPattern(); } @@ -11076,14 +11412,14 @@ var ts; return finishNode(node); } function parseObjectBindingPattern() { - var node = createNode(159 /* ObjectBindingPattern */); + var node = createNode(161 /* ObjectBindingPattern */); parseExpected(15 /* OpenBraceToken */); node.elements = parseDelimitedList(9 /* ObjectBindingElements */, parseObjectBindingElement); parseExpected(16 /* CloseBraceToken */); return finishNode(node); } function parseArrayBindingPattern() { - var node = createNode(160 /* ArrayBindingPattern */); + var node = createNode(162 /* ArrayBindingPattern */); parseExpected(19 /* OpenBracketToken */); node.elements = parseDelimitedList(10 /* ArrayBindingElements */, parseArrayBindingElement); parseExpected(20 /* CloseBracketToken */); @@ -11102,7 +11438,7 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(209 /* VariableDeclaration */); + var node = createNode(211 /* VariableDeclaration */); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); if (!isInOrOfKeyword(token)) { @@ -11111,14 +11447,14 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(inForStatementInitializer) { - var node = createNode(210 /* VariableDeclarationList */); + var node = createNode(212 /* VariableDeclarationList */); switch (token) { - case 100 /* VarKeyword */: + case 102 /* VarKeyword */: break; - case 106 /* LetKeyword */: + case 108 /* LetKeyword */: node.flags |= 16384 /* Let */; break; - case 72 /* ConstKeyword */: + case 74 /* ConstKeyword */: node.flags |= 32768 /* Const */; break; default: @@ -11134,7 +11470,7 @@ var ts; // So we need to look ahead to determine if 'of' should be treated as a keyword in // this context. // The checker will then give an error that there is an empty declaration list. - if (token === 132 /* OfKeyword */ && lookAhead(canFollowContextualOfKeyword)) { + if (token === 134 /* OfKeyword */ && lookAhead(canFollowContextualOfKeyword)) { node.declarations = createMissingList(); } else { @@ -11149,7 +11485,7 @@ var ts; return nextTokenIsIdentifier() && nextToken() === 18 /* CloseParenToken */; } function parseVariableStatement(fullStart, decorators, modifiers) { - var node = createNode(191 /* VariableStatement */, fullStart); + var node = createNode(193 /* VariableStatement */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer*/ false); @@ -11157,29 +11493,29 @@ var ts; return finishNode(node); } function parseFunctionDeclaration(fullStart, decorators, modifiers) { - var node = createNode(211 /* FunctionDeclaration */, fullStart); + var node = createNode(213 /* FunctionDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(85 /* FunctionKeyword */); + parseExpected(87 /* FunctionKeyword */); node.asteriskToken = parseOptionalToken(37 /* AsteriskToken */); node.name = node.flags & 1024 /* Default */ ? parseOptionalIdentifier() : parseIdentifier(); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512 /* Async */); - fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, decorators, modifiers) { - var node = createNode(142 /* Constructor */, pos); + var node = createNode(144 /* Constructor */, pos); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(119 /* ConstructorKeyword */); - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); + parseExpected(121 /* ConstructorKeyword */); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false, ts.Diagnostics.or_expected); return finishNode(node); } function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { - var method = createNode(141 /* MethodDeclaration */, fullStart); + var method = createNode(143 /* MethodDeclaration */, fullStart); method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; @@ -11187,12 +11523,12 @@ var ts; method.questionToken = questionToken; var isGenerator = !!asteriskToken; var isAsync = !!(method.flags & 512 /* Async */); - fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method); + fillSignature(54 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method); method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage); return finishNode(method); } function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) { - var property = createNode(139 /* PropertyDeclaration */, fullStart); + var property = createNode(141 /* PropertyDeclaration */, fullStart); property.decorators = decorators; setModifiers(property, modifiers); property.name = name; @@ -11218,7 +11554,7 @@ var ts; var name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (asteriskToken || token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } @@ -11234,16 +11570,16 @@ var ts; node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false); return finishNode(node); } function isClassMemberModifier(idToken) { switch (idToken) { - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 113 /* StaticKeyword */: return true; default: return false; @@ -11251,7 +11587,7 @@ var ts; } function isClassMemberStart() { var idToken; - if (token === 54 /* AtToken */) { + if (token === 55 /* AtToken */) { return true; } // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. @@ -11284,7 +11620,7 @@ var ts; // If we were able to get any potential identifier... if (idToken !== undefined) { // If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse. - if (!ts.isKeyword(idToken) || idToken === 127 /* SetKeyword */ || idToken === 121 /* GetKeyword */) { + if (!ts.isKeyword(idToken) || idToken === 129 /* SetKeyword */ || idToken === 123 /* GetKeyword */) { return true; } // If it *is* a keyword, but not an accessor, check a little farther along @@ -11292,9 +11628,9 @@ var ts; switch (token) { case 17 /* OpenParenToken */: // Method declaration case 25 /* LessThanToken */: // Generic Method declaration - case 53 /* ColonToken */: // Type Annotation for declaration - case 55 /* EqualsToken */: // Initializer for declaration - case 52 /* QuestionToken */: + case 54 /* ColonToken */: // Type Annotation for declaration + case 56 /* EqualsToken */: // Initializer for declaration + case 53 /* QuestionToken */: return true; default: // Covers @@ -11311,14 +11647,14 @@ var ts; var decorators; while (true) { var decoratorStart = getNodePos(); - if (!parseOptional(54 /* AtToken */)) { + if (!parseOptional(55 /* AtToken */)) { break; } if (!decorators) { decorators = []; decorators.pos = scanner.getStartPos(); } - var decorator = createNode(137 /* Decorator */, decoratorStart); + var decorator = createNode(139 /* Decorator */, decoratorStart); decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); decorators.push(finishNode(decorator)); } @@ -11352,7 +11688,7 @@ var ts; function parseModifiersForArrowFunction() { var flags = 0; var modifiers; - if (token === 116 /* AsyncKeyword */) { + if (token === 118 /* AsyncKeyword */) { var modifierStart = scanner.getStartPos(); var modifierKind = token; nextToken(); @@ -11367,7 +11703,7 @@ var ts; } function parseClassElement() { if (token === 23 /* SemicolonToken */) { - var result = createNode(189 /* SemicolonClassElement */); + var result = createNode(191 /* SemicolonClassElement */); nextToken(); return finishNode(result); } @@ -11378,7 +11714,7 @@ var ts; if (accessor) { return accessor; } - if (token === 119 /* ConstructorKeyword */) { + if (token === 121 /* ConstructorKeyword */) { return parseConstructorDeclaration(fullStart, decorators, modifiers); } if (isIndexSignature()) { @@ -11395,7 +11731,7 @@ var ts; } if (decorators || modifiers) { // treat this as a property declaration with a missing name. - var name_7 = createMissingNode(67 /* Identifier */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); + var name_7 = createMissingNode(69 /* Identifier */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_7, /*questionToken*/ undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. @@ -11405,17 +11741,17 @@ var ts; return parseClassDeclarationOrExpression( /*fullStart*/ scanner.getStartPos(), /*decorators*/ undefined, - /*modifiers*/ undefined, 184 /* ClassExpression */); + /*modifiers*/ undefined, 186 /* ClassExpression */); } function parseClassDeclaration(fullStart, decorators, modifiers) { - return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 212 /* ClassDeclaration */); + return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 214 /* ClassDeclaration */); } function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) { var node = createNode(kind, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(71 /* ClassKeyword */); - node.name = parseOptionalIdentifier(); + parseExpected(73 /* ClassKeyword */); + node.name = parseNameOfClassDeclarationOrExpression(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ true); if (parseExpected(15 /* OpenBraceToken */)) { @@ -11429,6 +11765,19 @@ var ts; } return finishNode(node); } + function parseNameOfClassDeclarationOrExpression() { + // implements is a future reserved word so + // 'class implements' might mean either + // - class expression with omitted name, 'implements' starts heritage clause + // - class with name 'implements' + // 'isImplementsClause' helps to disambiguate between these two cases + return isIdentifier() && !isImplementsClause() + ? parseIdentifier() + : undefined; + } + function isImplementsClause() { + return token === 106 /* ImplementsKeyword */ && lookAhead(nextTokenIsIdentifierOrKeyword); + } function parseHeritageClauses(isClassHeritageClause) { // ClassTail[Yield,Await] : (Modified) See 14.5 // ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt } @@ -11441,8 +11790,8 @@ var ts; return parseList(20 /* HeritageClauses */, parseHeritageClause); } function parseHeritageClause() { - if (token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */) { - var node = createNode(241 /* HeritageClause */); + if (token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */) { + var node = createNode(243 /* HeritageClause */); node.token = token; nextToken(); node.types = parseDelimitedList(7 /* HeritageClauseElement */, parseExpressionWithTypeArguments); @@ -11451,7 +11800,7 @@ var ts; return undefined; } function parseExpressionWithTypeArguments() { - var node = createNode(186 /* ExpressionWithTypeArguments */); + var node = createNode(188 /* ExpressionWithTypeArguments */); node.expression = parseLeftHandSideExpressionOrHigher(); if (token === 25 /* LessThanToken */) { node.typeArguments = parseBracketedList(18 /* TypeArguments */, parseType, 25 /* LessThanToken */, 27 /* GreaterThanToken */); @@ -11459,16 +11808,16 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */; + return token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */; } function parseClassMembers() { return parseList(5 /* ClassMembers */, parseClassElement); } function parseInterfaceDeclaration(fullStart, decorators, modifiers) { - var node = createNode(213 /* InterfaceDeclaration */, fullStart); + var node = createNode(215 /* InterfaceDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(105 /* InterfaceKeyword */); + parseExpected(107 /* InterfaceKeyword */); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ false); @@ -11476,13 +11825,13 @@ var ts; return finishNode(node); } function parseTypeAliasDeclaration(fullStart, decorators, modifiers) { - var node = createNode(214 /* TypeAliasDeclaration */, fullStart); + var node = createNode(216 /* TypeAliasDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(130 /* TypeKeyword */); + parseExpected(132 /* TypeKeyword */); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); - parseExpected(55 /* EqualsToken */); + parseExpected(56 /* EqualsToken */); node.type = parseType(); parseSemicolon(); return finishNode(node); @@ -11492,16 +11841,16 @@ var ts; // ConstantEnumMemberSection, which starts at the beginning of an enum declaration // or any time an integer literal initializer is encountered. function parseEnumMember() { - var node = createNode(245 /* EnumMember */, scanner.getStartPos()); + var node = createNode(247 /* EnumMember */, scanner.getStartPos()); node.name = parsePropertyName(); node.initializer = allowInAnd(parseNonParameterInitializer); return finishNode(node); } function parseEnumDeclaration(fullStart, decorators, modifiers) { - var node = createNode(215 /* EnumDeclaration */, fullStart); + var node = createNode(217 /* EnumDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(79 /* EnumKeyword */); + parseExpected(81 /* EnumKeyword */); node.name = parseIdentifier(); if (parseExpected(15 /* OpenBraceToken */)) { node.members = parseDelimitedList(6 /* EnumMembers */, parseEnumMember); @@ -11513,7 +11862,7 @@ var ts; return finishNode(node); } function parseModuleBlock() { - var node = createNode(217 /* ModuleBlock */, scanner.getStartPos()); + var node = createNode(219 /* ModuleBlock */, scanner.getStartPos()); if (parseExpected(15 /* OpenBraceToken */)) { node.statements = parseList(1 /* BlockStatements */, parseStatement); parseExpected(16 /* CloseBraceToken */); @@ -11524,7 +11873,7 @@ var ts; return finishNode(node); } function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) { - var node = createNode(216 /* ModuleDeclaration */, fullStart); + var node = createNode(218 /* ModuleDeclaration */, fullStart); // If we are parsing a dotted namespace name, we want to // propagate the 'Namespace' flag across the names if set. var namespaceFlag = flags & 131072 /* Namespace */; @@ -11538,7 +11887,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) { - var node = createNode(216 /* ModuleDeclaration */, fullStart); + var node = createNode(218 /* ModuleDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(/*internName*/ true); @@ -11547,11 +11896,11 @@ var ts; } function parseModuleDeclaration(fullStart, decorators, modifiers) { var flags = modifiers ? modifiers.flags : 0; - if (parseOptional(124 /* NamespaceKeyword */)) { + if (parseOptional(126 /* NamespaceKeyword */)) { flags |= 131072 /* Namespace */; } else { - parseExpected(123 /* ModuleKeyword */); + parseExpected(125 /* ModuleKeyword */); if (token === 9 /* StringLiteral */) { return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } @@ -11559,42 +11908,42 @@ var ts; return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags); } function isExternalModuleReference() { - return token === 125 /* RequireKeyword */ && + return token === 127 /* RequireKeyword */ && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { return nextToken() === 17 /* OpenParenToken */; } function nextTokenIsSlash() { - return nextToken() === 38 /* SlashToken */; + return nextToken() === 39 /* SlashToken */; } function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 24 /* CommaToken */ || - token === 131 /* FromKeyword */; + token === 133 /* FromKeyword */; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) { - parseExpected(87 /* ImportKeyword */); + parseExpected(89 /* ImportKeyword */); var afterImportPos = scanner.getStartPos(); var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 24 /* CommaToken */ && token !== 131 /* FromKeyword */) { + if (token !== 24 /* CommaToken */ && token !== 133 /* FromKeyword */) { // ImportEquals declaration of type: // import x = require("mod"); or // import x = M.x; - var importEqualsDeclaration = createNode(219 /* ImportEqualsDeclaration */, fullStart); + var importEqualsDeclaration = createNode(221 /* ImportEqualsDeclaration */, fullStart); importEqualsDeclaration.decorators = decorators; setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; - parseExpected(55 /* EqualsToken */); + parseExpected(56 /* EqualsToken */); importEqualsDeclaration.moduleReference = parseModuleReference(); parseSemicolon(); return finishNode(importEqualsDeclaration); } } // Import statement - var importDeclaration = createNode(220 /* ImportDeclaration */, fullStart); + var importDeclaration = createNode(222 /* ImportDeclaration */, fullStart); importDeclaration.decorators = decorators; setModifiers(importDeclaration, modifiers); // ImportDeclaration: @@ -11604,7 +11953,7 @@ var ts; token === 37 /* AsteriskToken */ || token === 15 /* OpenBraceToken */) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(131 /* FromKeyword */); + parseExpected(133 /* FromKeyword */); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); @@ -11617,7 +11966,7 @@ var ts; // NamedImports // ImportedDefaultBinding, NameSpaceImport // ImportedDefaultBinding, NamedImports - var importClause = createNode(221 /* ImportClause */, fullStart); + var importClause = createNode(223 /* ImportClause */, fullStart); if (identifier) { // ImportedDefaultBinding: // ImportedBinding @@ -11627,7 +11976,7 @@ var ts; // parse namespace or named imports if (!importClause.name || parseOptional(24 /* CommaToken */)) { - importClause.namedBindings = token === 37 /* AsteriskToken */ ? parseNamespaceImport() : parseNamedImportsOrExports(223 /* NamedImports */); + importClause.namedBindings = token === 37 /* AsteriskToken */ ? parseNamespaceImport() : parseNamedImportsOrExports(225 /* NamedImports */); } return finishNode(importClause); } @@ -11637,8 +11986,8 @@ var ts; : parseEntityName(/*allowReservedWords*/ false); } function parseExternalModuleReference() { - var node = createNode(230 /* ExternalModuleReference */); - parseExpected(125 /* RequireKeyword */); + var node = createNode(232 /* ExternalModuleReference */); + parseExpected(127 /* RequireKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = parseModuleSpecifier(); parseExpected(18 /* CloseParenToken */); @@ -11659,9 +12008,9 @@ var ts; function parseNamespaceImport() { // NameSpaceImport: // * as ImportedBinding - var namespaceImport = createNode(222 /* NamespaceImport */); + var namespaceImport = createNode(224 /* NamespaceImport */); parseExpected(37 /* AsteriskToken */); - parseExpected(114 /* AsKeyword */); + parseExpected(116 /* AsKeyword */); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } @@ -11674,14 +12023,14 @@ var ts; // ImportsList: // ImportSpecifier // ImportsList, ImportSpecifier - node.elements = parseBracketedList(21 /* ImportOrExportSpecifiers */, kind === 223 /* NamedImports */ ? parseImportSpecifier : parseExportSpecifier, 15 /* OpenBraceToken */, 16 /* CloseBraceToken */); + node.elements = parseBracketedList(21 /* ImportOrExportSpecifiers */, kind === 225 /* NamedImports */ ? parseImportSpecifier : parseExportSpecifier, 15 /* OpenBraceToken */, 16 /* CloseBraceToken */); return finishNode(node); } function parseExportSpecifier() { - return parseImportOrExportSpecifier(228 /* ExportSpecifier */); + return parseImportOrExportSpecifier(230 /* ExportSpecifier */); } function parseImportSpecifier() { - return parseImportOrExportSpecifier(224 /* ImportSpecifier */); + return parseImportOrExportSpecifier(226 /* ImportSpecifier */); } function parseImportOrExportSpecifier(kind) { var node = createNode(kind); @@ -11695,9 +12044,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 114 /* AsKeyword */) { + if (token === 116 /* AsKeyword */) { node.propertyName = identifierName; - parseExpected(114 /* AsKeyword */); + parseExpected(116 /* AsKeyword */); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -11706,27 +12055,27 @@ var ts; else { node.name = identifierName; } - if (kind === 224 /* ImportSpecifier */ && checkIdentifierIsKeyword) { + if (kind === 226 /* ImportSpecifier */ && checkIdentifierIsKeyword) { // Report error identifier expected parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected); } return finishNode(node); } function parseExportDeclaration(fullStart, decorators, modifiers) { - var node = createNode(226 /* ExportDeclaration */, fullStart); + var node = createNode(228 /* ExportDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(37 /* AsteriskToken */)) { - parseExpected(131 /* FromKeyword */); + parseExpected(133 /* FromKeyword */); node.moduleSpecifier = parseModuleSpecifier(); } else { - node.exportClause = parseNamedImportsOrExports(227 /* NamedExports */); + node.exportClause = parseNamedImportsOrExports(229 /* NamedExports */); // It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios, // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. - if (token === 131 /* FromKeyword */ || (token === 9 /* StringLiteral */ && !scanner.hasPrecedingLineBreak())) { - parseExpected(131 /* FromKeyword */); + if (token === 133 /* FromKeyword */ || (token === 9 /* StringLiteral */ && !scanner.hasPrecedingLineBreak())) { + parseExpected(133 /* FromKeyword */); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -11734,14 +12083,14 @@ var ts; return finishNode(node); } function parseExportAssignment(fullStart, decorators, modifiers) { - var node = createNode(225 /* ExportAssignment */, fullStart); + var node = createNode(227 /* ExportAssignment */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - if (parseOptional(55 /* EqualsToken */)) { + if (parseOptional(56 /* EqualsToken */)) { node.isExportEquals = true; } else { - parseExpected(75 /* DefaultKeyword */); + parseExpected(77 /* DefaultKeyword */); } node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); @@ -11807,10 +12156,10 @@ var ts; function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 /* Export */ - || node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 230 /* ExternalModuleReference */ - || node.kind === 220 /* ImportDeclaration */ - || node.kind === 225 /* ExportAssignment */ - || node.kind === 226 /* ExportDeclaration */ + || node.kind === 221 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 232 /* ExternalModuleReference */ + || node.kind === 222 /* ImportDeclaration */ + || node.kind === 227 /* ExportAssignment */ + || node.kind === 228 /* ExportDeclaration */ ? node : undefined; }); @@ -11856,15 +12205,15 @@ var ts; function isJSDocType() { switch (token) { case 37 /* AsteriskToken */: - case 52 /* QuestionToken */: + case 53 /* QuestionToken */: case 17 /* OpenParenToken */: case 19 /* OpenBracketToken */: - case 48 /* ExclamationToken */: + case 49 /* ExclamationToken */: case 15 /* OpenBraceToken */: - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: case 22 /* DotDotDotToken */: - case 90 /* NewKeyword */: - case 95 /* ThisKeyword */: + case 92 /* NewKeyword */: + case 97 /* ThisKeyword */: return true; } return ts.tokenIsIdentifierOrKeyword(token); @@ -11885,7 +12234,7 @@ var ts; scanner.setText(sourceText, start, length); // Prime the first token for us to start processing. token = nextToken(); - var result = createNode(247 /* JSDocTypeExpression */); + var result = createNode(249 /* JSDocTypeExpression */); parseExpected(15 /* OpenBraceToken */); result.type = parseJSDocTopLevelType(); parseExpected(16 /* CloseBraceToken */); @@ -11895,13 +12244,13 @@ var ts; JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; function parseJSDocTopLevelType() { var type = parseJSDocType(); - if (token === 46 /* BarToken */) { - var unionType = createNode(251 /* JSDocUnionType */, type.pos); + if (token === 47 /* BarToken */) { + var unionType = createNode(253 /* JSDocUnionType */, type.pos); unionType.types = parseJSDocTypeList(type); type = finishNode(unionType); } - if (token === 55 /* EqualsToken */) { - var optionalType = createNode(258 /* JSDocOptionalType */, type.pos); + if (token === 56 /* EqualsToken */) { + var optionalType = createNode(260 /* JSDocOptionalType */, type.pos); nextToken(); optionalType.type = type; type = finishNode(optionalType); @@ -11912,20 +12261,20 @@ var ts; var type = parseBasicTypeExpression(); while (true) { if (token === 19 /* OpenBracketToken */) { - var arrayType = createNode(250 /* JSDocArrayType */, type.pos); + var arrayType = createNode(252 /* JSDocArrayType */, type.pos); arrayType.elementType = type; nextToken(); parseExpected(20 /* CloseBracketToken */); type = finishNode(arrayType); } - else if (token === 52 /* QuestionToken */) { - var nullableType = createNode(253 /* JSDocNullableType */, type.pos); + else if (token === 53 /* QuestionToken */) { + var nullableType = createNode(255 /* JSDocNullableType */, type.pos); nullableType.type = type; nextToken(); type = finishNode(nullableType); } - else if (token === 48 /* ExclamationToken */) { - var nonNullableType = createNode(254 /* JSDocNonNullableType */, type.pos); + else if (token === 49 /* ExclamationToken */) { + var nonNullableType = createNode(256 /* JSDocNonNullableType */, type.pos); nonNullableType.type = type; nextToken(); type = finishNode(nonNullableType); @@ -11940,80 +12289,80 @@ var ts; switch (token) { case 37 /* AsteriskToken */: return parseJSDocAllType(); - case 52 /* QuestionToken */: + case 53 /* QuestionToken */: return parseJSDocUnknownOrNullableType(); case 17 /* OpenParenToken */: return parseJSDocUnionType(); case 19 /* OpenBracketToken */: return parseJSDocTupleType(); - case 48 /* ExclamationToken */: + case 49 /* ExclamationToken */: return parseJSDocNonNullableType(); case 15 /* OpenBraceToken */: return parseJSDocRecordType(); - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseJSDocFunctionType(); case 22 /* DotDotDotToken */: return parseJSDocVariadicType(); - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: return parseJSDocConstructorType(); - case 95 /* ThisKeyword */: + case 97 /* ThisKeyword */: return parseJSDocThisType(); - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: - case 101 /* VoidKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: return parseTokenNode(); } return parseJSDocTypeReference(); } function parseJSDocThisType() { - var result = createNode(262 /* JSDocThisType */); + var result = createNode(264 /* JSDocThisType */); nextToken(); - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocConstructorType() { - var result = createNode(261 /* JSDocConstructorType */); + var result = createNode(263 /* JSDocConstructorType */); nextToken(); - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocVariadicType() { - var result = createNode(260 /* JSDocVariadicType */); + var result = createNode(262 /* JSDocVariadicType */); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocFunctionType() { - var result = createNode(259 /* JSDocFunctionType */); + var result = createNode(261 /* JSDocFunctionType */); nextToken(); parseExpected(17 /* OpenParenToken */); result.parameters = parseDelimitedList(22 /* JSDocFunctionParameters */, parseJSDocParameter); checkForTrailingComma(result.parameters); parseExpected(18 /* CloseParenToken */); - if (token === 53 /* ColonToken */) { + if (token === 54 /* ColonToken */) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocParameter() { - var parameter = createNode(136 /* Parameter */); + var parameter = createNode(138 /* Parameter */); parameter.type = parseJSDocType(); return finishNode(parameter); } function parseJSDocOptionalType(type) { - var result = createNode(258 /* JSDocOptionalType */, type.pos); + var result = createNode(260 /* JSDocOptionalType */, type.pos); nextToken(); result.type = type; return finishNode(result); } function parseJSDocTypeReference() { - var result = createNode(257 /* JSDocTypeReference */); + var result = createNode(259 /* JSDocTypeReference */); result.name = parseSimplePropertyName(); while (parseOptional(21 /* DotToken */)) { if (token === 25 /* LessThanToken */) { @@ -12043,13 +12392,13 @@ var ts; } } function parseQualifiedName(left) { - var result = createNode(133 /* QualifiedName */, left.pos); + var result = createNode(135 /* QualifiedName */, left.pos); result.left = left; result.right = parseIdentifierName(); return finishNode(result); } function parseJSDocRecordType() { - var result = createNode(255 /* JSDocRecordType */); + var result = createNode(257 /* JSDocRecordType */); nextToken(); result.members = parseDelimitedList(24 /* JSDocRecordMembers */, parseJSDocRecordMember); checkForTrailingComma(result.members); @@ -12057,22 +12406,22 @@ var ts; return finishNode(result); } function parseJSDocRecordMember() { - var result = createNode(256 /* JSDocRecordMember */); + var result = createNode(258 /* JSDocRecordMember */); result.name = parseSimplePropertyName(); - if (token === 53 /* ColonToken */) { + if (token === 54 /* ColonToken */) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocNonNullableType() { - var result = createNode(254 /* JSDocNonNullableType */); + var result = createNode(256 /* JSDocNonNullableType */); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocTupleType() { - var result = createNode(252 /* JSDocTupleType */); + var result = createNode(254 /* JSDocTupleType */); nextToken(); result.types = parseDelimitedList(25 /* JSDocTupleTypes */, parseJSDocType); checkForTrailingComma(result.types); @@ -12086,7 +12435,7 @@ var ts; } } function parseJSDocUnionType() { - var result = createNode(251 /* JSDocUnionType */); + var result = createNode(253 /* JSDocUnionType */); nextToken(); result.types = parseJSDocTypeList(parseJSDocType()); parseExpected(18 /* CloseParenToken */); @@ -12097,14 +12446,14 @@ var ts; var types = []; types.pos = firstType.pos; types.push(firstType); - while (parseOptional(46 /* BarToken */)) { + while (parseOptional(47 /* BarToken */)) { types.push(parseJSDocType()); } types.end = scanner.getStartPos(); return types; } function parseJSDocAllType() { - var result = createNode(248 /* JSDocAllType */); + var result = createNode(250 /* JSDocAllType */); nextToken(); return finishNode(result); } @@ -12125,13 +12474,13 @@ var ts; token === 16 /* CloseBraceToken */ || token === 18 /* CloseParenToken */ || token === 27 /* GreaterThanToken */ || - token === 55 /* EqualsToken */ || - token === 46 /* BarToken */) { - var result = createNode(249 /* JSDocUnknownType */, pos); + token === 56 /* EqualsToken */ || + token === 47 /* BarToken */) { + var result = createNode(251 /* JSDocUnknownType */, pos); return finishNode(result); } else { - var result = createNode(253 /* JSDocNullableType */, pos); + var result = createNode(255 /* JSDocNullableType */, pos); result.type = parseJSDocType(); return finishNode(result); } @@ -12219,7 +12568,7 @@ var ts; if (!tags) { return undefined; } - var result = createNode(263 /* JSDocComment */, start); + var result = createNode(265 /* JSDocComment */, start); result.tags = tags; return finishNode(result, end); } @@ -12230,7 +12579,7 @@ var ts; } function parseTag() { ts.Debug.assert(content.charCodeAt(pos - 1) === 64 /* at */); - var atToken = createNode(54 /* AtToken */, pos - 1); + var atToken = createNode(55 /* AtToken */, pos - 1); atToken.end = pos; var tagName = scanIdentifier(); if (!tagName) { @@ -12256,7 +12605,7 @@ var ts; return undefined; } function handleUnknownTag(atToken, tagName) { - var result = createNode(264 /* JSDocTag */, atToken.pos); + var result = createNode(266 /* JSDocTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; return finishNode(result, pos); @@ -12307,7 +12656,7 @@ var ts; if (!typeExpression) { typeExpression = tryParseTypeExpression(); } - var result = createNode(265 /* JSDocParameterTag */, atToken.pos); + var result = createNode(267 /* JSDocParameterTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.preParameterName = preName; @@ -12317,27 +12666,27 @@ var ts; return finishNode(result, pos); } function handleReturnTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 266 /* JSDocReturnTag */; })) { + if (ts.forEach(tags, function (t) { return t.kind === 268 /* JSDocReturnTag */; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(266 /* JSDocReturnTag */, atToken.pos); + var result = createNode(268 /* JSDocReturnTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTypeTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 267 /* JSDocTypeTag */; })) { + if (ts.forEach(tags, function (t) { return t.kind === 269 /* JSDocTypeTag */; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(267 /* JSDocTypeTag */, atToken.pos); + var result = createNode(269 /* JSDocTypeTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTemplateTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 268 /* JSDocTemplateTag */; })) { + if (ts.forEach(tags, function (t) { return t.kind === 270 /* JSDocTemplateTag */; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } var typeParameters = []; @@ -12350,7 +12699,7 @@ var ts; parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(135 /* TypeParameter */, name_8.pos); + var typeParameter = createNode(137 /* TypeParameter */, name_8.pos); typeParameter.name = name_8; finishNode(typeParameter, pos); typeParameters.push(typeParameter); @@ -12361,7 +12710,7 @@ var ts; pos++; } typeParameters.end = pos; - var result = createNode(268 /* JSDocTemplateTag */, atToken.pos); + var result = createNode(270 /* JSDocTemplateTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeParameters = typeParameters; @@ -12382,7 +12731,7 @@ var ts; if (startPos === pos) { return undefined; } - var result = createNode(67 /* Identifier */, startPos); + var result = createNode(69 /* Identifier */, startPos); result.text = content.substring(startPos, pos); return finishNode(result, pos); } @@ -12505,7 +12854,7 @@ var ts; switch (node.kind) { case 9 /* StringLiteral */: case 8 /* NumericLiteral */: - case 67 /* Identifier */: + case 69 /* Identifier */: return true; } return false; @@ -12898,17 +13247,19 @@ var ts; var Type = ts.objectAllocator.getTypeConstructor(); var Signature = ts.objectAllocator.getSignatureConstructor(); var typeCount = 0; + var symbolCount = 0; var emptyArray = []; var emptySymbols = {}; var compilerOptions = host.getCompilerOptions(); var languageVersion = compilerOptions.target || 0 /* ES3 */; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 /* ES6 */ ? 5 /* ES6 */ : 0 /* None */; var emitResolver = createResolver(); var undefinedSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "arguments"); var checker = { getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); }, - getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); }, + getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount") + symbolCount; }, getTypeCount: function () { return typeCount; }, isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; }, @@ -13069,6 +13420,7 @@ var ts; diagnostics.add(diagnostic); } function createSymbol(flags, name) { + symbolCount++; return new Symbol(flags, name); } function getExcludedSymbolFlags(flags) { @@ -13198,10 +13550,10 @@ var ts; return nodeLinks[nodeId] || (nodeLinks[nodeId] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 246 /* SourceFile */); + return ts.getAncestor(node, 248 /* SourceFile */); } function isGlobalSourceFile(node) { - return node.kind === 246 /* SourceFile */ && !ts.isExternalModule(node); + return node.kind === 248 /* SourceFile */ && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -13220,18 +13572,62 @@ var ts; } // return undefined if we can't find a symbol. } - /** Returns true if node1 is defined before node 2**/ - function isDefinedBefore(node1, node2) { - var file1 = ts.getSourceFileOfNode(node1); - var file2 = ts.getSourceFileOfNode(node2); - if (file1 === file2) { - return node1.pos <= node2.pos; + function isBlockScopedNameDeclaredBeforeUse(declaration, usage) { + var declarationFile = ts.getSourceFileOfNode(declaration); + var useFile = ts.getSourceFileOfNode(usage); + if (declarationFile !== useFile) { + if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) { + // nodes are in different files and order cannot be determines + return true; + } + var sourceFiles = host.getSourceFiles(); + return ts.indexOf(sourceFiles, declarationFile) <= ts.indexOf(sourceFiles, useFile); } - if (!compilerOptions.outFile && !compilerOptions.out) { - return true; + if (declaration.pos <= usage.pos) { + // declaration is before usage + // still might be illegal if usage is in the initializer of the variable declaration + return declaration.kind !== 211 /* VariableDeclaration */ || + !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage); + } + // declaration is after usage + // can be legal if usage is deferred (i.e. inside function or in initializer of instance property) + return isUsedInFunctionOrNonStaticProperty(declaration, usage); + function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + if (declaration.parent.parent.kind === 193 /* VariableStatement */ || + declaration.parent.parent.kind === 199 /* ForStatement */) { + // variable statement/for statement case, + // use site should not be inside variable declaration (initializer of declaration or binding element) + return isSameScopeDescendentOf(usage, declaration, container); + } + else if (declaration.parent.parent.kind === 201 /* ForOfStatement */ || + declaration.parent.parent.kind === 200 /* ForInStatement */) { + // ForIn/ForOf case - use site should not be used in expression part + var expression = declaration.parent.parent.expression; + return isSameScopeDescendentOf(usage, expression, container); + } + } + function isUsedInFunctionOrNonStaticProperty(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + var current = usage; + while (current) { + if (current === container) { + return false; + } + if (ts.isFunctionLike(current)) { + return true; + } + var initializerOfNonStaticProperty = current.parent && + current.parent.kind === 141 /* PropertyDeclaration */ && + (current.parent.flags & 128 /* Static */) === 0 && + current.parent.initializer === current; + if (initializerOfNonStaticProperty) { + return true; + } + current = current.parent; + } + return false; } - var sourceFiles = host.getSourceFiles(); - return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2); } // Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and // the nameNotFoundMessage argument is not undefined. Returns the resolved symbol, or undefined if no symbol with @@ -13258,13 +13654,13 @@ var ts; } } switch (location.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; - if (location.kind === 246 /* SourceFile */ || - (location.kind === 216 /* ModuleDeclaration */ && location.name.kind === 9 /* StringLiteral */)) { + if (location.kind === 248 /* SourceFile */ || + (location.kind === 218 /* ModuleDeclaration */ && location.name.kind === 9 /* StringLiteral */)) { // It's an external module. Because of module/namespace merging, a module's exports are in scope, // yet we never want to treat an export specifier as putting a member in scope. Therefore, // if the name we find is purely an export specifier, it is not actually considered in scope. @@ -13278,7 +13674,7 @@ var ts; // which is not the desired behavior. if (ts.hasProperty(moduleExports, name) && moduleExports[name].flags === 8388608 /* Alias */ && - ts.getDeclarationOfKind(moduleExports[name], 228 /* ExportSpecifier */)) { + ts.getDeclarationOfKind(moduleExports[name], 230 /* ExportSpecifier */)) { break; } result = moduleExports["default"]; @@ -13292,13 +13688,13 @@ var ts; break loop; } break; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: // TypeScript 1.0 spec (April 2014): 8.4.1 // Initializer expressions for instance member variables are evaluated in the scope // of the class constructor body but are not permitted to reference parameters or @@ -13315,9 +13711,9 @@ var ts; } } break; - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056 /* Type */)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { // TypeScript 1.0 spec (April 2014): 3.4.1 @@ -13328,7 +13724,7 @@ var ts; } break loop; } - if (location.kind === 184 /* ClassExpression */ && meaning & 32 /* Class */) { + if (location.kind === 186 /* ClassExpression */ && meaning & 32 /* Class */) { var className = location.name; if (className && name === className.text) { result = location.symbol; @@ -13344,9 +13740,9 @@ var ts; // [foo()]() { } // <-- Reference to T from class's own computed property // } // - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: grandparent = location.parent.parent; - if (ts.isClassLike(grandparent) || grandparent.kind === 213 /* InterfaceDeclaration */) { + if (ts.isClassLike(grandparent) || grandparent.kind === 215 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); @@ -13354,19 +13750,19 @@ var ts; } } break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; - case 171 /* FunctionExpression */: + case 173 /* FunctionExpression */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; @@ -13379,7 +13775,7 @@ var ts; } } break; - case 137 /* Decorator */: + case 139 /* Decorator */: // Decorators are resolved at the class declaration. Resolving at the parameter // or member would result in looking up locals in the method. // @@ -13388,7 +13784,7 @@ var ts; // method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. // } // - if (location.parent && location.parent.kind === 136 /* Parameter */) { + if (location.parent && location.parent.kind === 138 /* Parameter */) { location = location.parent; } // @@ -13434,8 +13830,11 @@ var ts; // block - scope variable and namespace module. However, only when we // try to resolve name in /*1*/ which is used in variable position, // we want to check for block- scoped - if (meaning & 2 /* BlockScopedVariable */ && result.flags & 2 /* BlockScopedVariable */) { - checkResolvedBlockScopedVariable(result, errorLocation); + if (meaning & 2 /* BlockScopedVariable */) { + var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result); + if (exportOrLocalSymbol.flags & 2 /* BlockScopedVariable */) { + checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); + } } } return result; @@ -13445,32 +13844,7 @@ var ts; // Block-scoped variables cannot be used before their definition var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); - // first check if usage is lexically located after the declaration - var isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation); - if (!isUsedBeforeDeclaration) { - // lexical check succeeded however code still can be illegal. - // - block scoped variables cannot be used in its initializers - // let x = x; // illegal but usage is lexically after definition - // - in ForIn/ForOf statements variable cannot be contained in expression part - // for (let x in x) - // for (let x of x) - // climb up to the variable declaration skipping binding patterns - var variableDeclaration = ts.getAncestor(declaration, 209 /* VariableDeclaration */); - var container = ts.getEnclosingBlockScopeContainer(variableDeclaration); - if (variableDeclaration.parent.parent.kind === 191 /* VariableStatement */ || - variableDeclaration.parent.parent.kind === 197 /* ForStatement */) { - // variable statement/for statement case, - // use site should not be inside variable declaration (initializer of declaration or binding element) - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container); - } - else if (variableDeclaration.parent.parent.kind === 199 /* ForOfStatement */ || - variableDeclaration.parent.parent.kind === 198 /* ForInStatement */) { - // ForIn/ForOf case - use site should not be used in expression part - var expression = variableDeclaration.parent.parent.expression; - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container); - } - } - if (isUsedBeforeDeclaration) { + if (!isBlockScopedNameDeclaredBeforeUse(ts.getAncestor(declaration, 211 /* VariableDeclaration */), errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); } } @@ -13491,10 +13865,10 @@ var ts; } function getAnyImportSyntax(node) { if (ts.isAliasSymbolDeclaration(node)) { - if (node.kind === 219 /* ImportEqualsDeclaration */) { + if (node.kind === 221 /* ImportEqualsDeclaration */) { return node; } - while (node && node.kind !== 220 /* ImportDeclaration */) { + while (node && node.kind !== 222 /* ImportDeclaration */) { node = node.parent; } return node; @@ -13504,7 +13878,7 @@ var ts; return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { - if (node.moduleReference.kind === 230 /* ExternalModuleReference */) { + if (node.moduleReference.kind === 232 /* ExternalModuleReference */) { return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node))); } return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); @@ -13611,17 +13985,17 @@ var ts; } function getTargetOfAliasDeclaration(node) { switch (node.kind) { - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return getTargetOfImportEqualsDeclaration(node); - case 221 /* ImportClause */: + case 223 /* ImportClause */: return getTargetOfImportClause(node); - case 222 /* NamespaceImport */: + case 224 /* NamespaceImport */: return getTargetOfNamespaceImport(node); - case 224 /* ImportSpecifier */: + case 226 /* ImportSpecifier */: return getTargetOfImportSpecifier(node); - case 228 /* ExportSpecifier */: + case 230 /* ExportSpecifier */: return getTargetOfExportSpecifier(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return getTargetOfExportAssignment(node); } } @@ -13666,11 +14040,11 @@ var ts; if (!links.referenced) { links.referenced = true; var node = getDeclarationOfAliasSymbol(symbol); - if (node.kind === 225 /* ExportAssignment */) { + if (node.kind === 227 /* ExportAssignment */) { // export default checkExpressionCached(node.expression); } - else if (node.kind === 228 /* ExportSpecifier */) { + else if (node.kind === 230 /* ExportSpecifier */) { // export { } or export { as foo } checkExpressionCached(node.propertyName || node.name); } @@ -13683,7 +14057,7 @@ var ts; // This function is only for imports with entity names function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 219 /* ImportEqualsDeclaration */); + importDeclaration = ts.getAncestor(entityName, 221 /* ImportEqualsDeclaration */); ts.Debug.assert(importDeclaration !== undefined); } // There are three things we might try to look for. In the following examples, @@ -13692,17 +14066,17 @@ var ts; // import a = |b|; // Namespace // import a = |b.c|; // Value, type, namespace // import a = |b.c|.d; // Namespace - if (entityName.kind === 67 /* Identifier */ && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { + if (entityName.kind === 69 /* Identifier */ && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { entityName = entityName.parent; } // Check for case 1 and 3 in the above example - if (entityName.kind === 67 /* Identifier */ || entityName.parent.kind === 133 /* QualifiedName */) { + if (entityName.kind === 69 /* Identifier */ || entityName.parent.kind === 135 /* QualifiedName */) { return resolveEntityName(entityName, 1536 /* Namespace */); } else { // Case 2 in above example // entityName.kind could be a QualifiedName or a Missing identifier - ts.Debug.assert(entityName.parent.kind === 219 /* ImportEqualsDeclaration */); + ts.Debug.assert(entityName.parent.kind === 221 /* ImportEqualsDeclaration */); return resolveEntityName(entityName, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */); } } @@ -13715,16 +14089,16 @@ var ts; return undefined; } var symbol; - if (name.kind === 67 /* Identifier */) { + if (name.kind === 69 /* Identifier */) { var message = meaning === 1536 /* Namespace */ ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0; symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } } - else if (name.kind === 133 /* QualifiedName */ || name.kind === 164 /* PropertyAccessExpression */) { - var left = name.kind === 133 /* QualifiedName */ ? name.left : name.expression; - var right = name.kind === 133 /* QualifiedName */ ? name.right : name.name; + else if (name.kind === 135 /* QualifiedName */ || name.kind === 166 /* PropertyAccessExpression */) { + var left = name.kind === 135 /* QualifiedName */ ? name.left : name.expression; + var right = name.kind === 135 /* QualifiedName */ ? name.right : name.name; var namespace = resolveEntityName(left, 1536 /* Namespace */, ignoreErrors); if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { return undefined; @@ -13743,11 +14117,6 @@ var ts; ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); return symbol.flags & meaning ? symbol : resolveAlias(symbol); } - function isExternalModuleNameRelative(moduleName) { - // TypeScript 1.0 spec (April 2014): 11.2.1 - // An external module name is "relative" if the first term is "." or "..". - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; - } function resolveExternalModuleName(location, moduleReferenceExpression) { if (moduleReferenceExpression.kind !== 9 /* StringLiteral */) { return; @@ -13760,7 +14129,7 @@ var ts; if (moduleName === undefined) { return; } - var isRelative = isExternalModuleNameRelative(moduleName); + var isRelative = ts.isExternalModuleNameRelative(moduleName); if (!isRelative) { var symbol = getSymbol(globals, "\"" + moduleName + "\"", 512 /* ValueModule */); if (symbol) { @@ -13876,7 +14245,7 @@ var ts; var members = node.members; for (var _i = 0; _i < members.length; _i++) { var member = members[_i]; - if (member.kind === 142 /* Constructor */ && ts.nodeIsPresent(member.body)) { + if (member.kind === 144 /* Constructor */ && ts.nodeIsPresent(member.body)) { return member; } } @@ -13946,17 +14315,17 @@ var ts; } } switch (location_1.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (!ts.isExternalModule(location_1)) { break; } - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (result = callback(getSymbolOfNode(location_1).exports)) { return result; } break; - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: if (result = callback(getSymbolOfNode(location_1).members)) { return result; } @@ -13997,7 +14366,7 @@ var ts; return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 8388608 /* Alias */ && symbolFromSymbolTable.name !== "export=" - && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228 /* ExportSpecifier */)) { + && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230 /* ExportSpecifier */)) { if (!useOnlyExternalAliasing || // Is this external alias, then use it to name ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { @@ -14034,7 +14403,7 @@ var ts; return true; } // Qualify if the symbol from symbol table has same meaning as expected - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 /* Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228 /* ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 /* Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230 /* ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -14107,8 +14476,8 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 216 /* ModuleDeclaration */ && declaration.name.kind === 9 /* StringLiteral */) || - (declaration.kind === 246 /* SourceFile */ && ts.isExternalModule(declaration)); + return (declaration.kind === 218 /* ModuleDeclaration */ && declaration.name.kind === 9 /* StringLiteral */) || + (declaration.kind === 248 /* SourceFile */ && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -14144,12 +14513,12 @@ var ts; function isEntityNameVisible(entityName, enclosingDeclaration) { // get symbol of the first identifier of the entityName var meaning; - if (entityName.parent.kind === 152 /* TypeQuery */) { + if (entityName.parent.kind === 154 /* TypeQuery */) { // Typeof value meaning = 107455 /* Value */ | 1048576 /* ExportValue */; } - else if (entityName.kind === 133 /* QualifiedName */ || entityName.kind === 164 /* PropertyAccessExpression */ || - entityName.parent.kind === 219 /* ImportEqualsDeclaration */) { + else if (entityName.kind === 135 /* QualifiedName */ || entityName.kind === 166 /* PropertyAccessExpression */ || + entityName.parent.kind === 221 /* ImportEqualsDeclaration */) { // Left identifier from type reference or TypeAlias // Entity name of the import declaration meaning = 1536 /* Namespace */; @@ -14204,10 +14573,10 @@ var ts; function getTypeAliasForTypeLiteral(type) { if (type.symbol && type.symbol.flags & 2048 /* TypeLiteral */) { var node = type.symbol.declarations[0].parent; - while (node.kind === 158 /* ParenthesizedType */) { + while (node.kind === 160 /* ParenthesizedType */) { node = node.parent; } - if (node.kind === 214 /* TypeAliasDeclaration */) { + if (node.kind === 216 /* TypeAliasDeclaration */) { return getSymbolOfNode(node); } } @@ -14221,10 +14590,10 @@ var ts; return ts.declarationNameToString(declaration.name); } switch (declaration.kind) { - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: return "(Anonymous class)"; - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return "(Anonymous function)"; } } @@ -14307,6 +14676,7 @@ var ts; } function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; + var inObjectTypeLiteral = false; return writeType(type, globalFlags); function writeType(type, flags) { // Write undefined/null type as any @@ -14316,6 +14686,12 @@ var ts; ? "any" : type.intrinsicName); } + else if (type.flags & 33554432 /* ThisType */) { + if (inObjectTypeLiteral) { + writer.reportInaccessibleThisError(); + } + writer.writeKeyword("this"); + } else if (type.flags & 4096 /* Reference */) { writeTypeReference(type, flags); } @@ -14357,11 +14733,10 @@ var ts; writeType(types[i], delimiter === 24 /* CommaToken */ ? 0 /* None */ : 64 /* InElementType */); } } - function writeSymbolTypeReference(symbol, typeArguments, pos, end) { - // Unnamed function expressions, arrow functions, and unnamed class expressions have reserved names that - // we don't want to display - if (!isReservedMemberName(symbol.name)) { - buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056 /* Type */); + function writeSymbolTypeReference(symbol, typeArguments, pos, end, flags) { + // Unnamed function expressions and arrow functions have reserved names that we don't want to display + if (symbol.flags & 32 /* Class */ || !isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); } if (pos < end) { writePunctuation(writer, 25 /* LessThanToken */); @@ -14375,7 +14750,7 @@ var ts; } } function writeTypeReference(type, flags) { - var typeArguments = type.typeArguments; + var typeArguments = type.typeArguments || emptyArray; if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { writeType(typeArguments[0], 64 /* InElementType */); writePunctuation(writer, 19 /* OpenBracketToken */); @@ -14399,12 +14774,13 @@ var ts; // When type parameters are their own type arguments for the whole group (i.e. we have // the default outer type arguments), we don't show the group. if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { - writeSymbolTypeReference(parent_3, typeArguments, start, i); + writeSymbolTypeReference(parent_3, typeArguments, start, i, flags); writePunctuation(writer, 21 /* DotToken */); } } } - writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); + var typeParameterCount = (type.target.typeParameters || emptyArray).length; + writeSymbolTypeReference(type.symbol, typeArguments, i, typeParameterCount, flags); } } function writeTupleType(type) { @@ -14416,7 +14792,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* OpenParenToken */); } - writeTypeList(type.types, type.flags & 16384 /* Union */ ? 46 /* BarToken */ : 45 /* AmpersandToken */); + writeTypeList(type.types, type.flags & 16384 /* Union */ ? 47 /* BarToken */ : 46 /* AmpersandToken */); if (flags & 64 /* InElementType */) { writePunctuation(writer, 18 /* CloseParenToken */); } @@ -14440,7 +14816,7 @@ var ts; } else { // Recursive usage, use any - writeKeyword(writer, 115 /* AnyKeyword */); + writeKeyword(writer, 117 /* AnyKeyword */); } } else { @@ -14464,7 +14840,7 @@ var ts; var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) && (symbol.parent || ts.forEach(symbol.declarations, function (declaration) { - return declaration.parent.kind === 246 /* SourceFile */ || declaration.parent.kind === 217 /* ModuleBlock */; + return declaration.parent.kind === 248 /* SourceFile */ || declaration.parent.kind === 219 /* ModuleBlock */; })); if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { // typeof is allowed only for static/non local functions @@ -14474,7 +14850,7 @@ var ts; } } function writeTypeofSymbol(type, typeFormatFlags) { - writeKeyword(writer, 99 /* TypeOfKeyword */); + writeKeyword(writer, 101 /* TypeOfKeyword */); writeSpace(writer); buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455 /* Value */, 0 /* None */, typeFormatFlags); } @@ -14510,7 +14886,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* OpenParenToken */); } - writeKeyword(writer, 90 /* NewKeyword */); + writeKeyword(writer, 92 /* NewKeyword */); writeSpace(writer); buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { @@ -14519,6 +14895,8 @@ var ts; return; } } + var saveInObjectTypeLiteral = inObjectTypeLiteral; + inObjectTypeLiteral = true; writePunctuation(writer, 15 /* OpenBraceToken */); writer.writeLine(); writer.increaseIndent(); @@ -14530,7 +14908,7 @@ var ts; } for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) { var signature = _c[_b]; - writeKeyword(writer, 90 /* NewKeyword */); + writeKeyword(writer, 92 /* NewKeyword */); writeSpace(writer); buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14540,11 +14918,11 @@ var ts; // [x: string]: writePunctuation(writer, 19 /* OpenBracketToken */); writer.writeParameter(getIndexerParameterName(resolved, 0 /* String */, /*fallbackName*/ "x")); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); - writeKeyword(writer, 128 /* StringKeyword */); + writeKeyword(writer, 130 /* StringKeyword */); writePunctuation(writer, 20 /* CloseBracketToken */); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); writeType(resolved.stringIndexType, 0 /* None */); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14554,11 +14932,11 @@ var ts; // [x: number]: writePunctuation(writer, 19 /* OpenBracketToken */); writer.writeParameter(getIndexerParameterName(resolved, 1 /* Number */, /*fallbackName*/ "x")); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); - writeKeyword(writer, 126 /* NumberKeyword */); + writeKeyword(writer, 128 /* NumberKeyword */); writePunctuation(writer, 20 /* CloseBracketToken */); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); writeType(resolved.numberIndexType, 0 /* None */); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14573,7 +14951,7 @@ var ts; var signature = signatures[_f]; buildSymbolDisplay(p, writer); if (p.flags & 536870912 /* Optional */) { - writePunctuation(writer, 52 /* QuestionToken */); + writePunctuation(writer, 53 /* QuestionToken */); } buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14583,9 +14961,9 @@ var ts; else { buildSymbolDisplay(p, writer); if (p.flags & 536870912 /* Optional */) { - writePunctuation(writer, 52 /* QuestionToken */); + writePunctuation(writer, 53 /* QuestionToken */); } - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); writeType(t, 0 /* None */); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14594,6 +14972,7 @@ var ts; } writer.decreaseIndent(); writePunctuation(writer, 16 /* CloseBraceToken */); + inObjectTypeLiteral = saveInObjectTypeLiteral; } } function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { @@ -14607,7 +14986,7 @@ var ts; var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); - writeKeyword(writer, 81 /* ExtendsKeyword */); + writeKeyword(writer, 83 /* ExtendsKeyword */); writeSpace(writer); buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } @@ -14619,9 +14998,9 @@ var ts; } appendSymbolNameOnly(p, writer); if (isOptionalParameter(parameterNode)) { - writePunctuation(writer, 52 /* QuestionToken */); + writePunctuation(writer, 53 /* QuestionToken */); } - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } @@ -14668,14 +15047,14 @@ var ts; writePunctuation(writer, 34 /* EqualsGreaterThanToken */); } else { - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); } writeSpace(writer); var returnType; if (signature.typePredicate) { writer.writeParameter(signature.typePredicate.parameterName); writeSpace(writer); - writeKeyword(writer, 122 /* IsKeyword */); + writeKeyword(writer, 124 /* IsKeyword */); writeSpace(writer); returnType = signature.typePredicate.type; } @@ -14711,12 +15090,12 @@ var ts; function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 216 /* ModuleDeclaration */) { + if (node.kind === 218 /* ModuleDeclaration */) { if (node.name.kind === 9 /* StringLiteral */) { return node; } } - else if (node.kind === 246 /* SourceFile */) { + else if (node.kind === 248 /* SourceFile */) { return ts.isExternalModule(node) ? node : undefined; } } @@ -14765,70 +15144,70 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 161 /* BindingElement */: + case 163 /* BindingElement */: return isDeclarationVisible(node.parent.parent); - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: if (ts.isBindingPattern(node.name) && !node.name.elements.length) { // If the binding pattern is empty, this variable declaration is not visible return false; } // Otherwise fall through - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 211 /* FunctionDeclaration */: - case 215 /* EnumDeclaration */: - case 219 /* ImportEqualsDeclaration */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 213 /* FunctionDeclaration */: + case 217 /* EnumDeclaration */: + case 221 /* ImportEqualsDeclaration */: var parent_4 = getDeclarationContainer(node); // If the node is not exported or it is not ambient module element (except import declaration) if (!(ts.getCombinedNodeFlags(node) & 1 /* Export */) && - !(node.kind !== 219 /* ImportEqualsDeclaration */ && parent_4.kind !== 246 /* SourceFile */ && ts.isInAmbientContext(parent_4))) { + !(node.kind !== 221 /* ImportEqualsDeclaration */ && parent_4.kind !== 248 /* SourceFile */ && ts.isInAmbientContext(parent_4))) { return isGlobalSourceFile(parent_4); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent_4); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.flags & (32 /* Private */ | 64 /* Protected */)) { // Private/protected properties/methods are not visible return false; } // Public properties/methods are visible if its parents are visible, so let it fall into next case statement - case 142 /* Constructor */: - case 146 /* ConstructSignature */: - case 145 /* CallSignature */: - case 147 /* IndexSignature */: - case 136 /* Parameter */: - case 217 /* ModuleBlock */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 153 /* TypeLiteral */: - case 149 /* TypeReference */: - case 154 /* ArrayType */: - case 155 /* TupleType */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: - case 158 /* ParenthesizedType */: + case 144 /* Constructor */: + case 148 /* ConstructSignature */: + case 147 /* CallSignature */: + case 149 /* IndexSignature */: + case 138 /* Parameter */: + case 219 /* ModuleBlock */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 155 /* TypeLiteral */: + case 151 /* TypeReference */: + case 156 /* ArrayType */: + case 157 /* TupleType */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: + case 160 /* ParenthesizedType */: return isDeclarationVisible(node.parent); // Default binding, import specifier and namespace import is visible // only on demand so by default it is not visible - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: - case 224 /* ImportSpecifier */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: + case 226 /* ImportSpecifier */: return false; // Type parameters are always visible - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: // Source file is always visible - case 246 /* SourceFile */: + case 248 /* SourceFile */: return true; // Export assignements do not create name bindings outside the module - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return false; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); @@ -14844,10 +15223,10 @@ var ts; } function collectLinkedAliases(node) { var exportSymbol; - if (node.parent && node.parent.kind === 225 /* ExportAssignment */) { + if (node.parent && node.parent.kind === 227 /* ExportAssignment */) { exportSymbol = resolveName(node.parent, node.text, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */ | 8388608 /* Alias */, ts.Diagnostics.Cannot_find_name_0, node); } - else if (node.parent.kind === 228 /* ExportSpecifier */) { + else if (node.parent.kind === 230 /* ExportSpecifier */) { var exportSpecifier = node.parent; exportSymbol = exportSpecifier.parent.parent.moduleSpecifier ? getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) : @@ -14939,7 +15318,7 @@ var ts; node = ts.getRootDeclaration(node); // Parent chain: // VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container' - return node.kind === 209 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; + return node.kind === 211 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { // TypeScript 1.0 spec (April 2014): 8.4 @@ -14957,10 +15336,16 @@ var ts; function isTypeAny(type) { return type && (type.flags & 1 /* Any */) !== 0; } + // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been + // assigned by contextual typing. + function getTypeForBindingElementParent(node) { + var symbol = getSymbolOfNode(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + } // Return the inferred type for a binding element function getTypeForBindingElement(declaration) { var pattern = declaration.parent; - var parentType = getTypeForVariableLikeDeclaration(pattern.parent); + var parentType = getTypeForBindingElementParent(pattern.parent); // If parent has the unknown (error) type, then so does this binding element if (parentType === unknownType) { return unknownType; @@ -14975,7 +15360,7 @@ var ts; return parentType; } var type; - if (pattern.kind === 159 /* ObjectBindingPattern */) { + if (pattern.kind === 161 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) var name_10 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, @@ -15019,10 +15404,10 @@ var ts; // Return the inferred type for a variable, parameter, or property declaration function getTypeForVariableLikeDeclaration(declaration) { // A variable declared in a for..in statement is always of type any - if (declaration.parent.parent.kind === 198 /* ForInStatement */) { + if (declaration.parent.parent.kind === 200 /* ForInStatement */) { return anyType; } - if (declaration.parent.parent.kind === 199 /* ForOfStatement */) { + if (declaration.parent.parent.kind === 201 /* ForOfStatement */) { // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like // [Symbol.iterator] or next). This may be because we accessed properties from anyType, @@ -15036,11 +15421,11 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136 /* Parameter */) { + if (declaration.kind === 138 /* Parameter */) { var func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present - if (func.kind === 144 /* SetAccessor */ && !ts.hasDynamicName(func)) { - var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 143 /* GetAccessor */); + if (func.kind === 146 /* SetAccessor */ && !ts.hasDynamicName(func)) { + var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 145 /* GetAccessor */); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); } @@ -15056,7 +15441,7 @@ var ts; return checkExpressionCached(declaration.initializer); } // If it is a short-hand property assignment, use the type of the identifier - if (declaration.kind === 244 /* ShorthandPropertyAssignment */) { + if (declaration.kind === 246 /* ShorthandPropertyAssignment */) { return checkIdentifier(declaration.name); } // If the declaration specifies a binding pattern, use the type implied by the binding pattern @@ -15102,7 +15487,7 @@ var ts; return languageVersion >= 2 /* ES6 */ ? createIterableType(anyType) : anyArrayType; } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. - var elementTypes = ts.map(elements, function (e) { return e.kind === 185 /* OmittedExpression */ ? anyType : getTypeFromBindingElement(e, includePatternInType); }); + var elementTypes = ts.map(elements, function (e) { return e.kind === 187 /* OmittedExpression */ ? anyType : getTypeFromBindingElement(e, includePatternInType); }); if (includePatternInType) { var result = createNewTupleType(elementTypes); result.pattern = pattern; @@ -15118,7 +15503,7 @@ var ts; // parameter with no type annotation or initializer, the type implied by the binding pattern becomes the type of // the parameter. function getTypeFromBindingPattern(pattern, includePatternInType) { - return pattern.kind === 159 /* ObjectBindingPattern */ + return pattern.kind === 161 /* ObjectBindingPattern */ ? getTypeFromObjectBindingPattern(pattern, includePatternInType) : getTypeFromArrayBindingPattern(pattern, includePatternInType); } @@ -15140,14 +15525,14 @@ var ts; // During a normal type check we'll never get to here with a property assignment (the check of the containing // object literal uses a different path). We exclude widening only so that language services and type verification // tools see the actual type. - return declaration.kind !== 243 /* PropertyAssignment */ ? getWidenedType(type) : type; + return declaration.kind !== 245 /* PropertyAssignment */ ? getWidenedType(type) : type; } // Rest parameters default to type any[], other parameters default to type any type = declaration.dotDotDotToken ? anyArrayType : anyType; // Report implicit any errors unless this is a private property within an ambient declaration if (reportErrors && compilerOptions.noImplicitAny) { var root = ts.getRootDeclaration(declaration); - if (!isPrivateWithinAmbient(root) && !(root.kind === 136 /* Parameter */ && isPrivateWithinAmbient(root.parent))) { + if (!isPrivateWithinAmbient(root) && !(root.kind === 138 /* Parameter */ && isPrivateWithinAmbient(root.parent))) { reportImplicitAnyError(declaration, type); } } @@ -15162,11 +15547,11 @@ var ts; } // Handle catch clause variables var declaration = symbol.valueDeclaration; - if (declaration.parent.kind === 242 /* CatchClause */) { + if (declaration.parent.kind === 244 /* CatchClause */) { return links.type = anyType; } // Handle export default expressions - if (declaration.kind === 225 /* ExportAssignment */) { + if (declaration.kind === 227 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } // Handle variable, parameter or property @@ -15194,7 +15579,7 @@ var ts; } function getAnnotatedAccessorType(accessor) { if (accessor) { - if (accessor.kind === 143 /* GetAccessor */) { + if (accessor.kind === 145 /* GetAccessor */) { return accessor.type && getTypeFromTypeNode(accessor.type); } else { @@ -15210,8 +15595,8 @@ var ts; if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } - var getter = ts.getDeclarationOfKind(symbol, 143 /* GetAccessor */); - var setter = ts.getDeclarationOfKind(symbol, 144 /* SetAccessor */); + var getter = ts.getDeclarationOfKind(symbol, 145 /* GetAccessor */); + var setter = ts.getDeclarationOfKind(symbol, 146 /* SetAccessor */); var type; // First try to see if the user specified a return type on the get-accessor. var getterReturnType = getAnnotatedAccessorType(getter); @@ -15240,7 +15625,7 @@ var ts; if (!popTypeResolution()) { type = anyType; if (compilerOptions.noImplicitAny) { - var getter_1 = ts.getDeclarationOfKind(symbol, 143 /* GetAccessor */); + var getter_1 = ts.getDeclarationOfKind(symbol, 145 /* GetAccessor */); error(getter_1, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } } @@ -15340,9 +15725,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 212 /* ClassDeclaration */ || node.kind === 184 /* ClassExpression */ || - node.kind === 211 /* FunctionDeclaration */ || node.kind === 171 /* FunctionExpression */ || - node.kind === 141 /* MethodDeclaration */ || node.kind === 172 /* ArrowFunction */) { + if (node.kind === 214 /* ClassDeclaration */ || node.kind === 186 /* ClassExpression */ || + node.kind === 213 /* FunctionDeclaration */ || node.kind === 173 /* FunctionExpression */ || + node.kind === 143 /* MethodDeclaration */ || node.kind === 174 /* ArrowFunction */) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -15352,7 +15737,7 @@ var ts; } // The outer type parameters are those defined by enclosing generic classes, methods, or functions. function getOuterTypeParametersOfClassOrInterface(symbol) { - var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 213 /* InterfaceDeclaration */); + var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 215 /* InterfaceDeclaration */); return appendOuterTypeParameters(undefined, declaration); } // The local type parameters are the combined set of type parameters from all declarations of the class, @@ -15361,8 +15746,8 @@ var ts; var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 213 /* InterfaceDeclaration */ || node.kind === 212 /* ClassDeclaration */ || - node.kind === 184 /* ClassExpression */ || node.kind === 214 /* TypeAliasDeclaration */) { + if (node.kind === 215 /* InterfaceDeclaration */ || node.kind === 214 /* ClassDeclaration */ || + node.kind === 186 /* ClassExpression */ || node.kind === 216 /* TypeAliasDeclaration */) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -15482,7 +15867,7 @@ var ts; type.resolvedBaseTypes = []; for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) { var declaration = _a[_i]; - if (declaration.kind === 213 /* InterfaceDeclaration */ && ts.getInterfaceBaseTypeNodes(declaration)) { + if (declaration.kind === 215 /* InterfaceDeclaration */ && ts.getInterfaceBaseTypeNodes(declaration)) { for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) { var node = _c[_b]; var baseType = getTypeFromTypeNode(node); @@ -15503,6 +15888,32 @@ var ts; } } } + // Returns true if the interface given by the symbol is free of "this" references. Specifically, the result is + // true if the interface itself contains no references to "this" in its body, if all base types are interfaces, + // and if none of the base interfaces have a "this" type. + function isIndependentInterface(symbol) { + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var declaration = _a[_i]; + if (declaration.kind === 215 /* InterfaceDeclaration */) { + if (declaration.flags & 524288 /* ContainsThis */) { + return false; + } + var baseTypeNodes = ts.getInterfaceBaseTypeNodes(declaration); + if (baseTypeNodes) { + for (var _b = 0; _b < baseTypeNodes.length; _b++) { + var node = baseTypeNodes[_b]; + if (ts.isSupportedExpressionWithTypeArguments(node)) { + var baseSymbol = resolveEntityName(node.expression, 793056 /* Type */, /*ignoreErrors*/ true); + if (!baseSymbol || !(baseSymbol.flags & 64 /* Interface */) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) { + return false; + } + } + } + } + } + } + return true; + } function getDeclaredTypeOfClassOrInterface(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { @@ -15510,7 +15921,12 @@ var ts; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); - if (outerTypeParameters || localTypeParameters) { + // A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type + // because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular, + // property types inferred from initializers and method return types inferred from return statements are very hard + // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of + // "this" references. + if (outerTypeParameters || localTypeParameters || kind === 1024 /* Class */ || !isIndependentInterface(symbol)) { type.flags |= 4096 /* Reference */; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; @@ -15519,6 +15935,9 @@ var ts; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; + type.thisType = createType(512 /* TypeParameter */ | 33554432 /* ThisType */); + type.thisType.symbol = symbol; + type.thisType.constraint = getTypeWithThisArgument(type); } } return links.declaredType; @@ -15531,7 +15950,7 @@ var ts; if (!pushTypeResolution(symbol, 2 /* DeclaredType */)) { return unknownType; } - var declaration = ts.getDeclarationOfKind(symbol, 214 /* TypeAliasDeclaration */); + var declaration = ts.getDeclarationOfKind(symbol, 216 /* TypeAliasDeclaration */); var type = getTypeFromTypeNode(declaration.type); if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); @@ -15564,7 +15983,7 @@ var ts; if (!links.declaredType) { var type = createType(512 /* TypeParameter */); type.symbol = symbol; - if (!ts.getDeclarationOfKind(symbol, 135 /* TypeParameter */).constraint) { + if (!ts.getDeclarationOfKind(symbol, 137 /* TypeParameter */).constraint) { type.constraint = noConstraintType; } links.declaredType = type; @@ -15597,6 +16016,79 @@ var ts; } return unknownType; } + // A type reference is considered independent if each type argument is considered independent. + function isIndependentTypeReference(node) { + if (node.typeArguments) { + for (var _i = 0, _a = node.typeArguments; _i < _a.length; _i++) { + var typeNode = _a[_i]; + if (!isIndependentType(typeNode)) { + return false; + } + } + } + return true; + } + // A type is considered independent if it the any, string, number, boolean, symbol, or void keyword, a string + // literal type, an array with an element type that is considered independent, or a type reference that is + // considered independent. + function isIndependentType(node) { + switch (node.kind) { + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: + case 9 /* StringLiteral */: + return true; + case 156 /* ArrayType */: + return isIndependentType(node.elementType); + case 151 /* TypeReference */: + return isIndependentTypeReference(node); + } + return false; + } + // A variable-like declaration is considered independent (free of this references) if it has a type annotation + // that specifies an independent type, or if it has no type annotation and no initializer (and thus of type any). + function isIndependentVariableLikeDeclaration(node) { + return node.type && isIndependentType(node.type) || !node.type && !node.initializer; + } + // A function-like declaration is considered independent (free of this references) if it has a return type + // annotation that is considered independent and if each parameter is considered independent. + function isIndependentFunctionLikeDeclaration(node) { + if (node.kind !== 144 /* Constructor */ && (!node.type || !isIndependentType(node.type))) { + return false; + } + for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) { + var parameter = _a[_i]; + if (!isIndependentVariableLikeDeclaration(parameter)) { + return false; + } + } + return true; + } + // Returns true if the class or interface member given by the symbol is free of "this" references. The + // function may return false for symbols that are actually free of "this" references because it is not + // feasible to perform a complete analysis in all cases. In particular, property members with types + // inferred from their initializers and function members with inferred return types are convervatively + // assumed not to be free of "this" references. + function isIndependentMember(symbol) { + if (symbol.declarations && symbol.declarations.length === 1) { + var declaration = symbol.declarations[0]; + if (declaration) { + switch (declaration.kind) { + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + return isIndependentVariableLikeDeclaration(declaration); + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + return isIndependentFunctionLikeDeclaration(declaration); + } + } + } + return false; + } function createSymbolTable(symbols) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { @@ -15605,11 +16097,13 @@ var ts; } return result; } - function createInstantiatedSymbolTable(symbols, mapper) { + // The mappingThisOnly flag indicates that the only type parameter being mapped is "this". When the flag is true, + // we check symbols to see if we can quickly conclude they are free of "this" references, thus needing no instantiation. + function createInstantiatedSymbolTable(symbols, mapper, mappingThisOnly) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { var symbol = symbols[_i]; - result[symbol.name] = instantiateSymbol(symbol, mapper); + result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper); } return result; } @@ -15640,44 +16134,54 @@ var ts; } return type; } - function resolveClassOrInterfaceMembers(type) { - var target = resolveDeclaredMembers(type); - var members = target.symbol.members; - var callSignatures = target.declaredCallSignatures; - var constructSignatures = target.declaredConstructSignatures; - var stringIndexType = target.declaredStringIndexType; - var numberIndexType = target.declaredNumberIndexType; - var baseTypes = getBaseTypes(target); + function getTypeWithThisArgument(type, thisArgument) { + if (type.flags & 4096 /* Reference */) { + return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType])); + } + return type; + } + function resolveObjectTypeMembers(type, source, typeParameters, typeArguments) { + var mapper = identityMapper; + var members = source.symbol.members; + var callSignatures = source.declaredCallSignatures; + var constructSignatures = source.declaredConstructSignatures; + var stringIndexType = source.declaredStringIndexType; + var numberIndexType = source.declaredNumberIndexType; + if (!ts.rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { + mapper = createTypeMapper(typeParameters, typeArguments); + members = createInstantiatedSymbolTable(source.declaredProperties, mapper, /*mappingThisOnly*/ typeParameters.length === 1); + callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); + constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); + stringIndexType = instantiateType(source.declaredStringIndexType, mapper); + numberIndexType = instantiateType(source.declaredNumberIndexType, mapper); + } + var baseTypes = getBaseTypes(source); if (baseTypes.length) { - members = createSymbolTable(target.declaredProperties); + if (members === source.symbol.members) { + members = createSymbolTable(source.declaredProperties); + } + var thisArgument = ts.lastOrUndefined(typeArguments); for (var _i = 0; _i < baseTypes.length; _i++) { var baseType = baseTypes[_i]; - addInheritedMembers(members, getPropertiesOfObjectType(baseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0 /* Call */)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1 /* Construct */)); - stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0 /* String */); - numberIndexType = numberIndexType || getIndexTypeOfType(baseType, 1 /* Number */); + var instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType; + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); + callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); + constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); + stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); + numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1 /* Number */); } } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } + function resolveClassOrInterfaceMembers(type) { + resolveObjectTypeMembers(type, resolveDeclaredMembers(type), emptyArray, emptyArray); + } function resolveTypeReferenceMembers(type) { - var target = resolveDeclaredMembers(type.target); - var mapper = createTypeMapper(target.typeParameters, type.typeArguments); - var members = createInstantiatedSymbolTable(target.declaredProperties, mapper); - var callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature); - var constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature); - var stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined; - var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; - ts.forEach(getBaseTypes(target), function (baseType) { - var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); - stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); - numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1 /* Number */); - }); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + var source = resolveDeclaredMembers(type.target); + var typeParameters = ts.concatenate(source.typeParameters, [source.thisType]); + var typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ? + type.typeArguments : ts.concatenate(type.typeArguments, [type]); + resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); @@ -15726,7 +16230,9 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveStructuredTypeMembers(createArrayType(getUnionType(type.elementTypes, /*noSubtypeReduction*/ true))); + var arrayElementType = getUnionType(type.elementTypes, /*noSubtypeReduction*/ true); + // Make the tuple type itself the 'this' type by including an extra type argument + var arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); @@ -15842,7 +16348,14 @@ var ts; var constructSignatures; var stringIndexType; var numberIndexType; - if (symbol.flags & 2048 /* TypeLiteral */) { + if (type.target) { + members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); + callSignatures = instantiateList(getSignaturesOfType(type.target, 0 /* Call */), type.mapper, instantiateSignature); + constructSignatures = instantiateList(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper, instantiateSignature); + stringIndexType = instantiateType(getIndexTypeOfType(type.target, 0 /* String */), type.mapper); + numberIndexType = instantiateType(getIndexTypeOfType(type.target, 1 /* Number */), type.mapper); + } + else if (symbol.flags & 2048 /* TypeLiteral */) { members = symbol.members; callSignatures = getSignaturesOfSymbol(members["__call"]); constructSignatures = getSignaturesOfSymbol(members["__new"]); @@ -15879,7 +16392,10 @@ var ts; } function resolveStructuredTypeMembers(type) { if (!type.members) { - if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { + if (type.flags & 4096 /* Reference */) { + resolveTypeReferenceMembers(type); + } + else if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { resolveClassOrInterfaceMembers(type); } else if (type.flags & 65536 /* Anonymous */) { @@ -15894,9 +16410,6 @@ var ts; else if (type.flags & 32768 /* Intersection */) { resolveIntersectionTypeMembers(type); } - else { - resolveTypeReferenceMembers(type); - } } return type; } @@ -16125,7 +16638,7 @@ var ts; function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { - var classType = declaration.kind === 142 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; + var classType = declaration.kind === 144 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; @@ -16157,7 +16670,7 @@ var ts; } else if (declaration.type) { returnType = getTypeFromTypeNode(declaration.type); - if (declaration.type.kind === 148 /* TypePredicate */) { + if (declaration.type.kind === 150 /* TypePredicate */) { var typePredicateNode = declaration.type; typePredicate = { parameterName: typePredicateNode.parameterName ? typePredicateNode.parameterName.text : undefined, @@ -16169,8 +16682,8 @@ var ts; else { // TypeScript 1.0 spec (April 2014): // If only one accessor includes a type annotation, the other behaves as if it had the same type annotation. - if (declaration.kind === 143 /* GetAccessor */ && !ts.hasDynamicName(declaration)) { - var setter = ts.getDeclarationOfKind(declaration.symbol, 144 /* SetAccessor */); + if (declaration.kind === 145 /* GetAccessor */ && !ts.hasDynamicName(declaration)) { + var setter = ts.getDeclarationOfKind(declaration.symbol, 146 /* SetAccessor */); returnType = getAnnotatedAccessorType(setter); } if (!returnType && ts.nodeIsMissing(declaration.body)) { @@ -16188,19 +16701,19 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: // Don't include signature if node is the implementation of an overloaded function. A node is considered // an implementation node if it has a body and the previous node is of the same kind and immediately // precedes the implementation node (i.e. has the same parent and ends where the implementation starts). @@ -16277,7 +16790,7 @@ var ts; // object type literal or interface (using the new keyword). Each way of declaring a constructor // will result in a different declaration kind. if (!signature.isolatedSignatureType) { - var isConstructor = signature.declaration.kind === 142 /* Constructor */ || signature.declaration.kind === 146 /* ConstructSignature */; + var isConstructor = signature.declaration.kind === 144 /* Constructor */ || signature.declaration.kind === 148 /* ConstructSignature */; var type = createObjectType(65536 /* Anonymous */ | 262144 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; @@ -16291,7 +16804,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 /* Number */ ? 126 /* NumberKeyword */ : 128 /* StringKeyword */; + var syntaxKind = kind === 1 /* Number */ ? 128 /* NumberKeyword */ : 130 /* StringKeyword */; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) { @@ -16320,30 +16833,33 @@ var ts; type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType; } else { - type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 135 /* TypeParameter */).constraint); + type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 137 /* TypeParameter */).constraint); } } return type.constraint === noConstraintType ? undefined : type.constraint; } function getParentSymbolOfTypeParameter(typeParameter) { - return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 135 /* TypeParameter */).parent); + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 137 /* TypeParameter */).parent); } function getTypeListId(types) { - switch (types.length) { - case 1: - return "" + types[0].id; - case 2: - return types[0].id + "," + types[1].id; - default: - var result = ""; - for (var i = 0; i < types.length; i++) { - if (i > 0) { - result += ","; + if (types) { + switch (types.length) { + case 1: + return "" + types[0].id; + case 2: + return types[0].id + "," + types[1].id; + default: + var result = ""; + for (var i = 0; i < types.length; i++) { + if (i > 0) { + result += ","; + } + result += types[i].id; } - result += types[i].id; - } - return result; + return result; + } } + return ""; } // This function is used to propagate certain flags when creating new object type references and union types. // It is only necessary to do so if a constituent type might be the undefined type, the null type, the type @@ -16361,7 +16877,7 @@ var ts; var id = getTypeListId(typeArguments); var type = target.instantiations[id]; if (!type) { - var flags = 4096 /* Reference */ | getPropagatingFlagsOfTypes(typeArguments); + var flags = 4096 /* Reference */ | (typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -16380,13 +16896,13 @@ var ts; currentNode = currentNode.parent; } // if last step was made from the type parameter this means that path has started somewhere in constraint which is illegal - links.isIllegalTypeReferenceInConstraint = currentNode.kind === 135 /* TypeParameter */; + links.isIllegalTypeReferenceInConstraint = currentNode.kind === 137 /* TypeParameter */; return links.isIllegalTypeReferenceInConstraint; } function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) { var typeParameterSymbol; function check(n) { - if (n.kind === 149 /* TypeReference */ && n.typeName.kind === 67 /* Identifier */) { + if (n.kind === 151 /* TypeReference */ && n.typeName.kind === 69 /* Identifier */) { var links = getNodeLinks(n); if (links.isIllegalTypeReferenceInConstraint === undefined) { var symbol = resolveName(typeParameter, n.typeName.text, 793056 /* Type */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); @@ -16473,7 +16989,7 @@ var ts; var links = getNodeLinks(node); if (!links.resolvedType) { // We only support expressions that are simple qualified names. For other expressions this produces undefined. - var typeNameOrExpression = node.kind === 149 /* TypeReference */ ? node.typeName : + var typeNameOrExpression = node.kind === 151 /* TypeReference */ ? node.typeName : ts.isSupportedExpressionWithTypeArguments(node) ? node.expression : undefined; var symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, 793056 /* Type */) || unknownSymbol; @@ -16505,9 +17021,9 @@ var ts; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; switch (declaration.kind) { - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: return declaration; } } @@ -16567,17 +17083,17 @@ var ts; /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ - function createTypeFromGenericGlobalType(genericGlobalType, elementType) { - return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + function createTypeFromGenericGlobalType(genericGlobalType, typeArguments) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, typeArguments) : emptyObjectType; } function createIterableType(elementType) { - return createTypeFromGenericGlobalType(globalIterableType, elementType); + return createTypeFromGenericGlobalType(globalIterableType, [elementType]); } function createIterableIteratorType(elementType) { - return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); + return createTypeFromGenericGlobalType(globalIterableIteratorType, [elementType]); } function createArrayType(elementType) { - return createTypeFromGenericGlobalType(globalArrayType, elementType); + return createTypeFromGenericGlobalType(globalArrayType, [elementType]); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -16749,48 +17265,68 @@ var ts; } return links.resolvedType; } + function getThisType(node) { + var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false); + var parent = container && container.parent; + if (parent && (ts.isClassLike(parent) || parent.kind === 215 /* InterfaceDeclaration */)) { + if (!(container.flags & 128 /* Static */)) { + return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType; + } + } + error(node, ts.Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface); + return unknownType; + } + function getTypeFromThisTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getThisType(node); + } + return links.resolvedType; + } function getTypeFromTypeNode(node) { switch (node.kind) { - case 115 /* AnyKeyword */: + case 117 /* AnyKeyword */: return anyType; - case 128 /* StringKeyword */: + case 130 /* StringKeyword */: return stringType; - case 126 /* NumberKeyword */: + case 128 /* NumberKeyword */: return numberType; - case 118 /* BooleanKeyword */: + case 120 /* BooleanKeyword */: return booleanType; - case 129 /* SymbolKeyword */: + case 131 /* SymbolKeyword */: return esSymbolType; - case 101 /* VoidKeyword */: + case 103 /* VoidKeyword */: return voidType; + case 97 /* ThisKeyword */: + return getTypeFromThisTypeNode(node); case 9 /* StringLiteral */: return getTypeFromStringLiteral(node); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return getTypeFromTypeReference(node); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return booleanType; - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return getTypeFromTypeQueryNode(node); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return getTypeFromArrayTypeNode(node); - case 155 /* TupleType */: + case 157 /* TupleType */: return getTypeFromTupleTypeNode(node); - case 156 /* UnionType */: + case 158 /* UnionType */: return getTypeFromUnionTypeNode(node); - case 157 /* IntersectionType */: + case 159 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return getTypeFromTypeNode(node.type); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 153 /* TypeLiteral */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 155 /* TypeLiteral */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode - case 67 /* Identifier */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 135 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: @@ -16894,7 +17430,7 @@ var ts; type: instantiateType(signature.typePredicate.type, mapper) }; } - var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), signature.resolvedReturnType ? instantiateType(signature.resolvedReturnType, mapper) : undefined, freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -16932,21 +17468,13 @@ var ts; } // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it var result = createObjectType(65536 /* Anonymous */ | 131072 /* Instantiated */, type.symbol); - result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); - result.members = createSymbolTable(result.properties); - result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); - result.constructSignatures = instantiateList(getSignaturesOfType(type, 1 /* Construct */), mapper, instantiateSignature); - var stringIndexType = getIndexTypeOfType(type, 0 /* String */); - var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); - if (stringIndexType) - result.stringIndexType = instantiateType(stringIndexType, mapper); - if (numberIndexType) - result.numberIndexType = instantiateType(numberIndexType, mapper); + result.target = type; + result.mapper = mapper; mapper.instantiations[type.id] = result; return result; } function instantiateType(type, mapper) { - if (mapper !== identityMapper) { + if (type && mapper !== identityMapper) { if (type.flags & 512 /* TypeParameter */) { return mapper(type); } @@ -16972,27 +17500,27 @@ var ts; // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. function isContextSensitive(node) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); switch (node.kind) { - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return isContextSensitiveFunctionLikeDeclaration(node); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return ts.forEach(node.properties, isContextSensitive); - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return ts.forEach(node.elements, isContextSensitive); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse); - case 179 /* BinaryExpression */: - return node.operatorToken.kind === 51 /* BarBarToken */ && + case 181 /* BinaryExpression */: + return node.operatorToken.kind === 52 /* BarBarToken */ && (isContextSensitive(node.left) || isContextSensitive(node.right)); - case 243 /* PropertyAssignment */: + case 245 /* PropertyAssignment */: return isContextSensitive(node.initializer); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return isContextSensitiveFunctionLikeDeclaration(node); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return isContextSensitive(node.expression); } return false; @@ -17176,7 +17704,7 @@ var ts; else { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, reportErrors)) { + if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } @@ -17205,7 +17733,7 @@ var ts; if (source.flags & 80896 /* ObjectType */ && target.flags & 80896 /* ObjectType */) { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if all type arguments are identical - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, /*reportErrors*/ false)) { + if (result = typeArgumentsRelatedTo(source, target, /*reportErrors*/ false)) { return result; } } @@ -17322,9 +17850,14 @@ var ts; } return result; } - function typesRelatedTo(sources, targets, reportErrors) { + function typeArgumentsRelatedTo(source, target, reportErrors) { + var sources = source.typeArguments || emptyArray; + var targets = target.typeArguments || emptyArray; + if (sources.length !== targets.length && relation === identityRelation) { + return 0 /* False */; + } var result = -1 /* True */; - for (var i = 0, len = sources.length; i < len; i++) { + for (var i = 0; i < targets.length; i++) { var related = isRelatedTo(sources[i], targets[i], reportErrors); if (!related) { return 0 /* False */; @@ -17542,7 +18075,7 @@ var ts; if (kind === 1 /* Construct */) { // Only want to compare the construct signatures for abstractness guarantees. // Because the "abstractness" of a class is the same across all construct signatures - // (internally we are checking the corresponding declaration), it is enough to perform + // (internally we are checking the corresponding declaration), it is enough to perform // the check and report an error once over all pairs of source and target construct signatures. // // sourceSig and targetSig are (possibly) undefined. @@ -18042,22 +18575,22 @@ var ts; var typeAsString = typeToString(getWidenedType(type)); var diagnostic; switch (declaration.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; - case 136 /* Parameter */: + case 138 /* Parameter */: diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; break; - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: if (!declaration.name) { error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); return; @@ -18167,9 +18700,10 @@ var ts; } else if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // If source and target are references to the same generic type, infer from type arguments - var sourceTypes = source.typeArguments; - var targetTypes = target.typeArguments; - for (var i = 0; i < sourceTypes.length; i++) { + var sourceTypes = source.typeArguments || emptyArray; + var targetTypes = target.typeArguments || emptyArray; + var count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length; + for (var i = 0; i < count; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } @@ -18347,10 +18881,10 @@ var ts; // The expression is restricted to a single identifier or a sequence of identifiers separated by periods while (node) { switch (node.kind) { - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return true; - case 67 /* Identifier */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 135 /* QualifiedName */: node = node.parent; continue; default: @@ -18396,12 +18930,12 @@ var ts; } return links.assignmentChecks[symbol.id] = isAssignedIn(node); function isAssignedInBinaryExpression(node) { - if (node.operatorToken.kind >= 55 /* FirstAssignment */ && node.operatorToken.kind <= 66 /* LastAssignment */) { + if (node.operatorToken.kind >= 56 /* FirstAssignment */ && node.operatorToken.kind <= 68 /* LastAssignment */) { var n = node.left; - while (n.kind === 170 /* ParenthesizedExpression */) { + while (n.kind === 172 /* ParenthesizedExpression */) { n = n.expression; } - if (n.kind === 67 /* Identifier */ && getResolvedSymbol(n) === symbol) { + if (n.kind === 69 /* Identifier */ && getResolvedSymbol(n) === symbol) { return true; } } @@ -18415,55 +18949,55 @@ var ts; } function isAssignedIn(node) { switch (node.kind) { - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return isAssignedInBinaryExpression(node); - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: return isAssignedInVariableDeclaration(node); - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: - case 162 /* ArrayLiteralExpression */: - case 163 /* ObjectLiteralExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: - case 170 /* ParenthesizedExpression */: - case 177 /* PrefixUnaryExpression */: - case 173 /* DeleteExpression */: - case 176 /* AwaitExpression */: - case 174 /* TypeOfExpression */: - case 175 /* VoidExpression */: - case 178 /* PostfixUnaryExpression */: - case 182 /* YieldExpression */: - case 180 /* ConditionalExpression */: - case 183 /* SpreadElementExpression */: - case 190 /* Block */: - case 191 /* VariableStatement */: - case 193 /* ExpressionStatement */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 202 /* ReturnStatement */: - case 203 /* WithStatement */: - case 204 /* SwitchStatement */: - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - case 205 /* LabeledStatement */: - case 206 /* ThrowStatement */: - case 207 /* TryStatement */: - case 242 /* CatchClause */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 236 /* JsxAttribute */: - case 237 /* JsxSpreadAttribute */: - case 233 /* JsxOpeningElement */: - case 238 /* JsxExpression */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: + case 164 /* ArrayLiteralExpression */: + case 165 /* ObjectLiteralExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: + case 172 /* ParenthesizedExpression */: + case 179 /* PrefixUnaryExpression */: + case 175 /* DeleteExpression */: + case 178 /* AwaitExpression */: + case 176 /* TypeOfExpression */: + case 177 /* VoidExpression */: + case 180 /* PostfixUnaryExpression */: + case 184 /* YieldExpression */: + case 182 /* ConditionalExpression */: + case 185 /* SpreadElementExpression */: + case 192 /* Block */: + case 193 /* VariableStatement */: + case 195 /* ExpressionStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 204 /* ReturnStatement */: + case 205 /* WithStatement */: + case 206 /* SwitchStatement */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + case 207 /* LabeledStatement */: + case 208 /* ThrowStatement */: + case 209 /* TryStatement */: + case 244 /* CatchClause */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 238 /* JsxAttribute */: + case 239 /* JsxSpreadAttribute */: + case 235 /* JsxOpeningElement */: + case 240 /* JsxExpression */: return ts.forEachChild(node, isAssignedIn); } return false; @@ -18480,37 +19014,37 @@ var ts; node = node.parent; var narrowedType = type; switch (node.kind) { - case 194 /* IfStatement */: + case 196 /* IfStatement */: // In a branch of an if statement, narrow based on controlling expression if (child !== node.expression) { narrowedType = narrowType(type, node.expression, /*assumeTrue*/ child === node.thenStatement); } break; - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: // In a branch of a conditional expression, narrow based on controlling condition if (child !== node.condition) { narrowedType = narrowType(type, node.condition, /*assumeTrue*/ child === node.whenTrue); } break; - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: // In the right operand of an && or ||, narrow based on left operand if (child === node.right) { - if (node.operatorToken.kind === 50 /* AmpersandAmpersandToken */) { + if (node.operatorToken.kind === 51 /* AmpersandAmpersandToken */) { narrowedType = narrowType(type, node.left, /*assumeTrue*/ true); } - else if (node.operatorToken.kind === 51 /* BarBarToken */) { + else if (node.operatorToken.kind === 52 /* BarBarToken */) { narrowedType = narrowType(type, node.left, /*assumeTrue*/ false); } } break; - case 246 /* SourceFile */: - case 216 /* ModuleDeclaration */: - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: + case 248 /* SourceFile */: + case 218 /* ModuleDeclaration */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: // Stop at the first containing function or module declaration break loop; } @@ -18527,12 +19061,12 @@ var ts; return type; function narrowTypeByEquality(type, expr, assumeTrue) { // Check that we have 'typeof ' on the left and string literal on the right - if (expr.left.kind !== 174 /* TypeOfExpression */ || expr.right.kind !== 9 /* StringLiteral */) { + if (expr.left.kind !== 176 /* TypeOfExpression */ || expr.right.kind !== 9 /* StringLiteral */) { return type; } var left = expr.left; var right = expr.right; - if (left.expression.kind !== 67 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { + if (left.expression.kind !== 69 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { return type; } var typeInfo = primitiveTypeInfo[right.text]; @@ -18592,7 +19126,7 @@ var ts; } function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 67 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 69 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -18664,27 +19198,27 @@ var ts; // will be a subtype or the same type as the argument. function narrowType(type, expr, assumeTrue) { switch (expr.kind) { - case 166 /* CallExpression */: + case 168 /* CallExpression */: return narrowTypeByTypePredicate(type, expr, assumeTrue); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return narrowType(type, expr.expression, assumeTrue); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: var operator = expr.operatorToken.kind; if (operator === 32 /* EqualsEqualsEqualsToken */ || operator === 33 /* ExclamationEqualsEqualsToken */) { return narrowTypeByEquality(type, expr, assumeTrue); } - else if (operator === 50 /* AmpersandAmpersandToken */) { + else if (operator === 51 /* AmpersandAmpersandToken */) { return narrowTypeByAnd(type, expr, assumeTrue); } - else if (operator === 51 /* BarBarToken */) { + else if (operator === 52 /* BarBarToken */) { return narrowTypeByOr(type, expr, assumeTrue); } - else if (operator === 89 /* InstanceOfKeyword */) { + else if (operator === 91 /* InstanceOfKeyword */) { return narrowTypeByInstanceof(type, expr, assumeTrue); } break; - case 177 /* PrefixUnaryExpression */: - if (expr.operator === 48 /* ExclamationToken */) { + case 179 /* PrefixUnaryExpression */: + if (expr.operator === 49 /* ExclamationToken */) { return narrowType(type, expr.operand, !assumeTrue); } break; @@ -18702,7 +19236,7 @@ var ts; // can explicitly bound arguments objects if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); - if (container.kind === 172 /* ArrowFunction */) { + if (container.kind === 174 /* ArrowFunction */) { if (languageVersion < 2 /* ES6 */) { error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } @@ -18733,7 +19267,7 @@ var ts; function checkBlockScopedBindingCapturedInLoop(node, symbol) { if (languageVersion >= 2 /* ES6 */ || (symbol.flags & 2 /* BlockScopedVariable */) === 0 || - symbol.valueDeclaration.parent.kind === 242 /* CatchClause */) { + symbol.valueDeclaration.parent.kind === 244 /* CatchClause */) { return; } // - check if binding is used in some function @@ -18742,12 +19276,12 @@ var ts; // nesting structure: // (variable declaration or binding element) -> variable declaration list -> container var container = symbol.valueDeclaration; - while (container.kind !== 210 /* VariableDeclarationList */) { + while (container.kind !== 212 /* VariableDeclarationList */) { container = container.parent; } // get the parent of variable declaration list container = container.parent; - if (container.kind === 191 /* VariableStatement */) { + if (container.kind === 193 /* VariableStatement */) { // if parent is variable statement - get its parent container = container.parent; } @@ -18767,7 +19301,7 @@ var ts; } function captureLexicalThis(node, container) { getNodeLinks(node).flags |= 2 /* LexicalThis */; - if (container.kind === 139 /* PropertyDeclaration */ || container.kind === 142 /* Constructor */) { + if (container.kind === 141 /* PropertyDeclaration */ || container.kind === 144 /* Constructor */) { var classNode = container.parent; getNodeLinks(classNode).flags |= 4 /* CaptureThis */; } @@ -18781,32 +19315,32 @@ var ts; var container = ts.getThisContainer(node, /* includeArrowFunctions */ true); var needToCaptureLexicalThis = false; // Now skip arrow functions to get the "real" owner of 'this'. - if (container.kind === 172 /* ArrowFunction */) { + if (container.kind === 174 /* ArrowFunction */) { container = ts.getThisContainer(container, /* includeArrowFunctions */ false); // When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code needToCaptureLexicalThis = (languageVersion < 2 /* ES6 */); } switch (container.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; - case 142 /* Constructor */: + case 144 /* Constructor */: if (isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments); } break; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: if (container.flags & 128 /* Static */) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; } @@ -18815,35 +19349,35 @@ var ts; } if (ts.isClassLike(container.parent)) { var symbol = getSymbolOfNode(container.parent); - return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); + return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol).thisType; } return anyType; } function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { - if (n.kind === 136 /* Parameter */) { + if (n.kind === 138 /* Parameter */) { return true; } } return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 166 /* CallExpression */ && node.parent.expression === node; + var isCallExpression = node.parent.kind === 168 /* CallExpression */ && node.parent.expression === node; var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; var container = ts.getSuperContainer(node, /*includeFunctions*/ true); var needToCaptureLexicalThis = false; if (!isCallExpression) { - // adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting - while (container && container.kind === 172 /* ArrowFunction */) { + // adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting + while (container && container.kind === 174 /* ArrowFunction */) { container = ts.getSuperContainer(container, /*includeFunctions*/ true); needToCaptureLexicalThis = languageVersion < 2 /* ES6 */; } } var canUseSuperExpression = isLegalUsageOfSuperExpression(container); var nodeCheckFlag = 0; - // always set NodeCheckFlags for 'super' expression node + // always set NodeCheckFlags for 'super' expression node if (canUseSuperExpression) { if ((container.flags & 128 /* Static */) || isCallExpression) { nodeCheckFlag = 512 /* SuperStatic */; @@ -18866,7 +19400,7 @@ var ts; return unknownType; } if (!canUseSuperExpression) { - if (container && container.kind === 134 /* ComputedPropertyName */) { + if (container && container.kind === 136 /* ComputedPropertyName */) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { @@ -18877,7 +19411,7 @@ var ts; } return unknownType; } - if (container.kind === 142 /* Constructor */ && isInConstructorArgumentInitializer(node, container)) { + if (container.kind === 144 /* Constructor */ && isInConstructorArgumentInitializer(node, container)) { // issue custom error message for super property access in constructor arguments (to be aligned with old compiler) error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments); return unknownType; @@ -18892,7 +19426,7 @@ var ts; if (isCallExpression) { // TS 1.0 SPEC (April 2014): 4.8.1 // Super calls are only permitted in constructors of derived classes - return container.kind === 142 /* Constructor */; + return container.kind === 144 /* Constructor */; } else { // TS 1.0 SPEC (April 2014) @@ -18902,19 +19436,19 @@ var ts; // topmost container must be something that is directly nested in the class declaration if (container && ts.isClassLike(container.parent)) { if (container.flags & 128 /* Static */) { - return container.kind === 141 /* MethodDeclaration */ || - container.kind === 140 /* MethodSignature */ || - container.kind === 143 /* GetAccessor */ || - container.kind === 144 /* SetAccessor */; + return container.kind === 143 /* MethodDeclaration */ || + container.kind === 142 /* MethodSignature */ || + container.kind === 145 /* GetAccessor */ || + container.kind === 146 /* SetAccessor */; } else { - return container.kind === 141 /* MethodDeclaration */ || - container.kind === 140 /* MethodSignature */ || - container.kind === 143 /* GetAccessor */ || - container.kind === 144 /* SetAccessor */ || - container.kind === 139 /* PropertyDeclaration */ || - container.kind === 138 /* PropertySignature */ || - container.kind === 142 /* Constructor */; + return container.kind === 143 /* MethodDeclaration */ || + container.kind === 142 /* MethodSignature */ || + container.kind === 145 /* GetAccessor */ || + container.kind === 146 /* SetAccessor */ || + container.kind === 141 /* PropertyDeclaration */ || + container.kind === 140 /* PropertySignature */ || + container.kind === 144 /* Constructor */; } } } @@ -18955,7 +19489,7 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136 /* Parameter */) { + if (declaration.kind === 138 /* Parameter */) { var type = getContextuallyTypedParameterType(declaration); if (type) { return type; @@ -18988,7 +19522,7 @@ var ts; } function isInParameterInitializerBeforeContainingFunction(node) { while (node.parent && !ts.isFunctionLike(node.parent)) { - if (node.parent.kind === 136 /* Parameter */ && node.parent.initializer === node) { + if (node.parent.kind === 138 /* Parameter */ && node.parent.initializer === node) { return true; } node = node.parent; @@ -18999,8 +19533,8 @@ var ts; // If the containing function has a return type annotation, is a constructor, or is a get accessor whose // corresponding set accessor has a type annotation, return statements in the function are contextually typed if (functionDecl.type || - functionDecl.kind === 142 /* Constructor */ || - functionDecl.kind === 143 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 144 /* SetAccessor */))) { + functionDecl.kind === 144 /* Constructor */ || + functionDecl.kind === 145 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 146 /* SetAccessor */))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); } // Otherwise, if the containing function is contextually typed by a function type with exactly one call signature @@ -19022,7 +19556,7 @@ var ts; return undefined; } function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { - if (template.parent.kind === 168 /* TaggedTemplateExpression */) { + if (template.parent.kind === 170 /* TaggedTemplateExpression */) { return getContextualTypeForArgument(template.parent, substitutionExpression); } return undefined; @@ -19030,13 +19564,13 @@ var ts; function getContextualTypeForBinaryOperand(node) { var binaryExpression = node.parent; var operator = binaryExpression.operatorToken.kind; - if (operator >= 55 /* FirstAssignment */ && operator <= 66 /* LastAssignment */) { + if (operator >= 56 /* FirstAssignment */ && operator <= 68 /* LastAssignment */) { // In an assignment expression, the right operand is contextually typed by the type of the left operand. if (node === binaryExpression.right) { return checkExpression(binaryExpression.left); } } - else if (operator === 51 /* BarBarToken */) { + else if (operator === 52 /* BarBarToken */) { // When an || expression has a contextual type, the operands are contextually typed by that type. When an || // expression has no contextual type, the right operand is contextually typed by the type of the left operand. var type = getContextualType(binaryExpression); @@ -19143,7 +19677,7 @@ var ts; } function getContextualTypeForJsxExpression(expr) { // Contextual type only applies to JSX expressions that are in attribute assignments (not in 'Children' positions) - if (expr.parent.kind === 236 /* JsxAttribute */) { + if (expr.parent.kind === 238 /* JsxAttribute */) { var attrib = expr.parent; var attrsType = getJsxElementAttributesType(attrib.parent); if (!attrsType || isTypeAny(attrsType)) { @@ -19153,7 +19687,7 @@ var ts; return getTypeOfPropertyOfType(attrsType, attrib.name.text); } } - if (expr.kind === 237 /* JsxSpreadAttribute */) { + if (expr.kind === 239 /* JsxSpreadAttribute */) { return getJsxElementAttributesType(expr.parent); } return undefined; @@ -19174,38 +19708,38 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 209 /* VariableDeclaration */: - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 163 /* BindingElement */: return getContextualTypeForInitializerExpression(node); - case 172 /* ArrowFunction */: - case 202 /* ReturnStatement */: + case 174 /* ArrowFunction */: + case 204 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: return getContextualTypeForYieldOperand(parent); - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return getContextualTypeForArgument(parent, node); - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: return getTypeFromTypeNode(parent.type); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return getContextualTypeForBinaryOperand(node); - case 243 /* PropertyAssignment */: + case 245 /* PropertyAssignment */: return getContextualTypeForObjectLiteralElement(parent); - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return getContextualTypeForElementExpression(node); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); - case 188 /* TemplateSpan */: - ts.Debug.assert(parent.parent.kind === 181 /* TemplateExpression */); + case 190 /* TemplateSpan */: + ts.Debug.assert(parent.parent.kind === 183 /* TemplateExpression */); return getContextualTypeForSubstitutionExpression(parent.parent, node); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return getContextualType(parent); - case 238 /* JsxExpression */: - case 237 /* JsxSpreadAttribute */: + case 240 /* JsxExpression */: + case 239 /* JsxSpreadAttribute */: return getContextualTypeForJsxExpression(parent); } return undefined; @@ -19222,7 +19756,7 @@ var ts; } } function isFunctionExpressionOrArrowFunction(node) { - return node.kind === 171 /* FunctionExpression */ || node.kind === 172 /* ArrowFunction */; + return node.kind === 173 /* FunctionExpression */ || node.kind === 174 /* ArrowFunction */; } function getContextualSignatureForFunctionLikeDeclaration(node) { // Only function expressions, arrow functions, and object literal methods are contextually typed. @@ -19236,7 +19770,7 @@ var ts; // all identical ignoring their return type, the result is same signature but with return type as // union type of return types from these signatures function getContextualSignature(node) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); @@ -19299,13 +19833,13 @@ var ts; // an assignment target. Examples include 'a = xxx', '{ p: a } = xxx', '[{ p: a}] = xxx'. function isAssignmentTarget(node) { var parent = node.parent; - if (parent.kind === 179 /* BinaryExpression */ && parent.operatorToken.kind === 55 /* EqualsToken */ && parent.left === node) { + if (parent.kind === 181 /* BinaryExpression */ && parent.operatorToken.kind === 56 /* EqualsToken */ && parent.left === node) { return true; } - if (parent.kind === 243 /* PropertyAssignment */) { + if (parent.kind === 245 /* PropertyAssignment */) { return isAssignmentTarget(parent.parent); } - if (parent.kind === 162 /* ArrayLiteralExpression */) { + if (parent.kind === 164 /* ArrayLiteralExpression */) { return isAssignmentTarget(parent); } return false; @@ -19321,8 +19855,8 @@ var ts; return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false); } function hasDefaultValue(node) { - return (node.kind === 161 /* BindingElement */ && !!node.initializer) || - (node.kind === 179 /* BinaryExpression */ && node.operatorToken.kind === 55 /* EqualsToken */); + return (node.kind === 163 /* BindingElement */ && !!node.initializer) || + (node.kind === 181 /* BinaryExpression */ && node.operatorToken.kind === 56 /* EqualsToken */); } function checkArrayLiteral(node, contextualMapper) { var elements = node.elements; @@ -19331,7 +19865,7 @@ var ts; var inDestructuringPattern = isAssignmentTarget(node); for (var _i = 0; _i < elements.length; _i++) { var e = elements[_i]; - if (inDestructuringPattern && e.kind === 183 /* SpreadElementExpression */) { + if (inDestructuringPattern && e.kind === 185 /* SpreadElementExpression */) { // Given the following situation: // var c: {}; // [...c] = ["", 0]; @@ -19355,7 +19889,7 @@ var ts; var type = checkExpression(e, contextualMapper); elementTypes.push(type); } - hasSpreadElement = hasSpreadElement || e.kind === 183 /* SpreadElementExpression */; + hasSpreadElement = hasSpreadElement || e.kind === 185 /* SpreadElementExpression */; } if (!hasSpreadElement) { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such @@ -19370,7 +19904,7 @@ var ts; var pattern = contextualType.pattern; // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting // tuple type with the corresponding binding or assignment element types to make the lengths equal. - if (pattern && (pattern.kind === 160 /* ArrayBindingPattern */ || pattern.kind === 162 /* ArrayLiteralExpression */)) { + if (pattern && (pattern.kind === 162 /* ArrayBindingPattern */ || pattern.kind === 164 /* ArrayLiteralExpression */)) { var patternElements = pattern.elements; for (var i = elementTypes.length; i < patternElements.length; i++) { var patternElement = patternElements[i]; @@ -19378,7 +19912,7 @@ var ts; elementTypes.push(contextualType.elementTypes[i]); } else { - if (patternElement.kind !== 185 /* OmittedExpression */) { + if (patternElement.kind !== 187 /* OmittedExpression */) { error(patternElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); } elementTypes.push(unknownType); @@ -19393,7 +19927,7 @@ var ts; return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType); } function isNumericName(name) { - return name.kind === 134 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); + return name.kind === 136 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { // It seems odd to consider an expression of type Any to result in a numeric name, @@ -19443,30 +19977,30 @@ var ts; return links.resolvedType; } function checkObjectLiteral(node, contextualMapper) { + var inDestructuringPattern = isAssignmentTarget(node); // Grammar checking - checkGrammarObjectLiteralExpression(node); + checkGrammarObjectLiteralExpression(node, inDestructuringPattern); var propertiesTable = {}; var propertiesArray = []; var contextualType = getContextualType(node); var contextualTypeHasPattern = contextualType && contextualType.pattern && - (contextualType.pattern.kind === 159 /* ObjectBindingPattern */ || contextualType.pattern.kind === 163 /* ObjectLiteralExpression */); - var inDestructuringPattern = isAssignmentTarget(node); + (contextualType.pattern.kind === 161 /* ObjectBindingPattern */ || contextualType.pattern.kind === 165 /* ObjectLiteralExpression */); var typeFlags = 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var memberDecl = _a[_i]; var member = memberDecl.symbol; - if (memberDecl.kind === 243 /* PropertyAssignment */ || - memberDecl.kind === 244 /* ShorthandPropertyAssignment */ || + if (memberDecl.kind === 245 /* PropertyAssignment */ || + memberDecl.kind === 246 /* ShorthandPropertyAssignment */ || ts.isObjectLiteralMethod(memberDecl)) { var type = void 0; - if (memberDecl.kind === 243 /* PropertyAssignment */) { + if (memberDecl.kind === 245 /* PropertyAssignment */) { type = checkPropertyAssignment(memberDecl, contextualMapper); } - else if (memberDecl.kind === 141 /* MethodDeclaration */) { + else if (memberDecl.kind === 143 /* MethodDeclaration */) { type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - ts.Debug.assert(memberDecl.kind === 244 /* ShorthandPropertyAssignment */); + ts.Debug.assert(memberDecl.kind === 246 /* ShorthandPropertyAssignment */); type = checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; @@ -19474,7 +20008,9 @@ var ts; if (inDestructuringPattern) { // If object literal is an assignment pattern and if the assignment pattern specifies a default value // for the property, make the property optional. - if (memberDecl.kind === 243 /* PropertyAssignment */ && hasDefaultValue(memberDecl.initializer)) { + var isOptional = (memberDecl.kind === 245 /* PropertyAssignment */ && hasDefaultValue(memberDecl.initializer)) || + (memberDecl.kind === 246 /* ShorthandPropertyAssignment */ && memberDecl.objectAssignmentInitializer); + if (isOptional) { prop.flags |= 536870912 /* Optional */; } } @@ -19504,7 +20040,7 @@ var ts; // an ordinary function declaration(section 6.1) with no parameters. // A set accessor declaration is processed in the same manner // as an ordinary function declaration with a single parameter and a Void return type. - ts.Debug.assert(memberDecl.kind === 143 /* GetAccessor */ || memberDecl.kind === 144 /* SetAccessor */); + ts.Debug.assert(memberDecl.kind === 145 /* GetAccessor */ || memberDecl.kind === 146 /* SetAccessor */); checkAccessorDeclaration(memberDecl); } if (!ts.hasDynamicName(memberDecl)) { @@ -19566,7 +20102,7 @@ var ts; if (lhs.kind !== rhs.kind) { return false; } - if (lhs.kind === 67 /* Identifier */) { + if (lhs.kind === 69 /* Identifier */) { return lhs.text === rhs.text; } return lhs.right.text === rhs.right.text && @@ -19587,18 +20123,18 @@ var ts; for (var _i = 0, _a = node.children; _i < _a.length; _i++) { var child = _a[_i]; switch (child.kind) { - case 238 /* JsxExpression */: + case 240 /* JsxExpression */: checkJsxExpression(child); break; - case 231 /* JsxElement */: + case 233 /* JsxElement */: checkJsxElement(child); break; - case 232 /* JsxSelfClosingElement */: + case 234 /* JsxSelfClosingElement */: checkJsxSelfClosingElement(child); break; default: // No checks for JSX Text - ts.Debug.assert(child.kind === 234 /* JsxText */); + ts.Debug.assert(child.kind === 236 /* JsxText */); } } return jsxElementType || anyType; @@ -19614,7 +20150,7 @@ var ts; * Returns true iff React would emit this tag name as a string rather than an identifier or qualified name */ function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 133 /* QualifiedName */) { + if (tagName.kind === 135 /* QualifiedName */) { return false; } else { @@ -19733,12 +20269,14 @@ var ts; // Look up the value in the current scope if (valueSymbol && valueSymbol !== unknownSymbol) { links.jsxFlags |= 4 /* ClassElement */; - getSymbolLinks(valueSymbol).referenced = true; + if (valueSymbol.flags & 8388608 /* Alias */) { + markAliasSymbolAsReferenced(valueSymbol); + } } return valueSymbol || unknownSymbol; } function resolveJsxTagName(node) { - if (node.tagName.kind === 67 /* Identifier */) { + if (node.tagName.kind === 69 /* Identifier */) { var tag = node.tagName; var sym = getResolvedSymbol(tag); return sym.exportSymbol || sym; @@ -19923,11 +20461,11 @@ var ts; // thus should have their types ignored var sawSpreadedAny = false; for (var i = node.attributes.length - 1; i >= 0; i--) { - if (node.attributes[i].kind === 236 /* JsxAttribute */) { + if (node.attributes[i].kind === 238 /* JsxAttribute */) { checkJsxAttribute((node.attributes[i]), targetAttributesType, nameTable); } else { - ts.Debug.assert(node.attributes[i].kind === 237 /* JsxSpreadAttribute */); + ts.Debug.assert(node.attributes[i].kind === 239 /* JsxSpreadAttribute */); var spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable); if (isTypeAny(spreadType)) { sawSpreadedAny = true; @@ -19957,7 +20495,7 @@ var ts; // If a symbol is a synthesized symbol with no value declaration, we assume it is a property. Example of this are the synthesized // '.prototype' property as well as synthesized tuple index properties. function getDeclarationKindFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.kind : 139 /* PropertyDeclaration */; + return s.valueDeclaration ? s.valueDeclaration.kind : 141 /* PropertyDeclaration */; } function getDeclarationFlagsFromSymbol(s) { return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 /* Prototype */ ? 16 /* Public */ | 128 /* Static */ : 0; @@ -19973,8 +20511,8 @@ var ts; function checkClassPropertyAccess(node, left, type, prop) { var flags = getDeclarationFlagsFromSymbol(prop); var declaringClass = getDeclaredTypeOfSymbol(prop.parent); - if (left.kind === 93 /* SuperKeyword */) { - var errorNode = node.kind === 164 /* PropertyAccessExpression */ ? + if (left.kind === 95 /* SuperKeyword */) { + var errorNode = node.kind === 166 /* PropertyAccessExpression */ ? node.name : node.right; // TS 1.0 spec (April 2014): 4.8.2 @@ -19984,7 +20522,7 @@ var ts; // - In a static member function or static member accessor // where this references the constructor function object of a derived class, // a super property access is permitted and must specify a public static member function of the base class. - if (getDeclarationKindFromSymbol(prop) !== 141 /* MethodDeclaration */) { + if (getDeclarationKindFromSymbol(prop) !== 143 /* MethodDeclaration */) { // `prop` refers to a *property* declared in the super class // rather than a *method*, so it does not satisfy the above criteria. error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); @@ -20017,7 +20555,7 @@ var ts; } // Property is known to be protected at this point // All protected properties of a supertype are accessible in a super access - if (left.kind === 93 /* SuperKeyword */) { + if (left.kind === 95 /* SuperKeyword */) { return true; } // A protected property is accessible in the declaring class and classes derived from it @@ -20030,6 +20568,10 @@ var ts; return true; } // An instance property must be accessed through an instance of the enclosing class + if (type.flags & 33554432 /* ThisType */) { + // get the original type -- represented as the type constraint of the 'this' type + type = getConstraintOfTypeParameter(type); + } // TODO: why is the first part of this check here? if (!(getTargetType(type).flags & (1024 /* Class */ | 2048 /* Interface */) && hasBaseType(type, enclosingClass))) { error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass)); @@ -20056,18 +20598,18 @@ var ts; var prop = getPropertyOfType(apparentType, right.text); if (!prop) { if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type.flags & 33554432 /* ThisType */ ? apparentType : type)); } return unknownType; } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32 /* Class */) { - checkClassPropertyAccess(node, left, type, prop); + checkClassPropertyAccess(node, left, apparentType, prop); } return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 164 /* PropertyAccessExpression */ + var left = node.kind === 166 /* PropertyAccessExpression */ ? node.expression : node.left; var type = checkExpression(left); @@ -20083,7 +20625,7 @@ var ts; // Grammar checking if (!node.argumentExpression) { var sourceFile = getSourceFile(node); - if (node.parent.kind === 167 /* NewExpression */ && node.parent.expression === node) { + if (node.parent.kind === 169 /* NewExpression */ && node.parent.expression === node) { var start = ts.skipTrivia(sourceFile.text, node.expression.end); var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); @@ -20155,6 +20697,7 @@ var ts; } /** * If indexArgumentExpression is a string literal or number literal, returns its text. + * If indexArgumentExpression is a constant value, returns its string value. * If indexArgumentExpression is a well known symbol, returns the property name corresponding * to this symbol, as long as it is a proper symbol reference. * Otherwise, returns undefined. @@ -20163,6 +20706,12 @@ var ts; if (indexArgumentExpression.kind === 9 /* StringLiteral */ || indexArgumentExpression.kind === 8 /* NumericLiteral */) { return indexArgumentExpression.text; } + if (indexArgumentExpression.kind === 167 /* ElementAccessExpression */ || indexArgumentExpression.kind === 166 /* PropertyAccessExpression */) { + var value = getConstantValue(indexArgumentExpression); + if (value !== undefined) { + return value.toString(); + } + } if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, /*reportError*/ false)) { var rightHandSideName = indexArgumentExpression.name.text; return ts.getPropertyNameForKnownSymbolName(rightHandSideName); @@ -20212,10 +20761,10 @@ var ts; return true; } function resolveUntypedCall(node) { - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { checkExpression(node.template); } - else if (node.kind !== 137 /* Decorator */) { + else if (node.kind !== 139 /* Decorator */) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -20281,7 +20830,7 @@ var ts; function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg && arg.kind === 183 /* SpreadElementExpression */) { + if (arg && arg.kind === 185 /* SpreadElementExpression */) { return i; } } @@ -20293,13 +20842,13 @@ var ts; var callIsIncomplete; // In incomplete call we want to be lenient when we have too few arguments var isDecorator; var spreadArgIndex = -1; - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { var tagExpression = node; // Even if the call is incomplete, we'll have a missing expression as our last argument, // so we can say the count is just the arg list length adjustedArgCount = args.length; typeArguments = undefined; - if (tagExpression.template.kind === 181 /* TemplateExpression */) { + if (tagExpression.template.kind === 183 /* TemplateExpression */) { // If a tagged template expression lacks a tail literal, the call is incomplete. // Specifically, a template only can end in a TemplateTail or a Missing literal. var templateExpression = tagExpression.template; @@ -20316,7 +20865,7 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } - else if (node.kind === 137 /* Decorator */) { + else if (node.kind === 139 /* Decorator */) { isDecorator = true; typeArguments = undefined; adjustedArgCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature); @@ -20325,7 +20874,7 @@ var ts; var callExpression = node; if (!callExpression.arguments) { // This only happens when we have something of the form: 'new C' - ts.Debug.assert(callExpression.kind === 167 /* NewExpression */); + ts.Debug.assert(callExpression.kind === 169 /* NewExpression */); return signature.minArgumentCount === 0; } // For IDE scenarios we may have an incomplete call, so a trailing comma is tantamount to adding another argument. @@ -20404,7 +20953,7 @@ var ts; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. - if (arg === undefined || arg.kind !== 185 /* OmittedExpression */) { + if (arg === undefined || arg.kind !== 187 /* OmittedExpression */) { var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); // If the effective argument type is 'undefined', there is no synthetic type @@ -20463,7 +21012,7 @@ var ts; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. - if (arg === undefined || arg.kind !== 185 /* OmittedExpression */) { + if (arg === undefined || arg.kind !== 187 /* OmittedExpression */) { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); @@ -20495,16 +21044,16 @@ var ts; */ function getEffectiveCallArguments(node) { var args; - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { var template = node.template; args = [undefined]; - if (template.kind === 181 /* TemplateExpression */) { + if (template.kind === 183 /* TemplateExpression */) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } - else if (node.kind === 137 /* Decorator */) { + else if (node.kind === 139 /* Decorator */) { // For a decorator, we return undefined as we will determine // the number and types of arguments for a decorator using // `getEffectiveArgumentCount` and `getEffectiveArgumentType` below. @@ -20529,25 +21078,29 @@ var ts; * Otherwise, the argument count is the length of the 'args' array. */ function getEffectiveArgumentCount(node, args, signature) { - if (node.kind === 137 /* Decorator */) { + if (node.kind === 139 /* Decorator */) { switch (node.parent.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // A class decorator will have one argument (see `ClassDecorator` in core.d.ts) return 1; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: // A property declaration decorator will have two arguments (see // `PropertyDecorator` in core.d.ts) return 2; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // A method or accessor declaration decorator will have two or three arguments (see // `PropertyDecorator` and `MethodDecorator` in core.d.ts) + // If we are emitting decorators for ES3, we will only pass two arguments. + if (languageVersion === 0 /* ES3 */) { + return 2; + } // If the method decorator signature only accepts a target and a key, we will only // type check those arguments. return signature.parameters.length >= 3 ? 3 : 2; - case 136 /* Parameter */: + case 138 /* Parameter */: // A parameter declaration decorator will have three arguments (see // `ParameterDecorator` in core.d.ts) return 3; @@ -20572,25 +21125,25 @@ var ts; function getEffectiveDecoratorFirstArgumentType(node) { // The first argument to a decorator is its `target`. switch (node.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // For a class decorator, the `target` is the type of the class (e.g. the // "static" or "constructor" side of the class) var classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); - case 136 /* Parameter */: + case 138 /* Parameter */: // For a parameter decorator, the `target` is the parent type of the // parameter's containing method. node = node.parent; - if (node.kind === 142 /* Constructor */) { + if (node.kind === 144 /* Constructor */) { var classSymbol_1 = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol_1); } // fall-through - case 139 /* PropertyDeclaration */: - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // For a property or method decorator, the `target` is the // "static"-side type of the parent of the member if the member is // declared "static"; otherwise, it is the "instance"-side type of the @@ -20619,33 +21172,33 @@ var ts; function getEffectiveDecoratorSecondArgumentType(node) { // The second argument to a decorator is its `propertyKey` switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: ts.Debug.fail("Class decorators should not have a second synthetic argument."); return unknownType; - case 136 /* Parameter */: + case 138 /* Parameter */: node = node.parent; - if (node.kind === 142 /* Constructor */) { + if (node.kind === 144 /* Constructor */) { // For a constructor parameter decorator, the `propertyKey` will be `undefined`. return anyType; } // For a non-constructor parameter decorator, the `propertyKey` will be either // a string or a symbol, based on the name of the parameter's containing method. // fall-through - case 139 /* PropertyDeclaration */: - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // The `propertyKey` for a property or method decorator will be a // string literal type if the member name is an identifier, number, or string; // otherwise, if the member name is a computed property name it will // be either string or symbol. var element = node; switch (element.name.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: case 8 /* NumericLiteral */: case 9 /* StringLiteral */: return getStringLiteralType(element.name); - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: var nameType = checkComputedPropertyName(element.name); if (allConstituentTypesHaveKind(nameType, 16777216 /* ESSymbol */)) { return nameType; @@ -20673,18 +21226,18 @@ var ts; // The third argument to a decorator is either its `descriptor` for a method decorator // or its `parameterIndex` for a paramter decorator switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: ts.Debug.fail("Class decorators should not have a third synthetic argument."); return unknownType; - case 136 /* Parameter */: + case 138 /* Parameter */: // The `parameterIndex` for a parameter decorator is always a number return numberType; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: ts.Debug.fail("Property decorators should not have a third synthetic argument."); return unknownType; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor` // for the type of the member. var propertyType = getTypeOfNode(node); @@ -20717,10 +21270,10 @@ var ts; // Decorators provide special arguments, a tagged template expression provides // a special first argument, and string literals get string literal types // unless we're reporting errors - if (node.kind === 137 /* Decorator */) { + if (node.kind === 139 /* Decorator */) { return getEffectiveDecoratorArgumentType(node, argIndex); } - else if (argIndex === 0 && node.kind === 168 /* TaggedTemplateExpression */) { + else if (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */) { return globalTemplateStringsArrayType; } // This is not a synthetic argument, so we return 'undefined' @@ -20732,8 +21285,8 @@ var ts; */ function getEffectiveArgument(node, args, argIndex) { // For a decorator or the first argument of a tagged template expression we return undefined. - if (node.kind === 137 /* Decorator */ || - (argIndex === 0 && node.kind === 168 /* TaggedTemplateExpression */)) { + if (node.kind === 139 /* Decorator */ || + (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */)) { return undefined; } return args[argIndex]; @@ -20742,11 +21295,11 @@ var ts; * Gets the error node to use when reporting errors for an effective argument. */ function getEffectiveArgumentErrorNode(node, argIndex, arg) { - if (node.kind === 137 /* Decorator */) { + if (node.kind === 139 /* Decorator */) { // For a decorator, we use the expression of the decorator for error reporting. return node.expression; } - else if (argIndex === 0 && node.kind === 168 /* TaggedTemplateExpression */) { + else if (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */) { // For a the first argument of a tagged template expression, we use the template of the tag for error reporting. return node.template; } @@ -20755,13 +21308,13 @@ var ts; } } function resolveCall(node, signatures, candidatesOutArray, headMessage) { - var isTaggedTemplate = node.kind === 168 /* TaggedTemplateExpression */; - var isDecorator = node.kind === 137 /* Decorator */; + var isTaggedTemplate = node.kind === 170 /* TaggedTemplateExpression */; + var isDecorator = node.kind === 139 /* Decorator */; var typeArguments; if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; // We already perform checking on the type arguments on the class declaration itself. - if (node.expression.kind !== 93 /* SuperKeyword */) { + if (node.expression.kind !== 95 /* SuperKeyword */) { ts.forEach(typeArguments, checkSourceElement); } } @@ -20968,7 +21521,7 @@ var ts; } } function resolveCallExpression(node, candidatesOutArray) { - if (node.expression.kind === 93 /* SuperKeyword */) { + if (node.expression.kind === 95 /* SuperKeyword */) { var superType = checkSuperExpression(node.expression); if (superType !== unknownType) { // In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated @@ -21101,16 +21654,16 @@ var ts; */ function getDiagnosticHeadMessageForDecoratorResolution(node) { switch (node.parent.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; - case 136 /* Parameter */: + case 138 /* Parameter */: return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; } } @@ -21147,16 +21700,16 @@ var ts; // to correctly fill the candidatesOutArray. if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - if (node.kind === 166 /* CallExpression */) { + if (node.kind === 168 /* CallExpression */) { links.resolvedSignature = resolveCallExpression(node, candidatesOutArray); } - else if (node.kind === 167 /* NewExpression */) { + else if (node.kind === 169 /* NewExpression */) { links.resolvedSignature = resolveNewExpression(node, candidatesOutArray); } - else if (node.kind === 168 /* TaggedTemplateExpression */) { + else if (node.kind === 170 /* TaggedTemplateExpression */) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } - else if (node.kind === 137 /* Decorator */) { + else if (node.kind === 139 /* Decorator */) { links.resolvedSignature = resolveDecorator(node, candidatesOutArray); } else { @@ -21174,15 +21727,15 @@ var ts; // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); var signature = getResolvedSignature(node); - if (node.expression.kind === 93 /* SuperKeyword */) { + if (node.expression.kind === 95 /* SuperKeyword */) { return voidType; } - if (node.kind === 167 /* NewExpression */) { + if (node.kind === 169 /* NewExpression */) { var declaration = signature.declaration; if (declaration && - declaration.kind !== 142 /* Constructor */ && - declaration.kind !== 146 /* ConstructSignature */ && - declaration.kind !== 151 /* ConstructorType */) { + declaration.kind !== 144 /* Constructor */ && + declaration.kind !== 148 /* ConstructSignature */ && + declaration.kind !== 153 /* ConstructorType */) { // When resolved signature is a call signature (and not a construct signature) the result type is any if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); @@ -21224,10 +21777,24 @@ var ts; assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } } + // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push + // the destructured type into the contained binding elements. + function assignBindingElementTypes(node) { + if (ts.isBindingPattern(node.name)) { + for (var _i = 0, _a = node.name.elements; _i < _a.length; _i++) { + var element = _a[_i]; + if (element.kind !== 187 /* OmittedExpression */) { + getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element); + assignBindingElementTypes(element); + } + } + } + } function assignTypeToParameterAndFixTypeParameters(parameter, contextualType, mapper) { var links = getSymbolLinks(parameter); if (!links.type) { links.type = instantiateType(contextualType, mapper); + assignBindingElementTypes(parameter.valueDeclaration); } else if (isInferentialContext(mapper)) { // Even if the parameter already has a type, it might be because it was given a type while @@ -21279,7 +21846,7 @@ var ts; } var isAsync = ts.isAsyncFunctionLike(func); var type; - if (func.body.kind !== 190 /* Block */) { + if (func.body.kind !== 192 /* Block */) { type = checkExpressionCached(func.body, contextualMapper); if (isAsync) { // From within an async function you can return either a non-promise value or a promise. Any @@ -21398,7 +21965,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 206 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 208 /* ThrowStatement */); } // TypeScript Specification 1.0 (6.3) - July 2014 // An explicitly typed function whose return type isn't the Void or the Any type @@ -21413,7 +21980,7 @@ var ts; return; } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. - if (ts.nodeIsMissing(func.body) || func.body.kind !== 190 /* Block */) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 192 /* Block */) { return; } var bodyBlock = func.body; @@ -21431,10 +21998,10 @@ var ts; error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); // Grammar checking var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); - if (!hasGrammarError && node.kind === 171 /* FunctionExpression */) { + if (!hasGrammarError && node.kind === 173 /* FunctionExpression */) { checkGrammarForGenerator(node); } // The identityMapper object is used to indicate that function expressions are wildcards @@ -21477,14 +22044,14 @@ var ts; } } } - if (produceDiagnostics && node.kind !== 141 /* MethodDeclaration */ && node.kind !== 140 /* MethodSignature */) { + if (produceDiagnostics && node.kind !== 143 /* MethodDeclaration */ && node.kind !== 142 /* MethodSignature */) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); } return type; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; @@ -21506,7 +22073,7 @@ var ts; // checkFunctionExpressionBodies). So it must be done now. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - if (node.body.kind === 190 /* Block */) { + if (node.body.kind === 192 /* Block */) { checkSourceElement(node.body); } else { @@ -21552,24 +22119,24 @@ var ts; // and property accesses(section 4.10). // All other expression constructs described in this chapter are classified as values. switch (n.kind) { - case 67 /* Identifier */: { + case 69 /* Identifier */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.3 // An identifier expression that references a variable or parameter is classified as a reference. // An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment). return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3 /* Variable */) !== 0; } - case 164 /* PropertyAccessExpression */: { + case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.10 // A property access expression is always classified as a reference. // NOTE (not in spec): assignment to enum members should not be allowed return !symbol || symbol === unknownSymbol || (symbol.flags & ~8 /* EnumMember */) !== 0; } - case 165 /* ElementAccessExpression */: - // old compiler doesn't check indexed assess + case 167 /* ElementAccessExpression */: + // old compiler doesn't check indexed access return true; - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -21577,12 +22144,12 @@ var ts; } function isConstVariableReference(n) { switch (n.kind) { - case 67 /* Identifier */: - case 164 /* PropertyAccessExpression */: { + case 69 /* Identifier */: + case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); return symbol && (symbol.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 32768 /* Const */) !== 0; } - case 165 /* ElementAccessExpression */: { + case 167 /* ElementAccessExpression */: { var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 9 /* StringLiteral */) { @@ -21592,7 +22159,7 @@ var ts; } return false; } - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return isConstVariableReference(n.expression); default: return false; @@ -21638,15 +22205,15 @@ var ts; switch (node.operator) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: + case 50 /* TildeToken */: if (someConstituentTypeHasKind(operandType, 16777216 /* ESSymbol */)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; - case 48 /* ExclamationToken */: + case 49 /* ExclamationToken */: return booleanType; - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 41 /* PlusPlusToken */: + case 42 /* MinusMinusToken */: var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors @@ -21706,31 +22273,31 @@ var ts; function isConstEnumSymbol(symbol) { return (symbol.flags & 128 /* ConstEnum */) !== 0; } - function checkInstanceOfExpression(node, leftType, rightType) { + function checkInstanceOfExpression(left, right, leftType, rightType) { // TypeScript 1.0 spec (April 2014): 4.15.4 // The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type, // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported if (allConstituentTypesHaveKind(leftType, 16777726 /* Primitive */)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); + error(right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } - function checkInExpression(node, leftType, rightType) { + function checkInExpression(left, right, leftType, rightType) { // TypeScript 1.0 spec (April 2014): 4.15.5 // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */ | 132 /* NumberLike */ | 16777216 /* ESSymbol */)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); + error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 /* ObjectType */ | 512 /* TypeParameter */)) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; } @@ -21738,7 +22305,7 @@ var ts; var properties = node.properties; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; - if (p.kind === 243 /* PropertyAssignment */ || p.kind === 244 /* ShorthandPropertyAssignment */) { + if (p.kind === 245 /* PropertyAssignment */ || p.kind === 246 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support var name_13 = p.name; var type = isTypeAny(sourceType) @@ -21747,7 +22314,12 @@ var ts; isNumericLiteralName(name_13.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_13, type); + if (p.kind === 246 /* ShorthandPropertyAssignment */) { + checkDestructuringAssignment(p, type); + } + else { + checkDestructuringAssignment(p.initializer || name_13, type); + } } else { error(name_13, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_13)); @@ -21767,8 +22339,8 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 185 /* OmittedExpression */) { - if (e.kind !== 183 /* SpreadElementExpression */) { + if (e.kind !== 187 /* OmittedExpression */) { + if (e.kind !== 185 /* SpreadElementExpression */) { var propName = "" + i; var type = isTypeAny(sourceType) ? sourceType @@ -21793,7 +22365,7 @@ var ts; } else { var restExpression = e.expression; - if (restExpression.kind === 179 /* BinaryExpression */ && restExpression.operatorToken.kind === 55 /* EqualsToken */) { + if (restExpression.kind === 181 /* BinaryExpression */ && restExpression.operatorToken.kind === 56 /* EqualsToken */) { error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer); } else { @@ -21805,15 +22377,26 @@ var ts; } return sourceType; } - function checkDestructuringAssignment(target, sourceType, contextualMapper) { - if (target.kind === 179 /* BinaryExpression */ && target.operatorToken.kind === 55 /* EqualsToken */) { + function checkDestructuringAssignment(exprOrAssignment, sourceType, contextualMapper) { + var target; + if (exprOrAssignment.kind === 246 /* ShorthandPropertyAssignment */) { + var prop = exprOrAssignment; + if (prop.objectAssignmentInitializer) { + checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper); + } + target = exprOrAssignment.name; + } + else { + target = exprOrAssignment; + } + if (target.kind === 181 /* BinaryExpression */ && target.operatorToken.kind === 56 /* EqualsToken */) { checkBinaryExpression(target, contextualMapper); target = target.left; } - if (target.kind === 163 /* ObjectLiteralExpression */) { + if (target.kind === 165 /* ObjectLiteralExpression */) { return checkObjectLiteralAssignment(target, sourceType, contextualMapper); } - if (target.kind === 162 /* ArrayLiteralExpression */) { + if (target.kind === 164 /* ArrayLiteralExpression */) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } return checkReferenceAssignment(target, sourceType, contextualMapper); @@ -21826,34 +22409,39 @@ var ts; return sourceType; } function checkBinaryExpression(node, contextualMapper) { - var operator = node.operatorToken.kind; - if (operator === 55 /* EqualsToken */ && (node.left.kind === 163 /* ObjectLiteralExpression */ || node.left.kind === 162 /* ArrayLiteralExpression */)) { - return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); + return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node); + } + function checkBinaryLikeExpression(left, operatorToken, right, contextualMapper, errorNode) { + var operator = operatorToken.kind; + if (operator === 56 /* EqualsToken */ && (left.kind === 165 /* ObjectLiteralExpression */ || left.kind === 164 /* ArrayLiteralExpression */)) { + return checkDestructuringAssignment(left, checkExpression(right, contextualMapper), contextualMapper); } - var leftType = checkExpression(node.left, contextualMapper); - var rightType = checkExpression(node.right, contextualMapper); + var leftType = checkExpression(left, contextualMapper); + var rightType = checkExpression(right, contextualMapper); switch (operator) { case 37 /* AsteriskToken */: - case 58 /* AsteriskEqualsToken */: - case 38 /* SlashToken */: - case 59 /* SlashEqualsToken */: - case 39 /* PercentToken */: - case 60 /* PercentEqualsToken */: + case 38 /* AsteriskAsteriskToken */: + case 59 /* AsteriskEqualsToken */: + case 60 /* AsteriskAsteriskEqualsToken */: + case 39 /* SlashToken */: + case 61 /* SlashEqualsToken */: + case 40 /* PercentToken */: + case 62 /* PercentEqualsToken */: case 36 /* MinusToken */: - case 57 /* MinusEqualsToken */: - case 42 /* LessThanLessThanToken */: - case 61 /* LessThanLessThanEqualsToken */: - case 43 /* GreaterThanGreaterThanToken */: - case 62 /* GreaterThanGreaterThanEqualsToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: - case 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */: - case 46 /* BarToken */: - case 65 /* BarEqualsToken */: - case 47 /* CaretToken */: - case 66 /* CaretEqualsToken */: - case 45 /* AmpersandToken */: - case 64 /* AmpersandEqualsToken */: - // TypeScript 1.0 spec (April 2014): 4.15.1 + case 58 /* MinusEqualsToken */: + case 43 /* LessThanLessThanToken */: + case 63 /* LessThanLessThanEqualsToken */: + case 44 /* GreaterThanGreaterThanToken */: + case 64 /* GreaterThanGreaterThanEqualsToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: + case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */: + case 47 /* BarToken */: + case 67 /* BarEqualsToken */: + case 48 /* CaretToken */: + case 68 /* CaretEqualsToken */: + case 46 /* AmpersandToken */: + case 66 /* AmpersandEqualsToken */: + // TypeScript 1.0 spec (April 2014): 4.19.1 // These operators require their operands to be of type Any, the Number primitive type, // or an enum type. Operands of an enum type are treated // as having the primitive type Number. If one operand is the null or undefined value, @@ -21868,21 +22456,21 @@ var ts; // try and return them a helpful suggestion if ((leftType.flags & 8 /* Boolean */) && (rightType.flags & 8 /* Boolean */) && - (suggestedOperator = getSuggestedBooleanOperator(node.operatorToken.kind)) !== undefined) { - error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operatorToken.kind), ts.tokenToString(suggestedOperator)); + (suggestedOperator = getSuggestedBooleanOperator(operatorToken.kind)) !== undefined) { + error(errorNode || operatorToken, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(operatorToken.kind), ts.tokenToString(suggestedOperator)); } else { // otherwise just check each operand separately and report errors as normal - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var leftOk = checkArithmeticOperandType(left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); if (leftOk && rightOk) { checkAssignmentOperator(numberType); } } return numberType; case 35 /* PlusToken */: - case 56 /* PlusEqualsToken */: - // TypeScript 1.0 spec (April 2014): 4.15.2 + case 57 /* PlusEqualsToken */: + // TypeScript 1.0 spec (April 2014): 4.19.2 // The binary + operator requires both operands to be of the Number primitive type or an enum type, // or at least one of the operands to be of type Any or the String primitive type. // If one operand is the null or undefined value, it is treated as having the type of the other operand. @@ -21915,7 +22503,7 @@ var ts; reportOperatorError(); return anyType; } - if (operator === 56 /* PlusEqualsToken */) { + if (operator === 57 /* PlusEqualsToken */) { checkAssignmentOperator(resultType); } return resultType; @@ -21935,15 +22523,15 @@ var ts; reportOperatorError(); } return booleanType; - case 89 /* InstanceOfKeyword */: - return checkInstanceOfExpression(node, leftType, rightType); - case 88 /* InKeyword */: - return checkInExpression(node, leftType, rightType); - case 50 /* AmpersandAmpersandToken */: + case 91 /* InstanceOfKeyword */: + return checkInstanceOfExpression(left, right, leftType, rightType); + case 90 /* InKeyword */: + return checkInExpression(left, right, leftType, rightType); + case 51 /* AmpersandAmpersandToken */: return rightType; - case 51 /* BarBarToken */: + case 52 /* BarBarToken */: return getUnionType([leftType, rightType]); - case 55 /* EqualsToken */: + case 56 /* EqualsToken */: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); case 24 /* CommaToken */: @@ -21951,8 +22539,8 @@ var ts; } // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216 /* ESSymbol */) ? node.left : - someConstituentTypeHasKind(rightType, 16777216 /* ESSymbol */) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216 /* ESSymbol */) ? left : + someConstituentTypeHasKind(rightType, 16777216 /* ESSymbol */) ? right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -21962,37 +22550,37 @@ var ts; } function getSuggestedBooleanOperator(operator) { switch (operator) { - case 46 /* BarToken */: - case 65 /* BarEqualsToken */: - return 51 /* BarBarToken */; - case 47 /* CaretToken */: - case 66 /* CaretEqualsToken */: + case 47 /* BarToken */: + case 67 /* BarEqualsToken */: + return 52 /* BarBarToken */; + case 48 /* CaretToken */: + case 68 /* CaretEqualsToken */: return 33 /* ExclamationEqualsEqualsToken */; - case 45 /* AmpersandToken */: - case 64 /* AmpersandEqualsToken */: - return 50 /* AmpersandAmpersandToken */; + case 46 /* AmpersandToken */: + case 66 /* AmpersandEqualsToken */: + return 51 /* AmpersandAmpersandToken */; default: return undefined; } } function checkAssignmentOperator(valueType) { - if (produceDiagnostics && operator >= 55 /* FirstAssignment */ && operator <= 66 /* LastAssignment */) { + if (produceDiagnostics && operator >= 56 /* FirstAssignment */ && operator <= 68 /* LastAssignment */) { // TypeScript 1.0 spec (April 2014): 4.17 // An assignment of the form // VarExpr = ValueExpr // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + var ok = checkReferenceExpression(left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported - checkTypeAssignableTo(valueType, leftType, node.left, /*headMessage*/ undefined); + checkTypeAssignableTo(valueType, leftType, left, /*headMessage*/ undefined); } } } function reportOperatorError() { - error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); + error(errorNode || operatorToken, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } function isYieldExpressionInClass(node) { @@ -22083,7 +22671,7 @@ var ts; // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); } return checkExpression(node.initializer, contextualMapper); @@ -22094,7 +22682,7 @@ var ts; // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); } var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); @@ -22124,7 +22712,7 @@ var ts; // contextually typed function and arrow expressions in the initial phase. function checkExpression(node, contextualMapper) { var type; - if (node.kind === 133 /* QualifiedName */) { + if (node.kind === 135 /* QualifiedName */) { type = checkQualifiedName(node); } else { @@ -22136,9 +22724,9 @@ var ts; // - 'left' in property access // - 'object' in indexed access // - target in rhs of import statement - var ok = (node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.expression === node) || - (node.parent.kind === 165 /* ElementAccessExpression */ && node.parent.expression === node) || - ((node.kind === 67 /* Identifier */ || node.kind === 133 /* QualifiedName */) && isInRightSideOfImportOrExportAssignment(node)); + var ok = (node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.expression === node) || + (node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.expression === node) || + ((node.kind === 69 /* Identifier */ || node.kind === 135 /* QualifiedName */) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } @@ -22152,78 +22740,78 @@ var ts; } function checkExpressionWorker(node, contextualMapper) { switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: return checkIdentifier(node); - case 95 /* ThisKeyword */: + case 97 /* ThisKeyword */: return checkThisExpression(node); - case 93 /* SuperKeyword */: + case 95 /* SuperKeyword */: return checkSuperExpression(node); - case 91 /* NullKeyword */: + case 93 /* NullKeyword */: return nullType; - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: return booleanType; case 8 /* NumericLiteral */: return checkNumericLiteral(node); - case 181 /* TemplateExpression */: + case 183 /* TemplateExpression */: return checkTemplateExpression(node); case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: return stringType; case 10 /* RegularExpressionLiteral */: return globalRegExpType; - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return checkArrayLiteral(node, contextualMapper); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return checkObjectLiteral(node, contextualMapper); - case 164 /* PropertyAccessExpression */: + case 166 /* PropertyAccessExpression */: return checkPropertyAccessExpression(node); - case 165 /* ElementAccessExpression */: + case 167 /* ElementAccessExpression */: return checkIndexedAccess(node); - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return checkCallExpression(node); - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: return checkTaggedTemplateExpression(node); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return checkExpression(node.expression, contextualMapper); - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: return checkClassExpression(node); - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); - case 174 /* TypeOfExpression */: + case 176 /* TypeOfExpression */: return checkTypeOfExpression(node); - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: return checkAssertion(node); - case 173 /* DeleteExpression */: + case 175 /* DeleteExpression */: return checkDeleteExpression(node); - case 175 /* VoidExpression */: + case 177 /* VoidExpression */: return checkVoidExpression(node); - case 176 /* AwaitExpression */: + case 178 /* AwaitExpression */: return checkAwaitExpression(node); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return checkPrefixUnaryExpression(node); - case 178 /* PostfixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: return checkPostfixUnaryExpression(node); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return checkBinaryExpression(node, contextualMapper); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); - case 183 /* SpreadElementExpression */: + case 185 /* SpreadElementExpression */: return checkSpreadElementExpression(node, contextualMapper); - case 185 /* OmittedExpression */: + case 187 /* OmittedExpression */: return undefinedType; - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: return checkYieldExpression(node); - case 238 /* JsxExpression */: + case 240 /* JsxExpression */: return checkJsxExpression(node); - case 231 /* JsxElement */: + case 233 /* JsxElement */: return checkJsxElement(node); - case 232 /* JsxSelfClosingElement */: + case 234 /* JsxSelfClosingElement */: return checkJsxSelfClosingElement(node); - case 233 /* JsxOpeningElement */: + case 235 /* JsxOpeningElement */: ts.Debug.fail("Shouldn't ever directly check a JsxOpeningElement"); } return unknownType; @@ -22252,7 +22840,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & 112 /* AccessibilityModifier */) { func = ts.getContainingFunction(node); - if (!(func.kind === 142 /* Constructor */ && ts.nodeIsPresent(func.body))) { + if (!(func.kind === 144 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -22269,15 +22857,15 @@ var ts; if (!node.asteriskToken || !node.body) { return false; } - return node.kind === 141 /* MethodDeclaration */ || - node.kind === 211 /* FunctionDeclaration */ || - node.kind === 171 /* FunctionExpression */; + return node.kind === 143 /* MethodDeclaration */ || + node.kind === 213 /* FunctionDeclaration */ || + node.kind === 173 /* FunctionExpression */; } function getTypePredicateParameterIndex(parameterList, parameter) { if (parameterList) { for (var i = 0; i < parameterList.length; i++) { var param = parameterList[i]; - if (param.name.kind === 67 /* Identifier */ && + if (param.name.kind === 69 /* Identifier */ && param.name.text === parameter.text) { return i; } @@ -22287,31 +22875,31 @@ var ts; } function isInLegalTypePredicatePosition(node) { switch (node.parent.kind) { - case 172 /* ArrowFunction */: - case 145 /* CallSignature */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 150 /* FunctionType */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 174 /* ArrowFunction */: + case 147 /* CallSignature */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 152 /* FunctionType */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return node === node.parent.type; } return false; } function checkSignatureDeclaration(node) { // Grammar checking - if (node.kind === 147 /* IndexSignature */) { + if (node.kind === 149 /* IndexSignature */) { checkGrammarIndexSignature(node); } - else if (node.kind === 150 /* FunctionType */ || node.kind === 211 /* FunctionDeclaration */ || node.kind === 151 /* ConstructorType */ || - node.kind === 145 /* CallSignature */ || node.kind === 142 /* Constructor */ || - node.kind === 146 /* ConstructSignature */) { + else if (node.kind === 152 /* FunctionType */ || node.kind === 213 /* FunctionDeclaration */ || node.kind === 153 /* ConstructorType */ || + node.kind === 147 /* CallSignature */ || node.kind === 144 /* Constructor */ || + node.kind === 148 /* ConstructSignature */) { checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { - if (node.type.kind === 148 /* TypePredicate */) { + if (node.type.kind === 150 /* TypePredicate */) { var typePredicate = getSignatureFromDeclaration(node).typePredicate; var typePredicateNode = node.type; if (isInLegalTypePredicatePosition(typePredicateNode)) { @@ -22330,19 +22918,19 @@ var ts; if (hasReportedError) { break; } - if (param.name.kind === 159 /* ObjectBindingPattern */ || - param.name.kind === 160 /* ArrayBindingPattern */) { + if (param.name.kind === 161 /* ObjectBindingPattern */ || + param.name.kind === 162 /* ArrayBindingPattern */) { (function checkBindingPattern(pattern) { for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.name.kind === 67 /* Identifier */ && + if (element.name.kind === 69 /* Identifier */ && element.name.text === typePredicate.parameterName) { error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName); hasReportedError = true; break; } - else if (element.name.kind === 160 /* ArrayBindingPattern */ || - element.name.kind === 159 /* ObjectBindingPattern */) { + else if (element.name.kind === 162 /* ArrayBindingPattern */ || + element.name.kind === 161 /* ObjectBindingPattern */) { checkBindingPattern(element.name); } } @@ -22366,10 +22954,10 @@ var ts; checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; - case 145 /* CallSignature */: + case 147 /* CallSignature */: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } @@ -22397,7 +22985,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 213 /* InterfaceDeclaration */) { + if (node.kind === 215 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); // in case of merging interface declaration it is possible that we'll enter this check procedure several times for every declaration // to prevent this run check only for the first declaration of a given kind @@ -22417,7 +23005,7 @@ var ts; var declaration = decl; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 128 /* StringKeyword */: + case 130 /* StringKeyword */: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -22425,7 +23013,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 126 /* NumberKeyword */: + case 128 /* NumberKeyword */: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -22474,7 +23062,7 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 166 /* CallExpression */ && n.expression.kind === 93 /* SuperKeyword */; + return n.kind === 168 /* CallExpression */ && n.expression.kind === 95 /* SuperKeyword */; } function containsSuperCallAsComputedPropertyName(n) { return n.name && containsSuperCall(n.name); @@ -22492,15 +23080,15 @@ var ts; return ts.forEachChild(n, containsSuperCall); } function markThisReferencesAsErrors(n) { - if (n.kind === 95 /* ThisKeyword */) { + if (n.kind === 97 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 171 /* FunctionExpression */ && n.kind !== 211 /* FunctionDeclaration */) { + else if (n.kind !== 173 /* FunctionExpression */ && n.kind !== 213 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } } function isInstancePropertyWithInitializer(n) { - return n.kind === 139 /* PropertyDeclaration */ && + return n.kind === 141 /* PropertyDeclaration */ && !(n.flags & 128 /* Static */) && !!n.initializer; } @@ -22530,7 +23118,7 @@ var ts; var superCallStatement; for (var _i = 0; _i < statements.length; _i++) { var statement = statements[_i]; - if (statement.kind === 193 /* ExpressionStatement */ && isSuperCallExpression(statement.expression)) { + if (statement.kind === 195 /* ExpressionStatement */ && isSuperCallExpression(statement.expression)) { superCallStatement = statement; break; } @@ -22556,7 +23144,7 @@ var ts; if (produceDiagnostics) { // Grammar checking accessors checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (node.kind === 143 /* GetAccessor */) { + if (node.kind === 145 /* GetAccessor */) { if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } @@ -22564,7 +23152,7 @@ var ts; if (!ts.hasDynamicName(node)) { // TypeScript 1.0 spec (April 2014): 8.4.3 // Accessors for the same member name must specify the same accessibility. - var otherKind = node.kind === 143 /* GetAccessor */ ? 144 /* SetAccessor */ : 143 /* GetAccessor */; + var otherKind = node.kind === 145 /* GetAccessor */ ? 146 /* SetAccessor */ : 145 /* GetAccessor */; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { if (((node.flags & 112 /* AccessibilityModifier */) !== (otherAccessor.flags & 112 /* AccessibilityModifier */))) { @@ -22660,9 +23248,9 @@ var ts; var signaturesToCheck; // Unnamed (call\construct) signatures in interfaces are inherited and not shadowed so examining just node symbol won't give complete answer. // Use declaring type to obtain full list of signatures. - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 213 /* InterfaceDeclaration */) { - ts.Debug.assert(signatureDeclarationNode.kind === 145 /* CallSignature */ || signatureDeclarationNode.kind === 146 /* ConstructSignature */); - var signatureKind = signatureDeclarationNode.kind === 145 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 215 /* InterfaceDeclaration */) { + ts.Debug.assert(signatureDeclarationNode.kind === 147 /* CallSignature */ || signatureDeclarationNode.kind === 148 /* ConstructSignature */); + var signatureKind = signatureDeclarationNode.kind === 147 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); var containingType = getDeclaredTypeOfSymbol(containingSymbol); signaturesToCheck = getSignaturesOfType(containingType, signatureKind); @@ -22680,7 +23268,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = ts.getCombinedNodeFlags(n); - if (n.parent.kind !== 213 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 215 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { // It is nested in an ambient context, which means it is automatically exported flags |= 1 /* Export */; @@ -22766,7 +23354,7 @@ var ts; // TODO(jfreeman): These are methods, so handle computed name case if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) { // the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members - ts.Debug.assert(node.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */); + ts.Debug.assert(node.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */); ts.Debug.assert((node.flags & 128 /* Static */) !== (subsequentNode.flags & 128 /* Static */)); var diagnostic = node.flags & 128 /* Static */ ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static; error(errorNode_1, diagnostic); @@ -22802,7 +23390,7 @@ var ts; var current = declarations[_i]; var node = current; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 213 /* InterfaceDeclaration */ || node.parent.kind === 153 /* TypeLiteral */ || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 215 /* InterfaceDeclaration */ || node.parent.kind === 155 /* TypeLiteral */ || inAmbientContext; if (inAmbientContextOrInterface) { // check if declarations are consecutive only if they are non-ambient // 1. ambient declarations can be interleaved @@ -22813,7 +23401,7 @@ var ts; // 2. mixing ambient and non-ambient declarations is a separate error that will be reported - do not want to report an extra one previousDeclaration = undefined; } - if (node.kind === 211 /* FunctionDeclaration */ || node.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */ || node.kind === 142 /* Constructor */) { + if (node.kind === 213 /* FunctionDeclaration */ || node.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */ || node.kind === 144 /* Constructor */) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -22953,16 +23541,16 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return 2097152 /* ExportType */; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return d.name.kind === 9 /* StringLiteral */ || ts.getModuleInstanceState(d) !== 0 /* NonInstantiated */ ? 4194304 /* ExportNamespace */ | 1048576 /* ExportValue */ : 4194304 /* ExportNamespace */; - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: return 2097152 /* ExportType */ | 1048576 /* ExportValue */; - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: var result = 0; var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); @@ -22973,7 +23561,8 @@ var ts; } } function checkNonThenableType(type, location, message) { - if (!(type.flags & 1 /* Any */) && isTypeAssignableTo(type, getGlobalThenableType())) { + type = getWidenedType(type); + if (!isTypeAny(type) && isTypeAssignableTo(type, getGlobalThenableType())) { if (location) { if (!message) { message = ts.Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member; @@ -23206,22 +23795,22 @@ var ts; var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); var errorInfo; switch (node.parent.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); expectedReturnType = getUnionType([classConstructorType, voidType]); break; - case 136 /* Parameter */: + case 138 /* Parameter */: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: var methodType = getTypeOfNode(node.parent); var descriptorType = createTypedPropertyDescriptorType(methodType); expectedReturnType = getUnionType([descriptorType, voidType]); @@ -23234,9 +23823,9 @@ var ts; // When we are emitting type metadata for decorators, we need to try to check the type // as if it were an expression so that we can emit the type in a value position when we // serialize the type metadata. - if (node && node.kind === 149 /* TypeReference */) { + if (node && node.kind === 151 /* TypeReference */) { var root = getFirstIdentifier(node.typeName); - var meaning = root.parent.kind === 149 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; + var meaning = root.parent.kind === 151 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; // Resolve type so we know which symbol is referenced var rootSymbol = resolveName(root, root.text, meaning | 8388608 /* Alias */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); // Resolved symbol is alias @@ -23255,19 +23844,19 @@ var ts; */ function checkTypeAnnotationAsExpression(node) { switch (node.kind) { - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: checkTypeNodeAsExpression(node.type); break; - case 136 /* Parameter */: + case 138 /* Parameter */: checkTypeNodeAsExpression(node.type); break; - case 141 /* MethodDeclaration */: + case 143 /* MethodDeclaration */: checkTypeNodeAsExpression(node.type); break; - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: checkTypeNodeAsExpression(node.type); break; - case 144 /* SetAccessor */: + case 146 /* SetAccessor */: checkTypeNodeAsExpression(ts.getSetAccessorTypeAnnotationNode(node)); break; } @@ -23296,25 +23885,25 @@ var ts; if (compilerOptions.emitDecoratorMetadata) { // we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator. switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var constructor = ts.getFirstConstructorWithBody(node); if (constructor) { checkParameterTypeAnnotationsAsExpressions(constructor); } break; - case 141 /* MethodDeclaration */: + case 143 /* MethodDeclaration */: checkParameterTypeAnnotationsAsExpressions(node); // fall-through - case 144 /* SetAccessor */: - case 143 /* GetAccessor */: - case 139 /* PropertyDeclaration */: - case 136 /* Parameter */: + case 146 /* SetAccessor */: + case 145 /* GetAccessor */: + case 141 /* PropertyDeclaration */: + case 138 /* Parameter */: checkTypeAnnotationAsExpression(node); break; } } emitDecorate = true; - if (node.kind === 136 /* Parameter */) { + if (node.kind === 138 /* Parameter */) { emitParam = true; } ts.forEach(node.decorators, checkDecorator); @@ -23332,15 +23921,12 @@ var ts; checkSignatureDeclaration(node); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { - if (!compilerOptions.experimentalAsyncFunctions) { - error(node, ts.Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning); - } emitAwaiter = true; } // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name && node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name && node.name.kind === 136 /* ComputedPropertyName */) { // This check will account for methods in class/interface declarations, // as well as accessors in classes/object literals checkComputedPropertyName(node.name); @@ -23389,11 +23975,11 @@ var ts; } function checkBlock(node) { // Grammar checking for SyntaxKind.Block - if (node.kind === 190 /* Block */) { + if (node.kind === 192 /* Block */) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); - if (ts.isFunctionBlock(node) || node.kind === 217 /* ModuleBlock */) { + if (ts.isFunctionBlock(node) || node.kind === 219 /* ModuleBlock */) { checkFunctionAndClassExpressionBodies(node); } } @@ -23412,12 +23998,12 @@ var ts; if (!(identifier && identifier.text === name)) { return false; } - if (node.kind === 139 /* PropertyDeclaration */ || - node.kind === 138 /* PropertySignature */ || - node.kind === 141 /* MethodDeclaration */ || - node.kind === 140 /* MethodSignature */ || - node.kind === 143 /* GetAccessor */ || - node.kind === 144 /* SetAccessor */) { + if (node.kind === 141 /* PropertyDeclaration */ || + node.kind === 140 /* PropertySignature */ || + node.kind === 143 /* MethodDeclaration */ || + node.kind === 142 /* MethodSignature */ || + node.kind === 145 /* GetAccessor */ || + node.kind === 146 /* SetAccessor */) { // it is ok to have member named '_super' or '_this' - member access is always qualified return false; } @@ -23426,7 +24012,7 @@ var ts; return false; } var root = ts.getRootDeclaration(node); - if (root.kind === 136 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { + if (root.kind === 138 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { // just an overload - no codegen impact return false; } @@ -23442,7 +24028,7 @@ var ts; var current = node; while (current) { if (getNodeCheckFlags(current) & 4 /* CaptureThis */) { - var isDeclaration_1 = node.kind !== 67 /* Identifier */; + var isDeclaration_1 = node.kind !== 69 /* Identifier */; if (isDeclaration_1) { error(node.name, ts.Diagnostics.Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference); } @@ -23465,7 +24051,7 @@ var ts; return; } if (ts.getClassExtendsHeritageClauseElement(enclosingClass)) { - var isDeclaration_2 = node.kind !== 67 /* Identifier */; + var isDeclaration_2 = node.kind !== 69 /* Identifier */; if (isDeclaration_2) { error(node, ts.Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference); } @@ -23479,12 +24065,12 @@ var ts; return; } // Uninstantiated modules shouldnt do this check - if (node.kind === 216 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) { + if (node.kind === 218 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) { return; } // In case of variable declaration, node.parent is variable statement so look at the variable statement's parent var parent = getDeclarationContainer(node); - if (parent.kind === 246 /* SourceFile */ && ts.isExternalModule(parent)) { + if (parent.kind === 248 /* SourceFile */ && ts.isExternalModule(parent)) { // If the declaration happens to be in external module, report error that require and exports are reserved keywords error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name)); } @@ -23519,7 +24105,7 @@ var ts; // skip variable declarations that don't have initializers // NOTE: in ES6 spec initializer is required in variable declarations where name is binding pattern // so we'll always treat binding elements as initialized - if (node.kind === 209 /* VariableDeclaration */ && !node.initializer) { + if (node.kind === 211 /* VariableDeclaration */ && !node.initializer) { return; } var symbol = getSymbolOfNode(node); @@ -23529,17 +24115,17 @@ var ts; localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & 2 /* BlockScopedVariable */) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 49152 /* BlockScoped */) { - var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 210 /* VariableDeclarationList */); - var container = varDeclList.parent.kind === 191 /* VariableStatement */ && varDeclList.parent.parent + var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 212 /* VariableDeclarationList */); + var container = varDeclList.parent.kind === 193 /* VariableStatement */ && varDeclList.parent.parent ? varDeclList.parent.parent : undefined; // names of block-scoped and function scoped variables can collide only // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) var namesShareScope = container && - (container.kind === 190 /* Block */ && ts.isFunctionLike(container.parent) || - container.kind === 217 /* ModuleBlock */ || - container.kind === 216 /* ModuleDeclaration */ || - container.kind === 246 /* SourceFile */); + (container.kind === 192 /* Block */ && ts.isFunctionLike(container.parent) || + container.kind === 219 /* ModuleBlock */ || + container.kind === 218 /* ModuleDeclaration */ || + container.kind === 248 /* SourceFile */); // here we know that function scoped variable is shadowed by block scoped one // if they are defined in the same scope - binder has already reported redeclaration error // otherwise if variable has an initializer - show error that initialization will fail @@ -23554,18 +24140,18 @@ var ts; } // Check that a parameter initializer contains no references to parameters declared to the right of itself function checkParameterInitializer(node) { - if (ts.getRootDeclaration(node).kind !== 136 /* Parameter */) { + if (ts.getRootDeclaration(node).kind !== 138 /* Parameter */) { return; } var func = ts.getContainingFunction(node); visit(node.initializer); function visit(n) { - if (n.kind === 67 /* Identifier */) { + if (n.kind === 69 /* Identifier */) { var referencedSymbol = getNodeLinks(n).resolvedSymbol; // check FunctionLikeDeclaration.locals (stores parameters\function local variable) // if it contains entry with a specified name and if this entry matches the resolved symbol if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455 /* Value */) === referencedSymbol) { - if (referencedSymbol.valueDeclaration.kind === 136 /* Parameter */) { + if (referencedSymbol.valueDeclaration.kind === 138 /* Parameter */) { if (referencedSymbol.valueDeclaration === node) { error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name)); return; @@ -23591,7 +24177,7 @@ var ts; // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); @@ -23602,7 +24188,7 @@ var ts; ts.forEach(node.name.elements, checkSourceElement); } // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body - if (node.initializer && ts.getRootDeclaration(node).kind === 136 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { + if (node.initializer && ts.getRootDeclaration(node).kind === 138 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -23634,10 +24220,10 @@ var ts; checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } } - if (node.kind !== 139 /* PropertyDeclaration */ && node.kind !== 138 /* PropertySignature */) { + if (node.kind !== 141 /* PropertyDeclaration */ && node.kind !== 140 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here checkExportsOnMergedDeclarations(node); - if (node.kind === 209 /* VariableDeclaration */ || node.kind === 161 /* BindingElement */) { + if (node.kind === 211 /* VariableDeclaration */ || node.kind === 163 /* BindingElement */) { checkVarDeclaredNamesNotShadowed(node); } checkCollisionWithCapturedSuperVariable(node, node.name); @@ -23660,7 +24246,7 @@ var ts; } function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) { // We only disallow modifier on a method declaration if it is a property of object-literal-expression - if (node.modifiers && node.parent.kind === 163 /* ObjectLiteralExpression */) { + if (node.modifiers && node.parent.kind === 165 /* ObjectLiteralExpression */) { if (ts.isAsyncFunctionLike(node)) { if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); @@ -23698,12 +24284,12 @@ var ts; function checkForStatement(node) { // Grammar checking if (!checkGrammarStatementInAmbientContext(node)) { - if (node.initializer && node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer && node.initializer.kind === 212 /* VariableDeclarationList */) { checkGrammarVariableDeclarationList(node.initializer); } } if (node.initializer) { - if (node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer.kind === 212 /* VariableDeclarationList */) { ts.forEach(node.initializer.declarations, checkVariableDeclaration); } else { @@ -23723,14 +24309,14 @@ var ts; // via checkRightHandSideOfForOf. // If the LHS is an expression, check the LHS, as a destructuring assignment or as a reference. // Then check that the RHS is assignable to it. - if (node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer.kind === 212 /* VariableDeclarationList */) { checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; var iteratedType = checkRightHandSideOfForOf(node.expression); // There may be a destructuring assignment on the left side - if (varExpr.kind === 162 /* ArrayLiteralExpression */ || varExpr.kind === 163 /* ObjectLiteralExpression */) { + if (varExpr.kind === 164 /* ArrayLiteralExpression */ || varExpr.kind === 165 /* ObjectLiteralExpression */) { // iteratedType may be undefined. In this case, we still want to check the structure of // varExpr, in particular making sure it's a valid LeftHandSideExpression. But we'd like // to short circuit the type relation checking as much as possible, so we pass the unknownType. @@ -23759,7 +24345,7 @@ var ts; // for (let VarDecl in Expr) Statement // VarDecl must be a variable declaration without a type annotation that declares a variable of type Any, // and Expr must be an expression of type Any, an object type, or a type parameter type. - if (node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer.kind === 212 /* VariableDeclarationList */) { var variable = node.initializer.declarations[0]; if (variable && ts.isBindingPattern(variable.name)) { error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); @@ -23773,7 +24359,7 @@ var ts; // and Expr must be an expression of type Any, an object type, or a type parameter type. var varExpr = node.initializer; var leftType = checkExpression(varExpr); - if (varExpr.kind === 162 /* ArrayLiteralExpression */ || varExpr.kind === 163 /* ObjectLiteralExpression */) { + if (varExpr.kind === 164 /* ArrayLiteralExpression */ || varExpr.kind === 165 /* ObjectLiteralExpression */) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */)) { @@ -24012,7 +24598,7 @@ var ts; // TODO: Check that target label is valid } function isGetAccessorWithAnnotatatedSetAccessor(node) { - return !!(node.kind === 143 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 144 /* SetAccessor */))); + return !!(node.kind === 145 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 146 /* SetAccessor */))); } function checkReturnStatement(node) { // Grammar checking @@ -24035,10 +24621,10 @@ var ts; // for generators. return; } - if (func.kind === 144 /* SetAccessor */) { + if (func.kind === 146 /* SetAccessor */) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else if (func.kind === 142 /* Constructor */) { + else if (func.kind === 144 /* Constructor */) { if (!isTypeAssignableTo(exprType, returnType)) { error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } @@ -24047,7 +24633,12 @@ var ts; if (ts.isAsyncFunctionLike(func)) { var promisedType = getPromisedType(returnType); var awaitedType = checkAwaitedType(exprType, node.expression, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); - checkTypeAssignableTo(awaitedType, promisedType, node.expression); + if (promisedType) { + // If the function has a return type, but promisedType is + // undefined, an error will be reported in checkAsyncFunctionReturnType + // so we don't need to report one here. + checkTypeAssignableTo(awaitedType, promisedType, node.expression); + } } else { checkTypeAssignableTo(exprType, returnType, node.expression); @@ -24074,7 +24665,7 @@ var ts; var expressionType = checkExpression(node.expression); ts.forEach(node.caseBlock.clauses, function (clause) { // Grammar check for duplicate default clauses, skip if we already report duplicate default clause - if (clause.kind === 240 /* DefaultClause */ && !hasDuplicateDefaultClause) { + if (clause.kind === 242 /* DefaultClause */ && !hasDuplicateDefaultClause) { if (firstDefaultClause === undefined) { firstDefaultClause = clause; } @@ -24086,7 +24677,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (produceDiagnostics && clause.kind === 239 /* CaseClause */) { + if (produceDiagnostics && clause.kind === 241 /* CaseClause */) { var caseClause = clause; // TypeScript 1.0 spec (April 2014):5.9 // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. @@ -24107,7 +24698,7 @@ var ts; if (ts.isFunctionLike(current)) { break; } - if (current.kind === 205 /* LabeledStatement */ && current.label.text === node.label.text) { + if (current.kind === 207 /* LabeledStatement */ && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -24137,7 +24728,7 @@ var ts; if (catchClause) { // Grammar checking if (catchClause.variableDeclaration) { - if (catchClause.variableDeclaration.name.kind !== 67 /* Identifier */) { + if (catchClause.variableDeclaration.name.kind !== 69 /* Identifier */) { grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); } else if (catchClause.variableDeclaration.type) { @@ -24212,7 +24803,7 @@ var ts; // perform property check if property or indexer is declared in 'type' // this allows to rule out cases when both property and indexer are inherited from the base class var errorNode; - if (prop.valueDeclaration.name.kind === 134 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { + if (prop.valueDeclaration.name.kind === 136 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { @@ -24289,6 +24880,7 @@ var ts; checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { @@ -24307,7 +24899,7 @@ var ts; } } } - checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32 /* Class */)) { // When the static base type is a "class-like" constructor function (but not actually a class), we verify @@ -24324,7 +24916,8 @@ var ts; } var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node); if (implementedTypeNodes) { - ts.forEach(implementedTypeNodes, function (typeRefNode) { + for (var _b = 0; _b < implementedTypeNodes.length; _b++) { + var typeRefNode = implementedTypeNodes[_b]; if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) { error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments); } @@ -24334,14 +24927,14 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096 /* Reference */) ? t.target : t; if (declaredType.flags & (1024 /* Class */ | 2048 /* Interface */)) { - checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(t, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); } } } - }); + } } if (produceDiagnostics) { checkIndexConstraints(type); @@ -24392,7 +24985,7 @@ var ts; // If there is no declaration for the derived class (as in the case of class expressions), // then the class cannot be declared abstract. if (baseDeclarationFlags & 256 /* Abstract */ && (!derivedClassDecl || !(derivedClassDecl.flags & 256 /* Abstract */))) { - if (derivedClassDecl.kind === 184 /* ClassExpression */) { + if (derivedClassDecl.kind === 186 /* ClassExpression */) { error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, symbolToString(baseProperty), typeToString(baseType)); } else { @@ -24440,7 +25033,7 @@ var ts; } } function isAccessor(kind) { - return kind === 143 /* GetAccessor */ || kind === 144 /* SetAccessor */; + return kind === 145 /* GetAccessor */ || kind === 146 /* SetAccessor */; } function areTypeParametersIdentical(list1, list2) { if (!list1 && !list2) { @@ -24480,7 +25073,7 @@ var ts; var ok = true; for (var _i = 0; _i < baseTypes.length; _i++) { var base = baseTypes[_i]; - var properties = getPropertiesOfObjectType(base); + var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType)); for (var _a = 0; _a < properties.length; _a++) { var prop = properties[_a]; if (!ts.hasProperty(seen, prop.name)) { @@ -24510,7 +25103,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 213 /* InterfaceDeclaration */); + var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 215 /* InterfaceDeclaration */); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -24519,19 +25112,21 @@ var ts; // Only check this symbol once if (node === firstInterfaceDecl) { var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); // run subsequent checks only if first set succeeded if (checkInheritedPropertiesAreIdentical(type, node.name)) { - ts.forEach(getBaseTypes(type), function (baseType) { - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); - }); + for (var _i = 0, _a = getBaseTypes(type); _i < _a.length; _i++) { + var baseType = _a[_i]; + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); + } checkIndexConstraints(type); } } // Interfaces cannot merge with non-ambient classes. if (symbol && symbol.declarations) { - for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { - var declaration = _a[_i]; - if (declaration.kind === 212 /* ClassDeclaration */ && !ts.isInAmbientContext(declaration)) { + for (var _b = 0, _c = symbol.declarations; _b < _c.length; _b++) { + var declaration = _c[_b]; + if (declaration.kind === 214 /* ClassDeclaration */ && !ts.isInAmbientContext(declaration)) { error(node, ts.Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface); break; } @@ -24560,24 +25155,38 @@ var ts; if (!(nodeLinks.flags & 8192 /* EnumValuesComputed */)) { var enumSymbol = getSymbolOfNode(node); var enumType = getDeclaredTypeOfSymbol(enumSymbol); - var autoValue = 0; + var autoValue = 0; // set to undefined when enum member is non-constant var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); - ts.forEach(node.members, function (member) { - if (member.name.kind !== 134 /* ComputedPropertyName */ && isNumericLiteralName(member.name.text)) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.name.kind === 136 /* ComputedPropertyName */) { + error(member.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); + } + else if (isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } + var previousEnumMemberIsNonConstant = autoValue === undefined; var initializer = member.initializer; if (initializer) { autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient); } else if (ambient && !enumIsConst) { + // In ambient enum declarations that specify no const modifier, enum member declarations + // that omit a value are considered computed members (as opposed to having auto-incremented values assigned). autoValue = undefined; } + else if (previousEnumMemberIsNonConstant) { + // If the member declaration specifies no value, the member is considered a constant enum member. + // If the member is the first member in the enum declaration, it is assigned the value zero. + // Otherwise, it is assigned the value of the immediately preceding member plus one, + // and an error occurs if the immediately preceding member is not a constant enum member + error(member.name, ts.Diagnostics.Enum_member_must_have_initializer); + } if (autoValue !== undefined) { getNodeLinks(member).enumMemberValue = autoValue++; } - }); + } nodeLinks.flags |= 8192 /* EnumValuesComputed */; } function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) { @@ -24590,11 +25199,11 @@ var ts; if (enumIsConst) { error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); } - else if (!ambient) { + else if (ambient) { + error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression); + } + else { // Only here do we need to check that the initializer is assignable to the enum type. - // If it is a constant value (not undefined), it is syntactically constrained to be a number. - // Also, we do not need to check this for ambients because there is already - // a syntax error if it is not a constant. checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); } } @@ -24610,7 +25219,7 @@ var ts; return value; function evalConstant(e) { switch (e.kind) { - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: var value_1 = evalConstant(e.operand); if (value_1 === undefined) { return undefined; @@ -24618,10 +25227,10 @@ var ts; switch (e.operator) { case 35 /* PlusToken */: return value_1; case 36 /* MinusToken */: return -value_1; - case 49 /* TildeToken */: return ~value_1; + case 50 /* TildeToken */: return ~value_1; } return undefined; - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: var left = evalConstant(e.left); if (left === undefined) { return undefined; @@ -24631,31 +25240,31 @@ var ts; return undefined; } switch (e.operatorToken.kind) { - case 46 /* BarToken */: return left | right; - case 45 /* AmpersandToken */: return left & right; - case 43 /* GreaterThanGreaterThanToken */: return left >> right; - case 44 /* GreaterThanGreaterThanGreaterThanToken */: return left >>> right; - case 42 /* LessThanLessThanToken */: return left << right; - case 47 /* CaretToken */: return left ^ right; + case 47 /* BarToken */: return left | right; + case 46 /* AmpersandToken */: return left & right; + case 44 /* GreaterThanGreaterThanToken */: return left >> right; + case 45 /* GreaterThanGreaterThanGreaterThanToken */: return left >>> right; + case 43 /* LessThanLessThanToken */: return left << right; + case 48 /* CaretToken */: return left ^ right; case 37 /* AsteriskToken */: return left * right; - case 38 /* SlashToken */: return left / right; + case 39 /* SlashToken */: return left / right; case 35 /* PlusToken */: return left + right; case 36 /* MinusToken */: return left - right; - case 39 /* PercentToken */: return left % right; + case 40 /* PercentToken */: return left % right; } return undefined; case 8 /* NumericLiteral */: return +e.text; - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return evalConstant(e.expression); - case 67 /* Identifier */: - case 165 /* ElementAccessExpression */: - case 164 /* PropertyAccessExpression */: + case 69 /* Identifier */: + case 167 /* ElementAccessExpression */: + case 166 /* PropertyAccessExpression */: var member = initializer.parent; var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); var enumType_1; var propertyName; - if (e.kind === 67 /* Identifier */) { + if (e.kind === 69 /* Identifier */) { // unqualified names can refer to member that reside in different declaration of the enum so just doing name resolution won't work. // instead pick current enum type and later try to fetch member from the type enumType_1 = currentType; @@ -24663,7 +25272,7 @@ var ts; } else { var expression; - if (e.kind === 165 /* ElementAccessExpression */) { + if (e.kind === 167 /* ElementAccessExpression */) { if (e.argumentExpression === undefined || e.argumentExpression.kind !== 9 /* StringLiteral */) { return undefined; @@ -24678,10 +25287,10 @@ var ts; // expression part in ElementAccess\PropertyAccess should be either identifier or dottedName var current = expression; while (current) { - if (current.kind === 67 /* Identifier */) { + if (current.kind === 69 /* Identifier */) { break; } - else if (current.kind === 164 /* PropertyAccessExpression */) { + else if (current.kind === 166 /* PropertyAccessExpression */) { current = current.expression; } else { @@ -24707,7 +25316,7 @@ var ts; return undefined; } // illegal case: forward reference - if (!isDefinedBefore(propertyDecl, member)) { + if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) { reportError = false; error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums); return undefined; @@ -24722,7 +25331,7 @@ var ts; return; } // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -24752,7 +25361,7 @@ var ts; var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { // return true if we hit a violation of the rule, false otherwise - if (declaration.kind !== 215 /* EnumDeclaration */) { + if (declaration.kind !== 217 /* EnumDeclaration */) { return false; } var enumDeclaration = declaration; @@ -24775,8 +25384,8 @@ var ts; var declarations = symbol.declarations; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; - if ((declaration.kind === 212 /* ClassDeclaration */ || - (declaration.kind === 211 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) && + if ((declaration.kind === 214 /* ClassDeclaration */ || + (declaration.kind === 213 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } @@ -24832,7 +25441,7 @@ var ts; } // if the module merges with a class declaration in the same lexical scope, // we need to track this to ensure the correct emit. - var mergedClass = ts.getDeclarationOfKind(symbol, 212 /* ClassDeclaration */); + var mergedClass = ts.getDeclarationOfKind(symbol, 214 /* ClassDeclaration */); if (mergedClass && inSameLexicalScope(node, mergedClass)) { getNodeLinks(node).flags |= 32768 /* LexicalModuleMergesWithClass */; @@ -24841,9 +25450,9 @@ var ts; // Checks for ambient external modules. if (isAmbientExternalModule) { if (!isGlobalSourceFile(node.parent)) { - error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules); + error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces); } - if (isExternalModuleNameRelative(node.name.text)) { + if (ts.isExternalModuleNameRelative(node.name.text)) { error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name); } } @@ -24852,17 +25461,17 @@ var ts; } function getFirstIdentifier(node) { while (true) { - if (node.kind === 133 /* QualifiedName */) { + if (node.kind === 135 /* QualifiedName */) { node = node.left; } - else if (node.kind === 164 /* PropertyAccessExpression */) { + else if (node.kind === 166 /* PropertyAccessExpression */) { node = node.expression; } else { break; } } - ts.Debug.assert(node.kind === 67 /* Identifier */); + ts.Debug.assert(node.kind === 69 /* Identifier */); return node; } function checkExternalImportOrExportDeclaration(node) { @@ -24871,14 +25480,14 @@ var ts; error(moduleName, ts.Diagnostics.String_literal_expected); return false; } - var inAmbientExternalModule = node.parent.kind === 217 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; - if (node.parent.kind !== 246 /* SourceFile */ && !inAmbientExternalModule) { - error(moduleName, node.kind === 226 /* ExportDeclaration */ ? + var inAmbientExternalModule = node.parent.kind === 219 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; + if (node.parent.kind !== 248 /* SourceFile */ && !inAmbientExternalModule) { + error(moduleName, node.kind === 228 /* ExportDeclaration */ ? ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace : ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module); return false; } - if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) { + if (inAmbientExternalModule && ts.isExternalModuleNameRelative(moduleName.text)) { // TypeScript 1.0 spec (April 2013): 12.1.6 // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference // other external modules only through top - level external module names. @@ -24896,7 +25505,7 @@ var ts; (symbol.flags & 793056 /* Type */ ? 793056 /* Type */ : 0) | (symbol.flags & 1536 /* Namespace */ ? 1536 /* Namespace */ : 0); if (target.flags & excludedMeanings) { - var message = node.kind === 228 /* ExportSpecifier */ ? + var message = node.kind === 230 /* ExportSpecifier */ ? ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; error(node, message, symbolToString(symbol)); @@ -24923,7 +25532,7 @@ var ts; checkImportBinding(importClause); } if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (importClause.namedBindings.kind === 224 /* NamespaceImport */) { checkImportBinding(importClause.namedBindings); } else { @@ -24960,9 +25569,9 @@ var ts; } } else { - if (languageVersion >= 2 /* ES6 */ && !ts.isInAmbientContext(node)) { + if (modulekind === 5 /* ES6 */ && !ts.isInAmbientContext(node)) { // Import equals declaration is deprecated in es6 or above - grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead); } } } @@ -24980,8 +25589,8 @@ var ts; // export { x, y } // export { x, y } from "foo" ts.forEach(node.exportClause.elements, checkExportSpecifier); - var inAmbientExternalModule = node.parent.kind === 217 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; - if (node.parent.kind !== 246 /* SourceFile */ && !inAmbientExternalModule) { + var inAmbientExternalModule = node.parent.kind === 219 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; + if (node.parent.kind !== 248 /* SourceFile */ && !inAmbientExternalModule) { error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace); } } @@ -24995,7 +25604,7 @@ var ts; } } function checkGrammarModuleElementContext(node, errorMessage) { - if (node.parent.kind !== 246 /* SourceFile */ && node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 216 /* ModuleDeclaration */) { + if (node.parent.kind !== 248 /* SourceFile */ && node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 218 /* ModuleDeclaration */) { return grammarErrorOnFirstToken(node, errorMessage); } } @@ -25010,8 +25619,8 @@ var ts; // If we hit an export assignment in an illegal context, just bail out to avoid cascading errors. return; } - var container = node.parent.kind === 246 /* SourceFile */ ? node.parent : node.parent.parent; - if (container.kind === 216 /* ModuleDeclaration */ && container.name.kind === 67 /* Identifier */) { + var container = node.parent.kind === 248 /* SourceFile */ ? node.parent : node.parent.parent; + if (container.kind === 218 /* ModuleDeclaration */ && container.name.kind === 69 /* Identifier */) { error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace); return; } @@ -25019,7 +25628,7 @@ var ts; if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035 /* Modifier */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - if (node.expression.kind === 67 /* Identifier */) { + if (node.expression.kind === 69 /* Identifier */) { markExportAsReferenced(node); } else { @@ -25027,21 +25636,21 @@ var ts; } checkExternalModuleExports(container); if (node.isExportEquals && !ts.isInAmbientContext(node)) { - if (languageVersion >= 2 /* ES6 */) { - // export assignment is deprecated in es6 or above - grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + if (modulekind === 5 /* ES6 */) { + // export assignment is not supported in es6 modules + grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead); } - else if (compilerOptions.module === 4 /* System */) { + else if (modulekind === 4 /* System */) { // system modules does not support export assignment grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); } } } function getModuleStatements(node) { - if (node.kind === 246 /* SourceFile */) { + if (node.kind === 248 /* SourceFile */) { return node.statements; } - if (node.kind === 216 /* ModuleDeclaration */ && node.body.kind === 217 /* ModuleBlock */) { + if (node.kind === 218 /* ModuleDeclaration */ && node.body.kind === 219 /* ModuleBlock */) { return node.body.statements; } return emptyArray; @@ -25080,118 +25689,118 @@ var ts; // Only bother checking on a few construct kinds. We don't want to be excessivly // hitting the cancellation token on every node we check. switch (kind) { - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: return checkTypeParameter(node); - case 136 /* Parameter */: + case 138 /* Parameter */: return checkParameter(node); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return checkPropertyDeclaration(node); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: return checkSignatureDeclaration(node); - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: return checkSignatureDeclaration(node); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return checkMethodDeclaration(node); - case 142 /* Constructor */: + case 144 /* Constructor */: return checkConstructorDeclaration(node); - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return checkAccessorDeclaration(node); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return checkTypeReferenceNode(node); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return checkTypePredicate(node); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return checkTypeQuery(node); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return checkTypeLiteral(node); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return checkArrayType(node); - case 155 /* TupleType */: + case 157 /* TupleType */: return checkTupleType(node); - case 156 /* UnionType */: - case 157 /* IntersectionType */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: return checkUnionOrIntersectionType(node); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return checkSourceElement(node.type); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 190 /* Block */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return checkBlock(node); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return checkVariableStatement(node); - case 193 /* ExpressionStatement */: + case 195 /* ExpressionStatement */: return checkExpressionStatement(node); - case 194 /* IfStatement */: + case 196 /* IfStatement */: return checkIfStatement(node); - case 195 /* DoStatement */: + case 197 /* DoStatement */: return checkDoStatement(node); - case 196 /* WhileStatement */: + case 198 /* WhileStatement */: return checkWhileStatement(node); - case 197 /* ForStatement */: + case 199 /* ForStatement */: return checkForStatement(node); - case 198 /* ForInStatement */: + case 200 /* ForInStatement */: return checkForInStatement(node); - case 199 /* ForOfStatement */: + case 201 /* ForOfStatement */: return checkForOfStatement(node); - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: return checkReturnStatement(node); - case 203 /* WithStatement */: + case 205 /* WithStatement */: return checkWithStatement(node); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: return checkSwitchStatement(node); - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return checkLabeledStatement(node); - case 206 /* ThrowStatement */: + case 208 /* ThrowStatement */: return checkThrowStatement(node); - case 207 /* TryStatement */: + case 209 /* TryStatement */: return checkTryStatement(node); - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: return checkVariableDeclaration(node); - case 161 /* BindingElement */: + case 163 /* BindingElement */: return checkBindingElement(node); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return checkClassDeclaration(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: return checkImportDeclaration(node); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return checkExportDeclaration(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return checkExportAssignment(node); - case 192 /* EmptyStatement */: + case 194 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; - case 208 /* DebuggerStatement */: + case 210 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; - case 229 /* MissingDeclaration */: + case 231 /* MissingDeclaration */: return checkMissingDeclaration(node); } } @@ -25206,97 +25815,98 @@ var ts; // Delaying the type check of the body ensures foo has been assigned a type. function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: ts.forEach(node.members, checkSourceElement); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } break; - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; - case 203 /* WithStatement */: + case 205 /* WithStatement */: checkFunctionAndClassExpressionBodies(node.expression); break; - case 137 /* Decorator */: - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: - case 161 /* BindingElement */: - case 162 /* ArrayLiteralExpression */: - case 163 /* ObjectLiteralExpression */: - case 243 /* PropertyAssignment */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 168 /* TaggedTemplateExpression */: - case 181 /* TemplateExpression */: - case 188 /* TemplateSpan */: - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: - case 170 /* ParenthesizedExpression */: - case 174 /* TypeOfExpression */: - case 175 /* VoidExpression */: - case 176 /* AwaitExpression */: - case 173 /* DeleteExpression */: - case 177 /* PrefixUnaryExpression */: - case 178 /* PostfixUnaryExpression */: - case 179 /* BinaryExpression */: - case 180 /* ConditionalExpression */: - case 183 /* SpreadElementExpression */: - case 182 /* YieldExpression */: - case 190 /* Block */: - case 217 /* ModuleBlock */: - case 191 /* VariableStatement */: - case 193 /* ExpressionStatement */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: - case 202 /* ReturnStatement */: - case 204 /* SwitchStatement */: - case 218 /* CaseBlock */: - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - case 205 /* LabeledStatement */: - case 206 /* ThrowStatement */: - case 207 /* TryStatement */: - case 242 /* CatchClause */: - case 209 /* VariableDeclaration */: - case 210 /* VariableDeclarationList */: - case 212 /* ClassDeclaration */: - case 241 /* HeritageClause */: - case 186 /* ExpressionWithTypeArguments */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 225 /* ExportAssignment */: - case 246 /* SourceFile */: - case 238 /* JsxExpression */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 236 /* JsxAttribute */: - case 237 /* JsxSpreadAttribute */: - case 233 /* JsxOpeningElement */: + case 139 /* Decorator */: + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: + case 163 /* BindingElement */: + case 164 /* ArrayLiteralExpression */: + case 165 /* ObjectLiteralExpression */: + case 245 /* PropertyAssignment */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 170 /* TaggedTemplateExpression */: + case 183 /* TemplateExpression */: + case 190 /* TemplateSpan */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: + case 172 /* ParenthesizedExpression */: + case 176 /* TypeOfExpression */: + case 177 /* VoidExpression */: + case 178 /* AwaitExpression */: + case 175 /* DeleteExpression */: + case 179 /* PrefixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: + case 181 /* BinaryExpression */: + case 182 /* ConditionalExpression */: + case 185 /* SpreadElementExpression */: + case 184 /* YieldExpression */: + case 192 /* Block */: + case 219 /* ModuleBlock */: + case 193 /* VariableStatement */: + case 195 /* ExpressionStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: + case 204 /* ReturnStatement */: + case 206 /* SwitchStatement */: + case 220 /* CaseBlock */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + case 207 /* LabeledStatement */: + case 208 /* ThrowStatement */: + case 209 /* TryStatement */: + case 244 /* CatchClause */: + case 211 /* VariableDeclaration */: + case 212 /* VariableDeclarationList */: + case 214 /* ClassDeclaration */: + case 243 /* HeritageClause */: + case 188 /* ExpressionWithTypeArguments */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 227 /* ExportAssignment */: + case 248 /* SourceFile */: + case 240 /* JsxExpression */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 238 /* JsxAttribute */: + case 239 /* JsxSpreadAttribute */: + case 235 /* JsxOpeningElement */: ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } @@ -25382,7 +25992,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 203 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 205 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -25405,34 +26015,34 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (!ts.isExternalModule(location)) { break; } - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 8914931 /* ModuleMember */); break; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */); break; - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: var className = location.name; if (className) { copySymbol(location.symbol, meaning); } // fall through; this fall-through is necessary because we would like to handle // type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: // If we didn't come from static member of class or interface, - // add the type parameters into the symbol table + // add the type parameters into the symbol table // (type parameters of classDeclaration/classExpression and interface are in member property of the symbol. // Note: that the memberFlags come from previous iteration. if (!(memberFlags & 128 /* Static */)) { copySymbols(getSymbolOfNode(location).members, meaning & 793056 /* Type */); } break; - case 171 /* FunctionExpression */: + case 173 /* FunctionExpression */: var funcName = location.name; if (funcName) { copySymbol(location.symbol, meaning); @@ -25475,43 +26085,43 @@ var ts; } } function isTypeDeclarationName(name) { - return name.kind === 67 /* Identifier */ && + return name.kind === 69 /* Identifier */ && isTypeDeclaration(name.parent) && name.parent.name === name; } function isTypeDeclaration(node) { switch (node.kind) { - case 135 /* TypeParameter */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 215 /* EnumDeclaration */: + case 137 /* TypeParameter */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 217 /* EnumDeclaration */: return true; } } // True if the given identifier is part of a type reference function isTypeReferenceIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 133 /* QualifiedName */) { + while (node.parent && node.parent.kind === 135 /* QualifiedName */) { node = node.parent; } - return node.parent && node.parent.kind === 149 /* TypeReference */; + return node.parent && node.parent.kind === 151 /* TypeReference */; } function isHeritageClauseElementIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 164 /* PropertyAccessExpression */) { + while (node.parent && node.parent.kind === 166 /* PropertyAccessExpression */) { node = node.parent; } - return node.parent && node.parent.kind === 186 /* ExpressionWithTypeArguments */; + return node.parent && node.parent.kind === 188 /* ExpressionWithTypeArguments */; } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { - while (nodeOnRightSide.parent.kind === 133 /* QualifiedName */) { + while (nodeOnRightSide.parent.kind === 135 /* QualifiedName */) { nodeOnRightSide = nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 219 /* ImportEqualsDeclaration */) { + if (nodeOnRightSide.parent.kind === 221 /* ImportEqualsDeclaration */) { return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 225 /* ExportAssignment */) { + if (nodeOnRightSide.parent.kind === 227 /* ExportAssignment */) { return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; @@ -25523,11 +26133,11 @@ var ts; if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 225 /* ExportAssignment */) { + if (entityName.parent.kind === 227 /* ExportAssignment */) { return resolveEntityName(entityName, /*all meanings*/ 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */ | 8388608 /* Alias */); } - if (entityName.kind !== 164 /* PropertyAccessExpression */) { + if (entityName.kind !== 166 /* PropertyAccessExpression */) { if (isInRightSideOfImportOrExportAssignment(entityName)) { // Since we already checked for ExportAssignment, this really could only be an Import return getSymbolOfPartOfRightHandSideOfImportEquals(entityName); @@ -25537,13 +26147,24 @@ var ts; entityName = entityName.parent; } if (isHeritageClauseElementIdentifier(entityName)) { - var meaning = entityName.parent.kind === 186 /* ExpressionWithTypeArguments */ ? 793056 /* Type */ : 1536 /* Namespace */; + var meaning = 0 /* None */; + // In an interface or class, we're definitely interested in a type. + if (entityName.parent.kind === 188 /* ExpressionWithTypeArguments */) { + meaning = 793056 /* Type */; + // In a class 'extends' clause we are also looking for a value. + if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent)) { + meaning |= 107455 /* Value */; + } + } + else { + meaning = 1536 /* Namespace */; + } meaning |= 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } - else if ((entityName.parent.kind === 233 /* JsxOpeningElement */) || - (entityName.parent.kind === 232 /* JsxSelfClosingElement */) || - (entityName.parent.kind === 235 /* JsxClosingElement */)) { + else if ((entityName.parent.kind === 235 /* JsxOpeningElement */) || + (entityName.parent.kind === 234 /* JsxSelfClosingElement */) || + (entityName.parent.kind === 237 /* JsxClosingElement */)) { return getJsxElementTagSymbol(entityName.parent); } else if (ts.isExpression(entityName)) { @@ -25551,20 +26172,20 @@ var ts; // Missing entity name. return undefined; } - if (entityName.kind === 67 /* Identifier */) { + if (entityName.kind === 69 /* Identifier */) { // Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead // return the alias symbol. var meaning = 107455 /* Value */ | 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } - else if (entityName.kind === 164 /* PropertyAccessExpression */) { + else if (entityName.kind === 166 /* PropertyAccessExpression */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccessExpression(entityName); } return getNodeLinks(entityName).resolvedSymbol; } - else if (entityName.kind === 133 /* QualifiedName */) { + else if (entityName.kind === 135 /* QualifiedName */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkQualifiedName(entityName); @@ -25573,16 +26194,16 @@ var ts; } } else if (isTypeReferenceIdentifier(entityName)) { - var meaning = entityName.parent.kind === 149 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; + var meaning = entityName.parent.kind === 151 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; // Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead // return the alias symbol. meaning |= 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } - else if (entityName.parent.kind === 236 /* JsxAttribute */) { + else if (entityName.parent.kind === 238 /* JsxAttribute */) { return getJsxAttributePropertySymbol(entityName.parent); } - if (entityName.parent.kind === 148 /* TypePredicate */) { + if (entityName.parent.kind === 150 /* TypePredicate */) { return resolveEntityName(entityName, /*meaning*/ 1 /* FunctionScopedVariable */); } // Do we want to return undefined here? @@ -25597,14 +26218,14 @@ var ts; // This is a declaration, call getSymbolOfNode return getSymbolOfNode(node.parent); } - if (node.kind === 67 /* Identifier */) { + if (node.kind === 69 /* Identifier */) { if (isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 225 /* ExportAssignment */ + return node.parent.kind === 227 /* ExportAssignment */ ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImportEquals(node); } - else if (node.parent.kind === 161 /* BindingElement */ && - node.parent.parent.kind === 159 /* ObjectBindingPattern */ && + else if (node.parent.kind === 163 /* BindingElement */ && + node.parent.parent.kind === 161 /* ObjectBindingPattern */ && node === node.parent.propertyName) { var typeOfPattern = getTypeOfNode(node.parent.parent); var propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, node.text); @@ -25614,18 +26235,18 @@ var ts; } } switch (node.kind) { - case 67 /* Identifier */: - case 164 /* PropertyAccessExpression */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 166 /* PropertyAccessExpression */: + case 135 /* QualifiedName */: return getSymbolOfEntityNameOrPropertyAccessExpression(node); - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - var type = checkExpression(node); + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: + var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; - case 119 /* ConstructorKeyword */: + case 121 /* ConstructorKeyword */: // constructor keyword for an overload, should take us to the definition if it exist var constructorDeclaration = node.parent; - if (constructorDeclaration && constructorDeclaration.kind === 142 /* Constructor */) { + if (constructorDeclaration && constructorDeclaration.kind === 144 /* Constructor */) { return constructorDeclaration.parent.symbol; } return undefined; @@ -25633,14 +26254,14 @@ var ts; // External module name in an import declaration if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || - ((node.parent.kind === 220 /* ImportDeclaration */ || node.parent.kind === 226 /* ExportDeclaration */) && + ((node.parent.kind === 222 /* ImportDeclaration */ || node.parent.kind === 228 /* ExportDeclaration */) && node.parent.moduleSpecifier === node)) { return resolveExternalModuleName(node, node); } // Fall through case 8 /* NumericLiteral */: // index access - if (node.parent.kind === 165 /* ElementAccessExpression */ && node.parent.argumentExpression === node) { + if (node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.argumentExpression === node) { var objectType = checkExpression(node.parent.expression); if (objectType === unknownType) return undefined; @@ -25657,7 +26278,7 @@ var ts; // The function returns a value symbol of an identifier in the short-hand property assignment. // This is necessary as an identifier in short-hand property assignment can contains two meaning: // property name and property value. - if (location && location.kind === 244 /* ShorthandPropertyAssignment */) { + if (location && location.kind === 246 /* ShorthandPropertyAssignment */) { return resolveEntityName(location.name, 107455 /* Value */); } return undefined; @@ -25774,11 +26395,11 @@ var ts; } var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { - if (parentSymbol.flags & 512 /* ValueModule */ && parentSymbol.valueDeclaration.kind === 246 /* SourceFile */) { + if (parentSymbol.flags & 512 /* ValueModule */ && parentSymbol.valueDeclaration.kind === 248 /* SourceFile */) { return parentSymbol.valueDeclaration; } for (var n = node.parent; n; n = n.parent) { - if ((n.kind === 216 /* ModuleDeclaration */ || n.kind === 215 /* EnumDeclaration */) && getSymbolOfNode(n) === parentSymbol) { + if ((n.kind === 218 /* ModuleDeclaration */ || n.kind === 217 /* EnumDeclaration */) && getSymbolOfNode(n) === parentSymbol) { return n; } } @@ -25793,11 +26414,11 @@ var ts; } function isStatementWithLocals(node) { switch (node.kind) { - case 190 /* Block */: - case 218 /* CaseBlock */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 192 /* Block */: + case 220 /* CaseBlock */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return true; } return false; @@ -25827,22 +26448,22 @@ var ts; } function isValueAliasDeclaration(node) { switch (node.kind) { - case 219 /* ImportEqualsDeclaration */: - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: return isAliasResolvedToValue(getSymbolOfNode(node)); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: var exportClause = node.exportClause; return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration); - case 225 /* ExportAssignment */: - return node.expression && node.expression.kind === 67 /* Identifier */ ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; + case 227 /* ExportAssignment */: + return node.expression && node.expression.kind === 69 /* Identifier */ ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; } return false; } function isTopLevelValueImportEqualsWithEntityName(node) { - if (node.parent.kind !== 246 /* SourceFile */ || !ts.isInternalModuleImportEqualsDeclaration(node)) { + if (node.parent.kind !== 248 /* SourceFile */ || !ts.isInternalModuleImportEqualsDeclaration(node)) { // parent is not source file or it is not reference to internal module return false; } @@ -25904,7 +26525,7 @@ var ts; return getNodeLinks(node).enumMemberValue; } function getConstantValue(node) { - if (node.kind === 245 /* EnumMember */) { + if (node.kind === 247 /* EnumMember */) { return getEnumMemberValue(node); } var symbol = getNodeLinks(node).resolvedSymbol; @@ -25996,23 +26617,6 @@ var ts; var symbol = getReferencedValueSymbol(reference); return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } - function getBlockScopedVariableId(n) { - ts.Debug.assert(!ts.nodeIsSynthesized(n)); - var isVariableDeclarationOrBindingElement = n.parent.kind === 161 /* BindingElement */ || (n.parent.kind === 209 /* VariableDeclaration */ && n.parent.name === n); - var symbol = (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) || - getNodeLinks(n).resolvedSymbol || - resolveName(n, n.text, 107455 /* Value */ | 8388608 /* Alias */, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); - var isLetOrConst = symbol && - (symbol.flags & 2 /* BlockScopedVariable */) && - symbol.valueDeclaration.parent.kind !== 242 /* CatchClause */; - if (isLetOrConst) { - // side-effect of calling this method: - // assign id to symbol if it was not yet set - getSymbolLinks(symbol); - return symbol.id; - } - return undefined; - } function instantiateSingleCallFunctionType(functionType, typeArguments) { if (functionType === unknownType) { return unknownType; @@ -26044,7 +26648,6 @@ var ts; isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, collectLinkedAliases: collectLinkedAliases, - getBlockScopedVariableId: getBlockScopedVariableId, getReferencedValueDeclaration: getReferencedValueDeclaration, getTypeReferenceSerializationKind: getTypeReferenceSerializationKind, isOptionalParameter: isOptionalParameter @@ -26136,10 +26739,7 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here); } - else if (languageVersion < 1 /* ES5 */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (node.kind === 143 /* GetAccessor */ || node.kind === 144 /* SetAccessor */) { + else if (node.kind === 145 /* GetAccessor */ || node.kind === 146 /* SetAccessor */) { var accessors = ts.getAllAccessorDeclarations(node.parent.members, node); if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name); @@ -26149,38 +26749,38 @@ var ts; } function checkGrammarModifiers(node) { switch (node.kind) { - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 147 /* IndexSignature */: - case 216 /* ModuleDeclaration */: - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 226 /* ExportDeclaration */: - case 225 /* ExportAssignment */: - case 136 /* Parameter */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 149 /* IndexSignature */: + case 218 /* ModuleDeclaration */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 228 /* ExportDeclaration */: + case 227 /* ExportAssignment */: + case 138 /* Parameter */: break; - case 211 /* FunctionDeclaration */: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 116 /* AsyncKeyword */) && - node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 246 /* SourceFile */) { + case 213 /* FunctionDeclaration */: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 118 /* AsyncKeyword */) && + node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 191 /* VariableStatement */: - case 214 /* TypeAliasDeclaration */: - if (node.modifiers && node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 246 /* SourceFile */) { + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 193 /* VariableStatement */: + case 216 /* TypeAliasDeclaration */: + if (node.modifiers && node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; - case 215 /* EnumDeclaration */: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 72 /* ConstKeyword */) && - node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 246 /* SourceFile */) { + case 217 /* EnumDeclaration */: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 74 /* ConstKeyword */) && + node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; @@ -26195,14 +26795,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { - case 110 /* PublicKeyword */: - case 109 /* ProtectedKeyword */: - case 108 /* PrivateKeyword */: + case 112 /* PublicKeyword */: + case 111 /* ProtectedKeyword */: + case 110 /* PrivateKeyword */: var text = void 0; - if (modifier.kind === 110 /* PublicKeyword */) { + if (modifier.kind === 112 /* PublicKeyword */) { text = "public"; } - else if (modifier.kind === 109 /* ProtectedKeyword */) { + else if (modifier.kind === 111 /* ProtectedKeyword */) { text = "protected"; lastProtected = modifier; } @@ -26219,11 +26819,11 @@ var ts; else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); } - else if (node.parent.kind === 217 /* ModuleBlock */ || node.parent.kind === 246 /* SourceFile */) { + else if (node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); } else if (flags & 256 /* Abstract */) { - if (modifier.kind === 108 /* PrivateKeyword */) { + if (modifier.kind === 110 /* PrivateKeyword */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract"); } else { @@ -26232,17 +26832,17 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 111 /* StaticKeyword */: + case 113 /* StaticKeyword */: if (flags & 128 /* Static */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } - else if (node.parent.kind === 217 /* ModuleBlock */ || node.parent.kind === 246 /* SourceFile */) { + else if (node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } else if (flags & 256 /* Abstract */) { @@ -26251,7 +26851,7 @@ var ts; flags |= 128 /* Static */; lastStatic = modifier; break; - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: if (flags & 1 /* Export */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); } @@ -26264,42 +26864,42 @@ var ts; else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= 1 /* Export */; break; - case 120 /* DeclareKeyword */: + case 122 /* DeclareKeyword */: if (flags & 2 /* Ambient */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } - else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 217 /* ModuleBlock */) { + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 219 /* ModuleBlock */) { return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= 2 /* Ambient */; lastDeclare = modifier; break; - case 113 /* AbstractKeyword */: + case 115 /* AbstractKeyword */: if (flags & 256 /* Abstract */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract"); } - if (node.kind !== 212 /* ClassDeclaration */) { - if (node.kind !== 141 /* MethodDeclaration */) { + if (node.kind !== 214 /* ClassDeclaration */) { + if (node.kind !== 143 /* MethodDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration); } - if (!(node.parent.kind === 212 /* ClassDeclaration */ && node.parent.flags & 256 /* Abstract */)) { + if (!(node.parent.kind === 214 /* ClassDeclaration */ && node.parent.flags & 256 /* Abstract */)) { return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); } if (flags & 128 /* Static */) { @@ -26311,14 +26911,14 @@ var ts; } flags |= 256 /* Abstract */; break; - case 116 /* AsyncKeyword */: + case 118 /* AsyncKeyword */: if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async"); } else if (flags & 2 /* Ambient */ || ts.isInAmbientContext(node.parent)) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); } flags |= 512 /* Async */; @@ -26326,7 +26926,7 @@ var ts; break; } } - if (node.kind === 142 /* Constructor */) { + if (node.kind === 144 /* Constructor */) { if (flags & 128 /* Static */) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); } @@ -26344,10 +26944,10 @@ var ts; } return; } - else if ((node.kind === 220 /* ImportDeclaration */ || node.kind === 219 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) { + else if ((node.kind === 222 /* ImportDeclaration */ || node.kind === 221 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 136 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { + else if (node.kind === 138 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } if (flags & 512 /* Async */) { @@ -26359,10 +26959,10 @@ var ts; return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher); } switch (node.kind) { - case 141 /* MethodDeclaration */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: if (!node.asteriskToken) { return false; } @@ -26428,7 +27028,7 @@ var ts; checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } function checkGrammarArrowFunction(node, file) { - if (node.kind === 172 /* ArrowFunction */) { + if (node.kind === 174 /* ArrowFunction */) { var arrowFunction = node; var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line; var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line; @@ -26463,7 +27063,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 128 /* StringKeyword */ && parameter.type.kind !== 126 /* NumberKeyword */) { + if (parameter.type.kind !== 130 /* StringKeyword */ && parameter.type.kind !== 128 /* NumberKeyword */) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -26496,7 +27096,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var _i = 0; _i < args.length; _i++) { var arg = args[_i]; - if (arg.kind === 185 /* OmittedExpression */) { + if (arg.kind === 187 /* OmittedExpression */) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -26523,7 +27123,7 @@ var ts; if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81 /* ExtendsKeyword */) { + if (heritageClause.token === 83 /* ExtendsKeyword */) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } @@ -26536,7 +27136,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 106 /* ImplementsKeyword */); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -26552,14 +27152,14 @@ var ts; if (node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81 /* ExtendsKeyword */) { + if (heritageClause.token === 83 /* ExtendsKeyword */) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 106 /* ImplementsKeyword */); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } // Grammar checking heritageClause inside class declaration @@ -26570,19 +27170,19 @@ var ts; } function checkGrammarComputedPropertyName(node) { // If node is not a computedPropertyName, just skip the grammar checking - if (node.kind !== 134 /* ComputedPropertyName */) { + if (node.kind !== 136 /* ComputedPropertyName */) { return false; } var computedPropertyName = node; - if (computedPropertyName.expression.kind === 179 /* BinaryExpression */ && computedPropertyName.expression.operatorToken.kind === 24 /* CommaToken */) { + if (computedPropertyName.expression.kind === 181 /* BinaryExpression */ && computedPropertyName.expression.operatorToken.kind === 24 /* CommaToken */) { return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - ts.Debug.assert(node.kind === 211 /* FunctionDeclaration */ || - node.kind === 171 /* FunctionExpression */ || - node.kind === 141 /* MethodDeclaration */); + ts.Debug.assert(node.kind === 213 /* FunctionDeclaration */ || + node.kind === 173 /* FunctionExpression */ || + node.kind === 143 /* MethodDeclaration */); if (ts.isInAmbientContext(node)) { return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); } @@ -26599,7 +27199,7 @@ var ts; return grammarErrorOnNode(questionToken, message); } } - function checkGrammarObjectLiteralExpression(node) { + function checkGrammarObjectLiteralExpression(node, inDestructuring) { var seen = {}; var Property = 1; var GetAccessor = 2; @@ -26608,12 +27208,17 @@ var ts; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; var name_16 = prop.name; - if (prop.kind === 185 /* OmittedExpression */ || - name_16.kind === 134 /* ComputedPropertyName */) { + if (prop.kind === 187 /* OmittedExpression */ || + name_16.kind === 136 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it checkGrammarComputedPropertyName(name_16); continue; } + if (prop.kind === 246 /* ShorthandPropertyAssignment */ && !inDestructuring && prop.objectAssignmentInitializer) { + // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern + // outside of destructuring it is a syntax error + return grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment); + } // ECMA-262 11.1.5 Object Initialiser // If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true // a.This production is contained in strict code and IsDataDescriptor(previous) is true and @@ -26623,7 +27228,7 @@ var ts; // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields var currentKind = void 0; - if (prop.kind === 243 /* PropertyAssignment */ || prop.kind === 244 /* ShorthandPropertyAssignment */) { + if (prop.kind === 245 /* PropertyAssignment */ || prop.kind === 246 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); if (name_16.kind === 8 /* NumericLiteral */) { @@ -26631,13 +27236,13 @@ var ts; } currentKind = Property; } - else if (prop.kind === 141 /* MethodDeclaration */) { + else if (prop.kind === 143 /* MethodDeclaration */) { currentKind = Property; } - else if (prop.kind === 143 /* GetAccessor */) { + else if (prop.kind === 145 /* GetAccessor */) { currentKind = GetAccessor; } - else if (prop.kind === 144 /* SetAccessor */) { + else if (prop.kind === 146 /* SetAccessor */) { currentKind = SetAccesor; } else { @@ -26669,7 +27274,7 @@ var ts; var seen = {}; for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) { var attr = _a[_i]; - if (attr.kind === 237 /* JsxSpreadAttribute */) { + if (attr.kind === 239 /* JsxSpreadAttribute */) { continue; } var jsxAttr = attr; @@ -26681,7 +27286,7 @@ var ts; return grammarErrorOnNode(name_17, ts.Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name); } var initializer = jsxAttr.initializer; - if (initializer && initializer.kind === 238 /* JsxExpression */ && !initializer.expression) { + if (initializer && initializer.kind === 240 /* JsxExpression */ && !initializer.expression) { return grammarErrorOnNode(jsxAttr.initializer, ts.Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression); } } @@ -26690,24 +27295,24 @@ var ts; if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) { return true; } - if (forInOrOfStatement.initializer.kind === 210 /* VariableDeclarationList */) { + if (forInOrOfStatement.initializer.kind === 212 /* VariableDeclarationList */) { var variableList = forInOrOfStatement.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { - var diagnostic = forInOrOfStatement.kind === 198 /* ForInStatement */ + var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */ ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic); } var firstDeclaration = variableList.declarations[0]; if (firstDeclaration.initializer) { - var diagnostic = forInOrOfStatement.kind === 198 /* ForInStatement */ + var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */ ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; return grammarErrorOnNode(firstDeclaration.name, diagnostic); } if (firstDeclaration.type) { - var diagnostic = forInOrOfStatement.kind === 198 /* ForInStatement */ + var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */ ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; return grammarErrorOnNode(firstDeclaration, diagnostic); @@ -26730,10 +27335,10 @@ var ts; else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } - else if (kind === 143 /* GetAccessor */ && accessor.parameters.length) { + else if (kind === 145 /* GetAccessor */ && accessor.parameters.length) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); } - else if (kind === 144 /* SetAccessor */) { + else if (kind === 146 /* SetAccessor */) { if (accessor.type) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); } @@ -26758,7 +27363,7 @@ var ts; } } function checkGrammarForNonSymbolComputedProperty(node, message) { - if (node.kind === 134 /* ComputedPropertyName */ && !ts.isWellKnownSymbolSyntactically(node.expression)) { + if (node.kind === 136 /* ComputedPropertyName */ && !ts.isWellKnownSymbolSyntactically(node.expression)) { return grammarErrorOnNode(node, message); } } @@ -26768,7 +27373,7 @@ var ts; checkGrammarForGenerator(node)) { return true; } - if (node.parent.kind === 163 /* ObjectLiteralExpression */) { + if (node.parent.kind === 165 /* ObjectLiteralExpression */) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -26792,22 +27397,22 @@ var ts; return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol); } } - else if (node.parent.kind === 213 /* InterfaceDeclaration */) { + else if (node.parent.kind === 215 /* InterfaceDeclaration */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol); } - else if (node.parent.kind === 153 /* TypeLiteral */) { + else if (node.parent.kind === 155 /* TypeLiteral */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol); } } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: return true; - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -26819,11 +27424,11 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: if (node.label && current.label.text === node.label.text) { // found matching label - verify that label usage is correct // continue can only target labels that are on iteration statements - var isMisplacedContinueLabel = node.kind === 200 /* ContinueStatement */ + var isMisplacedContinueLabel = node.kind === 202 /* ContinueStatement */ && !isIterationStatement(current.statement, /*lookInLabeledStatement*/ true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); @@ -26831,8 +27436,8 @@ var ts; return false; } break; - case 204 /* SwitchStatement */: - if (node.kind === 201 /* BreakStatement */ && !node.label) { + case 206 /* SwitchStatement */: + if (node.kind === 203 /* BreakStatement */ && !node.label) { // unlabeled break within switch statement - ok return false; } @@ -26847,13 +27452,13 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 201 /* BreakStatement */ + var message = node.kind === 203 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 201 /* BreakStatement */ + var message = node.kind === 203 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); @@ -26865,7 +27470,7 @@ var ts; if (node !== ts.lastOrUndefined(elements)) { return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); } - if (node.name.kind === 160 /* ArrayBindingPattern */ || node.name.kind === 159 /* ObjectBindingPattern */) { + if (node.name.kind === 162 /* ArrayBindingPattern */ || node.name.kind === 161 /* ObjectBindingPattern */) { return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); } if (node.initializer) { @@ -26875,7 +27480,7 @@ var ts; } } function checkGrammarVariableDeclaration(node) { - if (node.parent.parent.kind !== 198 /* ForInStatement */ && node.parent.parent.kind !== 199 /* ForOfStatement */) { + if (node.parent.parent.kind !== 200 /* ForInStatement */ && node.parent.parent.kind !== 201 /* ForOfStatement */) { if (ts.isInAmbientContext(node)) { if (node.initializer) { // Error on equals token which immediate precedes the initializer @@ -26902,7 +27507,7 @@ var ts; return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name); } function checkGrammarNameInLetOrConstDeclarations(name) { - if (name.kind === 67 /* Identifier */) { + if (name.kind === 69 /* Identifier */) { if (name.text === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } @@ -26911,7 +27516,7 @@ var ts; var elements = name.elements; for (var _i = 0; _i < elements.length; _i++) { var element = elements[_i]; - if (element.kind !== 185 /* OmittedExpression */) { + if (element.kind !== 187 /* OmittedExpression */) { checkGrammarNameInLetOrConstDeclarations(element.name); } } @@ -26928,15 +27533,15 @@ var ts; } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return false; - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return allowLetAndConstDeclarations(parent.parent); } return true; @@ -26952,7 +27557,7 @@ var ts; } } function isIntegerLiteral(expression) { - if (expression.kind === 177 /* PrefixUnaryExpression */) { + if (expression.kind === 179 /* PrefixUnaryExpression */) { var unaryExpression = expression; if (unaryExpression.operator === 35 /* PlusToken */ || unaryExpression.operator === 36 /* MinusToken */) { expression = unaryExpression.operand; @@ -26968,37 +27573,6 @@ var ts; } return false; } - function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 32768 /* Const */) !== 0; - var hasError = false; - // skip checks below for const enums - they allow arbitrary initializers as long as they can be evaluated to constant expressions. - // since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members. - if (!enumIsConst) { - var inConstantEnumMemberSection = true; - var inAmbientContext = ts.isInAmbientContext(enumDecl); - for (var _i = 0, _a = enumDecl.members; _i < _a.length; _i++) { - var node = _a[_i]; - // Do not use hasDynamicName here, because that returns false for well known symbols. - // We want to perform checkComputedPropertyName for all computed properties, including - // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); - } - else if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer)) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; - } - } - else if (node.initializer) { - inConstantEnumMemberSection = isIntegerLiteral(node.initializer); - } - else if (!inConstantEnumMemberSection) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; - } - } - } - return hasError; - } function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } @@ -27024,7 +27598,7 @@ var ts; } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 /* Identifier */ && + return node.kind === 69 /* Identifier */ && (node.text === "eval" || node.text === "arguments"); } function checkGrammarConstructorTypeParameters(node) { @@ -27044,12 +27618,12 @@ var ts; return true; } } - else if (node.parent.kind === 213 /* InterfaceDeclaration */) { + else if (node.parent.kind === 215 /* InterfaceDeclaration */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } } - else if (node.parent.kind === 153 /* TypeLiteral */) { + else if (node.parent.kind === 155 /* TypeLiteral */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } @@ -27069,11 +27643,11 @@ var ts; // export_opt ExternalImportDeclaration // export_opt AmbientDeclaration // - if (node.kind === 213 /* InterfaceDeclaration */ || - node.kind === 220 /* ImportDeclaration */ || - node.kind === 219 /* ImportEqualsDeclaration */ || - node.kind === 226 /* ExportDeclaration */ || - node.kind === 225 /* ExportAssignment */ || + if (node.kind === 215 /* InterfaceDeclaration */ || + node.kind === 222 /* ImportDeclaration */ || + node.kind === 221 /* ImportEqualsDeclaration */ || + node.kind === 228 /* ExportDeclaration */ || + node.kind === 227 /* ExportAssignment */ || (node.flags & 2 /* Ambient */) || (node.flags & (1 /* Export */ | 1024 /* Default */))) { return false; @@ -27083,7 +27657,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var decl = _a[_i]; - if (ts.isDeclaration(decl) || decl.kind === 191 /* VariableStatement */) { + if (ts.isDeclaration(decl) || decl.kind === 193 /* VariableStatement */) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -27109,7 +27683,7 @@ var ts; // to prevent noisyness. So use a bit on the block to indicate if // this has already been reported, and don't report if it has. // - if (node.parent.kind === 190 /* Block */ || node.parent.kind === 217 /* ModuleBlock */ || node.parent.kind === 246 /* SourceFile */) { + if (node.parent.kind === 192 /* Block */ || node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) { var links_1 = getNodeLinks(node.parent); // Check if the containing block ever report this error if (!links_1.hasReportedStatementInAmbientContext) { @@ -27160,6 +27734,7 @@ var ts; var enclosingDeclaration; var currentSourceFile; var reportedDeclarationError = false; + var errorNameNode; var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments; var emit = compilerOptions.stripInternal ? stripInternal : emitNode; var moduleElementDeclarationEmitInfo = []; @@ -27191,7 +27766,7 @@ var ts; var oldWriter = writer; ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) { if (aliasEmitInfo.isVisible) { - ts.Debug.assert(aliasEmitInfo.node.kind === 220 /* ImportDeclaration */); + ts.Debug.assert(aliasEmitInfo.node.kind === 222 /* ImportDeclaration */); createAndSetNewTextWriterWithSymbolWriter(); ts.Debug.assert(aliasEmitInfo.indent === 0); writeImportDeclaration(aliasEmitInfo.node); @@ -27245,6 +27820,7 @@ var ts; function createAndSetNewTextWriterWithSymbolWriter() { var writer = ts.createTextWriter(newLine); writer.trackSymbol = trackSymbol; + writer.reportInaccessibleThisError = reportInaccessibleThisError; writer.writeKeyword = writer.write; writer.writeOperator = writer.write; writer.writePunctuation = writer.write; @@ -27267,10 +27843,10 @@ var ts; var oldWriter = writer; ts.forEach(nodes, function (declaration) { var nodeToCheck; - if (declaration.kind === 209 /* VariableDeclaration */) { + if (declaration.kind === 211 /* VariableDeclaration */) { nodeToCheck = declaration.parent.parent; } - else if (declaration.kind === 223 /* NamedImports */ || declaration.kind === 224 /* ImportSpecifier */ || declaration.kind === 221 /* ImportClause */) { + else if (declaration.kind === 225 /* NamedImports */ || declaration.kind === 226 /* ImportSpecifier */ || declaration.kind === 223 /* ImportClause */) { ts.Debug.fail("We should be getting ImportDeclaration instead to write"); } else { @@ -27288,7 +27864,7 @@ var ts; // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, // we would write alias foo declaration when we visit it since it would now be marked as visible if (moduleElementEmitInfo) { - if (moduleElementEmitInfo.node.kind === 220 /* ImportDeclaration */) { + if (moduleElementEmitInfo.node.kind === 222 /* ImportDeclaration */) { // we have to create asynchronous output only after we have collected complete information // because it is possible to enable multiple bindings as asynchronously visible moduleElementEmitInfo.isVisible = true; @@ -27298,12 +27874,12 @@ var ts; for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { increaseIndent(); } - if (nodeToCheck.kind === 216 /* ModuleDeclaration */) { + if (nodeToCheck.kind === 218 /* ModuleDeclaration */) { ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); asynchronousSubModuleDeclarationEmitInfo = []; } writeModuleElement(nodeToCheck); - if (nodeToCheck.kind === 216 /* ModuleDeclaration */) { + if (nodeToCheck.kind === 218 /* ModuleDeclaration */) { moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; asynchronousSubModuleDeclarationEmitInfo = undefined; } @@ -27337,6 +27913,11 @@ var ts; function trackSymbol(symbol, enclosingDeclaration, meaning) { handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); } + function reportInaccessibleThisError() { + if (errorNameNode) { + diagnostics.push(ts.createDiagnosticForNode(errorNameNode, ts.Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, ts.declarationNameToString(errorNameNode))); + } + } function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; write(": "); @@ -27345,7 +27926,9 @@ var ts; emitType(type); } else { + errorNameNode = declaration.name; resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + errorNameNode = undefined; } } function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { @@ -27356,7 +27939,9 @@ var ts; emitType(signature.type); } else { + errorNameNode = signature.name; resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + errorNameNode = undefined; } } function emitLines(nodes) { @@ -27395,49 +27980,50 @@ var ts; } function emitType(type) { switch (type.kind) { - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: - case 101 /* VoidKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: + case 97 /* ThisKeyword */: case 9 /* StringLiteral */: return writeTextOfNode(currentSourceFile, type); - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return emitExpressionWithTypeArguments(type); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return emitTypeReference(type); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return emitTypeQuery(type); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return emitArrayType(type); - case 155 /* TupleType */: + case 157 /* TupleType */: return emitTupleType(type); - case 156 /* UnionType */: + case 158 /* UnionType */: return emitUnionType(type); - case 157 /* IntersectionType */: + case 159 /* IntersectionType */: return emitIntersectionType(type); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return emitParenType(type); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return emitSignatureDeclarationWithJsDocComments(type); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return emitTypeLiteral(type); - case 67 /* Identifier */: + case 69 /* Identifier */: return emitEntityName(type); - case 133 /* QualifiedName */: + case 135 /* QualifiedName */: return emitEntityName(type); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return emitTypePredicate(type); } function writeEntityName(entityName) { - if (entityName.kind === 67 /* Identifier */) { + if (entityName.kind === 69 /* Identifier */) { writeTextOfNode(currentSourceFile, entityName); } else { - var left = entityName.kind === 133 /* QualifiedName */ ? entityName.left : entityName.expression; - var right = entityName.kind === 133 /* QualifiedName */ ? entityName.right : entityName.name; + var left = entityName.kind === 135 /* QualifiedName */ ? entityName.left : entityName.expression; + var right = entityName.kind === 135 /* QualifiedName */ ? entityName.right : entityName.name; writeEntityName(left); write("."); writeTextOfNode(currentSourceFile, right); @@ -27446,13 +28032,13 @@ var ts; function emitEntityName(entityName) { var visibilityResult = resolver.isEntityNameVisible(entityName, // Aliases can be written asynchronously so use correct enclosing declaration - entityName.parent.kind === 219 /* ImportEqualsDeclaration */ ? entityName.parent : enclosingDeclaration); + entityName.parent.kind === 221 /* ImportEqualsDeclaration */ ? entityName.parent : enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); } function emitExpressionWithTypeArguments(node) { if (ts.isSupportedExpressionWithTypeArguments(node)) { - ts.Debug.assert(node.expression.kind === 67 /* Identifier */ || node.expression.kind === 164 /* PropertyAccessExpression */); + ts.Debug.assert(node.expression.kind === 69 /* Identifier */ || node.expression.kind === 166 /* PropertyAccessExpression */); emitEntityName(node.expression); if (node.typeArguments) { write("<"); @@ -27533,7 +28119,7 @@ var ts; } } function emitExportAssignment(node) { - if (node.expression.kind === 67 /* Identifier */) { + if (node.expression.kind === 69 /* Identifier */) { write(node.isExportEquals ? "export = " : "export default "); writeTextOfNode(currentSourceFile, node.expression); } @@ -27553,7 +28139,7 @@ var ts; write(";"); writeLine(); // Make all the declarations visible for the export name - if (node.expression.kind === 67 /* Identifier */) { + if (node.expression.kind === 69 /* Identifier */) { var nodes = resolver.collectLinkedAliases(node.expression); // write each of these declarations asynchronously writeAsynchronousModuleElements(nodes); @@ -27572,10 +28158,10 @@ var ts; if (isModuleElementVisible) { writeModuleElement(node); } - else if (node.kind === 219 /* ImportEqualsDeclaration */ || - (node.parent.kind === 246 /* SourceFile */ && ts.isExternalModule(currentSourceFile))) { + else if (node.kind === 221 /* ImportEqualsDeclaration */ || + (node.parent.kind === 248 /* SourceFile */ && ts.isExternalModule(currentSourceFile))) { var isVisible; - if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 246 /* SourceFile */) { + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 248 /* SourceFile */) { // Import declaration of another module that is visited async so lets put it in right spot asynchronousSubModuleDeclarationEmitInfo.push({ node: node, @@ -27585,7 +28171,7 @@ var ts; }); } else { - if (node.kind === 220 /* ImportDeclaration */) { + if (node.kind === 222 /* ImportDeclaration */) { var importDeclaration = node; if (importDeclaration.importClause) { isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || @@ -27603,23 +28189,23 @@ var ts; } function writeModuleElement(node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return writeFunctionDeclaration(node); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return writeVariableStatement(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return writeInterfaceDeclaration(node); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return writeClassDeclaration(node); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return writeTypeAliasDeclaration(node); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return writeEnumDeclaration(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return writeModuleDeclaration(node); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return writeImportEqualsDeclaration(node); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: return writeImportDeclaration(node); default: ts.Debug.fail("Unknown symbol kind"); @@ -27635,7 +28221,7 @@ var ts; if (node.flags & 1024 /* Default */) { write("default "); } - else if (node.kind !== 213 /* InterfaceDeclaration */) { + else if (node.kind !== 215 /* InterfaceDeclaration */) { write("declare "); } } @@ -27684,7 +28270,7 @@ var ts; } function isVisibleNamedBinding(namedBindings) { if (namedBindings) { - if (namedBindings.kind === 222 /* NamespaceImport */) { + if (namedBindings.kind === 224 /* NamespaceImport */) { return resolver.isDeclarationVisible(namedBindings); } else { @@ -27712,7 +28298,7 @@ var ts; // If the default binding was emitted, write the separated write(", "); } - if (node.importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (node.importClause.namedBindings.kind === 224 /* NamespaceImport */) { write("* as "); writeTextOfNode(currentSourceFile, node.importClause.namedBindings.name); } @@ -27770,7 +28356,7 @@ var ts; write("module "); } writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 217 /* ModuleBlock */) { + while (node.body.kind !== 219 /* ModuleBlock */) { node = node.body; write("."); writeTextOfNode(currentSourceFile, node.name); @@ -27835,7 +28421,7 @@ var ts; writeLine(); } function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 141 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); + return node.parent.kind === 143 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); } function emitTypeParameters(typeParameters) { function emitTypeParameter(node) { @@ -27846,15 +28432,15 @@ var ts; // If there is constraint present and this is not a type parameter of the private method emit the constraint if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); - if (node.parent.kind === 150 /* FunctionType */ || - node.parent.kind === 151 /* ConstructorType */ || - (node.parent.parent && node.parent.parent.kind === 153 /* TypeLiteral */)) { - ts.Debug.assert(node.parent.kind === 141 /* MethodDeclaration */ || - node.parent.kind === 140 /* MethodSignature */ || - node.parent.kind === 150 /* FunctionType */ || - node.parent.kind === 151 /* ConstructorType */ || - node.parent.kind === 145 /* CallSignature */ || - node.parent.kind === 146 /* ConstructSignature */); + if (node.parent.kind === 152 /* FunctionType */ || + node.parent.kind === 153 /* ConstructorType */ || + (node.parent.parent && node.parent.parent.kind === 155 /* TypeLiteral */)) { + ts.Debug.assert(node.parent.kind === 143 /* MethodDeclaration */ || + node.parent.kind === 142 /* MethodSignature */ || + node.parent.kind === 152 /* FunctionType */ || + node.parent.kind === 153 /* ConstructorType */ || + node.parent.kind === 147 /* CallSignature */ || + node.parent.kind === 148 /* ConstructSignature */); emitType(node.constraint); } else { @@ -27865,31 +28451,31 @@ var ts; // Type parameter constraints are named by user so we should always be able to name it var diagnosticMessage; switch (node.parent.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 145 /* CallSignature */: + case 147 /* CallSignature */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.parent.flags & 128 /* Static */) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 214 /* ClassDeclaration */) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -27917,13 +28503,13 @@ var ts; if (ts.isSupportedExpressionWithTypeArguments(node)) { emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); } - else if (!isImplementsList && node.expression.kind === 91 /* NullKeyword */) { + else if (!isImplementsList && node.expression.kind === 93 /* NullKeyword */) { write("null"); } function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; // Heritage clause is written by user so it can always be named - if (node.parent.parent.kind === 212 /* ClassDeclaration */) { + if (node.parent.parent.kind === 214 /* ClassDeclaration */) { // Class or Interface implemented/extended is inaccessible diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : @@ -28007,7 +28593,7 @@ var ts; function emitVariableDeclaration(node) { // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted // so there is no check needed to see if declaration is visible - if (node.kind !== 209 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + if (node.kind !== 211 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { if (ts.isBindingPattern(node.name)) { emitBindingPattern(node.name); } @@ -28017,10 +28603,10 @@ var ts; // what we want, namely the name expression enclosed in brackets. writeTextOfNode(currentSourceFile, node.name); // If optional property emit ? - if ((node.kind === 139 /* PropertyDeclaration */ || node.kind === 138 /* PropertySignature */) && ts.hasQuestionToken(node)) { + if ((node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) && ts.hasQuestionToken(node)) { write("?"); } - if ((node.kind === 139 /* PropertyDeclaration */ || node.kind === 138 /* PropertySignature */) && node.parent.kind === 153 /* TypeLiteral */) { + if ((node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) && node.parent.kind === 155 /* TypeLiteral */) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & 32 /* Private */)) { @@ -28029,14 +28615,14 @@ var ts; } } function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { - if (node.kind === 209 /* VariableDeclaration */) { + if (node.kind === 211 /* VariableDeclaration */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } - else if (node.kind === 139 /* PropertyDeclaration */ || node.kind === 138 /* PropertySignature */) { + else if (node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & 128 /* Static */) { return symbolAccesibilityResult.errorModuleName ? @@ -28045,7 +28631,7 @@ var ts; ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -28077,7 +28663,7 @@ var ts; var elements = []; for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.kind !== 185 /* OmittedExpression */) { + if (element.kind !== 187 /* OmittedExpression */) { elements.push(element); } } @@ -28147,7 +28733,7 @@ var ts; var type = getTypeAnnotationFromAccessor(node); if (!type) { // couldn't get type for the first accessor, try the another one - var anotherAccessor = node.kind === 143 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; + var anotherAccessor = node.kind === 145 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; type = getTypeAnnotationFromAccessor(anotherAccessor); if (type) { accessorWithTypeAnnotation = anotherAccessor; @@ -28160,7 +28746,7 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 143 /* GetAccessor */ + return accessor.kind === 145 /* GetAccessor */ ? accessor.type // Getter - return type : accessor.parameters.length > 0 ? accessor.parameters[0].type // Setter parameter type @@ -28169,7 +28755,7 @@ var ts; } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 144 /* SetAccessor */) { + if (accessorWithTypeAnnotation.kind === 146 /* SetAccessor */) { // Setters have to have type named and cannot infer it so, the type should always be named if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? @@ -28219,17 +28805,17 @@ var ts; // so no need to verify if the declaration is visible if (!resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); - if (node.kind === 211 /* FunctionDeclaration */) { + if (node.kind === 213 /* FunctionDeclaration */) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === 141 /* MethodDeclaration */) { + else if (node.kind === 143 /* MethodDeclaration */) { emitClassMemberDeclarationFlags(node); } - if (node.kind === 211 /* FunctionDeclaration */) { + if (node.kind === 213 /* FunctionDeclaration */) { write("function "); writeTextOfNode(currentSourceFile, node.name); } - else if (node.kind === 142 /* Constructor */) { + else if (node.kind === 144 /* Constructor */) { write("constructor"); } else { @@ -28247,11 +28833,11 @@ var ts; } function emitSignatureDeclaration(node) { // Construct signature or constructor type write new Signature - if (node.kind === 146 /* ConstructSignature */ || node.kind === 151 /* ConstructorType */) { + if (node.kind === 148 /* ConstructSignature */ || node.kind === 153 /* ConstructorType */) { write("new "); } emitTypeParameters(node.typeParameters); - if (node.kind === 147 /* IndexSignature */) { + if (node.kind === 149 /* IndexSignature */) { write("["); } else { @@ -28261,22 +28847,22 @@ var ts; enclosingDeclaration = node; // Parameters emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 147 /* IndexSignature */) { + if (node.kind === 149 /* IndexSignature */) { write("]"); } else { write(")"); } // If this is not a constructor and is not private, emit the return type - var isFunctionTypeOrConstructorType = node.kind === 150 /* FunctionType */ || node.kind === 151 /* ConstructorType */; - if (isFunctionTypeOrConstructorType || node.parent.kind === 153 /* TypeLiteral */) { + var isFunctionTypeOrConstructorType = node.kind === 152 /* FunctionType */ || node.kind === 153 /* ConstructorType */; + if (isFunctionTypeOrConstructorType || node.parent.kind === 155 /* TypeLiteral */) { // Emit type literal signature return type only if specified if (node.type) { write(isFunctionTypeOrConstructorType ? " => " : ": "); emitType(node.type); } } - else if (node.kind !== 142 /* Constructor */ && !(node.flags & 32 /* Private */)) { + else if (node.kind !== 144 /* Constructor */ && !(node.flags & 32 /* Private */)) { writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); } enclosingDeclaration = prevEnclosingDeclaration; @@ -28287,26 +28873,26 @@ var ts; function getReturnTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.kind) { - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 145 /* CallSignature */: + case 147 /* CallSignature */: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? @@ -28314,7 +28900,7 @@ var ts; ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -28328,7 +28914,7 @@ var ts; ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -28363,9 +28949,9 @@ var ts; write("?"); } decreaseIndent(); - if (node.parent.kind === 150 /* FunctionType */ || - node.parent.kind === 151 /* ConstructorType */ || - node.parent.parent.kind === 153 /* TypeLiteral */) { + if (node.parent.kind === 152 /* FunctionType */ || + node.parent.kind === 153 /* ConstructorType */ || + node.parent.parent.kind === 155 /* TypeLiteral */) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.parent.flags & 32 /* Private */)) { @@ -28381,24 +28967,24 @@ var ts; } function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { switch (node.parent.kind) { - case 142 /* Constructor */: + case 144 /* Constructor */: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: // Interfaces cannot have parameter types that cannot be named return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - case 145 /* CallSignature */: + case 147 /* CallSignature */: // Interfaces cannot have parameter types that cannot be named return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.parent.flags & 128 /* Static */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? @@ -28406,7 +28992,7 @@ var ts; ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 214 /* ClassDeclaration */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -28419,7 +29005,7 @@ var ts; ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -28431,12 +29017,12 @@ var ts; } function emitBindingPattern(bindingPattern) { // We have to explicitly emit square bracket and bracket because these tokens are not store inside the node. - if (bindingPattern.kind === 159 /* ObjectBindingPattern */) { + if (bindingPattern.kind === 161 /* ObjectBindingPattern */) { write("{"); emitCommaList(bindingPattern.elements, emitBindingElement); write("}"); } - else if (bindingPattern.kind === 160 /* ArrayBindingPattern */) { + else if (bindingPattern.kind === 162 /* ArrayBindingPattern */) { write("["); var elements = bindingPattern.elements; emitCommaList(elements, emitBindingElement); @@ -28455,7 +29041,7 @@ var ts; typeName: bindingElement.name } : undefined; } - if (bindingElement.kind === 185 /* OmittedExpression */) { + if (bindingElement.kind === 187 /* OmittedExpression */) { // If bindingElement is an omittedExpression (i.e. containing elision), // we will emit blank space (although this may differ from users' original code, // it allows emitSeparatedList to write separator appropriately) @@ -28464,7 +29050,7 @@ var ts; // emit : function foo([ , x, , ]) {} write(" "); } - else if (bindingElement.kind === 161 /* BindingElement */) { + else if (bindingElement.kind === 163 /* BindingElement */) { if (bindingElement.propertyName) { // bindingElement has propertyName property in the following case: // { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y" @@ -28487,7 +29073,7 @@ var ts; emitBindingPattern(bindingElement.name); } else { - ts.Debug.assert(bindingElement.name.kind === 67 /* Identifier */); + ts.Debug.assert(bindingElement.name.kind === 69 /* Identifier */); // If the node is just an identifier, we will simply emit the text associated with the node's name // Example: // original: function foo({y = 10, x}) {} @@ -28503,40 +29089,40 @@ var ts; } function emitNode(node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: - case 216 /* ModuleDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 213 /* InterfaceDeclaration */: - case 212 /* ClassDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 215 /* EnumDeclaration */: + case 213 /* FunctionDeclaration */: + case 218 /* ModuleDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 215 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 217 /* EnumDeclaration */: return emitModuleElement(node, isModuleElementVisible(node)); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return emitModuleElement(node, isVariableStatementVisible(node)); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: // Import declaration without import clause is visible, otherwise it is not visible return emitModuleElement(node, /*isModuleElementVisible*/ !node.importClause); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return emitExportDeclaration(node); - case 142 /* Constructor */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 144 /* Constructor */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return writeFunctionDeclaration(node); - case 146 /* ConstructSignature */: - case 145 /* CallSignature */: - case 147 /* IndexSignature */: + case 148 /* ConstructSignature */: + case 147 /* CallSignature */: + case 149 /* IndexSignature */: return emitSignatureDeclarationWithJsDocComments(node); - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return emitAccessorDeclaration(node); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return emitPropertyDeclaration(node); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return emitEnumMemberDeclaration(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return emitExportAssignment(node); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return emitSourceFile(node); } } @@ -28587,6425 +29173,6 @@ var ts; return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; - // Flags enum to track count of temp variables and a few dedicated names - var TempFlags; - (function (TempFlags) { - TempFlags[TempFlags["Auto"] = 0] = "Auto"; - TempFlags[TempFlags["CountMask"] = 268435455] = "CountMask"; - TempFlags[TempFlags["_i"] = 268435456] = "_i"; - })(TempFlags || (TempFlags = {})); - // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature - function emitFiles(resolver, host, targetSourceFile) { - // emit output for the __extends helper function - var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; - // emit output for the __decorate helper function - var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; - // emit output for the __metadata helper function - var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; - // emit output for the __param helper function - var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; - var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; - var compilerOptions = host.getCompilerOptions(); - var languageVersion = compilerOptions.target || 0 /* ES3 */; - var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; - var diagnostics = []; - var newLine = host.getNewLine(); - var jsxDesugaring = host.getCompilerOptions().jsx !== 1 /* Preserve */; - var shouldEmitJsx = function (s) { return (s.languageVariant === 1 /* JSX */ && !jsxDesugaring); }; - if (targetSourceFile === undefined) { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, sourceFile); - } - }); - if (compilerOptions.outFile || compilerOptions.out) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - else { - // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service) - if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, targetSourceFile); - } - else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - // Sort and make the unique list of diagnostics - diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); - return { - emitSkipped: false, - diagnostics: diagnostics, - sourceMaps: sourceMapDataList - }; - function isNodeDescendentOf(node, ancestor) { - while (node) { - if (node === ancestor) - return true; - node = node.parent; - } - return false; - } - function isUniqueLocalName(name, container) { - for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && ts.hasProperty(node.locals, name)) { - // We conservatively include alias symbols to cover cases where they're emitted as locals - if (node.locals[name].flags & (107455 /* Value */ | 1048576 /* ExportValue */ | 8388608 /* Alias */)) { - return false; - } - } - } - return true; - } - function emitJavaScript(jsFilePath, root) { - var writer = ts.createTextWriter(newLine); - var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; - var currentSourceFile; - // name of an exporter function if file is a System external module - // System.register([...], function () {...}) - // exporting in System modules looks like: - // export var x; ... x = 1 - // => - // var x;... exporter("x", x = 1) - var exportFunctionForFile; - var generatedNameSet = {}; - var nodeToGeneratedName = []; - var computedPropertyNamesToGeneratedNames; - var extendsEmitted = false; - var decorateEmitted = false; - var paramEmitted = false; - var awaiterEmitted = false; - var tempFlags = 0; - var tempVariables; - var tempParameters; - var externalImports; - var exportSpecifiers; - var exportEquals; - var hasExportStars; - /** Write emitted output to disk */ - var writeEmittedFiles = writeJavaScriptFile; - var detachedCommentsInfo; - var writeComment = ts.writeCommentRange; - /** Emit a node */ - var emit = emitNodeWithCommentsAndWithoutSourcemap; - /** Called just before starting emit of a node */ - var emitStart = function (node) { }; - /** Called once the emit of the node is done */ - var emitEnd = function (node) { }; - /** Emit the text for the given token that comes after startPos - * This by default writes the text provided with the given tokenKind - * but if optional emitFn callback is provided the text is emitted using the callback instead of default text - * @param tokenKind the kind of the token to search and emit - * @param startPos the position in the source to start searching for the token - * @param emitFn if given will be invoked to emit the text instead of actual token emit */ - var emitToken = emitTokenText; - /** Called to before starting the lexical scopes as in function/class in the emitted code because of node - * @param scopeDeclaration node that starts the lexical scope - * @param scopeName Optional name of this scope instead of deducing one from the declaration node */ - var scopeEmitStart = function (scopeDeclaration, scopeName) { }; - /** Called after coming out of the scope */ - var scopeEmitEnd = function () { }; - /** Sourcemap data that will get encoded */ - var sourceMapData; - /** If removeComments is true, no leading-comments needed to be emitted **/ - var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; - if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { - initializeEmitterWithSourceMaps(); - } - if (root) { - // Do not call emit directly. It does not set the currentSourceFile. - emitSourceFile(root); - } - else { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - emitSourceFile(sourceFile); - } - }); - } - writeLine(); - writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); - return; - function emitSourceFile(sourceFile) { - currentSourceFile = sourceFile; - exportFunctionForFile = undefined; - emit(sourceFile); - } - function isUniqueName(name) { - return !resolver.hasGlobalName(name) && - !ts.hasProperty(currentSourceFile.identifiers, name) && - !ts.hasProperty(generatedNameSet, name); - } - // Return the next available name in the pattern _a ... _z, _0, _1, ... - // TempFlags._i or TempFlags._n may be used to express a preference for that dedicated name. - // Note that names generated by makeTempVariableName and makeUniqueName will never conflict. - function makeTempVariableName(flags) { - if (flags && !(tempFlags & flags)) { - var name_19 = flags === 268435456 /* _i */ ? "_i" : "_n"; - if (isUniqueName(name_19)) { - tempFlags |= flags; - return name_19; - } - } - while (true) { - var count = tempFlags & 268435455 /* CountMask */; - tempFlags++; - // Skip over 'i' and 'n' - if (count !== 8 && count !== 13) { - var name_20 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_20)) { - return name_20; - } - } - } - } - // Generate a name that is unique within the current file and doesn't conflict with any names - // in global scope. The name is formed by adding an '_n' suffix to the specified base name, - // where n is a positive integer. Note that names generated by makeTempVariableName and - // makeUniqueName are guaranteed to never conflict. - function makeUniqueName(baseName) { - // Find the first unique 'name_n', where n is a positive number - if (baseName.charCodeAt(baseName.length - 1) !== 95 /* _ */) { - baseName += "_"; - } - var i = 1; - while (true) { - var generatedName = baseName + i; - if (isUniqueName(generatedName)) { - return generatedNameSet[generatedName] = generatedName; - } - i++; - } - } - function generateNameForModuleOrEnum(node) { - var name = node.name.text; - // Use module/enum name itself if it is unique, otherwise make a unique variation - return isUniqueLocalName(name, node) ? name : makeUniqueName(name); - } - function generateNameForImportOrExportDeclaration(node) { - var expr = ts.getExternalModuleName(node); - var baseName = expr.kind === 9 /* StringLiteral */ ? - ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; - return makeUniqueName(baseName); - } - function generateNameForExportDefault() { - return makeUniqueName("default"); - } - function generateNameForClassExpression() { - return makeUniqueName("class"); - } - function generateNameForNode(node) { - switch (node.kind) { - case 67 /* Identifier */: - return makeUniqueName(node.text); - case 216 /* ModuleDeclaration */: - case 215 /* EnumDeclaration */: - return generateNameForModuleOrEnum(node); - case 220 /* ImportDeclaration */: - case 226 /* ExportDeclaration */: - return generateNameForImportOrExportDeclaration(node); - case 211 /* FunctionDeclaration */: - case 212 /* ClassDeclaration */: - case 225 /* ExportAssignment */: - return generateNameForExportDefault(); - case 184 /* ClassExpression */: - return generateNameForClassExpression(); - } - } - function getGeneratedNameForNode(node) { - var id = ts.getNodeId(node); - return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); - } - function initializeEmitterWithSourceMaps() { - var sourceMapDir; // The directory in which sourcemap will be - // Current source map file and its index in the sources list - var sourceMapSourceIndex = -1; - // Names and its index map - var sourceMapNameIndexMap = {}; - var sourceMapNameIndices = []; - function getSourceMapNameIndex() { - return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; - } - // Last recorded and encoded spans - var lastRecordedSourceMapSpan; - var lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; - var lastEncodedNameIndex = 0; - // Encoding for sourcemap span - function encodeLastRecordedSourceMapSpan() { - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { - return; - } - var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; - // Line/Comma delimiters - if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { - // Emit comma to separate the entry - if (sourceMapData.sourceMapMappings) { - sourceMapData.sourceMapMappings += ","; - } - } - else { - // Emit line delimiters - for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { - sourceMapData.sourceMapMappings += ";"; - } - prevEncodedEmittedColumn = 1; - } - // 1. Relative Column 0 based - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); - // 2. Relative sourceIndex - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); - // 3. Relative sourceLine 0 based - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); - // 4. Relative sourceColumn 0 based - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); - // 5. Relative namePosition 0 based - if (lastRecordedSourceMapSpan.nameIndex >= 0) { - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); - lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; - } - lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; - sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); - function base64VLQFormatEncode(inValue) { - function base64FormatEncode(inValue) { - if (inValue < 64) { - return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); - } - throw TypeError(inValue + ": not a 64 based value"); - } - // Add a new least significant bit that has the sign of the value. - // if negative number the least significant bit that gets added to the number has value 1 - // else least significant bit value that gets added is 0 - // eg. -1 changes to binary : 01 [1] => 3 - // +1 changes to binary : 01 [0] => 2 - if (inValue < 0) { - inValue = ((-inValue) << 1) + 1; - } - else { - inValue = inValue << 1; - } - // Encode 5 bits at a time starting from least significant bits - var encodedStr = ""; - do { - var currentDigit = inValue & 31; // 11111 - inValue = inValue >> 5; - if (inValue > 0) { - // There are still more digits to decode, set the msb (6th bit) - currentDigit = currentDigit | 32; - } - encodedStr = encodedStr + base64FormatEncode(currentDigit); - } while (inValue > 0); - return encodedStr; - } - } - function recordSourceMapSpan(pos) { - var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); - // Convert the location to be one-based. - sourceLinePos.line++; - sourceLinePos.character++; - var emittedLine = writer.getLine(); - var emittedColumn = writer.getColumn(); - // If this location wasn't recorded or the location in source is going backwards, record the span - if (!lastRecordedSourceMapSpan || - lastRecordedSourceMapSpan.emittedLine !== emittedLine || - lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || - (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { - // Encode the last recordedSpan before assigning new - encodeLastRecordedSourceMapSpan(); - // New span - lastRecordedSourceMapSpan = { - emittedLine: emittedLine, - emittedColumn: emittedColumn, - sourceLine: sourceLinePos.line, - sourceColumn: sourceLinePos.character, - nameIndex: getSourceMapNameIndex(), - sourceIndex: sourceMapSourceIndex - }; - } - else { - // Take the new pos instead since there is no change in emittedLine and column since last location - lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; - lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; - lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; - } - } - function recordEmitNodeStartSpan(node) { - // Get the token pos after skipping to the token (ignoring the leading trivia) - recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); - } - function recordEmitNodeEndSpan(node) { - recordSourceMapSpan(node.end); - } - function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); - var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; - } - function recordNewSourceFileStart(node) { - // Add the file to tsFilePaths - // If sourceroot option: Use the relative path corresponding to the common directory path - // otherwise source locations relative to map file location - var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ true)); - sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; - // The one that can be used from program to get the actual source file - sourceMapData.inputSourceFileNames.push(node.fileName); - if (compilerOptions.inlineSources) { - if (!sourceMapData.sourceMapSourcesContent) { - sourceMapData.sourceMapSourcesContent = []; - } - sourceMapData.sourceMapSourcesContent.push(node.text); - } - } - function recordScopeNameOfNode(node, scopeName) { - function recordScopeNameIndex(scopeNameIndex) { - sourceMapNameIndices.push(scopeNameIndex); - } - function recordScopeNameStart(scopeName) { - var scopeNameIndex = -1; - if (scopeName) { - var parentIndex = getSourceMapNameIndex(); - if (parentIndex !== -1) { - // Child scopes are always shown with a dot (even if they have no name), - // unless it is a computed property. Then it is shown with brackets, - // but the brackets are included in the name. - var name_21 = node.name; - if (!name_21 || name_21.kind !== 134 /* ComputedPropertyName */) { - scopeName = "." + scopeName; - } - scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; - } - scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); - if (scopeNameIndex === undefined) { - scopeNameIndex = sourceMapData.sourceMapNames.length; - sourceMapData.sourceMapNames.push(scopeName); - sourceMapNameIndexMap[scopeName] = scopeNameIndex; - } - } - recordScopeNameIndex(scopeNameIndex); - } - if (scopeName) { - // The scope was already given a name use it - recordScopeNameStart(scopeName); - } - else if (node.kind === 211 /* FunctionDeclaration */ || - node.kind === 171 /* FunctionExpression */ || - node.kind === 141 /* MethodDeclaration */ || - node.kind === 140 /* MethodSignature */ || - node.kind === 143 /* GetAccessor */ || - node.kind === 144 /* SetAccessor */ || - node.kind === 216 /* ModuleDeclaration */ || - node.kind === 212 /* ClassDeclaration */ || - node.kind === 215 /* EnumDeclaration */) { - // Declaration and has associated name use it - if (node.name) { - var name_22 = node.name; - // For computed property names, the text will include the brackets - scopeName = name_22.kind === 134 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_22) - : node.name.text; - } - recordScopeNameStart(scopeName); - } - else { - // Block just use the name from upper level scope - recordScopeNameIndex(getSourceMapNameIndex()); - } - } - function recordScopeNameEnd() { - sourceMapNameIndices.pop(); - } - ; - function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { - recordSourceMapSpan(comment.pos); - ts.writeCommentRange(currentSourceFile, writer, comment, newLine); - recordSourceMapSpan(comment.end); - } - function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { - if (typeof JSON !== "undefined") { - var map_1 = { - version: version, - file: file, - sourceRoot: sourceRoot, - sources: sources, - names: names, - mappings: mappings - }; - if (sourcesContent !== undefined) { - map_1.sourcesContent = sourcesContent; - } - return JSON.stringify(map_1); - } - return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; - function serializeStringArray(list) { - var output = ""; - for (var i = 0, n = list.length; i < n; i++) { - if (i) { - output += ","; - } - output += "\"" + ts.escapeString(list[i]) + "\""; - } - return output; - } - } - function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { - encodeLastRecordedSourceMapSpan(); - var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); - sourceMapDataList.push(sourceMapData); - var sourceMapUrl; - if (compilerOptions.inlineSourceMap) { - // Encode the sourceMap into the sourceMap url - var base64SourceMapText = ts.convertToBase64(sourceMapText); - sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; - } - else { - // Write source map file - ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, /*writeByteOrderMark*/ false); - sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; - } - // Write sourcemap url to the js file and write the js file - writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); - } - // Initialize source map data - var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); - sourceMapData = { - sourceMapFilePath: jsFilePath + ".map", - jsSourceMappingURL: sourceMapJsFile + ".map", - sourceMapFile: sourceMapJsFile, - sourceMapSourceRoot: compilerOptions.sourceRoot || "", - sourceMapSources: [], - inputSourceFileNames: [], - sourceMapNames: [], - sourceMapMappings: "", - sourceMapSourcesContent: undefined, - sourceMapDecodedMappings: [] - }; - // Normalize source root and make sure it has trailing "/" so that it can be used to combine paths with the - // relative paths of the sources list in the sourcemap - sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); - if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { - sourceMapData.sourceMapSourceRoot += ts.directorySeparator; - } - if (compilerOptions.mapRoot) { - sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); - if (root) { - // For modules or multiple emit files the mapRoot will have directory structure like the sources - // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); - } - if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { - // The relative paths are relative to the common directory - sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath - ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap - host.getCurrentDirectory(), host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ true); - } - else { - sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); - } - } - else { - sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); - } - function emitNodeWithSourceMap(node) { - if (node) { - if (ts.nodeIsSynthesized(node)) { - return emitNodeWithoutSourceMap(node); - } - if (node.kind !== 246 /* SourceFile */) { - recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMap(node); - recordEmitNodeEndSpan(node); - } - else { - recordNewSourceFileStart(node); - emitNodeWithoutSourceMap(node); - } - } - } - function emitNodeWithCommentsAndWithSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; - emit = emitNodeWithCommentsAndWithSourcemap; - emitStart = recordEmitNodeStartSpan; - emitEnd = recordEmitNodeEndSpan; - emitToken = writeTextWithSpanRecord; - scopeEmitStart = recordScopeNameOfNode; - scopeEmitEnd = recordScopeNameEnd; - writeComment = writeCommentRangeWithMap; - } - function writeJavaScriptFile(emitOutput, writeByteOrderMark) { - ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); - } - // Create a temporary variable with a unique unused name. - function createTempVariable(flags) { - var result = ts.createSynthesizedNode(67 /* Identifier */); - result.text = makeTempVariableName(flags); - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; - } - tempVariables.push(name); - } - function createAndRecordTempVariable(flags) { - var temp = createTempVariable(flags); - recordTempDeclaration(temp); - return temp; - } - function emitTempDeclarations(newLine) { - if (tempVariables) { - if (newLine) { - writeLine(); - } - else { - write(" "); - } - write("var "); - emitCommaList(tempVariables); - write(";"); - } - } - function emitTokenText(tokenKind, startPos, emitFn) { - var tokenString = ts.tokenToString(tokenKind); - if (emitFn) { - emitFn(); - } - else { - write(tokenString); - } - return startPos + tokenString.length; - } - function emitOptional(prefix, node) { - if (node) { - write(prefix); - emit(node); - } - } - function emitParenthesizedIf(node, parenthesized) { - if (parenthesized) { - write("("); - } - emit(node); - if (parenthesized) { - write(")"); - } - } - function emitTrailingCommaIfPresent(nodeList) { - if (nodeList.hasTrailingComma) { - write(","); - } - } - function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { - ts.Debug.assert(nodes.length > 0); - increaseIndent(); - if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - for (var i = 0, n = nodes.length; i < n; i++) { - if (i) { - if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { - write(", "); - } - else { - write(","); - writeLine(); - } - } - emit(nodes[i]); - } - if (nodes.hasTrailingComma && allowTrailingComma) { - write(","); - } - decreaseIndent(); - if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - } - function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { - if (!emitNode) { - emitNode = emit; - } - for (var i = 0; i < count; i++) { - if (multiLine) { - if (i || leadingComma) { - write(","); - } - writeLine(); - } - else { - if (i || leadingComma) { - write(", "); - } - } - var node = nodes[start + i]; - // This emitting is to make sure we emit following comment properly - // ...(x, /*comment1*/ y)... - // ^ => node.pos - // "comment1" is not considered leading comment for "y" but rather - // considered as trailing comment of the previous node. - emitTrailingCommentsOfPosition(node.pos); - emitNode(node); - leadingComma = true; - } - if (trailingComma) { - write(","); - } - if (multiLine && !noTrailingNewLine) { - writeLine(); - } - return count; - } - function emitCommaList(nodes) { - if (nodes) { - emitList(nodes, 0, nodes.length, /*multiline*/ false, /*trailingComma*/ false); - } - } - function emitLines(nodes) { - emitLinesStartingAt(nodes, /*startIndex*/ 0); - } - function emitLinesStartingAt(nodes, startIndex) { - for (var i = startIndex; i < nodes.length; i++) { - writeLine(); - emit(nodes[i]); - } - } - function isBinaryOrOctalIntegerLiteral(node, text) { - if (node.kind === 8 /* NumericLiteral */ && text.length > 1) { - switch (text.charCodeAt(1)) { - case 98 /* b */: - case 66 /* B */: - case 111 /* o */: - case 79 /* O */: - return true; - } - } - return false; - } - function emitLiteral(node) { - var text = getLiteralText(node); - if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { - writer.writeLiteral(text); - } - else if (languageVersion < 2 /* ES6 */ && isBinaryOrOctalIntegerLiteral(node, text)) { - write(node.text); - } - else { - write(text); - } - } - function getLiteralText(node) { - // Any template literal or string literal with an extended escape - // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal. - if (languageVersion < 2 /* ES6 */ && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { - return getQuotedEscapedLiteralText("\"", node.text, "\""); - } - // If we don't need to downlevel and we can reach the original source text using - // the node's parent reference, then simply get the text as it was originally written. - if (node.parent) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - } - // If we can't reach the original source text, use the canonical form if it's a number, - // or an escaped quoted form of the original text if it's string-like. - switch (node.kind) { - case 9 /* StringLiteral */: - return getQuotedEscapedLiteralText("\"", node.text, "\""); - case 11 /* NoSubstitutionTemplateLiteral */: - return getQuotedEscapedLiteralText("`", node.text, "`"); - case 12 /* TemplateHead */: - return getQuotedEscapedLiteralText("`", node.text, "${"); - case 13 /* TemplateMiddle */: - return getQuotedEscapedLiteralText("}", node.text, "${"); - case 14 /* TemplateTail */: - return getQuotedEscapedLiteralText("}", node.text, "`"); - case 8 /* NumericLiteral */: - return node.text; - } - ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); - } - function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { - return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; - } - function emitDownlevelRawTemplateLiteral(node) { - // Find original source text, since we need to emit the raw strings of the tagged template. - // The raw strings contain the (escaped) strings of what the user wrote. - // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - var isLast = node.kind === 11 /* NoSubstitutionTemplateLiteral */ || node.kind === 14 /* TemplateTail */; - text = text.substring(1, text.length - (isLast ? 1 : 2)); - // Newline normalization: - // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's - // and LineTerminatorSequences are normalized to for both TV and TRV. - text = text.replace(/\r\n?/g, "\n"); - text = ts.escapeString(text); - write("\"" + text + "\""); - } - function emitDownlevelTaggedTemplateArray(node, literalEmitter) { - write("["); - if (node.template.kind === 11 /* NoSubstitutionTemplateLiteral */) { - literalEmitter(node.template); - } - else { - literalEmitter(node.template.head); - ts.forEach(node.template.templateSpans, function (child) { - write(", "); - literalEmitter(child.literal); - }); - } - write("]"); - } - function emitDownlevelTaggedTemplate(node) { - var tempVariable = createAndRecordTempVariable(0 /* Auto */); - write("("); - emit(tempVariable); - write(" = "); - emitDownlevelTaggedTemplateArray(node, emit); - write(", "); - emit(tempVariable); - write(".raw = "); - emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); - write(", "); - emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); - write("("); - emit(tempVariable); - // Now we emit the expressions - if (node.template.kind === 181 /* TemplateExpression */) { - ts.forEach(node.template.templateSpans, function (templateSpan) { - write(", "); - var needsParens = templateSpan.expression.kind === 179 /* BinaryExpression */ - && templateSpan.expression.operatorToken.kind === 24 /* CommaToken */; - emitParenthesizedIf(templateSpan.expression, needsParens); - }); - } - write("))"); - } - function emitTemplateExpression(node) { - // In ES6 mode and above, we can simply emit each portion of a template in order, but in - // ES3 & ES5 we must convert the template expression into a series of string concatenations. - if (languageVersion >= 2 /* ES6 */) { - ts.forEachChild(node, emit); - return; - } - var emitOuterParens = ts.isExpression(node.parent) - && templateNeedsParens(node, node.parent); - if (emitOuterParens) { - write("("); - } - var headEmitted = false; - if (shouldEmitTemplateHead()) { - emitLiteral(node.head); - headEmitted = true; - } - for (var i = 0, n = node.templateSpans.length; i < n; i++) { - var templateSpan = node.templateSpans[i]; - // Check if the expression has operands and binds its operands less closely than binary '+'. - // If it does, we need to wrap the expression in parentheses. Otherwise, something like - // `abc${ 1 << 2 }` - // becomes - // "abc" + 1 << 2 + "" - // which is really - // ("abc" + 1) << (2 + "") - // rather than - // "abc" + (1 << 2) + "" - var needsParens = templateSpan.expression.kind !== 170 /* ParenthesizedExpression */ - && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; - if (i > 0 || headEmitted) { - // If this is the first span and the head was not emitted, then this templateSpan's - // expression will be the first to be emitted. Don't emit the preceding ' + ' in that - // case. - write(" + "); - } - emitParenthesizedIf(templateSpan.expression, needsParens); - // Only emit if the literal is non-empty. - // The binary '+' operator is left-associative, so the first string concatenation - // with the head will force the result up to this point to be a string. - // Emitting a '+ ""' has no semantic effect for middles and tails. - if (templateSpan.literal.text.length !== 0) { - write(" + "); - emitLiteral(templateSpan.literal); - } - } - if (emitOuterParens) { - write(")"); - } - function shouldEmitTemplateHead() { - // If this expression has an empty head literal and the first template span has a non-empty - // literal, then emitting the empty head literal is not necessary. - // `${ foo } and ${ bar }` - // can be emitted as - // foo + " and " + bar - // This is because it is only required that one of the first two operands in the emit - // output must be a string literal, so that the other operand and all following operands - // are forced into strings. - // - // If the first template span has an empty literal, then the head must still be emitted. - // `${ foo }${ bar }` - // must still be emitted as - // "" + foo + bar - // There is always atleast one templateSpan in this code path, since - // NoSubstitutionTemplateLiterals are directly emitted via emitLiteral() - ts.Debug.assert(node.templateSpans.length !== 0); - return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; - } - function templateNeedsParens(template, parent) { - switch (parent.kind) { - case 166 /* CallExpression */: - case 167 /* NewExpression */: - return parent.expression === template; - case 168 /* TaggedTemplateExpression */: - case 170 /* ParenthesizedExpression */: - return false; - default: - return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; - } - } - /** - * Returns whether the expression has lesser, greater, - * or equal precedence to the binary '+' operator - */ - function comparePrecedenceToBinaryPlus(expression) { - // All binary expressions have lower precedence than '+' apart from '*', '/', and '%' - // which have greater precedence and '-' which has equal precedence. - // All unary operators have a higher precedence apart from yield. - // Arrow functions and conditionals have a lower precedence, - // although we convert the former into regular function expressions in ES5 mode, - // and in ES6 mode this function won't get called anyway. - // - // TODO (drosen): Note that we need to account for the upcoming 'yield' and - // spread ('...') unary operators that are anticipated for ES6. - switch (expression.kind) { - case 179 /* BinaryExpression */: - switch (expression.operatorToken.kind) { - case 37 /* AsteriskToken */: - case 38 /* SlashToken */: - case 39 /* PercentToken */: - return 1 /* GreaterThan */; - case 35 /* PlusToken */: - case 36 /* MinusToken */: - return 0 /* EqualTo */; - default: - return -1 /* LessThan */; - } - case 182 /* YieldExpression */: - case 180 /* ConditionalExpression */: - return -1 /* LessThan */; - default: - return 1 /* GreaterThan */; - } - } - } - function emitTemplateSpan(span) { - emit(span.expression); - emit(span.literal); - } - function jsxEmitReact(node) { - /// Emit a tag name, which is either '"div"' for lower-cased names, or - /// 'Div' for upper-cased or dotted names - function emitTagName(name) { - if (name.kind === 67 /* Identifier */ && ts.isIntrinsicJsxName(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - /// Emit an attribute name, which is quoted if it needs to be quoted. Because - /// these emit into an object literal property name, we don't need to be worried - /// about keywords, just non-identifier characters - function emitAttributeName(name) { - if (/[A-Za-z_]+[\w*]/.test(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - /// Emit an name/value pair for an attribute (e.g. "x: 3") - function emitJsxAttribute(node) { - emitAttributeName(node.name); - write(": "); - if (node.initializer) { - emit(node.initializer); - } - else { - write("true"); - } - } - function emitJsxElement(openingNode, children) { - var syntheticReactRef = ts.createSynthesizedNode(67 /* Identifier */); - syntheticReactRef.text = 'React'; - syntheticReactRef.parent = openingNode; - // Call React.createElement(tag, ... - emitLeadingComments(openingNode); - emitExpressionIdentifier(syntheticReactRef); - write(".createElement("); - emitTagName(openingNode.tagName); - write(", "); - // Attribute list - if (openingNode.attributes.length === 0) { - // When there are no attributes, React wants "null" - write("null"); - } - else { - // Either emit one big object literal (no spread attribs), or - // a call to React.__spread - var attrs = openingNode.attributes; - if (ts.forEach(attrs, function (attr) { return attr.kind === 237 /* JsxSpreadAttribute */; })) { - emitExpressionIdentifier(syntheticReactRef); - write(".__spread("); - var haveOpenedObjectLiteral = false; - for (var i_1 = 0; i_1 < attrs.length; i_1++) { - if (attrs[i_1].kind === 237 /* JsxSpreadAttribute */) { - // If this is the first argument, we need to emit a {} as the first argument - if (i_1 === 0) { - write("{}, "); - } - if (haveOpenedObjectLiteral) { - write("}"); - haveOpenedObjectLiteral = false; - } - if (i_1 > 0) { - write(", "); - } - emit(attrs[i_1].expression); - } - else { - ts.Debug.assert(attrs[i_1].kind === 236 /* JsxAttribute */); - if (haveOpenedObjectLiteral) { - write(", "); - } - else { - haveOpenedObjectLiteral = true; - if (i_1 > 0) { - write(", "); - } - write("{"); - } - emitJsxAttribute(attrs[i_1]); - } - } - if (haveOpenedObjectLiteral) - write("}"); - write(")"); // closing paren to React.__spread( - } - else { - // One object literal with all the attributes in them - write("{"); - for (var i = 0; i < attrs.length; i++) { - if (i > 0) { - write(", "); - } - emitJsxAttribute(attrs[i]); - } - write("}"); - } - } - // Children - if (children) { - for (var i = 0; i < children.length; i++) { - // Don't emit empty expressions - if (children[i].kind === 238 /* JsxExpression */ && !(children[i].expression)) { - continue; - } - // Don't emit empty strings - if (children[i].kind === 234 /* JsxText */) { - var text = getTextToEmit(children[i]); - if (text !== undefined) { - write(", \""); - write(text); - write("\""); - } - } - else { - write(", "); - emit(children[i]); - } - } - } - // Closing paren - write(")"); // closes "React.createElement(" - emitTrailingComments(openingNode); - } - if (node.kind === 231 /* JsxElement */) { - emitJsxElement(node.openingElement, node.children); - } - else { - ts.Debug.assert(node.kind === 232 /* JsxSelfClosingElement */); - emitJsxElement(node); - } - } - function jsxEmitPreserve(node) { - function emitJsxAttribute(node) { - emit(node.name); - if (node.initializer) { - write("="); - emit(node.initializer); - } - } - function emitJsxSpreadAttribute(node) { - write("{..."); - emit(node.expression); - write("}"); - } - function emitAttributes(attribs) { - for (var i = 0, n = attribs.length; i < n; i++) { - if (i > 0) { - write(" "); - } - if (attribs[i].kind === 237 /* JsxSpreadAttribute */) { - emitJsxSpreadAttribute(attribs[i]); - } - else { - ts.Debug.assert(attribs[i].kind === 236 /* JsxAttribute */); - emitJsxAttribute(attribs[i]); - } - } - } - function emitJsxOpeningOrSelfClosingElement(node) { - write("<"); - emit(node.tagName); - if (node.attributes.length > 0 || (node.kind === 232 /* JsxSelfClosingElement */)) { - write(" "); - } - emitAttributes(node.attributes); - if (node.kind === 232 /* JsxSelfClosingElement */) { - write("/>"); - } - else { - write(">"); - } - } - function emitJsxClosingElement(node) { - write(""); - } - function emitJsxElement(node) { - emitJsxOpeningOrSelfClosingElement(node.openingElement); - for (var i = 0, n = node.children.length; i < n; i++) { - emit(node.children[i]); - } - emitJsxClosingElement(node.closingElement); - } - if (node.kind === 231 /* JsxElement */) { - emitJsxElement(node); - } - else { - ts.Debug.assert(node.kind === 232 /* JsxSelfClosingElement */); - emitJsxOpeningOrSelfClosingElement(node); - } - } - // This function specifically handles numeric/string literals for enum and accessor 'identifiers'. - // In a sense, it does not actually emit identifiers as much as it declares a name for a specific property. - // For example, this is utilized when feeding in a result to Object.defineProperty. - function emitExpressionForPropertyName(node) { - ts.Debug.assert(node.kind !== 161 /* BindingElement */); - if (node.kind === 9 /* StringLiteral */) { - emitLiteral(node); - } - else if (node.kind === 134 /* ComputedPropertyName */) { - // if this is a decorated computed property, we will need to capture the result - // of the property expression so that we can apply decorators later. This is to ensure - // we don't introduce unintended side effects: - // - // class C { - // [_a = x]() { } - // } - // - // The emit for the decorated computed property decorator is: - // - // Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); - // - if (ts.nodeIsDecorated(node.parent)) { - if (!computedPropertyNamesToGeneratedNames) { - computedPropertyNamesToGeneratedNames = []; - } - var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; - if (generatedName) { - // we have already generated a variable for this node, write that value instead. - write(generatedName); - return; - } - generatedName = createAndRecordTempVariable(0 /* Auto */).text; - computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; - write(generatedName); - write(" = "); - } - emit(node.expression); - } - else { - write("\""); - if (node.kind === 8 /* NumericLiteral */) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - write("\""); - } - } - function isExpressionIdentifier(node) { - var parent = node.parent; - switch (parent.kind) { - case 162 /* ArrayLiteralExpression */: - case 179 /* BinaryExpression */: - case 166 /* CallExpression */: - case 239 /* CaseClause */: - case 134 /* ComputedPropertyName */: - case 180 /* ConditionalExpression */: - case 137 /* Decorator */: - case 173 /* DeleteExpression */: - case 195 /* DoStatement */: - case 165 /* ElementAccessExpression */: - case 225 /* ExportAssignment */: - case 193 /* ExpressionStatement */: - case 186 /* ExpressionWithTypeArguments */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 194 /* IfStatement */: - case 232 /* JsxSelfClosingElement */: - case 233 /* JsxOpeningElement */: - case 237 /* JsxSpreadAttribute */: - case 238 /* JsxExpression */: - case 167 /* NewExpression */: - case 170 /* ParenthesizedExpression */: - case 178 /* PostfixUnaryExpression */: - case 177 /* PrefixUnaryExpression */: - case 202 /* ReturnStatement */: - case 244 /* ShorthandPropertyAssignment */: - case 183 /* SpreadElementExpression */: - case 204 /* SwitchStatement */: - case 168 /* TaggedTemplateExpression */: - case 188 /* TemplateSpan */: - case 206 /* ThrowStatement */: - case 169 /* TypeAssertionExpression */: - case 174 /* TypeOfExpression */: - case 175 /* VoidExpression */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 182 /* YieldExpression */: - return true; - case 161 /* BindingElement */: - case 245 /* EnumMember */: - case 136 /* Parameter */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 209 /* VariableDeclaration */: - return parent.initializer === node; - case 164 /* PropertyAccessExpression */: - return parent.expression === node; - case 172 /* ArrowFunction */: - case 171 /* FunctionExpression */: - return parent.body === node; - case 219 /* ImportEqualsDeclaration */: - return parent.moduleReference === node; - case 133 /* QualifiedName */: - return parent.left === node; - } - return false; - } - function emitExpressionIdentifier(node) { - if (resolver.getNodeCheckFlags(node) & 2048 /* LexicalArguments */) { - write("_arguments"); - return; - } - var container = resolver.getReferencedExportContainer(node); - if (container) { - if (container.kind === 246 /* SourceFile */) { - // Identifier references module export - if (languageVersion < 2 /* ES6 */ && compilerOptions.module !== 4 /* System */) { - write("exports."); - } - } - else { - // Identifier references namespace export - write(getGeneratedNameForNode(container)); - write("."); - } - } - else if (languageVersion < 2 /* ES6 */) { - var declaration = resolver.getReferencedImportDeclaration(node); - if (declaration) { - if (declaration.kind === 221 /* ImportClause */) { - // Identifier references default import - write(getGeneratedNameForNode(declaration.parent)); - write(languageVersion === 0 /* ES3 */ ? "[\"default\"]" : ".default"); - return; - } - else if (declaration.kind === 224 /* ImportSpecifier */) { - // Identifier references named import - write(getGeneratedNameForNode(declaration.parent.parent.parent)); - var name = declaration.propertyName || declaration.name; - var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name); - if (languageVersion === 0 /* ES3 */ && identifier === "default") { - write("[\"default\"]"); - } - else { - write("."); - write(identifier); - } - return; - } - } - declaration = resolver.getReferencedNestedRedeclaration(node); - if (declaration) { - write(getGeneratedNameForNode(declaration.name)); - return; - } - } - if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function isNameOfNestedRedeclaration(node) { - if (languageVersion < 2 /* ES6 */) { - var parent_6 = node.parent; - switch (parent_6.kind) { - case 161 /* BindingElement */: - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 209 /* VariableDeclaration */: - return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); - } - } - return false; - } - function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (isExpressionIdentifier(node)) { - emitExpressionIdentifier(node); - } - else if (isNameOfNestedRedeclaration(node)) { - write(getGeneratedNameForNode(node)); - } - else if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function emitThis(node) { - if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { - write("_this"); - } - else { - write("this"); - } - } - function emitSuper(node) { - if (languageVersion >= 2 /* ES6 */) { - write("super"); - } - else { - var flags = resolver.getNodeCheckFlags(node); - if (flags & 256 /* SuperInstance */) { - write("_super.prototype"); - } - else { - write("_super"); - } - } - } - function emitObjectBindingPattern(node) { - write("{ "); - var elements = node.elements; - emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); - write(" }"); - } - function emitArrayBindingPattern(node) { - write("["); - var elements = node.elements; - emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); - write("]"); - } - function emitBindingElement(node) { - if (node.propertyName) { - emit(node.propertyName); - write(": "); - } - if (node.dotDotDotToken) { - write("..."); - } - if (ts.isBindingPattern(node.name)) { - emit(node.name); - } - else { - emitModuleMemberName(node); - } - emitOptional(" = ", node.initializer); - } - function emitSpreadElementExpression(node) { - write("..."); - emit(node.expression); - } - function emitYieldExpression(node) { - write(ts.tokenToString(112 /* YieldKeyword */)); - if (node.asteriskToken) { - write("*"); - } - if (node.expression) { - write(" "); - emit(node.expression); - } - } - function emitAwaitExpression(node) { - var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); - if (needsParenthesis) { - write("("); - } - write(ts.tokenToString(112 /* YieldKeyword */)); - write(" "); - emit(node.expression); - if (needsParenthesis) { - write(")"); - } - } - function needsParenthesisForAwaitExpressionAsYield(node) { - if (node.parent.kind === 179 /* BinaryExpression */ && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { - return true; - } - else if (node.parent.kind === 180 /* ConditionalExpression */ && node.parent.condition === node) { - return true; - } - return false; - } - function needsParenthesisForPropertyAccessOrInvocation(node) { - switch (node.kind) { - case 67 /* Identifier */: - case 162 /* ArrayLiteralExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 170 /* ParenthesizedExpression */: - // This list is not exhaustive and only includes those cases that are relevant - // to the check in emitArrayLiteral. More cases can be added as needed. - return false; - } - return true; - } - function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { - var pos = 0; - var group = 0; - var length = elements.length; - while (pos < length) { - // Emit using the pattern .concat(, , ...) - if (group === 1 && useConcat) { - write(".concat("); - } - else if (group > 0) { - write(", "); - } - var e = elements[pos]; - if (e.kind === 183 /* SpreadElementExpression */) { - e = e.expression; - emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); - pos++; - if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 162 /* ArrayLiteralExpression */) { - write(".slice()"); - } - } - else { - var i = pos; - while (i < length && elements[i].kind !== 183 /* SpreadElementExpression */) { - i++; - } - write("["); - if (multiLine) { - increaseIndent(); - } - emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); - if (multiLine) { - decreaseIndent(); - } - write("]"); - pos = i; - } - group++; - } - if (group > 1) { - if (useConcat) { - write(")"); - } - } - } - function isSpreadElementExpression(node) { - return node.kind === 183 /* SpreadElementExpression */; - } - function emitArrayLiteral(node) { - var elements = node.elements; - if (elements.length === 0) { - write("[]"); - } - else if (languageVersion >= 2 /* ES6 */ || !ts.forEach(elements, isSpreadElementExpression)) { - write("["); - emitLinePreservingList(node, node.elements, elements.hasTrailingComma, /*spacesBetweenBraces:*/ false); - write("]"); - } - else { - emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/ (node.flags & 2048 /* MultiLine */) !== 0, - /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); - } - } - function emitObjectLiteralBody(node, numElements) { - if (numElements === 0) { - write("{}"); - return; - } - write("{"); - if (numElements > 0) { - var properties = node.properties; - // If we are not doing a downlevel transformation for object literals, - // then try to preserve the original shape of the object literal. - // Otherwise just try to preserve the formatting. - if (numElements === properties.length) { - emitLinePreservingList(node, properties, /* allowTrailingComma */ languageVersion >= 1 /* ES5 */, /* spacesBetweenBraces */ true); - } - else { - var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; - if (!multiLine) { - write(" "); - } - else { - increaseIndent(); - } - emitList(properties, 0, numElements, /*multiLine*/ multiLine, /*trailingComma*/ false); - if (!multiLine) { - write(" "); - } - else { - decreaseIndent(); - } - } - } - write("}"); - } - function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { - var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; - var properties = node.properties; - write("("); - if (multiLine) { - increaseIndent(); - } - // For computed properties, we need to create a unique handle to the object - // literal so we can modify it without risking internal assignments tainting the object. - var tempVar = createAndRecordTempVariable(0 /* Auto */); - // Write out the first non-computed properties - // (or all properties if none of them are computed), - // then emit the rest through indexing on the temp variable. - emit(tempVar); - write(" = "); - emitObjectLiteralBody(node, firstComputedPropertyIndex); - for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { - writeComma(); - var property = properties[i]; - emitStart(property); - if (property.kind === 143 /* GetAccessor */ || property.kind === 144 /* SetAccessor */) { - // TODO (drosen): Reconcile with 'emitMemberFunctions'. - var accessors = ts.getAllAccessorDeclarations(node.properties, property); - if (property !== accessors.firstAccessor) { - continue; - } - write("Object.defineProperty("); - emit(tempVar); - write(", "); - emitStart(node.name); - emitExpressionForPropertyName(property.name); - emitEnd(property.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("})"); - emitEnd(property); - } - else { - emitLeadingComments(property); - emitStart(property.name); - emit(tempVar); - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - if (property.kind === 243 /* PropertyAssignment */) { - emit(property.initializer); - } - else if (property.kind === 244 /* ShorthandPropertyAssignment */) { - emitExpressionIdentifier(property.name); - } - else if (property.kind === 141 /* MethodDeclaration */) { - emitFunctionDeclaration(property); - } - else { - ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); - } - } - emitEnd(property); - } - writeComma(); - emit(tempVar); - if (multiLine) { - decreaseIndent(); - writeLine(); - } - write(")"); - function writeComma() { - if (multiLine) { - write(","); - writeLine(); - } - else { - write(", "); - } - } - } - function emitObjectLiteral(node) { - var properties = node.properties; - if (languageVersion < 2 /* ES6 */) { - var numProperties = properties.length; - // Find the first computed property. - // Everything until that point can be emitted as part of the initial object literal. - var numInitialNonComputedProperties = numProperties; - for (var i = 0, n = properties.length; i < n; i++) { - if (properties[i].name.kind === 134 /* ComputedPropertyName */) { - numInitialNonComputedProperties = i; - break; - } - } - var hasComputedProperty = numInitialNonComputedProperties !== properties.length; - if (hasComputedProperty) { - emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); - return; - } - } - // Ordinary case: either the object has no computed properties - // or we're compiling with an ES6+ target. - emitObjectLiteralBody(node, properties.length); - } - function createBinaryExpression(left, operator, right, startsOnNewLine) { - var result = ts.createSynthesizedNode(179 /* BinaryExpression */, startsOnNewLine); - result.operatorToken = ts.createSynthesizedNode(operator); - result.left = left; - result.right = right; - return result; - } - function createPropertyAccessExpression(expression, name) { - var result = ts.createSynthesizedNode(164 /* PropertyAccessExpression */); - result.expression = parenthesizeForAccess(expression); - result.dotToken = ts.createSynthesizedNode(21 /* DotToken */); - result.name = name; - return result; - } - function createElementAccessExpression(expression, argumentExpression) { - var result = ts.createSynthesizedNode(165 /* ElementAccessExpression */); - result.expression = parenthesizeForAccess(expression); - result.argumentExpression = argumentExpression; - return result; - } - function parenthesizeForAccess(expr) { - // When diagnosing whether the expression needs parentheses, the decision should be based - // on the innermost expression in a chain of nested type assertions. - while (expr.kind === 169 /* TypeAssertionExpression */ || expr.kind === 187 /* AsExpression */) { - expr = expr.expression; - } - // isLeftHandSideExpression is almost the correct criterion for when it is not necessary - // to parenthesize the expression before a dot. The known exceptions are: - // - // NewExpression: - // new C.x -> not the same as (new C).x - // NumberLiteral - // 1.x -> not the same as (1).x - // - if (ts.isLeftHandSideExpression(expr) && - expr.kind !== 167 /* NewExpression */ && - expr.kind !== 8 /* NumericLiteral */) { - return expr; - } - var node = ts.createSynthesizedNode(170 /* ParenthesizedExpression */); - node.expression = expr; - return node; - } - function emitComputedPropertyName(node) { - write("["); - emitExpressionForPropertyName(node); - write("]"); - } - function emitMethod(node) { - if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { - write("*"); - } - emit(node.name); - if (languageVersion < 2 /* ES6 */) { - write(": function "); - } - emitSignatureAndBody(node); - } - function emitPropertyAssignment(node) { - emit(node.name); - write(": "); - // This is to ensure that we emit comment in the following case: - // For example: - // obj = { - // id: /*comment1*/ ()=>void - // } - // "comment1" is not considered to be leading comment for node.initializer - // but rather a trailing comment on the previous node. - emitTrailingCommentsOfPosition(node.initializer.pos); - emit(node.initializer); - } - // Return true if identifier resolves to an exported member of a namespace - function isNamespaceExportReference(node) { - var container = resolver.getReferencedExportContainer(node); - return container && container.kind !== 246 /* SourceFile */; - } - function emitShorthandPropertyAssignment(node) { - // The name property of a short-hand property assignment is considered an expression position, so here - // we manually emit the identifier to avoid rewriting. - writeTextOfNode(currentSourceFile, node.name); - // If emitting pre-ES6 code, or if the name requires rewriting when resolved as an expression identifier, - // we emit a normal property assignment. For example: - // module m { - // export let y; - // } - // module m { - // let obj = { y }; - // } - // Here we need to emit obj = { y : m.y } regardless of the output target. - if (languageVersion < 2 /* ES6 */ || isNamespaceExportReference(node.name)) { - // Emit identifier as an identifier - write(": "); - emit(node.name); - } - } - function tryEmitConstantValue(node) { - var constantValue = tryGetConstEnumValue(node); - if (constantValue !== undefined) { - write(constantValue.toString()); - if (!compilerOptions.removeComments) { - var propertyName = node.kind === 164 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); - write(" /* " + propertyName + " */"); - } - return true; - } - return false; - } - function tryGetConstEnumValue(node) { - if (compilerOptions.isolatedModules) { - return undefined; - } - return node.kind === 164 /* PropertyAccessExpression */ || node.kind === 165 /* ElementAccessExpression */ - ? resolver.getConstantValue(node) - : undefined; - } - // Returns 'true' if the code was actually indented, false otherwise. - // If the code is not indented, an optional valueToWriteWhenNotIndenting will be - // emitted instead. - function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { - var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); - // Always use a newline for synthesized code if the synthesizer desires it. - var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); - if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { - increaseIndent(); - writeLine(); - return true; - } - else { - if (valueToWriteWhenNotIndenting) { - write(valueToWriteWhenNotIndenting); - } - return false; - } - } - function emitPropertyAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); - // 1 .toString is a valid property access, emit a space after the literal - // Also emit a space if expression is a integer const enum value - it will appear in generated code as numeric literal - var shouldEmitSpace; - if (!indentedBeforeDot) { - if (node.expression.kind === 8 /* NumericLiteral */) { - // check if numeric literal was originally written with a dot - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); - shouldEmitSpace = text.indexOf(ts.tokenToString(21 /* DotToken */)) < 0; - } - else { - // check if constant enum value is integer - var constantValue = tryGetConstEnumValue(node.expression); - // isFinite handles cases when constantValue is undefined - shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; - } - } - if (shouldEmitSpace) { - write(" ."); - } - else { - write("."); - } - var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); - emit(node.name); - decreaseIndentIf(indentedBeforeDot, indentedAfterDot); - } - function emitQualifiedName(node) { - emit(node.left); - write("."); - emit(node.right); - } - function emitQualifiedNameAsExpression(node, useFallback) { - if (node.left.kind === 67 /* Identifier */) { - emitEntityNameAsExpression(node.left, useFallback); - } - else if (useFallback) { - var temp = createAndRecordTempVariable(0 /* Auto */); - write("("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(node.left, /*useFallback*/ true); - write(") && "); - emitNodeWithoutSourceMap(temp); - } - else { - emitEntityNameAsExpression(node.left, /*useFallback*/ false); - } - write("."); - emit(node.right); - } - function emitEntityNameAsExpression(node, useFallback) { - switch (node.kind) { - case 67 /* Identifier */: - if (useFallback) { - write("typeof "); - emitExpressionIdentifier(node); - write(" !== 'undefined' && "); - } - emitExpressionIdentifier(node); - break; - case 133 /* QualifiedName */: - emitQualifiedNameAsExpression(node, useFallback); - break; - } - } - function emitIndexedAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("["); - emit(node.argumentExpression); - write("]"); - } - function hasSpreadElement(elements) { - return ts.forEach(elements, function (e) { return e.kind === 183 /* SpreadElementExpression */; }); - } - function skipParentheses(node) { - while (node.kind === 170 /* ParenthesizedExpression */ || node.kind === 169 /* TypeAssertionExpression */ || node.kind === 187 /* AsExpression */) { - node = node.expression; - } - return node; - } - function emitCallTarget(node) { - if (node.kind === 67 /* Identifier */ || node.kind === 95 /* ThisKeyword */ || node.kind === 93 /* SuperKeyword */) { - emit(node); - return node; - } - var temp = createAndRecordTempVariable(0 /* Auto */); - write("("); - emit(temp); - write(" = "); - emit(node); - write(")"); - return temp; - } - function emitCallWithSpread(node) { - var target; - var expr = skipParentheses(node.expression); - if (expr.kind === 164 /* PropertyAccessExpression */) { - // Target will be emitted as "this" argument - target = emitCallTarget(expr.expression); - write("."); - emit(expr.name); - } - else if (expr.kind === 165 /* ElementAccessExpression */) { - // Target will be emitted as "this" argument - target = emitCallTarget(expr.expression); - write("["); - emit(expr.argumentExpression); - write("]"); - } - else if (expr.kind === 93 /* SuperKeyword */) { - target = expr; - write("_super"); - } - else { - emit(node.expression); - } - write(".apply("); - if (target) { - if (target.kind === 93 /* SuperKeyword */) { - // Calls of form super(...) and super.foo(...) - emitThis(target); - } - else { - // Calls of form obj.foo(...) - emit(target); - } - } - else { - // Calls of form foo(...) - write("void 0"); - } - write(", "); - emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false, /*useConcat*/ true); - write(")"); - } - function emitCallExpression(node) { - if (languageVersion < 2 /* ES6 */ && hasSpreadElement(node.arguments)) { - emitCallWithSpread(node); - return; - } - var superCall = false; - if (node.expression.kind === 93 /* SuperKeyword */) { - emitSuper(node.expression); - superCall = true; - } - else { - emit(node.expression); - superCall = node.expression.kind === 164 /* PropertyAccessExpression */ && node.expression.expression.kind === 93 /* SuperKeyword */; - } - if (superCall && languageVersion < 2 /* ES6 */) { - write(".call("); - emitThis(node.expression); - if (node.arguments.length) { - write(", "); - emitCommaList(node.arguments); - } - write(")"); - } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitNewExpression(node) { - write("new "); - // Spread operator logic is supported in new expressions in ES5 using a combination - // of Function.prototype.bind() and Function.prototype.apply(). - // - // Example: - // - // var args = [1, 2, 3, 4, 5]; - // new Array(...args); - // - // is compiled into the following ES5: - // - // var args = [1, 2, 3, 4, 5]; - // new (Array.bind.apply(Array, [void 0].concat(args))); - // - // The 'thisArg' to 'bind' is ignored when invoking the result of 'bind' with 'new', - // Thus, we set it to undefined ('void 0'). - if (languageVersion === 1 /* ES5 */ && - node.arguments && - hasSpreadElement(node.arguments)) { - write("("); - var target = emitCallTarget(node.expression); - write(".bind.apply("); - emit(target); - write(", [void 0].concat("); - emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiline*/ false, /*trailingComma*/ false, /*useConcat*/ false); - write(")))"); - write("()"); - } - else { - emit(node.expression); - if (node.arguments) { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - } - function emitTaggedTemplateExpression(node) { - if (languageVersion >= 2 /* ES6 */) { - emit(node.tag); - write(" "); - emit(node.template); - } - else { - emitDownlevelTaggedTemplate(node); - } - } - function emitParenExpression(node) { - // If the node is synthesized, it means the emitter put the parentheses there, - // not the user. If we didn't want them, the emitter would not have put them - // there. - if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 172 /* ArrowFunction */) { - if (node.expression.kind === 169 /* TypeAssertionExpression */ || node.expression.kind === 187 /* AsExpression */) { - var operand = node.expression.expression; - // Make sure we consider all nested cast expressions, e.g.: - // (-A).x; - while (operand.kind === 169 /* TypeAssertionExpression */ || operand.kind === 187 /* AsExpression */) { - operand = operand.expression; - } - // We have an expression of the form: (SubExpr) - // Emitting this as (SubExpr) is really not desirable. We would like to emit the subexpr as is. - // Omitting the parentheses, however, could cause change in the semantics of the generated - // code if the casted expression has a lower precedence than the rest of the expression, e.g.: - // (new A).foo should be emitted as (new A).foo and not new A.foo - // (typeof A).toString() should be emitted as (typeof A).toString() and not typeof A.toString() - // new (A()) should be emitted as new (A()) and not new A() - // (function foo() { })() should be emitted as an IIF (function foo(){})() and not declaration function foo(){} () - if (operand.kind !== 177 /* PrefixUnaryExpression */ && - operand.kind !== 175 /* VoidExpression */ && - operand.kind !== 174 /* TypeOfExpression */ && - operand.kind !== 173 /* DeleteExpression */ && - operand.kind !== 178 /* PostfixUnaryExpression */ && - operand.kind !== 167 /* NewExpression */ && - !(operand.kind === 166 /* CallExpression */ && node.parent.kind === 167 /* NewExpression */) && - !(operand.kind === 171 /* FunctionExpression */ && node.parent.kind === 166 /* CallExpression */) && - !(operand.kind === 8 /* NumericLiteral */ && node.parent.kind === 164 /* PropertyAccessExpression */)) { - emit(operand); - return; - } - } - } - write("("); - emit(node.expression); - write(")"); - } - function emitDeleteExpression(node) { - write(ts.tokenToString(76 /* DeleteKeyword */)); - write(" "); - emit(node.expression); - } - function emitVoidExpression(node) { - write(ts.tokenToString(101 /* VoidKeyword */)); - write(" "); - emit(node.expression); - } - function emitTypeOfExpression(node) { - write(ts.tokenToString(99 /* TypeOfKeyword */)); - write(" "); - emit(node.expression); - } - function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { - if (!isCurrentFileSystemExternalModule() || node.kind !== 67 /* Identifier */ || ts.nodeIsSynthesized(node)) { - return false; - } - var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 209 /* VariableDeclaration */ || node.parent.kind === 161 /* BindingElement */); - var targetDeclaration = isVariableDeclarationOrBindingElement - ? node.parent - : resolver.getReferencedValueDeclaration(node); - return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true); - } - function emitPrefixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - // emit - // ++x - // as - // exports('x', ++x) - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - } - write(ts.tokenToString(node.operator)); - // In some cases, we need to emit a space between the operator and the operand. One obvious case - // is when the operator is an identifier, like delete or typeof. We also need to do this for plus - // and minus expressions in certain cases. Specifically, consider the following two cases (parens - // are just for clarity of exposition, and not part of the source code): - // - // (+(+1)) - // (+(++1)) - // - // We need to emit a space in both cases. In the first case, the absence of a space will make - // the resulting expression a prefix increment operation. And in the second, it will make the resulting - // expression a prefix increment whose operand is a plus expression - (++(+x)) - // The same is true of minus of course. - if (node.operand.kind === 177 /* PrefixUnaryExpression */) { - var operand = node.operand; - if (node.operator === 35 /* PlusToken */ && (operand.operator === 35 /* PlusToken */ || operand.operator === 40 /* PlusPlusToken */)) { - write(" "); - } - else if (node.operator === 36 /* MinusToken */ && (operand.operator === 36 /* MinusToken */ || operand.operator === 41 /* MinusMinusToken */)) { - write(" "); - } - } - emit(node.operand); - if (exportChanged) { - write(")"); - } - } - function emitPostfixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - // export function returns the value that was passes as the second argument - // however for postfix unary expressions result value should be the value before modification. - // emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)' - write("(" + exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - write(ts.tokenToString(node.operator)); - emit(node.operand); - if (node.operator === 40 /* PlusPlusToken */) { - write(") - 1)"); - } - else { - write(") + 1)"); - } - } - else { - emit(node.operand); - write(ts.tokenToString(node.operator)); - } - } - function shouldHoistDeclarationInSystemJsModule(node) { - return isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ false); - } - /* - * Checks if given node is a source file level declaration (not nested in module/function). - * If 'isExported' is true - then declaration must also be exported. - * This function is used in two cases: - * - check if node is a exported source file level value to determine - * if we should also export the value after its it changed - * - check if node is a source level declaration to emit it differently, - * i.e non-exported variable statement 'var x = 1' is hoisted so - * we we emit variable statement 'var' should be dropped. - */ - function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { - if (!node || languageVersion >= 2 /* ES6 */ || !isCurrentFileSystemExternalModule()) { - return false; - } - var current = node; - while (current) { - if (current.kind === 246 /* SourceFile */) { - return !isExported || ((ts.getCombinedNodeFlags(node) & 1 /* Export */) !== 0); - } - else if (ts.isFunctionLike(current) || current.kind === 217 /* ModuleBlock */) { - return false; - } - else { - current = current.parent; - } - } - } - function emitBinaryExpression(node) { - if (languageVersion < 2 /* ES6 */ && node.operatorToken.kind === 55 /* EqualsToken */ && - (node.left.kind === 163 /* ObjectLiteralExpression */ || node.left.kind === 162 /* ArrayLiteralExpression */)) { - emitDestructuring(node, node.parent.kind === 193 /* ExpressionStatement */); - } - else { - var exportChanged = node.operatorToken.kind >= 55 /* FirstAssignment */ && - node.operatorToken.kind <= 66 /* LastAssignment */ && - isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); - if (exportChanged) { - // emit assignment 'x y' as 'exports("x", x y)' - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.left); - write("\", "); - } - emit(node.left); - var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 /* CommaToken */ ? " " : undefined); - write(ts.tokenToString(node.operatorToken.kind)); - var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); - emit(node.right); - decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); - if (exportChanged) { - write(")"); - } - } - } - function synthesizedNodeStartsOnNewLine(node) { - return ts.nodeIsSynthesized(node) && node.startsOnNewLine; - } - function emitConditionalExpression(node) { - emit(node.condition); - var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); - write("?"); - var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); - emit(node.whenTrue); - decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); - var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); - write(":"); - var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); - emit(node.whenFalse); - decreaseIndentIf(indentedBeforeColon, indentedAfterColon); - } - // Helper function to decrease the indent if we previously indented. Allows multiple - // previous indent values to be considered at a time. This also allows caller to just - // call this once, passing in all their appropriate indent values, instead of needing - // to call this helper function multiple times. - function decreaseIndentIf(value1, value2) { - if (value1) { - decreaseIndent(); - } - if (value2) { - decreaseIndent(); - } - } - function isSingleLineEmptyBlock(node) { - if (node && node.kind === 190 /* Block */) { - var block = node; - return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); - } - } - function emitBlock(node) { - if (isSingleLineEmptyBlock(node)) { - emitToken(15 /* OpenBraceToken */, node.pos); - write(" "); - emitToken(16 /* CloseBraceToken */, node.statements.end); - return; - } - emitToken(15 /* OpenBraceToken */, node.pos); - increaseIndent(); - scopeEmitStart(node.parent); - if (node.kind === 217 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 216 /* ModuleDeclaration */); - emitCaptureThisForNodeIfNecessary(node.parent); - } - emitLines(node.statements); - if (node.kind === 217 /* ModuleBlock */) { - emitTempDeclarations(/*newLine*/ true); - } - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.statements.end); - scopeEmitEnd(); - } - function emitEmbeddedStatement(node) { - if (node.kind === 190 /* Block */) { - write(" "); - emit(node); - } - else { - increaseIndent(); - writeLine(); - emit(node); - decreaseIndent(); - } - } - function emitExpressionStatement(node) { - emitParenthesizedIf(node.expression, /*parenthesized*/ node.expression.kind === 172 /* ArrowFunction */); - write(";"); - } - function emitIfStatement(node) { - var endPos = emitToken(86 /* IfKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - emit(node.expression); - emitToken(18 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.thenStatement); - if (node.elseStatement) { - writeLine(); - emitToken(78 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 194 /* IfStatement */) { - write(" "); - emit(node.elseStatement); - } - else { - emitEmbeddedStatement(node.elseStatement); - } - } - } - function emitDoStatement(node) { - write("do"); - emitEmbeddedStatement(node.statement); - if (node.statement.kind === 190 /* Block */) { - write(" "); - } - else { - writeLine(); - } - write("while ("); - emit(node.expression); - write(");"); - } - function emitWhileStatement(node) { - write("while ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - /** - * Returns true if start of variable declaration list was emitted. - * Returns false if nothing was written - this can happen for source file level variable declarations - * in system modules where such variable declarations are hoisted. - */ - function tryEmitStartOfVariableDeclarationList(decl, startPos) { - if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) { - // variables in variable declaration list were already hoisted - return false; - } - var tokenKind = 100 /* VarKeyword */; - if (decl && languageVersion >= 2 /* ES6 */) { - if (ts.isLet(decl)) { - tokenKind = 106 /* LetKeyword */; - } - else if (ts.isConst(decl)) { - tokenKind = 72 /* ConstKeyword */; - } - } - if (startPos !== undefined) { - emitToken(tokenKind, startPos); - write(" "); - } - else { - switch (tokenKind) { - case 100 /* VarKeyword */: - write("var "); - break; - case 106 /* LetKeyword */: - write("let "); - break; - case 72 /* ConstKeyword */: - write("const "); - break; - } - } - return true; - } - function emitVariableDeclarationListSkippingUninitializedEntries(list) { - var started = false; - for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { - var decl = _b[_a]; - if (!decl.initializer) { - continue; - } - if (!started) { - started = true; - } - else { - write(", "); - } - emit(decl); - } - return started; - } - function emitForStatement(node) { - var endPos = emitToken(84 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - if (node.initializer && node.initializer.kind === 210 /* VariableDeclarationList */) { - var variableDeclarationList = node.initializer; - var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - if (startIsEmitted) { - emitCommaList(variableDeclarationList.declarations); - } - else { - emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); - } - } - else if (node.initializer) { - emit(node.initializer); - } - write(";"); - emitOptional(" ", node.condition); - write(";"); - emitOptional(" ", node.incrementor); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForInOrForOfStatement(node) { - if (languageVersion < 2 /* ES6 */ && node.kind === 199 /* ForOfStatement */) { - return emitDownLevelForOfStatement(node); - } - var endPos = emitToken(84 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - if (node.initializer.kind === 210 /* VariableDeclarationList */) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - emit(variableDeclarationList.declarations[0]); - } - } - else { - emit(node.initializer); - } - if (node.kind === 198 /* ForInStatement */) { - write(" in "); - } - else { - write(" of "); - } - emit(node.expression); - emitToken(18 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.statement); - } - function emitDownLevelForOfStatement(node) { - // The following ES6 code: - // - // for (let v of expr) { } - // - // should be emitted as - // - // for (let _i = 0, _a = expr; _i < _a.length; _i++) { - // let v = _a[_i]; - // } - // - // where _a and _i are temps emitted to capture the RHS and the counter, - // respectively. - // When the left hand side is an expression instead of a let declaration, - // the "let v" is not emitted. - // When the left hand side is a let/const, the v is renamed if there is - // another v in scope. - // Note that all assignments to the LHS are emitted in the body, including - // all destructuring. - // Note also that because an extra statement is needed to assign to the LHS, - // for-of bodies are always emitted as blocks. - var endPos = emitToken(84 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - // Do not emit the LHS let declaration yet, because it might contain destructuring. - // Do not call recordTempDeclaration because we are declaring the temps - // right here. Recording means they will be declared later. - // In the case where the user wrote an identifier as the RHS, like this: - // - // for (let v of arr) { } - // - // we don't want to emit a temporary variable for the RHS, just use it directly. - var rhsIsIdentifier = node.expression.kind === 67 /* Identifier */; - var counter = createTempVariable(268435456 /* _i */); - var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0 /* Auto */); - // This is the let keyword for the counter and rhsReference. The let keyword for - // the LHS will be emitted inside the body. - emitStart(node.expression); - write("var "); - // _i = 0 - emitNodeWithoutSourceMap(counter); - write(" = 0"); - emitEnd(node.expression); - if (!rhsIsIdentifier) { - // , _a = expr - write(", "); - emitStart(node.expression); - emitNodeWithoutSourceMap(rhsReference); - write(" = "); - emitNodeWithoutSourceMap(node.expression); - emitEnd(node.expression); - } - write("; "); - // _i < _a.length; - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write(" < "); - emitNodeWithCommentsAndWithoutSourcemap(rhsReference); - write(".length"); - emitEnd(node.initializer); - write("; "); - // _i++) - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write("++"); - emitEnd(node.initializer); - emitToken(18 /* CloseParenToken */, node.expression.end); - // Body - write(" {"); - writeLine(); - increaseIndent(); - // Initialize LHS - // let v = _a[_i]; - var rhsIterationValue = createElementAccessExpression(rhsReference, counter); - emitStart(node.initializer); - if (node.initializer.kind === 210 /* VariableDeclarationList */) { - write("var "); - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length > 0) { - var declaration = variableDeclarationList.declarations[0]; - if (ts.isBindingPattern(declaration.name)) { - // This works whether the declaration is a var, let, or const. - // It will use rhsIterationValue _a[_i] as the initializer. - emitDestructuring(declaration, /*isAssignmentExpressionStatement*/ false, rhsIterationValue); - } - else { - // The following call does not include the initializer, so we have - // to emit it separately. - emitNodeWithCommentsAndWithoutSourcemap(declaration); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - // It's an empty declaration list. This can only happen in an error case, if the user wrote - // for (let of []) {} - emitNodeWithoutSourceMap(createTempVariable(0 /* Auto */)); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - // Initializer is an expression. Emit the expression in the body, so that it's - // evaluated on every iteration. - var assignmentExpression = createBinaryExpression(node.initializer, 55 /* EqualsToken */, rhsIterationValue, /*startsOnNewLine*/ false); - if (node.initializer.kind === 162 /* ArrayLiteralExpression */ || node.initializer.kind === 163 /* ObjectLiteralExpression */) { - // This is a destructuring pattern, so call emitDestructuring instead of emit. Calling emit will not work, because it will cause - // the BinaryExpression to be passed in instead of the expression statement, which will cause emitDestructuring to crash. - emitDestructuring(assignmentExpression, /*isAssignmentExpressionStatement*/ true, /*value*/ undefined); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); - } - } - emitEnd(node.initializer); - write(";"); - if (node.statement.kind === 190 /* Block */) { - emitLines(node.statement.statements); - } - else { - writeLine(); - emit(node.statement); - } - writeLine(); - decreaseIndent(); - write("}"); - } - function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 201 /* BreakStatement */ ? 68 /* BreakKeyword */ : 73 /* ContinueKeyword */, node.pos); - emitOptional(" ", node.label); - write(";"); - } - function emitReturnStatement(node) { - emitToken(92 /* ReturnKeyword */, node.pos); - emitOptional(" ", node.expression); - write(";"); - } - function emitWithStatement(node) { - write("with ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitSwitchStatement(node) { - var endPos = emitToken(94 /* SwitchKeyword */, node.pos); - write(" "); - emitToken(17 /* OpenParenToken */, endPos); - emit(node.expression); - endPos = emitToken(18 /* CloseParenToken */, node.expression.end); - write(" "); - emitCaseBlock(node.caseBlock, endPos); - } - function emitCaseBlock(node, startPos) { - emitToken(15 /* OpenBraceToken */, startPos); - increaseIndent(); - emitLines(node.clauses); - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.clauses.end); - } - function nodeStartPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function nodeEndPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, node2.end); - } - function nodeEndIsOnSameLineAsNodeStart(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function emitCaseOrDefaultClause(node) { - if (node.kind === 239 /* CaseClause */) { - write("case "); - emit(node.expression); - write(":"); - } - else { - write("default:"); - } - if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { - write(" "); - emit(node.statements[0]); - } - else { - increaseIndent(); - emitLines(node.statements); - decreaseIndent(); - } - } - function emitThrowStatement(node) { - write("throw "); - emit(node.expression); - write(";"); - } - function emitTryStatement(node) { - write("try "); - emit(node.tryBlock); - emit(node.catchClause); - if (node.finallyBlock) { - writeLine(); - write("finally "); - emit(node.finallyBlock); - } - } - function emitCatchClause(node) { - writeLine(); - var endPos = emitToken(70 /* CatchKeyword */, node.pos); - write(" "); - emitToken(17 /* OpenParenToken */, endPos); - emit(node.variableDeclaration); - emitToken(18 /* CloseParenToken */, node.variableDeclaration ? node.variableDeclaration.end : endPos); - write(" "); - emitBlock(node.block); - } - function emitDebuggerStatement(node) { - emitToken(74 /* DebuggerKeyword */, node.pos); - write(";"); - } - function emitLabelledStatement(node) { - emit(node.label); - write(": "); - emit(node.statement); - } - function getContainingModule(node) { - do { - node = node.parent; - } while (node && node.kind !== 216 /* ModuleDeclaration */); - return node; - } - function emitContainingModuleName(node) { - var container = getContainingModule(node); - write(container ? getGeneratedNameForNode(container) : "exports"); - } - function emitModuleMemberName(node) { - emitStart(node.name); - if (ts.getCombinedNodeFlags(node) & 1 /* Export */) { - var container = getContainingModule(node); - if (container) { - write(getGeneratedNameForNode(container)); - write("."); - } - else if (languageVersion < 2 /* ES6 */ && compilerOptions.module !== 4 /* System */) { - write("exports."); - } - } - emitNodeWithCommentsAndWithoutSourcemap(node.name); - emitEnd(node.name); - } - function createVoidZero() { - var zero = ts.createSynthesizedNode(8 /* NumericLiteral */); - zero.text = "0"; - var result = ts.createSynthesizedNode(175 /* VoidExpression */); - result.expression = zero; - return result; - } - function emitEs6ExportDefaultCompat(node) { - if (node.parent.kind === 246 /* SourceFile */) { - ts.Debug.assert(!!(node.flags & 1024 /* Default */) || node.kind === 225 /* ExportAssignment */); - // only allow export default at a source file level - if (compilerOptions.module === 1 /* CommonJS */ || compilerOptions.module === 2 /* AMD */ || compilerOptions.module === 3 /* UMD */) { - if (!currentSourceFile.symbol.exports["___esModule"]) { - if (languageVersion === 1 /* ES5 */) { - // default value of configurable, enumerable, writable are `false`. - write("Object.defineProperty(exports, \"__esModule\", { value: true });"); - writeLine(); - } - else if (languageVersion === 0 /* ES3 */) { - write("exports.__esModule = true;"); - writeLine(); - } - } - } - } - } - function emitExportMemberAssignment(node) { - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - // emit call to exporter only for top level nodes - if (compilerOptions.module === 4 /* System */ && node.parent === currentSourceFile) { - // emit export default as - // export("default", ) - write(exportFunctionForFile + "(\""); - if (node.flags & 1024 /* Default */) { - write("default"); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - write("\", "); - emitDeclarationName(node); - write(")"); - } - else { - if (node.flags & 1024 /* Default */) { - emitEs6ExportDefaultCompat(node); - if (languageVersion === 0 /* ES3 */) { - write("exports[\"default\"]"); - } - else { - write("exports.default"); - } - } - else { - emitModuleMemberName(node); - } - write(" = "); - emitDeclarationName(node); - } - emitEnd(node); - write(";"); - } - } - function emitExportMemberAssignments(name) { - if (compilerOptions.module === 4 /* System */) { - return; - } - if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { - for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { - var specifier = _b[_a]; - writeLine(); - emitStart(specifier.name); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - emitEnd(specifier.name); - write(" = "); - emitExpressionIdentifier(name); - write(";"); - } - } - } - function emitExportSpecifierInSystemModule(specifier) { - ts.Debug.assert(compilerOptions.module === 4 /* System */); - if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { - return; - } - writeLine(); - emitStart(specifier.name); - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write("\", "); - emitExpressionIdentifier(specifier.propertyName || specifier.name); - write(")"); - emitEnd(specifier.name); - write(";"); - } - function emitDestructuring(root, isAssignmentExpressionStatement, value) { - var emitCount = 0; - // An exported declaration is actually emitted as an assignment (to a property on the module object), so - // temporary variables in an exported declaration need to have real declarations elsewhere - // Also temporary variables should be explicitly allocated for source level declarations when module target is system - // because actual variable declarations are hoisted - var canDefineTempVariablesInPlace = false; - if (root.kind === 209 /* VariableDeclaration */) { - var isExported = ts.getCombinedNodeFlags(root) & 1 /* Export */; - var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); - canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; - } - else if (root.kind === 136 /* Parameter */) { - canDefineTempVariablesInPlace = true; - } - if (root.kind === 179 /* BinaryExpression */) { - emitAssignmentExpression(root); - } - else { - ts.Debug.assert(!isAssignmentExpressionStatement); - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 209 /* VariableDeclaration */ || name.parent.kind === 161 /* BindingElement */); - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(name); - write("\", "); - } - if (isVariableDeclarationOrBindingElement) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - if (exportChanged) { - write(")"); - } - } - /** - * Ensures that there exists a declared identifier whose value holds the given expression. - * This function is useful to ensure that the expression's value can be read from in subsequent expressions. - * Unless 'reuseIdentifierExpressions' is false, 'expr' will be returned if it is just an identifier. - * - * @param expr the expression whose value needs to be bound. - * @param reuseIdentifierExpressions true if identifier expressions can simply be returned; - * false if it is necessary to always emit an identifier. - */ - function ensureIdentifier(expr, reuseIdentifierExpressions) { - if (expr.kind === 67 /* Identifier */ && reuseIdentifierExpressions) { - return expr; - } - var identifier = createTempVariable(0 /* Auto */); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - return identifier; - } - function createDefaultValueCheck(value, defaultValue) { - // The value expression will be evaluated twice, so for anything but a simple identifier - // we need to generate a temporary variable - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - // Return the expression 'value === void 0 ? defaultValue : value' - var equals = ts.createSynthesizedNode(179 /* BinaryExpression */); - equals.left = value; - equals.operatorToken = ts.createSynthesizedNode(32 /* EqualsEqualsEqualsToken */); - equals.right = createVoidZero(); - return createConditionalExpression(equals, defaultValue, value); - } - function createConditionalExpression(condition, whenTrue, whenFalse) { - var cond = ts.createSynthesizedNode(180 /* ConditionalExpression */); - cond.condition = condition; - cond.questionToken = ts.createSynthesizedNode(52 /* QuestionToken */); - cond.whenTrue = whenTrue; - cond.colonToken = ts.createSynthesizedNode(53 /* ColonToken */); - cond.whenFalse = whenFalse; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createSynthesizedNode(8 /* NumericLiteral */); - node.text = "" + value; - return node; - } - function createPropertyAccessForDestructuringProperty(object, propName) { - // We create a synthetic copy of the identifier in order to avoid the rewriting that might - // otherwise occur when the identifier is emitted. - var syntheticName = ts.createSynthesizedNode(propName.kind); - syntheticName.text = propName.text; - if (syntheticName.kind !== 67 /* Identifier */) { - return createElementAccessExpression(object, syntheticName); - } - return createPropertyAccessExpression(object, syntheticName); - } - function createSliceCall(value, sliceIndex) { - var call = ts.createSynthesizedNode(166 /* CallExpression */); - var sliceIdentifier = ts.createSynthesizedNode(67 /* Identifier */); - sliceIdentifier.text = "slice"; - call.expression = createPropertyAccessExpression(value, sliceIdentifier); - call.arguments = ts.createSynthesizedNodeArray(); - call.arguments[0] = createNumericLiteral(sliceIndex); - return call; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - // For anything but a single element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - } - for (var _a = 0; _a < properties.length; _a++) { - var p = properties[_a]; - if (p.kind === 243 /* PropertyAssignment */ || p.kind === 244 /* ShorthandPropertyAssignment */) { - var propName = p.name; - emitDestructuringAssignment(p.initializer || propName, createPropertyAccessForDestructuringProperty(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - // For anything but a single element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 185 /* OmittedExpression */) { - if (e.kind !== 183 /* SpreadElementExpression */) { - emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === elements.length - 1) { - emitDestructuringAssignment(e.expression, createSliceCall(value, i)); - } - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 179 /* BinaryExpression */ && target.operatorToken.kind === 55 /* EqualsToken */) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 163 /* ObjectLiteralExpression */) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 162 /* ArrayLiteralExpression */) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { - emit(value); - } - else if (isAssignmentExpressionStatement) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 170 /* ParenthesizedExpression */) { - write("("); - } - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 170 /* ParenthesizedExpression */) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - // Combine value and initializer - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - // Use 'void 0' in absence of value and initializer - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - var numElements = elements.length; - if (numElements !== 1) { - // For anything other than a single-element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. Additionally, if we have zero elements - // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, - // so in that case, we'll intentionally create that temporary. - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0); - } - for (var i = 0; i < numElements; i++) { - var element = elements[i]; - if (pattern.kind === 159 /* ObjectBindingPattern */) { - // Rewrite element to a declaration with an initializer that fetches property - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); - } - else if (element.kind !== 185 /* OmittedExpression */) { - if (!element.dotDotDotToken) { - // Rewrite element to a declaration that accesses array element at index i - emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === numElements - 1) { - emitBindingElement(element, createSliceCall(value, i)); - } - } - } - } - else { - emitAssignment(target.name, value); - } - } - } - function emitVariableDeclaration(node) { - if (ts.isBindingPattern(node.name)) { - if (languageVersion < 2 /* ES6 */) { - emitDestructuring(node, /*isAssignmentExpressionStatement*/ false); - } - else { - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - else { - var initializer = node.initializer; - if (!initializer && languageVersion < 2 /* ES6 */) { - // downlevel emit for non-initialized let bindings defined in loops - // for (...) { let x; } - // should be - // for (...) { var = void 0; } - // this is necessary to preserve ES6 semantic in scenarios like - // for (...) { let x; console.log(x); x = 1 } // assignment on one iteration should not affect other iterations - var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384 /* BlockScopedBindingInLoop */) && - (getCombinedFlagsForIdentifier(node.name) & 16384 /* Let */); - // NOTE: default initialization should not be added to let bindings in for-in\for-of statements - if (isUninitializedLet && - node.parent.parent.kind !== 198 /* ForInStatement */ && - node.parent.parent.kind !== 199 /* ForOfStatement */) { - initializer = createVoidZero(); - } - } - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(node.name); - write("\", "); - } - emitModuleMemberName(node); - emitOptional(" = ", initializer); - if (exportChanged) { - write(")"); - } - } - } - function emitExportVariableAssignments(node) { - if (node.kind === 185 /* OmittedExpression */) { - return; - } - var name = node.name; - if (name.kind === 67 /* Identifier */) { - emitExportMemberAssignments(name); - } - else if (ts.isBindingPattern(name)) { - ts.forEach(name.elements, emitExportVariableAssignments); - } - } - function getCombinedFlagsForIdentifier(node) { - if (!node.parent || (node.parent.kind !== 209 /* VariableDeclaration */ && node.parent.kind !== 161 /* BindingElement */)) { - return 0; - } - return ts.getCombinedNodeFlags(node.parent); - } - function isES6ExportedDeclaration(node) { - return !!(node.flags & 1 /* Export */) && - languageVersion >= 2 /* ES6 */ && - node.parent.kind === 246 /* SourceFile */; - } - function emitVariableStatement(node) { - var startIsEmitted = false; - if (node.flags & 1 /* Export */) { - if (isES6ExportedDeclaration(node)) { - // Exported ES6 module member - write("export "); - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - } - else { - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - if (startIsEmitted) { - emitCommaList(node.declarationList.declarations); - write(";"); - } - else { - var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); - if (atLeastOneItem) { - write(";"); - } - } - if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) { - ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); - } - } - function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { - // If we're not exporting the variables, there's nothing special here. - // Always emit comments for these nodes. - if (!(node.flags & 1 /* Export */)) { - return true; - } - // If we are exporting, but it's a top-level ES6 module exports, - // we'll emit the declaration list verbatim, so emit comments too. - if (isES6ExportedDeclaration(node)) { - return true; - } - // Otherwise, only emit if we have at least one initializer present. - for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { - var declaration = _b[_a]; - if (declaration.initializer) { - return true; - } - } - return false; - } - function emitParameter(node) { - if (languageVersion < 2 /* ES6 */) { - if (ts.isBindingPattern(node.name)) { - var name_23 = createTempVariable(0 /* Auto */); - if (!tempParameters) { - tempParameters = []; - } - tempParameters.push(name_23); - emit(name_23); - } - else { - emit(node.name); - } - } - else { - if (node.dotDotDotToken) { - write("..."); - } - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - function emitDefaultValueAssignments(node) { - if (languageVersion < 2 /* ES6 */) { - var tempIndex = 0; - ts.forEach(node.parameters, function (parameter) { - // A rest parameter cannot have a binding pattern or an initializer, - // so let's just ignore it. - if (parameter.dotDotDotToken) { - return; - } - var paramName = parameter.name, initializer = parameter.initializer; - if (ts.isBindingPattern(paramName)) { - // In cases where a binding pattern is simply '[]' or '{}', - // we usually don't want to emit a var declaration; however, in the presence - // of an initializer, we must emit that expression to preserve side effects. - var hasBindingElements = paramName.elements.length > 0; - if (hasBindingElements || initializer) { - writeLine(); - write("var "); - if (hasBindingElements) { - emitDestructuring(parameter, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]); - } - else { - emit(tempParameters[tempIndex]); - write(" = "); - emit(initializer); - } - write(";"); - tempIndex++; - } - } - else if (initializer) { - writeLine(); - emitStart(parameter); - write("if ("); - emitNodeWithoutSourceMap(paramName); - write(" === void 0)"); - emitEnd(parameter); - write(" { "); - emitStart(parameter); - emitNodeWithCommentsAndWithoutSourcemap(paramName); - write(" = "); - emitNodeWithCommentsAndWithoutSourcemap(initializer); - emitEnd(parameter); - write("; }"); - } - }); - } - } - function emitRestParameter(node) { - if (languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node)) { - var restIndex = node.parameters.length - 1; - var restParam = node.parameters[restIndex]; - // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. - if (ts.isBindingPattern(restParam.name)) { - return; - } - var tempName = createTempVariable(268435456 /* _i */).text; - writeLine(); - emitLeadingComments(restParam); - emitStart(restParam); - write("var "); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write(" = [];"); - emitEnd(restParam); - emitTrailingComments(restParam); - writeLine(); - write("for ("); - emitStart(restParam); - write("var " + tempName + " = " + restIndex + ";"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + " < arguments.length;"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + "++"); - emitEnd(restParam); - write(") {"); - increaseIndent(); - writeLine(); - emitStart(restParam); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); - emitEnd(restParam); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitAccessor(node) { - write(node.kind === 143 /* GetAccessor */ ? "get " : "set "); - emit(node.name); - emitSignatureAndBody(node); - } - function shouldEmitAsArrowFunction(node) { - return node.kind === 172 /* ArrowFunction */ && languageVersion >= 2 /* ES6 */; - } - function emitDeclarationName(node) { - if (node.name) { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - else { - write(getGeneratedNameForNode(node)); - } - } - function shouldEmitFunctionName(node) { - if (node.kind === 171 /* FunctionExpression */) { - // Emit name if one is present - return !!node.name; - } - if (node.kind === 211 /* FunctionDeclaration */) { - // Emit name if one is present, or emit generated name in down-level case (for export default case) - return !!node.name || languageVersion < 2 /* ES6 */; - } - } - function emitFunctionDeclaration(node) { - if (ts.nodeIsMissing(node.body)) { - return emitCommentsOnNotEmittedNode(node); - } - // TODO (yuisu) : we should not have special cases to condition emitting comments - // but have one place to fix check for these conditions. - if (node.kind !== 141 /* MethodDeclaration */ && node.kind !== 140 /* MethodSignature */ && - node.parent && node.parent.kind !== 243 /* PropertyAssignment */ && - node.parent.kind !== 166 /* CallExpression */) { - // 1. Methods will emit the comments as part of emitting method declaration - // 2. If the function is a property of object literal, emitting leading-comments - // is done by emitNodeWithoutSourceMap which then call this function. - // In particular, we would like to avoid emit comments twice in following case: - // For example: - // var obj = { - // id: - // /*comment*/ () => void - // } - // 3. If the function is an argument in call expression, emitting of comments will be - // taken care of in emit list of arguments inside of emitCallexpression - emitLeadingComments(node); - } - emitStart(node); - // For targeting below es6, emit functions-like declaration including arrow function using function keyword. - // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead - if (!shouldEmitAsArrowFunction(node)) { - if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024 /* Default */) { - write("default "); - } - } - write("function"); - if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { - write("*"); - } - write(" "); - } - if (shouldEmitFunctionName(node)) { - emitDeclarationName(node); - } - emitSignatureAndBody(node); - if (languageVersion < 2 /* ES6 */ && node.kind === 211 /* FunctionDeclaration */ && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - emitEnd(node); - if (node.kind !== 141 /* MethodDeclaration */ && node.kind !== 140 /* MethodSignature */) { - emitTrailingComments(node); - } - } - function emitCaptureThisForNodeIfNecessary(node) { - if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { - writeLine(); - emitStart(node); - write("var _this = this;"); - emitEnd(node); - } - } - function emitSignatureParameters(node) { - increaseIndent(); - write("("); - if (node) { - var parameters = node.parameters; - var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node) ? 1 : 0; - emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false); - } - write(")"); - decreaseIndent(); - } - function emitSignatureParametersForArrow(node) { - // Check whether the parameter list needs parentheses and preserve no-parenthesis - if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { - emit(node.parameters[0]); - return; - } - emitSignatureParameters(node); - } - function emitAsyncFunctionBodyForES6(node) { - var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); - var isArrowFunction = node.kind === 172 /* ArrowFunction */; - var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096 /* CaptureArguments */) !== 0; - var args; - // An async function is emit as an outer function that calls an inner - // generator function. To preserve lexical bindings, we pass the current - // `this` and `arguments` objects to `__awaiter`. The generator function - // passed to `__awaiter` is executed inside of the callback to the - // promise constructor. - // - // The emit for an async arrow without a lexical `arguments` binding might be: - // - // // input - // let a = async (b) => { await b; } - // - // // output - // let a = (b) => __awaiter(this, void 0, void 0, function* () { - // yield b; - // }); - // - // The emit for an async arrow with a lexical `arguments` binding might be: - // - // // input - // let a = async (b) => { await arguments[0]; } - // - // // output - // let a = (b) => __awaiter(this, arguments, void 0, function* (arguments) { - // yield arguments[0]; - // }); - // - // The emit for an async function expression without a lexical `arguments` binding - // might be: - // - // // input - // let a = async function (b) { - // await b; - // } - // - // // output - // let a = function (b) { - // return __awaiter(this, void 0, void 0, function* () { - // yield b; - // }); - // } - // - // The emit for an async function expression with a lexical `arguments` binding - // might be: - // - // // input - // let a = async function (b) { - // await arguments[0]; - // } - // - // // output - // let a = function (b) { - // return __awaiter(this, arguments, void 0, function* (_arguments) { - // yield _arguments[0]; - // }); - // } - // - // The emit for an async function expression with a lexical `arguments` binding - // and a return type annotation might be: - // - // // input - // let a = async function (b): MyPromise { - // await arguments[0]; - // } - // - // // output - // let a = function (b) { - // return __awaiter(this, arguments, MyPromise, function* (_arguments) { - // yield _arguments[0]; - // }); - // } - // - // If this is not an async arrow, emit the opening brace of the function body - // and the start of the return statement. - if (!isArrowFunction) { - write(" {"); - increaseIndent(); - writeLine(); - write("return"); - } - write(" __awaiter(this"); - if (hasLexicalArguments) { - write(", arguments"); - } - else { - write(", void 0"); - } - if (promiseConstructor) { - write(", "); - emitNodeWithoutSourceMap(promiseConstructor); - } - else { - write(", Promise"); - } - // Emit the call to __awaiter. - if (hasLexicalArguments) { - write(", function* (_arguments)"); - } - else { - write(", function* ()"); - } - // Emit the signature and body for the inner generator function. - emitFunctionBody(node); - write(")"); - // If this is not an async arrow, emit the closing brace of the outer function body. - if (!isArrowFunction) { - write(";"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitFunctionBody(node) { - if (!node.body) { - // There can be no body when there are parse errors. Just emit an empty block - // in that case. - write(" { }"); - } - else { - if (node.body.kind === 190 /* Block */) { - emitBlockFunctionBody(node, node.body); - } - else { - emitExpressionFunctionBody(node, node.body); - } - } - } - function emitSignatureAndBody(node) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - // When targeting ES6, emit arrow function natively in ES6 - if (shouldEmitAsArrowFunction(node)) { - emitSignatureParametersForArrow(node); - write(" =>"); - } - else { - emitSignatureParameters(node); - } - var isAsync = ts.isAsyncFunctionLike(node); - if (isAsync && languageVersion === 2 /* ES6 */) { - emitAsyncFunctionBodyForES6(node); - } - else { - emitFunctionBody(node); - } - if (!isES6ExportedDeclaration(node)) { - emitExportMemberAssignment(node); - } - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - // Returns true if any preamble code was emitted. - function emitFunctionBodyPreamble(node) { - emitCaptureThisForNodeIfNecessary(node); - emitDefaultValueAssignments(node); - emitRestParameter(node); - } - function emitExpressionFunctionBody(node, body) { - if (languageVersion < 2 /* ES6 */ || node.flags & 512 /* Async */) { - emitDownLevelExpressionFunctionBody(node, body); - return; - } - // For es6 and higher we can emit the expression as is. However, in the case - // where the expression might end up looking like a block when emitted, we'll - // also wrap it in parentheses first. For example if you have: a => {} - // then we need to generate: a => ({}) - write(" "); - // Unwrap all type assertions. - var current = body; - while (current.kind === 169 /* TypeAssertionExpression */) { - current = current.expression; - } - emitParenthesizedIf(body, current.kind === 163 /* ObjectLiteralExpression */); - } - function emitDownLevelExpressionFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - increaseIndent(); - var outPos = writer.getTextPos(); - emitDetachedComments(node.body); - emitFunctionBodyPreamble(node); - var preambleEmitted = writer.getTextPos() !== outPos; - decreaseIndent(); - // If we didn't have to emit any preamble code, then attempt to keep the arrow - // function on one line. - if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { - write(" "); - emitStart(body); - write("return "); - emit(body); - emitEnd(body); - write(";"); - emitTempDeclarations(/*newLine*/ false); - write(" "); - } - else { - increaseIndent(); - writeLine(); - emitLeadingComments(node.body); - write("return "); - emit(body); - write(";"); - emitTrailingComments(node.body); - emitTempDeclarations(/*newLine*/ true); - decreaseIndent(); - writeLine(); - } - emitStart(node.body); - write("}"); - emitEnd(node.body); - scopeEmitEnd(); - } - function emitBlockFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - var initialTextPos = writer.getTextPos(); - increaseIndent(); - emitDetachedComments(body.statements); - // Emit all the directive prologues (like "use strict"). These have to come before - // any other preamble code we write (like parameter initializers). - var startIndex = emitDirectivePrologues(body.statements, /*startWithNewLine*/ true); - emitFunctionBodyPreamble(node); - decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== initialTextPos; - if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { - for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { - var statement = _b[_a]; - write(" "); - emit(statement); - } - emitTempDeclarations(/*newLine*/ false); - write(" "); - emitLeadingCommentsOfPosition(body.statements.end); - } - else { - increaseIndent(); - emitLinesStartingAt(body.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - writeLine(); - emitLeadingCommentsOfPosition(body.statements.end); - decreaseIndent(); - } - emitToken(16 /* CloseBraceToken */, body.statements.end); - scopeEmitEnd(); - } - function findInitialSuperCall(ctor) { - if (ctor.body) { - var statement = ctor.body.statements[0]; - if (statement && statement.kind === 193 /* ExpressionStatement */) { - var expr = statement.expression; - if (expr && expr.kind === 166 /* CallExpression */) { - var func = expr.expression; - if (func && func.kind === 93 /* SuperKeyword */) { - return statement; - } - } - } - } - } - function emitParameterPropertyAssignments(node) { - ts.forEach(node.parameters, function (param) { - if (param.flags & 112 /* AccessibilityModifier */) { - writeLine(); - emitStart(param); - emitStart(param.name); - write("this."); - emitNodeWithoutSourceMap(param.name); - emitEnd(param.name); - write(" = "); - emit(param.name); - write(";"); - emitEnd(param); - } - }); - } - function emitMemberAccessForPropertyName(memberName) { - // This does not emit source map because it is emitted by caller as caller - // is aware how the property name changes to the property access - // eg. public x = 10; becomes this.x and static x = 10 becomes className.x - if (memberName.kind === 9 /* StringLiteral */ || memberName.kind === 8 /* NumericLiteral */) { - write("["); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - write("]"); - } - else if (memberName.kind === 134 /* ComputedPropertyName */) { - emitComputedPropertyName(memberName); - } - else { - write("."); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - } - } - function getInitializedProperties(node, isStatic) { - var properties = []; - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if (member.kind === 139 /* PropertyDeclaration */ && isStatic === ((member.flags & 128 /* Static */) !== 0) && member.initializer) { - properties.push(member); - } - } - return properties; - } - function emitPropertyDeclarations(node, properties) { - for (var _a = 0; _a < properties.length; _a++) { - var property = properties[_a]; - emitPropertyDeclaration(node, property); - } - } - function emitPropertyDeclaration(node, property, receiver, isExpression) { - writeLine(); - emitLeadingComments(property); - emitStart(property); - emitStart(property.name); - if (receiver) { - emit(receiver); - } - else { - if (property.flags & 128 /* Static */) { - emitDeclarationName(node); - } - else { - write("this"); - } - } - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - emit(property.initializer); - if (!isExpression) { - write(";"); - } - emitEnd(property); - emitTrailingComments(property); - } - function emitMemberFunctionsForES5AndLower(node) { - ts.forEach(node.members, function (member) { - if (member.kind === 189 /* SemicolonClassElement */) { - writeLine(); - write(";"); - } - else if (member.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */) { - if (!member.body) { - return emitCommentsOnNotEmittedNode(member); - } - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - emitClassMemberPrefix(node, member); - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emitFunctionDeclaration(member); - emitEnd(member); - write(";"); - emitTrailingComments(member); - } - else if (member.kind === 143 /* GetAccessor */ || member.kind === 144 /* SetAccessor */) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member === accessors.firstAccessor) { - writeLine(); - emitStart(member); - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("});"); - emitEnd(member); - } - } - }); - } - function emitMemberFunctionsForES6AndHigher(node) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if ((member.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */) && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - else if (member.kind === 141 /* MethodDeclaration */ || - member.kind === 143 /* GetAccessor */ || - member.kind === 144 /* SetAccessor */) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - if (member.flags & 128 /* Static */) { - write("static "); - } - if (member.kind === 143 /* GetAccessor */) { - write("get "); - } - else if (member.kind === 144 /* SetAccessor */) { - write("set "); - } - if (member.asteriskToken) { - write("*"); - } - emit(member.name); - emitSignatureAndBody(member); - emitEnd(member); - emitTrailingComments(member); - } - else if (member.kind === 189 /* SemicolonClassElement */) { - writeLine(); - write(";"); - } - } - } - function emitConstructor(node, baseTypeElement) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - emitConstructorWorker(node, baseTypeElement); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function emitConstructorWorker(node, baseTypeElement) { - // Check if we have property assignment inside class declaration. - // If there is property assignment, we need to emit constructor whether users define it or not - // If there is no property assignment, we can omit constructor if users do not define it - var hasInstancePropertyWithInitializer = false; - // Emit the constructor overload pinned comments - ts.forEach(node.members, function (member) { - if (member.kind === 142 /* Constructor */ && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - // Check if there is any non-static property assignment - if (member.kind === 139 /* PropertyDeclaration */ && member.initializer && (member.flags & 128 /* Static */) === 0) { - hasInstancePropertyWithInitializer = true; - } - }); - var ctor = ts.getFirstConstructorWithBody(node); - // For target ES6 and above, if there is no user-defined constructor and there is no property assignment - // do not emit constructor in class declaration. - if (languageVersion >= 2 /* ES6 */ && !ctor && !hasInstancePropertyWithInitializer) { - return; - } - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - if (languageVersion < 2 /* ES6 */) { - write("function "); - emitDeclarationName(node); - emitSignatureParameters(ctor); - } - else { - write("constructor"); - if (ctor) { - emitSignatureParameters(ctor); - } - else { - // Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation. - // If constructor is empty, then, - // If ClassHeritageopt is present, then - // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. - // Else, - // Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition - if (baseTypeElement) { - write("(...args)"); - } - else { - write("()"); - } - } - } - var startIndex = 0; - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - // Emit all the directive prologues (like "use strict"). These have to come before - // any other preamble code we write (like parameter initializers). - startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); - emitDetachedComments(ctor.body.statements); - } - emitCaptureThisForNodeIfNecessary(node); - var superCall; - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeElement) { - superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeElement) { - writeLine(); - emitStart(baseTypeElement); - if (languageVersion < 2 /* ES6 */) { - write("_super.apply(this, arguments);"); - } - else { - write("super(...args);"); - } - emitEnd(baseTypeElement); - } - } - emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ false)); - if (ctor) { - var statements = ctor.body.statements; - if (superCall) { - statements = statements.slice(1); - } - emitLinesStartingAt(statements, startIndex); - } - emitTempDeclarations(/*newLine*/ true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition(ctor.body.statements.end); - } - decreaseIndent(); - emitToken(16 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - } - function emitClassExpression(node) { - return emitClassLikeDeclaration(node); - } - function emitClassDeclaration(node) { - return emitClassLikeDeclaration(node); - } - function emitClassLikeDeclaration(node) { - if (languageVersion < 2 /* ES6 */) { - emitClassLikeDeclarationBelowES6(node); - } - else { - emitClassLikeDeclarationForES6AndHigher(node); - } - } - function emitClassLikeDeclarationForES6AndHigher(node) { - var thisNodeIsDecorated = ts.nodeIsDecorated(node); - if (node.kind === 212 /* ClassDeclaration */) { - if (thisNodeIsDecorated) { - // To preserve the correct runtime semantics when decorators are applied to the class, - // the emit needs to follow one of the following rules: - // - // * For a local class declaration: - // - // @dec class C { - // } - // - // The emit should be: - // - // let C = class { - // }; - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // C = __decorate([dec], C); - // - // * For an exported class declaration: - // - // @dec export class C { - // } - // - // The emit should be: - // - // export let C = class { - // }; - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // C = __decorate([dec], C); - // - // * For a default export of a class declaration with a name: - // - // @dec default export class C { - // } - // - // The emit should be: - // - // let C = class { - // } - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // C = __decorate([dec], C); - // export default C; - // - // * For a default export of a class declaration without a name: - // - // @dec default export class { - // } - // - // The emit should be: - // - // let _default = class { - // } - // _default = __decorate([dec], _default); - // export default _default; - // - if (isES6ExportedDeclaration(node) && !(node.flags & 1024 /* Default */)) { - write("export "); - } - write("let "); - emitDeclarationName(node); - write(" = "); - } - else if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024 /* Default */) { - write("default "); - } - } - } - // If the class has static properties, and it's a class expression, then we'll need - // to specialize the emit a bit. for a class expression of the form: - // - // class C { static a = 1; static b = 2; ... } - // - // We'll emit: - // - // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) - // - // This keeps the expression as an expression, while ensuring that the static parts - // of it have been initialized by the time it is used. - var staticProperties = getInitializedProperties(node, /*static:*/ true); - var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 184 /* ClassExpression */; - var tempVariable; - if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0 /* Auto */); - write("("); - increaseIndent(); - emit(tempVariable); - write(" = "); - } - write("class"); - // check if this is an "export default class" as it may not have a name. Do not emit the name if the class is decorated. - if ((node.name || !(node.flags & 1024 /* Default */)) && !thisNodeIsDecorated) { - write(" "); - emitDeclarationName(node); - } - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write(" extends "); - emit(baseTypeNode.expression); - } - write(" {"); - increaseIndent(); - scopeEmitStart(node); - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES6AndHigher(node); - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. - // For a decorated class, we need to assign its name (if it has one). This is because we emit - // the class as a class expression to avoid the double-binding of the identifier: - // - // let C = class { - // } - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // - if (thisNodeIsDecorated) { - write(";"); - } - // Emit static property assignment. Because classDeclaration is lexically evaluated, - // it is safe to emit static property assignment after classDeclaration - // From ES6 specification: - // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using - // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. - if (isClassExpressionWithStaticProperties) { - for (var _a = 0; _a < staticProperties.length; _a++) { - var property = staticProperties[_a]; - write(","); - writeLine(); - emitPropertyDeclaration(node, property, /*receiver:*/ tempVariable, /*isExpression:*/ true); - } - write(","); - writeLine(); - emit(tempVariable); - decreaseIndent(); - write(")"); - } - else { - writeLine(); - emitPropertyDeclarations(node, staticProperties); - emitDecoratorsOfClass(node); - } - // If this is an exported class, but not on the top level (i.e. on an internal - // module), export it - if (!isES6ExportedDeclaration(node) && (node.flags & 1 /* Export */)) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emitDeclarationName(node); - emitEnd(node); - write(";"); - } - else if (isES6ExportedDeclaration(node) && (node.flags & 1024 /* Default */) && thisNodeIsDecorated) { - // if this is a top level default export of decorated class, write the export after the declaration. - writeLine(); - write("export default "); - emitDeclarationName(node); - write(";"); - } - } - function emitClassLikeDeclarationBelowES6(node) { - if (node.kind === 212 /* ClassDeclaration */) { - // source file level classes in system modules are hoisted so 'var's for them are already defined - if (!shouldHoistDeclarationInSystemJsModule(node)) { - write("var "); - } - emitDeclarationName(node); - write(" = "); - } - write("(function ("); - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write("_super"); - } - write(") {"); - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - computedPropertyNamesToGeneratedNames = undefined; - increaseIndent(); - scopeEmitStart(node); - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("__extends("); - emitDeclarationName(node); - write(", _super);"); - emitEnd(baseTypeNode); - } - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES5AndLower(node); - emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ true)); - writeLine(); - emitDecoratorsOfClass(node); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end, function () { - write("return "); - emitDeclarationName(node); - }); - write(";"); - emitTempDeclarations(/*newLine*/ true); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - emitStart(node); - write(")("); - if (baseTypeNode) { - emit(baseTypeNode.expression); - } - write(")"); - if (node.kind === 212 /* ClassDeclaration */) { - write(";"); - } - emitEnd(node); - if (node.kind === 212 /* ClassDeclaration */) { - emitExportMemberAssignment(node); - } - if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - } - function emitClassMemberPrefix(node, member) { - emitDeclarationName(node); - if (!(member.flags & 128 /* Static */)) { - write(".prototype"); - } - } - function emitDecoratorsOfClass(node) { - emitDecoratorsOfMembers(node, /*staticFlag*/ 0); - emitDecoratorsOfMembers(node, 128 /* Static */); - emitDecoratorsOfConstructor(node); - } - function emitDecoratorsOfConstructor(node) { - var decorators = node.decorators; - var constructor = ts.getFirstConstructorWithBody(node); - var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); - // skip decoration of the constructor if neither it nor its parameters are decorated - if (!decorators && !hasDecoratedParameters) { - return; - } - // Emit the call to __decorate. Given the class: - // - // @dec - // class C { - // } - // - // The emit for the class is: - // - // C = __decorate([dec], C); - // - writeLine(); - emitStart(node); - emitDeclarationName(node); - write(" = __decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(constructor, /*leadingComma*/ argumentsWritten > 0); - emitSerializedTypeMetadata(node, /*leadingComma*/ argumentsWritten >= 0); - decreaseIndent(); - writeLine(); - write("], "); - emitDeclarationName(node); - write(");"); - emitEnd(node); - writeLine(); - } - function emitDecoratorsOfMembers(node, staticFlag) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - // only emit members in the correct group - if ((member.flags & 128 /* Static */) !== staticFlag) { - continue; - } - // skip members that cannot be decorated (such as the constructor) - if (!ts.nodeCanBeDecorated(member)) { - continue; - } - // skip a member if it or any of its parameters are not decorated - if (!ts.nodeOrChildIsDecorated(member)) { - continue; - } - // skip an accessor declaration if it is not the first accessor - var decorators = void 0; - var functionLikeMember = void 0; - if (ts.isAccessor(member)) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member !== accessors.firstAccessor) { - continue; - } - // get the decorators from the first accessor with decorators - decorators = accessors.firstAccessor.decorators; - if (!decorators && accessors.secondAccessor) { - decorators = accessors.secondAccessor.decorators; - } - // we only decorate parameters of the set accessor - functionLikeMember = accessors.setAccessor; - } - else { - decorators = member.decorators; - // we only decorate the parameters here if this is a method - if (member.kind === 141 /* MethodDeclaration */) { - functionLikeMember = member; - } - } - // Emit the call to __decorate. Given the following: - // - // class C { - // @dec method(@dec2 x) {} - // @dec get accessor() {} - // @dec prop; - // } - // - // The emit for a method is: - // - // Object.defineProperty(C.prototype, "method", - // __decorate([ - // dec, - // __param(0, dec2), - // __metadata("design:type", Function), - // __metadata("design:paramtypes", [Object]), - // __metadata("design:returntype", void 0) - // ], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); - // - // The emit for an accessor is: - // - // Object.defineProperty(C.prototype, "accessor", - // __decorate([ - // dec - // ], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); - // - // The emit for a property is: - // - // __decorate([ - // dec - // ], C.prototype, "prop"); - // - writeLine(); - emitStart(member); - if (member.kind !== 139 /* PropertyDeclaration */) { - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(","); - increaseIndent(); - writeLine(); - } - write("__decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); - emitSerializedTypeMetadata(member, argumentsWritten > 0); - decreaseIndent(); - writeLine(); - write("], "); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - if (member.kind !== 139 /* PropertyDeclaration */) { - write(", Object.getOwnPropertyDescriptor("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write("))"); - decreaseIndent(); - } - write(");"); - emitEnd(member); - writeLine(); - } - } - function emitDecoratorsOfParameters(node, leadingComma) { - var argumentsWritten = 0; - if (node) { - var parameterIndex = 0; - for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { - var parameter = _b[_a]; - if (ts.nodeIsDecorated(parameter)) { - var decorators = parameter.decorators; - argumentsWritten += emitList(decorators, 0, decorators.length, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ leadingComma, /*noTrailingNewLine*/ true, function (decorator) { - emitStart(decorator); - write("__param(" + parameterIndex + ", "); - emit(decorator.expression); - write(")"); - emitEnd(decorator); - }); - leadingComma = true; - } - ++parameterIndex; - } - } - return argumentsWritten; - } - function shouldEmitTypeMetadata(node) { - // This method determines whether to emit the "design:type" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata - // compiler option is set. - switch (node.kind) { - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 139 /* PropertyDeclaration */: - return true; - } - return false; - } - function shouldEmitReturnTypeMetadata(node) { - // This method determines whether to emit the "design:returntype" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata - // compiler option is set. - switch (node.kind) { - case 141 /* MethodDeclaration */: - return true; - } - return false; - } - function shouldEmitParamTypesMetadata(node) { - // This method determines whether to emit the "design:paramtypes" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata - // compiler option is set. - switch (node.kind) { - case 212 /* ClassDeclaration */: - case 141 /* MethodDeclaration */: - case 144 /* SetAccessor */: - return true; - } - return false; - } - /** Serializes the type of a declaration to an appropriate JS constructor value. Used by the __metadata decorator for a class member. */ - function emitSerializedTypeOfNode(node) { - // serialization of the type of a declaration uses the following rules: - // - // * The serialized type of a ClassDeclaration is "Function" - // * The serialized type of a ParameterDeclaration is the serialized type of its type annotation. - // * The serialized type of a PropertyDeclaration is the serialized type of its type annotation. - // * The serialized type of an AccessorDeclaration is the serialized type of the return type annotation of its getter or parameter type annotation of its setter. - // * The serialized type of any other FunctionLikeDeclaration is "Function". - // * The serialized type of any other node is "void 0". - // - // For rules on serializing type annotations, see `serializeTypeNode`. - switch (node.kind) { - case 212 /* ClassDeclaration */: - write("Function"); - return; - case 139 /* PropertyDeclaration */: - emitSerializedTypeNode(node.type); - return; - case 136 /* Parameter */: - emitSerializedTypeNode(node.type); - return; - case 143 /* GetAccessor */: - emitSerializedTypeNode(node.type); - return; - case 144 /* SetAccessor */: - emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); - return; - } - if (ts.isFunctionLike(node)) { - write("Function"); - return; - } - write("void 0"); - } - function emitSerializedTypeNode(node) { - if (node) { - switch (node.kind) { - case 101 /* VoidKeyword */: - write("void 0"); - return; - case 158 /* ParenthesizedType */: - emitSerializedTypeNode(node.type); - return; - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - write("Function"); - return; - case 154 /* ArrayType */: - case 155 /* TupleType */: - write("Array"); - return; - case 148 /* TypePredicate */: - case 118 /* BooleanKeyword */: - write("Boolean"); - return; - case 128 /* StringKeyword */: - case 9 /* StringLiteral */: - write("String"); - return; - case 126 /* NumberKeyword */: - write("Number"); - return; - case 129 /* SymbolKeyword */: - write("Symbol"); - return; - case 149 /* TypeReference */: - emitSerializedTypeReferenceNode(node); - return; - case 152 /* TypeQuery */: - case 153 /* TypeLiteral */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: - case 115 /* AnyKeyword */: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; - } - } - write("Object"); - } - /** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */ - function emitSerializedTypeReferenceNode(node) { - var location = node.parent; - while (ts.isDeclaration(location) || ts.isTypeNode(location)) { - location = location.parent; - } - // Clone the type name and parent it to a location outside of the current declaration. - var typeName = ts.cloneEntityName(node.typeName); - typeName.parent = location; - var result = resolver.getTypeReferenceSerializationKind(typeName); - switch (result) { - case ts.TypeReferenceSerializationKind.Unknown: - var temp = createAndRecordTempVariable(0 /* Auto */); - write("(typeof ("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(typeName, /*useFallback*/ true); - write(") === 'function' && "); - emitNodeWithoutSourceMap(temp); - write(") || Object"); - break; - case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - emitEntityNameAsExpression(typeName, /*useFallback*/ false); - break; - case ts.TypeReferenceSerializationKind.VoidType: - write("void 0"); - break; - case ts.TypeReferenceSerializationKind.BooleanType: - write("Boolean"); - break; - case ts.TypeReferenceSerializationKind.NumberLikeType: - write("Number"); - break; - case ts.TypeReferenceSerializationKind.StringLikeType: - write("String"); - break; - case ts.TypeReferenceSerializationKind.ArrayLikeType: - write("Array"); - break; - case ts.TypeReferenceSerializationKind.ESSymbolType: - if (languageVersion < 2 /* ES6 */) { - write("typeof Symbol === 'function' ? Symbol : Object"); - } - else { - write("Symbol"); - } - break; - case ts.TypeReferenceSerializationKind.TypeWithCallSignature: - write("Function"); - break; - case ts.TypeReferenceSerializationKind.ObjectType: - write("Object"); - break; - } - } - /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ - function emitSerializedParameterTypesOfNode(node) { - // serialization of parameter types uses the following rules: - // - // * If the declaration is a class, the parameters of the first constructor with a body are used. - // * If the declaration is function-like and has a body, the parameters of the function are used. - // - // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. - if (node) { - var valueDeclaration; - if (node.kind === 212 /* ClassDeclaration */) { - valueDeclaration = ts.getFirstConstructorWithBody(node); - } - else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { - valueDeclaration = node; - } - if (valueDeclaration) { - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; - if (parameterCount > 0) { - for (var i = 0; i < parameterCount; i++) { - if (i > 0) { - write(", "); - } - if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; - if (parameterType.kind === 154 /* ArrayType */) { - parameterType = parameterType.elementType; - } - else if (parameterType.kind === 149 /* TypeReference */ && parameterType.typeArguments && parameterType.typeArguments.length === 1) { - parameterType = parameterType.typeArguments[0]; - } - else { - parameterType = undefined; - } - emitSerializedTypeNode(parameterType); - } - else { - emitSerializedTypeOfNode(parameters[i]); - } - } - } - } - } - } - /** Serializes the return type of function. Used by the __metadata decorator for a method. */ - function emitSerializedReturnTypeOfNode(node) { - if (node && ts.isFunctionLike(node) && node.type) { - emitSerializedTypeNode(node.type); - return; - } - write("void 0"); - } - function emitSerializedTypeMetadata(node, writeComma) { - // This method emits the serialized type metadata for a decorator target. - // The caller should have already tested whether the node has decorators. - var argumentsWritten = 0; - if (compilerOptions.emitDecoratorMetadata) { - if (shouldEmitTypeMetadata(node)) { - if (writeComma) { - write(", "); - } - writeLine(); - write("__metadata('design:type', "); - emitSerializedTypeOfNode(node); - write(")"); - argumentsWritten++; - } - if (shouldEmitParamTypesMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:paramtypes', ["); - emitSerializedParameterTypesOfNode(node); - write("])"); - argumentsWritten++; - } - if (shouldEmitReturnTypeMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:returntype', "); - emitSerializedReturnTypeOfNode(node); - write(")"); - argumentsWritten++; - } - } - return argumentsWritten; - } - function emitInterfaceDeclaration(node) { - emitCommentsOnNotEmittedNode(node); - } - function shouldEmitEnumDeclaration(node) { - var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; - } - function emitEnumDeclaration(node) { - // const enums are completely erased during compilation. - if (!shouldEmitEnumDeclaration(node)) { - return; - } - if (!shouldHoistDeclarationInSystemJsModule(node)) { - // do not emit var if variable was already hoisted - if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - emitEnd(node); - write(";"); - } - } - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") {"); - increaseIndent(); - scopeEmitStart(node); - emitLines(node.members); - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - write(")("); - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */ && !shouldHoistDeclarationInSystemJsModule(node)) { - // do not emit var if variable was already hoisted - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } - if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 /* System */ && (node.flags & 1 /* Export */)) { - // write the call to exporter for enum - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - function emitEnumMember(node) { - var enumParent = node.parent; - emitStart(node); - write(getGeneratedNameForNode(enumParent)); - write("["); - write(getGeneratedNameForNode(enumParent)); - write("["); - emitExpressionForPropertyName(node.name); - write("] = "); - writeEnumMemberDeclarationValue(node); - write("] = "); - emitExpressionForPropertyName(node.name); - emitEnd(node); - write(";"); - } - function writeEnumMemberDeclarationValue(member) { - var value = resolver.getConstantValue(member); - if (value !== undefined) { - write(value.toString()); - return; - } - else if (member.initializer) { - emit(member.initializer); - } - else { - write("undefined"); - } - } - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 216 /* ModuleDeclaration */) { - var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); - } - function isModuleMergedWithES6Class(node) { - return languageVersion === 2 /* ES6 */ && !!(resolver.getNodeCheckFlags(node) & 32768 /* LexicalModuleMergesWithClass */); - } - function emitModuleDeclaration(node) { - // Emit only if this module is non-ambient. - var shouldEmit = shouldEmitModuleDeclaration(node); - if (!shouldEmit) { - return emitCommentsOnNotEmittedNode(node); - } - var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); - var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); - if (emitVarForModule) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - } - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") "); - if (node.body.kind === 217 /* ModuleBlock */) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - tempFlags = 0; - tempVariables = undefined; - emit(node.body); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - } - else { - write("{"); - increaseIndent(); - scopeEmitStart(node); - emitCaptureThisForNodeIfNecessary(node); - writeLine(); - emit(node.body); - decreaseIndent(); - writeLine(); - var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; - emitToken(16 /* CloseBraceToken */, moduleBlock.statements.end); - scopeEmitEnd(); - } - write(")("); - // write moduleDecl = containingModule.m only if it is not exported es6 module member - if ((node.flags & 1 /* Export */) && !isES6ExportedDeclaration(node)) { - emit(node.name); - write(" = "); - } - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.name.kind === 67 /* Identifier */ && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 /* System */ && (node.flags & 1 /* Export */)) { - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - /* - * Some bundlers (SystemJS builder) sometimes want to rename dependencies. - * Here we check if alternative name was provided for a given moduleName and return it if possible. - */ - function tryRenameExternalModule(moduleName) { - if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { - return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; - } - return undefined; - } - function emitRequire(moduleName) { - if (moduleName.kind === 9 /* StringLiteral */) { - write("require("); - var text = tryRenameExternalModule(moduleName); - if (text) { - write(text); - } - else { - emitStart(moduleName); - emitLiteral(moduleName); - emitEnd(moduleName); - } - emitToken(18 /* CloseParenToken */, moduleName.end); - } - else { - write("require()"); - } - } - function getNamespaceDeclarationNode(node) { - if (node.kind === 219 /* ImportEqualsDeclaration */) { - return node; - } - var importClause = node.importClause; - if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 222 /* NamespaceImport */) { - return importClause.namedBindings; - } - } - function isDefaultImport(node) { - return node.kind === 220 /* ImportDeclaration */ && node.importClause && !!node.importClause.name; - } - function emitExportImportAssignments(node) { - if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - emitExportMemberAssignments(node.name); - } - ts.forEachChild(node, emitExportImportAssignments); - } - function emitImportDeclaration(node) { - if (languageVersion < 2 /* ES6 */) { - return emitExternalImportDeclaration(node); - } - // ES6 import - if (node.importClause) { - var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); - var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, /* checkChildren */ true); - if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { - write("import "); - emitStart(node.importClause); - if (shouldEmitDefaultBindings) { - emit(node.importClause.name); - if (shouldEmitNamedBindings) { - write(", "); - } - } - if (shouldEmitNamedBindings) { - emitLeadingComments(node.importClause.namedBindings); - emitStart(node.importClause.namedBindings); - if (node.importClause.namedBindings.kind === 222 /* NamespaceImport */) { - write("* as "); - emit(node.importClause.namedBindings.name); - } - else { - write("{ "); - emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); - write(" }"); - } - emitEnd(node.importClause.namedBindings); - emitTrailingComments(node.importClause.namedBindings); - } - emitEnd(node.importClause); - write(" from "); - emit(node.moduleSpecifier); - write(";"); - } - } - else { - write("import "); - emit(node.moduleSpecifier); - write(";"); - } - } - function emitExternalImportDeclaration(node) { - if (ts.contains(externalImports, node)) { - var isExportedImport = node.kind === 219 /* ImportEqualsDeclaration */ && (node.flags & 1 /* Export */) !== 0; - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (compilerOptions.module !== 2 /* AMD */) { - emitLeadingComments(node); - emitStart(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - // import x = require("foo") - // import * as x from "foo" - if (!isExportedImport) - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - } - else { - // import "foo" - // import x from "foo" - // import { x, y } from "foo" - // import d, * as x from "foo" - // import d, { x, y } from "foo" - var isNakedImport = 220 /* ImportDeclaration */ && !node.importClause; - if (!isNakedImport) { - write("var "); - write(getGeneratedNameForNode(node)); - write(" = "); - } - } - emitRequire(ts.getExternalModuleName(node)); - if (namespaceDeclaration && isDefaultImport(node)) { - // import d, * as x from "foo" - write(", "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - else { - if (isExportedImport) { - emitModuleMemberName(namespaceDeclaration); - write(" = "); - emit(namespaceDeclaration.name); - write(";"); - } - else if (namespaceDeclaration && isDefaultImport(node)) { - // import d, * as x from "foo" - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - write(";"); - } - emitExportImportAssignments(node); - } - } - } - function emitImportEqualsDeclaration(node) { - if (ts.isExternalModuleImportEqualsDeclaration(node)) { - emitExternalImportDeclaration(node); - return; - } - // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when - // - current file is not external module - // - import declaration is top level and target is value imported by entity name - if (resolver.isReferencedAliasDeclaration(node) || - (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { - emitLeadingComments(node); - emitStart(node); - // variable declaration for import-equals declaration can be hoisted in system modules - // in this case 'var' should be omitted and emit should contain only initialization - var variableDeclarationIsHoisted = shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ true); - // is it top level export import v = a.b.c in system module? - // if yes - it needs to be rewritten as exporter('v', v = a.b.c) - var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ true); - if (!variableDeclarationIsHoisted) { - ts.Debug.assert(!isExported); - if (isES6ExportedDeclaration(node)) { - write("export "); - write("var "); - } - else if (!(node.flags & 1 /* Export */)) { - write("var "); - } - } - if (isExported) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.name); - write("\", "); - } - emitModuleMemberName(node); - write(" = "); - emit(node.moduleReference); - if (isExported) { - write(")"); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - } - function emitExportDeclaration(node) { - ts.Debug.assert(compilerOptions.module !== 4 /* System */); - if (languageVersion < 2 /* ES6 */) { - if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { - emitStart(node); - var generatedName = getGeneratedNameForNode(node); - if (node.exportClause) { - // export { x, y, ... } from "foo" - if (compilerOptions.module !== 2 /* AMD */) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(ts.getExternalModuleName(node)); - write(";"); - } - for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { - var specifier = _b[_a]; - if (resolver.isValueAliasDeclaration(specifier)) { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - } - } - } - else { - // export * from "foo" - writeLine(); - write("__export("); - if (compilerOptions.module !== 2 /* AMD */) { - emitRequire(ts.getExternalModuleName(node)); - } - else { - write(generatedName); - } - write(");"); - } - emitEnd(node); - } - } - else { - if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { - write("export "); - if (node.exportClause) { - // export { x, y, ... } - write("{ "); - emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); - write(" }"); - } - else { - write("*"); - } - if (node.moduleSpecifier) { - write(" from "); - emit(node.moduleSpecifier); - } - write(";"); - } - } - } - function emitExportOrImportSpecifierList(specifiers, shouldEmit) { - ts.Debug.assert(languageVersion >= 2 /* ES6 */); - var needsComma = false; - for (var _a = 0; _a < specifiers.length; _a++) { - var specifier = specifiers[_a]; - if (shouldEmit(specifier)) { - if (needsComma) { - write(", "); - } - if (specifier.propertyName) { - emit(specifier.propertyName); - write(" as "); - } - emit(specifier.name); - needsComma = true; - } - } - } - function emitExportAssignment(node) { - if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - if (languageVersion >= 2 /* ES6 */) { - writeLine(); - emitStart(node); - write("export default "); - var expression = node.expression; - emit(expression); - if (expression.kind !== 211 /* FunctionDeclaration */ && - expression.kind !== 212 /* ClassDeclaration */) { - write(";"); - } - emitEnd(node); - } - else { - writeLine(); - emitStart(node); - if (compilerOptions.module === 4 /* System */) { - write(exportFunctionForFile + "(\"default\","); - emit(node.expression); - write(")"); - } - else { - emitEs6ExportDefaultCompat(node); - emitContainingModuleName(node); - if (languageVersion === 0 /* ES3 */) { - write("[\"default\"] = "); - } - else { - write(".default = "); - } - emit(node.expression); - } - write(";"); - emitEnd(node); - } - } - } - function collectExternalModuleInfo(sourceFile) { - externalImports = []; - exportSpecifiers = {}; - exportEquals = undefined; - hasExportStars = false; - for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { - var node = _b[_a]; - switch (node.kind) { - case 220 /* ImportDeclaration */: - if (!node.importClause || - resolver.isReferencedAliasDeclaration(node.importClause, /*checkChildren*/ true)) { - // import "mod" - // import x from "mod" where x is referenced - // import * as x from "mod" where x is referenced - // import { x, y } from "mod" where at least one import is referenced - externalImports.push(node); - } - break; - case 219 /* ImportEqualsDeclaration */: - if (node.moduleReference.kind === 230 /* ExternalModuleReference */ && resolver.isReferencedAliasDeclaration(node)) { - // import x = require("mod") where x is referenced - externalImports.push(node); - } - break; - case 226 /* ExportDeclaration */: - if (node.moduleSpecifier) { - if (!node.exportClause) { - // export * from "mod" - externalImports.push(node); - hasExportStars = true; - } - else if (resolver.isValueAliasDeclaration(node)) { - // export { x, y } from "mod" where at least one export is a value symbol - externalImports.push(node); - } - } - else { - // export { x, y } - for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { - var specifier = _d[_c]; - var name_24 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); - } - } - break; - case 225 /* ExportAssignment */: - if (node.isExportEquals && !exportEquals) { - // export = x - exportEquals = node; - } - break; - } - } - } - function emitExportStarHelper() { - if (hasExportStars) { - writeLine(); - write("function __export(m) {"); - increaseIndent(); - writeLine(); - write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function getLocalNameForExternalImport(node) { - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); - } - if (node.kind === 220 /* ImportDeclaration */ && node.importClause) { - return getGeneratedNameForNode(node); - } - if (node.kind === 226 /* ExportDeclaration */ && node.moduleSpecifier) { - return getGeneratedNameForNode(node); - } - } - function getExternalModuleNameText(importNode) { - var moduleName = ts.getExternalModuleName(importNode); - if (moduleName.kind === 9 /* StringLiteral */) { - return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); - } - return undefined; - } - function emitVariableDeclarationsForImports() { - if (externalImports.length === 0) { - return; - } - writeLine(); - var started = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var importNode = externalImports[_a]; - // do not create variable declaration for exports and imports that lack import clause - var skipNode = importNode.kind === 226 /* ExportDeclaration */ || - (importNode.kind === 220 /* ImportDeclaration */ && !importNode.importClause); - if (skipNode) { - continue; - } - if (!started) { - write("var "); - started = true; - } - else { - write(", "); - } - write(getLocalNameForExternalImport(importNode)); - } - if (started) { - write(";"); - } - } - function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { - // when resolving exports local exported entries/indirect exported entries in the module - // should always win over entries with similar names that were added via star exports - // to support this we store names of local/indirect exported entries in a set. - // this set is used to filter names brought by star expors. - if (!hasExportStars) { - // local names set is needed only in presence of star exports - return undefined; - } - // local names set should only be added if we have anything exported - if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { - // no exported declarations (export var ...) or export specifiers (export {x}) - // check if we have any non star export declarations. - var hasExportDeclarationWithExportClause = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var externalImport = externalImports[_a]; - if (externalImport.kind === 226 /* ExportDeclaration */ && externalImport.exportClause) { - hasExportDeclarationWithExportClause = true; - break; - } - } - if (!hasExportDeclarationWithExportClause) { - // we still need to emit exportStar helper - return emitExportStarFunction(/*localNames*/ undefined); - } - } - var exportedNamesStorageRef = makeUniqueName("exportedNames"); - writeLine(); - write("var " + exportedNamesStorageRef + " = {"); - increaseIndent(); - var started = false; - if (exportedDeclarations) { - for (var i = 0; i < exportedDeclarations.length; ++i) { - // write name of exported declaration, i.e 'export var x...' - writeExportedName(exportedDeclarations[i]); - } - } - if (exportSpecifiers) { - for (var n in exportSpecifiers) { - for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { - var specifier = _c[_b]; - // write name of export specified, i.e. 'export {x}' - writeExportedName(specifier.name); - } - } - } - for (var _d = 0; _d < externalImports.length; _d++) { - var externalImport = externalImports[_d]; - if (externalImport.kind !== 226 /* ExportDeclaration */) { - continue; - } - var exportDecl = externalImport; - if (!exportDecl.exportClause) { - // export * from ... - continue; - } - for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { - var element = _f[_e]; - // write name of indirectly exported entry, i.e. 'export {x} from ...' - writeExportedName(element.name || element.propertyName); - } - } - decreaseIndent(); - writeLine(); - write("};"); - return emitExportStarFunction(exportedNamesStorageRef); - function emitExportStarFunction(localNames) { - var exportStarFunction = makeUniqueName("exportStar"); - writeLine(); - // define an export star helper function - write("function " + exportStarFunction + "(m) {"); - increaseIndent(); - writeLine(); - write("var exports = {};"); - writeLine(); - write("for(var n in m) {"); - increaseIndent(); - writeLine(); - write("if (n !== \"default\""); - if (localNames) { - write("&& !" + localNames + ".hasOwnProperty(n)"); - } - write(") exports[n] = m[n];"); - decreaseIndent(); - writeLine(); - write("}"); - writeLine(); - write(exportFunctionForFile + "(exports);"); - decreaseIndent(); - writeLine(); - write("}"); - return exportStarFunction; - } - function writeExportedName(node) { - // do not record default exports - // they are local to module and never overwritten (explicitly skipped) by star export - if (node.kind !== 67 /* Identifier */ && node.flags & 1024 /* Default */) { - return; - } - if (started) { - write(","); - } - else { - started = true; - } - writeLine(); - write("'"); - if (node.kind === 67 /* Identifier */) { - emitNodeWithCommentsAndWithoutSourcemap(node); - } - else { - emitDeclarationName(node); - } - write("': true"); - } - } - function processTopLevelVariableAndFunctionDeclarations(node) { - // per ES6 spec: - // 15.2.1.16.4 ModuleDeclarationInstantiation() Concrete Method - // - var declarations are initialized to undefined - 14.a.ii - // - function/generator declarations are instantiated - 16.a.iv - // this means that after module is instantiated but before its evaluation - // exported functions are already accessible at import sites - // in theory we should hoist only exported functions and its dependencies - // in practice to simplify things we'll hoist all source level functions and variable declaration - // including variables declarations for module and class declarations - var hoistedVars; - var hoistedFunctionDeclarations; - var exportedDeclarations; - visit(node); - if (hoistedVars) { - writeLine(); - write("var "); - var seen = {}; - for (var i = 0; i < hoistedVars.length; ++i) { - var local = hoistedVars[i]; - var name_25 = local.kind === 67 /* Identifier */ - ? local - : local.name; - if (name_25) { - // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_25.text); - if (ts.hasProperty(seen, text)) { - continue; - } - else { - seen[text] = text; - } - } - if (i !== 0) { - write(", "); - } - if (local.kind === 212 /* ClassDeclaration */ || local.kind === 216 /* ModuleDeclaration */ || local.kind === 215 /* EnumDeclaration */) { - emitDeclarationName(local); - } - else { - emit(local); - } - var flags = ts.getCombinedNodeFlags(local.kind === 67 /* Identifier */ ? local.parent : local); - if (flags & 1 /* Export */) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(local); - } - } - write(";"); - } - if (hoistedFunctionDeclarations) { - for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { - var f = hoistedFunctionDeclarations[_a]; - writeLine(); - emit(f); - if (f.flags & 1 /* Export */) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(f); - } - } - } - return exportedDeclarations; - function visit(node) { - if (node.flags & 2 /* Ambient */) { - return; - } - if (node.kind === 211 /* FunctionDeclaration */) { - if (!hoistedFunctionDeclarations) { - hoistedFunctionDeclarations = []; - } - hoistedFunctionDeclarations.push(node); - return; - } - if (node.kind === 212 /* ClassDeclaration */) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - return; - } - if (node.kind === 215 /* EnumDeclaration */) { - if (shouldEmitEnumDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 216 /* ModuleDeclaration */) { - if (shouldEmitModuleDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 209 /* VariableDeclaration */ || node.kind === 161 /* BindingElement */) { - if (shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ false)) { - var name_26 = node.name; - if (name_26.kind === 67 /* Identifier */) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(name_26); - } - else { - ts.forEachChild(name_26, visit); - } - } - return; - } - if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node.name); - return; - } - if (ts.isBindingPattern(node)) { - ts.forEach(node.elements, visit); - return; - } - if (!ts.isDeclaration(node)) { - ts.forEachChild(node, visit); - } - } - } - function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { - if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { - return false; - } - // hoist variable if - // - it is not block scoped - // - it is top level block scoped - // if block scoped variables are nested in some another block then - // no other functions can use them except ones that are defined at least in the same block - return (ts.getCombinedNodeFlags(node) & 49152 /* BlockScoped */) === 0 || - ts.getEnclosingBlockScopeContainer(node).kind === 246 /* SourceFile */; - } - function isCurrentFileSystemExternalModule() { - return compilerOptions.module === 4 /* System */ && ts.isExternalModule(currentSourceFile); - } - function emitSystemModuleBody(node, dependencyGroups, startIndex) { - // shape of the body in system modules: - // function (exports) { - // - // - // - // return { - // setters: [ - // - // ], - // execute: function() { - // - // } - // } - // - // } - // I.e: - // import {x} from 'file1' - // var y = 1; - // export function foo() { return y + x(); } - // console.log(y); - // will be transformed to - // function(exports) { - // var file1; // local alias - // var y; - // function foo() { return y + file1.x(); } - // exports("foo", foo); - // return { - // setters: [ - // function(v) { file1 = v } - // ], - // execute(): function() { - // y = 1; - // console.log(y); - // } - // }; - // } - emitVariableDeclarationsForImports(); - writeLine(); - var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); - var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); - writeLine(); - write("return {"); - increaseIndent(); - writeLine(); - emitSetters(exportStarFunction, dependencyGroups); - writeLine(); - emitExecute(node, startIndex); - decreaseIndent(); - writeLine(); - write("}"); // return - emitTempDeclarations(/*newLine*/ true); - } - function emitSetters(exportStarFunction, dependencyGroups) { - write("setters:["); - for (var i = 0; i < dependencyGroups.length; ++i) { - if (i !== 0) { - write(","); - } - writeLine(); - increaseIndent(); - var group = dependencyGroups[i]; - // derive a unique name for parameter from the first named entry in the group - var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); - write("function (" + parameterName + ") {"); - increaseIndent(); - for (var _a = 0; _a < group.length; _a++) { - var entry = group[_a]; - var importVariableName = getLocalNameForExternalImport(entry) || ""; - switch (entry.kind) { - case 220 /* ImportDeclaration */: - if (!entry.importClause) { - // 'import "..."' case - // module is imported only for side-effects, no emit required - break; - } - // fall-through - case 219 /* ImportEqualsDeclaration */: - ts.Debug.assert(importVariableName !== ""); - writeLine(); - // save import into the local - write(importVariableName + " = " + parameterName + ";"); - writeLine(); - break; - case 226 /* ExportDeclaration */: - ts.Debug.assert(importVariableName !== ""); - if (entry.exportClause) { - // export {a, b as c} from 'foo' - // emit as: - // exports_({ - // "a": _["a"], - // "c": _["b"] - // }); - writeLine(); - write(exportFunctionForFile + "({"); - writeLine(); - increaseIndent(); - for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { - if (i_2 !== 0) { - write(","); - writeLine(); - } - var e = entry.exportClause.elements[i_2]; - write("\""); - emitNodeWithCommentsAndWithoutSourcemap(e.name); - write("\": " + parameterName + "[\""); - emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); - write("\"]"); - } - decreaseIndent(); - writeLine(); - write("});"); - } - else { - writeLine(); - // export * from 'foo' - // emit as: - // exportStar(_foo); - write(exportStarFunction + "(" + parameterName + ");"); - } - writeLine(); - break; - } - } - decreaseIndent(); - write("}"); - decreaseIndent(); - } - write("],"); - } - function emitExecute(node, startIndex) { - write("execute: function() {"); - increaseIndent(); - writeLine(); - for (var i = startIndex; i < node.statements.length; ++i) { - var statement = node.statements[i]; - switch (statement.kind) { - // - function declarations are not emitted because they were already hoisted - // - import declarations are not emitted since they are already handled in setters - // - export declarations with module specifiers are not emitted since they were already written in setters - // - export declarations without module specifiers are emitted preserving the order - case 211 /* FunctionDeclaration */: - case 220 /* ImportDeclaration */: - continue; - case 226 /* ExportDeclaration */: - if (!statement.moduleSpecifier) { - for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { - var element = _b[_a]; - // write call to exporter function for every export specifier in exports list - emitExportSpecifierInSystemModule(element); - } - } - continue; - case 219 /* ImportEqualsDeclaration */: - if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { - // - import equals declarations that import external modules are not emitted - continue; - } - // fall-though for import declarations that import internal modules - default: - writeLine(); - emit(statement); - } - } - decreaseIndent(); - writeLine(); - write("}"); // execute - } - function emitSystemModule(node, startIndex) { - collectExternalModuleInfo(node); - // System modules has the following shape - // System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */}) - // 'exports' here is a function 'exports(name: string, value: T): T' that is used to publish exported values. - // 'exports' returns its 'value' argument so in most cases expressions - // that mutate exported values can be rewritten as: - // expr -> exports('name', expr). - // The only exception in this rule is postfix unary operators, - // see comment to 'emitPostfixUnaryExpression' for more details - ts.Debug.assert(!exportFunctionForFile); - // make sure that name of 'exports' function does not conflict with existing identifiers - exportFunctionForFile = makeUniqueName("exports"); - writeLine(); - write("System.register("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - write("["); - var groupIndices = {}; - var dependencyGroups = []; - for (var i = 0; i < externalImports.length; ++i) { - var text = getExternalModuleNameText(externalImports[i]); - if (ts.hasProperty(groupIndices, text)) { - // deduplicate/group entries in dependency list by the dependency name - var groupIndex = groupIndices[text]; - dependencyGroups[groupIndex].push(externalImports[i]); - continue; - } - else { - groupIndices[text] = dependencyGroups.length; - dependencyGroups.push([externalImports[i]]); - } - if (i !== 0) { - write(", "); - } - write(text); - } - write("], function(" + exportFunctionForFile + ") {"); - writeLine(); - increaseIndent(); - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitSystemModuleBody(node, dependencyGroups, startIndex); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitAMDDependencies(node, includeNonAmdDependencies) { - // An AMD define function has the following shape: - // define(id?, dependencies?, factory); - // - // This has the shape of - // define(name, ["module1", "module2"], function (module1Alias) { - // The location of the alias in the parameter list in the factory function needs to - // match the position of the module name in the dependency list. - // - // To ensure this is true in cases of modules with no aliases, e.g.: - // `import "module"` or `` - // we need to add modules without alias names to the end of the dependencies list - // names of modules with corresponding parameter in the factory function - var aliasedModuleNames = []; - // names of modules with no corresponding parameters in factory function - var unaliasedModuleNames = []; - var importAliasNames = []; // names of the parameters in the factory function; these - // parameters need to match the indexes of the corresponding - // module names in aliasedModuleNames. - // Fill in amd-dependency tags - for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { - var amdDependency = _b[_a]; - if (amdDependency.name) { - aliasedModuleNames.push("\"" + amdDependency.path + "\""); - importAliasNames.push(amdDependency.name); - } - else { - unaliasedModuleNames.push("\"" + amdDependency.path + "\""); - } - } - for (var _c = 0; _c < externalImports.length; _c++) { - var importNode = externalImports[_c]; - // Find the name of the external module - var externalModuleName = getExternalModuleNameText(importNode); - // Find the name of the module alias, if there is one - var importAliasName = getLocalNameForExternalImport(importNode); - if (includeNonAmdDependencies && importAliasName) { - aliasedModuleNames.push(externalModuleName); - importAliasNames.push(importAliasName); - } - else { - unaliasedModuleNames.push(externalModuleName); - } - } - write("[\"require\", \"exports\""); - if (aliasedModuleNames.length) { - write(", "); - write(aliasedModuleNames.join(", ")); - } - if (unaliasedModuleNames.length) { - write(", "); - write(unaliasedModuleNames.join(", ")); - } - write("], function (require, exports"); - if (importAliasNames.length) { - write(", "); - write(importAliasNames.join(", ")); - } - } - function emitAMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - writeLine(); - write("define("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - emitExportEquals(/*emitAsReturn*/ true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitCommonJSModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - emitExportEquals(/*emitAsReturn*/ false); - } - function emitUMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - // Module is detected first to support Browserify users that load into a browser with an AMD loader - writeLines("(function (deps, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define(deps, factory);\n }\n})("); - emitAMDDependencies(node, false); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - emitExportEquals(/*emitAsReturn*/ true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitES6Module(node, startIndex) { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - // Emit exportDefault if it exists will happen as part - // or normal statement emit. - } - function emitExportEquals(emitAsReturn) { - if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { - writeLine(); - emitStart(exportEquals); - write(emitAsReturn ? "return " : "module.exports = "); - emit(exportEquals.expression); - write(";"); - emitEnd(exportEquals); - } - } - function emitJsxElement(node) { - switch (compilerOptions.jsx) { - case 2 /* React */: - jsxEmitReact(node); - break; - case 1 /* Preserve */: - // Fall back to preserve if None was specified (we'll error earlier) - default: - jsxEmitPreserve(node); - break; - } - } - function trimReactWhitespaceAndApplyEntities(node) { - var result = undefined; - var text = ts.getTextOfNode(node, /*includeTrivia*/ true); - var firstNonWhitespace = 0; - var lastNonWhitespace = -1; - // JSX trims whitespace at the end and beginning of lines, except that the - // start/end of a tag is considered a start/end of a line only if that line is - // on the same line as the closing tag. See examples in tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx - for (var i = 0; i < text.length; i++) { - var c = text.charCodeAt(i); - if (ts.isLineBreak(c)) { - if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { - var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - firstNonWhitespace = -1; - } - else if (!ts.isWhiteSpace(c)) { - lastNonWhitespace = i; - if (firstNonWhitespace === -1) { - firstNonWhitespace = i; - } - } - } - if (firstNonWhitespace !== -1) { - var part = text.substr(firstNonWhitespace); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - if (result) { - // Replace entities like   - result = result.replace(/&(\w+);/g, function (s, m) { - if (entities[m] !== undefined) { - return String.fromCharCode(entities[m]); - } - else { - return s; - } - }); - } - return result; - } - function getTextToEmit(node) { - switch (compilerOptions.jsx) { - case 2 /* React */: - var text = trimReactWhitespaceAndApplyEntities(node); - if (text === undefined || text.length === 0) { - return undefined; - } - else { - return text; - } - case 1 /* Preserve */: - default: - return ts.getTextOfNode(node, /*includeTrivia*/ true); - } - } - function emitJsxText(node) { - switch (compilerOptions.jsx) { - case 2 /* React */: - write("\""); - write(trimReactWhitespaceAndApplyEntities(node)); - write("\""); - break; - case 1 /* Preserve */: - default: - writer.writeLiteral(ts.getTextOfNode(node, /*includeTrivia*/ true)); - break; - } - } - function emitJsxExpression(node) { - if (node.expression) { - switch (compilerOptions.jsx) { - case 1 /* Preserve */: - default: - write("{"); - emit(node.expression); - write("}"); - break; - case 2 /* React */: - emit(node.expression); - break; - } - } - } - function emitDirectivePrologues(statements, startWithNewLine) { - for (var i = 0; i < statements.length; ++i) { - if (ts.isPrologueDirective(statements[i])) { - if (startWithNewLine || i > 0) { - writeLine(); - } - emit(statements[i]); - } - else { - // return index of the first non prologue directive - return i; - } - } - return statements.length; - } - function writeLines(text) { - var lines = text.split(/\r\n|\r|\n/g); - for (var i = 0; i < lines.length; ++i) { - var line = lines[i]; - if (line.length) { - writeLine(); - write(line); - } - } - } - function emitEmitHelpers(node) { - // 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 < 2 /* ES6 */) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */)) { - writeLines(extendsHelper); - extendsEmitted = true; - } - if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16 /* EmitDecorate */) { - writeLines(decorateHelper); - if (compilerOptions.emitDecoratorMetadata) { - writeLines(metadataHelper); - } - decorateEmitted = true; - } - if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32 /* EmitParam */) { - writeLines(paramHelper); - paramEmitted = true; - } - if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64 /* EmitAwaiter */) { - writeLines(awaiterHelper); - awaiterEmitted = true; - } - } - } - function emitSourceFileNode(node) { - // Start new file on new line - writeLine(); - emitShebang(); - emitDetachedComments(node); - // emit prologue directives prior to __extends - var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); - if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { - if (languageVersion >= 2 /* ES6 */) { - emitES6Module(node, startIndex); - } - else if (compilerOptions.module === 2 /* AMD */) { - emitAMDModule(node, startIndex); - } - else if (compilerOptions.module === 4 /* System */) { - emitSystemModule(node, startIndex); - } - else if (compilerOptions.module === 3 /* UMD */) { - emitUMDModule(node, startIndex); - } - else { - emitCommonJSModule(node, startIndex); - } - } - else { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - } - emitLeadingComments(node.endOfFileToken); - } - function emitNodeWithCommentsAndWithoutSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); - } - function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { - if (node) { - if (node.flags & 2 /* Ambient */) { - return emitCommentsOnNotEmittedNode(node); - } - if (isSpecializedCommentHandling(node)) { - // This is the node that will handle its own comments and sourcemap - return emitNodeWithoutSourceMap(node); - } - var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); - if (emitComments_1) { - emitLeadingComments(node); - } - emitNodeConsideringSourcemap(node); - if (emitComments_1) { - emitTrailingComments(node); - } - } - } - function emitNodeWithoutSourceMap(node) { - if (node) { - emitJavaScriptWorker(node); - } - } - function isSpecializedCommentHandling(node) { - switch (node.kind) { - // All of these entities are emitted in a specialized fashion. As such, we allow - // the specialized methods for each to handle the comments on the nodes. - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 225 /* ExportAssignment */: - return true; - } - } - function shouldEmitLeadingAndTrailingComments(node) { - switch (node.kind) { - case 191 /* VariableStatement */: - return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); - case 216 /* ModuleDeclaration */: - // Only emit the leading/trailing comments for a module if we're actually - // emitting the module as well. - return shouldEmitModuleDeclaration(node); - case 215 /* EnumDeclaration */: - // Only emit the leading/trailing comments for an enum if we're actually - // emitting the module as well. - return shouldEmitEnumDeclaration(node); - } - // If the node is emitted in specialized fashion, dont emit comments as this node will handle - // emitting comments when emitting itself - ts.Debug.assert(!isSpecializedCommentHandling(node)); - // If this is the expression body of an arrow function that we're down-leveling, - // then we don't want to emit comments when we emit the body. It will have already - // been taken care of when we emitted the 'return' statement for the function - // expression body. - if (node.kind !== 190 /* Block */ && - node.parent && - node.parent.kind === 172 /* ArrowFunction */ && - node.parent.body === node && - compilerOptions.target <= 1 /* ES5 */) { - return false; - } - // Emit comments for everything else. - return true; - } - function emitJavaScriptWorker(node) { - // Check if the node can be emitted regardless of the ScriptTarget - switch (node.kind) { - case 67 /* Identifier */: - return emitIdentifier(node); - case 136 /* Parameter */: - return emitParameter(node); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - return emitMethod(node); - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - return emitAccessor(node); - case 95 /* ThisKeyword */: - return emitThis(node); - case 93 /* SuperKeyword */: - return emitSuper(node); - case 91 /* NullKeyword */: - return write("null"); - case 97 /* TrueKeyword */: - return write("true"); - case 82 /* FalseKeyword */: - return write("false"); - case 8 /* NumericLiteral */: - case 9 /* StringLiteral */: - case 10 /* RegularExpressionLiteral */: - case 11 /* NoSubstitutionTemplateLiteral */: - case 12 /* TemplateHead */: - case 13 /* TemplateMiddle */: - case 14 /* TemplateTail */: - return emitLiteral(node); - case 181 /* TemplateExpression */: - return emitTemplateExpression(node); - case 188 /* TemplateSpan */: - return emitTemplateSpan(node); - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - return emitJsxElement(node); - case 234 /* JsxText */: - return emitJsxText(node); - case 238 /* JsxExpression */: - return emitJsxExpression(node); - case 133 /* QualifiedName */: - return emitQualifiedName(node); - case 159 /* ObjectBindingPattern */: - return emitObjectBindingPattern(node); - case 160 /* ArrayBindingPattern */: - return emitArrayBindingPattern(node); - case 161 /* BindingElement */: - return emitBindingElement(node); - case 162 /* ArrayLiteralExpression */: - return emitArrayLiteral(node); - case 163 /* ObjectLiteralExpression */: - return emitObjectLiteral(node); - case 243 /* PropertyAssignment */: - return emitPropertyAssignment(node); - case 244 /* ShorthandPropertyAssignment */: - return emitShorthandPropertyAssignment(node); - case 134 /* ComputedPropertyName */: - return emitComputedPropertyName(node); - case 164 /* PropertyAccessExpression */: - return emitPropertyAccess(node); - case 165 /* ElementAccessExpression */: - return emitIndexedAccess(node); - case 166 /* CallExpression */: - return emitCallExpression(node); - case 167 /* NewExpression */: - return emitNewExpression(node); - case 168 /* TaggedTemplateExpression */: - return emitTaggedTemplateExpression(node); - case 169 /* TypeAssertionExpression */: - return emit(node.expression); - case 187 /* AsExpression */: - return emit(node.expression); - case 170 /* ParenthesizedExpression */: - return emitParenExpression(node); - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - return emitFunctionDeclaration(node); - case 173 /* DeleteExpression */: - return emitDeleteExpression(node); - case 174 /* TypeOfExpression */: - return emitTypeOfExpression(node); - case 175 /* VoidExpression */: - return emitVoidExpression(node); - case 176 /* AwaitExpression */: - return emitAwaitExpression(node); - case 177 /* PrefixUnaryExpression */: - return emitPrefixUnaryExpression(node); - case 178 /* PostfixUnaryExpression */: - return emitPostfixUnaryExpression(node); - case 179 /* BinaryExpression */: - return emitBinaryExpression(node); - case 180 /* ConditionalExpression */: - return emitConditionalExpression(node); - case 183 /* SpreadElementExpression */: - return emitSpreadElementExpression(node); - case 182 /* YieldExpression */: - return emitYieldExpression(node); - case 185 /* OmittedExpression */: - return; - case 190 /* Block */: - case 217 /* ModuleBlock */: - return emitBlock(node); - case 191 /* VariableStatement */: - return emitVariableStatement(node); - case 192 /* EmptyStatement */: - return write(";"); - case 193 /* ExpressionStatement */: - return emitExpressionStatement(node); - case 194 /* IfStatement */: - return emitIfStatement(node); - case 195 /* DoStatement */: - return emitDoStatement(node); - case 196 /* WhileStatement */: - return emitWhileStatement(node); - case 197 /* ForStatement */: - return emitForStatement(node); - case 199 /* ForOfStatement */: - case 198 /* ForInStatement */: - return emitForInOrForOfStatement(node); - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: - return emitBreakOrContinueStatement(node); - case 202 /* ReturnStatement */: - return emitReturnStatement(node); - case 203 /* WithStatement */: - return emitWithStatement(node); - case 204 /* SwitchStatement */: - return emitSwitchStatement(node); - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - return emitCaseOrDefaultClause(node); - case 205 /* LabeledStatement */: - return emitLabelledStatement(node); - case 206 /* ThrowStatement */: - return emitThrowStatement(node); - case 207 /* TryStatement */: - return emitTryStatement(node); - case 242 /* CatchClause */: - return emitCatchClause(node); - case 208 /* DebuggerStatement */: - return emitDebuggerStatement(node); - case 209 /* VariableDeclaration */: - return emitVariableDeclaration(node); - case 184 /* ClassExpression */: - return emitClassExpression(node); - case 212 /* ClassDeclaration */: - return emitClassDeclaration(node); - case 213 /* InterfaceDeclaration */: - return emitInterfaceDeclaration(node); - case 215 /* EnumDeclaration */: - return emitEnumDeclaration(node); - case 245 /* EnumMember */: - return emitEnumMember(node); - case 216 /* ModuleDeclaration */: - return emitModuleDeclaration(node); - case 220 /* ImportDeclaration */: - return emitImportDeclaration(node); - case 219 /* ImportEqualsDeclaration */: - return emitImportEqualsDeclaration(node); - case 226 /* ExportDeclaration */: - return emitExportDeclaration(node); - case 225 /* ExportAssignment */: - return emitExportAssignment(node); - case 246 /* SourceFile */: - return emitSourceFileNode(node); - } - } - function hasDetachedComments(pos) { - return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; - } - function getLeadingCommentsWithoutDetachedComments() { - // get the leading comments from detachedPos - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); - if (detachedCommentsInfo.length - 1) { - detachedCommentsInfo.pop(); - } - else { - detachedCommentsInfo = undefined; - } - return leadingComments; - } - function isPinnedComments(comment) { - return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; - } - /** - * Determine if the given comment is a triple-slash - * - * @return true if the comment is a triple-slash comment else false - **/ - function isTripleSlashComment(comment) { - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */) { - var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); - return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || - textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? - true : false; - } - return false; - } - function getLeadingCommentsToEmit(node) { - // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments - if (node.parent) { - if (node.parent.kind === 246 /* SourceFile */ || node.pos !== node.parent.pos) { - if (hasDetachedComments(node.pos)) { - // get comments without detached comments - return getLeadingCommentsWithoutDetachedComments(); - } - else { - // get the leading comments from the node - return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - } - } - } - function getTrailingCommentsToEmit(node) { - // Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments - if (node.parent) { - if (node.parent.kind === 246 /* SourceFile */ || node.end !== node.parent.end) { - return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - } - } - } - /** - * Emit comments associated with node that will not be emitted into JS file - */ - function emitCommentsOnNotEmittedNode(node) { - emitLeadingCommentsWorker(node, /*isEmittedNode:*/ false); - } - function emitLeadingComments(node) { - return emitLeadingCommentsWorker(node, /*isEmittedNode:*/ true); - } - function emitLeadingCommentsWorker(node, isEmittedNode) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (isEmittedNode) { - leadingComments = getLeadingCommentsToEmit(node); - } - else { - // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, - // unless it is a triple slash comment at the top of the file. - // For Example: - // /// - // declare var x; - // /// - // interface F {} - // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted - if (node.pos === 0) { - leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); - } - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator:*/ true, newLine, writeComment); - } - function emitTrailingComments(node) { - if (compilerOptions.removeComments) { - return; - } - // Emit the trailing comments only if the parent's end doesn't match - var trailingComments = getTrailingCommentsToEmit(node); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); - } - /** - * Emit trailing comments at the position. The term trailing comment is used here to describe following comment: - * x, /comment1/ y - * ^ => pos; the function will emit "comment1" in the emitJS - */ - function emitTrailingCommentsOfPosition(pos) { - if (compilerOptions.removeComments) { - return; - } - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); - } - function emitLeadingCommentsOfPositionWorker(pos) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (hasDetachedComments(pos)) { - // get comments without detached comments - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - // get the leading comments from the node - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); - // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); - } - function emitDetachedComments(node) { - var leadingComments; - if (compilerOptions.removeComments) { - // removeComments is true, only reserve pinned comment at the top of file - // For example: - // /*! Pinned Comment */ - // - // var x = 10; - if (node.pos === 0) { - leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); - } - } - else { - // removeComments is false, just get detached as normal and bypass the process to filter comment - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); - } - if (leadingComments) { - var detachedComments = []; - var lastComment; - ts.forEach(leadingComments, function (comment) { - if (lastComment) { - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); - var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); - if (commentLine >= lastCommentLine + 2) { - // There was a blank line between the last comment and this comment. This - // comment is not part of the copyright comments. Return what we have so - // far. - return detachedComments; - } - } - detachedComments.push(comment); - lastComment = comment; - }); - if (detachedComments.length) { - // All comments look like they could have been part of the copyright header. Make - // sure there is at least one blank line between it and the node. If not, it's not - // a copyright header. - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); - var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - if (nodeLine >= lastCommentLine + 2) { - // Valid detachedComments - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - ts.emitComments(currentSourceFile, writer, detachedComments, /*trailingSeparator*/ true, newLine, writeComment); - var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; - if (detachedCommentsInfo) { - detachedCommentsInfo.push(currentDetachedCommentInfo); - } - else { - detachedCommentsInfo = [currentDetachedCommentInfo]; - } - } - } - } - } - function emitShebang() { - var shebang = ts.getShebang(currentSourceFile.text); - if (shebang) { - write(shebang); - } - } - } - function emitFile(jsFilePath, sourceFile) { - emitJavaScript(jsFilePath, sourceFile); - if (compilerOptions.declaration) { - ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); - } - } - } - ts.emitFiles = emitFiles; var entities = { "quot": 0x0022, "amp": 0x0026, @@ -35261,6 +29428,6531 @@ var ts; "hearts": 0x2665, "diams": 0x2666 }; + // Flags enum to track count of temp variables and a few dedicated names + var TempFlags; + (function (TempFlags) { + TempFlags[TempFlags["Auto"] = 0] = "Auto"; + TempFlags[TempFlags["CountMask"] = 268435455] = "CountMask"; + TempFlags[TempFlags["_i"] = 268435456] = "_i"; + })(TempFlags || (TempFlags = {})); + // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature + function emitFiles(resolver, host, targetSourceFile) { + // emit output for the __extends helper function + var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; + // emit output for the __decorate helper function + var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};"; + // emit output for the __metadata helper function + var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; + // emit output for the __param helper function + var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; + var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; + var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 /* ES6 */ ? 5 /* ES6 */ : 0 /* None */; + var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; + var diagnostics = []; + var newLine = host.getNewLine(); + var jsxDesugaring = host.getCompilerOptions().jsx !== 1 /* Preserve */; + var shouldEmitJsx = function (s) { return (s.languageVariant === 1 /* JSX */ && !jsxDesugaring); }; + if (targetSourceFile === undefined) { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, sourceFile); + } + }); + if (compilerOptions.outFile || compilerOptions.out) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + else { + // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service) + if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + // Sort and make the unique list of diagnostics + diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); + return { + emitSkipped: false, + diagnostics: diagnostics, + sourceMaps: sourceMapDataList + }; + function isNodeDescendentOf(node, ancestor) { + while (node) { + if (node === ancestor) + return true; + node = node.parent; + } + return false; + } + function isUniqueLocalName(name, container) { + for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + if (node.locals && ts.hasProperty(node.locals, name)) { + // We conservatively include alias symbols to cover cases where they're emitted as locals + if (node.locals[name].flags & (107455 /* Value */ | 1048576 /* ExportValue */ | 8388608 /* Alias */)) { + return false; + } + } + } + return true; + } + function emitJavaScript(jsFilePath, root) { + var writer = ts.createTextWriter(newLine); + var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; + var currentSourceFile; + // name of an exporter function if file is a System external module + // System.register([...], function () {...}) + // exporting in System modules looks like: + // export var x; ... x = 1 + // => + // var x;... exporter("x", x = 1) + var exportFunctionForFile; + var generatedNameSet = {}; + var nodeToGeneratedName = []; + var computedPropertyNamesToGeneratedNames; + var extendsEmitted = false; + var decorateEmitted = false; + var paramEmitted = false; + var awaiterEmitted = false; + var tempFlags = 0; + var tempVariables; + var tempParameters; + var externalImports; + var exportSpecifiers; + var exportEquals; + var hasExportStars; + /** Write emitted output to disk */ + var writeEmittedFiles = writeJavaScriptFile; + var detachedCommentsInfo; + var writeComment = ts.writeCommentRange; + /** Emit a node */ + var emit = emitNodeWithCommentsAndWithoutSourcemap; + /** Called just before starting emit of a node */ + var emitStart = function (node) { }; + /** Called once the emit of the node is done */ + var emitEnd = function (node) { }; + /** Emit the text for the given token that comes after startPos + * This by default writes the text provided with the given tokenKind + * but if optional emitFn callback is provided the text is emitted using the callback instead of default text + * @param tokenKind the kind of the token to search and emit + * @param startPos the position in the source to start searching for the token + * @param emitFn if given will be invoked to emit the text instead of actual token emit */ + var emitToken = emitTokenText; + /** Called to before starting the lexical scopes as in function/class in the emitted code because of node + * @param scopeDeclaration node that starts the lexical scope + * @param scopeName Optional name of this scope instead of deducing one from the declaration node */ + var scopeEmitStart = function (scopeDeclaration, scopeName) { }; + /** Called after coming out of the scope */ + var scopeEmitEnd = function () { }; + /** Sourcemap data that will get encoded */ + var sourceMapData; + /** If removeComments is true, no leading-comments needed to be emitted **/ + var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; + var moduleEmitDelegates = (_a = {}, + _a[5 /* ES6 */] = emitES6Module, + _a[2 /* AMD */] = emitAMDModule, + _a[4 /* System */] = emitSystemModule, + _a[3 /* UMD */] = emitUMDModule, + _a[1 /* CommonJS */] = emitCommonJSModule, + _a + ); + if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { + initializeEmitterWithSourceMaps(); + } + if (root) { + // Do not call emit directly. It does not set the currentSourceFile. + emitSourceFile(root); + } + else { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + emitSourceFile(sourceFile); + } + }); + } + writeLine(); + writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); + return; + function emitSourceFile(sourceFile) { + currentSourceFile = sourceFile; + exportFunctionForFile = undefined; + emit(sourceFile); + } + function isUniqueName(name) { + return !resolver.hasGlobalName(name) && + !ts.hasProperty(currentSourceFile.identifiers, name) && + !ts.hasProperty(generatedNameSet, name); + } + // Return the next available name in the pattern _a ... _z, _0, _1, ... + // TempFlags._i or TempFlags._n may be used to express a preference for that dedicated name. + // Note that names generated by makeTempVariableName and makeUniqueName will never conflict. + function makeTempVariableName(flags) { + if (flags && !(tempFlags & flags)) { + var name_19 = flags === 268435456 /* _i */ ? "_i" : "_n"; + if (isUniqueName(name_19)) { + tempFlags |= flags; + return name_19; + } + } + while (true) { + var count = tempFlags & 268435455 /* CountMask */; + tempFlags++; + // Skip over 'i' and 'n' + if (count !== 8 && count !== 13) { + var name_20 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_20)) { + return name_20; + } + } + } + } + // Generate a name that is unique within the current file and doesn't conflict with any names + // in global scope. The name is formed by adding an '_n' suffix to the specified base name, + // where n is a positive integer. Note that names generated by makeTempVariableName and + // makeUniqueName are guaranteed to never conflict. + function makeUniqueName(baseName) { + // Find the first unique 'name_n', where n is a positive number + if (baseName.charCodeAt(baseName.length - 1) !== 95 /* _ */) { + baseName += "_"; + } + var i = 1; + while (true) { + var generatedName = baseName + i; + if (isUniqueName(generatedName)) { + return generatedNameSet[generatedName] = generatedName; + } + i++; + } + } + function generateNameForModuleOrEnum(node) { + var name = node.name.text; + // Use module/enum name itself if it is unique, otherwise make a unique variation + return isUniqueLocalName(name, node) ? name : makeUniqueName(name); + } + function generateNameForImportOrExportDeclaration(node) { + var expr = ts.getExternalModuleName(node); + var baseName = expr.kind === 9 /* StringLiteral */ ? + ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; + return makeUniqueName(baseName); + } + function generateNameForExportDefault() { + return makeUniqueName("default"); + } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } + function generateNameForNode(node) { + switch (node.kind) { + case 69 /* Identifier */: + return makeUniqueName(node.text); + case 218 /* ModuleDeclaration */: + case 217 /* EnumDeclaration */: + return generateNameForModuleOrEnum(node); + case 222 /* ImportDeclaration */: + case 228 /* ExportDeclaration */: + return generateNameForImportOrExportDeclaration(node); + case 213 /* FunctionDeclaration */: + case 214 /* ClassDeclaration */: + case 227 /* ExportAssignment */: + return generateNameForExportDefault(); + case 186 /* ClassExpression */: + return generateNameForClassExpression(); + } + } + function getGeneratedNameForNode(node) { + var id = ts.getNodeId(node); + return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); + } + function initializeEmitterWithSourceMaps() { + var sourceMapDir; // The directory in which sourcemap will be + // Current source map file and its index in the sources list + var sourceMapSourceIndex = -1; + // Names and its index map + var sourceMapNameIndexMap = {}; + var sourceMapNameIndices = []; + function getSourceMapNameIndex() { + return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; + } + // Last recorded and encoded spans + var lastRecordedSourceMapSpan; + var lastEncodedSourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; + var lastEncodedNameIndex = 0; + // Encoding for sourcemap span + function encodeLastRecordedSourceMapSpan() { + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { + return; + } + var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; + // Line/Comma delimiters + if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { + // Emit comma to separate the entry + if (sourceMapData.sourceMapMappings) { + sourceMapData.sourceMapMappings += ","; + } + } + else { + // Emit line delimiters + for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { + sourceMapData.sourceMapMappings += ";"; + } + prevEncodedEmittedColumn = 1; + } + // 1. Relative Column 0 based + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); + // 2. Relative sourceIndex + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); + // 3. Relative sourceLine 0 based + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); + // 4. Relative sourceColumn 0 based + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); + // 5. Relative namePosition 0 based + if (lastRecordedSourceMapSpan.nameIndex >= 0) { + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); + lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; + } + lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; + sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); + function base64VLQFormatEncode(inValue) { + function base64FormatEncode(inValue) { + if (inValue < 64) { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); + } + throw TypeError(inValue + ": not a 64 based value"); + } + // Add a new least significant bit that has the sign of the value. + // if negative number the least significant bit that gets added to the number has value 1 + // else least significant bit value that gets added is 0 + // eg. -1 changes to binary : 01 [1] => 3 + // +1 changes to binary : 01 [0] => 2 + if (inValue < 0) { + inValue = ((-inValue) << 1) + 1; + } + else { + inValue = inValue << 1; + } + // Encode 5 bits at a time starting from least significant bits + var encodedStr = ""; + do { + var currentDigit = inValue & 31; // 11111 + inValue = inValue >> 5; + if (inValue > 0) { + // There are still more digits to decode, set the msb (6th bit) + currentDigit = currentDigit | 32; + } + encodedStr = encodedStr + base64FormatEncode(currentDigit); + } while (inValue > 0); + return encodedStr; + } + } + function recordSourceMapSpan(pos) { + var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); + // Convert the location to be one-based. + sourceLinePos.line++; + sourceLinePos.character++; + var emittedLine = writer.getLine(); + var emittedColumn = writer.getColumn(); + // If this location wasn't recorded or the location in source is going backwards, record the span + if (!lastRecordedSourceMapSpan || + lastRecordedSourceMapSpan.emittedLine !== emittedLine || + lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || + (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + // Encode the last recordedSpan before assigning new + encodeLastRecordedSourceMapSpan(); + // New span + lastRecordedSourceMapSpan = { + emittedLine: emittedLine, + emittedColumn: emittedColumn, + sourceLine: sourceLinePos.line, + sourceColumn: sourceLinePos.character, + nameIndex: getSourceMapNameIndex(), + sourceIndex: sourceMapSourceIndex + }; + } + else { + // Take the new pos instead since there is no change in emittedLine and column since last location + lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; + lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; + lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; + } + } + function recordEmitNodeStartSpan(node) { + // Get the token pos after skipping to the token (ignoring the leading trivia) + recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); + } + function recordEmitNodeEndSpan(node) { + recordSourceMapSpan(node.end); + } + function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + function recordNewSourceFileStart(node) { + // Add the file to tsFilePaths + // If sourceroot option: Use the relative path corresponding to the common directory path + // otherwise source locations relative to map file location + var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ true)); + sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; + // The one that can be used from program to get the actual source file + sourceMapData.inputSourceFileNames.push(node.fileName); + if (compilerOptions.inlineSources) { + if (!sourceMapData.sourceMapSourcesContent) { + sourceMapData.sourceMapSourcesContent = []; + } + sourceMapData.sourceMapSourcesContent.push(node.text); + } + } + function recordScopeNameOfNode(node, scopeName) { + function recordScopeNameIndex(scopeNameIndex) { + sourceMapNameIndices.push(scopeNameIndex); + } + function recordScopeNameStart(scopeName) { + var scopeNameIndex = -1; + if (scopeName) { + var parentIndex = getSourceMapNameIndex(); + if (parentIndex !== -1) { + // Child scopes are always shown with a dot (even if they have no name), + // unless it is a computed property. Then it is shown with brackets, + // but the brackets are included in the name. + var name_21 = node.name; + if (!name_21 || name_21.kind !== 136 /* ComputedPropertyName */) { + scopeName = "." + scopeName; + } + scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; + } + scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); + if (scopeNameIndex === undefined) { + scopeNameIndex = sourceMapData.sourceMapNames.length; + sourceMapData.sourceMapNames.push(scopeName); + sourceMapNameIndexMap[scopeName] = scopeNameIndex; + } + } + recordScopeNameIndex(scopeNameIndex); + } + if (scopeName) { + // The scope was already given a name use it + recordScopeNameStart(scopeName); + } + else if (node.kind === 213 /* FunctionDeclaration */ || + node.kind === 173 /* FunctionExpression */ || + node.kind === 143 /* MethodDeclaration */ || + node.kind === 142 /* MethodSignature */ || + node.kind === 145 /* GetAccessor */ || + node.kind === 146 /* SetAccessor */ || + node.kind === 218 /* ModuleDeclaration */ || + node.kind === 214 /* ClassDeclaration */ || + node.kind === 217 /* EnumDeclaration */) { + // Declaration and has associated name use it + if (node.name) { + var name_22 = node.name; + // For computed property names, the text will include the brackets + scopeName = name_22.kind === 136 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_22) + : node.name.text; + } + recordScopeNameStart(scopeName); + } + else { + // Block just use the name from upper level scope + recordScopeNameIndex(getSourceMapNameIndex()); + } + } + function recordScopeNameEnd() { + sourceMapNameIndices.pop(); + } + ; + function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { + recordSourceMapSpan(comment.pos); + ts.writeCommentRange(currentSourceFile, writer, comment, newLine); + recordSourceMapSpan(comment.end); + } + function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { + if (typeof JSON !== "undefined") { + var map_1 = { + version: version, + file: file, + sourceRoot: sourceRoot, + sources: sources, + names: names, + mappings: mappings + }; + if (sourcesContent !== undefined) { + map_1.sourcesContent = sourcesContent; + } + return JSON.stringify(map_1); + } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; + function serializeStringArray(list) { + var output = ""; + for (var i = 0, n = list.length; i < n; i++) { + if (i) { + output += ","; + } + output += "\"" + ts.escapeString(list[i]) + "\""; + } + return output; + } + } + function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { + encodeLastRecordedSourceMapSpan(); + var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); + sourceMapDataList.push(sourceMapData); + var sourceMapUrl; + if (compilerOptions.inlineSourceMap) { + // Encode the sourceMap into the sourceMap url + var base64SourceMapText = ts.convertToBase64(sourceMapText); + sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; + } + else { + // Write source map file + ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, /*writeByteOrderMark*/ false); + sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; + } + // Write sourcemap url to the js file and write the js file + writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); + } + // Initialize source map data + var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); + sourceMapData = { + sourceMapFilePath: jsFilePath + ".map", + jsSourceMappingURL: sourceMapJsFile + ".map", + sourceMapFile: sourceMapJsFile, + sourceMapSourceRoot: compilerOptions.sourceRoot || "", + sourceMapSources: [], + inputSourceFileNames: [], + sourceMapNames: [], + sourceMapMappings: "", + sourceMapSourcesContent: undefined, + sourceMapDecodedMappings: [] + }; + // Normalize source root and make sure it has trailing "/" so that it can be used to combine paths with the + // relative paths of the sources list in the sourcemap + sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); + if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { + sourceMapData.sourceMapSourceRoot += ts.directorySeparator; + } + if (compilerOptions.mapRoot) { + sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); + if (root) { + // For modules or multiple emit files the mapRoot will have directory structure like the sources + // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); + } + if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { + // The relative paths are relative to the common directory + sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath + ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap + host.getCurrentDirectory(), host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ true); + } + else { + sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); + } + } + else { + sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); + } + function emitNodeWithSourceMap(node) { + if (node) { + if (ts.nodeIsSynthesized(node)) { + return emitNodeWithoutSourceMap(node); + } + if (node.kind !== 248 /* SourceFile */) { + recordEmitNodeStartSpan(node); + emitNodeWithoutSourceMap(node); + recordEmitNodeEndSpan(node); + } + else { + recordNewSourceFileStart(node); + emitNodeWithoutSourceMap(node); + } + } + } + function emitNodeWithCommentsAndWithSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); + } + writeEmittedFiles = writeJavaScriptAndSourceMapFile; + emit = emitNodeWithCommentsAndWithSourcemap; + emitStart = recordEmitNodeStartSpan; + emitEnd = recordEmitNodeEndSpan; + emitToken = writeTextWithSpanRecord; + scopeEmitStart = recordScopeNameOfNode; + scopeEmitEnd = recordScopeNameEnd; + writeComment = writeCommentRangeWithMap; + } + function writeJavaScriptFile(emitOutput, writeByteOrderMark) { + ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); + } + // Create a temporary variable with a unique unused name. + function createTempVariable(flags) { + var result = ts.createSynthesizedNode(69 /* Identifier */); + result.text = makeTempVariableName(flags); + return result; + } + function recordTempDeclaration(name) { + if (!tempVariables) { + tempVariables = []; + } + tempVariables.push(name); + } + function createAndRecordTempVariable(flags) { + var temp = createTempVariable(flags); + recordTempDeclaration(temp); + return temp; + } + function emitTempDeclarations(newLine) { + if (tempVariables) { + if (newLine) { + writeLine(); + } + else { + write(" "); + } + write("var "); + emitCommaList(tempVariables); + write(";"); + } + } + function emitTokenText(tokenKind, startPos, emitFn) { + var tokenString = ts.tokenToString(tokenKind); + if (emitFn) { + emitFn(); + } + else { + write(tokenString); + } + return startPos + tokenString.length; + } + function emitOptional(prefix, node) { + if (node) { + write(prefix); + emit(node); + } + } + function emitParenthesizedIf(node, parenthesized) { + if (parenthesized) { + write("("); + } + emit(node); + if (parenthesized) { + write(")"); + } + } + function emitTrailingCommaIfPresent(nodeList) { + if (nodeList.hasTrailingComma) { + write(","); + } + } + function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { + ts.Debug.assert(nodes.length > 0); + increaseIndent(); + if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + for (var i = 0, n = nodes.length; i < n; i++) { + if (i) { + if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { + write(", "); + } + else { + write(","); + writeLine(); + } + } + emit(nodes[i]); + } + if (nodes.hasTrailingComma && allowTrailingComma) { + write(","); + } + decreaseIndent(); + if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + } + function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { + if (!emitNode) { + emitNode = emit; + } + for (var i = 0; i < count; i++) { + if (multiLine) { + if (i || leadingComma) { + write(","); + } + writeLine(); + } + else { + if (i || leadingComma) { + write(", "); + } + } + var node = nodes[start + i]; + // This emitting is to make sure we emit following comment properly + // ...(x, /*comment1*/ y)... + // ^ => node.pos + // "comment1" is not considered leading comment for "y" but rather + // considered as trailing comment of the previous node. + emitTrailingCommentsOfPosition(node.pos); + emitNode(node); + leadingComma = true; + } + if (trailingComma) { + write(","); + } + if (multiLine && !noTrailingNewLine) { + writeLine(); + } + return count; + } + function emitCommaList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, /*multiline*/ false, /*trailingComma*/ false); + } + } + function emitLines(nodes) { + emitLinesStartingAt(nodes, /*startIndex*/ 0); + } + function emitLinesStartingAt(nodes, startIndex) { + for (var i = startIndex; i < nodes.length; i++) { + writeLine(); + emit(nodes[i]); + } + } + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 8 /* NumericLiteral */ && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98 /* b */: + case 66 /* B */: + case 111 /* o */: + case 79 /* O */: + return true; + } + } + return false; + } + function emitLiteral(node) { + var text = getLiteralText(node); + if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { + writer.writeLiteral(text); + } + else if (languageVersion < 2 /* ES6 */ && isBinaryOrOctalIntegerLiteral(node, text)) { + write(node.text); + } + else { + write(text); + } + } + function getLiteralText(node) { + // Any template literal or string literal with an extended escape + // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal. + if (languageVersion < 2 /* ES6 */ && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText("\"", node.text, "\""); + } + // If we don't need to downlevel and we can reach the original source text using + // the node's parent reference, then simply get the text as it was originally written. + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + // If we can't reach the original source text, use the canonical form if it's a number, + // or an escaped quoted form of the original text if it's string-like. + switch (node.kind) { + case 9 /* StringLiteral */: + return getQuotedEscapedLiteralText("\"", node.text, "\""); + case 11 /* NoSubstitutionTemplateLiteral */: + return getQuotedEscapedLiteralText("`", node.text, "`"); + case 12 /* TemplateHead */: + return getQuotedEscapedLiteralText("`", node.text, "${"); + case 13 /* TemplateMiddle */: + return getQuotedEscapedLiteralText("}", node.text, "${"); + case 14 /* TemplateTail */: + return getQuotedEscapedLiteralText("}", node.text, "`"); + case 8 /* NumericLiteral */: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + // Find original source text, since we need to emit the raw strings of the tagged template. + // The raw strings contain the (escaped) strings of what the user wrote. + // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + var isLast = node.kind === 11 /* NoSubstitutionTemplateLiteral */ || node.kind === 14 /* TemplateTail */; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + // Newline normalization: + // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's + // and LineTerminatorSequences are normalized to for both TV and TRV. + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write("\"" + text + "\""); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 11 /* NoSubstitutionTemplateLiteral */) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(0 /* Auto */); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + // Now we emit the expressions + if (node.template.kind === 183 /* TemplateExpression */) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 181 /* BinaryExpression */ + && templateSpan.expression.operatorToken.kind === 24 /* CommaToken */; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); + } + function emitTemplateExpression(node) { + // In ES6 mode and above, we can simply emit each portion of a template in order, but in + // ES3 & ES5 we must convert the template expression into a series of string concatenations. + if (languageVersion >= 2 /* ES6 */) { + ts.forEachChild(node, emit); + return; + } + var emitOuterParens = ts.isExpression(node.parent) + && templateNeedsParens(node, node.parent); + if (emitOuterParens) { + write("("); + } + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + for (var i = 0, n = node.templateSpans.length; i < n; i++) { + var templateSpan = node.templateSpans[i]; + // Check if the expression has operands and binds its operands less closely than binary '+'. + // If it does, we need to wrap the expression in parentheses. Otherwise, something like + // `abc${ 1 << 2 }` + // becomes + // "abc" + 1 << 2 + "" + // which is really + // ("abc" + 1) << (2 + "") + // rather than + // "abc" + (1 << 2) + "" + var needsParens = templateSpan.expression.kind !== 172 /* ParenthesizedExpression */ + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; + if (i > 0 || headEmitted) { + // If this is the first span and the head was not emitted, then this templateSpan's + // expression will be the first to be emitted. Don't emit the preceding ' + ' in that + // case. + write(" + "); + } + emitParenthesizedIf(templateSpan.expression, needsParens); + // Only emit if the literal is non-empty. + // The binary '+' operator is left-associative, so the first string concatenation + // with the head will force the result up to this point to be a string. + // Emitting a '+ ""' has no semantic effect for middles and tails. + if (templateSpan.literal.text.length !== 0) { + write(" + "); + emitLiteral(templateSpan.literal); + } + } + if (emitOuterParens) { + write(")"); + } + function shouldEmitTemplateHead() { + // If this expression has an empty head literal and the first template span has a non-empty + // literal, then emitting the empty head literal is not necessary. + // `${ foo } and ${ bar }` + // can be emitted as + // foo + " and " + bar + // This is because it is only required that one of the first two operands in the emit + // output must be a string literal, so that the other operand and all following operands + // are forced into strings. + // + // If the first template span has an empty literal, then the head must still be emitted. + // `${ foo }${ bar }` + // must still be emitted as + // "" + foo + bar + // There is always atleast one templateSpan in this code path, since + // NoSubstitutionTemplateLiterals are directly emitted via emitLiteral() + ts.Debug.assert(node.templateSpans.length !== 0); + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template, parent) { + switch (parent.kind) { + case 168 /* CallExpression */: + case 169 /* NewExpression */: + return parent.expression === template; + case 170 /* TaggedTemplateExpression */: + case 172 /* ParenthesizedExpression */: + return false; + default: + return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; + } + } + /** + * Returns whether the expression has lesser, greater, + * or equal precedence to the binary '+' operator + */ + function comparePrecedenceToBinaryPlus(expression) { + // All binary expressions have lower precedence than '+' apart from '*', '/', and '%' + // which have greater precedence and '-' which has equal precedence. + // All unary operators have a higher precedence apart from yield. + // Arrow functions and conditionals have a lower precedence, + // although we convert the former into regular function expressions in ES5 mode, + // and in ES6 mode this function won't get called anyway. + // + // TODO (drosen): Note that we need to account for the upcoming 'yield' and + // spread ('...') unary operators that are anticipated for ES6. + switch (expression.kind) { + case 181 /* BinaryExpression */: + switch (expression.operatorToken.kind) { + case 37 /* AsteriskToken */: + case 39 /* SlashToken */: + case 40 /* PercentToken */: + return 1 /* GreaterThan */; + case 35 /* PlusToken */: + case 36 /* MinusToken */: + return 0 /* EqualTo */; + default: + return -1 /* LessThan */; + } + case 184 /* YieldExpression */: + case 182 /* ConditionalExpression */: + return -1 /* LessThan */; + default: + return 1 /* GreaterThan */; + } + } + } + function emitTemplateSpan(span) { + emit(span.expression); + emit(span.literal); + } + function jsxEmitReact(node) { + /// Emit a tag name, which is either '"div"' for lower-cased names, or + /// 'Div' for upper-cased or dotted names + function emitTagName(name) { + if (name.kind === 69 /* Identifier */ && ts.isIntrinsicJsxName(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + /// Emit an attribute name, which is quoted if it needs to be quoted. Because + /// these emit into an object literal property name, we don't need to be worried + /// about keywords, just non-identifier characters + function emitAttributeName(name) { + if (/[A-Za-z_]+[\w*]/.test(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + /// Emit an name/value pair for an attribute (e.g. "x: 3") + function emitJsxAttribute(node) { + emitAttributeName(node.name); + write(": "); + if (node.initializer) { + emit(node.initializer); + } + else { + write("true"); + } + } + function emitJsxElement(openingNode, children) { + var syntheticReactRef = ts.createSynthesizedNode(69 /* Identifier */); + syntheticReactRef.text = "React"; + syntheticReactRef.parent = openingNode; + // Call React.createElement(tag, ... + emitLeadingComments(openingNode); + emitExpressionIdentifier(syntheticReactRef); + write(".createElement("); + emitTagName(openingNode.tagName); + write(", "); + // Attribute list + if (openingNode.attributes.length === 0) { + // When there are no attributes, React wants "null" + write("null"); + } + else { + // Either emit one big object literal (no spread attribs), or + // a call to React.__spread + var attrs = openingNode.attributes; + if (ts.forEach(attrs, function (attr) { return attr.kind === 239 /* JsxSpreadAttribute */; })) { + emitExpressionIdentifier(syntheticReactRef); + write(".__spread("); + var haveOpenedObjectLiteral = false; + for (var i_1 = 0; i_1 < attrs.length; i_1++) { + if (attrs[i_1].kind === 239 /* JsxSpreadAttribute */) { + // If this is the first argument, we need to emit a {} as the first argument + if (i_1 === 0) { + write("{}, "); + } + if (haveOpenedObjectLiteral) { + write("}"); + haveOpenedObjectLiteral = false; + } + if (i_1 > 0) { + write(", "); + } + emit(attrs[i_1].expression); + } + else { + ts.Debug.assert(attrs[i_1].kind === 238 /* JsxAttribute */); + if (haveOpenedObjectLiteral) { + write(", "); + } + else { + haveOpenedObjectLiteral = true; + if (i_1 > 0) { + write(", "); + } + write("{"); + } + emitJsxAttribute(attrs[i_1]); + } + } + if (haveOpenedObjectLiteral) + write("}"); + write(")"); // closing paren to React.__spread( + } + else { + // One object literal with all the attributes in them + write("{"); + for (var i = 0; i < attrs.length; i++) { + if (i > 0) { + write(", "); + } + emitJsxAttribute(attrs[i]); + } + write("}"); + } + } + // Children + if (children) { + for (var i = 0; i < children.length; i++) { + // Don't emit empty expressions + if (children[i].kind === 240 /* JsxExpression */ && !(children[i].expression)) { + continue; + } + // Don't emit empty strings + if (children[i].kind === 236 /* JsxText */) { + var text = getTextToEmit(children[i]); + if (text !== undefined) { + write(", \""); + write(text); + write("\""); + } + } + else { + write(", "); + emit(children[i]); + } + } + } + // Closing paren + write(")"); // closes "React.createElement(" + emitTrailingComments(openingNode); + } + if (node.kind === 233 /* JsxElement */) { + emitJsxElement(node.openingElement, node.children); + } + else { + ts.Debug.assert(node.kind === 234 /* JsxSelfClosingElement */); + emitJsxElement(node); + } + } + function jsxEmitPreserve(node) { + function emitJsxAttribute(node) { + emit(node.name); + if (node.initializer) { + write("="); + emit(node.initializer); + } + } + function emitJsxSpreadAttribute(node) { + write("{..."); + emit(node.expression); + write("}"); + } + function emitAttributes(attribs) { + for (var i = 0, n = attribs.length; i < n; i++) { + if (i > 0) { + write(" "); + } + if (attribs[i].kind === 239 /* JsxSpreadAttribute */) { + emitJsxSpreadAttribute(attribs[i]); + } + else { + ts.Debug.assert(attribs[i].kind === 238 /* JsxAttribute */); + emitJsxAttribute(attribs[i]); + } + } + } + function emitJsxOpeningOrSelfClosingElement(node) { + write("<"); + emit(node.tagName); + if (node.attributes.length > 0 || (node.kind === 234 /* JsxSelfClosingElement */)) { + write(" "); + } + emitAttributes(node.attributes); + if (node.kind === 234 /* JsxSelfClosingElement */) { + write("/>"); + } + else { + write(">"); + } + } + function emitJsxClosingElement(node) { + write(""); + } + function emitJsxElement(node) { + emitJsxOpeningOrSelfClosingElement(node.openingElement); + for (var i = 0, n = node.children.length; i < n; i++) { + emit(node.children[i]); + } + emitJsxClosingElement(node.closingElement); + } + if (node.kind === 233 /* JsxElement */) { + emitJsxElement(node); + } + else { + ts.Debug.assert(node.kind === 234 /* JsxSelfClosingElement */); + emitJsxOpeningOrSelfClosingElement(node); + } + } + // This function specifically handles numeric/string literals for enum and accessor 'identifiers'. + // In a sense, it does not actually emit identifiers as much as it declares a name for a specific property. + // For example, this is utilized when feeding in a result to Object.defineProperty. + function emitExpressionForPropertyName(node) { + ts.Debug.assert(node.kind !== 163 /* BindingElement */); + if (node.kind === 9 /* StringLiteral */) { + emitLiteral(node); + } + else if (node.kind === 136 /* ComputedPropertyName */) { + // if this is a decorated computed property, we will need to capture the result + // of the property expression so that we can apply decorators later. This is to ensure + // we don't introduce unintended side effects: + // + // class C { + // [_a = x]() { } + // } + // + // The emit for the decorated computed property decorator is: + // + // __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a)); + // + if (ts.nodeIsDecorated(node.parent)) { + if (!computedPropertyNamesToGeneratedNames) { + computedPropertyNamesToGeneratedNames = []; + } + var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; + if (generatedName) { + // we have already generated a variable for this node, write that value instead. + write(generatedName); + return; + } + generatedName = createAndRecordTempVariable(0 /* Auto */).text; + computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; + write(generatedName); + write(" = "); + } + emit(node.expression); + } + else { + write("\""); + if (node.kind === 8 /* NumericLiteral */) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + write("\""); + } + } + function isExpressionIdentifier(node) { + var parent = node.parent; + switch (parent.kind) { + case 164 /* ArrayLiteralExpression */: + case 189 /* AsExpression */: + case 181 /* BinaryExpression */: + case 168 /* CallExpression */: + case 241 /* CaseClause */: + case 136 /* ComputedPropertyName */: + case 182 /* ConditionalExpression */: + case 139 /* Decorator */: + case 175 /* DeleteExpression */: + case 197 /* DoStatement */: + case 167 /* ElementAccessExpression */: + case 227 /* ExportAssignment */: + case 195 /* ExpressionStatement */: + case 188 /* ExpressionWithTypeArguments */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 196 /* IfStatement */: + case 234 /* JsxSelfClosingElement */: + case 235 /* JsxOpeningElement */: + case 239 /* JsxSpreadAttribute */: + case 240 /* JsxExpression */: + case 169 /* NewExpression */: + case 172 /* ParenthesizedExpression */: + case 180 /* PostfixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: + case 204 /* ReturnStatement */: + case 246 /* ShorthandPropertyAssignment */: + case 185 /* SpreadElementExpression */: + case 206 /* SwitchStatement */: + case 170 /* TaggedTemplateExpression */: + case 190 /* TemplateSpan */: + case 208 /* ThrowStatement */: + case 171 /* TypeAssertionExpression */: + case 176 /* TypeOfExpression */: + case 177 /* VoidExpression */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 184 /* YieldExpression */: + return true; + case 163 /* BindingElement */: + case 247 /* EnumMember */: + case 138 /* Parameter */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 211 /* VariableDeclaration */: + return parent.initializer === node; + case 166 /* PropertyAccessExpression */: + return parent.expression === node; + case 174 /* ArrowFunction */: + case 173 /* FunctionExpression */: + return parent.body === node; + case 221 /* ImportEqualsDeclaration */: + return parent.moduleReference === node; + case 135 /* QualifiedName */: + return parent.left === node; + } + return false; + } + function emitExpressionIdentifier(node) { + if (resolver.getNodeCheckFlags(node) & 2048 /* LexicalArguments */) { + write("_arguments"); + return; + } + var container = resolver.getReferencedExportContainer(node); + if (container) { + if (container.kind === 248 /* SourceFile */) { + // Identifier references module export + if (modulekind !== 5 /* ES6 */ && modulekind !== 4 /* System */) { + write("exports."); + } + } + else { + // Identifier references namespace export + write(getGeneratedNameForNode(container)); + write("."); + } + } + else if (modulekind !== 5 /* ES6 */) { + var declaration = resolver.getReferencedImportDeclaration(node); + if (declaration) { + if (declaration.kind === 223 /* ImportClause */) { + // Identifier references default import + write(getGeneratedNameForNode(declaration.parent)); + write(languageVersion === 0 /* ES3 */ ? "[\"default\"]" : ".default"); + return; + } + else if (declaration.kind === 226 /* ImportSpecifier */) { + // Identifier references named import + write(getGeneratedNameForNode(declaration.parent.parent.parent)); + var name_23 = declaration.propertyName || declaration.name; + var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name_23); + if (languageVersion === 0 /* ES3 */ && identifier === "default") { + write("[\"default\"]"); + } + else { + write("."); + write(identifier); + } + return; + } + } + declaration = resolver.getReferencedNestedRedeclaration(node); + if (declaration) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } + if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function isNameOfNestedRedeclaration(node) { + if (languageVersion < 2 /* ES6 */) { + var parent_6 = node.parent; + switch (parent_6.kind) { + case 163 /* BindingElement */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 211 /* VariableDeclaration */: + return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); + } + } + return false; + } + function emitIdentifier(node) { + if (!node.parent) { + write(node.text); + } + else if (isExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else if (isNameOfNestedRedeclaration(node)) { + write(getGeneratedNameForNode(node)); + } + else if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function emitThis(node) { + if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { + write("_this"); + } + else { + write("this"); + } + } + function emitSuper(node) { + if (languageVersion >= 2 /* ES6 */) { + write("super"); + } + else { + var flags = resolver.getNodeCheckFlags(node); + if (flags & 256 /* SuperInstance */) { + write("_super.prototype"); + } + else { + write("_super"); + } + } + } + function emitObjectBindingPattern(node) { + write("{ "); + var elements = node.elements; + emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); + write(" }"); + } + function emitArrayBindingPattern(node) { + write("["); + var elements = node.elements; + emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); + write("]"); + } + function emitBindingElement(node) { + if (node.propertyName) { + emit(node.propertyName); + write(": "); + } + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + emit(node.name); + } + else { + emitModuleMemberName(node); + } + emitOptional(" = ", node.initializer); + } + function emitSpreadElementExpression(node) { + write("..."); + emit(node.expression); + } + function emitYieldExpression(node) { + write(ts.tokenToString(114 /* YieldKeyword */)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } + function emitAwaitExpression(node) { + var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); + if (needsParenthesis) { + write("("); + } + write(ts.tokenToString(114 /* YieldKeyword */)); + write(" "); + emit(node.expression); + if (needsParenthesis) { + write(")"); + } + } + function needsParenthesisForAwaitExpressionAsYield(node) { + if (node.parent.kind === 181 /* BinaryExpression */ && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { + return true; + } + else if (node.parent.kind === 182 /* ConditionalExpression */ && node.parent.condition === node) { + return true; + } + return false; + } + function needsParenthesisForPropertyAccessOrInvocation(node) { + switch (node.kind) { + case 69 /* Identifier */: + case 164 /* ArrayLiteralExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 172 /* ParenthesizedExpression */: + // This list is not exhaustive and only includes those cases that are relevant + // to the check in emitArrayLiteral. More cases can be added as needed. + return false; + } + return true; + } + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { + var pos = 0; + var group = 0; + var length = elements.length; + while (pos < length) { + // Emit using the pattern .concat(, , ...) + if (group === 1 && useConcat) { + write(".concat("); + } + else if (group > 0) { + write(", "); + } + var e = elements[pos]; + if (e.kind === 185 /* SpreadElementExpression */) { + e = e.expression; + emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); + pos++; + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 164 /* ArrayLiteralExpression */) { + write(".slice()"); + } + } + else { + var i = pos; + while (i < length && elements[i].kind !== 185 /* SpreadElementExpression */) { + i++; + } + write("["); + if (multiLine) { + increaseIndent(); + } + emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); + if (multiLine) { + decreaseIndent(); + } + write("]"); + pos = i; + } + group++; + } + if (group > 1) { + if (useConcat) { + write(")"); + } + } + } + function isSpreadElementExpression(node) { + return node.kind === 185 /* SpreadElementExpression */; + } + function emitArrayLiteral(node) { + var elements = node.elements; + if (elements.length === 0) { + write("[]"); + } + else if (languageVersion >= 2 /* ES6 */ || !ts.forEach(elements, isSpreadElementExpression)) { + write("["); + emitLinePreservingList(node, node.elements, elements.hasTrailingComma, /*spacesBetweenBraces:*/ false); + write("]"); + } + else { + emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/ (node.flags & 2048 /* MultiLine */) !== 0, + /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); + } + } + function emitObjectLiteralBody(node, numElements) { + if (numElements === 0) { + write("{}"); + return; + } + write("{"); + if (numElements > 0) { + var properties = node.properties; + // If we are not doing a downlevel transformation for object literals, + // then try to preserve the original shape of the object literal. + // Otherwise just try to preserve the formatting. + if (numElements === properties.length) { + emitLinePreservingList(node, properties, /* allowTrailingComma */ languageVersion >= 1 /* ES5 */, /* spacesBetweenBraces */ true); + } + else { + var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; + if (!multiLine) { + write(" "); + } + else { + increaseIndent(); + } + emitList(properties, 0, numElements, /*multiLine*/ multiLine, /*trailingComma*/ false); + if (!multiLine) { + write(" "); + } + else { + decreaseIndent(); + } + } + } + write("}"); + } + function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { + var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; + var properties = node.properties; + write("("); + if (multiLine) { + increaseIndent(); + } + // For computed properties, we need to create a unique handle to the object + // literal so we can modify it without risking internal assignments tainting the object. + var tempVar = createAndRecordTempVariable(0 /* Auto */); + // Write out the first non-computed properties + // (or all properties if none of them are computed), + // then emit the rest through indexing on the temp variable. + emit(tempVar); + write(" = "); + emitObjectLiteralBody(node, firstComputedPropertyIndex); + for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { + writeComma(); + var property = properties[i]; + emitStart(property); + if (property.kind === 145 /* GetAccessor */ || property.kind === 146 /* SetAccessor */) { + // TODO (drosen): Reconcile with 'emitMemberFunctions'. + var accessors = ts.getAllAccessorDeclarations(node.properties, property); + if (property !== accessors.firstAccessor) { + continue; + } + write("Object.defineProperty("); + emit(tempVar); + write(", "); + emitStart(node.name); + emitExpressionForPropertyName(property.name); + emitEnd(property.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("})"); + emitEnd(property); + } + else { + emitLeadingComments(property); + emitStart(property.name); + emit(tempVar); + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + if (property.kind === 245 /* PropertyAssignment */) { + emit(property.initializer); + } + else if (property.kind === 246 /* ShorthandPropertyAssignment */) { + emitExpressionIdentifier(property.name); + } + else if (property.kind === 143 /* MethodDeclaration */) { + emitFunctionDeclaration(property); + } + else { + ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); + } + } + emitEnd(property); + } + writeComma(); + emit(tempVar); + if (multiLine) { + decreaseIndent(); + writeLine(); + } + write(")"); + function writeComma() { + if (multiLine) { + write(","); + writeLine(); + } + else { + write(", "); + } + } + } + function emitObjectLiteral(node) { + var properties = node.properties; + if (languageVersion < 2 /* ES6 */) { + var numProperties = properties.length; + // Find the first computed property. + // Everything until that point can be emitted as part of the initial object literal. + var numInitialNonComputedProperties = numProperties; + for (var i = 0, n = properties.length; i < n; i++) { + if (properties[i].name.kind === 136 /* ComputedPropertyName */) { + numInitialNonComputedProperties = i; + break; + } + } + var hasComputedProperty = numInitialNonComputedProperties !== properties.length; + if (hasComputedProperty) { + emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); + return; + } + } + // Ordinary case: either the object has no computed properties + // or we're compiling with an ES6+ target. + emitObjectLiteralBody(node, properties.length); + } + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(181 /* BinaryExpression */, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); + result.left = left; + result.right = right; + return result; + } + function createPropertyAccessExpression(expression, name) { + var result = ts.createSynthesizedNode(166 /* PropertyAccessExpression */); + result.expression = parenthesizeForAccess(expression); + result.dotToken = ts.createSynthesizedNode(21 /* DotToken */); + result.name = name; + return result; + } + function createElementAccessExpression(expression, argumentExpression) { + var result = ts.createSynthesizedNode(167 /* ElementAccessExpression */); + result.expression = parenthesizeForAccess(expression); + result.argumentExpression = argumentExpression; + return result; + } + function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 171 /* TypeAssertionExpression */ || expr.kind === 189 /* AsExpression */) { + expr = expr.expression; + } + // isLeftHandSideExpression is almost the correct criterion for when it is not necessary + // to parenthesize the expression before a dot. The known exceptions are: + // + // NewExpression: + // new C.x -> not the same as (new C).x + // NumberLiteral + // 1.x -> not the same as (1).x + // + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 169 /* NewExpression */ && + expr.kind !== 8 /* NumericLiteral */) { + return expr; + } + var node = ts.createSynthesizedNode(172 /* ParenthesizedExpression */); + node.expression = expr; + return node; + } + function emitComputedPropertyName(node) { + write("["); + emitExpressionForPropertyName(node); + write("]"); + } + function emitMethod(node) { + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } + emit(node.name); + if (languageVersion < 2 /* ES6 */) { + write(": function "); + } + emitSignatureAndBody(node); + } + function emitPropertyAssignment(node) { + emit(node.name); + write(": "); + // This is to ensure that we emit comment in the following case: + // For example: + // obj = { + // id: /*comment1*/ ()=>void + // } + // "comment1" is not considered to be leading comment for node.initializer + // but rather a trailing comment on the previous node. + emitTrailingCommentsOfPosition(node.initializer.pos); + emit(node.initializer); + } + // Return true if identifier resolves to an exported member of a namespace + function isNamespaceExportReference(node) { + var container = resolver.getReferencedExportContainer(node); + return container && container.kind !== 248 /* SourceFile */; + } + function emitShorthandPropertyAssignment(node) { + // The name property of a short-hand property assignment is considered an expression position, so here + // we manually emit the identifier to avoid rewriting. + writeTextOfNode(currentSourceFile, node.name); + // If emitting pre-ES6 code, or if the name requires rewriting when resolved as an expression identifier, + // we emit a normal property assignment. For example: + // module m { + // export let y; + // } + // module m { + // let obj = { y }; + // } + // Here we need to emit obj = { y : m.y } regardless of the output target. + if (languageVersion < 2 /* ES6 */ || isNamespaceExportReference(node.name)) { + // Emit identifier as an identifier + write(": "); + emit(node.name); + } + if (languageVersion >= 2 /* ES6 */ && node.objectAssignmentInitializer) { + write(" = "); + emit(node.objectAssignmentInitializer); + } + } + function tryEmitConstantValue(node) { + var constantValue = tryGetConstEnumValue(node); + if (constantValue !== undefined) { + write(constantValue.toString()); + if (!compilerOptions.removeComments) { + var propertyName = node.kind === 166 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + write(" /* " + propertyName + " */"); + } + return true; + } + return false; + } + function tryGetConstEnumValue(node) { + if (compilerOptions.isolatedModules) { + return undefined; + } + return node.kind === 166 /* PropertyAccessExpression */ || node.kind === 167 /* ElementAccessExpression */ + ? resolver.getConstantValue(node) + : undefined; + } + // Returns 'true' if the code was actually indented, false otherwise. + // If the code is not indented, an optional valueToWriteWhenNotIndenting will be + // emitted instead. + function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { + var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + // Always use a newline for synthesized code if the synthesizer desires it. + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + else { + if (valueToWriteWhenNotIndenting) { + write(valueToWriteWhenNotIndenting); + } + return false; + } + } + function emitPropertyAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); + // 1 .toString is a valid property access, emit a space after the literal + // Also emit a space if expression is a integer const enum value - it will appear in generated code as numeric literal + var shouldEmitSpace; + if (!indentedBeforeDot) { + if (node.expression.kind === 8 /* NumericLiteral */) { + // check if numeric literal was originally written with a dot + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); + shouldEmitSpace = text.indexOf(ts.tokenToString(21 /* DotToken */)) < 0; + } + else { + // check if constant enum value is integer + var constantValue = tryGetConstEnumValue(node.expression); + // isFinite handles cases when constantValue is undefined + shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; + } + } + if (shouldEmitSpace) { + write(" ."); + } + else { + write("."); + } + var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); + emit(node.name); + decreaseIndentIf(indentedBeforeDot, indentedAfterDot); + } + function emitQualifiedName(node) { + emit(node.left); + write("."); + emit(node.right); + } + function emitQualifiedNameAsExpression(node, useFallback) { + if (node.left.kind === 69 /* Identifier */) { + emitEntityNameAsExpression(node.left, useFallback); + } + else if (useFallback) { + var temp = createAndRecordTempVariable(0 /* Auto */); + write("("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(node.left, /*useFallback*/ true); + write(") && "); + emitNodeWithoutSourceMap(temp); + } + else { + emitEntityNameAsExpression(node.left, /*useFallback*/ false); + } + write("."); + emit(node.right); + } + function emitEntityNameAsExpression(node, useFallback) { + switch (node.kind) { + case 69 /* Identifier */: + if (useFallback) { + write("typeof "); + emitExpressionIdentifier(node); + write(" !== 'undefined' && "); + } + emitExpressionIdentifier(node); + break; + case 135 /* QualifiedName */: + emitQualifiedNameAsExpression(node, useFallback); + break; + } + } + function emitIndexedAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("["); + emit(node.argumentExpression); + write("]"); + } + function hasSpreadElement(elements) { + return ts.forEach(elements, function (e) { return e.kind === 185 /* SpreadElementExpression */; }); + } + function skipParentheses(node) { + while (node.kind === 172 /* ParenthesizedExpression */ || node.kind === 171 /* TypeAssertionExpression */ || node.kind === 189 /* AsExpression */) { + node = node.expression; + } + return node; + } + function emitCallTarget(node) { + if (node.kind === 69 /* Identifier */ || node.kind === 97 /* ThisKeyword */ || node.kind === 95 /* SuperKeyword */) { + emit(node); + return node; + } + var temp = createAndRecordTempVariable(0 /* Auto */); + write("("); + emit(temp); + write(" = "); + emit(node); + write(")"); + return temp; + } + function emitCallWithSpread(node) { + var target; + var expr = skipParentheses(node.expression); + if (expr.kind === 166 /* PropertyAccessExpression */) { + // Target will be emitted as "this" argument + target = emitCallTarget(expr.expression); + write("."); + emit(expr.name); + } + else if (expr.kind === 167 /* ElementAccessExpression */) { + // Target will be emitted as "this" argument + target = emitCallTarget(expr.expression); + write("["); + emit(expr.argumentExpression); + write("]"); + } + else if (expr.kind === 95 /* SuperKeyword */) { + target = expr; + write("_super"); + } + else { + emit(node.expression); + } + write(".apply("); + if (target) { + if (target.kind === 95 /* SuperKeyword */) { + // Calls of form super(...) and super.foo(...) + emitThis(target); + } + else { + // Calls of form obj.foo(...) + emit(target); + } + } + else { + // Calls of form foo(...) + write("void 0"); + } + write(", "); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false, /*useConcat*/ true); + write(")"); + } + function emitCallExpression(node) { + if (languageVersion < 2 /* ES6 */ && hasSpreadElement(node.arguments)) { + emitCallWithSpread(node); + return; + } + var superCall = false; + if (node.expression.kind === 95 /* SuperKeyword */) { + emitSuper(node.expression); + superCall = true; + } + else { + emit(node.expression); + superCall = node.expression.kind === 166 /* PropertyAccessExpression */ && node.expression.expression.kind === 95 /* SuperKeyword */; + } + if (superCall && languageVersion < 2 /* ES6 */) { + write(".call("); + emitThis(node.expression); + if (node.arguments.length) { + write(", "); + emitCommaList(node.arguments); + } + write(")"); + } + else { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitNewExpression(node) { + write("new "); + // Spread operator logic is supported in new expressions in ES5 using a combination + // of Function.prototype.bind() and Function.prototype.apply(). + // + // Example: + // + // var args = [1, 2, 3, 4, 5]; + // new Array(...args); + // + // is compiled into the following ES5: + // + // var args = [1, 2, 3, 4, 5]; + // new (Array.bind.apply(Array, [void 0].concat(args))); + // + // The 'thisArg' to 'bind' is ignored when invoking the result of 'bind' with 'new', + // Thus, we set it to undefined ('void 0'). + if (languageVersion === 1 /* ES5 */ && + node.arguments && + hasSpreadElement(node.arguments)) { + write("("); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiline*/ false, /*trailingComma*/ false, /*useConcat*/ false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + } + function emitTaggedTemplateExpression(node) { + if (languageVersion >= 2 /* ES6 */) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } + } + function emitParenExpression(node) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 174 /* ArrowFunction */) { + if (node.expression.kind === 171 /* TypeAssertionExpression */ || node.expression.kind === 189 /* AsExpression */) { + var operand = node.expression.expression; + // Make sure we consider all nested cast expressions, e.g.: + // (-A).x; + while (operand.kind === 171 /* TypeAssertionExpression */ || operand.kind === 189 /* AsExpression */) { + operand = operand.expression; + } + // We have an expression of the form: (SubExpr) + // Emitting this as (SubExpr) is really not desirable. We would like to emit the subexpr as is. + // Omitting the parentheses, however, could cause change in the semantics of the generated + // code if the casted expression has a lower precedence than the rest of the expression, e.g.: + // (new A).foo should be emitted as (new A).foo and not new A.foo + // (typeof A).toString() should be emitted as (typeof A).toString() and not typeof A.toString() + // new (A()) should be emitted as new (A()) and not new A() + // (function foo() { })() should be emitted as an IIF (function foo(){})() and not declaration function foo(){} () + if (operand.kind !== 179 /* PrefixUnaryExpression */ && + operand.kind !== 177 /* VoidExpression */ && + operand.kind !== 176 /* TypeOfExpression */ && + operand.kind !== 175 /* DeleteExpression */ && + operand.kind !== 180 /* PostfixUnaryExpression */ && + operand.kind !== 169 /* NewExpression */ && + !(operand.kind === 168 /* CallExpression */ && node.parent.kind === 169 /* NewExpression */) && + !(operand.kind === 173 /* FunctionExpression */ && node.parent.kind === 168 /* CallExpression */) && + !(operand.kind === 8 /* NumericLiteral */ && node.parent.kind === 166 /* PropertyAccessExpression */)) { + emit(operand); + return; + } + } + } + write("("); + emit(node.expression); + write(")"); + } + function emitDeleteExpression(node) { + write(ts.tokenToString(78 /* DeleteKeyword */)); + write(" "); + emit(node.expression); + } + function emitVoidExpression(node) { + write(ts.tokenToString(103 /* VoidKeyword */)); + write(" "); + emit(node.expression); + } + function emitTypeOfExpression(node) { + write(ts.tokenToString(101 /* TypeOfKeyword */)); + write(" "); + emit(node.expression); + } + function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { + if (!isCurrentFileSystemExternalModule() || node.kind !== 69 /* Identifier */ || ts.nodeIsSynthesized(node)) { + return false; + } + var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 211 /* VariableDeclaration */ || node.parent.kind === 163 /* BindingElement */); + var targetDeclaration = isVariableDeclarationOrBindingElement + ? node.parent + : resolver.getReferencedValueDeclaration(node); + return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true); + } + function emitPrefixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + // emit + // ++x + // as + // exports('x', ++x) + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + } + write(ts.tokenToString(node.operator)); + // In some cases, we need to emit a space between the operator and the operand. One obvious case + // is when the operator is an identifier, like delete or typeof. We also need to do this for plus + // and minus expressions in certain cases. Specifically, consider the following two cases (parens + // are just for clarity of exposition, and not part of the source code): + // + // (+(+1)) + // (+(++1)) + // + // We need to emit a space in both cases. In the first case, the absence of a space will make + // the resulting expression a prefix increment operation. And in the second, it will make the resulting + // expression a prefix increment whose operand is a plus expression - (++(+x)) + // The same is true of minus of course. + if (node.operand.kind === 179 /* PrefixUnaryExpression */) { + var operand = node.operand; + if (node.operator === 35 /* PlusToken */ && (operand.operator === 35 /* PlusToken */ || operand.operator === 41 /* PlusPlusToken */)) { + write(" "); + } + else if (node.operator === 36 /* MinusToken */ && (operand.operator === 36 /* MinusToken */ || operand.operator === 42 /* MinusMinusToken */)) { + write(" "); + } + } + emit(node.operand); + if (exportChanged) { + write(")"); + } + } + function emitPostfixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + // export function returns the value that was passes as the second argument + // however for postfix unary expressions result value should be the value before modification. + // emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)' + write("(" + exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + write(ts.tokenToString(node.operator)); + emit(node.operand); + if (node.operator === 41 /* PlusPlusToken */) { + write(") - 1)"); + } + else { + write(") + 1)"); + } + } + else { + emit(node.operand); + write(ts.tokenToString(node.operator)); + } + } + function shouldHoistDeclarationInSystemJsModule(node) { + return isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ false); + } + /* + * Checks if given node is a source file level declaration (not nested in module/function). + * If 'isExported' is true - then declaration must also be exported. + * This function is used in two cases: + * - check if node is a exported source file level value to determine + * if we should also export the value after its it changed + * - check if node is a source level declaration to emit it differently, + * i.e non-exported variable statement 'var x = 1' is hoisted so + * we we emit variable statement 'var' should be dropped. + */ + function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { + if (!node || languageVersion >= 2 /* ES6 */ || !isCurrentFileSystemExternalModule()) { + return false; + } + var current = node; + while (current) { + if (current.kind === 248 /* SourceFile */) { + return !isExported || ((ts.getCombinedNodeFlags(node) & 1 /* Export */) !== 0); + } + else if (ts.isFunctionLike(current) || current.kind === 219 /* ModuleBlock */) { + return false; + } + else { + current = current.parent; + } + } + } + /** + * Emit ES7 exponentiation operator downlevel using Math.pow + * @param node a binary expression node containing exponentiationOperator (**, **=) + */ + function emitExponentiationOperator(node) { + var leftHandSideExpression = node.left; + if (node.operatorToken.kind === 60 /* AsteriskAsteriskEqualsToken */) { + var synthesizedLHS; + var shouldEmitParentheses = false; + if (ts.isElementAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(167 /* ElementAccessExpression */, /*startsOnNewLine*/ false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, /*canDefinedTempVariablesInPlaces*/ false, /*shouldEmitCommaBeforeAssignment*/ false); + synthesizedLHS.expression = identifier; + if (leftHandSideExpression.argumentExpression.kind !== 8 /* NumericLiteral */ && + leftHandSideExpression.argumentExpression.kind !== 9 /* StringLiteral */) { + var tempArgumentExpression = createAndRecordTempVariable(268435456 /* _i */); + synthesizedLHS.argumentExpression = tempArgumentExpression; + emitAssignment(tempArgumentExpression, leftHandSideExpression.argumentExpression, /*shouldEmitCommaBeforeAssignment*/ true); + } + else { + synthesizedLHS.argumentExpression = leftHandSideExpression.argumentExpression; + } + write(", "); + } + else if (ts.isPropertyAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(166 /* PropertyAccessExpression */, /*startsOnNewLine*/ false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, /*canDefinedTempVariablesInPlaces*/ false, /*shouldemitCommaBeforeAssignment*/ false); + synthesizedLHS.expression = identifier; + synthesizedLHS.dotToken = leftHandSideExpression.dotToken; + synthesizedLHS.name = leftHandSideExpression.name; + write(", "); + } + emit(synthesizedLHS || leftHandSideExpression); + write(" = "); + write("Math.pow("); + emit(synthesizedLHS || leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + if (shouldEmitParentheses) { + write(")"); + } + } + else { + write("Math.pow("); + emit(leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + } + } + function emitBinaryExpression(node) { + if (languageVersion < 2 /* ES6 */ && node.operatorToken.kind === 56 /* EqualsToken */ && + (node.left.kind === 165 /* ObjectLiteralExpression */ || node.left.kind === 164 /* ArrayLiteralExpression */)) { + emitDestructuring(node, node.parent.kind === 195 /* ExpressionStatement */); + } + else { + var exportChanged = node.operatorToken.kind >= 56 /* FirstAssignment */ && + node.operatorToken.kind <= 68 /* LastAssignment */ && + isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); + if (exportChanged) { + // emit assignment 'x y' as 'exports("x", x y)' + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.left); + write("\", "); + } + if (node.operatorToken.kind === 38 /* AsteriskAsteriskToken */ || node.operatorToken.kind === 60 /* AsteriskAsteriskEqualsToken */) { + // Downleveled emit exponentiation operator using Math.pow + emitExponentiationOperator(node); + } + else { + emit(node.left); + // Add indentation before emit the operator if the operator is on different line + // For example: + // 3 + // + 2; + // emitted as + // 3 + // + 2; + var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 /* CommaToken */ ? " " : undefined); + write(ts.tokenToString(node.operatorToken.kind)); + var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); + emit(node.right); + decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); + } + if (exportChanged) { + write(")"); + } + } + } + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; + } + function emitConditionalExpression(node) { + emit(node.condition); + var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); + write("?"); + var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); + emit(node.whenTrue); + decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); + var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); + write(":"); + var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); + emit(node.whenFalse); + decreaseIndentIf(indentedBeforeColon, indentedAfterColon); + } + // Helper function to decrease the indent if we previously indented. Allows multiple + // previous indent values to be considered at a time. This also allows caller to just + // call this once, passing in all their appropriate indent values, instead of needing + // to call this helper function multiple times. + function decreaseIndentIf(value1, value2) { + if (value1) { + decreaseIndent(); + } + if (value2) { + decreaseIndent(); + } + } + function isSingleLineEmptyBlock(node) { + if (node && node.kind === 192 /* Block */) { + var block = node; + return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); + } + } + function emitBlock(node) { + if (isSingleLineEmptyBlock(node)) { + emitToken(15 /* OpenBraceToken */, node.pos); + write(" "); + emitToken(16 /* CloseBraceToken */, node.statements.end); + return; + } + emitToken(15 /* OpenBraceToken */, node.pos); + increaseIndent(); + scopeEmitStart(node.parent); + if (node.kind === 219 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 218 /* ModuleDeclaration */); + emitCaptureThisForNodeIfNecessary(node.parent); + } + emitLines(node.statements); + if (node.kind === 219 /* ModuleBlock */) { + emitTempDeclarations(/*newLine*/ true); + } + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.statements.end); + scopeEmitEnd(); + } + function emitEmbeddedStatement(node) { + if (node.kind === 192 /* Block */) { + write(" "); + emit(node); + } + else { + increaseIndent(); + writeLine(); + emit(node); + decreaseIndent(); + } + } + function emitExpressionStatement(node) { + emitParenthesizedIf(node.expression, /*parenthesized*/ node.expression.kind === 174 /* ArrowFunction */); + write(";"); + } + function emitIfStatement(node) { + var endPos = emitToken(88 /* IfKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + emit(node.expression); + emitToken(18 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.thenStatement); + if (node.elseStatement) { + writeLine(); + emitToken(80 /* ElseKeyword */, node.thenStatement.end); + if (node.elseStatement.kind === 196 /* IfStatement */) { + write(" "); + emit(node.elseStatement); + } + else { + emitEmbeddedStatement(node.elseStatement); + } + } + } + function emitDoStatement(node) { + write("do"); + emitEmbeddedStatement(node.statement); + if (node.statement.kind === 192 /* Block */) { + write(" "); + } + else { + writeLine(); + } + write("while ("); + emit(node.expression); + write(");"); + } + function emitWhileStatement(node) { + write("while ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + /** + * Returns true if start of variable declaration list was emitted. + * Returns false if nothing was written - this can happen for source file level variable declarations + * in system modules where such variable declarations are hoisted. + */ + function tryEmitStartOfVariableDeclarationList(decl, startPos) { + if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) { + // variables in variable declaration list were already hoisted + return false; + } + var tokenKind = 102 /* VarKeyword */; + if (decl && languageVersion >= 2 /* ES6 */) { + if (ts.isLet(decl)) { + tokenKind = 108 /* LetKeyword */; + } + else if (ts.isConst(decl)) { + tokenKind = 74 /* ConstKeyword */; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + write(" "); + } + else { + switch (tokenKind) { + case 102 /* VarKeyword */: + write("var "); + break; + case 108 /* LetKeyword */: + write("let "); + break; + case 74 /* ConstKeyword */: + write("const "); + break; + } + } + return true; + } + function emitVariableDeclarationListSkippingUninitializedEntries(list) { + var started = false; + for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { + var decl = _b[_a]; + if (!decl.initializer) { + continue; + } + if (!started) { + started = true; + } + else { + write(", "); + } + emit(decl); + } + return started; + } + function emitForStatement(node) { + var endPos = emitToken(86 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + if (node.initializer && node.initializer.kind === 212 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + if (startIsEmitted) { + emitCommaList(variableDeclarationList.declarations); + } + else { + emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); + } + } + else if (node.initializer) { + emit(node.initializer); + } + write(";"); + emitOptional(" ", node.condition); + write(";"); + emitOptional(" ", node.incrementor); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForInOrForOfStatement(node) { + if (languageVersion < 2 /* ES6 */ && node.kind === 201 /* ForOfStatement */) { + return emitDownLevelForOfStatement(node); + } + var endPos = emitToken(86 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + if (node.initializer.kind === 212 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + emit(variableDeclarationList.declarations[0]); + } + } + else { + emit(node.initializer); + } + if (node.kind === 200 /* ForInStatement */) { + write(" in "); + } + else { + write(" of "); + } + emit(node.expression); + emitToken(18 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.statement); + } + function emitDownLevelForOfStatement(node) { + // The following ES6 code: + // + // for (let v of expr) { } + // + // should be emitted as + // + // for (let _i = 0, _a = expr; _i < _a.length; _i++) { + // let v = _a[_i]; + // } + // + // where _a and _i are temps emitted to capture the RHS and the counter, + // respectively. + // When the left hand side is an expression instead of a let declaration, + // the "let v" is not emitted. + // When the left hand side is a let/const, the v is renamed if there is + // another v in scope. + // Note that all assignments to the LHS are emitted in the body, including + // all destructuring. + // Note also that because an extra statement is needed to assign to the LHS, + // for-of bodies are always emitted as blocks. + var endPos = emitToken(86 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + // Do not emit the LHS let declaration yet, because it might contain destructuring. + // Do not call recordTempDeclaration because we are declaring the temps + // right here. Recording means they will be declared later. + // In the case where the user wrote an identifier as the RHS, like this: + // + // for (let v of arr) { } + // + // we don't want to emit a temporary variable for the RHS, just use it directly. + var rhsIsIdentifier = node.expression.kind === 69 /* Identifier */; + var counter = createTempVariable(268435456 /* _i */); + var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0 /* Auto */); + // This is the let keyword for the counter and rhsReference. The let keyword for + // the LHS will be emitted inside the body. + emitStart(node.expression); + write("var "); + // _i = 0 + emitNodeWithoutSourceMap(counter); + write(" = 0"); + emitEnd(node.expression); + if (!rhsIsIdentifier) { + // , _a = expr + write(", "); + emitStart(node.expression); + emitNodeWithoutSourceMap(rhsReference); + write(" = "); + emitNodeWithoutSourceMap(node.expression); + emitEnd(node.expression); + } + write("; "); + // _i < _a.length; + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write(" < "); + emitNodeWithCommentsAndWithoutSourcemap(rhsReference); + write(".length"); + emitEnd(node.initializer); + write("; "); + // _i++) + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write("++"); + emitEnd(node.initializer); + emitToken(18 /* CloseParenToken */, node.expression.end); + // Body + write(" {"); + writeLine(); + increaseIndent(); + // Initialize LHS + // let v = _a[_i]; + var rhsIterationValue = createElementAccessExpression(rhsReference, counter); + emitStart(node.initializer); + if (node.initializer.kind === 212 /* VariableDeclarationList */) { + write("var "); + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length > 0) { + var declaration = variableDeclarationList.declarations[0]; + if (ts.isBindingPattern(declaration.name)) { + // This works whether the declaration is a var, let, or const. + // It will use rhsIterationValue _a[_i] as the initializer. + emitDestructuring(declaration, /*isAssignmentExpressionStatement*/ false, rhsIterationValue); + } + else { + // The following call does not include the initializer, so we have + // to emit it separately. + emitNodeWithCommentsAndWithoutSourcemap(declaration); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + // It's an empty declaration list. This can only happen in an error case, if the user wrote + // for (let of []) {} + emitNodeWithoutSourceMap(createTempVariable(0 /* Auto */)); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + // Initializer is an expression. Emit the expression in the body, so that it's + // evaluated on every iteration. + var assignmentExpression = createBinaryExpression(node.initializer, 56 /* EqualsToken */, rhsIterationValue, /*startsOnNewLine*/ false); + if (node.initializer.kind === 164 /* ArrayLiteralExpression */ || node.initializer.kind === 165 /* ObjectLiteralExpression */) { + // This is a destructuring pattern, so call emitDestructuring instead of emit. Calling emit will not work, because it will cause + // the BinaryExpression to be passed in instead of the expression statement, which will cause emitDestructuring to crash. + emitDestructuring(assignmentExpression, /*isAssignmentExpressionStatement*/ true, /*value*/ undefined); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); + } + } + emitEnd(node.initializer); + write(";"); + if (node.statement.kind === 192 /* Block */) { + emitLines(node.statement.statements); + } + else { + writeLine(); + emit(node.statement); + } + writeLine(); + decreaseIndent(); + write("}"); + } + function emitBreakOrContinueStatement(node) { + emitToken(node.kind === 203 /* BreakStatement */ ? 70 /* BreakKeyword */ : 75 /* ContinueKeyword */, node.pos); + emitOptional(" ", node.label); + write(";"); + } + function emitReturnStatement(node) { + emitToken(94 /* ReturnKeyword */, node.pos); + emitOptional(" ", node.expression); + write(";"); + } + function emitWithStatement(node) { + write("with ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitSwitchStatement(node) { + var endPos = emitToken(96 /* SwitchKeyword */, node.pos); + write(" "); + emitToken(17 /* OpenParenToken */, endPos); + emit(node.expression); + endPos = emitToken(18 /* CloseParenToken */, node.expression.end); + write(" "); + emitCaseBlock(node.caseBlock, endPos); + } + function emitCaseBlock(node, startPos) { + emitToken(15 /* OpenBraceToken */, startPos); + increaseIndent(); + emitLines(node.clauses); + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.clauses.end); + } + function nodeStartPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function nodeEndPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, node2.end); + } + function nodeEndIsOnSameLineAsNodeStart(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function emitCaseOrDefaultClause(node) { + if (node.kind === 241 /* CaseClause */) { + write("case "); + emit(node.expression); + write(":"); + } + else { + write("default:"); + } + if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { + write(" "); + emit(node.statements[0]); + } + else { + increaseIndent(); + emitLines(node.statements); + decreaseIndent(); + } + } + function emitThrowStatement(node) { + write("throw "); + emit(node.expression); + write(";"); + } + function emitTryStatement(node) { + write("try "); + emit(node.tryBlock); + emit(node.catchClause); + if (node.finallyBlock) { + writeLine(); + write("finally "); + emit(node.finallyBlock); + } + } + function emitCatchClause(node) { + writeLine(); + var endPos = emitToken(72 /* CatchKeyword */, node.pos); + write(" "); + emitToken(17 /* OpenParenToken */, endPos); + emit(node.variableDeclaration); + emitToken(18 /* CloseParenToken */, node.variableDeclaration ? node.variableDeclaration.end : endPos); + write(" "); + emitBlock(node.block); + } + function emitDebuggerStatement(node) { + emitToken(76 /* DebuggerKeyword */, node.pos); + write(";"); + } + function emitLabelledStatement(node) { + emit(node.label); + write(": "); + emit(node.statement); + } + function getContainingModule(node) { + do { + node = node.parent; + } while (node && node.kind !== 218 /* ModuleDeclaration */); + return node; + } + function emitContainingModuleName(node) { + var container = getContainingModule(node); + write(container ? getGeneratedNameForNode(container) : "exports"); + } + function emitModuleMemberName(node) { + emitStart(node.name); + if (ts.getCombinedNodeFlags(node) & 1 /* Export */) { + var container = getContainingModule(node); + if (container) { + write(getGeneratedNameForNode(container)); + write("."); + } + else if (modulekind !== 5 /* ES6 */ && modulekind !== 4 /* System */) { + write("exports."); + } + } + emitNodeWithCommentsAndWithoutSourcemap(node.name); + emitEnd(node.name); + } + function createVoidZero() { + var zero = ts.createSynthesizedNode(8 /* NumericLiteral */); + zero.text = "0"; + var result = ts.createSynthesizedNode(177 /* VoidExpression */); + result.expression = zero; + return result; + } + function emitEs6ExportDefaultCompat(node) { + if (node.parent.kind === 248 /* SourceFile */) { + ts.Debug.assert(!!(node.flags & 1024 /* Default */) || node.kind === 227 /* ExportAssignment */); + // only allow export default at a source file level + if (modulekind === 1 /* CommonJS */ || modulekind === 2 /* AMD */ || modulekind === 3 /* UMD */) { + if (!currentSourceFile.symbol.exports["___esModule"]) { + if (languageVersion === 1 /* ES5 */) { + // default value of configurable, enumerable, writable are `false`. + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else if (languageVersion === 0 /* ES3 */) { + write("exports.__esModule = true;"); + writeLine(); + } + } + } + } + } + function emitExportMemberAssignment(node) { + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + // emit call to exporter only for top level nodes + if (modulekind === 4 /* System */ && node.parent === currentSourceFile) { + // emit export default as + // export("default", ) + write(exportFunctionForFile + "(\""); + if (node.flags & 1024 /* Default */) { + write("default"); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + write("\", "); + emitDeclarationName(node); + write(")"); + } + else { + if (node.flags & 1024 /* Default */) { + emitEs6ExportDefaultCompat(node); + if (languageVersion === 0 /* ES3 */) { + write("exports[\"default\"]"); + } + else { + write("exports.default"); + } + } + else { + emitModuleMemberName(node); + } + write(" = "); + emitDeclarationName(node); + } + emitEnd(node); + write(";"); + } + } + function emitExportMemberAssignments(name) { + if (modulekind === 4 /* System */) { + return; + } + if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { + var specifier = _b[_a]; + writeLine(); + emitStart(specifier.name); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + emitEnd(specifier.name); + write(" = "); + emitExpressionIdentifier(name); + write(";"); + } + } + } + function emitExportSpecifierInSystemModule(specifier) { + ts.Debug.assert(modulekind === 4 /* System */); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } + writeLine(); + emitStart(specifier.name); + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write("\", "); + emitExpressionIdentifier(specifier.propertyName || specifier.name); + write(")"); + emitEnd(specifier.name); + write(";"); + } + /** + * Emit an assignment to a given identifier, 'name', with a given expression, 'value'. + * @param name an identifier as a left-hand-side operand of the assignment + * @param value an expression as a right-hand-side operand of the assignment + * @param shouldEmitCommaBeforeAssignment a boolean indicating whether to prefix an assignment with comma + */ + function emitAssignment(name, value, shouldEmitCommaBeforeAssignment) { + if (shouldEmitCommaBeforeAssignment) { + write(", "); + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(name); + write("\", "); + } + var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 211 /* VariableDeclaration */ || name.parent.kind === 163 /* BindingElement */); + if (isVariableDeclarationOrBindingElement) { + emitModuleMemberName(name.parent); + } + else { + emit(name); + } + write(" = "); + emit(value); + if (exportChanged) { + write(")"); + } + } + /** + * Create temporary variable, emit an assignment of the variable the given expression + * @param expression an expression to assign to the newly created temporary variable + * @param canDefineTempVariablesInPlace a boolean indicating whether you can define the temporary variable at an assignment location + * @param shouldEmitCommaBeforeAssignment a boolean indicating whether an assignment should prefix with comma + */ + function emitTempVariableAssignment(expression, canDefineTempVariablesInPlace, shouldEmitCommaBeforeAssignment) { + var identifier = createTempVariable(0 /* Auto */); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expression, shouldEmitCommaBeforeAssignment); + return identifier; + } + function emitDestructuring(root, isAssignmentExpressionStatement, value) { + var emitCount = 0; + // An exported declaration is actually emitted as an assignment (to a property on the module object), so + // temporary variables in an exported declaration need to have real declarations elsewhere + // Also temporary variables should be explicitly allocated for source level declarations when module target is system + // because actual variable declarations are hoisted + var canDefineTempVariablesInPlace = false; + if (root.kind === 211 /* VariableDeclaration */) { + var isExported = ts.getCombinedNodeFlags(root) & 1 /* Export */; + var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); + canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; + } + else if (root.kind === 138 /* Parameter */) { + canDefineTempVariablesInPlace = true; + } + if (root.kind === 181 /* BinaryExpression */) { + emitAssignmentExpression(root); + } + else { + ts.Debug.assert(!isAssignmentExpressionStatement); + emitBindingElement(root, value); + } + /** + * Ensures that there exists a declared identifier whose value holds the given expression. + * This function is useful to ensure that the expression's value can be read from in subsequent expressions. + * Unless 'reuseIdentifierExpressions' is false, 'expr' will be returned if it is just an identifier. + * + * @param expr the expression whose value needs to be bound. + * @param reuseIdentifierExpressions true if identifier expressions can simply be returned; + * false if it is necessary to always emit an identifier. + */ + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 69 /* Identifier */ && reuseIdentifierExpressions) { + return expr; + } + var identifier = emitTempVariableAssignment(expr, canDefineTempVariablesInPlace, emitCount > 0); + emitCount++; + return identifier; + } + function createDefaultValueCheck(value, defaultValue) { + // The value expression will be evaluated twice, so for anything but a simple identifier + // we need to generate a temporary variable + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + // Return the expression 'value === void 0 ? defaultValue : value' + var equals = ts.createSynthesizedNode(181 /* BinaryExpression */); + equals.left = value; + equals.operatorToken = ts.createSynthesizedNode(32 /* EqualsEqualsEqualsToken */); + equals.right = createVoidZero(); + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(182 /* ConditionalExpression */); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(53 /* QuestionToken */); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(54 /* ColonToken */); + cond.whenFalse = whenFalse; + return cond; + } + function createNumericLiteral(value) { + var node = ts.createSynthesizedNode(8 /* NumericLiteral */); + node.text = "" + value; + return node; + } + function createPropertyAccessForDestructuringProperty(object, propName) { + // We create a synthetic copy of the identifier in order to avoid the rewriting that might + // otherwise occur when the identifier is emitted. + var syntheticName = ts.createSynthesizedNode(propName.kind); + syntheticName.text = propName.text; + if (syntheticName.kind !== 69 /* Identifier */) { + return createElementAccessExpression(object, syntheticName); + } + return createPropertyAccessExpression(object, syntheticName); + } + function createSliceCall(value, sliceIndex) { + var call = ts.createSynthesizedNode(168 /* CallExpression */); + var sliceIdentifier = ts.createSynthesizedNode(69 /* Identifier */); + sliceIdentifier.text = "slice"; + call.expression = createPropertyAccessExpression(value, sliceIdentifier); + call.arguments = ts.createSynthesizedNodeArray(); + call.arguments[0] = createNumericLiteral(sliceIndex); + return call; + } + function emitObjectLiteralAssignment(target, value) { + var properties = target.properties; + if (properties.length !== 1) { + // For anything but a single element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + } + for (var _a = 0; _a < properties.length; _a++) { + var p = properties[_a]; + if (p.kind === 245 /* PropertyAssignment */ || p.kind === 246 /* ShorthandPropertyAssignment */) { + var propName = p.name; + var target_1 = p.kind === 246 /* ShorthandPropertyAssignment */ ? p : p.initializer || propName; + emitDestructuringAssignment(target_1, createPropertyAccessForDestructuringProperty(value, propName)); + } + } + } + function emitArrayLiteralAssignment(target, value) { + var elements = target.elements; + if (elements.length !== 1) { + // For anything but a single element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 187 /* OmittedExpression */) { + if (e.kind !== 185 /* SpreadElementExpression */) { + emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === elements.length - 1) { + emitDestructuringAssignment(e.expression, createSliceCall(value, i)); + } + } + } + } + function emitDestructuringAssignment(target, value) { + if (target.kind === 246 /* ShorthandPropertyAssignment */) { + if (target.objectAssignmentInitializer) { + value = createDefaultValueCheck(value, target.objectAssignmentInitializer); + } + target = target.name; + } + else if (target.kind === 181 /* BinaryExpression */ && target.operatorToken.kind === 56 /* EqualsToken */) { + value = createDefaultValueCheck(value, target.right); + target = target.left; + } + if (target.kind === 165 /* ObjectLiteralExpression */) { + emitObjectLiteralAssignment(target, value); + } + else if (target.kind === 164 /* ArrayLiteralExpression */) { + emitArrayLiteralAssignment(target, value); + } + else { + emitAssignment(target, value, /*shouldEmitCommaBeforeAssignment*/ emitCount > 0); + emitCount++; + } + } + function emitAssignmentExpression(root) { + var target = root.left; + var value = root.right; + if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { + emit(value); + } + else if (isAssignmentExpressionStatement) { + emitDestructuringAssignment(target, value); + } + else { + if (root.parent.kind !== 172 /* ParenthesizedExpression */) { + write("("); + } + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + emitDestructuringAssignment(target, value); + write(", "); + emit(value); + if (root.parent.kind !== 172 /* ParenthesizedExpression */) { + write(")"); + } + } + } + function emitBindingElement(target, value) { + if (target.initializer) { + // Combine value and initializer + value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; + } + else if (!value) { + // Use 'void 0' in absence of value and initializer + value = createVoidZero(); + } + if (ts.isBindingPattern(target.name)) { + var pattern = target.name; + var elements = pattern.elements; + var numElements = elements.length; + if (numElements !== 1) { + // For anything other than a single-element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. Additionally, if we have zero elements + // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, + // so in that case, we'll intentionally create that temporary. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0); + } + for (var i = 0; i < numElements; i++) { + var element = elements[i]; + if (pattern.kind === 161 /* ObjectBindingPattern */) { + // Rewrite element to a declaration with an initializer that fetches property + var propName = element.propertyName || element.name; + emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); + } + else if (element.kind !== 187 /* OmittedExpression */) { + if (!element.dotDotDotToken) { + // Rewrite element to a declaration that accesses array element at index i + emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === numElements - 1) { + emitBindingElement(element, createSliceCall(value, i)); + } + } + } + } + else { + emitAssignment(target.name, value, /*shouldEmitCommaBeforeAssignment*/ emitCount > 0); + emitCount++; + } + } + } + function emitVariableDeclaration(node) { + if (ts.isBindingPattern(node.name)) { + if (languageVersion < 2 /* ES6 */) { + emitDestructuring(node, /*isAssignmentExpressionStatement*/ false); + } + else { + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + else { + var initializer = node.initializer; + if (!initializer && languageVersion < 2 /* ES6 */) { + // downlevel emit for non-initialized let bindings defined in loops + // for (...) { let x; } + // should be + // for (...) { var = void 0; } + // this is necessary to preserve ES6 semantic in scenarios like + // for (...) { let x; console.log(x); x = 1 } // assignment on one iteration should not affect other iterations + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384 /* BlockScopedBindingInLoop */) && + (getCombinedFlagsForIdentifier(node.name) & 16384 /* Let */); + // NOTE: default initialization should not be added to let bindings in for-in\for-of statements + if (isUninitializedLet && + node.parent.parent.kind !== 200 /* ForInStatement */ && + node.parent.parent.kind !== 201 /* ForOfStatement */) { + initializer = createVoidZero(); + } + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(node.name); + write("\", "); + } + emitModuleMemberName(node); + emitOptional(" = ", initializer); + if (exportChanged) { + write(")"); + } + } + } + function emitExportVariableAssignments(node) { + if (node.kind === 187 /* OmittedExpression */) { + return; + } + var name = node.name; + if (name.kind === 69 /* Identifier */) { + emitExportMemberAssignments(name); + } + else if (ts.isBindingPattern(name)) { + ts.forEach(name.elements, emitExportVariableAssignments); + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 211 /* VariableDeclaration */ && node.parent.kind !== 163 /* BindingElement */)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function isES6ExportedDeclaration(node) { + return !!(node.flags & 1 /* Export */) && + modulekind === 5 /* ES6 */ && + node.parent.kind === 248 /* SourceFile */; + } + function emitVariableStatement(node) { + var startIsEmitted = false; + if (node.flags & 1 /* Export */) { + if (isES6ExportedDeclaration(node)) { + // Exported ES6 module member + write("export "); + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + } + else { + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + if (startIsEmitted) { + emitCommaList(node.declarationList.declarations); + write(";"); + } + else { + var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); + if (atLeastOneItem) { + write(";"); + } + } + if (modulekind !== 5 /* ES6 */ && node.parent === currentSourceFile) { + ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); + } + } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + // If we're not exporting the variables, there's nothing special here. + // Always emit comments for these nodes. + if (!(node.flags & 1 /* Export */)) { + return true; + } + // If we are exporting, but it's a top-level ES6 module exports, + // we'll emit the declaration list verbatim, so emit comments too. + if (isES6ExportedDeclaration(node)) { + return true; + } + // Otherwise, only emit if we have at least one initializer present. + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } + function emitParameter(node) { + if (languageVersion < 2 /* ES6 */) { + if (ts.isBindingPattern(node.name)) { + var name_24 = createTempVariable(0 /* Auto */); + if (!tempParameters) { + tempParameters = []; + } + tempParameters.push(name_24); + emit(name_24); + } + else { + emit(node.name); + } + } + else { + if (node.dotDotDotToken) { + write("..."); + } + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + function emitDefaultValueAssignments(node) { + if (languageVersion < 2 /* ES6 */) { + var tempIndex = 0; + ts.forEach(node.parameters, function (parameter) { + // A rest parameter cannot have a binding pattern or an initializer, + // so let's just ignore it. + if (parameter.dotDotDotToken) { + return; + } + var paramName = parameter.name, initializer = parameter.initializer; + if (ts.isBindingPattern(paramName)) { + // In cases where a binding pattern is simply '[]' or '{}', + // we usually don't want to emit a var declaration; however, in the presence + // of an initializer, we must emit that expression to preserve side effects. + var hasBindingElements = paramName.elements.length > 0; + if (hasBindingElements || initializer) { + writeLine(); + write("var "); + if (hasBindingElements) { + emitDestructuring(parameter, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]); + } + else { + emit(tempParameters[tempIndex]); + write(" = "); + emit(initializer); + } + write(";"); + tempIndex++; + } + } + else if (initializer) { + writeLine(); + emitStart(parameter); + write("if ("); + emitNodeWithoutSourceMap(paramName); + write(" === void 0)"); + emitEnd(parameter); + write(" { "); + emitStart(parameter); + emitNodeWithCommentsAndWithoutSourcemap(paramName); + write(" = "); + emitNodeWithCommentsAndWithoutSourcemap(initializer); + emitEnd(parameter); + write("; }"); + } + }); + } + } + function emitRestParameter(node) { + if (languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node)) { + var restIndex = node.parameters.length - 1; + var restParam = node.parameters[restIndex]; + // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. + if (ts.isBindingPattern(restParam.name)) { + return; + } + var tempName = createTempVariable(268435456 /* _i */).text; + writeLine(); + emitLeadingComments(restParam); + emitStart(restParam); + write("var "); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write(" = [];"); + emitEnd(restParam); + emitTrailingComments(restParam); + writeLine(); + write("for ("); + emitStart(restParam); + write("var " + tempName + " = " + restIndex + ";"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + " < arguments.length;"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + "++"); + emitEnd(restParam); + write(") {"); + increaseIndent(); + writeLine(); + emitStart(restParam); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); + emitEnd(restParam); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitAccessor(node) { + write(node.kind === 145 /* GetAccessor */ ? "get " : "set "); + emit(node.name); + emitSignatureAndBody(node); + } + function shouldEmitAsArrowFunction(node) { + return node.kind === 174 /* ArrowFunction */ && languageVersion >= 2 /* ES6 */; + } + function emitDeclarationName(node) { + if (node.name) { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + else { + write(getGeneratedNameForNode(node)); + } + } + function shouldEmitFunctionName(node) { + if (node.kind === 173 /* FunctionExpression */) { + // Emit name if one is present + return !!node.name; + } + if (node.kind === 213 /* FunctionDeclaration */) { + // Emit name if one is present, or emit generated name in down-level case (for export default case) + return !!node.name || languageVersion < 2 /* ES6 */; + } + } + function emitFunctionDeclaration(node) { + if (ts.nodeIsMissing(node.body)) { + return emitCommentsOnNotEmittedNode(node); + } + // TODO (yuisu) : we should not have special cases to condition emitting comments + // but have one place to fix check for these conditions. + if (node.kind !== 143 /* MethodDeclaration */ && node.kind !== 142 /* MethodSignature */ && + node.parent && node.parent.kind !== 245 /* PropertyAssignment */ && + node.parent.kind !== 168 /* CallExpression */) { + // 1. Methods will emit the comments as part of emitting method declaration + // 2. If the function is a property of object literal, emitting leading-comments + // is done by emitNodeWithoutSourceMap which then call this function. + // In particular, we would like to avoid emit comments twice in following case: + // For example: + // var obj = { + // id: + // /*comment*/ () => void + // } + // 3. If the function is an argument in call expression, emitting of comments will be + // taken care of in emit list of arguments inside of emitCallexpression + emitLeadingComments(node); + } + emitStart(node); + // For targeting below es6, emit functions-like declaration including arrow function using function keyword. + // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead + if (!shouldEmitAsArrowFunction(node)) { + if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024 /* Default */) { + write("default "); + } + } + write("function"); + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } + write(" "); + } + if (shouldEmitFunctionName(node)) { + emitDeclarationName(node); + } + emitSignatureAndBody(node); + if (modulekind !== 5 /* ES6 */ && node.kind === 213 /* FunctionDeclaration */ && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + emitEnd(node); + if (node.kind !== 143 /* MethodDeclaration */ && node.kind !== 142 /* MethodSignature */) { + emitTrailingComments(node); + } + } + function emitCaptureThisForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { + writeLine(); + emitStart(node); + write("var _this = this;"); + emitEnd(node); + } + } + function emitSignatureParameters(node) { + increaseIndent(); + write("("); + if (node) { + var parameters = node.parameters; + var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node) ? 1 : 0; + emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false); + } + write(")"); + decreaseIndent(); + } + function emitSignatureParametersForArrow(node) { + // Check whether the parameter list needs parentheses and preserve no-parenthesis + if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { + emit(node.parameters[0]); + return; + } + emitSignatureParameters(node); + } + function emitAsyncFunctionBodyForES6(node) { + var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); + var isArrowFunction = node.kind === 174 /* ArrowFunction */; + var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096 /* CaptureArguments */) !== 0; + var args; + // An async function is emit as an outer function that calls an inner + // generator function. To preserve lexical bindings, we pass the current + // `this` and `arguments` objects to `__awaiter`. The generator function + // passed to `__awaiter` is executed inside of the callback to the + // promise constructor. + // + // The emit for an async arrow without a lexical `arguments` binding might be: + // + // // input + // let a = async (b) => { await b; } + // + // // output + // let a = (b) => __awaiter(this, void 0, void 0, function* () { + // yield b; + // }); + // + // The emit for an async arrow with a lexical `arguments` binding might be: + // + // // input + // let a = async (b) => { await arguments[0]; } + // + // // output + // let a = (b) => __awaiter(this, arguments, void 0, function* (arguments) { + // yield arguments[0]; + // }); + // + // The emit for an async function expression without a lexical `arguments` binding + // might be: + // + // // input + // let a = async function (b) { + // await b; + // } + // + // // output + // let a = function (b) { + // return __awaiter(this, void 0, void 0, function* () { + // yield b; + // }); + // } + // + // The emit for an async function expression with a lexical `arguments` binding + // might be: + // + // // input + // let a = async function (b) { + // await arguments[0]; + // } + // + // // output + // let a = function (b) { + // return __awaiter(this, arguments, void 0, function* (_arguments) { + // yield _arguments[0]; + // }); + // } + // + // The emit for an async function expression with a lexical `arguments` binding + // and a return type annotation might be: + // + // // input + // let a = async function (b): MyPromise { + // await arguments[0]; + // } + // + // // output + // let a = function (b) { + // return __awaiter(this, arguments, MyPromise, function* (_arguments) { + // yield _arguments[0]; + // }); + // } + // + // If this is not an async arrow, emit the opening brace of the function body + // and the start of the return statement. + if (!isArrowFunction) { + write(" {"); + increaseIndent(); + writeLine(); + write("return"); + } + write(" __awaiter(this"); + if (hasLexicalArguments) { + write(", arguments"); + } + else { + write(", void 0"); + } + if (promiseConstructor) { + write(", "); + emitNodeWithoutSourceMap(promiseConstructor); + } + else { + write(", Promise"); + } + // Emit the call to __awaiter. + if (hasLexicalArguments) { + write(", function* (_arguments)"); + } + else { + write(", function* ()"); + } + // Emit the signature and body for the inner generator function. + emitFunctionBody(node); + write(")"); + // If this is not an async arrow, emit the closing brace of the outer function body. + if (!isArrowFunction) { + write(";"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitFunctionBody(node) { + if (!node.body) { + // There can be no body when there are parse errors. Just emit an empty block + // in that case. + write(" { }"); + } + else { + if (node.body.kind === 192 /* Block */) { + emitBlockFunctionBody(node, node.body); + } + else { + emitExpressionFunctionBody(node, node.body); + } + } + } + function emitSignatureAndBody(node) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + // When targeting ES6, emit arrow function natively in ES6 + if (shouldEmitAsArrowFunction(node)) { + emitSignatureParametersForArrow(node); + write(" =>"); + } + else { + emitSignatureParameters(node); + } + var isAsync = ts.isAsyncFunctionLike(node); + if (isAsync && languageVersion === 2 /* ES6 */) { + emitAsyncFunctionBodyForES6(node); + } + else { + emitFunctionBody(node); + } + if (!isES6ExportedDeclaration(node)) { + emitExportMemberAssignment(node); + } + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + // Returns true if any preamble code was emitted. + function emitFunctionBodyPreamble(node) { + emitCaptureThisForNodeIfNecessary(node); + emitDefaultValueAssignments(node); + emitRestParameter(node); + } + function emitExpressionFunctionBody(node, body) { + if (languageVersion < 2 /* ES6 */ || node.flags & 512 /* Async */) { + emitDownLevelExpressionFunctionBody(node, body); + return; + } + // For es6 and higher we can emit the expression as is. However, in the case + // where the expression might end up looking like a block when emitted, we'll + // also wrap it in parentheses first. For example if you have: a => {} + // then we need to generate: a => ({}) + write(" "); + // Unwrap all type assertions. + var current = body; + while (current.kind === 171 /* TypeAssertionExpression */) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 165 /* ObjectLiteralExpression */); + } + function emitDownLevelExpressionFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + increaseIndent(); + var outPos = writer.getTextPos(); + emitDetachedComments(node.body); + emitFunctionBodyPreamble(node); + var preambleEmitted = writer.getTextPos() !== outPos; + decreaseIndent(); + // If we didn't have to emit any preamble code, then attempt to keep the arrow + // function on one line. + if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { + write(" "); + emitStart(body); + write("return "); + emit(body); + emitEnd(body); + write(";"); + emitTempDeclarations(/*newLine*/ false); + write(" "); + } + else { + increaseIndent(); + writeLine(); + emitLeadingComments(node.body); + write("return "); + emit(body); + write(";"); + emitTrailingComments(node.body); + emitTempDeclarations(/*newLine*/ true); + decreaseIndent(); + writeLine(); + } + emitStart(node.body); + write("}"); + emitEnd(node.body); + scopeEmitEnd(); + } + function emitBlockFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + var initialTextPos = writer.getTextPos(); + increaseIndent(); + emitDetachedComments(body.statements); + // Emit all the directive prologues (like "use strict"). These have to come before + // any other preamble code we write (like parameter initializers). + var startIndex = emitDirectivePrologues(body.statements, /*startWithNewLine*/ true); + emitFunctionBodyPreamble(node); + decreaseIndent(); + var preambleEmitted = writer.getTextPos() !== initialTextPos; + if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { + for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { + var statement = _b[_a]; + write(" "); + emit(statement); + } + emitTempDeclarations(/*newLine*/ false); + write(" "); + emitLeadingCommentsOfPosition(body.statements.end); + } + else { + increaseIndent(); + emitLinesStartingAt(body.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + writeLine(); + emitLeadingCommentsOfPosition(body.statements.end); + decreaseIndent(); + } + emitToken(16 /* CloseBraceToken */, body.statements.end); + scopeEmitEnd(); + } + function findInitialSuperCall(ctor) { + if (ctor.body) { + var statement = ctor.body.statements[0]; + if (statement && statement.kind === 195 /* ExpressionStatement */) { + var expr = statement.expression; + if (expr && expr.kind === 168 /* CallExpression */) { + var func = expr.expression; + if (func && func.kind === 95 /* SuperKeyword */) { + return statement; + } + } + } + } + } + function emitParameterPropertyAssignments(node) { + ts.forEach(node.parameters, function (param) { + if (param.flags & 112 /* AccessibilityModifier */) { + writeLine(); + emitStart(param); + emitStart(param.name); + write("this."); + emitNodeWithoutSourceMap(param.name); + emitEnd(param.name); + write(" = "); + emit(param.name); + write(";"); + emitEnd(param); + } + }); + } + function emitMemberAccessForPropertyName(memberName) { + // This does not emit source map because it is emitted by caller as caller + // is aware how the property name changes to the property access + // eg. public x = 10; becomes this.x and static x = 10 becomes className.x + if (memberName.kind === 9 /* StringLiteral */ || memberName.kind === 8 /* NumericLiteral */) { + write("["); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + write("]"); + } + else if (memberName.kind === 136 /* ComputedPropertyName */) { + emitComputedPropertyName(memberName); + } + else { + write("."); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + } + } + function getInitializedProperties(node, isStatic) { + var properties = []; + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if (member.kind === 141 /* PropertyDeclaration */ && isStatic === ((member.flags & 128 /* Static */) !== 0) && member.initializer) { + properties.push(member); + } + } + return properties; + } + function emitPropertyDeclarations(node, properties) { + for (var _a = 0; _a < properties.length; _a++) { + var property = properties[_a]; + emitPropertyDeclaration(node, property); + } + } + function emitPropertyDeclaration(node, property, receiver, isExpression) { + writeLine(); + emitLeadingComments(property); + emitStart(property); + emitStart(property.name); + if (receiver) { + emit(receiver); + } + else { + if (property.flags & 128 /* Static */) { + emitDeclarationName(node); + } + else { + write("this"); + } + } + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + emit(property.initializer); + if (!isExpression) { + write(";"); + } + emitEnd(property); + emitTrailingComments(property); + } + function emitMemberFunctionsForES5AndLower(node) { + ts.forEach(node.members, function (member) { + if (member.kind === 191 /* SemicolonClassElement */) { + writeLine(); + write(";"); + } + else if (member.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */) { + if (!member.body) { + return emitCommentsOnNotEmittedNode(member); + } + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + emitClassMemberPrefix(node, member); + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emitFunctionDeclaration(member); + emitEnd(member); + write(";"); + emitTrailingComments(member); + } + else if (member.kind === 145 /* GetAccessor */ || member.kind === 146 /* SetAccessor */) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor) { + writeLine(); + emitStart(member); + write("Object.defineProperty("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("});"); + emitEnd(member); + } + } + }); + } + function emitMemberFunctionsForES6AndHigher(node) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if ((member.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */) && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + else if (member.kind === 143 /* MethodDeclaration */ || + member.kind === 145 /* GetAccessor */ || + member.kind === 146 /* SetAccessor */) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + if (member.flags & 128 /* Static */) { + write("static "); + } + if (member.kind === 145 /* GetAccessor */) { + write("get "); + } + else if (member.kind === 146 /* SetAccessor */) { + write("set "); + } + if (member.asteriskToken) { + write("*"); + } + emit(member.name); + emitSignatureAndBody(member); + emitEnd(member); + emitTrailingComments(member); + } + else if (member.kind === 191 /* SemicolonClassElement */) { + writeLine(); + write(";"); + } + } + } + function emitConstructor(node, baseTypeElement) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + emitConstructorWorker(node, baseTypeElement); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function emitConstructorWorker(node, baseTypeElement) { + // Check if we have property assignment inside class declaration. + // If there is property assignment, we need to emit constructor whether users define it or not + // If there is no property assignment, we can omit constructor if users do not define it + var hasInstancePropertyWithInitializer = false; + // Emit the constructor overload pinned comments + ts.forEach(node.members, function (member) { + if (member.kind === 144 /* Constructor */ && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + // Check if there is any non-static property assignment + if (member.kind === 141 /* PropertyDeclaration */ && member.initializer && (member.flags & 128 /* Static */) === 0) { + hasInstancePropertyWithInitializer = true; + } + }); + var ctor = ts.getFirstConstructorWithBody(node); + // For target ES6 and above, if there is no user-defined constructor and there is no property assignment + // do not emit constructor in class declaration. + if (languageVersion >= 2 /* ES6 */ && !ctor && !hasInstancePropertyWithInitializer) { + return; + } + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + if (languageVersion < 2 /* ES6 */) { + write("function "); + emitDeclarationName(node); + emitSignatureParameters(ctor); + } + else { + write("constructor"); + if (ctor) { + emitSignatureParameters(ctor); + } + else { + // Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation. + // If constructor is empty, then, + // If ClassHeritageopt is present, then + // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. + // Else, + // Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition + if (baseTypeElement) { + write("(...args)"); + } + else { + write("()"); + } + } + } + var startIndex = 0; + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + // Emit all the directive prologues (like "use strict"). These have to come before + // any other preamble code we write (like parameter initializers). + startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); + emitDetachedComments(ctor.body.statements); + } + emitCaptureThisForNodeIfNecessary(node); + var superCall; + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeElement) { + superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeElement) { + writeLine(); + emitStart(baseTypeElement); + if (languageVersion < 2 /* ES6 */) { + write("_super.apply(this, arguments);"); + } + else { + write("super(...args);"); + } + emitEnd(baseTypeElement); + } + } + emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ false)); + if (ctor) { + var statements = ctor.body.statements; + if (superCall) { + statements = statements.slice(1); + } + emitLinesStartingAt(statements, startIndex); + } + emitTempDeclarations(/*newLine*/ true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition(ctor.body.statements.end); + } + decreaseIndent(); + emitToken(16 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + } + function emitClassExpression(node) { + return emitClassLikeDeclaration(node); + } + function emitClassDeclaration(node) { + return emitClassLikeDeclaration(node); + } + function emitClassLikeDeclaration(node) { + if (languageVersion < 2 /* ES6 */) { + emitClassLikeDeclarationBelowES6(node); + } + else { + emitClassLikeDeclarationForES6AndHigher(node); + } + if (modulekind !== 5 /* ES6 */ && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + } + function emitClassLikeDeclarationForES6AndHigher(node) { + var thisNodeIsDecorated = ts.nodeIsDecorated(node); + if (node.kind === 214 /* ClassDeclaration */) { + if (thisNodeIsDecorated) { + // To preserve the correct runtime semantics when decorators are applied to the class, + // the emit needs to follow one of the following rules: + // + // * For a local class declaration: + // + // @dec class C { + // } + // + // The emit should be: + // + // let C = class { + // }; + // C = __decorate([dec], C); + // + // * For an exported class declaration: + // + // @dec export class C { + // } + // + // The emit should be: + // + // export let C = class { + // }; + // C = __decorate([dec], C); + // + // * For a default export of a class declaration with a name: + // + // @dec default export class C { + // } + // + // The emit should be: + // + // let C = class { + // } + // C = __decorate([dec], C); + // export default C; + // + // * For a default export of a class declaration without a name: + // + // @dec default export class { + // } + // + // The emit should be: + // + // let _default = class { + // } + // _default = __decorate([dec], _default); + // export default _default; + // + if (isES6ExportedDeclaration(node) && !(node.flags & 1024 /* Default */)) { + write("export "); + } + write("let "); + emitDeclarationName(node); + write(" = "); + } + else if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024 /* Default */) { + write("default "); + } + } + } + // If the class has static properties, and it's a class expression, then we'll need + // to specialize the emit a bit. for a class expression of the form: + // + // class C { static a = 1; static b = 2; ... } + // + // We'll emit: + // + // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // + // This keeps the expression as an expression, while ensuring that the static parts + // of it have been initialized by the time it is used. + var staticProperties = getInitializedProperties(node, /*static:*/ true); + var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 186 /* ClassExpression */; + var tempVariable; + if (isClassExpressionWithStaticProperties) { + tempVariable = createAndRecordTempVariable(0 /* Auto */); + write("("); + increaseIndent(); + emit(tempVariable); + write(" = "); + } + write("class"); + // emit name if + // - node has a name + // - this is default export with static initializers + if ((node.name || (node.flags & 1024 /* Default */ && staticProperties.length > 0)) && !thisNodeIsDecorated) { + write(" "); + emitDeclarationName(node); + } + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write(" extends "); + emit(baseTypeNode.expression); + } + write(" {"); + increaseIndent(); + scopeEmitStart(node); + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES6AndHigher(node); + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. + // For a decorated class, we need to assign its name (if it has one). This is because we emit + // the class as a class expression to avoid the double-binding of the identifier: + // + // let C = class { + // } + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // + if (thisNodeIsDecorated) { + write(";"); + } + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + if (isClassExpressionWithStaticProperties) { + for (var _a = 0; _a < staticProperties.length; _a++) { + var property = staticProperties[_a]; + write(","); + writeLine(); + emitPropertyDeclaration(node, property, /*receiver:*/ tempVariable, /*isExpression:*/ true); + } + write(","); + writeLine(); + emit(tempVariable); + decreaseIndent(); + write(")"); + } + else { + writeLine(); + emitPropertyDeclarations(node, staticProperties); + emitDecoratorsOfClass(node); + } + // If this is an exported class, but not on the top level (i.e. on an internal + // module), export it + if (!isES6ExportedDeclaration(node) && (node.flags & 1 /* Export */)) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } + else if (isES6ExportedDeclaration(node) && (node.flags & 1024 /* Default */) && thisNodeIsDecorated) { + // if this is a top level default export of decorated class, write the export after the declaration. + writeLine(); + write("export default "); + emitDeclarationName(node); + write(";"); + } + } + function emitClassLikeDeclarationBelowES6(node) { + if (node.kind === 214 /* ClassDeclaration */) { + // source file level classes in system modules are hoisted so 'var's for them are already defined + if (!shouldHoistDeclarationInSystemJsModule(node)) { + write("var "); + } + emitDeclarationName(node); + write(" = "); + } + write("(function ("); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write("_super"); + } + write(") {"); + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + computedPropertyNamesToGeneratedNames = undefined; + increaseIndent(); + scopeEmitStart(node); + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("__extends("); + emitDeclarationName(node); + write(", _super);"); + emitEnd(baseTypeNode); + } + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES5AndLower(node); + emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ true)); + writeLine(); + emitDecoratorsOfClass(node); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end, function () { + write("return "); + emitDeclarationName(node); + }); + write(";"); + emitTempDeclarations(/*newLine*/ true); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + emitStart(node); + write(")("); + if (baseTypeNode) { + emit(baseTypeNode.expression); + } + write(")"); + if (node.kind === 214 /* ClassDeclaration */) { + write(";"); + } + emitEnd(node); + if (node.kind === 214 /* ClassDeclaration */) { + emitExportMemberAssignment(node); + } + } + function emitClassMemberPrefix(node, member) { + emitDeclarationName(node); + if (!(member.flags & 128 /* Static */)) { + write(".prototype"); + } + } + function emitDecoratorsOfClass(node) { + emitDecoratorsOfMembers(node, /*staticFlag*/ 0); + emitDecoratorsOfMembers(node, 128 /* Static */); + emitDecoratorsOfConstructor(node); + } + function emitDecoratorsOfConstructor(node) { + var decorators = node.decorators; + var constructor = ts.getFirstConstructorWithBody(node); + var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); + // skip decoration of the constructor if neither it nor its parameters are decorated + if (!decorators && !hasDecoratedParameters) { + return; + } + // Emit the call to __decorate. Given the class: + // + // @dec + // class C { + // } + // + // The emit for the class is: + // + // C = __decorate([dec], C); + // + writeLine(); + emitStart(node); + emitDeclarationName(node); + write(" = __decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(constructor, /*leadingComma*/ argumentsWritten > 0); + emitSerializedTypeMetadata(node, /*leadingComma*/ argumentsWritten >= 0); + decreaseIndent(); + writeLine(); + write("], "); + emitDeclarationName(node); + write(");"); + emitEnd(node); + writeLine(); + } + function emitDecoratorsOfMembers(node, staticFlag) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + // only emit members in the correct group + if ((member.flags & 128 /* Static */) !== staticFlag) { + continue; + } + // skip members that cannot be decorated (such as the constructor) + if (!ts.nodeCanBeDecorated(member)) { + continue; + } + // skip a member if it or any of its parameters are not decorated + if (!ts.nodeOrChildIsDecorated(member)) { + continue; + } + // skip an accessor declaration if it is not the first accessor + var decorators = void 0; + var functionLikeMember = void 0; + if (ts.isAccessor(member)) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member !== accessors.firstAccessor) { + continue; + } + // get the decorators from the first accessor with decorators + decorators = accessors.firstAccessor.decorators; + if (!decorators && accessors.secondAccessor) { + decorators = accessors.secondAccessor.decorators; + } + // we only decorate parameters of the set accessor + functionLikeMember = accessors.setAccessor; + } + else { + decorators = member.decorators; + // we only decorate the parameters here if this is a method + if (member.kind === 143 /* MethodDeclaration */) { + functionLikeMember = member; + } + } + // Emit the call to __decorate. Given the following: + // + // class C { + // @dec method(@dec2 x) {} + // @dec get accessor() {} + // @dec prop; + // } + // + // The emit for a method is: + // + // __decorate([ + // dec, + // __param(0, dec2), + // __metadata("design:type", Function), + // __metadata("design:paramtypes", [Object]), + // __metadata("design:returntype", void 0) + // ], C.prototype, "method", undefined); + // + // The emit for an accessor is: + // + // __decorate([ + // dec + // ], C.prototype, "accessor", undefined); + // + // The emit for a property is: + // + // __decorate([ + // dec + // ], C.prototype, "prop"); + // + writeLine(); + emitStart(member); + write("__decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); + emitSerializedTypeMetadata(member, argumentsWritten > 0); + decreaseIndent(); + writeLine(); + write("], "); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + if (languageVersion > 0 /* ES3 */) { + if (member.kind !== 141 /* PropertyDeclaration */) { + // We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly. + // We have this extra argument here so that we can inject an explicit property descriptor at a later date. + write(", null"); + } + else { + // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it + // should not invoke `Object.getOwnPropertyDescriptor`. + write(", void 0"); + } + } + write(");"); + emitEnd(member); + writeLine(); + } + } + function emitDecoratorsOfParameters(node, leadingComma) { + var argumentsWritten = 0; + if (node) { + var parameterIndex = 0; + for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { + var parameter = _b[_a]; + if (ts.nodeIsDecorated(parameter)) { + var decorators = parameter.decorators; + argumentsWritten += emitList(decorators, 0, decorators.length, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ leadingComma, /*noTrailingNewLine*/ true, function (decorator) { + emitStart(decorator); + write("__param(" + parameterIndex + ", "); + emit(decorator.expression); + write(")"); + emitEnd(decorator); + }); + leadingComma = true; + } + ++parameterIndex; + } + } + return argumentsWritten; + } + function shouldEmitTypeMetadata(node) { + // This method determines whether to emit the "design:type" metadata based on the node's kind. + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // compiler option is set. + switch (node.kind) { + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + return true; + } + return false; + } + function shouldEmitReturnTypeMetadata(node) { + // This method determines whether to emit the "design:returntype" metadata based on the node's kind. + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // compiler option is set. + switch (node.kind) { + case 143 /* MethodDeclaration */: + return true; + } + return false; + } + function shouldEmitParamTypesMetadata(node) { + // This method determines whether to emit the "design:paramtypes" metadata based on the node's kind. + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // compiler option is set. + switch (node.kind) { + case 214 /* ClassDeclaration */: + case 143 /* MethodDeclaration */: + case 146 /* SetAccessor */: + return true; + } + return false; + } + /** Serializes the type of a declaration to an appropriate JS constructor value. Used by the __metadata decorator for a class member. */ + function emitSerializedTypeOfNode(node) { + // serialization of the type of a declaration uses the following rules: + // + // * The serialized type of a ClassDeclaration is "Function" + // * The serialized type of a ParameterDeclaration is the serialized type of its type annotation. + // * The serialized type of a PropertyDeclaration is the serialized type of its type annotation. + // * The serialized type of an AccessorDeclaration is the serialized type of the return type annotation of its getter or parameter type annotation of its setter. + // * The serialized type of any other FunctionLikeDeclaration is "Function". + // * The serialized type of any other node is "void 0". + // + // For rules on serializing type annotations, see `serializeTypeNode`. + switch (node.kind) { + case 214 /* ClassDeclaration */: + write("Function"); + return; + case 141 /* PropertyDeclaration */: + emitSerializedTypeNode(node.type); + return; + case 138 /* Parameter */: + emitSerializedTypeNode(node.type); + return; + case 145 /* GetAccessor */: + emitSerializedTypeNode(node.type); + return; + case 146 /* SetAccessor */: + emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); + return; + } + if (ts.isFunctionLike(node)) { + write("Function"); + return; + } + write("void 0"); + } + function emitSerializedTypeNode(node) { + if (node) { + switch (node.kind) { + case 103 /* VoidKeyword */: + write("void 0"); + return; + case 160 /* ParenthesizedType */: + emitSerializedTypeNode(node.type); + return; + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + write("Function"); + return; + case 156 /* ArrayType */: + case 157 /* TupleType */: + write("Array"); + return; + case 150 /* TypePredicate */: + case 120 /* BooleanKeyword */: + write("Boolean"); + return; + case 130 /* StringKeyword */: + case 9 /* StringLiteral */: + write("String"); + return; + case 128 /* NumberKeyword */: + write("Number"); + return; + case 131 /* SymbolKeyword */: + write("Symbol"); + return; + case 151 /* TypeReference */: + emitSerializedTypeReferenceNode(node); + return; + case 154 /* TypeQuery */: + case 155 /* TypeLiteral */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: + case 117 /* AnyKeyword */: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } + } + write("Object"); + } + /** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */ + function emitSerializedTypeReferenceNode(node) { + var location = node.parent; + while (ts.isDeclaration(location) || ts.isTypeNode(location)) { + location = location.parent; + } + // Clone the type name and parent it to a location outside of the current declaration. + var typeName = ts.cloneEntityName(node.typeName); + typeName.parent = location; + var result = resolver.getTypeReferenceSerializationKind(typeName); + switch (result) { + case ts.TypeReferenceSerializationKind.Unknown: + var temp = createAndRecordTempVariable(0 /* Auto */); + write("(typeof ("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(typeName, /*useFallback*/ true); + write(") === 'function' && "); + emitNodeWithoutSourceMap(temp); + write(") || Object"); + break; + case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: + emitEntityNameAsExpression(typeName, /*useFallback*/ false); + break; + case ts.TypeReferenceSerializationKind.VoidType: + write("void 0"); + break; + case ts.TypeReferenceSerializationKind.BooleanType: + write("Boolean"); + break; + case ts.TypeReferenceSerializationKind.NumberLikeType: + write("Number"); + break; + case ts.TypeReferenceSerializationKind.StringLikeType: + write("String"); + break; + case ts.TypeReferenceSerializationKind.ArrayLikeType: + write("Array"); + break; + case ts.TypeReferenceSerializationKind.ESSymbolType: + if (languageVersion < 2 /* ES6 */) { + write("typeof Symbol === 'function' ? Symbol : Object"); + } + else { + write("Symbol"); + } + break; + case ts.TypeReferenceSerializationKind.TypeWithCallSignature: + write("Function"); + break; + case ts.TypeReferenceSerializationKind.ObjectType: + write("Object"); + break; + } + } + /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ + function emitSerializedParameterTypesOfNode(node) { + // serialization of parameter types uses the following rules: + // + // * If the declaration is a class, the parameters of the first constructor with a body are used. + // * If the declaration is function-like and has a body, the parameters of the function are used. + // + // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. + if (node) { + var valueDeclaration; + if (node.kind === 214 /* ClassDeclaration */) { + valueDeclaration = ts.getFirstConstructorWithBody(node); + } + else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { + valueDeclaration = node; + } + if (valueDeclaration) { + var parameters = valueDeclaration.parameters; + var parameterCount = parameters.length; + if (parameterCount > 0) { + for (var i = 0; i < parameterCount; i++) { + if (i > 0) { + write(", "); + } + if (parameters[i].dotDotDotToken) { + var parameterType = parameters[i].type; + if (parameterType.kind === 156 /* ArrayType */) { + parameterType = parameterType.elementType; + } + else if (parameterType.kind === 151 /* TypeReference */ && parameterType.typeArguments && parameterType.typeArguments.length === 1) { + parameterType = parameterType.typeArguments[0]; + } + else { + parameterType = undefined; + } + emitSerializedTypeNode(parameterType); + } + else { + emitSerializedTypeOfNode(parameters[i]); + } + } + } + } + } + } + /** Serializes the return type of function. Used by the __metadata decorator for a method. */ + function emitSerializedReturnTypeOfNode(node) { + if (node && ts.isFunctionLike(node) && node.type) { + emitSerializedTypeNode(node.type); + return; + } + write("void 0"); + } + function emitSerializedTypeMetadata(node, writeComma) { + // This method emits the serialized type metadata for a decorator target. + // The caller should have already tested whether the node has decorators. + var argumentsWritten = 0; + if (compilerOptions.emitDecoratorMetadata) { + if (shouldEmitTypeMetadata(node)) { + if (writeComma) { + write(", "); + } + writeLine(); + write("__metadata('design:type', "); + emitSerializedTypeOfNode(node); + write(")"); + argumentsWritten++; + } + if (shouldEmitParamTypesMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:paramtypes', ["); + emitSerializedParameterTypesOfNode(node); + write("])"); + argumentsWritten++; + } + if (shouldEmitReturnTypeMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:returntype', "); + emitSerializedReturnTypeOfNode(node); + write(")"); + argumentsWritten++; + } + } + return argumentsWritten; + } + function emitInterfaceDeclaration(node) { + emitCommentsOnNotEmittedNode(node); + } + function shouldEmitEnumDeclaration(node) { + var isConstEnum = ts.isConst(node); + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; + } + function emitEnumDeclaration(node) { + // const enums are completely erased during compilation. + if (!shouldEmitEnumDeclaration(node)) { + return; + } + if (!shouldHoistDeclarationInSystemJsModule(node)) { + // do not emit var if variable was already hoisted + if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + emitEnd(node); + write(";"); + } + } + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") {"); + increaseIndent(); + scopeEmitStart(node); + emitLines(node.members); + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + write(")("); + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */ && !shouldHoistDeclarationInSystemJsModule(node)) { + // do not emit var if variable was already hoisted + writeLine(); + emitStart(node); + write("var "); + emit(node.name); + write(" = "); + emitModuleMemberName(node); + emitEnd(node); + write(";"); + } + if (modulekind !== 5 /* ES6 */ && node.parent === currentSourceFile) { + if (modulekind === 4 /* System */ && (node.flags & 1 /* Export */)) { + // write the call to exporter for enum + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + function emitEnumMember(node) { + var enumParent = node.parent; + emitStart(node); + write(getGeneratedNameForNode(enumParent)); + write("["); + write(getGeneratedNameForNode(enumParent)); + write("["); + emitExpressionForPropertyName(node.name); + write("] = "); + writeEnumMemberDeclarationValue(node); + write("] = "); + emitExpressionForPropertyName(node.name); + emitEnd(node); + write(";"); + } + function writeEnumMemberDeclarationValue(member) { + var value = resolver.getConstantValue(member); + if (value !== undefined) { + write(value.toString()); + return; + } + else if (member.initializer) { + emit(member.initializer); + } + else { + write("undefined"); + } + } + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { + if (moduleDeclaration.body.kind === 218 /* ModuleDeclaration */) { + var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + function shouldEmitModuleDeclaration(node) { + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); + } + function isModuleMergedWithES6Class(node) { + return languageVersion === 2 /* ES6 */ && !!(resolver.getNodeCheckFlags(node) & 32768 /* LexicalModuleMergesWithClass */); + } + function emitModuleDeclaration(node) { + // Emit only if this module is non-ambient. + var shouldEmit = shouldEmitModuleDeclaration(node); + if (!shouldEmit) { + return emitCommentsOnNotEmittedNode(node); + } + var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); + var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); + if (emitVarForModule) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); + } + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") "); + if (node.body.kind === 219 /* ModuleBlock */) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + tempFlags = 0; + tempVariables = undefined; + emit(node.body); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + } + else { + write("{"); + increaseIndent(); + scopeEmitStart(node); + emitCaptureThisForNodeIfNecessary(node); + writeLine(); + emit(node.body); + decreaseIndent(); + writeLine(); + var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; + emitToken(16 /* CloseBraceToken */, moduleBlock.statements.end); + scopeEmitEnd(); + } + write(")("); + // write moduleDecl = containingModule.m only if it is not exported es6 module member + if ((node.flags & 1 /* Export */) && !isES6ExportedDeclaration(node)) { + emit(node.name); + write(" = "); + } + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.name.kind === 69 /* Identifier */ && node.parent === currentSourceFile) { + if (modulekind === 4 /* System */ && (node.flags & 1 /* Export */)) { + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + /* + * Some bundlers (SystemJS builder) sometimes want to rename dependencies. + * Here we check if alternative name was provided for a given moduleName and return it if possible. + */ + function tryRenameExternalModule(moduleName) { + if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { + return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; + } + return undefined; + } + function emitRequire(moduleName) { + if (moduleName.kind === 9 /* StringLiteral */) { + write("require("); + var text = tryRenameExternalModule(moduleName); + if (text) { + write(text); + } + else { + emitStart(moduleName); + emitLiteral(moduleName); + emitEnd(moduleName); + } + emitToken(18 /* CloseParenToken */, moduleName.end); + } + else { + write("require()"); + } + } + function getNamespaceDeclarationNode(node) { + if (node.kind === 221 /* ImportEqualsDeclaration */) { + return node; + } + var importClause = node.importClause; + if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 224 /* NamespaceImport */) { + return importClause.namedBindings; + } + } + function isDefaultImport(node) { + return node.kind === 222 /* ImportDeclaration */ && node.importClause && !!node.importClause.name; + } + function emitExportImportAssignments(node) { + if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + emitExportMemberAssignments(node.name); + } + ts.forEachChild(node, emitExportImportAssignments); + } + function emitImportDeclaration(node) { + if (modulekind !== 5 /* ES6 */) { + return emitExternalImportDeclaration(node); + } + // ES6 import + if (node.importClause) { + var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); + var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, /* checkChildren */ true); + if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { + write("import "); + emitStart(node.importClause); + if (shouldEmitDefaultBindings) { + emit(node.importClause.name); + if (shouldEmitNamedBindings) { + write(", "); + } + } + if (shouldEmitNamedBindings) { + emitLeadingComments(node.importClause.namedBindings); + emitStart(node.importClause.namedBindings); + if (node.importClause.namedBindings.kind === 224 /* NamespaceImport */) { + write("* as "); + emit(node.importClause.namedBindings.name); + } + else { + write("{ "); + emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); + write(" }"); + } + emitEnd(node.importClause.namedBindings); + emitTrailingComments(node.importClause.namedBindings); + } + emitEnd(node.importClause); + write(" from "); + emit(node.moduleSpecifier); + write(";"); + } + } + else { + write("import "); + emit(node.moduleSpecifier); + write(";"); + } + } + function emitExternalImportDeclaration(node) { + if (ts.contains(externalImports, node)) { + var isExportedImport = node.kind === 221 /* ImportEqualsDeclaration */ && (node.flags & 1 /* Export */) !== 0; + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (modulekind !== 2 /* AMD */) { + emitLeadingComments(node); + emitStart(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + // import x = require("foo") + // import * as x from "foo" + if (!isExportedImport) + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + } + else { + // import "foo" + // import x from "foo" + // import { x, y } from "foo" + // import d, * as x from "foo" + // import d, { x, y } from "foo" + var isNakedImport = 222 /* ImportDeclaration */ && !node.importClause; + if (!isNakedImport) { + write("var "); + write(getGeneratedNameForNode(node)); + write(" = "); + } + } + emitRequire(ts.getExternalModuleName(node)); + if (namespaceDeclaration && isDefaultImport(node)) { + // import d, * as x from "foo" + write(", "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + else { + if (isExportedImport) { + emitModuleMemberName(namespaceDeclaration); + write(" = "); + emit(namespaceDeclaration.name); + write(";"); + } + else if (namespaceDeclaration && isDefaultImport(node)) { + // import d, * as x from "foo" + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + write(";"); + } + emitExportImportAssignments(node); + } + } + } + function emitImportEqualsDeclaration(node) { + if (ts.isExternalModuleImportEqualsDeclaration(node)) { + emitExternalImportDeclaration(node); + return; + } + // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when + // - current file is not external module + // - import declaration is top level and target is value imported by entity name + if (resolver.isReferencedAliasDeclaration(node) || + (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { + emitLeadingComments(node); + emitStart(node); + // variable declaration for import-equals declaration can be hoisted in system modules + // in this case 'var' should be omitted and emit should contain only initialization + var variableDeclarationIsHoisted = shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ true); + // is it top level export import v = a.b.c in system module? + // if yes - it needs to be rewritten as exporter('v', v = a.b.c) + var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ true); + if (!variableDeclarationIsHoisted) { + ts.Debug.assert(!isExported); + if (isES6ExportedDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & 1 /* Export */)) { + write("var "); + } + } + if (isExported) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.name); + write("\", "); + } + emitModuleMemberName(node); + write(" = "); + emit(node.moduleReference); + if (isExported) { + write(")"); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + } + function emitExportDeclaration(node) { + ts.Debug.assert(modulekind !== 4 /* System */); + if (modulekind !== 5 /* ES6 */) { + if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { + emitStart(node); + var generatedName = getGeneratedNameForNode(node); + if (node.exportClause) { + // export { x, y, ... } from "foo" + if (modulekind !== 2 /* AMD */) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(ts.getExternalModuleName(node)); + write(";"); + } + for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { + var specifier = _b[_a]; + if (resolver.isValueAliasDeclaration(specifier)) { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + } + } + } + else { + // export * from "foo" + writeLine(); + write("__export("); + if (modulekind !== 2 /* AMD */) { + emitRequire(ts.getExternalModuleName(node)); + } + else { + write(generatedName); + } + write(");"); + } + emitEnd(node); + } + } + else { + if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { + write("export "); + if (node.exportClause) { + // export { x, y, ... } + write("{ "); + emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + emit(node.moduleSpecifier); + } + write(";"); + } + } + } + function emitExportOrImportSpecifierList(specifiers, shouldEmit) { + ts.Debug.assert(modulekind === 5 /* ES6 */); + var needsComma = false; + for (var _a = 0; _a < specifiers.length; _a++) { + var specifier = specifiers[_a]; + if (shouldEmit(specifier)) { + if (needsComma) { + write(", "); + } + if (specifier.propertyName) { + emit(specifier.propertyName); + write(" as "); + } + emit(specifier.name); + needsComma = true; + } + } + } + function emitExportAssignment(node) { + if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { + if (modulekind === 5 /* ES6 */) { + writeLine(); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== 213 /* FunctionDeclaration */ && + expression.kind !== 214 /* ClassDeclaration */) { + write(";"); + } + emitEnd(node); + } + else { + writeLine(); + emitStart(node); + if (modulekind === 4 /* System */) { + write(exportFunctionForFile + "(\"default\","); + emit(node.expression); + write(")"); + } + else { + emitEs6ExportDefaultCompat(node); + emitContainingModuleName(node); + if (languageVersion === 0 /* ES3 */) { + write("[\"default\"] = "); + } + else { + write(".default = "); + } + emit(node.expression); + } + write(";"); + emitEnd(node); + } + } + } + function collectExternalModuleInfo(sourceFile) { + externalImports = []; + exportSpecifiers = {}; + exportEquals = undefined; + hasExportStars = false; + for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { + var node = _b[_a]; + switch (node.kind) { + case 222 /* ImportDeclaration */: + if (!node.importClause || + resolver.isReferencedAliasDeclaration(node.importClause, /*checkChildren*/ true)) { + // import "mod" + // import x from "mod" where x is referenced + // import * as x from "mod" where x is referenced + // import { x, y } from "mod" where at least one import is referenced + externalImports.push(node); + } + break; + case 221 /* ImportEqualsDeclaration */: + if (node.moduleReference.kind === 232 /* ExternalModuleReference */ && resolver.isReferencedAliasDeclaration(node)) { + // import x = require("mod") where x is referenced + externalImports.push(node); + } + break; + case 228 /* ExportDeclaration */: + if (node.moduleSpecifier) { + if (!node.exportClause) { + // export * from "mod" + externalImports.push(node); + hasExportStars = true; + } + else if (resolver.isValueAliasDeclaration(node)) { + // export { x, y } from "mod" where at least one export is a value symbol + externalImports.push(node); + } + } + else { + // export { x, y } + for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { + var specifier = _d[_c]; + var name_25 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_25] || (exportSpecifiers[name_25] = [])).push(specifier); + } + } + break; + case 227 /* ExportAssignment */: + if (node.isExportEquals && !exportEquals) { + // export = x + exportEquals = node; + } + break; + } + } + } + function emitExportStarHelper() { + if (hasExportStars) { + writeLine(); + write("function __export(m) {"); + increaseIndent(); + writeLine(); + write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function getLocalNameForExternalImport(node) { + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); + } + if (node.kind === 222 /* ImportDeclaration */ && node.importClause) { + return getGeneratedNameForNode(node); + } + if (node.kind === 228 /* ExportDeclaration */ && node.moduleSpecifier) { + return getGeneratedNameForNode(node); + } + } + function getExternalModuleNameText(importNode) { + var moduleName = ts.getExternalModuleName(importNode); + if (moduleName.kind === 9 /* StringLiteral */) { + return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); + } + return undefined; + } + function emitVariableDeclarationsForImports() { + if (externalImports.length === 0) { + return; + } + writeLine(); + var started = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var importNode = externalImports[_a]; + // do not create variable declaration for exports and imports that lack import clause + var skipNode = importNode.kind === 228 /* ExportDeclaration */ || + (importNode.kind === 222 /* ImportDeclaration */ && !importNode.importClause); + if (skipNode) { + continue; + } + if (!started) { + write("var "); + started = true; + } + else { + write(", "); + } + write(getLocalNameForExternalImport(importNode)); + } + if (started) { + write(";"); + } + } + function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { + // when resolving exports local exported entries/indirect exported entries in the module + // should always win over entries with similar names that were added via star exports + // to support this we store names of local/indirect exported entries in a set. + // this set is used to filter names brought by star expors. + if (!hasExportStars) { + // local names set is needed only in presence of star exports + return undefined; + } + // local names set should only be added if we have anything exported + if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { + // no exported declarations (export var ...) or export specifiers (export {x}) + // check if we have any non star export declarations. + var hasExportDeclarationWithExportClause = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var externalImport = externalImports[_a]; + if (externalImport.kind === 228 /* ExportDeclaration */ && externalImport.exportClause) { + hasExportDeclarationWithExportClause = true; + break; + } + } + if (!hasExportDeclarationWithExportClause) { + // we still need to emit exportStar helper + return emitExportStarFunction(/*localNames*/ undefined); + } + } + var exportedNamesStorageRef = makeUniqueName("exportedNames"); + writeLine(); + write("var " + exportedNamesStorageRef + " = {"); + increaseIndent(); + var started = false; + if (exportedDeclarations) { + for (var i = 0; i < exportedDeclarations.length; ++i) { + // write name of exported declaration, i.e 'export var x...' + writeExportedName(exportedDeclarations[i]); + } + } + if (exportSpecifiers) { + for (var n in exportSpecifiers) { + for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { + var specifier = _c[_b]; + // write name of export specified, i.e. 'export {x}' + writeExportedName(specifier.name); + } + } + } + for (var _d = 0; _d < externalImports.length; _d++) { + var externalImport = externalImports[_d]; + if (externalImport.kind !== 228 /* ExportDeclaration */) { + continue; + } + var exportDecl = externalImport; + if (!exportDecl.exportClause) { + // export * from ... + continue; + } + for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { + var element = _f[_e]; + // write name of indirectly exported entry, i.e. 'export {x} from ...' + writeExportedName(element.name || element.propertyName); + } + } + decreaseIndent(); + writeLine(); + write("};"); + return emitExportStarFunction(exportedNamesStorageRef); + function emitExportStarFunction(localNames) { + var exportStarFunction = makeUniqueName("exportStar"); + writeLine(); + // define an export star helper function + write("function " + exportStarFunction + "(m) {"); + increaseIndent(); + writeLine(); + write("var exports = {};"); + writeLine(); + write("for(var n in m) {"); + increaseIndent(); + writeLine(); + write("if (n !== \"default\""); + if (localNames) { + write("&& !" + localNames + ".hasOwnProperty(n)"); + } + write(") exports[n] = m[n];"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write(exportFunctionForFile + "(exports);"); + decreaseIndent(); + writeLine(); + write("}"); + return exportStarFunction; + } + function writeExportedName(node) { + // do not record default exports + // they are local to module and never overwritten (explicitly skipped) by star export + if (node.kind !== 69 /* Identifier */ && node.flags & 1024 /* Default */) { + return; + } + if (started) { + write(","); + } + else { + started = true; + } + writeLine(); + write("'"); + if (node.kind === 69 /* Identifier */) { + emitNodeWithCommentsAndWithoutSourcemap(node); + } + else { + emitDeclarationName(node); + } + write("': true"); + } + } + function processTopLevelVariableAndFunctionDeclarations(node) { + // per ES6 spec: + // 15.2.1.16.4 ModuleDeclarationInstantiation() Concrete Method + // - var declarations are initialized to undefined - 14.a.ii + // - function/generator declarations are instantiated - 16.a.iv + // this means that after module is instantiated but before its evaluation + // exported functions are already accessible at import sites + // in theory we should hoist only exported functions and its dependencies + // in practice to simplify things we'll hoist all source level functions and variable declaration + // including variables declarations for module and class declarations + var hoistedVars; + var hoistedFunctionDeclarations; + var exportedDeclarations; + visit(node); + if (hoistedVars) { + writeLine(); + write("var "); + var seen = {}; + for (var i = 0; i < hoistedVars.length; ++i) { + var local = hoistedVars[i]; + var name_26 = local.kind === 69 /* Identifier */ + ? local + : local.name; + if (name_26) { + // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables + var text = ts.unescapeIdentifier(name_26.text); + if (ts.hasProperty(seen, text)) { + continue; + } + else { + seen[text] = text; + } + } + if (i !== 0) { + write(", "); + } + if (local.kind === 214 /* ClassDeclaration */ || local.kind === 218 /* ModuleDeclaration */ || local.kind === 217 /* EnumDeclaration */) { + emitDeclarationName(local); + } + else { + emit(local); + } + var flags = ts.getCombinedNodeFlags(local.kind === 69 /* Identifier */ ? local.parent : local); + if (flags & 1 /* Export */) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(local); + } + } + write(";"); + } + if (hoistedFunctionDeclarations) { + for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { + var f = hoistedFunctionDeclarations[_a]; + writeLine(); + emit(f); + if (f.flags & 1 /* Export */) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(f); + } + } + } + return exportedDeclarations; + function visit(node) { + if (node.flags & 2 /* Ambient */) { + return; + } + if (node.kind === 213 /* FunctionDeclaration */) { + if (!hoistedFunctionDeclarations) { + hoistedFunctionDeclarations = []; + } + hoistedFunctionDeclarations.push(node); + return; + } + if (node.kind === 214 /* ClassDeclaration */) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + return; + } + if (node.kind === 217 /* EnumDeclaration */) { + if (shouldEmitEnumDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 218 /* ModuleDeclaration */) { + if (shouldEmitModuleDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 211 /* VariableDeclaration */ || node.kind === 163 /* BindingElement */) { + if (shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ false)) { + var name_27 = node.name; + if (name_27.kind === 69 /* Identifier */) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(name_27); + } + else { + ts.forEachChild(name_27, visit); + } + } + return; + } + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node.name); + return; + } + if (ts.isBindingPattern(node)) { + ts.forEach(node.elements, visit); + return; + } + if (!ts.isDeclaration(node)) { + ts.forEachChild(node, visit); + } + } + } + function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { + if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { + return false; + } + // hoist variable if + // - it is not block scoped + // - it is top level block scoped + // if block scoped variables are nested in some another block then + // no other functions can use them except ones that are defined at least in the same block + return (ts.getCombinedNodeFlags(node) & 49152 /* BlockScoped */) === 0 || + ts.getEnclosingBlockScopeContainer(node).kind === 248 /* SourceFile */; + } + function isCurrentFileSystemExternalModule() { + return modulekind === 4 /* System */ && ts.isExternalModule(currentSourceFile); + } + function emitSystemModuleBody(node, dependencyGroups, startIndex) { + // shape of the body in system modules: + // function (exports) { + // + // + // + // return { + // setters: [ + // + // ], + // execute: function() { + // + // } + // } + // + // } + // I.e: + // import {x} from 'file1' + // var y = 1; + // export function foo() { return y + x(); } + // console.log(y); + // will be transformed to + // function(exports) { + // var file1; // local alias + // var y; + // function foo() { return y + file1.x(); } + // exports("foo", foo); + // return { + // setters: [ + // function(v) { file1 = v } + // ], + // execute(): function() { + // y = 1; + // console.log(y); + // } + // }; + // } + emitVariableDeclarationsForImports(); + writeLine(); + var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); + var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); + writeLine(); + write("return {"); + increaseIndent(); + writeLine(); + emitSetters(exportStarFunction, dependencyGroups); + writeLine(); + emitExecute(node, startIndex); + decreaseIndent(); + writeLine(); + write("}"); // return + emitTempDeclarations(/*newLine*/ true); + } + function emitSetters(exportStarFunction, dependencyGroups) { + write("setters:["); + for (var i = 0; i < dependencyGroups.length; ++i) { + if (i !== 0) { + write(","); + } + writeLine(); + increaseIndent(); + var group = dependencyGroups[i]; + // derive a unique name for parameter from the first named entry in the group + var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); + write("function (" + parameterName + ") {"); + increaseIndent(); + for (var _a = 0; _a < group.length; _a++) { + var entry = group[_a]; + var importVariableName = getLocalNameForExternalImport(entry) || ""; + switch (entry.kind) { + case 222 /* ImportDeclaration */: + if (!entry.importClause) { + // 'import "..."' case + // module is imported only for side-effects, no emit required + break; + } + // fall-through + case 221 /* ImportEqualsDeclaration */: + ts.Debug.assert(importVariableName !== ""); + writeLine(); + // save import into the local + write(importVariableName + " = " + parameterName + ";"); + writeLine(); + break; + case 228 /* ExportDeclaration */: + ts.Debug.assert(importVariableName !== ""); + if (entry.exportClause) { + // export {a, b as c} from 'foo' + // emit as: + // exports_({ + // "a": _["a"], + // "c": _["b"] + // }); + writeLine(); + write(exportFunctionForFile + "({"); + writeLine(); + increaseIndent(); + for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { + if (i_2 !== 0) { + write(","); + writeLine(); + } + var e = entry.exportClause.elements[i_2]; + write("\""); + emitNodeWithCommentsAndWithoutSourcemap(e.name); + write("\": " + parameterName + "[\""); + emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); + write("\"]"); + } + decreaseIndent(); + writeLine(); + write("});"); + } + else { + writeLine(); + // export * from 'foo' + // emit as: + // exportStar(_foo); + write(exportStarFunction + "(" + parameterName + ");"); + } + writeLine(); + break; + } + } + decreaseIndent(); + write("}"); + decreaseIndent(); + } + write("],"); + } + function emitExecute(node, startIndex) { + write("execute: function() {"); + increaseIndent(); + writeLine(); + for (var i = startIndex; i < node.statements.length; ++i) { + var statement = node.statements[i]; + switch (statement.kind) { + // - function declarations are not emitted because they were already hoisted + // - import declarations are not emitted since they are already handled in setters + // - export declarations with module specifiers are not emitted since they were already written in setters + // - export declarations without module specifiers are emitted preserving the order + case 213 /* FunctionDeclaration */: + case 222 /* ImportDeclaration */: + continue; + case 228 /* ExportDeclaration */: + if (!statement.moduleSpecifier) { + for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { + var element = _b[_a]; + // write call to exporter function for every export specifier in exports list + emitExportSpecifierInSystemModule(element); + } + } + continue; + case 221 /* ImportEqualsDeclaration */: + if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { + // - import equals declarations that import external modules are not emitted + continue; + } + // fall-though for import declarations that import internal modules + default: + writeLine(); + emit(statement); + } + } + decreaseIndent(); + writeLine(); + write("}"); // execute + } + function emitSystemModule(node) { + collectExternalModuleInfo(node); + // System modules has the following shape + // System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */}) + // 'exports' here is a function 'exports(name: string, value: T): T' that is used to publish exported values. + // 'exports' returns its 'value' argument so in most cases expressions + // that mutate exported values can be rewritten as: + // expr -> exports('name', expr). + // The only exception in this rule is postfix unary operators, + // see comment to 'emitPostfixUnaryExpression' for more details + ts.Debug.assert(!exportFunctionForFile); + // make sure that name of 'exports' function does not conflict with existing identifiers + exportFunctionForFile = makeUniqueName("exports"); + writeLine(); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); + var groupIndices = {}; + var dependencyGroups = []; + for (var i = 0; i < externalImports.length; ++i) { + var text = getExternalModuleNameText(externalImports[i]); + if (ts.hasProperty(groupIndices, text)) { + // deduplicate/group entries in dependency list by the dependency name + var groupIndex = groupIndices[text]; + dependencyGroups[groupIndex].push(externalImports[i]); + continue; + } + else { + groupIndices[text] = dependencyGroups.length; + dependencyGroups.push([externalImports[i]]); + } + if (i !== 0) { + write(", "); + } + write(text); + } + write("], function(" + exportFunctionForFile + ") {"); + writeLine(); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitSystemModuleBody(node, dependencyGroups, startIndex); + decreaseIndent(); + writeLine(); + write("});"); + } + function getAMDDependencyNames(node, includeNonAmdDependencies) { + // names of modules with corresponding parameter in the factory function + var aliasedModuleNames = []; + // names of modules with no corresponding parameters in factory function + var unaliasedModuleNames = []; + var importAliasNames = []; // names of the parameters in the factory function; these + // parameters need to match the indexes of the corresponding + // module names in aliasedModuleNames. + // Fill in amd-dependency tags + for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { + var amdDependency = _b[_a]; + if (amdDependency.name) { + aliasedModuleNames.push("\"" + amdDependency.path + "\""); + importAliasNames.push(amdDependency.name); + } + else { + unaliasedModuleNames.push("\"" + amdDependency.path + "\""); + } + } + for (var _c = 0; _c < externalImports.length; _c++) { + var importNode = externalImports[_c]; + // Find the name of the external module + var externalModuleName = getExternalModuleNameText(importNode); + // Find the name of the module alias, if there is one + var importAliasName = getLocalNameForExternalImport(importNode); + if (includeNonAmdDependencies && importAliasName) { + aliasedModuleNames.push(externalModuleName); + importAliasNames.push(importAliasName); + } + else { + unaliasedModuleNames.push(externalModuleName); + } + } + return { aliasedModuleNames: aliasedModuleNames, unaliasedModuleNames: unaliasedModuleNames, importAliasNames: importAliasNames }; + } + function emitAMDDependencies(node, includeNonAmdDependencies) { + // An AMD define function has the following shape: + // define(id?, dependencies?, factory); + // + // This has the shape of + // define(name, ["module1", "module2"], function (module1Alias) { + // The location of the alias in the parameter list in the factory function needs to + // match the position of the module name in the dependency list. + // + // To ensure this is true in cases of modules with no aliases, e.g.: + // `import "module"` or `` + // we need to add modules without alias names to the end of the dependencies list + var dependencyNames = getAMDDependencyNames(node, includeNonAmdDependencies); + emitAMDDependencyList(dependencyNames); + write(", "); + emitAMDFactoryHeader(dependencyNames); + } + function emitAMDDependencyList(_a) { + var aliasedModuleNames = _a.aliasedModuleNames, unaliasedModuleNames = _a.unaliasedModuleNames; + write("[\"require\", \"exports\""); + if (aliasedModuleNames.length) { + write(", "); + write(aliasedModuleNames.join(", ")); + } + if (unaliasedModuleNames.length) { + write(", "); + write(unaliasedModuleNames.join(", ")); + } + write("]"); + } + function emitAMDFactoryHeader(_a) { + var importAliasNames = _a.importAliasNames; + write("function (require, exports"); + if (importAliasNames.length) { + write(", "); + write(importAliasNames.join(", ")); + } + write(") {"); + } + function emitAMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + writeLine(); + write("define("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitCommonJSModule(node) { + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + emitEmitHelpers(node); + collectExternalModuleInfo(node); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ false); + } + function emitUMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + var dependencyNames = getAMDDependencyNames(node, /*includeNonAmdDependencies*/ false); + // Module is detected first to support Browserify users that load into a browser with an AMD loader + writeLines("(function (factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define("); + emitAMDDependencyList(dependencyNames); + write(", factory);"); + writeLines(" }\n})("); + emitAMDFactoryHeader(dependencyNames); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitES6Module(node) { + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + // Emit exportDefault if it exists will happen as part + // or normal statement emit. + } + function emitExportEquals(emitAsReturn) { + if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { + writeLine(); + emitStart(exportEquals); + write(emitAsReturn ? "return " : "module.exports = "); + emit(exportEquals.expression); + write(";"); + emitEnd(exportEquals); + } + } + function emitJsxElement(node) { + switch (compilerOptions.jsx) { + case 2 /* React */: + jsxEmitReact(node); + break; + case 1 /* Preserve */: + // Fall back to preserve if None was specified (we'll error earlier) + default: + jsxEmitPreserve(node); + break; + } + } + function trimReactWhitespaceAndApplyEntities(node) { + var result = undefined; + var text = ts.getTextOfNode(node, /*includeTrivia*/ true); + var firstNonWhitespace = 0; + var lastNonWhitespace = -1; + // JSX trims whitespace at the end and beginning of lines, except that the + // start/end of a tag is considered a start/end of a line only if that line is + // on the same line as the closing tag. See examples in tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx + for (var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + if (ts.isLineBreak(c)) { + if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { + var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + firstNonWhitespace = -1; + } + else if (!ts.isWhiteSpace(c)) { + lastNonWhitespace = i; + if (firstNonWhitespace === -1) { + firstNonWhitespace = i; + } + } + } + if (firstNonWhitespace !== -1) { + var part = text.substr(firstNonWhitespace); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + if (result) { + // Replace entities like   + result = result.replace(/&(\w+);/g, function (s, m) { + if (entities[m] !== undefined) { + return String.fromCharCode(entities[m]); + } + else { + return s; + } + }); + } + return result; + } + function getTextToEmit(node) { + switch (compilerOptions.jsx) { + case 2 /* React */: + var text = trimReactWhitespaceAndApplyEntities(node); + if (text === undefined || text.length === 0) { + return undefined; + } + else { + return text; + } + case 1 /* Preserve */: + default: + return ts.getTextOfNode(node, /*includeTrivia*/ true); + } + } + function emitJsxText(node) { + switch (compilerOptions.jsx) { + case 2 /* React */: + write("\""); + write(trimReactWhitespaceAndApplyEntities(node)); + write("\""); + break; + case 1 /* Preserve */: + default: + writer.writeLiteral(ts.getTextOfNode(node, /*includeTrivia*/ true)); + break; + } + } + function emitJsxExpression(node) { + if (node.expression) { + switch (compilerOptions.jsx) { + case 1 /* Preserve */: + default: + write("{"); + emit(node.expression); + write("}"); + break; + case 2 /* React */: + emit(node.expression); + break; + } + } + } + function emitDirectivePrologues(statements, startWithNewLine) { + for (var i = 0; i < statements.length; ++i) { + if (ts.isPrologueDirective(statements[i])) { + if (startWithNewLine || i > 0) { + writeLine(); + } + emit(statements[i]); + } + else { + // return index of the first non prologue directive + return i; + } + } + return statements.length; + } + function writeLines(text) { + var lines = text.split(/\r\n|\r|\n/g); + for (var i = 0; i < lines.length; ++i) { + var line = lines[i]; + if (line.length) { + writeLine(); + write(line); + } + } + } + function emitEmitHelpers(node) { + // 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 < 2 /* ES6 */) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */)) { + writeLines(extendsHelper); + extendsEmitted = true; + } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16 /* EmitDecorate */) { + writeLines(decorateHelper); + if (compilerOptions.emitDecoratorMetadata) { + writeLines(metadataHelper); + } + decorateEmitted = true; + } + if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32 /* EmitParam */) { + writeLines(paramHelper); + paramEmitted = true; + } + if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64 /* EmitAwaiter */) { + writeLines(awaiterHelper); + awaiterEmitted = true; + } + } + } + function emitSourceFileNode(node) { + // Start new file on new line + writeLine(); + emitShebang(); + emitDetachedComments(node); + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { + var emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[1 /* CommonJS */]; + emitModule(node); + } + else { + // emit prologue directives prior to __extends + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + } + emitLeadingComments(node.endOfFileToken); + } + function emitNodeWithCommentsAndWithoutSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); + } + function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { + if (node) { + if (node.flags & 2 /* Ambient */) { + return emitCommentsOnNotEmittedNode(node); + } + if (isSpecializedCommentHandling(node)) { + // This is the node that will handle its own comments and sourcemap + return emitNodeWithoutSourceMap(node); + } + var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); + if (emitComments_1) { + emitLeadingComments(node); + } + emitNodeConsideringSourcemap(node); + if (emitComments_1) { + emitTrailingComments(node); + } + } + } + function emitNodeWithoutSourceMap(node) { + if (node) { + emitJavaScriptWorker(node); + } + } + function isSpecializedCommentHandling(node) { + switch (node.kind) { + // All of these entities are emitted in a specialized fashion. As such, we allow + // the specialized methods for each to handle the comments on the nodes. + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 227 /* ExportAssignment */: + return true; + } + } + function shouldEmitLeadingAndTrailingComments(node) { + switch (node.kind) { + case 193 /* VariableStatement */: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); + case 218 /* ModuleDeclaration */: + // Only emit the leading/trailing comments for a module if we're actually + // emitting the module as well. + return shouldEmitModuleDeclaration(node); + case 217 /* EnumDeclaration */: + // Only emit the leading/trailing comments for an enum if we're actually + // emitting the module as well. + return shouldEmitEnumDeclaration(node); + } + // If the node is emitted in specialized fashion, dont emit comments as this node will handle + // emitting comments when emitting itself + ts.Debug.assert(!isSpecializedCommentHandling(node)); + // If this is the expression body of an arrow function that we're down-leveling, + // then we don't want to emit comments when we emit the body. It will have already + // been taken care of when we emitted the 'return' statement for the function + // expression body. + if (node.kind !== 192 /* Block */ && + node.parent && + node.parent.kind === 174 /* ArrowFunction */ && + node.parent.body === node && + compilerOptions.target <= 1 /* ES5 */) { + return false; + } + // Emit comments for everything else. + return true; + } + function emitJavaScriptWorker(node) { + // Check if the node can be emitted regardless of the ScriptTarget + switch (node.kind) { + case 69 /* Identifier */: + return emitIdentifier(node); + case 138 /* Parameter */: + return emitParameter(node); + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + return emitMethod(node); + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + return emitAccessor(node); + case 97 /* ThisKeyword */: + return emitThis(node); + case 95 /* SuperKeyword */: + return emitSuper(node); + case 93 /* NullKeyword */: + return write("null"); + case 99 /* TrueKeyword */: + return write("true"); + case 84 /* FalseKeyword */: + return write("false"); + case 8 /* NumericLiteral */: + case 9 /* StringLiteral */: + case 10 /* RegularExpressionLiteral */: + case 11 /* NoSubstitutionTemplateLiteral */: + case 12 /* TemplateHead */: + case 13 /* TemplateMiddle */: + case 14 /* TemplateTail */: + return emitLiteral(node); + case 183 /* TemplateExpression */: + return emitTemplateExpression(node); + case 190 /* TemplateSpan */: + return emitTemplateSpan(node); + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + return emitJsxElement(node); + case 236 /* JsxText */: + return emitJsxText(node); + case 240 /* JsxExpression */: + return emitJsxExpression(node); + case 135 /* QualifiedName */: + return emitQualifiedName(node); + case 161 /* ObjectBindingPattern */: + return emitObjectBindingPattern(node); + case 162 /* ArrayBindingPattern */: + return emitArrayBindingPattern(node); + case 163 /* BindingElement */: + return emitBindingElement(node); + case 164 /* ArrayLiteralExpression */: + return emitArrayLiteral(node); + case 165 /* ObjectLiteralExpression */: + return emitObjectLiteral(node); + case 245 /* PropertyAssignment */: + return emitPropertyAssignment(node); + case 246 /* ShorthandPropertyAssignment */: + return emitShorthandPropertyAssignment(node); + case 136 /* ComputedPropertyName */: + return emitComputedPropertyName(node); + case 166 /* PropertyAccessExpression */: + return emitPropertyAccess(node); + case 167 /* ElementAccessExpression */: + return emitIndexedAccess(node); + case 168 /* CallExpression */: + return emitCallExpression(node); + case 169 /* NewExpression */: + return emitNewExpression(node); + case 170 /* TaggedTemplateExpression */: + return emitTaggedTemplateExpression(node); + case 171 /* TypeAssertionExpression */: + return emit(node.expression); + case 189 /* AsExpression */: + return emit(node.expression); + case 172 /* ParenthesizedExpression */: + return emitParenExpression(node); + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + return emitFunctionDeclaration(node); + case 175 /* DeleteExpression */: + return emitDeleteExpression(node); + case 176 /* TypeOfExpression */: + return emitTypeOfExpression(node); + case 177 /* VoidExpression */: + return emitVoidExpression(node); + case 178 /* AwaitExpression */: + return emitAwaitExpression(node); + case 179 /* PrefixUnaryExpression */: + return emitPrefixUnaryExpression(node); + case 180 /* PostfixUnaryExpression */: + return emitPostfixUnaryExpression(node); + case 181 /* BinaryExpression */: + return emitBinaryExpression(node); + case 182 /* ConditionalExpression */: + return emitConditionalExpression(node); + case 185 /* SpreadElementExpression */: + return emitSpreadElementExpression(node); + case 184 /* YieldExpression */: + return emitYieldExpression(node); + case 187 /* OmittedExpression */: + return; + case 192 /* Block */: + case 219 /* ModuleBlock */: + return emitBlock(node); + case 193 /* VariableStatement */: + return emitVariableStatement(node); + case 194 /* EmptyStatement */: + return write(";"); + case 195 /* ExpressionStatement */: + return emitExpressionStatement(node); + case 196 /* IfStatement */: + return emitIfStatement(node); + case 197 /* DoStatement */: + return emitDoStatement(node); + case 198 /* WhileStatement */: + return emitWhileStatement(node); + case 199 /* ForStatement */: + return emitForStatement(node); + case 201 /* ForOfStatement */: + case 200 /* ForInStatement */: + return emitForInOrForOfStatement(node); + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: + return emitBreakOrContinueStatement(node); + case 204 /* ReturnStatement */: + return emitReturnStatement(node); + case 205 /* WithStatement */: + return emitWithStatement(node); + case 206 /* SwitchStatement */: + return emitSwitchStatement(node); + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + return emitCaseOrDefaultClause(node); + case 207 /* LabeledStatement */: + return emitLabelledStatement(node); + case 208 /* ThrowStatement */: + return emitThrowStatement(node); + case 209 /* TryStatement */: + return emitTryStatement(node); + case 244 /* CatchClause */: + return emitCatchClause(node); + case 210 /* DebuggerStatement */: + return emitDebuggerStatement(node); + case 211 /* VariableDeclaration */: + return emitVariableDeclaration(node); + case 186 /* ClassExpression */: + return emitClassExpression(node); + case 214 /* ClassDeclaration */: + return emitClassDeclaration(node); + case 215 /* InterfaceDeclaration */: + return emitInterfaceDeclaration(node); + case 217 /* EnumDeclaration */: + return emitEnumDeclaration(node); + case 247 /* EnumMember */: + return emitEnumMember(node); + case 218 /* ModuleDeclaration */: + return emitModuleDeclaration(node); + case 222 /* ImportDeclaration */: + return emitImportDeclaration(node); + case 221 /* ImportEqualsDeclaration */: + return emitImportEqualsDeclaration(node); + case 228 /* ExportDeclaration */: + return emitExportDeclaration(node); + case 227 /* ExportAssignment */: + return emitExportAssignment(node); + case 248 /* SourceFile */: + return emitSourceFileNode(node); + } + } + function hasDetachedComments(pos) { + return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; + } + function getLeadingCommentsWithoutDetachedComments() { + // get the leading comments from detachedPos + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); + if (detachedCommentsInfo.length - 1) { + detachedCommentsInfo.pop(); + } + else { + detachedCommentsInfo = undefined; + } + return leadingComments; + } + function isPinnedComments(comment) { + return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; + } + /** + * Determine if the given comment is a triple-slash + * + * @return true if the comment is a triple-slash comment else false + **/ + function isTripleSlashComment(comment) { + // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text + // so that we don't end up computing comment string and doing match for all // comments + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */) { + var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); + return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || + textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? + true : false; + } + return false; + } + function getLeadingCommentsToEmit(node) { + // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === 248 /* SourceFile */ || node.pos !== node.parent.pos) { + if (hasDetachedComments(node.pos)) { + // get comments without detached comments + return getLeadingCommentsWithoutDetachedComments(); + } + else { + // get the leading comments from the node + return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + } + } + } + function getTrailingCommentsToEmit(node) { + // Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === 248 /* SourceFile */ || node.end !== node.parent.end) { + return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + } + } + } + /** + * Emit comments associated with node that will not be emitted into JS file + */ + function emitCommentsOnNotEmittedNode(node) { + emitLeadingCommentsWorker(node, /*isEmittedNode:*/ false); + } + function emitLeadingComments(node) { + return emitLeadingCommentsWorker(node, /*isEmittedNode:*/ true); + } + function emitLeadingCommentsWorker(node, isEmittedNode) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (isEmittedNode) { + leadingComments = getLeadingCommentsToEmit(node); + } + else { + // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, + // unless it is a triple slash comment at the top of the file. + // For Example: + // /// + // declare var x; + // /// + // interface F {} + // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted + if (node.pos === 0) { + leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); + } + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space + ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator:*/ true, newLine, writeComment); + } + function emitTrailingComments(node) { + if (compilerOptions.removeComments) { + return; + } + // Emit the trailing comments only if the parent's end doesn't match + var trailingComments = getTrailingCommentsToEmit(node); + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); + } + /** + * Emit trailing comments at the position. The term trailing comment is used here to describe following comment: + * x, /comment1/ y + * ^ => pos; the function will emit "comment1" in the emitJS + */ + function emitTrailingCommentsOfPosition(pos) { + if (compilerOptions.removeComments) { + return; + } + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); + } + function emitLeadingCommentsOfPositionWorker(pos) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (hasDetachedComments(pos)) { + // get comments without detached comments + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + // get the leading comments from the node + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space + ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); + } + function emitDetachedComments(node) { + var leadingComments; + if (compilerOptions.removeComments) { + // removeComments is true, only reserve pinned comment at the top of file + // For example: + // /*! Pinned Comment */ + // + // var x = 10; + if (node.pos === 0) { + leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); + } + } + else { + // removeComments is false, just get detached as normal and bypass the process to filter comment + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); + } + if (leadingComments) { + var detachedComments = []; + var lastComment; + ts.forEach(leadingComments, function (comment) { + if (lastComment) { + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); + var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); + if (commentLine >= lastCommentLine + 2) { + // There was a blank line between the last comment and this comment. This + // comment is not part of the copyright comments. Return what we have so + // far. + return detachedComments; + } + } + detachedComments.push(comment); + lastComment = comment; + }); + if (detachedComments.length) { + // All comments look like they could have been part of the copyright header. Make + // sure there is at least one blank line between it and the node. If not, it's not + // a copyright header. + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); + var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); + if (nodeLine >= lastCommentLine + 2) { + // Valid detachedComments + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + ts.emitComments(currentSourceFile, writer, detachedComments, /*trailingSeparator*/ true, newLine, writeComment); + var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; + if (detachedCommentsInfo) { + detachedCommentsInfo.push(currentDetachedCommentInfo); + } + else { + detachedCommentsInfo = [currentDetachedCommentInfo]; + } + } + } + } + } + function emitShebang() { + var shebang = ts.getShebang(currentSourceFile.text); + if (shebang) { + write(shebang); + } + } + var _a; + } + function emitFile(jsFilePath, sourceFile) { + emitJavaScript(jsFilePath, sourceFile); + if (compilerOptions.declaration) { + ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); + } + } + } + ts.emitFiles = emitFiles; })(ts || (ts = {})); /// /// @@ -35273,7 +35965,7 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ var emptyArray = []; - ts.version = "1.7.0"; + ts.version = "1.8.0"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -35311,11 +36003,11 @@ var ts; if (ts.getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { var failedLookupLocations = []; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); - var resolvedFileName = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); + var resolvedFileName = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (resolvedFileName) { return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } - resolvedFileName = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); + resolvedFileName = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); return resolvedFileName ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; @@ -35325,13 +36017,8 @@ var ts; } } ts.nodeModuleNameResolver = nodeModuleNameResolver; - function loadNodeModuleFromFile(candidate, loadOnlyDts, failedLookupLocation, host) { - if (loadOnlyDts) { - return tryLoad(".d.ts"); - } - else { - return ts.forEach(ts.supportedExtensions, tryLoad); - } + function loadNodeModuleFromFile(candidate, failedLookupLocation, host) { + return ts.forEach(ts.moduleFileExtensions, tryLoad); function tryLoad(ext) { var fileName = ts.fileExtensionIs(candidate, ext) ? candidate : candidate + ext; if (host.fileExists(fileName)) { @@ -35343,7 +36030,7 @@ var ts; } } } - function loadNodeModuleFromDirectory(candidate, loadOnlyDts, failedLookupLocation, host) { + function loadNodeModuleFromDirectory(candidate, failedLookupLocation, host) { var packageJsonPath = ts.combinePaths(candidate, "package.json"); if (host.fileExists(packageJsonPath)) { var jsonContent; @@ -35356,7 +36043,7 @@ var ts; jsonContent = { typings: undefined }; } if (jsonContent.typings) { - var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), loadOnlyDts, failedLookupLocation, host); + var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), failedLookupLocation, host); if (result) { return result; } @@ -35366,7 +36053,7 @@ var ts; // record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results failedLookupLocation.push(packageJsonPath); } - return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host); + return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), failedLookupLocation, host); } function loadModuleFromNodeModules(moduleName, directory, host) { var failedLookupLocations = []; @@ -35376,11 +36063,11 @@ var ts; if (baseName !== "node_modules") { var nodeModulesFolder = ts.combinePaths(directory, "node_modules"); var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); - var result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); + var result = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } - result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); + result = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } @@ -35399,7 +36086,7 @@ var ts; } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { // module names that contain '!' are used to reference resources and are not resolved to actual files on disk - if (moduleName.indexOf('!') != -1) { + if (moduleName.indexOf("!") != -1) { return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); @@ -35746,7 +36433,9 @@ var ts; return emitResult; } function getSourceFile(fileName) { - return filesByName.get(fileName); + // first try to use file name as is to find file + // then try to convert relative file name to absolute and use it to retrieve source file + return filesByName.get(fileName) || filesByName.get(ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory())); } function getDiagnosticsHelper(sourceFile, getDiagnostics, cancellationToken) { if (sourceFile) { @@ -35845,10 +36534,14 @@ var ts; var imports; for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var node = _a[_i]; + collect(node, /* allowRelativeModuleNames */ true); + } + file.imports = imports || emptyArray; + function collect(node, allowRelativeModuleNames) { switch (node.kind) { - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 226 /* ExportDeclaration */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 228 /* ExportDeclaration */: var moduleNameExpr = ts.getExternalModuleName(node); if (!moduleNameExpr || moduleNameExpr.kind !== 9 /* StringLiteral */) { break; @@ -35856,9 +36549,11 @@ var ts; if (!moduleNameExpr.text) { break; } - (imports || (imports = [])).push(moduleNameExpr); + if (allowRelativeModuleNames || !ts.isExternalModuleNameRelative(moduleNameExpr.text)) { + (imports || (imports = [])).push(moduleNameExpr); + } break; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (node.name.kind === 9 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || ts.isDeclarationFile(file))) { // TypeScript 1.0 spec (April 2014): 12.1.6 // An AmbientExternalModuleDeclaration declares an external module. @@ -35866,22 +36561,15 @@ var ts; // The StringLiteral must specify a top - level external module name. // Relative external module names are not permitted ts.forEachChild(node.body, function (node) { - if (ts.isExternalModuleImportEqualsDeclaration(node) && - ts.getExternalModuleImportEqualsDeclarationExpression(node).kind === 9 /* StringLiteral */) { - var moduleName = ts.getExternalModuleImportEqualsDeclarationExpression(node); - // TypeScript 1.0 spec (April 2014): 12.1.6 - // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules - // only through top - level external module names. Relative external module names are not permitted. - if (moduleName) { - (imports || (imports = [])).push(moduleName); - } - } + // TypeScript 1.0 spec (April 2014): 12.1.6 + // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules + // only through top - level external module names. Relative external module names are not permitted. + collect(node, /* allowRelativeModuleNames */ false); }); } break; } } - file.imports = imports || emptyArray; } function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { var diagnosticArgument; @@ -35925,52 +36613,52 @@ var ts; } // Get source file from normalized fileName function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { - var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (filesByName.contains(canonicalName)) { + if (filesByName.contains(fileName)) { // We've already looked for this file, use cached result - return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false); + return getSourceFileFromCache(fileName, /*useAbsolutePath*/ false); } - else { - var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); - var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (filesByName.contains(canonicalAbsolutePath)) { - return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, /*useAbsolutePath*/ true); - } - // We haven't looked for this file, do so now and cache result - var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { - if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - else { - fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - }); - filesByName.set(canonicalName, file); - if (file) { - skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; - // Set the source file for normalized absolute path - filesByName.set(canonicalAbsolutePath, file); - var basePath = ts.getDirectoryPath(fileName); - if (!options.noResolve) { - processReferencedFiles(file, basePath); - } - // always process imported modules to record module name resolutions - processImportedModules(file, basePath); - if (isDefaultLib) { - file.isDefaultLib = true; - files.unshift(file); - } - else { - files.push(file); - } - } - return file; + var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); + if (filesByName.contains(normalizedAbsolutePath)) { + var file_1 = getSourceFileFromCache(normalizedAbsolutePath, /*useAbsolutePath*/ true); + // we don't have resolution for this relative file name but the match was found by absolute file name + // store resolution for relative name as well + filesByName.set(fileName, file_1); + return file_1; } - function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName.get(canonicalName); + // We haven't looked for this file, do so now and cache result + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + else { + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + }); + filesByName.set(fileName, file); + if (file) { + skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; + // Set the source file for normalized absolute path + filesByName.set(normalizedAbsolutePath, file); + var basePath = ts.getDirectoryPath(fileName); + if (!options.noResolve) { + processReferencedFiles(file, basePath); + } + // always process imported modules to record module name resolutions + processImportedModules(file, basePath); + if (isDefaultLib) { + file.isDefaultLib = true; + files.unshift(file); + } + else { + files.push(file); + } + } + return file; + function getSourceFileFromCache(fileName, useAbsolutePath) { + var file = filesByName.get(fileName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; - if (canonicalName !== sourceFileName) { + if (ts.normalizeSlashes(fileName) !== ts.normalizeSlashes(sourceFileName)) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } @@ -36138,9 +36826,9 @@ var ts; var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } - // Cannot specify module gen target when in es6 or above - if (options.module && languageVersion >= 2 /* ES6 */) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + // Cannot specify module gen target of es6 when below es6 + if (options.module === 5 /* ES6 */ && languageVersion < 2 /* ES6 */) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower)); } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -36181,10 +36869,6 @@ var ts; !options.experimentalDecorators) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } - if (options.experimentalAsyncFunctions && - options.target !== 2 /* ES6 */) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); - } } } ts.createProgram = createProgram; @@ -36266,11 +36950,13 @@ var ts; "commonjs": 1 /* CommonJS */, "amd": 2 /* AMD */, "system": 4 /* System */, - "umd": 3 /* UMD */ + "umd": 3 /* UMD */, + "es6": 5 /* ES6 */, + "es2015": 5 /* ES2015 */ }, - description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd, + description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6, paramType: ts.Diagnostics.KIND, - error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd + error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 }, { name: "newLine", @@ -36395,7 +37081,12 @@ var ts; { name: "target", shortName: "t", - type: { "es3": 0 /* ES3 */, "es5": 1 /* ES5 */, "es6": 2 /* ES6 */ }, + type: { + "es3": 0 /* ES3 */, + "es5": 1 /* ES5 */, + "es6": 2 /* ES6 */, + "es2015": 2 /* ES2015 */ + }, description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: ts.Diagnostics.VERSION, error: ts.Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6 @@ -36412,11 +37103,6 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, - { - name: "experimentalAsyncFunctions", - type: "boolean", - description: ts.Diagnostics.Enables_experimental_support_for_ES7_async_functions - }, { name: "experimentalDecorators", type: "boolean", @@ -36565,7 +37251,7 @@ var ts; catch (e) { return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; } - return parseConfigFileText(fileName, text); + return parseConfigFileTextToJson(fileName, text); } ts.readConfigFile = readConfigFile; /** @@ -36573,7 +37259,7 @@ var ts; * @param fileName The path to the config file * @param jsonText The text of the config file */ - function parseConfigFileText(fileName, jsonText) { + function parseConfigFileTextToJson(fileName, jsonText) { try { return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; } @@ -36581,14 +37267,14 @@ var ts; return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; } } - ts.parseConfigFileText = parseConfigFileText; + ts.parseConfigFileTextToJson = parseConfigFileTextToJson; /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - function parseConfigFile(json, host, basePath) { + function parseJsonConfigFileContent(json, host, basePath) { var errors = []; return { options: getCompilerOptions(), @@ -36622,6 +37308,9 @@ var ts; } if (opt.isFilePath) { value = ts.normalizePath(ts.combinePaths(basePath, value)); + if (value === "") { + value = "."; + } } options[opt.name] = value; } @@ -36650,27 +37339,27 @@ var ts; var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; var sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)); for (var i = 0; i < sysFiles.length; i++) { - var name_27 = sysFiles[i]; - if (ts.fileExtensionIs(name_27, ".d.ts")) { - var baseName = name_27.substr(0, name_27.length - ".d.ts".length); + var name_28 = sysFiles[i]; + if (ts.fileExtensionIs(name_28, ".d.ts")) { + var baseName = name_28.substr(0, name_28.length - ".d.ts".length); if (!ts.contains(sysFiles, baseName + ".tsx") && !ts.contains(sysFiles, baseName + ".ts")) { - fileNames.push(name_27); + fileNames.push(name_28); } } - else if (ts.fileExtensionIs(name_27, ".ts")) { - if (!ts.contains(sysFiles, name_27 + "x")) { - fileNames.push(name_27); + else if (ts.fileExtensionIs(name_28, ".ts")) { + if (!ts.contains(sysFiles, name_28 + "x")) { + fileNames.push(name_28); } } else { - fileNames.push(name_27); + fileNames.push(name_28); } } } return fileNames; } } - ts.parseConfigFile = parseConfigFile; + ts.parseJsonConfigFileContent = parseJsonConfigFileContent; })(ts || (ts = {})); /* @internal */ var ts; @@ -36744,7 +37433,7 @@ var ts; } } function autoCollapse(node) { - return ts.isFunctionBlock(node) && node.parent.kind !== 172 /* ArrowFunction */; + return ts.isFunctionBlock(node) && node.parent.kind !== 174 /* ArrowFunction */; } var depth = 0; var maxDepth = 20; @@ -36756,7 +37445,7 @@ var ts; addOutliningForLeadingCommentsForNode(n); } switch (n.kind) { - case 190 /* Block */: + case 192 /* Block */: if (!ts.isFunctionBlock(n)) { var parent_7 = n.parent; var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); @@ -36764,18 +37453,18 @@ var ts; // Check if the block is standalone, or 'attached' to some parent statement. // If the latter, we want to collaps the block, but consider its hint span // to be the entire span of the parent. - if (parent_7.kind === 195 /* DoStatement */ || - parent_7.kind === 198 /* ForInStatement */ || - parent_7.kind === 199 /* ForOfStatement */ || - parent_7.kind === 197 /* ForStatement */ || - parent_7.kind === 194 /* IfStatement */ || - parent_7.kind === 196 /* WhileStatement */ || - parent_7.kind === 203 /* WithStatement */ || - parent_7.kind === 242 /* CatchClause */) { + if (parent_7.kind === 197 /* DoStatement */ || + parent_7.kind === 200 /* ForInStatement */ || + parent_7.kind === 201 /* ForOfStatement */ || + parent_7.kind === 199 /* ForStatement */ || + parent_7.kind === 196 /* IfStatement */ || + parent_7.kind === 198 /* WhileStatement */ || + parent_7.kind === 205 /* WithStatement */ || + parent_7.kind === 244 /* CatchClause */) { addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_7.kind === 207 /* TryStatement */) { + if (parent_7.kind === 209 /* TryStatement */) { // Could be the try-block, or the finally-block. var tryStatement = parent_7; if (tryStatement.tryBlock === n) { @@ -36783,7 +37472,7 @@ var ts; break; } else if (tryStatement.finallyBlock === n) { - var finallyKeyword = ts.findChildOfKind(tryStatement, 83 /* FinallyKeyword */, sourceFile); + var finallyKeyword = ts.findChildOfKind(tryStatement, 85 /* FinallyKeyword */, sourceFile); if (finallyKeyword) { addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n)); break; @@ -36802,23 +37491,23 @@ var ts; break; } // Fallthrough. - case 217 /* ModuleBlock */: { + case 219 /* ModuleBlock */: { var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 16 /* CloseBraceToken */, sourceFile); addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); break; } - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 163 /* ObjectLiteralExpression */: - case 218 /* CaseBlock */: { + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 165 /* ObjectLiteralExpression */: + case 220 /* CaseBlock */: { var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 16 /* CloseBraceToken */, sourceFile); addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); break; } - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: var openBracket = ts.findChildOfKind(n, 19 /* OpenBracketToken */, sourceFile); var closeBracket = ts.findChildOfKind(n, 20 /* CloseBracketToken */, sourceFile); addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); @@ -36846,12 +37535,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_28 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_28); + for (var name_29 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_29); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_28); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_29); if (!matches) { continue; } @@ -36864,14 +37553,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_28); + matches = patternMatcher.getMatches(containers, name_29); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_28, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_29, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -36895,7 +37584,7 @@ var ts; } function getTextOfIdentifierOrLiteral(node) { if (node) { - if (node.kind === 67 /* Identifier */ || + if (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) { return node.text; @@ -36909,7 +37598,7 @@ var ts; if (text !== undefined) { containers.unshift(text); } - else if (declaration.name.kind === 134 /* ComputedPropertyName */) { + else if (declaration.name.kind === 136 /* ComputedPropertyName */) { return tryAddComputedPropertyName(declaration.name.expression, containers, /*includeLastPortion:*/ true); } else { @@ -36930,7 +37619,7 @@ var ts; } return true; } - if (expression.kind === 164 /* PropertyAccessExpression */) { + if (expression.kind === 166 /* PropertyAccessExpression */) { var propertyAccess = expression; if (includeLastPortion) { containers.unshift(propertyAccess.name.text); @@ -36943,7 +37632,7 @@ var ts; var containers = []; // First, if we started with a computed property name, then add all but the last // portion into the container array. - if (declaration.name.kind === 134 /* ComputedPropertyName */) { + if (declaration.name.kind === 136 /* ComputedPropertyName */) { if (!tryAddComputedPropertyName(declaration.name.expression, containers, /*includeLastPortion:*/ false)) { return undefined; } @@ -37019,17 +37708,17 @@ var ts; var current = node.parent; while (current) { switch (current.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: // If we have a module declared as A.B.C, it is more "intuitive" // to say it only has a single layer of depth do { current = current.parent; - } while (current.kind === 216 /* ModuleDeclaration */); + } while (current.kind === 218 /* ModuleDeclaration */); // fall through - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: indent++; } current = current.parent; @@ -37040,21 +37729,21 @@ var ts; var childNodes = []; function visit(node) { switch (node.kind) { - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: ts.forEach(node.declarationList.declarations, visit); break; - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: ts.forEach(node.elements, visit); break; - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: // Handle named exports case e.g.: // export {a, b as B} from "mod"; if (node.exportClause) { ts.forEach(node.exportClause.elements, visit); } break; - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: var importClause = node.importClause; if (importClause) { // Handle default import case e.g.: @@ -37066,7 +37755,7 @@ var ts; // import * as NS from "mod"; // import {a, b as B} from "mod"; if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (importClause.namedBindings.kind === 224 /* NamespaceImport */) { childNodes.push(importClause.namedBindings); } else { @@ -37075,21 +37764,21 @@ var ts; } } break; - case 161 /* BindingElement */: - case 209 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 211 /* VariableDeclaration */: if (ts.isBindingPattern(node.name)) { visit(node.name); break; } // Fall through - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: - case 216 /* ModuleDeclaration */: - case 211 /* FunctionDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: + case 218 /* ModuleDeclaration */: + case 213 /* FunctionDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: childNodes.push(node); break; } @@ -37137,17 +37826,17 @@ var ts; for (var _i = 0; _i < nodes.length; _i++) { var node = nodes[_i]; switch (node.kind) { - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: topLevelNodes.push(node); break; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: var moduleDeclaration = node; topLevelNodes.push(node); addTopLevelNodes(getInnermostModule(moduleDeclaration).body.statements, topLevelNodes); break; - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: var functionDeclaration = node; if (isTopLevelFunctionDeclaration(functionDeclaration)) { topLevelNodes.push(node); @@ -37158,12 +37847,12 @@ var ts; } } function isTopLevelFunctionDeclaration(functionDeclaration) { - if (functionDeclaration.kind === 211 /* FunctionDeclaration */) { + if (functionDeclaration.kind === 213 /* FunctionDeclaration */) { // A function declaration is 'top level' if it contains any function declarations // within it. - if (functionDeclaration.body && functionDeclaration.body.kind === 190 /* Block */) { + if (functionDeclaration.body && functionDeclaration.body.kind === 192 /* Block */) { // Proper function declarations can only have identifier names - if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 211 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) { + if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 213 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) { return true; } // Or if it is not parented by another function. i.e all functions @@ -37223,7 +37912,7 @@ var ts; } function createChildItem(node) { switch (node.kind) { - case 136 /* Parameter */: + case 138 /* Parameter */: if (ts.isBindingPattern(node.name)) { break; } @@ -37231,36 +37920,36 @@ var ts; return undefined; } return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberGetAccessorElement); - case 144 /* SetAccessor */: + case 146 /* SetAccessor */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 145 /* CallSignature */: + case 147 /* CallSignature */: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: var variableDeclarationNode; - var name_29; - if (node.kind === 161 /* BindingElement */) { - name_29 = node.name; + var name_30; + if (node.kind === 163 /* BindingElement */) { + name_30 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration - while (variableDeclarationNode && variableDeclarationNode.kind !== 209 /* VariableDeclaration */) { + while (variableDeclarationNode && variableDeclarationNode.kind !== 211 /* VariableDeclaration */) { variableDeclarationNode = variableDeclarationNode.parent; } ts.Debug.assert(variableDeclarationNode !== undefined); @@ -37268,24 +37957,24 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_29 = node.name; + name_30 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.variableElement); } - case 142 /* Constructor */: + case 144 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); - case 228 /* ExportSpecifier */: - case 224 /* ImportSpecifier */: - case 219 /* ImportEqualsDeclaration */: - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: + case 230 /* ExportSpecifier */: + case 226 /* ImportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.alias); } return undefined; @@ -37315,17 +38004,17 @@ var ts; } function createTopLevelItem(node) { switch (node.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: return createSourceFileItem(node); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return createClassItem(node); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return createEnumItem(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return createIterfaceItem(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return createModuleItem(node); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return createFunctionItem(node); } return undefined; @@ -37337,7 +38026,7 @@ var ts; // Otherwise, we need to aggregate each identifier to build up the qualified name. var result = []; result.push(moduleDeclaration.name.text); - while (moduleDeclaration.body && moduleDeclaration.body.kind === 216 /* ModuleDeclaration */) { + while (moduleDeclaration.body && moduleDeclaration.body.kind === 218 /* ModuleDeclaration */) { moduleDeclaration = moduleDeclaration.body; result.push(moduleDeclaration.name.text); } @@ -37349,7 +38038,7 @@ var ts; return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } function createFunctionItem(node) { - if (node.body && node.body.kind === 190 /* Block */) { + if (node.body && node.body.kind === 192 /* Block */) { var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem); return getNavigationBarItem(!node.name ? "default" : node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } @@ -37370,7 +38059,7 @@ var ts; var childItems; if (node.members) { var constructor = ts.forEach(node.members, function (member) { - return member.kind === 142 /* Constructor */ && member; + return member.kind === 144 /* Constructor */ && member; }); // Add the constructor parameters in as children of the class (for property parameters). // Note that *all non-binding pattern named* parameters will be added to the nodes array, but parameters that @@ -37394,7 +38083,7 @@ var ts; } } function removeComputedProperties(node) { - return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 134 /* ComputedPropertyName */; }); + return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 136 /* ComputedPropertyName */; }); } /** * Like removeComputedProperties, but retains the properties with well known symbol names @@ -37403,13 +38092,13 @@ var ts; return ts.filter(node.members, function (member) { return !ts.hasDynamicName(member); }); } function getInnermostModule(node) { - while (node.body.kind === 216 /* ModuleDeclaration */) { + while (node.body.kind === 218 /* ModuleDeclaration */) { node = node.body; } return node; } function getNodeSpan(node) { - return node.kind === 246 /* SourceFile */ + return node.kind === 248 /* SourceFile */ ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } @@ -38204,15 +38893,15 @@ var ts; } return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); function createJavaScriptSignatureHelpItems(argumentInfo) { - if (argumentInfo.invocation.kind !== 166 /* CallExpression */) { + if (argumentInfo.invocation.kind !== 168 /* CallExpression */) { return undefined; } // See if we can find some symbol with the call expression name that has call signatures. var callExpression = argumentInfo.invocation; var expression = callExpression.expression; - var name = expression.kind === 67 /* Identifier */ + var name = expression.kind === 69 /* Identifier */ ? expression - : expression.kind === 164 /* PropertyAccessExpression */ + : expression.kind === 166 /* PropertyAccessExpression */ ? expression.name : undefined; if (!name || !name.text) { @@ -38245,7 +38934,7 @@ var ts; * in the argument of an invocation; returns undefined otherwise. */ function getImmediatelyContainingArgumentInfo(node) { - if (node.parent.kind === 166 /* CallExpression */ || node.parent.kind === 167 /* NewExpression */) { + if (node.parent.kind === 168 /* CallExpression */ || node.parent.kind === 169 /* NewExpression */) { var callExpression = node.parent; // There are 3 cases to handle: // 1. The token introduces a list, and should begin a sig help session @@ -38298,25 +38987,25 @@ var ts; }; } } - else if (node.kind === 11 /* NoSubstitutionTemplateLiteral */ && node.parent.kind === 168 /* TaggedTemplateExpression */) { + else if (node.kind === 11 /* NoSubstitutionTemplateLiteral */ && node.parent.kind === 170 /* TaggedTemplateExpression */) { // Check if we're actually inside the template; // otherwise we'll fall out and return undefined. if (ts.isInsideTemplateLiteral(node, position)) { return getArgumentListInfoForTemplate(node.parent, /*argumentIndex*/ 0); } } - else if (node.kind === 12 /* TemplateHead */ && node.parent.parent.kind === 168 /* TaggedTemplateExpression */) { + else if (node.kind === 12 /* TemplateHead */ && node.parent.parent.kind === 170 /* TaggedTemplateExpression */) { var templateExpression = node.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 181 /* TemplateExpression */); + ts.Debug.assert(templateExpression.kind === 183 /* TemplateExpression */); var argumentIndex = ts.isInsideTemplateLiteral(node, position) ? 0 : 1; return getArgumentListInfoForTemplate(tagExpression, argumentIndex); } - else if (node.parent.kind === 188 /* TemplateSpan */ && node.parent.parent.parent.kind === 168 /* TaggedTemplateExpression */) { + else if (node.parent.kind === 190 /* TemplateSpan */ && node.parent.parent.parent.kind === 170 /* TaggedTemplateExpression */) { var templateSpan = node.parent; var templateExpression = templateSpan.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 181 /* TemplateExpression */); + ts.Debug.assert(templateExpression.kind === 183 /* TemplateExpression */); // If we're just after a template tail, don't show signature help. if (node.kind === 14 /* TemplateTail */ && !ts.isInsideTemplateLiteral(node, position)) { return undefined; @@ -38434,7 +39123,7 @@ var ts; // // This is because a Missing node has no width. However, what we actually want is to include trivia // leading up to the next token in case the user is about to type in a TemplateMiddle or TemplateTail. - if (template.kind === 181 /* TemplateExpression */) { + if (template.kind === 183 /* TemplateExpression */) { var lastSpan = ts.lastOrUndefined(template.templateSpans); if (lastSpan.literal.getFullWidth() === 0) { applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, /*stopAfterLineBreak*/ false); @@ -38443,7 +39132,7 @@ var ts; return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); } function getContainingArgumentInfo(node) { - for (var n = node; n.kind !== 246 /* SourceFile */; n = n.parent) { + for (var n = node; n.kind !== 248 /* SourceFile */; n = n.parent) { if (ts.isFunctionBlock(n)) { return undefined; } @@ -38643,40 +39332,40 @@ var ts; return false; } switch (n.kind) { - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 163 /* ObjectLiteralExpression */: - case 159 /* ObjectBindingPattern */: - case 153 /* TypeLiteral */: - case 190 /* Block */: - case 217 /* ModuleBlock */: - case 218 /* CaseBlock */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 165 /* ObjectLiteralExpression */: + case 161 /* ObjectBindingPattern */: + case 155 /* TypeLiteral */: + case 192 /* Block */: + case 219 /* ModuleBlock */: + case 220 /* CaseBlock */: return nodeEndsWith(n, 16 /* CloseBraceToken */, sourceFile); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return isCompletedNode(n.block, sourceFile); - case 167 /* NewExpression */: + case 169 /* NewExpression */: if (!n.arguments) { return true; } // fall through - case 166 /* CallExpression */: - case 170 /* ParenthesizedExpression */: - case 158 /* ParenthesizedType */: + case 168 /* CallExpression */: + case 172 /* ParenthesizedExpression */: + case 160 /* ParenthesizedType */: return nodeEndsWith(n, 18 /* CloseParenToken */, sourceFile); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return isCompletedNode(n.type, sourceFile); - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 146 /* ConstructSignature */: - case 145 /* CallSignature */: - case 172 /* ArrowFunction */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 148 /* ConstructSignature */: + case 147 /* CallSignature */: + case 174 /* ArrowFunction */: if (n.body) { return isCompletedNode(n.body, sourceFile); } @@ -38686,63 +39375,64 @@ var ts; // Even though type parameters can be unclosed, we can get away with // having at least a closing paren. return hasChildOfKind(n, 18 /* CloseParenToken */, sourceFile); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return n.body && isCompletedNode(n.body, sourceFile); - case 194 /* IfStatement */: + case 196 /* IfStatement */: if (n.elseStatement) { return isCompletedNode(n.elseStatement, sourceFile); } return isCompletedNode(n.thenStatement, sourceFile); - case 193 /* ExpressionStatement */: - return isCompletedNode(n.expression, sourceFile); - case 162 /* ArrayLiteralExpression */: - case 160 /* ArrayBindingPattern */: - case 165 /* ElementAccessExpression */: - case 134 /* ComputedPropertyName */: - case 155 /* TupleType */: + case 195 /* ExpressionStatement */: + return isCompletedNode(n.expression, sourceFile) || + hasChildOfKind(n, 23 /* SemicolonToken */); + case 164 /* ArrayLiteralExpression */: + case 162 /* ArrayBindingPattern */: + case 167 /* ElementAccessExpression */: + case 136 /* ComputedPropertyName */: + case 157 /* TupleType */: return nodeEndsWith(n, 20 /* CloseBracketToken */, sourceFile); - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: if (n.type) { return isCompletedNode(n.type, sourceFile); } return hasChildOfKind(n, 20 /* CloseBracketToken */, sourceFile); - case 239 /* CaseClause */: - case 240 /* DefaultClause */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed return false; - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 196 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 198 /* WhileStatement */: return isCompletedNode(n.statement, sourceFile); - case 195 /* DoStatement */: + case 197 /* DoStatement */: // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; - var hasWhileKeyword = findChildOfKind(n, 102 /* WhileKeyword */, sourceFile); + var hasWhileKeyword = findChildOfKind(n, 104 /* WhileKeyword */, sourceFile); if (hasWhileKeyword) { return nodeEndsWith(n, 18 /* CloseParenToken */, sourceFile); } return isCompletedNode(n.statement, sourceFile); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return isCompletedNode(n.exprName, sourceFile); - case 174 /* TypeOfExpression */: - case 173 /* DeleteExpression */: - case 175 /* VoidExpression */: - case 182 /* YieldExpression */: - case 183 /* SpreadElementExpression */: + case 176 /* TypeOfExpression */: + case 175 /* DeleteExpression */: + case 177 /* VoidExpression */: + case 184 /* YieldExpression */: + case 185 /* SpreadElementExpression */: var unaryWordExpression = n; return isCompletedNode(unaryWordExpression.expression, sourceFile); - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: return isCompletedNode(n.template, sourceFile); - case 181 /* TemplateExpression */: + case 183 /* TemplateExpression */: var lastSpan = ts.lastOrUndefined(n.templateSpans); return isCompletedNode(lastSpan, sourceFile); - case 188 /* TemplateSpan */: + case 190 /* TemplateSpan */: return ts.nodeIsPresent(n.literal); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return isCompletedNode(n.operand, sourceFile); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return isCompletedNode(n.right, sourceFile); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return isCompletedNode(n.whenFalse, sourceFile); default: return true; @@ -38798,7 +39488,7 @@ var ts; // for the position of the relevant node (or comma). var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { // find syntax list that covers the span of the node - if (c.kind === 269 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 271 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -38904,7 +39594,7 @@ var ts; function findPrecedingToken(position, sourceFile, startNode) { return find(startNode || sourceFile); function findRightmostToken(n) { - if (isToken(n) || n.kind === 234 /* JsxText */) { + if (isToken(n) || n.kind === 236 /* JsxText */) { return n; } var children = n.getChildren(); @@ -38912,7 +39602,7 @@ var ts; return candidate && findRightmostToken(candidate); } function find(n) { - if (isToken(n) || n.kind === 234 /* JsxText */) { + if (isToken(n) || n.kind === 236 /* JsxText */) { return n; } var children = n.getChildren(); @@ -38926,10 +39616,10 @@ var ts; // if no - position is in the node itself so we should recurse in it. // NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia). // if this is the case - then we should assume that token in question is located in previous child. - if (position < child.end && (nodeHasTokens(child) || child.kind === 234 /* JsxText */)) { + if (position < child.end && (nodeHasTokens(child) || child.kind === 236 /* JsxText */)) { var start = child.getStart(sourceFile); var lookInPreviousChild = (start >= position) || - (child.kind === 234 /* JsxText */ && start === child.end); // whitespace only JsxText + (child.kind === 236 /* JsxText */ && start === child.end); // whitespace only JsxText if (lookInPreviousChild) { // actual start of the node is past the position - previous token should be at the end of previous child var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i); @@ -38941,7 +39631,7 @@ var ts; } } } - ts.Debug.assert(startNode !== undefined || n.kind === 246 /* SourceFile */); + ts.Debug.assert(startNode !== undefined || n.kind === 248 /* SourceFile */); // Here we know that none of child token nodes embrace the position, // the only known case is when position is at the end of the file. // Try to find the rightmost token in the file without filtering. @@ -39016,9 +39706,9 @@ var ts; var node = ts.getTokenAtPosition(sourceFile, position); if (isToken(node)) { switch (node.kind) { - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: // if the current token is var, let or const, skip the VariableDeclarationList node = node.parent === undefined ? undefined : node.parent.parent; break; @@ -39067,21 +39757,21 @@ var ts; } ts.getNodeModifiers = getNodeModifiers; function getTypeArgumentOrTypeParameterList(node) { - if (node.kind === 149 /* TypeReference */ || node.kind === 166 /* CallExpression */) { + if (node.kind === 151 /* TypeReference */ || node.kind === 168 /* CallExpression */) { return node.typeArguments; } - if (ts.isFunctionLike(node) || node.kind === 212 /* ClassDeclaration */ || node.kind === 213 /* InterfaceDeclaration */) { + if (ts.isFunctionLike(node) || node.kind === 214 /* ClassDeclaration */ || node.kind === 215 /* InterfaceDeclaration */) { return node.typeParameters; } return undefined; } ts.getTypeArgumentOrTypeParameterList = getTypeArgumentOrTypeParameterList; function isToken(n) { - return n.kind >= 0 /* FirstToken */ && n.kind <= 132 /* LastToken */; + return n.kind >= 0 /* FirstToken */ && n.kind <= 134 /* LastToken */; } ts.isToken = isToken; function isWord(kind) { - return kind === 67 /* Identifier */ || ts.isKeyword(kind); + return kind === 69 /* Identifier */ || ts.isKeyword(kind); } ts.isWord = isWord; function isPropertyName(kind) { @@ -39091,8 +39781,17 @@ var ts; return kind === 2 /* SingleLineCommentTrivia */ || kind === 3 /* MultiLineCommentTrivia */; } ts.isComment = isComment; + function isStringOrRegularExpressionOrTemplateLiteral(kind) { + if (kind === 9 /* StringLiteral */ + || kind === 10 /* RegularExpressionLiteral */ + || ts.isTemplateLiteralKind(kind)) { + return true; + } + return false; + } + ts.isStringOrRegularExpressionOrTemplateLiteral = isStringOrRegularExpressionOrTemplateLiteral; function isPunctuation(kind) { - return 15 /* FirstPunctuation */ <= kind && kind <= 66 /* LastPunctuation */; + return 15 /* FirstPunctuation */ <= kind && kind <= 68 /* LastPunctuation */; } ts.isPunctuation = isPunctuation; function isInsideTemplateLiteral(node, position) { @@ -39102,9 +39801,9 @@ var ts; ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function isAccessibilityModifier(kind) { switch (kind) { - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: return true; } return false; @@ -39132,7 +39831,7 @@ var ts; var ts; (function (ts) { function isFirstDeclarationOfSymbolParameter(symbol) { - return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 136 /* Parameter */; + return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 138 /* Parameter */; } ts.isFirstDeclarationOfSymbolParameter = isFirstDeclarationOfSymbolParameter; var displayPartWriter = getDisplayPartWriter(); @@ -39154,7 +39853,8 @@ var ts; increaseIndent: function () { indent++; }, decreaseIndent: function () { indent--; }, clear: resetWriter, - trackSymbol: function () { } + trackSymbol: function () { }, + reportInaccessibleThisError: function () { } }; function writeIndent() { if (lineStart) { @@ -39319,7 +40019,7 @@ var ts; ts.getDeclaredName = getDeclaredName; function isImportOrExportSpecifierName(location) { return location.parent && - (location.parent.kind === 224 /* ImportSpecifier */ || location.parent.kind === 228 /* ExportSpecifier */) && + (location.parent.kind === 226 /* ImportSpecifier */ || location.parent.kind === 230 /* ExportSpecifier */) && location.parent.propertyName === location; } ts.isImportOrExportSpecifierName = isImportOrExportSpecifierName; @@ -39347,7 +40047,12 @@ var ts; (function (ts) { var formatting; (function (formatting) { - var scanner = ts.createScanner(2 /* Latest */, /*skipTrivia*/ false); + var standardScanner = ts.createScanner(2 /* Latest */, /*skipTrivia*/ false, 0 /* Standard */); + var jsxScanner = ts.createScanner(2 /* Latest */, /*skipTrivia*/ false, 1 /* JSX */); + /** + * Scanner that is currently used for formatting + */ + var scanner; var ScanAction; (function (ScanAction) { ScanAction[ScanAction["Scan"] = 0] = "Scan"; @@ -39357,6 +40062,8 @@ var ts; ScanAction[ScanAction["RescanJsxIdentifier"] = 4] = "RescanJsxIdentifier"; })(ScanAction || (ScanAction = {})); function getFormattingScanner(sourceFile, startPos, endPos) { + ts.Debug.assert(scanner === undefined); + scanner = sourceFile.languageVariant === 1 /* JSX */ ? jsxScanner : standardScanner; scanner.setText(sourceFile.text); scanner.setTextPos(startPos); var wasNewLine = true; @@ -39371,11 +40078,14 @@ var ts; isOnToken: isOnToken, lastTrailingTriviaWasNewLine: function () { return wasNewLine; }, close: function () { + ts.Debug.assert(scanner !== undefined); lastTokenInfo = undefined; scanner.setText(undefined); + scanner = undefined; } }; function advance() { + ts.Debug.assert(scanner !== undefined); lastTokenInfo = undefined; var isStarted = scanner.getStartPos() !== startPos; if (isStarted) { @@ -39419,10 +40129,10 @@ var ts; if (node) { switch (node.kind) { case 29 /* GreaterThanEqualsToken */: - case 62 /* GreaterThanGreaterThanEqualsToken */: - case 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: - case 43 /* GreaterThanGreaterThanToken */: + case 64 /* GreaterThanGreaterThanEqualsToken */: + case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: + case 44 /* GreaterThanGreaterThanToken */: return true; } } @@ -39431,11 +40141,11 @@ var ts; function shouldRescanJsxIdentifier(node) { if (node.parent) { switch (node.parent.kind) { - case 236 /* JsxAttribute */: - case 233 /* JsxOpeningElement */: - case 235 /* JsxClosingElement */: - case 232 /* JsxSelfClosingElement */: - return node.kind === 67 /* Identifier */; + case 238 /* JsxAttribute */: + case 235 /* JsxOpeningElement */: + case 237 /* JsxClosingElement */: + case 234 /* JsxSelfClosingElement */: + return node.kind === 69 /* Identifier */; } } return false; @@ -39448,9 +40158,10 @@ var ts; container.kind === 14 /* TemplateTail */; } function startsWithSlashToken(t) { - return t === 38 /* SlashToken */ || t === 59 /* SlashEqualsToken */; + return t === 39 /* SlashToken */ || t === 61 /* SlashEqualsToken */; } function readTokenInfo(n) { + ts.Debug.assert(scanner !== undefined); if (!isOnToken()) { // scanner is not on the token (either advance was not called yet or scanner is already past the end position) return { @@ -39500,7 +40211,7 @@ var ts; currentToken = scanner.reScanTemplateToken(); lastScanAction = 3 /* RescanTemplateToken */; } - else if (expectedScanAction === 4 /* RescanJsxIdentifier */ && currentToken === 67 /* Identifier */) { + else if (expectedScanAction === 4 /* RescanJsxIdentifier */ && currentToken === 69 /* Identifier */) { currentToken = scanner.scanJsxIdentifier(); lastScanAction = 4 /* RescanJsxIdentifier */; } @@ -39544,6 +40255,7 @@ var ts; return fixTokenKind(lastTokenInfo, n); } function isOnToken() { + ts.Debug.assert(scanner !== undefined); var current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken(); var startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos(); return startPos < endPos && current !== 1 /* EndOfFileToken */ && !ts.isTrivia(current); @@ -39822,17 +40534,17 @@ var ts; this.IgnoreAfterLineComment = new formatting.Rule(formatting.RuleDescriptor.create3(2 /* SingleLineCommentTrivia */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create1(1 /* Ignore */)); // Space after keyword but not before ; or : or ? this.NoSpaceBeforeSemicolon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceBeforeColon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 53 /* ColonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); - this.NoSpaceBeforeQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52 /* QuestionToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); - this.SpaceAfterColon = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* ColonToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 2 /* Space */)); - this.SpaceAfterQuestionMarkInConditionalOperator = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsConditionalOperatorContext), 2 /* Space */)); - this.NoSpaceAfterQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeColon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 54 /* ColonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); + this.NoSpaceBeforeQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 53 /* QuestionToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); + this.SpaceAfterColon = new formatting.Rule(formatting.RuleDescriptor.create3(54 /* ColonToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 2 /* Space */)); + this.SpaceAfterQuestionMarkInConditionalOperator = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsConditionalOperatorContext), 2 /* Space */)); + this.NoSpaceAfterQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterSemicolon = new formatting.Rule(formatting.RuleDescriptor.create3(23 /* SemicolonToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Space after }. this.SpaceAfterCloseBrace = new formatting.Rule(formatting.RuleDescriptor.create3(16 /* CloseBraceToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsAfterCodeBlockContext), 2 /* Space */)); // Special case for (}, else) and (}, while) since else & while tokens are not part of the tree which makes SpaceAfterCloseBrace rule not applied - this.SpaceBetweenCloseBraceAndElse = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 78 /* ElseKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceBetweenCloseBraceAndWhile = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 102 /* WhileKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenCloseBraceAndElse = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 80 /* ElseKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenCloseBraceAndWhile = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 104 /* WhileKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterCloseBrace = new formatting.Rule(formatting.RuleDescriptor.create3(16 /* CloseBraceToken */, formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 20 /* CloseBracketToken */, 24 /* CommaToken */, 23 /* SemicolonToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // No space for dot this.NoSpaceBeforeDot = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 21 /* DotToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); @@ -39844,10 +40556,10 @@ var ts; this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc) - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 3 /* MultiLineCommentTrivia */, 71 /* ClassKeyword */]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 3 /* MultiLineCommentTrivia */, 73 /* ClassKeyword */]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a control flow construct - this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 77 /* DoKeyword */, 98 /* TryKeyword */, 83 /* FinallyKeyword */, 78 /* ElseKeyword */]); + this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 79 /* DoKeyword */, 100 /* TryKeyword */, 85 /* FinallyKeyword */, 80 /* ElseKeyword */]); this.SpaceBeforeOpenBraceInControl = new formatting.Rule(formatting.RuleDescriptor.create2(this.ControlOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}. this.SpaceAfterOpenBrace = new formatting.Rule(formatting.RuleDescriptor.create3(15 /* OpenBraceToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSingleLineBlockContext), 2 /* Space */)); @@ -39861,55 +40573,55 @@ var ts; // Prefix operators generally shouldn't have a space between // them and their target unary expression. this.NoSpaceAfterUnaryPrefixOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.UnaryPrefixOperators, formatting.Shared.TokenRange.UnaryPrefixExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); - this.NoSpaceAfterUnaryPreincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(40 /* PlusPlusToken */, formatting.Shared.TokenRange.UnaryPreincrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceAfterUnaryPredecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(41 /* MinusMinusToken */, formatting.Shared.TokenRange.UnaryPredecrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceBeforeUnaryPostincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostincrementExpressions, 40 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceBeforeUnaryPostdecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostdecrementExpressions, 41 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterUnaryPreincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(41 /* PlusPlusToken */, formatting.Shared.TokenRange.UnaryPreincrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterUnaryPredecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(42 /* MinusMinusToken */, formatting.Shared.TokenRange.UnaryPredecrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeUnaryPostincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostincrementExpressions, 41 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeUnaryPostdecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostdecrementExpressions, 42 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // More unary operator special-casing. // DevDiv 181814: Be careful when removing leading whitespace // around unary operators. Examples: // 1 - -2 --X--> 1--2 // a + ++b --X--> a+++b - this.SpaceAfterPostincrementWhenFollowedByAdd = new formatting.Rule(formatting.RuleDescriptor.create1(40 /* PlusPlusToken */, 35 /* PlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterPostincrementWhenFollowedByAdd = new formatting.Rule(formatting.RuleDescriptor.create1(41 /* PlusPlusToken */, 35 /* PlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.SpaceAfterAddWhenFollowedByUnaryPlus = new formatting.Rule(formatting.RuleDescriptor.create1(35 /* PlusToken */, 35 /* PlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); - this.SpaceAfterAddWhenFollowedByPreincrement = new formatting.Rule(formatting.RuleDescriptor.create1(35 /* PlusToken */, 40 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); - this.SpaceAfterPostdecrementWhenFollowedBySubtract = new formatting.Rule(formatting.RuleDescriptor.create1(41 /* MinusMinusToken */, 36 /* MinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterAddWhenFollowedByPreincrement = new formatting.Rule(formatting.RuleDescriptor.create1(35 /* PlusToken */, 41 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterPostdecrementWhenFollowedBySubtract = new formatting.Rule(formatting.RuleDescriptor.create1(42 /* MinusMinusToken */, 36 /* MinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.SpaceAfterSubtractWhenFollowedByUnaryMinus = new formatting.Rule(formatting.RuleDescriptor.create1(36 /* MinusToken */, 36 /* MinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); - this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(36 /* MinusToken */, 41 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(36 /* MinusToken */, 42 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 24 /* CommaToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([100 /* VarKeyword */, 96 /* ThrowKeyword */, 90 /* NewKeyword */, 76 /* DeleteKeyword */, 92 /* ReturnKeyword */, 99 /* TypeOfKeyword */, 117 /* AwaitKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([106 /* LetKeyword */, 72 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); + this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([102 /* VarKeyword */, 98 /* ThrowKeyword */, 92 /* NewKeyword */, 78 /* DeleteKeyword */, 94 /* ReturnKeyword */, 101 /* TypeOfKeyword */, 119 /* AwaitKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([108 /* LetKeyword */, 74 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8 /* Delete */)); - this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(85 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(87 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8 /* Delete */)); - this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(101 /* VoidKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), 2 /* Space */)); - this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(92 /* ReturnKeyword */, 23 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(103 /* VoidKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), 2 /* Space */)); + this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(94 /* ReturnKeyword */, 23 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Add a space between statements. All keywords except (do,else,case) has open/close parens after them. // So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any] - this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 77 /* DoKeyword */, 78 /* ElseKeyword */, 69 /* CaseKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2 /* Space */)); + this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 79 /* DoKeyword */, 80 /* ElseKeyword */, 71 /* CaseKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2 /* Space */)); // This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter. - this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([98 /* TryKeyword */, 83 /* FinallyKeyword */]), 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([100 /* TryKeyword */, 85 /* FinallyKeyword */]), 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // get x() {} // set x(val) {} - this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([121 /* GetKeyword */, 127 /* SetKeyword */]), 67 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([123 /* GetKeyword */, 129 /* SetKeyword */]), 69 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); // Special case for binary operators (that are keywords). For these we have to add a space and shouldn't follow any user options. this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); // TypeScript-specific higher priority rules // Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses - this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(119 /* ConstructorKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(121 /* ConstructorKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Use of module as a function call. e.g.: import m2 = module("m2"); - this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([123 /* ModuleKeyword */, 125 /* RequireKeyword */]), 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([125 /* ModuleKeyword */, 127 /* RequireKeyword */]), 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([113 /* AbstractKeyword */, 71 /* ClassKeyword */, 120 /* DeclareKeyword */, 75 /* DefaultKeyword */, 79 /* EnumKeyword */, 80 /* ExportKeyword */, 81 /* ExtendsKeyword */, 121 /* GetKeyword */, 104 /* ImplementsKeyword */, 87 /* ImportKeyword */, 105 /* InterfaceKeyword */, 123 /* ModuleKeyword */, 124 /* NamespaceKeyword */, 108 /* PrivateKeyword */, 110 /* PublicKeyword */, 109 /* ProtectedKeyword */, 127 /* SetKeyword */, 111 /* StaticKeyword */, 130 /* TypeKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([81 /* ExtendsKeyword */, 104 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 73 /* ClassKeyword */, 122 /* DeclareKeyword */, 77 /* DefaultKeyword */, 81 /* EnumKeyword */, 82 /* ExportKeyword */, 83 /* ExtendsKeyword */, 123 /* GetKeyword */, 106 /* ImplementsKeyword */, 89 /* ImportKeyword */, 107 /* InterfaceKeyword */, 125 /* ModuleKeyword */, 126 /* NamespaceKeyword */, 110 /* PrivateKeyword */, 112 /* PublicKeyword */, 111 /* ProtectedKeyword */, 129 /* SetKeyword */, 113 /* StaticKeyword */, 132 /* TypeKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83 /* ExtendsKeyword */, 106 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9 /* StringLiteral */, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); // Lambda expressions this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(34 /* EqualsGreaterThanToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Optional parameters and let args - this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(22 /* DotDotDotToken */, 67 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceAfterOptionalParameters = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* QuestionToken */, formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 24 /* CommaToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); + this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(22 /* DotDotDotToken */, 69 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterOptionalParameters = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* QuestionToken */, formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 24 /* CommaToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); // generics and type assertions this.NoSpaceBeforeOpenAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.TypeNames, 25 /* LessThanToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8 /* Delete */)); this.NoSpaceBetweenCloseParenAndAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create1(18 /* CloseParenToken */, 25 /* LessThanToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8 /* Delete */)); @@ -39920,17 +40632,20 @@ var ts; // Remove spaces in empty interface literals. e.g.: x: {} this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(15 /* OpenBraceToken */, 16 /* CloseBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), 8 /* Delete */)); // decorators - this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 54 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(54 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([113 /* AbstractKeyword */, 67 /* Identifier */, 80 /* ExportKeyword */, 75 /* DefaultKeyword */, 71 /* ClassKeyword */, 111 /* StaticKeyword */, 110 /* PublicKeyword */, 108 /* PrivateKeyword */, 109 /* ProtectedKeyword */, 121 /* GetKeyword */, 127 /* SetKeyword */, 19 /* OpenBracketToken */, 37 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); - this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(85 /* FunctionKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8 /* Delete */)); - this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(37 /* AsteriskToken */, formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 17 /* OpenParenToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2 /* Space */)); - this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(112 /* YieldKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8 /* Delete */)); - this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([112 /* YieldKeyword */, 37 /* AsteriskToken */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2 /* Space */)); + this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 55 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(55 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 69 /* Identifier */, 82 /* ExportKeyword */, 77 /* DefaultKeyword */, 73 /* ClassKeyword */, 113 /* StaticKeyword */, 112 /* PublicKeyword */, 110 /* PrivateKeyword */, 111 /* ProtectedKeyword */, 123 /* GetKeyword */, 129 /* SetKeyword */, 19 /* OpenBracketToken */, 37 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); + this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(87 /* FunctionKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8 /* Delete */)); + this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(37 /* AsteriskToken */, formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 17 /* OpenParenToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2 /* Space */)); + this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(114 /* YieldKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8 /* Delete */)); + this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([114 /* YieldKeyword */, 37 /* AsteriskToken */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2 /* Space */)); // Async-await - this.SpaceBetweenAsyncAndFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(116 /* AsyncKeyword */, 85 /* FunctionKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenAsyncAndOpenParen = new formatting.Rule(formatting.RuleDescriptor.create1(118 /* AsyncKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsArrowFunctionContext, Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenAsyncAndFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(118 /* AsyncKeyword */, 87 /* FunctionKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // template string - this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(67 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(69 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.NoSpaceAfterTemplateHeadAndMiddle = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([12 /* TemplateHead */, 13 /* TemplateMiddle */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeTemplateMiddleAndTail = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([13 /* TemplateMiddle */, 14 /* TemplateTail */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -39957,8 +40672,8 @@ var ts; this.NoSpaceBeforeOpenParenInFuncCall, this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, this.SpaceAfterVoidOperator, - this.SpaceBetweenAsyncAndFunctionKeyword, - this.SpaceBetweenTagAndTemplateString, + this.SpaceBetweenAsyncAndOpenParen, this.SpaceBetweenAsyncAndFunctionKeyword, + this.SpaceBetweenTagAndTemplateString, this.NoSpaceAfterTemplateHeadAndMiddle, this.NoSpaceBeforeTemplateMiddleAndTail, // TypeScript-specific rules this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, @@ -40026,14 +40741,14 @@ var ts; this.NoSpaceAfterOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19 /* OpenBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.NoSpaceBeforeCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 20 /* CloseBracketToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Insert space after function keyword for anonymous functions - this.SpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(85 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); - this.NoSpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(85 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 8 /* Delete */)); + this.SpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(87 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.NoSpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(87 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 8 /* Delete */)); } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_30 in o) { - if (o[name_30] === rule) { - return name_30; + for (var name_31 in o) { + if (o[name_31] === rule) { + return name_31; } } throw new Error("Unknown rule"); @@ -40042,40 +40757,40 @@ var ts; /// Contexts /// Rules.IsForContext = function (context) { - return context.contextNode.kind === 197 /* ForStatement */; + return context.contextNode.kind === 199 /* ForStatement */; }; Rules.IsNotForContext = function (context) { return !Rules.IsForContext(context); }; Rules.IsBinaryOpContext = function (context) { switch (context.contextNode.kind) { - case 179 /* BinaryExpression */: - case 180 /* ConditionalExpression */: - case 187 /* AsExpression */: - case 148 /* TypePredicate */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: + case 181 /* BinaryExpression */: + case 182 /* ConditionalExpression */: + case 189 /* AsExpression */: + case 150 /* TypePredicate */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: return true; // equals in binding elements: function foo([[x, y] = [1, 2]]) - case 161 /* BindingElement */: + case 163 /* BindingElement */: // equals in type X = ... - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: // equal in import a = module('a'); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: // equal in let a = 0; - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: // equal in p = 0; - case 136 /* Parameter */: - case 245 /* EnumMember */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - return context.currentTokenSpan.kind === 55 /* EqualsToken */ || context.nextTokenSpan.kind === 55 /* EqualsToken */; + case 138 /* Parameter */: + case 247 /* EnumMember */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + return context.currentTokenSpan.kind === 56 /* EqualsToken */ || context.nextTokenSpan.kind === 56 /* EqualsToken */; // "in" keyword in for (let x in []) { } - case 198 /* ForInStatement */: - return context.currentTokenSpan.kind === 88 /* InKeyword */ || context.nextTokenSpan.kind === 88 /* InKeyword */; + case 200 /* ForInStatement */: + return context.currentTokenSpan.kind === 90 /* InKeyword */ || context.nextTokenSpan.kind === 90 /* InKeyword */; // Technically, "of" is not a binary operator, but format it the same way as "in" - case 199 /* ForOfStatement */: - return context.currentTokenSpan.kind === 132 /* OfKeyword */ || context.nextTokenSpan.kind === 132 /* OfKeyword */; + case 201 /* ForOfStatement */: + return context.currentTokenSpan.kind === 134 /* OfKeyword */ || context.nextTokenSpan.kind === 134 /* OfKeyword */; } return false; }; @@ -40083,7 +40798,7 @@ var ts; return !Rules.IsBinaryOpContext(context); }; Rules.IsConditionalOperatorContext = function (context) { - return context.contextNode.kind === 180 /* ConditionalExpression */; + return context.contextNode.kind === 182 /* ConditionalExpression */; }; Rules.IsSameLineTokenOrBeforeMultilineBlockContext = function (context) { //// This check is mainly used inside SpaceBeforeOpenBraceInControl and SpaceBeforeOpenBraceInFunction. @@ -40127,93 +40842,93 @@ var ts; return true; } switch (node.kind) { - case 190 /* Block */: - case 218 /* CaseBlock */: - case 163 /* ObjectLiteralExpression */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 220 /* CaseBlock */: + case 165 /* ObjectLiteralExpression */: + case 219 /* ModuleBlock */: return true; } return false; }; Rules.IsFunctionDeclContext = function (context) { switch (context.contextNode.kind) { - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: //case SyntaxKind.MemberFunctionDeclaration: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: ///case SyntaxKind.MethodSignature: - case 145 /* CallSignature */: - case 171 /* FunctionExpression */: - case 142 /* Constructor */: - case 172 /* ArrowFunction */: + case 147 /* CallSignature */: + case 173 /* FunctionExpression */: + case 144 /* Constructor */: + case 174 /* ArrowFunction */: //case SyntaxKind.ConstructorDeclaration: //case SyntaxKind.SimpleArrowFunctionExpression: //case SyntaxKind.ParenthesizedArrowFunctionExpression: - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return true; } return false; }; Rules.IsFunctionDeclarationOrFunctionExpressionContext = function (context) { - return context.contextNode.kind === 211 /* FunctionDeclaration */ || context.contextNode.kind === 171 /* FunctionExpression */; + return context.contextNode.kind === 213 /* FunctionDeclaration */ || context.contextNode.kind === 173 /* FunctionExpression */; }; Rules.IsTypeScriptDeclWithBlockContext = function (context) { return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode); }; Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) { switch (node.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 153 /* TypeLiteral */: - case 216 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 155 /* TypeLiteral */: + case 218 /* ModuleDeclaration */: return true; } return false; }; Rules.IsAfterCodeBlockContext = function (context) { switch (context.currentTokenParent.kind) { - case 212 /* ClassDeclaration */: - case 216 /* ModuleDeclaration */: - case 215 /* EnumDeclaration */: - case 190 /* Block */: - case 242 /* CatchClause */: - case 217 /* ModuleBlock */: - case 204 /* SwitchStatement */: + case 214 /* ClassDeclaration */: + case 218 /* ModuleDeclaration */: + case 217 /* EnumDeclaration */: + case 192 /* Block */: + case 244 /* CatchClause */: + case 219 /* ModuleBlock */: + case 206 /* SwitchStatement */: return true; } return false; }; Rules.IsControlDeclContext = function (context) { switch (context.contextNode.kind) { - case 194 /* IfStatement */: - case 204 /* SwitchStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 196 /* WhileStatement */: - case 207 /* TryStatement */: - case 195 /* DoStatement */: - case 203 /* WithStatement */: + case 196 /* IfStatement */: + case 206 /* SwitchStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 198 /* WhileStatement */: + case 209 /* TryStatement */: + case 197 /* DoStatement */: + case 205 /* WithStatement */: // TODO // case SyntaxKind.ElseClause: - case 242 /* CatchClause */: + case 244 /* CatchClause */: return true; default: return false; } }; Rules.IsObjectContext = function (context) { - return context.contextNode.kind === 163 /* ObjectLiteralExpression */; + return context.contextNode.kind === 165 /* ObjectLiteralExpression */; }; Rules.IsFunctionCallContext = function (context) { - return context.contextNode.kind === 166 /* CallExpression */; + return context.contextNode.kind === 168 /* CallExpression */; }; Rules.IsNewContext = function (context) { - return context.contextNode.kind === 167 /* NewExpression */; + return context.contextNode.kind === 169 /* NewExpression */; }; Rules.IsFunctionCallOrNewContext = function (context) { return Rules.IsFunctionCallContext(context) || Rules.IsNewContext(context); @@ -40221,6 +40936,9 @@ var ts; Rules.IsPreviousTokenNotComma = function (context) { return context.currentTokenSpan.kind !== 24 /* CommaToken */; }; + Rules.IsArrowFunctionContext = function (context) { + return context.contextNode.kind === 174 /* ArrowFunction */; + }; Rules.IsSameLineTokenContext = function (context) { return context.TokensAreOnSameLine(); }; @@ -40237,41 +40955,41 @@ var ts; while (ts.isExpression(node)) { node = node.parent; } - return node.kind === 137 /* Decorator */; + return node.kind === 139 /* Decorator */; }; Rules.IsStartOfVariableDeclarationList = function (context) { - return context.currentTokenParent.kind === 210 /* VariableDeclarationList */ && + return context.currentTokenParent.kind === 212 /* VariableDeclarationList */ && context.currentTokenParent.getStart(context.sourceFile) === context.currentTokenSpan.pos; }; Rules.IsNotFormatOnEnter = function (context) { return context.formattingRequestKind !== 2 /* FormatOnEnter */; }; Rules.IsModuleDeclContext = function (context) { - return context.contextNode.kind === 216 /* ModuleDeclaration */; + return context.contextNode.kind === 218 /* ModuleDeclaration */; }; Rules.IsObjectTypeContext = function (context) { - return context.contextNode.kind === 153 /* TypeLiteral */; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration; + return context.contextNode.kind === 155 /* TypeLiteral */; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration; }; Rules.IsTypeArgumentOrParameterOrAssertion = function (token, parent) { if (token.kind !== 25 /* LessThanToken */ && token.kind !== 27 /* GreaterThanToken */) { return false; } switch (parent.kind) { - case 149 /* TypeReference */: - case 169 /* TypeAssertionExpression */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 186 /* ExpressionWithTypeArguments */: + case 151 /* TypeReference */: + case 171 /* TypeAssertionExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 188 /* ExpressionWithTypeArguments */: return true; default: return false; @@ -40282,13 +41000,13 @@ var ts; Rules.IsTypeArgumentOrParameterOrAssertion(context.nextTokenSpan, context.nextTokenParent); }; Rules.IsTypeAssertionContext = function (context) { - return context.contextNode.kind === 169 /* TypeAssertionExpression */; + return context.contextNode.kind === 171 /* TypeAssertionExpression */; }; Rules.IsVoidOpContext = function (context) { - return context.currentTokenSpan.kind === 101 /* VoidKeyword */ && context.currentTokenParent.kind === 175 /* VoidExpression */; + return context.currentTokenSpan.kind === 103 /* VoidKeyword */ && context.currentTokenParent.kind === 177 /* VoidExpression */; }; Rules.IsYieldOrYieldStarWithOperand = function (context) { - return context.contextNode.kind === 182 /* YieldExpression */ && context.contextNode.expression !== undefined; + return context.contextNode.kind === 184 /* YieldExpression */ && context.contextNode.expression !== undefined; }; return Rules; })(); @@ -40312,7 +41030,7 @@ var ts; return result; }; RulesMap.prototype.Initialize = function (rules) { - this.mapRowLength = 132 /* LastToken */ + 1; + this.mapRowLength = 134 /* LastToken */ + 1; this.map = new Array(this.mapRowLength * this.mapRowLength); //new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map var rulesBucketConstructionStateList = new Array(this.map.length); //new Array(this.map.length); @@ -40507,7 +41225,7 @@ var ts; } TokenAllAccess.prototype.GetTokens = function () { var result = []; - for (var token = 0 /* FirstToken */; token <= 132 /* LastToken */; token++) { + for (var token = 0 /* FirstToken */; token <= 134 /* LastToken */; token++) { result.push(token); } return result; @@ -40549,17 +41267,17 @@ var ts; }; TokenRange.Any = TokenRange.AllTokens(); TokenRange.AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([3 /* MultiLineCommentTrivia */])); - TokenRange.Keywords = TokenRange.FromRange(68 /* FirstKeyword */, 132 /* LastKeyword */); - TokenRange.BinaryOperators = TokenRange.FromRange(25 /* FirstBinaryOperator */, 66 /* LastBinaryOperator */); - TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([88 /* InKeyword */, 89 /* InstanceOfKeyword */, 132 /* OfKeyword */, 114 /* AsKeyword */, 122 /* IsKeyword */]); - TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([40 /* PlusPlusToken */, 41 /* MinusMinusToken */, 49 /* TildeToken */, 48 /* ExclamationToken */]); - TokenRange.UnaryPrefixExpressions = TokenRange.FromTokens([8 /* NumericLiteral */, 67 /* Identifier */, 17 /* OpenParenToken */, 19 /* OpenBracketToken */, 15 /* OpenBraceToken */, 95 /* ThisKeyword */, 90 /* NewKeyword */]); - TokenRange.UnaryPreincrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 17 /* OpenParenToken */, 95 /* ThisKeyword */, 90 /* NewKeyword */]); - TokenRange.UnaryPostincrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 90 /* NewKeyword */]); - TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 17 /* OpenParenToken */, 95 /* ThisKeyword */, 90 /* NewKeyword */]); - TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 90 /* NewKeyword */]); + TokenRange.Keywords = TokenRange.FromRange(70 /* FirstKeyword */, 134 /* LastKeyword */); + TokenRange.BinaryOperators = TokenRange.FromRange(25 /* FirstBinaryOperator */, 68 /* LastBinaryOperator */); + TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([90 /* InKeyword */, 91 /* InstanceOfKeyword */, 134 /* OfKeyword */, 116 /* AsKeyword */, 124 /* IsKeyword */]); + TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([41 /* PlusPlusToken */, 42 /* MinusMinusToken */, 50 /* TildeToken */, 49 /* ExclamationToken */]); + TokenRange.UnaryPrefixExpressions = TokenRange.FromTokens([8 /* NumericLiteral */, 69 /* Identifier */, 17 /* OpenParenToken */, 19 /* OpenBracketToken */, 15 /* OpenBraceToken */, 97 /* ThisKeyword */, 92 /* NewKeyword */]); + TokenRange.UnaryPreincrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 17 /* OpenParenToken */, 97 /* ThisKeyword */, 92 /* NewKeyword */]); + TokenRange.UnaryPostincrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 92 /* NewKeyword */]); + TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 17 /* OpenParenToken */, 97 /* ThisKeyword */, 92 /* NewKeyword */]); + TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 92 /* NewKeyword */]); TokenRange.Comments = TokenRange.FromTokens([2 /* SingleLineCommentTrivia */, 3 /* MultiLineCommentTrivia */]); - TokenRange.TypeNames = TokenRange.FromTokens([67 /* Identifier */, 126 /* NumberKeyword */, 128 /* StringKeyword */, 118 /* BooleanKeyword */, 129 /* SymbolKeyword */, 101 /* VoidKeyword */, 115 /* AnyKeyword */]); + TokenRange.TypeNames = TokenRange.FromTokens([69 /* Identifier */, 128 /* NumberKeyword */, 130 /* StringKeyword */, 120 /* BooleanKeyword */, 131 /* SymbolKeyword */, 103 /* VoidKeyword */, 117 /* AnyKeyword */]); return TokenRange; })(); Shared.TokenRange = TokenRange; @@ -40773,17 +41491,17 @@ var ts; // i.e. parent is class declaration with the list of members and node is one of members. function isListElement(parent, node) { switch (parent.kind) { - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: return ts.rangeContainsRange(parent.members, node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: var body = parent.body; - return body && body.kind === 190 /* Block */ && ts.rangeContainsRange(body.statements, node); - case 246 /* SourceFile */: - case 190 /* Block */: - case 217 /* ModuleBlock */: + return body && body.kind === 192 /* Block */ && ts.rangeContainsRange(body.statements, node); + case 248 /* SourceFile */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return ts.rangeContainsRange(parent.statements, node); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return ts.rangeContainsRange(parent.block.statements, node); } return false; @@ -40956,9 +41674,9 @@ var ts; // - source file // - switch\default clauses if (isSomeBlock(parent.kind) || - parent.kind === 246 /* SourceFile */ || - parent.kind === 239 /* CaseClause */ || - parent.kind === 240 /* DefaultClause */) { + parent.kind === 248 /* SourceFile */ || + parent.kind === 241 /* CaseClause */ || + parent.kind === 242 /* DefaultClause */) { indentation = parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(); } else { @@ -40994,19 +41712,19 @@ var ts; return node.modifiers[0].kind; } switch (node.kind) { - case 212 /* ClassDeclaration */: return 71 /* ClassKeyword */; - case 213 /* InterfaceDeclaration */: return 105 /* InterfaceKeyword */; - case 211 /* FunctionDeclaration */: return 85 /* FunctionKeyword */; - case 215 /* EnumDeclaration */: return 215 /* EnumDeclaration */; - case 143 /* GetAccessor */: return 121 /* GetKeyword */; - case 144 /* SetAccessor */: return 127 /* SetKeyword */; - case 141 /* MethodDeclaration */: + case 214 /* ClassDeclaration */: return 73 /* ClassKeyword */; + case 215 /* InterfaceDeclaration */: return 107 /* InterfaceKeyword */; + case 213 /* FunctionDeclaration */: return 87 /* FunctionKeyword */; + case 217 /* EnumDeclaration */: return 217 /* EnumDeclaration */; + case 145 /* GetAccessor */: return 123 /* GetKeyword */; + case 146 /* SetAccessor */: return 129 /* SetKeyword */; + case 143 /* MethodDeclaration */: if (node.asteriskToken) { return 37 /* AsteriskToken */; } // fall-through - case 139 /* PropertyDeclaration */: - case 136 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 138 /* Parameter */: return node.name.kind; } } @@ -41040,9 +41758,9 @@ var ts; case 20 /* CloseBracketToken */: case 17 /* OpenParenToken */: case 18 /* CloseParenToken */: - case 78 /* ElseKeyword */: - case 102 /* WhileKeyword */: - case 54 /* AtToken */: + case 80 /* ElseKeyword */: + case 104 /* WhileKeyword */: + case 55 /* AtToken */: return indentation; default: // if token line equals to the line of containing node (this is a first token in the node) - use node indentation @@ -41142,7 +41860,7 @@ var ts; consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation); return inheritedIndentation; } - var effectiveParentStartLine = child.kind === 137 /* Decorator */ ? childStartLine : undecoratedParentStartLine; + var effectiveParentStartLine = child.kind === 139 /* Decorator */ ? childStartLine : undecoratedParentStartLine; var childIndentation = computeIndentation(child, childStartLine, childIndentationAmount, node, parentDynamicIndentation, effectiveParentStartLine); processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta); childContextNode = node; @@ -41399,8 +42117,8 @@ var ts; for (var line = line1; line < line2; ++line) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); - // do not trim whitespaces in comments - if (range && ts.isComment(range.kind) && range.pos <= lineEndPosition && range.end > lineEndPosition) { + // do not trim whitespaces in comments or template expression + if (range && (ts.isComment(range.kind) || ts.isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) { continue; } var pos = lineEndPosition; @@ -41466,20 +42184,20 @@ var ts; } function isSomeBlock(kind) { switch (kind) { - case 190 /* Block */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return true; } return false; } function getOpenTokenForList(node, list) { switch (node.kind) { - case 142 /* Constructor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 172 /* ArrowFunction */: + case 144 /* Constructor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 174 /* ArrowFunction */: if (node.typeParameters === list) { return 25 /* LessThanToken */; } @@ -41487,8 +42205,8 @@ var ts; return 17 /* OpenParenToken */; } break; - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: if (node.typeArguments === list) { return 25 /* LessThanToken */; } @@ -41496,7 +42214,7 @@ var ts; return 17 /* OpenParenToken */; } break; - case 149 /* TypeReference */: + case 151 /* TypeReference */: if (node.typeArguments === list) { return 25 /* LessThanToken */; } @@ -41580,22 +42298,39 @@ var ts; if (position > sourceFile.text.length) { return 0; // past EOF } + // no indentation when the indent style is set to none, + // so we can return fast + if (options.IndentStyle === ts.IndentStyle.None) { + return 0; + } var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { return 0; } // no indentation in string \regex\template literals - var precedingTokenIsLiteral = precedingToken.kind === 9 /* StringLiteral */ || - precedingToken.kind === 10 /* RegularExpressionLiteral */ || - precedingToken.kind === 11 /* NoSubstitutionTemplateLiteral */ || - precedingToken.kind === 12 /* TemplateHead */ || - precedingToken.kind === 13 /* TemplateMiddle */ || - precedingToken.kind === 14 /* TemplateTail */; + var precedingTokenIsLiteral = ts.isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind); if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } var lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line; - if (precedingToken.kind === 24 /* CommaToken */ && precedingToken.parent.kind !== 179 /* BinaryExpression */) { + // indentation is first non-whitespace character in a previous line + // for block indentation, we should look for a line which contains something that's not + // whitespace. + if (options.IndentStyle === ts.IndentStyle.Block) { + // move backwards until we find a line with a non-whitespace character, + // then find the first non-whitespace character for that line. + var current_1 = position; + while (current_1 > 0) { + var char = sourceFile.text.charCodeAt(current_1); + if (!ts.isWhiteSpace(char) && !ts.isLineBreak(char)) { + break; + } + current_1--; + } + var lineStart = ts.getLineStartPositionForPosition(current_1, sourceFile); + return SmartIndenter.findFirstNonWhitespaceColumn(lineStart, current_1, sourceFile, options); + } + if (precedingToken.kind === 24 /* CommaToken */ && precedingToken.parent.kind !== 181 /* BinaryExpression */) { // previous token is comma that separates items in list - find the previous item and try to derive indentation from it var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options); if (actualIndentation !== -1 /* Unknown */) { @@ -41714,7 +42449,7 @@ var ts; // - parent is SourceFile - by default immediate children of SourceFile are not indented except when user indents them manually // - parent and child are not on the same line var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && - (parent.kind === 246 /* SourceFile */ || !parentAndChildShareLine); + (parent.kind === 248 /* SourceFile */ || !parentAndChildShareLine); if (!useActualIndentation) { return -1 /* Unknown */; } @@ -41747,8 +42482,8 @@ var ts; return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); } function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) { - if (parent.kind === 194 /* IfStatement */ && parent.elseStatement === child) { - var elseKeyword = ts.findChildOfKind(parent, 78 /* ElseKeyword */, sourceFile); + if (parent.kind === 196 /* IfStatement */ && parent.elseStatement === child) { + var elseKeyword = ts.findChildOfKind(parent, 80 /* ElseKeyword */, sourceFile); ts.Debug.assert(elseKeyword !== undefined); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; return elseKeywordStartLine === childStartLine; @@ -41759,23 +42494,23 @@ var ts; function getContainingList(node, sourceFile) { if (node.parent) { switch (node.parent.kind) { - case 149 /* TypeReference */: + case 151 /* TypeReference */: if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, node.getStart(sourceFile), node.getEnd())) { return node.parent.typeArguments; } break; - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return node.parent.properties; - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return node.parent.elements; - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: { + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: { var start = node.getStart(sourceFile); if (node.parent.typeParameters && ts.rangeContainsStartEnd(node.parent.typeParameters, start, node.getEnd())) { @@ -41786,8 +42521,8 @@ var ts; } break; } - case 167 /* NewExpression */: - case 166 /* CallExpression */: { + case 169 /* NewExpression */: + case 168 /* CallExpression */: { var start = node.getStart(sourceFile); if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, start, node.getEnd())) { @@ -41817,8 +42552,8 @@ var ts; if (node.kind === 18 /* CloseParenToken */) { return -1 /* Unknown */; } - if (node.parent && (node.parent.kind === 166 /* CallExpression */ || - node.parent.kind === 167 /* NewExpression */) && + if (node.parent && (node.parent.kind === 168 /* CallExpression */ || + node.parent.kind === 169 /* NewExpression */) && node.parent.expression !== node) { var fullCallOrNewExpression = node.parent.expression; var startingExpression = getStartingExpression(fullCallOrNewExpression); @@ -41836,10 +42571,10 @@ var ts; function getStartingExpression(node) { while (true) { switch (node.kind) { - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: node = node.expression; break; default: @@ -41904,42 +42639,43 @@ var ts; SmartIndenter.findFirstNonWhitespaceColumn = findFirstNonWhitespaceColumn; function nodeContentIsAlwaysIndented(kind) { switch (kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 162 /* ArrayLiteralExpression */: - case 190 /* Block */: - case 217 /* ModuleBlock */: - case 163 /* ObjectLiteralExpression */: - case 153 /* TypeLiteral */: - case 155 /* TupleType */: - case 218 /* CaseBlock */: - case 240 /* DefaultClause */: - case 239 /* CaseClause */: - case 170 /* ParenthesizedExpression */: - case 164 /* PropertyAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 191 /* VariableStatement */: - case 209 /* VariableDeclaration */: - case 225 /* ExportAssignment */: - case 202 /* ReturnStatement */: - case 180 /* ConditionalExpression */: - case 160 /* ArrayBindingPattern */: - case 159 /* ObjectBindingPattern */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 140 /* MethodSignature */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 136 /* Parameter */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 158 /* ParenthesizedType */: - case 168 /* TaggedTemplateExpression */: - case 176 /* AwaitExpression */: + case 195 /* ExpressionStatement */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 164 /* ArrayLiteralExpression */: + case 192 /* Block */: + case 219 /* ModuleBlock */: + case 165 /* ObjectLiteralExpression */: + case 155 /* TypeLiteral */: + case 157 /* TupleType */: + case 220 /* CaseBlock */: + case 242 /* DefaultClause */: + case 241 /* CaseClause */: + case 172 /* ParenthesizedExpression */: + case 166 /* PropertyAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 193 /* VariableStatement */: + case 211 /* VariableDeclaration */: + case 227 /* ExportAssignment */: + case 204 /* ReturnStatement */: + case 182 /* ConditionalExpression */: + case 162 /* ArrayBindingPattern */: + case 161 /* ObjectBindingPattern */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 142 /* MethodSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 138 /* Parameter */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 160 /* ParenthesizedType */: + case 170 /* TaggedTemplateExpression */: + case 178 /* AwaitExpression */: return true; } return false; @@ -41949,20 +42685,20 @@ var ts; return true; } switch (parent) { - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 197 /* ForStatement */: - case 194 /* IfStatement */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 141 /* MethodDeclaration */: - case 172 /* ArrowFunction */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - return child !== 190 /* Block */; + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 199 /* ForStatement */: + case 196 /* IfStatement */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 174 /* ArrowFunction */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + return child !== 192 /* Block */; default: return false; } @@ -42104,7 +42840,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(269 /* SyntaxList */, nodes.pos, nodes.end, 4096 /* Synthetic */, this); + var list = createNode(271 /* SyntaxList */, nodes.pos, nodes.end, 4096 /* Synthetic */, this); list._children = []; var pos = nodes.pos; for (var _i = 0; _i < nodes.length; _i++) { @@ -42123,7 +42859,7 @@ var ts; NodeObject.prototype.createChildren = function (sourceFile) { var _this = this; var children; - if (this.kind >= 133 /* FirstNode */) { + if (this.kind >= 135 /* FirstNode */) { scanner.setText((sourceFile || this.getSourceFile()).text); children = []; var pos = this.pos; @@ -42170,7 +42906,7 @@ var ts; return undefined; } var child = children[0]; - return child.kind < 133 /* FirstNode */ ? child : child.getFirstToken(sourceFile); + return child.kind < 135 /* FirstNode */ ? child : child.getFirstToken(sourceFile); }; NodeObject.prototype.getLastToken = function (sourceFile) { var children = this.getChildren(sourceFile); @@ -42178,7 +42914,7 @@ var ts; if (!child) { return undefined; } - return child.kind < 133 /* FirstNode */ ? child : child.getLastToken(sourceFile); + return child.kind < 135 /* FirstNode */ ? child : child.getLastToken(sourceFile); }; return NodeObject; })(); @@ -42227,7 +42963,7 @@ var ts; if (ts.indexOf(declarations, declaration) === indexOfDeclaration) { var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); // If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments - if (canUseParsedParamTagComments && declaration.kind === 136 /* Parameter */) { + if (canUseParsedParamTagComments && declaration.kind === 138 /* Parameter */) { ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedParamJsDocComment) { @@ -42236,15 +42972,15 @@ var ts; }); } // If this is left side of dotted module declaration, there is no doc comments associated with this node - if (declaration.kind === 216 /* ModuleDeclaration */ && declaration.body.kind === 216 /* ModuleDeclaration */) { + if (declaration.kind === 218 /* ModuleDeclaration */ && declaration.body.kind === 218 /* ModuleDeclaration */) { return; } // If this is dotted module name, get the doc comments from the parent - while (declaration.kind === 216 /* ModuleDeclaration */ && declaration.parent.kind === 216 /* ModuleDeclaration */) { + while (declaration.kind === 218 /* ModuleDeclaration */ && declaration.parent.kind === 218 /* ModuleDeclaration */) { declaration = declaration.parent; } // Get the cleaned js doc comment text from the declaration - ts.forEach(getJsDocCommentTextRange(declaration.kind === 209 /* VariableDeclaration */ ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + ts.forEach(getJsDocCommentTextRange(declaration.kind === 211 /* VariableDeclaration */ ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { ts.addRange(jsDocCommentParts, cleanedJsDocComment); @@ -42588,9 +43324,9 @@ var ts; if (result_2 !== undefined) { return result_2; } - if (declaration.name.kind === 134 /* ComputedPropertyName */) { + if (declaration.name.kind === 136 /* ComputedPropertyName */) { var expr = declaration.name.expression; - if (expr.kind === 164 /* PropertyAccessExpression */) { + if (expr.kind === 166 /* PropertyAccessExpression */) { return expr.name.text; } return getTextOfIdentifierOrLiteral(expr); @@ -42600,7 +43336,7 @@ var ts; } function getTextOfIdentifierOrLiteral(node) { if (node) { - if (node.kind === 67 /* Identifier */ || + if (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) { return node.text; @@ -42610,9 +43346,9 @@ var ts; } function visit(node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: var functionDeclaration = node; var declarationName = getDeclarationName(functionDeclaration); if (declarationName) { @@ -42632,60 +43368,60 @@ var ts; ts.forEachChild(node, visit); } break; - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 215 /* EnumDeclaration */: - case 216 /* ModuleDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 228 /* ExportSpecifier */: - case 224 /* ImportSpecifier */: - case 219 /* ImportEqualsDeclaration */: - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 153 /* TypeLiteral */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 217 /* EnumDeclaration */: + case 218 /* ModuleDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 230 /* ExportSpecifier */: + case 226 /* ImportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 155 /* TypeLiteral */: addDeclaration(node); // fall through - case 142 /* Constructor */: - case 191 /* VariableStatement */: - case 210 /* VariableDeclarationList */: - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: - case 217 /* ModuleBlock */: + case 144 /* Constructor */: + case 193 /* VariableStatement */: + case 212 /* VariableDeclarationList */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: + case 219 /* ModuleBlock */: ts.forEachChild(node, visit); break; - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionBlock(node)) { ts.forEachChild(node, visit); } break; - case 136 /* Parameter */: + case 138 /* Parameter */: // Only consider properties defined as constructor parameters if (!(node.flags & 112 /* AccessibilityModifier */)) { break; } // fall through - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: if (ts.isBindingPattern(node.name)) { ts.forEachChild(node.name, visit); break; } - case 245 /* EnumMember */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 247 /* EnumMember */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: addDeclaration(node); break; - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: // Handle named exports case e.g.: // export {a, b as B} from "mod"; if (node.exportClause) { ts.forEach(node.exportClause.elements, visit); } break; - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: var importClause = node.importClause; if (importClause) { // Handle default import case e.g.: @@ -42697,7 +43433,7 @@ var ts; // import * as NS from "mod"; // import {a, b as B} from "mod"; if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (importClause.namedBindings.kind === 224 /* NamespaceImport */) { addDeclaration(importClause.namedBindings); } else { @@ -42724,6 +43460,12 @@ var ts; HighlightSpanKind.reference = "reference"; HighlightSpanKind.writtenReference = "writtenReference"; })(HighlightSpanKind = ts.HighlightSpanKind || (ts.HighlightSpanKind = {})); + (function (IndentStyle) { + IndentStyle[IndentStyle["None"] = 0] = "None"; + IndentStyle[IndentStyle["Block"] = 1] = "Block"; + IndentStyle[IndentStyle["Smart"] = 2] = "Smart"; + })(ts.IndentStyle || (ts.IndentStyle = {})); + var IndentStyle = ts.IndentStyle; (function (SymbolDisplayPartKind) { SymbolDisplayPartKind[SymbolDisplayPartKind["aliasName"] = 0] = "aliasName"; SymbolDisplayPartKind[SymbolDisplayPartKind["className"] = 1] = "className"; @@ -42901,16 +43643,16 @@ var ts; } return ts.forEach(symbol.declarations, function (declaration) { // Function expressions are local - if (declaration.kind === 171 /* FunctionExpression */) { + if (declaration.kind === 173 /* FunctionExpression */) { return true; } - if (declaration.kind !== 209 /* VariableDeclaration */ && declaration.kind !== 211 /* FunctionDeclaration */) { + if (declaration.kind !== 211 /* VariableDeclaration */ && declaration.kind !== 213 /* FunctionDeclaration */) { return false; } // If the parent is not sourceFile or module block it is local variable for (var parent_8 = declaration.parent; !ts.isFunctionBlock(parent_8); parent_8 = parent_8.parent) { // Reached source file or module block - if (parent_8.kind === 246 /* SourceFile */ || parent_8.kind === 217 /* ModuleBlock */) { + if (parent_8.kind === 248 /* SourceFile */ || parent_8.kind === 219 /* ModuleBlock */) { return false; } } @@ -43047,8 +43789,8 @@ var ts; // We are not doing a full typecheck, we are not resolving the whole context, // so pass --noResolve to avoid reporting missing file errors. options.noResolve = true; - // Parse - var inputFileName = transpileOptions.fileName || "module.ts"; + // if jsx is specified then treat file as .tsx + var inputFileName = transpileOptions.fileName || (options.jsx ? "module.tsx" : "module.ts"); var sourceFile = ts.createSourceFile(inputFileName, input, options.target); if (transpileOptions.moduleName) { sourceFile.moduleName = transpileOptions.moduleName; @@ -43310,10 +44052,10 @@ var ts; // export {a as b} from "mod" // export import i = require("mod") while (token !== 1 /* EndOfFileToken */) { - if (token === 120 /* DeclareKeyword */) { + if (token === 122 /* DeclareKeyword */) { // declare module "mod" token = scanner.scan(); - if (token === 123 /* ModuleKeyword */) { + if (token === 125 /* ModuleKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { recordAmbientExternalModule(); @@ -43321,7 +44063,7 @@ var ts; } } } - else if (token === 87 /* ImportKeyword */) { + else if (token === 89 /* ImportKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import "mod"; @@ -43329,9 +44071,9 @@ var ts; continue; } else { - if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + if (token === 69 /* Identifier */ || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import d from "mod"; @@ -43339,9 +44081,9 @@ var ts; continue; } } - else if (token === 55 /* EqualsToken */) { + else if (token === 56 /* EqualsToken */) { token = scanner.scan(); - if (token === 125 /* RequireKeyword */) { + if (token === 127 /* RequireKeyword */) { token = scanner.scan(); if (token === 17 /* OpenParenToken */) { token = scanner.scan(); @@ -43370,7 +44112,7 @@ var ts; } if (token === 16 /* CloseBraceToken */) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import {a as A} from "mod"; @@ -43382,11 +44124,11 @@ var ts; } else if (token === 37 /* AsteriskToken */) { token = scanner.scan(); - if (token === 114 /* AsKeyword */) { + if (token === 116 /* AsKeyword */) { token = scanner.scan(); - if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + if (token === 69 /* Identifier */ || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import * as NS from "mod" @@ -43399,7 +44141,7 @@ var ts; } } } - else if (token === 80 /* ExportKeyword */) { + else if (token === 82 /* ExportKeyword */) { token = scanner.scan(); if (token === 15 /* OpenBraceToken */) { token = scanner.scan(); @@ -43409,7 +44151,7 @@ var ts; } if (token === 16 /* CloseBraceToken */) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // export {a as A} from "mod"; @@ -43421,7 +44163,7 @@ var ts; } else if (token === 37 /* AsteriskToken */) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // export * from "mod" @@ -43429,13 +44171,13 @@ var ts; } } } - else if (token === 87 /* ImportKeyword */) { + else if (token === 89 /* ImportKeyword */) { token = scanner.scan(); - if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + if (token === 69 /* Identifier */ || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 55 /* EqualsToken */) { + if (token === 56 /* EqualsToken */) { token = scanner.scan(); - if (token === 125 /* RequireKeyword */) { + if (token === 127 /* RequireKeyword */) { token = scanner.scan(); if (token === 17 /* OpenParenToken */) { token = scanner.scan(); @@ -43463,7 +44205,7 @@ var ts; /// Helpers function getTargetLabel(referenceNode, labelName) { while (referenceNode) { - if (referenceNode.kind === 205 /* LabeledStatement */ && referenceNode.label.text === labelName) { + if (referenceNode.kind === 207 /* LabeledStatement */ && referenceNode.label.text === labelName) { return referenceNode.label; } referenceNode = referenceNode.parent; @@ -43471,13 +44213,13 @@ var ts; return undefined; } function isJumpStatementTarget(node) { - return node.kind === 67 /* Identifier */ && - (node.parent.kind === 201 /* BreakStatement */ || node.parent.kind === 200 /* ContinueStatement */) && + return node.kind === 69 /* Identifier */ && + (node.parent.kind === 203 /* BreakStatement */ || node.parent.kind === 202 /* ContinueStatement */) && node.parent.label === node; } function isLabelOfLabeledStatement(node) { - return node.kind === 67 /* Identifier */ && - node.parent.kind === 205 /* LabeledStatement */ && + return node.kind === 69 /* Identifier */ && + node.parent.kind === 207 /* LabeledStatement */ && node.parent.label === node; } /** @@ -43485,7 +44227,7 @@ var ts; * Note: 'node' cannot be a SourceFile. */ function isLabeledBy(node, labelName) { - for (var owner = node.parent; owner.kind === 205 /* LabeledStatement */; owner = owner.parent) { + for (var owner = node.parent; owner.kind === 207 /* LabeledStatement */; owner = owner.parent) { if (owner.label.text === labelName) { return true; } @@ -43496,49 +44238,49 @@ var ts; return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } function isRightSideOfQualifiedName(node) { - return node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node; + return node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node; } function isRightSideOfPropertyAccess(node) { - return node && node.parent && node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node; + return node && node.parent && node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.name === node; } function isCallExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 166 /* CallExpression */ && node.parent.expression === node; + return node && node.parent && node.parent.kind === 168 /* CallExpression */ && node.parent.expression === node; } function isNewExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 167 /* NewExpression */ && node.parent.expression === node; + return node && node.parent && node.parent.kind === 169 /* NewExpression */ && node.parent.expression === node; } function isNameOfModuleDeclaration(node) { - return node.parent.kind === 216 /* ModuleDeclaration */ && node.parent.name === node; + return node.parent.kind === 218 /* ModuleDeclaration */ && node.parent.name === node; } function isNameOfFunctionDeclaration(node) { - return node.kind === 67 /* Identifier */ && + return node.kind === 69 /* Identifier */ && ts.isFunctionLike(node.parent) && node.parent.name === node; } /** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */ function isNameOfPropertyAssignment(node) { - return (node.kind === 67 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) && - (node.parent.kind === 243 /* PropertyAssignment */ || node.parent.kind === 244 /* ShorthandPropertyAssignment */) && node.parent.name === node; + return (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) && + (node.parent.kind === 245 /* PropertyAssignment */ || node.parent.kind === 246 /* ShorthandPropertyAssignment */) && node.parent.name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node) { if (node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) { switch (node.parent.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 243 /* PropertyAssignment */: - case 245 /* EnumMember */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 216 /* ModuleDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 245 /* PropertyAssignment */: + case 247 /* EnumMember */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 218 /* ModuleDeclaration */: return node.parent.name === node; - case 165 /* ElementAccessExpression */: + case 167 /* ElementAccessExpression */: return node.parent.argumentExpression === node; } } @@ -43597,7 +44339,7 @@ var ts; })(BreakContinueSearchType || (BreakContinueSearchType = {})); // A cache of completion entries for keywords, these do not change between sessions var keywordCompletions = []; - for (var i = 68 /* FirstKeyword */; i <= 132 /* LastKeyword */; i++) { + for (var i = 70 /* FirstKeyword */; i <= 134 /* LastKeyword */; i++) { keywordCompletions.push({ name: ts.tokenToString(i), kind: ScriptElementKind.keyword, @@ -43612,17 +44354,17 @@ var ts; return undefined; } switch (node.kind) { - case 246 /* SourceFile */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 216 /* ModuleDeclaration */: + case 248 /* SourceFile */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 218 /* ModuleDeclaration */: return node; } } @@ -43630,38 +44372,38 @@ var ts; ts.getContainerNode = getContainerNode; /* @internal */ function getNodeKind(node) { switch (node.kind) { - case 216 /* ModuleDeclaration */: return ScriptElementKind.moduleElement; - case 212 /* ClassDeclaration */: return ScriptElementKind.classElement; - case 213 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement; - case 214 /* TypeAliasDeclaration */: return ScriptElementKind.typeElement; - case 215 /* EnumDeclaration */: return ScriptElementKind.enumElement; - case 209 /* VariableDeclaration */: + case 218 /* ModuleDeclaration */: return ScriptElementKind.moduleElement; + case 214 /* ClassDeclaration */: return ScriptElementKind.classElement; + case 215 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement; + case 216 /* TypeAliasDeclaration */: return ScriptElementKind.typeElement; + case 217 /* EnumDeclaration */: return ScriptElementKind.enumElement; + case 211 /* VariableDeclaration */: return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; - case 211 /* FunctionDeclaration */: return ScriptElementKind.functionElement; - case 143 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement; - case 144 /* SetAccessor */: return ScriptElementKind.memberSetAccessorElement; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 213 /* FunctionDeclaration */: return ScriptElementKind.functionElement; + case 145 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement; + case 146 /* SetAccessor */: return ScriptElementKind.memberSetAccessorElement; + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return ScriptElementKind.memberFunctionElement; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return ScriptElementKind.memberVariableElement; - case 147 /* IndexSignature */: return ScriptElementKind.indexSignatureElement; - case 146 /* ConstructSignature */: return ScriptElementKind.constructSignatureElement; - case 145 /* CallSignature */: return ScriptElementKind.callSignatureElement; - case 142 /* Constructor */: return ScriptElementKind.constructorImplementationElement; - case 135 /* TypeParameter */: return ScriptElementKind.typeParameterElement; - case 245 /* EnumMember */: return ScriptElementKind.variableElement; - case 136 /* Parameter */: return (node.flags & 112 /* AccessibilityModifier */) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; - case 219 /* ImportEqualsDeclaration */: - case 224 /* ImportSpecifier */: - case 221 /* ImportClause */: - case 228 /* ExportSpecifier */: - case 222 /* NamespaceImport */: + case 149 /* IndexSignature */: return ScriptElementKind.indexSignatureElement; + case 148 /* ConstructSignature */: return ScriptElementKind.constructSignatureElement; + case 147 /* CallSignature */: return ScriptElementKind.callSignatureElement; + case 144 /* Constructor */: return ScriptElementKind.constructorImplementationElement; + case 137 /* TypeParameter */: return ScriptElementKind.typeParameterElement; + case 247 /* EnumMember */: return ScriptElementKind.variableElement; + case 138 /* Parameter */: return (node.flags & 112 /* AccessibilityModifier */) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; + case 221 /* ImportEqualsDeclaration */: + case 226 /* ImportSpecifier */: + case 223 /* ImportClause */: + case 230 /* ExportSpecifier */: + case 224 /* NamespaceImport */: return ScriptElementKind.alias; } return ScriptElementKind.unknown; @@ -43907,44 +44649,44 @@ var ts; return false; } switch (node.kind) { - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.import_can_only_be_used_in_a_ts_file)); return true; - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.export_can_only_be_used_in_a_ts_file)); return true; - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var classDeclaration = node; if (checkModifiers(classDeclaration.modifiers) || checkTypeParameters(classDeclaration.typeParameters)) { return true; } break; - case 241 /* HeritageClause */: + case 243 /* HeritageClause */: var heritageClause = node; - if (heritageClause.token === 104 /* ImplementsKeyword */) { + if (heritageClause.token === 106 /* ImplementsKeyword */) { diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); return true; } break; - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file)); return true; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.module_declarations_can_only_be_used_in_a_ts_file)); return true; - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.type_aliases_can_only_be_used_in_a_ts_file)); return true; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: - case 211 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: var functionDeclaration = node; if (checkModifiers(functionDeclaration.modifiers) || checkTypeParameters(functionDeclaration.typeParameters) || @@ -43952,20 +44694,20 @@ var ts; return true; } break; - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: var variableStatement = node; if (checkModifiers(variableStatement.modifiers)) { return true; } break; - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: var variableDeclaration = node; if (checkTypeAnnotation(variableDeclaration.type)) { return true; } break; - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: var expression = node; if (expression.typeArguments && expression.typeArguments.length > 0) { var start = expression.typeArguments.pos; @@ -43973,7 +44715,7 @@ var ts; return true; } break; - case 136 /* Parameter */: + case 138 /* Parameter */: var parameter = node; if (parameter.modifiers) { var start = parameter.modifiers.pos; @@ -43989,17 +44731,17 @@ var ts; return true; } break; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.property_declarations_can_only_be_used_in_a_ts_file)); return true; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file)); return true; - case 169 /* TypeAssertionExpression */: + case 171 /* TypeAssertionExpression */: var typeAssertionExpression = node; diagnostics.push(ts.createDiagnosticForNode(typeAssertionExpression.type, ts.Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file)); return true; - case 137 /* Decorator */: + case 139 /* Decorator */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.decorators_can_only_be_used_in_a_ts_file)); return true; } @@ -44025,18 +44767,18 @@ var ts; for (var _i = 0; _i < modifiers.length; _i++) { var modifier = modifiers[_i]; switch (modifier.kind) { - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 120 /* DeclareKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 122 /* DeclareKeyword */: diagnostics.push(ts.createDiagnosticForNode(modifier, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, ts.tokenToString(modifier.kind))); return true; // These are all legal modifiers. - case 111 /* StaticKeyword */: - case 80 /* ExportKeyword */: - case 72 /* ConstKeyword */: - case 75 /* DefaultKeyword */: - case 113 /* AbstractKeyword */: + case 113 /* StaticKeyword */: + case 82 /* ExportKeyword */: + case 74 /* ConstKeyword */: + case 77 /* DefaultKeyword */: + case 115 /* AbstractKeyword */: } } } @@ -44122,9 +44864,9 @@ var ts; isJsDocTagName = true; } switch (tag.kind) { - case 267 /* JSDocTypeTag */: - case 265 /* JSDocParameterTag */: - case 266 /* JSDocReturnTag */: + case 269 /* JSDocTypeTag */: + case 267 /* JSDocParameterTag */: + case 268 /* JSDocReturnTag */: var tagWithExpression = tag; if (tagWithExpression.typeExpression) { insideJsDocTagExpression = tagWithExpression.typeExpression.pos < position && position < tagWithExpression.typeExpression.end; @@ -44161,6 +44903,7 @@ var ts; var node = currentToken; var isRightOfDot = false; var isRightOfOpenTag = false; + var isStartingCloseTag = false; var location = ts.getTouchingPropertyName(sourceFile, position); if (contextToken) { // Bail out if this is a known invalid completion location @@ -44170,11 +44913,11 @@ var ts; } var parent_9 = contextToken.parent, kind = contextToken.kind; if (kind === 21 /* DotToken */) { - if (parent_9.kind === 164 /* PropertyAccessExpression */) { + if (parent_9.kind === 166 /* PropertyAccessExpression */) { node = contextToken.parent.expression; isRightOfDot = true; } - else if (parent_9.kind === 133 /* QualifiedName */) { + else if (parent_9.kind === 135 /* QualifiedName */) { node = contextToken.parent.left; isRightOfDot = true; } @@ -44184,9 +44927,14 @@ var ts; return undefined; } } - else if (kind === 25 /* LessThanToken */ && sourceFile.languageVariant === 1 /* JSX */) { - isRightOfOpenTag = true; - location = contextToken; + else if (sourceFile.languageVariant === 1 /* JSX */) { + if (kind === 25 /* LessThanToken */) { + isRightOfOpenTag = true; + location = contextToken; + } + else if (kind === 39 /* SlashToken */ && contextToken.parent.kind === 237 /* JsxClosingElement */) { + isStartingCloseTag = true; + } } } var semanticStart = new Date().getTime(); @@ -44207,6 +44955,12 @@ var ts; isMemberCompletion = true; isNewIdentifierLocation = false; } + else if (isStartingCloseTag) { + var tagName = contextToken.parent.parent.openingElement.tagName; + symbols = [typeChecker.getSymbolAtLocation(tagName)]; + isMemberCompletion = true; + isNewIdentifierLocation = false; + } else { // For JavaScript or TypeScript, if we're not after a dot, then just try to get the // global symbols in scope. These results should be valid for either language as @@ -44221,7 +44975,7 @@ var ts; // Right of dot member completion list isMemberCompletion = true; isNewIdentifierLocation = false; - if (node.kind === 67 /* Identifier */ || node.kind === 133 /* QualifiedName */ || node.kind === 164 /* PropertyAccessExpression */) { + if (node.kind === 69 /* Identifier */ || node.kind === 135 /* QualifiedName */ || node.kind === 166 /* PropertyAccessExpression */) { var symbol = typeChecker.getSymbolAtLocation(node); // This is an alias, follow what it aliases if (symbol && symbol.flags & 8388608 /* Alias */) { @@ -44277,7 +45031,7 @@ var ts; } if (jsxContainer = tryGetContainingJsxElement(contextToken)) { var attrsType; - if ((jsxContainer.kind === 232 /* JsxSelfClosingElement */) || (jsxContainer.kind === 233 /* JsxOpeningElement */)) { + if ((jsxContainer.kind === 234 /* JsxSelfClosingElement */) || (jsxContainer.kind === 235 /* JsxOpeningElement */)) { // Cursor is inside a JSX self-closing element or opening element attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); if (attrsType) { @@ -44343,49 +45097,64 @@ var ts; var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || isSolelyIdentifierDefinitionLocation(contextToken) || - isDotOfNumericLiteral(contextToken); + isDotOfNumericLiteral(contextToken) || + isInJsxText(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } + function isInJsxText(contextToken) { + if (contextToken.kind === 236 /* JsxText */) { + return true; + } + if (contextToken.kind === 27 /* GreaterThanToken */ && contextToken.parent) { + if (contextToken.parent.kind === 235 /* JsxOpeningElement */) { + return true; + } + if (contextToken.parent.kind === 237 /* JsxClosingElement */ || contextToken.parent.kind === 234 /* JsxSelfClosingElement */) { + return contextToken.parent.parent && contextToken.parent.parent.kind === 233 /* JsxElement */; + } + } + return false; + } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 24 /* CommaToken */: - return containingNodeKind === 166 /* CallExpression */ // func( a, | - || containingNodeKind === 142 /* Constructor */ // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ - || containingNodeKind === 167 /* NewExpression */ // new C(a, | - || containingNodeKind === 162 /* ArrayLiteralExpression */ // [a, | - || containingNodeKind === 179 /* BinaryExpression */ // let x = (a, | - || containingNodeKind === 150 /* FunctionType */; // var x: (s: string, list| + return containingNodeKind === 168 /* CallExpression */ // func( a, | + || containingNodeKind === 144 /* Constructor */ // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ + || containingNodeKind === 169 /* NewExpression */ // new C(a, | + || containingNodeKind === 164 /* ArrayLiteralExpression */ // [a, | + || containingNodeKind === 181 /* BinaryExpression */ // let x = (a, | + || containingNodeKind === 152 /* FunctionType */; // var x: (s: string, list| case 17 /* OpenParenToken */: - return containingNodeKind === 166 /* CallExpression */ // func( | - || containingNodeKind === 142 /* Constructor */ // constructor( | - || containingNodeKind === 167 /* NewExpression */ // new C(a| - || containingNodeKind === 170 /* ParenthesizedExpression */ // let x = (a| - || containingNodeKind === 158 /* ParenthesizedType */; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */ + return containingNodeKind === 168 /* CallExpression */ // func( | + || containingNodeKind === 144 /* Constructor */ // constructor( | + || containingNodeKind === 169 /* NewExpression */ // new C(a| + || containingNodeKind === 172 /* ParenthesizedExpression */ // let x = (a| + || containingNodeKind === 160 /* ParenthesizedType */; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */ case 19 /* OpenBracketToken */: - return containingNodeKind === 162 /* ArrayLiteralExpression */ // [ | - || containingNodeKind === 147 /* IndexSignature */ // [ | : string ] - || containingNodeKind === 134 /* ComputedPropertyName */; // [ | /* this can become an index signature */ - case 123 /* ModuleKeyword */: // module | - case 124 /* NamespaceKeyword */: + return containingNodeKind === 164 /* ArrayLiteralExpression */ // [ | + || containingNodeKind === 149 /* IndexSignature */ // [ | : string ] + || containingNodeKind === 136 /* ComputedPropertyName */; // [ | /* this can become an index signature */ + case 125 /* ModuleKeyword */: // module | + case 126 /* NamespaceKeyword */: return true; case 21 /* DotToken */: - return containingNodeKind === 216 /* ModuleDeclaration */; // module A.| + return containingNodeKind === 218 /* ModuleDeclaration */; // module A.| case 15 /* OpenBraceToken */: - return containingNodeKind === 212 /* ClassDeclaration */; // class A{ | - case 55 /* EqualsToken */: - return containingNodeKind === 209 /* VariableDeclaration */ // let x = a| - || containingNodeKind === 179 /* BinaryExpression */; // x = a| + return containingNodeKind === 214 /* ClassDeclaration */; // class A{ | + case 56 /* EqualsToken */: + return containingNodeKind === 211 /* VariableDeclaration */ // let x = a| + || containingNodeKind === 181 /* BinaryExpression */; // x = a| case 12 /* TemplateHead */: - return containingNodeKind === 181 /* TemplateExpression */; // `aa ${| + return containingNodeKind === 183 /* TemplateExpression */; // `aa ${| case 13 /* TemplateMiddle */: - return containingNodeKind === 188 /* TemplateSpan */; // `aa ${10} dd ${| - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - return containingNodeKind === 139 /* PropertyDeclaration */; // class A{ public | + return containingNodeKind === 190 /* TemplateSpan */; // `aa ${10} dd ${| + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + return containingNodeKind === 141 /* PropertyDeclaration */; // class A{ public | } // Previous token may have been a keyword that was converted to an identifier. switch (previousToken.getText()) { @@ -44428,14 +45197,14 @@ var ts; isMemberCompletion = true; var typeForObject; var existingMembers; - if (objectLikeContainer.kind === 163 /* ObjectLiteralExpression */) { + if (objectLikeContainer.kind === 165 /* ObjectLiteralExpression */) { // We are completing on contextual types, but may also include properties // other than those within the declared type. isNewIdentifierLocation = true; typeForObject = typeChecker.getContextualType(objectLikeContainer); existingMembers = objectLikeContainer.properties; } - else if (objectLikeContainer.kind === 159 /* ObjectBindingPattern */) { + else if (objectLikeContainer.kind === 161 /* ObjectBindingPattern */) { // We are *only* completing on properties from the type being destructured. isNewIdentifierLocation = false; var rootDeclaration = ts.getRootDeclaration(objectLikeContainer.parent); @@ -44481,9 +45250,9 @@ var ts; * @returns true if 'symbols' was successfully populated; false otherwise. */ function tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports) { - var declarationKind = namedImportsOrExports.kind === 223 /* NamedImports */ ? - 220 /* ImportDeclaration */ : - 226 /* ExportDeclaration */; + var declarationKind = namedImportsOrExports.kind === 225 /* NamedImports */ ? + 222 /* ImportDeclaration */ : + 228 /* ExportDeclaration */; var importOrExportDeclaration = ts.getAncestor(namedImportsOrExports, declarationKind); var moduleSpecifier = importOrExportDeclaration.moduleSpecifier; if (!moduleSpecifier) { @@ -44509,7 +45278,7 @@ var ts; case 15 /* OpenBraceToken */: // let x = { | case 24 /* CommaToken */: var parent_10 = contextToken.parent; - if (parent_10 && (parent_10.kind === 163 /* ObjectLiteralExpression */ || parent_10.kind === 159 /* ObjectBindingPattern */)) { + if (parent_10 && (parent_10.kind === 165 /* ObjectLiteralExpression */ || parent_10.kind === 161 /* ObjectBindingPattern */)) { return parent_10; } break; @@ -44527,8 +45296,8 @@ var ts; case 15 /* OpenBraceToken */: // import { | case 24 /* CommaToken */: switch (contextToken.parent.kind) { - case 223 /* NamedImports */: - case 227 /* NamedExports */: + case 225 /* NamedImports */: + case 229 /* NamedExports */: return contextToken.parent; } } @@ -44540,30 +45309,33 @@ var ts; var parent_11 = contextToken.parent; switch (contextToken.kind) { case 26 /* LessThanSlashToken */: - case 38 /* SlashToken */: - case 67 /* Identifier */: - case 236 /* JsxAttribute */: - case 237 /* JsxSpreadAttribute */: - if (parent_11 && (parent_11.kind === 232 /* JsxSelfClosingElement */ || parent_11.kind === 233 /* JsxOpeningElement */)) { + case 39 /* SlashToken */: + case 69 /* Identifier */: + case 238 /* JsxAttribute */: + case 239 /* JsxSpreadAttribute */: + if (parent_11 && (parent_11.kind === 234 /* JsxSelfClosingElement */ || parent_11.kind === 235 /* JsxOpeningElement */)) { return parent_11; } + else if (parent_11.kind === 238 /* JsxAttribute */) { + return parent_11.parent; + } break; // The context token is the closing } or " of an attribute, which means // its parent is a JsxExpression, whose parent is a JsxAttribute, // whose parent is a JsxOpeningLikeElement case 9 /* StringLiteral */: - if (parent_11 && ((parent_11.kind === 236 /* JsxAttribute */) || (parent_11.kind === 237 /* JsxSpreadAttribute */))) { + if (parent_11 && ((parent_11.kind === 238 /* JsxAttribute */) || (parent_11.kind === 239 /* JsxSpreadAttribute */))) { return parent_11.parent; } break; case 16 /* CloseBraceToken */: if (parent_11 && - parent_11.kind === 238 /* JsxExpression */ && + parent_11.kind === 240 /* JsxExpression */ && parent_11.parent && - (parent_11.parent.kind === 236 /* JsxAttribute */)) { + (parent_11.parent.kind === 238 /* JsxAttribute */)) { return parent_11.parent.parent; } - if (parent_11 && parent_11.kind === 237 /* JsxSpreadAttribute */) { + if (parent_11 && parent_11.kind === 239 /* JsxSpreadAttribute */) { return parent_11.parent; } break; @@ -44573,16 +45345,16 @@ var ts; } function isFunction(kind) { switch (kind) { - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return true; } return false; @@ -44594,78 +45366,84 @@ var ts; var containingNodeKind = contextToken.parent.kind; switch (contextToken.kind) { case 24 /* CommaToken */: - return containingNodeKind === 209 /* VariableDeclaration */ || - containingNodeKind === 210 /* VariableDeclarationList */ || - containingNodeKind === 191 /* VariableStatement */ || - containingNodeKind === 215 /* EnumDeclaration */ || + return containingNodeKind === 211 /* VariableDeclaration */ || + containingNodeKind === 212 /* VariableDeclarationList */ || + containingNodeKind === 193 /* VariableStatement */ || + containingNodeKind === 217 /* EnumDeclaration */ || isFunction(containingNodeKind) || - containingNodeKind === 212 /* ClassDeclaration */ || - containingNodeKind === 184 /* ClassExpression */ || - containingNodeKind === 213 /* InterfaceDeclaration */ || - containingNodeKind === 160 /* ArrayBindingPattern */ || - containingNodeKind === 214 /* TypeAliasDeclaration */; // type Map, K, | + containingNodeKind === 214 /* ClassDeclaration */ || + containingNodeKind === 186 /* ClassExpression */ || + containingNodeKind === 215 /* InterfaceDeclaration */ || + containingNodeKind === 162 /* ArrayBindingPattern */ || + containingNodeKind === 216 /* TypeAliasDeclaration */; // type Map, K, | case 21 /* DotToken */: - return containingNodeKind === 160 /* ArrayBindingPattern */; // var [.| - case 53 /* ColonToken */: - return containingNodeKind === 161 /* BindingElement */; // var {x :html| + return containingNodeKind === 162 /* ArrayBindingPattern */; // var [.| + case 54 /* ColonToken */: + return containingNodeKind === 163 /* BindingElement */; // var {x :html| case 19 /* OpenBracketToken */: - return containingNodeKind === 160 /* ArrayBindingPattern */; // var [x| + return containingNodeKind === 162 /* ArrayBindingPattern */; // var [x| case 17 /* OpenParenToken */: - return containingNodeKind === 242 /* CatchClause */ || + return containingNodeKind === 244 /* CatchClause */ || isFunction(containingNodeKind); case 15 /* OpenBraceToken */: - return containingNodeKind === 215 /* EnumDeclaration */ || - containingNodeKind === 213 /* InterfaceDeclaration */ || - containingNodeKind === 153 /* TypeLiteral */; // let x : { | + return containingNodeKind === 217 /* EnumDeclaration */ || + containingNodeKind === 215 /* InterfaceDeclaration */ || + containingNodeKind === 155 /* TypeLiteral */; // let x : { | case 23 /* SemicolonToken */: - return containingNodeKind === 138 /* PropertySignature */ && + return containingNodeKind === 140 /* PropertySignature */ && contextToken.parent && contextToken.parent.parent && - (contextToken.parent.parent.kind === 213 /* InterfaceDeclaration */ || - contextToken.parent.parent.kind === 153 /* TypeLiteral */); // let x : { a; | + (contextToken.parent.parent.kind === 215 /* InterfaceDeclaration */ || + contextToken.parent.parent.kind === 155 /* TypeLiteral */); // let x : { a; | case 25 /* LessThanToken */: - return containingNodeKind === 212 /* ClassDeclaration */ || - containingNodeKind === 184 /* ClassExpression */ || - containingNodeKind === 213 /* InterfaceDeclaration */ || - containingNodeKind === 214 /* TypeAliasDeclaration */ || + return containingNodeKind === 214 /* ClassDeclaration */ || + containingNodeKind === 186 /* ClassExpression */ || + containingNodeKind === 215 /* InterfaceDeclaration */ || + containingNodeKind === 216 /* TypeAliasDeclaration */ || isFunction(containingNodeKind); - case 111 /* StaticKeyword */: - return containingNodeKind === 139 /* PropertyDeclaration */; + case 113 /* StaticKeyword */: + return containingNodeKind === 141 /* PropertyDeclaration */; case 22 /* DotDotDotToken */: - return containingNodeKind === 136 /* Parameter */ || + return containingNodeKind === 138 /* Parameter */ || (contextToken.parent && contextToken.parent.parent && - contextToken.parent.parent.kind === 160 /* ArrayBindingPattern */); // var [...z| - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - return containingNodeKind === 136 /* Parameter */; - case 114 /* AsKeyword */: - containingNodeKind === 224 /* ImportSpecifier */ || - containingNodeKind === 228 /* ExportSpecifier */ || - containingNodeKind === 222 /* NamespaceImport */; - case 71 /* ClassKeyword */: - case 79 /* EnumKeyword */: - case 105 /* InterfaceKeyword */: - case 85 /* FunctionKeyword */: - case 100 /* VarKeyword */: - case 121 /* GetKeyword */: - case 127 /* SetKeyword */: - case 87 /* ImportKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: - case 112 /* YieldKeyword */: - case 130 /* TypeKeyword */: + contextToken.parent.parent.kind === 162 /* ArrayBindingPattern */); // var [...z| + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + return containingNodeKind === 138 /* Parameter */; + case 116 /* AsKeyword */: + return containingNodeKind === 226 /* ImportSpecifier */ || + containingNodeKind === 230 /* ExportSpecifier */ || + containingNodeKind === 224 /* NamespaceImport */; + case 73 /* ClassKeyword */: + case 81 /* EnumKeyword */: + case 107 /* InterfaceKeyword */: + case 87 /* FunctionKeyword */: + case 102 /* VarKeyword */: + case 123 /* GetKeyword */: + case 129 /* SetKeyword */: + case 89 /* ImportKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: + case 114 /* YieldKeyword */: + case 132 /* TypeKeyword */: return true; } // Previous token may have been a keyword that was converted to an identifier. switch (contextToken.getText()) { + case "abstract": + case "async": case "class": - case "interface": + case "const": + case "declare": case "enum": case "function": - case "var": - case "static": + case "interface": case "let": - case "const": + case "private": + case "protected": + case "public": + case "static": + case "var": case "yield": return true; } @@ -44695,8 +45473,8 @@ var ts; if (element.getStart() <= position && position <= element.getEnd()) { continue; } - var name_31 = element.propertyName || element.name; - exisingImportsOrExports[name_31.text] = true; + var name_32 = element.propertyName || element.name; + exisingImportsOrExports[name_32.text] = true; } if (ts.isEmpty(exisingImportsOrExports)) { return exportsOfModule; @@ -44717,9 +45495,9 @@ var ts; for (var _i = 0; _i < existingMembers.length; _i++) { var m = existingMembers[_i]; // Ignore omitted expressions for missing members - if (m.kind !== 243 /* PropertyAssignment */ && - m.kind !== 244 /* ShorthandPropertyAssignment */ && - m.kind !== 161 /* BindingElement */) { + if (m.kind !== 245 /* PropertyAssignment */ && + m.kind !== 246 /* ShorthandPropertyAssignment */ && + m.kind !== 163 /* BindingElement */) { continue; } // If this is the current item we are editing right now, do not filter it out @@ -44727,7 +45505,7 @@ var ts; continue; } var existingName = void 0; - if (m.kind === 161 /* BindingElement */ && m.propertyName) { + if (m.kind === 163 /* BindingElement */ && m.propertyName) { existingName = m.propertyName.text; } else { @@ -44754,7 +45532,7 @@ var ts; if (attr.getStart() <= position && position <= attr.getEnd()) { continue; } - if (attr.kind === 236 /* JsxAttribute */) { + if (attr.kind === 238 /* JsxAttribute */) { seenNames[attr.name.text] = true; } } @@ -44795,10 +45573,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_32 in nameTable) { - if (!allNames[name_32]) { - allNames[name_32] = name_32; - var displayName = getCompletionEntryDisplayName(name_32, target, /*performCharacterChecks:*/ true); + for (var name_33 in nameTable) { + if (!allNames[name_33]) { + allNames[name_33] = name_33; + var displayName = getCompletionEntryDisplayName(name_33, target, /*performCharacterChecks:*/ true); if (displayName) { var entry = { name: displayName, @@ -44906,7 +45684,7 @@ var ts; function getSymbolKind(symbol, location) { var flags = symbol.getFlags(); if (flags & 32 /* Class */) - return ts.getDeclarationOfKind(symbol, 184 /* ClassExpression */) ? + return ts.getDeclarationOfKind(symbol, 186 /* ClassExpression */) ? ScriptElementKind.localClassElement : ScriptElementKind.classElement; if (flags & 384 /* Enum */) return ScriptElementKind.enumElement; @@ -45008,7 +45786,7 @@ var ts; var signature; type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (type) { - if (location.parent && location.parent.kind === 164 /* PropertyAccessExpression */) { + if (location.parent && location.parent.kind === 166 /* PropertyAccessExpression */) { var right = location.parent.name; // Either the location is on the right of a property access, or on the left and the right is missing if (right === location || (right && right.getFullWidth() === 0)) { @@ -45017,7 +45795,7 @@ var ts; } // try get the call/construct signature from the type if it matches var callExpression; - if (location.kind === 166 /* CallExpression */ || location.kind === 167 /* NewExpression */) { + if (location.kind === 168 /* CallExpression */ || location.kind === 169 /* NewExpression */) { callExpression = location; } else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { @@ -45030,10 +45808,11 @@ var ts; // Use the first candidate: signature = candidateSignatures[0]; } - var useConstructSignatures = callExpression.kind === 167 /* NewExpression */ || callExpression.expression.kind === 93 /* SuperKeyword */; + var useConstructSignatures = callExpression.kind === 169 /* NewExpression */ || callExpression.expression.kind === 95 /* SuperKeyword */; var allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); - if (!ts.contains(allSignatures, signature.target || signature)) { - // Get the first signature if there + if (!ts.contains(allSignatures, signature.target) && !ts.contains(allSignatures, signature)) { + // Get the first signature if there is one -- allSignatures may contain + // either the original signature or its target, so check for either signature = allSignatures.length ? allSignatures[0] : undefined; } if (signature) { @@ -45047,7 +45826,7 @@ var ts; pushTypePart(symbolKind); displayParts.push(ts.spacePart()); if (useConstructSignatures) { - displayParts.push(ts.keywordPart(90 /* NewKeyword */)); + displayParts.push(ts.keywordPart(92 /* NewKeyword */)); displayParts.push(ts.spacePart()); } addFullSymbolName(symbol); @@ -45063,10 +45842,10 @@ var ts; case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: // If it is call or construct signature of lambda's write type name - displayParts.push(ts.punctuationPart(53 /* ColonToken */)); + displayParts.push(ts.punctuationPart(54 /* ColonToken */)); displayParts.push(ts.spacePart()); if (useConstructSignatures) { - displayParts.push(ts.keywordPart(90 /* NewKeyword */)); + displayParts.push(ts.keywordPart(92 /* NewKeyword */)); displayParts.push(ts.spacePart()); } if (!(type.flags & 65536 /* Anonymous */)) { @@ -45082,24 +45861,24 @@ var ts; } } else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304 /* Accessor */)) || - (location.kind === 119 /* ConstructorKeyword */ && location.parent.kind === 142 /* Constructor */)) { + (location.kind === 121 /* ConstructorKeyword */ && location.parent.kind === 144 /* Constructor */)) { // get the signature from the declaration and write it var functionDeclaration = location.parent; - var allSignatures = functionDeclaration.kind === 142 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); + var allSignatures = functionDeclaration.kind === 144 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } else { signature = allSignatures[0]; } - if (functionDeclaration.kind === 142 /* Constructor */) { + if (functionDeclaration.kind === 144 /* Constructor */) { // show (constructor) Type(...) signature symbolKind = ScriptElementKind.constructorImplementationElement; addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); } else { // (function/method) symbol(..signature) - addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 145 /* CallSignature */ && + addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 147 /* CallSignature */ && !(type.symbol.flags & 2048 /* TypeLiteral */ || type.symbol.flags & 4096 /* ObjectLiteral */) ? type.symbol : symbol, symbolKind); } addSignatureDisplayParts(signature, allSignatures); @@ -45108,7 +45887,7 @@ var ts; } } if (symbolFlags & 32 /* Class */ && !hasAddedSymbolInfo) { - if (ts.getDeclarationOfKind(symbol, 184 /* ClassExpression */)) { + if (ts.getDeclarationOfKind(symbol, 186 /* ClassExpression */)) { // Special case for class expressions because we would like to indicate that // the class name is local to the class body (similar to function expression) // (local class) class @@ -45116,7 +45895,7 @@ var ts; } else { // Class declaration has name which is not local. - displayParts.push(ts.keywordPart(71 /* ClassKeyword */)); + displayParts.push(ts.keywordPart(73 /* ClassKeyword */)); } displayParts.push(ts.spacePart()); addFullSymbolName(symbol); @@ -45124,37 +45903,37 @@ var ts; } if ((symbolFlags & 64 /* Interface */) && (semanticMeaning & 2 /* Type */)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(105 /* InterfaceKeyword */)); + displayParts.push(ts.keywordPart(107 /* InterfaceKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if (symbolFlags & 524288 /* TypeAlias */) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(130 /* TypeKeyword */)); + displayParts.push(ts.keywordPart(132 /* TypeKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); ts.addRange(displayParts, ts.typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & 384 /* Enum */) { addNewLineIfDisplayPartsExist(); if (ts.forEach(symbol.declarations, ts.isConstEnumDeclaration)) { - displayParts.push(ts.keywordPart(72 /* ConstKeyword */)); + displayParts.push(ts.keywordPart(74 /* ConstKeyword */)); displayParts.push(ts.spacePart()); } - displayParts.push(ts.keywordPart(79 /* EnumKeyword */)); + displayParts.push(ts.keywordPart(81 /* EnumKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } if (symbolFlags & 1536 /* Module */) { addNewLineIfDisplayPartsExist(); - var declaration = ts.getDeclarationOfKind(symbol, 216 /* ModuleDeclaration */); - var isNamespace = declaration && declaration.name && declaration.name.kind === 67 /* Identifier */; - displayParts.push(ts.keywordPart(isNamespace ? 124 /* NamespaceKeyword */ : 123 /* ModuleKeyword */)); + var declaration = ts.getDeclarationOfKind(symbol, 218 /* ModuleDeclaration */); + var isNamespace = declaration && declaration.name && declaration.name.kind === 69 /* Identifier */; + displayParts.push(ts.keywordPart(isNamespace ? 126 /* NamespaceKeyword */ : 125 /* ModuleKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } @@ -45166,7 +45945,7 @@ var ts; displayParts.push(ts.spacePart()); addFullSymbolName(symbol); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(88 /* InKeyword */)); + displayParts.push(ts.keywordPart(90 /* InKeyword */)); displayParts.push(ts.spacePart()); if (symbol.parent) { // Class/Interface type parameter @@ -45177,13 +45956,13 @@ var ts; // Method/function type parameter var container = ts.getContainingFunction(location); if (container) { - var signatureDeclaration = ts.getDeclarationOfKind(symbol, 135 /* TypeParameter */).parent; + var signatureDeclaration = ts.getDeclarationOfKind(symbol, 137 /* TypeParameter */).parent; var signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration); - if (signatureDeclaration.kind === 146 /* ConstructSignature */) { - displayParts.push(ts.keywordPart(90 /* NewKeyword */)); + if (signatureDeclaration.kind === 148 /* ConstructSignature */) { + displayParts.push(ts.keywordPart(92 /* NewKeyword */)); displayParts.push(ts.spacePart()); } - else if (signatureDeclaration.kind !== 145 /* CallSignature */ && signatureDeclaration.name) { + else if (signatureDeclaration.kind !== 147 /* CallSignature */ && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } ts.addRange(displayParts, ts.signatureToDisplayParts(typeChecker, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); @@ -45192,8 +45971,8 @@ var ts; // Type aliash type parameter // For example // type list = T[]; // Both T will go through same code path - var declaration = ts.getDeclarationOfKind(symbol, 135 /* TypeParameter */).parent; - displayParts.push(ts.keywordPart(130 /* TypeKeyword */)); + var declaration = ts.getDeclarationOfKind(symbol, 137 /* TypeParameter */).parent; + displayParts.push(ts.keywordPart(132 /* TypeKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(declaration.symbol); writeTypeParametersOfSymbol(declaration.symbol, sourceFile); @@ -45203,11 +45982,11 @@ var ts; if (symbolFlags & 8 /* EnumMember */) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); var declaration = symbol.declarations[0]; - if (declaration.kind === 245 /* EnumMember */) { + if (declaration.kind === 247 /* EnumMember */) { var constantValue = typeChecker.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); displayParts.push(ts.displayPart(constantValue.toString(), SymbolDisplayPartKind.numericLiteral)); } @@ -45215,17 +45994,17 @@ var ts; } if (symbolFlags & 8388608 /* Alias */) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(87 /* ImportKeyword */)); + displayParts.push(ts.keywordPart(89 /* ImportKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 219 /* ImportEqualsDeclaration */) { + if (declaration.kind === 221 /* ImportEqualsDeclaration */) { var importEqualsDeclaration = declaration; if (ts.isExternalModuleImportEqualsDeclaration(importEqualsDeclaration)) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(125 /* RequireKeyword */)); + displayParts.push(ts.keywordPart(127 /* RequireKeyword */)); displayParts.push(ts.punctuationPart(17 /* OpenParenToken */)); displayParts.push(ts.displayPart(ts.getTextOfNode(ts.getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), SymbolDisplayPartKind.stringLiteral)); displayParts.push(ts.punctuationPart(18 /* CloseParenToken */)); @@ -45234,7 +46013,7 @@ var ts; var internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); addFullSymbolName(internalAliasSymbol, enclosingDeclaration); } @@ -45251,7 +46030,7 @@ var ts; if (symbolKind === ScriptElementKind.memberVariableElement || symbolFlags & 3 /* Variable */ || symbolKind === ScriptElementKind.localVariableElement) { - displayParts.push(ts.punctuationPart(53 /* ColonToken */)); + displayParts.push(ts.punctuationPart(54 /* ColonToken */)); displayParts.push(ts.spacePart()); // If the type is type parameter, format it specially if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */) { @@ -45351,11 +46130,11 @@ var ts; if (!symbol) { // Try getting just type at this position and show switch (node.kind) { - case 67 /* Identifier */: - case 164 /* PropertyAccessExpression */: - case 133 /* QualifiedName */: - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: + case 69 /* Identifier */: + case 166 /* PropertyAccessExpression */: + case 135 /* QualifiedName */: + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: // For the identifiers/this/super etc get the type at position var type = typeChecker.getTypeAtLocation(node); if (type) { @@ -45408,7 +46187,7 @@ var ts; function tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) { // Applicable only if we are in a new expression, or we are on a constructor declaration // and in either case the symbol has a construct signature definition, i.e. class - if (isNewExpressionTarget(location) || location.kind === 119 /* ConstructorKeyword */) { + if (isNewExpressionTarget(location) || location.kind === 121 /* ConstructorKeyword */) { if (symbol.flags & 32 /* Class */) { // Find the first class-like declaration and try to get the construct signature. for (var _i = 0, _a = symbol.getDeclarations(); _i < _a.length; _i++) { @@ -45433,8 +46212,8 @@ var ts; var declarations = []; var definition; ts.forEach(signatureDeclarations, function (d) { - if ((selectConstructors && d.kind === 142 /* Constructor */) || - (!selectConstructors && (d.kind === 211 /* FunctionDeclaration */ || d.kind === 141 /* MethodDeclaration */ || d.kind === 140 /* MethodSignature */))) { + if ((selectConstructors && d.kind === 144 /* Constructor */) || + (!selectConstructors && (d.kind === 213 /* FunctionDeclaration */ || d.kind === 143 /* MethodDeclaration */ || d.kind === 142 /* MethodSignature */))) { declarations.push(d); if (d.body) definition = d; @@ -45494,7 +46273,7 @@ var ts; // to jump to the implementation directly. if (symbol.flags & 8388608 /* Alias */) { var declaration = symbol.declarations[0]; - if (node.kind === 67 /* Identifier */ && node.parent === declaration) { + if (node.kind === 69 /* Identifier */ && node.parent === declaration) { symbol = typeChecker.getAliasedSymbol(symbol); } } @@ -45503,7 +46282,7 @@ var ts; // go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition // is performed at the location of property access, we would like to go to definition of the property in the short-hand // assignment. This case and others are handled by the following code. - if (node.parent.kind === 244 /* ShorthandPropertyAssignment */) { + if (node.parent.kind === 246 /* ShorthandPropertyAssignment */) { var shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); if (!shorthandSymbol) { return []; @@ -45577,9 +46356,9 @@ var ts; }; } function getSemanticDocumentHighlights(node) { - if (node.kind === 67 /* Identifier */ || - node.kind === 95 /* ThisKeyword */ || - node.kind === 93 /* SuperKeyword */ || + if (node.kind === 69 /* Identifier */ || + node.kind === 97 /* ThisKeyword */ || + node.kind === 95 /* SuperKeyword */ || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { var referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, /*findInStrings:*/ false, /*findInComments:*/ false); @@ -45630,77 +46409,77 @@ var ts; function getHighlightSpans(node) { if (node) { switch (node.kind) { - case 86 /* IfKeyword */: - case 78 /* ElseKeyword */: - if (hasKind(node.parent, 194 /* IfStatement */)) { + case 88 /* IfKeyword */: + case 80 /* ElseKeyword */: + if (hasKind(node.parent, 196 /* IfStatement */)) { return getIfElseOccurrences(node.parent); } break; - case 92 /* ReturnKeyword */: - if (hasKind(node.parent, 202 /* ReturnStatement */)) { + case 94 /* ReturnKeyword */: + if (hasKind(node.parent, 204 /* ReturnStatement */)) { return getReturnOccurrences(node.parent); } break; - case 96 /* ThrowKeyword */: - if (hasKind(node.parent, 206 /* ThrowStatement */)) { + case 98 /* ThrowKeyword */: + if (hasKind(node.parent, 208 /* ThrowStatement */)) { return getThrowOccurrences(node.parent); } break; - case 70 /* CatchKeyword */: - if (hasKind(parent(parent(node)), 207 /* TryStatement */)) { + case 72 /* CatchKeyword */: + if (hasKind(parent(parent(node)), 209 /* TryStatement */)) { return getTryCatchFinallyOccurrences(node.parent.parent); } break; - case 98 /* TryKeyword */: - case 83 /* FinallyKeyword */: - if (hasKind(parent(node), 207 /* TryStatement */)) { + case 100 /* TryKeyword */: + case 85 /* FinallyKeyword */: + if (hasKind(parent(node), 209 /* TryStatement */)) { return getTryCatchFinallyOccurrences(node.parent); } break; - case 94 /* SwitchKeyword */: - if (hasKind(node.parent, 204 /* SwitchStatement */)) { + case 96 /* SwitchKeyword */: + if (hasKind(node.parent, 206 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent); } break; - case 69 /* CaseKeyword */: - case 75 /* DefaultKeyword */: - if (hasKind(parent(parent(parent(node))), 204 /* SwitchStatement */)) { + case 71 /* CaseKeyword */: + case 77 /* DefaultKeyword */: + if (hasKind(parent(parent(parent(node))), 206 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent.parent.parent); } break; - case 68 /* BreakKeyword */: - case 73 /* ContinueKeyword */: - if (hasKind(node.parent, 201 /* BreakStatement */) || hasKind(node.parent, 200 /* ContinueStatement */)) { + case 70 /* BreakKeyword */: + case 75 /* ContinueKeyword */: + if (hasKind(node.parent, 203 /* BreakStatement */) || hasKind(node.parent, 202 /* ContinueStatement */)) { return getBreakOrContinueStatementOccurrences(node.parent); } break; - case 84 /* ForKeyword */: - if (hasKind(node.parent, 197 /* ForStatement */) || - hasKind(node.parent, 198 /* ForInStatement */) || - hasKind(node.parent, 199 /* ForOfStatement */)) { + case 86 /* ForKeyword */: + if (hasKind(node.parent, 199 /* ForStatement */) || + hasKind(node.parent, 200 /* ForInStatement */) || + hasKind(node.parent, 201 /* ForOfStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; - case 102 /* WhileKeyword */: - case 77 /* DoKeyword */: - if (hasKind(node.parent, 196 /* WhileStatement */) || hasKind(node.parent, 195 /* DoStatement */)) { + case 104 /* WhileKeyword */: + case 79 /* DoKeyword */: + if (hasKind(node.parent, 198 /* WhileStatement */) || hasKind(node.parent, 197 /* DoStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; - case 119 /* ConstructorKeyword */: - if (hasKind(node.parent, 142 /* Constructor */)) { + case 121 /* ConstructorKeyword */: + if (hasKind(node.parent, 144 /* Constructor */)) { return getConstructorOccurrences(node.parent); } break; - case 121 /* GetKeyword */: - case 127 /* SetKeyword */: - if (hasKind(node.parent, 143 /* GetAccessor */) || hasKind(node.parent, 144 /* SetAccessor */)) { + case 123 /* GetKeyword */: + case 129 /* SetKeyword */: + if (hasKind(node.parent, 145 /* GetAccessor */) || hasKind(node.parent, 146 /* SetAccessor */)) { return getGetAndSetOccurrences(node.parent); } break; default: if (ts.isModifier(node.kind) && node.parent && - (ts.isDeclaration(node.parent) || node.parent.kind === 191 /* VariableStatement */)) { + (ts.isDeclaration(node.parent) || node.parent.kind === 193 /* VariableStatement */)) { return getModifierOccurrences(node.kind, node.parent); } } @@ -45716,10 +46495,10 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 206 /* ThrowStatement */) { + if (node.kind === 208 /* ThrowStatement */) { statementAccumulator.push(node); } - else if (node.kind === 207 /* TryStatement */) { + else if (node.kind === 209 /* TryStatement */) { var tryStatement = node; if (tryStatement.catchClause) { aggregate(tryStatement.catchClause); @@ -45748,12 +46527,12 @@ var ts; var child = throwStatement; while (child.parent) { var parent_12 = child.parent; - if (ts.isFunctionBlock(parent_12) || parent_12.kind === 246 /* SourceFile */) { + if (ts.isFunctionBlock(parent_12) || parent_12.kind === 248 /* SourceFile */) { return parent_12; } // A throw-statement is only owned by a try-statement if the try-statement has // a catch clause, and if the throw-statement occurs within the try block. - if (parent_12.kind === 207 /* TryStatement */) { + if (parent_12.kind === 209 /* TryStatement */) { var tryStatement = parent_12; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; @@ -45768,7 +46547,7 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 201 /* BreakStatement */ || node.kind === 200 /* ContinueStatement */) { + if (node.kind === 203 /* BreakStatement */ || node.kind === 202 /* ContinueStatement */) { statementAccumulator.push(node); } else if (!ts.isFunctionLike(node)) { @@ -45784,16 +46563,16 @@ var ts; function getBreakOrContinueOwner(statement) { for (var node_2 = statement.parent; node_2; node_2 = node_2.parent) { switch (node_2.kind) { - case 204 /* SwitchStatement */: - if (statement.kind === 200 /* ContinueStatement */) { + case 206 /* SwitchStatement */: + if (statement.kind === 202 /* ContinueStatement */) { continue; } // Fall through. - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 196 /* WhileStatement */: - case 195 /* DoStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 198 /* WhileStatement */: + case 197 /* DoStatement */: if (!statement.label || isLabeledBy(node_2, statement.label.text)) { return node_2; } @@ -45812,24 +46591,24 @@ var ts; var container = declaration.parent; // Make sure we only highlight the keyword when it makes sense to do so. if (ts.isAccessibilityModifier(modifier)) { - if (!(container.kind === 212 /* ClassDeclaration */ || - container.kind === 184 /* ClassExpression */ || - (declaration.kind === 136 /* Parameter */ && hasKind(container, 142 /* Constructor */)))) { + if (!(container.kind === 214 /* ClassDeclaration */ || + container.kind === 186 /* ClassExpression */ || + (declaration.kind === 138 /* Parameter */ && hasKind(container, 144 /* Constructor */)))) { return undefined; } } - else if (modifier === 111 /* StaticKeyword */) { - if (!(container.kind === 212 /* ClassDeclaration */ || container.kind === 184 /* ClassExpression */)) { + else if (modifier === 113 /* StaticKeyword */) { + if (!(container.kind === 214 /* ClassDeclaration */ || container.kind === 186 /* ClassExpression */)) { return undefined; } } - else if (modifier === 80 /* ExportKeyword */ || modifier === 120 /* DeclareKeyword */) { - if (!(container.kind === 217 /* ModuleBlock */ || container.kind === 246 /* SourceFile */)) { + else if (modifier === 82 /* ExportKeyword */ || modifier === 122 /* DeclareKeyword */) { + if (!(container.kind === 219 /* ModuleBlock */ || container.kind === 248 /* SourceFile */)) { return undefined; } } - else if (modifier === 113 /* AbstractKeyword */) { - if (!(container.kind === 212 /* ClassDeclaration */ || declaration.kind === 212 /* ClassDeclaration */)) { + else if (modifier === 115 /* AbstractKeyword */) { + if (!(container.kind === 214 /* ClassDeclaration */ || declaration.kind === 214 /* ClassDeclaration */)) { return undefined; } } @@ -45841,8 +46620,8 @@ var ts; var modifierFlag = getFlagFromModifier(modifier); var nodes; switch (container.kind) { - case 217 /* ModuleBlock */: - case 246 /* SourceFile */: + case 219 /* ModuleBlock */: + case 248 /* SourceFile */: // Container is either a class declaration or the declaration is a classDeclaration if (modifierFlag & 256 /* Abstract */) { nodes = declaration.members.concat(declaration); @@ -45851,17 +46630,17 @@ var ts; nodes = container.statements; } break; - case 142 /* Constructor */: + case 144 /* Constructor */: nodes = container.parameters.concat(container.parent.members); break; - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: nodes = container.members; // If we're an accessibility modifier, we're in an instance member and should search // the constructor's parameter list for instance members as well. if (modifierFlag & 112 /* AccessibilityModifier */) { var constructor = ts.forEach(container.members, function (member) { - return member.kind === 142 /* Constructor */ && member; + return member.kind === 144 /* Constructor */ && member; }); if (constructor) { nodes = nodes.concat(constructor.parameters); @@ -45882,19 +46661,19 @@ var ts; return ts.map(keywords, getHighlightSpanForNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 110 /* PublicKeyword */: + case 112 /* PublicKeyword */: return 16 /* Public */; - case 108 /* PrivateKeyword */: + case 110 /* PrivateKeyword */: return 32 /* Private */; - case 109 /* ProtectedKeyword */: + case 111 /* ProtectedKeyword */: return 64 /* Protected */; - case 111 /* StaticKeyword */: + case 113 /* StaticKeyword */: return 128 /* Static */; - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: return 1 /* Export */; - case 120 /* DeclareKeyword */: + case 122 /* DeclareKeyword */: return 2 /* Ambient */; - case 113 /* AbstractKeyword */: + case 115 /* AbstractKeyword */: return 256 /* Abstract */; default: ts.Debug.fail(); @@ -45914,13 +46693,13 @@ var ts; } function getGetAndSetOccurrences(accessorDeclaration) { var keywords = []; - tryPushAccessorKeyword(accessorDeclaration.symbol, 143 /* GetAccessor */); - tryPushAccessorKeyword(accessorDeclaration.symbol, 144 /* SetAccessor */); + tryPushAccessorKeyword(accessorDeclaration.symbol, 145 /* GetAccessor */); + tryPushAccessorKeyword(accessorDeclaration.symbol, 146 /* SetAccessor */); return ts.map(keywords, getHighlightSpanForNode); function tryPushAccessorKeyword(accessorSymbol, accessorKind) { var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { - ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 121 /* GetKeyword */, 127 /* SetKeyword */); }); + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 123 /* GetKeyword */, 129 /* SetKeyword */); }); } } } @@ -45929,19 +46708,19 @@ var ts; var keywords = []; ts.forEach(declarations, function (declaration) { ts.forEach(declaration.getChildren(), function (token) { - return pushKeywordIf(keywords, token, 119 /* ConstructorKeyword */); + return pushKeywordIf(keywords, token, 121 /* ConstructorKeyword */); }); }); return ts.map(keywords, getHighlightSpanForNode); } function getLoopBreakContinueOccurrences(loopNode) { var keywords = []; - if (pushKeywordIf(keywords, loopNode.getFirstToken(), 84 /* ForKeyword */, 102 /* WhileKeyword */, 77 /* DoKeyword */)) { + if (pushKeywordIf(keywords, loopNode.getFirstToken(), 86 /* ForKeyword */, 104 /* WhileKeyword */, 79 /* DoKeyword */)) { // If we succeeded and got a do-while loop, then start looking for a 'while' keyword. - if (loopNode.kind === 195 /* DoStatement */) { + if (loopNode.kind === 197 /* DoStatement */) { var loopTokens = loopNode.getChildren(); for (var i = loopTokens.length - 1; i >= 0; i--) { - if (pushKeywordIf(keywords, loopTokens[i], 102 /* WhileKeyword */)) { + if (pushKeywordIf(keywords, loopTokens[i], 104 /* WhileKeyword */)) { break; } } @@ -45950,7 +46729,7 @@ var ts; var breaksAndContinues = aggregateAllBreakAndContinueStatements(loopNode.statement); ts.forEach(breaksAndContinues, function (statement) { if (ownsBreakOrContinueStatement(loopNode, statement)) { - pushKeywordIf(keywords, statement.getFirstToken(), 68 /* BreakKeyword */, 73 /* ContinueKeyword */); + pushKeywordIf(keywords, statement.getFirstToken(), 70 /* BreakKeyword */, 75 /* ContinueKeyword */); } }); return ts.map(keywords, getHighlightSpanForNode); @@ -45959,13 +46738,13 @@ var ts; var owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: return getLoopBreakContinueOccurrences(owner); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: return getSwitchCaseDefaultOccurrences(owner); } } @@ -45973,14 +46752,14 @@ var ts; } function getSwitchCaseDefaultOccurrences(switchStatement) { var keywords = []; - pushKeywordIf(keywords, switchStatement.getFirstToken(), 94 /* SwitchKeyword */); + pushKeywordIf(keywords, switchStatement.getFirstToken(), 96 /* SwitchKeyword */); // Go through each clause in the switch statement, collecting the 'case'/'default' keywords. ts.forEach(switchStatement.caseBlock.clauses, function (clause) { - pushKeywordIf(keywords, clause.getFirstToken(), 69 /* CaseKeyword */, 75 /* DefaultKeyword */); + pushKeywordIf(keywords, clause.getFirstToken(), 71 /* CaseKeyword */, 77 /* DefaultKeyword */); var breaksAndContinues = aggregateAllBreakAndContinueStatements(clause); ts.forEach(breaksAndContinues, function (statement) { if (ownsBreakOrContinueStatement(switchStatement, statement)) { - pushKeywordIf(keywords, statement.getFirstToken(), 68 /* BreakKeyword */); + pushKeywordIf(keywords, statement.getFirstToken(), 70 /* BreakKeyword */); } }); }); @@ -45988,13 +46767,13 @@ var ts; } function getTryCatchFinallyOccurrences(tryStatement) { var keywords = []; - pushKeywordIf(keywords, tryStatement.getFirstToken(), 98 /* TryKeyword */); + pushKeywordIf(keywords, tryStatement.getFirstToken(), 100 /* TryKeyword */); if (tryStatement.catchClause) { - pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), 70 /* CatchKeyword */); + pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), 72 /* CatchKeyword */); } if (tryStatement.finallyBlock) { - var finallyKeyword = ts.findChildOfKind(tryStatement, 83 /* FinallyKeyword */, sourceFile); - pushKeywordIf(keywords, finallyKeyword, 83 /* FinallyKeyword */); + var finallyKeyword = ts.findChildOfKind(tryStatement, 85 /* FinallyKeyword */, sourceFile); + pushKeywordIf(keywords, finallyKeyword, 85 /* FinallyKeyword */); } return ts.map(keywords, getHighlightSpanForNode); } @@ -46005,13 +46784,13 @@ var ts; } var keywords = []; ts.forEach(aggregateOwnedThrowStatements(owner), function (throwStatement) { - pushKeywordIf(keywords, throwStatement.getFirstToken(), 96 /* ThrowKeyword */); + pushKeywordIf(keywords, throwStatement.getFirstToken(), 98 /* ThrowKeyword */); }); // If the "owner" is a function, then we equate 'return' and 'throw' statements in their // ability to "jump out" of the function, and include occurrences for both. if (ts.isFunctionBlock(owner)) { ts.forEachReturnStatement(owner, function (returnStatement) { - pushKeywordIf(keywords, returnStatement.getFirstToken(), 92 /* ReturnKeyword */); + pushKeywordIf(keywords, returnStatement.getFirstToken(), 94 /* ReturnKeyword */); }); } return ts.map(keywords, getHighlightSpanForNode); @@ -46019,36 +46798,36 @@ var ts; function getReturnOccurrences(returnStatement) { var func = ts.getContainingFunction(returnStatement); // If we didn't find a containing function with a block body, bail out. - if (!(func && hasKind(func.body, 190 /* Block */))) { + if (!(func && hasKind(func.body, 192 /* Block */))) { return undefined; } var keywords = []; ts.forEachReturnStatement(func.body, function (returnStatement) { - pushKeywordIf(keywords, returnStatement.getFirstToken(), 92 /* ReturnKeyword */); + pushKeywordIf(keywords, returnStatement.getFirstToken(), 94 /* ReturnKeyword */); }); // Include 'throw' statements that do not occur within a try block. ts.forEach(aggregateOwnedThrowStatements(func.body), function (throwStatement) { - pushKeywordIf(keywords, throwStatement.getFirstToken(), 96 /* ThrowKeyword */); + pushKeywordIf(keywords, throwStatement.getFirstToken(), 98 /* ThrowKeyword */); }); return ts.map(keywords, getHighlightSpanForNode); } function getIfElseOccurrences(ifStatement) { var keywords = []; // Traverse upwards through all parent if-statements linked by their else-branches. - while (hasKind(ifStatement.parent, 194 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { + while (hasKind(ifStatement.parent, 196 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { ifStatement = ifStatement.parent; } // Now traverse back down through the else branches, aggregating if/else keywords of if-statements. while (ifStatement) { var children = ifStatement.getChildren(); - pushKeywordIf(keywords, children[0], 86 /* IfKeyword */); + pushKeywordIf(keywords, children[0], 88 /* IfKeyword */); // Generally the 'else' keyword is second-to-last, so we traverse backwards. for (var i = children.length - 1; i >= 0; i--) { - if (pushKeywordIf(keywords, children[i], 78 /* ElseKeyword */)) { + if (pushKeywordIf(keywords, children[i], 80 /* ElseKeyword */)) { break; } } - if (!hasKind(ifStatement.elseStatement, 194 /* IfStatement */)) { + if (!hasKind(ifStatement.elseStatement, 196 /* IfStatement */)) { break; } ifStatement = ifStatement.elseStatement; @@ -46057,7 +46836,7 @@ var ts; // We'd like to highlight else/ifs together if they are only separated by whitespace // (i.e. the keywords are separated by no comments, no newlines). for (var i = 0; i < keywords.length; i++) { - if (keywords[i].kind === 78 /* ElseKeyword */ && i < keywords.length - 1) { + if (keywords[i].kind === 80 /* ElseKeyword */ && i < keywords.length - 1) { var elseKeyword = keywords[i]; var ifKeyword = keywords[i + 1]; // this *should* always be an 'if' keyword. var shouldCombindElseAndIf = true; @@ -46139,7 +46918,7 @@ var ts; if (!node) { return undefined; } - if (node.kind !== 67 /* Identifier */ && + if (node.kind !== 69 /* Identifier */ && // TODO (drosen): This should be enabled in a later release - currently breaks rename. //node.kind !== SyntaxKind.ThisKeyword && //node.kind !== SyntaxKind.SuperKeyword && @@ -46147,7 +46926,7 @@ var ts; !isNameOfExternalModuleImportOrDeclaration(node)) { return undefined; } - ts.Debug.assert(node.kind === 67 /* Identifier */ || node.kind === 8 /* NumericLiteral */ || node.kind === 9 /* StringLiteral */); + ts.Debug.assert(node.kind === 69 /* Identifier */ || node.kind === 8 /* NumericLiteral */ || node.kind === 9 /* StringLiteral */); return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNode(node, sourceFiles, findInStrings, findInComments) { @@ -46165,10 +46944,10 @@ var ts; return getLabelReferencesInNode(node.parent, node); } } - if (node.kind === 95 /* ThisKeyword */) { + if (node.kind === 97 /* ThisKeyword */) { return getReferencesForThisKeyword(node, sourceFiles); } - if (node.kind === 93 /* SuperKeyword */) { + if (node.kind === 95 /* SuperKeyword */) { return getReferencesForSuperKeyword(node); } var symbol = typeChecker.getSymbolAtLocation(node); @@ -46228,7 +47007,7 @@ var ts; } function isImportOrExportSpecifierImportSymbol(symbol) { return (symbol.flags & 8388608 /* Alias */) && ts.forEach(symbol.declarations, function (declaration) { - return declaration.kind === 224 /* ImportSpecifier */ || declaration.kind === 228 /* ExportSpecifier */; + return declaration.kind === 226 /* ImportSpecifier */ || declaration.kind === 230 /* ExportSpecifier */; }); } function getInternedName(symbol, location, declarations) { @@ -46255,14 +47034,14 @@ var ts; // If this is the symbol of a named function expression or named class expression, // then named references are limited to its own scope. var valueDeclaration = symbol.valueDeclaration; - if (valueDeclaration && (valueDeclaration.kind === 171 /* FunctionExpression */ || valueDeclaration.kind === 184 /* ClassExpression */)) { + if (valueDeclaration && (valueDeclaration.kind === 173 /* FunctionExpression */ || valueDeclaration.kind === 186 /* ClassExpression */)) { return valueDeclaration; } // If this is private property or method, the scope is the containing class if (symbol.flags & (4 /* Property */ | 8192 /* Method */)) { var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32 /* Private */) ? d : undefined; }); if (privateDeclaration) { - return ts.getAncestor(privateDeclaration, 212 /* ClassDeclaration */); + return ts.getAncestor(privateDeclaration, 214 /* ClassDeclaration */); } } // If the symbol is an import we would like to find it if we are looking for what it imports. @@ -46288,7 +47067,7 @@ var ts; // Different declarations have different containers, bail out return undefined; } - if (container.kind === 246 /* SourceFile */ && !ts.isExternalModule(container)) { + if (container.kind === 248 /* SourceFile */ && !ts.isExternalModule(container)) { // This is a global variable and not an external module, any declaration defined // within this scope is visible outside the file return undefined; @@ -46359,7 +47138,7 @@ var ts; if (node) { // Compare the length so we filter out strict superstrings of the symbol we are looking for switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: return node.getWidth() === searchSymbolName.length; case 9 /* StringLiteral */: if (isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || @@ -46461,13 +47240,13 @@ var ts; // Whether 'super' occurs in a static context within a class. var staticFlag = 128 /* Static */; switch (searchSpaceNode.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; @@ -46480,7 +47259,7 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || node.kind !== 93 /* SuperKeyword */) { + if (!node || node.kind !== 95 /* SuperKeyword */) { return; } var container = ts.getSuperContainer(node, /*includeFunctions*/ false); @@ -46499,27 +47278,27 @@ var ts; // Whether 'this' occurs in a static context within a class. var staticFlag = 128 /* Static */; switch (searchSpaceNode.kind) { - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (ts.isObjectLiteralMethod(searchSpaceNode)) { break; } // fall through - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (ts.isExternalModule(searchSpaceNode)) { return undefined; } // Fall through - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: break; // Computed properties in classes are not handled here because references to this are illegal, // so there is no point finding references to them. @@ -46528,7 +47307,7 @@ var ts; } var references = []; var possiblePositions; - if (searchSpaceNode.kind === 246 /* SourceFile */) { + if (searchSpaceNode.kind === 248 /* SourceFile */) { ts.forEach(sourceFiles, function (sourceFile) { possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, references); @@ -46554,33 +47333,33 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || node.kind !== 95 /* ThisKeyword */) { + if (!node || node.kind !== 97 /* ThisKeyword */) { return; } var container = ts.getThisContainer(node, /* includeArrowFunctions */ false); switch (searchSpaceNode.kind) { - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: if (searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (ts.isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: // Make sure the container belongs to the same class // and has the appropriate static modifier from the original container. if (container.parent && searchSpaceNode.symbol === container.parent.symbol && (container.flags & 128 /* Static */) === staticFlag) { result.push(getReferenceEntryFromNode(node)); } break; - case 246 /* SourceFile */: - if (container.kind === 246 /* SourceFile */ && !ts.isExternalModule(container)) { + case 248 /* SourceFile */: + if (container.kind === 248 /* SourceFile */ && !ts.isExternalModule(container)) { result.push(getReferenceEntryFromNode(node)); } break; @@ -46634,11 +47413,11 @@ var ts; function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) { if (symbol && symbol.flags & (32 /* Class */ | 64 /* Interface */)) { ts.forEach(symbol.getDeclarations(), function (declaration) { - if (declaration.kind === 212 /* ClassDeclaration */) { + if (declaration.kind === 214 /* ClassDeclaration */) { getPropertySymbolFromTypeReference(ts.getClassExtendsHeritageClauseElement(declaration)); ts.forEach(ts.getClassImplementsHeritageClauseElements(declaration), getPropertySymbolFromTypeReference); } - else if (declaration.kind === 213 /* InterfaceDeclaration */) { + else if (declaration.kind === 215 /* InterfaceDeclaration */) { ts.forEach(ts.getInterfaceBaseTypeNodes(declaration), getPropertySymbolFromTypeReference); } }); @@ -46699,19 +47478,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_33 = node.text; + var name_34 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_33); + var unionProperty = contextualType.getProperty(name_34); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_33); + var symbol = t.getProperty(name_34); if (symbol) { result_4.push(symbol); } @@ -46720,7 +47499,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_33); + var symbol_1 = contextualType.getProperty(name_34); if (symbol_1) { return [symbol_1]; } @@ -46773,17 +47552,17 @@ var ts; } /** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */ function isWriteAccess(node) { - if (node.kind === 67 /* Identifier */ && ts.isDeclarationName(node)) { + if (node.kind === 69 /* Identifier */ && ts.isDeclarationName(node)) { return true; } var parent = node.parent; if (parent) { - if (parent.kind === 178 /* PostfixUnaryExpression */ || parent.kind === 177 /* PrefixUnaryExpression */) { + if (parent.kind === 180 /* PostfixUnaryExpression */ || parent.kind === 179 /* PrefixUnaryExpression */) { return true; } - else if (parent.kind === 179 /* BinaryExpression */ && parent.left === node) { + else if (parent.kind === 181 /* BinaryExpression */ && parent.left === node) { var operator = parent.operatorToken.kind; - return 55 /* FirstAssignment */ <= operator && operator <= 66 /* LastAssignment */; + return 56 /* FirstAssignment */ <= operator && operator <= 68 /* LastAssignment */; } } return false; @@ -46815,33 +47594,33 @@ var ts; } function getMeaningFromDeclaration(node) { switch (node.kind) { - case 136 /* Parameter */: - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 243 /* PropertyAssignment */: - case 244 /* ShorthandPropertyAssignment */: - case 245 /* EnumMember */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 242 /* CatchClause */: + case 138 /* Parameter */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 245 /* PropertyAssignment */: + case 246 /* ShorthandPropertyAssignment */: + case 247 /* EnumMember */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 244 /* CatchClause */: return 1 /* Value */; - case 135 /* TypeParameter */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 153 /* TypeLiteral */: + case 137 /* TypeParameter */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 155 /* TypeLiteral */: return 2 /* Type */; - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: return 1 /* Value */ | 2 /* Type */; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (node.name.kind === 9 /* StringLiteral */) { return 4 /* Namespace */ | 1 /* Value */; } @@ -46851,15 +47630,15 @@ var ts; else { return 4 /* Namespace */; } - case 223 /* NamedImports */: - case 224 /* ImportSpecifier */: - case 219 /* ImportEqualsDeclaration */: - case 220 /* ImportDeclaration */: - case 225 /* ExportAssignment */: - case 226 /* ExportDeclaration */: + case 225 /* NamedImports */: + case 226 /* ImportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 222 /* ImportDeclaration */: + case 227 /* ExportAssignment */: + case 228 /* ExportDeclaration */: return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; // An external module can be a Value - case 246 /* SourceFile */: + case 248 /* SourceFile */: return 4 /* Namespace */ | 1 /* Value */; } return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; @@ -46869,8 +47648,9 @@ var ts; if (ts.isRightSideOfQualifiedNameOrPropertyAccess(node)) { node = node.parent; } - return node.parent.kind === 149 /* TypeReference */ || - (node.parent.kind === 186 /* ExpressionWithTypeArguments */ && !ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent)); + return node.parent.kind === 151 /* TypeReference */ || + (node.parent.kind === 188 /* ExpressionWithTypeArguments */ && !ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent)) || + node.kind === 97 /* ThisKeyword */ && !ts.isExpression(node); } function isNamespaceReference(node) { return isQualifiedNameNamespaceReference(node) || isPropertyAccessNamespaceReference(node); @@ -46878,50 +47658,50 @@ var ts; function isPropertyAccessNamespaceReference(node) { var root = node; var isLastClause = true; - if (root.parent.kind === 164 /* PropertyAccessExpression */) { - while (root.parent && root.parent.kind === 164 /* PropertyAccessExpression */) { + if (root.parent.kind === 166 /* PropertyAccessExpression */) { + while (root.parent && root.parent.kind === 166 /* PropertyAccessExpression */) { root = root.parent; } isLastClause = root.name === node; } - if (!isLastClause && root.parent.kind === 186 /* ExpressionWithTypeArguments */ && root.parent.parent.kind === 241 /* HeritageClause */) { + if (!isLastClause && root.parent.kind === 188 /* ExpressionWithTypeArguments */ && root.parent.parent.kind === 243 /* HeritageClause */) { var decl = root.parent.parent.parent; - return (decl.kind === 212 /* ClassDeclaration */ && root.parent.parent.token === 104 /* ImplementsKeyword */) || - (decl.kind === 213 /* InterfaceDeclaration */ && root.parent.parent.token === 81 /* ExtendsKeyword */); + return (decl.kind === 214 /* ClassDeclaration */ && root.parent.parent.token === 106 /* ImplementsKeyword */) || + (decl.kind === 215 /* InterfaceDeclaration */ && root.parent.parent.token === 83 /* ExtendsKeyword */); } return false; } function isQualifiedNameNamespaceReference(node) { var root = node; var isLastClause = true; - if (root.parent.kind === 133 /* QualifiedName */) { - while (root.parent && root.parent.kind === 133 /* QualifiedName */) { + if (root.parent.kind === 135 /* QualifiedName */) { + while (root.parent && root.parent.kind === 135 /* QualifiedName */) { root = root.parent; } isLastClause = root.right === node; } - return root.parent.kind === 149 /* TypeReference */ && !isLastClause; + return root.parent.kind === 151 /* TypeReference */ && !isLastClause; } function isInRightSideOfImport(node) { - while (node.parent.kind === 133 /* QualifiedName */) { + while (node.parent.kind === 135 /* QualifiedName */) { node = node.parent; } return ts.isInternalModuleImportEqualsDeclaration(node.parent) && node.parent.moduleReference === node; } function getMeaningFromRightHandSideOfImportEquals(node) { - ts.Debug.assert(node.kind === 67 /* Identifier */); + ts.Debug.assert(node.kind === 69 /* Identifier */); // import a = |b|; // Namespace // import a = |b.c|; // Value, type, namespace // import a = |b.c|.d; // Namespace - if (node.parent.kind === 133 /* QualifiedName */ && + if (node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node && - node.parent.parent.kind === 219 /* ImportEqualsDeclaration */) { + node.parent.parent.kind === 221 /* ImportEqualsDeclaration */) { return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; } return 4 /* Namespace */; } function getMeaningFromLocation(node) { - if (node.parent.kind === 225 /* ExportAssignment */) { + if (node.parent.kind === 227 /* ExportAssignment */) { return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; } else if (isInRightSideOfImport(node)) { @@ -46961,15 +47741,15 @@ var ts; return; } switch (node.kind) { - case 164 /* PropertyAccessExpression */: - case 133 /* QualifiedName */: + case 166 /* PropertyAccessExpression */: + case 135 /* QualifiedName */: case 9 /* StringLiteral */: - case 82 /* FalseKeyword */: - case 97 /* TrueKeyword */: - case 91 /* NullKeyword */: - case 93 /* SuperKeyword */: - case 95 /* ThisKeyword */: - case 67 /* Identifier */: + case 84 /* FalseKeyword */: + case 99 /* TrueKeyword */: + case 93 /* NullKeyword */: + case 95 /* SuperKeyword */: + case 97 /* ThisKeyword */: + case 69 /* Identifier */: break; // Cant create the text span default: @@ -46985,7 +47765,7 @@ var ts; // If this is name of a module declarations, check if this is right side of dotted module name // If parent of the module declaration which is parent of this node is module declaration and its body is the module declaration that this node is name of // Then this name is name from dotted module - if (nodeForStartPos.parent.parent.kind === 216 /* ModuleDeclaration */ && + if (nodeForStartPos.parent.parent.kind === 218 /* ModuleDeclaration */ && nodeForStartPos.parent.parent.body === nodeForStartPos.parent) { // Use parent module declarations name for start pos nodeForStartPos = nodeForStartPos.parent.parent.name; @@ -47026,10 +47806,10 @@ var ts; // That means we're calling back into the host around every 1.2k of the file we process. // Lib.d.ts has similar numbers. switch (kind) { - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } @@ -47083,7 +47863,7 @@ var ts; */ function hasValueSideModule(symbol) { return ts.forEach(symbol.declarations, function (declaration) { - return declaration.kind === 216 /* ModuleDeclaration */ && + return declaration.kind === 218 /* ModuleDeclaration */ && ts.getModuleInstanceState(declaration) === 1 /* Instantiated */; }); } @@ -47093,7 +47873,7 @@ var ts; if (node && ts.textSpanIntersectsWith(span, node.getFullStart(), node.getFullWidth())) { var kind = node.kind; checkForClassificationCancellation(kind); - if (kind === 67 /* Identifier */ && !ts.nodeIsMissing(node)) { + if (kind === 69 /* Identifier */ && !ts.nodeIsMissing(node)) { var identifier = node; // Only bother calling into the typechecker if this is an identifier that // could possibly resolve to a type name. This makes classification run @@ -47238,16 +48018,16 @@ var ts; pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, 18 /* docCommentTagName */); pos = tag.tagName.end; switch (tag.kind) { - case 265 /* JSDocParameterTag */: + case 267 /* JSDocParameterTag */: processJSDocParameterTag(tag); break; - case 268 /* JSDocTemplateTag */: + case 270 /* JSDocTemplateTag */: processJSDocTemplateTag(tag); break; - case 267 /* JSDocTypeTag */: + case 269 /* JSDocTypeTag */: processElement(tag.typeExpression); break; - case 266 /* JSDocReturnTag */: + case 268 /* JSDocReturnTag */: processElement(tag.typeExpression); break; } @@ -47336,18 +48116,18 @@ var ts; } if (ts.isPunctuation(tokenKind)) { if (token) { - if (tokenKind === 55 /* EqualsToken */) { + if (tokenKind === 56 /* EqualsToken */) { // the '=' in a variable declaration is special cased here. - if (token.parent.kind === 209 /* VariableDeclaration */ || - token.parent.kind === 139 /* PropertyDeclaration */ || - token.parent.kind === 136 /* Parameter */) { + if (token.parent.kind === 211 /* VariableDeclaration */ || + token.parent.kind === 141 /* PropertyDeclaration */ || + token.parent.kind === 138 /* Parameter */) { return 5 /* operator */; } } - if (token.parent.kind === 179 /* BinaryExpression */ || - token.parent.kind === 177 /* PrefixUnaryExpression */ || - token.parent.kind === 178 /* PostfixUnaryExpression */ || - token.parent.kind === 180 /* ConditionalExpression */) { + if (token.parent.kind === 181 /* BinaryExpression */ || + token.parent.kind === 179 /* PrefixUnaryExpression */ || + token.parent.kind === 180 /* PostfixUnaryExpression */ || + token.parent.kind === 182 /* ConditionalExpression */) { return 5 /* operator */; } } @@ -47367,35 +48147,35 @@ var ts; // TODO (drosen): we should *also* get another classification type for these literals. return 6 /* stringLiteral */; } - else if (tokenKind === 67 /* Identifier */) { + else if (tokenKind === 69 /* Identifier */) { if (token) { switch (token.parent.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: if (token.parent.name === token) { return 11 /* className */; } return; - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: if (token.parent.name === token) { return 15 /* typeParameterName */; } return; - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: if (token.parent.name === token) { return 13 /* interfaceName */; } return; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: if (token.parent.name === token) { return 12 /* enumName */; } return; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (token.parent.name === token) { return 14 /* moduleName */; } return; - case 136 /* Parameter */: + case 138 /* Parameter */: if (token.parent.name === token) { return 17 /* parameterName */; } @@ -47507,8 +48287,12 @@ var ts; * Checks if position points to a valid position to add JSDoc comments, and if so, * returns the appropriate template. Otherwise returns an empty string. * Valid positions are - * - outside of comments, statements, and expressions, and - * - preceding a function declaration. + * - outside of comments, statements, and expressions, and + * - preceding a: + * - function/constructor/method declaration + * - class declarations + * - variable statements + * - namespace declarations * * Hosts should ideally check that: * - The line is all whitespace up to 'position' before performing the insertion. @@ -47532,23 +48316,48 @@ var ts; return undefined; } // TODO: add support for: - // - methods - // - constructors - // - class decls - var containingFunction = ts.getAncestor(tokenAtPos, 211 /* FunctionDeclaration */); - if (!containingFunction || containingFunction.getStart() < position) { + // - enums/enum members + // - interfaces + // - property declarations + // - potentially property assignments + var commentOwner; + findOwner: for (commentOwner = tokenAtPos; commentOwner; commentOwner = commentOwner.parent) { + switch (commentOwner.kind) { + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 144 /* Constructor */: + case 214 /* ClassDeclaration */: + case 193 /* VariableStatement */: + break findOwner; + case 248 /* SourceFile */: + return undefined; + case 218 /* ModuleDeclaration */: + // If in walking up the tree, we hit a a nested namespace declaration, + // then we must be somewhere within a dotted namespace name; however we don't + // want to give back a JSDoc template for the 'b' or 'c' in 'namespace a.b.c { }'. + if (commentOwner.parent.kind === 218 /* ModuleDeclaration */) { + return undefined; + } + break findOwner; + } + } + if (!commentOwner || commentOwner.getStart() < position) { return undefined; } - var parameters = containingFunction.parameters; + var parameters = getParametersForJsDocOwningNode(commentOwner); var posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position); var lineStart = sourceFile.getLineStarts()[posLineAndChar.line]; var indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character); // TODO: call a helper method instead once PR #4133 gets merged in. var newLine = host.getNewLine ? host.getNewLine() : "\r\n"; - var docParams = parameters.reduce(function (prev, cur, index) { - return prev + - indentationStr + " * @param " + (cur.name.kind === 67 /* Identifier */ ? cur.name.text : "param" + index) + newLine; - }, ""); + var docParams = ""; + for (var i = 0, numParams = parameters.length; i < numParams; i++) { + var currentName = parameters[i].name; + var paramName = currentName.kind === 69 /* Identifier */ ? + currentName.text : + "param" + i; + docParams += indentationStr + " * @param " + paramName + newLine; + } // A doc comment consists of the following // * The opening comment line // * the first line (without a param) for the object's untagged info (this is also where the caret ends up) @@ -47564,6 +48373,46 @@ var ts; (tokenStart === position ? newLine + indentationStr : ""); return { newText: result, caretOffset: preamble.length }; } + function getParametersForJsDocOwningNode(commentOwner) { + if (ts.isFunctionLike(commentOwner)) { + return commentOwner.parameters; + } + if (commentOwner.kind === 193 /* VariableStatement */) { + var varStatement = commentOwner; + var varDeclarations = varStatement.declarationList.declarations; + if (varDeclarations.length === 1 && varDeclarations[0].initializer) { + return getParametersFromRightHandSideOfAssignment(varDeclarations[0].initializer); + } + } + return emptyArray; + } + /** + * Digs into an an initializer or RHS operand of an assignment operation + * to get the parameters of an apt signature corresponding to a + * function expression or a class expression. + * + * @param rightHandSide the expression which may contain an appropriate set of parameters + * @returns the parameters of a signature found on the RHS if one exists; otherwise 'emptyArray'. + */ + function getParametersFromRightHandSideOfAssignment(rightHandSide) { + while (rightHandSide.kind === 172 /* ParenthesizedExpression */) { + rightHandSide = rightHandSide.expression; + } + switch (rightHandSide.kind) { + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + return rightHandSide.parameters; + case 186 /* ClassExpression */: + for (var _i = 0, _a = rightHandSide.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 144 /* Constructor */) { + return member.parameters; + } + } + break; + } + return emptyArray; + } function getTodoComments(fileName, descriptors) { // Note: while getting todo comments seems like a syntactic operation, we actually // treat it as a semantic operation here. This is because we expect our host to call @@ -47694,7 +48543,7 @@ var ts; var typeChecker = program.getTypeChecker(); var node = ts.getTouchingWord(sourceFile, position); // Can only rename an identifier. - if (node && node.kind === 67 /* Identifier */) { + if (node && node.kind === 69 /* Identifier */) { var symbol = typeChecker.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol) { @@ -47795,7 +48644,7 @@ var ts; sourceFile.nameTable = nameTable; function walk(node) { switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: nameTable[node.text] = node.text; break; case 9 /* StringLiteral */: @@ -47805,7 +48654,7 @@ var ts; // then we want 'something' to be in the name table. Similarly, if we have // "a['propname']" then we want to store "propname" in the name table. if (ts.isDeclarationName(node) || - node.parent.kind === 230 /* ExternalModuleReference */ || + node.parent.kind === 232 /* ExternalModuleReference */ || isArgumentOfElementAccessExpression(node)) { nameTable[node.text] = node.text; } @@ -47818,7 +48667,7 @@ var ts; function isArgumentOfElementAccessExpression(node) { return node && node.parent && - node.parent.kind === 165 /* ElementAccessExpression */ && + node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.argumentExpression === node; } /// Classifier @@ -47829,18 +48678,18 @@ var ts; /// we have a series of divide operator. this list allows us to be more accurate by ruling out /// locations where a regexp cannot exist. var noRegexTable = []; - noRegexTable[67 /* Identifier */] = true; + noRegexTable[69 /* Identifier */] = true; noRegexTable[9 /* StringLiteral */] = true; noRegexTable[8 /* NumericLiteral */] = true; noRegexTable[10 /* RegularExpressionLiteral */] = true; - noRegexTable[95 /* ThisKeyword */] = true; - noRegexTable[40 /* PlusPlusToken */] = true; - noRegexTable[41 /* MinusMinusToken */] = true; + noRegexTable[97 /* ThisKeyword */] = true; + noRegexTable[41 /* PlusPlusToken */] = true; + noRegexTable[42 /* MinusMinusToken */] = true; noRegexTable[18 /* CloseParenToken */] = true; noRegexTable[20 /* CloseBracketToken */] = true; noRegexTable[16 /* CloseBraceToken */] = true; - noRegexTable[97 /* TrueKeyword */] = true; - noRegexTable[82 /* FalseKeyword */] = true; + noRegexTable[99 /* TrueKeyword */] = true; + noRegexTable[84 /* FalseKeyword */] = true; // Just a stack of TemplateHeads and OpenCurlyBraces, used to perform rudimentary (inexact) // classification on template strings. Because of the context free nature of templates, // the only precise way to classify a template portion would be by propagating the stack across @@ -47865,10 +48714,10 @@ var ts; /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */ function canFollow(keyword1, keyword2) { if (ts.isAccessibilityModifier(keyword1)) { - if (keyword2 === 121 /* GetKeyword */ || - keyword2 === 127 /* SetKeyword */ || - keyword2 === 119 /* ConstructorKeyword */ || - keyword2 === 111 /* StaticKeyword */) { + if (keyword2 === 123 /* GetKeyword */ || + keyword2 === 129 /* SetKeyword */ || + keyword2 === 121 /* ConstructorKeyword */ || + keyword2 === 113 /* StaticKeyword */) { // Allow things like "public get", "public constructor" and "public static". // These are all legal. return true; @@ -47998,22 +48847,22 @@ var ts; do { token = scanner.scan(); if (!ts.isTrivia(token)) { - if ((token === 38 /* SlashToken */ || token === 59 /* SlashEqualsToken */) && !noRegexTable[lastNonTriviaToken]) { + if ((token === 39 /* SlashToken */ || token === 61 /* SlashEqualsToken */) && !noRegexTable[lastNonTriviaToken]) { if (scanner.reScanSlashToken() === 10 /* RegularExpressionLiteral */) { token = 10 /* RegularExpressionLiteral */; } } else if (lastNonTriviaToken === 21 /* DotToken */ && isKeyword(token)) { - token = 67 /* Identifier */; + token = 69 /* Identifier */; } else if (isKeyword(lastNonTriviaToken) && isKeyword(token) && !canFollow(lastNonTriviaToken, token)) { // We have two keywords in a row. Only treat the second as a keyword if // it's a sequence that could legally occur in the language. Otherwise // treat it as an identifier. This way, if someone writes "private var" // we recognize that 'var' is actually an identifier here. - token = 67 /* Identifier */; + token = 69 /* Identifier */; } - else if (lastNonTriviaToken === 67 /* Identifier */ && + else if (lastNonTriviaToken === 69 /* Identifier */ && token === 25 /* LessThanToken */) { // Could be the start of something generic. Keep track of that by bumping // up the current count of generic contexts we may be in. @@ -48024,16 +48873,16 @@ var ts; // generic entity is complete. angleBracketStack--; } - else if (token === 115 /* AnyKeyword */ || - token === 128 /* StringKeyword */ || - token === 126 /* NumberKeyword */ || - token === 118 /* BooleanKeyword */ || - token === 129 /* SymbolKeyword */) { + else if (token === 117 /* AnyKeyword */ || + token === 130 /* StringKeyword */ || + token === 128 /* NumberKeyword */ || + token === 120 /* BooleanKeyword */ || + token === 131 /* SymbolKeyword */) { if (angleBracketStack > 0 && !syntacticClassifierAbsent) { // If it looks like we're could be in something generic, don't classify this // as a keyword. We may just get overwritten by the syntactic classifier, // causing a noisy experience for the user. - token = 67 /* Identifier */; + token = 69 /* Identifier */; } } else if (token === 12 /* TemplateHead */) { @@ -48145,40 +48994,41 @@ var ts; function isBinaryExpressionOperatorToken(token) { switch (token) { case 37 /* AsteriskToken */: - case 38 /* SlashToken */: - case 39 /* PercentToken */: + case 39 /* SlashToken */: + case 40 /* PercentToken */: case 35 /* PlusToken */: case 36 /* MinusToken */: - case 42 /* LessThanLessThanToken */: - case 43 /* GreaterThanGreaterThanToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: + case 43 /* LessThanLessThanToken */: + case 44 /* GreaterThanGreaterThanToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: case 25 /* LessThanToken */: case 27 /* GreaterThanToken */: case 28 /* LessThanEqualsToken */: case 29 /* GreaterThanEqualsToken */: - case 89 /* InstanceOfKeyword */: - case 88 /* InKeyword */: + case 91 /* InstanceOfKeyword */: + case 90 /* InKeyword */: + case 116 /* AsKeyword */: case 30 /* EqualsEqualsToken */: case 31 /* ExclamationEqualsToken */: case 32 /* EqualsEqualsEqualsToken */: case 33 /* ExclamationEqualsEqualsToken */: - case 45 /* AmpersandToken */: - case 47 /* CaretToken */: - case 46 /* BarToken */: - case 50 /* AmpersandAmpersandToken */: - case 51 /* BarBarToken */: - case 65 /* BarEqualsToken */: - case 64 /* AmpersandEqualsToken */: - case 66 /* CaretEqualsToken */: - case 61 /* LessThanLessThanEqualsToken */: - case 62 /* GreaterThanGreaterThanEqualsToken */: - case 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */: - case 56 /* PlusEqualsToken */: - case 57 /* MinusEqualsToken */: - case 58 /* AsteriskEqualsToken */: - case 59 /* SlashEqualsToken */: - case 60 /* PercentEqualsToken */: - case 55 /* EqualsToken */: + case 46 /* AmpersandToken */: + case 48 /* CaretToken */: + case 47 /* BarToken */: + case 51 /* AmpersandAmpersandToken */: + case 52 /* BarBarToken */: + case 67 /* BarEqualsToken */: + case 66 /* AmpersandEqualsToken */: + case 68 /* CaretEqualsToken */: + case 63 /* LessThanLessThanEqualsToken */: + case 64 /* GreaterThanGreaterThanEqualsToken */: + case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */: + case 57 /* PlusEqualsToken */: + case 58 /* MinusEqualsToken */: + case 59 /* AsteriskEqualsToken */: + case 61 /* SlashEqualsToken */: + case 62 /* PercentEqualsToken */: + case 56 /* EqualsToken */: case 24 /* CommaToken */: return true; default: @@ -48189,17 +49039,17 @@ var ts; switch (token) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: - case 48 /* ExclamationToken */: - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: + case 41 /* PlusPlusToken */: + case 42 /* MinusMinusToken */: return true; default: return false; } } function isKeyword(token) { - return token >= 68 /* FirstKeyword */ && token <= 132 /* LastKeyword */; + return token >= 70 /* FirstKeyword */ && token <= 134 /* LastKeyword */; } function classFromKind(token) { if (isKeyword(token)) { @@ -48208,7 +49058,7 @@ var ts; else if (isBinaryExpressionOperatorToken(token) || isPrefixUnaryExpressionOperatorToken(token)) { return 5 /* operator */; } - else if (token >= 15 /* FirstPunctuation */ && token <= 66 /* LastPunctuation */) { + else if (token >= 15 /* FirstPunctuation */ && token <= 68 /* LastPunctuation */) { return 10 /* punctuation */; } switch (token) { @@ -48225,7 +49075,7 @@ var ts; case 5 /* WhitespaceTrivia */: case 4 /* NewLineTrivia */: return 8 /* whiteSpace */; - case 67 /* Identifier */: + case 69 /* Identifier */: default: if (ts.isTemplateLiteralKind(token)) { return 6 /* stringLiteral */; @@ -48257,7 +49107,7 @@ var ts; getNodeConstructor: function (kind) { function Node() { } - var proto = kind === 246 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); + var proto = kind === 248 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); proto.kind = kind; proto.pos = -1; proto.end = -1; @@ -48327,125 +49177,125 @@ var ts; function spanInNode(node) { if (node) { if (ts.isExpression(node)) { - if (node.parent.kind === 195 /* DoStatement */) { + if (node.parent.kind === 197 /* DoStatement */) { // Set span as if on while keyword return spanInPreviousNode(node); } - if (node.parent.kind === 197 /* ForStatement */) { + if (node.parent.kind === 199 /* ForStatement */) { // For now lets set the span on this expression, fix it later return textSpan(node); } - if (node.parent.kind === 179 /* BinaryExpression */ && node.parent.operatorToken.kind === 24 /* CommaToken */) { + if (node.parent.kind === 181 /* BinaryExpression */ && node.parent.operatorToken.kind === 24 /* CommaToken */) { // if this is comma expression, the breakpoint is possible in this expression return textSpan(node); } - if (node.parent.kind === 172 /* ArrowFunction */ && node.parent.body === node) { + if (node.parent.kind === 174 /* ArrowFunction */ && node.parent.body === node) { // If this is body of arrow function, it is allowed to have the breakpoint return textSpan(node); } } switch (node.kind) { - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: // Span on first variable declaration return spanInVariableDeclaration(node.declarationList.declarations[0]); - case 209 /* VariableDeclaration */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 211 /* VariableDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return spanInVariableDeclaration(node); - case 136 /* Parameter */: + case 138 /* Parameter */: return spanInParameterDeclaration(node); - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return spanInFunctionDeclaration(node); - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionBlock(node)) { return spanInFunctionBlock(node); } // Fall through - case 217 /* ModuleBlock */: + case 219 /* ModuleBlock */: return spanInBlock(node); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return spanInBlock(node.block); - case 193 /* ExpressionStatement */: + case 195 /* ExpressionStatement */: // span on the expression return textSpan(node.expression); - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: // span on return keyword and expression if present return textSpan(node.getChildAt(0), node.expression); - case 196 /* WhileStatement */: + case 198 /* WhileStatement */: // Span on while(...) return textSpan(node, ts.findNextToken(node.expression, node)); - case 195 /* DoStatement */: + case 197 /* DoStatement */: // span in statement of the do statement return spanInNode(node.statement); - case 208 /* DebuggerStatement */: + case 210 /* DebuggerStatement */: // span on debugger keyword return textSpan(node.getChildAt(0)); - case 194 /* IfStatement */: + case 196 /* IfStatement */: // set on if(..) span return textSpan(node, ts.findNextToken(node.expression, node)); - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: // span in statement return spanInNode(node.statement); - case 201 /* BreakStatement */: - case 200 /* ContinueStatement */: + case 203 /* BreakStatement */: + case 202 /* ContinueStatement */: // On break or continue keyword and label if present return textSpan(node.getChildAt(0), node.label); - case 197 /* ForStatement */: + case 199 /* ForStatement */: return spanInForStatement(node); - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: // span on for (a in ...) return textSpan(node, ts.findNextToken(node.expression, node)); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: // span on switch(...) return textSpan(node, ts.findNextToken(node.expression, node)); - case 239 /* CaseClause */: - case 240 /* DefaultClause */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: // span in first statement of the clause return spanInNode(node.statements[0]); - case 207 /* TryStatement */: + case 209 /* TryStatement */: // span in try block return spanInBlock(node.tryBlock); - case 206 /* ThrowStatement */: + case 208 /* ThrowStatement */: // span in throw ... return textSpan(node, node.expression); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: // span on export = id return textSpan(node, node.expression); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: // import statement without including semicolon return textSpan(node, node.moduleReference); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: // import statement without including semicolon return textSpan(node, node.moduleSpecifier); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: // import statement without including semicolon return textSpan(node, node.moduleSpecifier); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: // span on complete module if it is instantiated if (ts.getModuleInstanceState(node) !== 1 /* Instantiated */) { return undefined; } - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: // span on complete node return textSpan(node); - case 203 /* WithStatement */: + case 205 /* WithStatement */: // span in statement return spanInNode(node.statement); // No breakpoint in interface, type alias - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: return undefined; // Tokens: case 23 /* SemicolonToken */: @@ -48461,25 +49311,25 @@ var ts; return spanInOpenParenToken(node); case 18 /* CloseParenToken */: return spanInCloseParenToken(node); - case 53 /* ColonToken */: + case 54 /* ColonToken */: return spanInColonToken(node); case 27 /* GreaterThanToken */: case 25 /* LessThanToken */: return spanInGreaterThanOrLessThanToken(node); // Keywords: - case 102 /* WhileKeyword */: + case 104 /* WhileKeyword */: return spanInWhileKeyword(node); - case 78 /* ElseKeyword */: - case 70 /* CatchKeyword */: - case 83 /* FinallyKeyword */: + case 80 /* ElseKeyword */: + case 72 /* CatchKeyword */: + case 85 /* FinallyKeyword */: return spanInNextNode(node); default: // If this is name of property assignment, set breakpoint in the initializer - if (node.parent.kind === 243 /* PropertyAssignment */ && node.parent.name === node) { + if (node.parent.kind === 245 /* PropertyAssignment */ && node.parent.name === node) { return spanInNode(node.parent.initializer); } // Breakpoint in type assertion goes to its operand - if (node.parent.kind === 169 /* TypeAssertionExpression */ && node.parent.type === node) { + if (node.parent.kind === 171 /* TypeAssertionExpression */ && node.parent.type === node) { return spanInNode(node.parent.expression); } // return type of function go to previous token @@ -48492,12 +49342,12 @@ var ts; } function spanInVariableDeclaration(variableDeclaration) { // If declaration of for in statement, just set the span in parent - if (variableDeclaration.parent.parent.kind === 198 /* ForInStatement */ || - variableDeclaration.parent.parent.kind === 199 /* ForOfStatement */) { + if (variableDeclaration.parent.parent.kind === 200 /* ForInStatement */ || + variableDeclaration.parent.parent.kind === 201 /* ForOfStatement */) { return spanInNode(variableDeclaration.parent.parent); } - var isParentVariableStatement = variableDeclaration.parent.parent.kind === 191 /* VariableStatement */; - var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 197 /* ForStatement */ && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); + var isParentVariableStatement = variableDeclaration.parent.parent.kind === 193 /* VariableStatement */; + var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 199 /* ForStatement */ && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); var declarations = isParentVariableStatement ? variableDeclaration.parent.parent.declarationList.declarations : isDeclarationOfForStatement @@ -48551,7 +49401,7 @@ var ts; } function canFunctionHaveSpanInWholeDeclaration(functionDeclaration) { return !!(functionDeclaration.flags & 1 /* Export */) || - (functionDeclaration.parent.kind === 212 /* ClassDeclaration */ && functionDeclaration.kind !== 142 /* Constructor */); + (functionDeclaration.parent.kind === 214 /* ClassDeclaration */ && functionDeclaration.kind !== 144 /* Constructor */); } function spanInFunctionDeclaration(functionDeclaration) { // No breakpoints in the function signature @@ -48574,18 +49424,18 @@ var ts; } function spanInBlock(block) { switch (block.parent.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (ts.getModuleInstanceState(block.parent) !== 1 /* Instantiated */) { return undefined; } // Set on parent if on same line otherwise on first statement - case 196 /* WhileStatement */: - case 194 /* IfStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 198 /* WhileStatement */: + case 196 /* IfStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); // Set span on previous token if it starts on same line otherwise on the first statement of the block - case 197 /* ForStatement */: + case 199 /* ForStatement */: return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]); } // Default action is to set on first statement @@ -48593,7 +49443,7 @@ var ts; } function spanInForStatement(forStatement) { if (forStatement.initializer) { - if (forStatement.initializer.kind === 210 /* VariableDeclarationList */) { + if (forStatement.initializer.kind === 212 /* VariableDeclarationList */) { var variableDeclarationList = forStatement.initializer; if (variableDeclarationList.declarations.length > 0) { return spanInNode(variableDeclarationList.declarations[0]); @@ -48613,13 +49463,13 @@ var ts; // Tokens: function spanInOpenBraceToken(node) { switch (node.parent.kind) { - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: var enumDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var classDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); - case 218 /* CaseBlock */: + case 220 /* CaseBlock */: return spanInNodeIfStartsOnSameLine(node.parent.parent, node.parent.clauses[0]); } // Default to parent node @@ -48627,25 +49477,25 @@ var ts; } function spanInCloseBraceToken(node) { switch (node.parent.kind) { - case 217 /* ModuleBlock */: + case 219 /* ModuleBlock */: // If this is not instantiated module block no bp span if (ts.getModuleInstanceState(node.parent.parent) !== 1 /* Instantiated */) { return undefined; } - case 215 /* EnumDeclaration */: - case 212 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: // Span on close brace token return textSpan(node); - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionBlock(node.parent)) { // Span on close brace token return textSpan(node); } // fall through. - case 242 /* CatchClause */: + case 244 /* CatchClause */: return spanInNode(ts.lastOrUndefined(node.parent.statements)); ; - case 218 /* CaseBlock */: + case 220 /* CaseBlock */: // breakpoint in last statement of the last clause var caseBlock = node.parent; var lastClause = ts.lastOrUndefined(caseBlock.clauses); @@ -48659,7 +49509,7 @@ var ts; } } function spanInOpenParenToken(node) { - if (node.parent.kind === 195 /* DoStatement */) { + if (node.parent.kind === 197 /* DoStatement */) { // Go to while keyword and do action instead return spanInPreviousNode(node); } @@ -48669,17 +49519,17 @@ var ts; function spanInCloseParenToken(node) { // Is this close paren token of parameter list, set span in previous token switch (node.parent.kind) { - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: - case 196 /* WhileStatement */: - case 195 /* DoStatement */: - case 197 /* ForStatement */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: + case 198 /* WhileStatement */: + case 197 /* DoStatement */: + case 199 /* ForStatement */: return spanInPreviousNode(node); // Default to parent node default: @@ -48690,19 +49540,19 @@ var ts; } function spanInColonToken(node) { // Is this : specifying return annotation of the function declaration - if (ts.isFunctionLike(node.parent) || node.parent.kind === 243 /* PropertyAssignment */) { + if (ts.isFunctionLike(node.parent) || node.parent.kind === 245 /* PropertyAssignment */) { return spanInPreviousNode(node); } return spanInNode(node.parent); } function spanInGreaterThanOrLessThanToken(node) { - if (node.parent.kind === 169 /* TypeAssertionExpression */) { + if (node.parent.kind === 171 /* TypeAssertionExpression */) { return spanInNode(node.parent.expression); } return spanInNode(node.parent); } function spanInWhileKeyword(node) { - if (node.parent.kind === 195 /* DoStatement */) { + if (node.parent.kind === 197 /* DoStatement */) { // Set span on while expression return textSpan(node, ts.findNextToken(node.parent.expression, node.parent)); } @@ -49367,7 +50217,7 @@ var ts; var _this = this; return this.forwardJSONCall("getTSConfigFileInfo('" + fileName + "')", function () { var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - var result = ts.parseConfigFileText(fileName, text); + var result = ts.parseConfigFileTextToJson(fileName, text); if (result.error) { return { options: {}, @@ -49375,7 +50225,7 @@ var ts; errors: [realizeDiagnostic(result.error, '\r\n')] }; } - var configFile = ts.parseConfigFile(result.config, _this.host, ts.getDirectoryPath(ts.normalizeSlashes(fileName))); + var configFile = ts.parseJsonConfigFileContent(result.config, _this.host, ts.getDirectoryPath(ts.normalizeSlashes(fileName))); return { options: configFile.options, files: configFile.fileNames, diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 761ce39d418..98c4496d891 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -68,253 +68,255 @@ declare namespace ts { PlusToken = 35, MinusToken = 36, AsteriskToken = 37, - SlashToken = 38, - PercentToken = 39, - PlusPlusToken = 40, - MinusMinusToken = 41, - LessThanLessThanToken = 42, - GreaterThanGreaterThanToken = 43, - GreaterThanGreaterThanGreaterThanToken = 44, - AmpersandToken = 45, - BarToken = 46, - CaretToken = 47, - ExclamationToken = 48, - TildeToken = 49, - AmpersandAmpersandToken = 50, - BarBarToken = 51, - QuestionToken = 52, - ColonToken = 53, - AtToken = 54, - EqualsToken = 55, - PlusEqualsToken = 56, - MinusEqualsToken = 57, - AsteriskEqualsToken = 58, - SlashEqualsToken = 59, - PercentEqualsToken = 60, - LessThanLessThanEqualsToken = 61, - GreaterThanGreaterThanEqualsToken = 62, - GreaterThanGreaterThanGreaterThanEqualsToken = 63, - AmpersandEqualsToken = 64, - BarEqualsToken = 65, - CaretEqualsToken = 66, - Identifier = 67, - BreakKeyword = 68, - CaseKeyword = 69, - CatchKeyword = 70, - ClassKeyword = 71, - ConstKeyword = 72, - ContinueKeyword = 73, - DebuggerKeyword = 74, - DefaultKeyword = 75, - DeleteKeyword = 76, - DoKeyword = 77, - ElseKeyword = 78, - EnumKeyword = 79, - ExportKeyword = 80, - ExtendsKeyword = 81, - FalseKeyword = 82, - FinallyKeyword = 83, - ForKeyword = 84, - FunctionKeyword = 85, - IfKeyword = 86, - ImportKeyword = 87, - InKeyword = 88, - InstanceOfKeyword = 89, - NewKeyword = 90, - NullKeyword = 91, - ReturnKeyword = 92, - SuperKeyword = 93, - SwitchKeyword = 94, - ThisKeyword = 95, - ThrowKeyword = 96, - TrueKeyword = 97, - TryKeyword = 98, - TypeOfKeyword = 99, - VarKeyword = 100, - VoidKeyword = 101, - WhileKeyword = 102, - WithKeyword = 103, - ImplementsKeyword = 104, - InterfaceKeyword = 105, - LetKeyword = 106, - PackageKeyword = 107, - PrivateKeyword = 108, - ProtectedKeyword = 109, - PublicKeyword = 110, - StaticKeyword = 111, - YieldKeyword = 112, - AbstractKeyword = 113, - AsKeyword = 114, - AnyKeyword = 115, - AsyncKeyword = 116, - AwaitKeyword = 117, - BooleanKeyword = 118, - ConstructorKeyword = 119, - DeclareKeyword = 120, - GetKeyword = 121, - IsKeyword = 122, - ModuleKeyword = 123, - NamespaceKeyword = 124, - RequireKeyword = 125, - NumberKeyword = 126, - SetKeyword = 127, - StringKeyword = 128, - SymbolKeyword = 129, - TypeKeyword = 130, - FromKeyword = 131, - OfKeyword = 132, - QualifiedName = 133, - ComputedPropertyName = 134, - TypeParameter = 135, - Parameter = 136, - Decorator = 137, - PropertySignature = 138, - PropertyDeclaration = 139, - MethodSignature = 140, - MethodDeclaration = 141, - Constructor = 142, - GetAccessor = 143, - SetAccessor = 144, - CallSignature = 145, - ConstructSignature = 146, - IndexSignature = 147, - TypePredicate = 148, - TypeReference = 149, - FunctionType = 150, - ConstructorType = 151, - TypeQuery = 152, - TypeLiteral = 153, - ArrayType = 154, - TupleType = 155, - UnionType = 156, - IntersectionType = 157, - ParenthesizedType = 158, - ObjectBindingPattern = 159, - ArrayBindingPattern = 160, - BindingElement = 161, - ArrayLiteralExpression = 162, - ObjectLiteralExpression = 163, - PropertyAccessExpression = 164, - ElementAccessExpression = 165, - CallExpression = 166, - NewExpression = 167, - TaggedTemplateExpression = 168, - TypeAssertionExpression = 169, - ParenthesizedExpression = 170, - FunctionExpression = 171, - ArrowFunction = 172, - DeleteExpression = 173, - TypeOfExpression = 174, - VoidExpression = 175, - AwaitExpression = 176, - PrefixUnaryExpression = 177, - PostfixUnaryExpression = 178, - BinaryExpression = 179, - ConditionalExpression = 180, - TemplateExpression = 181, - YieldExpression = 182, - SpreadElementExpression = 183, - ClassExpression = 184, - OmittedExpression = 185, - ExpressionWithTypeArguments = 186, - AsExpression = 187, - TemplateSpan = 188, - SemicolonClassElement = 189, - Block = 190, - VariableStatement = 191, - EmptyStatement = 192, - ExpressionStatement = 193, - IfStatement = 194, - DoStatement = 195, - WhileStatement = 196, - ForStatement = 197, - ForInStatement = 198, - ForOfStatement = 199, - ContinueStatement = 200, - BreakStatement = 201, - ReturnStatement = 202, - WithStatement = 203, - SwitchStatement = 204, - LabeledStatement = 205, - ThrowStatement = 206, - TryStatement = 207, - DebuggerStatement = 208, - VariableDeclaration = 209, - VariableDeclarationList = 210, - FunctionDeclaration = 211, - ClassDeclaration = 212, - InterfaceDeclaration = 213, - TypeAliasDeclaration = 214, - EnumDeclaration = 215, - ModuleDeclaration = 216, - ModuleBlock = 217, - CaseBlock = 218, - ImportEqualsDeclaration = 219, - ImportDeclaration = 220, - ImportClause = 221, - NamespaceImport = 222, - NamedImports = 223, - ImportSpecifier = 224, - ExportAssignment = 225, - ExportDeclaration = 226, - NamedExports = 227, - ExportSpecifier = 228, - MissingDeclaration = 229, - ExternalModuleReference = 230, - JsxElement = 231, - JsxSelfClosingElement = 232, - JsxOpeningElement = 233, - JsxText = 234, - JsxClosingElement = 235, - JsxAttribute = 236, - JsxSpreadAttribute = 237, - JsxExpression = 238, - CaseClause = 239, - DefaultClause = 240, - HeritageClause = 241, - CatchClause = 242, - PropertyAssignment = 243, - ShorthandPropertyAssignment = 244, - EnumMember = 245, - SourceFile = 246, - JSDocTypeExpression = 247, - JSDocAllType = 248, - JSDocUnknownType = 249, - JSDocArrayType = 250, - JSDocUnionType = 251, - JSDocTupleType = 252, - JSDocNullableType = 253, - JSDocNonNullableType = 254, - JSDocRecordType = 255, - JSDocRecordMember = 256, - JSDocTypeReference = 257, - JSDocOptionalType = 258, - JSDocFunctionType = 259, - JSDocVariadicType = 260, - JSDocConstructorType = 261, - JSDocThisType = 262, - JSDocComment = 263, - JSDocTag = 264, - JSDocParameterTag = 265, - JSDocReturnTag = 266, - JSDocTypeTag = 267, - JSDocTemplateTag = 268, - SyntaxList = 269, - Count = 270, - FirstAssignment = 55, - LastAssignment = 66, - FirstReservedWord = 68, - LastReservedWord = 103, - FirstKeyword = 68, - LastKeyword = 132, - FirstFutureReservedWord = 104, - LastFutureReservedWord = 112, - FirstTypeNode = 149, - LastTypeNode = 158, + AsteriskAsteriskToken = 38, + SlashToken = 39, + PercentToken = 40, + PlusPlusToken = 41, + MinusMinusToken = 42, + LessThanLessThanToken = 43, + GreaterThanGreaterThanToken = 44, + GreaterThanGreaterThanGreaterThanToken = 45, + AmpersandToken = 46, + BarToken = 47, + CaretToken = 48, + ExclamationToken = 49, + TildeToken = 50, + AmpersandAmpersandToken = 51, + BarBarToken = 52, + QuestionToken = 53, + ColonToken = 54, + AtToken = 55, + EqualsToken = 56, + PlusEqualsToken = 57, + MinusEqualsToken = 58, + AsteriskEqualsToken = 59, + AsteriskAsteriskEqualsToken = 60, + SlashEqualsToken = 61, + PercentEqualsToken = 62, + LessThanLessThanEqualsToken = 63, + GreaterThanGreaterThanEqualsToken = 64, + GreaterThanGreaterThanGreaterThanEqualsToken = 65, + AmpersandEqualsToken = 66, + BarEqualsToken = 67, + CaretEqualsToken = 68, + Identifier = 69, + BreakKeyword = 70, + CaseKeyword = 71, + CatchKeyword = 72, + ClassKeyword = 73, + ConstKeyword = 74, + ContinueKeyword = 75, + DebuggerKeyword = 76, + DefaultKeyword = 77, + DeleteKeyword = 78, + DoKeyword = 79, + ElseKeyword = 80, + EnumKeyword = 81, + ExportKeyword = 82, + ExtendsKeyword = 83, + FalseKeyword = 84, + FinallyKeyword = 85, + ForKeyword = 86, + FunctionKeyword = 87, + IfKeyword = 88, + ImportKeyword = 89, + InKeyword = 90, + InstanceOfKeyword = 91, + NewKeyword = 92, + NullKeyword = 93, + ReturnKeyword = 94, + SuperKeyword = 95, + SwitchKeyword = 96, + ThisKeyword = 97, + ThrowKeyword = 98, + TrueKeyword = 99, + TryKeyword = 100, + TypeOfKeyword = 101, + VarKeyword = 102, + VoidKeyword = 103, + WhileKeyword = 104, + WithKeyword = 105, + ImplementsKeyword = 106, + InterfaceKeyword = 107, + LetKeyword = 108, + PackageKeyword = 109, + PrivateKeyword = 110, + ProtectedKeyword = 111, + PublicKeyword = 112, + StaticKeyword = 113, + YieldKeyword = 114, + AbstractKeyword = 115, + AsKeyword = 116, + AnyKeyword = 117, + AsyncKeyword = 118, + AwaitKeyword = 119, + BooleanKeyword = 120, + ConstructorKeyword = 121, + DeclareKeyword = 122, + GetKeyword = 123, + IsKeyword = 124, + ModuleKeyword = 125, + NamespaceKeyword = 126, + RequireKeyword = 127, + NumberKeyword = 128, + SetKeyword = 129, + StringKeyword = 130, + SymbolKeyword = 131, + TypeKeyword = 132, + FromKeyword = 133, + OfKeyword = 134, + QualifiedName = 135, + ComputedPropertyName = 136, + TypeParameter = 137, + Parameter = 138, + Decorator = 139, + PropertySignature = 140, + PropertyDeclaration = 141, + MethodSignature = 142, + MethodDeclaration = 143, + Constructor = 144, + GetAccessor = 145, + SetAccessor = 146, + CallSignature = 147, + ConstructSignature = 148, + IndexSignature = 149, + TypePredicate = 150, + TypeReference = 151, + FunctionType = 152, + ConstructorType = 153, + TypeQuery = 154, + TypeLiteral = 155, + ArrayType = 156, + TupleType = 157, + UnionType = 158, + IntersectionType = 159, + ParenthesizedType = 160, + ObjectBindingPattern = 161, + ArrayBindingPattern = 162, + BindingElement = 163, + ArrayLiteralExpression = 164, + ObjectLiteralExpression = 165, + PropertyAccessExpression = 166, + ElementAccessExpression = 167, + CallExpression = 168, + NewExpression = 169, + TaggedTemplateExpression = 170, + TypeAssertionExpression = 171, + ParenthesizedExpression = 172, + FunctionExpression = 173, + ArrowFunction = 174, + DeleteExpression = 175, + TypeOfExpression = 176, + VoidExpression = 177, + AwaitExpression = 178, + PrefixUnaryExpression = 179, + PostfixUnaryExpression = 180, + BinaryExpression = 181, + ConditionalExpression = 182, + TemplateExpression = 183, + YieldExpression = 184, + SpreadElementExpression = 185, + ClassExpression = 186, + OmittedExpression = 187, + ExpressionWithTypeArguments = 188, + AsExpression = 189, + TemplateSpan = 190, + SemicolonClassElement = 191, + Block = 192, + VariableStatement = 193, + EmptyStatement = 194, + ExpressionStatement = 195, + IfStatement = 196, + DoStatement = 197, + WhileStatement = 198, + ForStatement = 199, + ForInStatement = 200, + ForOfStatement = 201, + ContinueStatement = 202, + BreakStatement = 203, + ReturnStatement = 204, + WithStatement = 205, + SwitchStatement = 206, + LabeledStatement = 207, + ThrowStatement = 208, + TryStatement = 209, + DebuggerStatement = 210, + VariableDeclaration = 211, + VariableDeclarationList = 212, + FunctionDeclaration = 213, + ClassDeclaration = 214, + InterfaceDeclaration = 215, + TypeAliasDeclaration = 216, + EnumDeclaration = 217, + ModuleDeclaration = 218, + ModuleBlock = 219, + CaseBlock = 220, + ImportEqualsDeclaration = 221, + ImportDeclaration = 222, + ImportClause = 223, + NamespaceImport = 224, + NamedImports = 225, + ImportSpecifier = 226, + ExportAssignment = 227, + ExportDeclaration = 228, + NamedExports = 229, + ExportSpecifier = 230, + MissingDeclaration = 231, + ExternalModuleReference = 232, + JsxElement = 233, + JsxSelfClosingElement = 234, + JsxOpeningElement = 235, + JsxText = 236, + JsxClosingElement = 237, + JsxAttribute = 238, + JsxSpreadAttribute = 239, + JsxExpression = 240, + CaseClause = 241, + DefaultClause = 242, + HeritageClause = 243, + CatchClause = 244, + PropertyAssignment = 245, + ShorthandPropertyAssignment = 246, + EnumMember = 247, + SourceFile = 248, + JSDocTypeExpression = 249, + JSDocAllType = 250, + JSDocUnknownType = 251, + JSDocArrayType = 252, + JSDocUnionType = 253, + JSDocTupleType = 254, + JSDocNullableType = 255, + JSDocNonNullableType = 256, + JSDocRecordType = 257, + JSDocRecordMember = 258, + JSDocTypeReference = 259, + JSDocOptionalType = 260, + JSDocFunctionType = 261, + JSDocVariadicType = 262, + JSDocConstructorType = 263, + JSDocThisType = 264, + JSDocComment = 265, + JSDocTag = 266, + JSDocParameterTag = 267, + JSDocReturnTag = 268, + JSDocTypeTag = 269, + JSDocTemplateTag = 270, + SyntaxList = 271, + Count = 272, + FirstAssignment = 56, + LastAssignment = 68, + FirstReservedWord = 70, + LastReservedWord = 105, + FirstKeyword = 70, + LastKeyword = 134, + FirstFutureReservedWord = 106, + LastFutureReservedWord = 114, + FirstTypeNode = 151, + LastTypeNode = 160, FirstPunctuation = 15, - LastPunctuation = 66, + LastPunctuation = 68, FirstToken = 0, - LastToken = 132, + LastToken = 134, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -322,8 +324,8 @@ declare namespace ts { FirstTemplateToken = 11, LastTemplateToken = 14, FirstBinaryOperator = 25, - LastBinaryOperator = 66, - FirstNode = 133, + LastBinaryOperator = 68, + FirstNode = 135, } const enum NodeFlags { Export = 1, @@ -343,6 +345,7 @@ declare namespace ts { OctalLiteral = 65536, Namespace = 131072, ExportContext = 262144, + ContainsThis = 524288, Modifier = 2035, AccessibilityModifier = 112, BlockScoped = 49152, @@ -438,6 +441,8 @@ declare namespace ts { interface ShorthandPropertyAssignment extends ObjectLiteralElement { name: Identifier; questionToken?: Node; + equalsToken?: Node; + objectAssignmentInitializer?: Expression; } interface VariableLikeDeclaration extends Declaration { propertyName?: Identifier; @@ -530,18 +535,21 @@ declare namespace ts { interface UnaryExpression extends Expression { _unaryExpressionBrand: any; } - interface PrefixUnaryExpression extends UnaryExpression { + interface IncrementExpression extends UnaryExpression { + _incrementExpressionBrand: any; + } + interface PrefixUnaryExpression extends IncrementExpression { operator: SyntaxKind; operand: UnaryExpression; } - interface PostfixUnaryExpression extends PostfixExpression { + interface PostfixUnaryExpression extends IncrementExpression { operand: LeftHandSideExpression; operator: SyntaxKind; } interface PostfixExpression extends UnaryExpression { _postfixExpressionBrand: any; } - interface LeftHandSideExpression extends PostfixExpression { + interface LeftHandSideExpression extends IncrementExpression { _leftHandSideExpressionBrand: any; } interface MemberExpression extends LeftHandSideExpression { @@ -1082,6 +1090,7 @@ declare namespace ts { decreaseIndent(): void; clear(): void; trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; + reportInaccessibleThisError(): void; } const enum TypeFormatFlags { None = 0, @@ -1202,6 +1211,7 @@ declare namespace ts { Instantiated = 131072, ObjectLiteral = 524288, ESSymbol = 16777216, + ThisType = 33554432, StringLike = 258, NumberLike = 132, ObjectType = 80896, @@ -1223,6 +1233,7 @@ declare namespace ts { typeParameters: TypeParameter[]; outerTypeParameters: TypeParameter[]; localTypeParameters: TypeParameter[]; + thisType: TypeParameter; } interface InterfaceTypeWithDeclaredMembers extends InterfaceType { declaredProperties: Symbol[]; @@ -1337,7 +1348,6 @@ declare namespace ts { watch?: boolean; isolatedModules?: boolean; experimentalDecorators?: boolean; - experimentalAsyncFunctions?: boolean; emitDecoratorMetadata?: boolean; moduleResolution?: ModuleResolutionKind; [option: string]: string | number | boolean; @@ -1348,6 +1358,8 @@ declare namespace ts { AMD = 2, UMD = 3, System = 4, + ES6 = 5, + ES2015 = 5, } const enum JsxEmit { None = 0, @@ -1366,6 +1378,7 @@ declare namespace ts { ES3 = 0, ES5 = 1, ES6 = 2, + ES2015 = 2, Latest = 2, } const enum LanguageVariant { @@ -1417,7 +1430,8 @@ declare namespace ts { write(s: string): void; readFile(path: string, encoding?: string): string; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; - watchFile?(path: string, callback: (path: string) => void): FileWatcher; + watchFile?(path: string, callback: (path: string, removed?: boolean) => void): FileWatcher; + watchDirectory?(path: string, callback: (path: string) => void, recursive?: boolean): FileWatcher; resolvePath(path: string): string; fileExists(path: string): boolean; directoryExists(path: string): boolean; @@ -1507,6 +1521,7 @@ declare namespace ts { */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; function getTypeParameterOwner(d: Declaration): Declaration; + function arrayStructurallyIsEqualTo(array1: Array, array2: Array): boolean; } declare namespace ts { function getNodeConstructor(kind: SyntaxKind): new () => Node; @@ -1542,7 +1557,7 @@ declare namespace ts { * @param fileName The path to the config file * @param jsonText The text of the config file */ - function parseConfigFileText(fileName: string, jsonText: string): { + function parseConfigFileTextToJson(fileName: string, jsonText: string): { config?: any; error?: Diagnostic; }; @@ -1552,7 +1567,7 @@ declare namespace ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine; + function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine; } declare namespace ts { /** The version of the language service API */ @@ -1775,6 +1790,12 @@ declare namespace ts { TabSize: number; NewLineCharacter: string; ConvertTabsToSpaces: boolean; + IndentStyle: IndentStyle; + } + enum IndentStyle { + None = 0, + Block = 1, + Smart = 2, } interface FormatCodeOptions extends EditorOptions { InsertSpaceAfterCommaDelimiter: boolean; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index a1f9651570e..7f9c5c293ad 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -62,279 +62,281 @@ var ts; SyntaxKind[SyntaxKind["PlusToken"] = 35] = "PlusToken"; SyntaxKind[SyntaxKind["MinusToken"] = 36] = "MinusToken"; SyntaxKind[SyntaxKind["AsteriskToken"] = 37] = "AsteriskToken"; - SyntaxKind[SyntaxKind["SlashToken"] = 38] = "SlashToken"; - SyntaxKind[SyntaxKind["PercentToken"] = 39] = "PercentToken"; - SyntaxKind[SyntaxKind["PlusPlusToken"] = 40] = "PlusPlusToken"; - SyntaxKind[SyntaxKind["MinusMinusToken"] = 41] = "MinusMinusToken"; - SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 42] = "LessThanLessThanToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 43] = "GreaterThanGreaterThanToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 44] = "GreaterThanGreaterThanGreaterThanToken"; - SyntaxKind[SyntaxKind["AmpersandToken"] = 45] = "AmpersandToken"; - SyntaxKind[SyntaxKind["BarToken"] = 46] = "BarToken"; - SyntaxKind[SyntaxKind["CaretToken"] = 47] = "CaretToken"; - SyntaxKind[SyntaxKind["ExclamationToken"] = 48] = "ExclamationToken"; - SyntaxKind[SyntaxKind["TildeToken"] = 49] = "TildeToken"; - SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 50] = "AmpersandAmpersandToken"; - SyntaxKind[SyntaxKind["BarBarToken"] = 51] = "BarBarToken"; - SyntaxKind[SyntaxKind["QuestionToken"] = 52] = "QuestionToken"; - SyntaxKind[SyntaxKind["ColonToken"] = 53] = "ColonToken"; - SyntaxKind[SyntaxKind["AtToken"] = 54] = "AtToken"; + SyntaxKind[SyntaxKind["AsteriskAsteriskToken"] = 38] = "AsteriskAsteriskToken"; + SyntaxKind[SyntaxKind["SlashToken"] = 39] = "SlashToken"; + SyntaxKind[SyntaxKind["PercentToken"] = 40] = "PercentToken"; + SyntaxKind[SyntaxKind["PlusPlusToken"] = 41] = "PlusPlusToken"; + SyntaxKind[SyntaxKind["MinusMinusToken"] = 42] = "MinusMinusToken"; + SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 43] = "LessThanLessThanToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 44] = "GreaterThanGreaterThanToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 45] = "GreaterThanGreaterThanGreaterThanToken"; + SyntaxKind[SyntaxKind["AmpersandToken"] = 46] = "AmpersandToken"; + SyntaxKind[SyntaxKind["BarToken"] = 47] = "BarToken"; + SyntaxKind[SyntaxKind["CaretToken"] = 48] = "CaretToken"; + SyntaxKind[SyntaxKind["ExclamationToken"] = 49] = "ExclamationToken"; + SyntaxKind[SyntaxKind["TildeToken"] = 50] = "TildeToken"; + SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 51] = "AmpersandAmpersandToken"; + SyntaxKind[SyntaxKind["BarBarToken"] = 52] = "BarBarToken"; + SyntaxKind[SyntaxKind["QuestionToken"] = 53] = "QuestionToken"; + SyntaxKind[SyntaxKind["ColonToken"] = 54] = "ColonToken"; + SyntaxKind[SyntaxKind["AtToken"] = 55] = "AtToken"; // Assignments - SyntaxKind[SyntaxKind["EqualsToken"] = 55] = "EqualsToken"; - SyntaxKind[SyntaxKind["PlusEqualsToken"] = 56] = "PlusEqualsToken"; - SyntaxKind[SyntaxKind["MinusEqualsToken"] = 57] = "MinusEqualsToken"; - SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 58] = "AsteriskEqualsToken"; - SyntaxKind[SyntaxKind["SlashEqualsToken"] = 59] = "SlashEqualsToken"; - SyntaxKind[SyntaxKind["PercentEqualsToken"] = 60] = "PercentEqualsToken"; - SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 61] = "LessThanLessThanEqualsToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 62] = "GreaterThanGreaterThanEqualsToken"; - SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 63] = "GreaterThanGreaterThanGreaterThanEqualsToken"; - SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 64] = "AmpersandEqualsToken"; - SyntaxKind[SyntaxKind["BarEqualsToken"] = 65] = "BarEqualsToken"; - SyntaxKind[SyntaxKind["CaretEqualsToken"] = 66] = "CaretEqualsToken"; + SyntaxKind[SyntaxKind["EqualsToken"] = 56] = "EqualsToken"; + SyntaxKind[SyntaxKind["PlusEqualsToken"] = 57] = "PlusEqualsToken"; + SyntaxKind[SyntaxKind["MinusEqualsToken"] = 58] = "MinusEqualsToken"; + SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 59] = "AsteriskEqualsToken"; + SyntaxKind[SyntaxKind["AsteriskAsteriskEqualsToken"] = 60] = "AsteriskAsteriskEqualsToken"; + SyntaxKind[SyntaxKind["SlashEqualsToken"] = 61] = "SlashEqualsToken"; + SyntaxKind[SyntaxKind["PercentEqualsToken"] = 62] = "PercentEqualsToken"; + SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 63] = "LessThanLessThanEqualsToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 64] = "GreaterThanGreaterThanEqualsToken"; + SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 65] = "GreaterThanGreaterThanGreaterThanEqualsToken"; + SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 66] = "AmpersandEqualsToken"; + SyntaxKind[SyntaxKind["BarEqualsToken"] = 67] = "BarEqualsToken"; + SyntaxKind[SyntaxKind["CaretEqualsToken"] = 68] = "CaretEqualsToken"; // Identifiers - SyntaxKind[SyntaxKind["Identifier"] = 67] = "Identifier"; + SyntaxKind[SyntaxKind["Identifier"] = 69] = "Identifier"; // Reserved words - SyntaxKind[SyntaxKind["BreakKeyword"] = 68] = "BreakKeyword"; - SyntaxKind[SyntaxKind["CaseKeyword"] = 69] = "CaseKeyword"; - SyntaxKind[SyntaxKind["CatchKeyword"] = 70] = "CatchKeyword"; - SyntaxKind[SyntaxKind["ClassKeyword"] = 71] = "ClassKeyword"; - SyntaxKind[SyntaxKind["ConstKeyword"] = 72] = "ConstKeyword"; - SyntaxKind[SyntaxKind["ContinueKeyword"] = 73] = "ContinueKeyword"; - SyntaxKind[SyntaxKind["DebuggerKeyword"] = 74] = "DebuggerKeyword"; - SyntaxKind[SyntaxKind["DefaultKeyword"] = 75] = "DefaultKeyword"; - SyntaxKind[SyntaxKind["DeleteKeyword"] = 76] = "DeleteKeyword"; - SyntaxKind[SyntaxKind["DoKeyword"] = 77] = "DoKeyword"; - SyntaxKind[SyntaxKind["ElseKeyword"] = 78] = "ElseKeyword"; - SyntaxKind[SyntaxKind["EnumKeyword"] = 79] = "EnumKeyword"; - SyntaxKind[SyntaxKind["ExportKeyword"] = 80] = "ExportKeyword"; - SyntaxKind[SyntaxKind["ExtendsKeyword"] = 81] = "ExtendsKeyword"; - SyntaxKind[SyntaxKind["FalseKeyword"] = 82] = "FalseKeyword"; - SyntaxKind[SyntaxKind["FinallyKeyword"] = 83] = "FinallyKeyword"; - SyntaxKind[SyntaxKind["ForKeyword"] = 84] = "ForKeyword"; - SyntaxKind[SyntaxKind["FunctionKeyword"] = 85] = "FunctionKeyword"; - SyntaxKind[SyntaxKind["IfKeyword"] = 86] = "IfKeyword"; - SyntaxKind[SyntaxKind["ImportKeyword"] = 87] = "ImportKeyword"; - SyntaxKind[SyntaxKind["InKeyword"] = 88] = "InKeyword"; - SyntaxKind[SyntaxKind["InstanceOfKeyword"] = 89] = "InstanceOfKeyword"; - SyntaxKind[SyntaxKind["NewKeyword"] = 90] = "NewKeyword"; - SyntaxKind[SyntaxKind["NullKeyword"] = 91] = "NullKeyword"; - SyntaxKind[SyntaxKind["ReturnKeyword"] = 92] = "ReturnKeyword"; - SyntaxKind[SyntaxKind["SuperKeyword"] = 93] = "SuperKeyword"; - SyntaxKind[SyntaxKind["SwitchKeyword"] = 94] = "SwitchKeyword"; - SyntaxKind[SyntaxKind["ThisKeyword"] = 95] = "ThisKeyword"; - SyntaxKind[SyntaxKind["ThrowKeyword"] = 96] = "ThrowKeyword"; - SyntaxKind[SyntaxKind["TrueKeyword"] = 97] = "TrueKeyword"; - SyntaxKind[SyntaxKind["TryKeyword"] = 98] = "TryKeyword"; - SyntaxKind[SyntaxKind["TypeOfKeyword"] = 99] = "TypeOfKeyword"; - SyntaxKind[SyntaxKind["VarKeyword"] = 100] = "VarKeyword"; - SyntaxKind[SyntaxKind["VoidKeyword"] = 101] = "VoidKeyword"; - SyntaxKind[SyntaxKind["WhileKeyword"] = 102] = "WhileKeyword"; - SyntaxKind[SyntaxKind["WithKeyword"] = 103] = "WithKeyword"; + SyntaxKind[SyntaxKind["BreakKeyword"] = 70] = "BreakKeyword"; + SyntaxKind[SyntaxKind["CaseKeyword"] = 71] = "CaseKeyword"; + SyntaxKind[SyntaxKind["CatchKeyword"] = 72] = "CatchKeyword"; + SyntaxKind[SyntaxKind["ClassKeyword"] = 73] = "ClassKeyword"; + SyntaxKind[SyntaxKind["ConstKeyword"] = 74] = "ConstKeyword"; + SyntaxKind[SyntaxKind["ContinueKeyword"] = 75] = "ContinueKeyword"; + SyntaxKind[SyntaxKind["DebuggerKeyword"] = 76] = "DebuggerKeyword"; + SyntaxKind[SyntaxKind["DefaultKeyword"] = 77] = "DefaultKeyword"; + SyntaxKind[SyntaxKind["DeleteKeyword"] = 78] = "DeleteKeyword"; + SyntaxKind[SyntaxKind["DoKeyword"] = 79] = "DoKeyword"; + SyntaxKind[SyntaxKind["ElseKeyword"] = 80] = "ElseKeyword"; + SyntaxKind[SyntaxKind["EnumKeyword"] = 81] = "EnumKeyword"; + SyntaxKind[SyntaxKind["ExportKeyword"] = 82] = "ExportKeyword"; + SyntaxKind[SyntaxKind["ExtendsKeyword"] = 83] = "ExtendsKeyword"; + SyntaxKind[SyntaxKind["FalseKeyword"] = 84] = "FalseKeyword"; + SyntaxKind[SyntaxKind["FinallyKeyword"] = 85] = "FinallyKeyword"; + SyntaxKind[SyntaxKind["ForKeyword"] = 86] = "ForKeyword"; + SyntaxKind[SyntaxKind["FunctionKeyword"] = 87] = "FunctionKeyword"; + SyntaxKind[SyntaxKind["IfKeyword"] = 88] = "IfKeyword"; + SyntaxKind[SyntaxKind["ImportKeyword"] = 89] = "ImportKeyword"; + SyntaxKind[SyntaxKind["InKeyword"] = 90] = "InKeyword"; + SyntaxKind[SyntaxKind["InstanceOfKeyword"] = 91] = "InstanceOfKeyword"; + SyntaxKind[SyntaxKind["NewKeyword"] = 92] = "NewKeyword"; + SyntaxKind[SyntaxKind["NullKeyword"] = 93] = "NullKeyword"; + SyntaxKind[SyntaxKind["ReturnKeyword"] = 94] = "ReturnKeyword"; + SyntaxKind[SyntaxKind["SuperKeyword"] = 95] = "SuperKeyword"; + SyntaxKind[SyntaxKind["SwitchKeyword"] = 96] = "SwitchKeyword"; + SyntaxKind[SyntaxKind["ThisKeyword"] = 97] = "ThisKeyword"; + SyntaxKind[SyntaxKind["ThrowKeyword"] = 98] = "ThrowKeyword"; + SyntaxKind[SyntaxKind["TrueKeyword"] = 99] = "TrueKeyword"; + SyntaxKind[SyntaxKind["TryKeyword"] = 100] = "TryKeyword"; + SyntaxKind[SyntaxKind["TypeOfKeyword"] = 101] = "TypeOfKeyword"; + SyntaxKind[SyntaxKind["VarKeyword"] = 102] = "VarKeyword"; + SyntaxKind[SyntaxKind["VoidKeyword"] = 103] = "VoidKeyword"; + SyntaxKind[SyntaxKind["WhileKeyword"] = 104] = "WhileKeyword"; + SyntaxKind[SyntaxKind["WithKeyword"] = 105] = "WithKeyword"; // Strict mode reserved words - SyntaxKind[SyntaxKind["ImplementsKeyword"] = 104] = "ImplementsKeyword"; - SyntaxKind[SyntaxKind["InterfaceKeyword"] = 105] = "InterfaceKeyword"; - SyntaxKind[SyntaxKind["LetKeyword"] = 106] = "LetKeyword"; - SyntaxKind[SyntaxKind["PackageKeyword"] = 107] = "PackageKeyword"; - SyntaxKind[SyntaxKind["PrivateKeyword"] = 108] = "PrivateKeyword"; - SyntaxKind[SyntaxKind["ProtectedKeyword"] = 109] = "ProtectedKeyword"; - SyntaxKind[SyntaxKind["PublicKeyword"] = 110] = "PublicKeyword"; - SyntaxKind[SyntaxKind["StaticKeyword"] = 111] = "StaticKeyword"; - SyntaxKind[SyntaxKind["YieldKeyword"] = 112] = "YieldKeyword"; + SyntaxKind[SyntaxKind["ImplementsKeyword"] = 106] = "ImplementsKeyword"; + SyntaxKind[SyntaxKind["InterfaceKeyword"] = 107] = "InterfaceKeyword"; + SyntaxKind[SyntaxKind["LetKeyword"] = 108] = "LetKeyword"; + SyntaxKind[SyntaxKind["PackageKeyword"] = 109] = "PackageKeyword"; + SyntaxKind[SyntaxKind["PrivateKeyword"] = 110] = "PrivateKeyword"; + SyntaxKind[SyntaxKind["ProtectedKeyword"] = 111] = "ProtectedKeyword"; + SyntaxKind[SyntaxKind["PublicKeyword"] = 112] = "PublicKeyword"; + SyntaxKind[SyntaxKind["StaticKeyword"] = 113] = "StaticKeyword"; + SyntaxKind[SyntaxKind["YieldKeyword"] = 114] = "YieldKeyword"; // Contextual keywords - SyntaxKind[SyntaxKind["AbstractKeyword"] = 113] = "AbstractKeyword"; - SyntaxKind[SyntaxKind["AsKeyword"] = 114] = "AsKeyword"; - SyntaxKind[SyntaxKind["AnyKeyword"] = 115] = "AnyKeyword"; - SyntaxKind[SyntaxKind["AsyncKeyword"] = 116] = "AsyncKeyword"; - SyntaxKind[SyntaxKind["AwaitKeyword"] = 117] = "AwaitKeyword"; - SyntaxKind[SyntaxKind["BooleanKeyword"] = 118] = "BooleanKeyword"; - SyntaxKind[SyntaxKind["ConstructorKeyword"] = 119] = "ConstructorKeyword"; - SyntaxKind[SyntaxKind["DeclareKeyword"] = 120] = "DeclareKeyword"; - SyntaxKind[SyntaxKind["GetKeyword"] = 121] = "GetKeyword"; - SyntaxKind[SyntaxKind["IsKeyword"] = 122] = "IsKeyword"; - SyntaxKind[SyntaxKind["ModuleKeyword"] = 123] = "ModuleKeyword"; - SyntaxKind[SyntaxKind["NamespaceKeyword"] = 124] = "NamespaceKeyword"; - SyntaxKind[SyntaxKind["RequireKeyword"] = 125] = "RequireKeyword"; - SyntaxKind[SyntaxKind["NumberKeyword"] = 126] = "NumberKeyword"; - SyntaxKind[SyntaxKind["SetKeyword"] = 127] = "SetKeyword"; - SyntaxKind[SyntaxKind["StringKeyword"] = 128] = "StringKeyword"; - SyntaxKind[SyntaxKind["SymbolKeyword"] = 129] = "SymbolKeyword"; - SyntaxKind[SyntaxKind["TypeKeyword"] = 130] = "TypeKeyword"; - SyntaxKind[SyntaxKind["FromKeyword"] = 131] = "FromKeyword"; - SyntaxKind[SyntaxKind["OfKeyword"] = 132] = "OfKeyword"; + SyntaxKind[SyntaxKind["AbstractKeyword"] = 115] = "AbstractKeyword"; + SyntaxKind[SyntaxKind["AsKeyword"] = 116] = "AsKeyword"; + SyntaxKind[SyntaxKind["AnyKeyword"] = 117] = "AnyKeyword"; + SyntaxKind[SyntaxKind["AsyncKeyword"] = 118] = "AsyncKeyword"; + SyntaxKind[SyntaxKind["AwaitKeyword"] = 119] = "AwaitKeyword"; + SyntaxKind[SyntaxKind["BooleanKeyword"] = 120] = "BooleanKeyword"; + SyntaxKind[SyntaxKind["ConstructorKeyword"] = 121] = "ConstructorKeyword"; + SyntaxKind[SyntaxKind["DeclareKeyword"] = 122] = "DeclareKeyword"; + SyntaxKind[SyntaxKind["GetKeyword"] = 123] = "GetKeyword"; + SyntaxKind[SyntaxKind["IsKeyword"] = 124] = "IsKeyword"; + SyntaxKind[SyntaxKind["ModuleKeyword"] = 125] = "ModuleKeyword"; + SyntaxKind[SyntaxKind["NamespaceKeyword"] = 126] = "NamespaceKeyword"; + SyntaxKind[SyntaxKind["RequireKeyword"] = 127] = "RequireKeyword"; + SyntaxKind[SyntaxKind["NumberKeyword"] = 128] = "NumberKeyword"; + SyntaxKind[SyntaxKind["SetKeyword"] = 129] = "SetKeyword"; + SyntaxKind[SyntaxKind["StringKeyword"] = 130] = "StringKeyword"; + SyntaxKind[SyntaxKind["SymbolKeyword"] = 131] = "SymbolKeyword"; + SyntaxKind[SyntaxKind["TypeKeyword"] = 132] = "TypeKeyword"; + SyntaxKind[SyntaxKind["FromKeyword"] = 133] = "FromKeyword"; + SyntaxKind[SyntaxKind["OfKeyword"] = 134] = "OfKeyword"; // Parse tree nodes // Names - SyntaxKind[SyntaxKind["QualifiedName"] = 133] = "QualifiedName"; - SyntaxKind[SyntaxKind["ComputedPropertyName"] = 134] = "ComputedPropertyName"; + SyntaxKind[SyntaxKind["QualifiedName"] = 135] = "QualifiedName"; + SyntaxKind[SyntaxKind["ComputedPropertyName"] = 136] = "ComputedPropertyName"; // Signature elements - SyntaxKind[SyntaxKind["TypeParameter"] = 135] = "TypeParameter"; - SyntaxKind[SyntaxKind["Parameter"] = 136] = "Parameter"; - SyntaxKind[SyntaxKind["Decorator"] = 137] = "Decorator"; + SyntaxKind[SyntaxKind["TypeParameter"] = 137] = "TypeParameter"; + SyntaxKind[SyntaxKind["Parameter"] = 138] = "Parameter"; + SyntaxKind[SyntaxKind["Decorator"] = 139] = "Decorator"; // TypeMember - SyntaxKind[SyntaxKind["PropertySignature"] = 138] = "PropertySignature"; - SyntaxKind[SyntaxKind["PropertyDeclaration"] = 139] = "PropertyDeclaration"; - SyntaxKind[SyntaxKind["MethodSignature"] = 140] = "MethodSignature"; - SyntaxKind[SyntaxKind["MethodDeclaration"] = 141] = "MethodDeclaration"; - SyntaxKind[SyntaxKind["Constructor"] = 142] = "Constructor"; - SyntaxKind[SyntaxKind["GetAccessor"] = 143] = "GetAccessor"; - SyntaxKind[SyntaxKind["SetAccessor"] = 144] = "SetAccessor"; - SyntaxKind[SyntaxKind["CallSignature"] = 145] = "CallSignature"; - SyntaxKind[SyntaxKind["ConstructSignature"] = 146] = "ConstructSignature"; - SyntaxKind[SyntaxKind["IndexSignature"] = 147] = "IndexSignature"; + SyntaxKind[SyntaxKind["PropertySignature"] = 140] = "PropertySignature"; + SyntaxKind[SyntaxKind["PropertyDeclaration"] = 141] = "PropertyDeclaration"; + SyntaxKind[SyntaxKind["MethodSignature"] = 142] = "MethodSignature"; + SyntaxKind[SyntaxKind["MethodDeclaration"] = 143] = "MethodDeclaration"; + SyntaxKind[SyntaxKind["Constructor"] = 144] = "Constructor"; + SyntaxKind[SyntaxKind["GetAccessor"] = 145] = "GetAccessor"; + SyntaxKind[SyntaxKind["SetAccessor"] = 146] = "SetAccessor"; + SyntaxKind[SyntaxKind["CallSignature"] = 147] = "CallSignature"; + SyntaxKind[SyntaxKind["ConstructSignature"] = 148] = "ConstructSignature"; + SyntaxKind[SyntaxKind["IndexSignature"] = 149] = "IndexSignature"; // Type - SyntaxKind[SyntaxKind["TypePredicate"] = 148] = "TypePredicate"; - SyntaxKind[SyntaxKind["TypeReference"] = 149] = "TypeReference"; - SyntaxKind[SyntaxKind["FunctionType"] = 150] = "FunctionType"; - SyntaxKind[SyntaxKind["ConstructorType"] = 151] = "ConstructorType"; - SyntaxKind[SyntaxKind["TypeQuery"] = 152] = "TypeQuery"; - SyntaxKind[SyntaxKind["TypeLiteral"] = 153] = "TypeLiteral"; - SyntaxKind[SyntaxKind["ArrayType"] = 154] = "ArrayType"; - SyntaxKind[SyntaxKind["TupleType"] = 155] = "TupleType"; - SyntaxKind[SyntaxKind["UnionType"] = 156] = "UnionType"; - SyntaxKind[SyntaxKind["IntersectionType"] = 157] = "IntersectionType"; - SyntaxKind[SyntaxKind["ParenthesizedType"] = 158] = "ParenthesizedType"; + SyntaxKind[SyntaxKind["TypePredicate"] = 150] = "TypePredicate"; + SyntaxKind[SyntaxKind["TypeReference"] = 151] = "TypeReference"; + SyntaxKind[SyntaxKind["FunctionType"] = 152] = "FunctionType"; + SyntaxKind[SyntaxKind["ConstructorType"] = 153] = "ConstructorType"; + SyntaxKind[SyntaxKind["TypeQuery"] = 154] = "TypeQuery"; + SyntaxKind[SyntaxKind["TypeLiteral"] = 155] = "TypeLiteral"; + SyntaxKind[SyntaxKind["ArrayType"] = 156] = "ArrayType"; + SyntaxKind[SyntaxKind["TupleType"] = 157] = "TupleType"; + SyntaxKind[SyntaxKind["UnionType"] = 158] = "UnionType"; + SyntaxKind[SyntaxKind["IntersectionType"] = 159] = "IntersectionType"; + SyntaxKind[SyntaxKind["ParenthesizedType"] = 160] = "ParenthesizedType"; // Binding patterns - SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 159] = "ObjectBindingPattern"; - SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 160] = "ArrayBindingPattern"; - SyntaxKind[SyntaxKind["BindingElement"] = 161] = "BindingElement"; + SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 161] = "ObjectBindingPattern"; + SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 162] = "ArrayBindingPattern"; + SyntaxKind[SyntaxKind["BindingElement"] = 163] = "BindingElement"; // Expression - SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 162] = "ArrayLiteralExpression"; - SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 163] = "ObjectLiteralExpression"; - SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 164] = "PropertyAccessExpression"; - SyntaxKind[SyntaxKind["ElementAccessExpression"] = 165] = "ElementAccessExpression"; - SyntaxKind[SyntaxKind["CallExpression"] = 166] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 167] = "NewExpression"; - SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 168] = "TaggedTemplateExpression"; - SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 169] = "TypeAssertionExpression"; - SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 170] = "ParenthesizedExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 171] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 172] = "ArrowFunction"; - SyntaxKind[SyntaxKind["DeleteExpression"] = 173] = "DeleteExpression"; - SyntaxKind[SyntaxKind["TypeOfExpression"] = 174] = "TypeOfExpression"; - SyntaxKind[SyntaxKind["VoidExpression"] = 175] = "VoidExpression"; - SyntaxKind[SyntaxKind["AwaitExpression"] = 176] = "AwaitExpression"; - SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 177] = "PrefixUnaryExpression"; - SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 178] = "PostfixUnaryExpression"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 179] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 180] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["TemplateExpression"] = 181] = "TemplateExpression"; - SyntaxKind[SyntaxKind["YieldExpression"] = 182] = "YieldExpression"; - SyntaxKind[SyntaxKind["SpreadElementExpression"] = 183] = "SpreadElementExpression"; - SyntaxKind[SyntaxKind["ClassExpression"] = 184] = "ClassExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 185] = "OmittedExpression"; - SyntaxKind[SyntaxKind["ExpressionWithTypeArguments"] = 186] = "ExpressionWithTypeArguments"; - SyntaxKind[SyntaxKind["AsExpression"] = 187] = "AsExpression"; + SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 164] = "ArrayLiteralExpression"; + SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 165] = "ObjectLiteralExpression"; + SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 166] = "PropertyAccessExpression"; + SyntaxKind[SyntaxKind["ElementAccessExpression"] = 167] = "ElementAccessExpression"; + SyntaxKind[SyntaxKind["CallExpression"] = 168] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 169] = "NewExpression"; + SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 170] = "TaggedTemplateExpression"; + SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 171] = "TypeAssertionExpression"; + SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 172] = "ParenthesizedExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 173] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 174] = "ArrowFunction"; + SyntaxKind[SyntaxKind["DeleteExpression"] = 175] = "DeleteExpression"; + SyntaxKind[SyntaxKind["TypeOfExpression"] = 176] = "TypeOfExpression"; + SyntaxKind[SyntaxKind["VoidExpression"] = 177] = "VoidExpression"; + SyntaxKind[SyntaxKind["AwaitExpression"] = 178] = "AwaitExpression"; + SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 179] = "PrefixUnaryExpression"; + SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 180] = "PostfixUnaryExpression"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 181] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 182] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["TemplateExpression"] = 183] = "TemplateExpression"; + SyntaxKind[SyntaxKind["YieldExpression"] = 184] = "YieldExpression"; + SyntaxKind[SyntaxKind["SpreadElementExpression"] = 185] = "SpreadElementExpression"; + SyntaxKind[SyntaxKind["ClassExpression"] = 186] = "ClassExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 187] = "OmittedExpression"; + SyntaxKind[SyntaxKind["ExpressionWithTypeArguments"] = 188] = "ExpressionWithTypeArguments"; + SyntaxKind[SyntaxKind["AsExpression"] = 189] = "AsExpression"; // Misc - SyntaxKind[SyntaxKind["TemplateSpan"] = 188] = "TemplateSpan"; - SyntaxKind[SyntaxKind["SemicolonClassElement"] = 189] = "SemicolonClassElement"; + SyntaxKind[SyntaxKind["TemplateSpan"] = 190] = "TemplateSpan"; + SyntaxKind[SyntaxKind["SemicolonClassElement"] = 191] = "SemicolonClassElement"; // Element - SyntaxKind[SyntaxKind["Block"] = 190] = "Block"; - SyntaxKind[SyntaxKind["VariableStatement"] = 191] = "VariableStatement"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 192] = "EmptyStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 193] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 194] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 195] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 196] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 197] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 198] = "ForInStatement"; - SyntaxKind[SyntaxKind["ForOfStatement"] = 199] = "ForOfStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 200] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 201] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 202] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 203] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 204] = "SwitchStatement"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 205] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 206] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 207] = "TryStatement"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 208] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 209] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["VariableDeclarationList"] = 210] = "VariableDeclarationList"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 211] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 212] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 213] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 214] = "TypeAliasDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 215] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 216] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 217] = "ModuleBlock"; - SyntaxKind[SyntaxKind["CaseBlock"] = 218] = "CaseBlock"; - SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 219] = "ImportEqualsDeclaration"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 220] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ImportClause"] = 221] = "ImportClause"; - SyntaxKind[SyntaxKind["NamespaceImport"] = 222] = "NamespaceImport"; - SyntaxKind[SyntaxKind["NamedImports"] = 223] = "NamedImports"; - SyntaxKind[SyntaxKind["ImportSpecifier"] = 224] = "ImportSpecifier"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 225] = "ExportAssignment"; - SyntaxKind[SyntaxKind["ExportDeclaration"] = 226] = "ExportDeclaration"; - SyntaxKind[SyntaxKind["NamedExports"] = 227] = "NamedExports"; - SyntaxKind[SyntaxKind["ExportSpecifier"] = 228] = "ExportSpecifier"; - SyntaxKind[SyntaxKind["MissingDeclaration"] = 229] = "MissingDeclaration"; + SyntaxKind[SyntaxKind["Block"] = 192] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 193] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 194] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 195] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 196] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 197] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 198] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 199] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 200] = "ForInStatement"; + SyntaxKind[SyntaxKind["ForOfStatement"] = 201] = "ForOfStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 202] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 203] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 204] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 205] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 206] = "SwitchStatement"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 207] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 208] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 209] = "TryStatement"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 210] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 211] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["VariableDeclarationList"] = 212] = "VariableDeclarationList"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 213] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 214] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 215] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 216] = "TypeAliasDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 217] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 218] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 219] = "ModuleBlock"; + SyntaxKind[SyntaxKind["CaseBlock"] = 220] = "CaseBlock"; + SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 221] = "ImportEqualsDeclaration"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 222] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ImportClause"] = 223] = "ImportClause"; + SyntaxKind[SyntaxKind["NamespaceImport"] = 224] = "NamespaceImport"; + SyntaxKind[SyntaxKind["NamedImports"] = 225] = "NamedImports"; + SyntaxKind[SyntaxKind["ImportSpecifier"] = 226] = "ImportSpecifier"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 227] = "ExportAssignment"; + SyntaxKind[SyntaxKind["ExportDeclaration"] = 228] = "ExportDeclaration"; + SyntaxKind[SyntaxKind["NamedExports"] = 229] = "NamedExports"; + SyntaxKind[SyntaxKind["ExportSpecifier"] = 230] = "ExportSpecifier"; + SyntaxKind[SyntaxKind["MissingDeclaration"] = 231] = "MissingDeclaration"; // Module references - SyntaxKind[SyntaxKind["ExternalModuleReference"] = 230] = "ExternalModuleReference"; + SyntaxKind[SyntaxKind["ExternalModuleReference"] = 232] = "ExternalModuleReference"; // JSX - SyntaxKind[SyntaxKind["JsxElement"] = 231] = "JsxElement"; - SyntaxKind[SyntaxKind["JsxSelfClosingElement"] = 232] = "JsxSelfClosingElement"; - SyntaxKind[SyntaxKind["JsxOpeningElement"] = 233] = "JsxOpeningElement"; - SyntaxKind[SyntaxKind["JsxText"] = 234] = "JsxText"; - SyntaxKind[SyntaxKind["JsxClosingElement"] = 235] = "JsxClosingElement"; - SyntaxKind[SyntaxKind["JsxAttribute"] = 236] = "JsxAttribute"; - SyntaxKind[SyntaxKind["JsxSpreadAttribute"] = 237] = "JsxSpreadAttribute"; - SyntaxKind[SyntaxKind["JsxExpression"] = 238] = "JsxExpression"; + SyntaxKind[SyntaxKind["JsxElement"] = 233] = "JsxElement"; + SyntaxKind[SyntaxKind["JsxSelfClosingElement"] = 234] = "JsxSelfClosingElement"; + SyntaxKind[SyntaxKind["JsxOpeningElement"] = 235] = "JsxOpeningElement"; + SyntaxKind[SyntaxKind["JsxText"] = 236] = "JsxText"; + SyntaxKind[SyntaxKind["JsxClosingElement"] = 237] = "JsxClosingElement"; + SyntaxKind[SyntaxKind["JsxAttribute"] = 238] = "JsxAttribute"; + SyntaxKind[SyntaxKind["JsxSpreadAttribute"] = 239] = "JsxSpreadAttribute"; + SyntaxKind[SyntaxKind["JsxExpression"] = 240] = "JsxExpression"; // Clauses - SyntaxKind[SyntaxKind["CaseClause"] = 239] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 240] = "DefaultClause"; - SyntaxKind[SyntaxKind["HeritageClause"] = 241] = "HeritageClause"; - SyntaxKind[SyntaxKind["CatchClause"] = 242] = "CatchClause"; + SyntaxKind[SyntaxKind["CaseClause"] = 241] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 242] = "DefaultClause"; + SyntaxKind[SyntaxKind["HeritageClause"] = 243] = "HeritageClause"; + SyntaxKind[SyntaxKind["CatchClause"] = 244] = "CatchClause"; // Property assignments - SyntaxKind[SyntaxKind["PropertyAssignment"] = 243] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 244] = "ShorthandPropertyAssignment"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 245] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 246] = "ShorthandPropertyAssignment"; // Enum - SyntaxKind[SyntaxKind["EnumMember"] = 245] = "EnumMember"; + SyntaxKind[SyntaxKind["EnumMember"] = 247] = "EnumMember"; // Top-level nodes - SyntaxKind[SyntaxKind["SourceFile"] = 246] = "SourceFile"; + SyntaxKind[SyntaxKind["SourceFile"] = 248] = "SourceFile"; // JSDoc nodes. - SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 247] = "JSDocTypeExpression"; + SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 249] = "JSDocTypeExpression"; // The * type. - SyntaxKind[SyntaxKind["JSDocAllType"] = 248] = "JSDocAllType"; + SyntaxKind[SyntaxKind["JSDocAllType"] = 250] = "JSDocAllType"; // The ? type. - SyntaxKind[SyntaxKind["JSDocUnknownType"] = 249] = "JSDocUnknownType"; - SyntaxKind[SyntaxKind["JSDocArrayType"] = 250] = "JSDocArrayType"; - SyntaxKind[SyntaxKind["JSDocUnionType"] = 251] = "JSDocUnionType"; - SyntaxKind[SyntaxKind["JSDocTupleType"] = 252] = "JSDocTupleType"; - SyntaxKind[SyntaxKind["JSDocNullableType"] = 253] = "JSDocNullableType"; - SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 254] = "JSDocNonNullableType"; - SyntaxKind[SyntaxKind["JSDocRecordType"] = 255] = "JSDocRecordType"; - SyntaxKind[SyntaxKind["JSDocRecordMember"] = 256] = "JSDocRecordMember"; - SyntaxKind[SyntaxKind["JSDocTypeReference"] = 257] = "JSDocTypeReference"; - SyntaxKind[SyntaxKind["JSDocOptionalType"] = 258] = "JSDocOptionalType"; - SyntaxKind[SyntaxKind["JSDocFunctionType"] = 259] = "JSDocFunctionType"; - SyntaxKind[SyntaxKind["JSDocVariadicType"] = 260] = "JSDocVariadicType"; - SyntaxKind[SyntaxKind["JSDocConstructorType"] = 261] = "JSDocConstructorType"; - SyntaxKind[SyntaxKind["JSDocThisType"] = 262] = "JSDocThisType"; - SyntaxKind[SyntaxKind["JSDocComment"] = 263] = "JSDocComment"; - SyntaxKind[SyntaxKind["JSDocTag"] = 264] = "JSDocTag"; - SyntaxKind[SyntaxKind["JSDocParameterTag"] = 265] = "JSDocParameterTag"; - SyntaxKind[SyntaxKind["JSDocReturnTag"] = 266] = "JSDocReturnTag"; - SyntaxKind[SyntaxKind["JSDocTypeTag"] = 267] = "JSDocTypeTag"; - SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 268] = "JSDocTemplateTag"; + SyntaxKind[SyntaxKind["JSDocUnknownType"] = 251] = "JSDocUnknownType"; + SyntaxKind[SyntaxKind["JSDocArrayType"] = 252] = "JSDocArrayType"; + SyntaxKind[SyntaxKind["JSDocUnionType"] = 253] = "JSDocUnionType"; + SyntaxKind[SyntaxKind["JSDocTupleType"] = 254] = "JSDocTupleType"; + SyntaxKind[SyntaxKind["JSDocNullableType"] = 255] = "JSDocNullableType"; + SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 256] = "JSDocNonNullableType"; + SyntaxKind[SyntaxKind["JSDocRecordType"] = 257] = "JSDocRecordType"; + SyntaxKind[SyntaxKind["JSDocRecordMember"] = 258] = "JSDocRecordMember"; + SyntaxKind[SyntaxKind["JSDocTypeReference"] = 259] = "JSDocTypeReference"; + SyntaxKind[SyntaxKind["JSDocOptionalType"] = 260] = "JSDocOptionalType"; + SyntaxKind[SyntaxKind["JSDocFunctionType"] = 261] = "JSDocFunctionType"; + SyntaxKind[SyntaxKind["JSDocVariadicType"] = 262] = "JSDocVariadicType"; + SyntaxKind[SyntaxKind["JSDocConstructorType"] = 263] = "JSDocConstructorType"; + SyntaxKind[SyntaxKind["JSDocThisType"] = 264] = "JSDocThisType"; + SyntaxKind[SyntaxKind["JSDocComment"] = 265] = "JSDocComment"; + SyntaxKind[SyntaxKind["JSDocTag"] = 266] = "JSDocTag"; + SyntaxKind[SyntaxKind["JSDocParameterTag"] = 267] = "JSDocParameterTag"; + SyntaxKind[SyntaxKind["JSDocReturnTag"] = 268] = "JSDocReturnTag"; + SyntaxKind[SyntaxKind["JSDocTypeTag"] = 269] = "JSDocTypeTag"; + SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 270] = "JSDocTemplateTag"; // Synthesized list - SyntaxKind[SyntaxKind["SyntaxList"] = 269] = "SyntaxList"; + SyntaxKind[SyntaxKind["SyntaxList"] = 271] = "SyntaxList"; // Enum value count - SyntaxKind[SyntaxKind["Count"] = 270] = "Count"; + SyntaxKind[SyntaxKind["Count"] = 272] = "Count"; // Markers - SyntaxKind[SyntaxKind["FirstAssignment"] = 55] = "FirstAssignment"; - SyntaxKind[SyntaxKind["LastAssignment"] = 66] = "LastAssignment"; - SyntaxKind[SyntaxKind["FirstReservedWord"] = 68] = "FirstReservedWord"; - SyntaxKind[SyntaxKind["LastReservedWord"] = 103] = "LastReservedWord"; - SyntaxKind[SyntaxKind["FirstKeyword"] = 68] = "FirstKeyword"; - SyntaxKind[SyntaxKind["LastKeyword"] = 132] = "LastKeyword"; - SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 104] = "FirstFutureReservedWord"; - SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 112] = "LastFutureReservedWord"; - SyntaxKind[SyntaxKind["FirstTypeNode"] = 149] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = 158] = "LastTypeNode"; + SyntaxKind[SyntaxKind["FirstAssignment"] = 56] = "FirstAssignment"; + SyntaxKind[SyntaxKind["LastAssignment"] = 68] = "LastAssignment"; + SyntaxKind[SyntaxKind["FirstReservedWord"] = 70] = "FirstReservedWord"; + SyntaxKind[SyntaxKind["LastReservedWord"] = 105] = "LastReservedWord"; + SyntaxKind[SyntaxKind["FirstKeyword"] = 70] = "FirstKeyword"; + SyntaxKind[SyntaxKind["LastKeyword"] = 134] = "LastKeyword"; + SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 106] = "FirstFutureReservedWord"; + SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 114] = "LastFutureReservedWord"; + SyntaxKind[SyntaxKind["FirstTypeNode"] = 151] = "FirstTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = 160] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 15] = "FirstPunctuation"; - SyntaxKind[SyntaxKind["LastPunctuation"] = 66] = "LastPunctuation"; + SyntaxKind[SyntaxKind["LastPunctuation"] = 68] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = 0] = "FirstToken"; - SyntaxKind[SyntaxKind["LastToken"] = 132] = "LastToken"; + SyntaxKind[SyntaxKind["LastToken"] = 134] = "LastToken"; SyntaxKind[SyntaxKind["FirstTriviaToken"] = 2] = "FirstTriviaToken"; SyntaxKind[SyntaxKind["LastTriviaToken"] = 7] = "LastTriviaToken"; SyntaxKind[SyntaxKind["FirstLiteralToken"] = 8] = "FirstLiteralToken"; @@ -342,8 +344,8 @@ var ts; SyntaxKind[SyntaxKind["FirstTemplateToken"] = 11] = "FirstTemplateToken"; SyntaxKind[SyntaxKind["LastTemplateToken"] = 14] = "LastTemplateToken"; SyntaxKind[SyntaxKind["FirstBinaryOperator"] = 25] = "FirstBinaryOperator"; - SyntaxKind[SyntaxKind["LastBinaryOperator"] = 66] = "LastBinaryOperator"; - SyntaxKind[SyntaxKind["FirstNode"] = 133] = "FirstNode"; + SyntaxKind[SyntaxKind["LastBinaryOperator"] = 68] = "LastBinaryOperator"; + SyntaxKind[SyntaxKind["FirstNode"] = 135] = "FirstNode"; })(ts.SyntaxKind || (ts.SyntaxKind = {})); var SyntaxKind = ts.SyntaxKind; (function (NodeFlags) { @@ -364,6 +366,7 @@ var ts; NodeFlags[NodeFlags["OctalLiteral"] = 65536] = "OctalLiteral"; NodeFlags[NodeFlags["Namespace"] = 131072] = "Namespace"; NodeFlags[NodeFlags["ExportContext"] = 262144] = "ExportContext"; + NodeFlags[NodeFlags["ContainsThis"] = 524288] = "ContainsThis"; NodeFlags[NodeFlags["Modifier"] = 2035] = "Modifier"; NodeFlags[NodeFlags["AccessibilityModifier"] = 112] = "AccessibilityModifier"; NodeFlags[NodeFlags["BlockScoped"] = 49152] = "BlockScoped"; @@ -613,6 +616,7 @@ var ts; /* @internal */ TypeFlags[TypeFlags["ContainsAnyFunctionType"] = 8388608] = "ContainsAnyFunctionType"; TypeFlags[TypeFlags["ESSymbol"] = 16777216] = "ESSymbol"; + TypeFlags[TypeFlags["ThisType"] = 33554432] = "ThisType"; /* @internal */ TypeFlags[TypeFlags["Intrinsic"] = 16777343] = "Intrinsic"; /* @internal */ @@ -655,6 +659,8 @@ var ts; ModuleKind[ModuleKind["AMD"] = 2] = "AMD"; ModuleKind[ModuleKind["UMD"] = 3] = "UMD"; ModuleKind[ModuleKind["System"] = 4] = "System"; + ModuleKind[ModuleKind["ES6"] = 5] = "ES6"; + ModuleKind[ModuleKind["ES2015"] = 5] = "ES2015"; })(ts.ModuleKind || (ts.ModuleKind = {})); var ModuleKind = ts.ModuleKind; (function (JsxEmit) { @@ -672,6 +678,7 @@ var ts; ScriptTarget[ScriptTarget["ES3"] = 0] = "ES3"; ScriptTarget[ScriptTarget["ES5"] = 1] = "ES5"; ScriptTarget[ScriptTarget["ES6"] = 2] = "ES6"; + ScriptTarget[ScriptTarget["ES2015"] = 2] = "ES2015"; ScriptTarget[ScriptTarget["Latest"] = 2] = "Latest"; })(ts.ScriptTarget || (ts.ScriptTarget = {})); var ScriptTarget = ts.ScriptTarget; @@ -1221,8 +1228,11 @@ var ts; } ts.chainDiagnosticMessages = chainDiagnosticMessages; function concatenateDiagnosticMessageChains(headChain, tailChain) { - Debug.assert(!headChain.next); - headChain.next = tailChain; + var lastChain = headChain; + while (lastChain.next) { + lastChain = lastChain.next; + } + lastChain.next = tailChain; return headChain; } ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains; @@ -1470,6 +1480,9 @@ var ts; } ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl; function getBaseFileName(path) { + if (!path) { + return undefined; + } var i = path.lastIndexOf(ts.directorySeparator); return i < 0 ? path : path.substring(i + 1); } @@ -1496,6 +1509,25 @@ var ts; * List of supported extensions in order of file resolution precedence. */ ts.supportedExtensions = [".ts", ".tsx", ".d.ts"]; + /** + * List of extensions that will be used to look for external modules. + * This list is kept separate from supportedExtensions to for cases when we'll allow to include .js files in compilation, + * but still would like to load only TypeScript files as modules + */ + ts.moduleFileExtensions = ts.supportedExtensions; + function isSupportedSourceFileName(fileName) { + if (!fileName) { + return false; + } + for (var _i = 0; _i < ts.supportedExtensions.length; _i++) { + var extension = ts.supportedExtensions[_i]; + if (fileExtensionIs(fileName, extension)) { + return true; + } + } + return false; + } + ts.isSupportedSourceFileName = isSupportedSourceFileName; var extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"]; function removeFileExtension(path) { for (var _i = 0; _i < extensionsToRemove.length; _i++) { @@ -1579,6 +1611,16 @@ var ts; } Debug.fail = fail; })(Debug = ts.Debug || (ts.Debug = {})); + function copyListRemovingItem(item, list) { + var copiedList = []; + for (var i = 0, len = list.length; i < len; i++) { + if (list[i] !== item) { + copiedList.push(list[i]); + } + } + return copiedList; + } + ts.copyListRemovingItem = copyListRemovingItem; })(ts || (ts = {})); /// var ts; @@ -1725,6 +1767,94 @@ var ts; var _fs = require("fs"); var _path = require("path"); var _os = require("os"); + // average async stat takes about 30 microseconds + // set chunk size to do 30 files in < 1 millisecond + function createWatchedFileSet(interval, chunkSize) { + if (interval === void 0) { interval = 2500; } + if (chunkSize === void 0) { chunkSize = 30; } + var watchedFiles = []; + var nextFileToCheck = 0; + var watchTimer; + function getModifiedTime(fileName) { + return _fs.statSync(fileName).mtime; + } + function poll(checkedIndex) { + var watchedFile = watchedFiles[checkedIndex]; + if (!watchedFile) { + return; + } + _fs.stat(watchedFile.fileName, function (err, stats) { + if (err) { + watchedFile.callback(watchedFile.fileName); + } + else if (watchedFile.mtime.getTime() !== stats.mtime.getTime()) { + watchedFile.mtime = getModifiedTime(watchedFile.fileName); + watchedFile.callback(watchedFile.fileName, watchedFile.mtime.getTime() === 0); + } + }); + } + // this implementation uses polling and + // stat due to inconsistencies of fs.watch + // and efficiency of stat on modern filesystems + function startWatchTimer() { + watchTimer = setInterval(function () { + var count = 0; + var nextToCheck = nextFileToCheck; + var firstCheck = -1; + while ((count < chunkSize) && (nextToCheck !== firstCheck)) { + poll(nextToCheck); + if (firstCheck < 0) { + firstCheck = nextToCheck; + } + nextToCheck++; + if (nextToCheck === watchedFiles.length) { + nextToCheck = 0; + } + count++; + } + nextFileToCheck = nextToCheck; + }, interval); + } + function addFile(fileName, callback) { + var file = { + fileName: fileName, + callback: callback, + mtime: getModifiedTime(fileName) + }; + watchedFiles.push(file); + if (watchedFiles.length === 1) { + startWatchTimer(); + } + return file; + } + function removeFile(file) { + watchedFiles = ts.copyListRemovingItem(file, watchedFiles); + } + return { + getModifiedTime: getModifiedTime, + poll: poll, + startWatchTimer: startWatchTimer, + addFile: addFile, + removeFile: removeFile + }; + } + // REVIEW: for now this implementation uses polling. + // The advantage of polling is that it works reliably + // on all os and with network mounted files. + // For 90 referenced files, the average time to detect + // changes is 2*msInterval (by default 5 seconds). + // The overhead of this is .04 percent (1/2500) with + // average pause of < 1 millisecond (and max + // pause less than 1.5 milliseconds); question is + // do we anticipate reference sets in the 100s and + // do we care about waiting 10-20 seconds to detect + // changes for large reference sets? If so, do we want + // to increase the chunk size or decrease the interval + // time dynamically to match the large reference set? + var watchedFileSet = createWatchedFileSet(); + function isNode4OrLater() { + return parseInt(process.version.charAt(1)) >= 4; + } var platform = _os.platform(); // win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; @@ -1813,17 +1943,32 @@ var ts; readFile: readFile, writeFile: writeFile, watchFile: function (fileName, callback) { - // watchFile polls a file every 250ms, picking up file notifications. - _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged); - return { - close: function () { _fs.unwatchFile(fileName, fileChanged); } - }; - function fileChanged(curr, prev) { - if (+curr.mtime <= +prev.mtime) { - return; - } - callback(fileName); + // Node 4.0 stablized the `fs.watch` function on Windows which avoids polling + // and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649 + // and https://github.com/Microsoft/TypeScript/issues/4643), therefore + // if the current node.js version is newer than 4, use `fs.watch` instead. + if (isNode4OrLater()) { + // Note: in node the callback of fs.watch is given only the relative file name as a parameter + return _fs.watch(fileName, function (eventName, relativeFileName) { return callback(fileName); }); } + var watchedFile = watchedFileSet.addFile(fileName, callback); + return { + close: function () { return watchedFileSet.removeFile(watchedFile); } + }; + }, + watchDirectory: function (path, callback, recursive) { + // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows + // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643) + return _fs.watch(path, { persisten: true, recursive: !!recursive }, function (eventName, relativeFileName) { + // In watchDirectory we only care about adding and removing files (when event name is + // "rename"); changes made within files are handled by corresponding fileWatchers (when + // event name is "change") + if (eventName === "rename") { + // When deleting a file, the passed baseFileName is null + callback(!relativeFileName ? relativeFileName : ts.normalizePath(ts.combinePaths(path, relativeFileName))); + } + ; + }); }, resolvePath: function (path) { return _path.resolve(path); @@ -1925,7 +2070,7 @@ var ts; Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." }, _0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: { code: 1062, category: ts.DiagnosticCategory.Error, key: "{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method." }, An_export_assignment_cannot_be_used_in_a_namespace: { code: 1063, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a namespace." }, - Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: ts.DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." }, + In_ambient_enum_declarations_member_initializer_must_be_constant_expression: { code: 1066, category: ts.DiagnosticCategory.Error, key: "In ambient enum declarations member initializer must be constant expression." }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: ts.DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." }, @@ -2013,7 +2158,7 @@ var ts; Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." }, Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." }, A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." }, - An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, + An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1183, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." }, Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, @@ -2031,10 +2176,9 @@ var ts; An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: ts.DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, - Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, - Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, - Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." }, - Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead." }, + Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead." }, + Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'es6' when targeting 'ES5' or lower." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, @@ -2063,10 +2207,6 @@ var ts; An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, - Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning: { code: 1236, category: ts.DiagnosticCategory.Error, key: "Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning." }, - with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, - await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, - Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." }, The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." }, Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." }, @@ -2077,6 +2217,10 @@ var ts; _0_modifier_cannot_be_used_with_1_modifier: { code: 1243, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." }, Abstract_methods_can_only_appear_within_an_abstract_class: { code: 1244, category: ts.DiagnosticCategory.Error, key: "Abstract methods can only appear within an abstract class." }, Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: { code: 1245, category: ts.DiagnosticCategory.Error, key: "Method '{0}' cannot have an implementation because it is marked abstract." }, + with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." }, + await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." }, + Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, + can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment: { code: 1312, category: ts.DiagnosticCategory.Error, key: "'=' can only be used in an object literal property inside a destructuring assignment." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -2201,7 +2345,7 @@ var ts; In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element: { code: 2432, category: ts.DiagnosticCategory.Error, key: "In an enum with multiple declarations, only one declaration can omit an initializer for its first enum element." }, A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged: { code: 2433, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be in a different file from a class or function with which it is merged" }, A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: { code: 2434, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be located prior to a class or function with which it is merged" }, - Ambient_modules_cannot_be_nested_in_other_modules: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules." }, + Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules or namespaces." }, Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." }, Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: 2437, category: ts.DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" }, Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" }, @@ -2289,6 +2433,9 @@ var ts; yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: ts.DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." }, await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: ts.DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." }, Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value: { code: 2525, category: ts.DiagnosticCategory.Error, key: "Initializer provides no value for this binding element and the binding element has no default value." }, + A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface: { code: 2526, category: ts.DiagnosticCategory.Error, key: "A 'this' type is available only in a non-static member of a class or interface." }, + The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary: { code: 2527, category: ts.DiagnosticCategory.Error, key: "The inferred type of '{0}' references an inaccessible 'this' type. A type annotation is necessary." }, + A_module_cannot_have_multiple_default_exports: { code: 2528, category: ts.DiagnosticCategory.Error, key: "A module cannot have multiple default exports." }, JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: ts.DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." }, The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: ts.DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." }, JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." }, @@ -2389,7 +2536,7 @@ var ts; Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: ts.DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." }, Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." }, Option_0_cannot_be_specified_with_option_1: { code: 5053, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." }, - A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5053, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, + A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5054, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -2401,7 +2548,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, - Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" }, + Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es6'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -2422,7 +2569,7 @@ var ts; Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." }, + Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system', 'umd', or 'es6'." }, Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: ts.DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: ts.DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, @@ -2443,7 +2590,6 @@ var ts; Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." }, Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, - Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." }, Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." }, Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6)." }, Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." }, @@ -2490,7 +2636,9 @@ var ts; Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: ts.DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." }, JSX_attribute_expected: { code: 17003, category: ts.DiagnosticCategory.Error, key: "JSX attribute expected." }, Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: ts.DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." }, - A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" } + A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }, + An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17006, category: ts.DiagnosticCategory.Error, key: "An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, + A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." } }; })(ts || (ts = {})); /// @@ -2499,75 +2647,75 @@ var ts; (function (ts) { /* @internal */ function tokenIsIdentifierOrKeyword(token) { - return token >= 67 /* Identifier */; + return token >= 69 /* Identifier */; } ts.tokenIsIdentifierOrKeyword = tokenIsIdentifierOrKeyword; var textToToken = { - "abstract": 113 /* AbstractKeyword */, - "any": 115 /* AnyKeyword */, - "as": 114 /* AsKeyword */, - "boolean": 118 /* BooleanKeyword */, - "break": 68 /* BreakKeyword */, - "case": 69 /* CaseKeyword */, - "catch": 70 /* CatchKeyword */, - "class": 71 /* ClassKeyword */, - "continue": 73 /* ContinueKeyword */, - "const": 72 /* ConstKeyword */, - "constructor": 119 /* ConstructorKeyword */, - "debugger": 74 /* DebuggerKeyword */, - "declare": 120 /* DeclareKeyword */, - "default": 75 /* DefaultKeyword */, - "delete": 76 /* DeleteKeyword */, - "do": 77 /* DoKeyword */, - "else": 78 /* ElseKeyword */, - "enum": 79 /* EnumKeyword */, - "export": 80 /* ExportKeyword */, - "extends": 81 /* ExtendsKeyword */, - "false": 82 /* FalseKeyword */, - "finally": 83 /* FinallyKeyword */, - "for": 84 /* ForKeyword */, - "from": 131 /* FromKeyword */, - "function": 85 /* FunctionKeyword */, - "get": 121 /* GetKeyword */, - "if": 86 /* IfKeyword */, - "implements": 104 /* ImplementsKeyword */, - "import": 87 /* ImportKeyword */, - "in": 88 /* InKeyword */, - "instanceof": 89 /* InstanceOfKeyword */, - "interface": 105 /* InterfaceKeyword */, - "is": 122 /* IsKeyword */, - "let": 106 /* LetKeyword */, - "module": 123 /* ModuleKeyword */, - "namespace": 124 /* NamespaceKeyword */, - "new": 90 /* NewKeyword */, - "null": 91 /* NullKeyword */, - "number": 126 /* NumberKeyword */, - "package": 107 /* PackageKeyword */, - "private": 108 /* PrivateKeyword */, - "protected": 109 /* ProtectedKeyword */, - "public": 110 /* PublicKeyword */, - "require": 125 /* RequireKeyword */, - "return": 92 /* ReturnKeyword */, - "set": 127 /* SetKeyword */, - "static": 111 /* StaticKeyword */, - "string": 128 /* StringKeyword */, - "super": 93 /* SuperKeyword */, - "switch": 94 /* SwitchKeyword */, - "symbol": 129 /* SymbolKeyword */, - "this": 95 /* ThisKeyword */, - "throw": 96 /* ThrowKeyword */, - "true": 97 /* TrueKeyword */, - "try": 98 /* TryKeyword */, - "type": 130 /* TypeKeyword */, - "typeof": 99 /* TypeOfKeyword */, - "var": 100 /* VarKeyword */, - "void": 101 /* VoidKeyword */, - "while": 102 /* WhileKeyword */, - "with": 103 /* WithKeyword */, - "yield": 112 /* YieldKeyword */, - "async": 116 /* AsyncKeyword */, - "await": 117 /* AwaitKeyword */, - "of": 132 /* OfKeyword */, + "abstract": 115 /* AbstractKeyword */, + "any": 117 /* AnyKeyword */, + "as": 116 /* AsKeyword */, + "boolean": 120 /* BooleanKeyword */, + "break": 70 /* BreakKeyword */, + "case": 71 /* CaseKeyword */, + "catch": 72 /* CatchKeyword */, + "class": 73 /* ClassKeyword */, + "continue": 75 /* ContinueKeyword */, + "const": 74 /* ConstKeyword */, + "constructor": 121 /* ConstructorKeyword */, + "debugger": 76 /* DebuggerKeyword */, + "declare": 122 /* DeclareKeyword */, + "default": 77 /* DefaultKeyword */, + "delete": 78 /* DeleteKeyword */, + "do": 79 /* DoKeyword */, + "else": 80 /* ElseKeyword */, + "enum": 81 /* EnumKeyword */, + "export": 82 /* ExportKeyword */, + "extends": 83 /* ExtendsKeyword */, + "false": 84 /* FalseKeyword */, + "finally": 85 /* FinallyKeyword */, + "for": 86 /* ForKeyword */, + "from": 133 /* FromKeyword */, + "function": 87 /* FunctionKeyword */, + "get": 123 /* GetKeyword */, + "if": 88 /* IfKeyword */, + "implements": 106 /* ImplementsKeyword */, + "import": 89 /* ImportKeyword */, + "in": 90 /* InKeyword */, + "instanceof": 91 /* InstanceOfKeyword */, + "interface": 107 /* InterfaceKeyword */, + "is": 124 /* IsKeyword */, + "let": 108 /* LetKeyword */, + "module": 125 /* ModuleKeyword */, + "namespace": 126 /* NamespaceKeyword */, + "new": 92 /* NewKeyword */, + "null": 93 /* NullKeyword */, + "number": 128 /* NumberKeyword */, + "package": 109 /* PackageKeyword */, + "private": 110 /* PrivateKeyword */, + "protected": 111 /* ProtectedKeyword */, + "public": 112 /* PublicKeyword */, + "require": 127 /* RequireKeyword */, + "return": 94 /* ReturnKeyword */, + "set": 129 /* SetKeyword */, + "static": 113 /* StaticKeyword */, + "string": 130 /* StringKeyword */, + "super": 95 /* SuperKeyword */, + "switch": 96 /* SwitchKeyword */, + "symbol": 131 /* SymbolKeyword */, + "this": 97 /* ThisKeyword */, + "throw": 98 /* ThrowKeyword */, + "true": 99 /* TrueKeyword */, + "try": 100 /* TryKeyword */, + "type": 132 /* TypeKeyword */, + "typeof": 101 /* TypeOfKeyword */, + "var": 102 /* VarKeyword */, + "void": 103 /* VoidKeyword */, + "while": 104 /* WhileKeyword */, + "with": 105 /* WithKeyword */, + "yield": 114 /* YieldKeyword */, + "async": 118 /* AsyncKeyword */, + "await": 119 /* AwaitKeyword */, + "of": 134 /* OfKeyword */, "{": 15 /* OpenBraceToken */, "}": 16 /* CloseBraceToken */, "(": 17 /* OpenParenToken */, @@ -2589,37 +2737,39 @@ var ts; "=>": 34 /* EqualsGreaterThanToken */, "+": 35 /* PlusToken */, "-": 36 /* MinusToken */, + "**": 38 /* AsteriskAsteriskToken */, "*": 37 /* AsteriskToken */, - "/": 38 /* SlashToken */, - "%": 39 /* PercentToken */, - "++": 40 /* PlusPlusToken */, - "--": 41 /* MinusMinusToken */, - "<<": 42 /* LessThanLessThanToken */, + "/": 39 /* SlashToken */, + "%": 40 /* PercentToken */, + "++": 41 /* PlusPlusToken */, + "--": 42 /* MinusMinusToken */, + "<<": 43 /* LessThanLessThanToken */, ">": 43 /* GreaterThanGreaterThanToken */, - ">>>": 44 /* GreaterThanGreaterThanGreaterThanToken */, - "&": 45 /* AmpersandToken */, - "|": 46 /* BarToken */, - "^": 47 /* CaretToken */, - "!": 48 /* ExclamationToken */, - "~": 49 /* TildeToken */, - "&&": 50 /* AmpersandAmpersandToken */, - "||": 51 /* BarBarToken */, - "?": 52 /* QuestionToken */, - ":": 53 /* ColonToken */, - "=": 55 /* EqualsToken */, - "+=": 56 /* PlusEqualsToken */, - "-=": 57 /* MinusEqualsToken */, - "*=": 58 /* AsteriskEqualsToken */, - "/=": 59 /* SlashEqualsToken */, - "%=": 60 /* PercentEqualsToken */, - "<<=": 61 /* LessThanLessThanEqualsToken */, - ">>=": 62 /* GreaterThanGreaterThanEqualsToken */, - ">>>=": 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */, - "&=": 64 /* AmpersandEqualsToken */, - "|=": 65 /* BarEqualsToken */, - "^=": 66 /* CaretEqualsToken */, - "@": 54 /* AtToken */ + ">>": 44 /* GreaterThanGreaterThanToken */, + ">>>": 45 /* GreaterThanGreaterThanGreaterThanToken */, + "&": 46 /* AmpersandToken */, + "|": 47 /* BarToken */, + "^": 48 /* CaretToken */, + "!": 49 /* ExclamationToken */, + "~": 50 /* TildeToken */, + "&&": 51 /* AmpersandAmpersandToken */, + "||": 52 /* BarBarToken */, + "?": 53 /* QuestionToken */, + ":": 54 /* ColonToken */, + "=": 56 /* EqualsToken */, + "+=": 57 /* PlusEqualsToken */, + "-=": 58 /* MinusEqualsToken */, + "*=": 59 /* AsteriskEqualsToken */, + "**=": 60 /* AsteriskAsteriskEqualsToken */, + "/=": 61 /* SlashEqualsToken */, + "%=": 62 /* PercentEqualsToken */, + "<<=": 63 /* LessThanLessThanEqualsToken */, + ">>=": 64 /* GreaterThanGreaterThanEqualsToken */, + ">>>=": 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */, + "&=": 66 /* AmpersandEqualsToken */, + "|=": 67 /* BarEqualsToken */, + "^=": 68 /* CaretEqualsToken */, + "@": 55 /* AtToken */ }; /* As per ECMAScript Language Specification 3th Edition, Section 7.6: Identifiers @@ -3123,8 +3273,8 @@ var ts; getTokenValue: function () { return tokenValue; }, hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, - isIdentifier: function () { return token === 67 /* Identifier */ || token > 103 /* LastReservedWord */; }, - isReservedWord: function () { return token >= 68 /* FirstReservedWord */ && token <= 103 /* LastReservedWord */; }, + isIdentifier: function () { return token === 69 /* Identifier */ || token > 105 /* LastReservedWord */; }, + isReservedWord: function () { return token >= 70 /* FirstReservedWord */ && token <= 105 /* LastReservedWord */; }, isUnterminated: function () { return tokenIsUnterminated; }, reScanGreaterToken: reScanGreaterToken, reScanSlashToken: reScanSlashToken, @@ -3146,16 +3296,6 @@ var ts; onError(message, length || 0); } } - function isIdentifierStart(ch) { - return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || - ch === 36 /* $ */ || ch === 95 /* _ */ || - ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); - } - function isIdentifierPart(ch) { - return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || - ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || - ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion); - } function scanNumber() { var start = pos; while (isDigit(text.charCodeAt(pos))) @@ -3438,12 +3578,12 @@ var ts; var start = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (isIdentifierPart(ch)) { + if (isIdentifierPart(ch, languageVersion)) { pos++; } else if (ch === 92 /* backslash */) { ch = peekUnicodeEscape(); - if (!(ch >= 0 && isIdentifierPart(ch))) { + if (!(ch >= 0 && isIdentifierPart(ch, languageVersion))) { break; } result += text.substring(start, pos); @@ -3468,7 +3608,7 @@ var ts; return token = textToToken[tokenValue]; } } - return token = 67 /* Identifier */; + return token = 69 /* Identifier */; } function scanBinaryOrOctalDigits(base) { ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8"); @@ -3552,7 +3692,7 @@ var ts; } return pos += 2, token = 31 /* ExclamationEqualsToken */; } - return pos++, token = 48 /* ExclamationToken */; + return pos++, token = 49 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); @@ -3561,42 +3701,48 @@ var ts; return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 60 /* PercentEqualsToken */; + return pos += 2, token = 62 /* PercentEqualsToken */; } - return pos++, token = 39 /* PercentToken */; + return pos++, token = 40 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { - return pos += 2, token = 50 /* AmpersandAmpersandToken */; + return pos += 2, token = 51 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 64 /* AmpersandEqualsToken */; + return pos += 2, token = 66 /* AmpersandEqualsToken */; } - return pos++, token = 45 /* AmpersandToken */; + return pos++, token = 46 /* AmpersandToken */; case 40 /* openParen */: return pos++, token = 17 /* OpenParenToken */; case 41 /* closeParen */: return pos++, token = 18 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 58 /* AsteriskEqualsToken */; + return pos += 2, token = 59 /* AsteriskEqualsToken */; + } + if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { + if (text.charCodeAt(pos + 2) === 61 /* equals */) { + return pos += 3, token = 60 /* AsteriskAsteriskEqualsToken */; + } + return pos += 2, token = 38 /* AsteriskAsteriskToken */; } return pos++, token = 37 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { - return pos += 2, token = 40 /* PlusPlusToken */; + return pos += 2, token = 41 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 56 /* PlusEqualsToken */; + return pos += 2, token = 57 /* PlusEqualsToken */; } return pos++, token = 35 /* PlusToken */; case 44 /* comma */: return pos++, token = 24 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { - return pos += 2, token = 41 /* MinusMinusToken */; + return pos += 2, token = 42 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 57 /* MinusEqualsToken */; + return pos += 2, token = 58 /* MinusEqualsToken */; } return pos++, token = 36 /* MinusToken */; case 46 /* dot */: @@ -3653,9 +3799,9 @@ var ts; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 59 /* SlashEqualsToken */; + return pos += 2, token = 61 /* SlashEqualsToken */; } - return pos++, token = 38 /* SlashToken */; + return pos++, token = 39 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; @@ -3707,7 +3853,7 @@ var ts; tokenValue = "" + scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: - return pos++, token = 53 /* ColonToken */; + return pos++, token = 54 /* ColonToken */; case 59 /* semicolon */: return pos++, token = 23 /* SemicolonToken */; case 60 /* lessThan */: @@ -3722,14 +3868,16 @@ var ts; } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { - return pos += 3, token = 61 /* LessThanLessThanEqualsToken */; + return pos += 3, token = 63 /* LessThanLessThanEqualsToken */; } - return pos += 2, token = 42 /* LessThanLessThanToken */; + return pos += 2, token = 43 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 28 /* LessThanEqualsToken */; } - if (text.charCodeAt(pos + 1) === 47 /* slash */ && languageVariant === 1 /* JSX */) { + if (languageVariant === 1 /* JSX */ && + text.charCodeAt(pos + 1) === 47 /* slash */ && + text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 26 /* LessThanSlashToken */; } return pos++, token = 25 /* LessThanToken */; @@ -3752,7 +3900,7 @@ var ts; if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 34 /* EqualsGreaterThanToken */; } - return pos++, token = 55 /* EqualsToken */; + return pos++, token = 56 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -3765,35 +3913,35 @@ var ts; } return pos++, token = 27 /* GreaterThanToken */; case 63 /* question */: - return pos++, token = 52 /* QuestionToken */; + return pos++, token = 53 /* QuestionToken */; case 91 /* openBracket */: return pos++, token = 19 /* OpenBracketToken */; case 93 /* closeBracket */: return pos++, token = 20 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 66 /* CaretEqualsToken */; + return pos += 2, token = 68 /* CaretEqualsToken */; } - return pos++, token = 47 /* CaretToken */; + return pos++, token = 48 /* CaretToken */; case 123 /* openBrace */: return pos++, token = 15 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { - return pos += 2, token = 51 /* BarBarToken */; + return pos += 2, token = 52 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 65 /* BarEqualsToken */; + return pos += 2, token = 67 /* BarEqualsToken */; } - return pos++, token = 46 /* BarToken */; + return pos++, token = 47 /* BarToken */; case 125 /* closeBrace */: return pos++, token = 16 /* CloseBraceToken */; case 126 /* tilde */: - return pos++, token = 49 /* TildeToken */; + return pos++, token = 50 /* TildeToken */; case 64 /* at */: - return pos++, token = 54 /* AtToken */; + return pos++, token = 55 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); - if (cookedChar >= 0 && isIdentifierStart(cookedChar)) { + if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); @@ -3801,9 +3949,9 @@ var ts; error(ts.Diagnostics.Invalid_character); return pos++, token = 0 /* Unknown */; default: - if (isIdentifierStart(ch)) { + if (isIdentifierStart(ch, languageVersion)) { pos++; - while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos))) + while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { @@ -3830,14 +3978,14 @@ var ts; if (text.charCodeAt(pos) === 62 /* greaterThan */) { if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { - return pos += 3, token = 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */; + return pos += 3, token = 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */; } - return pos += 2, token = 44 /* GreaterThanGreaterThanGreaterThanToken */; + return pos += 2, token = 45 /* GreaterThanGreaterThanGreaterThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { - return pos += 2, token = 62 /* GreaterThanGreaterThanEqualsToken */; + return pos += 2, token = 64 /* GreaterThanGreaterThanEqualsToken */; } - return pos++, token = 43 /* GreaterThanGreaterThanToken */; + return pos++, token = 44 /* GreaterThanGreaterThanToken */; } if (text.charCodeAt(pos) === 61 /* equals */) { return pos++, token = 29 /* GreaterThanEqualsToken */; @@ -3846,7 +3994,7 @@ var ts; return token; } function reScanSlashToken() { - if (token === 38 /* SlashToken */ || token === 59 /* SlashEqualsToken */) { + if (token === 39 /* SlashToken */ || token === 61 /* SlashEqualsToken */) { var p = tokenPos + 1; var inEscape = false; var inCharacterClass = false; @@ -3886,7 +4034,7 @@ var ts; } p++; } - while (p < end && isIdentifierPart(text.charCodeAt(p))) { + while (p < end && isIdentifierPart(text.charCodeAt(p), languageVersion)) { p++; } pos = p; @@ -3932,7 +4080,7 @@ var ts; break; } } - return token = 234 /* JsxText */; + return token = 236 /* JsxText */; } // Scans a JSX identifier; these differ from normal identifiers in that // they allow dashes @@ -3941,7 +4089,7 @@ var ts; var firstCharPosition = pos; while (pos < end) { var ch = text.charCodeAt(pos); - if (ch === 45 /* minus */ || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) { + if (ch === 45 /* minus */ || ((firstCharPosition === pos) ? isIdentifierStart(ch, languageVersion) : isIdentifierPart(ch, languageVersion))) { pos++; } else { @@ -4020,16 +4168,16 @@ var ts; function getModuleInstanceState(node) { // A module is uninstantiated if it contains only // 1. interface declarations, type alias declarations - if (node.kind === 213 /* InterfaceDeclaration */ || node.kind === 214 /* TypeAliasDeclaration */) { + if (node.kind === 215 /* InterfaceDeclaration */ || node.kind === 216 /* TypeAliasDeclaration */) { return 0 /* NonInstantiated */; } else if (ts.isConstEnumDeclaration(node)) { return 2 /* ConstEnumOnly */; } - else if ((node.kind === 220 /* ImportDeclaration */ || node.kind === 219 /* ImportEqualsDeclaration */) && !(node.flags & 1 /* Export */)) { + else if ((node.kind === 222 /* ImportDeclaration */ || node.kind === 221 /* ImportEqualsDeclaration */) && !(node.flags & 1 /* Export */)) { return 0 /* NonInstantiated */; } - else if (node.kind === 217 /* ModuleBlock */) { + else if (node.kind === 219 /* ModuleBlock */) { var state = 0 /* NonInstantiated */; ts.forEachChild(node, function (n) { switch (getModuleInstanceState(n)) { @@ -4048,7 +4196,7 @@ var ts; }); return state; } - else if (node.kind === 216 /* ModuleDeclaration */) { + else if (node.kind === 218 /* ModuleDeclaration */) { return getModuleInstanceState(node.body); } else { @@ -4088,6 +4236,7 @@ var ts; var container; var blockScopeContainer; var lastContainer; + var seenThisKeyword; // If this file is an external module, then it is automatically in strict-mode according to // ES6. If it is not an external module, then we'll determine if it is in strict mode or // not depending on if we see "use strict" in certain places (or if we hit a class/namespace). @@ -4126,10 +4275,10 @@ var ts; // unless it is a well known Symbol. function getDeclarationName(node) { if (node.name) { - if (node.kind === 216 /* ModuleDeclaration */ && node.name.kind === 9 /* StringLiteral */) { + if (node.kind === 218 /* ModuleDeclaration */ && node.name.kind === 9 /* StringLiteral */) { return "\"" + node.name.text + "\""; } - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { var nameExpression = node.name.expression; ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression)); return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text); @@ -4137,22 +4286,22 @@ var ts; return node.name.text; } switch (node.kind) { - case 142 /* Constructor */: + case 144 /* Constructor */: return "__constructor"; - case 150 /* FunctionType */: - case 145 /* CallSignature */: + case 152 /* FunctionType */: + case 147 /* CallSignature */: return "__call"; - case 151 /* ConstructorType */: - case 146 /* ConstructSignature */: + case 153 /* ConstructorType */: + case 148 /* ConstructSignature */: return "__new"; - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: return "__index"; - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return "__export"; - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return node.isExportEquals ? "export=" : "default"; - case 211 /* FunctionDeclaration */: - case 212 /* ClassDeclaration */: + case 213 /* FunctionDeclaration */: + case 214 /* ClassDeclaration */: return node.flags & 1024 /* Default */ ? "default" : undefined; } } @@ -4169,8 +4318,9 @@ var ts; */ function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); + var isDefaultExport = node.flags & 1024 /* Default */; // The exported symbol for an export default function/class node is always named "default" - var name = node.flags & 1024 /* Default */ && parent ? "default" : getDeclarationName(node); + var name = isDefaultExport && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { // Check and see if the symbol table already has a symbol with this name. If not, @@ -4206,6 +4356,11 @@ var ts; var message = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + ts.forEach(symbol.declarations, function (declaration) { + if (declaration.flags & 1024 /* Default */) { + message = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + } + }); ts.forEach(symbol.declarations, function (declaration) { file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); @@ -4223,7 +4378,7 @@ var ts; function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1 /* Export */; if (symbolFlags & 8388608 /* Alias */) { - if (node.kind === 228 /* ExportSpecifier */ || (node.kind === 219 /* ImportEqualsDeclaration */ && hasExportModifier)) { + if (node.kind === 230 /* ExportSpecifier */ || (node.kind === 221 /* ImportEqualsDeclaration */ && hasExportModifier)) { return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { @@ -4297,44 +4452,51 @@ var ts; blockScopeContainer = node; blockScopeContainer.locals = undefined; } - ts.forEachChild(node, bind); + if (node.kind === 215 /* InterfaceDeclaration */) { + seenThisKeyword = false; + ts.forEachChild(node, bind); + node.flags = seenThisKeyword ? node.flags | 524288 /* ContainsThis */ : node.flags & ~524288 /* ContainsThis */; + } + else { + ts.forEachChild(node, bind); + } container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } function getContainerFlags(node) { switch (node.kind) { - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 153 /* TypeLiteral */: - case 163 /* ObjectLiteralExpression */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 155 /* TypeLiteral */: + case 165 /* ObjectLiteralExpression */: return 1 /* IsContainer */; - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 211 /* FunctionDeclaration */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 216 /* ModuleDeclaration */: - case 246 /* SourceFile */: - case 214 /* TypeAliasDeclaration */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 218 /* ModuleDeclaration */: + case 248 /* SourceFile */: + case 216 /* TypeAliasDeclaration */: return 5 /* IsContainerWithLocals */; - case 242 /* CatchClause */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 218 /* CaseBlock */: + case 244 /* CatchClause */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 220 /* CaseBlock */: return 2 /* IsBlockScopedContainer */; - case 190 /* Block */: + case 192 /* Block */: // do not treat blocks directly inside a function as a block-scoped-container. // Locals that reside in this block should go to the function locals. Othewise 'x' // would not appear to be a redeclaration of a block scoped local in the following @@ -4371,38 +4533,38 @@ var ts; // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); - case 153 /* TypeLiteral */: - case 163 /* ObjectLiteralExpression */: - case 213 /* InterfaceDeclaration */: + case 155 /* TypeLiteral */: + case 165 /* ObjectLiteralExpression */: + case 215 /* InterfaceDeclaration */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 214 /* TypeAliasDeclaration */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 216 /* TypeAliasDeclaration */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath @@ -4432,11 +4594,11 @@ var ts; return false; } function hasExportDeclarations(node) { - var body = node.kind === 246 /* SourceFile */ ? node : node.body; - if (body.kind === 246 /* SourceFile */ || body.kind === 217 /* ModuleBlock */) { + var body = node.kind === 248 /* SourceFile */ ? node : node.body; + if (body.kind === 248 /* SourceFile */ || body.kind === 219 /* ModuleBlock */) { for (var _i = 0, _a = body.statements; _i < _a.length; _i++) { var stat = _a[_i]; - if (stat.kind === 226 /* ExportDeclaration */ || stat.kind === 225 /* ExportAssignment */) { + if (stat.kind === 228 /* ExportDeclaration */ || stat.kind === 227 /* ExportAssignment */) { return true; } } @@ -4508,7 +4670,7 @@ var ts; var seen = {}; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - if (prop.name.kind !== 67 /* Identifier */) { + if (prop.name.kind !== 69 /* Identifier */) { continue; } var identifier = prop.name; @@ -4520,7 +4682,7 @@ var ts; // c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true. // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields - var currentKind = prop.kind === 243 /* PropertyAssignment */ || prop.kind === 244 /* ShorthandPropertyAssignment */ || prop.kind === 141 /* MethodDeclaration */ + var currentKind = prop.kind === 245 /* PropertyAssignment */ || prop.kind === 246 /* ShorthandPropertyAssignment */ || prop.kind === 143 /* MethodDeclaration */ ? 1 /* Property */ : 2 /* Accessor */; var existingKind = seen[identifier.text]; @@ -4542,10 +4704,10 @@ var ts; } function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: declareModuleMember(node, symbolFlags, symbolExcludes); break; - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolFlags, symbolExcludes); break; @@ -4566,8 +4728,8 @@ var ts; // check for reserved words used as identifiers in strict mode code. function checkStrictModeIdentifier(node) { if (inStrictMode && - node.originalKeywordKind >= 104 /* FirstFutureReservedWord */ && - node.originalKeywordKind <= 112 /* LastFutureReservedWord */ && + node.originalKeywordKind >= 106 /* FirstFutureReservedWord */ && + node.originalKeywordKind <= 114 /* LastFutureReservedWord */ && !ts.isIdentifierName(node)) { // Report error only if there are no parse errors in file if (!file.parseDiagnostics.length) { @@ -4602,7 +4764,7 @@ var ts; } function checkStrictModeDeleteExpression(node) { // Grammar checking - if (inStrictMode && node.expression.kind === 67 /* Identifier */) { + if (inStrictMode && node.expression.kind === 69 /* Identifier */) { // When a delete operator occurs within strict mode code, a SyntaxError is thrown if its // UnaryExpression is a direct reference to a variable, function argument, or function name var span = ts.getErrorSpanForNode(file, node.expression); @@ -4610,11 +4772,11 @@ var ts; } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 /* Identifier */ && + return node.kind === 69 /* Identifier */ && (node.text === "eval" || node.text === "arguments"); } function checkStrictModeEvalOrArguments(contextNode, name) { - if (name && name.kind === 67 /* Identifier */) { + if (name && name.kind === 69 /* Identifier */) { var identifier = name; if (isEvalOrArgumentsIdentifier(identifier)) { // We check first if the name is inside class declaration or class expression; if so give explicit message @@ -4658,7 +4820,7 @@ var ts; function checkStrictModePrefixUnaryExpression(node) { // Grammar checking if (inStrictMode) { - if (node.operator === 40 /* PlusPlusToken */ || node.operator === 41 /* MinusMinusToken */) { + if (node.operator === 41 /* PlusPlusToken */ || node.operator === 42 /* MinusMinusToken */) { checkStrictModeEvalOrArguments(node, node.operand); } } @@ -4702,17 +4864,17 @@ var ts; } function updateStrictMode(node) { switch (node.kind) { - case 246 /* SourceFile */: - case 217 /* ModuleBlock */: + case 248 /* SourceFile */: + case 219 /* ModuleBlock */: updateStrictModeStatementList(node.statements); return; - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionLike(node.parent)) { updateStrictModeStatementList(node.statements); } return; - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return; @@ -4739,92 +4901,95 @@ var ts; } function bindWorker(node) { switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: return checkStrictModeIdentifier(node); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return checkStrictModeBinaryExpression(node); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return checkStrictModeCatchClause(node); - case 173 /* DeleteExpression */: + case 175 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); - case 178 /* PostfixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); - case 203 /* WithStatement */: + case 205 /* WithStatement */: return checkStrictModeWithStatement(node); - case 135 /* TypeParameter */: + case 97 /* ThisKeyword */: + seenThisKeyword = true; + return; + case 137 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */); - case 136 /* Parameter */: + case 138 /* Parameter */: return bindParameter(node); - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); - case 243 /* PropertyAssignment */: - case 244 /* ShorthandPropertyAssignment */: + case 245 /* PropertyAssignment */: + case 246 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: checkStrictModeFunctionName(node); return declareSymbolAndAddToSymbolTable(node, 16 /* Function */, 106927 /* FunctionExcludes */); - case 142 /* Constructor */: + case 144 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); - case 144 /* SetAccessor */: + case 146 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return bindFunctionOrConstructorType(node); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: checkStrictModeFunctionName(node); var bindingName = node.name ? node.name.text : "__function"; return bindAnonymousDeclaration(node, 16 /* Function */, bindingName); - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: return bindClassLikeDeclaration(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792960 /* InterfaceExcludes */); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return bindEnumDeclaration(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return bindModuleDeclaration(node); - case 219 /* ImportEqualsDeclaration */: - case 222 /* NamespaceImport */: - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 224 /* NamespaceImport */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); - case 221 /* ImportClause */: + case 223 /* ImportClause */: return bindImportClause(node); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return bindExportDeclaration(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return bindExportAssignment(node); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return bindSourceFileIfExternalModule(); } } @@ -4839,7 +5004,7 @@ var ts; // Export assignment in some sort of block construct bindAnonymousDeclaration(node, 8388608 /* Alias */, getDeclarationName(node)); } - else if (node.expression.kind === 67 /* Identifier */) { + else if (node.expression.kind === 69 /* Identifier */) { // An export default clause with an identifier exports all meanings of that identifier declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } @@ -4864,7 +5029,7 @@ var ts; } } function bindClassLikeDeclaration(node) { - if (node.kind === 212 /* ClassDeclaration */) { + if (node.kind === 214 /* ClassDeclaration */) { bindBlockScopedDeclaration(node, 32 /* Class */, 899519 /* ClassExcludes */); } else { @@ -4940,7 +5105,7 @@ var ts; // If this is a property-parameter, then also declare the property symbol into the // containing class. if (node.flags & 112 /* AccessibilityModifier */ && - node.parent.kind === 142 /* Constructor */ && + node.parent.kind === 144 /* Constructor */ && ts.isClassLike(node.parent.parent)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); @@ -4992,7 +5157,8 @@ var ts; increaseIndent: function () { }, decreaseIndent: function () { }, clear: function () { return str = ""; }, - trackSymbol: function () { } + trackSymbol: function () { }, + reportInaccessibleThisError: function () { } }; } return stringWriters.pop(); @@ -5062,7 +5228,7 @@ var ts; } } function getSourceFileOfNode(node) { - while (node && node.kind !== 246 /* SourceFile */) { + while (node && node.kind !== 248 /* SourceFile */) { node = node.parent; } return node; @@ -5174,15 +5340,15 @@ var ts; return current; } switch (current.kind) { - case 246 /* SourceFile */: - case 218 /* CaseBlock */: - case 242 /* CatchClause */: - case 216 /* ModuleDeclaration */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 248 /* SourceFile */: + case 220 /* CaseBlock */: + case 244 /* CatchClause */: + case 218 /* ModuleDeclaration */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return current; - case 190 /* Block */: + case 192 /* Block */: // function block is not considered block-scope container // see comment in binder.ts: bind(...), case for SyntaxKind.Block if (!isFunctionLike(current.parent)) { @@ -5195,9 +5361,9 @@ var ts; ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer; function isCatchClauseVariableDeclaration(declaration) { return declaration && - declaration.kind === 209 /* VariableDeclaration */ && + declaration.kind === 211 /* VariableDeclaration */ && declaration.parent && - declaration.parent.kind === 242 /* CatchClause */; + declaration.parent.kind === 244 /* CatchClause */; } ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; // Return display name of an identifier @@ -5236,7 +5402,7 @@ var ts; function getErrorSpanForNode(sourceFile, node) { var errorNode = node; switch (node.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: var pos_1 = ts.skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false); if (pos_1 === sourceFile.text.length) { // file is empty - return span for the beginning of the file @@ -5245,16 +5411,16 @@ var ts; return getSpanOfTokenAtPosition(sourceFile, pos_1); // This list is a work in progress. Add missing node kinds to improve their error // spans. - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 216 /* ModuleDeclaration */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 218 /* ModuleDeclaration */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: errorNode = node.name; break; } @@ -5278,11 +5444,11 @@ var ts; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { - return node.kind === 215 /* EnumDeclaration */ && isConst(node); + return node.kind === 217 /* EnumDeclaration */ && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; function walkUpBindingElementsAndPatterns(node) { - while (node && (node.kind === 161 /* BindingElement */ || isBindingPattern(node))) { + while (node && (node.kind === 163 /* BindingElement */ || isBindingPattern(node))) { node = node.parent; } return node; @@ -5297,14 +5463,14 @@ var ts; function getCombinedNodeFlags(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; - if (node.kind === 209 /* VariableDeclaration */) { + if (node.kind === 211 /* VariableDeclaration */) { node = node.parent; } - if (node && node.kind === 210 /* VariableDeclarationList */) { + if (node && node.kind === 212 /* VariableDeclarationList */) { flags |= node.flags; node = node.parent; } - if (node && node.kind === 191 /* VariableStatement */) { + if (node && node.kind === 193 /* VariableStatement */) { flags |= node.flags; } return flags; @@ -5319,7 +5485,7 @@ var ts; } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 193 /* ExpressionStatement */ && node.expression.kind === 9 /* StringLiteral */; + return node.kind === 195 /* ExpressionStatement */ && node.expression.kind === 9 /* StringLiteral */; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { @@ -5327,7 +5493,7 @@ var ts; } ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode; function getJsDocComments(node, sourceFileOfNode) { - var commentRanges = (node.kind === 136 /* Parameter */ || node.kind === 135 /* TypeParameter */) ? + var commentRanges = (node.kind === 138 /* Parameter */ || node.kind === 137 /* TypeParameter */) ? ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) : getLeadingCommentRangesOfNode(node, sourceFileOfNode); return ts.filter(commentRanges, isJsDocComment); @@ -5342,40 +5508,40 @@ var ts; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; ts.fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*/; function isTypeNode(node) { - if (149 /* FirstTypeNode */ <= node.kind && node.kind <= 158 /* LastTypeNode */) { + if (151 /* FirstTypeNode */ <= node.kind && node.kind <= 160 /* LastTypeNode */) { return true; } switch (node.kind) { - case 115 /* AnyKeyword */: - case 126 /* NumberKeyword */: - case 128 /* StringKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: + case 117 /* AnyKeyword */: + case 128 /* NumberKeyword */: + case 130 /* StringKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: return true; - case 101 /* VoidKeyword */: - return node.parent.kind !== 175 /* VoidExpression */; + case 103 /* VoidKeyword */: + return node.parent.kind !== 177 /* VoidExpression */; case 9 /* StringLiteral */: // Specialized signatures can have string literals as their parameters' type names - return node.parent.kind === 136 /* Parameter */; - case 186 /* ExpressionWithTypeArguments */: + return node.parent.kind === 138 /* Parameter */; + case 188 /* ExpressionWithTypeArguments */: return !isExpressionWithTypeArgumentsInClassExtendsClause(node); // Identifiers and qualified names may be type nodes, depending on their context. Climb // above them to find the lowest container - case 67 /* Identifier */: + case 69 /* Identifier */: // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. - if (node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node) { + if (node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node) { node = node.parent; } - else if (node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node) { + else if (node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.name === node) { node = node.parent; } - // fall through - case 133 /* QualifiedName */: - case 164 /* PropertyAccessExpression */: // At this point, node is either a qualified name or an identifier - ts.Debug.assert(node.kind === 67 /* Identifier */ || node.kind === 133 /* QualifiedName */ || node.kind === 164 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + ts.Debug.assert(node.kind === 69 /* Identifier */ || node.kind === 135 /* QualifiedName */ || node.kind === 166 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + case 135 /* QualifiedName */: + case 166 /* PropertyAccessExpression */: + case 97 /* ThisKeyword */: var parent_1 = node.parent; - if (parent_1.kind === 152 /* TypeQuery */) { + if (parent_1.kind === 154 /* TypeQuery */) { return false; } // Do not recursively call isTypeNode on the parent. In the example: @@ -5384,38 +5550,38 @@ var ts; // // Calling isTypeNode would consider the qualified name A.B a type node. Only C or // A.B.C is a type node. - if (149 /* FirstTypeNode */ <= parent_1.kind && parent_1.kind <= 158 /* LastTypeNode */) { + if (151 /* FirstTypeNode */ <= parent_1.kind && parent_1.kind <= 160 /* LastTypeNode */) { return true; } switch (parent_1.kind) { - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return !isExpressionWithTypeArgumentsInClassExtendsClause(parent_1); - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: return node === parent_1.constraint; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 136 /* Parameter */: - case 209 /* VariableDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 138 /* Parameter */: + case 211 /* VariableDeclaration */: return node === parent_1.type; - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 142 /* Constructor */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 144 /* Constructor */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return node === parent_1.type; - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return node === parent_1.type; - case 169 /* TypeAssertionExpression */: + case 171 /* TypeAssertionExpression */: return node === parent_1.type; - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. return false; } @@ -5429,23 +5595,23 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: return visitor(node); - case 218 /* CaseBlock */: - case 190 /* Block */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 203 /* WithStatement */: - case 204 /* SwitchStatement */: - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - case 205 /* LabeledStatement */: - case 207 /* TryStatement */: - case 242 /* CatchClause */: + case 220 /* CaseBlock */: + case 192 /* Block */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 205 /* WithStatement */: + case 206 /* SwitchStatement */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + case 207 /* LabeledStatement */: + case 209 /* TryStatement */: + case 244 /* CatchClause */: return ts.forEachChild(node, traverse); } } @@ -5455,18 +5621,18 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: visitor(node); var operand = node.expression; if (operand) { traverse(operand); } - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: - case 216 /* ModuleDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: + case 218 /* ModuleDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // These are not allowed inside a generator now, but eventually they may be allowed // as local types. Regardless, any yield statements contained within them should be // skipped in this traversal. @@ -5474,7 +5640,7 @@ var ts; default: if (isFunctionLike(node)) { var name_5 = node.name; - if (name_5 && name_5.kind === 134 /* ComputedPropertyName */) { + if (name_5 && name_5.kind === 136 /* ComputedPropertyName */) { // Note that we will not include methods/accessors of a class because they would require // first descending into the class. This is by design. traverse(name_5.expression); @@ -5493,14 +5659,14 @@ var ts; function isVariableLike(node) { if (node) { switch (node.kind) { - case 161 /* BindingElement */: - case 245 /* EnumMember */: - case 136 /* Parameter */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 244 /* ShorthandPropertyAssignment */: - case 209 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 247 /* EnumMember */: + case 138 /* Parameter */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 246 /* ShorthandPropertyAssignment */: + case 211 /* VariableDeclaration */: return true; } } @@ -5508,29 +5674,29 @@ var ts; } ts.isVariableLike = isVariableLike; function isAccessor(node) { - return node && (node.kind === 143 /* GetAccessor */ || node.kind === 144 /* SetAccessor */); + return node && (node.kind === 145 /* GetAccessor */ || node.kind === 146 /* SetAccessor */); } ts.isAccessor = isAccessor; function isClassLike(node) { - return node && (node.kind === 212 /* ClassDeclaration */ || node.kind === 184 /* ClassExpression */); + return node && (node.kind === 214 /* ClassDeclaration */ || node.kind === 186 /* ClassExpression */); } ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { - case 142 /* Constructor */: - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 144 /* Constructor */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return true; } } @@ -5539,24 +5705,24 @@ var ts; ts.isFunctionLike = isFunctionLike; function introducesArgumentsExoticObject(node) { switch (node.kind) { - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: return true; } return false; } ts.introducesArgumentsExoticObject = introducesArgumentsExoticObject; function isFunctionBlock(node) { - return node && node.kind === 190 /* Block */ && isFunctionLike(node.parent); + return node && node.kind === 192 /* Block */ && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { - return node && node.kind === 141 /* MethodDeclaration */ && node.parent.kind === 163 /* ObjectLiteralExpression */; + return node && node.kind === 143 /* MethodDeclaration */ && node.parent.kind === 165 /* ObjectLiteralExpression */; } ts.isObjectLiteralMethod = isObjectLiteralMethod; function getContainingFunction(node) { @@ -5584,7 +5750,7 @@ var ts; return undefined; } switch (node.kind) { - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: // If the grandparent node is an object literal (as opposed to a class), // then the computed property is not a 'this' container. // A computed property name in a class needs to be a this container @@ -5599,9 +5765,9 @@ var ts; // the *body* of the container. node = node.parent; break; - case 137 /* Decorator */: + case 139 /* Decorator */: // Decorators are always applied outside of the body of a class or method. - if (node.parent.kind === 136 /* Parameter */ && isClassElement(node.parent.parent)) { + if (node.parent.kind === 138 /* Parameter */ && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. node = node.parent.parent; @@ -5612,23 +5778,26 @@ var ts; node = node.parent; } break; - case 172 /* ArrowFunction */: + case 174 /* ArrowFunction */: if (!includeArrowFunctions) { continue; } // Fall through - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 216 /* ModuleDeclaration */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 215 /* EnumDeclaration */: - case 246 /* SourceFile */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 218 /* ModuleDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 217 /* EnumDeclaration */: + case 248 /* SourceFile */: return node; } } @@ -5640,7 +5809,7 @@ var ts; if (!node) return node; switch (node.kind) { - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: // If the grandparent node is an object literal (as opposed to a class), // then the computed property is not a 'super' container. // A computed property name in a class needs to be a super container @@ -5655,9 +5824,9 @@ var ts; // the *body* of the container. node = node.parent; break; - case 137 /* Decorator */: + case 139 /* Decorator */: // Decorators are always applied outside of the body of a class or method. - if (node.parent.kind === 136 /* Parameter */ && isClassElement(node.parent.parent)) { + if (node.parent.kind === 138 /* Parameter */ && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. node = node.parent.parent; @@ -5668,19 +5837,19 @@ var ts; node = node.parent; } break; - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: if (!includeFunctions) { continue; } - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return node; } } @@ -5689,12 +5858,12 @@ var ts; function getEntityNameFromTypeNode(node) { if (node) { switch (node.kind) { - case 149 /* TypeReference */: + case 151 /* TypeReference */: return node.typeName; - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return node.expression; - case 67 /* Identifier */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 135 /* QualifiedName */: return node; } } @@ -5702,7 +5871,7 @@ var ts; } ts.getEntityNameFromTypeNode = getEntityNameFromTypeNode; function getInvokedExpression(node) { - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { return node.tag; } // Will either be a CallExpression, NewExpression, or Decorator. @@ -5711,44 +5880,44 @@ var ts; ts.getInvokedExpression = getInvokedExpression; function nodeCanBeDecorated(node) { switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: // classes are valid targets return true; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: // property declarations are valid if their parent is a class declaration. - return node.parent.kind === 212 /* ClassDeclaration */; - case 136 /* Parameter */: + return node.parent.kind === 214 /* ClassDeclaration */; + case 138 /* Parameter */: // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target; - return node.parent.body && node.parent.parent.kind === 212 /* ClassDeclaration */; - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 141 /* MethodDeclaration */: + return node.parent.body && node.parent.parent.kind === 214 /* ClassDeclaration */; + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 143 /* MethodDeclaration */: // if this method has a body and its parent is a class declaration, this is a valid target. - return node.body && node.parent.kind === 212 /* ClassDeclaration */; + return node.body && node.parent.kind === 214 /* ClassDeclaration */; } return false; } ts.nodeCanBeDecorated = nodeCanBeDecorated; function nodeIsDecorated(node) { switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: if (node.decorators) { return true; } return false; - case 139 /* PropertyDeclaration */: - case 136 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 138 /* Parameter */: if (node.decorators) { return true; } return false; - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: if (node.body && node.decorators) { return true; } return false; - case 141 /* MethodDeclaration */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 146 /* SetAccessor */: if (node.body && node.decorators) { return true; } @@ -5759,10 +5928,10 @@ var ts; ts.nodeIsDecorated = nodeIsDecorated; function childIsDecorated(node) { switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return ts.forEach(node.members, nodeOrChildIsDecorated); - case 141 /* MethodDeclaration */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 146 /* SetAccessor */: return ts.forEach(node.parameters, nodeIsDecorated); } return false; @@ -5772,96 +5941,106 @@ var ts; return nodeIsDecorated(node) || childIsDecorated(node); } ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated; + function isPropertyAccessExpression(node) { + return node.kind === 166 /* PropertyAccessExpression */; + } + ts.isPropertyAccessExpression = isPropertyAccessExpression; + function isElementAccessExpression(node) { + return node.kind === 167 /* ElementAccessExpression */; + } + ts.isElementAccessExpression = isElementAccessExpression; function isExpression(node) { switch (node.kind) { - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - case 91 /* NullKeyword */: - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 95 /* SuperKeyword */: + case 93 /* NullKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: case 10 /* RegularExpressionLiteral */: - case 162 /* ArrayLiteralExpression */: - case 163 /* ObjectLiteralExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 168 /* TaggedTemplateExpression */: - case 187 /* AsExpression */: - case 169 /* TypeAssertionExpression */: - case 170 /* ParenthesizedExpression */: - case 171 /* FunctionExpression */: - case 184 /* ClassExpression */: - case 172 /* ArrowFunction */: - case 175 /* VoidExpression */: - case 173 /* DeleteExpression */: - case 174 /* TypeOfExpression */: - case 177 /* PrefixUnaryExpression */: - case 178 /* PostfixUnaryExpression */: - case 179 /* BinaryExpression */: - case 180 /* ConditionalExpression */: - case 183 /* SpreadElementExpression */: - case 181 /* TemplateExpression */: + case 164 /* ArrayLiteralExpression */: + case 165 /* ObjectLiteralExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 170 /* TaggedTemplateExpression */: + case 189 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 172 /* ParenthesizedExpression */: + case 173 /* FunctionExpression */: + case 186 /* ClassExpression */: + case 174 /* ArrowFunction */: + case 177 /* VoidExpression */: + case 175 /* DeleteExpression */: + case 176 /* TypeOfExpression */: + case 179 /* PrefixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: + case 181 /* BinaryExpression */: + case 182 /* ConditionalExpression */: + case 185 /* SpreadElementExpression */: + case 183 /* TemplateExpression */: case 11 /* NoSubstitutionTemplateLiteral */: - case 185 /* OmittedExpression */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 182 /* YieldExpression */: + case 187 /* OmittedExpression */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 184 /* YieldExpression */: + case 178 /* AwaitExpression */: return true; - case 133 /* QualifiedName */: - while (node.parent.kind === 133 /* QualifiedName */) { + case 135 /* QualifiedName */: + while (node.parent.kind === 135 /* QualifiedName */) { node = node.parent; } - return node.parent.kind === 152 /* TypeQuery */; - case 67 /* Identifier */: - if (node.parent.kind === 152 /* TypeQuery */) { + return node.parent.kind === 154 /* TypeQuery */; + case 69 /* Identifier */: + if (node.parent.kind === 154 /* TypeQuery */) { return true; } // fall through case 8 /* NumericLiteral */: case 9 /* StringLiteral */: + case 97 /* ThisKeyword */: var parent_2 = node.parent; switch (parent_2.kind) { - case 209 /* VariableDeclaration */: - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 245 /* EnumMember */: - case 243 /* PropertyAssignment */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 247 /* EnumMember */: + case 245 /* PropertyAssignment */: + case 163 /* BindingElement */: return parent_2.initializer === node; - case 193 /* ExpressionStatement */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 202 /* ReturnStatement */: - case 203 /* WithStatement */: - case 204 /* SwitchStatement */: - case 239 /* CaseClause */: - case 206 /* ThrowStatement */: - case 204 /* SwitchStatement */: + case 195 /* ExpressionStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 204 /* ReturnStatement */: + case 205 /* WithStatement */: + case 206 /* SwitchStatement */: + case 241 /* CaseClause */: + case 208 /* ThrowStatement */: + case 206 /* SwitchStatement */: return parent_2.expression === node; - case 197 /* ForStatement */: + case 199 /* ForStatement */: var forStatement = parent_2; - return (forStatement.initializer === node && forStatement.initializer.kind !== 210 /* VariableDeclarationList */) || + return (forStatement.initializer === node && forStatement.initializer.kind !== 212 /* VariableDeclarationList */) || forStatement.condition === node || forStatement.incrementor === node; - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: var forInStatement = parent_2; - return (forInStatement.initializer === node && forInStatement.initializer.kind !== 210 /* VariableDeclarationList */) || + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 212 /* VariableDeclarationList */) || forInStatement.expression === node; - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: return node === parent_2.expression; - case 188 /* TemplateSpan */: + case 190 /* TemplateSpan */: return node === parent_2.expression; - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: return node === parent_2.expression; - case 137 /* Decorator */: - case 238 /* JsxExpression */: + case 139 /* Decorator */: + case 240 /* JsxExpression */: + case 239 /* JsxSpreadAttribute */: return true; - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return parent_2.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent_2); default: if (isExpression(parent_2)) { @@ -5872,6 +6051,12 @@ var ts; return false; } ts.isExpression = isExpression; + function isExternalModuleNameRelative(moduleName) { + // TypeScript 1.0 spec (April 2014): 11.2.1 + // An external module name is "relative" if the first term is "." or "..". + return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + } + ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { var moduleState = ts.getModuleInstanceState(node); return moduleState === 1 /* Instantiated */ || @@ -5879,7 +6064,7 @@ var ts; } ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 230 /* ExternalModuleReference */; + return node.kind === 221 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 232 /* ExternalModuleReference */; } ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration; function getExternalModuleImportEqualsDeclarationExpression(node) { @@ -5888,20 +6073,20 @@ var ts; } ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression; function isInternalModuleImportEqualsDeclaration(node) { - return node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 230 /* ExternalModuleReference */; + return node.kind === 221 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 232 /* ExternalModuleReference */; } ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration; function getExternalModuleName(node) { - if (node.kind === 220 /* ImportDeclaration */) { + if (node.kind === 222 /* ImportDeclaration */) { return node.moduleSpecifier; } - if (node.kind === 219 /* ImportEqualsDeclaration */) { + if (node.kind === 221 /* ImportEqualsDeclaration */) { var reference = node.moduleReference; - if (reference.kind === 230 /* ExternalModuleReference */) { + if (reference.kind === 232 /* ExternalModuleReference */) { return reference.expression; } } - if (node.kind === 226 /* ExportDeclaration */) { + if (node.kind === 228 /* ExportDeclaration */) { return node.moduleSpecifier; } } @@ -5909,13 +6094,13 @@ var ts; function hasQuestionToken(node) { if (node) { switch (node.kind) { - case 136 /* Parameter */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 244 /* ShorthandPropertyAssignment */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 138 /* Parameter */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 246 /* ShorthandPropertyAssignment */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return node.questionToken !== undefined; } } @@ -5923,9 +6108,9 @@ var ts; } ts.hasQuestionToken = hasQuestionToken; function isJSDocConstructSignature(node) { - return node.kind === 259 /* JSDocFunctionType */ && + return node.kind === 261 /* JSDocFunctionType */ && node.parameters.length > 0 && - node.parameters[0].type.kind === 261 /* JSDocConstructorType */; + node.parameters[0].type.kind === 263 /* JSDocConstructorType */; } ts.isJSDocConstructSignature = isJSDocConstructSignature; function getJSDocTag(node, kind) { @@ -5939,26 +6124,26 @@ var ts; } } function getJSDocTypeTag(node) { - return getJSDocTag(node, 267 /* JSDocTypeTag */); + return getJSDocTag(node, 269 /* JSDocTypeTag */); } ts.getJSDocTypeTag = getJSDocTypeTag; function getJSDocReturnTag(node) { - return getJSDocTag(node, 266 /* JSDocReturnTag */); + return getJSDocTag(node, 268 /* JSDocReturnTag */); } ts.getJSDocReturnTag = getJSDocReturnTag; function getJSDocTemplateTag(node) { - return getJSDocTag(node, 268 /* JSDocTemplateTag */); + return getJSDocTag(node, 270 /* JSDocTemplateTag */); } ts.getJSDocTemplateTag = getJSDocTemplateTag; function getCorrespondingJSDocParameterTag(parameter) { - if (parameter.name && parameter.name.kind === 67 /* Identifier */) { + if (parameter.name && parameter.name.kind === 69 /* Identifier */) { // If it's a parameter, see if the parent has a jsdoc comment with an @param // annotation. var parameterName = parameter.name.text; var docComment = parameter.parent.jsDocComment; if (docComment) { return ts.forEach(docComment.tags, function (t) { - if (t.kind === 265 /* JSDocParameterTag */) { + if (t.kind === 267 /* JSDocParameterTag */) { var parameterTag = t; var name_6 = parameterTag.preParameterName || parameterTag.postParameterName; if (name_6.text === parameterName) { @@ -5977,12 +6162,12 @@ var ts; function isRestParameter(node) { if (node) { if (node.parserContextFlags & 32 /* JavaScriptFile */) { - if (node.type && node.type.kind === 260 /* JSDocVariadicType */) { + if (node.type && node.type.kind === 262 /* JSDocVariadicType */) { return true; } var paramTag = getCorrespondingJSDocParameterTag(node); if (paramTag && paramTag.typeExpression) { - return paramTag.typeExpression.type.kind === 260 /* JSDocVariadicType */; + return paramTag.typeExpression.type.kind === 262 /* JSDocVariadicType */; } } return node.dotDotDotToken !== undefined; @@ -6003,7 +6188,7 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return !!node && (node.kind === 160 /* ArrayBindingPattern */ || node.kind === 159 /* ObjectBindingPattern */); + return !!node && (node.kind === 162 /* ArrayBindingPattern */ || node.kind === 161 /* ObjectBindingPattern */); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { @@ -6018,34 +6203,34 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 172 /* ArrowFunction */: - case 161 /* BindingElement */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 142 /* Constructor */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 228 /* ExportSpecifier */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 143 /* GetAccessor */: - case 221 /* ImportClause */: - case 219 /* ImportEqualsDeclaration */: - case 224 /* ImportSpecifier */: - case 213 /* InterfaceDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 216 /* ModuleDeclaration */: - case 222 /* NamespaceImport */: - case 136 /* Parameter */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 144 /* SetAccessor */: - case 244 /* ShorthandPropertyAssignment */: - case 214 /* TypeAliasDeclaration */: - case 135 /* TypeParameter */: - case 209 /* VariableDeclaration */: + case 174 /* ArrowFunction */: + case 163 /* BindingElement */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 144 /* Constructor */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 230 /* ExportSpecifier */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 145 /* GetAccessor */: + case 223 /* ImportClause */: + case 221 /* ImportEqualsDeclaration */: + case 226 /* ImportSpecifier */: + case 215 /* InterfaceDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 218 /* ModuleDeclaration */: + case 224 /* NamespaceImport */: + case 138 /* Parameter */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 146 /* SetAccessor */: + case 246 /* ShorthandPropertyAssignment */: + case 216 /* TypeAliasDeclaration */: + case 137 /* TypeParameter */: + case 211 /* VariableDeclaration */: return true; } return false; @@ -6053,25 +6238,25 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 201 /* BreakStatement */: - case 200 /* ContinueStatement */: - case 208 /* DebuggerStatement */: - case 195 /* DoStatement */: - case 193 /* ExpressionStatement */: - case 192 /* EmptyStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 197 /* ForStatement */: - case 194 /* IfStatement */: - case 205 /* LabeledStatement */: - case 202 /* ReturnStatement */: - case 204 /* SwitchStatement */: - case 96 /* ThrowKeyword */: - case 207 /* TryStatement */: - case 191 /* VariableStatement */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 225 /* ExportAssignment */: + case 203 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 210 /* DebuggerStatement */: + case 197 /* DoStatement */: + case 195 /* ExpressionStatement */: + case 194 /* EmptyStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 199 /* ForStatement */: + case 196 /* IfStatement */: + case 207 /* LabeledStatement */: + case 204 /* ReturnStatement */: + case 206 /* SwitchStatement */: + case 98 /* ThrowKeyword */: + case 209 /* TryStatement */: + case 193 /* VariableStatement */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 227 /* ExportAssignment */: return true; default: return false; @@ -6080,13 +6265,13 @@ var ts; ts.isStatement = isStatement; function isClassElement(n) { switch (n.kind) { - case 142 /* Constructor */: - case 139 /* PropertyDeclaration */: - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 140 /* MethodSignature */: - case 147 /* IndexSignature */: + case 144 /* Constructor */: + case 141 /* PropertyDeclaration */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 142 /* MethodSignature */: + case 149 /* IndexSignature */: return true; default: return false; @@ -6095,11 +6280,11 @@ var ts; ts.isClassElement = isClassElement; // True if the given identifier, string literal, or number literal is the name of a declaration node function isDeclarationName(name) { - if (name.kind !== 67 /* Identifier */ && name.kind !== 9 /* StringLiteral */ && name.kind !== 8 /* NumericLiteral */) { + if (name.kind !== 69 /* Identifier */ && name.kind !== 9 /* StringLiteral */ && name.kind !== 8 /* NumericLiteral */) { return false; } var parent = name.parent; - if (parent.kind === 224 /* ImportSpecifier */ || parent.kind === 228 /* ExportSpecifier */) { + if (parent.kind === 226 /* ImportSpecifier */ || parent.kind === 230 /* ExportSpecifier */) { if (parent.propertyName) { return true; } @@ -6114,31 +6299,31 @@ var ts; function isIdentifierName(node) { var parent = node.parent; switch (parent.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 245 /* EnumMember */: - case 243 /* PropertyAssignment */: - case 164 /* PropertyAccessExpression */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 247 /* EnumMember */: + case 245 /* PropertyAssignment */: + case 166 /* PropertyAccessExpression */: // Name in member declaration or property name in property access return parent.name === node; - case 133 /* QualifiedName */: + case 135 /* QualifiedName */: // Name on right hand side of dot in a type query if (parent.right === node) { - while (parent.kind === 133 /* QualifiedName */) { + while (parent.kind === 135 /* QualifiedName */) { parent = parent.parent; } - return parent.kind === 152 /* TypeQuery */; + return parent.kind === 154 /* TypeQuery */; } return false; - case 161 /* BindingElement */: - case 224 /* ImportSpecifier */: + case 163 /* BindingElement */: + case 226 /* ImportSpecifier */: // Property name in binding element or import specifier return parent.propertyName === node; - case 228 /* ExportSpecifier */: + case 230 /* ExportSpecifier */: // Any name in an export specifier return true; } @@ -6154,26 +6339,26 @@ var ts; // export = ... // export default ... function isAliasSymbolDeclaration(node) { - return node.kind === 219 /* ImportEqualsDeclaration */ || - node.kind === 221 /* ImportClause */ && !!node.name || - node.kind === 222 /* NamespaceImport */ || - node.kind === 224 /* ImportSpecifier */ || - node.kind === 228 /* ExportSpecifier */ || - node.kind === 225 /* ExportAssignment */ && node.expression.kind === 67 /* Identifier */; + return node.kind === 221 /* ImportEqualsDeclaration */ || + node.kind === 223 /* ImportClause */ && !!node.name || + node.kind === 224 /* NamespaceImport */ || + node.kind === 226 /* ImportSpecifier */ || + node.kind === 230 /* ExportSpecifier */ || + node.kind === 227 /* ExportAssignment */ && node.expression.kind === 69 /* Identifier */; } ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration; function getClassExtendsHeritageClauseElement(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81 /* ExtendsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 83 /* ExtendsKeyword */); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement; function getClassImplementsHeritageClauseElements(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 104 /* ImplementsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 106 /* ImplementsKeyword */); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements; function getInterfaceBaseTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 81 /* ExtendsKeyword */); + var heritageClause = getHeritageClause(node.heritageClauses, 83 /* ExtendsKeyword */); return heritageClause ? heritageClause.types : undefined; } ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes; @@ -6242,7 +6427,7 @@ var ts; } ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath; function isKeyword(token) { - return 68 /* FirstKeyword */ <= token && token <= 132 /* LastKeyword */; + return 70 /* FirstKeyword */ <= token && token <= 134 /* LastKeyword */; } ts.isKeyword = isKeyword; function isTrivia(token) { @@ -6262,7 +6447,7 @@ var ts; */ function hasDynamicName(declaration) { return declaration.name && - declaration.name.kind === 134 /* ComputedPropertyName */ && + declaration.name.kind === 136 /* ComputedPropertyName */ && !isWellKnownSymbolSyntactically(declaration.name.expression); } ts.hasDynamicName = hasDynamicName; @@ -6272,14 +6457,14 @@ var ts; * where Symbol is literally the word "Symbol", and name is any identifierName */ function isWellKnownSymbolSyntactically(node) { - return node.kind === 164 /* PropertyAccessExpression */ && isESSymbolIdentifier(node.expression); + return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression); } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 67 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { + if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { return name.text; } - if (name.kind === 134 /* ComputedPropertyName */) { + if (name.kind === 136 /* ComputedPropertyName */) { var nameExpression = name.expression; if (isWellKnownSymbolSyntactically(nameExpression)) { var rightHandSideName = nameExpression.name.text; @@ -6297,21 +6482,21 @@ var ts; * Includes the word "Symbol" with unicode escapes */ function isESSymbolIdentifier(node) { - return node.kind === 67 /* Identifier */ && node.text === "Symbol"; + return node.kind === 69 /* Identifier */ && node.text === "Symbol"; } ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 113 /* AbstractKeyword */: - case 116 /* AsyncKeyword */: - case 72 /* ConstKeyword */: - case 120 /* DeclareKeyword */: - case 75 /* DefaultKeyword */: - case 80 /* ExportKeyword */: - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: + case 115 /* AbstractKeyword */: + case 118 /* AsyncKeyword */: + case 74 /* ConstKeyword */: + case 122 /* DeclareKeyword */: + case 77 /* DefaultKeyword */: + case 82 /* ExportKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 113 /* StaticKeyword */: return true; } return false; @@ -6319,28 +6504,28 @@ var ts; ts.isModifier = isModifier; function isParameterDeclaration(node) { var root = getRootDeclaration(node); - return root.kind === 136 /* Parameter */; + return root.kind === 138 /* Parameter */; } ts.isParameterDeclaration = isParameterDeclaration; function getRootDeclaration(node) { - while (node.kind === 161 /* BindingElement */) { + while (node.kind === 163 /* BindingElement */) { node = node.parent.parent; } return node; } ts.getRootDeclaration = getRootDeclaration; function nodeStartsNewLexicalEnvironment(n) { - return isFunctionLike(n) || n.kind === 216 /* ModuleDeclaration */ || n.kind === 246 /* SourceFile */; + return isFunctionLike(n) || n.kind === 218 /* ModuleDeclaration */ || n.kind === 248 /* SourceFile */; } ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; function cloneEntityName(node) { - if (node.kind === 67 /* Identifier */) { - var clone_1 = createSynthesizedNode(67 /* Identifier */); + if (node.kind === 69 /* Identifier */) { + var clone_1 = createSynthesizedNode(69 /* Identifier */); clone_1.text = node.text; return clone_1; } else { - var clone_2 = createSynthesizedNode(133 /* QualifiedName */); + var clone_2 = createSynthesizedNode(135 /* QualifiedName */); clone_2.left = cloneEntityName(node.left); clone_2.left.parent = clone_2; clone_2.right = cloneEntityName(node.right); @@ -6595,7 +6780,7 @@ var ts; ts.getLineOfLocalPosition = getLineOfLocalPosition; function getFirstConstructorWithBody(node) { return ts.forEach(node.members, function (member) { - if (member.kind === 142 /* Constructor */ && nodeIsPresent(member.body)) { + if (member.kind === 144 /* Constructor */ && nodeIsPresent(member.body)) { return member; } }); @@ -6624,10 +6809,10 @@ var ts; var setAccessor; if (hasDynamicName(accessor)) { firstAccessor = accessor; - if (accessor.kind === 143 /* GetAccessor */) { + if (accessor.kind === 145 /* GetAccessor */) { getAccessor = accessor; } - else if (accessor.kind === 144 /* SetAccessor */) { + else if (accessor.kind === 146 /* SetAccessor */) { setAccessor = accessor; } else { @@ -6636,7 +6821,7 @@ var ts; } else { ts.forEach(declarations, function (member) { - if ((member.kind === 143 /* GetAccessor */ || member.kind === 144 /* SetAccessor */) + if ((member.kind === 145 /* GetAccessor */ || member.kind === 146 /* SetAccessor */) && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) { var memberName = getPropertyNameForPropertyNameNode(member.name); var accessorName = getPropertyNameForPropertyNameNode(accessor.name); @@ -6647,10 +6832,10 @@ var ts; else if (!secondAccessor) { secondAccessor = member; } - if (member.kind === 143 /* GetAccessor */ && !getAccessor) { + if (member.kind === 145 /* GetAccessor */ && !getAccessor) { getAccessor = member; } - if (member.kind === 144 /* SetAccessor */ && !setAccessor) { + if (member.kind === 146 /* SetAccessor */ && !setAccessor) { setAccessor = member; } } @@ -6783,16 +6968,16 @@ var ts; ts.writeCommentRange = writeCommentRange; function modifierToFlag(token) { switch (token) { - case 111 /* StaticKeyword */: return 128 /* Static */; - case 110 /* PublicKeyword */: return 16 /* Public */; - case 109 /* ProtectedKeyword */: return 64 /* Protected */; - case 108 /* PrivateKeyword */: return 32 /* Private */; - case 113 /* AbstractKeyword */: return 256 /* Abstract */; - case 80 /* ExportKeyword */: return 1 /* Export */; - case 120 /* DeclareKeyword */: return 2 /* Ambient */; - case 72 /* ConstKeyword */: return 32768 /* Const */; - case 75 /* DefaultKeyword */: return 1024 /* Default */; - case 116 /* AsyncKeyword */: return 512 /* Async */; + case 113 /* StaticKeyword */: return 128 /* Static */; + case 112 /* PublicKeyword */: return 16 /* Public */; + case 111 /* ProtectedKeyword */: return 64 /* Protected */; + case 110 /* PrivateKeyword */: return 32 /* Private */; + case 115 /* AbstractKeyword */: return 256 /* Abstract */; + case 82 /* ExportKeyword */: return 1 /* Export */; + case 122 /* DeclareKeyword */: return 2 /* Ambient */; + case 74 /* ConstKeyword */: return 32768 /* Const */; + case 77 /* DefaultKeyword */: return 1024 /* Default */; + case 118 /* AsyncKeyword */: return 512 /* Async */; } return 0; } @@ -6800,29 +6985,29 @@ var ts; function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 167 /* NewExpression */: - case 166 /* CallExpression */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 168 /* TaggedTemplateExpression */: - case 162 /* ArrayLiteralExpression */: - case 170 /* ParenthesizedExpression */: - case 163 /* ObjectLiteralExpression */: - case 184 /* ClassExpression */: - case 171 /* FunctionExpression */: - case 67 /* Identifier */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 169 /* NewExpression */: + case 168 /* CallExpression */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 170 /* TaggedTemplateExpression */: + case 164 /* ArrayLiteralExpression */: + case 172 /* ParenthesizedExpression */: + case 165 /* ObjectLiteralExpression */: + case 186 /* ClassExpression */: + case 173 /* FunctionExpression */: + case 69 /* Identifier */: case 10 /* RegularExpressionLiteral */: case 8 /* NumericLiteral */: case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: - case 181 /* TemplateExpression */: - case 82 /* FalseKeyword */: - case 91 /* NullKeyword */: - case 95 /* ThisKeyword */: - case 97 /* TrueKeyword */: - case 93 /* SuperKeyword */: + case 183 /* TemplateExpression */: + case 84 /* FalseKeyword */: + case 93 /* NullKeyword */: + case 97 /* ThisKeyword */: + case 99 /* TrueKeyword */: + case 95 /* SuperKeyword */: return true; } } @@ -6830,12 +7015,12 @@ var ts; } ts.isLeftHandSideExpression = isLeftHandSideExpression; function isAssignmentOperator(token) { - return token >= 55 /* FirstAssignment */ && token <= 66 /* LastAssignment */; + return token >= 56 /* FirstAssignment */ && token <= 68 /* LastAssignment */; } ts.isAssignmentOperator = isAssignmentOperator; function isExpressionWithTypeArgumentsInClassExtendsClause(node) { - return node.kind === 186 /* ExpressionWithTypeArguments */ && - node.parent.token === 81 /* ExtendsKeyword */ && + return node.kind === 188 /* ExpressionWithTypeArguments */ && + node.parent.token === 83 /* ExtendsKeyword */ && isClassLike(node.parent.parent); } ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause; @@ -6846,10 +7031,10 @@ var ts; } ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments; function isSupportedExpressionWithTypeArgumentsRest(node) { - if (node.kind === 67 /* Identifier */) { + if (node.kind === 69 /* Identifier */) { return true; } - else if (node.kind === 164 /* PropertyAccessExpression */) { + else if (isPropertyAccessExpression(node)) { return isSupportedExpressionWithTypeArgumentsRest(node.expression); } else { @@ -6857,16 +7042,16 @@ var ts; } } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node) || - (node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node); + return (node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node) || + (node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.name === node); } ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess; function isEmptyObjectLiteralOrArrayLiteral(expression) { var kind = expression.kind; - if (kind === 163 /* ObjectLiteralExpression */) { + if (kind === 165 /* ObjectLiteralExpression */) { return expression.properties.length === 0; } - if (kind === 162 /* ArrayLiteralExpression */) { + if (kind === 164 /* ArrayLiteralExpression */) { return expression.elements.length === 0; } return false; @@ -7178,21 +7363,31 @@ var ts; } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; function getTypeParameterOwner(d) { - if (d && d.kind === 135 /* TypeParameter */) { + if (d && d.kind === 137 /* TypeParameter */) { for (var current = d; current; current = current.parent) { - if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 213 /* InterfaceDeclaration */) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 215 /* InterfaceDeclaration */) { return current; } } } } ts.getTypeParameterOwner = getTypeParameterOwner; + function arrayStructurallyIsEqualTo(array1, array2) { + if (!array1 || !array2) { + return false; + } + if (array1.length !== array2.length) { + return false; + } + return ts.arrayIsEqualTo(array1.sort(), array2.sort()); + } + ts.arrayStructurallyIsEqualTo = arrayStructurallyIsEqualTo; })(ts || (ts = {})); /// /// var ts; (function (ts) { - var nodeConstructors = new Array(270 /* Count */); + var nodeConstructors = new Array(272 /* Count */); /* @internal */ ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -7237,20 +7432,26 @@ var ts; var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; var cbNodes = cbNodeArray || cbNode; switch (node.kind) { - case 133 /* QualifiedName */: + case 135 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 243 /* PropertyAssignment */: - case 244 /* ShorthandPropertyAssignment */: - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 246 /* ShorthandPropertyAssignment */: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, node.name) || + visitNode(cbNode, node.questionToken) || + visitNode(cbNode, node.equalsToken) || + visitNode(cbNode, node.objectAssignmentInitializer); + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 245 /* PropertyAssignment */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || @@ -7259,24 +7460,24 @@ var ts; visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || @@ -7287,290 +7488,290 @@ var ts; visitNode(cbNode, node.type) || visitNode(cbNode, node.equalsGreaterThanToken) || visitNode(cbNode, node.body); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return visitNode(cbNode, node.exprName); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return visitNodes(cbNodes, node.members); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return visitNode(cbNode, node.elementType); - case 155 /* TupleType */: + case 157 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); - case 156 /* UnionType */: - case 157 /* IntersectionType */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: return visitNodes(cbNodes, node.types); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return visitNode(cbNode, node.type); - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); - case 164 /* PropertyAccessExpression */: + case 166 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); - case 165 /* ElementAccessExpression */: + case 167 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); - case 169 /* TypeAssertionExpression */: + case 171 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); - case 173 /* DeleteExpression */: + case 175 /* DeleteExpression */: return visitNode(cbNode, node.expression); - case 174 /* TypeOfExpression */: + case 176 /* TypeOfExpression */: return visitNode(cbNode, node.expression); - case 175 /* VoidExpression */: + case 177 /* VoidExpression */: return visitNode(cbNode, node.expression); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); - case 176 /* AwaitExpression */: + case 178 /* AwaitExpression */: return visitNode(cbNode, node.expression); - case 178 /* PostfixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); - case 187 /* AsExpression */: + case 189 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); - case 183 /* SpreadElementExpression */: + case 185 /* SpreadElementExpression */: return visitNode(cbNode, node.expression); - case 190 /* Block */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); - case 210 /* VariableDeclarationList */: + case 212 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); - case 193 /* ExpressionStatement */: + case 195 /* ExpressionStatement */: return visitNode(cbNode, node.expression); - case 194 /* IfStatement */: + case 196 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); - case 195 /* DoStatement */: + case 197 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); - case 196 /* WhileStatement */: + case 198 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 197 /* ForStatement */: + case 199 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); - case 198 /* ForInStatement */: + case 200 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 199 /* ForOfStatement */: + case 201 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: return visitNode(cbNode, node.label); - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: return visitNode(cbNode, node.expression); - case 203 /* WithStatement */: + case 205 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); - case 218 /* CaseBlock */: + case 220 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); - case 239 /* CaseClause */: + case 241 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); - case 240 /* DefaultClause */: + case 242 /* DefaultClause */: return visitNodes(cbNodes, node.statements); - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); - case 206 /* ThrowStatement */: + case 208 /* ThrowStatement */: return visitNode(cbNode, node.expression); - case 207 /* TryStatement */: + case 209 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); - case 137 /* Decorator */: + case 139 /* Decorator */: return visitNode(cbNode, node.expression); - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); - case 221 /* ImportClause */: + case 223 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 222 /* NamespaceImport */: + case 224 /* NamespaceImport */: return visitNode(cbNode, node.name); - case 223 /* NamedImports */: - case 227 /* NamedExports */: + case 225 /* NamedImports */: + case 229 /* NamedExports */: return visitNodes(cbNodes, node.elements); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); - case 181 /* TemplateExpression */: + case 183 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); - case 188 /* TemplateSpan */: + case 190 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); - case 241 /* HeritageClause */: + case 243 /* HeritageClause */: return visitNodes(cbNodes, node.types); - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); - case 230 /* ExternalModuleReference */: + case 232 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); - case 229 /* MissingDeclaration */: + case 231 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); - case 231 /* JsxElement */: + case 233 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); - case 232 /* JsxSelfClosingElement */: - case 233 /* JsxOpeningElement */: + case 234 /* JsxSelfClosingElement */: + case 235 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); - case 236 /* JsxAttribute */: + case 238 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); - case 237 /* JsxSpreadAttribute */: + case 239 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); - case 238 /* JsxExpression */: + case 240 /* JsxExpression */: return visitNode(cbNode, node.expression); - case 235 /* JsxClosingElement */: + case 237 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); - case 247 /* JSDocTypeExpression */: + case 249 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); - case 251 /* JSDocUnionType */: + case 253 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); - case 252 /* JSDocTupleType */: + case 254 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); - case 250 /* JSDocArrayType */: + case 252 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); - case 254 /* JSDocNonNullableType */: + case 256 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); - case 253 /* JSDocNullableType */: + case 255 /* JSDocNullableType */: return visitNode(cbNode, node.type); - case 255 /* JSDocRecordType */: + case 257 /* JSDocRecordType */: return visitNodes(cbNodes, node.members); - case 257 /* JSDocTypeReference */: + case 259 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); - case 258 /* JSDocOptionalType */: + case 260 /* JSDocOptionalType */: return visitNode(cbNode, node.type); - case 259 /* JSDocFunctionType */: + case 261 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 260 /* JSDocVariadicType */: + case 262 /* JSDocVariadicType */: return visitNode(cbNode, node.type); - case 261 /* JSDocConstructorType */: + case 263 /* JSDocConstructorType */: return visitNode(cbNode, node.type); - case 262 /* JSDocThisType */: + case 264 /* JSDocThisType */: return visitNode(cbNode, node.type); - case 256 /* JSDocRecordMember */: + case 258 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); - case 263 /* JSDocComment */: + case 265 /* JSDocComment */: return visitNodes(cbNodes, node.tags); - case 265 /* JSDocParameterTag */: + case 267 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); - case 266 /* JSDocReturnTag */: + case 268 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); - case 267 /* JSDocTypeTag */: + case 269 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); - case 268 /* JSDocTemplateTag */: + case 270 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); } } @@ -7765,9 +7966,9 @@ var ts; // Add additional cases as necessary depending on how we see JSDoc comments used // in the wild. switch (node.kind) { - case 191 /* VariableStatement */: - case 211 /* FunctionDeclaration */: - case 136 /* Parameter */: + case 193 /* VariableStatement */: + case 213 /* FunctionDeclaration */: + case 138 /* Parameter */: addJSDocComment(node); } forEachChild(node, visit); @@ -7808,7 +8009,7 @@ var ts; } Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - var sourceFile = createNode(246 /* SourceFile */, /*pos*/ 0); + var sourceFile = createNode(248 /* SourceFile */, /*pos*/ 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; @@ -7972,7 +8173,7 @@ var ts; var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; // Note: it is not actually necessary to save/restore the context flags here. That's - // because the saving/restorating of these flags happens naturally through the recursive + // because the saving/restoring of these flags happens naturally through the recursive // descent nature of our parser. However, we still store this here just so we can // assert that that invariant holds. var saveContextFlags = contextFlags; @@ -8007,20 +8208,20 @@ var ts; } // Ignore strict mode flag because we will report an error in type checker instead. function isIdentifier() { - if (token === 67 /* Identifier */) { + if (token === 69 /* Identifier */) { return true; } // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. - if (token === 112 /* YieldKeyword */ && inYieldContext()) { + if (token === 114 /* YieldKeyword */ && inYieldContext()) { return false; } // If we have a 'await' keyword, and we're in the [Await] context, then 'await' is // considered a keyword and is not an identifier. - if (token === 117 /* AwaitKeyword */ && inAwaitContext()) { + if (token === 119 /* AwaitKeyword */ && inAwaitContext()) { return false; } - return token > 103 /* LastReservedWord */; + return token > 105 /* LastReservedWord */; } function parseExpected(kind, diagnosticMessage, shouldAdvance) { if (shouldAdvance === void 0) { shouldAdvance = true; } @@ -8126,16 +8327,16 @@ var ts; function createIdentifier(isIdentifier, diagnosticMessage) { identifierCount++; if (isIdentifier) { - var node = createNode(67 /* Identifier */); + var node = createNode(69 /* Identifier */); // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker - if (token !== 67 /* Identifier */) { + if (token !== 69 /* Identifier */) { node.originalKeywordKind = token; } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); } - return createMissingNode(67 /* Identifier */, /*reportAtCurrentPosition*/ false, diagnosticMessage || ts.Diagnostics.Identifier_expected); + return createMissingNode(69 /* Identifier */, /*reportAtCurrentPosition*/ false, diagnosticMessage || ts.Diagnostics.Identifier_expected); } function parseIdentifier(diagnosticMessage) { return createIdentifier(isIdentifier(), diagnosticMessage); @@ -8170,7 +8371,7 @@ var ts; // PropertyName [Yield]: // LiteralPropertyName // ComputedPropertyName[?Yield] - var node = createNode(134 /* ComputedPropertyName */); + var node = createNode(136 /* ComputedPropertyName */); parseExpected(19 /* OpenBracketToken */); // We parse any expression (including a comma expression). But the grammar // says that only an assignment expression is allowed, so the grammar checker @@ -8183,21 +8384,28 @@ var ts; return token === t && tryParse(nextTokenCanFollowModifier); } function nextTokenCanFollowModifier() { - if (token === 72 /* ConstKeyword */) { + if (token === 74 /* ConstKeyword */) { // 'const' is only a modifier if followed by 'enum'. - return nextToken() === 79 /* EnumKeyword */; + return nextToken() === 81 /* EnumKeyword */; } - if (token === 80 /* ExportKeyword */) { + if (token === 82 /* ExportKeyword */) { nextToken(); - if (token === 75 /* DefaultKeyword */) { + if (token === 77 /* DefaultKeyword */) { return lookAhead(nextTokenIsClassOrFunction); } return token !== 37 /* AsteriskToken */ && token !== 15 /* OpenBraceToken */ && canFollowModifier(); } - if (token === 75 /* DefaultKeyword */) { + if (token === 77 /* DefaultKeyword */) { return nextTokenIsClassOrFunction(); } + if (token === 113 /* StaticKeyword */) { + nextToken(); + return canFollowModifier(); + } nextToken(); + if (scanner.hasPrecedingLineBreak()) { + return false; + } return canFollowModifier(); } function parseAnyContextualModifier() { @@ -8211,7 +8419,7 @@ var ts; } function nextTokenIsClassOrFunction() { nextToken(); - return token === 71 /* ClassKeyword */ || token === 85 /* FunctionKeyword */; + return token === 73 /* ClassKeyword */ || token === 87 /* FunctionKeyword */; } // True if positioned at the start of a list element function isListElement(parsingContext, inErrorRecovery) { @@ -8231,7 +8439,7 @@ var ts; // outer module. We just want to consume and move on. return !(token === 23 /* SemicolonToken */ && inErrorRecovery) && isStartOfStatement(); case 2 /* SwitchClauses */: - return token === 69 /* CaseKeyword */ || token === 75 /* DefaultKeyword */; + return token === 71 /* CaseKeyword */ || token === 77 /* DefaultKeyword */; case 4 /* TypeMembers */: return isStartOfTypeMember(); case 5 /* ClassMembers */: @@ -8305,7 +8513,7 @@ var ts; // extends {} extends // extends {} implements var next = nextToken(); - return next === 24 /* CommaToken */ || next === 15 /* OpenBraceToken */ || next === 81 /* ExtendsKeyword */ || next === 104 /* ImplementsKeyword */; + return next === 24 /* CommaToken */ || next === 15 /* OpenBraceToken */ || next === 83 /* ExtendsKeyword */ || next === 106 /* ImplementsKeyword */; } return true; } @@ -8318,8 +8526,8 @@ var ts; return ts.tokenIsIdentifierOrKeyword(token); } function isHeritageClauseExtendsOrImplementsKeyword() { - if (token === 104 /* ImplementsKeyword */ || - token === 81 /* ExtendsKeyword */) { + if (token === 106 /* ImplementsKeyword */ || + token === 83 /* ExtendsKeyword */) { return lookAhead(nextTokenIsStartOfExpression); } return false; @@ -8345,14 +8553,14 @@ var ts; case 21 /* ImportOrExportSpecifiers */: return token === 16 /* CloseBraceToken */; case 3 /* SwitchClauseStatements */: - return token === 16 /* CloseBraceToken */ || token === 69 /* CaseKeyword */ || token === 75 /* DefaultKeyword */; + return token === 16 /* CloseBraceToken */ || token === 71 /* CaseKeyword */ || token === 77 /* DefaultKeyword */; case 7 /* HeritageClauseElement */: - return token === 15 /* OpenBraceToken */ || token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */; + return token === 15 /* OpenBraceToken */ || token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */; case 8 /* VariableDeclarations */: return isVariableDeclaratorListTerminator(); case 17 /* TypeParameters */: // Tokens other than '>' are here for better error recovery - return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */ || token === 15 /* OpenBraceToken */ || token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */; + return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */ || token === 15 /* OpenBraceToken */ || token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */; case 11 /* ArgumentExpressions */: // Tokens other than ')' are here for better error recovery return token === 18 /* CloseParenToken */ || token === 23 /* SemicolonToken */; @@ -8369,11 +8577,11 @@ var ts; case 20 /* HeritageClauses */: return token === 15 /* OpenBraceToken */ || token === 16 /* CloseBraceToken */; case 13 /* JsxAttributes */: - return token === 27 /* GreaterThanToken */ || token === 38 /* SlashToken */; + return token === 27 /* GreaterThanToken */ || token === 39 /* SlashToken */; case 14 /* JsxChildren */: return token === 25 /* LessThanToken */ && lookAhead(nextTokenIsSlash); case 22 /* JSDocFunctionParameters */: - return token === 18 /* CloseParenToken */ || token === 53 /* ColonToken */ || token === 16 /* CloseBraceToken */; + return token === 18 /* CloseParenToken */ || token === 54 /* ColonToken */ || token === 16 /* CloseBraceToken */; case 23 /* JSDocTypeArguments */: return token === 27 /* GreaterThanToken */ || token === 16 /* CloseBraceToken */; case 25 /* JSDocTupleTypes */: @@ -8561,20 +8769,20 @@ var ts; function isReusableClassMember(node) { if (node) { switch (node.kind) { - case 142 /* Constructor */: - case 147 /* IndexSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 139 /* PropertyDeclaration */: - case 189 /* SemicolonClassElement */: + case 144 /* Constructor */: + case 149 /* IndexSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 191 /* SemicolonClassElement */: return true; - case 141 /* MethodDeclaration */: + case 143 /* MethodDeclaration */: // Method declarations are not necessarily reusable. An object-literal // may have a method calls "constructor(...)" and we must reparse that // into an actual .ConstructorDeclaration. var methodDeclaration = node; - var nameIsConstructor = methodDeclaration.name.kind === 67 /* Identifier */ && - methodDeclaration.name.originalKeywordKind === 119 /* ConstructorKeyword */; + var nameIsConstructor = methodDeclaration.name.kind === 69 /* Identifier */ && + methodDeclaration.name.originalKeywordKind === 121 /* ConstructorKeyword */; return !nameIsConstructor; } } @@ -8583,8 +8791,8 @@ var ts; function isReusableSwitchClause(node) { if (node) { switch (node.kind) { - case 239 /* CaseClause */: - case 240 /* DefaultClause */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: return true; } } @@ -8593,58 +8801,58 @@ var ts; function isReusableStatement(node) { if (node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: - case 191 /* VariableStatement */: - case 190 /* Block */: - case 194 /* IfStatement */: - case 193 /* ExpressionStatement */: - case 206 /* ThrowStatement */: - case 202 /* ReturnStatement */: - case 204 /* SwitchStatement */: - case 201 /* BreakStatement */: - case 200 /* ContinueStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 197 /* ForStatement */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 192 /* EmptyStatement */: - case 207 /* TryStatement */: - case 205 /* LabeledStatement */: - case 195 /* DoStatement */: - case 208 /* DebuggerStatement */: - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 226 /* ExportDeclaration */: - case 225 /* ExportAssignment */: - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 214 /* TypeAliasDeclaration */: + case 213 /* FunctionDeclaration */: + case 193 /* VariableStatement */: + case 192 /* Block */: + case 196 /* IfStatement */: + case 195 /* ExpressionStatement */: + case 208 /* ThrowStatement */: + case 204 /* ReturnStatement */: + case 206 /* SwitchStatement */: + case 203 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 199 /* ForStatement */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 194 /* EmptyStatement */: + case 209 /* TryStatement */: + case 207 /* LabeledStatement */: + case 197 /* DoStatement */: + case 210 /* DebuggerStatement */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 228 /* ExportDeclaration */: + case 227 /* ExportAssignment */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 216 /* TypeAliasDeclaration */: return true; } } return false; } function isReusableEnumMember(node) { - return node.kind === 245 /* EnumMember */; + return node.kind === 247 /* EnumMember */; } function isReusableTypeMember(node) { if (node) { switch (node.kind) { - case 146 /* ConstructSignature */: - case 140 /* MethodSignature */: - case 147 /* IndexSignature */: - case 138 /* PropertySignature */: - case 145 /* CallSignature */: + case 148 /* ConstructSignature */: + case 142 /* MethodSignature */: + case 149 /* IndexSignature */: + case 140 /* PropertySignature */: + case 147 /* CallSignature */: return true; } } return false; } function isReusableVariableDeclaration(node) { - if (node.kind !== 209 /* VariableDeclaration */) { + if (node.kind !== 211 /* VariableDeclaration */) { return false; } // Very subtle incremental parsing bug. Consider the following code: @@ -8665,7 +8873,7 @@ var ts; return variableDeclarator.initializer === undefined; } function isReusableParameter(node) { - if (node.kind !== 136 /* Parameter */) { + if (node.kind !== 138 /* Parameter */) { return false; } // See the comment in isReusableVariableDeclaration for why we do this. @@ -8782,7 +8990,7 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var entity = parseIdentifier(diagnosticMessage); while (parseOptional(21 /* DotToken */)) { - var node = createNode(133 /* QualifiedName */, entity.pos); + var node = createNode(135 /* QualifiedName */, entity.pos); node.left = entity; node.right = parseRightSideOfDot(allowReservedWords); entity = finishNode(node); @@ -8815,13 +9023,13 @@ var ts; // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually // be an identifier and the error would be quite confusing. - return createMissingNode(67 /* Identifier */, /*reportAtCurrentToken*/ true, ts.Diagnostics.Identifier_expected); + return createMissingNode(69 /* Identifier */, /*reportAtCurrentToken*/ true, ts.Diagnostics.Identifier_expected); } } return allowIdentifierNames ? parseIdentifierName() : parseIdentifier(); } function parseTemplateExpression() { - var template = createNode(181 /* TemplateExpression */); + var template = createNode(183 /* TemplateExpression */); template.head = parseLiteralNode(); ts.Debug.assert(template.head.kind === 12 /* TemplateHead */, "Template head has wrong token kind"); var templateSpans = []; @@ -8834,7 +9042,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(188 /* TemplateSpan */); + var span = createNode(190 /* TemplateSpan */); span.expression = allowInAnd(parseExpression); var literal; if (token === 16 /* CloseBraceToken */) { @@ -8876,14 +9084,14 @@ var ts; // TYPES function parseTypeReferenceOrTypePredicate() { var typeName = parseEntityName(/*allowReservedWords*/ false, ts.Diagnostics.Type_expected); - if (typeName.kind === 67 /* Identifier */ && token === 122 /* IsKeyword */ && !scanner.hasPrecedingLineBreak()) { + if (typeName.kind === 69 /* Identifier */ && token === 124 /* IsKeyword */ && !scanner.hasPrecedingLineBreak()) { nextToken(); - var node_1 = createNode(148 /* TypePredicate */, typeName.pos); + var node_1 = createNode(150 /* TypePredicate */, typeName.pos); node_1.parameterName = typeName; node_1.type = parseType(); return finishNode(node_1); } - var node = createNode(149 /* TypeReference */, typeName.pos); + var node = createNode(151 /* TypeReference */, typeName.pos); node.typeName = typeName; if (!scanner.hasPrecedingLineBreak() && token === 25 /* LessThanToken */) { node.typeArguments = parseBracketedList(18 /* TypeArguments */, parseType, 25 /* LessThanToken */, 27 /* GreaterThanToken */); @@ -8891,15 +9099,15 @@ var ts; return finishNode(node); } function parseTypeQuery() { - var node = createNode(152 /* TypeQuery */); - parseExpected(99 /* TypeOfKeyword */); + var node = createNode(154 /* TypeQuery */); + parseExpected(101 /* TypeOfKeyword */); node.exprName = parseEntityName(/*allowReservedWords*/ true); return finishNode(node); } function parseTypeParameter() { - var node = createNode(135 /* TypeParameter */); + var node = createNode(137 /* TypeParameter */); node.name = parseIdentifier(); - if (parseOptional(81 /* ExtendsKeyword */)) { + if (parseOptional(83 /* ExtendsKeyword */)) { // It's not uncommon for people to write improper constraints to a generic. If the // user writes a constraint that is an expression and not an actual type, then parse // it out as an expression (so we can recover well), but report that a type is needed @@ -8926,7 +9134,7 @@ var ts; } } function parseParameterType() { - if (parseOptional(53 /* ColonToken */)) { + if (parseOptional(54 /* ColonToken */)) { return token === 9 /* StringLiteral */ ? parseLiteralNode(/*internName*/ true) : parseType(); @@ -8934,7 +9142,7 @@ var ts; return undefined; } function isStartOfParameter() { - return token === 22 /* DotDotDotToken */ || isIdentifierOrPattern() || ts.isModifier(token) || token === 54 /* AtToken */; + return token === 22 /* DotDotDotToken */ || isIdentifierOrPattern() || ts.isModifier(token) || token === 55 /* AtToken */; } function setModifiers(node, modifiers) { if (modifiers) { @@ -8943,7 +9151,7 @@ var ts; } } function parseParameter() { - var node = createNode(136 /* Parameter */); + var node = createNode(138 /* Parameter */); node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(22 /* DotDotDotToken */); @@ -8961,7 +9169,7 @@ var ts; // to avoid this we'll advance cursor to the next token. nextToken(); } - node.questionToken = parseOptionalToken(52 /* QuestionToken */); + node.questionToken = parseOptionalToken(53 /* QuestionToken */); node.type = parseParameterType(); node.initializer = parseBindingElementInitializer(/*inParameter*/ true); // Do not check for initializers in an ambient context for parameters. This is not @@ -9037,10 +9245,10 @@ var ts; } function parseSignatureMember(kind) { var node = createNode(kind); - if (kind === 146 /* ConstructSignature */) { - parseExpected(90 /* NewKeyword */); + if (kind === 148 /* ConstructSignature */) { + parseExpected(92 /* NewKeyword */); } - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); parseTypeMemberSemicolon(); return finishNode(node); } @@ -9087,21 +9295,21 @@ var ts; // A colon signifies a well formed indexer // A comma should be a badly formed indexer because comma expressions are not allowed // in computed properties. - if (token === 53 /* ColonToken */ || token === 24 /* CommaToken */) { + if (token === 54 /* ColonToken */ || token === 24 /* CommaToken */) { return true; } // Question mark could be an indexer with an optional property, // or it could be a conditional expression in a computed property. - if (token !== 52 /* QuestionToken */) { + if (token !== 53 /* QuestionToken */) { return false; } // If any of the following tokens are after the question mark, it cannot // be a conditional expression, so treat it as an indexer. nextToken(); - return token === 53 /* ColonToken */ || token === 24 /* CommaToken */ || token === 20 /* CloseBracketToken */; + return token === 54 /* ColonToken */ || token === 24 /* CommaToken */ || token === 20 /* CloseBracketToken */; } function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) { - var node = createNode(147 /* IndexSignature */, fullStart); + var node = createNode(149 /* IndexSignature */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(16 /* Parameters */, parseParameter, 19 /* OpenBracketToken */, 20 /* CloseBracketToken */); @@ -9112,19 +9320,19 @@ var ts; function parsePropertyOrMethodSignature() { var fullStart = scanner.getStartPos(); var name = parsePropertyName(); - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) { - var method = createNode(140 /* MethodSignature */, fullStart); + var method = createNode(142 /* MethodSignature */, fullStart); method.name = name; method.questionToken = questionToken; // Method signatues don't exist in expression contexts. So they have neither // [Yield] nor [Await] - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method); parseTypeMemberSemicolon(); return finishNode(method); } else { - var property = createNode(138 /* PropertySignature */, fullStart); + var property = createNode(140 /* PropertySignature */, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -9158,23 +9366,23 @@ var ts; nextToken(); return token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */ || - token === 52 /* QuestionToken */ || - token === 53 /* ColonToken */ || + token === 53 /* QuestionToken */ || + token === 54 /* ColonToken */ || canParseSemicolon(); } function parseTypeMember() { switch (token) { case 17 /* OpenParenToken */: case 25 /* LessThanToken */: - return parseSignatureMember(145 /* CallSignature */); + return parseSignatureMember(147 /* CallSignature */); case 19 /* OpenBracketToken */: // Indexer or computed property return isIndexSignature() ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined) : parsePropertyOrMethodSignature(); - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(146 /* ConstructSignature */); + return parseSignatureMember(148 /* ConstructSignature */); } // fall through. case 9 /* StringLiteral */: @@ -9211,7 +9419,7 @@ var ts; return token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */; } function parseTypeLiteral() { - var node = createNode(153 /* TypeLiteral */); + var node = createNode(155 /* TypeLiteral */); node.members = parseObjectTypeMembers(); return finishNode(node); } @@ -9227,12 +9435,12 @@ var ts; return members; } function parseTupleType() { - var node = createNode(155 /* TupleType */); + var node = createNode(157 /* TupleType */); node.elementTypes = parseBracketedList(19 /* TupleElementTypes */, parseType, 19 /* OpenBracketToken */, 20 /* CloseBracketToken */); return finishNode(node); } function parseParenthesizedType() { - var node = createNode(158 /* ParenthesizedType */); + var node = createNode(160 /* ParenthesizedType */); parseExpected(17 /* OpenParenToken */); node.type = parseType(); parseExpected(18 /* CloseParenToken */); @@ -9240,8 +9448,8 @@ var ts; } function parseFunctionOrConstructorType(kind) { var node = createNode(kind); - if (kind === 151 /* ConstructorType */) { - parseExpected(90 /* NewKeyword */); + if (kind === 153 /* ConstructorType */) { + parseExpected(92 /* NewKeyword */); } fillSignature(34 /* EqualsGreaterThanToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); return finishNode(node); @@ -9252,17 +9460,18 @@ var ts; } function parseNonArrayType() { switch (token) { - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: // If these are followed by a dot, then parse these out as a dotted type reference instead. var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReferenceOrTypePredicate(); - case 101 /* VoidKeyword */: + case 103 /* VoidKeyword */: + case 97 /* ThisKeyword */: return parseTokenNode(); - case 99 /* TypeOfKeyword */: + case 101 /* TypeOfKeyword */: return parseTypeQuery(); case 15 /* OpenBraceToken */: return parseTypeLiteral(); @@ -9276,17 +9485,18 @@ var ts; } function isStartOfType() { switch (token) { - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: - case 101 /* VoidKeyword */: - case 99 /* TypeOfKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: + case 97 /* ThisKeyword */: + case 101 /* TypeOfKeyword */: case 15 /* OpenBraceToken */: case 19 /* OpenBracketToken */: case 25 /* LessThanToken */: - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: return true; case 17 /* OpenParenToken */: // Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier, @@ -9304,7 +9514,7 @@ var ts; var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(19 /* OpenBracketToken */)) { parseExpected(20 /* CloseBracketToken */); - var node = createNode(154 /* ArrayType */, type.pos); + var node = createNode(156 /* ArrayType */, type.pos); node.elementType = type; type = finishNode(node); } @@ -9326,10 +9536,10 @@ var ts; return type; } function parseIntersectionTypeOrHigher() { - return parseUnionOrIntersectionType(157 /* IntersectionType */, parseArrayTypeOrHigher, 45 /* AmpersandToken */); + return parseUnionOrIntersectionType(159 /* IntersectionType */, parseArrayTypeOrHigher, 46 /* AmpersandToken */); } function parseUnionTypeOrHigher() { - return parseUnionOrIntersectionType(156 /* UnionType */, parseIntersectionTypeOrHigher, 46 /* BarToken */); + return parseUnionOrIntersectionType(158 /* UnionType */, parseIntersectionTypeOrHigher, 47 /* BarToken */); } function isStartOfFunctionType() { if (token === 25 /* LessThanToken */) { @@ -9346,8 +9556,8 @@ var ts; } if (isIdentifier() || ts.isModifier(token)) { nextToken(); - if (token === 53 /* ColonToken */ || token === 24 /* CommaToken */ || - token === 52 /* QuestionToken */ || token === 55 /* EqualsToken */ || + if (token === 54 /* ColonToken */ || token === 24 /* CommaToken */ || + token === 53 /* QuestionToken */ || token === 56 /* EqualsToken */ || isIdentifier() || ts.isModifier(token)) { // ( id : // ( id , @@ -9373,24 +9583,24 @@ var ts; } function parseTypeWorker() { if (isStartOfFunctionType()) { - return parseFunctionOrConstructorType(150 /* FunctionType */); + return parseFunctionOrConstructorType(152 /* FunctionType */); } - if (token === 90 /* NewKeyword */) { - return parseFunctionOrConstructorType(151 /* ConstructorType */); + if (token === 92 /* NewKeyword */) { + return parseFunctionOrConstructorType(153 /* ConstructorType */); } return parseUnionTypeOrHigher(); } function parseTypeAnnotation() { - return parseOptional(53 /* ColonToken */) ? parseType() : undefined; + return parseOptional(54 /* ColonToken */) ? parseType() : undefined; } // EXPRESSIONS function isStartOfLeftHandSideExpression() { switch (token) { - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - case 91 /* NullKeyword */: - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: + case 93 /* NullKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: case 8 /* NumericLiteral */: case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: @@ -9398,12 +9608,12 @@ var ts; case 17 /* OpenParenToken */: case 19 /* OpenBracketToken */: case 15 /* OpenBraceToken */: - case 85 /* FunctionKeyword */: - case 71 /* ClassKeyword */: - case 90 /* NewKeyword */: - case 38 /* SlashToken */: - case 59 /* SlashEqualsToken */: - case 67 /* Identifier */: + case 87 /* FunctionKeyword */: + case 73 /* ClassKeyword */: + case 92 /* NewKeyword */: + case 39 /* SlashToken */: + case 61 /* SlashEqualsToken */: + case 69 /* Identifier */: return true; default: return isIdentifier(); @@ -9416,16 +9626,16 @@ var ts; switch (token) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: - case 48 /* ExclamationToken */: - case 76 /* DeleteKeyword */: - case 99 /* TypeOfKeyword */: - case 101 /* VoidKeyword */: - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: + case 78 /* DeleteKeyword */: + case 101 /* TypeOfKeyword */: + case 103 /* VoidKeyword */: + case 41 /* PlusPlusToken */: + case 42 /* MinusMinusToken */: case 25 /* LessThanToken */: - case 117 /* AwaitKeyword */: - case 112 /* YieldKeyword */: + case 119 /* AwaitKeyword */: + case 114 /* YieldKeyword */: // Yield/await always starts an expression. Either it is an identifier (in which case // it is definitely an expression). Or it's a keyword (either because we're in // a generator or async function, or in strict mode (or both)) and it started a yield or await expression. @@ -9444,9 +9654,9 @@ var ts; function isStartOfExpressionStatement() { // As per the grammar, none of '{' or 'function' or 'class' can start an expression statement. return token !== 15 /* OpenBraceToken */ && - token !== 85 /* FunctionKeyword */ && - token !== 71 /* ClassKeyword */ && - token !== 54 /* AtToken */ && + token !== 87 /* FunctionKeyword */ && + token !== 73 /* ClassKeyword */ && + token !== 55 /* AtToken */ && isStartOfExpression(); } function allowInAndParseExpression() { @@ -9472,7 +9682,7 @@ var ts; return expr; } function parseInitializer(inParameter) { - if (token !== 55 /* EqualsToken */) { + if (token !== 56 /* EqualsToken */) { // It's not uncommon during typing for the user to miss writing the '=' token. Check if // there is no newline after the last token and if we're on an expression. If so, parse // this as an equals-value clause with a missing equals. @@ -9489,7 +9699,7 @@ var ts; } // Initializer[In, Yield] : // = AssignmentExpression[?In, ?Yield] - parseExpected(55 /* EqualsToken */); + parseExpected(56 /* EqualsToken */); return parseAssignmentExpressionOrHigher(); } function parseAssignmentExpressionOrHigher() { @@ -9527,7 +9737,7 @@ var ts; // To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single // identifier and the current token is an arrow. - if (expr.kind === 67 /* Identifier */ && token === 34 /* EqualsGreaterThanToken */) { + if (expr.kind === 69 /* Identifier */ && token === 34 /* EqualsGreaterThanToken */) { return parseSimpleArrowFunctionExpression(expr); } // Now see if we might be in cases '2' or '3'. @@ -9543,7 +9753,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 112 /* YieldKeyword */) { + if (token === 114 /* YieldKeyword */) { // If we have a 'yield' keyword, and htis is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { @@ -9572,7 +9782,7 @@ var ts; return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression() { - var node = createNode(182 /* YieldExpression */); + var node = createNode(184 /* YieldExpression */); // YieldExpression[In] : // yield // yield [no LineTerminator here] [Lexical goal InputElementRegExp]AssignmentExpression[?In, Yield] @@ -9592,8 +9802,8 @@ var ts; } function parseSimpleArrowFunctionExpression(identifier) { ts.Debug.assert(token === 34 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - var node = createNode(172 /* ArrowFunction */, identifier.pos); - var parameter = createNode(136 /* Parameter */, identifier.pos); + var node = createNode(174 /* ArrowFunction */, identifier.pos); + var parameter = createNode(138 /* Parameter */, identifier.pos); parameter.name = identifier; finishNode(parameter); node.parameters = [parameter]; @@ -9635,7 +9845,7 @@ var ts; // Unknown -> There *might* be a parenthesized arrow function here. // Speculatively look ahead to be sure, and rollback if not. function isParenthesizedArrowFunctionExpression() { - if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */ || token === 116 /* AsyncKeyword */) { + if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */ || token === 118 /* AsyncKeyword */) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } if (token === 34 /* EqualsGreaterThanToken */) { @@ -9648,7 +9858,7 @@ var ts; return 0 /* False */; } function isParenthesizedArrowFunctionExpressionWorker() { - if (token === 116 /* AsyncKeyword */) { + if (token === 118 /* AsyncKeyword */) { nextToken(); if (scanner.hasPrecedingLineBreak()) { return 0 /* False */; @@ -9668,7 +9878,7 @@ var ts; var third = nextToken(); switch (third) { case 34 /* EqualsGreaterThanToken */: - case 53 /* ColonToken */: + case 54 /* ColonToken */: case 15 /* OpenBraceToken */: return 1 /* True */; default: @@ -9699,7 +9909,7 @@ var ts; } // If we have something like "(a:", then we must have a // type-annotated parameter in an arrow function expression. - if (nextToken() === 53 /* ColonToken */) { + if (nextToken() === 54 /* ColonToken */) { return 1 /* True */; } // This *could* be a parenthesized arrow function. @@ -9717,10 +9927,10 @@ var ts; if (sourceFile.languageVariant === 1 /* JSX */) { var isArrowFunctionInJsx = lookAhead(function () { var third = nextToken(); - if (third === 81 /* ExtendsKeyword */) { + if (third === 83 /* ExtendsKeyword */) { var fourth = nextToken(); switch (fourth) { - case 55 /* EqualsToken */: + case 56 /* EqualsToken */: case 27 /* GreaterThanToken */: return false; default: @@ -9745,7 +9955,7 @@ var ts; return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false); } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) { - var node = createNode(172 /* ArrowFunction */); + var node = createNode(174 /* ArrowFunction */); setModifiers(node, parseModifiersForArrowFunction()); var isAsync = !!(node.flags & 512 /* Async */); // Arrow functions are never generators. @@ -9755,7 +9965,7 @@ var ts; // a => (b => c) // And think that "(b =>" was actually a parenthesized arrow function with a missing // close paren. - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node); // If we couldn't get parameters, we definitely could not parse out an arrow function. if (!node.parameters) { return undefined; @@ -9779,8 +9989,8 @@ var ts; return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); } if (token !== 23 /* SemicolonToken */ && - token !== 85 /* FunctionKeyword */ && - token !== 71 /* ClassKeyword */ && + token !== 87 /* FunctionKeyword */ && + token !== 73 /* ClassKeyword */ && isStartOfStatement() && !isStartOfExpressionStatement()) { // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) @@ -9805,17 +10015,17 @@ var ts; } function parseConditionalExpressionRest(leftOperand) { // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher. - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (!questionToken) { return leftOperand; } // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and // we do not that for the 'whenFalse' part. - var node = createNode(180 /* ConditionalExpression */, leftOperand.pos); + var node = createNode(182 /* ConditionalExpression */, leftOperand.pos); node.condition = leftOperand; node.questionToken = questionToken; node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); - node.colonToken = parseExpectedToken(53 /* ColonToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(53 /* ColonToken */)); + node.colonToken = parseExpectedToken(54 /* ColonToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(54 /* ColonToken */)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -9824,7 +10034,7 @@ var ts; return parseBinaryExpressionRest(precedence, leftOperand); } function isInOrOfKeyword(t) { - return t === 88 /* InKeyword */ || t === 132 /* OfKeyword */; + return t === 90 /* InKeyword */ || t === 134 /* OfKeyword */; } function parseBinaryExpressionRest(precedence, leftOperand) { while (true) { @@ -9833,13 +10043,36 @@ var ts; reScanGreaterToken(); var newPrecedence = getBinaryOperatorPrecedence(); // Check the precedence to see if we should "take" this operator - if (newPrecedence <= precedence) { + // - For left associative operator (all operator but **), consume the operator, + // recursively call the function below, and parse binaryExpression as a rightOperand + // of the caller if the new precendence of the operator is greater then or equal to the current precendence. + // For example: + // a - b - c; + // ^token; leftOperand = b. Return b to the caller as a rightOperand + // a * b - c + // ^token; leftOperand = b. Return b to the caller as a rightOperand + // a - b * c; + // ^token; leftOperand = b. Return b * c to the caller as a rightOperand + // - For right associative operator (**), consume the operator, recursively call the function + // and parse binaryExpression as a rightOperand of the caller if the new precendence of + // the operator is strictly grater than the current precendence + // For example: + // a ** b ** c; + // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand + // a - b ** c; + // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand + // a ** b - c + // ^token; leftOperand = b. Return b to the caller as a rightOperand + var consumeCurrentOperator = token === 38 /* AsteriskAsteriskToken */ ? + newPrecedence >= precedence : + newPrecedence > precedence; + if (!consumeCurrentOperator) { break; } - if (token === 88 /* InKeyword */ && inDisallowInContext()) { + if (token === 90 /* InKeyword */ && inDisallowInContext()) { break; } - if (token === 114 /* AsKeyword */) { + if (token === 116 /* AsKeyword */) { // Make sure we *do* perform ASI for constructs like this: // var x = foo // as (Bar) @@ -9860,22 +10093,22 @@ var ts; return leftOperand; } function isBinaryOperator() { - if (inDisallowInContext() && token === 88 /* InKeyword */) { + if (inDisallowInContext() && token === 90 /* InKeyword */) { return false; } return getBinaryOperatorPrecedence() > 0; } function getBinaryOperatorPrecedence() { switch (token) { - case 51 /* BarBarToken */: + case 52 /* BarBarToken */: return 1; - case 50 /* AmpersandAmpersandToken */: + case 51 /* AmpersandAmpersandToken */: return 2; - case 46 /* BarToken */: + case 47 /* BarToken */: return 3; - case 47 /* CaretToken */: + case 48 /* CaretToken */: return 4; - case 45 /* AmpersandToken */: + case 46 /* AmpersandToken */: return 5; case 30 /* EqualsEqualsToken */: case 31 /* ExclamationEqualsToken */: @@ -9886,66 +10119,68 @@ var ts; case 27 /* GreaterThanToken */: case 28 /* LessThanEqualsToken */: case 29 /* GreaterThanEqualsToken */: - case 89 /* InstanceOfKeyword */: - case 88 /* InKeyword */: - case 114 /* AsKeyword */: + case 91 /* InstanceOfKeyword */: + case 90 /* InKeyword */: + case 116 /* AsKeyword */: return 7; - case 42 /* LessThanLessThanToken */: - case 43 /* GreaterThanGreaterThanToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: + case 43 /* LessThanLessThanToken */: + case 44 /* GreaterThanGreaterThanToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: return 8; case 35 /* PlusToken */: case 36 /* MinusToken */: return 9; case 37 /* AsteriskToken */: - case 38 /* SlashToken */: - case 39 /* PercentToken */: + case 39 /* SlashToken */: + case 40 /* PercentToken */: return 10; + case 38 /* AsteriskAsteriskToken */: + return 11; } // -1 is lower than all other precedences. Returning it will cause binary expression // parsing to stop. return -1; } function makeBinaryExpression(left, operatorToken, right) { - var node = createNode(179 /* BinaryExpression */, left.pos); + var node = createNode(181 /* BinaryExpression */, left.pos); node.left = left; node.operatorToken = operatorToken; node.right = right; return finishNode(node); } function makeAsExpression(left, right) { - var node = createNode(187 /* AsExpression */, left.pos); + var node = createNode(189 /* AsExpression */, left.pos); node.expression = left; node.type = right; return finishNode(node); } function parsePrefixUnaryExpression() { - var node = createNode(177 /* PrefixUnaryExpression */); + var node = createNode(179 /* PrefixUnaryExpression */); node.operator = token; nextToken(); - node.operand = parseUnaryExpressionOrHigher(); + node.operand = parseSimpleUnaryExpression(); return finishNode(node); } function parseDeleteExpression() { - var node = createNode(173 /* DeleteExpression */); + var node = createNode(175 /* DeleteExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseTypeOfExpression() { - var node = createNode(174 /* TypeOfExpression */); + var node = createNode(176 /* TypeOfExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseVoidExpression() { - var node = createNode(175 /* VoidExpression */); + var node = createNode(177 /* VoidExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function isAwaitExpression() { - if (token === 117 /* AwaitKeyword */) { + if (token === 119 /* AwaitKeyword */) { if (inAwaitContext()) { return true; } @@ -9955,46 +10190,137 @@ var ts; return false; } function parseAwaitExpression() { - var node = createNode(176 /* AwaitExpression */); + var node = createNode(178 /* AwaitExpression */); nextToken(); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } + /** + * Parse ES7 unary expression and await expression + * + * ES7 UnaryExpression: + * 1) SimpleUnaryExpression[?yield] + * 2) IncrementExpression[?yield] ** UnaryExpression[?yield] + */ function parseUnaryExpressionOrHigher() { if (isAwaitExpression()) { return parseAwaitExpression(); } + if (isIncrementExpression()) { + var incrementExpression = parseIncrementExpression(); + return token === 38 /* AsteriskAsteriskToken */ ? + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : + incrementExpression; + } + var unaryOperator = token; + var simpleUnaryExpression = parseSimpleUnaryExpression(); + if (token === 38 /* AsteriskAsteriskToken */) { + var diagnostic; + var start = ts.skipTrivia(sourceText, simpleUnaryExpression.pos); + if (simpleUnaryExpression.kind === 171 /* TypeAssertionExpression */) { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses); + } + else { + parseErrorAtPosition(start, simpleUnaryExpression.end - start, ts.Diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses, ts.tokenToString(unaryOperator)); + } + } + return simpleUnaryExpression; + } + /** + * Parse ES7 simple-unary expression or higher: + * + * ES7 SimpleUnaryExpression: + * 1) IncrementExpression[?yield] + * 2) delete UnaryExpression[?yield] + * 3) void UnaryExpression[?yield] + * 4) typeof UnaryExpression[?yield] + * 5) + UnaryExpression[?yield] + * 6) - UnaryExpression[?yield] + * 7) ~ UnaryExpression[?yield] + * 8) ! UnaryExpression[?yield] + */ + function parseSimpleUnaryExpression() { switch (token) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: - case 48 /* ExclamationToken */: - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: return parsePrefixUnaryExpression(); - case 76 /* DeleteKeyword */: + case 78 /* DeleteKeyword */: return parseDeleteExpression(); - case 99 /* TypeOfKeyword */: + case 101 /* TypeOfKeyword */: return parseTypeOfExpression(); - case 101 /* VoidKeyword */: + case 103 /* VoidKeyword */: return parseVoidExpression(); case 25 /* LessThanToken */: - if (sourceFile.languageVariant !== 1 /* JSX */) { - return parseTypeAssertion(); - } - if (lookAhead(nextTokenIsIdentifierOrKeyword)) { - return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true); - } - // Fall through + // This is modified UnaryExpression grammar in TypeScript + // UnaryExpression (modified): + // < type > UnaryExpression + return parseTypeAssertion(); default: - return parsePostfixExpressionOrHigher(); + return parseIncrementExpression(); } } - function parsePostfixExpressionOrHigher() { + /** + * Check if the current token can possibly be an ES7 increment expression. + * + * ES7 IncrementExpression: + * LeftHandSideExpression[?Yield] + * LeftHandSideExpression[?Yield][no LineTerminator here]++ + * LeftHandSideExpression[?Yield][no LineTerminator here]-- + * ++LeftHandSideExpression[?Yield] + * --LeftHandSideExpression[?Yield] + */ + function isIncrementExpression() { + // This function is called inside parseUnaryExpression to decide + // whether to call parseSimpleUnaryExpression or call parseIncrmentExpression directly + switch (token) { + case 35 /* PlusToken */: + case 36 /* MinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: + case 78 /* DeleteKeyword */: + case 101 /* TypeOfKeyword */: + case 103 /* VoidKeyword */: + return false; + case 25 /* LessThanToken */: + // If we are not in JSX context, we are parsing TypeAssertion which is an UnaryExpression + if (sourceFile.languageVariant !== 1 /* JSX */) { + return false; + } + // We are in JSX context and the token is part of JSXElement. + // Fall through + default: + return true; + } + } + /** + * Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression. + * + * ES7 IncrementExpression[yield]: + * 1) LeftHandSideExpression[?yield] + * 2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++ + * 3) LeftHandSideExpression[?yield] [[no LineTerminator here]]-- + * 4) ++LeftHandSideExpression[?yield] + * 5) --LeftHandSideExpression[?yield] + * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression + */ + function parseIncrementExpression() { + if (token === 41 /* PlusPlusToken */ || token === 42 /* MinusMinusToken */) { + var node = createNode(179 /* PrefixUnaryExpression */); + node.operator = token; + nextToken(); + node.operand = parseLeftHandSideExpressionOrHigher(); + return finishNode(node); + } + else if (sourceFile.languageVariant === 1 /* JSX */ && token === 25 /* LessThanToken */ && lookAhead(nextTokenIsIdentifierOrKeyword)) { + // JSXElement is part of primaryExpression + return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true); + } var expression = parseLeftHandSideExpressionOrHigher(); ts.Debug.assert(ts.isLeftHandSideExpression(expression)); - if ((token === 40 /* PlusPlusToken */ || token === 41 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) { - var node = createNode(178 /* PostfixUnaryExpression */, expression.pos); + if ((token === 41 /* PlusPlusToken */ || token === 42 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) { + var node = createNode(180 /* PostfixUnaryExpression */, expression.pos); node.operand = expression; node.operator = token; nextToken(); @@ -10033,7 +10359,7 @@ var ts; // the last two CallExpression productions. Or we have a MemberExpression which either // completes the LeftHandSideExpression, or starts the beginning of the first four // CallExpression productions. - var expression = token === 93 /* SuperKeyword */ + var expression = token === 95 /* SuperKeyword */ ? parseSuperExpression() : parseMemberExpressionOrHigher(); // Now, we *may* be complete. However, we might have consumed the start of a @@ -10098,7 +10424,7 @@ var ts; } // If we have seen "super" it must be followed by '(' or '.'. // If it wasn't then just try to parse out a '.' and report an error. - var node = createNode(164 /* PropertyAccessExpression */, expression.pos); + var node = createNode(166 /* PropertyAccessExpression */, expression.pos); node.expression = expression; node.dotToken = parseExpectedToken(21 /* DotToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); @@ -10106,27 +10432,27 @@ var ts; } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); - if (opening.kind === 233 /* JsxOpeningElement */) { - var node = createNode(231 /* JsxElement */, opening.pos); + if (opening.kind === 235 /* JsxOpeningElement */) { + var node = createNode(233 /* JsxElement */, opening.pos); node.openingElement = opening; node.children = parseJsxChildren(node.openingElement.tagName); node.closingElement = parseJsxClosingElement(inExpressionContext); return finishNode(node); } else { - ts.Debug.assert(opening.kind === 232 /* JsxSelfClosingElement */); + ts.Debug.assert(opening.kind === 234 /* JsxSelfClosingElement */); // Nothing else to do for self-closing elements return opening; } } function parseJsxText() { - var node = createNode(234 /* JsxText */, scanner.getStartPos()); + var node = createNode(236 /* JsxText */, scanner.getStartPos()); token = scanner.scanJsxToken(); return finishNode(node); } function parseJsxChild() { switch (token) { - case 234 /* JsxText */: + case 236 /* JsxText */: return parseJsxText(); case 15 /* OpenBraceToken */: return parseJsxExpression(/*inExpressionContext*/ false); @@ -10165,11 +10491,11 @@ var ts; // Closing tag, so scan the immediately-following text with the JSX scanning instead // of regular scanning to avoid treating illegal characters (e.g. '#') as immediate // scanning errors - node = createNode(233 /* JsxOpeningElement */, fullStart); + node = createNode(235 /* JsxOpeningElement */, fullStart); scanJsxText(); } else { - parseExpected(38 /* SlashToken */); + parseExpected(39 /* SlashToken */); if (inExpressionContext) { parseExpected(27 /* GreaterThanToken */); } @@ -10177,7 +10503,7 @@ var ts; parseExpected(27 /* GreaterThanToken */, /*diagnostic*/ undefined, /*advance*/ false); scanJsxText(); } - node = createNode(232 /* JsxSelfClosingElement */, fullStart); + node = createNode(234 /* JsxSelfClosingElement */, fullStart); } node.tagName = tagName; node.attributes = attributes; @@ -10188,7 +10514,7 @@ var ts; var elementName = parseIdentifierName(); while (parseOptional(21 /* DotToken */)) { scanJsxIdentifier(); - var node = createNode(133 /* QualifiedName */, elementName.pos); + var node = createNode(135 /* QualifiedName */, elementName.pos); node.left = elementName; node.right = parseIdentifierName(); elementName = finishNode(node); @@ -10196,7 +10522,7 @@ var ts; return elementName; } function parseJsxExpression(inExpressionContext) { - var node = createNode(238 /* JsxExpression */); + var node = createNode(240 /* JsxExpression */); parseExpected(15 /* OpenBraceToken */); if (token !== 16 /* CloseBraceToken */) { node.expression = parseExpression(); @@ -10215,9 +10541,9 @@ var ts; return parseJsxSpreadAttribute(); } scanJsxIdentifier(); - var node = createNode(236 /* JsxAttribute */); + var node = createNode(238 /* JsxAttribute */); node.name = parseIdentifierName(); - if (parseOptional(55 /* EqualsToken */)) { + if (parseOptional(56 /* EqualsToken */)) { switch (token) { case 9 /* StringLiteral */: node.initializer = parseLiteralNode(); @@ -10230,7 +10556,7 @@ var ts; return finishNode(node); } function parseJsxSpreadAttribute() { - var node = createNode(237 /* JsxSpreadAttribute */); + var node = createNode(239 /* JsxSpreadAttribute */); parseExpected(15 /* OpenBraceToken */); parseExpected(22 /* DotDotDotToken */); node.expression = parseExpression(); @@ -10238,7 +10564,7 @@ var ts; return finishNode(node); } function parseJsxClosingElement(inExpressionContext) { - var node = createNode(235 /* JsxClosingElement */); + var node = createNode(237 /* JsxClosingElement */); parseExpected(26 /* LessThanSlashToken */); node.tagName = parseJsxElementName(); if (inExpressionContext) { @@ -10251,18 +10577,18 @@ var ts; return finishNode(node); } function parseTypeAssertion() { - var node = createNode(169 /* TypeAssertionExpression */); + var node = createNode(171 /* TypeAssertionExpression */); parseExpected(25 /* LessThanToken */); node.type = parseType(); parseExpected(27 /* GreaterThanToken */); - node.expression = parseUnaryExpressionOrHigher(); + node.expression = parseSimpleUnaryExpression(); return finishNode(node); } function parseMemberExpressionRest(expression) { while (true) { var dotToken = parseOptionalToken(21 /* DotToken */); if (dotToken) { - var propertyAccess = createNode(164 /* PropertyAccessExpression */, expression.pos); + var propertyAccess = createNode(166 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); @@ -10271,7 +10597,7 @@ var ts; } // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName if (!inDecoratorContext() && parseOptional(19 /* OpenBracketToken */)) { - var indexedAccess = createNode(165 /* ElementAccessExpression */, expression.pos); + var indexedAccess = createNode(167 /* ElementAccessExpression */, expression.pos); indexedAccess.expression = expression; // It's not uncommon for a user to write: "new Type[]". // Check for that common pattern and report a better error message. @@ -10287,7 +10613,7 @@ var ts; continue; } if (token === 11 /* NoSubstitutionTemplateLiteral */ || token === 12 /* TemplateHead */) { - var tagExpression = createNode(168 /* TaggedTemplateExpression */, expression.pos); + var tagExpression = createNode(170 /* TaggedTemplateExpression */, expression.pos); tagExpression.tag = expression; tagExpression.template = token === 11 /* NoSubstitutionTemplateLiteral */ ? parseLiteralNode() @@ -10310,7 +10636,7 @@ var ts; if (!typeArguments) { return expression; } - var callExpr = createNode(166 /* CallExpression */, expression.pos); + var callExpr = createNode(168 /* CallExpression */, expression.pos); callExpr.expression = expression; callExpr.typeArguments = typeArguments; callExpr.arguments = parseArgumentList(); @@ -10318,7 +10644,7 @@ var ts; continue; } else if (token === 17 /* OpenParenToken */) { - var callExpr = createNode(166 /* CallExpression */, expression.pos); + var callExpr = createNode(168 /* CallExpression */, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); expression = finishNode(callExpr); @@ -10356,18 +10682,18 @@ var ts; case 21 /* DotToken */: // foo. case 18 /* CloseParenToken */: // foo) case 20 /* CloseBracketToken */: // foo] - case 53 /* ColonToken */: // foo: + case 54 /* ColonToken */: // foo: case 23 /* SemicolonToken */: // foo; - case 52 /* QuestionToken */: // foo? + case 53 /* QuestionToken */: // foo? case 30 /* EqualsEqualsToken */: // foo == case 32 /* EqualsEqualsEqualsToken */: // foo === case 31 /* ExclamationEqualsToken */: // foo != case 33 /* ExclamationEqualsEqualsToken */: // foo !== - case 50 /* AmpersandAmpersandToken */: // foo && - case 51 /* BarBarToken */: // foo || - case 47 /* CaretToken */: // foo ^ - case 45 /* AmpersandToken */: // foo & - case 46 /* BarToken */: // foo | + case 51 /* AmpersandAmpersandToken */: // foo && + case 52 /* BarBarToken */: // foo || + case 48 /* CaretToken */: // foo ^ + case 46 /* AmpersandToken */: // foo & + case 47 /* BarToken */: // foo | case 16 /* CloseBraceToken */: // foo } case 1 /* EndOfFileToken */: // these cases can't legally follow a type arg list. However, they're not legal @@ -10390,11 +10716,11 @@ var ts; case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: return parseLiteralNode(); - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - case 91 /* NullKeyword */: - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: + case 93 /* NullKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: return parseTokenNode(); case 17 /* OpenParenToken */: return parseParenthesizedExpression(); @@ -10402,7 +10728,7 @@ var ts; return parseArrayLiteralExpression(); case 15 /* OpenBraceToken */: return parseObjectLiteralExpression(); - case 116 /* AsyncKeyword */: + case 118 /* AsyncKeyword */: // Async arrow functions are parsed earlier in parseAssignmentExpressionOrHigher. // If we encounter `async [no LineTerminator here] function` then this is an async // function; otherwise, its an identifier. @@ -10410,14 +10736,14 @@ var ts; break; } return parseFunctionExpression(); - case 71 /* ClassKeyword */: + case 73 /* ClassKeyword */: return parseClassExpression(); - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseFunctionExpression(); - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: return parseNewExpression(); - case 38 /* SlashToken */: - case 59 /* SlashEqualsToken */: + case 39 /* SlashToken */: + case 61 /* SlashEqualsToken */: if (reScanSlashToken() === 10 /* RegularExpressionLiteral */) { return parseLiteralNode(); } @@ -10428,28 +10754,28 @@ var ts; return parseIdentifier(ts.Diagnostics.Expression_expected); } function parseParenthesizedExpression() { - var node = createNode(170 /* ParenthesizedExpression */); + var node = createNode(172 /* ParenthesizedExpression */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); return finishNode(node); } function parseSpreadElement() { - var node = createNode(183 /* SpreadElementExpression */); + var node = createNode(185 /* SpreadElementExpression */); parseExpected(22 /* DotDotDotToken */); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); } function parseArgumentOrArrayLiteralElement() { return token === 22 /* DotDotDotToken */ ? parseSpreadElement() : - token === 24 /* CommaToken */ ? createNode(185 /* OmittedExpression */) : + token === 24 /* CommaToken */ ? createNode(187 /* OmittedExpression */) : parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression() { - var node = createNode(162 /* ArrayLiteralExpression */); + var node = createNode(164 /* ArrayLiteralExpression */); parseExpected(19 /* OpenBracketToken */); if (scanner.hasPrecedingLineBreak()) node.flags |= 2048 /* MultiLine */; @@ -10458,11 +10784,11 @@ var ts; return finishNode(node); } function tryParseAccessorDeclaration(fullStart, decorators, modifiers) { - if (parseContextualModifier(121 /* GetKeyword */)) { - return parseAccessorDeclaration(143 /* GetAccessor */, fullStart, decorators, modifiers); + if (parseContextualModifier(123 /* GetKeyword */)) { + return parseAccessorDeclaration(145 /* GetAccessor */, fullStart, decorators, modifiers); } - else if (parseContextualModifier(127 /* SetKeyword */)) { - return parseAccessorDeclaration(144 /* SetAccessor */, fullStart, decorators, modifiers); + else if (parseContextualModifier(129 /* SetKeyword */)) { + return parseAccessorDeclaration(146 /* SetAccessor */, fullStart, decorators, modifiers); } return undefined; } @@ -10479,28 +10805,38 @@ var ts; var nameToken = token; var propertyName = parsePropertyName(); // Disallowing of optional property assignments happens in the grammar checker. - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (asteriskToken || token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } - // Parse to check if it is short-hand property assignment or normal property assignment - if ((token === 24 /* CommaToken */ || token === 16 /* CloseBraceToken */) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(244 /* ShorthandPropertyAssignment */, fullStart); + // check if it is short-hand property assignment or normal property assignment + // NOTE: if token is EqualsToken it is interpreted as CoverInitializedName production + // CoverInitializedName[Yield] : + // IdentifierReference[?Yield] Initializer[In, ?Yield] + // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern + var isShorthandPropertyAssignment = tokenIsIdentifier && (token === 24 /* CommaToken */ || token === 16 /* CloseBraceToken */ || token === 56 /* EqualsToken */); + if (isShorthandPropertyAssignment) { + var shorthandDeclaration = createNode(246 /* ShorthandPropertyAssignment */, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; + var equalsToken = parseOptionalToken(56 /* EqualsToken */); + if (equalsToken) { + shorthandDeclaration.equalsToken = equalsToken; + shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher); + } return finishNode(shorthandDeclaration); } else { - var propertyAssignment = createNode(243 /* PropertyAssignment */, fullStart); + var propertyAssignment = createNode(245 /* PropertyAssignment */, fullStart); propertyAssignment.name = propertyName; propertyAssignment.questionToken = questionToken; - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher); return finishNode(propertyAssignment); } } function parseObjectLiteralExpression() { - var node = createNode(163 /* ObjectLiteralExpression */); + var node = createNode(165 /* ObjectLiteralExpression */); parseExpected(15 /* OpenBraceToken */); if (scanner.hasPrecedingLineBreak()) { node.flags |= 2048 /* MultiLine */; @@ -10519,9 +10855,9 @@ var ts; if (saveDecoratorContext) { setDecoratorContext(false); } - var node = createNode(171 /* FunctionExpression */); + var node = createNode(173 /* FunctionExpression */); setModifiers(node, parseModifiers()); - parseExpected(85 /* FunctionKeyword */); + parseExpected(87 /* FunctionKeyword */); node.asteriskToken = parseOptionalToken(37 /* AsteriskToken */); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512 /* Async */); @@ -10530,7 +10866,7 @@ var ts; isGenerator ? doInYieldContext(parseOptionalIdentifier) : isAsync ? doInAwaitContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); if (saveDecoratorContext) { setDecoratorContext(true); @@ -10541,8 +10877,8 @@ var ts; return isIdentifier() ? parseIdentifier() : undefined; } function parseNewExpression() { - var node = createNode(167 /* NewExpression */); - parseExpected(90 /* NewKeyword */); + var node = createNode(169 /* NewExpression */); + parseExpected(92 /* NewKeyword */); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); if (node.typeArguments || token === 17 /* OpenParenToken */) { @@ -10552,7 +10888,7 @@ var ts; } // STATEMENTS function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) { - var node = createNode(190 /* Block */); + var node = createNode(192 /* Block */); if (parseExpected(15 /* OpenBraceToken */, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(1 /* BlockStatements */, parseStatement); parseExpected(16 /* CloseBraceToken */); @@ -10582,25 +10918,25 @@ var ts; return block; } function parseEmptyStatement() { - var node = createNode(192 /* EmptyStatement */); + var node = createNode(194 /* EmptyStatement */); parseExpected(23 /* SemicolonToken */); return finishNode(node); } function parseIfStatement() { - var node = createNode(194 /* IfStatement */); - parseExpected(86 /* IfKeyword */); + var node = createNode(196 /* IfStatement */); + parseExpected(88 /* IfKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); node.thenStatement = parseStatement(); - node.elseStatement = parseOptional(78 /* ElseKeyword */) ? parseStatement() : undefined; + node.elseStatement = parseOptional(80 /* ElseKeyword */) ? parseStatement() : undefined; return finishNode(node); } function parseDoStatement() { - var node = createNode(195 /* DoStatement */); - parseExpected(77 /* DoKeyword */); + var node = createNode(197 /* DoStatement */); + parseExpected(79 /* DoKeyword */); node.statement = parseStatement(); - parseExpected(102 /* WhileKeyword */); + parseExpected(104 /* WhileKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); @@ -10612,8 +10948,8 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(196 /* WhileStatement */); - parseExpected(102 /* WhileKeyword */); + var node = createNode(198 /* WhileStatement */); + parseExpected(104 /* WhileKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); @@ -10622,11 +10958,11 @@ var ts; } function parseForOrForInOrForOfStatement() { var pos = getNodePos(); - parseExpected(84 /* ForKeyword */); + parseExpected(86 /* ForKeyword */); parseExpected(17 /* OpenParenToken */); var initializer = undefined; if (token !== 23 /* SemicolonToken */) { - if (token === 100 /* VarKeyword */ || token === 106 /* LetKeyword */ || token === 72 /* ConstKeyword */) { + if (token === 102 /* VarKeyword */ || token === 108 /* LetKeyword */ || token === 74 /* ConstKeyword */) { initializer = parseVariableDeclarationList(/*inForStatementInitializer*/ true); } else { @@ -10634,22 +10970,22 @@ var ts; } } var forOrForInOrForOfStatement; - if (parseOptional(88 /* InKeyword */)) { - var forInStatement = createNode(198 /* ForInStatement */, pos); + if (parseOptional(90 /* InKeyword */)) { + var forInStatement = createNode(200 /* ForInStatement */, pos); forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); forOrForInOrForOfStatement = forInStatement; } - else if (parseOptional(132 /* OfKeyword */)) { - var forOfStatement = createNode(199 /* ForOfStatement */, pos); + else if (parseOptional(134 /* OfKeyword */)) { + var forOfStatement = createNode(201 /* ForOfStatement */, pos); forOfStatement.initializer = initializer; forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher); parseExpected(18 /* CloseParenToken */); forOrForInOrForOfStatement = forOfStatement; } else { - var forStatement = createNode(197 /* ForStatement */, pos); + var forStatement = createNode(199 /* ForStatement */, pos); forStatement.initializer = initializer; parseExpected(23 /* SemicolonToken */); if (token !== 23 /* SemicolonToken */ && token !== 18 /* CloseParenToken */) { @@ -10667,7 +11003,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 201 /* BreakStatement */ ? 68 /* BreakKeyword */ : 73 /* ContinueKeyword */); + parseExpected(kind === 203 /* BreakStatement */ ? 70 /* BreakKeyword */ : 75 /* ContinueKeyword */); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -10675,8 +11011,8 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(202 /* ReturnStatement */); - parseExpected(92 /* ReturnKeyword */); + var node = createNode(204 /* ReturnStatement */); + parseExpected(94 /* ReturnKeyword */); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); } @@ -10684,8 +11020,8 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(203 /* WithStatement */); - parseExpected(103 /* WithKeyword */); + var node = createNode(205 /* WithStatement */); + parseExpected(105 /* WithKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); @@ -10693,30 +11029,30 @@ var ts; return finishNode(node); } function parseCaseClause() { - var node = createNode(239 /* CaseClause */); - parseExpected(69 /* CaseKeyword */); + var node = createNode(241 /* CaseClause */); + parseExpected(71 /* CaseKeyword */); node.expression = allowInAnd(parseExpression); - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); node.statements = parseList(3 /* SwitchClauseStatements */, parseStatement); return finishNode(node); } function parseDefaultClause() { - var node = createNode(240 /* DefaultClause */); - parseExpected(75 /* DefaultKeyword */); - parseExpected(53 /* ColonToken */); + var node = createNode(242 /* DefaultClause */); + parseExpected(77 /* DefaultKeyword */); + parseExpected(54 /* ColonToken */); node.statements = parseList(3 /* SwitchClauseStatements */, parseStatement); return finishNode(node); } function parseCaseOrDefaultClause() { - return token === 69 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); + return token === 71 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(204 /* SwitchStatement */); - parseExpected(94 /* SwitchKeyword */); + var node = createNode(206 /* SwitchStatement */); + parseExpected(96 /* SwitchKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = allowInAnd(parseExpression); parseExpected(18 /* CloseParenToken */); - var caseBlock = createNode(218 /* CaseBlock */, scanner.getStartPos()); + var caseBlock = createNode(220 /* CaseBlock */, scanner.getStartPos()); parseExpected(15 /* OpenBraceToken */); caseBlock.clauses = parseList(2 /* SwitchClauses */, parseCaseOrDefaultClause); parseExpected(16 /* CloseBraceToken */); @@ -10731,29 +11067,29 @@ var ts; // directly as that might consume an expression on the following line. // We just return 'undefined' in that case. The actual error will be reported in the // grammar walker. - var node = createNode(206 /* ThrowStatement */); - parseExpected(96 /* ThrowKeyword */); + var node = createNode(208 /* ThrowStatement */); + parseExpected(98 /* ThrowKeyword */); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } // TODO: Review for error recovery function parseTryStatement() { - var node = createNode(207 /* TryStatement */); - parseExpected(98 /* TryKeyword */); + var node = createNode(209 /* TryStatement */); + parseExpected(100 /* TryKeyword */); node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); - node.catchClause = token === 70 /* CatchKeyword */ ? parseCatchClause() : undefined; + node.catchClause = token === 72 /* CatchKeyword */ ? parseCatchClause() : undefined; // If we don't have a catch clause, then we must have a finally clause. Try to parse // one out no matter what. - if (!node.catchClause || token === 83 /* FinallyKeyword */) { - parseExpected(83 /* FinallyKeyword */); + if (!node.catchClause || token === 85 /* FinallyKeyword */) { + parseExpected(85 /* FinallyKeyword */); node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); } return finishNode(node); } function parseCatchClause() { - var result = createNode(242 /* CatchClause */); - parseExpected(70 /* CatchKeyword */); + var result = createNode(244 /* CatchClause */); + parseExpected(72 /* CatchKeyword */); if (parseExpected(17 /* OpenParenToken */)) { result.variableDeclaration = parseVariableDeclaration(); } @@ -10762,8 +11098,8 @@ var ts; return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(208 /* DebuggerStatement */); - parseExpected(74 /* DebuggerKeyword */); + var node = createNode(210 /* DebuggerStatement */); + parseExpected(76 /* DebuggerKeyword */); parseSemicolon(); return finishNode(node); } @@ -10773,14 +11109,14 @@ var ts; // a colon. var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); - if (expression.kind === 67 /* Identifier */ && parseOptional(53 /* ColonToken */)) { - var labeledStatement = createNode(205 /* LabeledStatement */, fullStart); + if (expression.kind === 69 /* Identifier */ && parseOptional(54 /* ColonToken */)) { + var labeledStatement = createNode(207 /* LabeledStatement */, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(193 /* ExpressionStatement */, fullStart); + var expressionStatement = createNode(195 /* ExpressionStatement */, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); @@ -10792,7 +11128,7 @@ var ts; } function nextTokenIsFunctionKeywordOnSameLine() { nextToken(); - return token === 85 /* FunctionKeyword */ && !scanner.hasPrecedingLineBreak(); + return token === 87 /* FunctionKeyword */ && !scanner.hasPrecedingLineBreak(); } function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); @@ -10801,12 +11137,12 @@ var ts; function isDeclaration() { while (true) { switch (token) { - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: - case 85 /* FunctionKeyword */: - case 71 /* ClassKeyword */: - case 79 /* EnumKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: + case 87 /* FunctionKeyword */: + case 73 /* ClassKeyword */: + case 81 /* EnumKeyword */: return true; // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; // however, an identifier cannot be followed by another identifier on the same line. This is what we @@ -10829,36 +11165,36 @@ var ts; // I {} // // could be legal, it would add complexity for very little gain. - case 105 /* InterfaceKeyword */: - case 130 /* TypeKeyword */: + case 107 /* InterfaceKeyword */: + case 132 /* TypeKeyword */: return nextTokenIsIdentifierOnSameLine(); - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: return nextTokenIsIdentifierOrStringLiteralOnSameLine(); - case 116 /* AsyncKeyword */: - case 120 /* DeclareKeyword */: + case 115 /* AbstractKeyword */: + case 118 /* AsyncKeyword */: + case 122 /* DeclareKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 112 /* PublicKeyword */: nextToken(); // ASI takes effect for this modifier. if (scanner.hasPrecedingLineBreak()) { return false; } continue; - case 87 /* ImportKeyword */: + case 89 /* ImportKeyword */: nextToken(); return token === 9 /* StringLiteral */ || token === 37 /* AsteriskToken */ || token === 15 /* OpenBraceToken */ || ts.tokenIsIdentifierOrKeyword(token); - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: nextToken(); - if (token === 55 /* EqualsToken */ || token === 37 /* AsteriskToken */ || - token === 15 /* OpenBraceToken */ || token === 75 /* DefaultKeyword */) { + if (token === 56 /* EqualsToken */ || token === 37 /* AsteriskToken */ || + token === 15 /* OpenBraceToken */ || token === 77 /* DefaultKeyword */) { return true; } continue; - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: - case 113 /* AbstractKeyword */: + case 113 /* StaticKeyword */: nextToken(); continue; default: @@ -10871,47 +11207,47 @@ var ts; } function isStartOfStatement() { switch (token) { - case 54 /* AtToken */: + case 55 /* AtToken */: case 23 /* SemicolonToken */: case 15 /* OpenBraceToken */: - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 85 /* FunctionKeyword */: - case 71 /* ClassKeyword */: - case 79 /* EnumKeyword */: - case 86 /* IfKeyword */: - case 77 /* DoKeyword */: - case 102 /* WhileKeyword */: - case 84 /* ForKeyword */: - case 73 /* ContinueKeyword */: - case 68 /* BreakKeyword */: - case 92 /* ReturnKeyword */: - case 103 /* WithKeyword */: - case 94 /* SwitchKeyword */: - case 96 /* ThrowKeyword */: - case 98 /* TryKeyword */: - case 74 /* DebuggerKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 87 /* FunctionKeyword */: + case 73 /* ClassKeyword */: + case 81 /* EnumKeyword */: + case 88 /* IfKeyword */: + case 79 /* DoKeyword */: + case 104 /* WhileKeyword */: + case 86 /* ForKeyword */: + case 75 /* ContinueKeyword */: + case 70 /* BreakKeyword */: + case 94 /* ReturnKeyword */: + case 105 /* WithKeyword */: + case 96 /* SwitchKeyword */: + case 98 /* ThrowKeyword */: + case 100 /* TryKeyword */: + case 76 /* DebuggerKeyword */: // 'catch' and 'finally' do not actually indicate that the code is part of a statement, // however, we say they are here so that we may gracefully parse them and error later. - case 70 /* CatchKeyword */: - case 83 /* FinallyKeyword */: + case 72 /* CatchKeyword */: + case 85 /* FinallyKeyword */: return true; - case 72 /* ConstKeyword */: - case 80 /* ExportKeyword */: - case 87 /* ImportKeyword */: + case 74 /* ConstKeyword */: + case 82 /* ExportKeyword */: + case 89 /* ImportKeyword */: return isStartOfDeclaration(); - case 116 /* AsyncKeyword */: - case 120 /* DeclareKeyword */: - case 105 /* InterfaceKeyword */: - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: - case 130 /* TypeKeyword */: + case 118 /* AsyncKeyword */: + case 122 /* DeclareKeyword */: + case 107 /* InterfaceKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: + case 132 /* TypeKeyword */: // When these don't start a declaration, they're an identifier in an expression statement return true; - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 113 /* StaticKeyword */: // When these don't start a declaration, they may be the start of a class member if an identifier // immediately follows. Otherwise they're an identifier in an expression statement. return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); @@ -10934,61 +11270,61 @@ var ts; return parseEmptyStatement(); case 15 /* OpenBraceToken */: return parseBlock(/*ignoreMissingOpenBrace*/ false); - case 100 /* VarKeyword */: + case 102 /* VarKeyword */: return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); - case 106 /* LetKeyword */: + case 108 /* LetKeyword */: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); } break; - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); - case 71 /* ClassKeyword */: + case 73 /* ClassKeyword */: return parseClassDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); - case 86 /* IfKeyword */: + case 88 /* IfKeyword */: return parseIfStatement(); - case 77 /* DoKeyword */: + case 79 /* DoKeyword */: return parseDoStatement(); - case 102 /* WhileKeyword */: + case 104 /* WhileKeyword */: return parseWhileStatement(); - case 84 /* ForKeyword */: + case 86 /* ForKeyword */: return parseForOrForInOrForOfStatement(); - case 73 /* ContinueKeyword */: - return parseBreakOrContinueStatement(200 /* ContinueStatement */); - case 68 /* BreakKeyword */: - return parseBreakOrContinueStatement(201 /* BreakStatement */); - case 92 /* ReturnKeyword */: + case 75 /* ContinueKeyword */: + return parseBreakOrContinueStatement(202 /* ContinueStatement */); + case 70 /* BreakKeyword */: + return parseBreakOrContinueStatement(203 /* BreakStatement */); + case 94 /* ReturnKeyword */: return parseReturnStatement(); - case 103 /* WithKeyword */: + case 105 /* WithKeyword */: return parseWithStatement(); - case 94 /* SwitchKeyword */: + case 96 /* SwitchKeyword */: return parseSwitchStatement(); - case 96 /* ThrowKeyword */: + case 98 /* ThrowKeyword */: return parseThrowStatement(); - case 98 /* TryKeyword */: + case 100 /* TryKeyword */: // Include 'catch' and 'finally' for error recovery. - case 70 /* CatchKeyword */: - case 83 /* FinallyKeyword */: + case 72 /* CatchKeyword */: + case 85 /* FinallyKeyword */: return parseTryStatement(); - case 74 /* DebuggerKeyword */: + case 76 /* DebuggerKeyword */: return parseDebuggerStatement(); - case 54 /* AtToken */: + case 55 /* AtToken */: return parseDeclaration(); - case 116 /* AsyncKeyword */: - case 105 /* InterfaceKeyword */: - case 130 /* TypeKeyword */: - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: - case 120 /* DeclareKeyword */: - case 72 /* ConstKeyword */: - case 79 /* EnumKeyword */: - case 80 /* ExportKeyword */: - case 87 /* ImportKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 110 /* PublicKeyword */: - case 113 /* AbstractKeyword */: - case 111 /* StaticKeyword */: + case 118 /* AsyncKeyword */: + case 107 /* InterfaceKeyword */: + case 132 /* TypeKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: + case 122 /* DeclareKeyword */: + case 74 /* ConstKeyword */: + case 81 /* EnumKeyword */: + case 82 /* ExportKeyword */: + case 89 /* ImportKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 112 /* PublicKeyword */: + case 115 /* AbstractKeyword */: + case 113 /* StaticKeyword */: if (isStartOfDeclaration()) { return parseDeclaration(); } @@ -11001,35 +11337,35 @@ var ts; var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: return parseVariableStatement(fullStart, decorators, modifiers); - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 71 /* ClassKeyword */: + case 73 /* ClassKeyword */: return parseClassDeclaration(fullStart, decorators, modifiers); - case 105 /* InterfaceKeyword */: + case 107 /* InterfaceKeyword */: return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 130 /* TypeKeyword */: + case 132 /* TypeKeyword */: return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 79 /* EnumKeyword */: + case 81 /* EnumKeyword */: return parseEnumDeclaration(fullStart, decorators, modifiers); - case 123 /* ModuleKeyword */: - case 124 /* NamespaceKeyword */: + case 125 /* ModuleKeyword */: + case 126 /* NamespaceKeyword */: return parseModuleDeclaration(fullStart, decorators, modifiers); - case 87 /* ImportKeyword */: + case 89 /* ImportKeyword */: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: nextToken(); - return token === 75 /* DefaultKeyword */ || token === 55 /* EqualsToken */ ? + return token === 77 /* DefaultKeyword */ || token === 56 /* EqualsToken */ ? parseExportAssignment(fullStart, decorators, modifiers) : parseExportDeclaration(fullStart, decorators, modifiers); default: if (decorators || modifiers) { // We reached this point because we encountered decorators and/or modifiers and assumed a declaration // would follow. For recovery and error reporting purposes, return an incomplete declaration. - var node = createMissingNode(229 /* MissingDeclaration */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); + var node = createMissingNode(231 /* MissingDeclaration */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; setModifiers(node, modifiers); @@ -11051,24 +11387,24 @@ var ts; // DECLARATIONS function parseArrayBindingElement() { if (token === 24 /* CommaToken */) { - return createNode(185 /* OmittedExpression */); + return createNode(187 /* OmittedExpression */); } - var node = createNode(161 /* BindingElement */); + var node = createNode(163 /* BindingElement */); node.dotDotDotToken = parseOptionalToken(22 /* DotDotDotToken */); node.name = parseIdentifierOrPattern(); node.initializer = parseBindingElementInitializer(/*inParameter*/ false); return finishNode(node); } function parseObjectBindingElement() { - var node = createNode(161 /* BindingElement */); + var node = createNode(163 /* BindingElement */); // TODO(andersh): Handle computed properties var tokenIsIdentifier = isIdentifier(); var propertyName = parsePropertyName(); - if (tokenIsIdentifier && token !== 53 /* ColonToken */) { + if (tokenIsIdentifier && token !== 54 /* ColonToken */) { node.name = propertyName; } else { - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); node.propertyName = propertyName; node.name = parseIdentifierOrPattern(); } @@ -11076,14 +11412,14 @@ var ts; return finishNode(node); } function parseObjectBindingPattern() { - var node = createNode(159 /* ObjectBindingPattern */); + var node = createNode(161 /* ObjectBindingPattern */); parseExpected(15 /* OpenBraceToken */); node.elements = parseDelimitedList(9 /* ObjectBindingElements */, parseObjectBindingElement); parseExpected(16 /* CloseBraceToken */); return finishNode(node); } function parseArrayBindingPattern() { - var node = createNode(160 /* ArrayBindingPattern */); + var node = createNode(162 /* ArrayBindingPattern */); parseExpected(19 /* OpenBracketToken */); node.elements = parseDelimitedList(10 /* ArrayBindingElements */, parseArrayBindingElement); parseExpected(20 /* CloseBracketToken */); @@ -11102,7 +11438,7 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(209 /* VariableDeclaration */); + var node = createNode(211 /* VariableDeclaration */); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); if (!isInOrOfKeyword(token)) { @@ -11111,14 +11447,14 @@ var ts; return finishNode(node); } function parseVariableDeclarationList(inForStatementInitializer) { - var node = createNode(210 /* VariableDeclarationList */); + var node = createNode(212 /* VariableDeclarationList */); switch (token) { - case 100 /* VarKeyword */: + case 102 /* VarKeyword */: break; - case 106 /* LetKeyword */: + case 108 /* LetKeyword */: node.flags |= 16384 /* Let */; break; - case 72 /* ConstKeyword */: + case 74 /* ConstKeyword */: node.flags |= 32768 /* Const */; break; default: @@ -11134,7 +11470,7 @@ var ts; // So we need to look ahead to determine if 'of' should be treated as a keyword in // this context. // The checker will then give an error that there is an empty declaration list. - if (token === 132 /* OfKeyword */ && lookAhead(canFollowContextualOfKeyword)) { + if (token === 134 /* OfKeyword */ && lookAhead(canFollowContextualOfKeyword)) { node.declarations = createMissingList(); } else { @@ -11149,7 +11485,7 @@ var ts; return nextTokenIsIdentifier() && nextToken() === 18 /* CloseParenToken */; } function parseVariableStatement(fullStart, decorators, modifiers) { - var node = createNode(191 /* VariableStatement */, fullStart); + var node = createNode(193 /* VariableStatement */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer*/ false); @@ -11157,29 +11493,29 @@ var ts; return finishNode(node); } function parseFunctionDeclaration(fullStart, decorators, modifiers) { - var node = createNode(211 /* FunctionDeclaration */, fullStart); + var node = createNode(213 /* FunctionDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(85 /* FunctionKeyword */); + parseExpected(87 /* FunctionKeyword */); node.asteriskToken = parseOptionalToken(37 /* AsteriskToken */); node.name = node.flags & 1024 /* Default */ ? parseOptionalIdentifier() : parseIdentifier(); var isGenerator = !!node.asteriskToken; var isAsync = !!(node.flags & 512 /* Async */); - fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, decorators, modifiers) { - var node = createNode(142 /* Constructor */, pos); + var node = createNode(144 /* Constructor */, pos); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(119 /* ConstructorKeyword */); - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); + parseExpected(121 /* ConstructorKeyword */); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false, ts.Diagnostics.or_expected); return finishNode(node); } function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { - var method = createNode(141 /* MethodDeclaration */, fullStart); + var method = createNode(143 /* MethodDeclaration */, fullStart); method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; @@ -11187,12 +11523,12 @@ var ts; method.questionToken = questionToken; var isGenerator = !!asteriskToken; var isAsync = !!(method.flags & 512 /* Async */); - fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method); + fillSignature(54 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method); method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage); return finishNode(method); } function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) { - var property = createNode(139 /* PropertyDeclaration */, fullStart); + var property = createNode(141 /* PropertyDeclaration */, fullStart); property.decorators = decorators; setModifiers(property, modifiers); property.name = name; @@ -11218,7 +11554,7 @@ var ts; var name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. - var questionToken = parseOptionalToken(52 /* QuestionToken */); + var questionToken = parseOptionalToken(53 /* QuestionToken */); if (asteriskToken || token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } @@ -11234,16 +11570,16 @@ var ts; node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); - fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); + fillSignature(54 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false); return finishNode(node); } function isClassMemberModifier(idToken) { switch (idToken) { - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 111 /* StaticKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 113 /* StaticKeyword */: return true; default: return false; @@ -11251,7 +11587,7 @@ var ts; } function isClassMemberStart() { var idToken; - if (token === 54 /* AtToken */) { + if (token === 55 /* AtToken */) { return true; } // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. @@ -11284,7 +11620,7 @@ var ts; // If we were able to get any potential identifier... if (idToken !== undefined) { // If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse. - if (!ts.isKeyword(idToken) || idToken === 127 /* SetKeyword */ || idToken === 121 /* GetKeyword */) { + if (!ts.isKeyword(idToken) || idToken === 129 /* SetKeyword */ || idToken === 123 /* GetKeyword */) { return true; } // If it *is* a keyword, but not an accessor, check a little farther along @@ -11292,9 +11628,9 @@ var ts; switch (token) { case 17 /* OpenParenToken */: // Method declaration case 25 /* LessThanToken */: // Generic Method declaration - case 53 /* ColonToken */: // Type Annotation for declaration - case 55 /* EqualsToken */: // Initializer for declaration - case 52 /* QuestionToken */: + case 54 /* ColonToken */: // Type Annotation for declaration + case 56 /* EqualsToken */: // Initializer for declaration + case 53 /* QuestionToken */: return true; default: // Covers @@ -11311,14 +11647,14 @@ var ts; var decorators; while (true) { var decoratorStart = getNodePos(); - if (!parseOptional(54 /* AtToken */)) { + if (!parseOptional(55 /* AtToken */)) { break; } if (!decorators) { decorators = []; decorators.pos = scanner.getStartPos(); } - var decorator = createNode(137 /* Decorator */, decoratorStart); + var decorator = createNode(139 /* Decorator */, decoratorStart); decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); decorators.push(finishNode(decorator)); } @@ -11352,7 +11688,7 @@ var ts; function parseModifiersForArrowFunction() { var flags = 0; var modifiers; - if (token === 116 /* AsyncKeyword */) { + if (token === 118 /* AsyncKeyword */) { var modifierStart = scanner.getStartPos(); var modifierKind = token; nextToken(); @@ -11367,7 +11703,7 @@ var ts; } function parseClassElement() { if (token === 23 /* SemicolonToken */) { - var result = createNode(189 /* SemicolonClassElement */); + var result = createNode(191 /* SemicolonClassElement */); nextToken(); return finishNode(result); } @@ -11378,7 +11714,7 @@ var ts; if (accessor) { return accessor; } - if (token === 119 /* ConstructorKeyword */) { + if (token === 121 /* ConstructorKeyword */) { return parseConstructorDeclaration(fullStart, decorators, modifiers); } if (isIndexSignature()) { @@ -11395,7 +11731,7 @@ var ts; } if (decorators || modifiers) { // treat this as a property declaration with a missing name. - var name_7 = createMissingNode(67 /* Identifier */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); + var name_7 = createMissingNode(69 /* Identifier */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_7, /*questionToken*/ undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. @@ -11405,17 +11741,17 @@ var ts; return parseClassDeclarationOrExpression( /*fullStart*/ scanner.getStartPos(), /*decorators*/ undefined, - /*modifiers*/ undefined, 184 /* ClassExpression */); + /*modifiers*/ undefined, 186 /* ClassExpression */); } function parseClassDeclaration(fullStart, decorators, modifiers) { - return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 212 /* ClassDeclaration */); + return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 214 /* ClassDeclaration */); } function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) { var node = createNode(kind, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(71 /* ClassKeyword */); - node.name = parseOptionalIdentifier(); + parseExpected(73 /* ClassKeyword */); + node.name = parseNameOfClassDeclarationOrExpression(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ true); if (parseExpected(15 /* OpenBraceToken */)) { @@ -11429,6 +11765,19 @@ var ts; } return finishNode(node); } + function parseNameOfClassDeclarationOrExpression() { + // implements is a future reserved word so + // 'class implements' might mean either + // - class expression with omitted name, 'implements' starts heritage clause + // - class with name 'implements' + // 'isImplementsClause' helps to disambiguate between these two cases + return isIdentifier() && !isImplementsClause() + ? parseIdentifier() + : undefined; + } + function isImplementsClause() { + return token === 106 /* ImplementsKeyword */ && lookAhead(nextTokenIsIdentifierOrKeyword); + } function parseHeritageClauses(isClassHeritageClause) { // ClassTail[Yield,Await] : (Modified) See 14.5 // ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt } @@ -11441,8 +11790,8 @@ var ts; return parseList(20 /* HeritageClauses */, parseHeritageClause); } function parseHeritageClause() { - if (token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */) { - var node = createNode(241 /* HeritageClause */); + if (token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */) { + var node = createNode(243 /* HeritageClause */); node.token = token; nextToken(); node.types = parseDelimitedList(7 /* HeritageClauseElement */, parseExpressionWithTypeArguments); @@ -11451,7 +11800,7 @@ var ts; return undefined; } function parseExpressionWithTypeArguments() { - var node = createNode(186 /* ExpressionWithTypeArguments */); + var node = createNode(188 /* ExpressionWithTypeArguments */); node.expression = parseLeftHandSideExpressionOrHigher(); if (token === 25 /* LessThanToken */) { node.typeArguments = parseBracketedList(18 /* TypeArguments */, parseType, 25 /* LessThanToken */, 27 /* GreaterThanToken */); @@ -11459,16 +11808,16 @@ var ts; return finishNode(node); } function isHeritageClause() { - return token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */; + return token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */; } function parseClassMembers() { return parseList(5 /* ClassMembers */, parseClassElement); } function parseInterfaceDeclaration(fullStart, decorators, modifiers) { - var node = createNode(213 /* InterfaceDeclaration */, fullStart); + var node = createNode(215 /* InterfaceDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(105 /* InterfaceKeyword */); + parseExpected(107 /* InterfaceKeyword */); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ false); @@ -11476,13 +11825,13 @@ var ts; return finishNode(node); } function parseTypeAliasDeclaration(fullStart, decorators, modifiers) { - var node = createNode(214 /* TypeAliasDeclaration */, fullStart); + var node = createNode(216 /* TypeAliasDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(130 /* TypeKeyword */); + parseExpected(132 /* TypeKeyword */); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); - parseExpected(55 /* EqualsToken */); + parseExpected(56 /* EqualsToken */); node.type = parseType(); parseSemicolon(); return finishNode(node); @@ -11492,16 +11841,16 @@ var ts; // ConstantEnumMemberSection, which starts at the beginning of an enum declaration // or any time an integer literal initializer is encountered. function parseEnumMember() { - var node = createNode(245 /* EnumMember */, scanner.getStartPos()); + var node = createNode(247 /* EnumMember */, scanner.getStartPos()); node.name = parsePropertyName(); node.initializer = allowInAnd(parseNonParameterInitializer); return finishNode(node); } function parseEnumDeclaration(fullStart, decorators, modifiers) { - var node = createNode(215 /* EnumDeclaration */, fullStart); + var node = createNode(217 /* EnumDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - parseExpected(79 /* EnumKeyword */); + parseExpected(81 /* EnumKeyword */); node.name = parseIdentifier(); if (parseExpected(15 /* OpenBraceToken */)) { node.members = parseDelimitedList(6 /* EnumMembers */, parseEnumMember); @@ -11513,7 +11862,7 @@ var ts; return finishNode(node); } function parseModuleBlock() { - var node = createNode(217 /* ModuleBlock */, scanner.getStartPos()); + var node = createNode(219 /* ModuleBlock */, scanner.getStartPos()); if (parseExpected(15 /* OpenBraceToken */)) { node.statements = parseList(1 /* BlockStatements */, parseStatement); parseExpected(16 /* CloseBraceToken */); @@ -11524,7 +11873,7 @@ var ts; return finishNode(node); } function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) { - var node = createNode(216 /* ModuleDeclaration */, fullStart); + var node = createNode(218 /* ModuleDeclaration */, fullStart); // If we are parsing a dotted namespace name, we want to // propagate the 'Namespace' flag across the names if set. var namespaceFlag = flags & 131072 /* Namespace */; @@ -11538,7 +11887,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) { - var node = createNode(216 /* ModuleDeclaration */, fullStart); + var node = createNode(218 /* ModuleDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(/*internName*/ true); @@ -11547,11 +11896,11 @@ var ts; } function parseModuleDeclaration(fullStart, decorators, modifiers) { var flags = modifiers ? modifiers.flags : 0; - if (parseOptional(124 /* NamespaceKeyword */)) { + if (parseOptional(126 /* NamespaceKeyword */)) { flags |= 131072 /* Namespace */; } else { - parseExpected(123 /* ModuleKeyword */); + parseExpected(125 /* ModuleKeyword */); if (token === 9 /* StringLiteral */) { return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } @@ -11559,42 +11908,42 @@ var ts; return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags); } function isExternalModuleReference() { - return token === 125 /* RequireKeyword */ && + return token === 127 /* RequireKeyword */ && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { return nextToken() === 17 /* OpenParenToken */; } function nextTokenIsSlash() { - return nextToken() === 38 /* SlashToken */; + return nextToken() === 39 /* SlashToken */; } function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 24 /* CommaToken */ || - token === 131 /* FromKeyword */; + token === 133 /* FromKeyword */; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) { - parseExpected(87 /* ImportKeyword */); + parseExpected(89 /* ImportKeyword */); var afterImportPos = scanner.getStartPos(); var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 24 /* CommaToken */ && token !== 131 /* FromKeyword */) { + if (token !== 24 /* CommaToken */ && token !== 133 /* FromKeyword */) { // ImportEquals declaration of type: // import x = require("mod"); or // import x = M.x; - var importEqualsDeclaration = createNode(219 /* ImportEqualsDeclaration */, fullStart); + var importEqualsDeclaration = createNode(221 /* ImportEqualsDeclaration */, fullStart); importEqualsDeclaration.decorators = decorators; setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; - parseExpected(55 /* EqualsToken */); + parseExpected(56 /* EqualsToken */); importEqualsDeclaration.moduleReference = parseModuleReference(); parseSemicolon(); return finishNode(importEqualsDeclaration); } } // Import statement - var importDeclaration = createNode(220 /* ImportDeclaration */, fullStart); + var importDeclaration = createNode(222 /* ImportDeclaration */, fullStart); importDeclaration.decorators = decorators; setModifiers(importDeclaration, modifiers); // ImportDeclaration: @@ -11604,7 +11953,7 @@ var ts; token === 37 /* AsteriskToken */ || token === 15 /* OpenBraceToken */) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(131 /* FromKeyword */); + parseExpected(133 /* FromKeyword */); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); @@ -11617,7 +11966,7 @@ var ts; // NamedImports // ImportedDefaultBinding, NameSpaceImport // ImportedDefaultBinding, NamedImports - var importClause = createNode(221 /* ImportClause */, fullStart); + var importClause = createNode(223 /* ImportClause */, fullStart); if (identifier) { // ImportedDefaultBinding: // ImportedBinding @@ -11627,7 +11976,7 @@ var ts; // parse namespace or named imports if (!importClause.name || parseOptional(24 /* CommaToken */)) { - importClause.namedBindings = token === 37 /* AsteriskToken */ ? parseNamespaceImport() : parseNamedImportsOrExports(223 /* NamedImports */); + importClause.namedBindings = token === 37 /* AsteriskToken */ ? parseNamespaceImport() : parseNamedImportsOrExports(225 /* NamedImports */); } return finishNode(importClause); } @@ -11637,8 +11986,8 @@ var ts; : parseEntityName(/*allowReservedWords*/ false); } function parseExternalModuleReference() { - var node = createNode(230 /* ExternalModuleReference */); - parseExpected(125 /* RequireKeyword */); + var node = createNode(232 /* ExternalModuleReference */); + parseExpected(127 /* RequireKeyword */); parseExpected(17 /* OpenParenToken */); node.expression = parseModuleSpecifier(); parseExpected(18 /* CloseParenToken */); @@ -11659,9 +12008,9 @@ var ts; function parseNamespaceImport() { // NameSpaceImport: // * as ImportedBinding - var namespaceImport = createNode(222 /* NamespaceImport */); + var namespaceImport = createNode(224 /* NamespaceImport */); parseExpected(37 /* AsteriskToken */); - parseExpected(114 /* AsKeyword */); + parseExpected(116 /* AsKeyword */); namespaceImport.name = parseIdentifier(); return finishNode(namespaceImport); } @@ -11674,14 +12023,14 @@ var ts; // ImportsList: // ImportSpecifier // ImportsList, ImportSpecifier - node.elements = parseBracketedList(21 /* ImportOrExportSpecifiers */, kind === 223 /* NamedImports */ ? parseImportSpecifier : parseExportSpecifier, 15 /* OpenBraceToken */, 16 /* CloseBraceToken */); + node.elements = parseBracketedList(21 /* ImportOrExportSpecifiers */, kind === 225 /* NamedImports */ ? parseImportSpecifier : parseExportSpecifier, 15 /* OpenBraceToken */, 16 /* CloseBraceToken */); return finishNode(node); } function parseExportSpecifier() { - return parseImportOrExportSpecifier(228 /* ExportSpecifier */); + return parseImportOrExportSpecifier(230 /* ExportSpecifier */); } function parseImportSpecifier() { - return parseImportOrExportSpecifier(224 /* ImportSpecifier */); + return parseImportOrExportSpecifier(226 /* ImportSpecifier */); } function parseImportOrExportSpecifier(kind) { var node = createNode(kind); @@ -11695,9 +12044,9 @@ var ts; var checkIdentifierStart = scanner.getTokenPos(); var checkIdentifierEnd = scanner.getTextPos(); var identifierName = parseIdentifierName(); - if (token === 114 /* AsKeyword */) { + if (token === 116 /* AsKeyword */) { node.propertyName = identifierName; - parseExpected(114 /* AsKeyword */); + parseExpected(116 /* AsKeyword */); checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); @@ -11706,27 +12055,27 @@ var ts; else { node.name = identifierName; } - if (kind === 224 /* ImportSpecifier */ && checkIdentifierIsKeyword) { + if (kind === 226 /* ImportSpecifier */ && checkIdentifierIsKeyword) { // Report error identifier expected parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected); } return finishNode(node); } function parseExportDeclaration(fullStart, decorators, modifiers) { - var node = createNode(226 /* ExportDeclaration */, fullStart); + var node = createNode(228 /* ExportDeclaration */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(37 /* AsteriskToken */)) { - parseExpected(131 /* FromKeyword */); + parseExpected(133 /* FromKeyword */); node.moduleSpecifier = parseModuleSpecifier(); } else { - node.exportClause = parseNamedImportsOrExports(227 /* NamedExports */); + node.exportClause = parseNamedImportsOrExports(229 /* NamedExports */); // It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios, // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. - if (token === 131 /* FromKeyword */ || (token === 9 /* StringLiteral */ && !scanner.hasPrecedingLineBreak())) { - parseExpected(131 /* FromKeyword */); + if (token === 133 /* FromKeyword */ || (token === 9 /* StringLiteral */ && !scanner.hasPrecedingLineBreak())) { + parseExpected(133 /* FromKeyword */); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -11734,14 +12083,14 @@ var ts; return finishNode(node); } function parseExportAssignment(fullStart, decorators, modifiers) { - var node = createNode(225 /* ExportAssignment */, fullStart); + var node = createNode(227 /* ExportAssignment */, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - if (parseOptional(55 /* EqualsToken */)) { + if (parseOptional(56 /* EqualsToken */)) { node.isExportEquals = true; } else { - parseExpected(75 /* DefaultKeyword */); + parseExpected(77 /* DefaultKeyword */); } node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); @@ -11807,10 +12156,10 @@ var ts; function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 /* Export */ - || node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 230 /* ExternalModuleReference */ - || node.kind === 220 /* ImportDeclaration */ - || node.kind === 225 /* ExportAssignment */ - || node.kind === 226 /* ExportDeclaration */ + || node.kind === 221 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 232 /* ExternalModuleReference */ + || node.kind === 222 /* ImportDeclaration */ + || node.kind === 227 /* ExportAssignment */ + || node.kind === 228 /* ExportDeclaration */ ? node : undefined; }); @@ -11856,15 +12205,15 @@ var ts; function isJSDocType() { switch (token) { case 37 /* AsteriskToken */: - case 52 /* QuestionToken */: + case 53 /* QuestionToken */: case 17 /* OpenParenToken */: case 19 /* OpenBracketToken */: - case 48 /* ExclamationToken */: + case 49 /* ExclamationToken */: case 15 /* OpenBraceToken */: - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: case 22 /* DotDotDotToken */: - case 90 /* NewKeyword */: - case 95 /* ThisKeyword */: + case 92 /* NewKeyword */: + case 97 /* ThisKeyword */: return true; } return ts.tokenIsIdentifierOrKeyword(token); @@ -11885,7 +12234,7 @@ var ts; scanner.setText(sourceText, start, length); // Prime the first token for us to start processing. token = nextToken(); - var result = createNode(247 /* JSDocTypeExpression */); + var result = createNode(249 /* JSDocTypeExpression */); parseExpected(15 /* OpenBraceToken */); result.type = parseJSDocTopLevelType(); parseExpected(16 /* CloseBraceToken */); @@ -11895,13 +12244,13 @@ var ts; JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; function parseJSDocTopLevelType() { var type = parseJSDocType(); - if (token === 46 /* BarToken */) { - var unionType = createNode(251 /* JSDocUnionType */, type.pos); + if (token === 47 /* BarToken */) { + var unionType = createNode(253 /* JSDocUnionType */, type.pos); unionType.types = parseJSDocTypeList(type); type = finishNode(unionType); } - if (token === 55 /* EqualsToken */) { - var optionalType = createNode(258 /* JSDocOptionalType */, type.pos); + if (token === 56 /* EqualsToken */) { + var optionalType = createNode(260 /* JSDocOptionalType */, type.pos); nextToken(); optionalType.type = type; type = finishNode(optionalType); @@ -11912,20 +12261,20 @@ var ts; var type = parseBasicTypeExpression(); while (true) { if (token === 19 /* OpenBracketToken */) { - var arrayType = createNode(250 /* JSDocArrayType */, type.pos); + var arrayType = createNode(252 /* JSDocArrayType */, type.pos); arrayType.elementType = type; nextToken(); parseExpected(20 /* CloseBracketToken */); type = finishNode(arrayType); } - else if (token === 52 /* QuestionToken */) { - var nullableType = createNode(253 /* JSDocNullableType */, type.pos); + else if (token === 53 /* QuestionToken */) { + var nullableType = createNode(255 /* JSDocNullableType */, type.pos); nullableType.type = type; nextToken(); type = finishNode(nullableType); } - else if (token === 48 /* ExclamationToken */) { - var nonNullableType = createNode(254 /* JSDocNonNullableType */, type.pos); + else if (token === 49 /* ExclamationToken */) { + var nonNullableType = createNode(256 /* JSDocNonNullableType */, type.pos); nonNullableType.type = type; nextToken(); type = finishNode(nonNullableType); @@ -11940,80 +12289,80 @@ var ts; switch (token) { case 37 /* AsteriskToken */: return parseJSDocAllType(); - case 52 /* QuestionToken */: + case 53 /* QuestionToken */: return parseJSDocUnknownOrNullableType(); case 17 /* OpenParenToken */: return parseJSDocUnionType(); case 19 /* OpenBracketToken */: return parseJSDocTupleType(); - case 48 /* ExclamationToken */: + case 49 /* ExclamationToken */: return parseJSDocNonNullableType(); case 15 /* OpenBraceToken */: return parseJSDocRecordType(); - case 85 /* FunctionKeyword */: + case 87 /* FunctionKeyword */: return parseJSDocFunctionType(); case 22 /* DotDotDotToken */: return parseJSDocVariadicType(); - case 90 /* NewKeyword */: + case 92 /* NewKeyword */: return parseJSDocConstructorType(); - case 95 /* ThisKeyword */: + case 97 /* ThisKeyword */: return parseJSDocThisType(); - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: - case 101 /* VoidKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: return parseTokenNode(); } return parseJSDocTypeReference(); } function parseJSDocThisType() { - var result = createNode(262 /* JSDocThisType */); + var result = createNode(264 /* JSDocThisType */); nextToken(); - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocConstructorType() { - var result = createNode(261 /* JSDocConstructorType */); + var result = createNode(263 /* JSDocConstructorType */); nextToken(); - parseExpected(53 /* ColonToken */); + parseExpected(54 /* ColonToken */); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocVariadicType() { - var result = createNode(260 /* JSDocVariadicType */); + var result = createNode(262 /* JSDocVariadicType */); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocFunctionType() { - var result = createNode(259 /* JSDocFunctionType */); + var result = createNode(261 /* JSDocFunctionType */); nextToken(); parseExpected(17 /* OpenParenToken */); result.parameters = parseDelimitedList(22 /* JSDocFunctionParameters */, parseJSDocParameter); checkForTrailingComma(result.parameters); parseExpected(18 /* CloseParenToken */); - if (token === 53 /* ColonToken */) { + if (token === 54 /* ColonToken */) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocParameter() { - var parameter = createNode(136 /* Parameter */); + var parameter = createNode(138 /* Parameter */); parameter.type = parseJSDocType(); return finishNode(parameter); } function parseJSDocOptionalType(type) { - var result = createNode(258 /* JSDocOptionalType */, type.pos); + var result = createNode(260 /* JSDocOptionalType */, type.pos); nextToken(); result.type = type; return finishNode(result); } function parseJSDocTypeReference() { - var result = createNode(257 /* JSDocTypeReference */); + var result = createNode(259 /* JSDocTypeReference */); result.name = parseSimplePropertyName(); while (parseOptional(21 /* DotToken */)) { if (token === 25 /* LessThanToken */) { @@ -12043,13 +12392,13 @@ var ts; } } function parseQualifiedName(left) { - var result = createNode(133 /* QualifiedName */, left.pos); + var result = createNode(135 /* QualifiedName */, left.pos); result.left = left; result.right = parseIdentifierName(); return finishNode(result); } function parseJSDocRecordType() { - var result = createNode(255 /* JSDocRecordType */); + var result = createNode(257 /* JSDocRecordType */); nextToken(); result.members = parseDelimitedList(24 /* JSDocRecordMembers */, parseJSDocRecordMember); checkForTrailingComma(result.members); @@ -12057,22 +12406,22 @@ var ts; return finishNode(result); } function parseJSDocRecordMember() { - var result = createNode(256 /* JSDocRecordMember */); + var result = createNode(258 /* JSDocRecordMember */); result.name = parseSimplePropertyName(); - if (token === 53 /* ColonToken */) { + if (token === 54 /* ColonToken */) { nextToken(); result.type = parseJSDocType(); } return finishNode(result); } function parseJSDocNonNullableType() { - var result = createNode(254 /* JSDocNonNullableType */); + var result = createNode(256 /* JSDocNonNullableType */); nextToken(); result.type = parseJSDocType(); return finishNode(result); } function parseJSDocTupleType() { - var result = createNode(252 /* JSDocTupleType */); + var result = createNode(254 /* JSDocTupleType */); nextToken(); result.types = parseDelimitedList(25 /* JSDocTupleTypes */, parseJSDocType); checkForTrailingComma(result.types); @@ -12086,7 +12435,7 @@ var ts; } } function parseJSDocUnionType() { - var result = createNode(251 /* JSDocUnionType */); + var result = createNode(253 /* JSDocUnionType */); nextToken(); result.types = parseJSDocTypeList(parseJSDocType()); parseExpected(18 /* CloseParenToken */); @@ -12097,14 +12446,14 @@ var ts; var types = []; types.pos = firstType.pos; types.push(firstType); - while (parseOptional(46 /* BarToken */)) { + while (parseOptional(47 /* BarToken */)) { types.push(parseJSDocType()); } types.end = scanner.getStartPos(); return types; } function parseJSDocAllType() { - var result = createNode(248 /* JSDocAllType */); + var result = createNode(250 /* JSDocAllType */); nextToken(); return finishNode(result); } @@ -12125,13 +12474,13 @@ var ts; token === 16 /* CloseBraceToken */ || token === 18 /* CloseParenToken */ || token === 27 /* GreaterThanToken */ || - token === 55 /* EqualsToken */ || - token === 46 /* BarToken */) { - var result = createNode(249 /* JSDocUnknownType */, pos); + token === 56 /* EqualsToken */ || + token === 47 /* BarToken */) { + var result = createNode(251 /* JSDocUnknownType */, pos); return finishNode(result); } else { - var result = createNode(253 /* JSDocNullableType */, pos); + var result = createNode(255 /* JSDocNullableType */, pos); result.type = parseJSDocType(); return finishNode(result); } @@ -12219,7 +12568,7 @@ var ts; if (!tags) { return undefined; } - var result = createNode(263 /* JSDocComment */, start); + var result = createNode(265 /* JSDocComment */, start); result.tags = tags; return finishNode(result, end); } @@ -12230,7 +12579,7 @@ var ts; } function parseTag() { ts.Debug.assert(content.charCodeAt(pos - 1) === 64 /* at */); - var atToken = createNode(54 /* AtToken */, pos - 1); + var atToken = createNode(55 /* AtToken */, pos - 1); atToken.end = pos; var tagName = scanIdentifier(); if (!tagName) { @@ -12256,7 +12605,7 @@ var ts; return undefined; } function handleUnknownTag(atToken, tagName) { - var result = createNode(264 /* JSDocTag */, atToken.pos); + var result = createNode(266 /* JSDocTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; return finishNode(result, pos); @@ -12307,7 +12656,7 @@ var ts; if (!typeExpression) { typeExpression = tryParseTypeExpression(); } - var result = createNode(265 /* JSDocParameterTag */, atToken.pos); + var result = createNode(267 /* JSDocParameterTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.preParameterName = preName; @@ -12317,27 +12666,27 @@ var ts; return finishNode(result, pos); } function handleReturnTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 266 /* JSDocReturnTag */; })) { + if (ts.forEach(tags, function (t) { return t.kind === 268 /* JSDocReturnTag */; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(266 /* JSDocReturnTag */, atToken.pos); + var result = createNode(268 /* JSDocReturnTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTypeTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 267 /* JSDocTypeTag */; })) { + if (ts.forEach(tags, function (t) { return t.kind === 269 /* JSDocTypeTag */; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } - var result = createNode(267 /* JSDocTypeTag */, atToken.pos); + var result = createNode(269 /* JSDocTypeTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result, pos); } function handleTemplateTag(atToken, tagName) { - if (ts.forEach(tags, function (t) { return t.kind === 268 /* JSDocTemplateTag */; })) { + if (ts.forEach(tags, function (t) { return t.kind === 270 /* JSDocTemplateTag */; })) { parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } var typeParameters = []; @@ -12350,7 +12699,7 @@ var ts; parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); return undefined; } - var typeParameter = createNode(135 /* TypeParameter */, name_8.pos); + var typeParameter = createNode(137 /* TypeParameter */, name_8.pos); typeParameter.name = name_8; finishNode(typeParameter, pos); typeParameters.push(typeParameter); @@ -12361,7 +12710,7 @@ var ts; pos++; } typeParameters.end = pos; - var result = createNode(268 /* JSDocTemplateTag */, atToken.pos); + var result = createNode(270 /* JSDocTemplateTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeParameters = typeParameters; @@ -12382,7 +12731,7 @@ var ts; if (startPos === pos) { return undefined; } - var result = createNode(67 /* Identifier */, startPos); + var result = createNode(69 /* Identifier */, startPos); result.text = content.substring(startPos, pos); return finishNode(result, pos); } @@ -12505,7 +12854,7 @@ var ts; switch (node.kind) { case 9 /* StringLiteral */: case 8 /* NumericLiteral */: - case 67 /* Identifier */: + case 69 /* Identifier */: return true; } return false; @@ -12898,17 +13247,19 @@ var ts; var Type = ts.objectAllocator.getTypeConstructor(); var Signature = ts.objectAllocator.getSignatureConstructor(); var typeCount = 0; + var symbolCount = 0; var emptyArray = []; var emptySymbols = {}; var compilerOptions = host.getCompilerOptions(); var languageVersion = compilerOptions.target || 0 /* ES3 */; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 /* ES6 */ ? 5 /* ES6 */ : 0 /* None */; var emitResolver = createResolver(); var undefinedSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "undefined"); var argumentsSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "arguments"); var checker = { getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); }, - getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); }, + getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount") + symbolCount; }, getTypeCount: function () { return typeCount; }, isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; }, isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; }, @@ -13069,6 +13420,7 @@ var ts; diagnostics.add(diagnostic); } function createSymbol(flags, name) { + symbolCount++; return new Symbol(flags, name); } function getExcludedSymbolFlags(flags) { @@ -13198,10 +13550,10 @@ var ts; return nodeLinks[nodeId] || (nodeLinks[nodeId] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 246 /* SourceFile */); + return ts.getAncestor(node, 248 /* SourceFile */); } function isGlobalSourceFile(node) { - return node.kind === 246 /* SourceFile */ && !ts.isExternalModule(node); + return node.kind === 248 /* SourceFile */ && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -13220,18 +13572,62 @@ var ts; } // return undefined if we can't find a symbol. } - /** Returns true if node1 is defined before node 2**/ - function isDefinedBefore(node1, node2) { - var file1 = ts.getSourceFileOfNode(node1); - var file2 = ts.getSourceFileOfNode(node2); - if (file1 === file2) { - return node1.pos <= node2.pos; + function isBlockScopedNameDeclaredBeforeUse(declaration, usage) { + var declarationFile = ts.getSourceFileOfNode(declaration); + var useFile = ts.getSourceFileOfNode(usage); + if (declarationFile !== useFile) { + if (modulekind || (!compilerOptions.outFile && !compilerOptions.out)) { + // nodes are in different files and order cannot be determines + return true; + } + var sourceFiles = host.getSourceFiles(); + return ts.indexOf(sourceFiles, declarationFile) <= ts.indexOf(sourceFiles, useFile); } - if (!compilerOptions.outFile && !compilerOptions.out) { - return true; + if (declaration.pos <= usage.pos) { + // declaration is before usage + // still might be illegal if usage is in the initializer of the variable declaration + return declaration.kind !== 211 /* VariableDeclaration */ || + !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage); + } + // declaration is after usage + // can be legal if usage is deferred (i.e. inside function or in initializer of instance property) + return isUsedInFunctionOrNonStaticProperty(declaration, usage); + function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + if (declaration.parent.parent.kind === 193 /* VariableStatement */ || + declaration.parent.parent.kind === 199 /* ForStatement */) { + // variable statement/for statement case, + // use site should not be inside variable declaration (initializer of declaration or binding element) + return isSameScopeDescendentOf(usage, declaration, container); + } + else if (declaration.parent.parent.kind === 201 /* ForOfStatement */ || + declaration.parent.parent.kind === 200 /* ForInStatement */) { + // ForIn/ForOf case - use site should not be used in expression part + var expression = declaration.parent.parent.expression; + return isSameScopeDescendentOf(usage, expression, container); + } + } + function isUsedInFunctionOrNonStaticProperty(declaration, usage) { + var container = ts.getEnclosingBlockScopeContainer(declaration); + var current = usage; + while (current) { + if (current === container) { + return false; + } + if (ts.isFunctionLike(current)) { + return true; + } + var initializerOfNonStaticProperty = current.parent && + current.parent.kind === 141 /* PropertyDeclaration */ && + (current.parent.flags & 128 /* Static */) === 0 && + current.parent.initializer === current; + if (initializerOfNonStaticProperty) { + return true; + } + current = current.parent; + } + return false; } - var sourceFiles = host.getSourceFiles(); - return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2); } // Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and // the nameNotFoundMessage argument is not undefined. Returns the resolved symbol, or undefined if no symbol with @@ -13258,13 +13654,13 @@ var ts; } } switch (location.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (!ts.isExternalModule(location)) break; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; - if (location.kind === 246 /* SourceFile */ || - (location.kind === 216 /* ModuleDeclaration */ && location.name.kind === 9 /* StringLiteral */)) { + if (location.kind === 248 /* SourceFile */ || + (location.kind === 218 /* ModuleDeclaration */ && location.name.kind === 9 /* StringLiteral */)) { // It's an external module. Because of module/namespace merging, a module's exports are in scope, // yet we never want to treat an export specifier as putting a member in scope. Therefore, // if the name we find is purely an export specifier, it is not actually considered in scope. @@ -13278,7 +13674,7 @@ var ts; // which is not the desired behavior. if (ts.hasProperty(moduleExports, name) && moduleExports[name].flags === 8388608 /* Alias */ && - ts.getDeclarationOfKind(moduleExports[name], 228 /* ExportSpecifier */)) { + ts.getDeclarationOfKind(moduleExports[name], 230 /* ExportSpecifier */)) { break; } result = moduleExports["default"]; @@ -13292,13 +13688,13 @@ var ts; break loop; } break; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: // TypeScript 1.0 spec (April 2014): 8.4.1 // Initializer expressions for instance member variables are evaluated in the scope // of the class constructor body but are not permitted to reference parameters or @@ -13315,9 +13711,9 @@ var ts; } } break; - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056 /* Type */)) { if (lastLocation && lastLocation.flags & 128 /* Static */) { // TypeScript 1.0 spec (April 2014): 3.4.1 @@ -13328,7 +13724,7 @@ var ts; } break loop; } - if (location.kind === 184 /* ClassExpression */ && meaning & 32 /* Class */) { + if (location.kind === 186 /* ClassExpression */ && meaning & 32 /* Class */) { var className = location.name; if (className && name === className.text) { result = location.symbol; @@ -13344,9 +13740,9 @@ var ts; // [foo()]() { } // <-- Reference to T from class's own computed property // } // - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: grandparent = location.parent.parent; - if (ts.isClassLike(grandparent) || grandparent.kind === 213 /* InterfaceDeclaration */) { + if (ts.isClassLike(grandparent) || grandparent.kind === 215 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); @@ -13354,19 +13750,19 @@ var ts; } } break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; - case 171 /* FunctionExpression */: + case 173 /* FunctionExpression */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; @@ -13379,7 +13775,7 @@ var ts; } } break; - case 137 /* Decorator */: + case 139 /* Decorator */: // Decorators are resolved at the class declaration. Resolving at the parameter // or member would result in looking up locals in the method. // @@ -13388,7 +13784,7 @@ var ts; // method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. // } // - if (location.parent && location.parent.kind === 136 /* Parameter */) { + if (location.parent && location.parent.kind === 138 /* Parameter */) { location = location.parent; } // @@ -13434,8 +13830,11 @@ var ts; // block - scope variable and namespace module. However, only when we // try to resolve name in /*1*/ which is used in variable position, // we want to check for block- scoped - if (meaning & 2 /* BlockScopedVariable */ && result.flags & 2 /* BlockScopedVariable */) { - checkResolvedBlockScopedVariable(result, errorLocation); + if (meaning & 2 /* BlockScopedVariable */) { + var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result); + if (exportOrLocalSymbol.flags & 2 /* BlockScopedVariable */) { + checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); + } } } return result; @@ -13445,32 +13844,7 @@ var ts; // Block-scoped variables cannot be used before their definition var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); - // first check if usage is lexically located after the declaration - var isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation); - if (!isUsedBeforeDeclaration) { - // lexical check succeeded however code still can be illegal. - // - block scoped variables cannot be used in its initializers - // let x = x; // illegal but usage is lexically after definition - // - in ForIn/ForOf statements variable cannot be contained in expression part - // for (let x in x) - // for (let x of x) - // climb up to the variable declaration skipping binding patterns - var variableDeclaration = ts.getAncestor(declaration, 209 /* VariableDeclaration */); - var container = ts.getEnclosingBlockScopeContainer(variableDeclaration); - if (variableDeclaration.parent.parent.kind === 191 /* VariableStatement */ || - variableDeclaration.parent.parent.kind === 197 /* ForStatement */) { - // variable statement/for statement case, - // use site should not be inside variable declaration (initializer of declaration or binding element) - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container); - } - else if (variableDeclaration.parent.parent.kind === 199 /* ForOfStatement */ || - variableDeclaration.parent.parent.kind === 198 /* ForInStatement */) { - // ForIn/ForOf case - use site should not be used in expression part - var expression = variableDeclaration.parent.parent.expression; - isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container); - } - } - if (isUsedBeforeDeclaration) { + if (!isBlockScopedNameDeclaredBeforeUse(ts.getAncestor(declaration, 211 /* VariableDeclaration */), errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); } } @@ -13491,10 +13865,10 @@ var ts; } function getAnyImportSyntax(node) { if (ts.isAliasSymbolDeclaration(node)) { - if (node.kind === 219 /* ImportEqualsDeclaration */) { + if (node.kind === 221 /* ImportEqualsDeclaration */) { return node; } - while (node && node.kind !== 220 /* ImportDeclaration */) { + while (node && node.kind !== 222 /* ImportDeclaration */) { node = node.parent; } return node; @@ -13504,7 +13878,7 @@ var ts; return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { - if (node.moduleReference.kind === 230 /* ExternalModuleReference */) { + if (node.moduleReference.kind === 232 /* ExternalModuleReference */) { return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node))); } return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); @@ -13611,17 +13985,17 @@ var ts; } function getTargetOfAliasDeclaration(node) { switch (node.kind) { - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return getTargetOfImportEqualsDeclaration(node); - case 221 /* ImportClause */: + case 223 /* ImportClause */: return getTargetOfImportClause(node); - case 222 /* NamespaceImport */: + case 224 /* NamespaceImport */: return getTargetOfNamespaceImport(node); - case 224 /* ImportSpecifier */: + case 226 /* ImportSpecifier */: return getTargetOfImportSpecifier(node); - case 228 /* ExportSpecifier */: + case 230 /* ExportSpecifier */: return getTargetOfExportSpecifier(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return getTargetOfExportAssignment(node); } } @@ -13666,11 +14040,11 @@ var ts; if (!links.referenced) { links.referenced = true; var node = getDeclarationOfAliasSymbol(symbol); - if (node.kind === 225 /* ExportAssignment */) { + if (node.kind === 227 /* ExportAssignment */) { // export default checkExpressionCached(node.expression); } - else if (node.kind === 228 /* ExportSpecifier */) { + else if (node.kind === 230 /* ExportSpecifier */) { // export { } or export { as foo } checkExpressionCached(node.propertyName || node.name); } @@ -13683,7 +14057,7 @@ var ts; // This function is only for imports with entity names function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 219 /* ImportEqualsDeclaration */); + importDeclaration = ts.getAncestor(entityName, 221 /* ImportEqualsDeclaration */); ts.Debug.assert(importDeclaration !== undefined); } // There are three things we might try to look for. In the following examples, @@ -13692,17 +14066,17 @@ var ts; // import a = |b|; // Namespace // import a = |b.c|; // Value, type, namespace // import a = |b.c|.d; // Namespace - if (entityName.kind === 67 /* Identifier */ && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { + if (entityName.kind === 69 /* Identifier */ && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { entityName = entityName.parent; } // Check for case 1 and 3 in the above example - if (entityName.kind === 67 /* Identifier */ || entityName.parent.kind === 133 /* QualifiedName */) { + if (entityName.kind === 69 /* Identifier */ || entityName.parent.kind === 135 /* QualifiedName */) { return resolveEntityName(entityName, 1536 /* Namespace */); } else { // Case 2 in above example // entityName.kind could be a QualifiedName or a Missing identifier - ts.Debug.assert(entityName.parent.kind === 219 /* ImportEqualsDeclaration */); + ts.Debug.assert(entityName.parent.kind === 221 /* ImportEqualsDeclaration */); return resolveEntityName(entityName, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */); } } @@ -13715,16 +14089,16 @@ var ts; return undefined; } var symbol; - if (name.kind === 67 /* Identifier */) { + if (name.kind === 69 /* Identifier */) { var message = meaning === 1536 /* Namespace */ ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0; symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } } - else if (name.kind === 133 /* QualifiedName */ || name.kind === 164 /* PropertyAccessExpression */) { - var left = name.kind === 133 /* QualifiedName */ ? name.left : name.expression; - var right = name.kind === 133 /* QualifiedName */ ? name.right : name.name; + else if (name.kind === 135 /* QualifiedName */ || name.kind === 166 /* PropertyAccessExpression */) { + var left = name.kind === 135 /* QualifiedName */ ? name.left : name.expression; + var right = name.kind === 135 /* QualifiedName */ ? name.right : name.name; var namespace = resolveEntityName(left, 1536 /* Namespace */, ignoreErrors); if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { return undefined; @@ -13743,11 +14117,6 @@ var ts; ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); return symbol.flags & meaning ? symbol : resolveAlias(symbol); } - function isExternalModuleNameRelative(moduleName) { - // TypeScript 1.0 spec (April 2014): 11.2.1 - // An external module name is "relative" if the first term is "." or "..". - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; - } function resolveExternalModuleName(location, moduleReferenceExpression) { if (moduleReferenceExpression.kind !== 9 /* StringLiteral */) { return; @@ -13760,7 +14129,7 @@ var ts; if (moduleName === undefined) { return; } - var isRelative = isExternalModuleNameRelative(moduleName); + var isRelative = ts.isExternalModuleNameRelative(moduleName); if (!isRelative) { var symbol = getSymbol(globals, "\"" + moduleName + "\"", 512 /* ValueModule */); if (symbol) { @@ -13876,7 +14245,7 @@ var ts; var members = node.members; for (var _i = 0; _i < members.length; _i++) { var member = members[_i]; - if (member.kind === 142 /* Constructor */ && ts.nodeIsPresent(member.body)) { + if (member.kind === 144 /* Constructor */ && ts.nodeIsPresent(member.body)) { return member; } } @@ -13946,17 +14315,17 @@ var ts; } } switch (location_1.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (!ts.isExternalModule(location_1)) { break; } - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (result = callback(getSymbolOfNode(location_1).exports)) { return result; } break; - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: if (result = callback(getSymbolOfNode(location_1).members)) { return result; } @@ -13997,7 +14366,7 @@ var ts; return ts.forEachValue(symbols, function (symbolFromSymbolTable) { if (symbolFromSymbolTable.flags & 8388608 /* Alias */ && symbolFromSymbolTable.name !== "export=" - && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228 /* ExportSpecifier */)) { + && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230 /* ExportSpecifier */)) { if (!useOnlyExternalAliasing || // Is this external alias, then use it to name ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { @@ -14034,7 +14403,7 @@ var ts; return true; } // Qualify if the symbol from symbol table has same meaning as expected - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 /* Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228 /* ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 /* Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 230 /* ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -14107,8 +14476,8 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 216 /* ModuleDeclaration */ && declaration.name.kind === 9 /* StringLiteral */) || - (declaration.kind === 246 /* SourceFile */ && ts.isExternalModule(declaration)); + return (declaration.kind === 218 /* ModuleDeclaration */ && declaration.name.kind === 9 /* StringLiteral */) || + (declaration.kind === 248 /* SourceFile */ && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -14144,12 +14513,12 @@ var ts; function isEntityNameVisible(entityName, enclosingDeclaration) { // get symbol of the first identifier of the entityName var meaning; - if (entityName.parent.kind === 152 /* TypeQuery */) { + if (entityName.parent.kind === 154 /* TypeQuery */) { // Typeof value meaning = 107455 /* Value */ | 1048576 /* ExportValue */; } - else if (entityName.kind === 133 /* QualifiedName */ || entityName.kind === 164 /* PropertyAccessExpression */ || - entityName.parent.kind === 219 /* ImportEqualsDeclaration */) { + else if (entityName.kind === 135 /* QualifiedName */ || entityName.kind === 166 /* PropertyAccessExpression */ || + entityName.parent.kind === 221 /* ImportEqualsDeclaration */) { // Left identifier from type reference or TypeAlias // Entity name of the import declaration meaning = 1536 /* Namespace */; @@ -14204,10 +14573,10 @@ var ts; function getTypeAliasForTypeLiteral(type) { if (type.symbol && type.symbol.flags & 2048 /* TypeLiteral */) { var node = type.symbol.declarations[0].parent; - while (node.kind === 158 /* ParenthesizedType */) { + while (node.kind === 160 /* ParenthesizedType */) { node = node.parent; } - if (node.kind === 214 /* TypeAliasDeclaration */) { + if (node.kind === 216 /* TypeAliasDeclaration */) { return getSymbolOfNode(node); } } @@ -14221,10 +14590,10 @@ var ts; return ts.declarationNameToString(declaration.name); } switch (declaration.kind) { - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: return "(Anonymous class)"; - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return "(Anonymous function)"; } } @@ -14307,6 +14676,7 @@ var ts; } function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) { var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */; + var inObjectTypeLiteral = false; return writeType(type, globalFlags); function writeType(type, flags) { // Write undefined/null type as any @@ -14316,6 +14686,12 @@ var ts; ? "any" : type.intrinsicName); } + else if (type.flags & 33554432 /* ThisType */) { + if (inObjectTypeLiteral) { + writer.reportInaccessibleThisError(); + } + writer.writeKeyword("this"); + } else if (type.flags & 4096 /* Reference */) { writeTypeReference(type, flags); } @@ -14357,11 +14733,10 @@ var ts; writeType(types[i], delimiter === 24 /* CommaToken */ ? 0 /* None */ : 64 /* InElementType */); } } - function writeSymbolTypeReference(symbol, typeArguments, pos, end) { - // Unnamed function expressions, arrow functions, and unnamed class expressions have reserved names that - // we don't want to display - if (!isReservedMemberName(symbol.name)) { - buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056 /* Type */); + function writeSymbolTypeReference(symbol, typeArguments, pos, end, flags) { + // Unnamed function expressions and arrow functions have reserved names that we don't want to display + if (symbol.flags & 32 /* Class */ || !isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags); } if (pos < end) { writePunctuation(writer, 25 /* LessThanToken */); @@ -14375,7 +14750,7 @@ var ts; } } function writeTypeReference(type, flags) { - var typeArguments = type.typeArguments; + var typeArguments = type.typeArguments || emptyArray; if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { writeType(typeArguments[0], 64 /* InElementType */); writePunctuation(writer, 19 /* OpenBracketToken */); @@ -14399,12 +14774,13 @@ var ts; // When type parameters are their own type arguments for the whole group (i.e. we have // the default outer type arguments), we don't show the group. if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { - writeSymbolTypeReference(parent_3, typeArguments, start, i); + writeSymbolTypeReference(parent_3, typeArguments, start, i, flags); writePunctuation(writer, 21 /* DotToken */); } } } - writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); + var typeParameterCount = (type.target.typeParameters || emptyArray).length; + writeSymbolTypeReference(type.symbol, typeArguments, i, typeParameterCount, flags); } } function writeTupleType(type) { @@ -14416,7 +14792,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* OpenParenToken */); } - writeTypeList(type.types, type.flags & 16384 /* Union */ ? 46 /* BarToken */ : 45 /* AmpersandToken */); + writeTypeList(type.types, type.flags & 16384 /* Union */ ? 47 /* BarToken */ : 46 /* AmpersandToken */); if (flags & 64 /* InElementType */) { writePunctuation(writer, 18 /* CloseParenToken */); } @@ -14440,7 +14816,7 @@ var ts; } else { // Recursive usage, use any - writeKeyword(writer, 115 /* AnyKeyword */); + writeKeyword(writer, 117 /* AnyKeyword */); } } else { @@ -14464,7 +14840,7 @@ var ts; var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) && (symbol.parent || ts.forEach(symbol.declarations, function (declaration) { - return declaration.parent.kind === 246 /* SourceFile */ || declaration.parent.kind === 217 /* ModuleBlock */; + return declaration.parent.kind === 248 /* SourceFile */ || declaration.parent.kind === 219 /* ModuleBlock */; })); if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { // typeof is allowed only for static/non local functions @@ -14474,7 +14850,7 @@ var ts; } } function writeTypeofSymbol(type, typeFormatFlags) { - writeKeyword(writer, 99 /* TypeOfKeyword */); + writeKeyword(writer, 101 /* TypeOfKeyword */); writeSpace(writer); buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455 /* Value */, 0 /* None */, typeFormatFlags); } @@ -14510,7 +14886,7 @@ var ts; if (flags & 64 /* InElementType */) { writePunctuation(writer, 17 /* OpenParenToken */); } - writeKeyword(writer, 90 /* NewKeyword */); + writeKeyword(writer, 92 /* NewKeyword */); writeSpace(writer); buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack); if (flags & 64 /* InElementType */) { @@ -14519,6 +14895,8 @@ var ts; return; } } + var saveInObjectTypeLiteral = inObjectTypeLiteral; + inObjectTypeLiteral = true; writePunctuation(writer, 15 /* OpenBraceToken */); writer.writeLine(); writer.increaseIndent(); @@ -14530,7 +14908,7 @@ var ts; } for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) { var signature = _c[_b]; - writeKeyword(writer, 90 /* NewKeyword */); + writeKeyword(writer, 92 /* NewKeyword */); writeSpace(writer); buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14540,11 +14918,11 @@ var ts; // [x: string]: writePunctuation(writer, 19 /* OpenBracketToken */); writer.writeParameter(getIndexerParameterName(resolved, 0 /* String */, /*fallbackName*/ "x")); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); - writeKeyword(writer, 128 /* StringKeyword */); + writeKeyword(writer, 130 /* StringKeyword */); writePunctuation(writer, 20 /* CloseBracketToken */); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); writeType(resolved.stringIndexType, 0 /* None */); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14554,11 +14932,11 @@ var ts; // [x: number]: writePunctuation(writer, 19 /* OpenBracketToken */); writer.writeParameter(getIndexerParameterName(resolved, 1 /* Number */, /*fallbackName*/ "x")); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); - writeKeyword(writer, 126 /* NumberKeyword */); + writeKeyword(writer, 128 /* NumberKeyword */); writePunctuation(writer, 20 /* CloseBracketToken */); - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); writeType(resolved.numberIndexType, 0 /* None */); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14573,7 +14951,7 @@ var ts; var signature = signatures[_f]; buildSymbolDisplay(p, writer); if (p.flags & 536870912 /* Optional */) { - writePunctuation(writer, 52 /* QuestionToken */); + writePunctuation(writer, 53 /* QuestionToken */); } buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14583,9 +14961,9 @@ var ts; else { buildSymbolDisplay(p, writer); if (p.flags & 536870912 /* Optional */) { - writePunctuation(writer, 52 /* QuestionToken */); + writePunctuation(writer, 53 /* QuestionToken */); } - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); writeType(t, 0 /* None */); writePunctuation(writer, 23 /* SemicolonToken */); @@ -14594,6 +14972,7 @@ var ts; } writer.decreaseIndent(); writePunctuation(writer, 16 /* CloseBraceToken */); + inObjectTypeLiteral = saveInObjectTypeLiteral; } } function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { @@ -14607,7 +14986,7 @@ var ts; var constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); - writeKeyword(writer, 81 /* ExtendsKeyword */); + writeKeyword(writer, 83 /* ExtendsKeyword */); writeSpace(writer); buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } @@ -14619,9 +14998,9 @@ var ts; } appendSymbolNameOnly(p, writer); if (isOptionalParameter(parameterNode)) { - writePunctuation(writer, 52 /* QuestionToken */); + writePunctuation(writer, 53 /* QuestionToken */); } - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); writeSpace(writer); buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } @@ -14668,14 +15047,14 @@ var ts; writePunctuation(writer, 34 /* EqualsGreaterThanToken */); } else { - writePunctuation(writer, 53 /* ColonToken */); + writePunctuation(writer, 54 /* ColonToken */); } writeSpace(writer); var returnType; if (signature.typePredicate) { writer.writeParameter(signature.typePredicate.parameterName); writeSpace(writer); - writeKeyword(writer, 122 /* IsKeyword */); + writeKeyword(writer, 124 /* IsKeyword */); writeSpace(writer); returnType = signature.typePredicate.type; } @@ -14711,12 +15090,12 @@ var ts; function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 216 /* ModuleDeclaration */) { + if (node.kind === 218 /* ModuleDeclaration */) { if (node.name.kind === 9 /* StringLiteral */) { return node; } } - else if (node.kind === 246 /* SourceFile */) { + else if (node.kind === 248 /* SourceFile */) { return ts.isExternalModule(node) ? node : undefined; } } @@ -14765,70 +15144,70 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 161 /* BindingElement */: + case 163 /* BindingElement */: return isDeclarationVisible(node.parent.parent); - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: if (ts.isBindingPattern(node.name) && !node.name.elements.length) { // If the binding pattern is empty, this variable declaration is not visible return false; } // Otherwise fall through - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 211 /* FunctionDeclaration */: - case 215 /* EnumDeclaration */: - case 219 /* ImportEqualsDeclaration */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 213 /* FunctionDeclaration */: + case 217 /* EnumDeclaration */: + case 221 /* ImportEqualsDeclaration */: var parent_4 = getDeclarationContainer(node); // If the node is not exported or it is not ambient module element (except import declaration) if (!(ts.getCombinedNodeFlags(node) & 1 /* Export */) && - !(node.kind !== 219 /* ImportEqualsDeclaration */ && parent_4.kind !== 246 /* SourceFile */ && ts.isInAmbientContext(parent_4))) { + !(node.kind !== 221 /* ImportEqualsDeclaration */ && parent_4.kind !== 248 /* SourceFile */ && ts.isInAmbientContext(parent_4))) { return isGlobalSourceFile(parent_4); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent_4); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.flags & (32 /* Private */ | 64 /* Protected */)) { // Private/protected properties/methods are not visible return false; } // Public properties/methods are visible if its parents are visible, so let it fall into next case statement - case 142 /* Constructor */: - case 146 /* ConstructSignature */: - case 145 /* CallSignature */: - case 147 /* IndexSignature */: - case 136 /* Parameter */: - case 217 /* ModuleBlock */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 153 /* TypeLiteral */: - case 149 /* TypeReference */: - case 154 /* ArrayType */: - case 155 /* TupleType */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: - case 158 /* ParenthesizedType */: + case 144 /* Constructor */: + case 148 /* ConstructSignature */: + case 147 /* CallSignature */: + case 149 /* IndexSignature */: + case 138 /* Parameter */: + case 219 /* ModuleBlock */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 155 /* TypeLiteral */: + case 151 /* TypeReference */: + case 156 /* ArrayType */: + case 157 /* TupleType */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: + case 160 /* ParenthesizedType */: return isDeclarationVisible(node.parent); // Default binding, import specifier and namespace import is visible // only on demand so by default it is not visible - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: - case 224 /* ImportSpecifier */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: + case 226 /* ImportSpecifier */: return false; // Type parameters are always visible - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: // Source file is always visible - case 246 /* SourceFile */: + case 248 /* SourceFile */: return true; // Export assignements do not create name bindings outside the module - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return false; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); @@ -14844,10 +15223,10 @@ var ts; } function collectLinkedAliases(node) { var exportSymbol; - if (node.parent && node.parent.kind === 225 /* ExportAssignment */) { + if (node.parent && node.parent.kind === 227 /* ExportAssignment */) { exportSymbol = resolveName(node.parent, node.text, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */ | 8388608 /* Alias */, ts.Diagnostics.Cannot_find_name_0, node); } - else if (node.parent.kind === 228 /* ExportSpecifier */) { + else if (node.parent.kind === 230 /* ExportSpecifier */) { var exportSpecifier = node.parent; exportSymbol = exportSpecifier.parent.parent.moduleSpecifier ? getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) : @@ -14939,7 +15318,7 @@ var ts; node = ts.getRootDeclaration(node); // Parent chain: // VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container' - return node.kind === 209 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; + return node.kind === 211 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { // TypeScript 1.0 spec (April 2014): 8.4 @@ -14957,10 +15336,16 @@ var ts; function isTypeAny(type) { return type && (type.flags & 1 /* Any */) !== 0; } + // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been + // assigned by contextual typing. + function getTypeForBindingElementParent(node) { + var symbol = getSymbolOfNode(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + } // Return the inferred type for a binding element function getTypeForBindingElement(declaration) { var pattern = declaration.parent; - var parentType = getTypeForVariableLikeDeclaration(pattern.parent); + var parentType = getTypeForBindingElementParent(pattern.parent); // If parent has the unknown (error) type, then so does this binding element if (parentType === unknownType) { return unknownType; @@ -14975,7 +15360,7 @@ var ts; return parentType; } var type; - if (pattern.kind === 159 /* ObjectBindingPattern */) { + if (pattern.kind === 161 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) var name_10 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, @@ -15019,10 +15404,10 @@ var ts; // Return the inferred type for a variable, parameter, or property declaration function getTypeForVariableLikeDeclaration(declaration) { // A variable declared in a for..in statement is always of type any - if (declaration.parent.parent.kind === 198 /* ForInStatement */) { + if (declaration.parent.parent.kind === 200 /* ForInStatement */) { return anyType; } - if (declaration.parent.parent.kind === 199 /* ForOfStatement */) { + if (declaration.parent.parent.kind === 201 /* ForOfStatement */) { // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like // [Symbol.iterator] or next). This may be because we accessed properties from anyType, @@ -15036,11 +15421,11 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136 /* Parameter */) { + if (declaration.kind === 138 /* Parameter */) { var func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present - if (func.kind === 144 /* SetAccessor */ && !ts.hasDynamicName(func)) { - var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 143 /* GetAccessor */); + if (func.kind === 146 /* SetAccessor */ && !ts.hasDynamicName(func)) { + var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 145 /* GetAccessor */); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); } @@ -15056,7 +15441,7 @@ var ts; return checkExpressionCached(declaration.initializer); } // If it is a short-hand property assignment, use the type of the identifier - if (declaration.kind === 244 /* ShorthandPropertyAssignment */) { + if (declaration.kind === 246 /* ShorthandPropertyAssignment */) { return checkIdentifier(declaration.name); } // If the declaration specifies a binding pattern, use the type implied by the binding pattern @@ -15102,7 +15487,7 @@ var ts; return languageVersion >= 2 /* ES6 */ ? createIterableType(anyType) : anyArrayType; } // If the pattern has at least one element, and no rest element, then it should imply a tuple type. - var elementTypes = ts.map(elements, function (e) { return e.kind === 185 /* OmittedExpression */ ? anyType : getTypeFromBindingElement(e, includePatternInType); }); + var elementTypes = ts.map(elements, function (e) { return e.kind === 187 /* OmittedExpression */ ? anyType : getTypeFromBindingElement(e, includePatternInType); }); if (includePatternInType) { var result = createNewTupleType(elementTypes); result.pattern = pattern; @@ -15118,7 +15503,7 @@ var ts; // parameter with no type annotation or initializer, the type implied by the binding pattern becomes the type of // the parameter. function getTypeFromBindingPattern(pattern, includePatternInType) { - return pattern.kind === 159 /* ObjectBindingPattern */ + return pattern.kind === 161 /* ObjectBindingPattern */ ? getTypeFromObjectBindingPattern(pattern, includePatternInType) : getTypeFromArrayBindingPattern(pattern, includePatternInType); } @@ -15140,14 +15525,14 @@ var ts; // During a normal type check we'll never get to here with a property assignment (the check of the containing // object literal uses a different path). We exclude widening only so that language services and type verification // tools see the actual type. - return declaration.kind !== 243 /* PropertyAssignment */ ? getWidenedType(type) : type; + return declaration.kind !== 245 /* PropertyAssignment */ ? getWidenedType(type) : type; } // Rest parameters default to type any[], other parameters default to type any type = declaration.dotDotDotToken ? anyArrayType : anyType; // Report implicit any errors unless this is a private property within an ambient declaration if (reportErrors && compilerOptions.noImplicitAny) { var root = ts.getRootDeclaration(declaration); - if (!isPrivateWithinAmbient(root) && !(root.kind === 136 /* Parameter */ && isPrivateWithinAmbient(root.parent))) { + if (!isPrivateWithinAmbient(root) && !(root.kind === 138 /* Parameter */ && isPrivateWithinAmbient(root.parent))) { reportImplicitAnyError(declaration, type); } } @@ -15162,11 +15547,11 @@ var ts; } // Handle catch clause variables var declaration = symbol.valueDeclaration; - if (declaration.parent.kind === 242 /* CatchClause */) { + if (declaration.parent.kind === 244 /* CatchClause */) { return links.type = anyType; } // Handle export default expressions - if (declaration.kind === 225 /* ExportAssignment */) { + if (declaration.kind === 227 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } // Handle variable, parameter or property @@ -15194,7 +15579,7 @@ var ts; } function getAnnotatedAccessorType(accessor) { if (accessor) { - if (accessor.kind === 143 /* GetAccessor */) { + if (accessor.kind === 145 /* GetAccessor */) { return accessor.type && getTypeFromTypeNode(accessor.type); } else { @@ -15210,8 +15595,8 @@ var ts; if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } - var getter = ts.getDeclarationOfKind(symbol, 143 /* GetAccessor */); - var setter = ts.getDeclarationOfKind(symbol, 144 /* SetAccessor */); + var getter = ts.getDeclarationOfKind(symbol, 145 /* GetAccessor */); + var setter = ts.getDeclarationOfKind(symbol, 146 /* SetAccessor */); var type; // First try to see if the user specified a return type on the get-accessor. var getterReturnType = getAnnotatedAccessorType(getter); @@ -15240,7 +15625,7 @@ var ts; if (!popTypeResolution()) { type = anyType; if (compilerOptions.noImplicitAny) { - var getter_1 = ts.getDeclarationOfKind(symbol, 143 /* GetAccessor */); + var getter_1 = ts.getDeclarationOfKind(symbol, 145 /* GetAccessor */); error(getter_1, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } } @@ -15340,9 +15725,9 @@ var ts; if (!node) { return typeParameters; } - if (node.kind === 212 /* ClassDeclaration */ || node.kind === 184 /* ClassExpression */ || - node.kind === 211 /* FunctionDeclaration */ || node.kind === 171 /* FunctionExpression */ || - node.kind === 141 /* MethodDeclaration */ || node.kind === 172 /* ArrowFunction */) { + if (node.kind === 214 /* ClassDeclaration */ || node.kind === 186 /* ClassExpression */ || + node.kind === 213 /* FunctionDeclaration */ || node.kind === 173 /* FunctionExpression */ || + node.kind === 143 /* MethodDeclaration */ || node.kind === 174 /* ArrowFunction */) { var declarations = node.typeParameters; if (declarations) { return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); @@ -15352,7 +15737,7 @@ var ts; } // The outer type parameters are those defined by enclosing generic classes, methods, or functions. function getOuterTypeParametersOfClassOrInterface(symbol) { - var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 213 /* InterfaceDeclaration */); + var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 215 /* InterfaceDeclaration */); return appendOuterTypeParameters(undefined, declaration); } // The local type parameters are the combined set of type parameters from all declarations of the class, @@ -15361,8 +15746,8 @@ var ts; var result; for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var node = _a[_i]; - if (node.kind === 213 /* InterfaceDeclaration */ || node.kind === 212 /* ClassDeclaration */ || - node.kind === 184 /* ClassExpression */ || node.kind === 214 /* TypeAliasDeclaration */) { + if (node.kind === 215 /* InterfaceDeclaration */ || node.kind === 214 /* ClassDeclaration */ || + node.kind === 186 /* ClassExpression */ || node.kind === 216 /* TypeAliasDeclaration */) { var declaration = node; if (declaration.typeParameters) { result = appendTypeParameters(result, declaration.typeParameters); @@ -15482,7 +15867,7 @@ var ts; type.resolvedBaseTypes = []; for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) { var declaration = _a[_i]; - if (declaration.kind === 213 /* InterfaceDeclaration */ && ts.getInterfaceBaseTypeNodes(declaration)) { + if (declaration.kind === 215 /* InterfaceDeclaration */ && ts.getInterfaceBaseTypeNodes(declaration)) { for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) { var node = _c[_b]; var baseType = getTypeFromTypeNode(node); @@ -15503,6 +15888,32 @@ var ts; } } } + // Returns true if the interface given by the symbol is free of "this" references. Specifically, the result is + // true if the interface itself contains no references to "this" in its body, if all base types are interfaces, + // and if none of the base interfaces have a "this" type. + function isIndependentInterface(symbol) { + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var declaration = _a[_i]; + if (declaration.kind === 215 /* InterfaceDeclaration */) { + if (declaration.flags & 524288 /* ContainsThis */) { + return false; + } + var baseTypeNodes = ts.getInterfaceBaseTypeNodes(declaration); + if (baseTypeNodes) { + for (var _b = 0; _b < baseTypeNodes.length; _b++) { + var node = baseTypeNodes[_b]; + if (ts.isSupportedExpressionWithTypeArguments(node)) { + var baseSymbol = resolveEntityName(node.expression, 793056 /* Type */, /*ignoreErrors*/ true); + if (!baseSymbol || !(baseSymbol.flags & 64 /* Interface */) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) { + return false; + } + } + } + } + } + } + return true; + } function getDeclaredTypeOfClassOrInterface(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { @@ -15510,7 +15921,12 @@ var ts; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); - if (outerTypeParameters || localTypeParameters) { + // A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type + // because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular, + // property types inferred from initializers and method return types inferred from return statements are very hard + // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of + // "this" references. + if (outerTypeParameters || localTypeParameters || kind === 1024 /* Class */ || !isIndependentInterface(symbol)) { type.flags |= 4096 /* Reference */; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; @@ -15519,6 +15935,9 @@ var ts; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; + type.thisType = createType(512 /* TypeParameter */ | 33554432 /* ThisType */); + type.thisType.symbol = symbol; + type.thisType.constraint = getTypeWithThisArgument(type); } } return links.declaredType; @@ -15531,7 +15950,7 @@ var ts; if (!pushTypeResolution(symbol, 2 /* DeclaredType */)) { return unknownType; } - var declaration = ts.getDeclarationOfKind(symbol, 214 /* TypeAliasDeclaration */); + var declaration = ts.getDeclarationOfKind(symbol, 216 /* TypeAliasDeclaration */); var type = getTypeFromTypeNode(declaration.type); if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); @@ -15564,7 +15983,7 @@ var ts; if (!links.declaredType) { var type = createType(512 /* TypeParameter */); type.symbol = symbol; - if (!ts.getDeclarationOfKind(symbol, 135 /* TypeParameter */).constraint) { + if (!ts.getDeclarationOfKind(symbol, 137 /* TypeParameter */).constraint) { type.constraint = noConstraintType; } links.declaredType = type; @@ -15597,6 +16016,79 @@ var ts; } return unknownType; } + // A type reference is considered independent if each type argument is considered independent. + function isIndependentTypeReference(node) { + if (node.typeArguments) { + for (var _i = 0, _a = node.typeArguments; _i < _a.length; _i++) { + var typeNode = _a[_i]; + if (!isIndependentType(typeNode)) { + return false; + } + } + } + return true; + } + // A type is considered independent if it the any, string, number, boolean, symbol, or void keyword, a string + // literal type, an array with an element type that is considered independent, or a type reference that is + // considered independent. + function isIndependentType(node) { + switch (node.kind) { + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: + case 9 /* StringLiteral */: + return true; + case 156 /* ArrayType */: + return isIndependentType(node.elementType); + case 151 /* TypeReference */: + return isIndependentTypeReference(node); + } + return false; + } + // A variable-like declaration is considered independent (free of this references) if it has a type annotation + // that specifies an independent type, or if it has no type annotation and no initializer (and thus of type any). + function isIndependentVariableLikeDeclaration(node) { + return node.type && isIndependentType(node.type) || !node.type && !node.initializer; + } + // A function-like declaration is considered independent (free of this references) if it has a return type + // annotation that is considered independent and if each parameter is considered independent. + function isIndependentFunctionLikeDeclaration(node) { + if (node.kind !== 144 /* Constructor */ && (!node.type || !isIndependentType(node.type))) { + return false; + } + for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) { + var parameter = _a[_i]; + if (!isIndependentVariableLikeDeclaration(parameter)) { + return false; + } + } + return true; + } + // Returns true if the class or interface member given by the symbol is free of "this" references. The + // function may return false for symbols that are actually free of "this" references because it is not + // feasible to perform a complete analysis in all cases. In particular, property members with types + // inferred from their initializers and function members with inferred return types are convervatively + // assumed not to be free of "this" references. + function isIndependentMember(symbol) { + if (symbol.declarations && symbol.declarations.length === 1) { + var declaration = symbol.declarations[0]; + if (declaration) { + switch (declaration.kind) { + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + return isIndependentVariableLikeDeclaration(declaration); + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + return isIndependentFunctionLikeDeclaration(declaration); + } + } + } + return false; + } function createSymbolTable(symbols) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { @@ -15605,11 +16097,13 @@ var ts; } return result; } - function createInstantiatedSymbolTable(symbols, mapper) { + // The mappingThisOnly flag indicates that the only type parameter being mapped is "this". When the flag is true, + // we check symbols to see if we can quickly conclude they are free of "this" references, thus needing no instantiation. + function createInstantiatedSymbolTable(symbols, mapper, mappingThisOnly) { var result = {}; for (var _i = 0; _i < symbols.length; _i++) { var symbol = symbols[_i]; - result[symbol.name] = instantiateSymbol(symbol, mapper); + result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper); } return result; } @@ -15640,44 +16134,54 @@ var ts; } return type; } - function resolveClassOrInterfaceMembers(type) { - var target = resolveDeclaredMembers(type); - var members = target.symbol.members; - var callSignatures = target.declaredCallSignatures; - var constructSignatures = target.declaredConstructSignatures; - var stringIndexType = target.declaredStringIndexType; - var numberIndexType = target.declaredNumberIndexType; - var baseTypes = getBaseTypes(target); + function getTypeWithThisArgument(type, thisArgument) { + if (type.flags & 4096 /* Reference */) { + return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType])); + } + return type; + } + function resolveObjectTypeMembers(type, source, typeParameters, typeArguments) { + var mapper = identityMapper; + var members = source.symbol.members; + var callSignatures = source.declaredCallSignatures; + var constructSignatures = source.declaredConstructSignatures; + var stringIndexType = source.declaredStringIndexType; + var numberIndexType = source.declaredNumberIndexType; + if (!ts.rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { + mapper = createTypeMapper(typeParameters, typeArguments); + members = createInstantiatedSymbolTable(source.declaredProperties, mapper, /*mappingThisOnly*/ typeParameters.length === 1); + callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); + constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); + stringIndexType = instantiateType(source.declaredStringIndexType, mapper); + numberIndexType = instantiateType(source.declaredNumberIndexType, mapper); + } + var baseTypes = getBaseTypes(source); if (baseTypes.length) { - members = createSymbolTable(target.declaredProperties); + if (members === source.symbol.members) { + members = createSymbolTable(source.declaredProperties); + } + var thisArgument = ts.lastOrUndefined(typeArguments); for (var _i = 0; _i < baseTypes.length; _i++) { var baseType = baseTypes[_i]; - addInheritedMembers(members, getPropertiesOfObjectType(baseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0 /* Call */)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1 /* Construct */)); - stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0 /* String */); - numberIndexType = numberIndexType || getIndexTypeOfType(baseType, 1 /* Number */); + var instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType; + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); + callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); + constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); + stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); + numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1 /* Number */); } } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } + function resolveClassOrInterfaceMembers(type) { + resolveObjectTypeMembers(type, resolveDeclaredMembers(type), emptyArray, emptyArray); + } function resolveTypeReferenceMembers(type) { - var target = resolveDeclaredMembers(type.target); - var mapper = createTypeMapper(target.typeParameters, type.typeArguments); - var members = createInstantiatedSymbolTable(target.declaredProperties, mapper); - var callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature); - var constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature); - var stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined; - var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; - ts.forEach(getBaseTypes(target), function (baseType) { - var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); - callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); - constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); - stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); - numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1 /* Number */); - }); - setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + var source = resolveDeclaredMembers(type.target); + var typeParameters = ts.concatenate(source.typeParameters, [source.thisType]); + var typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ? + type.typeArguments : ts.concatenate(type.typeArguments, [type]); + resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); @@ -15726,7 +16230,9 @@ var ts; return members; } function resolveTupleTypeMembers(type) { - var arrayType = resolveStructuredTypeMembers(createArrayType(getUnionType(type.elementTypes, /*noSubtypeReduction*/ true))); + var arrayElementType = getUnionType(type.elementTypes, /*noSubtypeReduction*/ true); + // Make the tuple type itself the 'this' type by including an extra type argument + var arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); @@ -15842,7 +16348,14 @@ var ts; var constructSignatures; var stringIndexType; var numberIndexType; - if (symbol.flags & 2048 /* TypeLiteral */) { + if (type.target) { + members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); + callSignatures = instantiateList(getSignaturesOfType(type.target, 0 /* Call */), type.mapper, instantiateSignature); + constructSignatures = instantiateList(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper, instantiateSignature); + stringIndexType = instantiateType(getIndexTypeOfType(type.target, 0 /* String */), type.mapper); + numberIndexType = instantiateType(getIndexTypeOfType(type.target, 1 /* Number */), type.mapper); + } + else if (symbol.flags & 2048 /* TypeLiteral */) { members = symbol.members; callSignatures = getSignaturesOfSymbol(members["__call"]); constructSignatures = getSignaturesOfSymbol(members["__new"]); @@ -15879,7 +16392,10 @@ var ts; } function resolveStructuredTypeMembers(type) { if (!type.members) { - if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { + if (type.flags & 4096 /* Reference */) { + resolveTypeReferenceMembers(type); + } + else if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { resolveClassOrInterfaceMembers(type); } else if (type.flags & 65536 /* Anonymous */) { @@ -15894,9 +16410,6 @@ var ts; else if (type.flags & 32768 /* Intersection */) { resolveIntersectionTypeMembers(type); } - else { - resolveTypeReferenceMembers(type); - } } return type; } @@ -16125,7 +16638,7 @@ var ts; function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { - var classType = declaration.kind === 142 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; + var classType = declaration.kind === 144 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; @@ -16157,7 +16670,7 @@ var ts; } else if (declaration.type) { returnType = getTypeFromTypeNode(declaration.type); - if (declaration.type.kind === 148 /* TypePredicate */) { + if (declaration.type.kind === 150 /* TypePredicate */) { var typePredicateNode = declaration.type; typePredicate = { parameterName: typePredicateNode.parameterName ? typePredicateNode.parameterName.text : undefined, @@ -16169,8 +16682,8 @@ var ts; else { // TypeScript 1.0 spec (April 2014): // If only one accessor includes a type annotation, the other behaves as if it had the same type annotation. - if (declaration.kind === 143 /* GetAccessor */ && !ts.hasDynamicName(declaration)) { - var setter = ts.getDeclarationOfKind(declaration.symbol, 144 /* SetAccessor */); + if (declaration.kind === 145 /* GetAccessor */ && !ts.hasDynamicName(declaration)) { + var setter = ts.getDeclarationOfKind(declaration.symbol, 146 /* SetAccessor */); returnType = getAnnotatedAccessorType(setter); } if (!returnType && ts.nodeIsMissing(declaration.body)) { @@ -16188,19 +16701,19 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: // Don't include signature if node is the implementation of an overloaded function. A node is considered // an implementation node if it has a body and the previous node is of the same kind and immediately // precedes the implementation node (i.e. has the same parent and ends where the implementation starts). @@ -16277,7 +16790,7 @@ var ts; // object type literal or interface (using the new keyword). Each way of declaring a constructor // will result in a different declaration kind. if (!signature.isolatedSignatureType) { - var isConstructor = signature.declaration.kind === 142 /* Constructor */ || signature.declaration.kind === 146 /* ConstructSignature */; + var isConstructor = signature.declaration.kind === 144 /* Constructor */ || signature.declaration.kind === 148 /* ConstructSignature */; var type = createObjectType(65536 /* Anonymous */ | 262144 /* FromSignature */); type.members = emptySymbols; type.properties = emptyArray; @@ -16291,7 +16804,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 /* Number */ ? 126 /* NumberKeyword */ : 128 /* StringKeyword */; + var syntaxKind = kind === 1 /* Number */ ? 128 /* NumberKeyword */ : 130 /* StringKeyword */; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) { @@ -16320,30 +16833,33 @@ var ts; type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType; } else { - type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 135 /* TypeParameter */).constraint); + type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 137 /* TypeParameter */).constraint); } } return type.constraint === noConstraintType ? undefined : type.constraint; } function getParentSymbolOfTypeParameter(typeParameter) { - return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 135 /* TypeParameter */).parent); + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 137 /* TypeParameter */).parent); } function getTypeListId(types) { - switch (types.length) { - case 1: - return "" + types[0].id; - case 2: - return types[0].id + "," + types[1].id; - default: - var result = ""; - for (var i = 0; i < types.length; i++) { - if (i > 0) { - result += ","; + if (types) { + switch (types.length) { + case 1: + return "" + types[0].id; + case 2: + return types[0].id + "," + types[1].id; + default: + var result = ""; + for (var i = 0; i < types.length; i++) { + if (i > 0) { + result += ","; + } + result += types[i].id; } - result += types[i].id; - } - return result; + return result; + } } + return ""; } // This function is used to propagate certain flags when creating new object type references and union types. // It is only necessary to do so if a constituent type might be the undefined type, the null type, the type @@ -16361,7 +16877,7 @@ var ts; var id = getTypeListId(typeArguments); var type = target.instantiations[id]; if (!type) { - var flags = 4096 /* Reference */ | getPropagatingFlagsOfTypes(typeArguments); + var flags = 4096 /* Reference */ | (typeArguments ? getPropagatingFlagsOfTypes(typeArguments) : 0); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -16380,13 +16896,13 @@ var ts; currentNode = currentNode.parent; } // if last step was made from the type parameter this means that path has started somewhere in constraint which is illegal - links.isIllegalTypeReferenceInConstraint = currentNode.kind === 135 /* TypeParameter */; + links.isIllegalTypeReferenceInConstraint = currentNode.kind === 137 /* TypeParameter */; return links.isIllegalTypeReferenceInConstraint; } function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) { var typeParameterSymbol; function check(n) { - if (n.kind === 149 /* TypeReference */ && n.typeName.kind === 67 /* Identifier */) { + if (n.kind === 151 /* TypeReference */ && n.typeName.kind === 69 /* Identifier */) { var links = getNodeLinks(n); if (links.isIllegalTypeReferenceInConstraint === undefined) { var symbol = resolveName(typeParameter, n.typeName.text, 793056 /* Type */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); @@ -16473,7 +16989,7 @@ var ts; var links = getNodeLinks(node); if (!links.resolvedType) { // We only support expressions that are simple qualified names. For other expressions this produces undefined. - var typeNameOrExpression = node.kind === 149 /* TypeReference */ ? node.typeName : + var typeNameOrExpression = node.kind === 151 /* TypeReference */ ? node.typeName : ts.isSupportedExpressionWithTypeArguments(node) ? node.expression : undefined; var symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, 793056 /* Type */) || unknownSymbol; @@ -16505,9 +17021,9 @@ var ts; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; switch (declaration.kind) { - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: return declaration; } } @@ -16567,17 +17083,17 @@ var ts; /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ - function createTypeFromGenericGlobalType(genericGlobalType, elementType) { - return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + function createTypeFromGenericGlobalType(genericGlobalType, typeArguments) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, typeArguments) : emptyObjectType; } function createIterableType(elementType) { - return createTypeFromGenericGlobalType(globalIterableType, elementType); + return createTypeFromGenericGlobalType(globalIterableType, [elementType]); } function createIterableIteratorType(elementType) { - return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); + return createTypeFromGenericGlobalType(globalIterableIteratorType, [elementType]); } function createArrayType(elementType) { - return createTypeFromGenericGlobalType(globalArrayType, elementType); + return createTypeFromGenericGlobalType(globalArrayType, [elementType]); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -16749,48 +17265,68 @@ var ts; } return links.resolvedType; } + function getThisType(node) { + var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false); + var parent = container && container.parent; + if (parent && (ts.isClassLike(parent) || parent.kind === 215 /* InterfaceDeclaration */)) { + if (!(container.flags & 128 /* Static */)) { + return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType; + } + } + error(node, ts.Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface); + return unknownType; + } + function getTypeFromThisTypeNode(node) { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getThisType(node); + } + return links.resolvedType; + } function getTypeFromTypeNode(node) { switch (node.kind) { - case 115 /* AnyKeyword */: + case 117 /* AnyKeyword */: return anyType; - case 128 /* StringKeyword */: + case 130 /* StringKeyword */: return stringType; - case 126 /* NumberKeyword */: + case 128 /* NumberKeyword */: return numberType; - case 118 /* BooleanKeyword */: + case 120 /* BooleanKeyword */: return booleanType; - case 129 /* SymbolKeyword */: + case 131 /* SymbolKeyword */: return esSymbolType; - case 101 /* VoidKeyword */: + case 103 /* VoidKeyword */: return voidType; + case 97 /* ThisKeyword */: + return getTypeFromThisTypeNode(node); case 9 /* StringLiteral */: return getTypeFromStringLiteral(node); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return getTypeFromTypeReference(node); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return booleanType; - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return getTypeFromTypeQueryNode(node); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return getTypeFromArrayTypeNode(node); - case 155 /* TupleType */: + case 157 /* TupleType */: return getTypeFromTupleTypeNode(node); - case 156 /* UnionType */: + case 158 /* UnionType */: return getTypeFromUnionTypeNode(node); - case 157 /* IntersectionType */: + case 159 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return getTypeFromTypeNode(node.type); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 153 /* TypeLiteral */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 155 /* TypeLiteral */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode - case 67 /* Identifier */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 135 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: @@ -16894,7 +17430,7 @@ var ts; type: instantiateType(signature.typePredicate.type, mapper) }; } - var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), signature.resolvedReturnType ? instantiateType(signature.resolvedReturnType, mapper) : undefined, freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -16932,21 +17468,13 @@ var ts; } // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it var result = createObjectType(65536 /* Anonymous */ | 131072 /* Instantiated */, type.symbol); - result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); - result.members = createSymbolTable(result.properties); - result.callSignatures = instantiateList(getSignaturesOfType(type, 0 /* Call */), mapper, instantiateSignature); - result.constructSignatures = instantiateList(getSignaturesOfType(type, 1 /* Construct */), mapper, instantiateSignature); - var stringIndexType = getIndexTypeOfType(type, 0 /* String */); - var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); - if (stringIndexType) - result.stringIndexType = instantiateType(stringIndexType, mapper); - if (numberIndexType) - result.numberIndexType = instantiateType(numberIndexType, mapper); + result.target = type; + result.mapper = mapper; mapper.instantiations[type.id] = result; return result; } function instantiateType(type, mapper) { - if (mapper !== identityMapper) { + if (type && mapper !== identityMapper) { if (type.flags & 512 /* TypeParameter */) { return mapper(type); } @@ -16972,27 +17500,27 @@ var ts; // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. function isContextSensitive(node) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); switch (node.kind) { - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return isContextSensitiveFunctionLikeDeclaration(node); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return ts.forEach(node.properties, isContextSensitive); - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return ts.forEach(node.elements, isContextSensitive); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse); - case 179 /* BinaryExpression */: - return node.operatorToken.kind === 51 /* BarBarToken */ && + case 181 /* BinaryExpression */: + return node.operatorToken.kind === 52 /* BarBarToken */ && (isContextSensitive(node.left) || isContextSensitive(node.right)); - case 243 /* PropertyAssignment */: + case 245 /* PropertyAssignment */: return isContextSensitive(node.initializer); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return isContextSensitiveFunctionLikeDeclaration(node); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return isContextSensitive(node.expression); } return false; @@ -17176,7 +17704,7 @@ var ts; else { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, reportErrors)) { + if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } @@ -17205,7 +17733,7 @@ var ts; if (source.flags & 80896 /* ObjectType */ && target.flags & 80896 /* ObjectType */) { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if all type arguments are identical - if (result = typesRelatedTo(source.typeArguments, target.typeArguments, /*reportErrors*/ false)) { + if (result = typeArgumentsRelatedTo(source, target, /*reportErrors*/ false)) { return result; } } @@ -17322,9 +17850,14 @@ var ts; } return result; } - function typesRelatedTo(sources, targets, reportErrors) { + function typeArgumentsRelatedTo(source, target, reportErrors) { + var sources = source.typeArguments || emptyArray; + var targets = target.typeArguments || emptyArray; + if (sources.length !== targets.length && relation === identityRelation) { + return 0 /* False */; + } var result = -1 /* True */; - for (var i = 0, len = sources.length; i < len; i++) { + for (var i = 0; i < targets.length; i++) { var related = isRelatedTo(sources[i], targets[i], reportErrors); if (!related) { return 0 /* False */; @@ -17542,7 +18075,7 @@ var ts; if (kind === 1 /* Construct */) { // Only want to compare the construct signatures for abstractness guarantees. // Because the "abstractness" of a class is the same across all construct signatures - // (internally we are checking the corresponding declaration), it is enough to perform + // (internally we are checking the corresponding declaration), it is enough to perform // the check and report an error once over all pairs of source and target construct signatures. // // sourceSig and targetSig are (possibly) undefined. @@ -18042,22 +18575,22 @@ var ts; var typeAsString = typeToString(getWidenedType(type)); var diagnostic; switch (declaration.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; - case 136 /* Parameter */: + case 138 /* Parameter */: diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; break; - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: if (!declaration.name) { error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); return; @@ -18167,9 +18700,10 @@ var ts; } else if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // If source and target are references to the same generic type, infer from type arguments - var sourceTypes = source.typeArguments; - var targetTypes = target.typeArguments; - for (var i = 0; i < sourceTypes.length; i++) { + var sourceTypes = source.typeArguments || emptyArray; + var targetTypes = target.typeArguments || emptyArray; + var count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length; + for (var i = 0; i < count; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } @@ -18347,10 +18881,10 @@ var ts; // The expression is restricted to a single identifier or a sequence of identifiers separated by periods while (node) { switch (node.kind) { - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return true; - case 67 /* Identifier */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 135 /* QualifiedName */: node = node.parent; continue; default: @@ -18396,12 +18930,12 @@ var ts; } return links.assignmentChecks[symbol.id] = isAssignedIn(node); function isAssignedInBinaryExpression(node) { - if (node.operatorToken.kind >= 55 /* FirstAssignment */ && node.operatorToken.kind <= 66 /* LastAssignment */) { + if (node.operatorToken.kind >= 56 /* FirstAssignment */ && node.operatorToken.kind <= 68 /* LastAssignment */) { var n = node.left; - while (n.kind === 170 /* ParenthesizedExpression */) { + while (n.kind === 172 /* ParenthesizedExpression */) { n = n.expression; } - if (n.kind === 67 /* Identifier */ && getResolvedSymbol(n) === symbol) { + if (n.kind === 69 /* Identifier */ && getResolvedSymbol(n) === symbol) { return true; } } @@ -18415,55 +18949,55 @@ var ts; } function isAssignedIn(node) { switch (node.kind) { - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return isAssignedInBinaryExpression(node); - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: return isAssignedInVariableDeclaration(node); - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: - case 162 /* ArrayLiteralExpression */: - case 163 /* ObjectLiteralExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: - case 170 /* ParenthesizedExpression */: - case 177 /* PrefixUnaryExpression */: - case 173 /* DeleteExpression */: - case 176 /* AwaitExpression */: - case 174 /* TypeOfExpression */: - case 175 /* VoidExpression */: - case 178 /* PostfixUnaryExpression */: - case 182 /* YieldExpression */: - case 180 /* ConditionalExpression */: - case 183 /* SpreadElementExpression */: - case 190 /* Block */: - case 191 /* VariableStatement */: - case 193 /* ExpressionStatement */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 202 /* ReturnStatement */: - case 203 /* WithStatement */: - case 204 /* SwitchStatement */: - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - case 205 /* LabeledStatement */: - case 206 /* ThrowStatement */: - case 207 /* TryStatement */: - case 242 /* CatchClause */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 236 /* JsxAttribute */: - case 237 /* JsxSpreadAttribute */: - case 233 /* JsxOpeningElement */: - case 238 /* JsxExpression */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: + case 164 /* ArrayLiteralExpression */: + case 165 /* ObjectLiteralExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: + case 172 /* ParenthesizedExpression */: + case 179 /* PrefixUnaryExpression */: + case 175 /* DeleteExpression */: + case 178 /* AwaitExpression */: + case 176 /* TypeOfExpression */: + case 177 /* VoidExpression */: + case 180 /* PostfixUnaryExpression */: + case 184 /* YieldExpression */: + case 182 /* ConditionalExpression */: + case 185 /* SpreadElementExpression */: + case 192 /* Block */: + case 193 /* VariableStatement */: + case 195 /* ExpressionStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 204 /* ReturnStatement */: + case 205 /* WithStatement */: + case 206 /* SwitchStatement */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + case 207 /* LabeledStatement */: + case 208 /* ThrowStatement */: + case 209 /* TryStatement */: + case 244 /* CatchClause */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 238 /* JsxAttribute */: + case 239 /* JsxSpreadAttribute */: + case 235 /* JsxOpeningElement */: + case 240 /* JsxExpression */: return ts.forEachChild(node, isAssignedIn); } return false; @@ -18480,37 +19014,37 @@ var ts; node = node.parent; var narrowedType = type; switch (node.kind) { - case 194 /* IfStatement */: + case 196 /* IfStatement */: // In a branch of an if statement, narrow based on controlling expression if (child !== node.expression) { narrowedType = narrowType(type, node.expression, /*assumeTrue*/ child === node.thenStatement); } break; - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: // In a branch of a conditional expression, narrow based on controlling condition if (child !== node.condition) { narrowedType = narrowType(type, node.condition, /*assumeTrue*/ child === node.whenTrue); } break; - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: // In the right operand of an && or ||, narrow based on left operand if (child === node.right) { - if (node.operatorToken.kind === 50 /* AmpersandAmpersandToken */) { + if (node.operatorToken.kind === 51 /* AmpersandAmpersandToken */) { narrowedType = narrowType(type, node.left, /*assumeTrue*/ true); } - else if (node.operatorToken.kind === 51 /* BarBarToken */) { + else if (node.operatorToken.kind === 52 /* BarBarToken */) { narrowedType = narrowType(type, node.left, /*assumeTrue*/ false); } } break; - case 246 /* SourceFile */: - case 216 /* ModuleDeclaration */: - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: + case 248 /* SourceFile */: + case 218 /* ModuleDeclaration */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: // Stop at the first containing function or module declaration break loop; } @@ -18527,12 +19061,12 @@ var ts; return type; function narrowTypeByEquality(type, expr, assumeTrue) { // Check that we have 'typeof ' on the left and string literal on the right - if (expr.left.kind !== 174 /* TypeOfExpression */ || expr.right.kind !== 9 /* StringLiteral */) { + if (expr.left.kind !== 176 /* TypeOfExpression */ || expr.right.kind !== 9 /* StringLiteral */) { return type; } var left = expr.left; var right = expr.right; - if (left.expression.kind !== 67 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { + if (left.expression.kind !== 69 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { return type; } var typeInfo = primitiveTypeInfo[right.text]; @@ -18592,7 +19126,7 @@ var ts; } function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left - if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 67 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { + if (isTypeAny(type) || !assumeTrue || expr.left.kind !== 69 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -18664,27 +19198,27 @@ var ts; // will be a subtype or the same type as the argument. function narrowType(type, expr, assumeTrue) { switch (expr.kind) { - case 166 /* CallExpression */: + case 168 /* CallExpression */: return narrowTypeByTypePredicate(type, expr, assumeTrue); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return narrowType(type, expr.expression, assumeTrue); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: var operator = expr.operatorToken.kind; if (operator === 32 /* EqualsEqualsEqualsToken */ || operator === 33 /* ExclamationEqualsEqualsToken */) { return narrowTypeByEquality(type, expr, assumeTrue); } - else if (operator === 50 /* AmpersandAmpersandToken */) { + else if (operator === 51 /* AmpersandAmpersandToken */) { return narrowTypeByAnd(type, expr, assumeTrue); } - else if (operator === 51 /* BarBarToken */) { + else if (operator === 52 /* BarBarToken */) { return narrowTypeByOr(type, expr, assumeTrue); } - else if (operator === 89 /* InstanceOfKeyword */) { + else if (operator === 91 /* InstanceOfKeyword */) { return narrowTypeByInstanceof(type, expr, assumeTrue); } break; - case 177 /* PrefixUnaryExpression */: - if (expr.operator === 48 /* ExclamationToken */) { + case 179 /* PrefixUnaryExpression */: + if (expr.operator === 49 /* ExclamationToken */) { return narrowType(type, expr.operand, !assumeTrue); } break; @@ -18702,7 +19236,7 @@ var ts; // can explicitly bound arguments objects if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); - if (container.kind === 172 /* ArrowFunction */) { + if (container.kind === 174 /* ArrowFunction */) { if (languageVersion < 2 /* ES6 */) { error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } @@ -18733,7 +19267,7 @@ var ts; function checkBlockScopedBindingCapturedInLoop(node, symbol) { if (languageVersion >= 2 /* ES6 */ || (symbol.flags & 2 /* BlockScopedVariable */) === 0 || - symbol.valueDeclaration.parent.kind === 242 /* CatchClause */) { + symbol.valueDeclaration.parent.kind === 244 /* CatchClause */) { return; } // - check if binding is used in some function @@ -18742,12 +19276,12 @@ var ts; // nesting structure: // (variable declaration or binding element) -> variable declaration list -> container var container = symbol.valueDeclaration; - while (container.kind !== 210 /* VariableDeclarationList */) { + while (container.kind !== 212 /* VariableDeclarationList */) { container = container.parent; } // get the parent of variable declaration list container = container.parent; - if (container.kind === 191 /* VariableStatement */) { + if (container.kind === 193 /* VariableStatement */) { // if parent is variable statement - get its parent container = container.parent; } @@ -18767,7 +19301,7 @@ var ts; } function captureLexicalThis(node, container) { getNodeLinks(node).flags |= 2 /* LexicalThis */; - if (container.kind === 139 /* PropertyDeclaration */ || container.kind === 142 /* Constructor */) { + if (container.kind === 141 /* PropertyDeclaration */ || container.kind === 144 /* Constructor */) { var classNode = container.parent; getNodeLinks(classNode).flags |= 4 /* CaptureThis */; } @@ -18781,32 +19315,32 @@ var ts; var container = ts.getThisContainer(node, /* includeArrowFunctions */ true); var needToCaptureLexicalThis = false; // Now skip arrow functions to get the "real" owner of 'this'. - if (container.kind === 172 /* ArrowFunction */) { + if (container.kind === 174 /* ArrowFunction */) { container = ts.getThisContainer(container, /* includeArrowFunctions */ false); // When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code needToCaptureLexicalThis = (languageVersion < 2 /* ES6 */); } switch (container.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; - case 142 /* Constructor */: + case 144 /* Constructor */: if (isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments); } break; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: if (container.flags & 128 /* Static */) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; } @@ -18815,35 +19349,35 @@ var ts; } if (ts.isClassLike(container.parent)) { var symbol = getSymbolOfNode(container.parent); - return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); + return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol).thisType; } return anyType; } function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { - if (n.kind === 136 /* Parameter */) { + if (n.kind === 138 /* Parameter */) { return true; } } return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 166 /* CallExpression */ && node.parent.expression === node; + var isCallExpression = node.parent.kind === 168 /* CallExpression */ && node.parent.expression === node; var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; var container = ts.getSuperContainer(node, /*includeFunctions*/ true); var needToCaptureLexicalThis = false; if (!isCallExpression) { - // adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting - while (container && container.kind === 172 /* ArrowFunction */) { + // adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting + while (container && container.kind === 174 /* ArrowFunction */) { container = ts.getSuperContainer(container, /*includeFunctions*/ true); needToCaptureLexicalThis = languageVersion < 2 /* ES6 */; } } var canUseSuperExpression = isLegalUsageOfSuperExpression(container); var nodeCheckFlag = 0; - // always set NodeCheckFlags for 'super' expression node + // always set NodeCheckFlags for 'super' expression node if (canUseSuperExpression) { if ((container.flags & 128 /* Static */) || isCallExpression) { nodeCheckFlag = 512 /* SuperStatic */; @@ -18866,7 +19400,7 @@ var ts; return unknownType; } if (!canUseSuperExpression) { - if (container && container.kind === 134 /* ComputedPropertyName */) { + if (container && container.kind === 136 /* ComputedPropertyName */) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { @@ -18877,7 +19411,7 @@ var ts; } return unknownType; } - if (container.kind === 142 /* Constructor */ && isInConstructorArgumentInitializer(node, container)) { + if (container.kind === 144 /* Constructor */ && isInConstructorArgumentInitializer(node, container)) { // issue custom error message for super property access in constructor arguments (to be aligned with old compiler) error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments); return unknownType; @@ -18892,7 +19426,7 @@ var ts; if (isCallExpression) { // TS 1.0 SPEC (April 2014): 4.8.1 // Super calls are only permitted in constructors of derived classes - return container.kind === 142 /* Constructor */; + return container.kind === 144 /* Constructor */; } else { // TS 1.0 SPEC (April 2014) @@ -18902,19 +19436,19 @@ var ts; // topmost container must be something that is directly nested in the class declaration if (container && ts.isClassLike(container.parent)) { if (container.flags & 128 /* Static */) { - return container.kind === 141 /* MethodDeclaration */ || - container.kind === 140 /* MethodSignature */ || - container.kind === 143 /* GetAccessor */ || - container.kind === 144 /* SetAccessor */; + return container.kind === 143 /* MethodDeclaration */ || + container.kind === 142 /* MethodSignature */ || + container.kind === 145 /* GetAccessor */ || + container.kind === 146 /* SetAccessor */; } else { - return container.kind === 141 /* MethodDeclaration */ || - container.kind === 140 /* MethodSignature */ || - container.kind === 143 /* GetAccessor */ || - container.kind === 144 /* SetAccessor */ || - container.kind === 139 /* PropertyDeclaration */ || - container.kind === 138 /* PropertySignature */ || - container.kind === 142 /* Constructor */; + return container.kind === 143 /* MethodDeclaration */ || + container.kind === 142 /* MethodSignature */ || + container.kind === 145 /* GetAccessor */ || + container.kind === 146 /* SetAccessor */ || + container.kind === 141 /* PropertyDeclaration */ || + container.kind === 140 /* PropertySignature */ || + container.kind === 144 /* Constructor */; } } } @@ -18955,7 +19489,7 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 136 /* Parameter */) { + if (declaration.kind === 138 /* Parameter */) { var type = getContextuallyTypedParameterType(declaration); if (type) { return type; @@ -18988,7 +19522,7 @@ var ts; } function isInParameterInitializerBeforeContainingFunction(node) { while (node.parent && !ts.isFunctionLike(node.parent)) { - if (node.parent.kind === 136 /* Parameter */ && node.parent.initializer === node) { + if (node.parent.kind === 138 /* Parameter */ && node.parent.initializer === node) { return true; } node = node.parent; @@ -18999,8 +19533,8 @@ var ts; // If the containing function has a return type annotation, is a constructor, or is a get accessor whose // corresponding set accessor has a type annotation, return statements in the function are contextually typed if (functionDecl.type || - functionDecl.kind === 142 /* Constructor */ || - functionDecl.kind === 143 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 144 /* SetAccessor */))) { + functionDecl.kind === 144 /* Constructor */ || + functionDecl.kind === 145 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 146 /* SetAccessor */))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); } // Otherwise, if the containing function is contextually typed by a function type with exactly one call signature @@ -19022,7 +19556,7 @@ var ts; return undefined; } function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { - if (template.parent.kind === 168 /* TaggedTemplateExpression */) { + if (template.parent.kind === 170 /* TaggedTemplateExpression */) { return getContextualTypeForArgument(template.parent, substitutionExpression); } return undefined; @@ -19030,13 +19564,13 @@ var ts; function getContextualTypeForBinaryOperand(node) { var binaryExpression = node.parent; var operator = binaryExpression.operatorToken.kind; - if (operator >= 55 /* FirstAssignment */ && operator <= 66 /* LastAssignment */) { + if (operator >= 56 /* FirstAssignment */ && operator <= 68 /* LastAssignment */) { // In an assignment expression, the right operand is contextually typed by the type of the left operand. if (node === binaryExpression.right) { return checkExpression(binaryExpression.left); } } - else if (operator === 51 /* BarBarToken */) { + else if (operator === 52 /* BarBarToken */) { // When an || expression has a contextual type, the operands are contextually typed by that type. When an || // expression has no contextual type, the right operand is contextually typed by the type of the left operand. var type = getContextualType(binaryExpression); @@ -19143,7 +19677,7 @@ var ts; } function getContextualTypeForJsxExpression(expr) { // Contextual type only applies to JSX expressions that are in attribute assignments (not in 'Children' positions) - if (expr.parent.kind === 236 /* JsxAttribute */) { + if (expr.parent.kind === 238 /* JsxAttribute */) { var attrib = expr.parent; var attrsType = getJsxElementAttributesType(attrib.parent); if (!attrsType || isTypeAny(attrsType)) { @@ -19153,7 +19687,7 @@ var ts; return getTypeOfPropertyOfType(attrsType, attrib.name.text); } } - if (expr.kind === 237 /* JsxSpreadAttribute */) { + if (expr.kind === 239 /* JsxSpreadAttribute */) { return getJsxElementAttributesType(expr.parent); } return undefined; @@ -19174,38 +19708,38 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 209 /* VariableDeclaration */: - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 163 /* BindingElement */: return getContextualTypeForInitializerExpression(node); - case 172 /* ArrowFunction */: - case 202 /* ReturnStatement */: + case 174 /* ArrowFunction */: + case 204 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: return getContextualTypeForYieldOperand(parent); - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return getContextualTypeForArgument(parent, node); - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: return getTypeFromTypeNode(parent.type); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return getContextualTypeForBinaryOperand(node); - case 243 /* PropertyAssignment */: + case 245 /* PropertyAssignment */: return getContextualTypeForObjectLiteralElement(parent); - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return getContextualTypeForElementExpression(node); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); - case 188 /* TemplateSpan */: - ts.Debug.assert(parent.parent.kind === 181 /* TemplateExpression */); + case 190 /* TemplateSpan */: + ts.Debug.assert(parent.parent.kind === 183 /* TemplateExpression */); return getContextualTypeForSubstitutionExpression(parent.parent, node); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return getContextualType(parent); - case 238 /* JsxExpression */: - case 237 /* JsxSpreadAttribute */: + case 240 /* JsxExpression */: + case 239 /* JsxSpreadAttribute */: return getContextualTypeForJsxExpression(parent); } return undefined; @@ -19222,7 +19756,7 @@ var ts; } } function isFunctionExpressionOrArrowFunction(node) { - return node.kind === 171 /* FunctionExpression */ || node.kind === 172 /* ArrowFunction */; + return node.kind === 173 /* FunctionExpression */ || node.kind === 174 /* ArrowFunction */; } function getContextualSignatureForFunctionLikeDeclaration(node) { // Only function expressions, arrow functions, and object literal methods are contextually typed. @@ -19236,7 +19770,7 @@ var ts; // all identical ignoring their return type, the result is same signature but with return type as // union type of return types from these signatures function getContextualSignature(node) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); @@ -19299,13 +19833,13 @@ var ts; // an assignment target. Examples include 'a = xxx', '{ p: a } = xxx', '[{ p: a}] = xxx'. function isAssignmentTarget(node) { var parent = node.parent; - if (parent.kind === 179 /* BinaryExpression */ && parent.operatorToken.kind === 55 /* EqualsToken */ && parent.left === node) { + if (parent.kind === 181 /* BinaryExpression */ && parent.operatorToken.kind === 56 /* EqualsToken */ && parent.left === node) { return true; } - if (parent.kind === 243 /* PropertyAssignment */) { + if (parent.kind === 245 /* PropertyAssignment */) { return isAssignmentTarget(parent.parent); } - if (parent.kind === 162 /* ArrayLiteralExpression */) { + if (parent.kind === 164 /* ArrayLiteralExpression */) { return isAssignmentTarget(parent); } return false; @@ -19321,8 +19855,8 @@ var ts; return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false); } function hasDefaultValue(node) { - return (node.kind === 161 /* BindingElement */ && !!node.initializer) || - (node.kind === 179 /* BinaryExpression */ && node.operatorToken.kind === 55 /* EqualsToken */); + return (node.kind === 163 /* BindingElement */ && !!node.initializer) || + (node.kind === 181 /* BinaryExpression */ && node.operatorToken.kind === 56 /* EqualsToken */); } function checkArrayLiteral(node, contextualMapper) { var elements = node.elements; @@ -19331,7 +19865,7 @@ var ts; var inDestructuringPattern = isAssignmentTarget(node); for (var _i = 0; _i < elements.length; _i++) { var e = elements[_i]; - if (inDestructuringPattern && e.kind === 183 /* SpreadElementExpression */) { + if (inDestructuringPattern && e.kind === 185 /* SpreadElementExpression */) { // Given the following situation: // var c: {}; // [...c] = ["", 0]; @@ -19355,7 +19889,7 @@ var ts; var type = checkExpression(e, contextualMapper); elementTypes.push(type); } - hasSpreadElement = hasSpreadElement || e.kind === 183 /* SpreadElementExpression */; + hasSpreadElement = hasSpreadElement || e.kind === 185 /* SpreadElementExpression */; } if (!hasSpreadElement) { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such @@ -19370,7 +19904,7 @@ var ts; var pattern = contextualType.pattern; // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting // tuple type with the corresponding binding or assignment element types to make the lengths equal. - if (pattern && (pattern.kind === 160 /* ArrayBindingPattern */ || pattern.kind === 162 /* ArrayLiteralExpression */)) { + if (pattern && (pattern.kind === 162 /* ArrayBindingPattern */ || pattern.kind === 164 /* ArrayLiteralExpression */)) { var patternElements = pattern.elements; for (var i = elementTypes.length; i < patternElements.length; i++) { var patternElement = patternElements[i]; @@ -19378,7 +19912,7 @@ var ts; elementTypes.push(contextualType.elementTypes[i]); } else { - if (patternElement.kind !== 185 /* OmittedExpression */) { + if (patternElement.kind !== 187 /* OmittedExpression */) { error(patternElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); } elementTypes.push(unknownType); @@ -19393,7 +19927,7 @@ var ts; return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType); } function isNumericName(name) { - return name.kind === 134 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); + return name.kind === 136 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { // It seems odd to consider an expression of type Any to result in a numeric name, @@ -19443,30 +19977,30 @@ var ts; return links.resolvedType; } function checkObjectLiteral(node, contextualMapper) { + var inDestructuringPattern = isAssignmentTarget(node); // Grammar checking - checkGrammarObjectLiteralExpression(node); + checkGrammarObjectLiteralExpression(node, inDestructuringPattern); var propertiesTable = {}; var propertiesArray = []; var contextualType = getContextualType(node); var contextualTypeHasPattern = contextualType && contextualType.pattern && - (contextualType.pattern.kind === 159 /* ObjectBindingPattern */ || contextualType.pattern.kind === 163 /* ObjectLiteralExpression */); - var inDestructuringPattern = isAssignmentTarget(node); + (contextualType.pattern.kind === 161 /* ObjectBindingPattern */ || contextualType.pattern.kind === 165 /* ObjectLiteralExpression */); var typeFlags = 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var memberDecl = _a[_i]; var member = memberDecl.symbol; - if (memberDecl.kind === 243 /* PropertyAssignment */ || - memberDecl.kind === 244 /* ShorthandPropertyAssignment */ || + if (memberDecl.kind === 245 /* PropertyAssignment */ || + memberDecl.kind === 246 /* ShorthandPropertyAssignment */ || ts.isObjectLiteralMethod(memberDecl)) { var type = void 0; - if (memberDecl.kind === 243 /* PropertyAssignment */) { + if (memberDecl.kind === 245 /* PropertyAssignment */) { type = checkPropertyAssignment(memberDecl, contextualMapper); } - else if (memberDecl.kind === 141 /* MethodDeclaration */) { + else if (memberDecl.kind === 143 /* MethodDeclaration */) { type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - ts.Debug.assert(memberDecl.kind === 244 /* ShorthandPropertyAssignment */); + ts.Debug.assert(memberDecl.kind === 246 /* ShorthandPropertyAssignment */); type = checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; @@ -19474,7 +20008,9 @@ var ts; if (inDestructuringPattern) { // If object literal is an assignment pattern and if the assignment pattern specifies a default value // for the property, make the property optional. - if (memberDecl.kind === 243 /* PropertyAssignment */ && hasDefaultValue(memberDecl.initializer)) { + var isOptional = (memberDecl.kind === 245 /* PropertyAssignment */ && hasDefaultValue(memberDecl.initializer)) || + (memberDecl.kind === 246 /* ShorthandPropertyAssignment */ && memberDecl.objectAssignmentInitializer); + if (isOptional) { prop.flags |= 536870912 /* Optional */; } } @@ -19504,7 +20040,7 @@ var ts; // an ordinary function declaration(section 6.1) with no parameters. // A set accessor declaration is processed in the same manner // as an ordinary function declaration with a single parameter and a Void return type. - ts.Debug.assert(memberDecl.kind === 143 /* GetAccessor */ || memberDecl.kind === 144 /* SetAccessor */); + ts.Debug.assert(memberDecl.kind === 145 /* GetAccessor */ || memberDecl.kind === 146 /* SetAccessor */); checkAccessorDeclaration(memberDecl); } if (!ts.hasDynamicName(memberDecl)) { @@ -19566,7 +20102,7 @@ var ts; if (lhs.kind !== rhs.kind) { return false; } - if (lhs.kind === 67 /* Identifier */) { + if (lhs.kind === 69 /* Identifier */) { return lhs.text === rhs.text; } return lhs.right.text === rhs.right.text && @@ -19587,18 +20123,18 @@ var ts; for (var _i = 0, _a = node.children; _i < _a.length; _i++) { var child = _a[_i]; switch (child.kind) { - case 238 /* JsxExpression */: + case 240 /* JsxExpression */: checkJsxExpression(child); break; - case 231 /* JsxElement */: + case 233 /* JsxElement */: checkJsxElement(child); break; - case 232 /* JsxSelfClosingElement */: + case 234 /* JsxSelfClosingElement */: checkJsxSelfClosingElement(child); break; default: // No checks for JSX Text - ts.Debug.assert(child.kind === 234 /* JsxText */); + ts.Debug.assert(child.kind === 236 /* JsxText */); } } return jsxElementType || anyType; @@ -19614,7 +20150,7 @@ var ts; * Returns true iff React would emit this tag name as a string rather than an identifier or qualified name */ function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 133 /* QualifiedName */) { + if (tagName.kind === 135 /* QualifiedName */) { return false; } else { @@ -19733,12 +20269,14 @@ var ts; // Look up the value in the current scope if (valueSymbol && valueSymbol !== unknownSymbol) { links.jsxFlags |= 4 /* ClassElement */; - getSymbolLinks(valueSymbol).referenced = true; + if (valueSymbol.flags & 8388608 /* Alias */) { + markAliasSymbolAsReferenced(valueSymbol); + } } return valueSymbol || unknownSymbol; } function resolveJsxTagName(node) { - if (node.tagName.kind === 67 /* Identifier */) { + if (node.tagName.kind === 69 /* Identifier */) { var tag = node.tagName; var sym = getResolvedSymbol(tag); return sym.exportSymbol || sym; @@ -19923,11 +20461,11 @@ var ts; // thus should have their types ignored var sawSpreadedAny = false; for (var i = node.attributes.length - 1; i >= 0; i--) { - if (node.attributes[i].kind === 236 /* JsxAttribute */) { + if (node.attributes[i].kind === 238 /* JsxAttribute */) { checkJsxAttribute((node.attributes[i]), targetAttributesType, nameTable); } else { - ts.Debug.assert(node.attributes[i].kind === 237 /* JsxSpreadAttribute */); + ts.Debug.assert(node.attributes[i].kind === 239 /* JsxSpreadAttribute */); var spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable); if (isTypeAny(spreadType)) { sawSpreadedAny = true; @@ -19957,7 +20495,7 @@ var ts; // If a symbol is a synthesized symbol with no value declaration, we assume it is a property. Example of this are the synthesized // '.prototype' property as well as synthesized tuple index properties. function getDeclarationKindFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.kind : 139 /* PropertyDeclaration */; + return s.valueDeclaration ? s.valueDeclaration.kind : 141 /* PropertyDeclaration */; } function getDeclarationFlagsFromSymbol(s) { return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 /* Prototype */ ? 16 /* Public */ | 128 /* Static */ : 0; @@ -19973,8 +20511,8 @@ var ts; function checkClassPropertyAccess(node, left, type, prop) { var flags = getDeclarationFlagsFromSymbol(prop); var declaringClass = getDeclaredTypeOfSymbol(prop.parent); - if (left.kind === 93 /* SuperKeyword */) { - var errorNode = node.kind === 164 /* PropertyAccessExpression */ ? + if (left.kind === 95 /* SuperKeyword */) { + var errorNode = node.kind === 166 /* PropertyAccessExpression */ ? node.name : node.right; // TS 1.0 spec (April 2014): 4.8.2 @@ -19984,7 +20522,7 @@ var ts; // - In a static member function or static member accessor // where this references the constructor function object of a derived class, // a super property access is permitted and must specify a public static member function of the base class. - if (getDeclarationKindFromSymbol(prop) !== 141 /* MethodDeclaration */) { + if (getDeclarationKindFromSymbol(prop) !== 143 /* MethodDeclaration */) { // `prop` refers to a *property* declared in the super class // rather than a *method*, so it does not satisfy the above criteria. error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); @@ -20017,7 +20555,7 @@ var ts; } // Property is known to be protected at this point // All protected properties of a supertype are accessible in a super access - if (left.kind === 93 /* SuperKeyword */) { + if (left.kind === 95 /* SuperKeyword */) { return true; } // A protected property is accessible in the declaring class and classes derived from it @@ -20030,6 +20568,10 @@ var ts; return true; } // An instance property must be accessed through an instance of the enclosing class + if (type.flags & 33554432 /* ThisType */) { + // get the original type -- represented as the type constraint of the 'this' type + type = getConstraintOfTypeParameter(type); + } // TODO: why is the first part of this check here? if (!(getTargetType(type).flags & (1024 /* Class */ | 2048 /* Interface */) && hasBaseType(type, enclosingClass))) { error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass)); @@ -20056,18 +20598,18 @@ var ts; var prop = getPropertyOfType(apparentType, right.text); if (!prop) { if (right.text) { - error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type)); + error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type.flags & 33554432 /* ThisType */ ? apparentType : type)); } return unknownType; } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32 /* Class */) { - checkClassPropertyAccess(node, left, type, prop); + checkClassPropertyAccess(node, left, apparentType, prop); } return getTypeOfSymbol(prop); } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 164 /* PropertyAccessExpression */ + var left = node.kind === 166 /* PropertyAccessExpression */ ? node.expression : node.left; var type = checkExpression(left); @@ -20083,7 +20625,7 @@ var ts; // Grammar checking if (!node.argumentExpression) { var sourceFile = getSourceFile(node); - if (node.parent.kind === 167 /* NewExpression */ && node.parent.expression === node) { + if (node.parent.kind === 169 /* NewExpression */ && node.parent.expression === node) { var start = ts.skipTrivia(sourceFile.text, node.expression.end); var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); @@ -20155,6 +20697,7 @@ var ts; } /** * If indexArgumentExpression is a string literal or number literal, returns its text. + * If indexArgumentExpression is a constant value, returns its string value. * If indexArgumentExpression is a well known symbol, returns the property name corresponding * to this symbol, as long as it is a proper symbol reference. * Otherwise, returns undefined. @@ -20163,6 +20706,12 @@ var ts; if (indexArgumentExpression.kind === 9 /* StringLiteral */ || indexArgumentExpression.kind === 8 /* NumericLiteral */) { return indexArgumentExpression.text; } + if (indexArgumentExpression.kind === 167 /* ElementAccessExpression */ || indexArgumentExpression.kind === 166 /* PropertyAccessExpression */) { + var value = getConstantValue(indexArgumentExpression); + if (value !== undefined) { + return value.toString(); + } + } if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, /*reportError*/ false)) { var rightHandSideName = indexArgumentExpression.name.text; return ts.getPropertyNameForKnownSymbolName(rightHandSideName); @@ -20212,10 +20761,10 @@ var ts; return true; } function resolveUntypedCall(node) { - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { checkExpression(node.template); } - else if (node.kind !== 137 /* Decorator */) { + else if (node.kind !== 139 /* Decorator */) { ts.forEach(node.arguments, function (argument) { checkExpression(argument); }); @@ -20281,7 +20830,7 @@ var ts; function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg && arg.kind === 183 /* SpreadElementExpression */) { + if (arg && arg.kind === 185 /* SpreadElementExpression */) { return i; } } @@ -20293,13 +20842,13 @@ var ts; var callIsIncomplete; // In incomplete call we want to be lenient when we have too few arguments var isDecorator; var spreadArgIndex = -1; - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { var tagExpression = node; // Even if the call is incomplete, we'll have a missing expression as our last argument, // so we can say the count is just the arg list length adjustedArgCount = args.length; typeArguments = undefined; - if (tagExpression.template.kind === 181 /* TemplateExpression */) { + if (tagExpression.template.kind === 183 /* TemplateExpression */) { // If a tagged template expression lacks a tail literal, the call is incomplete. // Specifically, a template only can end in a TemplateTail or a Missing literal. var templateExpression = tagExpression.template; @@ -20316,7 +20865,7 @@ var ts; callIsIncomplete = !!templateLiteral.isUnterminated; } } - else if (node.kind === 137 /* Decorator */) { + else if (node.kind === 139 /* Decorator */) { isDecorator = true; typeArguments = undefined; adjustedArgCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature); @@ -20325,7 +20874,7 @@ var ts; var callExpression = node; if (!callExpression.arguments) { // This only happens when we have something of the form: 'new C' - ts.Debug.assert(callExpression.kind === 167 /* NewExpression */); + ts.Debug.assert(callExpression.kind === 169 /* NewExpression */); return signature.minArgumentCount === 0; } // For IDE scenarios we may have an incomplete call, so a trailing comma is tantamount to adding another argument. @@ -20404,7 +20953,7 @@ var ts; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. - if (arg === undefined || arg.kind !== 185 /* OmittedExpression */) { + if (arg === undefined || arg.kind !== 187 /* OmittedExpression */) { var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); // If the effective argument type is 'undefined', there is no synthetic type @@ -20463,7 +21012,7 @@ var ts; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. - if (arg === undefined || arg.kind !== 185 /* OmittedExpression */) { + if (arg === undefined || arg.kind !== 187 /* OmittedExpression */) { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) var paramType = getTypeAtPosition(signature, i); var argType = getEffectiveArgumentType(node, i, arg); @@ -20495,16 +21044,16 @@ var ts; */ function getEffectiveCallArguments(node) { var args; - if (node.kind === 168 /* TaggedTemplateExpression */) { + if (node.kind === 170 /* TaggedTemplateExpression */) { var template = node.template; args = [undefined]; - if (template.kind === 181 /* TemplateExpression */) { + if (template.kind === 183 /* TemplateExpression */) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); } } - else if (node.kind === 137 /* Decorator */) { + else if (node.kind === 139 /* Decorator */) { // For a decorator, we return undefined as we will determine // the number and types of arguments for a decorator using // `getEffectiveArgumentCount` and `getEffectiveArgumentType` below. @@ -20529,25 +21078,29 @@ var ts; * Otherwise, the argument count is the length of the 'args' array. */ function getEffectiveArgumentCount(node, args, signature) { - if (node.kind === 137 /* Decorator */) { + if (node.kind === 139 /* Decorator */) { switch (node.parent.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // A class decorator will have one argument (see `ClassDecorator` in core.d.ts) return 1; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: // A property declaration decorator will have two arguments (see // `PropertyDecorator` in core.d.ts) return 2; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // A method or accessor declaration decorator will have two or three arguments (see // `PropertyDecorator` and `MethodDecorator` in core.d.ts) + // If we are emitting decorators for ES3, we will only pass two arguments. + if (languageVersion === 0 /* ES3 */) { + return 2; + } // If the method decorator signature only accepts a target and a key, we will only // type check those arguments. return signature.parameters.length >= 3 ? 3 : 2; - case 136 /* Parameter */: + case 138 /* Parameter */: // A parameter declaration decorator will have three arguments (see // `ParameterDecorator` in core.d.ts) return 3; @@ -20572,25 +21125,25 @@ var ts; function getEffectiveDecoratorFirstArgumentType(node) { // The first argument to a decorator is its `target`. switch (node.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: // For a class decorator, the `target` is the type of the class (e.g. the // "static" or "constructor" side of the class) var classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); - case 136 /* Parameter */: + case 138 /* Parameter */: // For a parameter decorator, the `target` is the parent type of the // parameter's containing method. node = node.parent; - if (node.kind === 142 /* Constructor */) { + if (node.kind === 144 /* Constructor */) { var classSymbol_1 = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol_1); } // fall-through - case 139 /* PropertyDeclaration */: - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // For a property or method decorator, the `target` is the // "static"-side type of the parent of the member if the member is // declared "static"; otherwise, it is the "instance"-side type of the @@ -20619,33 +21172,33 @@ var ts; function getEffectiveDecoratorSecondArgumentType(node) { // The second argument to a decorator is its `propertyKey` switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: ts.Debug.fail("Class decorators should not have a second synthetic argument."); return unknownType; - case 136 /* Parameter */: + case 138 /* Parameter */: node = node.parent; - if (node.kind === 142 /* Constructor */) { + if (node.kind === 144 /* Constructor */) { // For a constructor parameter decorator, the `propertyKey` will be `undefined`. return anyType; } // For a non-constructor parameter decorator, the `propertyKey` will be either // a string or a symbol, based on the name of the parameter's containing method. // fall-through - case 139 /* PropertyDeclaration */: - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // The `propertyKey` for a property or method decorator will be a // string literal type if the member name is an identifier, number, or string; // otherwise, if the member name is a computed property name it will // be either string or symbol. var element = node; switch (element.name.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: case 8 /* NumericLiteral */: case 9 /* StringLiteral */: return getStringLiteralType(element.name); - case 134 /* ComputedPropertyName */: + case 136 /* ComputedPropertyName */: var nameType = checkComputedPropertyName(element.name); if (allConstituentTypesHaveKind(nameType, 16777216 /* ESSymbol */)) { return nameType; @@ -20673,18 +21226,18 @@ var ts; // The third argument to a decorator is either its `descriptor` for a method decorator // or its `parameterIndex` for a paramter decorator switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: ts.Debug.fail("Class decorators should not have a third synthetic argument."); return unknownType; - case 136 /* Parameter */: + case 138 /* Parameter */: // The `parameterIndex` for a parameter decorator is always a number return numberType; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: ts.Debug.fail("Property decorators should not have a third synthetic argument."); return unknownType; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor` // for the type of the member. var propertyType = getTypeOfNode(node); @@ -20717,10 +21270,10 @@ var ts; // Decorators provide special arguments, a tagged template expression provides // a special first argument, and string literals get string literal types // unless we're reporting errors - if (node.kind === 137 /* Decorator */) { + if (node.kind === 139 /* Decorator */) { return getEffectiveDecoratorArgumentType(node, argIndex); } - else if (argIndex === 0 && node.kind === 168 /* TaggedTemplateExpression */) { + else if (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */) { return globalTemplateStringsArrayType; } // This is not a synthetic argument, so we return 'undefined' @@ -20732,8 +21285,8 @@ var ts; */ function getEffectiveArgument(node, args, argIndex) { // For a decorator or the first argument of a tagged template expression we return undefined. - if (node.kind === 137 /* Decorator */ || - (argIndex === 0 && node.kind === 168 /* TaggedTemplateExpression */)) { + if (node.kind === 139 /* Decorator */ || + (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */)) { return undefined; } return args[argIndex]; @@ -20742,11 +21295,11 @@ var ts; * Gets the error node to use when reporting errors for an effective argument. */ function getEffectiveArgumentErrorNode(node, argIndex, arg) { - if (node.kind === 137 /* Decorator */) { + if (node.kind === 139 /* Decorator */) { // For a decorator, we use the expression of the decorator for error reporting. return node.expression; } - else if (argIndex === 0 && node.kind === 168 /* TaggedTemplateExpression */) { + else if (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */) { // For a the first argument of a tagged template expression, we use the template of the tag for error reporting. return node.template; } @@ -20755,13 +21308,13 @@ var ts; } } function resolveCall(node, signatures, candidatesOutArray, headMessage) { - var isTaggedTemplate = node.kind === 168 /* TaggedTemplateExpression */; - var isDecorator = node.kind === 137 /* Decorator */; + var isTaggedTemplate = node.kind === 170 /* TaggedTemplateExpression */; + var isDecorator = node.kind === 139 /* Decorator */; var typeArguments; if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; // We already perform checking on the type arguments on the class declaration itself. - if (node.expression.kind !== 93 /* SuperKeyword */) { + if (node.expression.kind !== 95 /* SuperKeyword */) { ts.forEach(typeArguments, checkSourceElement); } } @@ -20968,7 +21521,7 @@ var ts; } } function resolveCallExpression(node, candidatesOutArray) { - if (node.expression.kind === 93 /* SuperKeyword */) { + if (node.expression.kind === 95 /* SuperKeyword */) { var superType = checkSuperExpression(node.expression); if (superType !== unknownType) { // In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated @@ -21101,16 +21654,16 @@ var ts; */ function getDiagnosticHeadMessageForDecoratorResolution(node) { switch (node.parent.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; - case 136 /* Parameter */: + case 138 /* Parameter */: return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression; } } @@ -21147,16 +21700,16 @@ var ts; // to correctly fill the candidatesOutArray. if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - if (node.kind === 166 /* CallExpression */) { + if (node.kind === 168 /* CallExpression */) { links.resolvedSignature = resolveCallExpression(node, candidatesOutArray); } - else if (node.kind === 167 /* NewExpression */) { + else if (node.kind === 169 /* NewExpression */) { links.resolvedSignature = resolveNewExpression(node, candidatesOutArray); } - else if (node.kind === 168 /* TaggedTemplateExpression */) { + else if (node.kind === 170 /* TaggedTemplateExpression */) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } - else if (node.kind === 137 /* Decorator */) { + else if (node.kind === 139 /* Decorator */) { links.resolvedSignature = resolveDecorator(node, candidatesOutArray); } else { @@ -21174,15 +21727,15 @@ var ts; // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); var signature = getResolvedSignature(node); - if (node.expression.kind === 93 /* SuperKeyword */) { + if (node.expression.kind === 95 /* SuperKeyword */) { return voidType; } - if (node.kind === 167 /* NewExpression */) { + if (node.kind === 169 /* NewExpression */) { var declaration = signature.declaration; if (declaration && - declaration.kind !== 142 /* Constructor */ && - declaration.kind !== 146 /* ConstructSignature */ && - declaration.kind !== 151 /* ConstructorType */) { + declaration.kind !== 144 /* Constructor */ && + declaration.kind !== 148 /* ConstructSignature */ && + declaration.kind !== 153 /* ConstructorType */) { // When resolved signature is a call signature (and not a construct signature) the result type is any if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); @@ -21224,10 +21777,24 @@ var ts; assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } } + // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push + // the destructured type into the contained binding elements. + function assignBindingElementTypes(node) { + if (ts.isBindingPattern(node.name)) { + for (var _i = 0, _a = node.name.elements; _i < _a.length; _i++) { + var element = _a[_i]; + if (element.kind !== 187 /* OmittedExpression */) { + getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element); + assignBindingElementTypes(element); + } + } + } + } function assignTypeToParameterAndFixTypeParameters(parameter, contextualType, mapper) { var links = getSymbolLinks(parameter); if (!links.type) { links.type = instantiateType(contextualType, mapper); + assignBindingElementTypes(parameter.valueDeclaration); } else if (isInferentialContext(mapper)) { // Even if the parameter already has a type, it might be because it was given a type while @@ -21279,7 +21846,7 @@ var ts; } var isAsync = ts.isAsyncFunctionLike(func); var type; - if (func.body.kind !== 190 /* Block */) { + if (func.body.kind !== 192 /* Block */) { type = checkExpressionCached(func.body, contextualMapper); if (isAsync) { // From within an async function you can return either a non-promise value or a promise. Any @@ -21398,7 +21965,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 206 /* ThrowStatement */); + return (body.statements.length === 1) && (body.statements[0].kind === 208 /* ThrowStatement */); } // TypeScript Specification 1.0 (6.3) - July 2014 // An explicitly typed function whose return type isn't the Void or the Any type @@ -21413,7 +21980,7 @@ var ts; return; } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. - if (ts.nodeIsMissing(func.body) || func.body.kind !== 190 /* Block */) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 192 /* Block */) { return; } var bodyBlock = func.body; @@ -21431,10 +21998,10 @@ var ts; error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); // Grammar checking var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); - if (!hasGrammarError && node.kind === 171 /* FunctionExpression */) { + if (!hasGrammarError && node.kind === 173 /* FunctionExpression */) { checkGrammarForGenerator(node); } // The identityMapper object is used to indicate that function expressions are wildcards @@ -21477,14 +22044,14 @@ var ts; } } } - if (produceDiagnostics && node.kind !== 141 /* MethodDeclaration */ && node.kind !== 140 /* MethodSignature */) { + if (produceDiagnostics && node.kind !== 143 /* MethodDeclaration */ && node.kind !== 142 /* MethodSignature */) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); } return type; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { - ts.Debug.assert(node.kind !== 141 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; @@ -21506,7 +22073,7 @@ var ts; // checkFunctionExpressionBodies). So it must be done now. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - if (node.body.kind === 190 /* Block */) { + if (node.body.kind === 192 /* Block */) { checkSourceElement(node.body); } else { @@ -21552,24 +22119,24 @@ var ts; // and property accesses(section 4.10). // All other expression constructs described in this chapter are classified as values. switch (n.kind) { - case 67 /* Identifier */: { + case 69 /* Identifier */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.3 // An identifier expression that references a variable or parameter is classified as a reference. // An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment). return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3 /* Variable */) !== 0; } - case 164 /* PropertyAccessExpression */: { + case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.10 // A property access expression is always classified as a reference. // NOTE (not in spec): assignment to enum members should not be allowed return !symbol || symbol === unknownSymbol || (symbol.flags & ~8 /* EnumMember */) !== 0; } - case 165 /* ElementAccessExpression */: - // old compiler doesn't check indexed assess + case 167 /* ElementAccessExpression */: + // old compiler doesn't check indexed access return true; - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -21577,12 +22144,12 @@ var ts; } function isConstVariableReference(n) { switch (n.kind) { - case 67 /* Identifier */: - case 164 /* PropertyAccessExpression */: { + case 69 /* Identifier */: + case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); return symbol && (symbol.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 32768 /* Const */) !== 0; } - case 165 /* ElementAccessExpression */: { + case 167 /* ElementAccessExpression */: { var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 9 /* StringLiteral */) { @@ -21592,7 +22159,7 @@ var ts; } return false; } - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return isConstVariableReference(n.expression); default: return false; @@ -21638,15 +22205,15 @@ var ts; switch (node.operator) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: + case 50 /* TildeToken */: if (someConstituentTypeHasKind(operandType, 16777216 /* ESSymbol */)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; - case 48 /* ExclamationToken */: + case 49 /* ExclamationToken */: return booleanType; - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 41 /* PlusPlusToken */: + case 42 /* MinusMinusToken */: var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors @@ -21706,31 +22273,31 @@ var ts; function isConstEnumSymbol(symbol) { return (symbol.flags & 128 /* ConstEnum */) !== 0; } - function checkInstanceOfExpression(node, leftType, rightType) { + function checkInstanceOfExpression(left, right, leftType, rightType) { // TypeScript 1.0 spec (April 2014): 4.15.4 // The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type, // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported if (allConstituentTypesHaveKind(leftType, 16777726 /* Primitive */)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); + error(right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; } - function checkInExpression(node, leftType, rightType) { + function checkInExpression(left, right, leftType, rightType) { // TypeScript 1.0 spec (April 2014): 4.15.5 // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */ | 132 /* NumberLike */ | 16777216 /* ESSymbol */)) { - error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); + error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 /* ObjectType */ | 512 /* TypeParameter */)) { - error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); + error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; } @@ -21738,7 +22305,7 @@ var ts; var properties = node.properties; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; - if (p.kind === 243 /* PropertyAssignment */ || p.kind === 244 /* ShorthandPropertyAssignment */) { + if (p.kind === 245 /* PropertyAssignment */ || p.kind === 246 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support var name_13 = p.name; var type = isTypeAny(sourceType) @@ -21747,7 +22314,12 @@ var ts; isNumericLiteralName(name_13.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_13, type); + if (p.kind === 246 /* ShorthandPropertyAssignment */) { + checkDestructuringAssignment(p, type); + } + else { + checkDestructuringAssignment(p.initializer || name_13, type); + } } else { error(name_13, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_13)); @@ -21767,8 +22339,8 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 185 /* OmittedExpression */) { - if (e.kind !== 183 /* SpreadElementExpression */) { + if (e.kind !== 187 /* OmittedExpression */) { + if (e.kind !== 185 /* SpreadElementExpression */) { var propName = "" + i; var type = isTypeAny(sourceType) ? sourceType @@ -21793,7 +22365,7 @@ var ts; } else { var restExpression = e.expression; - if (restExpression.kind === 179 /* BinaryExpression */ && restExpression.operatorToken.kind === 55 /* EqualsToken */) { + if (restExpression.kind === 181 /* BinaryExpression */ && restExpression.operatorToken.kind === 56 /* EqualsToken */) { error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer); } else { @@ -21805,15 +22377,26 @@ var ts; } return sourceType; } - function checkDestructuringAssignment(target, sourceType, contextualMapper) { - if (target.kind === 179 /* BinaryExpression */ && target.operatorToken.kind === 55 /* EqualsToken */) { + function checkDestructuringAssignment(exprOrAssignment, sourceType, contextualMapper) { + var target; + if (exprOrAssignment.kind === 246 /* ShorthandPropertyAssignment */) { + var prop = exprOrAssignment; + if (prop.objectAssignmentInitializer) { + checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper); + } + target = exprOrAssignment.name; + } + else { + target = exprOrAssignment; + } + if (target.kind === 181 /* BinaryExpression */ && target.operatorToken.kind === 56 /* EqualsToken */) { checkBinaryExpression(target, contextualMapper); target = target.left; } - if (target.kind === 163 /* ObjectLiteralExpression */) { + if (target.kind === 165 /* ObjectLiteralExpression */) { return checkObjectLiteralAssignment(target, sourceType, contextualMapper); } - if (target.kind === 162 /* ArrayLiteralExpression */) { + if (target.kind === 164 /* ArrayLiteralExpression */) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } return checkReferenceAssignment(target, sourceType, contextualMapper); @@ -21826,34 +22409,39 @@ var ts; return sourceType; } function checkBinaryExpression(node, contextualMapper) { - var operator = node.operatorToken.kind; - if (operator === 55 /* EqualsToken */ && (node.left.kind === 163 /* ObjectLiteralExpression */ || node.left.kind === 162 /* ArrayLiteralExpression */)) { - return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); + return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node); + } + function checkBinaryLikeExpression(left, operatorToken, right, contextualMapper, errorNode) { + var operator = operatorToken.kind; + if (operator === 56 /* EqualsToken */ && (left.kind === 165 /* ObjectLiteralExpression */ || left.kind === 164 /* ArrayLiteralExpression */)) { + return checkDestructuringAssignment(left, checkExpression(right, contextualMapper), contextualMapper); } - var leftType = checkExpression(node.left, contextualMapper); - var rightType = checkExpression(node.right, contextualMapper); + var leftType = checkExpression(left, contextualMapper); + var rightType = checkExpression(right, contextualMapper); switch (operator) { case 37 /* AsteriskToken */: - case 58 /* AsteriskEqualsToken */: - case 38 /* SlashToken */: - case 59 /* SlashEqualsToken */: - case 39 /* PercentToken */: - case 60 /* PercentEqualsToken */: + case 38 /* AsteriskAsteriskToken */: + case 59 /* AsteriskEqualsToken */: + case 60 /* AsteriskAsteriskEqualsToken */: + case 39 /* SlashToken */: + case 61 /* SlashEqualsToken */: + case 40 /* PercentToken */: + case 62 /* PercentEqualsToken */: case 36 /* MinusToken */: - case 57 /* MinusEqualsToken */: - case 42 /* LessThanLessThanToken */: - case 61 /* LessThanLessThanEqualsToken */: - case 43 /* GreaterThanGreaterThanToken */: - case 62 /* GreaterThanGreaterThanEqualsToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: - case 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */: - case 46 /* BarToken */: - case 65 /* BarEqualsToken */: - case 47 /* CaretToken */: - case 66 /* CaretEqualsToken */: - case 45 /* AmpersandToken */: - case 64 /* AmpersandEqualsToken */: - // TypeScript 1.0 spec (April 2014): 4.15.1 + case 58 /* MinusEqualsToken */: + case 43 /* LessThanLessThanToken */: + case 63 /* LessThanLessThanEqualsToken */: + case 44 /* GreaterThanGreaterThanToken */: + case 64 /* GreaterThanGreaterThanEqualsToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: + case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */: + case 47 /* BarToken */: + case 67 /* BarEqualsToken */: + case 48 /* CaretToken */: + case 68 /* CaretEqualsToken */: + case 46 /* AmpersandToken */: + case 66 /* AmpersandEqualsToken */: + // TypeScript 1.0 spec (April 2014): 4.19.1 // These operators require their operands to be of type Any, the Number primitive type, // or an enum type. Operands of an enum type are treated // as having the primitive type Number. If one operand is the null or undefined value, @@ -21868,21 +22456,21 @@ var ts; // try and return them a helpful suggestion if ((leftType.flags & 8 /* Boolean */) && (rightType.flags & 8 /* Boolean */) && - (suggestedOperator = getSuggestedBooleanOperator(node.operatorToken.kind)) !== undefined) { - error(node, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(node.operatorToken.kind), ts.tokenToString(suggestedOperator)); + (suggestedOperator = getSuggestedBooleanOperator(operatorToken.kind)) !== undefined) { + error(errorNode || operatorToken, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(operatorToken.kind), ts.tokenToString(suggestedOperator)); } else { // otherwise just check each operand separately and report errors as normal - var leftOk = checkArithmeticOperandType(node.left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); - var rightOk = checkArithmeticOperandType(node.right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var leftOk = checkArithmeticOperandType(left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); + var rightOk = checkArithmeticOperandType(right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); if (leftOk && rightOk) { checkAssignmentOperator(numberType); } } return numberType; case 35 /* PlusToken */: - case 56 /* PlusEqualsToken */: - // TypeScript 1.0 spec (April 2014): 4.15.2 + case 57 /* PlusEqualsToken */: + // TypeScript 1.0 spec (April 2014): 4.19.2 // The binary + operator requires both operands to be of the Number primitive type or an enum type, // or at least one of the operands to be of type Any or the String primitive type. // If one operand is the null or undefined value, it is treated as having the type of the other operand. @@ -21915,7 +22503,7 @@ var ts; reportOperatorError(); return anyType; } - if (operator === 56 /* PlusEqualsToken */) { + if (operator === 57 /* PlusEqualsToken */) { checkAssignmentOperator(resultType); } return resultType; @@ -21935,15 +22523,15 @@ var ts; reportOperatorError(); } return booleanType; - case 89 /* InstanceOfKeyword */: - return checkInstanceOfExpression(node, leftType, rightType); - case 88 /* InKeyword */: - return checkInExpression(node, leftType, rightType); - case 50 /* AmpersandAmpersandToken */: + case 91 /* InstanceOfKeyword */: + return checkInstanceOfExpression(left, right, leftType, rightType); + case 90 /* InKeyword */: + return checkInExpression(left, right, leftType, rightType); + case 51 /* AmpersandAmpersandToken */: return rightType; - case 51 /* BarBarToken */: + case 52 /* BarBarToken */: return getUnionType([leftType, rightType]); - case 55 /* EqualsToken */: + case 56 /* EqualsToken */: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); case 24 /* CommaToken */: @@ -21951,8 +22539,8 @@ var ts; } // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216 /* ESSymbol */) ? node.left : - someConstituentTypeHasKind(rightType, 16777216 /* ESSymbol */) ? node.right : + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216 /* ESSymbol */) ? left : + someConstituentTypeHasKind(rightType, 16777216 /* ESSymbol */) ? right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); @@ -21962,37 +22550,37 @@ var ts; } function getSuggestedBooleanOperator(operator) { switch (operator) { - case 46 /* BarToken */: - case 65 /* BarEqualsToken */: - return 51 /* BarBarToken */; - case 47 /* CaretToken */: - case 66 /* CaretEqualsToken */: + case 47 /* BarToken */: + case 67 /* BarEqualsToken */: + return 52 /* BarBarToken */; + case 48 /* CaretToken */: + case 68 /* CaretEqualsToken */: return 33 /* ExclamationEqualsEqualsToken */; - case 45 /* AmpersandToken */: - case 64 /* AmpersandEqualsToken */: - return 50 /* AmpersandAmpersandToken */; + case 46 /* AmpersandToken */: + case 66 /* AmpersandEqualsToken */: + return 51 /* AmpersandAmpersandToken */; default: return undefined; } } function checkAssignmentOperator(valueType) { - if (produceDiagnostics && operator >= 55 /* FirstAssignment */ && operator <= 66 /* LastAssignment */) { + if (produceDiagnostics && operator >= 56 /* FirstAssignment */ && operator <= 68 /* LastAssignment */) { // TypeScript 1.0 spec (April 2014): 4.17 // An assignment of the form // VarExpr = ValueExpr // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. - var ok = checkReferenceExpression(node.left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + var ok = checkReferenceExpression(left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported - checkTypeAssignableTo(valueType, leftType, node.left, /*headMessage*/ undefined); + checkTypeAssignableTo(valueType, leftType, left, /*headMessage*/ undefined); } } } function reportOperatorError() { - error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); + error(errorNode || operatorToken, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } function isYieldExpressionInClass(node) { @@ -22083,7 +22671,7 @@ var ts; // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); } return checkExpression(node.initializer, contextualMapper); @@ -22094,7 +22682,7 @@ var ts; // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); } var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); @@ -22124,7 +22712,7 @@ var ts; // contextually typed function and arrow expressions in the initial phase. function checkExpression(node, contextualMapper) { var type; - if (node.kind === 133 /* QualifiedName */) { + if (node.kind === 135 /* QualifiedName */) { type = checkQualifiedName(node); } else { @@ -22136,9 +22724,9 @@ var ts; // - 'left' in property access // - 'object' in indexed access // - target in rhs of import statement - var ok = (node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.expression === node) || - (node.parent.kind === 165 /* ElementAccessExpression */ && node.parent.expression === node) || - ((node.kind === 67 /* Identifier */ || node.kind === 133 /* QualifiedName */) && isInRightSideOfImportOrExportAssignment(node)); + var ok = (node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.expression === node) || + (node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.expression === node) || + ((node.kind === 69 /* Identifier */ || node.kind === 135 /* QualifiedName */) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } @@ -22152,78 +22740,78 @@ var ts; } function checkExpressionWorker(node, contextualMapper) { switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: return checkIdentifier(node); - case 95 /* ThisKeyword */: + case 97 /* ThisKeyword */: return checkThisExpression(node); - case 93 /* SuperKeyword */: + case 95 /* SuperKeyword */: return checkSuperExpression(node); - case 91 /* NullKeyword */: + case 93 /* NullKeyword */: return nullType; - case 97 /* TrueKeyword */: - case 82 /* FalseKeyword */: + case 99 /* TrueKeyword */: + case 84 /* FalseKeyword */: return booleanType; case 8 /* NumericLiteral */: return checkNumericLiteral(node); - case 181 /* TemplateExpression */: + case 183 /* TemplateExpression */: return checkTemplateExpression(node); case 9 /* StringLiteral */: case 11 /* NoSubstitutionTemplateLiteral */: return stringType; case 10 /* RegularExpressionLiteral */: return globalRegExpType; - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return checkArrayLiteral(node, contextualMapper); - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return checkObjectLiteral(node, contextualMapper); - case 164 /* PropertyAccessExpression */: + case 166 /* PropertyAccessExpression */: return checkPropertyAccessExpression(node); - case 165 /* ElementAccessExpression */: + case 167 /* ElementAccessExpression */: return checkIndexedAccess(node); - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: return checkCallExpression(node); - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: return checkTaggedTemplateExpression(node); - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return checkExpression(node.expression, contextualMapper); - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: return checkClassExpression(node); - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); - case 174 /* TypeOfExpression */: + case 176 /* TypeOfExpression */: return checkTypeOfExpression(node); - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: return checkAssertion(node); - case 173 /* DeleteExpression */: + case 175 /* DeleteExpression */: return checkDeleteExpression(node); - case 175 /* VoidExpression */: + case 177 /* VoidExpression */: return checkVoidExpression(node); - case 176 /* AwaitExpression */: + case 178 /* AwaitExpression */: return checkAwaitExpression(node); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return checkPrefixUnaryExpression(node); - case 178 /* PostfixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: return checkPostfixUnaryExpression(node); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return checkBinaryExpression(node, contextualMapper); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); - case 183 /* SpreadElementExpression */: + case 185 /* SpreadElementExpression */: return checkSpreadElementExpression(node, contextualMapper); - case 185 /* OmittedExpression */: + case 187 /* OmittedExpression */: return undefinedType; - case 182 /* YieldExpression */: + case 184 /* YieldExpression */: return checkYieldExpression(node); - case 238 /* JsxExpression */: + case 240 /* JsxExpression */: return checkJsxExpression(node); - case 231 /* JsxElement */: + case 233 /* JsxElement */: return checkJsxElement(node); - case 232 /* JsxSelfClosingElement */: + case 234 /* JsxSelfClosingElement */: return checkJsxSelfClosingElement(node); - case 233 /* JsxOpeningElement */: + case 235 /* JsxOpeningElement */: ts.Debug.fail("Shouldn't ever directly check a JsxOpeningElement"); } return unknownType; @@ -22252,7 +22840,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & 112 /* AccessibilityModifier */) { func = ts.getContainingFunction(node); - if (!(func.kind === 142 /* Constructor */ && ts.nodeIsPresent(func.body))) { + if (!(func.kind === 144 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -22269,15 +22857,15 @@ var ts; if (!node.asteriskToken || !node.body) { return false; } - return node.kind === 141 /* MethodDeclaration */ || - node.kind === 211 /* FunctionDeclaration */ || - node.kind === 171 /* FunctionExpression */; + return node.kind === 143 /* MethodDeclaration */ || + node.kind === 213 /* FunctionDeclaration */ || + node.kind === 173 /* FunctionExpression */; } function getTypePredicateParameterIndex(parameterList, parameter) { if (parameterList) { for (var i = 0; i < parameterList.length; i++) { var param = parameterList[i]; - if (param.name.kind === 67 /* Identifier */ && + if (param.name.kind === 69 /* Identifier */ && param.name.text === parameter.text) { return i; } @@ -22287,31 +22875,31 @@ var ts; } function isInLegalTypePredicatePosition(node) { switch (node.parent.kind) { - case 172 /* ArrowFunction */: - case 145 /* CallSignature */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 150 /* FunctionType */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 174 /* ArrowFunction */: + case 147 /* CallSignature */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 152 /* FunctionType */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return node === node.parent.type; } return false; } function checkSignatureDeclaration(node) { // Grammar checking - if (node.kind === 147 /* IndexSignature */) { + if (node.kind === 149 /* IndexSignature */) { checkGrammarIndexSignature(node); } - else if (node.kind === 150 /* FunctionType */ || node.kind === 211 /* FunctionDeclaration */ || node.kind === 151 /* ConstructorType */ || - node.kind === 145 /* CallSignature */ || node.kind === 142 /* Constructor */ || - node.kind === 146 /* ConstructSignature */) { + else if (node.kind === 152 /* FunctionType */ || node.kind === 213 /* FunctionDeclaration */ || node.kind === 153 /* ConstructorType */ || + node.kind === 147 /* CallSignature */ || node.kind === 144 /* Constructor */ || + node.kind === 148 /* ConstructSignature */) { checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { - if (node.type.kind === 148 /* TypePredicate */) { + if (node.type.kind === 150 /* TypePredicate */) { var typePredicate = getSignatureFromDeclaration(node).typePredicate; var typePredicateNode = node.type; if (isInLegalTypePredicatePosition(typePredicateNode)) { @@ -22330,19 +22918,19 @@ var ts; if (hasReportedError) { break; } - if (param.name.kind === 159 /* ObjectBindingPattern */ || - param.name.kind === 160 /* ArrayBindingPattern */) { + if (param.name.kind === 161 /* ObjectBindingPattern */ || + param.name.kind === 162 /* ArrayBindingPattern */) { (function checkBindingPattern(pattern) { for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.name.kind === 67 /* Identifier */ && + if (element.name.kind === 69 /* Identifier */ && element.name.text === typePredicate.parameterName) { error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName); hasReportedError = true; break; } - else if (element.name.kind === 160 /* ArrayBindingPattern */ || - element.name.kind === 159 /* ObjectBindingPattern */) { + else if (element.name.kind === 162 /* ArrayBindingPattern */ || + element.name.kind === 161 /* ObjectBindingPattern */) { checkBindingPattern(element.name); } } @@ -22366,10 +22954,10 @@ var ts; checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; - case 145 /* CallSignature */: + case 147 /* CallSignature */: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } @@ -22397,7 +22985,7 @@ var ts; checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 213 /* InterfaceDeclaration */) { + if (node.kind === 215 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); // in case of merging interface declaration it is possible that we'll enter this check procedure several times for every declaration // to prevent this run check only for the first declaration of a given kind @@ -22417,7 +23005,7 @@ var ts; var declaration = decl; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 128 /* StringKeyword */: + case 130 /* StringKeyword */: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -22425,7 +23013,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 126 /* NumberKeyword */: + case 128 /* NumberKeyword */: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -22474,7 +23062,7 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 166 /* CallExpression */ && n.expression.kind === 93 /* SuperKeyword */; + return n.kind === 168 /* CallExpression */ && n.expression.kind === 95 /* SuperKeyword */; } function containsSuperCallAsComputedPropertyName(n) { return n.name && containsSuperCall(n.name); @@ -22492,15 +23080,15 @@ var ts; return ts.forEachChild(n, containsSuperCall); } function markThisReferencesAsErrors(n) { - if (n.kind === 95 /* ThisKeyword */) { + if (n.kind === 97 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 171 /* FunctionExpression */ && n.kind !== 211 /* FunctionDeclaration */) { + else if (n.kind !== 173 /* FunctionExpression */ && n.kind !== 213 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } } function isInstancePropertyWithInitializer(n) { - return n.kind === 139 /* PropertyDeclaration */ && + return n.kind === 141 /* PropertyDeclaration */ && !(n.flags & 128 /* Static */) && !!n.initializer; } @@ -22530,7 +23118,7 @@ var ts; var superCallStatement; for (var _i = 0; _i < statements.length; _i++) { var statement = statements[_i]; - if (statement.kind === 193 /* ExpressionStatement */ && isSuperCallExpression(statement.expression)) { + if (statement.kind === 195 /* ExpressionStatement */ && isSuperCallExpression(statement.expression)) { superCallStatement = statement; break; } @@ -22556,7 +23144,7 @@ var ts; if (produceDiagnostics) { // Grammar checking accessors checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (node.kind === 143 /* GetAccessor */) { + if (node.kind === 145 /* GetAccessor */) { if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } @@ -22564,7 +23152,7 @@ var ts; if (!ts.hasDynamicName(node)) { // TypeScript 1.0 spec (April 2014): 8.4.3 // Accessors for the same member name must specify the same accessibility. - var otherKind = node.kind === 143 /* GetAccessor */ ? 144 /* SetAccessor */ : 143 /* GetAccessor */; + var otherKind = node.kind === 145 /* GetAccessor */ ? 146 /* SetAccessor */ : 145 /* GetAccessor */; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { if (((node.flags & 112 /* AccessibilityModifier */) !== (otherAccessor.flags & 112 /* AccessibilityModifier */))) { @@ -22660,9 +23248,9 @@ var ts; var signaturesToCheck; // Unnamed (call\construct) signatures in interfaces are inherited and not shadowed so examining just node symbol won't give complete answer. // Use declaring type to obtain full list of signatures. - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 213 /* InterfaceDeclaration */) { - ts.Debug.assert(signatureDeclarationNode.kind === 145 /* CallSignature */ || signatureDeclarationNode.kind === 146 /* ConstructSignature */); - var signatureKind = signatureDeclarationNode.kind === 145 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 215 /* InterfaceDeclaration */) { + ts.Debug.assert(signatureDeclarationNode.kind === 147 /* CallSignature */ || signatureDeclarationNode.kind === 148 /* ConstructSignature */); + var signatureKind = signatureDeclarationNode.kind === 147 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); var containingType = getDeclaredTypeOfSymbol(containingSymbol); signaturesToCheck = getSignaturesOfType(containingType, signatureKind); @@ -22680,7 +23268,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = ts.getCombinedNodeFlags(n); - if (n.parent.kind !== 213 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 215 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { // It is nested in an ambient context, which means it is automatically exported flags |= 1 /* Export */; @@ -22766,7 +23354,7 @@ var ts; // TODO(jfreeman): These are methods, so handle computed name case if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) { // the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members - ts.Debug.assert(node.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */); + ts.Debug.assert(node.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */); ts.Debug.assert((node.flags & 128 /* Static */) !== (subsequentNode.flags & 128 /* Static */)); var diagnostic = node.flags & 128 /* Static */ ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static; error(errorNode_1, diagnostic); @@ -22802,7 +23390,7 @@ var ts; var current = declarations[_i]; var node = current; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 213 /* InterfaceDeclaration */ || node.parent.kind === 153 /* TypeLiteral */ || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 215 /* InterfaceDeclaration */ || node.parent.kind === 155 /* TypeLiteral */ || inAmbientContext; if (inAmbientContextOrInterface) { // check if declarations are consecutive only if they are non-ambient // 1. ambient declarations can be interleaved @@ -22813,7 +23401,7 @@ var ts; // 2. mixing ambient and non-ambient declarations is a separate error that will be reported - do not want to report an extra one previousDeclaration = undefined; } - if (node.kind === 211 /* FunctionDeclaration */ || node.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */ || node.kind === 142 /* Constructor */) { + if (node.kind === 213 /* FunctionDeclaration */ || node.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */ || node.kind === 144 /* Constructor */) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -22953,16 +23541,16 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return 2097152 /* ExportType */; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return d.name.kind === 9 /* StringLiteral */ || ts.getModuleInstanceState(d) !== 0 /* NonInstantiated */ ? 4194304 /* ExportNamespace */ | 1048576 /* ExportValue */ : 4194304 /* ExportNamespace */; - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: return 2097152 /* ExportType */ | 1048576 /* ExportValue */; - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: var result = 0; var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); @@ -22973,7 +23561,8 @@ var ts; } } function checkNonThenableType(type, location, message) { - if (!(type.flags & 1 /* Any */) && isTypeAssignableTo(type, getGlobalThenableType())) { + type = getWidenedType(type); + if (!isTypeAny(type) && isTypeAssignableTo(type, getGlobalThenableType())) { if (location) { if (!message) { message = ts.Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member; @@ -23206,22 +23795,22 @@ var ts; var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); var errorInfo; switch (node.parent.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var classSymbol = getSymbolOfNode(node.parent); var classConstructorType = getTypeOfSymbol(classSymbol); expectedReturnType = getUnionType([classConstructorType, voidType]); break; - case 136 /* Parameter */: + case 138 /* Parameter */: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: expectedReturnType = voidType; errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any); break; - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: var methodType = getTypeOfNode(node.parent); var descriptorType = createTypedPropertyDescriptorType(methodType); expectedReturnType = getUnionType([descriptorType, voidType]); @@ -23234,9 +23823,9 @@ var ts; // When we are emitting type metadata for decorators, we need to try to check the type // as if it were an expression so that we can emit the type in a value position when we // serialize the type metadata. - if (node && node.kind === 149 /* TypeReference */) { + if (node && node.kind === 151 /* TypeReference */) { var root = getFirstIdentifier(node.typeName); - var meaning = root.parent.kind === 149 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; + var meaning = root.parent.kind === 151 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; // Resolve type so we know which symbol is referenced var rootSymbol = resolveName(root, root.text, meaning | 8388608 /* Alias */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); // Resolved symbol is alias @@ -23255,19 +23844,19 @@ var ts; */ function checkTypeAnnotationAsExpression(node) { switch (node.kind) { - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: checkTypeNodeAsExpression(node.type); break; - case 136 /* Parameter */: + case 138 /* Parameter */: checkTypeNodeAsExpression(node.type); break; - case 141 /* MethodDeclaration */: + case 143 /* MethodDeclaration */: checkTypeNodeAsExpression(node.type); break; - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: checkTypeNodeAsExpression(node.type); break; - case 144 /* SetAccessor */: + case 146 /* SetAccessor */: checkTypeNodeAsExpression(ts.getSetAccessorTypeAnnotationNode(node)); break; } @@ -23296,25 +23885,25 @@ var ts; if (compilerOptions.emitDecoratorMetadata) { // we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator. switch (node.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var constructor = ts.getFirstConstructorWithBody(node); if (constructor) { checkParameterTypeAnnotationsAsExpressions(constructor); } break; - case 141 /* MethodDeclaration */: + case 143 /* MethodDeclaration */: checkParameterTypeAnnotationsAsExpressions(node); // fall-through - case 144 /* SetAccessor */: - case 143 /* GetAccessor */: - case 139 /* PropertyDeclaration */: - case 136 /* Parameter */: + case 146 /* SetAccessor */: + case 145 /* GetAccessor */: + case 141 /* PropertyDeclaration */: + case 138 /* Parameter */: checkTypeAnnotationAsExpression(node); break; } } emitDecorate = true; - if (node.kind === 136 /* Parameter */) { + if (node.kind === 138 /* Parameter */) { emitParam = true; } ts.forEach(node.decorators, checkDecorator); @@ -23332,15 +23921,12 @@ var ts; checkSignatureDeclaration(node); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { - if (!compilerOptions.experimentalAsyncFunctions) { - error(node, ts.Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning); - } emitAwaiter = true; } // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name && node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name && node.name.kind === 136 /* ComputedPropertyName */) { // This check will account for methods in class/interface declarations, // as well as accessors in classes/object literals checkComputedPropertyName(node.name); @@ -23389,11 +23975,11 @@ var ts; } function checkBlock(node) { // Grammar checking for SyntaxKind.Block - if (node.kind === 190 /* Block */) { + if (node.kind === 192 /* Block */) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); - if (ts.isFunctionBlock(node) || node.kind === 217 /* ModuleBlock */) { + if (ts.isFunctionBlock(node) || node.kind === 219 /* ModuleBlock */) { checkFunctionAndClassExpressionBodies(node); } } @@ -23412,12 +23998,12 @@ var ts; if (!(identifier && identifier.text === name)) { return false; } - if (node.kind === 139 /* PropertyDeclaration */ || - node.kind === 138 /* PropertySignature */ || - node.kind === 141 /* MethodDeclaration */ || - node.kind === 140 /* MethodSignature */ || - node.kind === 143 /* GetAccessor */ || - node.kind === 144 /* SetAccessor */) { + if (node.kind === 141 /* PropertyDeclaration */ || + node.kind === 140 /* PropertySignature */ || + node.kind === 143 /* MethodDeclaration */ || + node.kind === 142 /* MethodSignature */ || + node.kind === 145 /* GetAccessor */ || + node.kind === 146 /* SetAccessor */) { // it is ok to have member named '_super' or '_this' - member access is always qualified return false; } @@ -23426,7 +24012,7 @@ var ts; return false; } var root = ts.getRootDeclaration(node); - if (root.kind === 136 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { + if (root.kind === 138 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { // just an overload - no codegen impact return false; } @@ -23442,7 +24028,7 @@ var ts; var current = node; while (current) { if (getNodeCheckFlags(current) & 4 /* CaptureThis */) { - var isDeclaration_1 = node.kind !== 67 /* Identifier */; + var isDeclaration_1 = node.kind !== 69 /* Identifier */; if (isDeclaration_1) { error(node.name, ts.Diagnostics.Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference); } @@ -23465,7 +24051,7 @@ var ts; return; } if (ts.getClassExtendsHeritageClauseElement(enclosingClass)) { - var isDeclaration_2 = node.kind !== 67 /* Identifier */; + var isDeclaration_2 = node.kind !== 69 /* Identifier */; if (isDeclaration_2) { error(node, ts.Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference); } @@ -23479,12 +24065,12 @@ var ts; return; } // Uninstantiated modules shouldnt do this check - if (node.kind === 216 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) { + if (node.kind === 218 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) { return; } // In case of variable declaration, node.parent is variable statement so look at the variable statement's parent var parent = getDeclarationContainer(node); - if (parent.kind === 246 /* SourceFile */ && ts.isExternalModule(parent)) { + if (parent.kind === 248 /* SourceFile */ && ts.isExternalModule(parent)) { // If the declaration happens to be in external module, report error that require and exports are reserved keywords error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name)); } @@ -23519,7 +24105,7 @@ var ts; // skip variable declarations that don't have initializers // NOTE: in ES6 spec initializer is required in variable declarations where name is binding pattern // so we'll always treat binding elements as initialized - if (node.kind === 209 /* VariableDeclaration */ && !node.initializer) { + if (node.kind === 211 /* VariableDeclaration */ && !node.initializer) { return; } var symbol = getSymbolOfNode(node); @@ -23529,17 +24115,17 @@ var ts; localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & 2 /* BlockScopedVariable */) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 49152 /* BlockScoped */) { - var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 210 /* VariableDeclarationList */); - var container = varDeclList.parent.kind === 191 /* VariableStatement */ && varDeclList.parent.parent + var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 212 /* VariableDeclarationList */); + var container = varDeclList.parent.kind === 193 /* VariableStatement */ && varDeclList.parent.parent ? varDeclList.parent.parent : undefined; // names of block-scoped and function scoped variables can collide only // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) var namesShareScope = container && - (container.kind === 190 /* Block */ && ts.isFunctionLike(container.parent) || - container.kind === 217 /* ModuleBlock */ || - container.kind === 216 /* ModuleDeclaration */ || - container.kind === 246 /* SourceFile */); + (container.kind === 192 /* Block */ && ts.isFunctionLike(container.parent) || + container.kind === 219 /* ModuleBlock */ || + container.kind === 218 /* ModuleDeclaration */ || + container.kind === 248 /* SourceFile */); // here we know that function scoped variable is shadowed by block scoped one // if they are defined in the same scope - binder has already reported redeclaration error // otherwise if variable has an initializer - show error that initialization will fail @@ -23554,18 +24140,18 @@ var ts; } // Check that a parameter initializer contains no references to parameters declared to the right of itself function checkParameterInitializer(node) { - if (ts.getRootDeclaration(node).kind !== 136 /* Parameter */) { + if (ts.getRootDeclaration(node).kind !== 138 /* Parameter */) { return; } var func = ts.getContainingFunction(node); visit(node.initializer); function visit(n) { - if (n.kind === 67 /* Identifier */) { + if (n.kind === 69 /* Identifier */) { var referencedSymbol = getNodeLinks(n).resolvedSymbol; // check FunctionLikeDeclaration.locals (stores parameters\function local variable) // if it contains entry with a specified name and if this entry matches the resolved symbol if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455 /* Value */) === referencedSymbol) { - if (referencedSymbol.valueDeclaration.kind === 136 /* Parameter */) { + if (referencedSymbol.valueDeclaration.kind === 138 /* Parameter */) { if (referencedSymbol.valueDeclaration === node) { error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name)); return; @@ -23591,7 +24177,7 @@ var ts; // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { + if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); @@ -23602,7 +24188,7 @@ var ts; ts.forEach(node.name.elements, checkSourceElement); } // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body - if (node.initializer && ts.getRootDeclaration(node).kind === 136 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { + if (node.initializer && ts.getRootDeclaration(node).kind === 138 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -23634,10 +24220,10 @@ var ts; checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } } - if (node.kind !== 139 /* PropertyDeclaration */ && node.kind !== 138 /* PropertySignature */) { + if (node.kind !== 141 /* PropertyDeclaration */ && node.kind !== 140 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here checkExportsOnMergedDeclarations(node); - if (node.kind === 209 /* VariableDeclaration */ || node.kind === 161 /* BindingElement */) { + if (node.kind === 211 /* VariableDeclaration */ || node.kind === 163 /* BindingElement */) { checkVarDeclaredNamesNotShadowed(node); } checkCollisionWithCapturedSuperVariable(node, node.name); @@ -23660,7 +24246,7 @@ var ts; } function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) { // We only disallow modifier on a method declaration if it is a property of object-literal-expression - if (node.modifiers && node.parent.kind === 163 /* ObjectLiteralExpression */) { + if (node.modifiers && node.parent.kind === 165 /* ObjectLiteralExpression */) { if (ts.isAsyncFunctionLike(node)) { if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); @@ -23698,12 +24284,12 @@ var ts; function checkForStatement(node) { // Grammar checking if (!checkGrammarStatementInAmbientContext(node)) { - if (node.initializer && node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer && node.initializer.kind === 212 /* VariableDeclarationList */) { checkGrammarVariableDeclarationList(node.initializer); } } if (node.initializer) { - if (node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer.kind === 212 /* VariableDeclarationList */) { ts.forEach(node.initializer.declarations, checkVariableDeclaration); } else { @@ -23723,14 +24309,14 @@ var ts; // via checkRightHandSideOfForOf. // If the LHS is an expression, check the LHS, as a destructuring assignment or as a reference. // Then check that the RHS is assignable to it. - if (node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer.kind === 212 /* VariableDeclarationList */) { checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; var iteratedType = checkRightHandSideOfForOf(node.expression); // There may be a destructuring assignment on the left side - if (varExpr.kind === 162 /* ArrayLiteralExpression */ || varExpr.kind === 163 /* ObjectLiteralExpression */) { + if (varExpr.kind === 164 /* ArrayLiteralExpression */ || varExpr.kind === 165 /* ObjectLiteralExpression */) { // iteratedType may be undefined. In this case, we still want to check the structure of // varExpr, in particular making sure it's a valid LeftHandSideExpression. But we'd like // to short circuit the type relation checking as much as possible, so we pass the unknownType. @@ -23759,7 +24345,7 @@ var ts; // for (let VarDecl in Expr) Statement // VarDecl must be a variable declaration without a type annotation that declares a variable of type Any, // and Expr must be an expression of type Any, an object type, or a type parameter type. - if (node.initializer.kind === 210 /* VariableDeclarationList */) { + if (node.initializer.kind === 212 /* VariableDeclarationList */) { var variable = node.initializer.declarations[0]; if (variable && ts.isBindingPattern(variable.name)) { error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); @@ -23773,7 +24359,7 @@ var ts; // and Expr must be an expression of type Any, an object type, or a type parameter type. var varExpr = node.initializer; var leftType = checkExpression(varExpr); - if (varExpr.kind === 162 /* ArrayLiteralExpression */ || varExpr.kind === 163 /* ObjectLiteralExpression */) { + if (varExpr.kind === 164 /* ArrayLiteralExpression */ || varExpr.kind === 165 /* ObjectLiteralExpression */) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */)) { @@ -24012,7 +24598,7 @@ var ts; // TODO: Check that target label is valid } function isGetAccessorWithAnnotatatedSetAccessor(node) { - return !!(node.kind === 143 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 144 /* SetAccessor */))); + return !!(node.kind === 145 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 146 /* SetAccessor */))); } function checkReturnStatement(node) { // Grammar checking @@ -24035,10 +24621,10 @@ var ts; // for generators. return; } - if (func.kind === 144 /* SetAccessor */) { + if (func.kind === 146 /* SetAccessor */) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else if (func.kind === 142 /* Constructor */) { + else if (func.kind === 144 /* Constructor */) { if (!isTypeAssignableTo(exprType, returnType)) { error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } @@ -24047,7 +24633,12 @@ var ts; if (ts.isAsyncFunctionLike(func)) { var promisedType = getPromisedType(returnType); var awaitedType = checkAwaitedType(exprType, node.expression, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); - checkTypeAssignableTo(awaitedType, promisedType, node.expression); + if (promisedType) { + // If the function has a return type, but promisedType is + // undefined, an error will be reported in checkAsyncFunctionReturnType + // so we don't need to report one here. + checkTypeAssignableTo(awaitedType, promisedType, node.expression); + } } else { checkTypeAssignableTo(exprType, returnType, node.expression); @@ -24074,7 +24665,7 @@ var ts; var expressionType = checkExpression(node.expression); ts.forEach(node.caseBlock.clauses, function (clause) { // Grammar check for duplicate default clauses, skip if we already report duplicate default clause - if (clause.kind === 240 /* DefaultClause */ && !hasDuplicateDefaultClause) { + if (clause.kind === 242 /* DefaultClause */ && !hasDuplicateDefaultClause) { if (firstDefaultClause === undefined) { firstDefaultClause = clause; } @@ -24086,7 +24677,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (produceDiagnostics && clause.kind === 239 /* CaseClause */) { + if (produceDiagnostics && clause.kind === 241 /* CaseClause */) { var caseClause = clause; // TypeScript 1.0 spec (April 2014):5.9 // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. @@ -24107,7 +24698,7 @@ var ts; if (ts.isFunctionLike(current)) { break; } - if (current.kind === 205 /* LabeledStatement */ && current.label.text === node.label.text) { + if (current.kind === 207 /* LabeledStatement */ && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -24137,7 +24728,7 @@ var ts; if (catchClause) { // Grammar checking if (catchClause.variableDeclaration) { - if (catchClause.variableDeclaration.name.kind !== 67 /* Identifier */) { + if (catchClause.variableDeclaration.name.kind !== 69 /* Identifier */) { grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); } else if (catchClause.variableDeclaration.type) { @@ -24212,7 +24803,7 @@ var ts; // perform property check if property or indexer is declared in 'type' // this allows to rule out cases when both property and indexer are inherited from the base class var errorNode; - if (prop.valueDeclaration.name.kind === 134 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { + if (prop.valueDeclaration.name.kind === 136 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { @@ -24289,6 +24880,7 @@ var ts; checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { @@ -24307,7 +24899,7 @@ var ts; } } } - checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32 /* Class */)) { // When the static base type is a "class-like" constructor function (but not actually a class), we verify @@ -24324,7 +24916,8 @@ var ts; } var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node); if (implementedTypeNodes) { - ts.forEach(implementedTypeNodes, function (typeRefNode) { + for (var _b = 0; _b < implementedTypeNodes.length; _b++) { + var typeRefNode = implementedTypeNodes[_b]; if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) { error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments); } @@ -24334,14 +24927,14 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096 /* Reference */) ? t.target : t; if (declaredType.flags & (1024 /* Class */ | 2048 /* Interface */)) { - checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(t, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); } } } - }); + } } if (produceDiagnostics) { checkIndexConstraints(type); @@ -24392,7 +24985,7 @@ var ts; // If there is no declaration for the derived class (as in the case of class expressions), // then the class cannot be declared abstract. if (baseDeclarationFlags & 256 /* Abstract */ && (!derivedClassDecl || !(derivedClassDecl.flags & 256 /* Abstract */))) { - if (derivedClassDecl.kind === 184 /* ClassExpression */) { + if (derivedClassDecl.kind === 186 /* ClassExpression */) { error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, symbolToString(baseProperty), typeToString(baseType)); } else { @@ -24440,7 +25033,7 @@ var ts; } } function isAccessor(kind) { - return kind === 143 /* GetAccessor */ || kind === 144 /* SetAccessor */; + return kind === 145 /* GetAccessor */ || kind === 146 /* SetAccessor */; } function areTypeParametersIdentical(list1, list2) { if (!list1 && !list2) { @@ -24480,7 +25073,7 @@ var ts; var ok = true; for (var _i = 0; _i < baseTypes.length; _i++) { var base = baseTypes[_i]; - var properties = getPropertiesOfObjectType(base); + var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType)); for (var _a = 0; _a < properties.length; _a++) { var prop = properties[_a]; if (!ts.hasProperty(seen, prop.name)) { @@ -24510,7 +25103,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 213 /* InterfaceDeclaration */); + var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 215 /* InterfaceDeclaration */); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -24519,19 +25112,21 @@ var ts; // Only check this symbol once if (node === firstInterfaceDecl) { var type = getDeclaredTypeOfSymbol(symbol); + var typeWithThis = getTypeWithThisArgument(type); // run subsequent checks only if first set succeeded if (checkInheritedPropertiesAreIdentical(type, node.name)) { - ts.forEach(getBaseTypes(type), function (baseType) { - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); - }); + for (var _i = 0, _a = getBaseTypes(type); _i < _a.length; _i++) { + var baseType = _a[_i]; + checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1); + } checkIndexConstraints(type); } } // Interfaces cannot merge with non-ambient classes. if (symbol && symbol.declarations) { - for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { - var declaration = _a[_i]; - if (declaration.kind === 212 /* ClassDeclaration */ && !ts.isInAmbientContext(declaration)) { + for (var _b = 0, _c = symbol.declarations; _b < _c.length; _b++) { + var declaration = _c[_b]; + if (declaration.kind === 214 /* ClassDeclaration */ && !ts.isInAmbientContext(declaration)) { error(node, ts.Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface); break; } @@ -24560,24 +25155,38 @@ var ts; if (!(nodeLinks.flags & 8192 /* EnumValuesComputed */)) { var enumSymbol = getSymbolOfNode(node); var enumType = getDeclaredTypeOfSymbol(enumSymbol); - var autoValue = 0; + var autoValue = 0; // set to undefined when enum member is non-constant var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); - ts.forEach(node.members, function (member) { - if (member.name.kind !== 134 /* ComputedPropertyName */ && isNumericLiteralName(member.name.text)) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.name.kind === 136 /* ComputedPropertyName */) { + error(member.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); + } + else if (isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } + var previousEnumMemberIsNonConstant = autoValue === undefined; var initializer = member.initializer; if (initializer) { autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient); } else if (ambient && !enumIsConst) { + // In ambient enum declarations that specify no const modifier, enum member declarations + // that omit a value are considered computed members (as opposed to having auto-incremented values assigned). autoValue = undefined; } + else if (previousEnumMemberIsNonConstant) { + // If the member declaration specifies no value, the member is considered a constant enum member. + // If the member is the first member in the enum declaration, it is assigned the value zero. + // Otherwise, it is assigned the value of the immediately preceding member plus one, + // and an error occurs if the immediately preceding member is not a constant enum member + error(member.name, ts.Diagnostics.Enum_member_must_have_initializer); + } if (autoValue !== undefined) { getNodeLinks(member).enumMemberValue = autoValue++; } - }); + } nodeLinks.flags |= 8192 /* EnumValuesComputed */; } function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) { @@ -24590,11 +25199,11 @@ var ts; if (enumIsConst) { error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); } - else if (!ambient) { + else if (ambient) { + error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression); + } + else { // Only here do we need to check that the initializer is assignable to the enum type. - // If it is a constant value (not undefined), it is syntactically constrained to be a number. - // Also, we do not need to check this for ambients because there is already - // a syntax error if it is not a constant. checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); } } @@ -24610,7 +25219,7 @@ var ts; return value; function evalConstant(e) { switch (e.kind) { - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: var value_1 = evalConstant(e.operand); if (value_1 === undefined) { return undefined; @@ -24618,10 +25227,10 @@ var ts; switch (e.operator) { case 35 /* PlusToken */: return value_1; case 36 /* MinusToken */: return -value_1; - case 49 /* TildeToken */: return ~value_1; + case 50 /* TildeToken */: return ~value_1; } return undefined; - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: var left = evalConstant(e.left); if (left === undefined) { return undefined; @@ -24631,31 +25240,31 @@ var ts; return undefined; } switch (e.operatorToken.kind) { - case 46 /* BarToken */: return left | right; - case 45 /* AmpersandToken */: return left & right; - case 43 /* GreaterThanGreaterThanToken */: return left >> right; - case 44 /* GreaterThanGreaterThanGreaterThanToken */: return left >>> right; - case 42 /* LessThanLessThanToken */: return left << right; - case 47 /* CaretToken */: return left ^ right; + case 47 /* BarToken */: return left | right; + case 46 /* AmpersandToken */: return left & right; + case 44 /* GreaterThanGreaterThanToken */: return left >> right; + case 45 /* GreaterThanGreaterThanGreaterThanToken */: return left >>> right; + case 43 /* LessThanLessThanToken */: return left << right; + case 48 /* CaretToken */: return left ^ right; case 37 /* AsteriskToken */: return left * right; - case 38 /* SlashToken */: return left / right; + case 39 /* SlashToken */: return left / right; case 35 /* PlusToken */: return left + right; case 36 /* MinusToken */: return left - right; - case 39 /* PercentToken */: return left % right; + case 40 /* PercentToken */: return left % right; } return undefined; case 8 /* NumericLiteral */: return +e.text; - case 170 /* ParenthesizedExpression */: + case 172 /* ParenthesizedExpression */: return evalConstant(e.expression); - case 67 /* Identifier */: - case 165 /* ElementAccessExpression */: - case 164 /* PropertyAccessExpression */: + case 69 /* Identifier */: + case 167 /* ElementAccessExpression */: + case 166 /* PropertyAccessExpression */: var member = initializer.parent; var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); var enumType_1; var propertyName; - if (e.kind === 67 /* Identifier */) { + if (e.kind === 69 /* Identifier */) { // unqualified names can refer to member that reside in different declaration of the enum so just doing name resolution won't work. // instead pick current enum type and later try to fetch member from the type enumType_1 = currentType; @@ -24663,7 +25272,7 @@ var ts; } else { var expression; - if (e.kind === 165 /* ElementAccessExpression */) { + if (e.kind === 167 /* ElementAccessExpression */) { if (e.argumentExpression === undefined || e.argumentExpression.kind !== 9 /* StringLiteral */) { return undefined; @@ -24678,10 +25287,10 @@ var ts; // expression part in ElementAccess\PropertyAccess should be either identifier or dottedName var current = expression; while (current) { - if (current.kind === 67 /* Identifier */) { + if (current.kind === 69 /* Identifier */) { break; } - else if (current.kind === 164 /* PropertyAccessExpression */) { + else if (current.kind === 166 /* PropertyAccessExpression */) { current = current.expression; } else { @@ -24707,7 +25316,7 @@ var ts; return undefined; } // illegal case: forward reference - if (!isDefinedBefore(propertyDecl, member)) { + if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) { reportError = false; error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums); return undefined; @@ -24722,7 +25331,7 @@ var ts; return; } // Grammar checking - checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -24752,7 +25361,7 @@ var ts; var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { // return true if we hit a violation of the rule, false otherwise - if (declaration.kind !== 215 /* EnumDeclaration */) { + if (declaration.kind !== 217 /* EnumDeclaration */) { return false; } var enumDeclaration = declaration; @@ -24775,8 +25384,8 @@ var ts; var declarations = symbol.declarations; for (var _i = 0; _i < declarations.length; _i++) { var declaration = declarations[_i]; - if ((declaration.kind === 212 /* ClassDeclaration */ || - (declaration.kind === 211 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) && + if ((declaration.kind === 214 /* ClassDeclaration */ || + (declaration.kind === 213 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } @@ -24832,7 +25441,7 @@ var ts; } // if the module merges with a class declaration in the same lexical scope, // we need to track this to ensure the correct emit. - var mergedClass = ts.getDeclarationOfKind(symbol, 212 /* ClassDeclaration */); + var mergedClass = ts.getDeclarationOfKind(symbol, 214 /* ClassDeclaration */); if (mergedClass && inSameLexicalScope(node, mergedClass)) { getNodeLinks(node).flags |= 32768 /* LexicalModuleMergesWithClass */; @@ -24841,9 +25450,9 @@ var ts; // Checks for ambient external modules. if (isAmbientExternalModule) { if (!isGlobalSourceFile(node.parent)) { - error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules); + error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces); } - if (isExternalModuleNameRelative(node.name.text)) { + if (ts.isExternalModuleNameRelative(node.name.text)) { error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name); } } @@ -24852,17 +25461,17 @@ var ts; } function getFirstIdentifier(node) { while (true) { - if (node.kind === 133 /* QualifiedName */) { + if (node.kind === 135 /* QualifiedName */) { node = node.left; } - else if (node.kind === 164 /* PropertyAccessExpression */) { + else if (node.kind === 166 /* PropertyAccessExpression */) { node = node.expression; } else { break; } } - ts.Debug.assert(node.kind === 67 /* Identifier */); + ts.Debug.assert(node.kind === 69 /* Identifier */); return node; } function checkExternalImportOrExportDeclaration(node) { @@ -24871,14 +25480,14 @@ var ts; error(moduleName, ts.Diagnostics.String_literal_expected); return false; } - var inAmbientExternalModule = node.parent.kind === 217 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; - if (node.parent.kind !== 246 /* SourceFile */ && !inAmbientExternalModule) { - error(moduleName, node.kind === 226 /* ExportDeclaration */ ? + var inAmbientExternalModule = node.parent.kind === 219 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; + if (node.parent.kind !== 248 /* SourceFile */ && !inAmbientExternalModule) { + error(moduleName, node.kind === 228 /* ExportDeclaration */ ? ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace : ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module); return false; } - if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) { + if (inAmbientExternalModule && ts.isExternalModuleNameRelative(moduleName.text)) { // TypeScript 1.0 spec (April 2013): 12.1.6 // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference // other external modules only through top - level external module names. @@ -24896,7 +25505,7 @@ var ts; (symbol.flags & 793056 /* Type */ ? 793056 /* Type */ : 0) | (symbol.flags & 1536 /* Namespace */ ? 1536 /* Namespace */ : 0); if (target.flags & excludedMeanings) { - var message = node.kind === 228 /* ExportSpecifier */ ? + var message = node.kind === 230 /* ExportSpecifier */ ? ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; error(node, message, symbolToString(symbol)); @@ -24923,7 +25532,7 @@ var ts; checkImportBinding(importClause); } if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (importClause.namedBindings.kind === 224 /* NamespaceImport */) { checkImportBinding(importClause.namedBindings); } else { @@ -24960,9 +25569,9 @@ var ts; } } else { - if (languageVersion >= 2 /* ES6 */ && !ts.isInAmbientContext(node)) { + if (modulekind === 5 /* ES6 */ && !ts.isInAmbientContext(node)) { // Import equals declaration is deprecated in es6 or above - grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead); } } } @@ -24980,8 +25589,8 @@ var ts; // export { x, y } // export { x, y } from "foo" ts.forEach(node.exportClause.elements, checkExportSpecifier); - var inAmbientExternalModule = node.parent.kind === 217 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; - if (node.parent.kind !== 246 /* SourceFile */ && !inAmbientExternalModule) { + var inAmbientExternalModule = node.parent.kind === 219 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */; + if (node.parent.kind !== 248 /* SourceFile */ && !inAmbientExternalModule) { error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace); } } @@ -24995,7 +25604,7 @@ var ts; } } function checkGrammarModuleElementContext(node, errorMessage) { - if (node.parent.kind !== 246 /* SourceFile */ && node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 216 /* ModuleDeclaration */) { + if (node.parent.kind !== 248 /* SourceFile */ && node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 218 /* ModuleDeclaration */) { return grammarErrorOnFirstToken(node, errorMessage); } } @@ -25010,8 +25619,8 @@ var ts; // If we hit an export assignment in an illegal context, just bail out to avoid cascading errors. return; } - var container = node.parent.kind === 246 /* SourceFile */ ? node.parent : node.parent.parent; - if (container.kind === 216 /* ModuleDeclaration */ && container.name.kind === 67 /* Identifier */) { + var container = node.parent.kind === 248 /* SourceFile */ ? node.parent : node.parent.parent; + if (container.kind === 218 /* ModuleDeclaration */ && container.name.kind === 69 /* Identifier */) { error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace); return; } @@ -25019,7 +25628,7 @@ var ts; if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 2035 /* Modifier */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - if (node.expression.kind === 67 /* Identifier */) { + if (node.expression.kind === 69 /* Identifier */) { markExportAsReferenced(node); } else { @@ -25027,21 +25636,21 @@ var ts; } checkExternalModuleExports(container); if (node.isExportEquals && !ts.isInAmbientContext(node)) { - if (languageVersion >= 2 /* ES6 */) { - // export assignment is deprecated in es6 or above - grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + if (modulekind === 5 /* ES6 */) { + // export assignment is not supported in es6 modules + grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead); } - else if (compilerOptions.module === 4 /* System */) { + else if (modulekind === 4 /* System */) { // system modules does not support export assignment grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); } } } function getModuleStatements(node) { - if (node.kind === 246 /* SourceFile */) { + if (node.kind === 248 /* SourceFile */) { return node.statements; } - if (node.kind === 216 /* ModuleDeclaration */ && node.body.kind === 217 /* ModuleBlock */) { + if (node.kind === 218 /* ModuleDeclaration */ && node.body.kind === 219 /* ModuleBlock */) { return node.body.statements; } return emptyArray; @@ -25080,118 +25689,118 @@ var ts; // Only bother checking on a few construct kinds. We don't want to be excessivly // hitting the cancellation token on every node we check. switch (kind) { - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: return checkTypeParameter(node); - case 136 /* Parameter */: + case 138 /* Parameter */: return checkParameter(node); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return checkPropertyDeclaration(node); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: return checkSignatureDeclaration(node); - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: return checkSignatureDeclaration(node); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return checkMethodDeclaration(node); - case 142 /* Constructor */: + case 144 /* Constructor */: return checkConstructorDeclaration(node); - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return checkAccessorDeclaration(node); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return checkTypeReferenceNode(node); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return checkTypePredicate(node); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return checkTypeQuery(node); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return checkTypeLiteral(node); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return checkArrayType(node); - case 155 /* TupleType */: + case 157 /* TupleType */: return checkTupleType(node); - case 156 /* UnionType */: - case 157 /* IntersectionType */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: return checkUnionOrIntersectionType(node); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return checkSourceElement(node.type); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return checkFunctionDeclaration(node); - case 190 /* Block */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return checkBlock(node); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return checkVariableStatement(node); - case 193 /* ExpressionStatement */: + case 195 /* ExpressionStatement */: return checkExpressionStatement(node); - case 194 /* IfStatement */: + case 196 /* IfStatement */: return checkIfStatement(node); - case 195 /* DoStatement */: + case 197 /* DoStatement */: return checkDoStatement(node); - case 196 /* WhileStatement */: + case 198 /* WhileStatement */: return checkWhileStatement(node); - case 197 /* ForStatement */: + case 199 /* ForStatement */: return checkForStatement(node); - case 198 /* ForInStatement */: + case 200 /* ForInStatement */: return checkForInStatement(node); - case 199 /* ForOfStatement */: + case 201 /* ForOfStatement */: return checkForOfStatement(node); - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: return checkBreakOrContinueStatement(node); - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: return checkReturnStatement(node); - case 203 /* WithStatement */: + case 205 /* WithStatement */: return checkWithStatement(node); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: return checkSwitchStatement(node); - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return checkLabeledStatement(node); - case 206 /* ThrowStatement */: + case 208 /* ThrowStatement */: return checkThrowStatement(node); - case 207 /* TryStatement */: + case 209 /* TryStatement */: return checkTryStatement(node); - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: return checkVariableDeclaration(node); - case 161 /* BindingElement */: + case 163 /* BindingElement */: return checkBindingElement(node); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return checkClassDeclaration(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return checkEnumDeclaration(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return checkModuleDeclaration(node); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: return checkImportDeclaration(node); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return checkExportDeclaration(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return checkExportAssignment(node); - case 192 /* EmptyStatement */: + case 194 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; - case 208 /* DebuggerStatement */: + case 210 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; - case 229 /* MissingDeclaration */: + case 231 /* MissingDeclaration */: return checkMissingDeclaration(node); } } @@ -25206,97 +25815,98 @@ var ts; // Delaying the type check of the body ensures foo has been assigned a type. function checkFunctionAndClassExpressionBodies(node) { switch (node.kind) { - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: ts.forEach(node.members, checkSourceElement); + ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: ts.forEach(node.decorators, checkFunctionAndClassExpressionBodies); ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } break; - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: ts.forEach(node.parameters, checkFunctionAndClassExpressionBodies); break; - case 203 /* WithStatement */: + case 205 /* WithStatement */: checkFunctionAndClassExpressionBodies(node.expression); break; - case 137 /* Decorator */: - case 136 /* Parameter */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: - case 161 /* BindingElement */: - case 162 /* ArrayLiteralExpression */: - case 163 /* ObjectLiteralExpression */: - case 243 /* PropertyAssignment */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 168 /* TaggedTemplateExpression */: - case 181 /* TemplateExpression */: - case 188 /* TemplateSpan */: - case 169 /* TypeAssertionExpression */: - case 187 /* AsExpression */: - case 170 /* ParenthesizedExpression */: - case 174 /* TypeOfExpression */: - case 175 /* VoidExpression */: - case 176 /* AwaitExpression */: - case 173 /* DeleteExpression */: - case 177 /* PrefixUnaryExpression */: - case 178 /* PostfixUnaryExpression */: - case 179 /* BinaryExpression */: - case 180 /* ConditionalExpression */: - case 183 /* SpreadElementExpression */: - case 182 /* YieldExpression */: - case 190 /* Block */: - case 217 /* ModuleBlock */: - case 191 /* VariableStatement */: - case 193 /* ExpressionStatement */: - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: - case 202 /* ReturnStatement */: - case 204 /* SwitchStatement */: - case 218 /* CaseBlock */: - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - case 205 /* LabeledStatement */: - case 206 /* ThrowStatement */: - case 207 /* TryStatement */: - case 242 /* CatchClause */: - case 209 /* VariableDeclaration */: - case 210 /* VariableDeclarationList */: - case 212 /* ClassDeclaration */: - case 241 /* HeritageClause */: - case 186 /* ExpressionWithTypeArguments */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 225 /* ExportAssignment */: - case 246 /* SourceFile */: - case 238 /* JsxExpression */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 236 /* JsxAttribute */: - case 237 /* JsxSpreadAttribute */: - case 233 /* JsxOpeningElement */: + case 139 /* Decorator */: + case 138 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: + case 163 /* BindingElement */: + case 164 /* ArrayLiteralExpression */: + case 165 /* ObjectLiteralExpression */: + case 245 /* PropertyAssignment */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 170 /* TaggedTemplateExpression */: + case 183 /* TemplateExpression */: + case 190 /* TemplateSpan */: + case 171 /* TypeAssertionExpression */: + case 189 /* AsExpression */: + case 172 /* ParenthesizedExpression */: + case 176 /* TypeOfExpression */: + case 177 /* VoidExpression */: + case 178 /* AwaitExpression */: + case 175 /* DeleteExpression */: + case 179 /* PrefixUnaryExpression */: + case 180 /* PostfixUnaryExpression */: + case 181 /* BinaryExpression */: + case 182 /* ConditionalExpression */: + case 185 /* SpreadElementExpression */: + case 184 /* YieldExpression */: + case 192 /* Block */: + case 219 /* ModuleBlock */: + case 193 /* VariableStatement */: + case 195 /* ExpressionStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: + case 204 /* ReturnStatement */: + case 206 /* SwitchStatement */: + case 220 /* CaseBlock */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + case 207 /* LabeledStatement */: + case 208 /* ThrowStatement */: + case 209 /* TryStatement */: + case 244 /* CatchClause */: + case 211 /* VariableDeclaration */: + case 212 /* VariableDeclarationList */: + case 214 /* ClassDeclaration */: + case 243 /* HeritageClause */: + case 188 /* ExpressionWithTypeArguments */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 227 /* ExportAssignment */: + case 248 /* SourceFile */: + case 240 /* JsxExpression */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 238 /* JsxAttribute */: + case 239 /* JsxSpreadAttribute */: + case 235 /* JsxOpeningElement */: ts.forEachChild(node, checkFunctionAndClassExpressionBodies); break; } @@ -25382,7 +25992,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 203 /* WithStatement */ && node.parent.statement === node) { + if (node.parent.kind === 205 /* WithStatement */ && node.parent.statement === node) { return true; } node = node.parent; @@ -25405,34 +26015,34 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (!ts.isExternalModule(location)) { break; } - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 8914931 /* ModuleMember */); break; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */); break; - case 184 /* ClassExpression */: + case 186 /* ClassExpression */: var className = location.name; if (className) { copySymbol(location.symbol, meaning); } // fall through; this fall-through is necessary because we would like to handle // type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: // If we didn't come from static member of class or interface, - // add the type parameters into the symbol table + // add the type parameters into the symbol table // (type parameters of classDeclaration/classExpression and interface are in member property of the symbol. // Note: that the memberFlags come from previous iteration. if (!(memberFlags & 128 /* Static */)) { copySymbols(getSymbolOfNode(location).members, meaning & 793056 /* Type */); } break; - case 171 /* FunctionExpression */: + case 173 /* FunctionExpression */: var funcName = location.name; if (funcName) { copySymbol(location.symbol, meaning); @@ -25475,43 +26085,43 @@ var ts; } } function isTypeDeclarationName(name) { - return name.kind === 67 /* Identifier */ && + return name.kind === 69 /* Identifier */ && isTypeDeclaration(name.parent) && name.parent.name === name; } function isTypeDeclaration(node) { switch (node.kind) { - case 135 /* TypeParameter */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 215 /* EnumDeclaration */: + case 137 /* TypeParameter */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 217 /* EnumDeclaration */: return true; } } // True if the given identifier is part of a type reference function isTypeReferenceIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 133 /* QualifiedName */) { + while (node.parent && node.parent.kind === 135 /* QualifiedName */) { node = node.parent; } - return node.parent && node.parent.kind === 149 /* TypeReference */; + return node.parent && node.parent.kind === 151 /* TypeReference */; } function isHeritageClauseElementIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 164 /* PropertyAccessExpression */) { + while (node.parent && node.parent.kind === 166 /* PropertyAccessExpression */) { node = node.parent; } - return node.parent && node.parent.kind === 186 /* ExpressionWithTypeArguments */; + return node.parent && node.parent.kind === 188 /* ExpressionWithTypeArguments */; } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { - while (nodeOnRightSide.parent.kind === 133 /* QualifiedName */) { + while (nodeOnRightSide.parent.kind === 135 /* QualifiedName */) { nodeOnRightSide = nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 219 /* ImportEqualsDeclaration */) { + if (nodeOnRightSide.parent.kind === 221 /* ImportEqualsDeclaration */) { return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 225 /* ExportAssignment */) { + if (nodeOnRightSide.parent.kind === 227 /* ExportAssignment */) { return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; @@ -25523,11 +26133,11 @@ var ts; if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 225 /* ExportAssignment */) { + if (entityName.parent.kind === 227 /* ExportAssignment */) { return resolveEntityName(entityName, /*all meanings*/ 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */ | 8388608 /* Alias */); } - if (entityName.kind !== 164 /* PropertyAccessExpression */) { + if (entityName.kind !== 166 /* PropertyAccessExpression */) { if (isInRightSideOfImportOrExportAssignment(entityName)) { // Since we already checked for ExportAssignment, this really could only be an Import return getSymbolOfPartOfRightHandSideOfImportEquals(entityName); @@ -25537,13 +26147,24 @@ var ts; entityName = entityName.parent; } if (isHeritageClauseElementIdentifier(entityName)) { - var meaning = entityName.parent.kind === 186 /* ExpressionWithTypeArguments */ ? 793056 /* Type */ : 1536 /* Namespace */; + var meaning = 0 /* None */; + // In an interface or class, we're definitely interested in a type. + if (entityName.parent.kind === 188 /* ExpressionWithTypeArguments */) { + meaning = 793056 /* Type */; + // In a class 'extends' clause we are also looking for a value. + if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent)) { + meaning |= 107455 /* Value */; + } + } + else { + meaning = 1536 /* Namespace */; + } meaning |= 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } - else if ((entityName.parent.kind === 233 /* JsxOpeningElement */) || - (entityName.parent.kind === 232 /* JsxSelfClosingElement */) || - (entityName.parent.kind === 235 /* JsxClosingElement */)) { + else if ((entityName.parent.kind === 235 /* JsxOpeningElement */) || + (entityName.parent.kind === 234 /* JsxSelfClosingElement */) || + (entityName.parent.kind === 237 /* JsxClosingElement */)) { return getJsxElementTagSymbol(entityName.parent); } else if (ts.isExpression(entityName)) { @@ -25551,20 +26172,20 @@ var ts; // Missing entity name. return undefined; } - if (entityName.kind === 67 /* Identifier */) { + if (entityName.kind === 69 /* Identifier */) { // Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead // return the alias symbol. var meaning = 107455 /* Value */ | 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } - else if (entityName.kind === 164 /* PropertyAccessExpression */) { + else if (entityName.kind === 166 /* PropertyAccessExpression */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccessExpression(entityName); } return getNodeLinks(entityName).resolvedSymbol; } - else if (entityName.kind === 133 /* QualifiedName */) { + else if (entityName.kind === 135 /* QualifiedName */) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkQualifiedName(entityName); @@ -25573,16 +26194,16 @@ var ts; } } else if (isTypeReferenceIdentifier(entityName)) { - var meaning = entityName.parent.kind === 149 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; + var meaning = entityName.parent.kind === 151 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */; // Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead // return the alias symbol. meaning |= 8388608 /* Alias */; return resolveEntityName(entityName, meaning); } - else if (entityName.parent.kind === 236 /* JsxAttribute */) { + else if (entityName.parent.kind === 238 /* JsxAttribute */) { return getJsxAttributePropertySymbol(entityName.parent); } - if (entityName.parent.kind === 148 /* TypePredicate */) { + if (entityName.parent.kind === 150 /* TypePredicate */) { return resolveEntityName(entityName, /*meaning*/ 1 /* FunctionScopedVariable */); } // Do we want to return undefined here? @@ -25597,14 +26218,14 @@ var ts; // This is a declaration, call getSymbolOfNode return getSymbolOfNode(node.parent); } - if (node.kind === 67 /* Identifier */) { + if (node.kind === 69 /* Identifier */) { if (isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 225 /* ExportAssignment */ + return node.parent.kind === 227 /* ExportAssignment */ ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImportEquals(node); } - else if (node.parent.kind === 161 /* BindingElement */ && - node.parent.parent.kind === 159 /* ObjectBindingPattern */ && + else if (node.parent.kind === 163 /* BindingElement */ && + node.parent.parent.kind === 161 /* ObjectBindingPattern */ && node === node.parent.propertyName) { var typeOfPattern = getTypeOfNode(node.parent.parent); var propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, node.text); @@ -25614,18 +26235,18 @@ var ts; } } switch (node.kind) { - case 67 /* Identifier */: - case 164 /* PropertyAccessExpression */: - case 133 /* QualifiedName */: + case 69 /* Identifier */: + case 166 /* PropertyAccessExpression */: + case 135 /* QualifiedName */: return getSymbolOfEntityNameOrPropertyAccessExpression(node); - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: - var type = checkExpression(node); + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: + var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; - case 119 /* ConstructorKeyword */: + case 121 /* ConstructorKeyword */: // constructor keyword for an overload, should take us to the definition if it exist var constructorDeclaration = node.parent; - if (constructorDeclaration && constructorDeclaration.kind === 142 /* Constructor */) { + if (constructorDeclaration && constructorDeclaration.kind === 144 /* Constructor */) { return constructorDeclaration.parent.symbol; } return undefined; @@ -25633,14 +26254,14 @@ var ts; // External module name in an import declaration if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || - ((node.parent.kind === 220 /* ImportDeclaration */ || node.parent.kind === 226 /* ExportDeclaration */) && + ((node.parent.kind === 222 /* ImportDeclaration */ || node.parent.kind === 228 /* ExportDeclaration */) && node.parent.moduleSpecifier === node)) { return resolveExternalModuleName(node, node); } // Fall through case 8 /* NumericLiteral */: // index access - if (node.parent.kind === 165 /* ElementAccessExpression */ && node.parent.argumentExpression === node) { + if (node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.argumentExpression === node) { var objectType = checkExpression(node.parent.expression); if (objectType === unknownType) return undefined; @@ -25657,7 +26278,7 @@ var ts; // The function returns a value symbol of an identifier in the short-hand property assignment. // This is necessary as an identifier in short-hand property assignment can contains two meaning: // property name and property value. - if (location && location.kind === 244 /* ShorthandPropertyAssignment */) { + if (location && location.kind === 246 /* ShorthandPropertyAssignment */) { return resolveEntityName(location.name, 107455 /* Value */); } return undefined; @@ -25774,11 +26395,11 @@ var ts; } var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { - if (parentSymbol.flags & 512 /* ValueModule */ && parentSymbol.valueDeclaration.kind === 246 /* SourceFile */) { + if (parentSymbol.flags & 512 /* ValueModule */ && parentSymbol.valueDeclaration.kind === 248 /* SourceFile */) { return parentSymbol.valueDeclaration; } for (var n = node.parent; n; n = n.parent) { - if ((n.kind === 216 /* ModuleDeclaration */ || n.kind === 215 /* EnumDeclaration */) && getSymbolOfNode(n) === parentSymbol) { + if ((n.kind === 218 /* ModuleDeclaration */ || n.kind === 217 /* EnumDeclaration */) && getSymbolOfNode(n) === parentSymbol) { return n; } } @@ -25793,11 +26414,11 @@ var ts; } function isStatementWithLocals(node) { switch (node.kind) { - case 190 /* Block */: - case 218 /* CaseBlock */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 192 /* Block */: + case 220 /* CaseBlock */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return true; } return false; @@ -25827,22 +26448,22 @@ var ts; } function isValueAliasDeclaration(node) { switch (node.kind) { - case 219 /* ImportEqualsDeclaration */: - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: return isAliasResolvedToValue(getSymbolOfNode(node)); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: var exportClause = node.exportClause; return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration); - case 225 /* ExportAssignment */: - return node.expression && node.expression.kind === 67 /* Identifier */ ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; + case 227 /* ExportAssignment */: + return node.expression && node.expression.kind === 69 /* Identifier */ ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; } return false; } function isTopLevelValueImportEqualsWithEntityName(node) { - if (node.parent.kind !== 246 /* SourceFile */ || !ts.isInternalModuleImportEqualsDeclaration(node)) { + if (node.parent.kind !== 248 /* SourceFile */ || !ts.isInternalModuleImportEqualsDeclaration(node)) { // parent is not source file or it is not reference to internal module return false; } @@ -25904,7 +26525,7 @@ var ts; return getNodeLinks(node).enumMemberValue; } function getConstantValue(node) { - if (node.kind === 245 /* EnumMember */) { + if (node.kind === 247 /* EnumMember */) { return getEnumMemberValue(node); } var symbol = getNodeLinks(node).resolvedSymbol; @@ -25996,23 +26617,6 @@ var ts; var symbol = getReferencedValueSymbol(reference); return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } - function getBlockScopedVariableId(n) { - ts.Debug.assert(!ts.nodeIsSynthesized(n)); - var isVariableDeclarationOrBindingElement = n.parent.kind === 161 /* BindingElement */ || (n.parent.kind === 209 /* VariableDeclaration */ && n.parent.name === n); - var symbol = (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) || - getNodeLinks(n).resolvedSymbol || - resolveName(n, n.text, 107455 /* Value */ | 8388608 /* Alias */, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); - var isLetOrConst = symbol && - (symbol.flags & 2 /* BlockScopedVariable */) && - symbol.valueDeclaration.parent.kind !== 242 /* CatchClause */; - if (isLetOrConst) { - // side-effect of calling this method: - // assign id to symbol if it was not yet set - getSymbolLinks(symbol); - return symbol.id; - } - return undefined; - } function instantiateSingleCallFunctionType(functionType, typeArguments) { if (functionType === unknownType) { return unknownType; @@ -26044,7 +26648,6 @@ var ts; isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, collectLinkedAliases: collectLinkedAliases, - getBlockScopedVariableId: getBlockScopedVariableId, getReferencedValueDeclaration: getReferencedValueDeclaration, getTypeReferenceSerializationKind: getTypeReferenceSerializationKind, isOptionalParameter: isOptionalParameter @@ -26136,10 +26739,7 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here); } - else if (languageVersion < 1 /* ES5 */) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher); - } - else if (node.kind === 143 /* GetAccessor */ || node.kind === 144 /* SetAccessor */) { + else if (node.kind === 145 /* GetAccessor */ || node.kind === 146 /* SetAccessor */) { var accessors = ts.getAllAccessorDeclarations(node.parent.members, node); if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name); @@ -26149,38 +26749,38 @@ var ts; } function checkGrammarModifiers(node) { switch (node.kind) { - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 147 /* IndexSignature */: - case 216 /* ModuleDeclaration */: - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 226 /* ExportDeclaration */: - case 225 /* ExportAssignment */: - case 136 /* Parameter */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 149 /* IndexSignature */: + case 218 /* ModuleDeclaration */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 228 /* ExportDeclaration */: + case 227 /* ExportAssignment */: + case 138 /* Parameter */: break; - case 211 /* FunctionDeclaration */: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 116 /* AsyncKeyword */) && - node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 246 /* SourceFile */) { + case 213 /* FunctionDeclaration */: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 118 /* AsyncKeyword */) && + node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 191 /* VariableStatement */: - case 214 /* TypeAliasDeclaration */: - if (node.modifiers && node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 246 /* SourceFile */) { + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 193 /* VariableStatement */: + case 216 /* TypeAliasDeclaration */: + if (node.modifiers && node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; - case 215 /* EnumDeclaration */: - if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 72 /* ConstKeyword */) && - node.parent.kind !== 217 /* ModuleBlock */ && node.parent.kind !== 246 /* SourceFile */) { + case 217 /* EnumDeclaration */: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 74 /* ConstKeyword */) && + node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); } break; @@ -26195,14 +26795,14 @@ var ts; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; switch (modifier.kind) { - case 110 /* PublicKeyword */: - case 109 /* ProtectedKeyword */: - case 108 /* PrivateKeyword */: + case 112 /* PublicKeyword */: + case 111 /* ProtectedKeyword */: + case 110 /* PrivateKeyword */: var text = void 0; - if (modifier.kind === 110 /* PublicKeyword */) { + if (modifier.kind === 112 /* PublicKeyword */) { text = "public"; } - else if (modifier.kind === 109 /* ProtectedKeyword */) { + else if (modifier.kind === 111 /* ProtectedKeyword */) { text = "protected"; lastProtected = modifier; } @@ -26219,11 +26819,11 @@ var ts; else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); } - else if (node.parent.kind === 217 /* ModuleBlock */ || node.parent.kind === 246 /* SourceFile */) { + else if (node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); } else if (flags & 256 /* Abstract */) { - if (modifier.kind === 108 /* PrivateKeyword */) { + if (modifier.kind === 110 /* PrivateKeyword */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract"); } else { @@ -26232,17 +26832,17 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 111 /* StaticKeyword */: + case 113 /* StaticKeyword */: if (flags & 128 /* Static */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } - else if (node.parent.kind === 217 /* ModuleBlock */ || node.parent.kind === 246 /* SourceFile */) { + else if (node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } else if (flags & 256 /* Abstract */) { @@ -26251,7 +26851,7 @@ var ts; flags |= 128 /* Static */; lastStatic = modifier; break; - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: if (flags & 1 /* Export */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); } @@ -26264,42 +26864,42 @@ var ts; else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= 1 /* Export */; break; - case 120 /* DeclareKeyword */: + case 122 /* DeclareKeyword */: if (flags & 2 /* Ambient */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } else if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } - else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 217 /* ModuleBlock */) { + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 219 /* ModuleBlock */) { return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= 2 /* Ambient */; lastDeclare = modifier; break; - case 113 /* AbstractKeyword */: + case 115 /* AbstractKeyword */: if (flags & 256 /* Abstract */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract"); } - if (node.kind !== 212 /* ClassDeclaration */) { - if (node.kind !== 141 /* MethodDeclaration */) { + if (node.kind !== 214 /* ClassDeclaration */) { + if (node.kind !== 143 /* MethodDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration); } - if (!(node.parent.kind === 212 /* ClassDeclaration */ && node.parent.flags & 256 /* Abstract */)) { + if (!(node.parent.kind === 214 /* ClassDeclaration */ && node.parent.flags & 256 /* Abstract */)) { return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); } if (flags & 128 /* Static */) { @@ -26311,14 +26911,14 @@ var ts; } flags |= 256 /* Abstract */; break; - case 116 /* AsyncKeyword */: + case 118 /* AsyncKeyword */: if (flags & 512 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async"); } else if (flags & 2 /* Ambient */ || ts.isInAmbientContext(node.parent)) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } - else if (node.kind === 136 /* Parameter */) { + else if (node.kind === 138 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); } flags |= 512 /* Async */; @@ -26326,7 +26926,7 @@ var ts; break; } } - if (node.kind === 142 /* Constructor */) { + if (node.kind === 144 /* Constructor */) { if (flags & 128 /* Static */) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); } @@ -26344,10 +26944,10 @@ var ts; } return; } - else if ((node.kind === 220 /* ImportDeclaration */ || node.kind === 219 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) { + else if ((node.kind === 222 /* ImportDeclaration */ || node.kind === 221 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 136 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { + else if (node.kind === 138 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } if (flags & 512 /* Async */) { @@ -26359,10 +26959,10 @@ var ts; return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher); } switch (node.kind) { - case 141 /* MethodDeclaration */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: if (!node.asteriskToken) { return false; } @@ -26428,7 +27028,7 @@ var ts; checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } function checkGrammarArrowFunction(node, file) { - if (node.kind === 172 /* ArrowFunction */) { + if (node.kind === 174 /* ArrowFunction */) { var arrowFunction = node; var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line; var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line; @@ -26463,7 +27063,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 128 /* StringKeyword */ && parameter.type.kind !== 126 /* NumberKeyword */) { + if (parameter.type.kind !== 130 /* StringKeyword */ && parameter.type.kind !== 128 /* NumberKeyword */) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -26496,7 +27096,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var _i = 0; _i < args.length; _i++) { var arg = args[_i]; - if (arg.kind === 185 /* OmittedExpression */) { + if (arg.kind === 187 /* OmittedExpression */) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -26523,7 +27123,7 @@ var ts; if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81 /* ExtendsKeyword */) { + if (heritageClause.token === 83 /* ExtendsKeyword */) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } @@ -26536,7 +27136,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 106 /* ImplementsKeyword */); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -26552,14 +27152,14 @@ var ts; if (node.heritageClauses) { for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) { var heritageClause = _a[_i]; - if (heritageClause.token === 81 /* ExtendsKeyword */) { + if (heritageClause.token === 83 /* ExtendsKeyword */) { if (seenExtendsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen); } seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 104 /* ImplementsKeyword */); + ts.Debug.assert(heritageClause.token === 106 /* ImplementsKeyword */); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } // Grammar checking heritageClause inside class declaration @@ -26570,19 +27170,19 @@ var ts; } function checkGrammarComputedPropertyName(node) { // If node is not a computedPropertyName, just skip the grammar checking - if (node.kind !== 134 /* ComputedPropertyName */) { + if (node.kind !== 136 /* ComputedPropertyName */) { return false; } var computedPropertyName = node; - if (computedPropertyName.expression.kind === 179 /* BinaryExpression */ && computedPropertyName.expression.operatorToken.kind === 24 /* CommaToken */) { + if (computedPropertyName.expression.kind === 181 /* BinaryExpression */ && computedPropertyName.expression.operatorToken.kind === 24 /* CommaToken */) { return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - ts.Debug.assert(node.kind === 211 /* FunctionDeclaration */ || - node.kind === 171 /* FunctionExpression */ || - node.kind === 141 /* MethodDeclaration */); + ts.Debug.assert(node.kind === 213 /* FunctionDeclaration */ || + node.kind === 173 /* FunctionExpression */ || + node.kind === 143 /* MethodDeclaration */); if (ts.isInAmbientContext(node)) { return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); } @@ -26599,7 +27199,7 @@ var ts; return grammarErrorOnNode(questionToken, message); } } - function checkGrammarObjectLiteralExpression(node) { + function checkGrammarObjectLiteralExpression(node, inDestructuring) { var seen = {}; var Property = 1; var GetAccessor = 2; @@ -26608,12 +27208,17 @@ var ts; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; var name_16 = prop.name; - if (prop.kind === 185 /* OmittedExpression */ || - name_16.kind === 134 /* ComputedPropertyName */) { + if (prop.kind === 187 /* OmittedExpression */ || + name_16.kind === 136 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it checkGrammarComputedPropertyName(name_16); continue; } + if (prop.kind === 246 /* ShorthandPropertyAssignment */ && !inDestructuring && prop.objectAssignmentInitializer) { + // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern + // outside of destructuring it is a syntax error + return grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment); + } // ECMA-262 11.1.5 Object Initialiser // If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true // a.This production is contained in strict code and IsDataDescriptor(previous) is true and @@ -26623,7 +27228,7 @@ var ts; // d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true // and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields var currentKind = void 0; - if (prop.kind === 243 /* PropertyAssignment */ || prop.kind === 244 /* ShorthandPropertyAssignment */) { + if (prop.kind === 245 /* PropertyAssignment */ || prop.kind === 246 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); if (name_16.kind === 8 /* NumericLiteral */) { @@ -26631,13 +27236,13 @@ var ts; } currentKind = Property; } - else if (prop.kind === 141 /* MethodDeclaration */) { + else if (prop.kind === 143 /* MethodDeclaration */) { currentKind = Property; } - else if (prop.kind === 143 /* GetAccessor */) { + else if (prop.kind === 145 /* GetAccessor */) { currentKind = GetAccessor; } - else if (prop.kind === 144 /* SetAccessor */) { + else if (prop.kind === 146 /* SetAccessor */) { currentKind = SetAccesor; } else { @@ -26669,7 +27274,7 @@ var ts; var seen = {}; for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) { var attr = _a[_i]; - if (attr.kind === 237 /* JsxSpreadAttribute */) { + if (attr.kind === 239 /* JsxSpreadAttribute */) { continue; } var jsxAttr = attr; @@ -26681,7 +27286,7 @@ var ts; return grammarErrorOnNode(name_17, ts.Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name); } var initializer = jsxAttr.initializer; - if (initializer && initializer.kind === 238 /* JsxExpression */ && !initializer.expression) { + if (initializer && initializer.kind === 240 /* JsxExpression */ && !initializer.expression) { return grammarErrorOnNode(jsxAttr.initializer, ts.Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression); } } @@ -26690,24 +27295,24 @@ var ts; if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) { return true; } - if (forInOrOfStatement.initializer.kind === 210 /* VariableDeclarationList */) { + if (forInOrOfStatement.initializer.kind === 212 /* VariableDeclarationList */) { var variableList = forInOrOfStatement.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { - var diagnostic = forInOrOfStatement.kind === 198 /* ForInStatement */ + var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */ ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic); } var firstDeclaration = variableList.declarations[0]; if (firstDeclaration.initializer) { - var diagnostic = forInOrOfStatement.kind === 198 /* ForInStatement */ + var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */ ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; return grammarErrorOnNode(firstDeclaration.name, diagnostic); } if (firstDeclaration.type) { - var diagnostic = forInOrOfStatement.kind === 198 /* ForInStatement */ + var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */ ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; return grammarErrorOnNode(firstDeclaration, diagnostic); @@ -26730,10 +27335,10 @@ var ts; else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } - else if (kind === 143 /* GetAccessor */ && accessor.parameters.length) { + else if (kind === 145 /* GetAccessor */ && accessor.parameters.length) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); } - else if (kind === 144 /* SetAccessor */) { + else if (kind === 146 /* SetAccessor */) { if (accessor.type) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); } @@ -26758,7 +27363,7 @@ var ts; } } function checkGrammarForNonSymbolComputedProperty(node, message) { - if (node.kind === 134 /* ComputedPropertyName */ && !ts.isWellKnownSymbolSyntactically(node.expression)) { + if (node.kind === 136 /* ComputedPropertyName */ && !ts.isWellKnownSymbolSyntactically(node.expression)) { return grammarErrorOnNode(node, message); } } @@ -26768,7 +27373,7 @@ var ts; checkGrammarForGenerator(node)) { return true; } - if (node.parent.kind === 163 /* ObjectLiteralExpression */) { + if (node.parent.kind === 165 /* ObjectLiteralExpression */) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -26792,22 +27397,22 @@ var ts; return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol); } } - else if (node.parent.kind === 213 /* InterfaceDeclaration */) { + else if (node.parent.kind === 215 /* InterfaceDeclaration */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol); } - else if (node.parent.kind === 153 /* TypeLiteral */) { + else if (node.parent.kind === 155 /* TypeLiteral */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol); } } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: return true; - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -26819,11 +27424,11 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: if (node.label && current.label.text === node.label.text) { // found matching label - verify that label usage is correct // continue can only target labels that are on iteration statements - var isMisplacedContinueLabel = node.kind === 200 /* ContinueStatement */ + var isMisplacedContinueLabel = node.kind === 202 /* ContinueStatement */ && !isIterationStatement(current.statement, /*lookInLabeledStatement*/ true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); @@ -26831,8 +27436,8 @@ var ts; return false; } break; - case 204 /* SwitchStatement */: - if (node.kind === 201 /* BreakStatement */ && !node.label) { + case 206 /* SwitchStatement */: + if (node.kind === 203 /* BreakStatement */ && !node.label) { // unlabeled break within switch statement - ok return false; } @@ -26847,13 +27452,13 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 201 /* BreakStatement */ + var message = node.kind === 203 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 201 /* BreakStatement */ + var message = node.kind === 203 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); @@ -26865,7 +27470,7 @@ var ts; if (node !== ts.lastOrUndefined(elements)) { return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); } - if (node.name.kind === 160 /* ArrayBindingPattern */ || node.name.kind === 159 /* ObjectBindingPattern */) { + if (node.name.kind === 162 /* ArrayBindingPattern */ || node.name.kind === 161 /* ObjectBindingPattern */) { return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); } if (node.initializer) { @@ -26875,7 +27480,7 @@ var ts; } } function checkGrammarVariableDeclaration(node) { - if (node.parent.parent.kind !== 198 /* ForInStatement */ && node.parent.parent.kind !== 199 /* ForOfStatement */) { + if (node.parent.parent.kind !== 200 /* ForInStatement */ && node.parent.parent.kind !== 201 /* ForOfStatement */) { if (ts.isInAmbientContext(node)) { if (node.initializer) { // Error on equals token which immediate precedes the initializer @@ -26902,7 +27507,7 @@ var ts; return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name); } function checkGrammarNameInLetOrConstDeclarations(name) { - if (name.kind === 67 /* Identifier */) { + if (name.kind === 69 /* Identifier */) { if (name.text === "let") { return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations); } @@ -26911,7 +27516,7 @@ var ts; var elements = name.elements; for (var _i = 0; _i < elements.length; _i++) { var element = elements[_i]; - if (element.kind !== 185 /* OmittedExpression */) { + if (element.kind !== 187 /* OmittedExpression */) { checkGrammarNameInLetOrConstDeclarations(element.name); } } @@ -26928,15 +27533,15 @@ var ts; } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 194 /* IfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 196 /* IfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return false; - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: return allowLetAndConstDeclarations(parent.parent); } return true; @@ -26952,7 +27557,7 @@ var ts; } } function isIntegerLiteral(expression) { - if (expression.kind === 177 /* PrefixUnaryExpression */) { + if (expression.kind === 179 /* PrefixUnaryExpression */) { var unaryExpression = expression; if (unaryExpression.operator === 35 /* PlusToken */ || unaryExpression.operator === 36 /* MinusToken */) { expression = unaryExpression.operand; @@ -26968,37 +27573,6 @@ var ts; } return false; } - function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 32768 /* Const */) !== 0; - var hasError = false; - // skip checks below for const enums - they allow arbitrary initializers as long as they can be evaluated to constant expressions. - // since all values are known in compile time - it is not necessary to check that constant enum section precedes computed enum members. - if (!enumIsConst) { - var inConstantEnumMemberSection = true; - var inAmbientContext = ts.isInAmbientContext(enumDecl); - for (var _i = 0, _a = enumDecl.members; _i < _a.length; _i++) { - var node = _a[_i]; - // Do not use hasDynamicName here, because that returns false for well known symbols. - // We want to perform checkComputedPropertyName for all computed properties, including - // well known symbols. - if (node.name.kind === 134 /* ComputedPropertyName */) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); - } - else if (inAmbientContext) { - if (node.initializer && !isIntegerLiteral(node.initializer)) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError; - } - } - else if (node.initializer) { - inConstantEnumMemberSection = isIntegerLiteral(node.initializer); - } - else if (!inConstantEnumMemberSection) { - hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError; - } - } - } - return hasError; - } function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } @@ -27024,7 +27598,7 @@ var ts; } } function isEvalOrArgumentsIdentifier(node) { - return node.kind === 67 /* Identifier */ && + return node.kind === 69 /* Identifier */ && (node.text === "eval" || node.text === "arguments"); } function checkGrammarConstructorTypeParameters(node) { @@ -27044,12 +27618,12 @@ var ts; return true; } } - else if (node.parent.kind === 213 /* InterfaceDeclaration */) { + else if (node.parent.kind === 215 /* InterfaceDeclaration */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } } - else if (node.parent.kind === 153 /* TypeLiteral */) { + else if (node.parent.kind === 155 /* TypeLiteral */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } @@ -27069,11 +27643,11 @@ var ts; // export_opt ExternalImportDeclaration // export_opt AmbientDeclaration // - if (node.kind === 213 /* InterfaceDeclaration */ || - node.kind === 220 /* ImportDeclaration */ || - node.kind === 219 /* ImportEqualsDeclaration */ || - node.kind === 226 /* ExportDeclaration */ || - node.kind === 225 /* ExportAssignment */ || + if (node.kind === 215 /* InterfaceDeclaration */ || + node.kind === 222 /* ImportDeclaration */ || + node.kind === 221 /* ImportEqualsDeclaration */ || + node.kind === 228 /* ExportDeclaration */ || + node.kind === 227 /* ExportAssignment */ || (node.flags & 2 /* Ambient */) || (node.flags & (1 /* Export */ | 1024 /* Default */))) { return false; @@ -27083,7 +27657,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var decl = _a[_i]; - if (ts.isDeclaration(decl) || decl.kind === 191 /* VariableStatement */) { + if (ts.isDeclaration(decl) || decl.kind === 193 /* VariableStatement */) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -27109,7 +27683,7 @@ var ts; // to prevent noisyness. So use a bit on the block to indicate if // this has already been reported, and don't report if it has. // - if (node.parent.kind === 190 /* Block */ || node.parent.kind === 217 /* ModuleBlock */ || node.parent.kind === 246 /* SourceFile */) { + if (node.parent.kind === 192 /* Block */ || node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) { var links_1 = getNodeLinks(node.parent); // Check if the containing block ever report this error if (!links_1.hasReportedStatementInAmbientContext) { @@ -27160,6 +27734,7 @@ var ts; var enclosingDeclaration; var currentSourceFile; var reportedDeclarationError = false; + var errorNameNode; var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments; var emit = compilerOptions.stripInternal ? stripInternal : emitNode; var moduleElementDeclarationEmitInfo = []; @@ -27191,7 +27766,7 @@ var ts; var oldWriter = writer; ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) { if (aliasEmitInfo.isVisible) { - ts.Debug.assert(aliasEmitInfo.node.kind === 220 /* ImportDeclaration */); + ts.Debug.assert(aliasEmitInfo.node.kind === 222 /* ImportDeclaration */); createAndSetNewTextWriterWithSymbolWriter(); ts.Debug.assert(aliasEmitInfo.indent === 0); writeImportDeclaration(aliasEmitInfo.node); @@ -27245,6 +27820,7 @@ var ts; function createAndSetNewTextWriterWithSymbolWriter() { var writer = ts.createTextWriter(newLine); writer.trackSymbol = trackSymbol; + writer.reportInaccessibleThisError = reportInaccessibleThisError; writer.writeKeyword = writer.write; writer.writeOperator = writer.write; writer.writePunctuation = writer.write; @@ -27267,10 +27843,10 @@ var ts; var oldWriter = writer; ts.forEach(nodes, function (declaration) { var nodeToCheck; - if (declaration.kind === 209 /* VariableDeclaration */) { + if (declaration.kind === 211 /* VariableDeclaration */) { nodeToCheck = declaration.parent.parent; } - else if (declaration.kind === 223 /* NamedImports */ || declaration.kind === 224 /* ImportSpecifier */ || declaration.kind === 221 /* ImportClause */) { + else if (declaration.kind === 225 /* NamedImports */ || declaration.kind === 226 /* ImportSpecifier */ || declaration.kind === 223 /* ImportClause */) { ts.Debug.fail("We should be getting ImportDeclaration instead to write"); } else { @@ -27288,7 +27864,7 @@ var ts; // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, // we would write alias foo declaration when we visit it since it would now be marked as visible if (moduleElementEmitInfo) { - if (moduleElementEmitInfo.node.kind === 220 /* ImportDeclaration */) { + if (moduleElementEmitInfo.node.kind === 222 /* ImportDeclaration */) { // we have to create asynchronous output only after we have collected complete information // because it is possible to enable multiple bindings as asynchronously visible moduleElementEmitInfo.isVisible = true; @@ -27298,12 +27874,12 @@ var ts; for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { increaseIndent(); } - if (nodeToCheck.kind === 216 /* ModuleDeclaration */) { + if (nodeToCheck.kind === 218 /* ModuleDeclaration */) { ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); asynchronousSubModuleDeclarationEmitInfo = []; } writeModuleElement(nodeToCheck); - if (nodeToCheck.kind === 216 /* ModuleDeclaration */) { + if (nodeToCheck.kind === 218 /* ModuleDeclaration */) { moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; asynchronousSubModuleDeclarationEmitInfo = undefined; } @@ -27337,6 +27913,11 @@ var ts; function trackSymbol(symbol, enclosingDeclaration, meaning) { handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); } + function reportInaccessibleThisError() { + if (errorNameNode) { + diagnostics.push(ts.createDiagnosticForNode(errorNameNode, ts.Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, ts.declarationNameToString(errorNameNode))); + } + } function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) { writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; write(": "); @@ -27345,7 +27926,9 @@ var ts; emitType(type); } else { + errorNameNode = declaration.name; resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + errorNameNode = undefined; } } function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) { @@ -27356,7 +27939,9 @@ var ts; emitType(signature.type); } else { + errorNameNode = signature.name; resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer); + errorNameNode = undefined; } } function emitLines(nodes) { @@ -27395,49 +27980,50 @@ var ts; } function emitType(type) { switch (type.kind) { - case 115 /* AnyKeyword */: - case 128 /* StringKeyword */: - case 126 /* NumberKeyword */: - case 118 /* BooleanKeyword */: - case 129 /* SymbolKeyword */: - case 101 /* VoidKeyword */: + case 117 /* AnyKeyword */: + case 130 /* StringKeyword */: + case 128 /* NumberKeyword */: + case 120 /* BooleanKeyword */: + case 131 /* SymbolKeyword */: + case 103 /* VoidKeyword */: + case 97 /* ThisKeyword */: case 9 /* StringLiteral */: return writeTextOfNode(currentSourceFile, type); - case 186 /* ExpressionWithTypeArguments */: + case 188 /* ExpressionWithTypeArguments */: return emitExpressionWithTypeArguments(type); - case 149 /* TypeReference */: + case 151 /* TypeReference */: return emitTypeReference(type); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return emitTypeQuery(type); - case 154 /* ArrayType */: + case 156 /* ArrayType */: return emitArrayType(type); - case 155 /* TupleType */: + case 157 /* TupleType */: return emitTupleType(type); - case 156 /* UnionType */: + case 158 /* UnionType */: return emitUnionType(type); - case 157 /* IntersectionType */: + case 159 /* IntersectionType */: return emitIntersectionType(type); - case 158 /* ParenthesizedType */: + case 160 /* ParenthesizedType */: return emitParenType(type); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return emitSignatureDeclarationWithJsDocComments(type); - case 153 /* TypeLiteral */: + case 155 /* TypeLiteral */: return emitTypeLiteral(type); - case 67 /* Identifier */: + case 69 /* Identifier */: return emitEntityName(type); - case 133 /* QualifiedName */: + case 135 /* QualifiedName */: return emitEntityName(type); - case 148 /* TypePredicate */: + case 150 /* TypePredicate */: return emitTypePredicate(type); } function writeEntityName(entityName) { - if (entityName.kind === 67 /* Identifier */) { + if (entityName.kind === 69 /* Identifier */) { writeTextOfNode(currentSourceFile, entityName); } else { - var left = entityName.kind === 133 /* QualifiedName */ ? entityName.left : entityName.expression; - var right = entityName.kind === 133 /* QualifiedName */ ? entityName.right : entityName.name; + var left = entityName.kind === 135 /* QualifiedName */ ? entityName.left : entityName.expression; + var right = entityName.kind === 135 /* QualifiedName */ ? entityName.right : entityName.name; writeEntityName(left); write("."); writeTextOfNode(currentSourceFile, right); @@ -27446,13 +28032,13 @@ var ts; function emitEntityName(entityName) { var visibilityResult = resolver.isEntityNameVisible(entityName, // Aliases can be written asynchronously so use correct enclosing declaration - entityName.parent.kind === 219 /* ImportEqualsDeclaration */ ? entityName.parent : enclosingDeclaration); + entityName.parent.kind === 221 /* ImportEqualsDeclaration */ ? entityName.parent : enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); } function emitExpressionWithTypeArguments(node) { if (ts.isSupportedExpressionWithTypeArguments(node)) { - ts.Debug.assert(node.expression.kind === 67 /* Identifier */ || node.expression.kind === 164 /* PropertyAccessExpression */); + ts.Debug.assert(node.expression.kind === 69 /* Identifier */ || node.expression.kind === 166 /* PropertyAccessExpression */); emitEntityName(node.expression); if (node.typeArguments) { write("<"); @@ -27533,7 +28119,7 @@ var ts; } } function emitExportAssignment(node) { - if (node.expression.kind === 67 /* Identifier */) { + if (node.expression.kind === 69 /* Identifier */) { write(node.isExportEquals ? "export = " : "export default "); writeTextOfNode(currentSourceFile, node.expression); } @@ -27553,7 +28139,7 @@ var ts; write(";"); writeLine(); // Make all the declarations visible for the export name - if (node.expression.kind === 67 /* Identifier */) { + if (node.expression.kind === 69 /* Identifier */) { var nodes = resolver.collectLinkedAliases(node.expression); // write each of these declarations asynchronously writeAsynchronousModuleElements(nodes); @@ -27572,10 +28158,10 @@ var ts; if (isModuleElementVisible) { writeModuleElement(node); } - else if (node.kind === 219 /* ImportEqualsDeclaration */ || - (node.parent.kind === 246 /* SourceFile */ && ts.isExternalModule(currentSourceFile))) { + else if (node.kind === 221 /* ImportEqualsDeclaration */ || + (node.parent.kind === 248 /* SourceFile */ && ts.isExternalModule(currentSourceFile))) { var isVisible; - if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 246 /* SourceFile */) { + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 248 /* SourceFile */) { // Import declaration of another module that is visited async so lets put it in right spot asynchronousSubModuleDeclarationEmitInfo.push({ node: node, @@ -27585,7 +28171,7 @@ var ts; }); } else { - if (node.kind === 220 /* ImportDeclaration */) { + if (node.kind === 222 /* ImportDeclaration */) { var importDeclaration = node; if (importDeclaration.importClause) { isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || @@ -27603,23 +28189,23 @@ var ts; } function writeModuleElement(node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return writeFunctionDeclaration(node); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return writeVariableStatement(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return writeInterfaceDeclaration(node); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return writeClassDeclaration(node); - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: return writeTypeAliasDeclaration(node); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return writeEnumDeclaration(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return writeModuleDeclaration(node); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: return writeImportEqualsDeclaration(node); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: return writeImportDeclaration(node); default: ts.Debug.fail("Unknown symbol kind"); @@ -27635,7 +28221,7 @@ var ts; if (node.flags & 1024 /* Default */) { write("default "); } - else if (node.kind !== 213 /* InterfaceDeclaration */) { + else if (node.kind !== 215 /* InterfaceDeclaration */) { write("declare "); } } @@ -27684,7 +28270,7 @@ var ts; } function isVisibleNamedBinding(namedBindings) { if (namedBindings) { - if (namedBindings.kind === 222 /* NamespaceImport */) { + if (namedBindings.kind === 224 /* NamespaceImport */) { return resolver.isDeclarationVisible(namedBindings); } else { @@ -27712,7 +28298,7 @@ var ts; // If the default binding was emitted, write the separated write(", "); } - if (node.importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (node.importClause.namedBindings.kind === 224 /* NamespaceImport */) { write("* as "); writeTextOfNode(currentSourceFile, node.importClause.namedBindings.name); } @@ -27770,7 +28356,7 @@ var ts; write("module "); } writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 217 /* ModuleBlock */) { + while (node.body.kind !== 219 /* ModuleBlock */) { node = node.body; write("."); writeTextOfNode(currentSourceFile, node.name); @@ -27835,7 +28421,7 @@ var ts; writeLine(); } function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 141 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); + return node.parent.kind === 143 /* MethodDeclaration */ && (node.parent.flags & 32 /* Private */); } function emitTypeParameters(typeParameters) { function emitTypeParameter(node) { @@ -27846,15 +28432,15 @@ var ts; // If there is constraint present and this is not a type parameter of the private method emit the constraint if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); - if (node.parent.kind === 150 /* FunctionType */ || - node.parent.kind === 151 /* ConstructorType */ || - (node.parent.parent && node.parent.parent.kind === 153 /* TypeLiteral */)) { - ts.Debug.assert(node.parent.kind === 141 /* MethodDeclaration */ || - node.parent.kind === 140 /* MethodSignature */ || - node.parent.kind === 150 /* FunctionType */ || - node.parent.kind === 151 /* ConstructorType */ || - node.parent.kind === 145 /* CallSignature */ || - node.parent.kind === 146 /* ConstructSignature */); + if (node.parent.kind === 152 /* FunctionType */ || + node.parent.kind === 153 /* ConstructorType */ || + (node.parent.parent && node.parent.parent.kind === 155 /* TypeLiteral */)) { + ts.Debug.assert(node.parent.kind === 143 /* MethodDeclaration */ || + node.parent.kind === 142 /* MethodSignature */ || + node.parent.kind === 152 /* FunctionType */ || + node.parent.kind === 153 /* ConstructorType */ || + node.parent.kind === 147 /* CallSignature */ || + node.parent.kind === 148 /* ConstructSignature */); emitType(node.constraint); } else { @@ -27865,31 +28451,31 @@ var ts; // Type parameter constraints are named by user so we should always be able to name it var diagnosticMessage; switch (node.parent.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 145 /* CallSignature */: + case 147 /* CallSignature */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.parent.flags & 128 /* Static */) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 214 /* ClassDeclaration */) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -27917,13 +28503,13 @@ var ts; if (ts.isSupportedExpressionWithTypeArguments(node)) { emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); } - else if (!isImplementsList && node.expression.kind === 91 /* NullKeyword */) { + else if (!isImplementsList && node.expression.kind === 93 /* NullKeyword */) { write("null"); } function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; // Heritage clause is written by user so it can always be named - if (node.parent.parent.kind === 212 /* ClassDeclaration */) { + if (node.parent.parent.kind === 214 /* ClassDeclaration */) { // Class or Interface implemented/extended is inaccessible diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : @@ -28007,7 +28593,7 @@ var ts; function emitVariableDeclaration(node) { // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted // so there is no check needed to see if declaration is visible - if (node.kind !== 209 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { + if (node.kind !== 211 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) { if (ts.isBindingPattern(node.name)) { emitBindingPattern(node.name); } @@ -28017,10 +28603,10 @@ var ts; // what we want, namely the name expression enclosed in brackets. writeTextOfNode(currentSourceFile, node.name); // If optional property emit ? - if ((node.kind === 139 /* PropertyDeclaration */ || node.kind === 138 /* PropertySignature */) && ts.hasQuestionToken(node)) { + if ((node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) && ts.hasQuestionToken(node)) { write("?"); } - if ((node.kind === 139 /* PropertyDeclaration */ || node.kind === 138 /* PropertySignature */) && node.parent.kind === 153 /* TypeLiteral */) { + if ((node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) && node.parent.kind === 155 /* TypeLiteral */) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & 32 /* Private */)) { @@ -28029,14 +28615,14 @@ var ts; } } function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { - if (node.kind === 209 /* VariableDeclaration */) { + if (node.kind === 211 /* VariableDeclaration */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } - else if (node.kind === 139 /* PropertyDeclaration */ || node.kind === 138 /* PropertySignature */) { + else if (node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & 128 /* Static */) { return symbolAccesibilityResult.errorModuleName ? @@ -28045,7 +28631,7 @@ var ts; ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -28077,7 +28663,7 @@ var ts; var elements = []; for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) { var element = _a[_i]; - if (element.kind !== 185 /* OmittedExpression */) { + if (element.kind !== 187 /* OmittedExpression */) { elements.push(element); } } @@ -28147,7 +28733,7 @@ var ts; var type = getTypeAnnotationFromAccessor(node); if (!type) { // couldn't get type for the first accessor, try the another one - var anotherAccessor = node.kind === 143 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; + var anotherAccessor = node.kind === 145 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor; type = getTypeAnnotationFromAccessor(anotherAccessor); if (type) { accessorWithTypeAnnotation = anotherAccessor; @@ -28160,7 +28746,7 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 143 /* GetAccessor */ + return accessor.kind === 145 /* GetAccessor */ ? accessor.type // Getter - return type : accessor.parameters.length > 0 ? accessor.parameters[0].type // Setter parameter type @@ -28169,7 +28755,7 @@ var ts; } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 144 /* SetAccessor */) { + if (accessorWithTypeAnnotation.kind === 146 /* SetAccessor */) { // Setters have to have type named and cannot infer it so, the type should always be named if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? @@ -28219,17 +28805,17 @@ var ts; // so no need to verify if the declaration is visible if (!resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); - if (node.kind === 211 /* FunctionDeclaration */) { + if (node.kind === 213 /* FunctionDeclaration */) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === 141 /* MethodDeclaration */) { + else if (node.kind === 143 /* MethodDeclaration */) { emitClassMemberDeclarationFlags(node); } - if (node.kind === 211 /* FunctionDeclaration */) { + if (node.kind === 213 /* FunctionDeclaration */) { write("function "); writeTextOfNode(currentSourceFile, node.name); } - else if (node.kind === 142 /* Constructor */) { + else if (node.kind === 144 /* Constructor */) { write("constructor"); } else { @@ -28247,11 +28833,11 @@ var ts; } function emitSignatureDeclaration(node) { // Construct signature or constructor type write new Signature - if (node.kind === 146 /* ConstructSignature */ || node.kind === 151 /* ConstructorType */) { + if (node.kind === 148 /* ConstructSignature */ || node.kind === 153 /* ConstructorType */) { write("new "); } emitTypeParameters(node.typeParameters); - if (node.kind === 147 /* IndexSignature */) { + if (node.kind === 149 /* IndexSignature */) { write("["); } else { @@ -28261,22 +28847,22 @@ var ts; enclosingDeclaration = node; // Parameters emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 147 /* IndexSignature */) { + if (node.kind === 149 /* IndexSignature */) { write("]"); } else { write(")"); } // If this is not a constructor and is not private, emit the return type - var isFunctionTypeOrConstructorType = node.kind === 150 /* FunctionType */ || node.kind === 151 /* ConstructorType */; - if (isFunctionTypeOrConstructorType || node.parent.kind === 153 /* TypeLiteral */) { + var isFunctionTypeOrConstructorType = node.kind === 152 /* FunctionType */ || node.kind === 153 /* ConstructorType */; + if (isFunctionTypeOrConstructorType || node.parent.kind === 155 /* TypeLiteral */) { // Emit type literal signature return type only if specified if (node.type) { write(isFunctionTypeOrConstructorType ? " => " : ": "); emitType(node.type); } } - else if (node.kind !== 142 /* Constructor */ && !(node.flags & 32 /* Private */)) { + else if (node.kind !== 144 /* Constructor */ && !(node.flags & 32 /* Private */)) { writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); } enclosingDeclaration = prevEnclosingDeclaration; @@ -28287,26 +28873,26 @@ var ts; function getReturnTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.kind) { - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 145 /* CallSignature */: + case 147 /* CallSignature */: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.flags & 128 /* Static */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? @@ -28314,7 +28900,7 @@ var ts; ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.kind === 214 /* ClassDeclaration */) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -28328,7 +28914,7 @@ var ts; ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -28363,9 +28949,9 @@ var ts; write("?"); } decreaseIndent(); - if (node.parent.kind === 150 /* FunctionType */ || - node.parent.kind === 151 /* ConstructorType */ || - node.parent.parent.kind === 153 /* TypeLiteral */) { + if (node.parent.kind === 152 /* FunctionType */ || + node.parent.kind === 153 /* ConstructorType */ || + node.parent.parent.kind === 155 /* TypeLiteral */) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.parent.flags & 32 /* Private */)) { @@ -28381,24 +28967,24 @@ var ts; } function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) { switch (node.parent.kind) { - case 142 /* Constructor */: + case 144 /* Constructor */: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: // Interfaces cannot have parameter types that cannot be named return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - case 145 /* CallSignature */: + case 147 /* CallSignature */: // Interfaces cannot have parameter types that cannot be named return symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (node.parent.flags & 128 /* Static */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? @@ -28406,7 +28992,7 @@ var ts; ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 212 /* ClassDeclaration */) { + else if (node.parent.parent.kind === 214 /* ClassDeclaration */) { return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -28419,7 +29005,7 @@ var ts; ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -28431,12 +29017,12 @@ var ts; } function emitBindingPattern(bindingPattern) { // We have to explicitly emit square bracket and bracket because these tokens are not store inside the node. - if (bindingPattern.kind === 159 /* ObjectBindingPattern */) { + if (bindingPattern.kind === 161 /* ObjectBindingPattern */) { write("{"); emitCommaList(bindingPattern.elements, emitBindingElement); write("}"); } - else if (bindingPattern.kind === 160 /* ArrayBindingPattern */) { + else if (bindingPattern.kind === 162 /* ArrayBindingPattern */) { write("["); var elements = bindingPattern.elements; emitCommaList(elements, emitBindingElement); @@ -28455,7 +29041,7 @@ var ts; typeName: bindingElement.name } : undefined; } - if (bindingElement.kind === 185 /* OmittedExpression */) { + if (bindingElement.kind === 187 /* OmittedExpression */) { // If bindingElement is an omittedExpression (i.e. containing elision), // we will emit blank space (although this may differ from users' original code, // it allows emitSeparatedList to write separator appropriately) @@ -28464,7 +29050,7 @@ var ts; // emit : function foo([ , x, , ]) {} write(" "); } - else if (bindingElement.kind === 161 /* BindingElement */) { + else if (bindingElement.kind === 163 /* BindingElement */) { if (bindingElement.propertyName) { // bindingElement has propertyName property in the following case: // { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y" @@ -28487,7 +29073,7 @@ var ts; emitBindingPattern(bindingElement.name); } else { - ts.Debug.assert(bindingElement.name.kind === 67 /* Identifier */); + ts.Debug.assert(bindingElement.name.kind === 69 /* Identifier */); // If the node is just an identifier, we will simply emit the text associated with the node's name // Example: // original: function foo({y = 10, x}) {} @@ -28503,40 +29089,40 @@ var ts; } function emitNode(node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: - case 216 /* ModuleDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 213 /* InterfaceDeclaration */: - case 212 /* ClassDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 215 /* EnumDeclaration */: + case 213 /* FunctionDeclaration */: + case 218 /* ModuleDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 215 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 217 /* EnumDeclaration */: return emitModuleElement(node, isModuleElementVisible(node)); - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: return emitModuleElement(node, isVariableStatementVisible(node)); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: // Import declaration without import clause is visible, otherwise it is not visible return emitModuleElement(node, /*isModuleElementVisible*/ !node.importClause); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: return emitExportDeclaration(node); - case 142 /* Constructor */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 144 /* Constructor */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return writeFunctionDeclaration(node); - case 146 /* ConstructSignature */: - case 145 /* CallSignature */: - case 147 /* IndexSignature */: + case 148 /* ConstructSignature */: + case 147 /* CallSignature */: + case 149 /* IndexSignature */: return emitSignatureDeclarationWithJsDocComments(node); - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: return emitAccessorDeclaration(node); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return emitPropertyDeclaration(node); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return emitEnumMemberDeclaration(node); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: return emitExportAssignment(node); - case 246 /* SourceFile */: + case 248 /* SourceFile */: return emitSourceFile(node); } } @@ -28587,6425 +29173,6 @@ var ts; return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile); } ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; - // Flags enum to track count of temp variables and a few dedicated names - var TempFlags; - (function (TempFlags) { - TempFlags[TempFlags["Auto"] = 0] = "Auto"; - TempFlags[TempFlags["CountMask"] = 268435455] = "CountMask"; - TempFlags[TempFlags["_i"] = 268435456] = "_i"; - })(TempFlags || (TempFlags = {})); - // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature - function emitFiles(resolver, host, targetSourceFile) { - // emit output for the __extends helper function - var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; - // emit output for the __decorate helper function - var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; - // emit output for the __metadata helper function - var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; - // emit output for the __param helper function - var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; - var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; - var compilerOptions = host.getCompilerOptions(); - var languageVersion = compilerOptions.target || 0 /* ES3 */; - var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; - var diagnostics = []; - var newLine = host.getNewLine(); - var jsxDesugaring = host.getCompilerOptions().jsx !== 1 /* Preserve */; - var shouldEmitJsx = function (s) { return (s.languageVariant === 1 /* JSX */ && !jsxDesugaring); }; - if (targetSourceFile === undefined) { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, sourceFile); - } - }); - if (compilerOptions.outFile || compilerOptions.out) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - else { - // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service) - if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { - var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); - emitFile(jsFilePath, targetSourceFile); - } - else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { - emitFile(compilerOptions.outFile || compilerOptions.out); - } - } - // Sort and make the unique list of diagnostics - diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); - return { - emitSkipped: false, - diagnostics: diagnostics, - sourceMaps: sourceMapDataList - }; - function isNodeDescendentOf(node, ancestor) { - while (node) { - if (node === ancestor) - return true; - node = node.parent; - } - return false; - } - function isUniqueLocalName(name, container) { - for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && ts.hasProperty(node.locals, name)) { - // We conservatively include alias symbols to cover cases where they're emitted as locals - if (node.locals[name].flags & (107455 /* Value */ | 1048576 /* ExportValue */ | 8388608 /* Alias */)) { - return false; - } - } - } - return true; - } - function emitJavaScript(jsFilePath, root) { - var writer = ts.createTextWriter(newLine); - var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; - var currentSourceFile; - // name of an exporter function if file is a System external module - // System.register([...], function () {...}) - // exporting in System modules looks like: - // export var x; ... x = 1 - // => - // var x;... exporter("x", x = 1) - var exportFunctionForFile; - var generatedNameSet = {}; - var nodeToGeneratedName = []; - var computedPropertyNamesToGeneratedNames; - var extendsEmitted = false; - var decorateEmitted = false; - var paramEmitted = false; - var awaiterEmitted = false; - var tempFlags = 0; - var tempVariables; - var tempParameters; - var externalImports; - var exportSpecifiers; - var exportEquals; - var hasExportStars; - /** Write emitted output to disk */ - var writeEmittedFiles = writeJavaScriptFile; - var detachedCommentsInfo; - var writeComment = ts.writeCommentRange; - /** Emit a node */ - var emit = emitNodeWithCommentsAndWithoutSourcemap; - /** Called just before starting emit of a node */ - var emitStart = function (node) { }; - /** Called once the emit of the node is done */ - var emitEnd = function (node) { }; - /** Emit the text for the given token that comes after startPos - * This by default writes the text provided with the given tokenKind - * but if optional emitFn callback is provided the text is emitted using the callback instead of default text - * @param tokenKind the kind of the token to search and emit - * @param startPos the position in the source to start searching for the token - * @param emitFn if given will be invoked to emit the text instead of actual token emit */ - var emitToken = emitTokenText; - /** Called to before starting the lexical scopes as in function/class in the emitted code because of node - * @param scopeDeclaration node that starts the lexical scope - * @param scopeName Optional name of this scope instead of deducing one from the declaration node */ - var scopeEmitStart = function (scopeDeclaration, scopeName) { }; - /** Called after coming out of the scope */ - var scopeEmitEnd = function () { }; - /** Sourcemap data that will get encoded */ - var sourceMapData; - /** If removeComments is true, no leading-comments needed to be emitted **/ - var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; - if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { - initializeEmitterWithSourceMaps(); - } - if (root) { - // Do not call emit directly. It does not set the currentSourceFile. - emitSourceFile(root); - } - else { - ts.forEach(host.getSourceFiles(), function (sourceFile) { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - emitSourceFile(sourceFile); - } - }); - } - writeLine(); - writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); - return; - function emitSourceFile(sourceFile) { - currentSourceFile = sourceFile; - exportFunctionForFile = undefined; - emit(sourceFile); - } - function isUniqueName(name) { - return !resolver.hasGlobalName(name) && - !ts.hasProperty(currentSourceFile.identifiers, name) && - !ts.hasProperty(generatedNameSet, name); - } - // Return the next available name in the pattern _a ... _z, _0, _1, ... - // TempFlags._i or TempFlags._n may be used to express a preference for that dedicated name. - // Note that names generated by makeTempVariableName and makeUniqueName will never conflict. - function makeTempVariableName(flags) { - if (flags && !(tempFlags & flags)) { - var name_19 = flags === 268435456 /* _i */ ? "_i" : "_n"; - if (isUniqueName(name_19)) { - tempFlags |= flags; - return name_19; - } - } - while (true) { - var count = tempFlags & 268435455 /* CountMask */; - tempFlags++; - // Skip over 'i' and 'n' - if (count !== 8 && count !== 13) { - var name_20 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_20)) { - return name_20; - } - } - } - } - // Generate a name that is unique within the current file and doesn't conflict with any names - // in global scope. The name is formed by adding an '_n' suffix to the specified base name, - // where n is a positive integer. Note that names generated by makeTempVariableName and - // makeUniqueName are guaranteed to never conflict. - function makeUniqueName(baseName) { - // Find the first unique 'name_n', where n is a positive number - if (baseName.charCodeAt(baseName.length - 1) !== 95 /* _ */) { - baseName += "_"; - } - var i = 1; - while (true) { - var generatedName = baseName + i; - if (isUniqueName(generatedName)) { - return generatedNameSet[generatedName] = generatedName; - } - i++; - } - } - function generateNameForModuleOrEnum(node) { - var name = node.name.text; - // Use module/enum name itself if it is unique, otherwise make a unique variation - return isUniqueLocalName(name, node) ? name : makeUniqueName(name); - } - function generateNameForImportOrExportDeclaration(node) { - var expr = ts.getExternalModuleName(node); - var baseName = expr.kind === 9 /* StringLiteral */ ? - ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; - return makeUniqueName(baseName); - } - function generateNameForExportDefault() { - return makeUniqueName("default"); - } - function generateNameForClassExpression() { - return makeUniqueName("class"); - } - function generateNameForNode(node) { - switch (node.kind) { - case 67 /* Identifier */: - return makeUniqueName(node.text); - case 216 /* ModuleDeclaration */: - case 215 /* EnumDeclaration */: - return generateNameForModuleOrEnum(node); - case 220 /* ImportDeclaration */: - case 226 /* ExportDeclaration */: - return generateNameForImportOrExportDeclaration(node); - case 211 /* FunctionDeclaration */: - case 212 /* ClassDeclaration */: - case 225 /* ExportAssignment */: - return generateNameForExportDefault(); - case 184 /* ClassExpression */: - return generateNameForClassExpression(); - } - } - function getGeneratedNameForNode(node) { - var id = ts.getNodeId(node); - return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); - } - function initializeEmitterWithSourceMaps() { - var sourceMapDir; // The directory in which sourcemap will be - // Current source map file and its index in the sources list - var sourceMapSourceIndex = -1; - // Names and its index map - var sourceMapNameIndexMap = {}; - var sourceMapNameIndices = []; - function getSourceMapNameIndex() { - return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; - } - // Last recorded and encoded spans - var lastRecordedSourceMapSpan; - var lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; - var lastEncodedNameIndex = 0; - // Encoding for sourcemap span - function encodeLastRecordedSourceMapSpan() { - if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { - return; - } - var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; - // Line/Comma delimiters - if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { - // Emit comma to separate the entry - if (sourceMapData.sourceMapMappings) { - sourceMapData.sourceMapMappings += ","; - } - } - else { - // Emit line delimiters - for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { - sourceMapData.sourceMapMappings += ";"; - } - prevEncodedEmittedColumn = 1; - } - // 1. Relative Column 0 based - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); - // 2. Relative sourceIndex - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); - // 3. Relative sourceLine 0 based - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); - // 4. Relative sourceColumn 0 based - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); - // 5. Relative namePosition 0 based - if (lastRecordedSourceMapSpan.nameIndex >= 0) { - sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); - lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; - } - lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; - sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); - function base64VLQFormatEncode(inValue) { - function base64FormatEncode(inValue) { - if (inValue < 64) { - return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); - } - throw TypeError(inValue + ": not a 64 based value"); - } - // Add a new least significant bit that has the sign of the value. - // if negative number the least significant bit that gets added to the number has value 1 - // else least significant bit value that gets added is 0 - // eg. -1 changes to binary : 01 [1] => 3 - // +1 changes to binary : 01 [0] => 2 - if (inValue < 0) { - inValue = ((-inValue) << 1) + 1; - } - else { - inValue = inValue << 1; - } - // Encode 5 bits at a time starting from least significant bits - var encodedStr = ""; - do { - var currentDigit = inValue & 31; // 11111 - inValue = inValue >> 5; - if (inValue > 0) { - // There are still more digits to decode, set the msb (6th bit) - currentDigit = currentDigit | 32; - } - encodedStr = encodedStr + base64FormatEncode(currentDigit); - } while (inValue > 0); - return encodedStr; - } - } - function recordSourceMapSpan(pos) { - var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); - // Convert the location to be one-based. - sourceLinePos.line++; - sourceLinePos.character++; - var emittedLine = writer.getLine(); - var emittedColumn = writer.getColumn(); - // If this location wasn't recorded or the location in source is going backwards, record the span - if (!lastRecordedSourceMapSpan || - lastRecordedSourceMapSpan.emittedLine !== emittedLine || - lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || - (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { - // Encode the last recordedSpan before assigning new - encodeLastRecordedSourceMapSpan(); - // New span - lastRecordedSourceMapSpan = { - emittedLine: emittedLine, - emittedColumn: emittedColumn, - sourceLine: sourceLinePos.line, - sourceColumn: sourceLinePos.character, - nameIndex: getSourceMapNameIndex(), - sourceIndex: sourceMapSourceIndex - }; - } - else { - // Take the new pos instead since there is no change in emittedLine and column since last location - lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; - lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; - lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; - } - } - function recordEmitNodeStartSpan(node) { - // Get the token pos after skipping to the token (ignoring the leading trivia) - recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); - } - function recordEmitNodeEndSpan(node) { - recordSourceMapSpan(node.end); - } - function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); - var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; - } - function recordNewSourceFileStart(node) { - // Add the file to tsFilePaths - // If sourceroot option: Use the relative path corresponding to the common directory path - // otherwise source locations relative to map file location - var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; - sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ true)); - sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; - // The one that can be used from program to get the actual source file - sourceMapData.inputSourceFileNames.push(node.fileName); - if (compilerOptions.inlineSources) { - if (!sourceMapData.sourceMapSourcesContent) { - sourceMapData.sourceMapSourcesContent = []; - } - sourceMapData.sourceMapSourcesContent.push(node.text); - } - } - function recordScopeNameOfNode(node, scopeName) { - function recordScopeNameIndex(scopeNameIndex) { - sourceMapNameIndices.push(scopeNameIndex); - } - function recordScopeNameStart(scopeName) { - var scopeNameIndex = -1; - if (scopeName) { - var parentIndex = getSourceMapNameIndex(); - if (parentIndex !== -1) { - // Child scopes are always shown with a dot (even if they have no name), - // unless it is a computed property. Then it is shown with brackets, - // but the brackets are included in the name. - var name_21 = node.name; - if (!name_21 || name_21.kind !== 134 /* ComputedPropertyName */) { - scopeName = "." + scopeName; - } - scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; - } - scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); - if (scopeNameIndex === undefined) { - scopeNameIndex = sourceMapData.sourceMapNames.length; - sourceMapData.sourceMapNames.push(scopeName); - sourceMapNameIndexMap[scopeName] = scopeNameIndex; - } - } - recordScopeNameIndex(scopeNameIndex); - } - if (scopeName) { - // The scope was already given a name use it - recordScopeNameStart(scopeName); - } - else if (node.kind === 211 /* FunctionDeclaration */ || - node.kind === 171 /* FunctionExpression */ || - node.kind === 141 /* MethodDeclaration */ || - node.kind === 140 /* MethodSignature */ || - node.kind === 143 /* GetAccessor */ || - node.kind === 144 /* SetAccessor */ || - node.kind === 216 /* ModuleDeclaration */ || - node.kind === 212 /* ClassDeclaration */ || - node.kind === 215 /* EnumDeclaration */) { - // Declaration and has associated name use it - if (node.name) { - var name_22 = node.name; - // For computed property names, the text will include the brackets - scopeName = name_22.kind === 134 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_22) - : node.name.text; - } - recordScopeNameStart(scopeName); - } - else { - // Block just use the name from upper level scope - recordScopeNameIndex(getSourceMapNameIndex()); - } - } - function recordScopeNameEnd() { - sourceMapNameIndices.pop(); - } - ; - function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { - recordSourceMapSpan(comment.pos); - ts.writeCommentRange(currentSourceFile, writer, comment, newLine); - recordSourceMapSpan(comment.end); - } - function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { - if (typeof JSON !== "undefined") { - var map_1 = { - version: version, - file: file, - sourceRoot: sourceRoot, - sources: sources, - names: names, - mappings: mappings - }; - if (sourcesContent !== undefined) { - map_1.sourcesContent = sourcesContent; - } - return JSON.stringify(map_1); - } - return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; - function serializeStringArray(list) { - var output = ""; - for (var i = 0, n = list.length; i < n; i++) { - if (i) { - output += ","; - } - output += "\"" + ts.escapeString(list[i]) + "\""; - } - return output; - } - } - function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { - encodeLastRecordedSourceMapSpan(); - var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); - sourceMapDataList.push(sourceMapData); - var sourceMapUrl; - if (compilerOptions.inlineSourceMap) { - // Encode the sourceMap into the sourceMap url - var base64SourceMapText = ts.convertToBase64(sourceMapText); - sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; - } - else { - // Write source map file - ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, /*writeByteOrderMark*/ false); - sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; - } - // Write sourcemap url to the js file and write the js file - writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); - } - // Initialize source map data - var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); - sourceMapData = { - sourceMapFilePath: jsFilePath + ".map", - jsSourceMappingURL: sourceMapJsFile + ".map", - sourceMapFile: sourceMapJsFile, - sourceMapSourceRoot: compilerOptions.sourceRoot || "", - sourceMapSources: [], - inputSourceFileNames: [], - sourceMapNames: [], - sourceMapMappings: "", - sourceMapSourcesContent: undefined, - sourceMapDecodedMappings: [] - }; - // Normalize source root and make sure it has trailing "/" so that it can be used to combine paths with the - // relative paths of the sources list in the sourcemap - sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); - if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { - sourceMapData.sourceMapSourceRoot += ts.directorySeparator; - } - if (compilerOptions.mapRoot) { - sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); - if (root) { - // For modules or multiple emit files the mapRoot will have directory structure like the sources - // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); - } - if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { - // The relative paths are relative to the common directory - sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); - sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath - ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap - host.getCurrentDirectory(), host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ true); - } - else { - sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); - } - } - else { - sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); - } - function emitNodeWithSourceMap(node) { - if (node) { - if (ts.nodeIsSynthesized(node)) { - return emitNodeWithoutSourceMap(node); - } - if (node.kind !== 246 /* SourceFile */) { - recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMap(node); - recordEmitNodeEndSpan(node); - } - else { - recordNewSourceFileStart(node); - emitNodeWithoutSourceMap(node); - } - } - } - function emitNodeWithCommentsAndWithSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; - emit = emitNodeWithCommentsAndWithSourcemap; - emitStart = recordEmitNodeStartSpan; - emitEnd = recordEmitNodeEndSpan; - emitToken = writeTextWithSpanRecord; - scopeEmitStart = recordScopeNameOfNode; - scopeEmitEnd = recordScopeNameEnd; - writeComment = writeCommentRangeWithMap; - } - function writeJavaScriptFile(emitOutput, writeByteOrderMark) { - ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); - } - // Create a temporary variable with a unique unused name. - function createTempVariable(flags) { - var result = ts.createSynthesizedNode(67 /* Identifier */); - result.text = makeTempVariableName(flags); - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; - } - tempVariables.push(name); - } - function createAndRecordTempVariable(flags) { - var temp = createTempVariable(flags); - recordTempDeclaration(temp); - return temp; - } - function emitTempDeclarations(newLine) { - if (tempVariables) { - if (newLine) { - writeLine(); - } - else { - write(" "); - } - write("var "); - emitCommaList(tempVariables); - write(";"); - } - } - function emitTokenText(tokenKind, startPos, emitFn) { - var tokenString = ts.tokenToString(tokenKind); - if (emitFn) { - emitFn(); - } - else { - write(tokenString); - } - return startPos + tokenString.length; - } - function emitOptional(prefix, node) { - if (node) { - write(prefix); - emit(node); - } - } - function emitParenthesizedIf(node, parenthesized) { - if (parenthesized) { - write("("); - } - emit(node); - if (parenthesized) { - write(")"); - } - } - function emitTrailingCommaIfPresent(nodeList) { - if (nodeList.hasTrailingComma) { - write(","); - } - } - function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { - ts.Debug.assert(nodes.length > 0); - increaseIndent(); - if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - for (var i = 0, n = nodes.length; i < n; i++) { - if (i) { - if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { - write(", "); - } - else { - write(","); - writeLine(); - } - } - emit(nodes[i]); - } - if (nodes.hasTrailingComma && allowTrailingComma) { - write(","); - } - decreaseIndent(); - if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { - if (spacesBetweenBraces) { - write(" "); - } - } - else { - writeLine(); - } - } - function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { - if (!emitNode) { - emitNode = emit; - } - for (var i = 0; i < count; i++) { - if (multiLine) { - if (i || leadingComma) { - write(","); - } - writeLine(); - } - else { - if (i || leadingComma) { - write(", "); - } - } - var node = nodes[start + i]; - // This emitting is to make sure we emit following comment properly - // ...(x, /*comment1*/ y)... - // ^ => node.pos - // "comment1" is not considered leading comment for "y" but rather - // considered as trailing comment of the previous node. - emitTrailingCommentsOfPosition(node.pos); - emitNode(node); - leadingComma = true; - } - if (trailingComma) { - write(","); - } - if (multiLine && !noTrailingNewLine) { - writeLine(); - } - return count; - } - function emitCommaList(nodes) { - if (nodes) { - emitList(nodes, 0, nodes.length, /*multiline*/ false, /*trailingComma*/ false); - } - } - function emitLines(nodes) { - emitLinesStartingAt(nodes, /*startIndex*/ 0); - } - function emitLinesStartingAt(nodes, startIndex) { - for (var i = startIndex; i < nodes.length; i++) { - writeLine(); - emit(nodes[i]); - } - } - function isBinaryOrOctalIntegerLiteral(node, text) { - if (node.kind === 8 /* NumericLiteral */ && text.length > 1) { - switch (text.charCodeAt(1)) { - case 98 /* b */: - case 66 /* B */: - case 111 /* o */: - case 79 /* O */: - return true; - } - } - return false; - } - function emitLiteral(node) { - var text = getLiteralText(node); - if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { - writer.writeLiteral(text); - } - else if (languageVersion < 2 /* ES6 */ && isBinaryOrOctalIntegerLiteral(node, text)) { - write(node.text); - } - else { - write(text); - } - } - function getLiteralText(node) { - // Any template literal or string literal with an extended escape - // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal. - if (languageVersion < 2 /* ES6 */ && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { - return getQuotedEscapedLiteralText("\"", node.text, "\""); - } - // If we don't need to downlevel and we can reach the original source text using - // the node's parent reference, then simply get the text as it was originally written. - if (node.parent) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - } - // If we can't reach the original source text, use the canonical form if it's a number, - // or an escaped quoted form of the original text if it's string-like. - switch (node.kind) { - case 9 /* StringLiteral */: - return getQuotedEscapedLiteralText("\"", node.text, "\""); - case 11 /* NoSubstitutionTemplateLiteral */: - return getQuotedEscapedLiteralText("`", node.text, "`"); - case 12 /* TemplateHead */: - return getQuotedEscapedLiteralText("`", node.text, "${"); - case 13 /* TemplateMiddle */: - return getQuotedEscapedLiteralText("}", node.text, "${"); - case 14 /* TemplateTail */: - return getQuotedEscapedLiteralText("}", node.text, "`"); - case 8 /* NumericLiteral */: - return node.text; - } - ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); - } - function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { - return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; - } - function emitDownlevelRawTemplateLiteral(node) { - // Find original source text, since we need to emit the raw strings of the tagged template. - // The raw strings contain the (escaped) strings of what the user wrote. - // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - var isLast = node.kind === 11 /* NoSubstitutionTemplateLiteral */ || node.kind === 14 /* TemplateTail */; - text = text.substring(1, text.length - (isLast ? 1 : 2)); - // Newline normalization: - // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's - // and LineTerminatorSequences are normalized to for both TV and TRV. - text = text.replace(/\r\n?/g, "\n"); - text = ts.escapeString(text); - write("\"" + text + "\""); - } - function emitDownlevelTaggedTemplateArray(node, literalEmitter) { - write("["); - if (node.template.kind === 11 /* NoSubstitutionTemplateLiteral */) { - literalEmitter(node.template); - } - else { - literalEmitter(node.template.head); - ts.forEach(node.template.templateSpans, function (child) { - write(", "); - literalEmitter(child.literal); - }); - } - write("]"); - } - function emitDownlevelTaggedTemplate(node) { - var tempVariable = createAndRecordTempVariable(0 /* Auto */); - write("("); - emit(tempVariable); - write(" = "); - emitDownlevelTaggedTemplateArray(node, emit); - write(", "); - emit(tempVariable); - write(".raw = "); - emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); - write(", "); - emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); - write("("); - emit(tempVariable); - // Now we emit the expressions - if (node.template.kind === 181 /* TemplateExpression */) { - ts.forEach(node.template.templateSpans, function (templateSpan) { - write(", "); - var needsParens = templateSpan.expression.kind === 179 /* BinaryExpression */ - && templateSpan.expression.operatorToken.kind === 24 /* CommaToken */; - emitParenthesizedIf(templateSpan.expression, needsParens); - }); - } - write("))"); - } - function emitTemplateExpression(node) { - // In ES6 mode and above, we can simply emit each portion of a template in order, but in - // ES3 & ES5 we must convert the template expression into a series of string concatenations. - if (languageVersion >= 2 /* ES6 */) { - ts.forEachChild(node, emit); - return; - } - var emitOuterParens = ts.isExpression(node.parent) - && templateNeedsParens(node, node.parent); - if (emitOuterParens) { - write("("); - } - var headEmitted = false; - if (shouldEmitTemplateHead()) { - emitLiteral(node.head); - headEmitted = true; - } - for (var i = 0, n = node.templateSpans.length; i < n; i++) { - var templateSpan = node.templateSpans[i]; - // Check if the expression has operands and binds its operands less closely than binary '+'. - // If it does, we need to wrap the expression in parentheses. Otherwise, something like - // `abc${ 1 << 2 }` - // becomes - // "abc" + 1 << 2 + "" - // which is really - // ("abc" + 1) << (2 + "") - // rather than - // "abc" + (1 << 2) + "" - var needsParens = templateSpan.expression.kind !== 170 /* ParenthesizedExpression */ - && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; - if (i > 0 || headEmitted) { - // If this is the first span and the head was not emitted, then this templateSpan's - // expression will be the first to be emitted. Don't emit the preceding ' + ' in that - // case. - write(" + "); - } - emitParenthesizedIf(templateSpan.expression, needsParens); - // Only emit if the literal is non-empty. - // The binary '+' operator is left-associative, so the first string concatenation - // with the head will force the result up to this point to be a string. - // Emitting a '+ ""' has no semantic effect for middles and tails. - if (templateSpan.literal.text.length !== 0) { - write(" + "); - emitLiteral(templateSpan.literal); - } - } - if (emitOuterParens) { - write(")"); - } - function shouldEmitTemplateHead() { - // If this expression has an empty head literal and the first template span has a non-empty - // literal, then emitting the empty head literal is not necessary. - // `${ foo } and ${ bar }` - // can be emitted as - // foo + " and " + bar - // This is because it is only required that one of the first two operands in the emit - // output must be a string literal, so that the other operand and all following operands - // are forced into strings. - // - // If the first template span has an empty literal, then the head must still be emitted. - // `${ foo }${ bar }` - // must still be emitted as - // "" + foo + bar - // There is always atleast one templateSpan in this code path, since - // NoSubstitutionTemplateLiterals are directly emitted via emitLiteral() - ts.Debug.assert(node.templateSpans.length !== 0); - return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; - } - function templateNeedsParens(template, parent) { - switch (parent.kind) { - case 166 /* CallExpression */: - case 167 /* NewExpression */: - return parent.expression === template; - case 168 /* TaggedTemplateExpression */: - case 170 /* ParenthesizedExpression */: - return false; - default: - return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; - } - } - /** - * Returns whether the expression has lesser, greater, - * or equal precedence to the binary '+' operator - */ - function comparePrecedenceToBinaryPlus(expression) { - // All binary expressions have lower precedence than '+' apart from '*', '/', and '%' - // which have greater precedence and '-' which has equal precedence. - // All unary operators have a higher precedence apart from yield. - // Arrow functions and conditionals have a lower precedence, - // although we convert the former into regular function expressions in ES5 mode, - // and in ES6 mode this function won't get called anyway. - // - // TODO (drosen): Note that we need to account for the upcoming 'yield' and - // spread ('...') unary operators that are anticipated for ES6. - switch (expression.kind) { - case 179 /* BinaryExpression */: - switch (expression.operatorToken.kind) { - case 37 /* AsteriskToken */: - case 38 /* SlashToken */: - case 39 /* PercentToken */: - return 1 /* GreaterThan */; - case 35 /* PlusToken */: - case 36 /* MinusToken */: - return 0 /* EqualTo */; - default: - return -1 /* LessThan */; - } - case 182 /* YieldExpression */: - case 180 /* ConditionalExpression */: - return -1 /* LessThan */; - default: - return 1 /* GreaterThan */; - } - } - } - function emitTemplateSpan(span) { - emit(span.expression); - emit(span.literal); - } - function jsxEmitReact(node) { - /// Emit a tag name, which is either '"div"' for lower-cased names, or - /// 'Div' for upper-cased or dotted names - function emitTagName(name) { - if (name.kind === 67 /* Identifier */ && ts.isIntrinsicJsxName(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - /// Emit an attribute name, which is quoted if it needs to be quoted. Because - /// these emit into an object literal property name, we don't need to be worried - /// about keywords, just non-identifier characters - function emitAttributeName(name) { - if (/[A-Za-z_]+[\w*]/.test(name.text)) { - write("\""); - emit(name); - write("\""); - } - else { - emit(name); - } - } - /// Emit an name/value pair for an attribute (e.g. "x: 3") - function emitJsxAttribute(node) { - emitAttributeName(node.name); - write(": "); - if (node.initializer) { - emit(node.initializer); - } - else { - write("true"); - } - } - function emitJsxElement(openingNode, children) { - var syntheticReactRef = ts.createSynthesizedNode(67 /* Identifier */); - syntheticReactRef.text = 'React'; - syntheticReactRef.parent = openingNode; - // Call React.createElement(tag, ... - emitLeadingComments(openingNode); - emitExpressionIdentifier(syntheticReactRef); - write(".createElement("); - emitTagName(openingNode.tagName); - write(", "); - // Attribute list - if (openingNode.attributes.length === 0) { - // When there are no attributes, React wants "null" - write("null"); - } - else { - // Either emit one big object literal (no spread attribs), or - // a call to React.__spread - var attrs = openingNode.attributes; - if (ts.forEach(attrs, function (attr) { return attr.kind === 237 /* JsxSpreadAttribute */; })) { - emitExpressionIdentifier(syntheticReactRef); - write(".__spread("); - var haveOpenedObjectLiteral = false; - for (var i_1 = 0; i_1 < attrs.length; i_1++) { - if (attrs[i_1].kind === 237 /* JsxSpreadAttribute */) { - // If this is the first argument, we need to emit a {} as the first argument - if (i_1 === 0) { - write("{}, "); - } - if (haveOpenedObjectLiteral) { - write("}"); - haveOpenedObjectLiteral = false; - } - if (i_1 > 0) { - write(", "); - } - emit(attrs[i_1].expression); - } - else { - ts.Debug.assert(attrs[i_1].kind === 236 /* JsxAttribute */); - if (haveOpenedObjectLiteral) { - write(", "); - } - else { - haveOpenedObjectLiteral = true; - if (i_1 > 0) { - write(", "); - } - write("{"); - } - emitJsxAttribute(attrs[i_1]); - } - } - if (haveOpenedObjectLiteral) - write("}"); - write(")"); // closing paren to React.__spread( - } - else { - // One object literal with all the attributes in them - write("{"); - for (var i = 0; i < attrs.length; i++) { - if (i > 0) { - write(", "); - } - emitJsxAttribute(attrs[i]); - } - write("}"); - } - } - // Children - if (children) { - for (var i = 0; i < children.length; i++) { - // Don't emit empty expressions - if (children[i].kind === 238 /* JsxExpression */ && !(children[i].expression)) { - continue; - } - // Don't emit empty strings - if (children[i].kind === 234 /* JsxText */) { - var text = getTextToEmit(children[i]); - if (text !== undefined) { - write(", \""); - write(text); - write("\""); - } - } - else { - write(", "); - emit(children[i]); - } - } - } - // Closing paren - write(")"); // closes "React.createElement(" - emitTrailingComments(openingNode); - } - if (node.kind === 231 /* JsxElement */) { - emitJsxElement(node.openingElement, node.children); - } - else { - ts.Debug.assert(node.kind === 232 /* JsxSelfClosingElement */); - emitJsxElement(node); - } - } - function jsxEmitPreserve(node) { - function emitJsxAttribute(node) { - emit(node.name); - if (node.initializer) { - write("="); - emit(node.initializer); - } - } - function emitJsxSpreadAttribute(node) { - write("{..."); - emit(node.expression); - write("}"); - } - function emitAttributes(attribs) { - for (var i = 0, n = attribs.length; i < n; i++) { - if (i > 0) { - write(" "); - } - if (attribs[i].kind === 237 /* JsxSpreadAttribute */) { - emitJsxSpreadAttribute(attribs[i]); - } - else { - ts.Debug.assert(attribs[i].kind === 236 /* JsxAttribute */); - emitJsxAttribute(attribs[i]); - } - } - } - function emitJsxOpeningOrSelfClosingElement(node) { - write("<"); - emit(node.tagName); - if (node.attributes.length > 0 || (node.kind === 232 /* JsxSelfClosingElement */)) { - write(" "); - } - emitAttributes(node.attributes); - if (node.kind === 232 /* JsxSelfClosingElement */) { - write("/>"); - } - else { - write(">"); - } - } - function emitJsxClosingElement(node) { - write(""); - } - function emitJsxElement(node) { - emitJsxOpeningOrSelfClosingElement(node.openingElement); - for (var i = 0, n = node.children.length; i < n; i++) { - emit(node.children[i]); - } - emitJsxClosingElement(node.closingElement); - } - if (node.kind === 231 /* JsxElement */) { - emitJsxElement(node); - } - else { - ts.Debug.assert(node.kind === 232 /* JsxSelfClosingElement */); - emitJsxOpeningOrSelfClosingElement(node); - } - } - // This function specifically handles numeric/string literals for enum and accessor 'identifiers'. - // In a sense, it does not actually emit identifiers as much as it declares a name for a specific property. - // For example, this is utilized when feeding in a result to Object.defineProperty. - function emitExpressionForPropertyName(node) { - ts.Debug.assert(node.kind !== 161 /* BindingElement */); - if (node.kind === 9 /* StringLiteral */) { - emitLiteral(node); - } - else if (node.kind === 134 /* ComputedPropertyName */) { - // if this is a decorated computed property, we will need to capture the result - // of the property expression so that we can apply decorators later. This is to ensure - // we don't introduce unintended side effects: - // - // class C { - // [_a = x]() { } - // } - // - // The emit for the decorated computed property decorator is: - // - // Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); - // - if (ts.nodeIsDecorated(node.parent)) { - if (!computedPropertyNamesToGeneratedNames) { - computedPropertyNamesToGeneratedNames = []; - } - var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; - if (generatedName) { - // we have already generated a variable for this node, write that value instead. - write(generatedName); - return; - } - generatedName = createAndRecordTempVariable(0 /* Auto */).text; - computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; - write(generatedName); - write(" = "); - } - emit(node.expression); - } - else { - write("\""); - if (node.kind === 8 /* NumericLiteral */) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - write("\""); - } - } - function isExpressionIdentifier(node) { - var parent = node.parent; - switch (parent.kind) { - case 162 /* ArrayLiteralExpression */: - case 179 /* BinaryExpression */: - case 166 /* CallExpression */: - case 239 /* CaseClause */: - case 134 /* ComputedPropertyName */: - case 180 /* ConditionalExpression */: - case 137 /* Decorator */: - case 173 /* DeleteExpression */: - case 195 /* DoStatement */: - case 165 /* ElementAccessExpression */: - case 225 /* ExportAssignment */: - case 193 /* ExpressionStatement */: - case 186 /* ExpressionWithTypeArguments */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 194 /* IfStatement */: - case 232 /* JsxSelfClosingElement */: - case 233 /* JsxOpeningElement */: - case 237 /* JsxSpreadAttribute */: - case 238 /* JsxExpression */: - case 167 /* NewExpression */: - case 170 /* ParenthesizedExpression */: - case 178 /* PostfixUnaryExpression */: - case 177 /* PrefixUnaryExpression */: - case 202 /* ReturnStatement */: - case 244 /* ShorthandPropertyAssignment */: - case 183 /* SpreadElementExpression */: - case 204 /* SwitchStatement */: - case 168 /* TaggedTemplateExpression */: - case 188 /* TemplateSpan */: - case 206 /* ThrowStatement */: - case 169 /* TypeAssertionExpression */: - case 174 /* TypeOfExpression */: - case 175 /* VoidExpression */: - case 196 /* WhileStatement */: - case 203 /* WithStatement */: - case 182 /* YieldExpression */: - return true; - case 161 /* BindingElement */: - case 245 /* EnumMember */: - case 136 /* Parameter */: - case 243 /* PropertyAssignment */: - case 139 /* PropertyDeclaration */: - case 209 /* VariableDeclaration */: - return parent.initializer === node; - case 164 /* PropertyAccessExpression */: - return parent.expression === node; - case 172 /* ArrowFunction */: - case 171 /* FunctionExpression */: - return parent.body === node; - case 219 /* ImportEqualsDeclaration */: - return parent.moduleReference === node; - case 133 /* QualifiedName */: - return parent.left === node; - } - return false; - } - function emitExpressionIdentifier(node) { - if (resolver.getNodeCheckFlags(node) & 2048 /* LexicalArguments */) { - write("_arguments"); - return; - } - var container = resolver.getReferencedExportContainer(node); - if (container) { - if (container.kind === 246 /* SourceFile */) { - // Identifier references module export - if (languageVersion < 2 /* ES6 */ && compilerOptions.module !== 4 /* System */) { - write("exports."); - } - } - else { - // Identifier references namespace export - write(getGeneratedNameForNode(container)); - write("."); - } - } - else if (languageVersion < 2 /* ES6 */) { - var declaration = resolver.getReferencedImportDeclaration(node); - if (declaration) { - if (declaration.kind === 221 /* ImportClause */) { - // Identifier references default import - write(getGeneratedNameForNode(declaration.parent)); - write(languageVersion === 0 /* ES3 */ ? "[\"default\"]" : ".default"); - return; - } - else if (declaration.kind === 224 /* ImportSpecifier */) { - // Identifier references named import - write(getGeneratedNameForNode(declaration.parent.parent.parent)); - var name = declaration.propertyName || declaration.name; - var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name); - if (languageVersion === 0 /* ES3 */ && identifier === "default") { - write("[\"default\"]"); - } - else { - write("."); - write(identifier); - } - return; - } - } - declaration = resolver.getReferencedNestedRedeclaration(node); - if (declaration) { - write(getGeneratedNameForNode(declaration.name)); - return; - } - } - if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function isNameOfNestedRedeclaration(node) { - if (languageVersion < 2 /* ES6 */) { - var parent_6 = node.parent; - switch (parent_6.kind) { - case 161 /* BindingElement */: - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 209 /* VariableDeclaration */: - return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); - } - } - return false; - } - function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (isExpressionIdentifier(node)) { - emitExpressionIdentifier(node); - } - else if (isNameOfNestedRedeclaration(node)) { - write(getGeneratedNameForNode(node)); - } - else if (ts.nodeIsSynthesized(node)) { - write(node.text); - } - else { - writeTextOfNode(currentSourceFile, node); - } - } - function emitThis(node) { - if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { - write("_this"); - } - else { - write("this"); - } - } - function emitSuper(node) { - if (languageVersion >= 2 /* ES6 */) { - write("super"); - } - else { - var flags = resolver.getNodeCheckFlags(node); - if (flags & 256 /* SuperInstance */) { - write("_super.prototype"); - } - else { - write("_super"); - } - } - } - function emitObjectBindingPattern(node) { - write("{ "); - var elements = node.elements; - emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); - write(" }"); - } - function emitArrayBindingPattern(node) { - write("["); - var elements = node.elements; - emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); - write("]"); - } - function emitBindingElement(node) { - if (node.propertyName) { - emit(node.propertyName); - write(": "); - } - if (node.dotDotDotToken) { - write("..."); - } - if (ts.isBindingPattern(node.name)) { - emit(node.name); - } - else { - emitModuleMemberName(node); - } - emitOptional(" = ", node.initializer); - } - function emitSpreadElementExpression(node) { - write("..."); - emit(node.expression); - } - function emitYieldExpression(node) { - write(ts.tokenToString(112 /* YieldKeyword */)); - if (node.asteriskToken) { - write("*"); - } - if (node.expression) { - write(" "); - emit(node.expression); - } - } - function emitAwaitExpression(node) { - var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); - if (needsParenthesis) { - write("("); - } - write(ts.tokenToString(112 /* YieldKeyword */)); - write(" "); - emit(node.expression); - if (needsParenthesis) { - write(")"); - } - } - function needsParenthesisForAwaitExpressionAsYield(node) { - if (node.parent.kind === 179 /* BinaryExpression */ && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { - return true; - } - else if (node.parent.kind === 180 /* ConditionalExpression */ && node.parent.condition === node) { - return true; - } - return false; - } - function needsParenthesisForPropertyAccessOrInvocation(node) { - switch (node.kind) { - case 67 /* Identifier */: - case 162 /* ArrayLiteralExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: - case 166 /* CallExpression */: - case 170 /* ParenthesizedExpression */: - // This list is not exhaustive and only includes those cases that are relevant - // to the check in emitArrayLiteral. More cases can be added as needed. - return false; - } - return true; - } - function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { - var pos = 0; - var group = 0; - var length = elements.length; - while (pos < length) { - // Emit using the pattern .concat(, , ...) - if (group === 1 && useConcat) { - write(".concat("); - } - else if (group > 0) { - write(", "); - } - var e = elements[pos]; - if (e.kind === 183 /* SpreadElementExpression */) { - e = e.expression; - emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); - pos++; - if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 162 /* ArrayLiteralExpression */) { - write(".slice()"); - } - } - else { - var i = pos; - while (i < length && elements[i].kind !== 183 /* SpreadElementExpression */) { - i++; - } - write("["); - if (multiLine) { - increaseIndent(); - } - emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); - if (multiLine) { - decreaseIndent(); - } - write("]"); - pos = i; - } - group++; - } - if (group > 1) { - if (useConcat) { - write(")"); - } - } - } - function isSpreadElementExpression(node) { - return node.kind === 183 /* SpreadElementExpression */; - } - function emitArrayLiteral(node) { - var elements = node.elements; - if (elements.length === 0) { - write("[]"); - } - else if (languageVersion >= 2 /* ES6 */ || !ts.forEach(elements, isSpreadElementExpression)) { - write("["); - emitLinePreservingList(node, node.elements, elements.hasTrailingComma, /*spacesBetweenBraces:*/ false); - write("]"); - } - else { - emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/ (node.flags & 2048 /* MultiLine */) !== 0, - /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); - } - } - function emitObjectLiteralBody(node, numElements) { - if (numElements === 0) { - write("{}"); - return; - } - write("{"); - if (numElements > 0) { - var properties = node.properties; - // If we are not doing a downlevel transformation for object literals, - // then try to preserve the original shape of the object literal. - // Otherwise just try to preserve the formatting. - if (numElements === properties.length) { - emitLinePreservingList(node, properties, /* allowTrailingComma */ languageVersion >= 1 /* ES5 */, /* spacesBetweenBraces */ true); - } - else { - var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; - if (!multiLine) { - write(" "); - } - else { - increaseIndent(); - } - emitList(properties, 0, numElements, /*multiLine*/ multiLine, /*trailingComma*/ false); - if (!multiLine) { - write(" "); - } - else { - decreaseIndent(); - } - } - } - write("}"); - } - function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { - var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; - var properties = node.properties; - write("("); - if (multiLine) { - increaseIndent(); - } - // For computed properties, we need to create a unique handle to the object - // literal so we can modify it without risking internal assignments tainting the object. - var tempVar = createAndRecordTempVariable(0 /* Auto */); - // Write out the first non-computed properties - // (or all properties if none of them are computed), - // then emit the rest through indexing on the temp variable. - emit(tempVar); - write(" = "); - emitObjectLiteralBody(node, firstComputedPropertyIndex); - for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { - writeComma(); - var property = properties[i]; - emitStart(property); - if (property.kind === 143 /* GetAccessor */ || property.kind === 144 /* SetAccessor */) { - // TODO (drosen): Reconcile with 'emitMemberFunctions'. - var accessors = ts.getAllAccessorDeclarations(node.properties, property); - if (property !== accessors.firstAccessor) { - continue; - } - write("Object.defineProperty("); - emit(tempVar); - write(", "); - emitStart(node.name); - emitExpressionForPropertyName(property.name); - emitEnd(property.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("})"); - emitEnd(property); - } - else { - emitLeadingComments(property); - emitStart(property.name); - emit(tempVar); - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - if (property.kind === 243 /* PropertyAssignment */) { - emit(property.initializer); - } - else if (property.kind === 244 /* ShorthandPropertyAssignment */) { - emitExpressionIdentifier(property.name); - } - else if (property.kind === 141 /* MethodDeclaration */) { - emitFunctionDeclaration(property); - } - else { - ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); - } - } - emitEnd(property); - } - writeComma(); - emit(tempVar); - if (multiLine) { - decreaseIndent(); - writeLine(); - } - write(")"); - function writeComma() { - if (multiLine) { - write(","); - writeLine(); - } - else { - write(", "); - } - } - } - function emitObjectLiteral(node) { - var properties = node.properties; - if (languageVersion < 2 /* ES6 */) { - var numProperties = properties.length; - // Find the first computed property. - // Everything until that point can be emitted as part of the initial object literal. - var numInitialNonComputedProperties = numProperties; - for (var i = 0, n = properties.length; i < n; i++) { - if (properties[i].name.kind === 134 /* ComputedPropertyName */) { - numInitialNonComputedProperties = i; - break; - } - } - var hasComputedProperty = numInitialNonComputedProperties !== properties.length; - if (hasComputedProperty) { - emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); - return; - } - } - // Ordinary case: either the object has no computed properties - // or we're compiling with an ES6+ target. - emitObjectLiteralBody(node, properties.length); - } - function createBinaryExpression(left, operator, right, startsOnNewLine) { - var result = ts.createSynthesizedNode(179 /* BinaryExpression */, startsOnNewLine); - result.operatorToken = ts.createSynthesizedNode(operator); - result.left = left; - result.right = right; - return result; - } - function createPropertyAccessExpression(expression, name) { - var result = ts.createSynthesizedNode(164 /* PropertyAccessExpression */); - result.expression = parenthesizeForAccess(expression); - result.dotToken = ts.createSynthesizedNode(21 /* DotToken */); - result.name = name; - return result; - } - function createElementAccessExpression(expression, argumentExpression) { - var result = ts.createSynthesizedNode(165 /* ElementAccessExpression */); - result.expression = parenthesizeForAccess(expression); - result.argumentExpression = argumentExpression; - return result; - } - function parenthesizeForAccess(expr) { - // When diagnosing whether the expression needs parentheses, the decision should be based - // on the innermost expression in a chain of nested type assertions. - while (expr.kind === 169 /* TypeAssertionExpression */ || expr.kind === 187 /* AsExpression */) { - expr = expr.expression; - } - // isLeftHandSideExpression is almost the correct criterion for when it is not necessary - // to parenthesize the expression before a dot. The known exceptions are: - // - // NewExpression: - // new C.x -> not the same as (new C).x - // NumberLiteral - // 1.x -> not the same as (1).x - // - if (ts.isLeftHandSideExpression(expr) && - expr.kind !== 167 /* NewExpression */ && - expr.kind !== 8 /* NumericLiteral */) { - return expr; - } - var node = ts.createSynthesizedNode(170 /* ParenthesizedExpression */); - node.expression = expr; - return node; - } - function emitComputedPropertyName(node) { - write("["); - emitExpressionForPropertyName(node); - write("]"); - } - function emitMethod(node) { - if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { - write("*"); - } - emit(node.name); - if (languageVersion < 2 /* ES6 */) { - write(": function "); - } - emitSignatureAndBody(node); - } - function emitPropertyAssignment(node) { - emit(node.name); - write(": "); - // This is to ensure that we emit comment in the following case: - // For example: - // obj = { - // id: /*comment1*/ ()=>void - // } - // "comment1" is not considered to be leading comment for node.initializer - // but rather a trailing comment on the previous node. - emitTrailingCommentsOfPosition(node.initializer.pos); - emit(node.initializer); - } - // Return true if identifier resolves to an exported member of a namespace - function isNamespaceExportReference(node) { - var container = resolver.getReferencedExportContainer(node); - return container && container.kind !== 246 /* SourceFile */; - } - function emitShorthandPropertyAssignment(node) { - // The name property of a short-hand property assignment is considered an expression position, so here - // we manually emit the identifier to avoid rewriting. - writeTextOfNode(currentSourceFile, node.name); - // If emitting pre-ES6 code, or if the name requires rewriting when resolved as an expression identifier, - // we emit a normal property assignment. For example: - // module m { - // export let y; - // } - // module m { - // let obj = { y }; - // } - // Here we need to emit obj = { y : m.y } regardless of the output target. - if (languageVersion < 2 /* ES6 */ || isNamespaceExportReference(node.name)) { - // Emit identifier as an identifier - write(": "); - emit(node.name); - } - } - function tryEmitConstantValue(node) { - var constantValue = tryGetConstEnumValue(node); - if (constantValue !== undefined) { - write(constantValue.toString()); - if (!compilerOptions.removeComments) { - var propertyName = node.kind === 164 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); - write(" /* " + propertyName + " */"); - } - return true; - } - return false; - } - function tryGetConstEnumValue(node) { - if (compilerOptions.isolatedModules) { - return undefined; - } - return node.kind === 164 /* PropertyAccessExpression */ || node.kind === 165 /* ElementAccessExpression */ - ? resolver.getConstantValue(node) - : undefined; - } - // Returns 'true' if the code was actually indented, false otherwise. - // If the code is not indented, an optional valueToWriteWhenNotIndenting will be - // emitted instead. - function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { - var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); - // Always use a newline for synthesized code if the synthesizer desires it. - var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); - if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { - increaseIndent(); - writeLine(); - return true; - } - else { - if (valueToWriteWhenNotIndenting) { - write(valueToWriteWhenNotIndenting); - } - return false; - } - } - function emitPropertyAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); - // 1 .toString is a valid property access, emit a space after the literal - // Also emit a space if expression is a integer const enum value - it will appear in generated code as numeric literal - var shouldEmitSpace; - if (!indentedBeforeDot) { - if (node.expression.kind === 8 /* NumericLiteral */) { - // check if numeric literal was originally written with a dot - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); - shouldEmitSpace = text.indexOf(ts.tokenToString(21 /* DotToken */)) < 0; - } - else { - // check if constant enum value is integer - var constantValue = tryGetConstEnumValue(node.expression); - // isFinite handles cases when constantValue is undefined - shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; - } - } - if (shouldEmitSpace) { - write(" ."); - } - else { - write("."); - } - var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); - emit(node.name); - decreaseIndentIf(indentedBeforeDot, indentedAfterDot); - } - function emitQualifiedName(node) { - emit(node.left); - write("."); - emit(node.right); - } - function emitQualifiedNameAsExpression(node, useFallback) { - if (node.left.kind === 67 /* Identifier */) { - emitEntityNameAsExpression(node.left, useFallback); - } - else if (useFallback) { - var temp = createAndRecordTempVariable(0 /* Auto */); - write("("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(node.left, /*useFallback*/ true); - write(") && "); - emitNodeWithoutSourceMap(temp); - } - else { - emitEntityNameAsExpression(node.left, /*useFallback*/ false); - } - write("."); - emit(node.right); - } - function emitEntityNameAsExpression(node, useFallback) { - switch (node.kind) { - case 67 /* Identifier */: - if (useFallback) { - write("typeof "); - emitExpressionIdentifier(node); - write(" !== 'undefined' && "); - } - emitExpressionIdentifier(node); - break; - case 133 /* QualifiedName */: - emitQualifiedNameAsExpression(node, useFallback); - break; - } - } - function emitIndexedAccess(node) { - if (tryEmitConstantValue(node)) { - return; - } - emit(node.expression); - write("["); - emit(node.argumentExpression); - write("]"); - } - function hasSpreadElement(elements) { - return ts.forEach(elements, function (e) { return e.kind === 183 /* SpreadElementExpression */; }); - } - function skipParentheses(node) { - while (node.kind === 170 /* ParenthesizedExpression */ || node.kind === 169 /* TypeAssertionExpression */ || node.kind === 187 /* AsExpression */) { - node = node.expression; - } - return node; - } - function emitCallTarget(node) { - if (node.kind === 67 /* Identifier */ || node.kind === 95 /* ThisKeyword */ || node.kind === 93 /* SuperKeyword */) { - emit(node); - return node; - } - var temp = createAndRecordTempVariable(0 /* Auto */); - write("("); - emit(temp); - write(" = "); - emit(node); - write(")"); - return temp; - } - function emitCallWithSpread(node) { - var target; - var expr = skipParentheses(node.expression); - if (expr.kind === 164 /* PropertyAccessExpression */) { - // Target will be emitted as "this" argument - target = emitCallTarget(expr.expression); - write("."); - emit(expr.name); - } - else if (expr.kind === 165 /* ElementAccessExpression */) { - // Target will be emitted as "this" argument - target = emitCallTarget(expr.expression); - write("["); - emit(expr.argumentExpression); - write("]"); - } - else if (expr.kind === 93 /* SuperKeyword */) { - target = expr; - write("_super"); - } - else { - emit(node.expression); - } - write(".apply("); - if (target) { - if (target.kind === 93 /* SuperKeyword */) { - // Calls of form super(...) and super.foo(...) - emitThis(target); - } - else { - // Calls of form obj.foo(...) - emit(target); - } - } - else { - // Calls of form foo(...) - write("void 0"); - } - write(", "); - emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false, /*useConcat*/ true); - write(")"); - } - function emitCallExpression(node) { - if (languageVersion < 2 /* ES6 */ && hasSpreadElement(node.arguments)) { - emitCallWithSpread(node); - return; - } - var superCall = false; - if (node.expression.kind === 93 /* SuperKeyword */) { - emitSuper(node.expression); - superCall = true; - } - else { - emit(node.expression); - superCall = node.expression.kind === 164 /* PropertyAccessExpression */ && node.expression.expression.kind === 93 /* SuperKeyword */; - } - if (superCall && languageVersion < 2 /* ES6 */) { - write(".call("); - emitThis(node.expression); - if (node.arguments.length) { - write(", "); - emitCommaList(node.arguments); - } - write(")"); - } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - function emitNewExpression(node) { - write("new "); - // Spread operator logic is supported in new expressions in ES5 using a combination - // of Function.prototype.bind() and Function.prototype.apply(). - // - // Example: - // - // var args = [1, 2, 3, 4, 5]; - // new Array(...args); - // - // is compiled into the following ES5: - // - // var args = [1, 2, 3, 4, 5]; - // new (Array.bind.apply(Array, [void 0].concat(args))); - // - // The 'thisArg' to 'bind' is ignored when invoking the result of 'bind' with 'new', - // Thus, we set it to undefined ('void 0'). - if (languageVersion === 1 /* ES5 */ && - node.arguments && - hasSpreadElement(node.arguments)) { - write("("); - var target = emitCallTarget(node.expression); - write(".bind.apply("); - emit(target); - write(", [void 0].concat("); - emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiline*/ false, /*trailingComma*/ false, /*useConcat*/ false); - write(")))"); - write("()"); - } - else { - emit(node.expression); - if (node.arguments) { - write("("); - emitCommaList(node.arguments); - write(")"); - } - } - } - function emitTaggedTemplateExpression(node) { - if (languageVersion >= 2 /* ES6 */) { - emit(node.tag); - write(" "); - emit(node.template); - } - else { - emitDownlevelTaggedTemplate(node); - } - } - function emitParenExpression(node) { - // If the node is synthesized, it means the emitter put the parentheses there, - // not the user. If we didn't want them, the emitter would not have put them - // there. - if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 172 /* ArrowFunction */) { - if (node.expression.kind === 169 /* TypeAssertionExpression */ || node.expression.kind === 187 /* AsExpression */) { - var operand = node.expression.expression; - // Make sure we consider all nested cast expressions, e.g.: - // (-A).x; - while (operand.kind === 169 /* TypeAssertionExpression */ || operand.kind === 187 /* AsExpression */) { - operand = operand.expression; - } - // We have an expression of the form: (SubExpr) - // Emitting this as (SubExpr) is really not desirable. We would like to emit the subexpr as is. - // Omitting the parentheses, however, could cause change in the semantics of the generated - // code if the casted expression has a lower precedence than the rest of the expression, e.g.: - // (new A).foo should be emitted as (new A).foo and not new A.foo - // (typeof A).toString() should be emitted as (typeof A).toString() and not typeof A.toString() - // new (A()) should be emitted as new (A()) and not new A() - // (function foo() { })() should be emitted as an IIF (function foo(){})() and not declaration function foo(){} () - if (operand.kind !== 177 /* PrefixUnaryExpression */ && - operand.kind !== 175 /* VoidExpression */ && - operand.kind !== 174 /* TypeOfExpression */ && - operand.kind !== 173 /* DeleteExpression */ && - operand.kind !== 178 /* PostfixUnaryExpression */ && - operand.kind !== 167 /* NewExpression */ && - !(operand.kind === 166 /* CallExpression */ && node.parent.kind === 167 /* NewExpression */) && - !(operand.kind === 171 /* FunctionExpression */ && node.parent.kind === 166 /* CallExpression */) && - !(operand.kind === 8 /* NumericLiteral */ && node.parent.kind === 164 /* PropertyAccessExpression */)) { - emit(operand); - return; - } - } - } - write("("); - emit(node.expression); - write(")"); - } - function emitDeleteExpression(node) { - write(ts.tokenToString(76 /* DeleteKeyword */)); - write(" "); - emit(node.expression); - } - function emitVoidExpression(node) { - write(ts.tokenToString(101 /* VoidKeyword */)); - write(" "); - emit(node.expression); - } - function emitTypeOfExpression(node) { - write(ts.tokenToString(99 /* TypeOfKeyword */)); - write(" "); - emit(node.expression); - } - function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { - if (!isCurrentFileSystemExternalModule() || node.kind !== 67 /* Identifier */ || ts.nodeIsSynthesized(node)) { - return false; - } - var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 209 /* VariableDeclaration */ || node.parent.kind === 161 /* BindingElement */); - var targetDeclaration = isVariableDeclarationOrBindingElement - ? node.parent - : resolver.getReferencedValueDeclaration(node); - return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true); - } - function emitPrefixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - // emit - // ++x - // as - // exports('x', ++x) - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - } - write(ts.tokenToString(node.operator)); - // In some cases, we need to emit a space between the operator and the operand. One obvious case - // is when the operator is an identifier, like delete or typeof. We also need to do this for plus - // and minus expressions in certain cases. Specifically, consider the following two cases (parens - // are just for clarity of exposition, and not part of the source code): - // - // (+(+1)) - // (+(++1)) - // - // We need to emit a space in both cases. In the first case, the absence of a space will make - // the resulting expression a prefix increment operation. And in the second, it will make the resulting - // expression a prefix increment whose operand is a plus expression - (++(+x)) - // The same is true of minus of course. - if (node.operand.kind === 177 /* PrefixUnaryExpression */) { - var operand = node.operand; - if (node.operator === 35 /* PlusToken */ && (operand.operator === 35 /* PlusToken */ || operand.operator === 40 /* PlusPlusToken */)) { - write(" "); - } - else if (node.operator === 36 /* MinusToken */ && (operand.operator === 36 /* MinusToken */ || operand.operator === 41 /* MinusMinusToken */)) { - write(" "); - } - } - emit(node.operand); - if (exportChanged) { - write(")"); - } - } - function emitPostfixUnaryExpression(node) { - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (exportChanged) { - // export function returns the value that was passes as the second argument - // however for postfix unary expressions result value should be the value before modification. - // emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)' - write("(" + exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.operand); - write("\", "); - write(ts.tokenToString(node.operator)); - emit(node.operand); - if (node.operator === 40 /* PlusPlusToken */) { - write(") - 1)"); - } - else { - write(") + 1)"); - } - } - else { - emit(node.operand); - write(ts.tokenToString(node.operator)); - } - } - function shouldHoistDeclarationInSystemJsModule(node) { - return isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ false); - } - /* - * Checks if given node is a source file level declaration (not nested in module/function). - * If 'isExported' is true - then declaration must also be exported. - * This function is used in two cases: - * - check if node is a exported source file level value to determine - * if we should also export the value after its it changed - * - check if node is a source level declaration to emit it differently, - * i.e non-exported variable statement 'var x = 1' is hoisted so - * we we emit variable statement 'var' should be dropped. - */ - function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { - if (!node || languageVersion >= 2 /* ES6 */ || !isCurrentFileSystemExternalModule()) { - return false; - } - var current = node; - while (current) { - if (current.kind === 246 /* SourceFile */) { - return !isExported || ((ts.getCombinedNodeFlags(node) & 1 /* Export */) !== 0); - } - else if (ts.isFunctionLike(current) || current.kind === 217 /* ModuleBlock */) { - return false; - } - else { - current = current.parent; - } - } - } - function emitBinaryExpression(node) { - if (languageVersion < 2 /* ES6 */ && node.operatorToken.kind === 55 /* EqualsToken */ && - (node.left.kind === 163 /* ObjectLiteralExpression */ || node.left.kind === 162 /* ArrayLiteralExpression */)) { - emitDestructuring(node, node.parent.kind === 193 /* ExpressionStatement */); - } - else { - var exportChanged = node.operatorToken.kind >= 55 /* FirstAssignment */ && - node.operatorToken.kind <= 66 /* LastAssignment */ && - isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); - if (exportChanged) { - // emit assignment 'x y' as 'exports("x", x y)' - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.left); - write("\", "); - } - emit(node.left); - var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 /* CommaToken */ ? " " : undefined); - write(ts.tokenToString(node.operatorToken.kind)); - var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); - emit(node.right); - decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); - if (exportChanged) { - write(")"); - } - } - } - function synthesizedNodeStartsOnNewLine(node) { - return ts.nodeIsSynthesized(node) && node.startsOnNewLine; - } - function emitConditionalExpression(node) { - emit(node.condition); - var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); - write("?"); - var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); - emit(node.whenTrue); - decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); - var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); - write(":"); - var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); - emit(node.whenFalse); - decreaseIndentIf(indentedBeforeColon, indentedAfterColon); - } - // Helper function to decrease the indent if we previously indented. Allows multiple - // previous indent values to be considered at a time. This also allows caller to just - // call this once, passing in all their appropriate indent values, instead of needing - // to call this helper function multiple times. - function decreaseIndentIf(value1, value2) { - if (value1) { - decreaseIndent(); - } - if (value2) { - decreaseIndent(); - } - } - function isSingleLineEmptyBlock(node) { - if (node && node.kind === 190 /* Block */) { - var block = node; - return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); - } - } - function emitBlock(node) { - if (isSingleLineEmptyBlock(node)) { - emitToken(15 /* OpenBraceToken */, node.pos); - write(" "); - emitToken(16 /* CloseBraceToken */, node.statements.end); - return; - } - emitToken(15 /* OpenBraceToken */, node.pos); - increaseIndent(); - scopeEmitStart(node.parent); - if (node.kind === 217 /* ModuleBlock */) { - ts.Debug.assert(node.parent.kind === 216 /* ModuleDeclaration */); - emitCaptureThisForNodeIfNecessary(node.parent); - } - emitLines(node.statements); - if (node.kind === 217 /* ModuleBlock */) { - emitTempDeclarations(/*newLine*/ true); - } - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.statements.end); - scopeEmitEnd(); - } - function emitEmbeddedStatement(node) { - if (node.kind === 190 /* Block */) { - write(" "); - emit(node); - } - else { - increaseIndent(); - writeLine(); - emit(node); - decreaseIndent(); - } - } - function emitExpressionStatement(node) { - emitParenthesizedIf(node.expression, /*parenthesized*/ node.expression.kind === 172 /* ArrowFunction */); - write(";"); - } - function emitIfStatement(node) { - var endPos = emitToken(86 /* IfKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - emit(node.expression); - emitToken(18 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.thenStatement); - if (node.elseStatement) { - writeLine(); - emitToken(78 /* ElseKeyword */, node.thenStatement.end); - if (node.elseStatement.kind === 194 /* IfStatement */) { - write(" "); - emit(node.elseStatement); - } - else { - emitEmbeddedStatement(node.elseStatement); - } - } - } - function emitDoStatement(node) { - write("do"); - emitEmbeddedStatement(node.statement); - if (node.statement.kind === 190 /* Block */) { - write(" "); - } - else { - writeLine(); - } - write("while ("); - emit(node.expression); - write(");"); - } - function emitWhileStatement(node) { - write("while ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - /** - * Returns true if start of variable declaration list was emitted. - * Returns false if nothing was written - this can happen for source file level variable declarations - * in system modules where such variable declarations are hoisted. - */ - function tryEmitStartOfVariableDeclarationList(decl, startPos) { - if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) { - // variables in variable declaration list were already hoisted - return false; - } - var tokenKind = 100 /* VarKeyword */; - if (decl && languageVersion >= 2 /* ES6 */) { - if (ts.isLet(decl)) { - tokenKind = 106 /* LetKeyword */; - } - else if (ts.isConst(decl)) { - tokenKind = 72 /* ConstKeyword */; - } - } - if (startPos !== undefined) { - emitToken(tokenKind, startPos); - write(" "); - } - else { - switch (tokenKind) { - case 100 /* VarKeyword */: - write("var "); - break; - case 106 /* LetKeyword */: - write("let "); - break; - case 72 /* ConstKeyword */: - write("const "); - break; - } - } - return true; - } - function emitVariableDeclarationListSkippingUninitializedEntries(list) { - var started = false; - for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { - var decl = _b[_a]; - if (!decl.initializer) { - continue; - } - if (!started) { - started = true; - } - else { - write(", "); - } - emit(decl); - } - return started; - } - function emitForStatement(node) { - var endPos = emitToken(84 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - if (node.initializer && node.initializer.kind === 210 /* VariableDeclarationList */) { - var variableDeclarationList = node.initializer; - var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - if (startIsEmitted) { - emitCommaList(variableDeclarationList.declarations); - } - else { - emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); - } - } - else if (node.initializer) { - emit(node.initializer); - } - write(";"); - emitOptional(" ", node.condition); - write(";"); - emitOptional(" ", node.incrementor); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitForInOrForOfStatement(node) { - if (languageVersion < 2 /* ES6 */ && node.kind === 199 /* ForOfStatement */) { - return emitDownLevelForOfStatement(node); - } - var endPos = emitToken(84 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - if (node.initializer.kind === 210 /* VariableDeclarationList */) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); - emit(variableDeclarationList.declarations[0]); - } - } - else { - emit(node.initializer); - } - if (node.kind === 198 /* ForInStatement */) { - write(" in "); - } - else { - write(" of "); - } - emit(node.expression); - emitToken(18 /* CloseParenToken */, node.expression.end); - emitEmbeddedStatement(node.statement); - } - function emitDownLevelForOfStatement(node) { - // The following ES6 code: - // - // for (let v of expr) { } - // - // should be emitted as - // - // for (let _i = 0, _a = expr; _i < _a.length; _i++) { - // let v = _a[_i]; - // } - // - // where _a and _i are temps emitted to capture the RHS and the counter, - // respectively. - // When the left hand side is an expression instead of a let declaration, - // the "let v" is not emitted. - // When the left hand side is a let/const, the v is renamed if there is - // another v in scope. - // Note that all assignments to the LHS are emitted in the body, including - // all destructuring. - // Note also that because an extra statement is needed to assign to the LHS, - // for-of bodies are always emitted as blocks. - var endPos = emitToken(84 /* ForKeyword */, node.pos); - write(" "); - endPos = emitToken(17 /* OpenParenToken */, endPos); - // Do not emit the LHS let declaration yet, because it might contain destructuring. - // Do not call recordTempDeclaration because we are declaring the temps - // right here. Recording means they will be declared later. - // In the case where the user wrote an identifier as the RHS, like this: - // - // for (let v of arr) { } - // - // we don't want to emit a temporary variable for the RHS, just use it directly. - var rhsIsIdentifier = node.expression.kind === 67 /* Identifier */; - var counter = createTempVariable(268435456 /* _i */); - var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0 /* Auto */); - // This is the let keyword for the counter and rhsReference. The let keyword for - // the LHS will be emitted inside the body. - emitStart(node.expression); - write("var "); - // _i = 0 - emitNodeWithoutSourceMap(counter); - write(" = 0"); - emitEnd(node.expression); - if (!rhsIsIdentifier) { - // , _a = expr - write(", "); - emitStart(node.expression); - emitNodeWithoutSourceMap(rhsReference); - write(" = "); - emitNodeWithoutSourceMap(node.expression); - emitEnd(node.expression); - } - write("; "); - // _i < _a.length; - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write(" < "); - emitNodeWithCommentsAndWithoutSourcemap(rhsReference); - write(".length"); - emitEnd(node.initializer); - write("; "); - // _i++) - emitStart(node.initializer); - emitNodeWithoutSourceMap(counter); - write("++"); - emitEnd(node.initializer); - emitToken(18 /* CloseParenToken */, node.expression.end); - // Body - write(" {"); - writeLine(); - increaseIndent(); - // Initialize LHS - // let v = _a[_i]; - var rhsIterationValue = createElementAccessExpression(rhsReference, counter); - emitStart(node.initializer); - if (node.initializer.kind === 210 /* VariableDeclarationList */) { - write("var "); - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length > 0) { - var declaration = variableDeclarationList.declarations[0]; - if (ts.isBindingPattern(declaration.name)) { - // This works whether the declaration is a var, let, or const. - // It will use rhsIterationValue _a[_i] as the initializer. - emitDestructuring(declaration, /*isAssignmentExpressionStatement*/ false, rhsIterationValue); - } - else { - // The following call does not include the initializer, so we have - // to emit it separately. - emitNodeWithCommentsAndWithoutSourcemap(declaration); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - // It's an empty declaration list. This can only happen in an error case, if the user wrote - // for (let of []) {} - emitNodeWithoutSourceMap(createTempVariable(0 /* Auto */)); - write(" = "); - emitNodeWithoutSourceMap(rhsIterationValue); - } - } - else { - // Initializer is an expression. Emit the expression in the body, so that it's - // evaluated on every iteration. - var assignmentExpression = createBinaryExpression(node.initializer, 55 /* EqualsToken */, rhsIterationValue, /*startsOnNewLine*/ false); - if (node.initializer.kind === 162 /* ArrayLiteralExpression */ || node.initializer.kind === 163 /* ObjectLiteralExpression */) { - // This is a destructuring pattern, so call emitDestructuring instead of emit. Calling emit will not work, because it will cause - // the BinaryExpression to be passed in instead of the expression statement, which will cause emitDestructuring to crash. - emitDestructuring(assignmentExpression, /*isAssignmentExpressionStatement*/ true, /*value*/ undefined); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); - } - } - emitEnd(node.initializer); - write(";"); - if (node.statement.kind === 190 /* Block */) { - emitLines(node.statement.statements); - } - else { - writeLine(); - emit(node.statement); - } - writeLine(); - decreaseIndent(); - write("}"); - } - function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 201 /* BreakStatement */ ? 68 /* BreakKeyword */ : 73 /* ContinueKeyword */, node.pos); - emitOptional(" ", node.label); - write(";"); - } - function emitReturnStatement(node) { - emitToken(92 /* ReturnKeyword */, node.pos); - emitOptional(" ", node.expression); - write(";"); - } - function emitWithStatement(node) { - write("with ("); - emit(node.expression); - write(")"); - emitEmbeddedStatement(node.statement); - } - function emitSwitchStatement(node) { - var endPos = emitToken(94 /* SwitchKeyword */, node.pos); - write(" "); - emitToken(17 /* OpenParenToken */, endPos); - emit(node.expression); - endPos = emitToken(18 /* CloseParenToken */, node.expression.end); - write(" "); - emitCaseBlock(node.caseBlock, endPos); - } - function emitCaseBlock(node, startPos) { - emitToken(15 /* OpenBraceToken */, startPos); - increaseIndent(); - emitLines(node.clauses); - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.clauses.end); - } - function nodeStartPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function nodeEndPositionsAreOnSameLine(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, node2.end); - } - function nodeEndIsOnSameLineAsNodeStart(node1, node2) { - return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === - ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); - } - function emitCaseOrDefaultClause(node) { - if (node.kind === 239 /* CaseClause */) { - write("case "); - emit(node.expression); - write(":"); - } - else { - write("default:"); - } - if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { - write(" "); - emit(node.statements[0]); - } - else { - increaseIndent(); - emitLines(node.statements); - decreaseIndent(); - } - } - function emitThrowStatement(node) { - write("throw "); - emit(node.expression); - write(";"); - } - function emitTryStatement(node) { - write("try "); - emit(node.tryBlock); - emit(node.catchClause); - if (node.finallyBlock) { - writeLine(); - write("finally "); - emit(node.finallyBlock); - } - } - function emitCatchClause(node) { - writeLine(); - var endPos = emitToken(70 /* CatchKeyword */, node.pos); - write(" "); - emitToken(17 /* OpenParenToken */, endPos); - emit(node.variableDeclaration); - emitToken(18 /* CloseParenToken */, node.variableDeclaration ? node.variableDeclaration.end : endPos); - write(" "); - emitBlock(node.block); - } - function emitDebuggerStatement(node) { - emitToken(74 /* DebuggerKeyword */, node.pos); - write(";"); - } - function emitLabelledStatement(node) { - emit(node.label); - write(": "); - emit(node.statement); - } - function getContainingModule(node) { - do { - node = node.parent; - } while (node && node.kind !== 216 /* ModuleDeclaration */); - return node; - } - function emitContainingModuleName(node) { - var container = getContainingModule(node); - write(container ? getGeneratedNameForNode(container) : "exports"); - } - function emitModuleMemberName(node) { - emitStart(node.name); - if (ts.getCombinedNodeFlags(node) & 1 /* Export */) { - var container = getContainingModule(node); - if (container) { - write(getGeneratedNameForNode(container)); - write("."); - } - else if (languageVersion < 2 /* ES6 */ && compilerOptions.module !== 4 /* System */) { - write("exports."); - } - } - emitNodeWithCommentsAndWithoutSourcemap(node.name); - emitEnd(node.name); - } - function createVoidZero() { - var zero = ts.createSynthesizedNode(8 /* NumericLiteral */); - zero.text = "0"; - var result = ts.createSynthesizedNode(175 /* VoidExpression */); - result.expression = zero; - return result; - } - function emitEs6ExportDefaultCompat(node) { - if (node.parent.kind === 246 /* SourceFile */) { - ts.Debug.assert(!!(node.flags & 1024 /* Default */) || node.kind === 225 /* ExportAssignment */); - // only allow export default at a source file level - if (compilerOptions.module === 1 /* CommonJS */ || compilerOptions.module === 2 /* AMD */ || compilerOptions.module === 3 /* UMD */) { - if (!currentSourceFile.symbol.exports["___esModule"]) { - if (languageVersion === 1 /* ES5 */) { - // default value of configurable, enumerable, writable are `false`. - write("Object.defineProperty(exports, \"__esModule\", { value: true });"); - writeLine(); - } - else if (languageVersion === 0 /* ES3 */) { - write("exports.__esModule = true;"); - writeLine(); - } - } - } - } - } - function emitExportMemberAssignment(node) { - if (node.flags & 1 /* Export */) { - writeLine(); - emitStart(node); - // emit call to exporter only for top level nodes - if (compilerOptions.module === 4 /* System */ && node.parent === currentSourceFile) { - // emit export default as - // export("default", ) - write(exportFunctionForFile + "(\""); - if (node.flags & 1024 /* Default */) { - write("default"); - } - else { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - write("\", "); - emitDeclarationName(node); - write(")"); - } - else { - if (node.flags & 1024 /* Default */) { - emitEs6ExportDefaultCompat(node); - if (languageVersion === 0 /* ES3 */) { - write("exports[\"default\"]"); - } - else { - write("exports.default"); - } - } - else { - emitModuleMemberName(node); - } - write(" = "); - emitDeclarationName(node); - } - emitEnd(node); - write(";"); - } - } - function emitExportMemberAssignments(name) { - if (compilerOptions.module === 4 /* System */) { - return; - } - if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { - for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { - var specifier = _b[_a]; - writeLine(); - emitStart(specifier.name); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - emitEnd(specifier.name); - write(" = "); - emitExpressionIdentifier(name); - write(";"); - } - } - } - function emitExportSpecifierInSystemModule(specifier) { - ts.Debug.assert(compilerOptions.module === 4 /* System */); - if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { - return; - } - writeLine(); - emitStart(specifier.name); - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write("\", "); - emitExpressionIdentifier(specifier.propertyName || specifier.name); - write(")"); - emitEnd(specifier.name); - write(";"); - } - function emitDestructuring(root, isAssignmentExpressionStatement, value) { - var emitCount = 0; - // An exported declaration is actually emitted as an assignment (to a property on the module object), so - // temporary variables in an exported declaration need to have real declarations elsewhere - // Also temporary variables should be explicitly allocated for source level declarations when module target is system - // because actual variable declarations are hoisted - var canDefineTempVariablesInPlace = false; - if (root.kind === 209 /* VariableDeclaration */) { - var isExported = ts.getCombinedNodeFlags(root) & 1 /* Export */; - var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); - canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; - } - else if (root.kind === 136 /* Parameter */) { - canDefineTempVariablesInPlace = true; - } - if (root.kind === 179 /* BinaryExpression */) { - emitAssignmentExpression(root); - } - else { - ts.Debug.assert(!isAssignmentExpressionStatement); - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 209 /* VariableDeclaration */ || name.parent.kind === 161 /* BindingElement */); - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(name); - write("\", "); - } - if (isVariableDeclarationOrBindingElement) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - if (exportChanged) { - write(")"); - } - } - /** - * Ensures that there exists a declared identifier whose value holds the given expression. - * This function is useful to ensure that the expression's value can be read from in subsequent expressions. - * Unless 'reuseIdentifierExpressions' is false, 'expr' will be returned if it is just an identifier. - * - * @param expr the expression whose value needs to be bound. - * @param reuseIdentifierExpressions true if identifier expressions can simply be returned; - * false if it is necessary to always emit an identifier. - */ - function ensureIdentifier(expr, reuseIdentifierExpressions) { - if (expr.kind === 67 /* Identifier */ && reuseIdentifierExpressions) { - return expr; - } - var identifier = createTempVariable(0 /* Auto */); - if (!canDefineTempVariablesInPlace) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - return identifier; - } - function createDefaultValueCheck(value, defaultValue) { - // The value expression will be evaluated twice, so for anything but a simple identifier - // we need to generate a temporary variable - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - // Return the expression 'value === void 0 ? defaultValue : value' - var equals = ts.createSynthesizedNode(179 /* BinaryExpression */); - equals.left = value; - equals.operatorToken = ts.createSynthesizedNode(32 /* EqualsEqualsEqualsToken */); - equals.right = createVoidZero(); - return createConditionalExpression(equals, defaultValue, value); - } - function createConditionalExpression(condition, whenTrue, whenFalse) { - var cond = ts.createSynthesizedNode(180 /* ConditionalExpression */); - cond.condition = condition; - cond.questionToken = ts.createSynthesizedNode(52 /* QuestionToken */); - cond.whenTrue = whenTrue; - cond.colonToken = ts.createSynthesizedNode(53 /* ColonToken */); - cond.whenFalse = whenFalse; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createSynthesizedNode(8 /* NumericLiteral */); - node.text = "" + value; - return node; - } - function createPropertyAccessForDestructuringProperty(object, propName) { - // We create a synthetic copy of the identifier in order to avoid the rewriting that might - // otherwise occur when the identifier is emitted. - var syntheticName = ts.createSynthesizedNode(propName.kind); - syntheticName.text = propName.text; - if (syntheticName.kind !== 67 /* Identifier */) { - return createElementAccessExpression(object, syntheticName); - } - return createPropertyAccessExpression(object, syntheticName); - } - function createSliceCall(value, sliceIndex) { - var call = ts.createSynthesizedNode(166 /* CallExpression */); - var sliceIdentifier = ts.createSynthesizedNode(67 /* Identifier */); - sliceIdentifier.text = "slice"; - call.expression = createPropertyAccessExpression(value, sliceIdentifier); - call.arguments = ts.createSynthesizedNodeArray(); - call.arguments[0] = createNumericLiteral(sliceIndex); - return call; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - // For anything but a single element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - } - for (var _a = 0; _a < properties.length; _a++) { - var p = properties[_a]; - if (p.kind === 243 /* PropertyAssignment */ || p.kind === 244 /* ShorthandPropertyAssignment */) { - var propName = p.name; - emitDestructuringAssignment(p.initializer || propName, createPropertyAccessForDestructuringProperty(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - // For anything but a single element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 185 /* OmittedExpression */) { - if (e.kind !== 183 /* SpreadElementExpression */) { - emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === elements.length - 1) { - emitDestructuringAssignment(e.expression, createSliceCall(value, i)); - } - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 179 /* BinaryExpression */ && target.operatorToken.kind === 55 /* EqualsToken */) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 163 /* ObjectLiteralExpression */) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 162 /* ArrayLiteralExpression */) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { - emit(value); - } - else if (isAssignmentExpressionStatement) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 170 /* ParenthesizedExpression */) { - write("("); - } - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 170 /* ParenthesizedExpression */) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - // Combine value and initializer - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - // Use 'void 0' in absence of value and initializer - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - var numElements = elements.length; - if (numElements !== 1) { - // For anything other than a single-element destructuring we need to generate a temporary - // to ensure value is evaluated exactly once. Additionally, if we have zero elements - // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, - // so in that case, we'll intentionally create that temporary. - value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0); - } - for (var i = 0; i < numElements; i++) { - var element = elements[i]; - if (pattern.kind === 159 /* ObjectBindingPattern */) { - // Rewrite element to a declaration with an initializer that fetches property - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); - } - else if (element.kind !== 185 /* OmittedExpression */) { - if (!element.dotDotDotToken) { - // Rewrite element to a declaration that accesses array element at index i - emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); - } - else if (i === numElements - 1) { - emitBindingElement(element, createSliceCall(value, i)); - } - } - } - } - else { - emitAssignment(target.name, value); - } - } - } - function emitVariableDeclaration(node) { - if (ts.isBindingPattern(node.name)) { - if (languageVersion < 2 /* ES6 */) { - emitDestructuring(node, /*isAssignmentExpressionStatement*/ false); - } - else { - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - else { - var initializer = node.initializer; - if (!initializer && languageVersion < 2 /* ES6 */) { - // downlevel emit for non-initialized let bindings defined in loops - // for (...) { let x; } - // should be - // for (...) { var = void 0; } - // this is necessary to preserve ES6 semantic in scenarios like - // for (...) { let x; console.log(x); x = 1 } // assignment on one iteration should not affect other iterations - var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384 /* BlockScopedBindingInLoop */) && - (getCombinedFlagsForIdentifier(node.name) & 16384 /* Let */); - // NOTE: default initialization should not be added to let bindings in for-in\for-of statements - if (isUninitializedLet && - node.parent.parent.kind !== 198 /* ForInStatement */ && - node.parent.parent.kind !== 199 /* ForOfStatement */) { - initializer = createVoidZero(); - } - } - var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); - if (exportChanged) { - write(exportFunctionForFile + "(\""); - emitNodeWithCommentsAndWithoutSourcemap(node.name); - write("\", "); - } - emitModuleMemberName(node); - emitOptional(" = ", initializer); - if (exportChanged) { - write(")"); - } - } - } - function emitExportVariableAssignments(node) { - if (node.kind === 185 /* OmittedExpression */) { - return; - } - var name = node.name; - if (name.kind === 67 /* Identifier */) { - emitExportMemberAssignments(name); - } - else if (ts.isBindingPattern(name)) { - ts.forEach(name.elements, emitExportVariableAssignments); - } - } - function getCombinedFlagsForIdentifier(node) { - if (!node.parent || (node.parent.kind !== 209 /* VariableDeclaration */ && node.parent.kind !== 161 /* BindingElement */)) { - return 0; - } - return ts.getCombinedNodeFlags(node.parent); - } - function isES6ExportedDeclaration(node) { - return !!(node.flags & 1 /* Export */) && - languageVersion >= 2 /* ES6 */ && - node.parent.kind === 246 /* SourceFile */; - } - function emitVariableStatement(node) { - var startIsEmitted = false; - if (node.flags & 1 /* Export */) { - if (isES6ExportedDeclaration(node)) { - // Exported ES6 module member - write("export "); - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - } - else { - startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); - } - if (startIsEmitted) { - emitCommaList(node.declarationList.declarations); - write(";"); - } - else { - var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); - if (atLeastOneItem) { - write(";"); - } - } - if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) { - ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); - } - } - function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { - // If we're not exporting the variables, there's nothing special here. - // Always emit comments for these nodes. - if (!(node.flags & 1 /* Export */)) { - return true; - } - // If we are exporting, but it's a top-level ES6 module exports, - // we'll emit the declaration list verbatim, so emit comments too. - if (isES6ExportedDeclaration(node)) { - return true; - } - // Otherwise, only emit if we have at least one initializer present. - for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { - var declaration = _b[_a]; - if (declaration.initializer) { - return true; - } - } - return false; - } - function emitParameter(node) { - if (languageVersion < 2 /* ES6 */) { - if (ts.isBindingPattern(node.name)) { - var name_23 = createTempVariable(0 /* Auto */); - if (!tempParameters) { - tempParameters = []; - } - tempParameters.push(name_23); - emit(name_23); - } - else { - emit(node.name); - } - } - else { - if (node.dotDotDotToken) { - write("..."); - } - emit(node.name); - emitOptional(" = ", node.initializer); - } - } - function emitDefaultValueAssignments(node) { - if (languageVersion < 2 /* ES6 */) { - var tempIndex = 0; - ts.forEach(node.parameters, function (parameter) { - // A rest parameter cannot have a binding pattern or an initializer, - // so let's just ignore it. - if (parameter.dotDotDotToken) { - return; - } - var paramName = parameter.name, initializer = parameter.initializer; - if (ts.isBindingPattern(paramName)) { - // In cases where a binding pattern is simply '[]' or '{}', - // we usually don't want to emit a var declaration; however, in the presence - // of an initializer, we must emit that expression to preserve side effects. - var hasBindingElements = paramName.elements.length > 0; - if (hasBindingElements || initializer) { - writeLine(); - write("var "); - if (hasBindingElements) { - emitDestructuring(parameter, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]); - } - else { - emit(tempParameters[tempIndex]); - write(" = "); - emit(initializer); - } - write(";"); - tempIndex++; - } - } - else if (initializer) { - writeLine(); - emitStart(parameter); - write("if ("); - emitNodeWithoutSourceMap(paramName); - write(" === void 0)"); - emitEnd(parameter); - write(" { "); - emitStart(parameter); - emitNodeWithCommentsAndWithoutSourcemap(paramName); - write(" = "); - emitNodeWithCommentsAndWithoutSourcemap(initializer); - emitEnd(parameter); - write("; }"); - } - }); - } - } - function emitRestParameter(node) { - if (languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node)) { - var restIndex = node.parameters.length - 1; - var restParam = node.parameters[restIndex]; - // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. - if (ts.isBindingPattern(restParam.name)) { - return; - } - var tempName = createTempVariable(268435456 /* _i */).text; - writeLine(); - emitLeadingComments(restParam); - emitStart(restParam); - write("var "); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write(" = [];"); - emitEnd(restParam); - emitTrailingComments(restParam); - writeLine(); - write("for ("); - emitStart(restParam); - write("var " + tempName + " = " + restIndex + ";"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + " < arguments.length;"); - emitEnd(restParam); - write(" "); - emitStart(restParam); - write(tempName + "++"); - emitEnd(restParam); - write(") {"); - increaseIndent(); - writeLine(); - emitStart(restParam); - emitNodeWithCommentsAndWithoutSourcemap(restParam.name); - write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); - emitEnd(restParam); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitAccessor(node) { - write(node.kind === 143 /* GetAccessor */ ? "get " : "set "); - emit(node.name); - emitSignatureAndBody(node); - } - function shouldEmitAsArrowFunction(node) { - return node.kind === 172 /* ArrowFunction */ && languageVersion >= 2 /* ES6 */; - } - function emitDeclarationName(node) { - if (node.name) { - emitNodeWithCommentsAndWithoutSourcemap(node.name); - } - else { - write(getGeneratedNameForNode(node)); - } - } - function shouldEmitFunctionName(node) { - if (node.kind === 171 /* FunctionExpression */) { - // Emit name if one is present - return !!node.name; - } - if (node.kind === 211 /* FunctionDeclaration */) { - // Emit name if one is present, or emit generated name in down-level case (for export default case) - return !!node.name || languageVersion < 2 /* ES6 */; - } - } - function emitFunctionDeclaration(node) { - if (ts.nodeIsMissing(node.body)) { - return emitCommentsOnNotEmittedNode(node); - } - // TODO (yuisu) : we should not have special cases to condition emitting comments - // but have one place to fix check for these conditions. - if (node.kind !== 141 /* MethodDeclaration */ && node.kind !== 140 /* MethodSignature */ && - node.parent && node.parent.kind !== 243 /* PropertyAssignment */ && - node.parent.kind !== 166 /* CallExpression */) { - // 1. Methods will emit the comments as part of emitting method declaration - // 2. If the function is a property of object literal, emitting leading-comments - // is done by emitNodeWithoutSourceMap which then call this function. - // In particular, we would like to avoid emit comments twice in following case: - // For example: - // var obj = { - // id: - // /*comment*/ () => void - // } - // 3. If the function is an argument in call expression, emitting of comments will be - // taken care of in emit list of arguments inside of emitCallexpression - emitLeadingComments(node); - } - emitStart(node); - // For targeting below es6, emit functions-like declaration including arrow function using function keyword. - // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead - if (!shouldEmitAsArrowFunction(node)) { - if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024 /* Default */) { - write("default "); - } - } - write("function"); - if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { - write("*"); - } - write(" "); - } - if (shouldEmitFunctionName(node)) { - emitDeclarationName(node); - } - emitSignatureAndBody(node); - if (languageVersion < 2 /* ES6 */ && node.kind === 211 /* FunctionDeclaration */ && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - emitEnd(node); - if (node.kind !== 141 /* MethodDeclaration */ && node.kind !== 140 /* MethodSignature */) { - emitTrailingComments(node); - } - } - function emitCaptureThisForNodeIfNecessary(node) { - if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { - writeLine(); - emitStart(node); - write("var _this = this;"); - emitEnd(node); - } - } - function emitSignatureParameters(node) { - increaseIndent(); - write("("); - if (node) { - var parameters = node.parameters; - var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node) ? 1 : 0; - emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false); - } - write(")"); - decreaseIndent(); - } - function emitSignatureParametersForArrow(node) { - // Check whether the parameter list needs parentheses and preserve no-parenthesis - if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { - emit(node.parameters[0]); - return; - } - emitSignatureParameters(node); - } - function emitAsyncFunctionBodyForES6(node) { - var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); - var isArrowFunction = node.kind === 172 /* ArrowFunction */; - var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096 /* CaptureArguments */) !== 0; - var args; - // An async function is emit as an outer function that calls an inner - // generator function. To preserve lexical bindings, we pass the current - // `this` and `arguments` objects to `__awaiter`. The generator function - // passed to `__awaiter` is executed inside of the callback to the - // promise constructor. - // - // The emit for an async arrow without a lexical `arguments` binding might be: - // - // // input - // let a = async (b) => { await b; } - // - // // output - // let a = (b) => __awaiter(this, void 0, void 0, function* () { - // yield b; - // }); - // - // The emit for an async arrow with a lexical `arguments` binding might be: - // - // // input - // let a = async (b) => { await arguments[0]; } - // - // // output - // let a = (b) => __awaiter(this, arguments, void 0, function* (arguments) { - // yield arguments[0]; - // }); - // - // The emit for an async function expression without a lexical `arguments` binding - // might be: - // - // // input - // let a = async function (b) { - // await b; - // } - // - // // output - // let a = function (b) { - // return __awaiter(this, void 0, void 0, function* () { - // yield b; - // }); - // } - // - // The emit for an async function expression with a lexical `arguments` binding - // might be: - // - // // input - // let a = async function (b) { - // await arguments[0]; - // } - // - // // output - // let a = function (b) { - // return __awaiter(this, arguments, void 0, function* (_arguments) { - // yield _arguments[0]; - // }); - // } - // - // The emit for an async function expression with a lexical `arguments` binding - // and a return type annotation might be: - // - // // input - // let a = async function (b): MyPromise { - // await arguments[0]; - // } - // - // // output - // let a = function (b) { - // return __awaiter(this, arguments, MyPromise, function* (_arguments) { - // yield _arguments[0]; - // }); - // } - // - // If this is not an async arrow, emit the opening brace of the function body - // and the start of the return statement. - if (!isArrowFunction) { - write(" {"); - increaseIndent(); - writeLine(); - write("return"); - } - write(" __awaiter(this"); - if (hasLexicalArguments) { - write(", arguments"); - } - else { - write(", void 0"); - } - if (promiseConstructor) { - write(", "); - emitNodeWithoutSourceMap(promiseConstructor); - } - else { - write(", Promise"); - } - // Emit the call to __awaiter. - if (hasLexicalArguments) { - write(", function* (_arguments)"); - } - else { - write(", function* ()"); - } - // Emit the signature and body for the inner generator function. - emitFunctionBody(node); - write(")"); - // If this is not an async arrow, emit the closing brace of the outer function body. - if (!isArrowFunction) { - write(";"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function emitFunctionBody(node) { - if (!node.body) { - // There can be no body when there are parse errors. Just emit an empty block - // in that case. - write(" { }"); - } - else { - if (node.body.kind === 190 /* Block */) { - emitBlockFunctionBody(node, node.body); - } - else { - emitExpressionFunctionBody(node, node.body); - } - } - } - function emitSignatureAndBody(node) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - // When targeting ES6, emit arrow function natively in ES6 - if (shouldEmitAsArrowFunction(node)) { - emitSignatureParametersForArrow(node); - write(" =>"); - } - else { - emitSignatureParameters(node); - } - var isAsync = ts.isAsyncFunctionLike(node); - if (isAsync && languageVersion === 2 /* ES6 */) { - emitAsyncFunctionBodyForES6(node); - } - else { - emitFunctionBody(node); - } - if (!isES6ExportedDeclaration(node)) { - emitExportMemberAssignment(node); - } - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - // Returns true if any preamble code was emitted. - function emitFunctionBodyPreamble(node) { - emitCaptureThisForNodeIfNecessary(node); - emitDefaultValueAssignments(node); - emitRestParameter(node); - } - function emitExpressionFunctionBody(node, body) { - if (languageVersion < 2 /* ES6 */ || node.flags & 512 /* Async */) { - emitDownLevelExpressionFunctionBody(node, body); - return; - } - // For es6 and higher we can emit the expression as is. However, in the case - // where the expression might end up looking like a block when emitted, we'll - // also wrap it in parentheses first. For example if you have: a => {} - // then we need to generate: a => ({}) - write(" "); - // Unwrap all type assertions. - var current = body; - while (current.kind === 169 /* TypeAssertionExpression */) { - current = current.expression; - } - emitParenthesizedIf(body, current.kind === 163 /* ObjectLiteralExpression */); - } - function emitDownLevelExpressionFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - increaseIndent(); - var outPos = writer.getTextPos(); - emitDetachedComments(node.body); - emitFunctionBodyPreamble(node); - var preambleEmitted = writer.getTextPos() !== outPos; - decreaseIndent(); - // If we didn't have to emit any preamble code, then attempt to keep the arrow - // function on one line. - if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { - write(" "); - emitStart(body); - write("return "); - emit(body); - emitEnd(body); - write(";"); - emitTempDeclarations(/*newLine*/ false); - write(" "); - } - else { - increaseIndent(); - writeLine(); - emitLeadingComments(node.body); - write("return "); - emit(body); - write(";"); - emitTrailingComments(node.body); - emitTempDeclarations(/*newLine*/ true); - decreaseIndent(); - writeLine(); - } - emitStart(node.body); - write("}"); - emitEnd(node.body); - scopeEmitEnd(); - } - function emitBlockFunctionBody(node, body) { - write(" {"); - scopeEmitStart(node); - var initialTextPos = writer.getTextPos(); - increaseIndent(); - emitDetachedComments(body.statements); - // Emit all the directive prologues (like "use strict"). These have to come before - // any other preamble code we write (like parameter initializers). - var startIndex = emitDirectivePrologues(body.statements, /*startWithNewLine*/ true); - emitFunctionBodyPreamble(node); - decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== initialTextPos; - if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { - for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { - var statement = _b[_a]; - write(" "); - emit(statement); - } - emitTempDeclarations(/*newLine*/ false); - write(" "); - emitLeadingCommentsOfPosition(body.statements.end); - } - else { - increaseIndent(); - emitLinesStartingAt(body.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - writeLine(); - emitLeadingCommentsOfPosition(body.statements.end); - decreaseIndent(); - } - emitToken(16 /* CloseBraceToken */, body.statements.end); - scopeEmitEnd(); - } - function findInitialSuperCall(ctor) { - if (ctor.body) { - var statement = ctor.body.statements[0]; - if (statement && statement.kind === 193 /* ExpressionStatement */) { - var expr = statement.expression; - if (expr && expr.kind === 166 /* CallExpression */) { - var func = expr.expression; - if (func && func.kind === 93 /* SuperKeyword */) { - return statement; - } - } - } - } - } - function emitParameterPropertyAssignments(node) { - ts.forEach(node.parameters, function (param) { - if (param.flags & 112 /* AccessibilityModifier */) { - writeLine(); - emitStart(param); - emitStart(param.name); - write("this."); - emitNodeWithoutSourceMap(param.name); - emitEnd(param.name); - write(" = "); - emit(param.name); - write(";"); - emitEnd(param); - } - }); - } - function emitMemberAccessForPropertyName(memberName) { - // This does not emit source map because it is emitted by caller as caller - // is aware how the property name changes to the property access - // eg. public x = 10; becomes this.x and static x = 10 becomes className.x - if (memberName.kind === 9 /* StringLiteral */ || memberName.kind === 8 /* NumericLiteral */) { - write("["); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - write("]"); - } - else if (memberName.kind === 134 /* ComputedPropertyName */) { - emitComputedPropertyName(memberName); - } - else { - write("."); - emitNodeWithCommentsAndWithoutSourcemap(memberName); - } - } - function getInitializedProperties(node, isStatic) { - var properties = []; - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if (member.kind === 139 /* PropertyDeclaration */ && isStatic === ((member.flags & 128 /* Static */) !== 0) && member.initializer) { - properties.push(member); - } - } - return properties; - } - function emitPropertyDeclarations(node, properties) { - for (var _a = 0; _a < properties.length; _a++) { - var property = properties[_a]; - emitPropertyDeclaration(node, property); - } - } - function emitPropertyDeclaration(node, property, receiver, isExpression) { - writeLine(); - emitLeadingComments(property); - emitStart(property); - emitStart(property.name); - if (receiver) { - emit(receiver); - } - else { - if (property.flags & 128 /* Static */) { - emitDeclarationName(node); - } - else { - write("this"); - } - } - emitMemberAccessForPropertyName(property.name); - emitEnd(property.name); - write(" = "); - emit(property.initializer); - if (!isExpression) { - write(";"); - } - emitEnd(property); - emitTrailingComments(property); - } - function emitMemberFunctionsForES5AndLower(node) { - ts.forEach(node.members, function (member) { - if (member.kind === 189 /* SemicolonClassElement */) { - writeLine(); - write(";"); - } - else if (member.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */) { - if (!member.body) { - return emitCommentsOnNotEmittedNode(member); - } - writeLine(); - emitLeadingComments(member); - emitStart(member); - emitStart(member.name); - emitClassMemberPrefix(node, member); - emitMemberAccessForPropertyName(member.name); - emitEnd(member.name); - write(" = "); - emitFunctionDeclaration(member); - emitEnd(member); - write(";"); - emitTrailingComments(member); - } - else if (member.kind === 143 /* GetAccessor */ || member.kind === 144 /* SetAccessor */) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member === accessors.firstAccessor) { - writeLine(); - emitStart(member); - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(", {"); - increaseIndent(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - write("get: "); - emitStart(accessors.getAccessor); - write("function "); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - write(","); - } - if (accessors.setAccessor) { - writeLine(); - emitLeadingComments(accessors.setAccessor); - write("set: "); - emitStart(accessors.setAccessor); - write("function "); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor); - write(","); - } - writeLine(); - write("enumerable: true,"); - writeLine(); - write("configurable: true"); - decreaseIndent(); - writeLine(); - write("});"); - emitEnd(member); - } - } - }); - } - function emitMemberFunctionsForES6AndHigher(node) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - if ((member.kind === 141 /* MethodDeclaration */ || node.kind === 140 /* MethodSignature */) && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - else if (member.kind === 141 /* MethodDeclaration */ || - member.kind === 143 /* GetAccessor */ || - member.kind === 144 /* SetAccessor */) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - if (member.flags & 128 /* Static */) { - write("static "); - } - if (member.kind === 143 /* GetAccessor */) { - write("get "); - } - else if (member.kind === 144 /* SetAccessor */) { - write("set "); - } - if (member.asteriskToken) { - write("*"); - } - emit(member.name); - emitSignatureAndBody(member); - emitEnd(member); - emitTrailingComments(member); - } - else if (member.kind === 189 /* SemicolonClassElement */) { - writeLine(); - write(";"); - } - } - } - function emitConstructor(node, baseTypeElement) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - emitConstructorWorker(node, baseTypeElement); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } - function emitConstructorWorker(node, baseTypeElement) { - // Check if we have property assignment inside class declaration. - // If there is property assignment, we need to emit constructor whether users define it or not - // If there is no property assignment, we can omit constructor if users do not define it - var hasInstancePropertyWithInitializer = false; - // Emit the constructor overload pinned comments - ts.forEach(node.members, function (member) { - if (member.kind === 142 /* Constructor */ && !member.body) { - emitCommentsOnNotEmittedNode(member); - } - // Check if there is any non-static property assignment - if (member.kind === 139 /* PropertyDeclaration */ && member.initializer && (member.flags & 128 /* Static */) === 0) { - hasInstancePropertyWithInitializer = true; - } - }); - var ctor = ts.getFirstConstructorWithBody(node); - // For target ES6 and above, if there is no user-defined constructor and there is no property assignment - // do not emit constructor in class declaration. - if (languageVersion >= 2 /* ES6 */ && !ctor && !hasInstancePropertyWithInitializer) { - return; - } - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - if (languageVersion < 2 /* ES6 */) { - write("function "); - emitDeclarationName(node); - emitSignatureParameters(ctor); - } - else { - write("constructor"); - if (ctor) { - emitSignatureParameters(ctor); - } - else { - // Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation. - // If constructor is empty, then, - // If ClassHeritageopt is present, then - // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. - // Else, - // Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition - if (baseTypeElement) { - write("(...args)"); - } - else { - write("()"); - } - } - } - var startIndex = 0; - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - // Emit all the directive prologues (like "use strict"). These have to come before - // any other preamble code we write (like parameter initializers). - startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); - emitDetachedComments(ctor.body.statements); - } - emitCaptureThisForNodeIfNecessary(node); - var superCall; - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeElement) { - superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeElement) { - writeLine(); - emitStart(baseTypeElement); - if (languageVersion < 2 /* ES6 */) { - write("_super.apply(this, arguments);"); - } - else { - write("super(...args);"); - } - emitEnd(baseTypeElement); - } - } - emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ false)); - if (ctor) { - var statements = ctor.body.statements; - if (superCall) { - statements = statements.slice(1); - } - emitLinesStartingAt(statements, startIndex); - } - emitTempDeclarations(/*newLine*/ true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition(ctor.body.statements.end); - } - decreaseIndent(); - emitToken(16 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - } - function emitClassExpression(node) { - return emitClassLikeDeclaration(node); - } - function emitClassDeclaration(node) { - return emitClassLikeDeclaration(node); - } - function emitClassLikeDeclaration(node) { - if (languageVersion < 2 /* ES6 */) { - emitClassLikeDeclarationBelowES6(node); - } - else { - emitClassLikeDeclarationForES6AndHigher(node); - } - } - function emitClassLikeDeclarationForES6AndHigher(node) { - var thisNodeIsDecorated = ts.nodeIsDecorated(node); - if (node.kind === 212 /* ClassDeclaration */) { - if (thisNodeIsDecorated) { - // To preserve the correct runtime semantics when decorators are applied to the class, - // the emit needs to follow one of the following rules: - // - // * For a local class declaration: - // - // @dec class C { - // } - // - // The emit should be: - // - // let C = class { - // }; - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // C = __decorate([dec], C); - // - // * For an exported class declaration: - // - // @dec export class C { - // } - // - // The emit should be: - // - // export let C = class { - // }; - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // C = __decorate([dec], C); - // - // * For a default export of a class declaration with a name: - // - // @dec default export class C { - // } - // - // The emit should be: - // - // let C = class { - // } - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // C = __decorate([dec], C); - // export default C; - // - // * For a default export of a class declaration without a name: - // - // @dec default export class { - // } - // - // The emit should be: - // - // let _default = class { - // } - // _default = __decorate([dec], _default); - // export default _default; - // - if (isES6ExportedDeclaration(node) && !(node.flags & 1024 /* Default */)) { - write("export "); - } - write("let "); - emitDeclarationName(node); - write(" = "); - } - else if (isES6ExportedDeclaration(node)) { - write("export "); - if (node.flags & 1024 /* Default */) { - write("default "); - } - } - } - // If the class has static properties, and it's a class expression, then we'll need - // to specialize the emit a bit. for a class expression of the form: - // - // class C { static a = 1; static b = 2; ... } - // - // We'll emit: - // - // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) - // - // This keeps the expression as an expression, while ensuring that the static parts - // of it have been initialized by the time it is used. - var staticProperties = getInitializedProperties(node, /*static:*/ true); - var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 184 /* ClassExpression */; - var tempVariable; - if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0 /* Auto */); - write("("); - increaseIndent(); - emit(tempVariable); - write(" = "); - } - write("class"); - // check if this is an "export default class" as it may not have a name. Do not emit the name if the class is decorated. - if ((node.name || !(node.flags & 1024 /* Default */)) && !thisNodeIsDecorated) { - write(" "); - emitDeclarationName(node); - } - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write(" extends "); - emit(baseTypeNode.expression); - } - write(" {"); - increaseIndent(); - scopeEmitStart(node); - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES6AndHigher(node); - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. - // For a decorated class, we need to assign its name (if it has one). This is because we emit - // the class as a class expression to avoid the double-binding of the identifier: - // - // let C = class { - // } - // Object.defineProperty(C, "name", { value: "C", configurable: true }); - // - if (thisNodeIsDecorated) { - write(";"); - } - // Emit static property assignment. Because classDeclaration is lexically evaluated, - // it is safe to emit static property assignment after classDeclaration - // From ES6 specification: - // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using - // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. - if (isClassExpressionWithStaticProperties) { - for (var _a = 0; _a < staticProperties.length; _a++) { - var property = staticProperties[_a]; - write(","); - writeLine(); - emitPropertyDeclaration(node, property, /*receiver:*/ tempVariable, /*isExpression:*/ true); - } - write(","); - writeLine(); - emit(tempVariable); - decreaseIndent(); - write(")"); - } - else { - writeLine(); - emitPropertyDeclarations(node, staticProperties); - emitDecoratorsOfClass(node); - } - // If this is an exported class, but not on the top level (i.e. on an internal - // module), export it - if (!isES6ExportedDeclaration(node) && (node.flags & 1 /* Export */)) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emitDeclarationName(node); - emitEnd(node); - write(";"); - } - else if (isES6ExportedDeclaration(node) && (node.flags & 1024 /* Default */) && thisNodeIsDecorated) { - // if this is a top level default export of decorated class, write the export after the declaration. - writeLine(); - write("export default "); - emitDeclarationName(node); - write(";"); - } - } - function emitClassLikeDeclarationBelowES6(node) { - if (node.kind === 212 /* ClassDeclaration */) { - // source file level classes in system modules are hoisted so 'var's for them are already defined - if (!shouldHoistDeclarationInSystemJsModule(node)) { - write("var "); - } - emitDeclarationName(node); - write(" = "); - } - write("(function ("); - var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); - if (baseTypeNode) { - write("_super"); - } - write(") {"); - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; - tempFlags = 0; - tempVariables = undefined; - tempParameters = undefined; - computedPropertyNamesToGeneratedNames = undefined; - increaseIndent(); - scopeEmitStart(node); - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("__extends("); - emitDeclarationName(node); - write(", _super);"); - emitEnd(baseTypeNode); - } - writeLine(); - emitConstructor(node, baseTypeNode); - emitMemberFunctionsForES5AndLower(node); - emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ true)); - writeLine(); - emitDecoratorsOfClass(node); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end, function () { - write("return "); - emitDeclarationName(node); - }); - write(";"); - emitTempDeclarations(/*newLine*/ true); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - emitStart(node); - write(")("); - if (baseTypeNode) { - emit(baseTypeNode.expression); - } - write(")"); - if (node.kind === 212 /* ClassDeclaration */) { - write(";"); - } - emitEnd(node); - if (node.kind === 212 /* ClassDeclaration */) { - emitExportMemberAssignment(node); - } - if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile && node.name) { - emitExportMemberAssignments(node.name); - } - } - function emitClassMemberPrefix(node, member) { - emitDeclarationName(node); - if (!(member.flags & 128 /* Static */)) { - write(".prototype"); - } - } - function emitDecoratorsOfClass(node) { - emitDecoratorsOfMembers(node, /*staticFlag*/ 0); - emitDecoratorsOfMembers(node, 128 /* Static */); - emitDecoratorsOfConstructor(node); - } - function emitDecoratorsOfConstructor(node) { - var decorators = node.decorators; - var constructor = ts.getFirstConstructorWithBody(node); - var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); - // skip decoration of the constructor if neither it nor its parameters are decorated - if (!decorators && !hasDecoratedParameters) { - return; - } - // Emit the call to __decorate. Given the class: - // - // @dec - // class C { - // } - // - // The emit for the class is: - // - // C = __decorate([dec], C); - // - writeLine(); - emitStart(node); - emitDeclarationName(node); - write(" = __decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(constructor, /*leadingComma*/ argumentsWritten > 0); - emitSerializedTypeMetadata(node, /*leadingComma*/ argumentsWritten >= 0); - decreaseIndent(); - writeLine(); - write("], "); - emitDeclarationName(node); - write(");"); - emitEnd(node); - writeLine(); - } - function emitDecoratorsOfMembers(node, staticFlag) { - for (var _a = 0, _b = node.members; _a < _b.length; _a++) { - var member = _b[_a]; - // only emit members in the correct group - if ((member.flags & 128 /* Static */) !== staticFlag) { - continue; - } - // skip members that cannot be decorated (such as the constructor) - if (!ts.nodeCanBeDecorated(member)) { - continue; - } - // skip a member if it or any of its parameters are not decorated - if (!ts.nodeOrChildIsDecorated(member)) { - continue; - } - // skip an accessor declaration if it is not the first accessor - var decorators = void 0; - var functionLikeMember = void 0; - if (ts.isAccessor(member)) { - var accessors = ts.getAllAccessorDeclarations(node.members, member); - if (member !== accessors.firstAccessor) { - continue; - } - // get the decorators from the first accessor with decorators - decorators = accessors.firstAccessor.decorators; - if (!decorators && accessors.secondAccessor) { - decorators = accessors.secondAccessor.decorators; - } - // we only decorate parameters of the set accessor - functionLikeMember = accessors.setAccessor; - } - else { - decorators = member.decorators; - // we only decorate the parameters here if this is a method - if (member.kind === 141 /* MethodDeclaration */) { - functionLikeMember = member; - } - } - // Emit the call to __decorate. Given the following: - // - // class C { - // @dec method(@dec2 x) {} - // @dec get accessor() {} - // @dec prop; - // } - // - // The emit for a method is: - // - // Object.defineProperty(C.prototype, "method", - // __decorate([ - // dec, - // __param(0, dec2), - // __metadata("design:type", Function), - // __metadata("design:paramtypes", [Object]), - // __metadata("design:returntype", void 0) - // ], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); - // - // The emit for an accessor is: - // - // Object.defineProperty(C.prototype, "accessor", - // __decorate([ - // dec - // ], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); - // - // The emit for a property is: - // - // __decorate([ - // dec - // ], C.prototype, "prop"); - // - writeLine(); - emitStart(member); - if (member.kind !== 139 /* PropertyDeclaration */) { - write("Object.defineProperty("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write(","); - increaseIndent(); - writeLine(); - } - write("__decorate(["); - increaseIndent(); - writeLine(); - var decoratorCount = decorators ? decorators.length : 0; - var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { - emitStart(decorator); - emit(decorator.expression); - emitEnd(decorator); - }); - argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); - emitSerializedTypeMetadata(member, argumentsWritten > 0); - decreaseIndent(); - writeLine(); - write("], "); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - if (member.kind !== 139 /* PropertyDeclaration */) { - write(", Object.getOwnPropertyDescriptor("); - emitStart(member.name); - emitClassMemberPrefix(node, member); - write(", "); - emitExpressionForPropertyName(member.name); - emitEnd(member.name); - write("))"); - decreaseIndent(); - } - write(");"); - emitEnd(member); - writeLine(); - } - } - function emitDecoratorsOfParameters(node, leadingComma) { - var argumentsWritten = 0; - if (node) { - var parameterIndex = 0; - for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { - var parameter = _b[_a]; - if (ts.nodeIsDecorated(parameter)) { - var decorators = parameter.decorators; - argumentsWritten += emitList(decorators, 0, decorators.length, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ leadingComma, /*noTrailingNewLine*/ true, function (decorator) { - emitStart(decorator); - write("__param(" + parameterIndex + ", "); - emit(decorator.expression); - write(")"); - emitEnd(decorator); - }); - leadingComma = true; - } - ++parameterIndex; - } - } - return argumentsWritten; - } - function shouldEmitTypeMetadata(node) { - // This method determines whether to emit the "design:type" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata - // compiler option is set. - switch (node.kind) { - case 141 /* MethodDeclaration */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 139 /* PropertyDeclaration */: - return true; - } - return false; - } - function shouldEmitReturnTypeMetadata(node) { - // This method determines whether to emit the "design:returntype" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata - // compiler option is set. - switch (node.kind) { - case 141 /* MethodDeclaration */: - return true; - } - return false; - } - function shouldEmitParamTypesMetadata(node) { - // This method determines whether to emit the "design:paramtypes" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata - // compiler option is set. - switch (node.kind) { - case 212 /* ClassDeclaration */: - case 141 /* MethodDeclaration */: - case 144 /* SetAccessor */: - return true; - } - return false; - } - /** Serializes the type of a declaration to an appropriate JS constructor value. Used by the __metadata decorator for a class member. */ - function emitSerializedTypeOfNode(node) { - // serialization of the type of a declaration uses the following rules: - // - // * The serialized type of a ClassDeclaration is "Function" - // * The serialized type of a ParameterDeclaration is the serialized type of its type annotation. - // * The serialized type of a PropertyDeclaration is the serialized type of its type annotation. - // * The serialized type of an AccessorDeclaration is the serialized type of the return type annotation of its getter or parameter type annotation of its setter. - // * The serialized type of any other FunctionLikeDeclaration is "Function". - // * The serialized type of any other node is "void 0". - // - // For rules on serializing type annotations, see `serializeTypeNode`. - switch (node.kind) { - case 212 /* ClassDeclaration */: - write("Function"); - return; - case 139 /* PropertyDeclaration */: - emitSerializedTypeNode(node.type); - return; - case 136 /* Parameter */: - emitSerializedTypeNode(node.type); - return; - case 143 /* GetAccessor */: - emitSerializedTypeNode(node.type); - return; - case 144 /* SetAccessor */: - emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); - return; - } - if (ts.isFunctionLike(node)) { - write("Function"); - return; - } - write("void 0"); - } - function emitSerializedTypeNode(node) { - if (node) { - switch (node.kind) { - case 101 /* VoidKeyword */: - write("void 0"); - return; - case 158 /* ParenthesizedType */: - emitSerializedTypeNode(node.type); - return; - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - write("Function"); - return; - case 154 /* ArrayType */: - case 155 /* TupleType */: - write("Array"); - return; - case 148 /* TypePredicate */: - case 118 /* BooleanKeyword */: - write("Boolean"); - return; - case 128 /* StringKeyword */: - case 9 /* StringLiteral */: - write("String"); - return; - case 126 /* NumberKeyword */: - write("Number"); - return; - case 129 /* SymbolKeyword */: - write("Symbol"); - return; - case 149 /* TypeReference */: - emitSerializedTypeReferenceNode(node); - return; - case 152 /* TypeQuery */: - case 153 /* TypeLiteral */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: - case 115 /* AnyKeyword */: - break; - default: - ts.Debug.fail("Cannot serialize unexpected type node."); - break; - } - } - write("Object"); - } - /** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */ - function emitSerializedTypeReferenceNode(node) { - var location = node.parent; - while (ts.isDeclaration(location) || ts.isTypeNode(location)) { - location = location.parent; - } - // Clone the type name and parent it to a location outside of the current declaration. - var typeName = ts.cloneEntityName(node.typeName); - typeName.parent = location; - var result = resolver.getTypeReferenceSerializationKind(typeName); - switch (result) { - case ts.TypeReferenceSerializationKind.Unknown: - var temp = createAndRecordTempVariable(0 /* Auto */); - write("(typeof ("); - emitNodeWithoutSourceMap(temp); - write(" = "); - emitEntityNameAsExpression(typeName, /*useFallback*/ true); - write(") === 'function' && "); - emitNodeWithoutSourceMap(temp); - write(") || Object"); - break; - case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: - emitEntityNameAsExpression(typeName, /*useFallback*/ false); - break; - case ts.TypeReferenceSerializationKind.VoidType: - write("void 0"); - break; - case ts.TypeReferenceSerializationKind.BooleanType: - write("Boolean"); - break; - case ts.TypeReferenceSerializationKind.NumberLikeType: - write("Number"); - break; - case ts.TypeReferenceSerializationKind.StringLikeType: - write("String"); - break; - case ts.TypeReferenceSerializationKind.ArrayLikeType: - write("Array"); - break; - case ts.TypeReferenceSerializationKind.ESSymbolType: - if (languageVersion < 2 /* ES6 */) { - write("typeof Symbol === 'function' ? Symbol : Object"); - } - else { - write("Symbol"); - } - break; - case ts.TypeReferenceSerializationKind.TypeWithCallSignature: - write("Function"); - break; - case ts.TypeReferenceSerializationKind.ObjectType: - write("Object"); - break; - } - } - /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ - function emitSerializedParameterTypesOfNode(node) { - // serialization of parameter types uses the following rules: - // - // * If the declaration is a class, the parameters of the first constructor with a body are used. - // * If the declaration is function-like and has a body, the parameters of the function are used. - // - // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. - if (node) { - var valueDeclaration; - if (node.kind === 212 /* ClassDeclaration */) { - valueDeclaration = ts.getFirstConstructorWithBody(node); - } - else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { - valueDeclaration = node; - } - if (valueDeclaration) { - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; - if (parameterCount > 0) { - for (var i = 0; i < parameterCount; i++) { - if (i > 0) { - write(", "); - } - if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; - if (parameterType.kind === 154 /* ArrayType */) { - parameterType = parameterType.elementType; - } - else if (parameterType.kind === 149 /* TypeReference */ && parameterType.typeArguments && parameterType.typeArguments.length === 1) { - parameterType = parameterType.typeArguments[0]; - } - else { - parameterType = undefined; - } - emitSerializedTypeNode(parameterType); - } - else { - emitSerializedTypeOfNode(parameters[i]); - } - } - } - } - } - } - /** Serializes the return type of function. Used by the __metadata decorator for a method. */ - function emitSerializedReturnTypeOfNode(node) { - if (node && ts.isFunctionLike(node) && node.type) { - emitSerializedTypeNode(node.type); - return; - } - write("void 0"); - } - function emitSerializedTypeMetadata(node, writeComma) { - // This method emits the serialized type metadata for a decorator target. - // The caller should have already tested whether the node has decorators. - var argumentsWritten = 0; - if (compilerOptions.emitDecoratorMetadata) { - if (shouldEmitTypeMetadata(node)) { - if (writeComma) { - write(", "); - } - writeLine(); - write("__metadata('design:type', "); - emitSerializedTypeOfNode(node); - write(")"); - argumentsWritten++; - } - if (shouldEmitParamTypesMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:paramtypes', ["); - emitSerializedParameterTypesOfNode(node); - write("])"); - argumentsWritten++; - } - if (shouldEmitReturnTypeMetadata(node)) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:returntype', "); - emitSerializedReturnTypeOfNode(node); - write(")"); - argumentsWritten++; - } - } - return argumentsWritten; - } - function emitInterfaceDeclaration(node) { - emitCommentsOnNotEmittedNode(node); - } - function shouldEmitEnumDeclaration(node) { - var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; - } - function emitEnumDeclaration(node) { - // const enums are completely erased during compilation. - if (!shouldEmitEnumDeclaration(node)) { - return; - } - if (!shouldHoistDeclarationInSystemJsModule(node)) { - // do not emit var if variable was already hoisted - if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - emitEnd(node); - write(";"); - } - } - writeLine(); - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") {"); - increaseIndent(); - scopeEmitStart(node); - emitLines(node.members); - decreaseIndent(); - writeLine(); - emitToken(16 /* CloseBraceToken */, node.members.end); - scopeEmitEnd(); - write(")("); - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */ && !shouldHoistDeclarationInSystemJsModule(node)) { - // do not emit var if variable was already hoisted - writeLine(); - emitStart(node); - write("var "); - emit(node.name); - write(" = "); - emitModuleMemberName(node); - emitEnd(node); - write(";"); - } - if (languageVersion < 2 /* ES6 */ && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 /* System */ && (node.flags & 1 /* Export */)) { - // write the call to exporter for enum - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - function emitEnumMember(node) { - var enumParent = node.parent; - emitStart(node); - write(getGeneratedNameForNode(enumParent)); - write("["); - write(getGeneratedNameForNode(enumParent)); - write("["); - emitExpressionForPropertyName(node.name); - write("] = "); - writeEnumMemberDeclarationValue(node); - write("] = "); - emitExpressionForPropertyName(node.name); - emitEnd(node); - write(";"); - } - function writeEnumMemberDeclarationValue(member) { - var value = resolver.getConstantValue(member); - if (value !== undefined) { - write(value.toString()); - return; - } - else if (member.initializer) { - emit(member.initializer); - } - else { - write("undefined"); - } - } - function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 216 /* ModuleDeclaration */) { - var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); - return recursiveInnerModule || moduleDeclaration.body; - } - } - function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); - } - function isModuleMergedWithES6Class(node) { - return languageVersion === 2 /* ES6 */ && !!(resolver.getNodeCheckFlags(node) & 32768 /* LexicalModuleMergesWithClass */); - } - function emitModuleDeclaration(node) { - // Emit only if this module is non-ambient. - var shouldEmit = shouldEmitModuleDeclaration(node); - if (!shouldEmit) { - return emitCommentsOnNotEmittedNode(node); - } - var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); - var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); - if (emitVarForModule) { - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - } - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); - } - emitStart(node); - write("(function ("); - emitStart(node.name); - write(getGeneratedNameForNode(node)); - emitEnd(node.name); - write(") "); - if (node.body.kind === 217 /* ModuleBlock */) { - var saveTempFlags = tempFlags; - var saveTempVariables = tempVariables; - tempFlags = 0; - tempVariables = undefined; - emit(node.body); - tempFlags = saveTempFlags; - tempVariables = saveTempVariables; - } - else { - write("{"); - increaseIndent(); - scopeEmitStart(node); - emitCaptureThisForNodeIfNecessary(node); - writeLine(); - emit(node.body); - decreaseIndent(); - writeLine(); - var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; - emitToken(16 /* CloseBraceToken */, moduleBlock.statements.end); - scopeEmitEnd(); - } - write(")("); - // write moduleDecl = containingModule.m only if it is not exported es6 module member - if ((node.flags & 1 /* Export */) && !isES6ExportedDeclaration(node)) { - emit(node.name); - write(" = "); - } - emitModuleMemberName(node); - write(" || ("); - emitModuleMemberName(node); - write(" = {}));"); - emitEnd(node); - if (!isES6ExportedDeclaration(node) && node.name.kind === 67 /* Identifier */ && node.parent === currentSourceFile) { - if (compilerOptions.module === 4 /* System */ && (node.flags & 1 /* Export */)) { - writeLine(); - write(exportFunctionForFile + "(\""); - emitDeclarationName(node); - write("\", "); - emitDeclarationName(node); - write(");"); - } - emitExportMemberAssignments(node.name); - } - } - /* - * Some bundlers (SystemJS builder) sometimes want to rename dependencies. - * Here we check if alternative name was provided for a given moduleName and return it if possible. - */ - function tryRenameExternalModule(moduleName) { - if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { - return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; - } - return undefined; - } - function emitRequire(moduleName) { - if (moduleName.kind === 9 /* StringLiteral */) { - write("require("); - var text = tryRenameExternalModule(moduleName); - if (text) { - write(text); - } - else { - emitStart(moduleName); - emitLiteral(moduleName); - emitEnd(moduleName); - } - emitToken(18 /* CloseParenToken */, moduleName.end); - } - else { - write("require()"); - } - } - function getNamespaceDeclarationNode(node) { - if (node.kind === 219 /* ImportEqualsDeclaration */) { - return node; - } - var importClause = node.importClause; - if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 222 /* NamespaceImport */) { - return importClause.namedBindings; - } - } - function isDefaultImport(node) { - return node.kind === 220 /* ImportDeclaration */ && node.importClause && !!node.importClause.name; - } - function emitExportImportAssignments(node) { - if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - emitExportMemberAssignments(node.name); - } - ts.forEachChild(node, emitExportImportAssignments); - } - function emitImportDeclaration(node) { - if (languageVersion < 2 /* ES6 */) { - return emitExternalImportDeclaration(node); - } - // ES6 import - if (node.importClause) { - var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); - var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, /* checkChildren */ true); - if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { - write("import "); - emitStart(node.importClause); - if (shouldEmitDefaultBindings) { - emit(node.importClause.name); - if (shouldEmitNamedBindings) { - write(", "); - } - } - if (shouldEmitNamedBindings) { - emitLeadingComments(node.importClause.namedBindings); - emitStart(node.importClause.namedBindings); - if (node.importClause.namedBindings.kind === 222 /* NamespaceImport */) { - write("* as "); - emit(node.importClause.namedBindings.name); - } - else { - write("{ "); - emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); - write(" }"); - } - emitEnd(node.importClause.namedBindings); - emitTrailingComments(node.importClause.namedBindings); - } - emitEnd(node.importClause); - write(" from "); - emit(node.moduleSpecifier); - write(";"); - } - } - else { - write("import "); - emit(node.moduleSpecifier); - write(";"); - } - } - function emitExternalImportDeclaration(node) { - if (ts.contains(externalImports, node)) { - var isExportedImport = node.kind === 219 /* ImportEqualsDeclaration */ && (node.flags & 1 /* Export */) !== 0; - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (compilerOptions.module !== 2 /* AMD */) { - emitLeadingComments(node); - emitStart(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - // import x = require("foo") - // import * as x from "foo" - if (!isExportedImport) - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - } - else { - // import "foo" - // import x from "foo" - // import { x, y } from "foo" - // import d, * as x from "foo" - // import d, { x, y } from "foo" - var isNakedImport = 220 /* ImportDeclaration */ && !node.importClause; - if (!isNakedImport) { - write("var "); - write(getGeneratedNameForNode(node)); - write(" = "); - } - } - emitRequire(ts.getExternalModuleName(node)); - if (namespaceDeclaration && isDefaultImport(node)) { - // import d, * as x from "foo" - write(", "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - else { - if (isExportedImport) { - emitModuleMemberName(namespaceDeclaration); - write(" = "); - emit(namespaceDeclaration.name); - write(";"); - } - else if (namespaceDeclaration && isDefaultImport(node)) { - // import d, * as x from "foo" - write("var "); - emitModuleMemberName(namespaceDeclaration); - write(" = "); - write(getGeneratedNameForNode(node)); - write(";"); - } - emitExportImportAssignments(node); - } - } - } - function emitImportEqualsDeclaration(node) { - if (ts.isExternalModuleImportEqualsDeclaration(node)) { - emitExternalImportDeclaration(node); - return; - } - // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when - // - current file is not external module - // - import declaration is top level and target is value imported by entity name - if (resolver.isReferencedAliasDeclaration(node) || - (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { - emitLeadingComments(node); - emitStart(node); - // variable declaration for import-equals declaration can be hoisted in system modules - // in this case 'var' should be omitted and emit should contain only initialization - var variableDeclarationIsHoisted = shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ true); - // is it top level export import v = a.b.c in system module? - // if yes - it needs to be rewritten as exporter('v', v = a.b.c) - var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ true); - if (!variableDeclarationIsHoisted) { - ts.Debug.assert(!isExported); - if (isES6ExportedDeclaration(node)) { - write("export "); - write("var "); - } - else if (!(node.flags & 1 /* Export */)) { - write("var "); - } - } - if (isExported) { - write(exportFunctionForFile + "(\""); - emitNodeWithoutSourceMap(node.name); - write("\", "); - } - emitModuleMemberName(node); - write(" = "); - emit(node.moduleReference); - if (isExported) { - write(")"); - } - write(";"); - emitEnd(node); - emitExportImportAssignments(node); - emitTrailingComments(node); - } - } - function emitExportDeclaration(node) { - ts.Debug.assert(compilerOptions.module !== 4 /* System */); - if (languageVersion < 2 /* ES6 */) { - if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { - emitStart(node); - var generatedName = getGeneratedNameForNode(node); - if (node.exportClause) { - // export { x, y, ... } from "foo" - if (compilerOptions.module !== 2 /* AMD */) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(ts.getExternalModuleName(node)); - write(";"); - } - for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { - var specifier = _b[_a]; - if (resolver.isValueAliasDeclaration(specifier)) { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - } - } - } - else { - // export * from "foo" - writeLine(); - write("__export("); - if (compilerOptions.module !== 2 /* AMD */) { - emitRequire(ts.getExternalModuleName(node)); - } - else { - write(generatedName); - } - write(");"); - } - emitEnd(node); - } - } - else { - if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { - write("export "); - if (node.exportClause) { - // export { x, y, ... } - write("{ "); - emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); - write(" }"); - } - else { - write("*"); - } - if (node.moduleSpecifier) { - write(" from "); - emit(node.moduleSpecifier); - } - write(";"); - } - } - } - function emitExportOrImportSpecifierList(specifiers, shouldEmit) { - ts.Debug.assert(languageVersion >= 2 /* ES6 */); - var needsComma = false; - for (var _a = 0; _a < specifiers.length; _a++) { - var specifier = specifiers[_a]; - if (shouldEmit(specifier)) { - if (needsComma) { - write(", "); - } - if (specifier.propertyName) { - emit(specifier.propertyName); - write(" as "); - } - emit(specifier.name); - needsComma = true; - } - } - } - function emitExportAssignment(node) { - if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - if (languageVersion >= 2 /* ES6 */) { - writeLine(); - emitStart(node); - write("export default "); - var expression = node.expression; - emit(expression); - if (expression.kind !== 211 /* FunctionDeclaration */ && - expression.kind !== 212 /* ClassDeclaration */) { - write(";"); - } - emitEnd(node); - } - else { - writeLine(); - emitStart(node); - if (compilerOptions.module === 4 /* System */) { - write(exportFunctionForFile + "(\"default\","); - emit(node.expression); - write(")"); - } - else { - emitEs6ExportDefaultCompat(node); - emitContainingModuleName(node); - if (languageVersion === 0 /* ES3 */) { - write("[\"default\"] = "); - } - else { - write(".default = "); - } - emit(node.expression); - } - write(";"); - emitEnd(node); - } - } - } - function collectExternalModuleInfo(sourceFile) { - externalImports = []; - exportSpecifiers = {}; - exportEquals = undefined; - hasExportStars = false; - for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { - var node = _b[_a]; - switch (node.kind) { - case 220 /* ImportDeclaration */: - if (!node.importClause || - resolver.isReferencedAliasDeclaration(node.importClause, /*checkChildren*/ true)) { - // import "mod" - // import x from "mod" where x is referenced - // import * as x from "mod" where x is referenced - // import { x, y } from "mod" where at least one import is referenced - externalImports.push(node); - } - break; - case 219 /* ImportEqualsDeclaration */: - if (node.moduleReference.kind === 230 /* ExternalModuleReference */ && resolver.isReferencedAliasDeclaration(node)) { - // import x = require("mod") where x is referenced - externalImports.push(node); - } - break; - case 226 /* ExportDeclaration */: - if (node.moduleSpecifier) { - if (!node.exportClause) { - // export * from "mod" - externalImports.push(node); - hasExportStars = true; - } - else if (resolver.isValueAliasDeclaration(node)) { - // export { x, y } from "mod" where at least one export is a value symbol - externalImports.push(node); - } - } - else { - // export { x, y } - for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { - var specifier = _d[_c]; - var name_24 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_24] || (exportSpecifiers[name_24] = [])).push(specifier); - } - } - break; - case 225 /* ExportAssignment */: - if (node.isExportEquals && !exportEquals) { - // export = x - exportEquals = node; - } - break; - } - } - } - function emitExportStarHelper() { - if (hasExportStars) { - writeLine(); - write("function __export(m) {"); - increaseIndent(); - writeLine(); - write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); - decreaseIndent(); - writeLine(); - write("}"); - } - } - function getLocalNameForExternalImport(node) { - var namespaceDeclaration = getNamespaceDeclarationNode(node); - if (namespaceDeclaration && !isDefaultImport(node)) { - return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); - } - if (node.kind === 220 /* ImportDeclaration */ && node.importClause) { - return getGeneratedNameForNode(node); - } - if (node.kind === 226 /* ExportDeclaration */ && node.moduleSpecifier) { - return getGeneratedNameForNode(node); - } - } - function getExternalModuleNameText(importNode) { - var moduleName = ts.getExternalModuleName(importNode); - if (moduleName.kind === 9 /* StringLiteral */) { - return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); - } - return undefined; - } - function emitVariableDeclarationsForImports() { - if (externalImports.length === 0) { - return; - } - writeLine(); - var started = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var importNode = externalImports[_a]; - // do not create variable declaration for exports and imports that lack import clause - var skipNode = importNode.kind === 226 /* ExportDeclaration */ || - (importNode.kind === 220 /* ImportDeclaration */ && !importNode.importClause); - if (skipNode) { - continue; - } - if (!started) { - write("var "); - started = true; - } - else { - write(", "); - } - write(getLocalNameForExternalImport(importNode)); - } - if (started) { - write(";"); - } - } - function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { - // when resolving exports local exported entries/indirect exported entries in the module - // should always win over entries with similar names that were added via star exports - // to support this we store names of local/indirect exported entries in a set. - // this set is used to filter names brought by star expors. - if (!hasExportStars) { - // local names set is needed only in presence of star exports - return undefined; - } - // local names set should only be added if we have anything exported - if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { - // no exported declarations (export var ...) or export specifiers (export {x}) - // check if we have any non star export declarations. - var hasExportDeclarationWithExportClause = false; - for (var _a = 0; _a < externalImports.length; _a++) { - var externalImport = externalImports[_a]; - if (externalImport.kind === 226 /* ExportDeclaration */ && externalImport.exportClause) { - hasExportDeclarationWithExportClause = true; - break; - } - } - if (!hasExportDeclarationWithExportClause) { - // we still need to emit exportStar helper - return emitExportStarFunction(/*localNames*/ undefined); - } - } - var exportedNamesStorageRef = makeUniqueName("exportedNames"); - writeLine(); - write("var " + exportedNamesStorageRef + " = {"); - increaseIndent(); - var started = false; - if (exportedDeclarations) { - for (var i = 0; i < exportedDeclarations.length; ++i) { - // write name of exported declaration, i.e 'export var x...' - writeExportedName(exportedDeclarations[i]); - } - } - if (exportSpecifiers) { - for (var n in exportSpecifiers) { - for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { - var specifier = _c[_b]; - // write name of export specified, i.e. 'export {x}' - writeExportedName(specifier.name); - } - } - } - for (var _d = 0; _d < externalImports.length; _d++) { - var externalImport = externalImports[_d]; - if (externalImport.kind !== 226 /* ExportDeclaration */) { - continue; - } - var exportDecl = externalImport; - if (!exportDecl.exportClause) { - // export * from ... - continue; - } - for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { - var element = _f[_e]; - // write name of indirectly exported entry, i.e. 'export {x} from ...' - writeExportedName(element.name || element.propertyName); - } - } - decreaseIndent(); - writeLine(); - write("};"); - return emitExportStarFunction(exportedNamesStorageRef); - function emitExportStarFunction(localNames) { - var exportStarFunction = makeUniqueName("exportStar"); - writeLine(); - // define an export star helper function - write("function " + exportStarFunction + "(m) {"); - increaseIndent(); - writeLine(); - write("var exports = {};"); - writeLine(); - write("for(var n in m) {"); - increaseIndent(); - writeLine(); - write("if (n !== \"default\""); - if (localNames) { - write("&& !" + localNames + ".hasOwnProperty(n)"); - } - write(") exports[n] = m[n];"); - decreaseIndent(); - writeLine(); - write("}"); - writeLine(); - write(exportFunctionForFile + "(exports);"); - decreaseIndent(); - writeLine(); - write("}"); - return exportStarFunction; - } - function writeExportedName(node) { - // do not record default exports - // they are local to module and never overwritten (explicitly skipped) by star export - if (node.kind !== 67 /* Identifier */ && node.flags & 1024 /* Default */) { - return; - } - if (started) { - write(","); - } - else { - started = true; - } - writeLine(); - write("'"); - if (node.kind === 67 /* Identifier */) { - emitNodeWithCommentsAndWithoutSourcemap(node); - } - else { - emitDeclarationName(node); - } - write("': true"); - } - } - function processTopLevelVariableAndFunctionDeclarations(node) { - // per ES6 spec: - // 15.2.1.16.4 ModuleDeclarationInstantiation() Concrete Method - // - var declarations are initialized to undefined - 14.a.ii - // - function/generator declarations are instantiated - 16.a.iv - // this means that after module is instantiated but before its evaluation - // exported functions are already accessible at import sites - // in theory we should hoist only exported functions and its dependencies - // in practice to simplify things we'll hoist all source level functions and variable declaration - // including variables declarations for module and class declarations - var hoistedVars; - var hoistedFunctionDeclarations; - var exportedDeclarations; - visit(node); - if (hoistedVars) { - writeLine(); - write("var "); - var seen = {}; - for (var i = 0; i < hoistedVars.length; ++i) { - var local = hoistedVars[i]; - var name_25 = local.kind === 67 /* Identifier */ - ? local - : local.name; - if (name_25) { - // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_25.text); - if (ts.hasProperty(seen, text)) { - continue; - } - else { - seen[text] = text; - } - } - if (i !== 0) { - write(", "); - } - if (local.kind === 212 /* ClassDeclaration */ || local.kind === 216 /* ModuleDeclaration */ || local.kind === 215 /* EnumDeclaration */) { - emitDeclarationName(local); - } - else { - emit(local); - } - var flags = ts.getCombinedNodeFlags(local.kind === 67 /* Identifier */ ? local.parent : local); - if (flags & 1 /* Export */) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(local); - } - } - write(";"); - } - if (hoistedFunctionDeclarations) { - for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { - var f = hoistedFunctionDeclarations[_a]; - writeLine(); - emit(f); - if (f.flags & 1 /* Export */) { - if (!exportedDeclarations) { - exportedDeclarations = []; - } - exportedDeclarations.push(f); - } - } - } - return exportedDeclarations; - function visit(node) { - if (node.flags & 2 /* Ambient */) { - return; - } - if (node.kind === 211 /* FunctionDeclaration */) { - if (!hoistedFunctionDeclarations) { - hoistedFunctionDeclarations = []; - } - hoistedFunctionDeclarations.push(node); - return; - } - if (node.kind === 212 /* ClassDeclaration */) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - return; - } - if (node.kind === 215 /* EnumDeclaration */) { - if (shouldEmitEnumDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 216 /* ModuleDeclaration */) { - if (shouldEmitModuleDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node); - } - return; - } - if (node.kind === 209 /* VariableDeclaration */ || node.kind === 161 /* BindingElement */) { - if (shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ false)) { - var name_26 = node.name; - if (name_26.kind === 67 /* Identifier */) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(name_26); - } - else { - ts.forEachChild(name_26, visit); - } - } - return; - } - if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { - if (!hoistedVars) { - hoistedVars = []; - } - hoistedVars.push(node.name); - return; - } - if (ts.isBindingPattern(node)) { - ts.forEach(node.elements, visit); - return; - } - if (!ts.isDeclaration(node)) { - ts.forEachChild(node, visit); - } - } - } - function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { - if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { - return false; - } - // hoist variable if - // - it is not block scoped - // - it is top level block scoped - // if block scoped variables are nested in some another block then - // no other functions can use them except ones that are defined at least in the same block - return (ts.getCombinedNodeFlags(node) & 49152 /* BlockScoped */) === 0 || - ts.getEnclosingBlockScopeContainer(node).kind === 246 /* SourceFile */; - } - function isCurrentFileSystemExternalModule() { - return compilerOptions.module === 4 /* System */ && ts.isExternalModule(currentSourceFile); - } - function emitSystemModuleBody(node, dependencyGroups, startIndex) { - // shape of the body in system modules: - // function (exports) { - // - // - // - // return { - // setters: [ - // - // ], - // execute: function() { - // - // } - // } - // - // } - // I.e: - // import {x} from 'file1' - // var y = 1; - // export function foo() { return y + x(); } - // console.log(y); - // will be transformed to - // function(exports) { - // var file1; // local alias - // var y; - // function foo() { return y + file1.x(); } - // exports("foo", foo); - // return { - // setters: [ - // function(v) { file1 = v } - // ], - // execute(): function() { - // y = 1; - // console.log(y); - // } - // }; - // } - emitVariableDeclarationsForImports(); - writeLine(); - var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); - var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); - writeLine(); - write("return {"); - increaseIndent(); - writeLine(); - emitSetters(exportStarFunction, dependencyGroups); - writeLine(); - emitExecute(node, startIndex); - decreaseIndent(); - writeLine(); - write("}"); // return - emitTempDeclarations(/*newLine*/ true); - } - function emitSetters(exportStarFunction, dependencyGroups) { - write("setters:["); - for (var i = 0; i < dependencyGroups.length; ++i) { - if (i !== 0) { - write(","); - } - writeLine(); - increaseIndent(); - var group = dependencyGroups[i]; - // derive a unique name for parameter from the first named entry in the group - var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); - write("function (" + parameterName + ") {"); - increaseIndent(); - for (var _a = 0; _a < group.length; _a++) { - var entry = group[_a]; - var importVariableName = getLocalNameForExternalImport(entry) || ""; - switch (entry.kind) { - case 220 /* ImportDeclaration */: - if (!entry.importClause) { - // 'import "..."' case - // module is imported only for side-effects, no emit required - break; - } - // fall-through - case 219 /* ImportEqualsDeclaration */: - ts.Debug.assert(importVariableName !== ""); - writeLine(); - // save import into the local - write(importVariableName + " = " + parameterName + ";"); - writeLine(); - break; - case 226 /* ExportDeclaration */: - ts.Debug.assert(importVariableName !== ""); - if (entry.exportClause) { - // export {a, b as c} from 'foo' - // emit as: - // exports_({ - // "a": _["a"], - // "c": _["b"] - // }); - writeLine(); - write(exportFunctionForFile + "({"); - writeLine(); - increaseIndent(); - for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { - if (i_2 !== 0) { - write(","); - writeLine(); - } - var e = entry.exportClause.elements[i_2]; - write("\""); - emitNodeWithCommentsAndWithoutSourcemap(e.name); - write("\": " + parameterName + "[\""); - emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); - write("\"]"); - } - decreaseIndent(); - writeLine(); - write("});"); - } - else { - writeLine(); - // export * from 'foo' - // emit as: - // exportStar(_foo); - write(exportStarFunction + "(" + parameterName + ");"); - } - writeLine(); - break; - } - } - decreaseIndent(); - write("}"); - decreaseIndent(); - } - write("],"); - } - function emitExecute(node, startIndex) { - write("execute: function() {"); - increaseIndent(); - writeLine(); - for (var i = startIndex; i < node.statements.length; ++i) { - var statement = node.statements[i]; - switch (statement.kind) { - // - function declarations are not emitted because they were already hoisted - // - import declarations are not emitted since they are already handled in setters - // - export declarations with module specifiers are not emitted since they were already written in setters - // - export declarations without module specifiers are emitted preserving the order - case 211 /* FunctionDeclaration */: - case 220 /* ImportDeclaration */: - continue; - case 226 /* ExportDeclaration */: - if (!statement.moduleSpecifier) { - for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { - var element = _b[_a]; - // write call to exporter function for every export specifier in exports list - emitExportSpecifierInSystemModule(element); - } - } - continue; - case 219 /* ImportEqualsDeclaration */: - if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { - // - import equals declarations that import external modules are not emitted - continue; - } - // fall-though for import declarations that import internal modules - default: - writeLine(); - emit(statement); - } - } - decreaseIndent(); - writeLine(); - write("}"); // execute - } - function emitSystemModule(node, startIndex) { - collectExternalModuleInfo(node); - // System modules has the following shape - // System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */}) - // 'exports' here is a function 'exports(name: string, value: T): T' that is used to publish exported values. - // 'exports' returns its 'value' argument so in most cases expressions - // that mutate exported values can be rewritten as: - // expr -> exports('name', expr). - // The only exception in this rule is postfix unary operators, - // see comment to 'emitPostfixUnaryExpression' for more details - ts.Debug.assert(!exportFunctionForFile); - // make sure that name of 'exports' function does not conflict with existing identifiers - exportFunctionForFile = makeUniqueName("exports"); - writeLine(); - write("System.register("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - write("["); - var groupIndices = {}; - var dependencyGroups = []; - for (var i = 0; i < externalImports.length; ++i) { - var text = getExternalModuleNameText(externalImports[i]); - if (ts.hasProperty(groupIndices, text)) { - // deduplicate/group entries in dependency list by the dependency name - var groupIndex = groupIndices[text]; - dependencyGroups[groupIndex].push(externalImports[i]); - continue; - } - else { - groupIndices[text] = dependencyGroups.length; - dependencyGroups.push([externalImports[i]]); - } - if (i !== 0) { - write(", "); - } - write(text); - } - write("], function(" + exportFunctionForFile + ") {"); - writeLine(); - increaseIndent(); - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitSystemModuleBody(node, dependencyGroups, startIndex); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitAMDDependencies(node, includeNonAmdDependencies) { - // An AMD define function has the following shape: - // define(id?, dependencies?, factory); - // - // This has the shape of - // define(name, ["module1", "module2"], function (module1Alias) { - // The location of the alias in the parameter list in the factory function needs to - // match the position of the module name in the dependency list. - // - // To ensure this is true in cases of modules with no aliases, e.g.: - // `import "module"` or `` - // we need to add modules without alias names to the end of the dependencies list - // names of modules with corresponding parameter in the factory function - var aliasedModuleNames = []; - // names of modules with no corresponding parameters in factory function - var unaliasedModuleNames = []; - var importAliasNames = []; // names of the parameters in the factory function; these - // parameters need to match the indexes of the corresponding - // module names in aliasedModuleNames. - // Fill in amd-dependency tags - for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { - var amdDependency = _b[_a]; - if (amdDependency.name) { - aliasedModuleNames.push("\"" + amdDependency.path + "\""); - importAliasNames.push(amdDependency.name); - } - else { - unaliasedModuleNames.push("\"" + amdDependency.path + "\""); - } - } - for (var _c = 0; _c < externalImports.length; _c++) { - var importNode = externalImports[_c]; - // Find the name of the external module - var externalModuleName = getExternalModuleNameText(importNode); - // Find the name of the module alias, if there is one - var importAliasName = getLocalNameForExternalImport(importNode); - if (includeNonAmdDependencies && importAliasName) { - aliasedModuleNames.push(externalModuleName); - importAliasNames.push(importAliasName); - } - else { - unaliasedModuleNames.push(externalModuleName); - } - } - write("[\"require\", \"exports\""); - if (aliasedModuleNames.length) { - write(", "); - write(aliasedModuleNames.join(", ")); - } - if (unaliasedModuleNames.length) { - write(", "); - write(unaliasedModuleNames.join(", ")); - } - write("], function (require, exports"); - if (importAliasNames.length) { - write(", "); - write(importAliasNames.join(", ")); - } - } - function emitAMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - writeLine(); - write("define("); - if (node.moduleName) { - write("\"" + node.moduleName + "\", "); - } - emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - emitExportEquals(/*emitAsReturn*/ true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitCommonJSModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - emitExportEquals(/*emitAsReturn*/ false); - } - function emitUMDModule(node, startIndex) { - emitEmitHelpers(node); - collectExternalModuleInfo(node); - // Module is detected first to support Browserify users that load into a browser with an AMD loader - writeLines("(function (deps, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define(deps, factory);\n }\n})("); - emitAMDDependencies(node, false); - write(") {"); - increaseIndent(); - emitExportStarHelper(); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - emitExportEquals(/*emitAsReturn*/ true); - decreaseIndent(); - writeLine(); - write("});"); - } - function emitES6Module(node, startIndex) { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - // Emit exportDefault if it exists will happen as part - // or normal statement emit. - } - function emitExportEquals(emitAsReturn) { - if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { - writeLine(); - emitStart(exportEquals); - write(emitAsReturn ? "return " : "module.exports = "); - emit(exportEquals.expression); - write(";"); - emitEnd(exportEquals); - } - } - function emitJsxElement(node) { - switch (compilerOptions.jsx) { - case 2 /* React */: - jsxEmitReact(node); - break; - case 1 /* Preserve */: - // Fall back to preserve if None was specified (we'll error earlier) - default: - jsxEmitPreserve(node); - break; - } - } - function trimReactWhitespaceAndApplyEntities(node) { - var result = undefined; - var text = ts.getTextOfNode(node, /*includeTrivia*/ true); - var firstNonWhitespace = 0; - var lastNonWhitespace = -1; - // JSX trims whitespace at the end and beginning of lines, except that the - // start/end of a tag is considered a start/end of a line only if that line is - // on the same line as the closing tag. See examples in tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx - for (var i = 0; i < text.length; i++) { - var c = text.charCodeAt(i); - if (ts.isLineBreak(c)) { - if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { - var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - firstNonWhitespace = -1; - } - else if (!ts.isWhiteSpace(c)) { - lastNonWhitespace = i; - if (firstNonWhitespace === -1) { - firstNonWhitespace = i; - } - } - } - if (firstNonWhitespace !== -1) { - var part = text.substr(firstNonWhitespace); - result = (result ? result + "\" + ' ' + \"" : "") + part; - } - if (result) { - // Replace entities like   - result = result.replace(/&(\w+);/g, function (s, m) { - if (entities[m] !== undefined) { - return String.fromCharCode(entities[m]); - } - else { - return s; - } - }); - } - return result; - } - function getTextToEmit(node) { - switch (compilerOptions.jsx) { - case 2 /* React */: - var text = trimReactWhitespaceAndApplyEntities(node); - if (text === undefined || text.length === 0) { - return undefined; - } - else { - return text; - } - case 1 /* Preserve */: - default: - return ts.getTextOfNode(node, /*includeTrivia*/ true); - } - } - function emitJsxText(node) { - switch (compilerOptions.jsx) { - case 2 /* React */: - write("\""); - write(trimReactWhitespaceAndApplyEntities(node)); - write("\""); - break; - case 1 /* Preserve */: - default: - writer.writeLiteral(ts.getTextOfNode(node, /*includeTrivia*/ true)); - break; - } - } - function emitJsxExpression(node) { - if (node.expression) { - switch (compilerOptions.jsx) { - case 1 /* Preserve */: - default: - write("{"); - emit(node.expression); - write("}"); - break; - case 2 /* React */: - emit(node.expression); - break; - } - } - } - function emitDirectivePrologues(statements, startWithNewLine) { - for (var i = 0; i < statements.length; ++i) { - if (ts.isPrologueDirective(statements[i])) { - if (startWithNewLine || i > 0) { - writeLine(); - } - emit(statements[i]); - } - else { - // return index of the first non prologue directive - return i; - } - } - return statements.length; - } - function writeLines(text) { - var lines = text.split(/\r\n|\r|\n/g); - for (var i = 0; i < lines.length; ++i) { - var line = lines[i]; - if (line.length) { - writeLine(); - write(line); - } - } - } - function emitEmitHelpers(node) { - // 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 < 2 /* ES6 */) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */)) { - writeLines(extendsHelper); - extendsEmitted = true; - } - if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16 /* EmitDecorate */) { - writeLines(decorateHelper); - if (compilerOptions.emitDecoratorMetadata) { - writeLines(metadataHelper); - } - decorateEmitted = true; - } - if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32 /* EmitParam */) { - writeLines(paramHelper); - paramEmitted = true; - } - if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64 /* EmitAwaiter */) { - writeLines(awaiterHelper); - awaiterEmitted = true; - } - } - } - function emitSourceFileNode(node) { - // Start new file on new line - writeLine(); - emitShebang(); - emitDetachedComments(node); - // emit prologue directives prior to __extends - var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); - if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { - if (languageVersion >= 2 /* ES6 */) { - emitES6Module(node, startIndex); - } - else if (compilerOptions.module === 2 /* AMD */) { - emitAMDModule(node, startIndex); - } - else if (compilerOptions.module === 4 /* System */) { - emitSystemModule(node, startIndex); - } - else if (compilerOptions.module === 3 /* UMD */) { - emitUMDModule(node, startIndex); - } - else { - emitCommonJSModule(node, startIndex); - } - } - else { - externalImports = undefined; - exportSpecifiers = undefined; - exportEquals = undefined; - hasExportStars = false; - emitEmitHelpers(node); - emitCaptureThisForNodeIfNecessary(node); - emitLinesStartingAt(node.statements, startIndex); - emitTempDeclarations(/*newLine*/ true); - } - emitLeadingComments(node.endOfFileToken); - } - function emitNodeWithCommentsAndWithoutSourcemap(node) { - emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); - } - function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { - if (node) { - if (node.flags & 2 /* Ambient */) { - return emitCommentsOnNotEmittedNode(node); - } - if (isSpecializedCommentHandling(node)) { - // This is the node that will handle its own comments and sourcemap - return emitNodeWithoutSourceMap(node); - } - var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); - if (emitComments_1) { - emitLeadingComments(node); - } - emitNodeConsideringSourcemap(node); - if (emitComments_1) { - emitTrailingComments(node); - } - } - } - function emitNodeWithoutSourceMap(node) { - if (node) { - emitJavaScriptWorker(node); - } - } - function isSpecializedCommentHandling(node) { - switch (node.kind) { - // All of these entities are emitted in a specialized fashion. As such, we allow - // the specialized methods for each to handle the comments on the nodes. - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 225 /* ExportAssignment */: - return true; - } - } - function shouldEmitLeadingAndTrailingComments(node) { - switch (node.kind) { - case 191 /* VariableStatement */: - return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); - case 216 /* ModuleDeclaration */: - // Only emit the leading/trailing comments for a module if we're actually - // emitting the module as well. - return shouldEmitModuleDeclaration(node); - case 215 /* EnumDeclaration */: - // Only emit the leading/trailing comments for an enum if we're actually - // emitting the module as well. - return shouldEmitEnumDeclaration(node); - } - // If the node is emitted in specialized fashion, dont emit comments as this node will handle - // emitting comments when emitting itself - ts.Debug.assert(!isSpecializedCommentHandling(node)); - // If this is the expression body of an arrow function that we're down-leveling, - // then we don't want to emit comments when we emit the body. It will have already - // been taken care of when we emitted the 'return' statement for the function - // expression body. - if (node.kind !== 190 /* Block */ && - node.parent && - node.parent.kind === 172 /* ArrowFunction */ && - node.parent.body === node && - compilerOptions.target <= 1 /* ES5 */) { - return false; - } - // Emit comments for everything else. - return true; - } - function emitJavaScriptWorker(node) { - // Check if the node can be emitted regardless of the ScriptTarget - switch (node.kind) { - case 67 /* Identifier */: - return emitIdentifier(node); - case 136 /* Parameter */: - return emitParameter(node); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - return emitMethod(node); - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - return emitAccessor(node); - case 95 /* ThisKeyword */: - return emitThis(node); - case 93 /* SuperKeyword */: - return emitSuper(node); - case 91 /* NullKeyword */: - return write("null"); - case 97 /* TrueKeyword */: - return write("true"); - case 82 /* FalseKeyword */: - return write("false"); - case 8 /* NumericLiteral */: - case 9 /* StringLiteral */: - case 10 /* RegularExpressionLiteral */: - case 11 /* NoSubstitutionTemplateLiteral */: - case 12 /* TemplateHead */: - case 13 /* TemplateMiddle */: - case 14 /* TemplateTail */: - return emitLiteral(node); - case 181 /* TemplateExpression */: - return emitTemplateExpression(node); - case 188 /* TemplateSpan */: - return emitTemplateSpan(node); - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - return emitJsxElement(node); - case 234 /* JsxText */: - return emitJsxText(node); - case 238 /* JsxExpression */: - return emitJsxExpression(node); - case 133 /* QualifiedName */: - return emitQualifiedName(node); - case 159 /* ObjectBindingPattern */: - return emitObjectBindingPattern(node); - case 160 /* ArrayBindingPattern */: - return emitArrayBindingPattern(node); - case 161 /* BindingElement */: - return emitBindingElement(node); - case 162 /* ArrayLiteralExpression */: - return emitArrayLiteral(node); - case 163 /* ObjectLiteralExpression */: - return emitObjectLiteral(node); - case 243 /* PropertyAssignment */: - return emitPropertyAssignment(node); - case 244 /* ShorthandPropertyAssignment */: - return emitShorthandPropertyAssignment(node); - case 134 /* ComputedPropertyName */: - return emitComputedPropertyName(node); - case 164 /* PropertyAccessExpression */: - return emitPropertyAccess(node); - case 165 /* ElementAccessExpression */: - return emitIndexedAccess(node); - case 166 /* CallExpression */: - return emitCallExpression(node); - case 167 /* NewExpression */: - return emitNewExpression(node); - case 168 /* TaggedTemplateExpression */: - return emitTaggedTemplateExpression(node); - case 169 /* TypeAssertionExpression */: - return emit(node.expression); - case 187 /* AsExpression */: - return emit(node.expression); - case 170 /* ParenthesizedExpression */: - return emitParenExpression(node); - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - return emitFunctionDeclaration(node); - case 173 /* DeleteExpression */: - return emitDeleteExpression(node); - case 174 /* TypeOfExpression */: - return emitTypeOfExpression(node); - case 175 /* VoidExpression */: - return emitVoidExpression(node); - case 176 /* AwaitExpression */: - return emitAwaitExpression(node); - case 177 /* PrefixUnaryExpression */: - return emitPrefixUnaryExpression(node); - case 178 /* PostfixUnaryExpression */: - return emitPostfixUnaryExpression(node); - case 179 /* BinaryExpression */: - return emitBinaryExpression(node); - case 180 /* ConditionalExpression */: - return emitConditionalExpression(node); - case 183 /* SpreadElementExpression */: - return emitSpreadElementExpression(node); - case 182 /* YieldExpression */: - return emitYieldExpression(node); - case 185 /* OmittedExpression */: - return; - case 190 /* Block */: - case 217 /* ModuleBlock */: - return emitBlock(node); - case 191 /* VariableStatement */: - return emitVariableStatement(node); - case 192 /* EmptyStatement */: - return write(";"); - case 193 /* ExpressionStatement */: - return emitExpressionStatement(node); - case 194 /* IfStatement */: - return emitIfStatement(node); - case 195 /* DoStatement */: - return emitDoStatement(node); - case 196 /* WhileStatement */: - return emitWhileStatement(node); - case 197 /* ForStatement */: - return emitForStatement(node); - case 199 /* ForOfStatement */: - case 198 /* ForInStatement */: - return emitForInOrForOfStatement(node); - case 200 /* ContinueStatement */: - case 201 /* BreakStatement */: - return emitBreakOrContinueStatement(node); - case 202 /* ReturnStatement */: - return emitReturnStatement(node); - case 203 /* WithStatement */: - return emitWithStatement(node); - case 204 /* SwitchStatement */: - return emitSwitchStatement(node); - case 239 /* CaseClause */: - case 240 /* DefaultClause */: - return emitCaseOrDefaultClause(node); - case 205 /* LabeledStatement */: - return emitLabelledStatement(node); - case 206 /* ThrowStatement */: - return emitThrowStatement(node); - case 207 /* TryStatement */: - return emitTryStatement(node); - case 242 /* CatchClause */: - return emitCatchClause(node); - case 208 /* DebuggerStatement */: - return emitDebuggerStatement(node); - case 209 /* VariableDeclaration */: - return emitVariableDeclaration(node); - case 184 /* ClassExpression */: - return emitClassExpression(node); - case 212 /* ClassDeclaration */: - return emitClassDeclaration(node); - case 213 /* InterfaceDeclaration */: - return emitInterfaceDeclaration(node); - case 215 /* EnumDeclaration */: - return emitEnumDeclaration(node); - case 245 /* EnumMember */: - return emitEnumMember(node); - case 216 /* ModuleDeclaration */: - return emitModuleDeclaration(node); - case 220 /* ImportDeclaration */: - return emitImportDeclaration(node); - case 219 /* ImportEqualsDeclaration */: - return emitImportEqualsDeclaration(node); - case 226 /* ExportDeclaration */: - return emitExportDeclaration(node); - case 225 /* ExportAssignment */: - return emitExportAssignment(node); - case 246 /* SourceFile */: - return emitSourceFileNode(node); - } - } - function hasDetachedComments(pos) { - return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; - } - function getLeadingCommentsWithoutDetachedComments() { - // get the leading comments from detachedPos - var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); - if (detachedCommentsInfo.length - 1) { - detachedCommentsInfo.pop(); - } - else { - detachedCommentsInfo = undefined; - } - return leadingComments; - } - function isPinnedComments(comment) { - return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; - } - /** - * Determine if the given comment is a triple-slash - * - * @return true if the comment is a triple-slash comment else false - **/ - function isTripleSlashComment(comment) { - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */) { - var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); - return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || - textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? - true : false; - } - return false; - } - function getLeadingCommentsToEmit(node) { - // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments - if (node.parent) { - if (node.parent.kind === 246 /* SourceFile */ || node.pos !== node.parent.pos) { - if (hasDetachedComments(node.pos)) { - // get comments without detached comments - return getLeadingCommentsWithoutDetachedComments(); - } - else { - // get the leading comments from the node - return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - } - } - } - function getTrailingCommentsToEmit(node) { - // Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments - if (node.parent) { - if (node.parent.kind === 246 /* SourceFile */ || node.end !== node.parent.end) { - return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - } - } - } - /** - * Emit comments associated with node that will not be emitted into JS file - */ - function emitCommentsOnNotEmittedNode(node) { - emitLeadingCommentsWorker(node, /*isEmittedNode:*/ false); - } - function emitLeadingComments(node) { - return emitLeadingCommentsWorker(node, /*isEmittedNode:*/ true); - } - function emitLeadingCommentsWorker(node, isEmittedNode) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (isEmittedNode) { - leadingComments = getLeadingCommentsToEmit(node); - } - else { - // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, - // unless it is a triple slash comment at the top of the file. - // For Example: - // /// - // declare var x; - // /// - // interface F {} - // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted - if (node.pos === 0) { - leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); - } - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator:*/ true, newLine, writeComment); - } - function emitTrailingComments(node) { - if (compilerOptions.removeComments) { - return; - } - // Emit the trailing comments only if the parent's end doesn't match - var trailingComments = getTrailingCommentsToEmit(node); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); - } - /** - * Emit trailing comments at the position. The term trailing comment is used here to describe following comment: - * x, /comment1/ y - * ^ => pos; the function will emit "comment1" in the emitJS - */ - function emitTrailingCommentsOfPosition(pos) { - if (compilerOptions.removeComments) { - return; - } - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); - } - function emitLeadingCommentsOfPositionWorker(pos) { - if (compilerOptions.removeComments) { - return; - } - var leadingComments; - if (hasDetachedComments(pos)) { - // get comments without detached comments - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - // get the leading comments from the node - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); - } - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); - // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); - } - function emitDetachedComments(node) { - var leadingComments; - if (compilerOptions.removeComments) { - // removeComments is true, only reserve pinned comment at the top of file - // For example: - // /*! Pinned Comment */ - // - // var x = 10; - if (node.pos === 0) { - leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); - } - } - else { - // removeComments is false, just get detached as normal and bypass the process to filter comment - leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); - } - if (leadingComments) { - var detachedComments = []; - var lastComment; - ts.forEach(leadingComments, function (comment) { - if (lastComment) { - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); - var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); - if (commentLine >= lastCommentLine + 2) { - // There was a blank line between the last comment and this comment. This - // comment is not part of the copyright comments. Return what we have so - // far. - return detachedComments; - } - } - detachedComments.push(comment); - lastComment = comment; - }); - if (detachedComments.length) { - // All comments look like they could have been part of the copyright header. Make - // sure there is at least one blank line between it and the node. If not, it's not - // a copyright header. - var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); - var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - if (nodeLine >= lastCommentLine + 2) { - // Valid detachedComments - ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); - ts.emitComments(currentSourceFile, writer, detachedComments, /*trailingSeparator*/ true, newLine, writeComment); - var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; - if (detachedCommentsInfo) { - detachedCommentsInfo.push(currentDetachedCommentInfo); - } - else { - detachedCommentsInfo = [currentDetachedCommentInfo]; - } - } - } - } - } - function emitShebang() { - var shebang = ts.getShebang(currentSourceFile.text); - if (shebang) { - write(shebang); - } - } - } - function emitFile(jsFilePath, sourceFile) { - emitJavaScript(jsFilePath, sourceFile); - if (compilerOptions.declaration) { - ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); - } - } - } - ts.emitFiles = emitFiles; var entities = { "quot": 0x0022, "amp": 0x0026, @@ -35261,6 +29428,6531 @@ var ts; "hearts": 0x2665, "diams": 0x2666 }; + // Flags enum to track count of temp variables and a few dedicated names + var TempFlags; + (function (TempFlags) { + TempFlags[TempFlags["Auto"] = 0] = "Auto"; + TempFlags[TempFlags["CountMask"] = 268435455] = "CountMask"; + TempFlags[TempFlags["_i"] = 268435456] = "_i"; + })(TempFlags || (TempFlags = {})); + // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature + function emitFiles(resolver, host, targetSourceFile) { + // emit output for the __extends helper function + var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};"; + // emit output for the __decorate helper function + var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};"; + // emit output for the __metadata helper function + var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; + // emit output for the __param helper function + var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};"; + var awaiterHelper = "\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {\n return new Promise(function (resolve, reject) {\n generator = generator.call(thisArg, _arguments);\n function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }\n function onfulfill(value) { try { step(\"next\", value); } catch (e) { reject(e); } }\n function onreject(value) { try { step(\"throw\", value); } catch (e) { reject(e); } }\n function step(verb, value) {\n var result = generator[verb](value);\n result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);\n }\n step(\"next\", void 0);\n });\n};"; + var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; + var modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === 2 /* ES6 */ ? 5 /* ES6 */ : 0 /* None */; + var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; + var diagnostics = []; + var newLine = host.getNewLine(); + var jsxDesugaring = host.getCompilerOptions().jsx !== 1 /* Preserve */; + var shouldEmitJsx = function (s) { return (s.languageVariant === 1 /* JSX */ && !jsxDesugaring); }; + if (targetSourceFile === undefined) { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (ts.shouldEmitToOwnFile(sourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, sourceFile); + } + }); + if (compilerOptions.outFile || compilerOptions.out) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + else { + // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service) + if (ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { + var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js"); + emitFile(jsFilePath, targetSourceFile); + } + else if (!ts.isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) { + emitFile(compilerOptions.outFile || compilerOptions.out); + } + } + // Sort and make the unique list of diagnostics + diagnostics = ts.sortAndDeduplicateDiagnostics(diagnostics); + return { + emitSkipped: false, + diagnostics: diagnostics, + sourceMaps: sourceMapDataList + }; + function isNodeDescendentOf(node, ancestor) { + while (node) { + if (node === ancestor) + return true; + node = node.parent; + } + return false; + } + function isUniqueLocalName(name, container) { + for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + if (node.locals && ts.hasProperty(node.locals, name)) { + // We conservatively include alias symbols to cover cases where they're emitted as locals + if (node.locals[name].flags & (107455 /* Value */ | 1048576 /* ExportValue */ | 8388608 /* Alias */)) { + return false; + } + } + } + return true; + } + function emitJavaScript(jsFilePath, root) { + var writer = ts.createTextWriter(newLine); + var write = writer.write, writeTextOfNode = writer.writeTextOfNode, writeLine = writer.writeLine, increaseIndent = writer.increaseIndent, decreaseIndent = writer.decreaseIndent; + var currentSourceFile; + // name of an exporter function if file is a System external module + // System.register([...], function () {...}) + // exporting in System modules looks like: + // export var x; ... x = 1 + // => + // var x;... exporter("x", x = 1) + var exportFunctionForFile; + var generatedNameSet = {}; + var nodeToGeneratedName = []; + var computedPropertyNamesToGeneratedNames; + var extendsEmitted = false; + var decorateEmitted = false; + var paramEmitted = false; + var awaiterEmitted = false; + var tempFlags = 0; + var tempVariables; + var tempParameters; + var externalImports; + var exportSpecifiers; + var exportEquals; + var hasExportStars; + /** Write emitted output to disk */ + var writeEmittedFiles = writeJavaScriptFile; + var detachedCommentsInfo; + var writeComment = ts.writeCommentRange; + /** Emit a node */ + var emit = emitNodeWithCommentsAndWithoutSourcemap; + /** Called just before starting emit of a node */ + var emitStart = function (node) { }; + /** Called once the emit of the node is done */ + var emitEnd = function (node) { }; + /** Emit the text for the given token that comes after startPos + * This by default writes the text provided with the given tokenKind + * but if optional emitFn callback is provided the text is emitted using the callback instead of default text + * @param tokenKind the kind of the token to search and emit + * @param startPos the position in the source to start searching for the token + * @param emitFn if given will be invoked to emit the text instead of actual token emit */ + var emitToken = emitTokenText; + /** Called to before starting the lexical scopes as in function/class in the emitted code because of node + * @param scopeDeclaration node that starts the lexical scope + * @param scopeName Optional name of this scope instead of deducing one from the declaration node */ + var scopeEmitStart = function (scopeDeclaration, scopeName) { }; + /** Called after coming out of the scope */ + var scopeEmitEnd = function () { }; + /** Sourcemap data that will get encoded */ + var sourceMapData; + /** If removeComments is true, no leading-comments needed to be emitted **/ + var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfPositionWorker; + var moduleEmitDelegates = (_a = {}, + _a[5 /* ES6 */] = emitES6Module, + _a[2 /* AMD */] = emitAMDModule, + _a[4 /* System */] = emitSystemModule, + _a[3 /* UMD */] = emitUMDModule, + _a[1 /* CommonJS */] = emitCommonJSModule, + _a + ); + if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { + initializeEmitterWithSourceMaps(); + } + if (root) { + // Do not call emit directly. It does not set the currentSourceFile. + emitSourceFile(root); + } + else { + ts.forEach(host.getSourceFiles(), function (sourceFile) { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + emitSourceFile(sourceFile); + } + }); + } + writeLine(); + writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); + return; + function emitSourceFile(sourceFile) { + currentSourceFile = sourceFile; + exportFunctionForFile = undefined; + emit(sourceFile); + } + function isUniqueName(name) { + return !resolver.hasGlobalName(name) && + !ts.hasProperty(currentSourceFile.identifiers, name) && + !ts.hasProperty(generatedNameSet, name); + } + // Return the next available name in the pattern _a ... _z, _0, _1, ... + // TempFlags._i or TempFlags._n may be used to express a preference for that dedicated name. + // Note that names generated by makeTempVariableName and makeUniqueName will never conflict. + function makeTempVariableName(flags) { + if (flags && !(tempFlags & flags)) { + var name_19 = flags === 268435456 /* _i */ ? "_i" : "_n"; + if (isUniqueName(name_19)) { + tempFlags |= flags; + return name_19; + } + } + while (true) { + var count = tempFlags & 268435455 /* CountMask */; + tempFlags++; + // Skip over 'i' and 'n' + if (count !== 8 && count !== 13) { + var name_20 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_20)) { + return name_20; + } + } + } + } + // Generate a name that is unique within the current file and doesn't conflict with any names + // in global scope. The name is formed by adding an '_n' suffix to the specified base name, + // where n is a positive integer. Note that names generated by makeTempVariableName and + // makeUniqueName are guaranteed to never conflict. + function makeUniqueName(baseName) { + // Find the first unique 'name_n', where n is a positive number + if (baseName.charCodeAt(baseName.length - 1) !== 95 /* _ */) { + baseName += "_"; + } + var i = 1; + while (true) { + var generatedName = baseName + i; + if (isUniqueName(generatedName)) { + return generatedNameSet[generatedName] = generatedName; + } + i++; + } + } + function generateNameForModuleOrEnum(node) { + var name = node.name.text; + // Use module/enum name itself if it is unique, otherwise make a unique variation + return isUniqueLocalName(name, node) ? name : makeUniqueName(name); + } + function generateNameForImportOrExportDeclaration(node) { + var expr = ts.getExternalModuleName(node); + var baseName = expr.kind === 9 /* StringLiteral */ ? + ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; + return makeUniqueName(baseName); + } + function generateNameForExportDefault() { + return makeUniqueName("default"); + } + function generateNameForClassExpression() { + return makeUniqueName("class"); + } + function generateNameForNode(node) { + switch (node.kind) { + case 69 /* Identifier */: + return makeUniqueName(node.text); + case 218 /* ModuleDeclaration */: + case 217 /* EnumDeclaration */: + return generateNameForModuleOrEnum(node); + case 222 /* ImportDeclaration */: + case 228 /* ExportDeclaration */: + return generateNameForImportOrExportDeclaration(node); + case 213 /* FunctionDeclaration */: + case 214 /* ClassDeclaration */: + case 227 /* ExportAssignment */: + return generateNameForExportDefault(); + case 186 /* ClassExpression */: + return generateNameForClassExpression(); + } + } + function getGeneratedNameForNode(node) { + var id = ts.getNodeId(node); + return nodeToGeneratedName[id] || (nodeToGeneratedName[id] = ts.unescapeIdentifier(generateNameForNode(node))); + } + function initializeEmitterWithSourceMaps() { + var sourceMapDir; // The directory in which sourcemap will be + // Current source map file and its index in the sources list + var sourceMapSourceIndex = -1; + // Names and its index map + var sourceMapNameIndexMap = {}; + var sourceMapNameIndices = []; + function getSourceMapNameIndex() { + return sourceMapNameIndices.length ? ts.lastOrUndefined(sourceMapNameIndices) : -1; + } + // Last recorded and encoded spans + var lastRecordedSourceMapSpan; + var lastEncodedSourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; + var lastEncodedNameIndex = 0; + // Encoding for sourcemap span + function encodeLastRecordedSourceMapSpan() { + if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) { + return; + } + var prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn; + // Line/Comma delimiters + if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) { + // Emit comma to separate the entry + if (sourceMapData.sourceMapMappings) { + sourceMapData.sourceMapMappings += ","; + } + } + else { + // Emit line delimiters + for (var encodedLine = lastEncodedSourceMapSpan.emittedLine; encodedLine < lastRecordedSourceMapSpan.emittedLine; encodedLine++) { + sourceMapData.sourceMapMappings += ";"; + } + prevEncodedEmittedColumn = 1; + } + // 1. Relative Column 0 based + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.emittedColumn - prevEncodedEmittedColumn); + // 2. Relative sourceIndex + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceIndex - lastEncodedSourceMapSpan.sourceIndex); + // 3. Relative sourceLine 0 based + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceLine - lastEncodedSourceMapSpan.sourceLine); + // 4. Relative sourceColumn 0 based + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.sourceColumn - lastEncodedSourceMapSpan.sourceColumn); + // 5. Relative namePosition 0 based + if (lastRecordedSourceMapSpan.nameIndex >= 0) { + sourceMapData.sourceMapMappings += base64VLQFormatEncode(lastRecordedSourceMapSpan.nameIndex - lastEncodedNameIndex); + lastEncodedNameIndex = lastRecordedSourceMapSpan.nameIndex; + } + lastEncodedSourceMapSpan = lastRecordedSourceMapSpan; + sourceMapData.sourceMapDecodedMappings.push(lastEncodedSourceMapSpan); + function base64VLQFormatEncode(inValue) { + function base64FormatEncode(inValue) { + if (inValue < 64) { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); + } + throw TypeError(inValue + ": not a 64 based value"); + } + // Add a new least significant bit that has the sign of the value. + // if negative number the least significant bit that gets added to the number has value 1 + // else least significant bit value that gets added is 0 + // eg. -1 changes to binary : 01 [1] => 3 + // +1 changes to binary : 01 [0] => 2 + if (inValue < 0) { + inValue = ((-inValue) << 1) + 1; + } + else { + inValue = inValue << 1; + } + // Encode 5 bits at a time starting from least significant bits + var encodedStr = ""; + do { + var currentDigit = inValue & 31; // 11111 + inValue = inValue >> 5; + if (inValue > 0) { + // There are still more digits to decode, set the msb (6th bit) + currentDigit = currentDigit | 32; + } + encodedStr = encodedStr + base64FormatEncode(currentDigit); + } while (inValue > 0); + return encodedStr; + } + } + function recordSourceMapSpan(pos) { + var sourceLinePos = ts.getLineAndCharacterOfPosition(currentSourceFile, pos); + // Convert the location to be one-based. + sourceLinePos.line++; + sourceLinePos.character++; + var emittedLine = writer.getLine(); + var emittedColumn = writer.getColumn(); + // If this location wasn't recorded or the location in source is going backwards, record the span + if (!lastRecordedSourceMapSpan || + lastRecordedSourceMapSpan.emittedLine !== emittedLine || + lastRecordedSourceMapSpan.emittedColumn !== emittedColumn || + (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + // Encode the last recordedSpan before assigning new + encodeLastRecordedSourceMapSpan(); + // New span + lastRecordedSourceMapSpan = { + emittedLine: emittedLine, + emittedColumn: emittedColumn, + sourceLine: sourceLinePos.line, + sourceColumn: sourceLinePos.character, + nameIndex: getSourceMapNameIndex(), + sourceIndex: sourceMapSourceIndex + }; + } + else { + // Take the new pos instead since there is no change in emittedLine and column since last location + lastRecordedSourceMapSpan.sourceLine = sourceLinePos.line; + lastRecordedSourceMapSpan.sourceColumn = sourceLinePos.character; + lastRecordedSourceMapSpan.sourceIndex = sourceMapSourceIndex; + } + } + function recordEmitNodeStartSpan(node) { + // Get the token pos after skipping to the token (ignoring the leading trivia) + recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); + } + function recordEmitNodeEndSpan(node) { + recordSourceMapSpan(node.end); + } + function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + function recordNewSourceFileStart(node) { + // Add the file to tsFilePaths + // If sourceroot option: Use the relative path corresponding to the common directory path + // otherwise source locations relative to map file location + var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; + sourceMapData.sourceMapSources.push(ts.getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.fileName, host.getCurrentDirectory(), host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ true)); + sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; + // The one that can be used from program to get the actual source file + sourceMapData.inputSourceFileNames.push(node.fileName); + if (compilerOptions.inlineSources) { + if (!sourceMapData.sourceMapSourcesContent) { + sourceMapData.sourceMapSourcesContent = []; + } + sourceMapData.sourceMapSourcesContent.push(node.text); + } + } + function recordScopeNameOfNode(node, scopeName) { + function recordScopeNameIndex(scopeNameIndex) { + sourceMapNameIndices.push(scopeNameIndex); + } + function recordScopeNameStart(scopeName) { + var scopeNameIndex = -1; + if (scopeName) { + var parentIndex = getSourceMapNameIndex(); + if (parentIndex !== -1) { + // Child scopes are always shown with a dot (even if they have no name), + // unless it is a computed property. Then it is shown with brackets, + // but the brackets are included in the name. + var name_21 = node.name; + if (!name_21 || name_21.kind !== 136 /* ComputedPropertyName */) { + scopeName = "." + scopeName; + } + scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; + } + scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); + if (scopeNameIndex === undefined) { + scopeNameIndex = sourceMapData.sourceMapNames.length; + sourceMapData.sourceMapNames.push(scopeName); + sourceMapNameIndexMap[scopeName] = scopeNameIndex; + } + } + recordScopeNameIndex(scopeNameIndex); + } + if (scopeName) { + // The scope was already given a name use it + recordScopeNameStart(scopeName); + } + else if (node.kind === 213 /* FunctionDeclaration */ || + node.kind === 173 /* FunctionExpression */ || + node.kind === 143 /* MethodDeclaration */ || + node.kind === 142 /* MethodSignature */ || + node.kind === 145 /* GetAccessor */ || + node.kind === 146 /* SetAccessor */ || + node.kind === 218 /* ModuleDeclaration */ || + node.kind === 214 /* ClassDeclaration */ || + node.kind === 217 /* EnumDeclaration */) { + // Declaration and has associated name use it + if (node.name) { + var name_22 = node.name; + // For computed property names, the text will include the brackets + scopeName = name_22.kind === 136 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_22) + : node.name.text; + } + recordScopeNameStart(scopeName); + } + else { + // Block just use the name from upper level scope + recordScopeNameIndex(getSourceMapNameIndex()); + } + } + function recordScopeNameEnd() { + sourceMapNameIndices.pop(); + } + ; + function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) { + recordSourceMapSpan(comment.pos); + ts.writeCommentRange(currentSourceFile, writer, comment, newLine); + recordSourceMapSpan(comment.end); + } + function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings, sourcesContent) { + if (typeof JSON !== "undefined") { + var map_1 = { + version: version, + file: file, + sourceRoot: sourceRoot, + sources: sources, + names: names, + mappings: mappings + }; + if (sourcesContent !== undefined) { + map_1.sourcesContent = sourcesContent; + } + return JSON.stringify(map_1); + } + return "{\"version\":" + version + ",\"file\":\"" + ts.escapeString(file) + "\",\"sourceRoot\":\"" + ts.escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + ts.escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; + function serializeStringArray(list) { + var output = ""; + for (var i = 0, n = list.length; i < n; i++) { + if (i) { + output += ","; + } + output += "\"" + ts.escapeString(list[i]) + "\""; + } + return output; + } + } + function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) { + encodeLastRecordedSourceMapSpan(); + var sourceMapText = serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, sourceMapData.sourceMapSourcesContent); + sourceMapDataList.push(sourceMapData); + var sourceMapUrl; + if (compilerOptions.inlineSourceMap) { + // Encode the sourceMap into the sourceMap url + var base64SourceMapText = ts.convertToBase64(sourceMapText); + sourceMapUrl = "//# sourceMappingURL=data:application/json;base64," + base64SourceMapText; + } + else { + // Write source map file + ts.writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, /*writeByteOrderMark*/ false); + sourceMapUrl = "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL; + } + // Write sourcemap url to the js file and write the js file + writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); + } + // Initialize source map data + var sourceMapJsFile = ts.getBaseFileName(ts.normalizeSlashes(jsFilePath)); + sourceMapData = { + sourceMapFilePath: jsFilePath + ".map", + jsSourceMappingURL: sourceMapJsFile + ".map", + sourceMapFile: sourceMapJsFile, + sourceMapSourceRoot: compilerOptions.sourceRoot || "", + sourceMapSources: [], + inputSourceFileNames: [], + sourceMapNames: [], + sourceMapMappings: "", + sourceMapSourcesContent: undefined, + sourceMapDecodedMappings: [] + }; + // Normalize source root and make sure it has trailing "/" so that it can be used to combine paths with the + // relative paths of the sources list in the sourcemap + sourceMapData.sourceMapSourceRoot = ts.normalizeSlashes(sourceMapData.sourceMapSourceRoot); + if (sourceMapData.sourceMapSourceRoot.length && sourceMapData.sourceMapSourceRoot.charCodeAt(sourceMapData.sourceMapSourceRoot.length - 1) !== 47 /* slash */) { + sourceMapData.sourceMapSourceRoot += ts.directorySeparator; + } + if (compilerOptions.mapRoot) { + sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); + if (root) { + // For modules or multiple emit files the mapRoot will have directory structure like the sources + // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(root, host, sourceMapDir)); + } + if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { + // The relative paths are relative to the common directory + sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); + sourceMapData.jsSourceMappingURL = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath + ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap + host.getCurrentDirectory(), host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ true); + } + else { + sourceMapData.jsSourceMappingURL = ts.combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); + } + } + else { + sourceMapDir = ts.getDirectoryPath(ts.normalizePath(jsFilePath)); + } + function emitNodeWithSourceMap(node) { + if (node) { + if (ts.nodeIsSynthesized(node)) { + return emitNodeWithoutSourceMap(node); + } + if (node.kind !== 248 /* SourceFile */) { + recordEmitNodeStartSpan(node); + emitNodeWithoutSourceMap(node); + recordEmitNodeEndSpan(node); + } + else { + recordNewSourceFileStart(node); + emitNodeWithoutSourceMap(node); + } + } + } + function emitNodeWithCommentsAndWithSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap); + } + writeEmittedFiles = writeJavaScriptAndSourceMapFile; + emit = emitNodeWithCommentsAndWithSourcemap; + emitStart = recordEmitNodeStartSpan; + emitEnd = recordEmitNodeEndSpan; + emitToken = writeTextWithSpanRecord; + scopeEmitStart = recordScopeNameOfNode; + scopeEmitEnd = recordScopeNameEnd; + writeComment = writeCommentRangeWithMap; + } + function writeJavaScriptFile(emitOutput, writeByteOrderMark) { + ts.writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); + } + // Create a temporary variable with a unique unused name. + function createTempVariable(flags) { + var result = ts.createSynthesizedNode(69 /* Identifier */); + result.text = makeTempVariableName(flags); + return result; + } + function recordTempDeclaration(name) { + if (!tempVariables) { + tempVariables = []; + } + tempVariables.push(name); + } + function createAndRecordTempVariable(flags) { + var temp = createTempVariable(flags); + recordTempDeclaration(temp); + return temp; + } + function emitTempDeclarations(newLine) { + if (tempVariables) { + if (newLine) { + writeLine(); + } + else { + write(" "); + } + write("var "); + emitCommaList(tempVariables); + write(";"); + } + } + function emitTokenText(tokenKind, startPos, emitFn) { + var tokenString = ts.tokenToString(tokenKind); + if (emitFn) { + emitFn(); + } + else { + write(tokenString); + } + return startPos + tokenString.length; + } + function emitOptional(prefix, node) { + if (node) { + write(prefix); + emit(node); + } + } + function emitParenthesizedIf(node, parenthesized) { + if (parenthesized) { + write("("); + } + emit(node); + if (parenthesized) { + write(")"); + } + } + function emitTrailingCommaIfPresent(nodeList) { + if (nodeList.hasTrailingComma) { + write(","); + } + } + function emitLinePreservingList(parent, nodes, allowTrailingComma, spacesBetweenBraces) { + ts.Debug.assert(nodes.length > 0); + increaseIndent(); + if (nodeStartPositionsAreOnSameLine(parent, nodes[0])) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + for (var i = 0, n = nodes.length; i < n; i++) { + if (i) { + if (nodeEndIsOnSameLineAsNodeStart(nodes[i - 1], nodes[i])) { + write(", "); + } + else { + write(","); + writeLine(); + } + } + emit(nodes[i]); + } + if (nodes.hasTrailingComma && allowTrailingComma) { + write(","); + } + decreaseIndent(); + if (nodeEndPositionsAreOnSameLine(parent, ts.lastOrUndefined(nodes))) { + if (spacesBetweenBraces) { + write(" "); + } + } + else { + writeLine(); + } + } + function emitList(nodes, start, count, multiLine, trailingComma, leadingComma, noTrailingNewLine, emitNode) { + if (!emitNode) { + emitNode = emit; + } + for (var i = 0; i < count; i++) { + if (multiLine) { + if (i || leadingComma) { + write(","); + } + writeLine(); + } + else { + if (i || leadingComma) { + write(", "); + } + } + var node = nodes[start + i]; + // This emitting is to make sure we emit following comment properly + // ...(x, /*comment1*/ y)... + // ^ => node.pos + // "comment1" is not considered leading comment for "y" but rather + // considered as trailing comment of the previous node. + emitTrailingCommentsOfPosition(node.pos); + emitNode(node); + leadingComma = true; + } + if (trailingComma) { + write(","); + } + if (multiLine && !noTrailingNewLine) { + writeLine(); + } + return count; + } + function emitCommaList(nodes) { + if (nodes) { + emitList(nodes, 0, nodes.length, /*multiline*/ false, /*trailingComma*/ false); + } + } + function emitLines(nodes) { + emitLinesStartingAt(nodes, /*startIndex*/ 0); + } + function emitLinesStartingAt(nodes, startIndex) { + for (var i = startIndex; i < nodes.length; i++) { + writeLine(); + emit(nodes[i]); + } + } + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 8 /* NumericLiteral */ && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98 /* b */: + case 66 /* B */: + case 111 /* o */: + case 79 /* O */: + return true; + } + } + return false; + } + function emitLiteral(node) { + var text = getLiteralText(node); + if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === 9 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { + writer.writeLiteral(text); + } + else if (languageVersion < 2 /* ES6 */ && isBinaryOrOctalIntegerLiteral(node, text)) { + write(node.text); + } + else { + write(text); + } + } + function getLiteralText(node) { + // Any template literal or string literal with an extended escape + // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal. + if (languageVersion < 2 /* ES6 */ && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText("\"", node.text, "\""); + } + // If we don't need to downlevel and we can reach the original source text using + // the node's parent reference, then simply get the text as it was originally written. + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + // If we can't reach the original source text, use the canonical form if it's a number, + // or an escaped quoted form of the original text if it's string-like. + switch (node.kind) { + case 9 /* StringLiteral */: + return getQuotedEscapedLiteralText("\"", node.text, "\""); + case 11 /* NoSubstitutionTemplateLiteral */: + return getQuotedEscapedLiteralText("`", node.text, "`"); + case 12 /* TemplateHead */: + return getQuotedEscapedLiteralText("`", node.text, "${"); + case 13 /* TemplateMiddle */: + return getQuotedEscapedLiteralText("}", node.text, "${"); + case 14 /* TemplateTail */: + return getQuotedEscapedLiteralText("}", node.text, "`"); + case 8 /* NumericLiteral */: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + // Find original source text, since we need to emit the raw strings of the tagged template. + // The raw strings contain the (escaped) strings of what the user wrote. + // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + var isLast = node.kind === 11 /* NoSubstitutionTemplateLiteral */ || node.kind === 14 /* TemplateTail */; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + // Newline normalization: + // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's + // and LineTerminatorSequences are normalized to for both TV and TRV. + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write("\"" + text + "\""); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 11 /* NoSubstitutionTemplateLiteral */) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(0 /* Auto */); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + // Now we emit the expressions + if (node.template.kind === 183 /* TemplateExpression */) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 181 /* BinaryExpression */ + && templateSpan.expression.operatorToken.kind === 24 /* CommaToken */; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); + } + function emitTemplateExpression(node) { + // In ES6 mode and above, we can simply emit each portion of a template in order, but in + // ES3 & ES5 we must convert the template expression into a series of string concatenations. + if (languageVersion >= 2 /* ES6 */) { + ts.forEachChild(node, emit); + return; + } + var emitOuterParens = ts.isExpression(node.parent) + && templateNeedsParens(node, node.parent); + if (emitOuterParens) { + write("("); + } + var headEmitted = false; + if (shouldEmitTemplateHead()) { + emitLiteral(node.head); + headEmitted = true; + } + for (var i = 0, n = node.templateSpans.length; i < n; i++) { + var templateSpan = node.templateSpans[i]; + // Check if the expression has operands and binds its operands less closely than binary '+'. + // If it does, we need to wrap the expression in parentheses. Otherwise, something like + // `abc${ 1 << 2 }` + // becomes + // "abc" + 1 << 2 + "" + // which is really + // ("abc" + 1) << (2 + "") + // rather than + // "abc" + (1 << 2) + "" + var needsParens = templateSpan.expression.kind !== 172 /* ParenthesizedExpression */ + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1 /* GreaterThan */; + if (i > 0 || headEmitted) { + // If this is the first span and the head was not emitted, then this templateSpan's + // expression will be the first to be emitted. Don't emit the preceding ' + ' in that + // case. + write(" + "); + } + emitParenthesizedIf(templateSpan.expression, needsParens); + // Only emit if the literal is non-empty. + // The binary '+' operator is left-associative, so the first string concatenation + // with the head will force the result up to this point to be a string. + // Emitting a '+ ""' has no semantic effect for middles and tails. + if (templateSpan.literal.text.length !== 0) { + write(" + "); + emitLiteral(templateSpan.literal); + } + } + if (emitOuterParens) { + write(")"); + } + function shouldEmitTemplateHead() { + // If this expression has an empty head literal and the first template span has a non-empty + // literal, then emitting the empty head literal is not necessary. + // `${ foo } and ${ bar }` + // can be emitted as + // foo + " and " + bar + // This is because it is only required that one of the first two operands in the emit + // output must be a string literal, so that the other operand and all following operands + // are forced into strings. + // + // If the first template span has an empty literal, then the head must still be emitted. + // `${ foo }${ bar }` + // must still be emitted as + // "" + foo + bar + // There is always atleast one templateSpan in this code path, since + // NoSubstitutionTemplateLiterals are directly emitted via emitLiteral() + ts.Debug.assert(node.templateSpans.length !== 0); + return node.head.text.length !== 0 || node.templateSpans[0].literal.text.length === 0; + } + function templateNeedsParens(template, parent) { + switch (parent.kind) { + case 168 /* CallExpression */: + case 169 /* NewExpression */: + return parent.expression === template; + case 170 /* TaggedTemplateExpression */: + case 172 /* ParenthesizedExpression */: + return false; + default: + return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */; + } + } + /** + * Returns whether the expression has lesser, greater, + * or equal precedence to the binary '+' operator + */ + function comparePrecedenceToBinaryPlus(expression) { + // All binary expressions have lower precedence than '+' apart from '*', '/', and '%' + // which have greater precedence and '-' which has equal precedence. + // All unary operators have a higher precedence apart from yield. + // Arrow functions and conditionals have a lower precedence, + // although we convert the former into regular function expressions in ES5 mode, + // and in ES6 mode this function won't get called anyway. + // + // TODO (drosen): Note that we need to account for the upcoming 'yield' and + // spread ('...') unary operators that are anticipated for ES6. + switch (expression.kind) { + case 181 /* BinaryExpression */: + switch (expression.operatorToken.kind) { + case 37 /* AsteriskToken */: + case 39 /* SlashToken */: + case 40 /* PercentToken */: + return 1 /* GreaterThan */; + case 35 /* PlusToken */: + case 36 /* MinusToken */: + return 0 /* EqualTo */; + default: + return -1 /* LessThan */; + } + case 184 /* YieldExpression */: + case 182 /* ConditionalExpression */: + return -1 /* LessThan */; + default: + return 1 /* GreaterThan */; + } + } + } + function emitTemplateSpan(span) { + emit(span.expression); + emit(span.literal); + } + function jsxEmitReact(node) { + /// Emit a tag name, which is either '"div"' for lower-cased names, or + /// 'Div' for upper-cased or dotted names + function emitTagName(name) { + if (name.kind === 69 /* Identifier */ && ts.isIntrinsicJsxName(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + /// Emit an attribute name, which is quoted if it needs to be quoted. Because + /// these emit into an object literal property name, we don't need to be worried + /// about keywords, just non-identifier characters + function emitAttributeName(name) { + if (/[A-Za-z_]+[\w*]/.test(name.text)) { + write("\""); + emit(name); + write("\""); + } + else { + emit(name); + } + } + /// Emit an name/value pair for an attribute (e.g. "x: 3") + function emitJsxAttribute(node) { + emitAttributeName(node.name); + write(": "); + if (node.initializer) { + emit(node.initializer); + } + else { + write("true"); + } + } + function emitJsxElement(openingNode, children) { + var syntheticReactRef = ts.createSynthesizedNode(69 /* Identifier */); + syntheticReactRef.text = "React"; + syntheticReactRef.parent = openingNode; + // Call React.createElement(tag, ... + emitLeadingComments(openingNode); + emitExpressionIdentifier(syntheticReactRef); + write(".createElement("); + emitTagName(openingNode.tagName); + write(", "); + // Attribute list + if (openingNode.attributes.length === 0) { + // When there are no attributes, React wants "null" + write("null"); + } + else { + // Either emit one big object literal (no spread attribs), or + // a call to React.__spread + var attrs = openingNode.attributes; + if (ts.forEach(attrs, function (attr) { return attr.kind === 239 /* JsxSpreadAttribute */; })) { + emitExpressionIdentifier(syntheticReactRef); + write(".__spread("); + var haveOpenedObjectLiteral = false; + for (var i_1 = 0; i_1 < attrs.length; i_1++) { + if (attrs[i_1].kind === 239 /* JsxSpreadAttribute */) { + // If this is the first argument, we need to emit a {} as the first argument + if (i_1 === 0) { + write("{}, "); + } + if (haveOpenedObjectLiteral) { + write("}"); + haveOpenedObjectLiteral = false; + } + if (i_1 > 0) { + write(", "); + } + emit(attrs[i_1].expression); + } + else { + ts.Debug.assert(attrs[i_1].kind === 238 /* JsxAttribute */); + if (haveOpenedObjectLiteral) { + write(", "); + } + else { + haveOpenedObjectLiteral = true; + if (i_1 > 0) { + write(", "); + } + write("{"); + } + emitJsxAttribute(attrs[i_1]); + } + } + if (haveOpenedObjectLiteral) + write("}"); + write(")"); // closing paren to React.__spread( + } + else { + // One object literal with all the attributes in them + write("{"); + for (var i = 0; i < attrs.length; i++) { + if (i > 0) { + write(", "); + } + emitJsxAttribute(attrs[i]); + } + write("}"); + } + } + // Children + if (children) { + for (var i = 0; i < children.length; i++) { + // Don't emit empty expressions + if (children[i].kind === 240 /* JsxExpression */ && !(children[i].expression)) { + continue; + } + // Don't emit empty strings + if (children[i].kind === 236 /* JsxText */) { + var text = getTextToEmit(children[i]); + if (text !== undefined) { + write(", \""); + write(text); + write("\""); + } + } + else { + write(", "); + emit(children[i]); + } + } + } + // Closing paren + write(")"); // closes "React.createElement(" + emitTrailingComments(openingNode); + } + if (node.kind === 233 /* JsxElement */) { + emitJsxElement(node.openingElement, node.children); + } + else { + ts.Debug.assert(node.kind === 234 /* JsxSelfClosingElement */); + emitJsxElement(node); + } + } + function jsxEmitPreserve(node) { + function emitJsxAttribute(node) { + emit(node.name); + if (node.initializer) { + write("="); + emit(node.initializer); + } + } + function emitJsxSpreadAttribute(node) { + write("{..."); + emit(node.expression); + write("}"); + } + function emitAttributes(attribs) { + for (var i = 0, n = attribs.length; i < n; i++) { + if (i > 0) { + write(" "); + } + if (attribs[i].kind === 239 /* JsxSpreadAttribute */) { + emitJsxSpreadAttribute(attribs[i]); + } + else { + ts.Debug.assert(attribs[i].kind === 238 /* JsxAttribute */); + emitJsxAttribute(attribs[i]); + } + } + } + function emitJsxOpeningOrSelfClosingElement(node) { + write("<"); + emit(node.tagName); + if (node.attributes.length > 0 || (node.kind === 234 /* JsxSelfClosingElement */)) { + write(" "); + } + emitAttributes(node.attributes); + if (node.kind === 234 /* JsxSelfClosingElement */) { + write("/>"); + } + else { + write(">"); + } + } + function emitJsxClosingElement(node) { + write(""); + } + function emitJsxElement(node) { + emitJsxOpeningOrSelfClosingElement(node.openingElement); + for (var i = 0, n = node.children.length; i < n; i++) { + emit(node.children[i]); + } + emitJsxClosingElement(node.closingElement); + } + if (node.kind === 233 /* JsxElement */) { + emitJsxElement(node); + } + else { + ts.Debug.assert(node.kind === 234 /* JsxSelfClosingElement */); + emitJsxOpeningOrSelfClosingElement(node); + } + } + // This function specifically handles numeric/string literals for enum and accessor 'identifiers'. + // In a sense, it does not actually emit identifiers as much as it declares a name for a specific property. + // For example, this is utilized when feeding in a result to Object.defineProperty. + function emitExpressionForPropertyName(node) { + ts.Debug.assert(node.kind !== 163 /* BindingElement */); + if (node.kind === 9 /* StringLiteral */) { + emitLiteral(node); + } + else if (node.kind === 136 /* ComputedPropertyName */) { + // if this is a decorated computed property, we will need to capture the result + // of the property expression so that we can apply decorators later. This is to ensure + // we don't introduce unintended side effects: + // + // class C { + // [_a = x]() { } + // } + // + // The emit for the decorated computed property decorator is: + // + // __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a)); + // + if (ts.nodeIsDecorated(node.parent)) { + if (!computedPropertyNamesToGeneratedNames) { + computedPropertyNamesToGeneratedNames = []; + } + var generatedName = computedPropertyNamesToGeneratedNames[ts.getNodeId(node)]; + if (generatedName) { + // we have already generated a variable for this node, write that value instead. + write(generatedName); + return; + } + generatedName = createAndRecordTempVariable(0 /* Auto */).text; + computedPropertyNamesToGeneratedNames[ts.getNodeId(node)] = generatedName; + write(generatedName); + write(" = "); + } + emit(node.expression); + } + else { + write("\""); + if (node.kind === 8 /* NumericLiteral */) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + write("\""); + } + } + function isExpressionIdentifier(node) { + var parent = node.parent; + switch (parent.kind) { + case 164 /* ArrayLiteralExpression */: + case 189 /* AsExpression */: + case 181 /* BinaryExpression */: + case 168 /* CallExpression */: + case 241 /* CaseClause */: + case 136 /* ComputedPropertyName */: + case 182 /* ConditionalExpression */: + case 139 /* Decorator */: + case 175 /* DeleteExpression */: + case 197 /* DoStatement */: + case 167 /* ElementAccessExpression */: + case 227 /* ExportAssignment */: + case 195 /* ExpressionStatement */: + case 188 /* ExpressionWithTypeArguments */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 196 /* IfStatement */: + case 234 /* JsxSelfClosingElement */: + case 235 /* JsxOpeningElement */: + case 239 /* JsxSpreadAttribute */: + case 240 /* JsxExpression */: + case 169 /* NewExpression */: + case 172 /* ParenthesizedExpression */: + case 180 /* PostfixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: + case 204 /* ReturnStatement */: + case 246 /* ShorthandPropertyAssignment */: + case 185 /* SpreadElementExpression */: + case 206 /* SwitchStatement */: + case 170 /* TaggedTemplateExpression */: + case 190 /* TemplateSpan */: + case 208 /* ThrowStatement */: + case 171 /* TypeAssertionExpression */: + case 176 /* TypeOfExpression */: + case 177 /* VoidExpression */: + case 198 /* WhileStatement */: + case 205 /* WithStatement */: + case 184 /* YieldExpression */: + return true; + case 163 /* BindingElement */: + case 247 /* EnumMember */: + case 138 /* Parameter */: + case 245 /* PropertyAssignment */: + case 141 /* PropertyDeclaration */: + case 211 /* VariableDeclaration */: + return parent.initializer === node; + case 166 /* PropertyAccessExpression */: + return parent.expression === node; + case 174 /* ArrowFunction */: + case 173 /* FunctionExpression */: + return parent.body === node; + case 221 /* ImportEqualsDeclaration */: + return parent.moduleReference === node; + case 135 /* QualifiedName */: + return parent.left === node; + } + return false; + } + function emitExpressionIdentifier(node) { + if (resolver.getNodeCheckFlags(node) & 2048 /* LexicalArguments */) { + write("_arguments"); + return; + } + var container = resolver.getReferencedExportContainer(node); + if (container) { + if (container.kind === 248 /* SourceFile */) { + // Identifier references module export + if (modulekind !== 5 /* ES6 */ && modulekind !== 4 /* System */) { + write("exports."); + } + } + else { + // Identifier references namespace export + write(getGeneratedNameForNode(container)); + write("."); + } + } + else if (modulekind !== 5 /* ES6 */) { + var declaration = resolver.getReferencedImportDeclaration(node); + if (declaration) { + if (declaration.kind === 223 /* ImportClause */) { + // Identifier references default import + write(getGeneratedNameForNode(declaration.parent)); + write(languageVersion === 0 /* ES3 */ ? "[\"default\"]" : ".default"); + return; + } + else if (declaration.kind === 226 /* ImportSpecifier */) { + // Identifier references named import + write(getGeneratedNameForNode(declaration.parent.parent.parent)); + var name_23 = declaration.propertyName || declaration.name; + var identifier = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, name_23); + if (languageVersion === 0 /* ES3 */ && identifier === "default") { + write("[\"default\"]"); + } + else { + write("."); + write(identifier); + } + return; + } + } + declaration = resolver.getReferencedNestedRedeclaration(node); + if (declaration) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } + if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function isNameOfNestedRedeclaration(node) { + if (languageVersion < 2 /* ES6 */) { + var parent_6 = node.parent; + switch (parent_6.kind) { + case 163 /* BindingElement */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 211 /* VariableDeclaration */: + return parent_6.name === node && resolver.isNestedRedeclaration(parent_6); + } + } + return false; + } + function emitIdentifier(node) { + if (!node.parent) { + write(node.text); + } + else if (isExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else if (isNameOfNestedRedeclaration(node)) { + write(getGeneratedNameForNode(node)); + } + else if (ts.nodeIsSynthesized(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } + function emitThis(node) { + if (resolver.getNodeCheckFlags(node) & 2 /* LexicalThis */) { + write("_this"); + } + else { + write("this"); + } + } + function emitSuper(node) { + if (languageVersion >= 2 /* ES6 */) { + write("super"); + } + else { + var flags = resolver.getNodeCheckFlags(node); + if (flags & 256 /* SuperInstance */) { + write("_super.prototype"); + } + else { + write("_super"); + } + } + } + function emitObjectBindingPattern(node) { + write("{ "); + var elements = node.elements; + emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); + write(" }"); + } + function emitArrayBindingPattern(node) { + write("["); + var elements = node.elements; + emitList(elements, 0, elements.length, /*multiLine*/ false, /*trailingComma*/ elements.hasTrailingComma); + write("]"); + } + function emitBindingElement(node) { + if (node.propertyName) { + emit(node.propertyName); + write(": "); + } + if (node.dotDotDotToken) { + write("..."); + } + if (ts.isBindingPattern(node.name)) { + emit(node.name); + } + else { + emitModuleMemberName(node); + } + emitOptional(" = ", node.initializer); + } + function emitSpreadElementExpression(node) { + write("..."); + emit(node.expression); + } + function emitYieldExpression(node) { + write(ts.tokenToString(114 /* YieldKeyword */)); + if (node.asteriskToken) { + write("*"); + } + if (node.expression) { + write(" "); + emit(node.expression); + } + } + function emitAwaitExpression(node) { + var needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); + if (needsParenthesis) { + write("("); + } + write(ts.tokenToString(114 /* YieldKeyword */)); + write(" "); + emit(node.expression); + if (needsParenthesis) { + write(")"); + } + } + function needsParenthesisForAwaitExpressionAsYield(node) { + if (node.parent.kind === 181 /* BinaryExpression */ && !ts.isAssignmentOperator(node.parent.operatorToken.kind)) { + return true; + } + else if (node.parent.kind === 182 /* ConditionalExpression */ && node.parent.condition === node) { + return true; + } + return false; + } + function needsParenthesisForPropertyAccessOrInvocation(node) { + switch (node.kind) { + case 69 /* Identifier */: + case 164 /* ArrayLiteralExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 172 /* ParenthesizedExpression */: + // This list is not exhaustive and only includes those cases that are relevant + // to the check in emitArrayLiteral. More cases can be added as needed. + return false; + } + return true; + } + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { + var pos = 0; + var group = 0; + var length = elements.length; + while (pos < length) { + // Emit using the pattern .concat(, , ...) + if (group === 1 && useConcat) { + write(".concat("); + } + else if (group > 0) { + write(", "); + } + var e = elements[pos]; + if (e.kind === 185 /* SpreadElementExpression */) { + e = e.expression; + emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); + pos++; + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 164 /* ArrayLiteralExpression */) { + write(".slice()"); + } + } + else { + var i = pos; + while (i < length && elements[i].kind !== 185 /* SpreadElementExpression */) { + i++; + } + write("["); + if (multiLine) { + increaseIndent(); + } + emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); + if (multiLine) { + decreaseIndent(); + } + write("]"); + pos = i; + } + group++; + } + if (group > 1) { + if (useConcat) { + write(")"); + } + } + } + function isSpreadElementExpression(node) { + return node.kind === 185 /* SpreadElementExpression */; + } + function emitArrayLiteral(node) { + var elements = node.elements; + if (elements.length === 0) { + write("[]"); + } + else if (languageVersion >= 2 /* ES6 */ || !ts.forEach(elements, isSpreadElementExpression)) { + write("["); + emitLinePreservingList(node, node.elements, elements.hasTrailingComma, /*spacesBetweenBraces:*/ false); + write("]"); + } + else { + emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/ (node.flags & 2048 /* MultiLine */) !== 0, + /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); + } + } + function emitObjectLiteralBody(node, numElements) { + if (numElements === 0) { + write("{}"); + return; + } + write("{"); + if (numElements > 0) { + var properties = node.properties; + // If we are not doing a downlevel transformation for object literals, + // then try to preserve the original shape of the object literal. + // Otherwise just try to preserve the formatting. + if (numElements === properties.length) { + emitLinePreservingList(node, properties, /* allowTrailingComma */ languageVersion >= 1 /* ES5 */, /* spacesBetweenBraces */ true); + } + else { + var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; + if (!multiLine) { + write(" "); + } + else { + increaseIndent(); + } + emitList(properties, 0, numElements, /*multiLine*/ multiLine, /*trailingComma*/ false); + if (!multiLine) { + write(" "); + } + else { + decreaseIndent(); + } + } + } + write("}"); + } + function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { + var multiLine = (node.flags & 2048 /* MultiLine */) !== 0; + var properties = node.properties; + write("("); + if (multiLine) { + increaseIndent(); + } + // For computed properties, we need to create a unique handle to the object + // literal so we can modify it without risking internal assignments tainting the object. + var tempVar = createAndRecordTempVariable(0 /* Auto */); + // Write out the first non-computed properties + // (or all properties if none of them are computed), + // then emit the rest through indexing on the temp variable. + emit(tempVar); + write(" = "); + emitObjectLiteralBody(node, firstComputedPropertyIndex); + for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { + writeComma(); + var property = properties[i]; + emitStart(property); + if (property.kind === 145 /* GetAccessor */ || property.kind === 146 /* SetAccessor */) { + // TODO (drosen): Reconcile with 'emitMemberFunctions'. + var accessors = ts.getAllAccessorDeclarations(node.properties, property); + if (property !== accessors.firstAccessor) { + continue; + } + write("Object.defineProperty("); + emit(tempVar); + write(", "); + emitStart(node.name); + emitExpressionForPropertyName(property.name); + emitEnd(property.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("})"); + emitEnd(property); + } + else { + emitLeadingComments(property); + emitStart(property.name); + emit(tempVar); + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + if (property.kind === 245 /* PropertyAssignment */) { + emit(property.initializer); + } + else if (property.kind === 246 /* ShorthandPropertyAssignment */) { + emitExpressionIdentifier(property.name); + } + else if (property.kind === 143 /* MethodDeclaration */) { + emitFunctionDeclaration(property); + } + else { + ts.Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); + } + } + emitEnd(property); + } + writeComma(); + emit(tempVar); + if (multiLine) { + decreaseIndent(); + writeLine(); + } + write(")"); + function writeComma() { + if (multiLine) { + write(","); + writeLine(); + } + else { + write(", "); + } + } + } + function emitObjectLiteral(node) { + var properties = node.properties; + if (languageVersion < 2 /* ES6 */) { + var numProperties = properties.length; + // Find the first computed property. + // Everything until that point can be emitted as part of the initial object literal. + var numInitialNonComputedProperties = numProperties; + for (var i = 0, n = properties.length; i < n; i++) { + if (properties[i].name.kind === 136 /* ComputedPropertyName */) { + numInitialNonComputedProperties = i; + break; + } + } + var hasComputedProperty = numInitialNonComputedProperties !== properties.length; + if (hasComputedProperty) { + emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); + return; + } + } + // Ordinary case: either the object has no computed properties + // or we're compiling with an ES6+ target. + emitObjectLiteralBody(node, properties.length); + } + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(181 /* BinaryExpression */, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); + result.left = left; + result.right = right; + return result; + } + function createPropertyAccessExpression(expression, name) { + var result = ts.createSynthesizedNode(166 /* PropertyAccessExpression */); + result.expression = parenthesizeForAccess(expression); + result.dotToken = ts.createSynthesizedNode(21 /* DotToken */); + result.name = name; + return result; + } + function createElementAccessExpression(expression, argumentExpression) { + var result = ts.createSynthesizedNode(167 /* ElementAccessExpression */); + result.expression = parenthesizeForAccess(expression); + result.argumentExpression = argumentExpression; + return result; + } + function parenthesizeForAccess(expr) { + // When diagnosing whether the expression needs parentheses, the decision should be based + // on the innermost expression in a chain of nested type assertions. + while (expr.kind === 171 /* TypeAssertionExpression */ || expr.kind === 189 /* AsExpression */) { + expr = expr.expression; + } + // isLeftHandSideExpression is almost the correct criterion for when it is not necessary + // to parenthesize the expression before a dot. The known exceptions are: + // + // NewExpression: + // new C.x -> not the same as (new C).x + // NumberLiteral + // 1.x -> not the same as (1).x + // + if (ts.isLeftHandSideExpression(expr) && + expr.kind !== 169 /* NewExpression */ && + expr.kind !== 8 /* NumericLiteral */) { + return expr; + } + var node = ts.createSynthesizedNode(172 /* ParenthesizedExpression */); + node.expression = expr; + return node; + } + function emitComputedPropertyName(node) { + write("["); + emitExpressionForPropertyName(node); + write("]"); + } + function emitMethod(node) { + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } + emit(node.name); + if (languageVersion < 2 /* ES6 */) { + write(": function "); + } + emitSignatureAndBody(node); + } + function emitPropertyAssignment(node) { + emit(node.name); + write(": "); + // This is to ensure that we emit comment in the following case: + // For example: + // obj = { + // id: /*comment1*/ ()=>void + // } + // "comment1" is not considered to be leading comment for node.initializer + // but rather a trailing comment on the previous node. + emitTrailingCommentsOfPosition(node.initializer.pos); + emit(node.initializer); + } + // Return true if identifier resolves to an exported member of a namespace + function isNamespaceExportReference(node) { + var container = resolver.getReferencedExportContainer(node); + return container && container.kind !== 248 /* SourceFile */; + } + function emitShorthandPropertyAssignment(node) { + // The name property of a short-hand property assignment is considered an expression position, so here + // we manually emit the identifier to avoid rewriting. + writeTextOfNode(currentSourceFile, node.name); + // If emitting pre-ES6 code, or if the name requires rewriting when resolved as an expression identifier, + // we emit a normal property assignment. For example: + // module m { + // export let y; + // } + // module m { + // let obj = { y }; + // } + // Here we need to emit obj = { y : m.y } regardless of the output target. + if (languageVersion < 2 /* ES6 */ || isNamespaceExportReference(node.name)) { + // Emit identifier as an identifier + write(": "); + emit(node.name); + } + if (languageVersion >= 2 /* ES6 */ && node.objectAssignmentInitializer) { + write(" = "); + emit(node.objectAssignmentInitializer); + } + } + function tryEmitConstantValue(node) { + var constantValue = tryGetConstEnumValue(node); + if (constantValue !== undefined) { + write(constantValue.toString()); + if (!compilerOptions.removeComments) { + var propertyName = node.kind === 166 /* PropertyAccessExpression */ ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + write(" /* " + propertyName + " */"); + } + return true; + } + return false; + } + function tryGetConstEnumValue(node) { + if (compilerOptions.isolatedModules) { + return undefined; + } + return node.kind === 166 /* PropertyAccessExpression */ || node.kind === 167 /* ElementAccessExpression */ + ? resolver.getConstantValue(node) + : undefined; + } + // Returns 'true' if the code was actually indented, false otherwise. + // If the code is not indented, an optional valueToWriteWhenNotIndenting will be + // emitted instead. + function indentIfOnDifferentLines(parent, node1, node2, valueToWriteWhenNotIndenting) { + var realNodesAreOnDifferentLines = !ts.nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + // Always use a newline for synthesized code if the synthesizer desires it. + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + else { + if (valueToWriteWhenNotIndenting) { + write(valueToWriteWhenNotIndenting); + } + return false; + } + } + function emitPropertyAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + var indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); + // 1 .toString is a valid property access, emit a space after the literal + // Also emit a space if expression is a integer const enum value - it will appear in generated code as numeric literal + var shouldEmitSpace; + if (!indentedBeforeDot) { + if (node.expression.kind === 8 /* NumericLiteral */) { + // check if numeric literal was originally written with a dot + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); + shouldEmitSpace = text.indexOf(ts.tokenToString(21 /* DotToken */)) < 0; + } + else { + // check if constant enum value is integer + var constantValue = tryGetConstEnumValue(node.expression); + // isFinite handles cases when constantValue is undefined + shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; + } + } + if (shouldEmitSpace) { + write(" ."); + } + else { + write("."); + } + var indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); + emit(node.name); + decreaseIndentIf(indentedBeforeDot, indentedAfterDot); + } + function emitQualifiedName(node) { + emit(node.left); + write("."); + emit(node.right); + } + function emitQualifiedNameAsExpression(node, useFallback) { + if (node.left.kind === 69 /* Identifier */) { + emitEntityNameAsExpression(node.left, useFallback); + } + else if (useFallback) { + var temp = createAndRecordTempVariable(0 /* Auto */); + write("("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(node.left, /*useFallback*/ true); + write(") && "); + emitNodeWithoutSourceMap(temp); + } + else { + emitEntityNameAsExpression(node.left, /*useFallback*/ false); + } + write("."); + emit(node.right); + } + function emitEntityNameAsExpression(node, useFallback) { + switch (node.kind) { + case 69 /* Identifier */: + if (useFallback) { + write("typeof "); + emitExpressionIdentifier(node); + write(" !== 'undefined' && "); + } + emitExpressionIdentifier(node); + break; + case 135 /* QualifiedName */: + emitQualifiedNameAsExpression(node, useFallback); + break; + } + } + function emitIndexedAccess(node) { + if (tryEmitConstantValue(node)) { + return; + } + emit(node.expression); + write("["); + emit(node.argumentExpression); + write("]"); + } + function hasSpreadElement(elements) { + return ts.forEach(elements, function (e) { return e.kind === 185 /* SpreadElementExpression */; }); + } + function skipParentheses(node) { + while (node.kind === 172 /* ParenthesizedExpression */ || node.kind === 171 /* TypeAssertionExpression */ || node.kind === 189 /* AsExpression */) { + node = node.expression; + } + return node; + } + function emitCallTarget(node) { + if (node.kind === 69 /* Identifier */ || node.kind === 97 /* ThisKeyword */ || node.kind === 95 /* SuperKeyword */) { + emit(node); + return node; + } + var temp = createAndRecordTempVariable(0 /* Auto */); + write("("); + emit(temp); + write(" = "); + emit(node); + write(")"); + return temp; + } + function emitCallWithSpread(node) { + var target; + var expr = skipParentheses(node.expression); + if (expr.kind === 166 /* PropertyAccessExpression */) { + // Target will be emitted as "this" argument + target = emitCallTarget(expr.expression); + write("."); + emit(expr.name); + } + else if (expr.kind === 167 /* ElementAccessExpression */) { + // Target will be emitted as "this" argument + target = emitCallTarget(expr.expression); + write("["); + emit(expr.argumentExpression); + write("]"); + } + else if (expr.kind === 95 /* SuperKeyword */) { + target = expr; + write("_super"); + } + else { + emit(node.expression); + } + write(".apply("); + if (target) { + if (target.kind === 95 /* SuperKeyword */) { + // Calls of form super(...) and super.foo(...) + emitThis(target); + } + else { + // Calls of form obj.foo(...) + emit(target); + } + } + else { + // Calls of form foo(...) + write("void 0"); + } + write(", "); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false, /*useConcat*/ true); + write(")"); + } + function emitCallExpression(node) { + if (languageVersion < 2 /* ES6 */ && hasSpreadElement(node.arguments)) { + emitCallWithSpread(node); + return; + } + var superCall = false; + if (node.expression.kind === 95 /* SuperKeyword */) { + emitSuper(node.expression); + superCall = true; + } + else { + emit(node.expression); + superCall = node.expression.kind === 166 /* PropertyAccessExpression */ && node.expression.expression.kind === 95 /* SuperKeyword */; + } + if (superCall && languageVersion < 2 /* ES6 */) { + write(".call("); + emitThis(node.expression); + if (node.arguments.length) { + write(", "); + emitCommaList(node.arguments); + } + write(")"); + } + else { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + function emitNewExpression(node) { + write("new "); + // Spread operator logic is supported in new expressions in ES5 using a combination + // of Function.prototype.bind() and Function.prototype.apply(). + // + // Example: + // + // var args = [1, 2, 3, 4, 5]; + // new Array(...args); + // + // is compiled into the following ES5: + // + // var args = [1, 2, 3, 4, 5]; + // new (Array.bind.apply(Array, [void 0].concat(args))); + // + // The 'thisArg' to 'bind' is ignored when invoking the result of 'bind' with 'new', + // Thus, we set it to undefined ('void 0'). + if (languageVersion === 1 /* ES5 */ && + node.arguments && + hasSpreadElement(node.arguments)) { + write("("); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiline*/ false, /*trailingComma*/ false, /*useConcat*/ false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } + } + } + function emitTaggedTemplateExpression(node) { + if (languageVersion >= 2 /* ES6 */) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } + } + function emitParenExpression(node) { + // If the node is synthesized, it means the emitter put the parentheses there, + // not the user. If we didn't want them, the emitter would not have put them + // there. + if (!ts.nodeIsSynthesized(node) && node.parent.kind !== 174 /* ArrowFunction */) { + if (node.expression.kind === 171 /* TypeAssertionExpression */ || node.expression.kind === 189 /* AsExpression */) { + var operand = node.expression.expression; + // Make sure we consider all nested cast expressions, e.g.: + // (-A).x; + while (operand.kind === 171 /* TypeAssertionExpression */ || operand.kind === 189 /* AsExpression */) { + operand = operand.expression; + } + // We have an expression of the form: (SubExpr) + // Emitting this as (SubExpr) is really not desirable. We would like to emit the subexpr as is. + // Omitting the parentheses, however, could cause change in the semantics of the generated + // code if the casted expression has a lower precedence than the rest of the expression, e.g.: + // (new A).foo should be emitted as (new A).foo and not new A.foo + // (typeof A).toString() should be emitted as (typeof A).toString() and not typeof A.toString() + // new (A()) should be emitted as new (A()) and not new A() + // (function foo() { })() should be emitted as an IIF (function foo(){})() and not declaration function foo(){} () + if (operand.kind !== 179 /* PrefixUnaryExpression */ && + operand.kind !== 177 /* VoidExpression */ && + operand.kind !== 176 /* TypeOfExpression */ && + operand.kind !== 175 /* DeleteExpression */ && + operand.kind !== 180 /* PostfixUnaryExpression */ && + operand.kind !== 169 /* NewExpression */ && + !(operand.kind === 168 /* CallExpression */ && node.parent.kind === 169 /* NewExpression */) && + !(operand.kind === 173 /* FunctionExpression */ && node.parent.kind === 168 /* CallExpression */) && + !(operand.kind === 8 /* NumericLiteral */ && node.parent.kind === 166 /* PropertyAccessExpression */)) { + emit(operand); + return; + } + } + } + write("("); + emit(node.expression); + write(")"); + } + function emitDeleteExpression(node) { + write(ts.tokenToString(78 /* DeleteKeyword */)); + write(" "); + emit(node.expression); + } + function emitVoidExpression(node) { + write(ts.tokenToString(103 /* VoidKeyword */)); + write(" "); + emit(node.expression); + } + function emitTypeOfExpression(node) { + write(ts.tokenToString(101 /* TypeOfKeyword */)); + write(" "); + emit(node.expression); + } + function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node) { + if (!isCurrentFileSystemExternalModule() || node.kind !== 69 /* Identifier */ || ts.nodeIsSynthesized(node)) { + return false; + } + var isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === 211 /* VariableDeclaration */ || node.parent.kind === 163 /* BindingElement */); + var targetDeclaration = isVariableDeclarationOrBindingElement + ? node.parent + : resolver.getReferencedValueDeclaration(node); + return isSourceFileLevelDeclarationInSystemJsModule(targetDeclaration, /*isExported*/ true); + } + function emitPrefixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + // emit + // ++x + // as + // exports('x', ++x) + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + } + write(ts.tokenToString(node.operator)); + // In some cases, we need to emit a space between the operator and the operand. One obvious case + // is when the operator is an identifier, like delete or typeof. We also need to do this for plus + // and minus expressions in certain cases. Specifically, consider the following two cases (parens + // are just for clarity of exposition, and not part of the source code): + // + // (+(+1)) + // (+(++1)) + // + // We need to emit a space in both cases. In the first case, the absence of a space will make + // the resulting expression a prefix increment operation. And in the second, it will make the resulting + // expression a prefix increment whose operand is a plus expression - (++(+x)) + // The same is true of minus of course. + if (node.operand.kind === 179 /* PrefixUnaryExpression */) { + var operand = node.operand; + if (node.operator === 35 /* PlusToken */ && (operand.operator === 35 /* PlusToken */ || operand.operator === 41 /* PlusPlusToken */)) { + write(" "); + } + else if (node.operator === 36 /* MinusToken */ && (operand.operator === 36 /* MinusToken */ || operand.operator === 42 /* MinusMinusToken */)) { + write(" "); + } + } + emit(node.operand); + if (exportChanged) { + write(")"); + } + } + function emitPostfixUnaryExpression(node) { + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { + // export function returns the value that was passes as the second argument + // however for postfix unary expressions result value should be the value before modification. + // emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)' + write("(" + exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.operand); + write("\", "); + write(ts.tokenToString(node.operator)); + emit(node.operand); + if (node.operator === 41 /* PlusPlusToken */) { + write(") - 1)"); + } + else { + write(") + 1)"); + } + } + else { + emit(node.operand); + write(ts.tokenToString(node.operator)); + } + } + function shouldHoistDeclarationInSystemJsModule(node) { + return isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ false); + } + /* + * Checks if given node is a source file level declaration (not nested in module/function). + * If 'isExported' is true - then declaration must also be exported. + * This function is used in two cases: + * - check if node is a exported source file level value to determine + * if we should also export the value after its it changed + * - check if node is a source level declaration to emit it differently, + * i.e non-exported variable statement 'var x = 1' is hoisted so + * we we emit variable statement 'var' should be dropped. + */ + function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { + if (!node || languageVersion >= 2 /* ES6 */ || !isCurrentFileSystemExternalModule()) { + return false; + } + var current = node; + while (current) { + if (current.kind === 248 /* SourceFile */) { + return !isExported || ((ts.getCombinedNodeFlags(node) & 1 /* Export */) !== 0); + } + else if (ts.isFunctionLike(current) || current.kind === 219 /* ModuleBlock */) { + return false; + } + else { + current = current.parent; + } + } + } + /** + * Emit ES7 exponentiation operator downlevel using Math.pow + * @param node a binary expression node containing exponentiationOperator (**, **=) + */ + function emitExponentiationOperator(node) { + var leftHandSideExpression = node.left; + if (node.operatorToken.kind === 60 /* AsteriskAsteriskEqualsToken */) { + var synthesizedLHS; + var shouldEmitParentheses = false; + if (ts.isElementAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(167 /* ElementAccessExpression */, /*startsOnNewLine*/ false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, /*canDefinedTempVariablesInPlaces*/ false, /*shouldEmitCommaBeforeAssignment*/ false); + synthesizedLHS.expression = identifier; + if (leftHandSideExpression.argumentExpression.kind !== 8 /* NumericLiteral */ && + leftHandSideExpression.argumentExpression.kind !== 9 /* StringLiteral */) { + var tempArgumentExpression = createAndRecordTempVariable(268435456 /* _i */); + synthesizedLHS.argumentExpression = tempArgumentExpression; + emitAssignment(tempArgumentExpression, leftHandSideExpression.argumentExpression, /*shouldEmitCommaBeforeAssignment*/ true); + } + else { + synthesizedLHS.argumentExpression = leftHandSideExpression.argumentExpression; + } + write(", "); + } + else if (ts.isPropertyAccessExpression(leftHandSideExpression)) { + shouldEmitParentheses = true; + write("("); + synthesizedLHS = ts.createSynthesizedNode(166 /* PropertyAccessExpression */, /*startsOnNewLine*/ false); + var identifier = emitTempVariableAssignment(leftHandSideExpression.expression, /*canDefinedTempVariablesInPlaces*/ false, /*shouldemitCommaBeforeAssignment*/ false); + synthesizedLHS.expression = identifier; + synthesizedLHS.dotToken = leftHandSideExpression.dotToken; + synthesizedLHS.name = leftHandSideExpression.name; + write(", "); + } + emit(synthesizedLHS || leftHandSideExpression); + write(" = "); + write("Math.pow("); + emit(synthesizedLHS || leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + if (shouldEmitParentheses) { + write(")"); + } + } + else { + write("Math.pow("); + emit(leftHandSideExpression); + write(", "); + emit(node.right); + write(")"); + } + } + function emitBinaryExpression(node) { + if (languageVersion < 2 /* ES6 */ && node.operatorToken.kind === 56 /* EqualsToken */ && + (node.left.kind === 165 /* ObjectLiteralExpression */ || node.left.kind === 164 /* ArrayLiteralExpression */)) { + emitDestructuring(node, node.parent.kind === 195 /* ExpressionStatement */); + } + else { + var exportChanged = node.operatorToken.kind >= 56 /* FirstAssignment */ && + node.operatorToken.kind <= 68 /* LastAssignment */ && + isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); + if (exportChanged) { + // emit assignment 'x y' as 'exports("x", x y)' + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.left); + write("\", "); + } + if (node.operatorToken.kind === 38 /* AsteriskAsteriskToken */ || node.operatorToken.kind === 60 /* AsteriskAsteriskEqualsToken */) { + // Downleveled emit exponentiation operator using Math.pow + emitExponentiationOperator(node); + } + else { + emit(node.left); + // Add indentation before emit the operator if the operator is on different line + // For example: + // 3 + // + 2; + // emitted as + // 3 + // + 2; + var indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== 24 /* CommaToken */ ? " " : undefined); + write(ts.tokenToString(node.operatorToken.kind)); + var indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); + emit(node.right); + decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); + } + if (exportChanged) { + write(")"); + } + } + } + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; + } + function emitConditionalExpression(node) { + emit(node.condition); + var indentedBeforeQuestion = indentIfOnDifferentLines(node, node.condition, node.questionToken, " "); + write("?"); + var indentedAfterQuestion = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue, " "); + emit(node.whenTrue); + decreaseIndentIf(indentedBeforeQuestion, indentedAfterQuestion); + var indentedBeforeColon = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken, " "); + write(":"); + var indentedAfterColon = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse, " "); + emit(node.whenFalse); + decreaseIndentIf(indentedBeforeColon, indentedAfterColon); + } + // Helper function to decrease the indent if we previously indented. Allows multiple + // previous indent values to be considered at a time. This also allows caller to just + // call this once, passing in all their appropriate indent values, instead of needing + // to call this helper function multiple times. + function decreaseIndentIf(value1, value2) { + if (value1) { + decreaseIndent(); + } + if (value2) { + decreaseIndent(); + } + } + function isSingleLineEmptyBlock(node) { + if (node && node.kind === 192 /* Block */) { + var block = node; + return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); + } + } + function emitBlock(node) { + if (isSingleLineEmptyBlock(node)) { + emitToken(15 /* OpenBraceToken */, node.pos); + write(" "); + emitToken(16 /* CloseBraceToken */, node.statements.end); + return; + } + emitToken(15 /* OpenBraceToken */, node.pos); + increaseIndent(); + scopeEmitStart(node.parent); + if (node.kind === 219 /* ModuleBlock */) { + ts.Debug.assert(node.parent.kind === 218 /* ModuleDeclaration */); + emitCaptureThisForNodeIfNecessary(node.parent); + } + emitLines(node.statements); + if (node.kind === 219 /* ModuleBlock */) { + emitTempDeclarations(/*newLine*/ true); + } + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.statements.end); + scopeEmitEnd(); + } + function emitEmbeddedStatement(node) { + if (node.kind === 192 /* Block */) { + write(" "); + emit(node); + } + else { + increaseIndent(); + writeLine(); + emit(node); + decreaseIndent(); + } + } + function emitExpressionStatement(node) { + emitParenthesizedIf(node.expression, /*parenthesized*/ node.expression.kind === 174 /* ArrowFunction */); + write(";"); + } + function emitIfStatement(node) { + var endPos = emitToken(88 /* IfKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + emit(node.expression); + emitToken(18 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.thenStatement); + if (node.elseStatement) { + writeLine(); + emitToken(80 /* ElseKeyword */, node.thenStatement.end); + if (node.elseStatement.kind === 196 /* IfStatement */) { + write(" "); + emit(node.elseStatement); + } + else { + emitEmbeddedStatement(node.elseStatement); + } + } + } + function emitDoStatement(node) { + write("do"); + emitEmbeddedStatement(node.statement); + if (node.statement.kind === 192 /* Block */) { + write(" "); + } + else { + writeLine(); + } + write("while ("); + emit(node.expression); + write(");"); + } + function emitWhileStatement(node) { + write("while ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + /** + * Returns true if start of variable declaration list was emitted. + * Returns false if nothing was written - this can happen for source file level variable declarations + * in system modules where such variable declarations are hoisted. + */ + function tryEmitStartOfVariableDeclarationList(decl, startPos) { + if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) { + // variables in variable declaration list were already hoisted + return false; + } + var tokenKind = 102 /* VarKeyword */; + if (decl && languageVersion >= 2 /* ES6 */) { + if (ts.isLet(decl)) { + tokenKind = 108 /* LetKeyword */; + } + else if (ts.isConst(decl)) { + tokenKind = 74 /* ConstKeyword */; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + write(" "); + } + else { + switch (tokenKind) { + case 102 /* VarKeyword */: + write("var "); + break; + case 108 /* LetKeyword */: + write("let "); + break; + case 74 /* ConstKeyword */: + write("const "); + break; + } + } + return true; + } + function emitVariableDeclarationListSkippingUninitializedEntries(list) { + var started = false; + for (var _a = 0, _b = list.declarations; _a < _b.length; _a++) { + var decl = _b[_a]; + if (!decl.initializer) { + continue; + } + if (!started) { + started = true; + } + else { + write(", "); + } + emit(decl); + } + return started; + } + function emitForStatement(node) { + var endPos = emitToken(86 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + if (node.initializer && node.initializer.kind === 212 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + var startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + if (startIsEmitted) { + emitCommaList(variableDeclarationList.declarations); + } + else { + emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); + } + } + else if (node.initializer) { + emit(node.initializer); + } + write(";"); + emitOptional(" ", node.condition); + write(";"); + emitOptional(" ", node.incrementor); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitForInOrForOfStatement(node) { + if (languageVersion < 2 /* ES6 */ && node.kind === 201 /* ForOfStatement */) { + return emitDownLevelForOfStatement(node); + } + var endPos = emitToken(86 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + if (node.initializer.kind === 212 /* VariableDeclarationList */) { + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length >= 1) { + tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); + emit(variableDeclarationList.declarations[0]); + } + } + else { + emit(node.initializer); + } + if (node.kind === 200 /* ForInStatement */) { + write(" in "); + } + else { + write(" of "); + } + emit(node.expression); + emitToken(18 /* CloseParenToken */, node.expression.end); + emitEmbeddedStatement(node.statement); + } + function emitDownLevelForOfStatement(node) { + // The following ES6 code: + // + // for (let v of expr) { } + // + // should be emitted as + // + // for (let _i = 0, _a = expr; _i < _a.length; _i++) { + // let v = _a[_i]; + // } + // + // where _a and _i are temps emitted to capture the RHS and the counter, + // respectively. + // When the left hand side is an expression instead of a let declaration, + // the "let v" is not emitted. + // When the left hand side is a let/const, the v is renamed if there is + // another v in scope. + // Note that all assignments to the LHS are emitted in the body, including + // all destructuring. + // Note also that because an extra statement is needed to assign to the LHS, + // for-of bodies are always emitted as blocks. + var endPos = emitToken(86 /* ForKeyword */, node.pos); + write(" "); + endPos = emitToken(17 /* OpenParenToken */, endPos); + // Do not emit the LHS let declaration yet, because it might contain destructuring. + // Do not call recordTempDeclaration because we are declaring the temps + // right here. Recording means they will be declared later. + // In the case where the user wrote an identifier as the RHS, like this: + // + // for (let v of arr) { } + // + // we don't want to emit a temporary variable for the RHS, just use it directly. + var rhsIsIdentifier = node.expression.kind === 69 /* Identifier */; + var counter = createTempVariable(268435456 /* _i */); + var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(0 /* Auto */); + // This is the let keyword for the counter and rhsReference. The let keyword for + // the LHS will be emitted inside the body. + emitStart(node.expression); + write("var "); + // _i = 0 + emitNodeWithoutSourceMap(counter); + write(" = 0"); + emitEnd(node.expression); + if (!rhsIsIdentifier) { + // , _a = expr + write(", "); + emitStart(node.expression); + emitNodeWithoutSourceMap(rhsReference); + write(" = "); + emitNodeWithoutSourceMap(node.expression); + emitEnd(node.expression); + } + write("; "); + // _i < _a.length; + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write(" < "); + emitNodeWithCommentsAndWithoutSourcemap(rhsReference); + write(".length"); + emitEnd(node.initializer); + write("; "); + // _i++) + emitStart(node.initializer); + emitNodeWithoutSourceMap(counter); + write("++"); + emitEnd(node.initializer); + emitToken(18 /* CloseParenToken */, node.expression.end); + // Body + write(" {"); + writeLine(); + increaseIndent(); + // Initialize LHS + // let v = _a[_i]; + var rhsIterationValue = createElementAccessExpression(rhsReference, counter); + emitStart(node.initializer); + if (node.initializer.kind === 212 /* VariableDeclarationList */) { + write("var "); + var variableDeclarationList = node.initializer; + if (variableDeclarationList.declarations.length > 0) { + var declaration = variableDeclarationList.declarations[0]; + if (ts.isBindingPattern(declaration.name)) { + // This works whether the declaration is a var, let, or const. + // It will use rhsIterationValue _a[_i] as the initializer. + emitDestructuring(declaration, /*isAssignmentExpressionStatement*/ false, rhsIterationValue); + } + else { + // The following call does not include the initializer, so we have + // to emit it separately. + emitNodeWithCommentsAndWithoutSourcemap(declaration); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + // It's an empty declaration list. This can only happen in an error case, if the user wrote + // for (let of []) {} + emitNodeWithoutSourceMap(createTempVariable(0 /* Auto */)); + write(" = "); + emitNodeWithoutSourceMap(rhsIterationValue); + } + } + else { + // Initializer is an expression. Emit the expression in the body, so that it's + // evaluated on every iteration. + var assignmentExpression = createBinaryExpression(node.initializer, 56 /* EqualsToken */, rhsIterationValue, /*startsOnNewLine*/ false); + if (node.initializer.kind === 164 /* ArrayLiteralExpression */ || node.initializer.kind === 165 /* ObjectLiteralExpression */) { + // This is a destructuring pattern, so call emitDestructuring instead of emit. Calling emit will not work, because it will cause + // the BinaryExpression to be passed in instead of the expression statement, which will cause emitDestructuring to crash. + emitDestructuring(assignmentExpression, /*isAssignmentExpressionStatement*/ true, /*value*/ undefined); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression); + } + } + emitEnd(node.initializer); + write(";"); + if (node.statement.kind === 192 /* Block */) { + emitLines(node.statement.statements); + } + else { + writeLine(); + emit(node.statement); + } + writeLine(); + decreaseIndent(); + write("}"); + } + function emitBreakOrContinueStatement(node) { + emitToken(node.kind === 203 /* BreakStatement */ ? 70 /* BreakKeyword */ : 75 /* ContinueKeyword */, node.pos); + emitOptional(" ", node.label); + write(";"); + } + function emitReturnStatement(node) { + emitToken(94 /* ReturnKeyword */, node.pos); + emitOptional(" ", node.expression); + write(";"); + } + function emitWithStatement(node) { + write("with ("); + emit(node.expression); + write(")"); + emitEmbeddedStatement(node.statement); + } + function emitSwitchStatement(node) { + var endPos = emitToken(96 /* SwitchKeyword */, node.pos); + write(" "); + emitToken(17 /* OpenParenToken */, endPos); + emit(node.expression); + endPos = emitToken(18 /* CloseParenToken */, node.expression.end); + write(" "); + emitCaseBlock(node.caseBlock, endPos); + } + function emitCaseBlock(node, startPos) { + emitToken(15 /* OpenBraceToken */, startPos); + increaseIndent(); + emitLines(node.clauses); + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.clauses.end); + } + function nodeStartPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function nodeEndPositionsAreOnSameLine(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, node2.end); + } + function nodeEndIsOnSameLineAsNodeStart(node1, node2) { + return ts.getLineOfLocalPosition(currentSourceFile, node1.end) === + ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); + } + function emitCaseOrDefaultClause(node) { + if (node.kind === 241 /* CaseClause */) { + write("case "); + emit(node.expression); + write(":"); + } + else { + write("default:"); + } + if (node.statements.length === 1 && nodeStartPositionsAreOnSameLine(node, node.statements[0])) { + write(" "); + emit(node.statements[0]); + } + else { + increaseIndent(); + emitLines(node.statements); + decreaseIndent(); + } + } + function emitThrowStatement(node) { + write("throw "); + emit(node.expression); + write(";"); + } + function emitTryStatement(node) { + write("try "); + emit(node.tryBlock); + emit(node.catchClause); + if (node.finallyBlock) { + writeLine(); + write("finally "); + emit(node.finallyBlock); + } + } + function emitCatchClause(node) { + writeLine(); + var endPos = emitToken(72 /* CatchKeyword */, node.pos); + write(" "); + emitToken(17 /* OpenParenToken */, endPos); + emit(node.variableDeclaration); + emitToken(18 /* CloseParenToken */, node.variableDeclaration ? node.variableDeclaration.end : endPos); + write(" "); + emitBlock(node.block); + } + function emitDebuggerStatement(node) { + emitToken(76 /* DebuggerKeyword */, node.pos); + write(";"); + } + function emitLabelledStatement(node) { + emit(node.label); + write(": "); + emit(node.statement); + } + function getContainingModule(node) { + do { + node = node.parent; + } while (node && node.kind !== 218 /* ModuleDeclaration */); + return node; + } + function emitContainingModuleName(node) { + var container = getContainingModule(node); + write(container ? getGeneratedNameForNode(container) : "exports"); + } + function emitModuleMemberName(node) { + emitStart(node.name); + if (ts.getCombinedNodeFlags(node) & 1 /* Export */) { + var container = getContainingModule(node); + if (container) { + write(getGeneratedNameForNode(container)); + write("."); + } + else if (modulekind !== 5 /* ES6 */ && modulekind !== 4 /* System */) { + write("exports."); + } + } + emitNodeWithCommentsAndWithoutSourcemap(node.name); + emitEnd(node.name); + } + function createVoidZero() { + var zero = ts.createSynthesizedNode(8 /* NumericLiteral */); + zero.text = "0"; + var result = ts.createSynthesizedNode(177 /* VoidExpression */); + result.expression = zero; + return result; + } + function emitEs6ExportDefaultCompat(node) { + if (node.parent.kind === 248 /* SourceFile */) { + ts.Debug.assert(!!(node.flags & 1024 /* Default */) || node.kind === 227 /* ExportAssignment */); + // only allow export default at a source file level + if (modulekind === 1 /* CommonJS */ || modulekind === 2 /* AMD */ || modulekind === 3 /* UMD */) { + if (!currentSourceFile.symbol.exports["___esModule"]) { + if (languageVersion === 1 /* ES5 */) { + // default value of configurable, enumerable, writable are `false`. + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else if (languageVersion === 0 /* ES3 */) { + write("exports.__esModule = true;"); + writeLine(); + } + } + } + } + } + function emitExportMemberAssignment(node) { + if (node.flags & 1 /* Export */) { + writeLine(); + emitStart(node); + // emit call to exporter only for top level nodes + if (modulekind === 4 /* System */ && node.parent === currentSourceFile) { + // emit export default as + // export("default", ) + write(exportFunctionForFile + "(\""); + if (node.flags & 1024 /* Default */) { + write("default"); + } + else { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + write("\", "); + emitDeclarationName(node); + write(")"); + } + else { + if (node.flags & 1024 /* Default */) { + emitEs6ExportDefaultCompat(node); + if (languageVersion === 0 /* ES3 */) { + write("exports[\"default\"]"); + } + else { + write("exports.default"); + } + } + else { + emitModuleMemberName(node); + } + write(" = "); + emitDeclarationName(node); + } + emitEnd(node); + write(";"); + } + } + function emitExportMemberAssignments(name) { + if (modulekind === 4 /* System */) { + return; + } + if (!exportEquals && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + for (var _a = 0, _b = exportSpecifiers[name.text]; _a < _b.length; _a++) { + var specifier = _b[_a]; + writeLine(); + emitStart(specifier.name); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + emitEnd(specifier.name); + write(" = "); + emitExpressionIdentifier(name); + write(";"); + } + } + } + function emitExportSpecifierInSystemModule(specifier) { + ts.Debug.assert(modulekind === 4 /* System */); + if (!resolver.getReferencedValueDeclaration(specifier.propertyName || specifier.name) && !resolver.isValueAliasDeclaration(specifier)) { + return; + } + writeLine(); + emitStart(specifier.name); + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write("\", "); + emitExpressionIdentifier(specifier.propertyName || specifier.name); + write(")"); + emitEnd(specifier.name); + write(";"); + } + /** + * Emit an assignment to a given identifier, 'name', with a given expression, 'value'. + * @param name an identifier as a left-hand-side operand of the assignment + * @param value an expression as a right-hand-side operand of the assignment + * @param shouldEmitCommaBeforeAssignment a boolean indicating whether to prefix an assignment with comma + */ + function emitAssignment(name, value, shouldEmitCommaBeforeAssignment) { + if (shouldEmitCommaBeforeAssignment) { + write(", "); + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(name); + write("\", "); + } + var isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === 211 /* VariableDeclaration */ || name.parent.kind === 163 /* BindingElement */); + if (isVariableDeclarationOrBindingElement) { + emitModuleMemberName(name.parent); + } + else { + emit(name); + } + write(" = "); + emit(value); + if (exportChanged) { + write(")"); + } + } + /** + * Create temporary variable, emit an assignment of the variable the given expression + * @param expression an expression to assign to the newly created temporary variable + * @param canDefineTempVariablesInPlace a boolean indicating whether you can define the temporary variable at an assignment location + * @param shouldEmitCommaBeforeAssignment a boolean indicating whether an assignment should prefix with comma + */ + function emitTempVariableAssignment(expression, canDefineTempVariablesInPlace, shouldEmitCommaBeforeAssignment) { + var identifier = createTempVariable(0 /* Auto */); + if (!canDefineTempVariablesInPlace) { + recordTempDeclaration(identifier); + } + emitAssignment(identifier, expression, shouldEmitCommaBeforeAssignment); + return identifier; + } + function emitDestructuring(root, isAssignmentExpressionStatement, value) { + var emitCount = 0; + // An exported declaration is actually emitted as an assignment (to a property on the module object), so + // temporary variables in an exported declaration need to have real declarations elsewhere + // Also temporary variables should be explicitly allocated for source level declarations when module target is system + // because actual variable declarations are hoisted + var canDefineTempVariablesInPlace = false; + if (root.kind === 211 /* VariableDeclaration */) { + var isExported = ts.getCombinedNodeFlags(root) & 1 /* Export */; + var isSourceLevelForSystemModuleKind = shouldHoistDeclarationInSystemJsModule(root); + canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; + } + else if (root.kind === 138 /* Parameter */) { + canDefineTempVariablesInPlace = true; + } + if (root.kind === 181 /* BinaryExpression */) { + emitAssignmentExpression(root); + } + else { + ts.Debug.assert(!isAssignmentExpressionStatement); + emitBindingElement(root, value); + } + /** + * Ensures that there exists a declared identifier whose value holds the given expression. + * This function is useful to ensure that the expression's value can be read from in subsequent expressions. + * Unless 'reuseIdentifierExpressions' is false, 'expr' will be returned if it is just an identifier. + * + * @param expr the expression whose value needs to be bound. + * @param reuseIdentifierExpressions true if identifier expressions can simply be returned; + * false if it is necessary to always emit an identifier. + */ + function ensureIdentifier(expr, reuseIdentifierExpressions) { + if (expr.kind === 69 /* Identifier */ && reuseIdentifierExpressions) { + return expr; + } + var identifier = emitTempVariableAssignment(expr, canDefineTempVariablesInPlace, emitCount > 0); + emitCount++; + return identifier; + } + function createDefaultValueCheck(value, defaultValue) { + // The value expression will be evaluated twice, so for anything but a simple identifier + // we need to generate a temporary variable + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + // Return the expression 'value === void 0 ? defaultValue : value' + var equals = ts.createSynthesizedNode(181 /* BinaryExpression */); + equals.left = value; + equals.operatorToken = ts.createSynthesizedNode(32 /* EqualsEqualsEqualsToken */); + equals.right = createVoidZero(); + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(182 /* ConditionalExpression */); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(53 /* QuestionToken */); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(54 /* ColonToken */); + cond.whenFalse = whenFalse; + return cond; + } + function createNumericLiteral(value) { + var node = ts.createSynthesizedNode(8 /* NumericLiteral */); + node.text = "" + value; + return node; + } + function createPropertyAccessForDestructuringProperty(object, propName) { + // We create a synthetic copy of the identifier in order to avoid the rewriting that might + // otherwise occur when the identifier is emitted. + var syntheticName = ts.createSynthesizedNode(propName.kind); + syntheticName.text = propName.text; + if (syntheticName.kind !== 69 /* Identifier */) { + return createElementAccessExpression(object, syntheticName); + } + return createPropertyAccessExpression(object, syntheticName); + } + function createSliceCall(value, sliceIndex) { + var call = ts.createSynthesizedNode(168 /* CallExpression */); + var sliceIdentifier = ts.createSynthesizedNode(69 /* Identifier */); + sliceIdentifier.text = "slice"; + call.expression = createPropertyAccessExpression(value, sliceIdentifier); + call.arguments = ts.createSynthesizedNodeArray(); + call.arguments[0] = createNumericLiteral(sliceIndex); + return call; + } + function emitObjectLiteralAssignment(target, value) { + var properties = target.properties; + if (properties.length !== 1) { + // For anything but a single element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + } + for (var _a = 0; _a < properties.length; _a++) { + var p = properties[_a]; + if (p.kind === 245 /* PropertyAssignment */ || p.kind === 246 /* ShorthandPropertyAssignment */) { + var propName = p.name; + var target_1 = p.kind === 246 /* ShorthandPropertyAssignment */ ? p : p.initializer || propName; + emitDestructuringAssignment(target_1, createPropertyAccessForDestructuringProperty(value, propName)); + } + } + } + function emitArrayLiteralAssignment(target, value) { + var elements = target.elements; + if (elements.length !== 1) { + // For anything but a single element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 187 /* OmittedExpression */) { + if (e.kind !== 185 /* SpreadElementExpression */) { + emitDestructuringAssignment(e, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === elements.length - 1) { + emitDestructuringAssignment(e.expression, createSliceCall(value, i)); + } + } + } + } + function emitDestructuringAssignment(target, value) { + if (target.kind === 246 /* ShorthandPropertyAssignment */) { + if (target.objectAssignmentInitializer) { + value = createDefaultValueCheck(value, target.objectAssignmentInitializer); + } + target = target.name; + } + else if (target.kind === 181 /* BinaryExpression */ && target.operatorToken.kind === 56 /* EqualsToken */) { + value = createDefaultValueCheck(value, target.right); + target = target.left; + } + if (target.kind === 165 /* ObjectLiteralExpression */) { + emitObjectLiteralAssignment(target, value); + } + else if (target.kind === 164 /* ArrayLiteralExpression */) { + emitArrayLiteralAssignment(target, value); + } + else { + emitAssignment(target, value, /*shouldEmitCommaBeforeAssignment*/ emitCount > 0); + emitCount++; + } + } + function emitAssignmentExpression(root) { + var target = root.left; + var value = root.right; + if (ts.isEmptyObjectLiteralOrArrayLiteral(target)) { + emit(value); + } + else if (isAssignmentExpressionStatement) { + emitDestructuringAssignment(target, value); + } + else { + if (root.parent.kind !== 172 /* ParenthesizedExpression */) { + write("("); + } + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true); + emitDestructuringAssignment(target, value); + write(", "); + emit(value); + if (root.parent.kind !== 172 /* ParenthesizedExpression */) { + write(")"); + } + } + } + function emitBindingElement(target, value) { + if (target.initializer) { + // Combine value and initializer + value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; + } + else if (!value) { + // Use 'void 0' in absence of value and initializer + value = createVoidZero(); + } + if (ts.isBindingPattern(target.name)) { + var pattern = target.name; + var elements = pattern.elements; + var numElements = elements.length; + if (numElements !== 1) { + // For anything other than a single-element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. Additionally, if we have zero elements + // we need to emit *something* to ensure that in case a 'var' keyword was already emitted, + // so in that case, we'll intentionally create that temporary. + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0); + } + for (var i = 0; i < numElements; i++) { + var element = elements[i]; + if (pattern.kind === 161 /* ObjectBindingPattern */) { + // Rewrite element to a declaration with an initializer that fetches property + var propName = element.propertyName || element.name; + emitBindingElement(element, createPropertyAccessForDestructuringProperty(value, propName)); + } + else if (element.kind !== 187 /* OmittedExpression */) { + if (!element.dotDotDotToken) { + // Rewrite element to a declaration that accesses array element at index i + emitBindingElement(element, createElementAccessExpression(value, createNumericLiteral(i))); + } + else if (i === numElements - 1) { + emitBindingElement(element, createSliceCall(value, i)); + } + } + } + } + else { + emitAssignment(target.name, value, /*shouldEmitCommaBeforeAssignment*/ emitCount > 0); + emitCount++; + } + } + } + function emitVariableDeclaration(node) { + if (ts.isBindingPattern(node.name)) { + if (languageVersion < 2 /* ES6 */) { + emitDestructuring(node, /*isAssignmentExpressionStatement*/ false); + } + else { + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + else { + var initializer = node.initializer; + if (!initializer && languageVersion < 2 /* ES6 */) { + // downlevel emit for non-initialized let bindings defined in loops + // for (...) { let x; } + // should be + // for (...) { var = void 0; } + // this is necessary to preserve ES6 semantic in scenarios like + // for (...) { let x; console.log(x); x = 1 } // assignment on one iteration should not affect other iterations + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 16384 /* BlockScopedBindingInLoop */) && + (getCombinedFlagsForIdentifier(node.name) & 16384 /* Let */); + // NOTE: default initialization should not be added to let bindings in for-in\for-of statements + if (isUninitializedLet && + node.parent.parent.kind !== 200 /* ForInStatement */ && + node.parent.parent.kind !== 201 /* ForOfStatement */) { + initializer = createVoidZero(); + } + } + var exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); + if (exportChanged) { + write(exportFunctionForFile + "(\""); + emitNodeWithCommentsAndWithoutSourcemap(node.name); + write("\", "); + } + emitModuleMemberName(node); + emitOptional(" = ", initializer); + if (exportChanged) { + write(")"); + } + } + } + function emitExportVariableAssignments(node) { + if (node.kind === 187 /* OmittedExpression */) { + return; + } + var name = node.name; + if (name.kind === 69 /* Identifier */) { + emitExportMemberAssignments(name); + } + else if (ts.isBindingPattern(name)) { + ts.forEach(name.elements, emitExportVariableAssignments); + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 211 /* VariableDeclaration */ && node.parent.kind !== 163 /* BindingElement */)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function isES6ExportedDeclaration(node) { + return !!(node.flags & 1 /* Export */) && + modulekind === 5 /* ES6 */ && + node.parent.kind === 248 /* SourceFile */; + } + function emitVariableStatement(node) { + var startIsEmitted = false; + if (node.flags & 1 /* Export */) { + if (isES6ExportedDeclaration(node)) { + // Exported ES6 module member + write("export "); + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + } + else { + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); + } + if (startIsEmitted) { + emitCommaList(node.declarationList.declarations); + write(";"); + } + else { + var atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); + if (atLeastOneItem) { + write(";"); + } + } + if (modulekind !== 5 /* ES6 */ && node.parent === currentSourceFile) { + ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); + } + } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + // If we're not exporting the variables, there's nothing special here. + // Always emit comments for these nodes. + if (!(node.flags & 1 /* Export */)) { + return true; + } + // If we are exporting, but it's a top-level ES6 module exports, + // we'll emit the declaration list verbatim, so emit comments too. + if (isES6ExportedDeclaration(node)) { + return true; + } + // Otherwise, only emit if we have at least one initializer present. + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } + function emitParameter(node) { + if (languageVersion < 2 /* ES6 */) { + if (ts.isBindingPattern(node.name)) { + var name_24 = createTempVariable(0 /* Auto */); + if (!tempParameters) { + tempParameters = []; + } + tempParameters.push(name_24); + emit(name_24); + } + else { + emit(node.name); + } + } + else { + if (node.dotDotDotToken) { + write("..."); + } + emit(node.name); + emitOptional(" = ", node.initializer); + } + } + function emitDefaultValueAssignments(node) { + if (languageVersion < 2 /* ES6 */) { + var tempIndex = 0; + ts.forEach(node.parameters, function (parameter) { + // A rest parameter cannot have a binding pattern or an initializer, + // so let's just ignore it. + if (parameter.dotDotDotToken) { + return; + } + var paramName = parameter.name, initializer = parameter.initializer; + if (ts.isBindingPattern(paramName)) { + // In cases where a binding pattern is simply '[]' or '{}', + // we usually don't want to emit a var declaration; however, in the presence + // of an initializer, we must emit that expression to preserve side effects. + var hasBindingElements = paramName.elements.length > 0; + if (hasBindingElements || initializer) { + writeLine(); + write("var "); + if (hasBindingElements) { + emitDestructuring(parameter, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]); + } + else { + emit(tempParameters[tempIndex]); + write(" = "); + emit(initializer); + } + write(";"); + tempIndex++; + } + } + else if (initializer) { + writeLine(); + emitStart(parameter); + write("if ("); + emitNodeWithoutSourceMap(paramName); + write(" === void 0)"); + emitEnd(parameter); + write(" { "); + emitStart(parameter); + emitNodeWithCommentsAndWithoutSourcemap(paramName); + write(" = "); + emitNodeWithCommentsAndWithoutSourcemap(initializer); + emitEnd(parameter); + write("; }"); + } + }); + } + } + function emitRestParameter(node) { + if (languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node)) { + var restIndex = node.parameters.length - 1; + var restParam = node.parameters[restIndex]; + // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. + if (ts.isBindingPattern(restParam.name)) { + return; + } + var tempName = createTempVariable(268435456 /* _i */).text; + writeLine(); + emitLeadingComments(restParam); + emitStart(restParam); + write("var "); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write(" = [];"); + emitEnd(restParam); + emitTrailingComments(restParam); + writeLine(); + write("for ("); + emitStart(restParam); + write("var " + tempName + " = " + restIndex + ";"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + " < arguments.length;"); + emitEnd(restParam); + write(" "); + emitStart(restParam); + write(tempName + "++"); + emitEnd(restParam); + write(") {"); + increaseIndent(); + writeLine(); + emitStart(restParam); + emitNodeWithCommentsAndWithoutSourcemap(restParam.name); + write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];"); + emitEnd(restParam); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitAccessor(node) { + write(node.kind === 145 /* GetAccessor */ ? "get " : "set "); + emit(node.name); + emitSignatureAndBody(node); + } + function shouldEmitAsArrowFunction(node) { + return node.kind === 174 /* ArrowFunction */ && languageVersion >= 2 /* ES6 */; + } + function emitDeclarationName(node) { + if (node.name) { + emitNodeWithCommentsAndWithoutSourcemap(node.name); + } + else { + write(getGeneratedNameForNode(node)); + } + } + function shouldEmitFunctionName(node) { + if (node.kind === 173 /* FunctionExpression */) { + // Emit name if one is present + return !!node.name; + } + if (node.kind === 213 /* FunctionDeclaration */) { + // Emit name if one is present, or emit generated name in down-level case (for export default case) + return !!node.name || languageVersion < 2 /* ES6 */; + } + } + function emitFunctionDeclaration(node) { + if (ts.nodeIsMissing(node.body)) { + return emitCommentsOnNotEmittedNode(node); + } + // TODO (yuisu) : we should not have special cases to condition emitting comments + // but have one place to fix check for these conditions. + if (node.kind !== 143 /* MethodDeclaration */ && node.kind !== 142 /* MethodSignature */ && + node.parent && node.parent.kind !== 245 /* PropertyAssignment */ && + node.parent.kind !== 168 /* CallExpression */) { + // 1. Methods will emit the comments as part of emitting method declaration + // 2. If the function is a property of object literal, emitting leading-comments + // is done by emitNodeWithoutSourceMap which then call this function. + // In particular, we would like to avoid emit comments twice in following case: + // For example: + // var obj = { + // id: + // /*comment*/ () => void + // } + // 3. If the function is an argument in call expression, emitting of comments will be + // taken care of in emit list of arguments inside of emitCallexpression + emitLeadingComments(node); + } + emitStart(node); + // For targeting below es6, emit functions-like declaration including arrow function using function keyword. + // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead + if (!shouldEmitAsArrowFunction(node)) { + if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024 /* Default */) { + write("default "); + } + } + write("function"); + if (languageVersion >= 2 /* ES6 */ && node.asteriskToken) { + write("*"); + } + write(" "); + } + if (shouldEmitFunctionName(node)) { + emitDeclarationName(node); + } + emitSignatureAndBody(node); + if (modulekind !== 5 /* ES6 */ && node.kind === 213 /* FunctionDeclaration */ && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + emitEnd(node); + if (node.kind !== 143 /* MethodDeclaration */ && node.kind !== 142 /* MethodSignature */) { + emitTrailingComments(node); + } + } + function emitCaptureThisForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 4 /* CaptureThis */) { + writeLine(); + emitStart(node); + write("var _this = this;"); + emitEnd(node); + } + } + function emitSignatureParameters(node) { + increaseIndent(); + write("("); + if (node) { + var parameters = node.parameters; + var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node) ? 1 : 0; + emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false); + } + write(")"); + decreaseIndent(); + } + function emitSignatureParametersForArrow(node) { + // Check whether the parameter list needs parentheses and preserve no-parenthesis + if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) { + emit(node.parameters[0]); + return; + } + emitSignatureParameters(node); + } + function emitAsyncFunctionBodyForES6(node) { + var promiseConstructor = ts.getEntityNameFromTypeNode(node.type); + var isArrowFunction = node.kind === 174 /* ArrowFunction */; + var hasLexicalArguments = (resolver.getNodeCheckFlags(node) & 4096 /* CaptureArguments */) !== 0; + var args; + // An async function is emit as an outer function that calls an inner + // generator function. To preserve lexical bindings, we pass the current + // `this` and `arguments` objects to `__awaiter`. The generator function + // passed to `__awaiter` is executed inside of the callback to the + // promise constructor. + // + // The emit for an async arrow without a lexical `arguments` binding might be: + // + // // input + // let a = async (b) => { await b; } + // + // // output + // let a = (b) => __awaiter(this, void 0, void 0, function* () { + // yield b; + // }); + // + // The emit for an async arrow with a lexical `arguments` binding might be: + // + // // input + // let a = async (b) => { await arguments[0]; } + // + // // output + // let a = (b) => __awaiter(this, arguments, void 0, function* (arguments) { + // yield arguments[0]; + // }); + // + // The emit for an async function expression without a lexical `arguments` binding + // might be: + // + // // input + // let a = async function (b) { + // await b; + // } + // + // // output + // let a = function (b) { + // return __awaiter(this, void 0, void 0, function* () { + // yield b; + // }); + // } + // + // The emit for an async function expression with a lexical `arguments` binding + // might be: + // + // // input + // let a = async function (b) { + // await arguments[0]; + // } + // + // // output + // let a = function (b) { + // return __awaiter(this, arguments, void 0, function* (_arguments) { + // yield _arguments[0]; + // }); + // } + // + // The emit for an async function expression with a lexical `arguments` binding + // and a return type annotation might be: + // + // // input + // let a = async function (b): MyPromise { + // await arguments[0]; + // } + // + // // output + // let a = function (b) { + // return __awaiter(this, arguments, MyPromise, function* (_arguments) { + // yield _arguments[0]; + // }); + // } + // + // If this is not an async arrow, emit the opening brace of the function body + // and the start of the return statement. + if (!isArrowFunction) { + write(" {"); + increaseIndent(); + writeLine(); + write("return"); + } + write(" __awaiter(this"); + if (hasLexicalArguments) { + write(", arguments"); + } + else { + write(", void 0"); + } + if (promiseConstructor) { + write(", "); + emitNodeWithoutSourceMap(promiseConstructor); + } + else { + write(", Promise"); + } + // Emit the call to __awaiter. + if (hasLexicalArguments) { + write(", function* (_arguments)"); + } + else { + write(", function* ()"); + } + // Emit the signature and body for the inner generator function. + emitFunctionBody(node); + write(")"); + // If this is not an async arrow, emit the closing brace of the outer function body. + if (!isArrowFunction) { + write(";"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitFunctionBody(node) { + if (!node.body) { + // There can be no body when there are parse errors. Just emit an empty block + // in that case. + write(" { }"); + } + else { + if (node.body.kind === 192 /* Block */) { + emitBlockFunctionBody(node, node.body); + } + else { + emitExpressionFunctionBody(node, node.body); + } + } + } + function emitSignatureAndBody(node) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + // When targeting ES6, emit arrow function natively in ES6 + if (shouldEmitAsArrowFunction(node)) { + emitSignatureParametersForArrow(node); + write(" =>"); + } + else { + emitSignatureParameters(node); + } + var isAsync = ts.isAsyncFunctionLike(node); + if (isAsync && languageVersion === 2 /* ES6 */) { + emitAsyncFunctionBodyForES6(node); + } + else { + emitFunctionBody(node); + } + if (!isES6ExportedDeclaration(node)) { + emitExportMemberAssignment(node); + } + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + // Returns true if any preamble code was emitted. + function emitFunctionBodyPreamble(node) { + emitCaptureThisForNodeIfNecessary(node); + emitDefaultValueAssignments(node); + emitRestParameter(node); + } + function emitExpressionFunctionBody(node, body) { + if (languageVersion < 2 /* ES6 */ || node.flags & 512 /* Async */) { + emitDownLevelExpressionFunctionBody(node, body); + return; + } + // For es6 and higher we can emit the expression as is. However, in the case + // where the expression might end up looking like a block when emitted, we'll + // also wrap it in parentheses first. For example if you have: a => {} + // then we need to generate: a => ({}) + write(" "); + // Unwrap all type assertions. + var current = body; + while (current.kind === 171 /* TypeAssertionExpression */) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 165 /* ObjectLiteralExpression */); + } + function emitDownLevelExpressionFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + increaseIndent(); + var outPos = writer.getTextPos(); + emitDetachedComments(node.body); + emitFunctionBodyPreamble(node); + var preambleEmitted = writer.getTextPos() !== outPos; + decreaseIndent(); + // If we didn't have to emit any preamble code, then attempt to keep the arrow + // function on one line. + if (!preambleEmitted && nodeStartPositionsAreOnSameLine(node, body)) { + write(" "); + emitStart(body); + write("return "); + emit(body); + emitEnd(body); + write(";"); + emitTempDeclarations(/*newLine*/ false); + write(" "); + } + else { + increaseIndent(); + writeLine(); + emitLeadingComments(node.body); + write("return "); + emit(body); + write(";"); + emitTrailingComments(node.body); + emitTempDeclarations(/*newLine*/ true); + decreaseIndent(); + writeLine(); + } + emitStart(node.body); + write("}"); + emitEnd(node.body); + scopeEmitEnd(); + } + function emitBlockFunctionBody(node, body) { + write(" {"); + scopeEmitStart(node); + var initialTextPos = writer.getTextPos(); + increaseIndent(); + emitDetachedComments(body.statements); + // Emit all the directive prologues (like "use strict"). These have to come before + // any other preamble code we write (like parameter initializers). + var startIndex = emitDirectivePrologues(body.statements, /*startWithNewLine*/ true); + emitFunctionBodyPreamble(node); + decreaseIndent(); + var preambleEmitted = writer.getTextPos() !== initialTextPos; + if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { + for (var _a = 0, _b = body.statements; _a < _b.length; _a++) { + var statement = _b[_a]; + write(" "); + emit(statement); + } + emitTempDeclarations(/*newLine*/ false); + write(" "); + emitLeadingCommentsOfPosition(body.statements.end); + } + else { + increaseIndent(); + emitLinesStartingAt(body.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + writeLine(); + emitLeadingCommentsOfPosition(body.statements.end); + decreaseIndent(); + } + emitToken(16 /* CloseBraceToken */, body.statements.end); + scopeEmitEnd(); + } + function findInitialSuperCall(ctor) { + if (ctor.body) { + var statement = ctor.body.statements[0]; + if (statement && statement.kind === 195 /* ExpressionStatement */) { + var expr = statement.expression; + if (expr && expr.kind === 168 /* CallExpression */) { + var func = expr.expression; + if (func && func.kind === 95 /* SuperKeyword */) { + return statement; + } + } + } + } + } + function emitParameterPropertyAssignments(node) { + ts.forEach(node.parameters, function (param) { + if (param.flags & 112 /* AccessibilityModifier */) { + writeLine(); + emitStart(param); + emitStart(param.name); + write("this."); + emitNodeWithoutSourceMap(param.name); + emitEnd(param.name); + write(" = "); + emit(param.name); + write(";"); + emitEnd(param); + } + }); + } + function emitMemberAccessForPropertyName(memberName) { + // This does not emit source map because it is emitted by caller as caller + // is aware how the property name changes to the property access + // eg. public x = 10; becomes this.x and static x = 10 becomes className.x + if (memberName.kind === 9 /* StringLiteral */ || memberName.kind === 8 /* NumericLiteral */) { + write("["); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + write("]"); + } + else if (memberName.kind === 136 /* ComputedPropertyName */) { + emitComputedPropertyName(memberName); + } + else { + write("."); + emitNodeWithCommentsAndWithoutSourcemap(memberName); + } + } + function getInitializedProperties(node, isStatic) { + var properties = []; + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if (member.kind === 141 /* PropertyDeclaration */ && isStatic === ((member.flags & 128 /* Static */) !== 0) && member.initializer) { + properties.push(member); + } + } + return properties; + } + function emitPropertyDeclarations(node, properties) { + for (var _a = 0; _a < properties.length; _a++) { + var property = properties[_a]; + emitPropertyDeclaration(node, property); + } + } + function emitPropertyDeclaration(node, property, receiver, isExpression) { + writeLine(); + emitLeadingComments(property); + emitStart(property); + emitStart(property.name); + if (receiver) { + emit(receiver); + } + else { + if (property.flags & 128 /* Static */) { + emitDeclarationName(node); + } + else { + write("this"); + } + } + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + write(" = "); + emit(property.initializer); + if (!isExpression) { + write(";"); + } + emitEnd(property); + emitTrailingComments(property); + } + function emitMemberFunctionsForES5AndLower(node) { + ts.forEach(node.members, function (member) { + if (member.kind === 191 /* SemicolonClassElement */) { + writeLine(); + write(";"); + } + else if (member.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */) { + if (!member.body) { + return emitCommentsOnNotEmittedNode(member); + } + writeLine(); + emitLeadingComments(member); + emitStart(member); + emitStart(member.name); + emitClassMemberPrefix(node, member); + emitMemberAccessForPropertyName(member.name); + emitEnd(member.name); + write(" = "); + emitFunctionDeclaration(member); + emitEnd(member); + write(";"); + emitTrailingComments(member); + } + else if (member.kind === 145 /* GetAccessor */ || member.kind === 146 /* SetAccessor */) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor) { + writeLine(); + emitStart(member); + write("Object.defineProperty("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine(); + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("});"); + emitEnd(member); + } + } + }); + } + function emitMemberFunctionsForES6AndHigher(node) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + if ((member.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */) && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + else if (member.kind === 143 /* MethodDeclaration */ || + member.kind === 145 /* GetAccessor */ || + member.kind === 146 /* SetAccessor */) { + writeLine(); + emitLeadingComments(member); + emitStart(member); + if (member.flags & 128 /* Static */) { + write("static "); + } + if (member.kind === 145 /* GetAccessor */) { + write("get "); + } + else if (member.kind === 146 /* SetAccessor */) { + write("set "); + } + if (member.asteriskToken) { + write("*"); + } + emit(member.name); + emitSignatureAndBody(member); + emitEnd(member); + emitTrailingComments(member); + } + else if (member.kind === 191 /* SemicolonClassElement */) { + writeLine(); + write(";"); + } + } + } + function emitConstructor(node, baseTypeElement) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + emitConstructorWorker(node, baseTypeElement); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + function emitConstructorWorker(node, baseTypeElement) { + // Check if we have property assignment inside class declaration. + // If there is property assignment, we need to emit constructor whether users define it or not + // If there is no property assignment, we can omit constructor if users do not define it + var hasInstancePropertyWithInitializer = false; + // Emit the constructor overload pinned comments + ts.forEach(node.members, function (member) { + if (member.kind === 144 /* Constructor */ && !member.body) { + emitCommentsOnNotEmittedNode(member); + } + // Check if there is any non-static property assignment + if (member.kind === 141 /* PropertyDeclaration */ && member.initializer && (member.flags & 128 /* Static */) === 0) { + hasInstancePropertyWithInitializer = true; + } + }); + var ctor = ts.getFirstConstructorWithBody(node); + // For target ES6 and above, if there is no user-defined constructor and there is no property assignment + // do not emit constructor in class declaration. + if (languageVersion >= 2 /* ES6 */ && !ctor && !hasInstancePropertyWithInitializer) { + return; + } + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + if (languageVersion < 2 /* ES6 */) { + write("function "); + emitDeclarationName(node); + emitSignatureParameters(ctor); + } + else { + write("constructor"); + if (ctor) { + emitSignatureParameters(ctor); + } + else { + // Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation. + // If constructor is empty, then, + // If ClassHeritageopt is present, then + // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. + // Else, + // Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition + if (baseTypeElement) { + write("(...args)"); + } + else { + write("()"); + } + } + } + var startIndex = 0; + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + // Emit all the directive prologues (like "use strict"). These have to come before + // any other preamble code we write (like parameter initializers). + startIndex = emitDirectivePrologues(ctor.body.statements, /*startWithNewLine*/ true); + emitDetachedComments(ctor.body.statements); + } + emitCaptureThisForNodeIfNecessary(node); + var superCall; + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeElement) { + superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeElement) { + writeLine(); + emitStart(baseTypeElement); + if (languageVersion < 2 /* ES6 */) { + write("_super.apply(this, arguments);"); + } + else { + write("super(...args);"); + } + emitEnd(baseTypeElement); + } + } + emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ false)); + if (ctor) { + var statements = ctor.body.statements; + if (superCall) { + statements = statements.slice(1); + } + emitLinesStartingAt(statements, startIndex); + } + emitTempDeclarations(/*newLine*/ true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition(ctor.body.statements.end); + } + decreaseIndent(); + emitToken(16 /* CloseBraceToken */, ctor ? ctor.body.statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + } + function emitClassExpression(node) { + return emitClassLikeDeclaration(node); + } + function emitClassDeclaration(node) { + return emitClassLikeDeclaration(node); + } + function emitClassLikeDeclaration(node) { + if (languageVersion < 2 /* ES6 */) { + emitClassLikeDeclarationBelowES6(node); + } + else { + emitClassLikeDeclarationForES6AndHigher(node); + } + if (modulekind !== 5 /* ES6 */ && node.parent === currentSourceFile && node.name) { + emitExportMemberAssignments(node.name); + } + } + function emitClassLikeDeclarationForES6AndHigher(node) { + var thisNodeIsDecorated = ts.nodeIsDecorated(node); + if (node.kind === 214 /* ClassDeclaration */) { + if (thisNodeIsDecorated) { + // To preserve the correct runtime semantics when decorators are applied to the class, + // the emit needs to follow one of the following rules: + // + // * For a local class declaration: + // + // @dec class C { + // } + // + // The emit should be: + // + // let C = class { + // }; + // C = __decorate([dec], C); + // + // * For an exported class declaration: + // + // @dec export class C { + // } + // + // The emit should be: + // + // export let C = class { + // }; + // C = __decorate([dec], C); + // + // * For a default export of a class declaration with a name: + // + // @dec default export class C { + // } + // + // The emit should be: + // + // let C = class { + // } + // C = __decorate([dec], C); + // export default C; + // + // * For a default export of a class declaration without a name: + // + // @dec default export class { + // } + // + // The emit should be: + // + // let _default = class { + // } + // _default = __decorate([dec], _default); + // export default _default; + // + if (isES6ExportedDeclaration(node) && !(node.flags & 1024 /* Default */)) { + write("export "); + } + write("let "); + emitDeclarationName(node); + write(" = "); + } + else if (isES6ExportedDeclaration(node)) { + write("export "); + if (node.flags & 1024 /* Default */) { + write("default "); + } + } + } + // If the class has static properties, and it's a class expression, then we'll need + // to specialize the emit a bit. for a class expression of the form: + // + // class C { static a = 1; static b = 2; ... } + // + // We'll emit: + // + // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // + // This keeps the expression as an expression, while ensuring that the static parts + // of it have been initialized by the time it is used. + var staticProperties = getInitializedProperties(node, /*static:*/ true); + var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 186 /* ClassExpression */; + var tempVariable; + if (isClassExpressionWithStaticProperties) { + tempVariable = createAndRecordTempVariable(0 /* Auto */); + write("("); + increaseIndent(); + emit(tempVariable); + write(" = "); + } + write("class"); + // emit name if + // - node has a name + // - this is default export with static initializers + if ((node.name || (node.flags & 1024 /* Default */ && staticProperties.length > 0)) && !thisNodeIsDecorated) { + write(" "); + emitDeclarationName(node); + } + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write(" extends "); + emit(baseTypeNode.expression); + } + write(" {"); + increaseIndent(); + scopeEmitStart(node); + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES6AndHigher(node); + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. + // For a decorated class, we need to assign its name (if it has one). This is because we emit + // the class as a class expression to avoid the double-binding of the identifier: + // + // let C = class { + // } + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // + if (thisNodeIsDecorated) { + write(";"); + } + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + if (isClassExpressionWithStaticProperties) { + for (var _a = 0; _a < staticProperties.length; _a++) { + var property = staticProperties[_a]; + write(","); + writeLine(); + emitPropertyDeclaration(node, property, /*receiver:*/ tempVariable, /*isExpression:*/ true); + } + write(","); + writeLine(); + emit(tempVariable); + decreaseIndent(); + write(")"); + } + else { + writeLine(); + emitPropertyDeclarations(node, staticProperties); + emitDecoratorsOfClass(node); + } + // If this is an exported class, but not on the top level (i.e. on an internal + // module), export it + if (!isES6ExportedDeclaration(node) && (node.flags & 1 /* Export */)) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } + else if (isES6ExportedDeclaration(node) && (node.flags & 1024 /* Default */) && thisNodeIsDecorated) { + // if this is a top level default export of decorated class, write the export after the declaration. + writeLine(); + write("export default "); + emitDeclarationName(node); + write(";"); + } + } + function emitClassLikeDeclarationBelowES6(node) { + if (node.kind === 214 /* ClassDeclaration */) { + // source file level classes in system modules are hoisted so 'var's for them are already defined + if (!shouldHoistDeclarationInSystemJsModule(node)) { + write("var "); + } + emitDeclarationName(node); + write(" = "); + } + write("(function ("); + var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (baseTypeNode) { + write("_super"); + } + write(") {"); + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + var saveComputedPropertyNamesToGeneratedNames = computedPropertyNamesToGeneratedNames; + tempFlags = 0; + tempVariables = undefined; + tempParameters = undefined; + computedPropertyNamesToGeneratedNames = undefined; + increaseIndent(); + scopeEmitStart(node); + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + write("__extends("); + emitDeclarationName(node); + write(", _super);"); + emitEnd(baseTypeNode); + } + writeLine(); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES5AndLower(node); + emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ true)); + writeLine(); + emitDecoratorsOfClass(node); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end, function () { + write("return "); + emitDeclarationName(node); + }); + write(";"); + emitTempDeclarations(/*newLine*/ true); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + computedPropertyNamesToGeneratedNames = saveComputedPropertyNamesToGeneratedNames; + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + emitStart(node); + write(")("); + if (baseTypeNode) { + emit(baseTypeNode.expression); + } + write(")"); + if (node.kind === 214 /* ClassDeclaration */) { + write(";"); + } + emitEnd(node); + if (node.kind === 214 /* ClassDeclaration */) { + emitExportMemberAssignment(node); + } + } + function emitClassMemberPrefix(node, member) { + emitDeclarationName(node); + if (!(member.flags & 128 /* Static */)) { + write(".prototype"); + } + } + function emitDecoratorsOfClass(node) { + emitDecoratorsOfMembers(node, /*staticFlag*/ 0); + emitDecoratorsOfMembers(node, 128 /* Static */); + emitDecoratorsOfConstructor(node); + } + function emitDecoratorsOfConstructor(node) { + var decorators = node.decorators; + var constructor = ts.getFirstConstructorWithBody(node); + var hasDecoratedParameters = constructor && ts.forEach(constructor.parameters, ts.nodeIsDecorated); + // skip decoration of the constructor if neither it nor its parameters are decorated + if (!decorators && !hasDecoratedParameters) { + return; + } + // Emit the call to __decorate. Given the class: + // + // @dec + // class C { + // } + // + // The emit for the class is: + // + // C = __decorate([dec], C); + // + writeLine(); + emitStart(node); + emitDeclarationName(node); + write(" = __decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(constructor, /*leadingComma*/ argumentsWritten > 0); + emitSerializedTypeMetadata(node, /*leadingComma*/ argumentsWritten >= 0); + decreaseIndent(); + writeLine(); + write("], "); + emitDeclarationName(node); + write(");"); + emitEnd(node); + writeLine(); + } + function emitDecoratorsOfMembers(node, staticFlag) { + for (var _a = 0, _b = node.members; _a < _b.length; _a++) { + var member = _b[_a]; + // only emit members in the correct group + if ((member.flags & 128 /* Static */) !== staticFlag) { + continue; + } + // skip members that cannot be decorated (such as the constructor) + if (!ts.nodeCanBeDecorated(member)) { + continue; + } + // skip a member if it or any of its parameters are not decorated + if (!ts.nodeOrChildIsDecorated(member)) { + continue; + } + // skip an accessor declaration if it is not the first accessor + var decorators = void 0; + var functionLikeMember = void 0; + if (ts.isAccessor(member)) { + var accessors = ts.getAllAccessorDeclarations(node.members, member); + if (member !== accessors.firstAccessor) { + continue; + } + // get the decorators from the first accessor with decorators + decorators = accessors.firstAccessor.decorators; + if (!decorators && accessors.secondAccessor) { + decorators = accessors.secondAccessor.decorators; + } + // we only decorate parameters of the set accessor + functionLikeMember = accessors.setAccessor; + } + else { + decorators = member.decorators; + // we only decorate the parameters here if this is a method + if (member.kind === 143 /* MethodDeclaration */) { + functionLikeMember = member; + } + } + // Emit the call to __decorate. Given the following: + // + // class C { + // @dec method(@dec2 x) {} + // @dec get accessor() {} + // @dec prop; + // } + // + // The emit for a method is: + // + // __decorate([ + // dec, + // __param(0, dec2), + // __metadata("design:type", Function), + // __metadata("design:paramtypes", [Object]), + // __metadata("design:returntype", void 0) + // ], C.prototype, "method", undefined); + // + // The emit for an accessor is: + // + // __decorate([ + // dec + // ], C.prototype, "accessor", undefined); + // + // The emit for a property is: + // + // __decorate([ + // dec + // ], C.prototype, "prop"); + // + writeLine(); + emitStart(member); + write("__decorate(["); + increaseIndent(); + writeLine(); + var decoratorCount = decorators ? decorators.length : 0; + var argumentsWritten = emitList(decorators, 0, decoratorCount, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ false, /*noTrailingNewLine*/ true, function (decorator) { + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + }); + argumentsWritten += emitDecoratorsOfParameters(functionLikeMember, argumentsWritten > 0); + emitSerializedTypeMetadata(member, argumentsWritten > 0); + decreaseIndent(); + writeLine(); + write("], "); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + if (languageVersion > 0 /* ES3 */) { + if (member.kind !== 141 /* PropertyDeclaration */) { + // We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly. + // We have this extra argument here so that we can inject an explicit property descriptor at a later date. + write(", null"); + } + else { + // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it + // should not invoke `Object.getOwnPropertyDescriptor`. + write(", void 0"); + } + } + write(");"); + emitEnd(member); + writeLine(); + } + } + function emitDecoratorsOfParameters(node, leadingComma) { + var argumentsWritten = 0; + if (node) { + var parameterIndex = 0; + for (var _a = 0, _b = node.parameters; _a < _b.length; _a++) { + var parameter = _b[_a]; + if (ts.nodeIsDecorated(parameter)) { + var decorators = parameter.decorators; + argumentsWritten += emitList(decorators, 0, decorators.length, /*multiLine*/ true, /*trailingComma*/ false, /*leadingComma*/ leadingComma, /*noTrailingNewLine*/ true, function (decorator) { + emitStart(decorator); + write("__param(" + parameterIndex + ", "); + emit(decorator.expression); + write(")"); + emitEnd(decorator); + }); + leadingComma = true; + } + ++parameterIndex; + } + } + return argumentsWritten; + } + function shouldEmitTypeMetadata(node) { + // This method determines whether to emit the "design:type" metadata based on the node's kind. + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // compiler option is set. + switch (node.kind) { + case 143 /* MethodDeclaration */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + return true; + } + return false; + } + function shouldEmitReturnTypeMetadata(node) { + // This method determines whether to emit the "design:returntype" metadata based on the node's kind. + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // compiler option is set. + switch (node.kind) { + case 143 /* MethodDeclaration */: + return true; + } + return false; + } + function shouldEmitParamTypesMetadata(node) { + // This method determines whether to emit the "design:paramtypes" metadata based on the node's kind. + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // compiler option is set. + switch (node.kind) { + case 214 /* ClassDeclaration */: + case 143 /* MethodDeclaration */: + case 146 /* SetAccessor */: + return true; + } + return false; + } + /** Serializes the type of a declaration to an appropriate JS constructor value. Used by the __metadata decorator for a class member. */ + function emitSerializedTypeOfNode(node) { + // serialization of the type of a declaration uses the following rules: + // + // * The serialized type of a ClassDeclaration is "Function" + // * The serialized type of a ParameterDeclaration is the serialized type of its type annotation. + // * The serialized type of a PropertyDeclaration is the serialized type of its type annotation. + // * The serialized type of an AccessorDeclaration is the serialized type of the return type annotation of its getter or parameter type annotation of its setter. + // * The serialized type of any other FunctionLikeDeclaration is "Function". + // * The serialized type of any other node is "void 0". + // + // For rules on serializing type annotations, see `serializeTypeNode`. + switch (node.kind) { + case 214 /* ClassDeclaration */: + write("Function"); + return; + case 141 /* PropertyDeclaration */: + emitSerializedTypeNode(node.type); + return; + case 138 /* Parameter */: + emitSerializedTypeNode(node.type); + return; + case 145 /* GetAccessor */: + emitSerializedTypeNode(node.type); + return; + case 146 /* SetAccessor */: + emitSerializedTypeNode(ts.getSetAccessorTypeAnnotationNode(node)); + return; + } + if (ts.isFunctionLike(node)) { + write("Function"); + return; + } + write("void 0"); + } + function emitSerializedTypeNode(node) { + if (node) { + switch (node.kind) { + case 103 /* VoidKeyword */: + write("void 0"); + return; + case 160 /* ParenthesizedType */: + emitSerializedTypeNode(node.type); + return; + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + write("Function"); + return; + case 156 /* ArrayType */: + case 157 /* TupleType */: + write("Array"); + return; + case 150 /* TypePredicate */: + case 120 /* BooleanKeyword */: + write("Boolean"); + return; + case 130 /* StringKeyword */: + case 9 /* StringLiteral */: + write("String"); + return; + case 128 /* NumberKeyword */: + write("Number"); + return; + case 131 /* SymbolKeyword */: + write("Symbol"); + return; + case 151 /* TypeReference */: + emitSerializedTypeReferenceNode(node); + return; + case 154 /* TypeQuery */: + case 155 /* TypeLiteral */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: + case 117 /* AnyKeyword */: + break; + default: + ts.Debug.fail("Cannot serialize unexpected type node."); + break; + } + } + write("Object"); + } + /** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */ + function emitSerializedTypeReferenceNode(node) { + var location = node.parent; + while (ts.isDeclaration(location) || ts.isTypeNode(location)) { + location = location.parent; + } + // Clone the type name and parent it to a location outside of the current declaration. + var typeName = ts.cloneEntityName(node.typeName); + typeName.parent = location; + var result = resolver.getTypeReferenceSerializationKind(typeName); + switch (result) { + case ts.TypeReferenceSerializationKind.Unknown: + var temp = createAndRecordTempVariable(0 /* Auto */); + write("(typeof ("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(typeName, /*useFallback*/ true); + write(") === 'function' && "); + emitNodeWithoutSourceMap(temp); + write(") || Object"); + break; + case ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue: + emitEntityNameAsExpression(typeName, /*useFallback*/ false); + break; + case ts.TypeReferenceSerializationKind.VoidType: + write("void 0"); + break; + case ts.TypeReferenceSerializationKind.BooleanType: + write("Boolean"); + break; + case ts.TypeReferenceSerializationKind.NumberLikeType: + write("Number"); + break; + case ts.TypeReferenceSerializationKind.StringLikeType: + write("String"); + break; + case ts.TypeReferenceSerializationKind.ArrayLikeType: + write("Array"); + break; + case ts.TypeReferenceSerializationKind.ESSymbolType: + if (languageVersion < 2 /* ES6 */) { + write("typeof Symbol === 'function' ? Symbol : Object"); + } + else { + write("Symbol"); + } + break; + case ts.TypeReferenceSerializationKind.TypeWithCallSignature: + write("Function"); + break; + case ts.TypeReferenceSerializationKind.ObjectType: + write("Object"); + break; + } + } + /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ + function emitSerializedParameterTypesOfNode(node) { + // serialization of parameter types uses the following rules: + // + // * If the declaration is a class, the parameters of the first constructor with a body are used. + // * If the declaration is function-like and has a body, the parameters of the function are used. + // + // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. + if (node) { + var valueDeclaration; + if (node.kind === 214 /* ClassDeclaration */) { + valueDeclaration = ts.getFirstConstructorWithBody(node); + } + else if (ts.isFunctionLike(node) && ts.nodeIsPresent(node.body)) { + valueDeclaration = node; + } + if (valueDeclaration) { + var parameters = valueDeclaration.parameters; + var parameterCount = parameters.length; + if (parameterCount > 0) { + for (var i = 0; i < parameterCount; i++) { + if (i > 0) { + write(", "); + } + if (parameters[i].dotDotDotToken) { + var parameterType = parameters[i].type; + if (parameterType.kind === 156 /* ArrayType */) { + parameterType = parameterType.elementType; + } + else if (parameterType.kind === 151 /* TypeReference */ && parameterType.typeArguments && parameterType.typeArguments.length === 1) { + parameterType = parameterType.typeArguments[0]; + } + else { + parameterType = undefined; + } + emitSerializedTypeNode(parameterType); + } + else { + emitSerializedTypeOfNode(parameters[i]); + } + } + } + } + } + } + /** Serializes the return type of function. Used by the __metadata decorator for a method. */ + function emitSerializedReturnTypeOfNode(node) { + if (node && ts.isFunctionLike(node) && node.type) { + emitSerializedTypeNode(node.type); + return; + } + write("void 0"); + } + function emitSerializedTypeMetadata(node, writeComma) { + // This method emits the serialized type metadata for a decorator target. + // The caller should have already tested whether the node has decorators. + var argumentsWritten = 0; + if (compilerOptions.emitDecoratorMetadata) { + if (shouldEmitTypeMetadata(node)) { + if (writeComma) { + write(", "); + } + writeLine(); + write("__metadata('design:type', "); + emitSerializedTypeOfNode(node); + write(")"); + argumentsWritten++; + } + if (shouldEmitParamTypesMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:paramtypes', ["); + emitSerializedParameterTypesOfNode(node); + write("])"); + argumentsWritten++; + } + if (shouldEmitReturnTypeMetadata(node)) { + if (writeComma || argumentsWritten) { + write(", "); + } + writeLine(); + write("__metadata('design:returntype', "); + emitSerializedReturnTypeOfNode(node); + write(")"); + argumentsWritten++; + } + } + return argumentsWritten; + } + function emitInterfaceDeclaration(node) { + emitCommentsOnNotEmittedNode(node); + } + function shouldEmitEnumDeclaration(node) { + var isConstEnum = ts.isConst(node); + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; + } + function emitEnumDeclaration(node) { + // const enums are completely erased during compilation. + if (!shouldEmitEnumDeclaration(node)) { + return; + } + if (!shouldHoistDeclarationInSystemJsModule(node)) { + // do not emit var if variable was already hoisted + if (!(node.flags & 1 /* Export */) || isES6ExportedDeclaration(node)) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + emitEnd(node); + write(";"); + } + } + writeLine(); + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") {"); + increaseIndent(); + scopeEmitStart(node); + emitLines(node.members); + decreaseIndent(); + writeLine(); + emitToken(16 /* CloseBraceToken */, node.members.end); + scopeEmitEnd(); + write(")("); + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.flags & 1 /* Export */ && !shouldHoistDeclarationInSystemJsModule(node)) { + // do not emit var if variable was already hoisted + writeLine(); + emitStart(node); + write("var "); + emit(node.name); + write(" = "); + emitModuleMemberName(node); + emitEnd(node); + write(";"); + } + if (modulekind !== 5 /* ES6 */ && node.parent === currentSourceFile) { + if (modulekind === 4 /* System */ && (node.flags & 1 /* Export */)) { + // write the call to exporter for enum + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + function emitEnumMember(node) { + var enumParent = node.parent; + emitStart(node); + write(getGeneratedNameForNode(enumParent)); + write("["); + write(getGeneratedNameForNode(enumParent)); + write("["); + emitExpressionForPropertyName(node.name); + write("] = "); + writeEnumMemberDeclarationValue(node); + write("] = "); + emitExpressionForPropertyName(node.name); + emitEnd(node); + write(";"); + } + function writeEnumMemberDeclarationValue(member) { + var value = resolver.getConstantValue(member); + if (value !== undefined) { + write(value.toString()); + return; + } + else if (member.initializer) { + emit(member.initializer); + } + else { + write("undefined"); + } + } + function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { + if (moduleDeclaration.body.kind === 218 /* ModuleDeclaration */) { + var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); + return recursiveInnerModule || moduleDeclaration.body; + } + } + function shouldEmitModuleDeclaration(node) { + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); + } + function isModuleMergedWithES6Class(node) { + return languageVersion === 2 /* ES6 */ && !!(resolver.getNodeCheckFlags(node) & 32768 /* LexicalModuleMergesWithClass */); + } + function emitModuleDeclaration(node) { + // Emit only if this module is non-ambient. + var shouldEmit = shouldEmitModuleDeclaration(node); + if (!shouldEmit) { + return emitCommentsOnNotEmittedNode(node); + } + var hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); + var emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); + if (emitVarForModule) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); + } + emitStart(node); + write("(function ("); + emitStart(node.name); + write(getGeneratedNameForNode(node)); + emitEnd(node.name); + write(") "); + if (node.body.kind === 219 /* ModuleBlock */) { + var saveTempFlags = tempFlags; + var saveTempVariables = tempVariables; + tempFlags = 0; + tempVariables = undefined; + emit(node.body); + tempFlags = saveTempFlags; + tempVariables = saveTempVariables; + } + else { + write("{"); + increaseIndent(); + scopeEmitStart(node); + emitCaptureThisForNodeIfNecessary(node); + writeLine(); + emit(node.body); + decreaseIndent(); + writeLine(); + var moduleBlock = getInnerMostModuleDeclarationFromDottedModule(node).body; + emitToken(16 /* CloseBraceToken */, moduleBlock.statements.end); + scopeEmitEnd(); + } + write(")("); + // write moduleDecl = containingModule.m only if it is not exported es6 module member + if ((node.flags & 1 /* Export */) && !isES6ExportedDeclaration(node)) { + emit(node.name); + write(" = "); + } + emitModuleMemberName(node); + write(" || ("); + emitModuleMemberName(node); + write(" = {}));"); + emitEnd(node); + if (!isES6ExportedDeclaration(node) && node.name.kind === 69 /* Identifier */ && node.parent === currentSourceFile) { + if (modulekind === 4 /* System */ && (node.flags & 1 /* Export */)) { + writeLine(); + write(exportFunctionForFile + "(\""); + emitDeclarationName(node); + write("\", "); + emitDeclarationName(node); + write(");"); + } + emitExportMemberAssignments(node.name); + } + } + /* + * Some bundlers (SystemJS builder) sometimes want to rename dependencies. + * Here we check if alternative name was provided for a given moduleName and return it if possible. + */ + function tryRenameExternalModule(moduleName) { + if (currentSourceFile.renamedDependencies && ts.hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) { + return "\"" + currentSourceFile.renamedDependencies[moduleName.text] + "\""; + } + return undefined; + } + function emitRequire(moduleName) { + if (moduleName.kind === 9 /* StringLiteral */) { + write("require("); + var text = tryRenameExternalModule(moduleName); + if (text) { + write(text); + } + else { + emitStart(moduleName); + emitLiteral(moduleName); + emitEnd(moduleName); + } + emitToken(18 /* CloseParenToken */, moduleName.end); + } + else { + write("require()"); + } + } + function getNamespaceDeclarationNode(node) { + if (node.kind === 221 /* ImportEqualsDeclaration */) { + return node; + } + var importClause = node.importClause; + if (importClause && importClause.namedBindings && importClause.namedBindings.kind === 224 /* NamespaceImport */) { + return importClause.namedBindings; + } + } + function isDefaultImport(node) { + return node.kind === 222 /* ImportDeclaration */ && node.importClause && !!node.importClause.name; + } + function emitExportImportAssignments(node) { + if (ts.isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + emitExportMemberAssignments(node.name); + } + ts.forEachChild(node, emitExportImportAssignments); + } + function emitImportDeclaration(node) { + if (modulekind !== 5 /* ES6 */) { + return emitExternalImportDeclaration(node); + } + // ES6 import + if (node.importClause) { + var shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); + var shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, /* checkChildren */ true); + if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { + write("import "); + emitStart(node.importClause); + if (shouldEmitDefaultBindings) { + emit(node.importClause.name); + if (shouldEmitNamedBindings) { + write(", "); + } + } + if (shouldEmitNamedBindings) { + emitLeadingComments(node.importClause.namedBindings); + emitStart(node.importClause.namedBindings); + if (node.importClause.namedBindings.kind === 224 /* NamespaceImport */) { + write("* as "); + emit(node.importClause.namedBindings.name); + } + else { + write("{ "); + emitExportOrImportSpecifierList(node.importClause.namedBindings.elements, resolver.isReferencedAliasDeclaration); + write(" }"); + } + emitEnd(node.importClause.namedBindings); + emitTrailingComments(node.importClause.namedBindings); + } + emitEnd(node.importClause); + write(" from "); + emit(node.moduleSpecifier); + write(";"); + } + } + else { + write("import "); + emit(node.moduleSpecifier); + write(";"); + } + } + function emitExternalImportDeclaration(node) { + if (ts.contains(externalImports, node)) { + var isExportedImport = node.kind === 221 /* ImportEqualsDeclaration */ && (node.flags & 1 /* Export */) !== 0; + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (modulekind !== 2 /* AMD */) { + emitLeadingComments(node); + emitStart(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + // import x = require("foo") + // import * as x from "foo" + if (!isExportedImport) + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + } + else { + // import "foo" + // import x from "foo" + // import { x, y } from "foo" + // import d, * as x from "foo" + // import d, { x, y } from "foo" + var isNakedImport = 222 /* ImportDeclaration */ && !node.importClause; + if (!isNakedImport) { + write("var "); + write(getGeneratedNameForNode(node)); + write(" = "); + } + } + emitRequire(ts.getExternalModuleName(node)); + if (namespaceDeclaration && isDefaultImport(node)) { + // import d, * as x from "foo" + write(", "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + else { + if (isExportedImport) { + emitModuleMemberName(namespaceDeclaration); + write(" = "); + emit(namespaceDeclaration.name); + write(";"); + } + else if (namespaceDeclaration && isDefaultImport(node)) { + // import d, * as x from "foo" + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(getGeneratedNameForNode(node)); + write(";"); + } + emitExportImportAssignments(node); + } + } + } + function emitImportEqualsDeclaration(node) { + if (ts.isExternalModuleImportEqualsDeclaration(node)) { + emitExternalImportDeclaration(node); + return; + } + // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when + // - current file is not external module + // - import declaration is top level and target is value imported by entity name + if (resolver.isReferencedAliasDeclaration(node) || + (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { + emitLeadingComments(node); + emitStart(node); + // variable declaration for import-equals declaration can be hoisted in system modules + // in this case 'var' should be omitted and emit should contain only initialization + var variableDeclarationIsHoisted = shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ true); + // is it top level export import v = a.b.c in system module? + // if yes - it needs to be rewritten as exporter('v', v = a.b.c) + var isExported = isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ true); + if (!variableDeclarationIsHoisted) { + ts.Debug.assert(!isExported); + if (isES6ExportedDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & 1 /* Export */)) { + write("var "); + } + } + if (isExported) { + write(exportFunctionForFile + "(\""); + emitNodeWithoutSourceMap(node.name); + write("\", "); + } + emitModuleMemberName(node); + write(" = "); + emit(node.moduleReference); + if (isExported) { + write(")"); + } + write(";"); + emitEnd(node); + emitExportImportAssignments(node); + emitTrailingComments(node); + } + } + function emitExportDeclaration(node) { + ts.Debug.assert(modulekind !== 4 /* System */); + if (modulekind !== 5 /* ES6 */) { + if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { + emitStart(node); + var generatedName = getGeneratedNameForNode(node); + if (node.exportClause) { + // export { x, y, ... } from "foo" + if (modulekind !== 2 /* AMD */) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(ts.getExternalModuleName(node)); + write(";"); + } + for (var _a = 0, _b = node.exportClause.elements; _a < _b.length; _a++) { + var specifier = _b[_a]; + if (resolver.isValueAliasDeclaration(specifier)) { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + } + } + } + else { + // export * from "foo" + writeLine(); + write("__export("); + if (modulekind !== 2 /* AMD */) { + emitRequire(ts.getExternalModuleName(node)); + } + else { + write(generatedName); + } + write(");"); + } + emitEnd(node); + } + } + else { + if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { + write("export "); + if (node.exportClause) { + // export { x, y, ... } + write("{ "); + emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + emit(node.moduleSpecifier); + } + write(";"); + } + } + } + function emitExportOrImportSpecifierList(specifiers, shouldEmit) { + ts.Debug.assert(modulekind === 5 /* ES6 */); + var needsComma = false; + for (var _a = 0; _a < specifiers.length; _a++) { + var specifier = specifiers[_a]; + if (shouldEmit(specifier)) { + if (needsComma) { + write(", "); + } + if (specifier.propertyName) { + emit(specifier.propertyName); + write(" as "); + } + emit(specifier.name); + needsComma = true; + } + } + } + function emitExportAssignment(node) { + if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { + if (modulekind === 5 /* ES6 */) { + writeLine(); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== 213 /* FunctionDeclaration */ && + expression.kind !== 214 /* ClassDeclaration */) { + write(";"); + } + emitEnd(node); + } + else { + writeLine(); + emitStart(node); + if (modulekind === 4 /* System */) { + write(exportFunctionForFile + "(\"default\","); + emit(node.expression); + write(")"); + } + else { + emitEs6ExportDefaultCompat(node); + emitContainingModuleName(node); + if (languageVersion === 0 /* ES3 */) { + write("[\"default\"] = "); + } + else { + write(".default = "); + } + emit(node.expression); + } + write(";"); + emitEnd(node); + } + } + } + function collectExternalModuleInfo(sourceFile) { + externalImports = []; + exportSpecifiers = {}; + exportEquals = undefined; + hasExportStars = false; + for (var _a = 0, _b = sourceFile.statements; _a < _b.length; _a++) { + var node = _b[_a]; + switch (node.kind) { + case 222 /* ImportDeclaration */: + if (!node.importClause || + resolver.isReferencedAliasDeclaration(node.importClause, /*checkChildren*/ true)) { + // import "mod" + // import x from "mod" where x is referenced + // import * as x from "mod" where x is referenced + // import { x, y } from "mod" where at least one import is referenced + externalImports.push(node); + } + break; + case 221 /* ImportEqualsDeclaration */: + if (node.moduleReference.kind === 232 /* ExternalModuleReference */ && resolver.isReferencedAliasDeclaration(node)) { + // import x = require("mod") where x is referenced + externalImports.push(node); + } + break; + case 228 /* ExportDeclaration */: + if (node.moduleSpecifier) { + if (!node.exportClause) { + // export * from "mod" + externalImports.push(node); + hasExportStars = true; + } + else if (resolver.isValueAliasDeclaration(node)) { + // export { x, y } from "mod" where at least one export is a value symbol + externalImports.push(node); + } + } + else { + // export { x, y } + for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { + var specifier = _d[_c]; + var name_25 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_25] || (exportSpecifiers[name_25] = [])).push(specifier); + } + } + break; + case 227 /* ExportAssignment */: + if (node.isExportEquals && !exportEquals) { + // export = x + exportEquals = node; + } + break; + } + } + } + function emitExportStarHelper() { + if (hasExportStars) { + writeLine(); + write("function __export(m) {"); + increaseIndent(); + writeLine(); + write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function getLocalNameForExternalImport(node) { + var namespaceDeclaration = getNamespaceDeclarationNode(node); + if (namespaceDeclaration && !isDefaultImport(node)) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, namespaceDeclaration.name); + } + if (node.kind === 222 /* ImportDeclaration */ && node.importClause) { + return getGeneratedNameForNode(node); + } + if (node.kind === 228 /* ExportDeclaration */ && node.moduleSpecifier) { + return getGeneratedNameForNode(node); + } + } + function getExternalModuleNameText(importNode) { + var moduleName = ts.getExternalModuleName(importNode); + if (moduleName.kind === 9 /* StringLiteral */) { + return tryRenameExternalModule(moduleName) || getLiteralText(moduleName); + } + return undefined; + } + function emitVariableDeclarationsForImports() { + if (externalImports.length === 0) { + return; + } + writeLine(); + var started = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var importNode = externalImports[_a]; + // do not create variable declaration for exports and imports that lack import clause + var skipNode = importNode.kind === 228 /* ExportDeclaration */ || + (importNode.kind === 222 /* ImportDeclaration */ && !importNode.importClause); + if (skipNode) { + continue; + } + if (!started) { + write("var "); + started = true; + } + else { + write(", "); + } + write(getLocalNameForExternalImport(importNode)); + } + if (started) { + write(";"); + } + } + function emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) { + // when resolving exports local exported entries/indirect exported entries in the module + // should always win over entries with similar names that were added via star exports + // to support this we store names of local/indirect exported entries in a set. + // this set is used to filter names brought by star expors. + if (!hasExportStars) { + // local names set is needed only in presence of star exports + return undefined; + } + // local names set should only be added if we have anything exported + if (!exportedDeclarations && ts.isEmpty(exportSpecifiers)) { + // no exported declarations (export var ...) or export specifiers (export {x}) + // check if we have any non star export declarations. + var hasExportDeclarationWithExportClause = false; + for (var _a = 0; _a < externalImports.length; _a++) { + var externalImport = externalImports[_a]; + if (externalImport.kind === 228 /* ExportDeclaration */ && externalImport.exportClause) { + hasExportDeclarationWithExportClause = true; + break; + } + } + if (!hasExportDeclarationWithExportClause) { + // we still need to emit exportStar helper + return emitExportStarFunction(/*localNames*/ undefined); + } + } + var exportedNamesStorageRef = makeUniqueName("exportedNames"); + writeLine(); + write("var " + exportedNamesStorageRef + " = {"); + increaseIndent(); + var started = false; + if (exportedDeclarations) { + for (var i = 0; i < exportedDeclarations.length; ++i) { + // write name of exported declaration, i.e 'export var x...' + writeExportedName(exportedDeclarations[i]); + } + } + if (exportSpecifiers) { + for (var n in exportSpecifiers) { + for (var _b = 0, _c = exportSpecifiers[n]; _b < _c.length; _b++) { + var specifier = _c[_b]; + // write name of export specified, i.e. 'export {x}' + writeExportedName(specifier.name); + } + } + } + for (var _d = 0; _d < externalImports.length; _d++) { + var externalImport = externalImports[_d]; + if (externalImport.kind !== 228 /* ExportDeclaration */) { + continue; + } + var exportDecl = externalImport; + if (!exportDecl.exportClause) { + // export * from ... + continue; + } + for (var _e = 0, _f = exportDecl.exportClause.elements; _e < _f.length; _e++) { + var element = _f[_e]; + // write name of indirectly exported entry, i.e. 'export {x} from ...' + writeExportedName(element.name || element.propertyName); + } + } + decreaseIndent(); + writeLine(); + write("};"); + return emitExportStarFunction(exportedNamesStorageRef); + function emitExportStarFunction(localNames) { + var exportStarFunction = makeUniqueName("exportStar"); + writeLine(); + // define an export star helper function + write("function " + exportStarFunction + "(m) {"); + increaseIndent(); + writeLine(); + write("var exports = {};"); + writeLine(); + write("for(var n in m) {"); + increaseIndent(); + writeLine(); + write("if (n !== \"default\""); + if (localNames) { + write("&& !" + localNames + ".hasOwnProperty(n)"); + } + write(") exports[n] = m[n];"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write(exportFunctionForFile + "(exports);"); + decreaseIndent(); + writeLine(); + write("}"); + return exportStarFunction; + } + function writeExportedName(node) { + // do not record default exports + // they are local to module and never overwritten (explicitly skipped) by star export + if (node.kind !== 69 /* Identifier */ && node.flags & 1024 /* Default */) { + return; + } + if (started) { + write(","); + } + else { + started = true; + } + writeLine(); + write("'"); + if (node.kind === 69 /* Identifier */) { + emitNodeWithCommentsAndWithoutSourcemap(node); + } + else { + emitDeclarationName(node); + } + write("': true"); + } + } + function processTopLevelVariableAndFunctionDeclarations(node) { + // per ES6 spec: + // 15.2.1.16.4 ModuleDeclarationInstantiation() Concrete Method + // - var declarations are initialized to undefined - 14.a.ii + // - function/generator declarations are instantiated - 16.a.iv + // this means that after module is instantiated but before its evaluation + // exported functions are already accessible at import sites + // in theory we should hoist only exported functions and its dependencies + // in practice to simplify things we'll hoist all source level functions and variable declaration + // including variables declarations for module and class declarations + var hoistedVars; + var hoistedFunctionDeclarations; + var exportedDeclarations; + visit(node); + if (hoistedVars) { + writeLine(); + write("var "); + var seen = {}; + for (var i = 0; i < hoistedVars.length; ++i) { + var local = hoistedVars[i]; + var name_26 = local.kind === 69 /* Identifier */ + ? local + : local.name; + if (name_26) { + // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables + var text = ts.unescapeIdentifier(name_26.text); + if (ts.hasProperty(seen, text)) { + continue; + } + else { + seen[text] = text; + } + } + if (i !== 0) { + write(", "); + } + if (local.kind === 214 /* ClassDeclaration */ || local.kind === 218 /* ModuleDeclaration */ || local.kind === 217 /* EnumDeclaration */) { + emitDeclarationName(local); + } + else { + emit(local); + } + var flags = ts.getCombinedNodeFlags(local.kind === 69 /* Identifier */ ? local.parent : local); + if (flags & 1 /* Export */) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(local); + } + } + write(";"); + } + if (hoistedFunctionDeclarations) { + for (var _a = 0; _a < hoistedFunctionDeclarations.length; _a++) { + var f = hoistedFunctionDeclarations[_a]; + writeLine(); + emit(f); + if (f.flags & 1 /* Export */) { + if (!exportedDeclarations) { + exportedDeclarations = []; + } + exportedDeclarations.push(f); + } + } + } + return exportedDeclarations; + function visit(node) { + if (node.flags & 2 /* Ambient */) { + return; + } + if (node.kind === 213 /* FunctionDeclaration */) { + if (!hoistedFunctionDeclarations) { + hoistedFunctionDeclarations = []; + } + hoistedFunctionDeclarations.push(node); + return; + } + if (node.kind === 214 /* ClassDeclaration */) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + return; + } + if (node.kind === 217 /* EnumDeclaration */) { + if (shouldEmitEnumDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 218 /* ModuleDeclaration */) { + if (shouldEmitModuleDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node); + } + return; + } + if (node.kind === 211 /* VariableDeclaration */ || node.kind === 163 /* BindingElement */) { + if (shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ false)) { + var name_27 = node.name; + if (name_27.kind === 69 /* Identifier */) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(name_27); + } + else { + ts.forEachChild(name_27, visit); + } + } + return; + } + if (ts.isInternalModuleImportEqualsDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + hoistedVars.push(node.name); + return; + } + if (ts.isBindingPattern(node)) { + ts.forEach(node.elements, visit); + return; + } + if (!ts.isDeclaration(node)) { + ts.forEachChild(node, visit); + } + } + } + function shouldHoistVariable(node, checkIfSourceFileLevelDecl) { + if (checkIfSourceFileLevelDecl && !shouldHoistDeclarationInSystemJsModule(node)) { + return false; + } + // hoist variable if + // - it is not block scoped + // - it is top level block scoped + // if block scoped variables are nested in some another block then + // no other functions can use them except ones that are defined at least in the same block + return (ts.getCombinedNodeFlags(node) & 49152 /* BlockScoped */) === 0 || + ts.getEnclosingBlockScopeContainer(node).kind === 248 /* SourceFile */; + } + function isCurrentFileSystemExternalModule() { + return modulekind === 4 /* System */ && ts.isExternalModule(currentSourceFile); + } + function emitSystemModuleBody(node, dependencyGroups, startIndex) { + // shape of the body in system modules: + // function (exports) { + // + // + // + // return { + // setters: [ + // + // ], + // execute: function() { + // + // } + // } + // + // } + // I.e: + // import {x} from 'file1' + // var y = 1; + // export function foo() { return y + x(); } + // console.log(y); + // will be transformed to + // function(exports) { + // var file1; // local alias + // var y; + // function foo() { return y + file1.x(); } + // exports("foo", foo); + // return { + // setters: [ + // function(v) { file1 = v } + // ], + // execute(): function() { + // y = 1; + // console.log(y); + // } + // }; + // } + emitVariableDeclarationsForImports(); + writeLine(); + var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); + var exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); + writeLine(); + write("return {"); + increaseIndent(); + writeLine(); + emitSetters(exportStarFunction, dependencyGroups); + writeLine(); + emitExecute(node, startIndex); + decreaseIndent(); + writeLine(); + write("}"); // return + emitTempDeclarations(/*newLine*/ true); + } + function emitSetters(exportStarFunction, dependencyGroups) { + write("setters:["); + for (var i = 0; i < dependencyGroups.length; ++i) { + if (i !== 0) { + write(","); + } + writeLine(); + increaseIndent(); + var group = dependencyGroups[i]; + // derive a unique name for parameter from the first named entry in the group + var parameterName = makeUniqueName(ts.forEach(group, getLocalNameForExternalImport) || ""); + write("function (" + parameterName + ") {"); + increaseIndent(); + for (var _a = 0; _a < group.length; _a++) { + var entry = group[_a]; + var importVariableName = getLocalNameForExternalImport(entry) || ""; + switch (entry.kind) { + case 222 /* ImportDeclaration */: + if (!entry.importClause) { + // 'import "..."' case + // module is imported only for side-effects, no emit required + break; + } + // fall-through + case 221 /* ImportEqualsDeclaration */: + ts.Debug.assert(importVariableName !== ""); + writeLine(); + // save import into the local + write(importVariableName + " = " + parameterName + ";"); + writeLine(); + break; + case 228 /* ExportDeclaration */: + ts.Debug.assert(importVariableName !== ""); + if (entry.exportClause) { + // export {a, b as c} from 'foo' + // emit as: + // exports_({ + // "a": _["a"], + // "c": _["b"] + // }); + writeLine(); + write(exportFunctionForFile + "({"); + writeLine(); + increaseIndent(); + for (var i_2 = 0, len = entry.exportClause.elements.length; i_2 < len; ++i_2) { + if (i_2 !== 0) { + write(","); + writeLine(); + } + var e = entry.exportClause.elements[i_2]; + write("\""); + emitNodeWithCommentsAndWithoutSourcemap(e.name); + write("\": " + parameterName + "[\""); + emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name); + write("\"]"); + } + decreaseIndent(); + writeLine(); + write("});"); + } + else { + writeLine(); + // export * from 'foo' + // emit as: + // exportStar(_foo); + write(exportStarFunction + "(" + parameterName + ");"); + } + writeLine(); + break; + } + } + decreaseIndent(); + write("}"); + decreaseIndent(); + } + write("],"); + } + function emitExecute(node, startIndex) { + write("execute: function() {"); + increaseIndent(); + writeLine(); + for (var i = startIndex; i < node.statements.length; ++i) { + var statement = node.statements[i]; + switch (statement.kind) { + // - function declarations are not emitted because they were already hoisted + // - import declarations are not emitted since they are already handled in setters + // - export declarations with module specifiers are not emitted since they were already written in setters + // - export declarations without module specifiers are emitted preserving the order + case 213 /* FunctionDeclaration */: + case 222 /* ImportDeclaration */: + continue; + case 228 /* ExportDeclaration */: + if (!statement.moduleSpecifier) { + for (var _a = 0, _b = statement.exportClause.elements; _a < _b.length; _a++) { + var element = _b[_a]; + // write call to exporter function for every export specifier in exports list + emitExportSpecifierInSystemModule(element); + } + } + continue; + case 221 /* ImportEqualsDeclaration */: + if (!ts.isInternalModuleImportEqualsDeclaration(statement)) { + // - import equals declarations that import external modules are not emitted + continue; + } + // fall-though for import declarations that import internal modules + default: + writeLine(); + emit(statement); + } + } + decreaseIndent(); + writeLine(); + write("}"); // execute + } + function emitSystemModule(node) { + collectExternalModuleInfo(node); + // System modules has the following shape + // System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */}) + // 'exports' here is a function 'exports(name: string, value: T): T' that is used to publish exported values. + // 'exports' returns its 'value' argument so in most cases expressions + // that mutate exported values can be rewritten as: + // expr -> exports('name', expr). + // The only exception in this rule is postfix unary operators, + // see comment to 'emitPostfixUnaryExpression' for more details + ts.Debug.assert(!exportFunctionForFile); + // make sure that name of 'exports' function does not conflict with existing identifiers + exportFunctionForFile = makeUniqueName("exports"); + writeLine(); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); + var groupIndices = {}; + var dependencyGroups = []; + for (var i = 0; i < externalImports.length; ++i) { + var text = getExternalModuleNameText(externalImports[i]); + if (ts.hasProperty(groupIndices, text)) { + // deduplicate/group entries in dependency list by the dependency name + var groupIndex = groupIndices[text]; + dependencyGroups[groupIndex].push(externalImports[i]); + continue; + } + else { + groupIndices[text] = dependencyGroups.length; + dependencyGroups.push([externalImports[i]]); + } + if (i !== 0) { + write(", "); + } + write(text); + } + write("], function(" + exportFunctionForFile + ") {"); + writeLine(); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitSystemModuleBody(node, dependencyGroups, startIndex); + decreaseIndent(); + writeLine(); + write("});"); + } + function getAMDDependencyNames(node, includeNonAmdDependencies) { + // names of modules with corresponding parameter in the factory function + var aliasedModuleNames = []; + // names of modules with no corresponding parameters in factory function + var unaliasedModuleNames = []; + var importAliasNames = []; // names of the parameters in the factory function; these + // parameters need to match the indexes of the corresponding + // module names in aliasedModuleNames. + // Fill in amd-dependency tags + for (var _a = 0, _b = node.amdDependencies; _a < _b.length; _a++) { + var amdDependency = _b[_a]; + if (amdDependency.name) { + aliasedModuleNames.push("\"" + amdDependency.path + "\""); + importAliasNames.push(amdDependency.name); + } + else { + unaliasedModuleNames.push("\"" + amdDependency.path + "\""); + } + } + for (var _c = 0; _c < externalImports.length; _c++) { + var importNode = externalImports[_c]; + // Find the name of the external module + var externalModuleName = getExternalModuleNameText(importNode); + // Find the name of the module alias, if there is one + var importAliasName = getLocalNameForExternalImport(importNode); + if (includeNonAmdDependencies && importAliasName) { + aliasedModuleNames.push(externalModuleName); + importAliasNames.push(importAliasName); + } + else { + unaliasedModuleNames.push(externalModuleName); + } + } + return { aliasedModuleNames: aliasedModuleNames, unaliasedModuleNames: unaliasedModuleNames, importAliasNames: importAliasNames }; + } + function emitAMDDependencies(node, includeNonAmdDependencies) { + // An AMD define function has the following shape: + // define(id?, dependencies?, factory); + // + // This has the shape of + // define(name, ["module1", "module2"], function (module1Alias) { + // The location of the alias in the parameter list in the factory function needs to + // match the position of the module name in the dependency list. + // + // To ensure this is true in cases of modules with no aliases, e.g.: + // `import "module"` or `` + // we need to add modules without alias names to the end of the dependencies list + var dependencyNames = getAMDDependencyNames(node, includeNonAmdDependencies); + emitAMDDependencyList(dependencyNames); + write(", "); + emitAMDFactoryHeader(dependencyNames); + } + function emitAMDDependencyList(_a) { + var aliasedModuleNames = _a.aliasedModuleNames, unaliasedModuleNames = _a.unaliasedModuleNames; + write("[\"require\", \"exports\""); + if (aliasedModuleNames.length) { + write(", "); + write(aliasedModuleNames.join(", ")); + } + if (unaliasedModuleNames.length) { + write(", "); + write(unaliasedModuleNames.join(", ")); + } + write("]"); + } + function emitAMDFactoryHeader(_a) { + var importAliasNames = _a.importAliasNames; + write("function (require, exports"); + if (importAliasNames.length) { + write(", "); + write(importAliasNames.join(", ")); + } + write(") {"); + } + function emitAMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + writeLine(); + write("define("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitCommonJSModule(node) { + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + emitEmitHelpers(node); + collectExternalModuleInfo(node); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ false); + } + function emitUMDModule(node) { + emitEmitHelpers(node); + collectExternalModuleInfo(node); + var dependencyNames = getAMDDependencyNames(node, /*includeNonAmdDependencies*/ false); + // Module is detected first to support Browserify users that load into a browser with an AMD loader + writeLines("(function (factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n var v = factory(require, exports); if (v !== undefined) module.exports = v;\n }\n else if (typeof define === 'function' && define.amd) {\n define("); + emitAMDDependencyList(dependencyNames); + write(", factory);"); + writeLines(" }\n})("); + emitAMDFactoryHeader(dependencyNames); + increaseIndent(); + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitES6Module(node) { + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + // Emit exportDefault if it exists will happen as part + // or normal statement emit. + } + function emitExportEquals(emitAsReturn) { + if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { + writeLine(); + emitStart(exportEquals); + write(emitAsReturn ? "return " : "module.exports = "); + emit(exportEquals.expression); + write(";"); + emitEnd(exportEquals); + } + } + function emitJsxElement(node) { + switch (compilerOptions.jsx) { + case 2 /* React */: + jsxEmitReact(node); + break; + case 1 /* Preserve */: + // Fall back to preserve if None was specified (we'll error earlier) + default: + jsxEmitPreserve(node); + break; + } + } + function trimReactWhitespaceAndApplyEntities(node) { + var result = undefined; + var text = ts.getTextOfNode(node, /*includeTrivia*/ true); + var firstNonWhitespace = 0; + var lastNonWhitespace = -1; + // JSX trims whitespace at the end and beginning of lines, except that the + // start/end of a tag is considered a start/end of a line only if that line is + // on the same line as the closing tag. See examples in tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx + for (var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + if (ts.isLineBreak(c)) { + if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { + var part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + firstNonWhitespace = -1; + } + else if (!ts.isWhiteSpace(c)) { + lastNonWhitespace = i; + if (firstNonWhitespace === -1) { + firstNonWhitespace = i; + } + } + } + if (firstNonWhitespace !== -1) { + var part = text.substr(firstNonWhitespace); + result = (result ? result + "\" + ' ' + \"" : "") + ts.escapeString(part); + } + if (result) { + // Replace entities like   + result = result.replace(/&(\w+);/g, function (s, m) { + if (entities[m] !== undefined) { + return String.fromCharCode(entities[m]); + } + else { + return s; + } + }); + } + return result; + } + function getTextToEmit(node) { + switch (compilerOptions.jsx) { + case 2 /* React */: + var text = trimReactWhitespaceAndApplyEntities(node); + if (text === undefined || text.length === 0) { + return undefined; + } + else { + return text; + } + case 1 /* Preserve */: + default: + return ts.getTextOfNode(node, /*includeTrivia*/ true); + } + } + function emitJsxText(node) { + switch (compilerOptions.jsx) { + case 2 /* React */: + write("\""); + write(trimReactWhitespaceAndApplyEntities(node)); + write("\""); + break; + case 1 /* Preserve */: + default: + writer.writeLiteral(ts.getTextOfNode(node, /*includeTrivia*/ true)); + break; + } + } + function emitJsxExpression(node) { + if (node.expression) { + switch (compilerOptions.jsx) { + case 1 /* Preserve */: + default: + write("{"); + emit(node.expression); + write("}"); + break; + case 2 /* React */: + emit(node.expression); + break; + } + } + } + function emitDirectivePrologues(statements, startWithNewLine) { + for (var i = 0; i < statements.length; ++i) { + if (ts.isPrologueDirective(statements[i])) { + if (startWithNewLine || i > 0) { + writeLine(); + } + emit(statements[i]); + } + else { + // return index of the first non prologue directive + return i; + } + } + return statements.length; + } + function writeLines(text) { + var lines = text.split(/\r\n|\r|\n/g); + for (var i = 0; i < lines.length; ++i) { + var line = lines[i]; + if (line.length) { + writeLine(); + write(line); + } + } + } + function emitEmitHelpers(node) { + // 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 < 2 /* ES6 */) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8 /* EmitExtends */)) { + writeLines(extendsHelper); + extendsEmitted = true; + } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 16 /* EmitDecorate */) { + writeLines(decorateHelper); + if (compilerOptions.emitDecoratorMetadata) { + writeLines(metadataHelper); + } + decorateEmitted = true; + } + if (!paramEmitted && resolver.getNodeCheckFlags(node) & 32 /* EmitParam */) { + writeLines(paramHelper); + paramEmitted = true; + } + if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 64 /* EmitAwaiter */) { + writeLines(awaiterHelper); + awaiterEmitted = true; + } + } + } + function emitSourceFileNode(node) { + // Start new file on new line + writeLine(); + emitShebang(); + emitDetachedComments(node); + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { + var emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[1 /* CommonJS */]; + emitModule(node); + } + else { + // emit prologue directives prior to __extends + var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + externalImports = undefined; + exportSpecifiers = undefined; + exportEquals = undefined; + hasExportStars = false; + emitEmitHelpers(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + } + emitLeadingComments(node.endOfFileToken); + } + function emitNodeWithCommentsAndWithoutSourcemap(node) { + emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap); + } + function emitNodeConsideringCommentsOption(node, emitNodeConsideringSourcemap) { + if (node) { + if (node.flags & 2 /* Ambient */) { + return emitCommentsOnNotEmittedNode(node); + } + if (isSpecializedCommentHandling(node)) { + // This is the node that will handle its own comments and sourcemap + return emitNodeWithoutSourceMap(node); + } + var emitComments_1 = shouldEmitLeadingAndTrailingComments(node); + if (emitComments_1) { + emitLeadingComments(node); + } + emitNodeConsideringSourcemap(node); + if (emitComments_1) { + emitTrailingComments(node); + } + } + } + function emitNodeWithoutSourceMap(node) { + if (node) { + emitJavaScriptWorker(node); + } + } + function isSpecializedCommentHandling(node) { + switch (node.kind) { + // All of these entities are emitted in a specialized fashion. As such, we allow + // the specialized methods for each to handle the comments on the nodes. + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 227 /* ExportAssignment */: + return true; + } + } + function shouldEmitLeadingAndTrailingComments(node) { + switch (node.kind) { + case 193 /* VariableStatement */: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); + case 218 /* ModuleDeclaration */: + // Only emit the leading/trailing comments for a module if we're actually + // emitting the module as well. + return shouldEmitModuleDeclaration(node); + case 217 /* EnumDeclaration */: + // Only emit the leading/trailing comments for an enum if we're actually + // emitting the module as well. + return shouldEmitEnumDeclaration(node); + } + // If the node is emitted in specialized fashion, dont emit comments as this node will handle + // emitting comments when emitting itself + ts.Debug.assert(!isSpecializedCommentHandling(node)); + // If this is the expression body of an arrow function that we're down-leveling, + // then we don't want to emit comments when we emit the body. It will have already + // been taken care of when we emitted the 'return' statement for the function + // expression body. + if (node.kind !== 192 /* Block */ && + node.parent && + node.parent.kind === 174 /* ArrowFunction */ && + node.parent.body === node && + compilerOptions.target <= 1 /* ES5 */) { + return false; + } + // Emit comments for everything else. + return true; + } + function emitJavaScriptWorker(node) { + // Check if the node can be emitted regardless of the ScriptTarget + switch (node.kind) { + case 69 /* Identifier */: + return emitIdentifier(node); + case 138 /* Parameter */: + return emitParameter(node); + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + return emitMethod(node); + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + return emitAccessor(node); + case 97 /* ThisKeyword */: + return emitThis(node); + case 95 /* SuperKeyword */: + return emitSuper(node); + case 93 /* NullKeyword */: + return write("null"); + case 99 /* TrueKeyword */: + return write("true"); + case 84 /* FalseKeyword */: + return write("false"); + case 8 /* NumericLiteral */: + case 9 /* StringLiteral */: + case 10 /* RegularExpressionLiteral */: + case 11 /* NoSubstitutionTemplateLiteral */: + case 12 /* TemplateHead */: + case 13 /* TemplateMiddle */: + case 14 /* TemplateTail */: + return emitLiteral(node); + case 183 /* TemplateExpression */: + return emitTemplateExpression(node); + case 190 /* TemplateSpan */: + return emitTemplateSpan(node); + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + return emitJsxElement(node); + case 236 /* JsxText */: + return emitJsxText(node); + case 240 /* JsxExpression */: + return emitJsxExpression(node); + case 135 /* QualifiedName */: + return emitQualifiedName(node); + case 161 /* ObjectBindingPattern */: + return emitObjectBindingPattern(node); + case 162 /* ArrayBindingPattern */: + return emitArrayBindingPattern(node); + case 163 /* BindingElement */: + return emitBindingElement(node); + case 164 /* ArrayLiteralExpression */: + return emitArrayLiteral(node); + case 165 /* ObjectLiteralExpression */: + return emitObjectLiteral(node); + case 245 /* PropertyAssignment */: + return emitPropertyAssignment(node); + case 246 /* ShorthandPropertyAssignment */: + return emitShorthandPropertyAssignment(node); + case 136 /* ComputedPropertyName */: + return emitComputedPropertyName(node); + case 166 /* PropertyAccessExpression */: + return emitPropertyAccess(node); + case 167 /* ElementAccessExpression */: + return emitIndexedAccess(node); + case 168 /* CallExpression */: + return emitCallExpression(node); + case 169 /* NewExpression */: + return emitNewExpression(node); + case 170 /* TaggedTemplateExpression */: + return emitTaggedTemplateExpression(node); + case 171 /* TypeAssertionExpression */: + return emit(node.expression); + case 189 /* AsExpression */: + return emit(node.expression); + case 172 /* ParenthesizedExpression */: + return emitParenExpression(node); + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + return emitFunctionDeclaration(node); + case 175 /* DeleteExpression */: + return emitDeleteExpression(node); + case 176 /* TypeOfExpression */: + return emitTypeOfExpression(node); + case 177 /* VoidExpression */: + return emitVoidExpression(node); + case 178 /* AwaitExpression */: + return emitAwaitExpression(node); + case 179 /* PrefixUnaryExpression */: + return emitPrefixUnaryExpression(node); + case 180 /* PostfixUnaryExpression */: + return emitPostfixUnaryExpression(node); + case 181 /* BinaryExpression */: + return emitBinaryExpression(node); + case 182 /* ConditionalExpression */: + return emitConditionalExpression(node); + case 185 /* SpreadElementExpression */: + return emitSpreadElementExpression(node); + case 184 /* YieldExpression */: + return emitYieldExpression(node); + case 187 /* OmittedExpression */: + return; + case 192 /* Block */: + case 219 /* ModuleBlock */: + return emitBlock(node); + case 193 /* VariableStatement */: + return emitVariableStatement(node); + case 194 /* EmptyStatement */: + return write(";"); + case 195 /* ExpressionStatement */: + return emitExpressionStatement(node); + case 196 /* IfStatement */: + return emitIfStatement(node); + case 197 /* DoStatement */: + return emitDoStatement(node); + case 198 /* WhileStatement */: + return emitWhileStatement(node); + case 199 /* ForStatement */: + return emitForStatement(node); + case 201 /* ForOfStatement */: + case 200 /* ForInStatement */: + return emitForInOrForOfStatement(node); + case 202 /* ContinueStatement */: + case 203 /* BreakStatement */: + return emitBreakOrContinueStatement(node); + case 204 /* ReturnStatement */: + return emitReturnStatement(node); + case 205 /* WithStatement */: + return emitWithStatement(node); + case 206 /* SwitchStatement */: + return emitSwitchStatement(node); + case 241 /* CaseClause */: + case 242 /* DefaultClause */: + return emitCaseOrDefaultClause(node); + case 207 /* LabeledStatement */: + return emitLabelledStatement(node); + case 208 /* ThrowStatement */: + return emitThrowStatement(node); + case 209 /* TryStatement */: + return emitTryStatement(node); + case 244 /* CatchClause */: + return emitCatchClause(node); + case 210 /* DebuggerStatement */: + return emitDebuggerStatement(node); + case 211 /* VariableDeclaration */: + return emitVariableDeclaration(node); + case 186 /* ClassExpression */: + return emitClassExpression(node); + case 214 /* ClassDeclaration */: + return emitClassDeclaration(node); + case 215 /* InterfaceDeclaration */: + return emitInterfaceDeclaration(node); + case 217 /* EnumDeclaration */: + return emitEnumDeclaration(node); + case 247 /* EnumMember */: + return emitEnumMember(node); + case 218 /* ModuleDeclaration */: + return emitModuleDeclaration(node); + case 222 /* ImportDeclaration */: + return emitImportDeclaration(node); + case 221 /* ImportEqualsDeclaration */: + return emitImportEqualsDeclaration(node); + case 228 /* ExportDeclaration */: + return emitExportDeclaration(node); + case 227 /* ExportAssignment */: + return emitExportAssignment(node); + case 248 /* SourceFile */: + return emitSourceFileNode(node); + } + } + function hasDetachedComments(pos) { + return detachedCommentsInfo !== undefined && ts.lastOrUndefined(detachedCommentsInfo).nodePos === pos; + } + function getLeadingCommentsWithoutDetachedComments() { + // get the leading comments from detachedPos + var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, ts.lastOrUndefined(detachedCommentsInfo).detachedCommentEndPos); + if (detachedCommentsInfo.length - 1) { + detachedCommentsInfo.pop(); + } + else { + detachedCommentsInfo = undefined; + } + return leadingComments; + } + function isPinnedComments(comment) { + return currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */; + } + /** + * Determine if the given comment is a triple-slash + * + * @return true if the comment is a triple-slash comment else false + **/ + function isTripleSlashComment(comment) { + // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text + // so that we don't end up computing comment string and doing match for all // comments + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */) { + var textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); + return textSubStr.match(ts.fullTripleSlashReferencePathRegEx) || + textSubStr.match(ts.fullTripleSlashAMDReferencePathRegEx) ? + true : false; + } + return false; + } + function getLeadingCommentsToEmit(node) { + // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === 248 /* SourceFile */ || node.pos !== node.parent.pos) { + if (hasDetachedComments(node.pos)) { + // get comments without detached comments + return getLeadingCommentsWithoutDetachedComments(); + } + else { + // get the leading comments from the node + return ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + } + } + } + function getTrailingCommentsToEmit(node) { + // Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === 248 /* SourceFile */ || node.end !== node.parent.end) { + return ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + } + } + } + /** + * Emit comments associated with node that will not be emitted into JS file + */ + function emitCommentsOnNotEmittedNode(node) { + emitLeadingCommentsWorker(node, /*isEmittedNode:*/ false); + } + function emitLeadingComments(node) { + return emitLeadingCommentsWorker(node, /*isEmittedNode:*/ true); + } + function emitLeadingCommentsWorker(node, isEmittedNode) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (isEmittedNode) { + leadingComments = getLeadingCommentsToEmit(node); + } + else { + // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, + // unless it is a triple slash comment at the top of the file. + // For Example: + // /// + // declare var x; + // /// + // interface F {} + // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted + if (node.pos === 0) { + leadingComments = ts.filter(getLeadingCommentsToEmit(node), isTripleSlashComment); + } + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space + ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator:*/ true, newLine, writeComment); + } + function emitTrailingComments(node) { + if (compilerOptions.removeComments) { + return; + } + // Emit the trailing comments only if the parent's end doesn't match + var trailingComments = getTrailingCommentsToEmit(node); + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); + } + /** + * Emit trailing comments at the position. The term trailing comment is used here to describe following comment: + * x, /comment1/ y + * ^ => pos; the function will emit "comment1" in the emitJS + */ + function emitTrailingCommentsOfPosition(pos) { + if (compilerOptions.removeComments) { + return; + } + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, pos); + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + ts.emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); + } + function emitLeadingCommentsOfPositionWorker(pos) { + if (compilerOptions.removeComments) { + return; + } + var leadingComments; + if (hasDetachedComments(pos)) { + // get comments without detached comments + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + // get the leading comments from the node + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos); + } + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space + ts.emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); + } + function emitDetachedComments(node) { + var leadingComments; + if (compilerOptions.removeComments) { + // removeComments is true, only reserve pinned comment at the top of file + // For example: + // /*! Pinned Comment */ + // + // var x = 10; + if (node.pos === 0) { + leadingComments = ts.filter(ts.getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); + } + } + else { + // removeComments is false, just get detached as normal and bypass the process to filter comment + leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); + } + if (leadingComments) { + var detachedComments = []; + var lastComment; + ts.forEach(leadingComments, function (comment) { + if (lastComment) { + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, lastComment.end); + var commentLine = ts.getLineOfLocalPosition(currentSourceFile, comment.pos); + if (commentLine >= lastCommentLine + 2) { + // There was a blank line between the last comment and this comment. This + // comment is not part of the copyright comments. Return what we have so + // far. + return detachedComments; + } + } + detachedComments.push(comment); + lastComment = comment; + }); + if (detachedComments.length) { + // All comments look like they could have been part of the copyright header. Make + // sure there is at least one blank line between it and the node. If not, it's not + // a copyright header. + var lastCommentLine = ts.getLineOfLocalPosition(currentSourceFile, ts.lastOrUndefined(detachedComments).end); + var nodeLine = ts.getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); + if (nodeLine >= lastCommentLine + 2) { + // Valid detachedComments + ts.emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + ts.emitComments(currentSourceFile, writer, detachedComments, /*trailingSeparator*/ true, newLine, writeComment); + var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: ts.lastOrUndefined(detachedComments).end }; + if (detachedCommentsInfo) { + detachedCommentsInfo.push(currentDetachedCommentInfo); + } + else { + detachedCommentsInfo = [currentDetachedCommentInfo]; + } + } + } + } + } + function emitShebang() { + var shebang = ts.getShebang(currentSourceFile.text); + if (shebang) { + write(shebang); + } + } + var _a; + } + function emitFile(jsFilePath, sourceFile) { + emitJavaScript(jsFilePath, sourceFile); + if (compilerOptions.declaration) { + ts.writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); + } + } + } + ts.emitFiles = emitFiles; })(ts || (ts = {})); /// /// @@ -35273,7 +35965,7 @@ var ts; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ var emptyArray = []; - ts.version = "1.7.0"; + ts.version = "1.8.0"; function findConfigFile(searchPath) { var fileName = "tsconfig.json"; while (true) { @@ -35311,11 +36003,11 @@ var ts; if (ts.getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { var failedLookupLocations = []; var candidate = ts.normalizePath(ts.combinePaths(containingDirectory, moduleName)); - var resolvedFileName = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); + var resolvedFileName = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (resolvedFileName) { return { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations }; } - resolvedFileName = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ false, failedLookupLocations, host); + resolvedFileName = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); return resolvedFileName ? { resolvedModule: { resolvedFileName: resolvedFileName }, failedLookupLocations: failedLookupLocations } : { resolvedModule: undefined, failedLookupLocations: failedLookupLocations }; @@ -35325,13 +36017,8 @@ var ts; } } ts.nodeModuleNameResolver = nodeModuleNameResolver; - function loadNodeModuleFromFile(candidate, loadOnlyDts, failedLookupLocation, host) { - if (loadOnlyDts) { - return tryLoad(".d.ts"); - } - else { - return ts.forEach(ts.supportedExtensions, tryLoad); - } + function loadNodeModuleFromFile(candidate, failedLookupLocation, host) { + return ts.forEach(ts.moduleFileExtensions, tryLoad); function tryLoad(ext) { var fileName = ts.fileExtensionIs(candidate, ext) ? candidate : candidate + ext; if (host.fileExists(fileName)) { @@ -35343,7 +36030,7 @@ var ts; } } } - function loadNodeModuleFromDirectory(candidate, loadOnlyDts, failedLookupLocation, host) { + function loadNodeModuleFromDirectory(candidate, failedLookupLocation, host) { var packageJsonPath = ts.combinePaths(candidate, "package.json"); if (host.fileExists(packageJsonPath)) { var jsonContent; @@ -35356,7 +36043,7 @@ var ts; jsonContent = { typings: undefined }; } if (jsonContent.typings) { - var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), loadOnlyDts, failedLookupLocation, host); + var result = loadNodeModuleFromFile(ts.normalizePath(ts.combinePaths(candidate, jsonContent.typings)), failedLookupLocation, host); if (result) { return result; } @@ -35366,7 +36053,7 @@ var ts; // record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results failedLookupLocation.push(packageJsonPath); } - return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host); + return loadNodeModuleFromFile(ts.combinePaths(candidate, "index"), failedLookupLocation, host); } function loadModuleFromNodeModules(moduleName, directory, host) { var failedLookupLocations = []; @@ -35376,11 +36063,11 @@ var ts; if (baseName !== "node_modules") { var nodeModulesFolder = ts.combinePaths(directory, "node_modules"); var candidate = ts.normalizePath(ts.combinePaths(nodeModulesFolder, moduleName)); - var result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); + var result = loadNodeModuleFromFile(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } - result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host); + result = loadNodeModuleFromDirectory(candidate, failedLookupLocations, host); if (result) { return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations: failedLookupLocations }; } @@ -35399,7 +36086,7 @@ var ts; } function classicNameResolver(moduleName, containingFile, compilerOptions, host) { // module names that contain '!' are used to reference resources and are not resolved to actual files on disk - if (moduleName.indexOf('!') != -1) { + if (moduleName.indexOf("!") != -1) { return { resolvedModule: undefined, failedLookupLocations: [] }; } var searchPath = ts.getDirectoryPath(containingFile); @@ -35746,7 +36433,9 @@ var ts; return emitResult; } function getSourceFile(fileName) { - return filesByName.get(fileName); + // first try to use file name as is to find file + // then try to convert relative file name to absolute and use it to retrieve source file + return filesByName.get(fileName) || filesByName.get(ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory())); } function getDiagnosticsHelper(sourceFile, getDiagnostics, cancellationToken) { if (sourceFile) { @@ -35845,10 +36534,14 @@ var ts; var imports; for (var _i = 0, _a = file.statements; _i < _a.length; _i++) { var node = _a[_i]; + collect(node, /* allowRelativeModuleNames */ true); + } + file.imports = imports || emptyArray; + function collect(node, allowRelativeModuleNames) { switch (node.kind) { - case 220 /* ImportDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 226 /* ExportDeclaration */: + case 222 /* ImportDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 228 /* ExportDeclaration */: var moduleNameExpr = ts.getExternalModuleName(node); if (!moduleNameExpr || moduleNameExpr.kind !== 9 /* StringLiteral */) { break; @@ -35856,9 +36549,11 @@ var ts; if (!moduleNameExpr.text) { break; } - (imports || (imports = [])).push(moduleNameExpr); + if (allowRelativeModuleNames || !ts.isExternalModuleNameRelative(moduleNameExpr.text)) { + (imports || (imports = [])).push(moduleNameExpr); + } break; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (node.name.kind === 9 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || ts.isDeclarationFile(file))) { // TypeScript 1.0 spec (April 2014): 12.1.6 // An AmbientExternalModuleDeclaration declares an external module. @@ -35866,22 +36561,15 @@ var ts; // The StringLiteral must specify a top - level external module name. // Relative external module names are not permitted ts.forEachChild(node.body, function (node) { - if (ts.isExternalModuleImportEqualsDeclaration(node) && - ts.getExternalModuleImportEqualsDeclarationExpression(node).kind === 9 /* StringLiteral */) { - var moduleName = ts.getExternalModuleImportEqualsDeclarationExpression(node); - // TypeScript 1.0 spec (April 2014): 12.1.6 - // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules - // only through top - level external module names. Relative external module names are not permitted. - if (moduleName) { - (imports || (imports = [])).push(moduleName); - } - } + // TypeScript 1.0 spec (April 2014): 12.1.6 + // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules + // only through top - level external module names. Relative external module names are not permitted. + collect(node, /* allowRelativeModuleNames */ false); }); } break; } } - file.imports = imports || emptyArray; } function processSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { var diagnosticArgument; @@ -35925,52 +36613,52 @@ var ts; } // Get source file from normalized fileName function findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd) { - var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (filesByName.contains(canonicalName)) { + if (filesByName.contains(fileName)) { // We've already looked for this file, use cached result - return getSourceFileFromCache(fileName, canonicalName, /*useAbsolutePath*/ false); + return getSourceFileFromCache(fileName, /*useAbsolutePath*/ false); } - else { - var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); - var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (filesByName.contains(canonicalAbsolutePath)) { - return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, /*useAbsolutePath*/ true); - } - // We haven't looked for this file, do so now and cache result - var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { - if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - else { - fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); - } - }); - filesByName.set(canonicalName, file); - if (file) { - skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; - // Set the source file for normalized absolute path - filesByName.set(canonicalAbsolutePath, file); - var basePath = ts.getDirectoryPath(fileName); - if (!options.noResolve) { - processReferencedFiles(file, basePath); - } - // always process imported modules to record module name resolutions - processImportedModules(file, basePath); - if (isDefaultLib) { - file.isDefaultLib = true; - files.unshift(file); - } - else { - files.push(file); - } - } - return file; + var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); + if (filesByName.contains(normalizedAbsolutePath)) { + var file_1 = getSourceFileFromCache(normalizedAbsolutePath, /*useAbsolutePath*/ true); + // we don't have resolution for this relative file name but the match was found by absolute file name + // store resolution for relative name as well + filesByName.set(fileName, file_1); + return file_1; } - function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName.get(canonicalName); + // We haven't looked for this file, do so now and cache result + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { + fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + else { + fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + } + }); + filesByName.set(fileName, file); + if (file) { + skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; + // Set the source file for normalized absolute path + filesByName.set(normalizedAbsolutePath, file); + var basePath = ts.getDirectoryPath(fileName); + if (!options.noResolve) { + processReferencedFiles(file, basePath); + } + // always process imported modules to record module name resolutions + processImportedModules(file, basePath); + if (isDefaultLib) { + file.isDefaultLib = true; + files.unshift(file); + } + else { + files.push(file); + } + } + return file; + function getSourceFileFromCache(fileName, useAbsolutePath) { + var file = filesByName.get(fileName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; - if (canonicalName !== sourceFileName) { + if (ts.normalizeSlashes(fileName) !== ts.normalizeSlashes(sourceFileName)) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } @@ -36138,9 +36826,9 @@ var ts; var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } - // Cannot specify module gen target when in es6 or above - if (options.module && languageVersion >= 2 /* ES6 */) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + // Cannot specify module gen target of es6 when below es6 + if (options.module === 5 /* ES6 */ && languageVersion < 2 /* ES6 */) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower)); } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -36181,10 +36869,6 @@ var ts; !options.experimentalDecorators) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } - if (options.experimentalAsyncFunctions && - options.target !== 2 /* ES6 */) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); - } } } ts.createProgram = createProgram; @@ -36266,11 +36950,13 @@ var ts; "commonjs": 1 /* CommonJS */, "amd": 2 /* AMD */, "system": 4 /* System */, - "umd": 3 /* UMD */ + "umd": 3 /* UMD */, + "es6": 5 /* ES6 */, + "es2015": 5 /* ES2015 */ }, - description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_or_umd, + description: ts.Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es6, paramType: ts.Diagnostics.KIND, - error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_or_umd + error: ts.Diagnostics.Argument_for_module_option_must_be_commonjs_amd_system_umd_or_es6 }, { name: "newLine", @@ -36395,7 +37081,12 @@ var ts; { name: "target", shortName: "t", - type: { "es3": 0 /* ES3 */, "es5": 1 /* ES5 */, "es6": 2 /* ES6 */ }, + type: { + "es3": 0 /* ES3 */, + "es5": 1 /* ES5 */, + "es6": 2 /* ES6 */, + "es2015": 2 /* ES2015 */ + }, description: ts.Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: ts.Diagnostics.VERSION, error: ts.Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6 @@ -36412,11 +37103,6 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, - { - name: "experimentalAsyncFunctions", - type: "boolean", - description: ts.Diagnostics.Enables_experimental_support_for_ES7_async_functions - }, { name: "experimentalDecorators", type: "boolean", @@ -36565,7 +37251,7 @@ var ts; catch (e) { return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; } - return parseConfigFileText(fileName, text); + return parseConfigFileTextToJson(fileName, text); } ts.readConfigFile = readConfigFile; /** @@ -36573,7 +37259,7 @@ var ts; * @param fileName The path to the config file * @param jsonText The text of the config file */ - function parseConfigFileText(fileName, jsonText) { + function parseConfigFileTextToJson(fileName, jsonText) { try { return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; } @@ -36581,14 +37267,14 @@ var ts; return { error: ts.createCompilerDiagnostic(ts.Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; } } - ts.parseConfigFileText = parseConfigFileText; + ts.parseConfigFileTextToJson = parseConfigFileTextToJson; /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - function parseConfigFile(json, host, basePath) { + function parseJsonConfigFileContent(json, host, basePath) { var errors = []; return { options: getCompilerOptions(), @@ -36622,6 +37308,9 @@ var ts; } if (opt.isFilePath) { value = ts.normalizePath(ts.combinePaths(basePath, value)); + if (value === "") { + value = "."; + } } options[opt.name] = value; } @@ -36650,27 +37339,27 @@ var ts; var exclude = json["exclude"] instanceof Array ? ts.map(json["exclude"], ts.normalizeSlashes) : undefined; var sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)); for (var i = 0; i < sysFiles.length; i++) { - var name_27 = sysFiles[i]; - if (ts.fileExtensionIs(name_27, ".d.ts")) { - var baseName = name_27.substr(0, name_27.length - ".d.ts".length); + var name_28 = sysFiles[i]; + if (ts.fileExtensionIs(name_28, ".d.ts")) { + var baseName = name_28.substr(0, name_28.length - ".d.ts".length); if (!ts.contains(sysFiles, baseName + ".tsx") && !ts.contains(sysFiles, baseName + ".ts")) { - fileNames.push(name_27); + fileNames.push(name_28); } } - else if (ts.fileExtensionIs(name_27, ".ts")) { - if (!ts.contains(sysFiles, name_27 + "x")) { - fileNames.push(name_27); + else if (ts.fileExtensionIs(name_28, ".ts")) { + if (!ts.contains(sysFiles, name_28 + "x")) { + fileNames.push(name_28); } } else { - fileNames.push(name_27); + fileNames.push(name_28); } } } return fileNames; } } - ts.parseConfigFile = parseConfigFile; + ts.parseJsonConfigFileContent = parseJsonConfigFileContent; })(ts || (ts = {})); /* @internal */ var ts; @@ -36744,7 +37433,7 @@ var ts; } } function autoCollapse(node) { - return ts.isFunctionBlock(node) && node.parent.kind !== 172 /* ArrowFunction */; + return ts.isFunctionBlock(node) && node.parent.kind !== 174 /* ArrowFunction */; } var depth = 0; var maxDepth = 20; @@ -36756,7 +37445,7 @@ var ts; addOutliningForLeadingCommentsForNode(n); } switch (n.kind) { - case 190 /* Block */: + case 192 /* Block */: if (!ts.isFunctionBlock(n)) { var parent_7 = n.parent; var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); @@ -36764,18 +37453,18 @@ var ts; // Check if the block is standalone, or 'attached' to some parent statement. // If the latter, we want to collaps the block, but consider its hint span // to be the entire span of the parent. - if (parent_7.kind === 195 /* DoStatement */ || - parent_7.kind === 198 /* ForInStatement */ || - parent_7.kind === 199 /* ForOfStatement */ || - parent_7.kind === 197 /* ForStatement */ || - parent_7.kind === 194 /* IfStatement */ || - parent_7.kind === 196 /* WhileStatement */ || - parent_7.kind === 203 /* WithStatement */ || - parent_7.kind === 242 /* CatchClause */) { + if (parent_7.kind === 197 /* DoStatement */ || + parent_7.kind === 200 /* ForInStatement */ || + parent_7.kind === 201 /* ForOfStatement */ || + parent_7.kind === 199 /* ForStatement */ || + parent_7.kind === 196 /* IfStatement */ || + parent_7.kind === 198 /* WhileStatement */ || + parent_7.kind === 205 /* WithStatement */ || + parent_7.kind === 244 /* CatchClause */) { addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_7.kind === 207 /* TryStatement */) { + if (parent_7.kind === 209 /* TryStatement */) { // Could be the try-block, or the finally-block. var tryStatement = parent_7; if (tryStatement.tryBlock === n) { @@ -36783,7 +37472,7 @@ var ts; break; } else if (tryStatement.finallyBlock === n) { - var finallyKeyword = ts.findChildOfKind(tryStatement, 83 /* FinallyKeyword */, sourceFile); + var finallyKeyword = ts.findChildOfKind(tryStatement, 85 /* FinallyKeyword */, sourceFile); if (finallyKeyword) { addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n)); break; @@ -36802,23 +37491,23 @@ var ts; break; } // Fallthrough. - case 217 /* ModuleBlock */: { + case 219 /* ModuleBlock */: { var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 16 /* CloseBraceToken */, sourceFile); addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); break; } - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 163 /* ObjectLiteralExpression */: - case 218 /* CaseBlock */: { + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 165 /* ObjectLiteralExpression */: + case 220 /* CaseBlock */: { var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 16 /* CloseBraceToken */, sourceFile); addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); break; } - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: var openBracket = ts.findChildOfKind(n, 19 /* OpenBracketToken */, sourceFile); var closeBracket = ts.findChildOfKind(n, 20 /* CloseBracketToken */, sourceFile); addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); @@ -36846,12 +37535,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_28 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_28); + for (var name_29 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_29); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_28); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_29); if (!matches) { continue; } @@ -36864,14 +37553,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_28); + matches = patternMatcher.getMatches(containers, name_29); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_28, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_29, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -36895,7 +37584,7 @@ var ts; } function getTextOfIdentifierOrLiteral(node) { if (node) { - if (node.kind === 67 /* Identifier */ || + if (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) { return node.text; @@ -36909,7 +37598,7 @@ var ts; if (text !== undefined) { containers.unshift(text); } - else if (declaration.name.kind === 134 /* ComputedPropertyName */) { + else if (declaration.name.kind === 136 /* ComputedPropertyName */) { return tryAddComputedPropertyName(declaration.name.expression, containers, /*includeLastPortion:*/ true); } else { @@ -36930,7 +37619,7 @@ var ts; } return true; } - if (expression.kind === 164 /* PropertyAccessExpression */) { + if (expression.kind === 166 /* PropertyAccessExpression */) { var propertyAccess = expression; if (includeLastPortion) { containers.unshift(propertyAccess.name.text); @@ -36943,7 +37632,7 @@ var ts; var containers = []; // First, if we started with a computed property name, then add all but the last // portion into the container array. - if (declaration.name.kind === 134 /* ComputedPropertyName */) { + if (declaration.name.kind === 136 /* ComputedPropertyName */) { if (!tryAddComputedPropertyName(declaration.name.expression, containers, /*includeLastPortion:*/ false)) { return undefined; } @@ -37019,17 +37708,17 @@ var ts; var current = node.parent; while (current) { switch (current.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: // If we have a module declared as A.B.C, it is more "intuitive" // to say it only has a single layer of depth do { current = current.parent; - } while (current.kind === 216 /* ModuleDeclaration */); + } while (current.kind === 218 /* ModuleDeclaration */); // fall through - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: indent++; } current = current.parent; @@ -37040,21 +37729,21 @@ var ts; var childNodes = []; function visit(node) { switch (node.kind) { - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: ts.forEach(node.declarationList.declarations, visit); break; - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: ts.forEach(node.elements, visit); break; - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: // Handle named exports case e.g.: // export {a, b as B} from "mod"; if (node.exportClause) { ts.forEach(node.exportClause.elements, visit); } break; - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: var importClause = node.importClause; if (importClause) { // Handle default import case e.g.: @@ -37066,7 +37755,7 @@ var ts; // import * as NS from "mod"; // import {a, b as B} from "mod"; if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (importClause.namedBindings.kind === 224 /* NamespaceImport */) { childNodes.push(importClause.namedBindings); } else { @@ -37075,21 +37764,21 @@ var ts; } } break; - case 161 /* BindingElement */: - case 209 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 211 /* VariableDeclaration */: if (ts.isBindingPattern(node.name)) { visit(node.name); break; } // Fall through - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: - case 216 /* ModuleDeclaration */: - case 211 /* FunctionDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 224 /* ImportSpecifier */: - case 228 /* ExportSpecifier */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: + case 218 /* ModuleDeclaration */: + case 213 /* FunctionDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 226 /* ImportSpecifier */: + case 230 /* ExportSpecifier */: childNodes.push(node); break; } @@ -37137,17 +37826,17 @@ var ts; for (var _i = 0; _i < nodes.length; _i++) { var node = nodes[_i]; switch (node.kind) { - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 215 /* InterfaceDeclaration */: topLevelNodes.push(node); break; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: var moduleDeclaration = node; topLevelNodes.push(node); addTopLevelNodes(getInnermostModule(moduleDeclaration).body.statements, topLevelNodes); break; - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: var functionDeclaration = node; if (isTopLevelFunctionDeclaration(functionDeclaration)) { topLevelNodes.push(node); @@ -37158,12 +37847,12 @@ var ts; } } function isTopLevelFunctionDeclaration(functionDeclaration) { - if (functionDeclaration.kind === 211 /* FunctionDeclaration */) { + if (functionDeclaration.kind === 213 /* FunctionDeclaration */) { // A function declaration is 'top level' if it contains any function declarations // within it. - if (functionDeclaration.body && functionDeclaration.body.kind === 190 /* Block */) { + if (functionDeclaration.body && functionDeclaration.body.kind === 192 /* Block */) { // Proper function declarations can only have identifier names - if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 211 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) { + if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 213 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) { return true; } // Or if it is not parented by another function. i.e all functions @@ -37223,7 +37912,7 @@ var ts; } function createChildItem(node) { switch (node.kind) { - case 136 /* Parameter */: + case 138 /* Parameter */: if (ts.isBindingPattern(node.name)) { break; } @@ -37231,36 +37920,36 @@ var ts; return undefined; } return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); - case 143 /* GetAccessor */: + case 145 /* GetAccessor */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberGetAccessorElement); - case 144 /* SetAccessor */: + case 146 /* SetAccessor */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); - case 245 /* EnumMember */: + case 247 /* EnumMember */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 145 /* CallSignature */: + case 147 /* CallSignature */: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); - case 146 /* ConstructSignature */: + case 148 /* ConstructSignature */: return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: var variableDeclarationNode; - var name_29; - if (node.kind === 161 /* BindingElement */) { - name_29 = node.name; + var name_30; + if (node.kind === 163 /* BindingElement */) { + name_30 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration - while (variableDeclarationNode && variableDeclarationNode.kind !== 209 /* VariableDeclaration */) { + while (variableDeclarationNode && variableDeclarationNode.kind !== 211 /* VariableDeclaration */) { variableDeclarationNode = variableDeclarationNode.parent; } ts.Debug.assert(variableDeclarationNode !== undefined); @@ -37268,24 +37957,24 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_29 = node.name; + name_30 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_29), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_30), ts.ScriptElementKind.variableElement); } - case 142 /* Constructor */: + case 144 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); - case 228 /* ExportSpecifier */: - case 224 /* ImportSpecifier */: - case 219 /* ImportEqualsDeclaration */: - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: + case 230 /* ExportSpecifier */: + case 226 /* ImportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.alias); } return undefined; @@ -37315,17 +38004,17 @@ var ts; } function createTopLevelItem(node) { switch (node.kind) { - case 246 /* SourceFile */: + case 248 /* SourceFile */: return createSourceFileItem(node); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: return createClassItem(node); - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: return createEnumItem(node); - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return createIterfaceItem(node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return createModuleItem(node); - case 211 /* FunctionDeclaration */: + case 213 /* FunctionDeclaration */: return createFunctionItem(node); } return undefined; @@ -37337,7 +38026,7 @@ var ts; // Otherwise, we need to aggregate each identifier to build up the qualified name. var result = []; result.push(moduleDeclaration.name.text); - while (moduleDeclaration.body && moduleDeclaration.body.kind === 216 /* ModuleDeclaration */) { + while (moduleDeclaration.body && moduleDeclaration.body.kind === 218 /* ModuleDeclaration */) { moduleDeclaration = moduleDeclaration.body; result.push(moduleDeclaration.name.text); } @@ -37349,7 +38038,7 @@ var ts; return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } function createFunctionItem(node) { - if (node.body && node.body.kind === 190 /* Block */) { + if (node.body && node.body.kind === 192 /* Block */) { var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem); return getNavigationBarItem(!node.name ? "default" : node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } @@ -37370,7 +38059,7 @@ var ts; var childItems; if (node.members) { var constructor = ts.forEach(node.members, function (member) { - return member.kind === 142 /* Constructor */ && member; + return member.kind === 144 /* Constructor */ && member; }); // Add the constructor parameters in as children of the class (for property parameters). // Note that *all non-binding pattern named* parameters will be added to the nodes array, but parameters that @@ -37394,7 +38083,7 @@ var ts; } } function removeComputedProperties(node) { - return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 134 /* ComputedPropertyName */; }); + return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 136 /* ComputedPropertyName */; }); } /** * Like removeComputedProperties, but retains the properties with well known symbol names @@ -37403,13 +38092,13 @@ var ts; return ts.filter(node.members, function (member) { return !ts.hasDynamicName(member); }); } function getInnermostModule(node) { - while (node.body.kind === 216 /* ModuleDeclaration */) { + while (node.body.kind === 218 /* ModuleDeclaration */) { node = node.body; } return node; } function getNodeSpan(node) { - return node.kind === 246 /* SourceFile */ + return node.kind === 248 /* SourceFile */ ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } @@ -38204,15 +38893,15 @@ var ts; } return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); function createJavaScriptSignatureHelpItems(argumentInfo) { - if (argumentInfo.invocation.kind !== 166 /* CallExpression */) { + if (argumentInfo.invocation.kind !== 168 /* CallExpression */) { return undefined; } // See if we can find some symbol with the call expression name that has call signatures. var callExpression = argumentInfo.invocation; var expression = callExpression.expression; - var name = expression.kind === 67 /* Identifier */ + var name = expression.kind === 69 /* Identifier */ ? expression - : expression.kind === 164 /* PropertyAccessExpression */ + : expression.kind === 166 /* PropertyAccessExpression */ ? expression.name : undefined; if (!name || !name.text) { @@ -38245,7 +38934,7 @@ var ts; * in the argument of an invocation; returns undefined otherwise. */ function getImmediatelyContainingArgumentInfo(node) { - if (node.parent.kind === 166 /* CallExpression */ || node.parent.kind === 167 /* NewExpression */) { + if (node.parent.kind === 168 /* CallExpression */ || node.parent.kind === 169 /* NewExpression */) { var callExpression = node.parent; // There are 3 cases to handle: // 1. The token introduces a list, and should begin a sig help session @@ -38298,25 +38987,25 @@ var ts; }; } } - else if (node.kind === 11 /* NoSubstitutionTemplateLiteral */ && node.parent.kind === 168 /* TaggedTemplateExpression */) { + else if (node.kind === 11 /* NoSubstitutionTemplateLiteral */ && node.parent.kind === 170 /* TaggedTemplateExpression */) { // Check if we're actually inside the template; // otherwise we'll fall out and return undefined. if (ts.isInsideTemplateLiteral(node, position)) { return getArgumentListInfoForTemplate(node.parent, /*argumentIndex*/ 0); } } - else if (node.kind === 12 /* TemplateHead */ && node.parent.parent.kind === 168 /* TaggedTemplateExpression */) { + else if (node.kind === 12 /* TemplateHead */ && node.parent.parent.kind === 170 /* TaggedTemplateExpression */) { var templateExpression = node.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 181 /* TemplateExpression */); + ts.Debug.assert(templateExpression.kind === 183 /* TemplateExpression */); var argumentIndex = ts.isInsideTemplateLiteral(node, position) ? 0 : 1; return getArgumentListInfoForTemplate(tagExpression, argumentIndex); } - else if (node.parent.kind === 188 /* TemplateSpan */ && node.parent.parent.parent.kind === 168 /* TaggedTemplateExpression */) { + else if (node.parent.kind === 190 /* TemplateSpan */ && node.parent.parent.parent.kind === 170 /* TaggedTemplateExpression */) { var templateSpan = node.parent; var templateExpression = templateSpan.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 181 /* TemplateExpression */); + ts.Debug.assert(templateExpression.kind === 183 /* TemplateExpression */); // If we're just after a template tail, don't show signature help. if (node.kind === 14 /* TemplateTail */ && !ts.isInsideTemplateLiteral(node, position)) { return undefined; @@ -38434,7 +39123,7 @@ var ts; // // This is because a Missing node has no width. However, what we actually want is to include trivia // leading up to the next token in case the user is about to type in a TemplateMiddle or TemplateTail. - if (template.kind === 181 /* TemplateExpression */) { + if (template.kind === 183 /* TemplateExpression */) { var lastSpan = ts.lastOrUndefined(template.templateSpans); if (lastSpan.literal.getFullWidth() === 0) { applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, /*stopAfterLineBreak*/ false); @@ -38443,7 +39132,7 @@ var ts; return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); } function getContainingArgumentInfo(node) { - for (var n = node; n.kind !== 246 /* SourceFile */; n = n.parent) { + for (var n = node; n.kind !== 248 /* SourceFile */; n = n.parent) { if (ts.isFunctionBlock(n)) { return undefined; } @@ -38643,40 +39332,40 @@ var ts; return false; } switch (n.kind) { - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 163 /* ObjectLiteralExpression */: - case 159 /* ObjectBindingPattern */: - case 153 /* TypeLiteral */: - case 190 /* Block */: - case 217 /* ModuleBlock */: - case 218 /* CaseBlock */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 165 /* ObjectLiteralExpression */: + case 161 /* ObjectBindingPattern */: + case 155 /* TypeLiteral */: + case 192 /* Block */: + case 219 /* ModuleBlock */: + case 220 /* CaseBlock */: return nodeEndsWith(n, 16 /* CloseBraceToken */, sourceFile); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return isCompletedNode(n.block, sourceFile); - case 167 /* NewExpression */: + case 169 /* NewExpression */: if (!n.arguments) { return true; } // fall through - case 166 /* CallExpression */: - case 170 /* ParenthesizedExpression */: - case 158 /* ParenthesizedType */: + case 168 /* CallExpression */: + case 172 /* ParenthesizedExpression */: + case 160 /* ParenthesizedType */: return nodeEndsWith(n, 18 /* CloseParenToken */, sourceFile); - case 150 /* FunctionType */: - case 151 /* ConstructorType */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: return isCompletedNode(n.type, sourceFile); - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 146 /* ConstructSignature */: - case 145 /* CallSignature */: - case 172 /* ArrowFunction */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 148 /* ConstructSignature */: + case 147 /* CallSignature */: + case 174 /* ArrowFunction */: if (n.body) { return isCompletedNode(n.body, sourceFile); } @@ -38686,63 +39375,64 @@ var ts; // Even though type parameters can be unclosed, we can get away with // having at least a closing paren. return hasChildOfKind(n, 18 /* CloseParenToken */, sourceFile); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: return n.body && isCompletedNode(n.body, sourceFile); - case 194 /* IfStatement */: + case 196 /* IfStatement */: if (n.elseStatement) { return isCompletedNode(n.elseStatement, sourceFile); } return isCompletedNode(n.thenStatement, sourceFile); - case 193 /* ExpressionStatement */: - return isCompletedNode(n.expression, sourceFile); - case 162 /* ArrayLiteralExpression */: - case 160 /* ArrayBindingPattern */: - case 165 /* ElementAccessExpression */: - case 134 /* ComputedPropertyName */: - case 155 /* TupleType */: + case 195 /* ExpressionStatement */: + return isCompletedNode(n.expression, sourceFile) || + hasChildOfKind(n, 23 /* SemicolonToken */); + case 164 /* ArrayLiteralExpression */: + case 162 /* ArrayBindingPattern */: + case 167 /* ElementAccessExpression */: + case 136 /* ComputedPropertyName */: + case 157 /* TupleType */: return nodeEndsWith(n, 20 /* CloseBracketToken */, sourceFile); - case 147 /* IndexSignature */: + case 149 /* IndexSignature */: if (n.type) { return isCompletedNode(n.type, sourceFile); } return hasChildOfKind(n, 20 /* CloseBracketToken */, sourceFile); - case 239 /* CaseClause */: - case 240 /* DefaultClause */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed return false; - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 196 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 198 /* WhileStatement */: return isCompletedNode(n.statement, sourceFile); - case 195 /* DoStatement */: + case 197 /* DoStatement */: // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; - var hasWhileKeyword = findChildOfKind(n, 102 /* WhileKeyword */, sourceFile); + var hasWhileKeyword = findChildOfKind(n, 104 /* WhileKeyword */, sourceFile); if (hasWhileKeyword) { return nodeEndsWith(n, 18 /* CloseParenToken */, sourceFile); } return isCompletedNode(n.statement, sourceFile); - case 152 /* TypeQuery */: + case 154 /* TypeQuery */: return isCompletedNode(n.exprName, sourceFile); - case 174 /* TypeOfExpression */: - case 173 /* DeleteExpression */: - case 175 /* VoidExpression */: - case 182 /* YieldExpression */: - case 183 /* SpreadElementExpression */: + case 176 /* TypeOfExpression */: + case 175 /* DeleteExpression */: + case 177 /* VoidExpression */: + case 184 /* YieldExpression */: + case 185 /* SpreadElementExpression */: var unaryWordExpression = n; return isCompletedNode(unaryWordExpression.expression, sourceFile); - case 168 /* TaggedTemplateExpression */: + case 170 /* TaggedTemplateExpression */: return isCompletedNode(n.template, sourceFile); - case 181 /* TemplateExpression */: + case 183 /* TemplateExpression */: var lastSpan = ts.lastOrUndefined(n.templateSpans); return isCompletedNode(lastSpan, sourceFile); - case 188 /* TemplateSpan */: + case 190 /* TemplateSpan */: return ts.nodeIsPresent(n.literal); - case 177 /* PrefixUnaryExpression */: + case 179 /* PrefixUnaryExpression */: return isCompletedNode(n.operand, sourceFile); - case 179 /* BinaryExpression */: + case 181 /* BinaryExpression */: return isCompletedNode(n.right, sourceFile); - case 180 /* ConditionalExpression */: + case 182 /* ConditionalExpression */: return isCompletedNode(n.whenFalse, sourceFile); default: return true; @@ -38798,7 +39488,7 @@ var ts; // for the position of the relevant node (or comma). var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { // find syntax list that covers the span of the node - if (c.kind === 269 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 271 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -38904,7 +39594,7 @@ var ts; function findPrecedingToken(position, sourceFile, startNode) { return find(startNode || sourceFile); function findRightmostToken(n) { - if (isToken(n) || n.kind === 234 /* JsxText */) { + if (isToken(n) || n.kind === 236 /* JsxText */) { return n; } var children = n.getChildren(); @@ -38912,7 +39602,7 @@ var ts; return candidate && findRightmostToken(candidate); } function find(n) { - if (isToken(n) || n.kind === 234 /* JsxText */) { + if (isToken(n) || n.kind === 236 /* JsxText */) { return n; } var children = n.getChildren(); @@ -38926,10 +39616,10 @@ var ts; // if no - position is in the node itself so we should recurse in it. // NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia). // if this is the case - then we should assume that token in question is located in previous child. - if (position < child.end && (nodeHasTokens(child) || child.kind === 234 /* JsxText */)) { + if (position < child.end && (nodeHasTokens(child) || child.kind === 236 /* JsxText */)) { var start = child.getStart(sourceFile); var lookInPreviousChild = (start >= position) || - (child.kind === 234 /* JsxText */ && start === child.end); // whitespace only JsxText + (child.kind === 236 /* JsxText */ && start === child.end); // whitespace only JsxText if (lookInPreviousChild) { // actual start of the node is past the position - previous token should be at the end of previous child var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i); @@ -38941,7 +39631,7 @@ var ts; } } } - ts.Debug.assert(startNode !== undefined || n.kind === 246 /* SourceFile */); + ts.Debug.assert(startNode !== undefined || n.kind === 248 /* SourceFile */); // Here we know that none of child token nodes embrace the position, // the only known case is when position is at the end of the file. // Try to find the rightmost token in the file without filtering. @@ -39016,9 +39706,9 @@ var ts; var node = ts.getTokenAtPosition(sourceFile, position); if (isToken(node)) { switch (node.kind) { - case 100 /* VarKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: + case 102 /* VarKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: // if the current token is var, let or const, skip the VariableDeclarationList node = node.parent === undefined ? undefined : node.parent.parent; break; @@ -39067,21 +39757,21 @@ var ts; } ts.getNodeModifiers = getNodeModifiers; function getTypeArgumentOrTypeParameterList(node) { - if (node.kind === 149 /* TypeReference */ || node.kind === 166 /* CallExpression */) { + if (node.kind === 151 /* TypeReference */ || node.kind === 168 /* CallExpression */) { return node.typeArguments; } - if (ts.isFunctionLike(node) || node.kind === 212 /* ClassDeclaration */ || node.kind === 213 /* InterfaceDeclaration */) { + if (ts.isFunctionLike(node) || node.kind === 214 /* ClassDeclaration */ || node.kind === 215 /* InterfaceDeclaration */) { return node.typeParameters; } return undefined; } ts.getTypeArgumentOrTypeParameterList = getTypeArgumentOrTypeParameterList; function isToken(n) { - return n.kind >= 0 /* FirstToken */ && n.kind <= 132 /* LastToken */; + return n.kind >= 0 /* FirstToken */ && n.kind <= 134 /* LastToken */; } ts.isToken = isToken; function isWord(kind) { - return kind === 67 /* Identifier */ || ts.isKeyword(kind); + return kind === 69 /* Identifier */ || ts.isKeyword(kind); } ts.isWord = isWord; function isPropertyName(kind) { @@ -39091,8 +39781,17 @@ var ts; return kind === 2 /* SingleLineCommentTrivia */ || kind === 3 /* MultiLineCommentTrivia */; } ts.isComment = isComment; + function isStringOrRegularExpressionOrTemplateLiteral(kind) { + if (kind === 9 /* StringLiteral */ + || kind === 10 /* RegularExpressionLiteral */ + || ts.isTemplateLiteralKind(kind)) { + return true; + } + return false; + } + ts.isStringOrRegularExpressionOrTemplateLiteral = isStringOrRegularExpressionOrTemplateLiteral; function isPunctuation(kind) { - return 15 /* FirstPunctuation */ <= kind && kind <= 66 /* LastPunctuation */; + return 15 /* FirstPunctuation */ <= kind && kind <= 68 /* LastPunctuation */; } ts.isPunctuation = isPunctuation; function isInsideTemplateLiteral(node, position) { @@ -39102,9 +39801,9 @@ var ts; ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function isAccessibilityModifier(kind) { switch (kind) { - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: return true; } return false; @@ -39132,7 +39831,7 @@ var ts; var ts; (function (ts) { function isFirstDeclarationOfSymbolParameter(symbol) { - return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 136 /* Parameter */; + return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 138 /* Parameter */; } ts.isFirstDeclarationOfSymbolParameter = isFirstDeclarationOfSymbolParameter; var displayPartWriter = getDisplayPartWriter(); @@ -39154,7 +39853,8 @@ var ts; increaseIndent: function () { indent++; }, decreaseIndent: function () { indent--; }, clear: resetWriter, - trackSymbol: function () { } + trackSymbol: function () { }, + reportInaccessibleThisError: function () { } }; function writeIndent() { if (lineStart) { @@ -39319,7 +40019,7 @@ var ts; ts.getDeclaredName = getDeclaredName; function isImportOrExportSpecifierName(location) { return location.parent && - (location.parent.kind === 224 /* ImportSpecifier */ || location.parent.kind === 228 /* ExportSpecifier */) && + (location.parent.kind === 226 /* ImportSpecifier */ || location.parent.kind === 230 /* ExportSpecifier */) && location.parent.propertyName === location; } ts.isImportOrExportSpecifierName = isImportOrExportSpecifierName; @@ -39347,7 +40047,12 @@ var ts; (function (ts) { var formatting; (function (formatting) { - var scanner = ts.createScanner(2 /* Latest */, /*skipTrivia*/ false); + var standardScanner = ts.createScanner(2 /* Latest */, /*skipTrivia*/ false, 0 /* Standard */); + var jsxScanner = ts.createScanner(2 /* Latest */, /*skipTrivia*/ false, 1 /* JSX */); + /** + * Scanner that is currently used for formatting + */ + var scanner; var ScanAction; (function (ScanAction) { ScanAction[ScanAction["Scan"] = 0] = "Scan"; @@ -39357,6 +40062,8 @@ var ts; ScanAction[ScanAction["RescanJsxIdentifier"] = 4] = "RescanJsxIdentifier"; })(ScanAction || (ScanAction = {})); function getFormattingScanner(sourceFile, startPos, endPos) { + ts.Debug.assert(scanner === undefined); + scanner = sourceFile.languageVariant === 1 /* JSX */ ? jsxScanner : standardScanner; scanner.setText(sourceFile.text); scanner.setTextPos(startPos); var wasNewLine = true; @@ -39371,11 +40078,14 @@ var ts; isOnToken: isOnToken, lastTrailingTriviaWasNewLine: function () { return wasNewLine; }, close: function () { + ts.Debug.assert(scanner !== undefined); lastTokenInfo = undefined; scanner.setText(undefined); + scanner = undefined; } }; function advance() { + ts.Debug.assert(scanner !== undefined); lastTokenInfo = undefined; var isStarted = scanner.getStartPos() !== startPos; if (isStarted) { @@ -39419,10 +40129,10 @@ var ts; if (node) { switch (node.kind) { case 29 /* GreaterThanEqualsToken */: - case 62 /* GreaterThanGreaterThanEqualsToken */: - case 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: - case 43 /* GreaterThanGreaterThanToken */: + case 64 /* GreaterThanGreaterThanEqualsToken */: + case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: + case 44 /* GreaterThanGreaterThanToken */: return true; } } @@ -39431,11 +40141,11 @@ var ts; function shouldRescanJsxIdentifier(node) { if (node.parent) { switch (node.parent.kind) { - case 236 /* JsxAttribute */: - case 233 /* JsxOpeningElement */: - case 235 /* JsxClosingElement */: - case 232 /* JsxSelfClosingElement */: - return node.kind === 67 /* Identifier */; + case 238 /* JsxAttribute */: + case 235 /* JsxOpeningElement */: + case 237 /* JsxClosingElement */: + case 234 /* JsxSelfClosingElement */: + return node.kind === 69 /* Identifier */; } } return false; @@ -39448,9 +40158,10 @@ var ts; container.kind === 14 /* TemplateTail */; } function startsWithSlashToken(t) { - return t === 38 /* SlashToken */ || t === 59 /* SlashEqualsToken */; + return t === 39 /* SlashToken */ || t === 61 /* SlashEqualsToken */; } function readTokenInfo(n) { + ts.Debug.assert(scanner !== undefined); if (!isOnToken()) { // scanner is not on the token (either advance was not called yet or scanner is already past the end position) return { @@ -39500,7 +40211,7 @@ var ts; currentToken = scanner.reScanTemplateToken(); lastScanAction = 3 /* RescanTemplateToken */; } - else if (expectedScanAction === 4 /* RescanJsxIdentifier */ && currentToken === 67 /* Identifier */) { + else if (expectedScanAction === 4 /* RescanJsxIdentifier */ && currentToken === 69 /* Identifier */) { currentToken = scanner.scanJsxIdentifier(); lastScanAction = 4 /* RescanJsxIdentifier */; } @@ -39544,6 +40255,7 @@ var ts; return fixTokenKind(lastTokenInfo, n); } function isOnToken() { + ts.Debug.assert(scanner !== undefined); var current = (lastTokenInfo && lastTokenInfo.token.kind) || scanner.getToken(); var startPos = (lastTokenInfo && lastTokenInfo.token.pos) || scanner.getStartPos(); return startPos < endPos && current !== 1 /* EndOfFileToken */ && !ts.isTrivia(current); @@ -39822,17 +40534,17 @@ var ts; this.IgnoreAfterLineComment = new formatting.Rule(formatting.RuleDescriptor.create3(2 /* SingleLineCommentTrivia */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create1(1 /* Ignore */)); // Space after keyword but not before ; or : or ? this.NoSpaceBeforeSemicolon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceBeforeColon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 53 /* ColonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); - this.NoSpaceBeforeQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52 /* QuestionToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); - this.SpaceAfterColon = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* ColonToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 2 /* Space */)); - this.SpaceAfterQuestionMarkInConditionalOperator = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsConditionalOperatorContext), 2 /* Space */)); - this.NoSpaceAfterQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeColon = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 54 /* ColonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); + this.NoSpaceBeforeQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 53 /* QuestionToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); + this.SpaceAfterColon = new formatting.Rule(formatting.RuleDescriptor.create3(54 /* ColonToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 2 /* Space */)); + this.SpaceAfterQuestionMarkInConditionalOperator = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsConditionalOperatorContext), 2 /* Space */)); + this.NoSpaceAfterQuestionMark = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* QuestionToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterSemicolon = new formatting.Rule(formatting.RuleDescriptor.create3(23 /* SemicolonToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Space after }. this.SpaceAfterCloseBrace = new formatting.Rule(formatting.RuleDescriptor.create3(16 /* CloseBraceToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsAfterCodeBlockContext), 2 /* Space */)); // Special case for (}, else) and (}, while) since else & while tokens are not part of the tree which makes SpaceAfterCloseBrace rule not applied - this.SpaceBetweenCloseBraceAndElse = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 78 /* ElseKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceBetweenCloseBraceAndWhile = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 102 /* WhileKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenCloseBraceAndElse = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 80 /* ElseKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenCloseBraceAndWhile = new formatting.Rule(formatting.RuleDescriptor.create1(16 /* CloseBraceToken */, 104 /* WhileKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterCloseBrace = new formatting.Rule(formatting.RuleDescriptor.create3(16 /* CloseBraceToken */, formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 20 /* CloseBracketToken */, 24 /* CommaToken */, 23 /* SemicolonToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // No space for dot this.NoSpaceBeforeDot = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 21 /* DotToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); @@ -39844,10 +40556,10 @@ var ts; this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc) - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 3 /* MultiLineCommentTrivia */, 71 /* ClassKeyword */]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 3 /* MultiLineCommentTrivia */, 73 /* ClassKeyword */]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a control flow construct - this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 77 /* DoKeyword */, 98 /* TryKeyword */, 83 /* FinallyKeyword */, 78 /* ElseKeyword */]); + this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 79 /* DoKeyword */, 100 /* TryKeyword */, 85 /* FinallyKeyword */, 80 /* ElseKeyword */]); this.SpaceBeforeOpenBraceInControl = new formatting.Rule(formatting.RuleDescriptor.create2(this.ControlOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}. this.SpaceAfterOpenBrace = new formatting.Rule(formatting.RuleDescriptor.create3(15 /* OpenBraceToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSingleLineBlockContext), 2 /* Space */)); @@ -39861,55 +40573,55 @@ var ts; // Prefix operators generally shouldn't have a space between // them and their target unary expression. this.NoSpaceAfterUnaryPrefixOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.UnaryPrefixOperators, formatting.Shared.TokenRange.UnaryPrefixExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); - this.NoSpaceAfterUnaryPreincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(40 /* PlusPlusToken */, formatting.Shared.TokenRange.UnaryPreincrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceAfterUnaryPredecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(41 /* MinusMinusToken */, formatting.Shared.TokenRange.UnaryPredecrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceBeforeUnaryPostincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostincrementExpressions, 40 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceBeforeUnaryPostdecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostdecrementExpressions, 41 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterUnaryPreincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(41 /* PlusPlusToken */, formatting.Shared.TokenRange.UnaryPreincrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterUnaryPredecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create3(42 /* MinusMinusToken */, formatting.Shared.TokenRange.UnaryPredecrementExpressions), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeUnaryPostincrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostincrementExpressions, 41 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeUnaryPostdecrementOperator = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.UnaryPostdecrementExpressions, 42 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // More unary operator special-casing. // DevDiv 181814: Be careful when removing leading whitespace // around unary operators. Examples: // 1 - -2 --X--> 1--2 // a + ++b --X--> a+++b - this.SpaceAfterPostincrementWhenFollowedByAdd = new formatting.Rule(formatting.RuleDescriptor.create1(40 /* PlusPlusToken */, 35 /* PlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterPostincrementWhenFollowedByAdd = new formatting.Rule(formatting.RuleDescriptor.create1(41 /* PlusPlusToken */, 35 /* PlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.SpaceAfterAddWhenFollowedByUnaryPlus = new formatting.Rule(formatting.RuleDescriptor.create1(35 /* PlusToken */, 35 /* PlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); - this.SpaceAfterAddWhenFollowedByPreincrement = new formatting.Rule(formatting.RuleDescriptor.create1(35 /* PlusToken */, 40 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); - this.SpaceAfterPostdecrementWhenFollowedBySubtract = new formatting.Rule(formatting.RuleDescriptor.create1(41 /* MinusMinusToken */, 36 /* MinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterAddWhenFollowedByPreincrement = new formatting.Rule(formatting.RuleDescriptor.create1(35 /* PlusToken */, 41 /* PlusPlusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterPostdecrementWhenFollowedBySubtract = new formatting.Rule(formatting.RuleDescriptor.create1(42 /* MinusMinusToken */, 36 /* MinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.SpaceAfterSubtractWhenFollowedByUnaryMinus = new formatting.Rule(formatting.RuleDescriptor.create1(36 /* MinusToken */, 36 /* MinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); - this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(36 /* MinusToken */, 41 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); + this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(36 /* MinusToken */, 42 /* MinusMinusToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 24 /* CommaToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([100 /* VarKeyword */, 96 /* ThrowKeyword */, 90 /* NewKeyword */, 76 /* DeleteKeyword */, 92 /* ReturnKeyword */, 99 /* TypeOfKeyword */, 117 /* AwaitKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([106 /* LetKeyword */, 72 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); + this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([102 /* VarKeyword */, 98 /* ThrowKeyword */, 92 /* NewKeyword */, 78 /* DeleteKeyword */, 94 /* ReturnKeyword */, 101 /* TypeOfKeyword */, 119 /* AwaitKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([108 /* LetKeyword */, 74 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8 /* Delete */)); - this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(85 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(87 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8 /* Delete */)); - this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(101 /* VoidKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), 2 /* Space */)); - this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(92 /* ReturnKeyword */, 23 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(103 /* VoidKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsVoidOpContext), 2 /* Space */)); + this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(94 /* ReturnKeyword */, 23 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Add a space between statements. All keywords except (do,else,case) has open/close parens after them. // So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any] - this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 77 /* DoKeyword */, 78 /* ElseKeyword */, 69 /* CaseKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2 /* Space */)); + this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 79 /* DoKeyword */, 80 /* ElseKeyword */, 71 /* CaseKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2 /* Space */)); // This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter. - this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([98 /* TryKeyword */, 83 /* FinallyKeyword */]), 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([100 /* TryKeyword */, 85 /* FinallyKeyword */]), 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // get x() {} // set x(val) {} - this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([121 /* GetKeyword */, 127 /* SetKeyword */]), 67 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([123 /* GetKeyword */, 129 /* SetKeyword */]), 69 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); // Special case for binary operators (that are keywords). For these we have to add a space and shouldn't follow any user options. this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); // TypeScript-specific higher priority rules // Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses - this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(119 /* ConstructorKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(121 /* ConstructorKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Use of module as a function call. e.g.: import m2 = module("m2"); - this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([123 /* ModuleKeyword */, 125 /* RequireKeyword */]), 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([125 /* ModuleKeyword */, 127 /* RequireKeyword */]), 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([113 /* AbstractKeyword */, 71 /* ClassKeyword */, 120 /* DeclareKeyword */, 75 /* DefaultKeyword */, 79 /* EnumKeyword */, 80 /* ExportKeyword */, 81 /* ExtendsKeyword */, 121 /* GetKeyword */, 104 /* ImplementsKeyword */, 87 /* ImportKeyword */, 105 /* InterfaceKeyword */, 123 /* ModuleKeyword */, 124 /* NamespaceKeyword */, 108 /* PrivateKeyword */, 110 /* PublicKeyword */, 109 /* ProtectedKeyword */, 127 /* SetKeyword */, 111 /* StaticKeyword */, 130 /* TypeKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([81 /* ExtendsKeyword */, 104 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 73 /* ClassKeyword */, 122 /* DeclareKeyword */, 77 /* DefaultKeyword */, 81 /* EnumKeyword */, 82 /* ExportKeyword */, 83 /* ExtendsKeyword */, 123 /* GetKeyword */, 106 /* ImplementsKeyword */, 89 /* ImportKeyword */, 107 /* InterfaceKeyword */, 125 /* ModuleKeyword */, 126 /* NamespaceKeyword */, 110 /* PrivateKeyword */, 112 /* PublicKeyword */, 111 /* ProtectedKeyword */, 129 /* SetKeyword */, 113 /* StaticKeyword */, 132 /* TypeKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83 /* ExtendsKeyword */, 106 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9 /* StringLiteral */, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); // Lambda expressions this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(34 /* EqualsGreaterThanToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // Optional parameters and let args - this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(22 /* DotDotDotToken */, 67 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceAfterOptionalParameters = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* QuestionToken */, formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 24 /* CommaToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); + this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(22 /* DotDotDotToken */, 69 /* Identifier */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterOptionalParameters = new formatting.Rule(formatting.RuleDescriptor.create3(53 /* QuestionToken */, formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 24 /* CommaToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), 8 /* Delete */)); // generics and type assertions this.NoSpaceBeforeOpenAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.TypeNames, 25 /* LessThanToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8 /* Delete */)); this.NoSpaceBetweenCloseParenAndAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create1(18 /* CloseParenToken */, 25 /* LessThanToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), 8 /* Delete */)); @@ -39920,17 +40632,20 @@ var ts; // Remove spaces in empty interface literals. e.g.: x: {} this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(15 /* OpenBraceToken */, 16 /* CloseBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), 8 /* Delete */)); // decorators - this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 54 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); - this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(54 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([113 /* AbstractKeyword */, 67 /* Identifier */, 80 /* ExportKeyword */, 75 /* DefaultKeyword */, 71 /* ClassKeyword */, 111 /* StaticKeyword */, 110 /* PublicKeyword */, 108 /* PrivateKeyword */, 109 /* ProtectedKeyword */, 121 /* GetKeyword */, 127 /* SetKeyword */, 19 /* OpenBracketToken */, 37 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); - this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(85 /* FunctionKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8 /* Delete */)); - this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(37 /* AsteriskToken */, formatting.Shared.TokenRange.FromTokens([67 /* Identifier */, 17 /* OpenParenToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2 /* Space */)); - this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(112 /* YieldKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8 /* Delete */)); - this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([112 /* YieldKeyword */, 37 /* AsteriskToken */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2 /* Space */)); + this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 55 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(55 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 69 /* Identifier */, 82 /* ExportKeyword */, 77 /* DefaultKeyword */, 73 /* ClassKeyword */, 113 /* StaticKeyword */, 112 /* PublicKeyword */, 110 /* PrivateKeyword */, 111 /* ProtectedKeyword */, 123 /* GetKeyword */, 129 /* SetKeyword */, 19 /* OpenBracketToken */, 37 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); + this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(87 /* FunctionKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8 /* Delete */)); + this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(37 /* AsteriskToken */, formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 17 /* OpenParenToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2 /* Space */)); + this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(114 /* YieldKeyword */, 37 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8 /* Delete */)); + this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([114 /* YieldKeyword */, 37 /* AsteriskToken */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2 /* Space */)); // Async-await - this.SpaceBetweenAsyncAndFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(116 /* AsyncKeyword */, 85 /* FunctionKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenAsyncAndOpenParen = new formatting.Rule(formatting.RuleDescriptor.create1(118 /* AsyncKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsArrowFunctionContext, Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenAsyncAndFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(118 /* AsyncKeyword */, 87 /* FunctionKeyword */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); // template string - this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(67 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.SpaceBetweenTagAndTemplateString = new formatting.Rule(formatting.RuleDescriptor.create3(69 /* Identifier */, formatting.Shared.TokenRange.FromTokens([11 /* NoSubstitutionTemplateLiteral */, 12 /* TemplateHead */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); + this.NoSpaceAfterTemplateHeadAndMiddle = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([12 /* TemplateHead */, 13 /* TemplateMiddle */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceBeforeTemplateMiddleAndTail = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([13 /* TemplateMiddle */, 14 /* TemplateTail */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -39957,8 +40672,8 @@ var ts; this.NoSpaceBeforeOpenParenInFuncCall, this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, this.SpaceAfterVoidOperator, - this.SpaceBetweenAsyncAndFunctionKeyword, - this.SpaceBetweenTagAndTemplateString, + this.SpaceBetweenAsyncAndOpenParen, this.SpaceBetweenAsyncAndFunctionKeyword, + this.SpaceBetweenTagAndTemplateString, this.NoSpaceAfterTemplateHeadAndMiddle, this.NoSpaceBeforeTemplateMiddleAndTail, // TypeScript-specific rules this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, @@ -40026,14 +40741,14 @@ var ts; this.NoSpaceAfterOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19 /* OpenBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.NoSpaceBeforeCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 20 /* CloseBracketToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); // Insert space after function keyword for anonymous functions - this.SpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(85 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); - this.NoSpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(85 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 8 /* Delete */)); + this.SpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(87 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.NoSpaceAfterAnonymousFunctionKeyword = new formatting.Rule(formatting.RuleDescriptor.create1(87 /* FunctionKeyword */, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 8 /* Delete */)); } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_30 in o) { - if (o[name_30] === rule) { - return name_30; + for (var name_31 in o) { + if (o[name_31] === rule) { + return name_31; } } throw new Error("Unknown rule"); @@ -40042,40 +40757,40 @@ var ts; /// Contexts /// Rules.IsForContext = function (context) { - return context.contextNode.kind === 197 /* ForStatement */; + return context.contextNode.kind === 199 /* ForStatement */; }; Rules.IsNotForContext = function (context) { return !Rules.IsForContext(context); }; Rules.IsBinaryOpContext = function (context) { switch (context.contextNode.kind) { - case 179 /* BinaryExpression */: - case 180 /* ConditionalExpression */: - case 187 /* AsExpression */: - case 148 /* TypePredicate */: - case 156 /* UnionType */: - case 157 /* IntersectionType */: + case 181 /* BinaryExpression */: + case 182 /* ConditionalExpression */: + case 189 /* AsExpression */: + case 150 /* TypePredicate */: + case 158 /* UnionType */: + case 159 /* IntersectionType */: return true; // equals in binding elements: function foo([[x, y] = [1, 2]]) - case 161 /* BindingElement */: + case 163 /* BindingElement */: // equals in type X = ... - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: // equal in import a = module('a'); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: // equal in let a = 0; - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: // equal in p = 0; - case 136 /* Parameter */: - case 245 /* EnumMember */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - return context.currentTokenSpan.kind === 55 /* EqualsToken */ || context.nextTokenSpan.kind === 55 /* EqualsToken */; + case 138 /* Parameter */: + case 247 /* EnumMember */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + return context.currentTokenSpan.kind === 56 /* EqualsToken */ || context.nextTokenSpan.kind === 56 /* EqualsToken */; // "in" keyword in for (let x in []) { } - case 198 /* ForInStatement */: - return context.currentTokenSpan.kind === 88 /* InKeyword */ || context.nextTokenSpan.kind === 88 /* InKeyword */; + case 200 /* ForInStatement */: + return context.currentTokenSpan.kind === 90 /* InKeyword */ || context.nextTokenSpan.kind === 90 /* InKeyword */; // Technically, "of" is not a binary operator, but format it the same way as "in" - case 199 /* ForOfStatement */: - return context.currentTokenSpan.kind === 132 /* OfKeyword */ || context.nextTokenSpan.kind === 132 /* OfKeyword */; + case 201 /* ForOfStatement */: + return context.currentTokenSpan.kind === 134 /* OfKeyword */ || context.nextTokenSpan.kind === 134 /* OfKeyword */; } return false; }; @@ -40083,7 +40798,7 @@ var ts; return !Rules.IsBinaryOpContext(context); }; Rules.IsConditionalOperatorContext = function (context) { - return context.contextNode.kind === 180 /* ConditionalExpression */; + return context.contextNode.kind === 182 /* ConditionalExpression */; }; Rules.IsSameLineTokenOrBeforeMultilineBlockContext = function (context) { //// This check is mainly used inside SpaceBeforeOpenBraceInControl and SpaceBeforeOpenBraceInFunction. @@ -40127,93 +40842,93 @@ var ts; return true; } switch (node.kind) { - case 190 /* Block */: - case 218 /* CaseBlock */: - case 163 /* ObjectLiteralExpression */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 220 /* CaseBlock */: + case 165 /* ObjectLiteralExpression */: + case 219 /* ModuleBlock */: return true; } return false; }; Rules.IsFunctionDeclContext = function (context) { switch (context.contextNode.kind) { - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: //case SyntaxKind.MemberFunctionDeclaration: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: ///case SyntaxKind.MethodSignature: - case 145 /* CallSignature */: - case 171 /* FunctionExpression */: - case 142 /* Constructor */: - case 172 /* ArrowFunction */: + case 147 /* CallSignature */: + case 173 /* FunctionExpression */: + case 144 /* Constructor */: + case 174 /* ArrowFunction */: //case SyntaxKind.ConstructorDeclaration: //case SyntaxKind.SimpleArrowFunctionExpression: //case SyntaxKind.ParenthesizedArrowFunctionExpression: - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: return true; } return false; }; Rules.IsFunctionDeclarationOrFunctionExpressionContext = function (context) { - return context.contextNode.kind === 211 /* FunctionDeclaration */ || context.contextNode.kind === 171 /* FunctionExpression */; + return context.contextNode.kind === 213 /* FunctionDeclaration */ || context.contextNode.kind === 173 /* FunctionExpression */; }; Rules.IsTypeScriptDeclWithBlockContext = function (context) { return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode); }; Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) { switch (node.kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 153 /* TypeLiteral */: - case 216 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 155 /* TypeLiteral */: + case 218 /* ModuleDeclaration */: return true; } return false; }; Rules.IsAfterCodeBlockContext = function (context) { switch (context.currentTokenParent.kind) { - case 212 /* ClassDeclaration */: - case 216 /* ModuleDeclaration */: - case 215 /* EnumDeclaration */: - case 190 /* Block */: - case 242 /* CatchClause */: - case 217 /* ModuleBlock */: - case 204 /* SwitchStatement */: + case 214 /* ClassDeclaration */: + case 218 /* ModuleDeclaration */: + case 217 /* EnumDeclaration */: + case 192 /* Block */: + case 244 /* CatchClause */: + case 219 /* ModuleBlock */: + case 206 /* SwitchStatement */: return true; } return false; }; Rules.IsControlDeclContext = function (context) { switch (context.contextNode.kind) { - case 194 /* IfStatement */: - case 204 /* SwitchStatement */: - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 196 /* WhileStatement */: - case 207 /* TryStatement */: - case 195 /* DoStatement */: - case 203 /* WithStatement */: + case 196 /* IfStatement */: + case 206 /* SwitchStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 198 /* WhileStatement */: + case 209 /* TryStatement */: + case 197 /* DoStatement */: + case 205 /* WithStatement */: // TODO // case SyntaxKind.ElseClause: - case 242 /* CatchClause */: + case 244 /* CatchClause */: return true; default: return false; } }; Rules.IsObjectContext = function (context) { - return context.contextNode.kind === 163 /* ObjectLiteralExpression */; + return context.contextNode.kind === 165 /* ObjectLiteralExpression */; }; Rules.IsFunctionCallContext = function (context) { - return context.contextNode.kind === 166 /* CallExpression */; + return context.contextNode.kind === 168 /* CallExpression */; }; Rules.IsNewContext = function (context) { - return context.contextNode.kind === 167 /* NewExpression */; + return context.contextNode.kind === 169 /* NewExpression */; }; Rules.IsFunctionCallOrNewContext = function (context) { return Rules.IsFunctionCallContext(context) || Rules.IsNewContext(context); @@ -40221,6 +40936,9 @@ var ts; Rules.IsPreviousTokenNotComma = function (context) { return context.currentTokenSpan.kind !== 24 /* CommaToken */; }; + Rules.IsArrowFunctionContext = function (context) { + return context.contextNode.kind === 174 /* ArrowFunction */; + }; Rules.IsSameLineTokenContext = function (context) { return context.TokensAreOnSameLine(); }; @@ -40237,41 +40955,41 @@ var ts; while (ts.isExpression(node)) { node = node.parent; } - return node.kind === 137 /* Decorator */; + return node.kind === 139 /* Decorator */; }; Rules.IsStartOfVariableDeclarationList = function (context) { - return context.currentTokenParent.kind === 210 /* VariableDeclarationList */ && + return context.currentTokenParent.kind === 212 /* VariableDeclarationList */ && context.currentTokenParent.getStart(context.sourceFile) === context.currentTokenSpan.pos; }; Rules.IsNotFormatOnEnter = function (context) { return context.formattingRequestKind !== 2 /* FormatOnEnter */; }; Rules.IsModuleDeclContext = function (context) { - return context.contextNode.kind === 216 /* ModuleDeclaration */; + return context.contextNode.kind === 218 /* ModuleDeclaration */; }; Rules.IsObjectTypeContext = function (context) { - return context.contextNode.kind === 153 /* TypeLiteral */; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration; + return context.contextNode.kind === 155 /* TypeLiteral */; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration; }; Rules.IsTypeArgumentOrParameterOrAssertion = function (token, parent) { if (token.kind !== 25 /* LessThanToken */ && token.kind !== 27 /* GreaterThanToken */) { return false; } switch (parent.kind) { - case 149 /* TypeReference */: - case 169 /* TypeAssertionExpression */: - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 186 /* ExpressionWithTypeArguments */: + case 151 /* TypeReference */: + case 171 /* TypeAssertionExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 188 /* ExpressionWithTypeArguments */: return true; default: return false; @@ -40282,13 +41000,13 @@ var ts; Rules.IsTypeArgumentOrParameterOrAssertion(context.nextTokenSpan, context.nextTokenParent); }; Rules.IsTypeAssertionContext = function (context) { - return context.contextNode.kind === 169 /* TypeAssertionExpression */; + return context.contextNode.kind === 171 /* TypeAssertionExpression */; }; Rules.IsVoidOpContext = function (context) { - return context.currentTokenSpan.kind === 101 /* VoidKeyword */ && context.currentTokenParent.kind === 175 /* VoidExpression */; + return context.currentTokenSpan.kind === 103 /* VoidKeyword */ && context.currentTokenParent.kind === 177 /* VoidExpression */; }; Rules.IsYieldOrYieldStarWithOperand = function (context) { - return context.contextNode.kind === 182 /* YieldExpression */ && context.contextNode.expression !== undefined; + return context.contextNode.kind === 184 /* YieldExpression */ && context.contextNode.expression !== undefined; }; return Rules; })(); @@ -40312,7 +41030,7 @@ var ts; return result; }; RulesMap.prototype.Initialize = function (rules) { - this.mapRowLength = 132 /* LastToken */ + 1; + this.mapRowLength = 134 /* LastToken */ + 1; this.map = new Array(this.mapRowLength * this.mapRowLength); //new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map var rulesBucketConstructionStateList = new Array(this.map.length); //new Array(this.map.length); @@ -40507,7 +41225,7 @@ var ts; } TokenAllAccess.prototype.GetTokens = function () { var result = []; - for (var token = 0 /* FirstToken */; token <= 132 /* LastToken */; token++) { + for (var token = 0 /* FirstToken */; token <= 134 /* LastToken */; token++) { result.push(token); } return result; @@ -40549,17 +41267,17 @@ var ts; }; TokenRange.Any = TokenRange.AllTokens(); TokenRange.AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([3 /* MultiLineCommentTrivia */])); - TokenRange.Keywords = TokenRange.FromRange(68 /* FirstKeyword */, 132 /* LastKeyword */); - TokenRange.BinaryOperators = TokenRange.FromRange(25 /* FirstBinaryOperator */, 66 /* LastBinaryOperator */); - TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([88 /* InKeyword */, 89 /* InstanceOfKeyword */, 132 /* OfKeyword */, 114 /* AsKeyword */, 122 /* IsKeyword */]); - TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([40 /* PlusPlusToken */, 41 /* MinusMinusToken */, 49 /* TildeToken */, 48 /* ExclamationToken */]); - TokenRange.UnaryPrefixExpressions = TokenRange.FromTokens([8 /* NumericLiteral */, 67 /* Identifier */, 17 /* OpenParenToken */, 19 /* OpenBracketToken */, 15 /* OpenBraceToken */, 95 /* ThisKeyword */, 90 /* NewKeyword */]); - TokenRange.UnaryPreincrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 17 /* OpenParenToken */, 95 /* ThisKeyword */, 90 /* NewKeyword */]); - TokenRange.UnaryPostincrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 90 /* NewKeyword */]); - TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 17 /* OpenParenToken */, 95 /* ThisKeyword */, 90 /* NewKeyword */]); - TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([67 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 90 /* NewKeyword */]); + TokenRange.Keywords = TokenRange.FromRange(70 /* FirstKeyword */, 134 /* LastKeyword */); + TokenRange.BinaryOperators = TokenRange.FromRange(25 /* FirstBinaryOperator */, 68 /* LastBinaryOperator */); + TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([90 /* InKeyword */, 91 /* InstanceOfKeyword */, 134 /* OfKeyword */, 116 /* AsKeyword */, 124 /* IsKeyword */]); + TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([41 /* PlusPlusToken */, 42 /* MinusMinusToken */, 50 /* TildeToken */, 49 /* ExclamationToken */]); + TokenRange.UnaryPrefixExpressions = TokenRange.FromTokens([8 /* NumericLiteral */, 69 /* Identifier */, 17 /* OpenParenToken */, 19 /* OpenBracketToken */, 15 /* OpenBraceToken */, 97 /* ThisKeyword */, 92 /* NewKeyword */]); + TokenRange.UnaryPreincrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 17 /* OpenParenToken */, 97 /* ThisKeyword */, 92 /* NewKeyword */]); + TokenRange.UnaryPostincrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 92 /* NewKeyword */]); + TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 17 /* OpenParenToken */, 97 /* ThisKeyword */, 92 /* NewKeyword */]); + TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([69 /* Identifier */, 18 /* CloseParenToken */, 20 /* CloseBracketToken */, 92 /* NewKeyword */]); TokenRange.Comments = TokenRange.FromTokens([2 /* SingleLineCommentTrivia */, 3 /* MultiLineCommentTrivia */]); - TokenRange.TypeNames = TokenRange.FromTokens([67 /* Identifier */, 126 /* NumberKeyword */, 128 /* StringKeyword */, 118 /* BooleanKeyword */, 129 /* SymbolKeyword */, 101 /* VoidKeyword */, 115 /* AnyKeyword */]); + TokenRange.TypeNames = TokenRange.FromTokens([69 /* Identifier */, 128 /* NumberKeyword */, 130 /* StringKeyword */, 120 /* BooleanKeyword */, 131 /* SymbolKeyword */, 103 /* VoidKeyword */, 117 /* AnyKeyword */]); return TokenRange; })(); Shared.TokenRange = TokenRange; @@ -40773,17 +41491,17 @@ var ts; // i.e. parent is class declaration with the list of members and node is one of members. function isListElement(parent, node) { switch (parent.kind) { - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: return ts.rangeContainsRange(parent.members, node); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: var body = parent.body; - return body && body.kind === 190 /* Block */ && ts.rangeContainsRange(body.statements, node); - case 246 /* SourceFile */: - case 190 /* Block */: - case 217 /* ModuleBlock */: + return body && body.kind === 192 /* Block */ && ts.rangeContainsRange(body.statements, node); + case 248 /* SourceFile */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return ts.rangeContainsRange(parent.statements, node); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return ts.rangeContainsRange(parent.block.statements, node); } return false; @@ -40956,9 +41674,9 @@ var ts; // - source file // - switch\default clauses if (isSomeBlock(parent.kind) || - parent.kind === 246 /* SourceFile */ || - parent.kind === 239 /* CaseClause */ || - parent.kind === 240 /* DefaultClause */) { + parent.kind === 248 /* SourceFile */ || + parent.kind === 241 /* CaseClause */ || + parent.kind === 242 /* DefaultClause */) { indentation = parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(); } else { @@ -40994,19 +41712,19 @@ var ts; return node.modifiers[0].kind; } switch (node.kind) { - case 212 /* ClassDeclaration */: return 71 /* ClassKeyword */; - case 213 /* InterfaceDeclaration */: return 105 /* InterfaceKeyword */; - case 211 /* FunctionDeclaration */: return 85 /* FunctionKeyword */; - case 215 /* EnumDeclaration */: return 215 /* EnumDeclaration */; - case 143 /* GetAccessor */: return 121 /* GetKeyword */; - case 144 /* SetAccessor */: return 127 /* SetKeyword */; - case 141 /* MethodDeclaration */: + case 214 /* ClassDeclaration */: return 73 /* ClassKeyword */; + case 215 /* InterfaceDeclaration */: return 107 /* InterfaceKeyword */; + case 213 /* FunctionDeclaration */: return 87 /* FunctionKeyword */; + case 217 /* EnumDeclaration */: return 217 /* EnumDeclaration */; + case 145 /* GetAccessor */: return 123 /* GetKeyword */; + case 146 /* SetAccessor */: return 129 /* SetKeyword */; + case 143 /* MethodDeclaration */: if (node.asteriskToken) { return 37 /* AsteriskToken */; } // fall-through - case 139 /* PropertyDeclaration */: - case 136 /* Parameter */: + case 141 /* PropertyDeclaration */: + case 138 /* Parameter */: return node.name.kind; } } @@ -41040,9 +41758,9 @@ var ts; case 20 /* CloseBracketToken */: case 17 /* OpenParenToken */: case 18 /* CloseParenToken */: - case 78 /* ElseKeyword */: - case 102 /* WhileKeyword */: - case 54 /* AtToken */: + case 80 /* ElseKeyword */: + case 104 /* WhileKeyword */: + case 55 /* AtToken */: return indentation; default: // if token line equals to the line of containing node (this is a first token in the node) - use node indentation @@ -41142,7 +41860,7 @@ var ts; consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation); return inheritedIndentation; } - var effectiveParentStartLine = child.kind === 137 /* Decorator */ ? childStartLine : undecoratedParentStartLine; + var effectiveParentStartLine = child.kind === 139 /* Decorator */ ? childStartLine : undecoratedParentStartLine; var childIndentation = computeIndentation(child, childStartLine, childIndentationAmount, node, parentDynamicIndentation, effectiveParentStartLine); processNode(child, childContextNode, childStartLine, undecoratedChildStartLine, childIndentation.indentation, childIndentation.delta); childContextNode = node; @@ -41399,8 +42117,8 @@ var ts; for (var line = line1; line < line2; ++line) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); - // do not trim whitespaces in comments - if (range && ts.isComment(range.kind) && range.pos <= lineEndPosition && range.end > lineEndPosition) { + // do not trim whitespaces in comments or template expression + if (range && (ts.isComment(range.kind) || ts.isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) { continue; } var pos = lineEndPosition; @@ -41466,20 +42184,20 @@ var ts; } function isSomeBlock(kind) { switch (kind) { - case 190 /* Block */: - case 217 /* ModuleBlock */: + case 192 /* Block */: + case 219 /* ModuleBlock */: return true; } return false; } function getOpenTokenForList(node, list) { switch (node.kind) { - case 142 /* Constructor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 172 /* ArrowFunction */: + case 144 /* Constructor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 174 /* ArrowFunction */: if (node.typeParameters === list) { return 25 /* LessThanToken */; } @@ -41487,8 +42205,8 @@ var ts; return 17 /* OpenParenToken */; } break; - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: if (node.typeArguments === list) { return 25 /* LessThanToken */; } @@ -41496,7 +42214,7 @@ var ts; return 17 /* OpenParenToken */; } break; - case 149 /* TypeReference */: + case 151 /* TypeReference */: if (node.typeArguments === list) { return 25 /* LessThanToken */; } @@ -41580,22 +42298,39 @@ var ts; if (position > sourceFile.text.length) { return 0; // past EOF } + // no indentation when the indent style is set to none, + // so we can return fast + if (options.IndentStyle === ts.IndentStyle.None) { + return 0; + } var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { return 0; } // no indentation in string \regex\template literals - var precedingTokenIsLiteral = precedingToken.kind === 9 /* StringLiteral */ || - precedingToken.kind === 10 /* RegularExpressionLiteral */ || - precedingToken.kind === 11 /* NoSubstitutionTemplateLiteral */ || - precedingToken.kind === 12 /* TemplateHead */ || - precedingToken.kind === 13 /* TemplateMiddle */ || - precedingToken.kind === 14 /* TemplateTail */; + var precedingTokenIsLiteral = ts.isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind); if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } var lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line; - if (precedingToken.kind === 24 /* CommaToken */ && precedingToken.parent.kind !== 179 /* BinaryExpression */) { + // indentation is first non-whitespace character in a previous line + // for block indentation, we should look for a line which contains something that's not + // whitespace. + if (options.IndentStyle === ts.IndentStyle.Block) { + // move backwards until we find a line with a non-whitespace character, + // then find the first non-whitespace character for that line. + var current_1 = position; + while (current_1 > 0) { + var char = sourceFile.text.charCodeAt(current_1); + if (!ts.isWhiteSpace(char) && !ts.isLineBreak(char)) { + break; + } + current_1--; + } + var lineStart = ts.getLineStartPositionForPosition(current_1, sourceFile); + return SmartIndenter.findFirstNonWhitespaceColumn(lineStart, current_1, sourceFile, options); + } + if (precedingToken.kind === 24 /* CommaToken */ && precedingToken.parent.kind !== 181 /* BinaryExpression */) { // previous token is comma that separates items in list - find the previous item and try to derive indentation from it var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options); if (actualIndentation !== -1 /* Unknown */) { @@ -41714,7 +42449,7 @@ var ts; // - parent is SourceFile - by default immediate children of SourceFile are not indented except when user indents them manually // - parent and child are not on the same line var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && - (parent.kind === 246 /* SourceFile */ || !parentAndChildShareLine); + (parent.kind === 248 /* SourceFile */ || !parentAndChildShareLine); if (!useActualIndentation) { return -1 /* Unknown */; } @@ -41747,8 +42482,8 @@ var ts; return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); } function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) { - if (parent.kind === 194 /* IfStatement */ && parent.elseStatement === child) { - var elseKeyword = ts.findChildOfKind(parent, 78 /* ElseKeyword */, sourceFile); + if (parent.kind === 196 /* IfStatement */ && parent.elseStatement === child) { + var elseKeyword = ts.findChildOfKind(parent, 80 /* ElseKeyword */, sourceFile); ts.Debug.assert(elseKeyword !== undefined); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; return elseKeywordStartLine === childStartLine; @@ -41759,23 +42494,23 @@ var ts; function getContainingList(node, sourceFile) { if (node.parent) { switch (node.parent.kind) { - case 149 /* TypeReference */: + case 151 /* TypeReference */: if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, node.getStart(sourceFile), node.getEnd())) { return node.parent.typeArguments; } break; - case 163 /* ObjectLiteralExpression */: + case 165 /* ObjectLiteralExpression */: return node.parent.properties; - case 162 /* ArrayLiteralExpression */: + case 164 /* ArrayLiteralExpression */: return node.parent.elements; - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: { + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: { var start = node.getStart(sourceFile); if (node.parent.typeParameters && ts.rangeContainsStartEnd(node.parent.typeParameters, start, node.getEnd())) { @@ -41786,8 +42521,8 @@ var ts; } break; } - case 167 /* NewExpression */: - case 166 /* CallExpression */: { + case 169 /* NewExpression */: + case 168 /* CallExpression */: { var start = node.getStart(sourceFile); if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, start, node.getEnd())) { @@ -41817,8 +42552,8 @@ var ts; if (node.kind === 18 /* CloseParenToken */) { return -1 /* Unknown */; } - if (node.parent && (node.parent.kind === 166 /* CallExpression */ || - node.parent.kind === 167 /* NewExpression */) && + if (node.parent && (node.parent.kind === 168 /* CallExpression */ || + node.parent.kind === 169 /* NewExpression */) && node.parent.expression !== node) { var fullCallOrNewExpression = node.parent.expression; var startingExpression = getStartingExpression(fullCallOrNewExpression); @@ -41836,10 +42571,10 @@ var ts; function getStartingExpression(node) { while (true) { switch (node.kind) { - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 164 /* PropertyAccessExpression */: - case 165 /* ElementAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 166 /* PropertyAccessExpression */: + case 167 /* ElementAccessExpression */: node = node.expression; break; default: @@ -41904,42 +42639,43 @@ var ts; SmartIndenter.findFirstNonWhitespaceColumn = findFirstNonWhitespaceColumn; function nodeContentIsAlwaysIndented(kind) { switch (kind) { - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 162 /* ArrayLiteralExpression */: - case 190 /* Block */: - case 217 /* ModuleBlock */: - case 163 /* ObjectLiteralExpression */: - case 153 /* TypeLiteral */: - case 155 /* TupleType */: - case 218 /* CaseBlock */: - case 240 /* DefaultClause */: - case 239 /* CaseClause */: - case 170 /* ParenthesizedExpression */: - case 164 /* PropertyAccessExpression */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: - case 191 /* VariableStatement */: - case 209 /* VariableDeclaration */: - case 225 /* ExportAssignment */: - case 202 /* ReturnStatement */: - case 180 /* ConditionalExpression */: - case 160 /* ArrayBindingPattern */: - case 159 /* ObjectBindingPattern */: - case 231 /* JsxElement */: - case 232 /* JsxSelfClosingElement */: - case 140 /* MethodSignature */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 136 /* Parameter */: - case 150 /* FunctionType */: - case 151 /* ConstructorType */: - case 158 /* ParenthesizedType */: - case 168 /* TaggedTemplateExpression */: - case 176 /* AwaitExpression */: + case 195 /* ExpressionStatement */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 164 /* ArrayLiteralExpression */: + case 192 /* Block */: + case 219 /* ModuleBlock */: + case 165 /* ObjectLiteralExpression */: + case 155 /* TypeLiteral */: + case 157 /* TupleType */: + case 220 /* CaseBlock */: + case 242 /* DefaultClause */: + case 241 /* CaseClause */: + case 172 /* ParenthesizedExpression */: + case 166 /* PropertyAccessExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: + case 193 /* VariableStatement */: + case 211 /* VariableDeclaration */: + case 227 /* ExportAssignment */: + case 204 /* ReturnStatement */: + case 182 /* ConditionalExpression */: + case 162 /* ArrayBindingPattern */: + case 161 /* ObjectBindingPattern */: + case 233 /* JsxElement */: + case 234 /* JsxSelfClosingElement */: + case 142 /* MethodSignature */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 138 /* Parameter */: + case 152 /* FunctionType */: + case 153 /* ConstructorType */: + case 160 /* ParenthesizedType */: + case 170 /* TaggedTemplateExpression */: + case 178 /* AwaitExpression */: return true; } return false; @@ -41949,20 +42685,20 @@ var ts; return true; } switch (parent) { - case 195 /* DoStatement */: - case 196 /* WhileStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 197 /* ForStatement */: - case 194 /* IfStatement */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 141 /* MethodDeclaration */: - case 172 /* ArrowFunction */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - return child !== 190 /* Block */; + case 197 /* DoStatement */: + case 198 /* WhileStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 199 /* ForStatement */: + case 196 /* IfStatement */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 143 /* MethodDeclaration */: + case 174 /* ArrowFunction */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + return child !== 192 /* Block */; default: return false; } @@ -42104,7 +42840,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(269 /* SyntaxList */, nodes.pos, nodes.end, 4096 /* Synthetic */, this); + var list = createNode(271 /* SyntaxList */, nodes.pos, nodes.end, 4096 /* Synthetic */, this); list._children = []; var pos = nodes.pos; for (var _i = 0; _i < nodes.length; _i++) { @@ -42123,7 +42859,7 @@ var ts; NodeObject.prototype.createChildren = function (sourceFile) { var _this = this; var children; - if (this.kind >= 133 /* FirstNode */) { + if (this.kind >= 135 /* FirstNode */) { scanner.setText((sourceFile || this.getSourceFile()).text); children = []; var pos = this.pos; @@ -42170,7 +42906,7 @@ var ts; return undefined; } var child = children[0]; - return child.kind < 133 /* FirstNode */ ? child : child.getFirstToken(sourceFile); + return child.kind < 135 /* FirstNode */ ? child : child.getFirstToken(sourceFile); }; NodeObject.prototype.getLastToken = function (sourceFile) { var children = this.getChildren(sourceFile); @@ -42178,7 +42914,7 @@ var ts; if (!child) { return undefined; } - return child.kind < 133 /* FirstNode */ ? child : child.getLastToken(sourceFile); + return child.kind < 135 /* FirstNode */ ? child : child.getLastToken(sourceFile); }; return NodeObject; })(); @@ -42227,7 +42963,7 @@ var ts; if (ts.indexOf(declarations, declaration) === indexOfDeclaration) { var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); // If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments - if (canUseParsedParamTagComments && declaration.kind === 136 /* Parameter */) { + if (canUseParsedParamTagComments && declaration.kind === 138 /* Parameter */) { ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedParamJsDocComment) { @@ -42236,15 +42972,15 @@ var ts; }); } // If this is left side of dotted module declaration, there is no doc comments associated with this node - if (declaration.kind === 216 /* ModuleDeclaration */ && declaration.body.kind === 216 /* ModuleDeclaration */) { + if (declaration.kind === 218 /* ModuleDeclaration */ && declaration.body.kind === 218 /* ModuleDeclaration */) { return; } // If this is dotted module name, get the doc comments from the parent - while (declaration.kind === 216 /* ModuleDeclaration */ && declaration.parent.kind === 216 /* ModuleDeclaration */) { + while (declaration.kind === 218 /* ModuleDeclaration */ && declaration.parent.kind === 218 /* ModuleDeclaration */) { declaration = declaration.parent; } // Get the cleaned js doc comment text from the declaration - ts.forEach(getJsDocCommentTextRange(declaration.kind === 209 /* VariableDeclaration */ ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + ts.forEach(getJsDocCommentTextRange(declaration.kind === 211 /* VariableDeclaration */ ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { ts.addRange(jsDocCommentParts, cleanedJsDocComment); @@ -42588,9 +43324,9 @@ var ts; if (result_2 !== undefined) { return result_2; } - if (declaration.name.kind === 134 /* ComputedPropertyName */) { + if (declaration.name.kind === 136 /* ComputedPropertyName */) { var expr = declaration.name.expression; - if (expr.kind === 164 /* PropertyAccessExpression */) { + if (expr.kind === 166 /* PropertyAccessExpression */) { return expr.name.text; } return getTextOfIdentifierOrLiteral(expr); @@ -42600,7 +43336,7 @@ var ts; } function getTextOfIdentifierOrLiteral(node) { if (node) { - if (node.kind === 67 /* Identifier */ || + if (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) { return node.text; @@ -42610,9 +43346,9 @@ var ts; } function visit(node) { switch (node.kind) { - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: var functionDeclaration = node; var declarationName = getDeclarationName(functionDeclaration); if (declarationName) { @@ -42632,60 +43368,60 @@ var ts; ts.forEachChild(node, visit); } break; - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 215 /* EnumDeclaration */: - case 216 /* ModuleDeclaration */: - case 219 /* ImportEqualsDeclaration */: - case 228 /* ExportSpecifier */: - case 224 /* ImportSpecifier */: - case 219 /* ImportEqualsDeclaration */: - case 221 /* ImportClause */: - case 222 /* NamespaceImport */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 153 /* TypeLiteral */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 217 /* EnumDeclaration */: + case 218 /* ModuleDeclaration */: + case 221 /* ImportEqualsDeclaration */: + case 230 /* ExportSpecifier */: + case 226 /* ImportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 223 /* ImportClause */: + case 224 /* NamespaceImport */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 155 /* TypeLiteral */: addDeclaration(node); // fall through - case 142 /* Constructor */: - case 191 /* VariableStatement */: - case 210 /* VariableDeclarationList */: - case 159 /* ObjectBindingPattern */: - case 160 /* ArrayBindingPattern */: - case 217 /* ModuleBlock */: + case 144 /* Constructor */: + case 193 /* VariableStatement */: + case 212 /* VariableDeclarationList */: + case 161 /* ObjectBindingPattern */: + case 162 /* ArrayBindingPattern */: + case 219 /* ModuleBlock */: ts.forEachChild(node, visit); break; - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionBlock(node)) { ts.forEachChild(node, visit); } break; - case 136 /* Parameter */: + case 138 /* Parameter */: // Only consider properties defined as constructor parameters if (!(node.flags & 112 /* AccessibilityModifier */)) { break; } // fall through - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: if (ts.isBindingPattern(node.name)) { ts.forEachChild(node.name, visit); break; } - case 245 /* EnumMember */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 247 /* EnumMember */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: addDeclaration(node); break; - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: // Handle named exports case e.g.: // export {a, b as B} from "mod"; if (node.exportClause) { ts.forEach(node.exportClause.elements, visit); } break; - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: var importClause = node.importClause; if (importClause) { // Handle default import case e.g.: @@ -42697,7 +43433,7 @@ var ts; // import * as NS from "mod"; // import {a, b as B} from "mod"; if (importClause.namedBindings) { - if (importClause.namedBindings.kind === 222 /* NamespaceImport */) { + if (importClause.namedBindings.kind === 224 /* NamespaceImport */) { addDeclaration(importClause.namedBindings); } else { @@ -42724,6 +43460,12 @@ var ts; HighlightSpanKind.reference = "reference"; HighlightSpanKind.writtenReference = "writtenReference"; })(HighlightSpanKind = ts.HighlightSpanKind || (ts.HighlightSpanKind = {})); + (function (IndentStyle) { + IndentStyle[IndentStyle["None"] = 0] = "None"; + IndentStyle[IndentStyle["Block"] = 1] = "Block"; + IndentStyle[IndentStyle["Smart"] = 2] = "Smart"; + })(ts.IndentStyle || (ts.IndentStyle = {})); + var IndentStyle = ts.IndentStyle; (function (SymbolDisplayPartKind) { SymbolDisplayPartKind[SymbolDisplayPartKind["aliasName"] = 0] = "aliasName"; SymbolDisplayPartKind[SymbolDisplayPartKind["className"] = 1] = "className"; @@ -42901,16 +43643,16 @@ var ts; } return ts.forEach(symbol.declarations, function (declaration) { // Function expressions are local - if (declaration.kind === 171 /* FunctionExpression */) { + if (declaration.kind === 173 /* FunctionExpression */) { return true; } - if (declaration.kind !== 209 /* VariableDeclaration */ && declaration.kind !== 211 /* FunctionDeclaration */) { + if (declaration.kind !== 211 /* VariableDeclaration */ && declaration.kind !== 213 /* FunctionDeclaration */) { return false; } // If the parent is not sourceFile or module block it is local variable for (var parent_8 = declaration.parent; !ts.isFunctionBlock(parent_8); parent_8 = parent_8.parent) { // Reached source file or module block - if (parent_8.kind === 246 /* SourceFile */ || parent_8.kind === 217 /* ModuleBlock */) { + if (parent_8.kind === 248 /* SourceFile */ || parent_8.kind === 219 /* ModuleBlock */) { return false; } } @@ -43047,8 +43789,8 @@ var ts; // We are not doing a full typecheck, we are not resolving the whole context, // so pass --noResolve to avoid reporting missing file errors. options.noResolve = true; - // Parse - var inputFileName = transpileOptions.fileName || "module.ts"; + // if jsx is specified then treat file as .tsx + var inputFileName = transpileOptions.fileName || (options.jsx ? "module.tsx" : "module.ts"); var sourceFile = ts.createSourceFile(inputFileName, input, options.target); if (transpileOptions.moduleName) { sourceFile.moduleName = transpileOptions.moduleName; @@ -43310,10 +44052,10 @@ var ts; // export {a as b} from "mod" // export import i = require("mod") while (token !== 1 /* EndOfFileToken */) { - if (token === 120 /* DeclareKeyword */) { + if (token === 122 /* DeclareKeyword */) { // declare module "mod" token = scanner.scan(); - if (token === 123 /* ModuleKeyword */) { + if (token === 125 /* ModuleKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { recordAmbientExternalModule(); @@ -43321,7 +44063,7 @@ var ts; } } } - else if (token === 87 /* ImportKeyword */) { + else if (token === 89 /* ImportKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import "mod"; @@ -43329,9 +44071,9 @@ var ts; continue; } else { - if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + if (token === 69 /* Identifier */ || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import d from "mod"; @@ -43339,9 +44081,9 @@ var ts; continue; } } - else if (token === 55 /* EqualsToken */) { + else if (token === 56 /* EqualsToken */) { token = scanner.scan(); - if (token === 125 /* RequireKeyword */) { + if (token === 127 /* RequireKeyword */) { token = scanner.scan(); if (token === 17 /* OpenParenToken */) { token = scanner.scan(); @@ -43370,7 +44112,7 @@ var ts; } if (token === 16 /* CloseBraceToken */) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import {a as A} from "mod"; @@ -43382,11 +44124,11 @@ var ts; } else if (token === 37 /* AsteriskToken */) { token = scanner.scan(); - if (token === 114 /* AsKeyword */) { + if (token === 116 /* AsKeyword */) { token = scanner.scan(); - if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + if (token === 69 /* Identifier */ || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // import * as NS from "mod" @@ -43399,7 +44141,7 @@ var ts; } } } - else if (token === 80 /* ExportKeyword */) { + else if (token === 82 /* ExportKeyword */) { token = scanner.scan(); if (token === 15 /* OpenBraceToken */) { token = scanner.scan(); @@ -43409,7 +44151,7 @@ var ts; } if (token === 16 /* CloseBraceToken */) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // export {a as A} from "mod"; @@ -43421,7 +44163,7 @@ var ts; } else if (token === 37 /* AsteriskToken */) { token = scanner.scan(); - if (token === 131 /* FromKeyword */) { + if (token === 133 /* FromKeyword */) { token = scanner.scan(); if (token === 9 /* StringLiteral */) { // export * from "mod" @@ -43429,13 +44171,13 @@ var ts; } } } - else if (token === 87 /* ImportKeyword */) { + else if (token === 89 /* ImportKeyword */) { token = scanner.scan(); - if (token === 67 /* Identifier */ || ts.isKeyword(token)) { + if (token === 69 /* Identifier */ || ts.isKeyword(token)) { token = scanner.scan(); - if (token === 55 /* EqualsToken */) { + if (token === 56 /* EqualsToken */) { token = scanner.scan(); - if (token === 125 /* RequireKeyword */) { + if (token === 127 /* RequireKeyword */) { token = scanner.scan(); if (token === 17 /* OpenParenToken */) { token = scanner.scan(); @@ -43463,7 +44205,7 @@ var ts; /// Helpers function getTargetLabel(referenceNode, labelName) { while (referenceNode) { - if (referenceNode.kind === 205 /* LabeledStatement */ && referenceNode.label.text === labelName) { + if (referenceNode.kind === 207 /* LabeledStatement */ && referenceNode.label.text === labelName) { return referenceNode.label; } referenceNode = referenceNode.parent; @@ -43471,13 +44213,13 @@ var ts; return undefined; } function isJumpStatementTarget(node) { - return node.kind === 67 /* Identifier */ && - (node.parent.kind === 201 /* BreakStatement */ || node.parent.kind === 200 /* ContinueStatement */) && + return node.kind === 69 /* Identifier */ && + (node.parent.kind === 203 /* BreakStatement */ || node.parent.kind === 202 /* ContinueStatement */) && node.parent.label === node; } function isLabelOfLabeledStatement(node) { - return node.kind === 67 /* Identifier */ && - node.parent.kind === 205 /* LabeledStatement */ && + return node.kind === 69 /* Identifier */ && + node.parent.kind === 207 /* LabeledStatement */ && node.parent.label === node; } /** @@ -43485,7 +44227,7 @@ var ts; * Note: 'node' cannot be a SourceFile. */ function isLabeledBy(node, labelName) { - for (var owner = node.parent; owner.kind === 205 /* LabeledStatement */; owner = owner.parent) { + for (var owner = node.parent; owner.kind === 207 /* LabeledStatement */; owner = owner.parent) { if (owner.label.text === labelName) { return true; } @@ -43496,49 +44238,49 @@ var ts; return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } function isRightSideOfQualifiedName(node) { - return node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node; + return node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node; } function isRightSideOfPropertyAccess(node) { - return node && node.parent && node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node; + return node && node.parent && node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.name === node; } function isCallExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 166 /* CallExpression */ && node.parent.expression === node; + return node && node.parent && node.parent.kind === 168 /* CallExpression */ && node.parent.expression === node; } function isNewExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 167 /* NewExpression */ && node.parent.expression === node; + return node && node.parent && node.parent.kind === 169 /* NewExpression */ && node.parent.expression === node; } function isNameOfModuleDeclaration(node) { - return node.parent.kind === 216 /* ModuleDeclaration */ && node.parent.name === node; + return node.parent.kind === 218 /* ModuleDeclaration */ && node.parent.name === node; } function isNameOfFunctionDeclaration(node) { - return node.kind === 67 /* Identifier */ && + return node.kind === 69 /* Identifier */ && ts.isFunctionLike(node.parent) && node.parent.name === node; } /** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */ function isNameOfPropertyAssignment(node) { - return (node.kind === 67 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) && - (node.parent.kind === 243 /* PropertyAssignment */ || node.parent.kind === 244 /* ShorthandPropertyAssignment */) && node.parent.name === node; + return (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) && + (node.parent.kind === 245 /* PropertyAssignment */ || node.parent.kind === 246 /* ShorthandPropertyAssignment */) && node.parent.name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node) { if (node.kind === 9 /* StringLiteral */ || node.kind === 8 /* NumericLiteral */) { switch (node.parent.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 243 /* PropertyAssignment */: - case 245 /* EnumMember */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 216 /* ModuleDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 245 /* PropertyAssignment */: + case 247 /* EnumMember */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 218 /* ModuleDeclaration */: return node.parent.name === node; - case 165 /* ElementAccessExpression */: + case 167 /* ElementAccessExpression */: return node.parent.argumentExpression === node; } } @@ -43597,7 +44339,7 @@ var ts; })(BreakContinueSearchType || (BreakContinueSearchType = {})); // A cache of completion entries for keywords, these do not change between sessions var keywordCompletions = []; - for (var i = 68 /* FirstKeyword */; i <= 132 /* LastKeyword */; i++) { + for (var i = 70 /* FirstKeyword */; i <= 134 /* LastKeyword */; i++) { keywordCompletions.push({ name: ts.tokenToString(i), kind: ScriptElementKind.keyword, @@ -43612,17 +44354,17 @@ var ts; return undefined; } switch (node.kind) { - case 246 /* SourceFile */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 215 /* EnumDeclaration */: - case 216 /* ModuleDeclaration */: + case 248 /* SourceFile */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 217 /* EnumDeclaration */: + case 218 /* ModuleDeclaration */: return node; } } @@ -43630,38 +44372,38 @@ var ts; ts.getContainerNode = getContainerNode; /* @internal */ function getNodeKind(node) { switch (node.kind) { - case 216 /* ModuleDeclaration */: return ScriptElementKind.moduleElement; - case 212 /* ClassDeclaration */: return ScriptElementKind.classElement; - case 213 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement; - case 214 /* TypeAliasDeclaration */: return ScriptElementKind.typeElement; - case 215 /* EnumDeclaration */: return ScriptElementKind.enumElement; - case 209 /* VariableDeclaration */: + case 218 /* ModuleDeclaration */: return ScriptElementKind.moduleElement; + case 214 /* ClassDeclaration */: return ScriptElementKind.classElement; + case 215 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement; + case 216 /* TypeAliasDeclaration */: return ScriptElementKind.typeElement; + case 217 /* EnumDeclaration */: return ScriptElementKind.enumElement; + case 211 /* VariableDeclaration */: return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; - case 211 /* FunctionDeclaration */: return ScriptElementKind.functionElement; - case 143 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement; - case 144 /* SetAccessor */: return ScriptElementKind.memberSetAccessorElement; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 213 /* FunctionDeclaration */: return ScriptElementKind.functionElement; + case 145 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement; + case 146 /* SetAccessor */: return ScriptElementKind.memberSetAccessorElement; + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: return ScriptElementKind.memberFunctionElement; - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return ScriptElementKind.memberVariableElement; - case 147 /* IndexSignature */: return ScriptElementKind.indexSignatureElement; - case 146 /* ConstructSignature */: return ScriptElementKind.constructSignatureElement; - case 145 /* CallSignature */: return ScriptElementKind.callSignatureElement; - case 142 /* Constructor */: return ScriptElementKind.constructorImplementationElement; - case 135 /* TypeParameter */: return ScriptElementKind.typeParameterElement; - case 245 /* EnumMember */: return ScriptElementKind.variableElement; - case 136 /* Parameter */: return (node.flags & 112 /* AccessibilityModifier */) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; - case 219 /* ImportEqualsDeclaration */: - case 224 /* ImportSpecifier */: - case 221 /* ImportClause */: - case 228 /* ExportSpecifier */: - case 222 /* NamespaceImport */: + case 149 /* IndexSignature */: return ScriptElementKind.indexSignatureElement; + case 148 /* ConstructSignature */: return ScriptElementKind.constructSignatureElement; + case 147 /* CallSignature */: return ScriptElementKind.callSignatureElement; + case 144 /* Constructor */: return ScriptElementKind.constructorImplementationElement; + case 137 /* TypeParameter */: return ScriptElementKind.typeParameterElement; + case 247 /* EnumMember */: return ScriptElementKind.variableElement; + case 138 /* Parameter */: return (node.flags & 112 /* AccessibilityModifier */) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; + case 221 /* ImportEqualsDeclaration */: + case 226 /* ImportSpecifier */: + case 223 /* ImportClause */: + case 230 /* ExportSpecifier */: + case 224 /* NamespaceImport */: return ScriptElementKind.alias; } return ScriptElementKind.unknown; @@ -43907,44 +44649,44 @@ var ts; return false; } switch (node.kind) { - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.import_can_only_be_used_in_a_ts_file)); return true; - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.export_can_only_be_used_in_a_ts_file)); return true; - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var classDeclaration = node; if (checkModifiers(classDeclaration.modifiers) || checkTypeParameters(classDeclaration.typeParameters)) { return true; } break; - case 241 /* HeritageClause */: + case 243 /* HeritageClause */: var heritageClause = node; - if (heritageClause.token === 104 /* ImplementsKeyword */) { + if (heritageClause.token === 106 /* ImplementsKeyword */) { diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); return true; } break; - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file)); return true; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.module_declarations_can_only_be_used_in_a_ts_file)); return true; - case 214 /* TypeAliasDeclaration */: + case 216 /* TypeAliasDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.type_aliases_can_only_be_used_in_a_ts_file)); return true; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: - case 211 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: var functionDeclaration = node; if (checkModifiers(functionDeclaration.modifiers) || checkTypeParameters(functionDeclaration.typeParameters) || @@ -43952,20 +44694,20 @@ var ts; return true; } break; - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: var variableStatement = node; if (checkModifiers(variableStatement.modifiers)) { return true; } break; - case 209 /* VariableDeclaration */: + case 211 /* VariableDeclaration */: var variableDeclaration = node; if (checkTypeAnnotation(variableDeclaration.type)) { return true; } break; - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: var expression = node; if (expression.typeArguments && expression.typeArguments.length > 0) { var start = expression.typeArguments.pos; @@ -43973,7 +44715,7 @@ var ts; return true; } break; - case 136 /* Parameter */: + case 138 /* Parameter */: var parameter = node; if (parameter.modifiers) { var start = parameter.modifiers.pos; @@ -43989,17 +44731,17 @@ var ts; return true; } break; - case 139 /* PropertyDeclaration */: + case 141 /* PropertyDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.property_declarations_can_only_be_used_in_a_ts_file)); return true; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file)); return true; - case 169 /* TypeAssertionExpression */: + case 171 /* TypeAssertionExpression */: var typeAssertionExpression = node; diagnostics.push(ts.createDiagnosticForNode(typeAssertionExpression.type, ts.Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file)); return true; - case 137 /* Decorator */: + case 139 /* Decorator */: diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.decorators_can_only_be_used_in_a_ts_file)); return true; } @@ -44025,18 +44767,18 @@ var ts; for (var _i = 0; _i < modifiers.length; _i++) { var modifier = modifiers[_i]; switch (modifier.kind) { - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - case 120 /* DeclareKeyword */: + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + case 122 /* DeclareKeyword */: diagnostics.push(ts.createDiagnosticForNode(modifier, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, ts.tokenToString(modifier.kind))); return true; // These are all legal modifiers. - case 111 /* StaticKeyword */: - case 80 /* ExportKeyword */: - case 72 /* ConstKeyword */: - case 75 /* DefaultKeyword */: - case 113 /* AbstractKeyword */: + case 113 /* StaticKeyword */: + case 82 /* ExportKeyword */: + case 74 /* ConstKeyword */: + case 77 /* DefaultKeyword */: + case 115 /* AbstractKeyword */: } } } @@ -44122,9 +44864,9 @@ var ts; isJsDocTagName = true; } switch (tag.kind) { - case 267 /* JSDocTypeTag */: - case 265 /* JSDocParameterTag */: - case 266 /* JSDocReturnTag */: + case 269 /* JSDocTypeTag */: + case 267 /* JSDocParameterTag */: + case 268 /* JSDocReturnTag */: var tagWithExpression = tag; if (tagWithExpression.typeExpression) { insideJsDocTagExpression = tagWithExpression.typeExpression.pos < position && position < tagWithExpression.typeExpression.end; @@ -44161,6 +44903,7 @@ var ts; var node = currentToken; var isRightOfDot = false; var isRightOfOpenTag = false; + var isStartingCloseTag = false; var location = ts.getTouchingPropertyName(sourceFile, position); if (contextToken) { // Bail out if this is a known invalid completion location @@ -44170,11 +44913,11 @@ var ts; } var parent_9 = contextToken.parent, kind = contextToken.kind; if (kind === 21 /* DotToken */) { - if (parent_9.kind === 164 /* PropertyAccessExpression */) { + if (parent_9.kind === 166 /* PropertyAccessExpression */) { node = contextToken.parent.expression; isRightOfDot = true; } - else if (parent_9.kind === 133 /* QualifiedName */) { + else if (parent_9.kind === 135 /* QualifiedName */) { node = contextToken.parent.left; isRightOfDot = true; } @@ -44184,9 +44927,14 @@ var ts; return undefined; } } - else if (kind === 25 /* LessThanToken */ && sourceFile.languageVariant === 1 /* JSX */) { - isRightOfOpenTag = true; - location = contextToken; + else if (sourceFile.languageVariant === 1 /* JSX */) { + if (kind === 25 /* LessThanToken */) { + isRightOfOpenTag = true; + location = contextToken; + } + else if (kind === 39 /* SlashToken */ && contextToken.parent.kind === 237 /* JsxClosingElement */) { + isStartingCloseTag = true; + } } } var semanticStart = new Date().getTime(); @@ -44207,6 +44955,12 @@ var ts; isMemberCompletion = true; isNewIdentifierLocation = false; } + else if (isStartingCloseTag) { + var tagName = contextToken.parent.parent.openingElement.tagName; + symbols = [typeChecker.getSymbolAtLocation(tagName)]; + isMemberCompletion = true; + isNewIdentifierLocation = false; + } else { // For JavaScript or TypeScript, if we're not after a dot, then just try to get the // global symbols in scope. These results should be valid for either language as @@ -44221,7 +44975,7 @@ var ts; // Right of dot member completion list isMemberCompletion = true; isNewIdentifierLocation = false; - if (node.kind === 67 /* Identifier */ || node.kind === 133 /* QualifiedName */ || node.kind === 164 /* PropertyAccessExpression */) { + if (node.kind === 69 /* Identifier */ || node.kind === 135 /* QualifiedName */ || node.kind === 166 /* PropertyAccessExpression */) { var symbol = typeChecker.getSymbolAtLocation(node); // This is an alias, follow what it aliases if (symbol && symbol.flags & 8388608 /* Alias */) { @@ -44277,7 +45031,7 @@ var ts; } if (jsxContainer = tryGetContainingJsxElement(contextToken)) { var attrsType; - if ((jsxContainer.kind === 232 /* JsxSelfClosingElement */) || (jsxContainer.kind === 233 /* JsxOpeningElement */)) { + if ((jsxContainer.kind === 234 /* JsxSelfClosingElement */) || (jsxContainer.kind === 235 /* JsxOpeningElement */)) { // Cursor is inside a JSX self-closing element or opening element attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); if (attrsType) { @@ -44343,49 +45097,64 @@ var ts; var start = new Date().getTime(); var result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || isSolelyIdentifierDefinitionLocation(contextToken) || - isDotOfNumericLiteral(contextToken); + isDotOfNumericLiteral(contextToken) || + isInJsxText(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } + function isInJsxText(contextToken) { + if (contextToken.kind === 236 /* JsxText */) { + return true; + } + if (contextToken.kind === 27 /* GreaterThanToken */ && contextToken.parent) { + if (contextToken.parent.kind === 235 /* JsxOpeningElement */) { + return true; + } + if (contextToken.parent.kind === 237 /* JsxClosingElement */ || contextToken.parent.kind === 234 /* JsxSelfClosingElement */) { + return contextToken.parent.parent && contextToken.parent.parent.kind === 233 /* JsxElement */; + } + } + return false; + } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 24 /* CommaToken */: - return containingNodeKind === 166 /* CallExpression */ // func( a, | - || containingNodeKind === 142 /* Constructor */ // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ - || containingNodeKind === 167 /* NewExpression */ // new C(a, | - || containingNodeKind === 162 /* ArrayLiteralExpression */ // [a, | - || containingNodeKind === 179 /* BinaryExpression */ // let x = (a, | - || containingNodeKind === 150 /* FunctionType */; // var x: (s: string, list| + return containingNodeKind === 168 /* CallExpression */ // func( a, | + || containingNodeKind === 144 /* Constructor */ // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ + || containingNodeKind === 169 /* NewExpression */ // new C(a, | + || containingNodeKind === 164 /* ArrayLiteralExpression */ // [a, | + || containingNodeKind === 181 /* BinaryExpression */ // let x = (a, | + || containingNodeKind === 152 /* FunctionType */; // var x: (s: string, list| case 17 /* OpenParenToken */: - return containingNodeKind === 166 /* CallExpression */ // func( | - || containingNodeKind === 142 /* Constructor */ // constructor( | - || containingNodeKind === 167 /* NewExpression */ // new C(a| - || containingNodeKind === 170 /* ParenthesizedExpression */ // let x = (a| - || containingNodeKind === 158 /* ParenthesizedType */; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */ + return containingNodeKind === 168 /* CallExpression */ // func( | + || containingNodeKind === 144 /* Constructor */ // constructor( | + || containingNodeKind === 169 /* NewExpression */ // new C(a| + || containingNodeKind === 172 /* ParenthesizedExpression */ // let x = (a| + || containingNodeKind === 160 /* ParenthesizedType */; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */ case 19 /* OpenBracketToken */: - return containingNodeKind === 162 /* ArrayLiteralExpression */ // [ | - || containingNodeKind === 147 /* IndexSignature */ // [ | : string ] - || containingNodeKind === 134 /* ComputedPropertyName */; // [ | /* this can become an index signature */ - case 123 /* ModuleKeyword */: // module | - case 124 /* NamespaceKeyword */: + return containingNodeKind === 164 /* ArrayLiteralExpression */ // [ | + || containingNodeKind === 149 /* IndexSignature */ // [ | : string ] + || containingNodeKind === 136 /* ComputedPropertyName */; // [ | /* this can become an index signature */ + case 125 /* ModuleKeyword */: // module | + case 126 /* NamespaceKeyword */: return true; case 21 /* DotToken */: - return containingNodeKind === 216 /* ModuleDeclaration */; // module A.| + return containingNodeKind === 218 /* ModuleDeclaration */; // module A.| case 15 /* OpenBraceToken */: - return containingNodeKind === 212 /* ClassDeclaration */; // class A{ | - case 55 /* EqualsToken */: - return containingNodeKind === 209 /* VariableDeclaration */ // let x = a| - || containingNodeKind === 179 /* BinaryExpression */; // x = a| + return containingNodeKind === 214 /* ClassDeclaration */; // class A{ | + case 56 /* EqualsToken */: + return containingNodeKind === 211 /* VariableDeclaration */ // let x = a| + || containingNodeKind === 181 /* BinaryExpression */; // x = a| case 12 /* TemplateHead */: - return containingNodeKind === 181 /* TemplateExpression */; // `aa ${| + return containingNodeKind === 183 /* TemplateExpression */; // `aa ${| case 13 /* TemplateMiddle */: - return containingNodeKind === 188 /* TemplateSpan */; // `aa ${10} dd ${| - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - return containingNodeKind === 139 /* PropertyDeclaration */; // class A{ public | + return containingNodeKind === 190 /* TemplateSpan */; // `aa ${10} dd ${| + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + return containingNodeKind === 141 /* PropertyDeclaration */; // class A{ public | } // Previous token may have been a keyword that was converted to an identifier. switch (previousToken.getText()) { @@ -44428,14 +45197,14 @@ var ts; isMemberCompletion = true; var typeForObject; var existingMembers; - if (objectLikeContainer.kind === 163 /* ObjectLiteralExpression */) { + if (objectLikeContainer.kind === 165 /* ObjectLiteralExpression */) { // We are completing on contextual types, but may also include properties // other than those within the declared type. isNewIdentifierLocation = true; typeForObject = typeChecker.getContextualType(objectLikeContainer); existingMembers = objectLikeContainer.properties; } - else if (objectLikeContainer.kind === 159 /* ObjectBindingPattern */) { + else if (objectLikeContainer.kind === 161 /* ObjectBindingPattern */) { // We are *only* completing on properties from the type being destructured. isNewIdentifierLocation = false; var rootDeclaration = ts.getRootDeclaration(objectLikeContainer.parent); @@ -44481,9 +45250,9 @@ var ts; * @returns true if 'symbols' was successfully populated; false otherwise. */ function tryGetImportOrExportClauseCompletionSymbols(namedImportsOrExports) { - var declarationKind = namedImportsOrExports.kind === 223 /* NamedImports */ ? - 220 /* ImportDeclaration */ : - 226 /* ExportDeclaration */; + var declarationKind = namedImportsOrExports.kind === 225 /* NamedImports */ ? + 222 /* ImportDeclaration */ : + 228 /* ExportDeclaration */; var importOrExportDeclaration = ts.getAncestor(namedImportsOrExports, declarationKind); var moduleSpecifier = importOrExportDeclaration.moduleSpecifier; if (!moduleSpecifier) { @@ -44509,7 +45278,7 @@ var ts; case 15 /* OpenBraceToken */: // let x = { | case 24 /* CommaToken */: var parent_10 = contextToken.parent; - if (parent_10 && (parent_10.kind === 163 /* ObjectLiteralExpression */ || parent_10.kind === 159 /* ObjectBindingPattern */)) { + if (parent_10 && (parent_10.kind === 165 /* ObjectLiteralExpression */ || parent_10.kind === 161 /* ObjectBindingPattern */)) { return parent_10; } break; @@ -44527,8 +45296,8 @@ var ts; case 15 /* OpenBraceToken */: // import { | case 24 /* CommaToken */: switch (contextToken.parent.kind) { - case 223 /* NamedImports */: - case 227 /* NamedExports */: + case 225 /* NamedImports */: + case 229 /* NamedExports */: return contextToken.parent; } } @@ -44540,30 +45309,33 @@ var ts; var parent_11 = contextToken.parent; switch (contextToken.kind) { case 26 /* LessThanSlashToken */: - case 38 /* SlashToken */: - case 67 /* Identifier */: - case 236 /* JsxAttribute */: - case 237 /* JsxSpreadAttribute */: - if (parent_11 && (parent_11.kind === 232 /* JsxSelfClosingElement */ || parent_11.kind === 233 /* JsxOpeningElement */)) { + case 39 /* SlashToken */: + case 69 /* Identifier */: + case 238 /* JsxAttribute */: + case 239 /* JsxSpreadAttribute */: + if (parent_11 && (parent_11.kind === 234 /* JsxSelfClosingElement */ || parent_11.kind === 235 /* JsxOpeningElement */)) { return parent_11; } + else if (parent_11.kind === 238 /* JsxAttribute */) { + return parent_11.parent; + } break; // The context token is the closing } or " of an attribute, which means // its parent is a JsxExpression, whose parent is a JsxAttribute, // whose parent is a JsxOpeningLikeElement case 9 /* StringLiteral */: - if (parent_11 && ((parent_11.kind === 236 /* JsxAttribute */) || (parent_11.kind === 237 /* JsxSpreadAttribute */))) { + if (parent_11 && ((parent_11.kind === 238 /* JsxAttribute */) || (parent_11.kind === 239 /* JsxSpreadAttribute */))) { return parent_11.parent; } break; case 16 /* CloseBraceToken */: if (parent_11 && - parent_11.kind === 238 /* JsxExpression */ && + parent_11.kind === 240 /* JsxExpression */ && parent_11.parent && - (parent_11.parent.kind === 236 /* JsxAttribute */)) { + (parent_11.parent.kind === 238 /* JsxAttribute */)) { return parent_11.parent.parent; } - if (parent_11 && parent_11.kind === 237 /* JsxSpreadAttribute */) { + if (parent_11 && parent_11.kind === 239 /* JsxSpreadAttribute */) { return parent_11.parent; } break; @@ -44573,16 +45345,16 @@ var ts; } function isFunction(kind) { switch (kind) { - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 145 /* CallSignature */: - case 146 /* ConstructSignature */: - case 147 /* IndexSignature */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 147 /* CallSignature */: + case 148 /* ConstructSignature */: + case 149 /* IndexSignature */: return true; } return false; @@ -44594,78 +45366,84 @@ var ts; var containingNodeKind = contextToken.parent.kind; switch (contextToken.kind) { case 24 /* CommaToken */: - return containingNodeKind === 209 /* VariableDeclaration */ || - containingNodeKind === 210 /* VariableDeclarationList */ || - containingNodeKind === 191 /* VariableStatement */ || - containingNodeKind === 215 /* EnumDeclaration */ || + return containingNodeKind === 211 /* VariableDeclaration */ || + containingNodeKind === 212 /* VariableDeclarationList */ || + containingNodeKind === 193 /* VariableStatement */ || + containingNodeKind === 217 /* EnumDeclaration */ || isFunction(containingNodeKind) || - containingNodeKind === 212 /* ClassDeclaration */ || - containingNodeKind === 184 /* ClassExpression */ || - containingNodeKind === 213 /* InterfaceDeclaration */ || - containingNodeKind === 160 /* ArrayBindingPattern */ || - containingNodeKind === 214 /* TypeAliasDeclaration */; // type Map, K, | + containingNodeKind === 214 /* ClassDeclaration */ || + containingNodeKind === 186 /* ClassExpression */ || + containingNodeKind === 215 /* InterfaceDeclaration */ || + containingNodeKind === 162 /* ArrayBindingPattern */ || + containingNodeKind === 216 /* TypeAliasDeclaration */; // type Map, K, | case 21 /* DotToken */: - return containingNodeKind === 160 /* ArrayBindingPattern */; // var [.| - case 53 /* ColonToken */: - return containingNodeKind === 161 /* BindingElement */; // var {x :html| + return containingNodeKind === 162 /* ArrayBindingPattern */; // var [.| + case 54 /* ColonToken */: + return containingNodeKind === 163 /* BindingElement */; // var {x :html| case 19 /* OpenBracketToken */: - return containingNodeKind === 160 /* ArrayBindingPattern */; // var [x| + return containingNodeKind === 162 /* ArrayBindingPattern */; // var [x| case 17 /* OpenParenToken */: - return containingNodeKind === 242 /* CatchClause */ || + return containingNodeKind === 244 /* CatchClause */ || isFunction(containingNodeKind); case 15 /* OpenBraceToken */: - return containingNodeKind === 215 /* EnumDeclaration */ || - containingNodeKind === 213 /* InterfaceDeclaration */ || - containingNodeKind === 153 /* TypeLiteral */; // let x : { | + return containingNodeKind === 217 /* EnumDeclaration */ || + containingNodeKind === 215 /* InterfaceDeclaration */ || + containingNodeKind === 155 /* TypeLiteral */; // let x : { | case 23 /* SemicolonToken */: - return containingNodeKind === 138 /* PropertySignature */ && + return containingNodeKind === 140 /* PropertySignature */ && contextToken.parent && contextToken.parent.parent && - (contextToken.parent.parent.kind === 213 /* InterfaceDeclaration */ || - contextToken.parent.parent.kind === 153 /* TypeLiteral */); // let x : { a; | + (contextToken.parent.parent.kind === 215 /* InterfaceDeclaration */ || + contextToken.parent.parent.kind === 155 /* TypeLiteral */); // let x : { a; | case 25 /* LessThanToken */: - return containingNodeKind === 212 /* ClassDeclaration */ || - containingNodeKind === 184 /* ClassExpression */ || - containingNodeKind === 213 /* InterfaceDeclaration */ || - containingNodeKind === 214 /* TypeAliasDeclaration */ || + return containingNodeKind === 214 /* ClassDeclaration */ || + containingNodeKind === 186 /* ClassExpression */ || + containingNodeKind === 215 /* InterfaceDeclaration */ || + containingNodeKind === 216 /* TypeAliasDeclaration */ || isFunction(containingNodeKind); - case 111 /* StaticKeyword */: - return containingNodeKind === 139 /* PropertyDeclaration */; + case 113 /* StaticKeyword */: + return containingNodeKind === 141 /* PropertyDeclaration */; case 22 /* DotDotDotToken */: - return containingNodeKind === 136 /* Parameter */ || + return containingNodeKind === 138 /* Parameter */ || (contextToken.parent && contextToken.parent.parent && - contextToken.parent.parent.kind === 160 /* ArrayBindingPattern */); // var [...z| - case 110 /* PublicKeyword */: - case 108 /* PrivateKeyword */: - case 109 /* ProtectedKeyword */: - return containingNodeKind === 136 /* Parameter */; - case 114 /* AsKeyword */: - containingNodeKind === 224 /* ImportSpecifier */ || - containingNodeKind === 228 /* ExportSpecifier */ || - containingNodeKind === 222 /* NamespaceImport */; - case 71 /* ClassKeyword */: - case 79 /* EnumKeyword */: - case 105 /* InterfaceKeyword */: - case 85 /* FunctionKeyword */: - case 100 /* VarKeyword */: - case 121 /* GetKeyword */: - case 127 /* SetKeyword */: - case 87 /* ImportKeyword */: - case 106 /* LetKeyword */: - case 72 /* ConstKeyword */: - case 112 /* YieldKeyword */: - case 130 /* TypeKeyword */: + contextToken.parent.parent.kind === 162 /* ArrayBindingPattern */); // var [...z| + case 112 /* PublicKeyword */: + case 110 /* PrivateKeyword */: + case 111 /* ProtectedKeyword */: + return containingNodeKind === 138 /* Parameter */; + case 116 /* AsKeyword */: + return containingNodeKind === 226 /* ImportSpecifier */ || + containingNodeKind === 230 /* ExportSpecifier */ || + containingNodeKind === 224 /* NamespaceImport */; + case 73 /* ClassKeyword */: + case 81 /* EnumKeyword */: + case 107 /* InterfaceKeyword */: + case 87 /* FunctionKeyword */: + case 102 /* VarKeyword */: + case 123 /* GetKeyword */: + case 129 /* SetKeyword */: + case 89 /* ImportKeyword */: + case 108 /* LetKeyword */: + case 74 /* ConstKeyword */: + case 114 /* YieldKeyword */: + case 132 /* TypeKeyword */: return true; } // Previous token may have been a keyword that was converted to an identifier. switch (contextToken.getText()) { + case "abstract": + case "async": case "class": - case "interface": + case "const": + case "declare": case "enum": case "function": - case "var": - case "static": + case "interface": case "let": - case "const": + case "private": + case "protected": + case "public": + case "static": + case "var": case "yield": return true; } @@ -44695,8 +45473,8 @@ var ts; if (element.getStart() <= position && position <= element.getEnd()) { continue; } - var name_31 = element.propertyName || element.name; - exisingImportsOrExports[name_31.text] = true; + var name_32 = element.propertyName || element.name; + exisingImportsOrExports[name_32.text] = true; } if (ts.isEmpty(exisingImportsOrExports)) { return exportsOfModule; @@ -44717,9 +45495,9 @@ var ts; for (var _i = 0; _i < existingMembers.length; _i++) { var m = existingMembers[_i]; // Ignore omitted expressions for missing members - if (m.kind !== 243 /* PropertyAssignment */ && - m.kind !== 244 /* ShorthandPropertyAssignment */ && - m.kind !== 161 /* BindingElement */) { + if (m.kind !== 245 /* PropertyAssignment */ && + m.kind !== 246 /* ShorthandPropertyAssignment */ && + m.kind !== 163 /* BindingElement */) { continue; } // If this is the current item we are editing right now, do not filter it out @@ -44727,7 +45505,7 @@ var ts; continue; } var existingName = void 0; - if (m.kind === 161 /* BindingElement */ && m.propertyName) { + if (m.kind === 163 /* BindingElement */ && m.propertyName) { existingName = m.propertyName.text; } else { @@ -44754,7 +45532,7 @@ var ts; if (attr.getStart() <= position && position <= attr.getEnd()) { continue; } - if (attr.kind === 236 /* JsxAttribute */) { + if (attr.kind === 238 /* JsxAttribute */) { seenNames[attr.name.text] = true; } } @@ -44795,10 +45573,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_32 in nameTable) { - if (!allNames[name_32]) { - allNames[name_32] = name_32; - var displayName = getCompletionEntryDisplayName(name_32, target, /*performCharacterChecks:*/ true); + for (var name_33 in nameTable) { + if (!allNames[name_33]) { + allNames[name_33] = name_33; + var displayName = getCompletionEntryDisplayName(name_33, target, /*performCharacterChecks:*/ true); if (displayName) { var entry = { name: displayName, @@ -44906,7 +45684,7 @@ var ts; function getSymbolKind(symbol, location) { var flags = symbol.getFlags(); if (flags & 32 /* Class */) - return ts.getDeclarationOfKind(symbol, 184 /* ClassExpression */) ? + return ts.getDeclarationOfKind(symbol, 186 /* ClassExpression */) ? ScriptElementKind.localClassElement : ScriptElementKind.classElement; if (flags & 384 /* Enum */) return ScriptElementKind.enumElement; @@ -45008,7 +45786,7 @@ var ts; var signature; type = typeChecker.getTypeOfSymbolAtLocation(symbol, location); if (type) { - if (location.parent && location.parent.kind === 164 /* PropertyAccessExpression */) { + if (location.parent && location.parent.kind === 166 /* PropertyAccessExpression */) { var right = location.parent.name; // Either the location is on the right of a property access, or on the left and the right is missing if (right === location || (right && right.getFullWidth() === 0)) { @@ -45017,7 +45795,7 @@ var ts; } // try get the call/construct signature from the type if it matches var callExpression; - if (location.kind === 166 /* CallExpression */ || location.kind === 167 /* NewExpression */) { + if (location.kind === 168 /* CallExpression */ || location.kind === 169 /* NewExpression */) { callExpression = location; } else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { @@ -45030,10 +45808,11 @@ var ts; // Use the first candidate: signature = candidateSignatures[0]; } - var useConstructSignatures = callExpression.kind === 167 /* NewExpression */ || callExpression.expression.kind === 93 /* SuperKeyword */; + var useConstructSignatures = callExpression.kind === 169 /* NewExpression */ || callExpression.expression.kind === 95 /* SuperKeyword */; var allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); - if (!ts.contains(allSignatures, signature.target || signature)) { - // Get the first signature if there + if (!ts.contains(allSignatures, signature.target) && !ts.contains(allSignatures, signature)) { + // Get the first signature if there is one -- allSignatures may contain + // either the original signature or its target, so check for either signature = allSignatures.length ? allSignatures[0] : undefined; } if (signature) { @@ -45047,7 +45826,7 @@ var ts; pushTypePart(symbolKind); displayParts.push(ts.spacePart()); if (useConstructSignatures) { - displayParts.push(ts.keywordPart(90 /* NewKeyword */)); + displayParts.push(ts.keywordPart(92 /* NewKeyword */)); displayParts.push(ts.spacePart()); } addFullSymbolName(symbol); @@ -45063,10 +45842,10 @@ var ts; case ScriptElementKind.parameterElement: case ScriptElementKind.localVariableElement: // If it is call or construct signature of lambda's write type name - displayParts.push(ts.punctuationPart(53 /* ColonToken */)); + displayParts.push(ts.punctuationPart(54 /* ColonToken */)); displayParts.push(ts.spacePart()); if (useConstructSignatures) { - displayParts.push(ts.keywordPart(90 /* NewKeyword */)); + displayParts.push(ts.keywordPart(92 /* NewKeyword */)); displayParts.push(ts.spacePart()); } if (!(type.flags & 65536 /* Anonymous */)) { @@ -45082,24 +45861,24 @@ var ts; } } else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304 /* Accessor */)) || - (location.kind === 119 /* ConstructorKeyword */ && location.parent.kind === 142 /* Constructor */)) { + (location.kind === 121 /* ConstructorKeyword */ && location.parent.kind === 144 /* Constructor */)) { // get the signature from the declaration and write it var functionDeclaration = location.parent; - var allSignatures = functionDeclaration.kind === 142 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); + var allSignatures = functionDeclaration.kind === 144 /* Constructor */ ? type.getConstructSignatures() : type.getCallSignatures(); if (!typeChecker.isImplementationOfOverload(functionDeclaration)) { signature = typeChecker.getSignatureFromDeclaration(functionDeclaration); } else { signature = allSignatures[0]; } - if (functionDeclaration.kind === 142 /* Constructor */) { + if (functionDeclaration.kind === 144 /* Constructor */) { // show (constructor) Type(...) signature symbolKind = ScriptElementKind.constructorImplementationElement; addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); } else { // (function/method) symbol(..signature) - addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 145 /* CallSignature */ && + addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 147 /* CallSignature */ && !(type.symbol.flags & 2048 /* TypeLiteral */ || type.symbol.flags & 4096 /* ObjectLiteral */) ? type.symbol : symbol, symbolKind); } addSignatureDisplayParts(signature, allSignatures); @@ -45108,7 +45887,7 @@ var ts; } } if (symbolFlags & 32 /* Class */ && !hasAddedSymbolInfo) { - if (ts.getDeclarationOfKind(symbol, 184 /* ClassExpression */)) { + if (ts.getDeclarationOfKind(symbol, 186 /* ClassExpression */)) { // Special case for class expressions because we would like to indicate that // the class name is local to the class body (similar to function expression) // (local class) class @@ -45116,7 +45895,7 @@ var ts; } else { // Class declaration has name which is not local. - displayParts.push(ts.keywordPart(71 /* ClassKeyword */)); + displayParts.push(ts.keywordPart(73 /* ClassKeyword */)); } displayParts.push(ts.spacePart()); addFullSymbolName(symbol); @@ -45124,37 +45903,37 @@ var ts; } if ((symbolFlags & 64 /* Interface */) && (semanticMeaning & 2 /* Type */)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(105 /* InterfaceKeyword */)); + displayParts.push(ts.keywordPart(107 /* InterfaceKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if (symbolFlags & 524288 /* TypeAlias */) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(130 /* TypeKeyword */)); + displayParts.push(ts.keywordPart(132 /* TypeKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); ts.addRange(displayParts, ts.typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & 384 /* Enum */) { addNewLineIfDisplayPartsExist(); if (ts.forEach(symbol.declarations, ts.isConstEnumDeclaration)) { - displayParts.push(ts.keywordPart(72 /* ConstKeyword */)); + displayParts.push(ts.keywordPart(74 /* ConstKeyword */)); displayParts.push(ts.spacePart()); } - displayParts.push(ts.keywordPart(79 /* EnumKeyword */)); + displayParts.push(ts.keywordPart(81 /* EnumKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } if (symbolFlags & 1536 /* Module */) { addNewLineIfDisplayPartsExist(); - var declaration = ts.getDeclarationOfKind(symbol, 216 /* ModuleDeclaration */); - var isNamespace = declaration && declaration.name && declaration.name.kind === 67 /* Identifier */; - displayParts.push(ts.keywordPart(isNamespace ? 124 /* NamespaceKeyword */ : 123 /* ModuleKeyword */)); + var declaration = ts.getDeclarationOfKind(symbol, 218 /* ModuleDeclaration */); + var isNamespace = declaration && declaration.name && declaration.name.kind === 69 /* Identifier */; + displayParts.push(ts.keywordPart(isNamespace ? 126 /* NamespaceKeyword */ : 125 /* ModuleKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } @@ -45166,7 +45945,7 @@ var ts; displayParts.push(ts.spacePart()); addFullSymbolName(symbol); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(88 /* InKeyword */)); + displayParts.push(ts.keywordPart(90 /* InKeyword */)); displayParts.push(ts.spacePart()); if (symbol.parent) { // Class/Interface type parameter @@ -45177,13 +45956,13 @@ var ts; // Method/function type parameter var container = ts.getContainingFunction(location); if (container) { - var signatureDeclaration = ts.getDeclarationOfKind(symbol, 135 /* TypeParameter */).parent; + var signatureDeclaration = ts.getDeclarationOfKind(symbol, 137 /* TypeParameter */).parent; var signature = typeChecker.getSignatureFromDeclaration(signatureDeclaration); - if (signatureDeclaration.kind === 146 /* ConstructSignature */) { - displayParts.push(ts.keywordPart(90 /* NewKeyword */)); + if (signatureDeclaration.kind === 148 /* ConstructSignature */) { + displayParts.push(ts.keywordPart(92 /* NewKeyword */)); displayParts.push(ts.spacePart()); } - else if (signatureDeclaration.kind !== 145 /* CallSignature */ && signatureDeclaration.name) { + else if (signatureDeclaration.kind !== 147 /* CallSignature */ && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } ts.addRange(displayParts, ts.signatureToDisplayParts(typeChecker, signature, sourceFile, 32 /* WriteTypeArgumentsOfSignature */)); @@ -45192,8 +45971,8 @@ var ts; // Type aliash type parameter // For example // type list = T[]; // Both T will go through same code path - var declaration = ts.getDeclarationOfKind(symbol, 135 /* TypeParameter */).parent; - displayParts.push(ts.keywordPart(130 /* TypeKeyword */)); + var declaration = ts.getDeclarationOfKind(symbol, 137 /* TypeParameter */).parent; + displayParts.push(ts.keywordPart(132 /* TypeKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(declaration.symbol); writeTypeParametersOfSymbol(declaration.symbol, sourceFile); @@ -45203,11 +45982,11 @@ var ts; if (symbolFlags & 8 /* EnumMember */) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); var declaration = symbol.declarations[0]; - if (declaration.kind === 245 /* EnumMember */) { + if (declaration.kind === 247 /* EnumMember */) { var constantValue = typeChecker.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); displayParts.push(ts.displayPart(constantValue.toString(), SymbolDisplayPartKind.numericLiteral)); } @@ -45215,17 +45994,17 @@ var ts; } if (symbolFlags & 8388608 /* Alias */) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(87 /* ImportKeyword */)); + displayParts.push(ts.keywordPart(89 /* ImportKeyword */)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 219 /* ImportEqualsDeclaration */) { + if (declaration.kind === 221 /* ImportEqualsDeclaration */) { var importEqualsDeclaration = declaration; if (ts.isExternalModuleImportEqualsDeclaration(importEqualsDeclaration)) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(125 /* RequireKeyword */)); + displayParts.push(ts.keywordPart(127 /* RequireKeyword */)); displayParts.push(ts.punctuationPart(17 /* OpenParenToken */)); displayParts.push(ts.displayPart(ts.getTextOfNode(ts.getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), SymbolDisplayPartKind.stringLiteral)); displayParts.push(ts.punctuationPart(18 /* CloseParenToken */)); @@ -45234,7 +46013,7 @@ var ts; var internalAliasSymbol = typeChecker.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(ts.spacePart()); - displayParts.push(ts.operatorPart(55 /* EqualsToken */)); + displayParts.push(ts.operatorPart(56 /* EqualsToken */)); displayParts.push(ts.spacePart()); addFullSymbolName(internalAliasSymbol, enclosingDeclaration); } @@ -45251,7 +46030,7 @@ var ts; if (symbolKind === ScriptElementKind.memberVariableElement || symbolFlags & 3 /* Variable */ || symbolKind === ScriptElementKind.localVariableElement) { - displayParts.push(ts.punctuationPart(53 /* ColonToken */)); + displayParts.push(ts.punctuationPart(54 /* ColonToken */)); displayParts.push(ts.spacePart()); // If the type is type parameter, format it specially if (type.symbol && type.symbol.flags & 262144 /* TypeParameter */) { @@ -45351,11 +46130,11 @@ var ts; if (!symbol) { // Try getting just type at this position and show switch (node.kind) { - case 67 /* Identifier */: - case 164 /* PropertyAccessExpression */: - case 133 /* QualifiedName */: - case 95 /* ThisKeyword */: - case 93 /* SuperKeyword */: + case 69 /* Identifier */: + case 166 /* PropertyAccessExpression */: + case 135 /* QualifiedName */: + case 97 /* ThisKeyword */: + case 95 /* SuperKeyword */: // For the identifiers/this/super etc get the type at position var type = typeChecker.getTypeAtLocation(node); if (type) { @@ -45408,7 +46187,7 @@ var ts; function tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) { // Applicable only if we are in a new expression, or we are on a constructor declaration // and in either case the symbol has a construct signature definition, i.e. class - if (isNewExpressionTarget(location) || location.kind === 119 /* ConstructorKeyword */) { + if (isNewExpressionTarget(location) || location.kind === 121 /* ConstructorKeyword */) { if (symbol.flags & 32 /* Class */) { // Find the first class-like declaration and try to get the construct signature. for (var _i = 0, _a = symbol.getDeclarations(); _i < _a.length; _i++) { @@ -45433,8 +46212,8 @@ var ts; var declarations = []; var definition; ts.forEach(signatureDeclarations, function (d) { - if ((selectConstructors && d.kind === 142 /* Constructor */) || - (!selectConstructors && (d.kind === 211 /* FunctionDeclaration */ || d.kind === 141 /* MethodDeclaration */ || d.kind === 140 /* MethodSignature */))) { + if ((selectConstructors && d.kind === 144 /* Constructor */) || + (!selectConstructors && (d.kind === 213 /* FunctionDeclaration */ || d.kind === 143 /* MethodDeclaration */ || d.kind === 142 /* MethodSignature */))) { declarations.push(d); if (d.body) definition = d; @@ -45494,7 +46273,7 @@ var ts; // to jump to the implementation directly. if (symbol.flags & 8388608 /* Alias */) { var declaration = symbol.declarations[0]; - if (node.kind === 67 /* Identifier */ && node.parent === declaration) { + if (node.kind === 69 /* Identifier */ && node.parent === declaration) { symbol = typeChecker.getAliasedSymbol(symbol); } } @@ -45503,7 +46282,7 @@ var ts; // go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition // is performed at the location of property access, we would like to go to definition of the property in the short-hand // assignment. This case and others are handled by the following code. - if (node.parent.kind === 244 /* ShorthandPropertyAssignment */) { + if (node.parent.kind === 246 /* ShorthandPropertyAssignment */) { var shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); if (!shorthandSymbol) { return []; @@ -45577,9 +46356,9 @@ var ts; }; } function getSemanticDocumentHighlights(node) { - if (node.kind === 67 /* Identifier */ || - node.kind === 95 /* ThisKeyword */ || - node.kind === 93 /* SuperKeyword */ || + if (node.kind === 69 /* Identifier */ || + node.kind === 97 /* ThisKeyword */ || + node.kind === 95 /* SuperKeyword */ || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { var referencedSymbols = getReferencedSymbolsForNode(node, sourceFilesToSearch, /*findInStrings:*/ false, /*findInComments:*/ false); @@ -45630,77 +46409,77 @@ var ts; function getHighlightSpans(node) { if (node) { switch (node.kind) { - case 86 /* IfKeyword */: - case 78 /* ElseKeyword */: - if (hasKind(node.parent, 194 /* IfStatement */)) { + case 88 /* IfKeyword */: + case 80 /* ElseKeyword */: + if (hasKind(node.parent, 196 /* IfStatement */)) { return getIfElseOccurrences(node.parent); } break; - case 92 /* ReturnKeyword */: - if (hasKind(node.parent, 202 /* ReturnStatement */)) { + case 94 /* ReturnKeyword */: + if (hasKind(node.parent, 204 /* ReturnStatement */)) { return getReturnOccurrences(node.parent); } break; - case 96 /* ThrowKeyword */: - if (hasKind(node.parent, 206 /* ThrowStatement */)) { + case 98 /* ThrowKeyword */: + if (hasKind(node.parent, 208 /* ThrowStatement */)) { return getThrowOccurrences(node.parent); } break; - case 70 /* CatchKeyword */: - if (hasKind(parent(parent(node)), 207 /* TryStatement */)) { + case 72 /* CatchKeyword */: + if (hasKind(parent(parent(node)), 209 /* TryStatement */)) { return getTryCatchFinallyOccurrences(node.parent.parent); } break; - case 98 /* TryKeyword */: - case 83 /* FinallyKeyword */: - if (hasKind(parent(node), 207 /* TryStatement */)) { + case 100 /* TryKeyword */: + case 85 /* FinallyKeyword */: + if (hasKind(parent(node), 209 /* TryStatement */)) { return getTryCatchFinallyOccurrences(node.parent); } break; - case 94 /* SwitchKeyword */: - if (hasKind(node.parent, 204 /* SwitchStatement */)) { + case 96 /* SwitchKeyword */: + if (hasKind(node.parent, 206 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent); } break; - case 69 /* CaseKeyword */: - case 75 /* DefaultKeyword */: - if (hasKind(parent(parent(parent(node))), 204 /* SwitchStatement */)) { + case 71 /* CaseKeyword */: + case 77 /* DefaultKeyword */: + if (hasKind(parent(parent(parent(node))), 206 /* SwitchStatement */)) { return getSwitchCaseDefaultOccurrences(node.parent.parent.parent); } break; - case 68 /* BreakKeyword */: - case 73 /* ContinueKeyword */: - if (hasKind(node.parent, 201 /* BreakStatement */) || hasKind(node.parent, 200 /* ContinueStatement */)) { + case 70 /* BreakKeyword */: + case 75 /* ContinueKeyword */: + if (hasKind(node.parent, 203 /* BreakStatement */) || hasKind(node.parent, 202 /* ContinueStatement */)) { return getBreakOrContinueStatementOccurrences(node.parent); } break; - case 84 /* ForKeyword */: - if (hasKind(node.parent, 197 /* ForStatement */) || - hasKind(node.parent, 198 /* ForInStatement */) || - hasKind(node.parent, 199 /* ForOfStatement */)) { + case 86 /* ForKeyword */: + if (hasKind(node.parent, 199 /* ForStatement */) || + hasKind(node.parent, 200 /* ForInStatement */) || + hasKind(node.parent, 201 /* ForOfStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; - case 102 /* WhileKeyword */: - case 77 /* DoKeyword */: - if (hasKind(node.parent, 196 /* WhileStatement */) || hasKind(node.parent, 195 /* DoStatement */)) { + case 104 /* WhileKeyword */: + case 79 /* DoKeyword */: + if (hasKind(node.parent, 198 /* WhileStatement */) || hasKind(node.parent, 197 /* DoStatement */)) { return getLoopBreakContinueOccurrences(node.parent); } break; - case 119 /* ConstructorKeyword */: - if (hasKind(node.parent, 142 /* Constructor */)) { + case 121 /* ConstructorKeyword */: + if (hasKind(node.parent, 144 /* Constructor */)) { return getConstructorOccurrences(node.parent); } break; - case 121 /* GetKeyword */: - case 127 /* SetKeyword */: - if (hasKind(node.parent, 143 /* GetAccessor */) || hasKind(node.parent, 144 /* SetAccessor */)) { + case 123 /* GetKeyword */: + case 129 /* SetKeyword */: + if (hasKind(node.parent, 145 /* GetAccessor */) || hasKind(node.parent, 146 /* SetAccessor */)) { return getGetAndSetOccurrences(node.parent); } break; default: if (ts.isModifier(node.kind) && node.parent && - (ts.isDeclaration(node.parent) || node.parent.kind === 191 /* VariableStatement */)) { + (ts.isDeclaration(node.parent) || node.parent.kind === 193 /* VariableStatement */)) { return getModifierOccurrences(node.kind, node.parent); } } @@ -45716,10 +46495,10 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 206 /* ThrowStatement */) { + if (node.kind === 208 /* ThrowStatement */) { statementAccumulator.push(node); } - else if (node.kind === 207 /* TryStatement */) { + else if (node.kind === 209 /* TryStatement */) { var tryStatement = node; if (tryStatement.catchClause) { aggregate(tryStatement.catchClause); @@ -45748,12 +46527,12 @@ var ts; var child = throwStatement; while (child.parent) { var parent_12 = child.parent; - if (ts.isFunctionBlock(parent_12) || parent_12.kind === 246 /* SourceFile */) { + if (ts.isFunctionBlock(parent_12) || parent_12.kind === 248 /* SourceFile */) { return parent_12; } // A throw-statement is only owned by a try-statement if the try-statement has // a catch clause, and if the throw-statement occurs within the try block. - if (parent_12.kind === 207 /* TryStatement */) { + if (parent_12.kind === 209 /* TryStatement */) { var tryStatement = parent_12; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; @@ -45768,7 +46547,7 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 201 /* BreakStatement */ || node.kind === 200 /* ContinueStatement */) { + if (node.kind === 203 /* BreakStatement */ || node.kind === 202 /* ContinueStatement */) { statementAccumulator.push(node); } else if (!ts.isFunctionLike(node)) { @@ -45784,16 +46563,16 @@ var ts; function getBreakOrContinueOwner(statement) { for (var node_2 = statement.parent; node_2; node_2 = node_2.parent) { switch (node_2.kind) { - case 204 /* SwitchStatement */: - if (statement.kind === 200 /* ContinueStatement */) { + case 206 /* SwitchStatement */: + if (statement.kind === 202 /* ContinueStatement */) { continue; } // Fall through. - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 196 /* WhileStatement */: - case 195 /* DoStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 198 /* WhileStatement */: + case 197 /* DoStatement */: if (!statement.label || isLabeledBy(node_2, statement.label.text)) { return node_2; } @@ -45812,24 +46591,24 @@ var ts; var container = declaration.parent; // Make sure we only highlight the keyword when it makes sense to do so. if (ts.isAccessibilityModifier(modifier)) { - if (!(container.kind === 212 /* ClassDeclaration */ || - container.kind === 184 /* ClassExpression */ || - (declaration.kind === 136 /* Parameter */ && hasKind(container, 142 /* Constructor */)))) { + if (!(container.kind === 214 /* ClassDeclaration */ || + container.kind === 186 /* ClassExpression */ || + (declaration.kind === 138 /* Parameter */ && hasKind(container, 144 /* Constructor */)))) { return undefined; } } - else if (modifier === 111 /* StaticKeyword */) { - if (!(container.kind === 212 /* ClassDeclaration */ || container.kind === 184 /* ClassExpression */)) { + else if (modifier === 113 /* StaticKeyword */) { + if (!(container.kind === 214 /* ClassDeclaration */ || container.kind === 186 /* ClassExpression */)) { return undefined; } } - else if (modifier === 80 /* ExportKeyword */ || modifier === 120 /* DeclareKeyword */) { - if (!(container.kind === 217 /* ModuleBlock */ || container.kind === 246 /* SourceFile */)) { + else if (modifier === 82 /* ExportKeyword */ || modifier === 122 /* DeclareKeyword */) { + if (!(container.kind === 219 /* ModuleBlock */ || container.kind === 248 /* SourceFile */)) { return undefined; } } - else if (modifier === 113 /* AbstractKeyword */) { - if (!(container.kind === 212 /* ClassDeclaration */ || declaration.kind === 212 /* ClassDeclaration */)) { + else if (modifier === 115 /* AbstractKeyword */) { + if (!(container.kind === 214 /* ClassDeclaration */ || declaration.kind === 214 /* ClassDeclaration */)) { return undefined; } } @@ -45841,8 +46620,8 @@ var ts; var modifierFlag = getFlagFromModifier(modifier); var nodes; switch (container.kind) { - case 217 /* ModuleBlock */: - case 246 /* SourceFile */: + case 219 /* ModuleBlock */: + case 248 /* SourceFile */: // Container is either a class declaration or the declaration is a classDeclaration if (modifierFlag & 256 /* Abstract */) { nodes = declaration.members.concat(declaration); @@ -45851,17 +46630,17 @@ var ts; nodes = container.statements; } break; - case 142 /* Constructor */: + case 144 /* Constructor */: nodes = container.parameters.concat(container.parent.members); break; - case 212 /* ClassDeclaration */: - case 184 /* ClassExpression */: + case 214 /* ClassDeclaration */: + case 186 /* ClassExpression */: nodes = container.members; // If we're an accessibility modifier, we're in an instance member and should search // the constructor's parameter list for instance members as well. if (modifierFlag & 112 /* AccessibilityModifier */) { var constructor = ts.forEach(container.members, function (member) { - return member.kind === 142 /* Constructor */ && member; + return member.kind === 144 /* Constructor */ && member; }); if (constructor) { nodes = nodes.concat(constructor.parameters); @@ -45882,19 +46661,19 @@ var ts; return ts.map(keywords, getHighlightSpanForNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 110 /* PublicKeyword */: + case 112 /* PublicKeyword */: return 16 /* Public */; - case 108 /* PrivateKeyword */: + case 110 /* PrivateKeyword */: return 32 /* Private */; - case 109 /* ProtectedKeyword */: + case 111 /* ProtectedKeyword */: return 64 /* Protected */; - case 111 /* StaticKeyword */: + case 113 /* StaticKeyword */: return 128 /* Static */; - case 80 /* ExportKeyword */: + case 82 /* ExportKeyword */: return 1 /* Export */; - case 120 /* DeclareKeyword */: + case 122 /* DeclareKeyword */: return 2 /* Ambient */; - case 113 /* AbstractKeyword */: + case 115 /* AbstractKeyword */: return 256 /* Abstract */; default: ts.Debug.fail(); @@ -45914,13 +46693,13 @@ var ts; } function getGetAndSetOccurrences(accessorDeclaration) { var keywords = []; - tryPushAccessorKeyword(accessorDeclaration.symbol, 143 /* GetAccessor */); - tryPushAccessorKeyword(accessorDeclaration.symbol, 144 /* SetAccessor */); + tryPushAccessorKeyword(accessorDeclaration.symbol, 145 /* GetAccessor */); + tryPushAccessorKeyword(accessorDeclaration.symbol, 146 /* SetAccessor */); return ts.map(keywords, getHighlightSpanForNode); function tryPushAccessorKeyword(accessorSymbol, accessorKind) { var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { - ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 121 /* GetKeyword */, 127 /* SetKeyword */); }); + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 123 /* GetKeyword */, 129 /* SetKeyword */); }); } } } @@ -45929,19 +46708,19 @@ var ts; var keywords = []; ts.forEach(declarations, function (declaration) { ts.forEach(declaration.getChildren(), function (token) { - return pushKeywordIf(keywords, token, 119 /* ConstructorKeyword */); + return pushKeywordIf(keywords, token, 121 /* ConstructorKeyword */); }); }); return ts.map(keywords, getHighlightSpanForNode); } function getLoopBreakContinueOccurrences(loopNode) { var keywords = []; - if (pushKeywordIf(keywords, loopNode.getFirstToken(), 84 /* ForKeyword */, 102 /* WhileKeyword */, 77 /* DoKeyword */)) { + if (pushKeywordIf(keywords, loopNode.getFirstToken(), 86 /* ForKeyword */, 104 /* WhileKeyword */, 79 /* DoKeyword */)) { // If we succeeded and got a do-while loop, then start looking for a 'while' keyword. - if (loopNode.kind === 195 /* DoStatement */) { + if (loopNode.kind === 197 /* DoStatement */) { var loopTokens = loopNode.getChildren(); for (var i = loopTokens.length - 1; i >= 0; i--) { - if (pushKeywordIf(keywords, loopTokens[i], 102 /* WhileKeyword */)) { + if (pushKeywordIf(keywords, loopTokens[i], 104 /* WhileKeyword */)) { break; } } @@ -45950,7 +46729,7 @@ var ts; var breaksAndContinues = aggregateAllBreakAndContinueStatements(loopNode.statement); ts.forEach(breaksAndContinues, function (statement) { if (ownsBreakOrContinueStatement(loopNode, statement)) { - pushKeywordIf(keywords, statement.getFirstToken(), 68 /* BreakKeyword */, 73 /* ContinueKeyword */); + pushKeywordIf(keywords, statement.getFirstToken(), 70 /* BreakKeyword */, 75 /* ContinueKeyword */); } }); return ts.map(keywords, getHighlightSpanForNode); @@ -45959,13 +46738,13 @@ var ts; var owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { - case 197 /* ForStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: - case 195 /* DoStatement */: - case 196 /* WhileStatement */: + case 199 /* ForStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: + case 197 /* DoStatement */: + case 198 /* WhileStatement */: return getLoopBreakContinueOccurrences(owner); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: return getSwitchCaseDefaultOccurrences(owner); } } @@ -45973,14 +46752,14 @@ var ts; } function getSwitchCaseDefaultOccurrences(switchStatement) { var keywords = []; - pushKeywordIf(keywords, switchStatement.getFirstToken(), 94 /* SwitchKeyword */); + pushKeywordIf(keywords, switchStatement.getFirstToken(), 96 /* SwitchKeyword */); // Go through each clause in the switch statement, collecting the 'case'/'default' keywords. ts.forEach(switchStatement.caseBlock.clauses, function (clause) { - pushKeywordIf(keywords, clause.getFirstToken(), 69 /* CaseKeyword */, 75 /* DefaultKeyword */); + pushKeywordIf(keywords, clause.getFirstToken(), 71 /* CaseKeyword */, 77 /* DefaultKeyword */); var breaksAndContinues = aggregateAllBreakAndContinueStatements(clause); ts.forEach(breaksAndContinues, function (statement) { if (ownsBreakOrContinueStatement(switchStatement, statement)) { - pushKeywordIf(keywords, statement.getFirstToken(), 68 /* BreakKeyword */); + pushKeywordIf(keywords, statement.getFirstToken(), 70 /* BreakKeyword */); } }); }); @@ -45988,13 +46767,13 @@ var ts; } function getTryCatchFinallyOccurrences(tryStatement) { var keywords = []; - pushKeywordIf(keywords, tryStatement.getFirstToken(), 98 /* TryKeyword */); + pushKeywordIf(keywords, tryStatement.getFirstToken(), 100 /* TryKeyword */); if (tryStatement.catchClause) { - pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), 70 /* CatchKeyword */); + pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), 72 /* CatchKeyword */); } if (tryStatement.finallyBlock) { - var finallyKeyword = ts.findChildOfKind(tryStatement, 83 /* FinallyKeyword */, sourceFile); - pushKeywordIf(keywords, finallyKeyword, 83 /* FinallyKeyword */); + var finallyKeyword = ts.findChildOfKind(tryStatement, 85 /* FinallyKeyword */, sourceFile); + pushKeywordIf(keywords, finallyKeyword, 85 /* FinallyKeyword */); } return ts.map(keywords, getHighlightSpanForNode); } @@ -46005,13 +46784,13 @@ var ts; } var keywords = []; ts.forEach(aggregateOwnedThrowStatements(owner), function (throwStatement) { - pushKeywordIf(keywords, throwStatement.getFirstToken(), 96 /* ThrowKeyword */); + pushKeywordIf(keywords, throwStatement.getFirstToken(), 98 /* ThrowKeyword */); }); // If the "owner" is a function, then we equate 'return' and 'throw' statements in their // ability to "jump out" of the function, and include occurrences for both. if (ts.isFunctionBlock(owner)) { ts.forEachReturnStatement(owner, function (returnStatement) { - pushKeywordIf(keywords, returnStatement.getFirstToken(), 92 /* ReturnKeyword */); + pushKeywordIf(keywords, returnStatement.getFirstToken(), 94 /* ReturnKeyword */); }); } return ts.map(keywords, getHighlightSpanForNode); @@ -46019,36 +46798,36 @@ var ts; function getReturnOccurrences(returnStatement) { var func = ts.getContainingFunction(returnStatement); // If we didn't find a containing function with a block body, bail out. - if (!(func && hasKind(func.body, 190 /* Block */))) { + if (!(func && hasKind(func.body, 192 /* Block */))) { return undefined; } var keywords = []; ts.forEachReturnStatement(func.body, function (returnStatement) { - pushKeywordIf(keywords, returnStatement.getFirstToken(), 92 /* ReturnKeyword */); + pushKeywordIf(keywords, returnStatement.getFirstToken(), 94 /* ReturnKeyword */); }); // Include 'throw' statements that do not occur within a try block. ts.forEach(aggregateOwnedThrowStatements(func.body), function (throwStatement) { - pushKeywordIf(keywords, throwStatement.getFirstToken(), 96 /* ThrowKeyword */); + pushKeywordIf(keywords, throwStatement.getFirstToken(), 98 /* ThrowKeyword */); }); return ts.map(keywords, getHighlightSpanForNode); } function getIfElseOccurrences(ifStatement) { var keywords = []; // Traverse upwards through all parent if-statements linked by their else-branches. - while (hasKind(ifStatement.parent, 194 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { + while (hasKind(ifStatement.parent, 196 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) { ifStatement = ifStatement.parent; } // Now traverse back down through the else branches, aggregating if/else keywords of if-statements. while (ifStatement) { var children = ifStatement.getChildren(); - pushKeywordIf(keywords, children[0], 86 /* IfKeyword */); + pushKeywordIf(keywords, children[0], 88 /* IfKeyword */); // Generally the 'else' keyword is second-to-last, so we traverse backwards. for (var i = children.length - 1; i >= 0; i--) { - if (pushKeywordIf(keywords, children[i], 78 /* ElseKeyword */)) { + if (pushKeywordIf(keywords, children[i], 80 /* ElseKeyword */)) { break; } } - if (!hasKind(ifStatement.elseStatement, 194 /* IfStatement */)) { + if (!hasKind(ifStatement.elseStatement, 196 /* IfStatement */)) { break; } ifStatement = ifStatement.elseStatement; @@ -46057,7 +46836,7 @@ var ts; // We'd like to highlight else/ifs together if they are only separated by whitespace // (i.e. the keywords are separated by no comments, no newlines). for (var i = 0; i < keywords.length; i++) { - if (keywords[i].kind === 78 /* ElseKeyword */ && i < keywords.length - 1) { + if (keywords[i].kind === 80 /* ElseKeyword */ && i < keywords.length - 1) { var elseKeyword = keywords[i]; var ifKeyword = keywords[i + 1]; // this *should* always be an 'if' keyword. var shouldCombindElseAndIf = true; @@ -46139,7 +46918,7 @@ var ts; if (!node) { return undefined; } - if (node.kind !== 67 /* Identifier */ && + if (node.kind !== 69 /* Identifier */ && // TODO (drosen): This should be enabled in a later release - currently breaks rename. //node.kind !== SyntaxKind.ThisKeyword && //node.kind !== SyntaxKind.SuperKeyword && @@ -46147,7 +46926,7 @@ var ts; !isNameOfExternalModuleImportOrDeclaration(node)) { return undefined; } - ts.Debug.assert(node.kind === 67 /* Identifier */ || node.kind === 8 /* NumericLiteral */ || node.kind === 9 /* StringLiteral */); + ts.Debug.assert(node.kind === 69 /* Identifier */ || node.kind === 8 /* NumericLiteral */ || node.kind === 9 /* StringLiteral */); return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNode(node, sourceFiles, findInStrings, findInComments) { @@ -46165,10 +46944,10 @@ var ts; return getLabelReferencesInNode(node.parent, node); } } - if (node.kind === 95 /* ThisKeyword */) { + if (node.kind === 97 /* ThisKeyword */) { return getReferencesForThisKeyword(node, sourceFiles); } - if (node.kind === 93 /* SuperKeyword */) { + if (node.kind === 95 /* SuperKeyword */) { return getReferencesForSuperKeyword(node); } var symbol = typeChecker.getSymbolAtLocation(node); @@ -46228,7 +47007,7 @@ var ts; } function isImportOrExportSpecifierImportSymbol(symbol) { return (symbol.flags & 8388608 /* Alias */) && ts.forEach(symbol.declarations, function (declaration) { - return declaration.kind === 224 /* ImportSpecifier */ || declaration.kind === 228 /* ExportSpecifier */; + return declaration.kind === 226 /* ImportSpecifier */ || declaration.kind === 230 /* ExportSpecifier */; }); } function getInternedName(symbol, location, declarations) { @@ -46255,14 +47034,14 @@ var ts; // If this is the symbol of a named function expression or named class expression, // then named references are limited to its own scope. var valueDeclaration = symbol.valueDeclaration; - if (valueDeclaration && (valueDeclaration.kind === 171 /* FunctionExpression */ || valueDeclaration.kind === 184 /* ClassExpression */)) { + if (valueDeclaration && (valueDeclaration.kind === 173 /* FunctionExpression */ || valueDeclaration.kind === 186 /* ClassExpression */)) { return valueDeclaration; } // If this is private property or method, the scope is the containing class if (symbol.flags & (4 /* Property */ | 8192 /* Method */)) { var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32 /* Private */) ? d : undefined; }); if (privateDeclaration) { - return ts.getAncestor(privateDeclaration, 212 /* ClassDeclaration */); + return ts.getAncestor(privateDeclaration, 214 /* ClassDeclaration */); } } // If the symbol is an import we would like to find it if we are looking for what it imports. @@ -46288,7 +47067,7 @@ var ts; // Different declarations have different containers, bail out return undefined; } - if (container.kind === 246 /* SourceFile */ && !ts.isExternalModule(container)) { + if (container.kind === 248 /* SourceFile */ && !ts.isExternalModule(container)) { // This is a global variable and not an external module, any declaration defined // within this scope is visible outside the file return undefined; @@ -46359,7 +47138,7 @@ var ts; if (node) { // Compare the length so we filter out strict superstrings of the symbol we are looking for switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: return node.getWidth() === searchSymbolName.length; case 9 /* StringLiteral */: if (isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || @@ -46461,13 +47240,13 @@ var ts; // Whether 'super' occurs in a static context within a class. var staticFlag = 128 /* Static */; switch (searchSpaceNode.kind) { - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; @@ -46480,7 +47259,7 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || node.kind !== 93 /* SuperKeyword */) { + if (!node || node.kind !== 95 /* SuperKeyword */) { return; } var container = ts.getSuperContainer(node, /*includeFunctions*/ false); @@ -46499,27 +47278,27 @@ var ts; // Whether 'this' occurs in a static context within a class. var staticFlag = 128 /* Static */; switch (searchSpaceNode.kind) { - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (ts.isObjectLiteralMethod(searchSpaceNode)) { break; } // fall through - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; // re-assign to be the owning class break; - case 246 /* SourceFile */: + case 248 /* SourceFile */: if (ts.isExternalModule(searchSpaceNode)) { return undefined; } // Fall through - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: break; // Computed properties in classes are not handled here because references to this are illegal, // so there is no point finding references to them. @@ -46528,7 +47307,7 @@ var ts; } var references = []; var possiblePositions; - if (searchSpaceNode.kind === 246 /* SourceFile */) { + if (searchSpaceNode.kind === 248 /* SourceFile */) { ts.forEach(sourceFiles, function (sourceFile) { possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, references); @@ -46554,33 +47333,33 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || node.kind !== 95 /* ThisKeyword */) { + if (!node || node.kind !== 97 /* ThisKeyword */) { return; } var container = ts.getThisContainer(node, /* includeArrowFunctions */ false); switch (searchSpaceNode.kind) { - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: if (searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: if (ts.isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 184 /* ClassExpression */: - case 212 /* ClassDeclaration */: + case 186 /* ClassExpression */: + case 214 /* ClassDeclaration */: // Make sure the container belongs to the same class // and has the appropriate static modifier from the original container. if (container.parent && searchSpaceNode.symbol === container.parent.symbol && (container.flags & 128 /* Static */) === staticFlag) { result.push(getReferenceEntryFromNode(node)); } break; - case 246 /* SourceFile */: - if (container.kind === 246 /* SourceFile */ && !ts.isExternalModule(container)) { + case 248 /* SourceFile */: + if (container.kind === 248 /* SourceFile */ && !ts.isExternalModule(container)) { result.push(getReferenceEntryFromNode(node)); } break; @@ -46634,11 +47413,11 @@ var ts; function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) { if (symbol && symbol.flags & (32 /* Class */ | 64 /* Interface */)) { ts.forEach(symbol.getDeclarations(), function (declaration) { - if (declaration.kind === 212 /* ClassDeclaration */) { + if (declaration.kind === 214 /* ClassDeclaration */) { getPropertySymbolFromTypeReference(ts.getClassExtendsHeritageClauseElement(declaration)); ts.forEach(ts.getClassImplementsHeritageClauseElements(declaration), getPropertySymbolFromTypeReference); } - else if (declaration.kind === 213 /* InterfaceDeclaration */) { + else if (declaration.kind === 215 /* InterfaceDeclaration */) { ts.forEach(ts.getInterfaceBaseTypeNodes(declaration), getPropertySymbolFromTypeReference); } }); @@ -46699,19 +47478,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_33 = node.text; + var name_34 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_33); + var unionProperty = contextualType.getProperty(name_34); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_33); + var symbol = t.getProperty(name_34); if (symbol) { result_4.push(symbol); } @@ -46720,7 +47499,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_33); + var symbol_1 = contextualType.getProperty(name_34); if (symbol_1) { return [symbol_1]; } @@ -46773,17 +47552,17 @@ var ts; } /** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */ function isWriteAccess(node) { - if (node.kind === 67 /* Identifier */ && ts.isDeclarationName(node)) { + if (node.kind === 69 /* Identifier */ && ts.isDeclarationName(node)) { return true; } var parent = node.parent; if (parent) { - if (parent.kind === 178 /* PostfixUnaryExpression */ || parent.kind === 177 /* PrefixUnaryExpression */) { + if (parent.kind === 180 /* PostfixUnaryExpression */ || parent.kind === 179 /* PrefixUnaryExpression */) { return true; } - else if (parent.kind === 179 /* BinaryExpression */ && parent.left === node) { + else if (parent.kind === 181 /* BinaryExpression */ && parent.left === node) { var operator = parent.operatorToken.kind; - return 55 /* FirstAssignment */ <= operator && operator <= 66 /* LastAssignment */; + return 56 /* FirstAssignment */ <= operator && operator <= 68 /* LastAssignment */; } } return false; @@ -46815,33 +47594,33 @@ var ts; } function getMeaningFromDeclaration(node) { switch (node.kind) { - case 136 /* Parameter */: - case 209 /* VariableDeclaration */: - case 161 /* BindingElement */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: - case 243 /* PropertyAssignment */: - case 244 /* ShorthandPropertyAssignment */: - case 245 /* EnumMember */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 142 /* Constructor */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 211 /* FunctionDeclaration */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: - case 242 /* CatchClause */: + case 138 /* Parameter */: + case 211 /* VariableDeclaration */: + case 163 /* BindingElement */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: + case 245 /* PropertyAssignment */: + case 246 /* ShorthandPropertyAssignment */: + case 247 /* EnumMember */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 144 /* Constructor */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 213 /* FunctionDeclaration */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + case 244 /* CatchClause */: return 1 /* Value */; - case 135 /* TypeParameter */: - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: - case 153 /* TypeLiteral */: + case 137 /* TypeParameter */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: + case 155 /* TypeLiteral */: return 2 /* Type */; - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: return 1 /* Value */ | 2 /* Type */; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (node.name.kind === 9 /* StringLiteral */) { return 4 /* Namespace */ | 1 /* Value */; } @@ -46851,15 +47630,15 @@ var ts; else { return 4 /* Namespace */; } - case 223 /* NamedImports */: - case 224 /* ImportSpecifier */: - case 219 /* ImportEqualsDeclaration */: - case 220 /* ImportDeclaration */: - case 225 /* ExportAssignment */: - case 226 /* ExportDeclaration */: + case 225 /* NamedImports */: + case 226 /* ImportSpecifier */: + case 221 /* ImportEqualsDeclaration */: + case 222 /* ImportDeclaration */: + case 227 /* ExportAssignment */: + case 228 /* ExportDeclaration */: return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; // An external module can be a Value - case 246 /* SourceFile */: + case 248 /* SourceFile */: return 4 /* Namespace */ | 1 /* Value */; } return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; @@ -46869,8 +47648,9 @@ var ts; if (ts.isRightSideOfQualifiedNameOrPropertyAccess(node)) { node = node.parent; } - return node.parent.kind === 149 /* TypeReference */ || - (node.parent.kind === 186 /* ExpressionWithTypeArguments */ && !ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent)); + return node.parent.kind === 151 /* TypeReference */ || + (node.parent.kind === 188 /* ExpressionWithTypeArguments */ && !ts.isExpressionWithTypeArgumentsInClassExtendsClause(node.parent)) || + node.kind === 97 /* ThisKeyword */ && !ts.isExpression(node); } function isNamespaceReference(node) { return isQualifiedNameNamespaceReference(node) || isPropertyAccessNamespaceReference(node); @@ -46878,50 +47658,50 @@ var ts; function isPropertyAccessNamespaceReference(node) { var root = node; var isLastClause = true; - if (root.parent.kind === 164 /* PropertyAccessExpression */) { - while (root.parent && root.parent.kind === 164 /* PropertyAccessExpression */) { + if (root.parent.kind === 166 /* PropertyAccessExpression */) { + while (root.parent && root.parent.kind === 166 /* PropertyAccessExpression */) { root = root.parent; } isLastClause = root.name === node; } - if (!isLastClause && root.parent.kind === 186 /* ExpressionWithTypeArguments */ && root.parent.parent.kind === 241 /* HeritageClause */) { + if (!isLastClause && root.parent.kind === 188 /* ExpressionWithTypeArguments */ && root.parent.parent.kind === 243 /* HeritageClause */) { var decl = root.parent.parent.parent; - return (decl.kind === 212 /* ClassDeclaration */ && root.parent.parent.token === 104 /* ImplementsKeyword */) || - (decl.kind === 213 /* InterfaceDeclaration */ && root.parent.parent.token === 81 /* ExtendsKeyword */); + return (decl.kind === 214 /* ClassDeclaration */ && root.parent.parent.token === 106 /* ImplementsKeyword */) || + (decl.kind === 215 /* InterfaceDeclaration */ && root.parent.parent.token === 83 /* ExtendsKeyword */); } return false; } function isQualifiedNameNamespaceReference(node) { var root = node; var isLastClause = true; - if (root.parent.kind === 133 /* QualifiedName */) { - while (root.parent && root.parent.kind === 133 /* QualifiedName */) { + if (root.parent.kind === 135 /* QualifiedName */) { + while (root.parent && root.parent.kind === 135 /* QualifiedName */) { root = root.parent; } isLastClause = root.right === node; } - return root.parent.kind === 149 /* TypeReference */ && !isLastClause; + return root.parent.kind === 151 /* TypeReference */ && !isLastClause; } function isInRightSideOfImport(node) { - while (node.parent.kind === 133 /* QualifiedName */) { + while (node.parent.kind === 135 /* QualifiedName */) { node = node.parent; } return ts.isInternalModuleImportEqualsDeclaration(node.parent) && node.parent.moduleReference === node; } function getMeaningFromRightHandSideOfImportEquals(node) { - ts.Debug.assert(node.kind === 67 /* Identifier */); + ts.Debug.assert(node.kind === 69 /* Identifier */); // import a = |b|; // Namespace // import a = |b.c|; // Value, type, namespace // import a = |b.c|.d; // Namespace - if (node.parent.kind === 133 /* QualifiedName */ && + if (node.parent.kind === 135 /* QualifiedName */ && node.parent.right === node && - node.parent.parent.kind === 219 /* ImportEqualsDeclaration */) { + node.parent.parent.kind === 221 /* ImportEqualsDeclaration */) { return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; } return 4 /* Namespace */; } function getMeaningFromLocation(node) { - if (node.parent.kind === 225 /* ExportAssignment */) { + if (node.parent.kind === 227 /* ExportAssignment */) { return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */; } else if (isInRightSideOfImport(node)) { @@ -46961,15 +47741,15 @@ var ts; return; } switch (node.kind) { - case 164 /* PropertyAccessExpression */: - case 133 /* QualifiedName */: + case 166 /* PropertyAccessExpression */: + case 135 /* QualifiedName */: case 9 /* StringLiteral */: - case 82 /* FalseKeyword */: - case 97 /* TrueKeyword */: - case 91 /* NullKeyword */: - case 93 /* SuperKeyword */: - case 95 /* ThisKeyword */: - case 67 /* Identifier */: + case 84 /* FalseKeyword */: + case 99 /* TrueKeyword */: + case 93 /* NullKeyword */: + case 95 /* SuperKeyword */: + case 97 /* ThisKeyword */: + case 69 /* Identifier */: break; // Cant create the text span default: @@ -46985,7 +47765,7 @@ var ts; // If this is name of a module declarations, check if this is right side of dotted module name // If parent of the module declaration which is parent of this node is module declaration and its body is the module declaration that this node is name of // Then this name is name from dotted module - if (nodeForStartPos.parent.parent.kind === 216 /* ModuleDeclaration */ && + if (nodeForStartPos.parent.parent.kind === 218 /* ModuleDeclaration */ && nodeForStartPos.parent.parent.body === nodeForStartPos.parent) { // Use parent module declarations name for start pos nodeForStartPos = nodeForStartPos.parent.parent.name; @@ -47026,10 +47806,10 @@ var ts; // That means we're calling back into the host around every 1.2k of the file we process. // Lib.d.ts has similar numbers. switch (kind) { - case 216 /* ModuleDeclaration */: - case 212 /* ClassDeclaration */: - case 213 /* InterfaceDeclaration */: - case 211 /* FunctionDeclaration */: + case 218 /* ModuleDeclaration */: + case 214 /* ClassDeclaration */: + case 215 /* InterfaceDeclaration */: + case 213 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } @@ -47083,7 +47863,7 @@ var ts; */ function hasValueSideModule(symbol) { return ts.forEach(symbol.declarations, function (declaration) { - return declaration.kind === 216 /* ModuleDeclaration */ && + return declaration.kind === 218 /* ModuleDeclaration */ && ts.getModuleInstanceState(declaration) === 1 /* Instantiated */; }); } @@ -47093,7 +47873,7 @@ var ts; if (node && ts.textSpanIntersectsWith(span, node.getFullStart(), node.getFullWidth())) { var kind = node.kind; checkForClassificationCancellation(kind); - if (kind === 67 /* Identifier */ && !ts.nodeIsMissing(node)) { + if (kind === 69 /* Identifier */ && !ts.nodeIsMissing(node)) { var identifier = node; // Only bother calling into the typechecker if this is an identifier that // could possibly resolve to a type name. This makes classification run @@ -47238,16 +48018,16 @@ var ts; pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, 18 /* docCommentTagName */); pos = tag.tagName.end; switch (tag.kind) { - case 265 /* JSDocParameterTag */: + case 267 /* JSDocParameterTag */: processJSDocParameterTag(tag); break; - case 268 /* JSDocTemplateTag */: + case 270 /* JSDocTemplateTag */: processJSDocTemplateTag(tag); break; - case 267 /* JSDocTypeTag */: + case 269 /* JSDocTypeTag */: processElement(tag.typeExpression); break; - case 266 /* JSDocReturnTag */: + case 268 /* JSDocReturnTag */: processElement(tag.typeExpression); break; } @@ -47336,18 +48116,18 @@ var ts; } if (ts.isPunctuation(tokenKind)) { if (token) { - if (tokenKind === 55 /* EqualsToken */) { + if (tokenKind === 56 /* EqualsToken */) { // the '=' in a variable declaration is special cased here. - if (token.parent.kind === 209 /* VariableDeclaration */ || - token.parent.kind === 139 /* PropertyDeclaration */ || - token.parent.kind === 136 /* Parameter */) { + if (token.parent.kind === 211 /* VariableDeclaration */ || + token.parent.kind === 141 /* PropertyDeclaration */ || + token.parent.kind === 138 /* Parameter */) { return 5 /* operator */; } } - if (token.parent.kind === 179 /* BinaryExpression */ || - token.parent.kind === 177 /* PrefixUnaryExpression */ || - token.parent.kind === 178 /* PostfixUnaryExpression */ || - token.parent.kind === 180 /* ConditionalExpression */) { + if (token.parent.kind === 181 /* BinaryExpression */ || + token.parent.kind === 179 /* PrefixUnaryExpression */ || + token.parent.kind === 180 /* PostfixUnaryExpression */ || + token.parent.kind === 182 /* ConditionalExpression */) { return 5 /* operator */; } } @@ -47367,35 +48147,35 @@ var ts; // TODO (drosen): we should *also* get another classification type for these literals. return 6 /* stringLiteral */; } - else if (tokenKind === 67 /* Identifier */) { + else if (tokenKind === 69 /* Identifier */) { if (token) { switch (token.parent.kind) { - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: if (token.parent.name === token) { return 11 /* className */; } return; - case 135 /* TypeParameter */: + case 137 /* TypeParameter */: if (token.parent.name === token) { return 15 /* typeParameterName */; } return; - case 213 /* InterfaceDeclaration */: + case 215 /* InterfaceDeclaration */: if (token.parent.name === token) { return 13 /* interfaceName */; } return; - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: if (token.parent.name === token) { return 12 /* enumName */; } return; - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (token.parent.name === token) { return 14 /* moduleName */; } return; - case 136 /* Parameter */: + case 138 /* Parameter */: if (token.parent.name === token) { return 17 /* parameterName */; } @@ -47507,8 +48287,12 @@ var ts; * Checks if position points to a valid position to add JSDoc comments, and if so, * returns the appropriate template. Otherwise returns an empty string. * Valid positions are - * - outside of comments, statements, and expressions, and - * - preceding a function declaration. + * - outside of comments, statements, and expressions, and + * - preceding a: + * - function/constructor/method declaration + * - class declarations + * - variable statements + * - namespace declarations * * Hosts should ideally check that: * - The line is all whitespace up to 'position' before performing the insertion. @@ -47532,23 +48316,48 @@ var ts; return undefined; } // TODO: add support for: - // - methods - // - constructors - // - class decls - var containingFunction = ts.getAncestor(tokenAtPos, 211 /* FunctionDeclaration */); - if (!containingFunction || containingFunction.getStart() < position) { + // - enums/enum members + // - interfaces + // - property declarations + // - potentially property assignments + var commentOwner; + findOwner: for (commentOwner = tokenAtPos; commentOwner; commentOwner = commentOwner.parent) { + switch (commentOwner.kind) { + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 144 /* Constructor */: + case 214 /* ClassDeclaration */: + case 193 /* VariableStatement */: + break findOwner; + case 248 /* SourceFile */: + return undefined; + case 218 /* ModuleDeclaration */: + // If in walking up the tree, we hit a a nested namespace declaration, + // then we must be somewhere within a dotted namespace name; however we don't + // want to give back a JSDoc template for the 'b' or 'c' in 'namespace a.b.c { }'. + if (commentOwner.parent.kind === 218 /* ModuleDeclaration */) { + return undefined; + } + break findOwner; + } + } + if (!commentOwner || commentOwner.getStart() < position) { return undefined; } - var parameters = containingFunction.parameters; + var parameters = getParametersForJsDocOwningNode(commentOwner); var posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position); var lineStart = sourceFile.getLineStarts()[posLineAndChar.line]; var indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character); // TODO: call a helper method instead once PR #4133 gets merged in. var newLine = host.getNewLine ? host.getNewLine() : "\r\n"; - var docParams = parameters.reduce(function (prev, cur, index) { - return prev + - indentationStr + " * @param " + (cur.name.kind === 67 /* Identifier */ ? cur.name.text : "param" + index) + newLine; - }, ""); + var docParams = ""; + for (var i = 0, numParams = parameters.length; i < numParams; i++) { + var currentName = parameters[i].name; + var paramName = currentName.kind === 69 /* Identifier */ ? + currentName.text : + "param" + i; + docParams += indentationStr + " * @param " + paramName + newLine; + } // A doc comment consists of the following // * The opening comment line // * the first line (without a param) for the object's untagged info (this is also where the caret ends up) @@ -47564,6 +48373,46 @@ var ts; (tokenStart === position ? newLine + indentationStr : ""); return { newText: result, caretOffset: preamble.length }; } + function getParametersForJsDocOwningNode(commentOwner) { + if (ts.isFunctionLike(commentOwner)) { + return commentOwner.parameters; + } + if (commentOwner.kind === 193 /* VariableStatement */) { + var varStatement = commentOwner; + var varDeclarations = varStatement.declarationList.declarations; + if (varDeclarations.length === 1 && varDeclarations[0].initializer) { + return getParametersFromRightHandSideOfAssignment(varDeclarations[0].initializer); + } + } + return emptyArray; + } + /** + * Digs into an an initializer or RHS operand of an assignment operation + * to get the parameters of an apt signature corresponding to a + * function expression or a class expression. + * + * @param rightHandSide the expression which may contain an appropriate set of parameters + * @returns the parameters of a signature found on the RHS if one exists; otherwise 'emptyArray'. + */ + function getParametersFromRightHandSideOfAssignment(rightHandSide) { + while (rightHandSide.kind === 172 /* ParenthesizedExpression */) { + rightHandSide = rightHandSide.expression; + } + switch (rightHandSide.kind) { + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: + return rightHandSide.parameters; + case 186 /* ClassExpression */: + for (var _i = 0, _a = rightHandSide.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 144 /* Constructor */) { + return member.parameters; + } + } + break; + } + return emptyArray; + } function getTodoComments(fileName, descriptors) { // Note: while getting todo comments seems like a syntactic operation, we actually // treat it as a semantic operation here. This is because we expect our host to call @@ -47694,7 +48543,7 @@ var ts; var typeChecker = program.getTypeChecker(); var node = ts.getTouchingWord(sourceFile, position); // Can only rename an identifier. - if (node && node.kind === 67 /* Identifier */) { + if (node && node.kind === 69 /* Identifier */) { var symbol = typeChecker.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol) { @@ -47795,7 +48644,7 @@ var ts; sourceFile.nameTable = nameTable; function walk(node) { switch (node.kind) { - case 67 /* Identifier */: + case 69 /* Identifier */: nameTable[node.text] = node.text; break; case 9 /* StringLiteral */: @@ -47805,7 +48654,7 @@ var ts; // then we want 'something' to be in the name table. Similarly, if we have // "a['propname']" then we want to store "propname" in the name table. if (ts.isDeclarationName(node) || - node.parent.kind === 230 /* ExternalModuleReference */ || + node.parent.kind === 232 /* ExternalModuleReference */ || isArgumentOfElementAccessExpression(node)) { nameTable[node.text] = node.text; } @@ -47818,7 +48667,7 @@ var ts; function isArgumentOfElementAccessExpression(node) { return node && node.parent && - node.parent.kind === 165 /* ElementAccessExpression */ && + node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.argumentExpression === node; } /// Classifier @@ -47829,18 +48678,18 @@ var ts; /// we have a series of divide operator. this list allows us to be more accurate by ruling out /// locations where a regexp cannot exist. var noRegexTable = []; - noRegexTable[67 /* Identifier */] = true; + noRegexTable[69 /* Identifier */] = true; noRegexTable[9 /* StringLiteral */] = true; noRegexTable[8 /* NumericLiteral */] = true; noRegexTable[10 /* RegularExpressionLiteral */] = true; - noRegexTable[95 /* ThisKeyword */] = true; - noRegexTable[40 /* PlusPlusToken */] = true; - noRegexTable[41 /* MinusMinusToken */] = true; + noRegexTable[97 /* ThisKeyword */] = true; + noRegexTable[41 /* PlusPlusToken */] = true; + noRegexTable[42 /* MinusMinusToken */] = true; noRegexTable[18 /* CloseParenToken */] = true; noRegexTable[20 /* CloseBracketToken */] = true; noRegexTable[16 /* CloseBraceToken */] = true; - noRegexTable[97 /* TrueKeyword */] = true; - noRegexTable[82 /* FalseKeyword */] = true; + noRegexTable[99 /* TrueKeyword */] = true; + noRegexTable[84 /* FalseKeyword */] = true; // Just a stack of TemplateHeads and OpenCurlyBraces, used to perform rudimentary (inexact) // classification on template strings. Because of the context free nature of templates, // the only precise way to classify a template portion would be by propagating the stack across @@ -47865,10 +48714,10 @@ var ts; /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */ function canFollow(keyword1, keyword2) { if (ts.isAccessibilityModifier(keyword1)) { - if (keyword2 === 121 /* GetKeyword */ || - keyword2 === 127 /* SetKeyword */ || - keyword2 === 119 /* ConstructorKeyword */ || - keyword2 === 111 /* StaticKeyword */) { + if (keyword2 === 123 /* GetKeyword */ || + keyword2 === 129 /* SetKeyword */ || + keyword2 === 121 /* ConstructorKeyword */ || + keyword2 === 113 /* StaticKeyword */) { // Allow things like "public get", "public constructor" and "public static". // These are all legal. return true; @@ -47998,22 +48847,22 @@ var ts; do { token = scanner.scan(); if (!ts.isTrivia(token)) { - if ((token === 38 /* SlashToken */ || token === 59 /* SlashEqualsToken */) && !noRegexTable[lastNonTriviaToken]) { + if ((token === 39 /* SlashToken */ || token === 61 /* SlashEqualsToken */) && !noRegexTable[lastNonTriviaToken]) { if (scanner.reScanSlashToken() === 10 /* RegularExpressionLiteral */) { token = 10 /* RegularExpressionLiteral */; } } else if (lastNonTriviaToken === 21 /* DotToken */ && isKeyword(token)) { - token = 67 /* Identifier */; + token = 69 /* Identifier */; } else if (isKeyword(lastNonTriviaToken) && isKeyword(token) && !canFollow(lastNonTriviaToken, token)) { // We have two keywords in a row. Only treat the second as a keyword if // it's a sequence that could legally occur in the language. Otherwise // treat it as an identifier. This way, if someone writes "private var" // we recognize that 'var' is actually an identifier here. - token = 67 /* Identifier */; + token = 69 /* Identifier */; } - else if (lastNonTriviaToken === 67 /* Identifier */ && + else if (lastNonTriviaToken === 69 /* Identifier */ && token === 25 /* LessThanToken */) { // Could be the start of something generic. Keep track of that by bumping // up the current count of generic contexts we may be in. @@ -48024,16 +48873,16 @@ var ts; // generic entity is complete. angleBracketStack--; } - else if (token === 115 /* AnyKeyword */ || - token === 128 /* StringKeyword */ || - token === 126 /* NumberKeyword */ || - token === 118 /* BooleanKeyword */ || - token === 129 /* SymbolKeyword */) { + else if (token === 117 /* AnyKeyword */ || + token === 130 /* StringKeyword */ || + token === 128 /* NumberKeyword */ || + token === 120 /* BooleanKeyword */ || + token === 131 /* SymbolKeyword */) { if (angleBracketStack > 0 && !syntacticClassifierAbsent) { // If it looks like we're could be in something generic, don't classify this // as a keyword. We may just get overwritten by the syntactic classifier, // causing a noisy experience for the user. - token = 67 /* Identifier */; + token = 69 /* Identifier */; } } else if (token === 12 /* TemplateHead */) { @@ -48145,40 +48994,41 @@ var ts; function isBinaryExpressionOperatorToken(token) { switch (token) { case 37 /* AsteriskToken */: - case 38 /* SlashToken */: - case 39 /* PercentToken */: + case 39 /* SlashToken */: + case 40 /* PercentToken */: case 35 /* PlusToken */: case 36 /* MinusToken */: - case 42 /* LessThanLessThanToken */: - case 43 /* GreaterThanGreaterThanToken */: - case 44 /* GreaterThanGreaterThanGreaterThanToken */: + case 43 /* LessThanLessThanToken */: + case 44 /* GreaterThanGreaterThanToken */: + case 45 /* GreaterThanGreaterThanGreaterThanToken */: case 25 /* LessThanToken */: case 27 /* GreaterThanToken */: case 28 /* LessThanEqualsToken */: case 29 /* GreaterThanEqualsToken */: - case 89 /* InstanceOfKeyword */: - case 88 /* InKeyword */: + case 91 /* InstanceOfKeyword */: + case 90 /* InKeyword */: + case 116 /* AsKeyword */: case 30 /* EqualsEqualsToken */: case 31 /* ExclamationEqualsToken */: case 32 /* EqualsEqualsEqualsToken */: case 33 /* ExclamationEqualsEqualsToken */: - case 45 /* AmpersandToken */: - case 47 /* CaretToken */: - case 46 /* BarToken */: - case 50 /* AmpersandAmpersandToken */: - case 51 /* BarBarToken */: - case 65 /* BarEqualsToken */: - case 64 /* AmpersandEqualsToken */: - case 66 /* CaretEqualsToken */: - case 61 /* LessThanLessThanEqualsToken */: - case 62 /* GreaterThanGreaterThanEqualsToken */: - case 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */: - case 56 /* PlusEqualsToken */: - case 57 /* MinusEqualsToken */: - case 58 /* AsteriskEqualsToken */: - case 59 /* SlashEqualsToken */: - case 60 /* PercentEqualsToken */: - case 55 /* EqualsToken */: + case 46 /* AmpersandToken */: + case 48 /* CaretToken */: + case 47 /* BarToken */: + case 51 /* AmpersandAmpersandToken */: + case 52 /* BarBarToken */: + case 67 /* BarEqualsToken */: + case 66 /* AmpersandEqualsToken */: + case 68 /* CaretEqualsToken */: + case 63 /* LessThanLessThanEqualsToken */: + case 64 /* GreaterThanGreaterThanEqualsToken */: + case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */: + case 57 /* PlusEqualsToken */: + case 58 /* MinusEqualsToken */: + case 59 /* AsteriskEqualsToken */: + case 61 /* SlashEqualsToken */: + case 62 /* PercentEqualsToken */: + case 56 /* EqualsToken */: case 24 /* CommaToken */: return true; default: @@ -48189,17 +49039,17 @@ var ts; switch (token) { case 35 /* PlusToken */: case 36 /* MinusToken */: - case 49 /* TildeToken */: - case 48 /* ExclamationToken */: - case 40 /* PlusPlusToken */: - case 41 /* MinusMinusToken */: + case 50 /* TildeToken */: + case 49 /* ExclamationToken */: + case 41 /* PlusPlusToken */: + case 42 /* MinusMinusToken */: return true; default: return false; } } function isKeyword(token) { - return token >= 68 /* FirstKeyword */ && token <= 132 /* LastKeyword */; + return token >= 70 /* FirstKeyword */ && token <= 134 /* LastKeyword */; } function classFromKind(token) { if (isKeyword(token)) { @@ -48208,7 +49058,7 @@ var ts; else if (isBinaryExpressionOperatorToken(token) || isPrefixUnaryExpressionOperatorToken(token)) { return 5 /* operator */; } - else if (token >= 15 /* FirstPunctuation */ && token <= 66 /* LastPunctuation */) { + else if (token >= 15 /* FirstPunctuation */ && token <= 68 /* LastPunctuation */) { return 10 /* punctuation */; } switch (token) { @@ -48225,7 +49075,7 @@ var ts; case 5 /* WhitespaceTrivia */: case 4 /* NewLineTrivia */: return 8 /* whiteSpace */; - case 67 /* Identifier */: + case 69 /* Identifier */: default: if (ts.isTemplateLiteralKind(token)) { return 6 /* stringLiteral */; @@ -48257,7 +49107,7 @@ var ts; getNodeConstructor: function (kind) { function Node() { } - var proto = kind === 246 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); + var proto = kind === 248 /* SourceFile */ ? new SourceFileObject() : new NodeObject(); proto.kind = kind; proto.pos = -1; proto.end = -1; @@ -48327,125 +49177,125 @@ var ts; function spanInNode(node) { if (node) { if (ts.isExpression(node)) { - if (node.parent.kind === 195 /* DoStatement */) { + if (node.parent.kind === 197 /* DoStatement */) { // Set span as if on while keyword return spanInPreviousNode(node); } - if (node.parent.kind === 197 /* ForStatement */) { + if (node.parent.kind === 199 /* ForStatement */) { // For now lets set the span on this expression, fix it later return textSpan(node); } - if (node.parent.kind === 179 /* BinaryExpression */ && node.parent.operatorToken.kind === 24 /* CommaToken */) { + if (node.parent.kind === 181 /* BinaryExpression */ && node.parent.operatorToken.kind === 24 /* CommaToken */) { // if this is comma expression, the breakpoint is possible in this expression return textSpan(node); } - if (node.parent.kind === 172 /* ArrowFunction */ && node.parent.body === node) { + if (node.parent.kind === 174 /* ArrowFunction */ && node.parent.body === node) { // If this is body of arrow function, it is allowed to have the breakpoint return textSpan(node); } } switch (node.kind) { - case 191 /* VariableStatement */: + case 193 /* VariableStatement */: // Span on first variable declaration return spanInVariableDeclaration(node.declarationList.declarations[0]); - case 209 /* VariableDeclaration */: - case 139 /* PropertyDeclaration */: - case 138 /* PropertySignature */: + case 211 /* VariableDeclaration */: + case 141 /* PropertyDeclaration */: + case 140 /* PropertySignature */: return spanInVariableDeclaration(node); - case 136 /* Parameter */: + case 138 /* Parameter */: return spanInParameterDeclaration(node); - case 211 /* FunctionDeclaration */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: - case 171 /* FunctionExpression */: - case 172 /* ArrowFunction */: + case 213 /* FunctionDeclaration */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: + case 173 /* FunctionExpression */: + case 174 /* ArrowFunction */: return spanInFunctionDeclaration(node); - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionBlock(node)) { return spanInFunctionBlock(node); } // Fall through - case 217 /* ModuleBlock */: + case 219 /* ModuleBlock */: return spanInBlock(node); - case 242 /* CatchClause */: + case 244 /* CatchClause */: return spanInBlock(node.block); - case 193 /* ExpressionStatement */: + case 195 /* ExpressionStatement */: // span on the expression return textSpan(node.expression); - case 202 /* ReturnStatement */: + case 204 /* ReturnStatement */: // span on return keyword and expression if present return textSpan(node.getChildAt(0), node.expression); - case 196 /* WhileStatement */: + case 198 /* WhileStatement */: // Span on while(...) return textSpan(node, ts.findNextToken(node.expression, node)); - case 195 /* DoStatement */: + case 197 /* DoStatement */: // span in statement of the do statement return spanInNode(node.statement); - case 208 /* DebuggerStatement */: + case 210 /* DebuggerStatement */: // span on debugger keyword return textSpan(node.getChildAt(0)); - case 194 /* IfStatement */: + case 196 /* IfStatement */: // set on if(..) span return textSpan(node, ts.findNextToken(node.expression, node)); - case 205 /* LabeledStatement */: + case 207 /* LabeledStatement */: // span in statement return spanInNode(node.statement); - case 201 /* BreakStatement */: - case 200 /* ContinueStatement */: + case 203 /* BreakStatement */: + case 202 /* ContinueStatement */: // On break or continue keyword and label if present return textSpan(node.getChildAt(0), node.label); - case 197 /* ForStatement */: + case 199 /* ForStatement */: return spanInForStatement(node); - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: // span on for (a in ...) return textSpan(node, ts.findNextToken(node.expression, node)); - case 204 /* SwitchStatement */: + case 206 /* SwitchStatement */: // span on switch(...) return textSpan(node, ts.findNextToken(node.expression, node)); - case 239 /* CaseClause */: - case 240 /* DefaultClause */: + case 241 /* CaseClause */: + case 242 /* DefaultClause */: // span in first statement of the clause return spanInNode(node.statements[0]); - case 207 /* TryStatement */: + case 209 /* TryStatement */: // span in try block return spanInBlock(node.tryBlock); - case 206 /* ThrowStatement */: + case 208 /* ThrowStatement */: // span in throw ... return textSpan(node, node.expression); - case 225 /* ExportAssignment */: + case 227 /* ExportAssignment */: // span on export = id return textSpan(node, node.expression); - case 219 /* ImportEqualsDeclaration */: + case 221 /* ImportEqualsDeclaration */: // import statement without including semicolon return textSpan(node, node.moduleReference); - case 220 /* ImportDeclaration */: + case 222 /* ImportDeclaration */: // import statement without including semicolon return textSpan(node, node.moduleSpecifier); - case 226 /* ExportDeclaration */: + case 228 /* ExportDeclaration */: // import statement without including semicolon return textSpan(node, node.moduleSpecifier); - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: // span on complete module if it is instantiated if (ts.getModuleInstanceState(node) !== 1 /* Instantiated */) { return undefined; } - case 212 /* ClassDeclaration */: - case 215 /* EnumDeclaration */: - case 245 /* EnumMember */: - case 166 /* CallExpression */: - case 167 /* NewExpression */: + case 214 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 247 /* EnumMember */: + case 168 /* CallExpression */: + case 169 /* NewExpression */: // span on complete node return textSpan(node); - case 203 /* WithStatement */: + case 205 /* WithStatement */: // span in statement return spanInNode(node.statement); // No breakpoint in interface, type alias - case 213 /* InterfaceDeclaration */: - case 214 /* TypeAliasDeclaration */: + case 215 /* InterfaceDeclaration */: + case 216 /* TypeAliasDeclaration */: return undefined; // Tokens: case 23 /* SemicolonToken */: @@ -48461,25 +49311,25 @@ var ts; return spanInOpenParenToken(node); case 18 /* CloseParenToken */: return spanInCloseParenToken(node); - case 53 /* ColonToken */: + case 54 /* ColonToken */: return spanInColonToken(node); case 27 /* GreaterThanToken */: case 25 /* LessThanToken */: return spanInGreaterThanOrLessThanToken(node); // Keywords: - case 102 /* WhileKeyword */: + case 104 /* WhileKeyword */: return spanInWhileKeyword(node); - case 78 /* ElseKeyword */: - case 70 /* CatchKeyword */: - case 83 /* FinallyKeyword */: + case 80 /* ElseKeyword */: + case 72 /* CatchKeyword */: + case 85 /* FinallyKeyword */: return spanInNextNode(node); default: // If this is name of property assignment, set breakpoint in the initializer - if (node.parent.kind === 243 /* PropertyAssignment */ && node.parent.name === node) { + if (node.parent.kind === 245 /* PropertyAssignment */ && node.parent.name === node) { return spanInNode(node.parent.initializer); } // Breakpoint in type assertion goes to its operand - if (node.parent.kind === 169 /* TypeAssertionExpression */ && node.parent.type === node) { + if (node.parent.kind === 171 /* TypeAssertionExpression */ && node.parent.type === node) { return spanInNode(node.parent.expression); } // return type of function go to previous token @@ -48492,12 +49342,12 @@ var ts; } function spanInVariableDeclaration(variableDeclaration) { // If declaration of for in statement, just set the span in parent - if (variableDeclaration.parent.parent.kind === 198 /* ForInStatement */ || - variableDeclaration.parent.parent.kind === 199 /* ForOfStatement */) { + if (variableDeclaration.parent.parent.kind === 200 /* ForInStatement */ || + variableDeclaration.parent.parent.kind === 201 /* ForOfStatement */) { return spanInNode(variableDeclaration.parent.parent); } - var isParentVariableStatement = variableDeclaration.parent.parent.kind === 191 /* VariableStatement */; - var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 197 /* ForStatement */ && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); + var isParentVariableStatement = variableDeclaration.parent.parent.kind === 193 /* VariableStatement */; + var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 199 /* ForStatement */ && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); var declarations = isParentVariableStatement ? variableDeclaration.parent.parent.declarationList.declarations : isDeclarationOfForStatement @@ -48551,7 +49401,7 @@ var ts; } function canFunctionHaveSpanInWholeDeclaration(functionDeclaration) { return !!(functionDeclaration.flags & 1 /* Export */) || - (functionDeclaration.parent.kind === 212 /* ClassDeclaration */ && functionDeclaration.kind !== 142 /* Constructor */); + (functionDeclaration.parent.kind === 214 /* ClassDeclaration */ && functionDeclaration.kind !== 144 /* Constructor */); } function spanInFunctionDeclaration(functionDeclaration) { // No breakpoints in the function signature @@ -48574,18 +49424,18 @@ var ts; } function spanInBlock(block) { switch (block.parent.kind) { - case 216 /* ModuleDeclaration */: + case 218 /* ModuleDeclaration */: if (ts.getModuleInstanceState(block.parent) !== 1 /* Instantiated */) { return undefined; } // Set on parent if on same line otherwise on first statement - case 196 /* WhileStatement */: - case 194 /* IfStatement */: - case 198 /* ForInStatement */: - case 199 /* ForOfStatement */: + case 198 /* WhileStatement */: + case 196 /* IfStatement */: + case 200 /* ForInStatement */: + case 201 /* ForOfStatement */: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); // Set span on previous token if it starts on same line otherwise on the first statement of the block - case 197 /* ForStatement */: + case 199 /* ForStatement */: return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]); } // Default action is to set on first statement @@ -48593,7 +49443,7 @@ var ts; } function spanInForStatement(forStatement) { if (forStatement.initializer) { - if (forStatement.initializer.kind === 210 /* VariableDeclarationList */) { + if (forStatement.initializer.kind === 212 /* VariableDeclarationList */) { var variableDeclarationList = forStatement.initializer; if (variableDeclarationList.declarations.length > 0) { return spanInNode(variableDeclarationList.declarations[0]); @@ -48613,13 +49463,13 @@ var ts; // Tokens: function spanInOpenBraceToken(node) { switch (node.parent.kind) { - case 215 /* EnumDeclaration */: + case 217 /* EnumDeclaration */: var enumDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); - case 212 /* ClassDeclaration */: + case 214 /* ClassDeclaration */: var classDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); - case 218 /* CaseBlock */: + case 220 /* CaseBlock */: return spanInNodeIfStartsOnSameLine(node.parent.parent, node.parent.clauses[0]); } // Default to parent node @@ -48627,25 +49477,25 @@ var ts; } function spanInCloseBraceToken(node) { switch (node.parent.kind) { - case 217 /* ModuleBlock */: + case 219 /* ModuleBlock */: // If this is not instantiated module block no bp span if (ts.getModuleInstanceState(node.parent.parent) !== 1 /* Instantiated */) { return undefined; } - case 215 /* EnumDeclaration */: - case 212 /* ClassDeclaration */: + case 217 /* EnumDeclaration */: + case 214 /* ClassDeclaration */: // Span on close brace token return textSpan(node); - case 190 /* Block */: + case 192 /* Block */: if (ts.isFunctionBlock(node.parent)) { // Span on close brace token return textSpan(node); } // fall through. - case 242 /* CatchClause */: + case 244 /* CatchClause */: return spanInNode(ts.lastOrUndefined(node.parent.statements)); ; - case 218 /* CaseBlock */: + case 220 /* CaseBlock */: // breakpoint in last statement of the last clause var caseBlock = node.parent; var lastClause = ts.lastOrUndefined(caseBlock.clauses); @@ -48659,7 +49509,7 @@ var ts; } } function spanInOpenParenToken(node) { - if (node.parent.kind === 195 /* DoStatement */) { + if (node.parent.kind === 197 /* DoStatement */) { // Go to while keyword and do action instead return spanInPreviousNode(node); } @@ -48669,17 +49519,17 @@ var ts; function spanInCloseParenToken(node) { // Is this close paren token of parameter list, set span in previous token switch (node.parent.kind) { - case 171 /* FunctionExpression */: - case 211 /* FunctionDeclaration */: - case 172 /* ArrowFunction */: - case 141 /* MethodDeclaration */: - case 140 /* MethodSignature */: - case 143 /* GetAccessor */: - case 144 /* SetAccessor */: - case 142 /* Constructor */: - case 196 /* WhileStatement */: - case 195 /* DoStatement */: - case 197 /* ForStatement */: + case 173 /* FunctionExpression */: + case 213 /* FunctionDeclaration */: + case 174 /* ArrowFunction */: + case 143 /* MethodDeclaration */: + case 142 /* MethodSignature */: + case 145 /* GetAccessor */: + case 146 /* SetAccessor */: + case 144 /* Constructor */: + case 198 /* WhileStatement */: + case 197 /* DoStatement */: + case 199 /* ForStatement */: return spanInPreviousNode(node); // Default to parent node default: @@ -48690,19 +49540,19 @@ var ts; } function spanInColonToken(node) { // Is this : specifying return annotation of the function declaration - if (ts.isFunctionLike(node.parent) || node.parent.kind === 243 /* PropertyAssignment */) { + if (ts.isFunctionLike(node.parent) || node.parent.kind === 245 /* PropertyAssignment */) { return spanInPreviousNode(node); } return spanInNode(node.parent); } function spanInGreaterThanOrLessThanToken(node) { - if (node.parent.kind === 169 /* TypeAssertionExpression */) { + if (node.parent.kind === 171 /* TypeAssertionExpression */) { return spanInNode(node.parent.expression); } return spanInNode(node.parent); } function spanInWhileKeyword(node) { - if (node.parent.kind === 195 /* DoStatement */) { + if (node.parent.kind === 197 /* DoStatement */) { // Set span on while expression return textSpan(node, ts.findNextToken(node.parent.expression, node.parent)); } @@ -49367,7 +50217,7 @@ var ts; var _this = this; return this.forwardJSONCall("getTSConfigFileInfo('" + fileName + "')", function () { var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - var result = ts.parseConfigFileText(fileName, text); + var result = ts.parseConfigFileTextToJson(fileName, text); if (result.error) { return { options: {}, @@ -49375,7 +50225,7 @@ var ts; errors: [realizeDiagnostic(result.error, '\r\n')] }; } - var configFile = ts.parseConfigFile(result.config, _this.host, ts.getDirectoryPath(ts.normalizeSlashes(fileName))); + var configFile = ts.parseJsonConfigFileContent(result.config, _this.host, ts.getDirectoryPath(ts.normalizeSlashes(fileName))); return { options: configFile.options, files: configFile.fileNames, From 798ffa763ddb0208d59f113c6cafd6da97a1c723 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 16 Oct 2015 12:36:51 -0700 Subject: [PATCH 13/25] Switched switch statement to if branches. Fixes #5229. --- src/compiler/checker.ts | 199 ++++++++++++++++++++-------------------- 1 file changed, 97 insertions(+), 102 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b13520cee2d..6382dfa99d9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8646,39 +8646,36 @@ namespace ts { */ function getEffectiveDecoratorFirstArgumentType(node: Node): Type { // The first argument to a decorator is its `target`. - switch (node.kind) { - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: - // For a class decorator, the `target` is the type of the class (e.g. the - // "static" or "constructor" side of the class) + if (node.kind === SyntaxKind.ClassDeclaration) { + // For a class decorator, the `target` is the type of the class (e.g. the + // "static" or "constructor" side of the class) + let classSymbol = getSymbolOfNode(node); + return getTypeOfSymbol(classSymbol); + } + + if (node.kind === SyntaxKind.Parameter) { + // For a parameter decorator, the `target` is the parent type of the + // parameter's containing method. + node = node.parent; + if (node.kind === SyntaxKind.Constructor) { let classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); - - case SyntaxKind.Parameter: - // For a parameter decorator, the `target` is the parent type of the - // parameter's containing method. - node = node.parent; - if (node.kind === SyntaxKind.Constructor) { - let classSymbol = getSymbolOfNode(node); - return getTypeOfSymbol(classSymbol); - } - - // fall-through - - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - // For a property or method decorator, the `target` is the - // "static"-side type of the parent of the member if the member is - // declared "static"; otherwise, it is the "instance"-side type of the - // parent of the member. - return getParentTypeOfClassElement(node); - - default: - Debug.fail("Unsupported decorator target."); - return unknownType; + } } + + if (node.kind === SyntaxKind.PropertyDeclaration || + node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.GetAccessor || + node.kind === SyntaxKind.SetAccessor) { + // For a property or method decorator, the `target` is the + // "static"-side type of the parent of the member if the member is + // declared "static"; otherwise, it is the "instance"-side type of the + // parent of the member. + return getParentTypeOfClassElement(node); + } + + Debug.fail("Unsupported decorator target."); + return unknownType; } /** @@ -8698,57 +8695,54 @@ namespace ts { */ function getEffectiveDecoratorSecondArgumentType(node: Node) { // The second argument to a decorator is its `propertyKey` - switch (node.kind) { - case SyntaxKind.ClassDeclaration: - Debug.fail("Class decorators should not have a second synthetic argument."); - return unknownType; - - case SyntaxKind.Parameter: - node = node.parent; - if (node.kind === SyntaxKind.Constructor) { - // For a constructor parameter decorator, the `propertyKey` will be `undefined`. - return anyType; - } + if (node.kind === SyntaxKind.ClassDeclaration) { + Debug.fail("Class decorators should not have a second synthetic argument."); + return unknownType; + } + + if (node.kind === SyntaxKind.Parameter) { + node = node.parent; + if (node.kind === SyntaxKind.Constructor) { + // For a constructor parameter decorator, the `propertyKey` will be `undefined`. + return anyType; + } // For a non-constructor parameter decorator, the `propertyKey` will be either // a string or a symbol, based on the name of the parameter's containing method. - - // fall-through - - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - // The `propertyKey` for a property or method decorator will be a - // string literal type if the member name is an identifier, number, or string; - // otherwise, if the member name is a computed property name it will - // be either string or symbol. - let element = node; - switch (element.name.kind) { - case SyntaxKind.Identifier: - case SyntaxKind.NumericLiteral: - case SyntaxKind.StringLiteral: - return getStringLiteralType(element.name); - - case SyntaxKind.ComputedPropertyName: - let nameType = checkComputedPropertyName(element.name); - if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) { - return nameType; - } - else { - return stringType; - } - - default: - Debug.fail("Unsupported property name."); - return unknownType; - } - - - default: - Debug.fail("Unsupported decorator target."); - return unknownType; } + + if (node.kind === SyntaxKind.PropertyDeclaration || + node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.GetAccessor || + node.kind === SyntaxKind.SetAccessor) { + // The `propertyKey` for a property or method decorator will be a + // string literal type if the member name is an identifier, number, or string; + // otherwise, if the member name is a computed property name it will + // be either string or symbol. + let element = node; + switch (element.name.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.NumericLiteral: + case SyntaxKind.StringLiteral: + return getStringLiteralType(element.name); + + case SyntaxKind.ComputedPropertyName: + let nameType = checkComputedPropertyName(element.name); + if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) { + return nameType; + } + else { + return stringType; + } + + default: + Debug.fail("Unsupported property name."); + return unknownType; + } + } + + Debug.fail("Unsupported decorator target."); + return unknownType; } /** @@ -8761,33 +8755,34 @@ namespace ts { function getEffectiveDecoratorThirdArgumentType(node: Node) { // The third argument to a decorator is either its `descriptor` for a method decorator // or its `parameterIndex` for a paramter decorator - switch (node.kind) { - case SyntaxKind.ClassDeclaration: - Debug.fail("Class decorators should not have a third synthetic argument."); - return unknownType; - - case SyntaxKind.Parameter: - // The `parameterIndex` for a parameter decorator is always a number - return numberType; - - case SyntaxKind.PropertyDeclaration: - Debug.fail("Property decorators should not have a third synthetic argument."); - return unknownType; - - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor` - // for the type of the member. - let propertyType = getTypeOfNode(node); - return createTypedPropertyDescriptorType(propertyType); - - default: - Debug.fail("Unsupported decorator target."); - return unknownType; + if (node.kind === SyntaxKind.ClassDeclaration) { + Debug.fail("Class decorators should not have a third synthetic argument."); + return unknownType; + } + + if (node.kind === SyntaxKind.Parameter) { + // The `parameterIndex` for a parameter decorator is always a number + return numberType; + } + + if (node.kind === SyntaxKind.PropertyDeclaration) { + Debug.fail("Property decorators should not have a third synthetic argument."); + return unknownType; + } + + if (node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.GetAccessor || + node.kind === SyntaxKind.SetAccessor) { + // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor` + // for the type of the member. + let propertyType = getTypeOfNode(node); + return createTypedPropertyDescriptorType(propertyType); } - } + Debug.fail("Unsupported decorator target."); + return unknownType; + } + /** * Returns the effective argument type for the provided argument to a decorator. */ From 81e784c01e02dfc647a561911a14e9007c34046c Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 16 Oct 2015 14:36:36 -0700 Subject: [PATCH 14/25] Fixed linter error --- src/compiler/checker.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6382dfa99d9..c0ede7db3a8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8652,7 +8652,7 @@ namespace ts { let classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); } - + if (node.kind === SyntaxKind.Parameter) { // For a parameter decorator, the `target` is the parent type of the // parameter's containing method. @@ -8662,7 +8662,7 @@ namespace ts { return getTypeOfSymbol(classSymbol); } } - + if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.GetAccessor || @@ -8699,7 +8699,7 @@ namespace ts { Debug.fail("Class decorators should not have a second synthetic argument."); return unknownType; } - + if (node.kind === SyntaxKind.Parameter) { node = node.parent; if (node.kind === SyntaxKind.Constructor) { @@ -8710,7 +8710,7 @@ namespace ts { // For a non-constructor parameter decorator, the `propertyKey` will be either // a string or a symbol, based on the name of the parameter's containing method. } - + if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.GetAccessor || @@ -8759,17 +8759,17 @@ namespace ts { Debug.fail("Class decorators should not have a third synthetic argument."); return unknownType; } - + if (node.kind === SyntaxKind.Parameter) { // The `parameterIndex` for a parameter decorator is always a number return numberType; } - + if (node.kind === SyntaxKind.PropertyDeclaration) { Debug.fail("Property decorators should not have a third synthetic argument."); return unknownType; } - + if (node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) { @@ -8782,7 +8782,7 @@ namespace ts { Debug.fail("Unsupported decorator target."); return unknownType; } - + /** * Returns the effective argument type for the provided argument to a decorator. */ From 8b8d33d8b8048b2bc31408f66086f9bab51aa740 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 16 Oct 2015 16:29:11 -0700 Subject: [PATCH 15/25] Fix comments --- .../reference/augmentedTypesClass2.errors.txt | 4 ++-- .../reference/augmentedTypesClass2.js | 4 ++-- .../augmentedTypesInterface.errors.txt | 4 ++-- .../reference/augmentedTypesInterface.js | 4 ++-- .../classAndInterfaceWithSameName.errors.txt | 4 ++-- .../classAndInterfaceWithSameName.js | 4 ++-- ...ifiersAcrossContainerBoundaries.errors.txt | 2 +- ...ateIdentifiersAcrossContainerBoundaries.js | 4 ++-- .../reference/interfaceClassMerging2.js | 4 ++-- .../reference/interfaceClassMerging2.symbols | 12 +++++------ .../reference/interfaceClassMerging2.types | 20 +++++++++---------- .../reference/mergedClassInterface.js | 12 +++++------ .../reference/mergedClassInterface.symbols | 8 ++++---- .../reference/mergedClassInterface.types | 8 ++++---- .../reference/nameCollisions.errors.txt | 4 ++-- tests/baselines/reference/nameCollisions.js | 6 +++--- tests/cases/compiler/augmentedTypesClass2.ts | 4 ++-- .../cases/compiler/augmentedTypesInterface.ts | 4 ++-- ...ateIdentifiersAcrossContainerBoundaries.ts | 2 +- .../cases/compiler/interfaceClassMerging2.ts | 2 +- tests/cases/compiler/nameCollisions.ts | 4 ++-- .../classAndInterfaceWithSameName.ts | 4 ++-- .../classDeclarations/mergedClassInterface.ts | 8 ++++---- 23 files changed, 66 insertions(+), 66 deletions(-) diff --git a/tests/baselines/reference/augmentedTypesClass2.errors.txt b/tests/baselines/reference/augmentedTypesClass2.errors.txt index 7a203f06e90..a27189cf2c2 100644 --- a/tests/baselines/reference/augmentedTypesClass2.errors.txt +++ b/tests/baselines/reference/augmentedTypesClass2.errors.txt @@ -6,13 +6,13 @@ tests/cases/compiler/augmentedTypesClass2.ts(21,6): error TS2300: Duplicate iden // Checking class with other things in type space not value space // class then interface - class c11 { // error + class c11 { foo() { return 1; } } - interface c11 { // error + interface c11 { bar(): void; } diff --git a/tests/baselines/reference/augmentedTypesClass2.js b/tests/baselines/reference/augmentedTypesClass2.js index f75c08a5920..4a919913ce0 100644 --- a/tests/baselines/reference/augmentedTypesClass2.js +++ b/tests/baselines/reference/augmentedTypesClass2.js @@ -2,13 +2,13 @@ // Checking class with other things in type space not value space // class then interface -class c11 { // error +class c11 { foo() { return 1; } } -interface c11 { // error +interface c11 { bar(): void; } diff --git a/tests/baselines/reference/augmentedTypesInterface.errors.txt b/tests/baselines/reference/augmentedTypesInterface.errors.txt index 534cba43ba1..51092e1d27f 100644 --- a/tests/baselines/reference/augmentedTypesInterface.errors.txt +++ b/tests/baselines/reference/augmentedTypesInterface.errors.txt @@ -14,11 +14,11 @@ tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate i } // interface then class - interface i2 { // error + interface i2 { foo(): void; } - class i2 { // error + class i2 { bar() { return 1; } diff --git a/tests/baselines/reference/augmentedTypesInterface.js b/tests/baselines/reference/augmentedTypesInterface.js index e28864fd547..330fc035a9e 100644 --- a/tests/baselines/reference/augmentedTypesInterface.js +++ b/tests/baselines/reference/augmentedTypesInterface.js @@ -10,11 +10,11 @@ interface i { } // interface then class -interface i2 { // error +interface i2 { foo(): void; } -class i2 { // error +class i2 { bar() { return 1; } diff --git a/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt b/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt index 62f1e6c71f7..f1f26f50f3e 100644 --- a/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt +++ b/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt @@ -8,7 +8,7 @@ tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName. class C { foo: string; } ~~~ !!! error TS2300: Duplicate identifier 'foo'. - interface C { foo: string; } // error + interface C { foo: string; } ~~~ !!! error TS2300: Duplicate identifier 'foo'. @@ -19,7 +19,7 @@ tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName. !!! error TS2300: Duplicate identifier 'bar'. } - interface D { // error + interface D { bar: string; ~~~ !!! error TS2300: Duplicate identifier 'bar'. diff --git a/tests/baselines/reference/classAndInterfaceWithSameName.js b/tests/baselines/reference/classAndInterfaceWithSameName.js index 09886e34bc8..bca0c96892c 100644 --- a/tests/baselines/reference/classAndInterfaceWithSameName.js +++ b/tests/baselines/reference/classAndInterfaceWithSameName.js @@ -1,13 +1,13 @@ //// [classAndInterfaceWithSameName.ts] class C { foo: string; } -interface C { foo: string; } // error +interface C { foo: string; } module M { class D { bar: string; } - interface D { // error + interface D { bar: string; } } diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt index ed4c23bdd60..684c123ebd7 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt +++ b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt @@ -9,7 +9,7 @@ tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(41,16): er export interface I { } } module M { - export class I { } // error + export class I { } } module M { diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js index 944ef4e3d5f..ad96e55a507 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js +++ b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js @@ -3,7 +3,7 @@ module M { export interface I { } } module M { - export class I { } // error + export class I { } } module M { @@ -60,7 +60,7 @@ var M; } return I; })(); - M.I = I; // error + M.I = I; })(M || (M = {})); var M; (function (M) { diff --git a/tests/baselines/reference/interfaceClassMerging2.js b/tests/baselines/reference/interfaceClassMerging2.js index 66146e29684..0b40067640c 100644 --- a/tests/baselines/reference/interfaceClassMerging2.js +++ b/tests/baselines/reference/interfaceClassMerging2.js @@ -28,7 +28,7 @@ class Bar extends Foo { var bar = new Bar(); -bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod(); var foo = new Foo(); @@ -61,6 +61,6 @@ var Bar = (function (_super) { return Bar; })(Foo); var bar = new Bar(); -bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod(); var foo = new Foo(); foo = bar; diff --git a/tests/baselines/reference/interfaceClassMerging2.symbols b/tests/baselines/reference/interfaceClassMerging2.symbols index 98949cc5461..290b49fdb3d 100644 --- a/tests/baselines/reference/interfaceClassMerging2.symbols +++ b/tests/baselines/reference/interfaceClassMerging2.symbols @@ -54,13 +54,13 @@ var bar = new Bar(); >bar : Symbol(bar, Decl(interfaceClassMerging2.ts, 28, 3)) >Bar : Symbol(Bar, Decl(interfaceClassMerging2.ts, 11, 1), Decl(interfaceClassMerging2.ts, 17, 1)) -bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); ->bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) ->bar.classFooMethod().interfaceFooMethod().classBarMethod : Symbol(Bar.classBarMethod, Decl(interfaceClassMerging2.ts, 20, 27)) ->bar.classFooMethod().interfaceFooMethod : Symbol(Foo.interfaceFooMethod, Decl(interfaceClassMerging2.ts, 0, 15)) ->bar.classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) +bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +>bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) +>bar.interfaceBarMethod().interfaceFooMethod().classBarMethod : Symbol(Bar.classBarMethod, Decl(interfaceClassMerging2.ts, 20, 27)) +>bar.interfaceBarMethod().interfaceFooMethod : Symbol(Foo.interfaceFooMethod, Decl(interfaceClassMerging2.ts, 0, 15)) +>bar.interfaceBarMethod : Symbol(Bar.interfaceBarMethod, Decl(interfaceClassMerging2.ts, 14, 15)) >bar : Symbol(bar, Decl(interfaceClassMerging2.ts, 28, 3)) ->classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) +>interfaceBarMethod : Symbol(Bar.interfaceBarMethod, Decl(interfaceClassMerging2.ts, 14, 15)) >interfaceFooMethod : Symbol(Foo.interfaceFooMethod, Decl(interfaceClassMerging2.ts, 0, 15)) >classBarMethod : Symbol(Bar.classBarMethod, Decl(interfaceClassMerging2.ts, 20, 27)) >classFooMethod : Symbol(Foo.classFooMethod, Decl(interfaceClassMerging2.ts, 6, 27)) diff --git a/tests/baselines/reference/interfaceClassMerging2.types b/tests/baselines/reference/interfaceClassMerging2.types index 127777cb70c..68da86b8821 100644 --- a/tests/baselines/reference/interfaceClassMerging2.types +++ b/tests/baselines/reference/interfaceClassMerging2.types @@ -55,17 +55,17 @@ var bar = new Bar(); >new Bar() : Bar >Bar : typeof Bar -bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); ->bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod() : Bar ->bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod : () => Bar ->bar.classFooMethod().interfaceFooMethod().classBarMethod() : Bar ->bar.classFooMethod().interfaceFooMethod().classBarMethod : () => Bar ->bar.classFooMethod().interfaceFooMethod() : Bar ->bar.classFooMethod().interfaceFooMethod : () => Bar ->bar.classFooMethod() : Bar ->bar.classFooMethod : () => Bar +bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +>bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod() : Bar +>bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod : () => Bar +>bar.interfaceBarMethod().interfaceFooMethod().classBarMethod() : Bar +>bar.interfaceBarMethod().interfaceFooMethod().classBarMethod : () => Bar +>bar.interfaceBarMethod().interfaceFooMethod() : Bar +>bar.interfaceBarMethod().interfaceFooMethod : () => Bar +>bar.interfaceBarMethod() : Bar +>bar.interfaceBarMethod : () => Bar >bar : Bar ->classFooMethod : () => Bar +>interfaceBarMethod : () => Bar >interfaceFooMethod : () => Bar >classBarMethod : () => Bar >classFooMethod : () => Bar diff --git a/tests/baselines/reference/mergedClassInterface.js b/tests/baselines/reference/mergedClassInterface.js index 7176255655d..64b52c23713 100644 --- a/tests/baselines/reference/mergedClassInterface.js +++ b/tests/baselines/reference/mergedClassInterface.js @@ -11,13 +11,13 @@ interface C2 { } declare class C2 { } -class C3 { } // error -- cannot merge non-ambient class and interface +class C3 { } -interface C3 { } // error -- cannot merge non-ambient class and interface +interface C3 { } -interface C4 { } // error -- cannot merge non-ambient class and interface +interface C4 { } -class C4 { } // error -- cannot merge non-ambient class and interface +class C4 { } interface C5 { x1: number; @@ -59,12 +59,12 @@ var C3 = (function () { function C3() { } return C3; -})(); // error -- cannot merge non-ambient class and interface +})(); var C4 = (function () { function C4() { } return C4; -})(); // error -- cannot merge non-ambient class and interface +})(); // checks if properties actually were merged var c5; c5.x1; diff --git a/tests/baselines/reference/mergedClassInterface.symbols b/tests/baselines/reference/mergedClassInterface.symbols index 9e886eaa4d8..1c452851780 100644 --- a/tests/baselines/reference/mergedClassInterface.symbols +++ b/tests/baselines/reference/mergedClassInterface.symbols @@ -13,16 +13,16 @@ interface C2 { } declare class C2 { } >C2 : Symbol(C2, Decl(file1.ts, 4, 16), Decl(file1.ts, 6, 16)) -class C3 { } // error -- cannot merge non-ambient class and interface +class C3 { } >C3 : Symbol(C3, Decl(file1.ts, 8, 20), Decl(file1.ts, 10, 12)) -interface C3 { } // error -- cannot merge non-ambient class and interface +interface C3 { } >C3 : Symbol(C3, Decl(file1.ts, 8, 20), Decl(file1.ts, 10, 12)) -interface C4 { } // error -- cannot merge non-ambient class and interface +interface C4 { } >C4 : Symbol(C4, Decl(file1.ts, 12, 16), Decl(file1.ts, 14, 16)) -class C4 { } // error -- cannot merge non-ambient class and interface +class C4 { } >C4 : Symbol(C4, Decl(file1.ts, 12, 16), Decl(file1.ts, 14, 16)) interface C5 { diff --git a/tests/baselines/reference/mergedClassInterface.types b/tests/baselines/reference/mergedClassInterface.types index 0e75434a5b1..4c3a6cca6a9 100644 --- a/tests/baselines/reference/mergedClassInterface.types +++ b/tests/baselines/reference/mergedClassInterface.types @@ -13,16 +13,16 @@ interface C2 { } declare class C2 { } >C2 : C2 -class C3 { } // error -- cannot merge non-ambient class and interface +class C3 { } >C3 : C3 -interface C3 { } // error -- cannot merge non-ambient class and interface +interface C3 { } >C3 : C3 -interface C4 { } // error -- cannot merge non-ambient class and interface +interface C4 { } >C4 : C4 -class C4 { } // error -- cannot merge non-ambient class and interface +class C4 { } >C4 : C4 interface C5 { diff --git a/tests/baselines/reference/nameCollisions.errors.txt b/tests/baselines/reference/nameCollisions.errors.txt index 5977b039847..e3c1b691371 100644 --- a/tests/baselines/reference/nameCollisions.errors.txt +++ b/tests/baselines/reference/nameCollisions.errors.txt @@ -82,8 +82,8 @@ tests/cases/compiler/nameCollisions.ts(37,11): error TS2300: Duplicate identifie interface fi { } // ok class cli { } - interface cli { } // error + interface cli { } interface cli2 { } - class cli2 { } // error + class cli2 { } } \ No newline at end of file diff --git a/tests/baselines/reference/nameCollisions.js b/tests/baselines/reference/nameCollisions.js index 2cfaba94993..96ae2e9838b 100644 --- a/tests/baselines/reference/nameCollisions.js +++ b/tests/baselines/reference/nameCollisions.js @@ -41,10 +41,10 @@ module T { interface fi { } // ok class cli { } - interface cli { } // error + interface cli { } interface cli2 { } - class cli2 { } // error + class cli2 { } } //// [nameCollisions.js] @@ -102,5 +102,5 @@ var T; function cli2() { } return cli2; - })(); // error + })(); })(T || (T = {})); diff --git a/tests/cases/compiler/augmentedTypesClass2.ts b/tests/cases/compiler/augmentedTypesClass2.ts index c6d64e2bf82..b3be1378fb8 100644 --- a/tests/cases/compiler/augmentedTypesClass2.ts +++ b/tests/cases/compiler/augmentedTypesClass2.ts @@ -1,13 +1,13 @@ // Checking class with other things in type space not value space // class then interface -class c11 { // error +class c11 { foo() { return 1; } } -interface c11 { // error +interface c11 { bar(): void; } diff --git a/tests/cases/compiler/augmentedTypesInterface.ts b/tests/cases/compiler/augmentedTypesInterface.ts index 72c85d6619d..7a51a21736f 100644 --- a/tests/cases/compiler/augmentedTypesInterface.ts +++ b/tests/cases/compiler/augmentedTypesInterface.ts @@ -9,11 +9,11 @@ interface i { } // interface then class -interface i2 { // error +interface i2 { foo(): void; } -class i2 { // error +class i2 { bar() { return 1; } diff --git a/tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts b/tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts index e62dc5c7f97..93d69444362 100644 --- a/tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts +++ b/tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts @@ -2,7 +2,7 @@ module M { export interface I { } } module M { - export class I { } // error + export class I { } } module M { diff --git a/tests/cases/compiler/interfaceClassMerging2.ts b/tests/cases/compiler/interfaceClassMerging2.ts index cd32a93c988..b214dc1e793 100644 --- a/tests/cases/compiler/interfaceClassMerging2.ts +++ b/tests/cases/compiler/interfaceClassMerging2.ts @@ -27,7 +27,7 @@ class Bar extends Foo { var bar = new Bar(); -bar.classFooMethod().interfaceFooMethod().classBarMethod().classFooMethod(); +bar.interfaceBarMethod().interfaceFooMethod().classBarMethod().classFooMethod(); var foo = new Foo(); diff --git a/tests/cases/compiler/nameCollisions.ts b/tests/cases/compiler/nameCollisions.ts index 25b3efae26f..90b2967fa5f 100644 --- a/tests/cases/compiler/nameCollisions.ts +++ b/tests/cases/compiler/nameCollisions.ts @@ -40,8 +40,8 @@ module T { interface fi { } // ok class cli { } - interface cli { } // error + interface cli { } interface cli2 { } - class cli2 { } // error + class cli2 { } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts b/tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts index 314c1e2c8f6..27ea77644a6 100644 --- a/tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts +++ b/tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts @@ -1,12 +1,12 @@ class C { foo: string; } -interface C { foo: string; } // error +interface C { foo: string; } module M { class D { bar: string; } - interface D { // error + interface D { bar: string; } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts b/tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts index 29400c63808..d64a0df3661 100644 --- a/tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts +++ b/tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts @@ -10,13 +10,13 @@ interface C2 { } declare class C2 { } -class C3 { } // error -- cannot merge non-ambient class and interface +class C3 { } -interface C3 { } // error -- cannot merge non-ambient class and interface +interface C3 { } -interface C4 { } // error -- cannot merge non-ambient class and interface +interface C4 { } -class C4 { } // error -- cannot merge non-ambient class and interface +class C4 { } interface C5 { x1: number; From 952ea0f82bc70ee60ba0e204b84f6c844c2cb46c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Sat, 17 Oct 2015 11:38:55 -0700 Subject: [PATCH 16/25] Add instructions on how to debug tests --- CONTRIBUTING.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2865280f44..a95cb4d8e33 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,12 +47,27 @@ e.g. to run all compiler baseline tests: jake runtests tests=compiler ``` -or to run specifc test: `tests\cases\compiler\2dArrays.ts` +or to run a specific test: `tests\cases\compiler\2dArrays.ts` ```Shell jake runtests tests=2dArrays ``` +## Debugging the tests + +To debug the tests, invoke the runtests-browser using jake. +You will probably only want to debug one test at a time: + +```Shell +jake runtests-browser tests=2dArrays +``` + +You can specify which browser to use for debugging. Currently Chrome and IE are supported: + +```Shell +jake runtests-browser tests=2dArrays browser=chrome +``` + ## Adding a Test To add a new testcase, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. From 0bd50ca08c3990c5cb4dfc8e38b2e432241266d9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 17 Oct 2015 14:35:28 -0700 Subject: [PATCH 17/25] extract 'convertCompilerOptionsFromJson' to separate function --- src/compiler/commandLineParser.ts | 100 ++++++++++++++++-------------- src/compiler/types.ts | 2 +- 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index acf0474b7bf..95583a19038 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -410,63 +410,19 @@ namespace ts { /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse + * @param host Instance of ParseConfigHost used to enumerate files in folder. * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine { - let errors: Diagnostic[] = []; + let { options, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath); return { - options: getCompilerOptions(), + options, fileNames: getFileNames(), errors }; - function getCompilerOptions(): CompilerOptions { - let options: CompilerOptions = {}; - let optionNameMap: Map = {}; - forEach(optionDeclarations, option => { - optionNameMap[option.name] = option; - }); - let jsonOptions = json["compilerOptions"]; - if (jsonOptions) { - for (let id in jsonOptions) { - if (hasProperty(optionNameMap, id)) { - let opt = optionNameMap[id]; - let optType = opt.type; - let value = jsonOptions[id]; - let expectedType = typeof optType === "string" ? optType : "string"; - if (typeof value === expectedType) { - if (typeof optType !== "string") { - let key = value.toLowerCase(); - if (hasProperty(optType, key)) { - value = optType[key]; - } - else { - errors.push(createCompilerDiagnostic((opt).error)); - value = 0; - } - } - if (opt.isFilePath) { - value = normalizePath(combinePaths(basePath, value)); - if (value === "") { - value = "."; - } - } - options[opt.name] = value; - } - else { - errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); - } - } - else { - errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id)); - } - } - } - return options; - } - function getFileNames(): string[] { let fileNames: string[] = []; if (hasProperty(json, "files")) { @@ -501,4 +457,54 @@ namespace ts { return fileNames; } } + + export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string): { options: CompilerOptions, errors: Diagnostic[] } { + let options: CompilerOptions = {}; + let optionNameMap: Map = {}; + let errors: Diagnostic[] = []; + + if (!jsonOptions) { + return { options, errors }; + } + + forEach(optionDeclarations, option => { + optionNameMap[option.name] = option; + }); + + for (let id in jsonOptions) { + if (hasProperty(optionNameMap, id)) { + let opt = optionNameMap[id]; + let optType = opt.type; + let value = jsonOptions[id]; + let expectedType = typeof optType === "string" ? optType : "string"; + if (typeof value === expectedType) { + if (typeof optType !== "string") { + let key = value.toLowerCase(); + if (hasProperty(optType, key)) { + value = optType[key]; + } + else { + errors.push(createCompilerDiagnostic((opt).error)); + value = 0; + } + } + if (opt.isFilePath) { + value = normalizePath(combinePaths(basePath, value)); + if (value === "") { + value = "."; + } + } + options[opt.name] = value; + } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); + } + } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Unknown_compiler_option_0, id)); + } + } + + return { options, errors }; + } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c44c6ad2cc0..2818ef04a48 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1305,7 +1305,7 @@ namespace ts { getCurrentDirectory(): string; } - export interface ParseConfigHost extends ModuleResolutionHost { + export interface ParseConfigHost { readDirectory(rootDir: string, extension: string, exclude: string[]): string[]; } From 1c4a1169f2b4f449852c701127883da7b7fa4245 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Sun, 18 Oct 2015 07:35:56 -0700 Subject: [PATCH 18/25] Add debug=true option also --- CONTRIBUTING.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a95cb4d8e33..53860e44df4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,6 +68,11 @@ You can specify which browser to use for debugging. Currently Chrome and IE are jake runtests-browser tests=2dArrays browser=chrome ``` +You can debug with VS Code or Node instead with `jake runtests debug=true`: + +```Shell +jake runtests tests=2dArrays debug=true +``` ## Adding a Test To add a new testcase, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. From 72d6ec0667a78e67c9c06c594ab34c262a117a68 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Sun, 18 Oct 2015 07:39:17 -0700 Subject: [PATCH 19/25] Add missing newline after runtests/debug --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53860e44df4..51b232712e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -73,6 +73,7 @@ You can debug with VS Code or Node instead with `jake runtests debug=true`: ```Shell jake runtests tests=2dArrays debug=true ``` + ## Adding a Test To add a new testcase, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. From 14ea332d9405740f6e2b1cac1a618c7aa6a9531d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 18 Oct 2015 16:34:02 -0700 Subject: [PATCH 20/25] Updated test options in 'CONTRIBUTING.md'. --- CONTRIBUTING.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 51b232712e6..9010b14311f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,17 +1,21 @@ ## Contributing bug fixes + TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved ("Milestone == Community") by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort. ## Contributing features + Features (things that add new or improved functionality to TypeScript) may be accepted, but will need to first be approved (marked as "Milestone == Community" by a TypeScript coordinator with the message "Approved") in the suggestion issue. Features with language design impact, or that are adequately satisfied with external tools, will not be accepted. Design changes will not be accepted at this time. If you have a design change proposal, please log a suggestion issue. ## Legal + You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright. Please submit a Contributor License Agreement (CLA) before submitting a pull request. You may visit https://cla.microsoft.com to sign digitally. Alternatively, download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to . Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. ## Housekeeping + Your pull request should: * Include a description of what your change intends to do @@ -75,14 +79,15 @@ jake runtests tests=2dArrays debug=true ``` ## Adding a Test + To add a new testcase, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. These files support metadata tags in the format `// @metaDataName: value`. The supported names and values are: -* `comments`, `sourcemap`, `noimplicitany`, `declaration`: true or false (corresponds to the compiler command-line options of the same name) -* `target`: ES3 or ES5 (same as compiler) -* `out`, outDir: path (same as compiler) -* `module`: local, commonjs, or amd (local corresponds to not passing any compiler --module flag) +* `comments`, `sourcemap`, `noimplicitany`, `declaration`: `true` or `false` (corresponds to the compiler command-line options of the same name) +* `target`: `ES3`, `ES5`, `ES6`, `ES2015`, or `ES7` (same as compiler) +* `outFile`, `out`, `outDir`: path (same as compiler) +* `module`: `local`, `commonjs`, or `amd`, `umd`, `system`, `es6` (local corresponds to not passing any compiler `--module` flag) * `fileName`: path * These tags delimit sections of a file to be used as separate compilation units. They are useful for tests relating to modules. See below for examples. @@ -107,6 +112,7 @@ var x = g(); One can also write a project test, but it is slightly more involved. ## Managing the Baselines + Compiler testcases generate baselines that track the emitted `.js`, the errors produced by the compiler, and the type of each expression in the file. Additionally, some testcases opt in to baselining the source map output. When a change in the baselines is detected, the test will fail. To inspect changes vs the expected baselines, use @@ -123,4 +129,4 @@ jake baseline-accept to establish the new baselines as the desired behavior. This will change the files in `tests\baselines\reference`, which should be included as part of your commit. It's important to carefully validate changes in the baselines. -**Note** that baseline-accept should only be run after a full test run! Accepting baselines after running a subset of tests will delete baseline files for the tests that didn't run. +**Note** that `baseline-accept` should only be run after a full test run! Accepting baselines after running a subset of tests will delete baseline files for the tests that didn't run. From f10c7cc154cb5b62a9368790e30d65b9a2bcfc3d Mon Sep 17 00:00:00 2001 From: John Vilk Date: Sun, 18 Oct 2015 20:05:30 -0400 Subject: [PATCH 21/25] Change ArrayBuffer.isView declaration to type guard for ArrayBufferView. Also adds a test that checks that `ArrayBuffer.isView` appropriately narrows its argument to `ArrayBufferView`. Fixes #5308. --- src/lib/core.d.ts | 2 +- .../reference/arrayBufferIsViewNarrowsType.js | 13 +++++++++++++ .../arrayBufferIsViewNarrowsType.symbols | 17 +++++++++++++++++ .../arrayBufferIsViewNarrowsType.types | 18 ++++++++++++++++++ .../compiler/arrayBufferIsViewNarrowsType.ts | 5 +++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/arrayBufferIsViewNarrowsType.js create mode 100644 tests/baselines/reference/arrayBufferIsViewNarrowsType.symbols create mode 100644 tests/baselines/reference/arrayBufferIsViewNarrowsType.types create mode 100644 tests/cases/compiler/arrayBufferIsViewNarrowsType.ts diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 7259ff5081c..12df449931e 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1210,7 +1210,7 @@ interface ArrayBuffer { interface ArrayBufferConstructor { prototype: ArrayBuffer; new (byteLength: number): ArrayBuffer; - isView(arg: any): boolean; + isView(arg: any): arg is ArrayBufferView; } declare var ArrayBuffer: ArrayBufferConstructor; diff --git a/tests/baselines/reference/arrayBufferIsViewNarrowsType.js b/tests/baselines/reference/arrayBufferIsViewNarrowsType.js new file mode 100644 index 00000000000..fcda4d5976b --- /dev/null +++ b/tests/baselines/reference/arrayBufferIsViewNarrowsType.js @@ -0,0 +1,13 @@ +//// [arrayBufferIsViewNarrowsType.ts] +var obj: Object; +if (ArrayBuffer.isView(obj)) { + // isView should be a guard that narrows type to ArrayBufferView. + var ab: ArrayBufferView = obj; +} + +//// [arrayBufferIsViewNarrowsType.js] +var obj; +if (ArrayBuffer.isView(obj)) { + // isView should be a guard that narrows type to ArrayBufferView. + var ab = obj; +} diff --git a/tests/baselines/reference/arrayBufferIsViewNarrowsType.symbols b/tests/baselines/reference/arrayBufferIsViewNarrowsType.symbols new file mode 100644 index 00000000000..eb7ffe7479e --- /dev/null +++ b/tests/baselines/reference/arrayBufferIsViewNarrowsType.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/arrayBufferIsViewNarrowsType.ts === +var obj: Object; +>obj : Symbol(obj, Decl(arrayBufferIsViewNarrowsType.ts, 0, 3)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +if (ArrayBuffer.isView(obj)) { +>ArrayBuffer.isView : Symbol(ArrayBufferConstructor.isView, Decl(lib.d.ts, --, --)) +>ArrayBuffer : Symbol(ArrayBuffer, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>isView : Symbol(ArrayBufferConstructor.isView, Decl(lib.d.ts, --, --)) +>obj : Symbol(obj, Decl(arrayBufferIsViewNarrowsType.ts, 0, 3)) + + // isView should be a guard that narrows type to ArrayBufferView. + var ab: ArrayBufferView = obj; +>ab : Symbol(ab, Decl(arrayBufferIsViewNarrowsType.ts, 3, 7)) +>ArrayBufferView : Symbol(ArrayBufferView, Decl(lib.d.ts, --, --)) +>obj : Symbol(obj, Decl(arrayBufferIsViewNarrowsType.ts, 0, 3)) +} diff --git a/tests/baselines/reference/arrayBufferIsViewNarrowsType.types b/tests/baselines/reference/arrayBufferIsViewNarrowsType.types new file mode 100644 index 00000000000..129b7d601d8 --- /dev/null +++ b/tests/baselines/reference/arrayBufferIsViewNarrowsType.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/arrayBufferIsViewNarrowsType.ts === +var obj: Object; +>obj : Object +>Object : Object + +if (ArrayBuffer.isView(obj)) { +>ArrayBuffer.isView(obj) : boolean +>ArrayBuffer.isView : (arg: any) => arg is ArrayBufferView +>ArrayBuffer : ArrayBufferConstructor +>isView : (arg: any) => arg is ArrayBufferView +>obj : Object + + // isView should be a guard that narrows type to ArrayBufferView. + var ab: ArrayBufferView = obj; +>ab : ArrayBufferView +>ArrayBufferView : ArrayBufferView +>obj : ArrayBufferView +} diff --git a/tests/cases/compiler/arrayBufferIsViewNarrowsType.ts b/tests/cases/compiler/arrayBufferIsViewNarrowsType.ts new file mode 100644 index 00000000000..ba653408c20 --- /dev/null +++ b/tests/cases/compiler/arrayBufferIsViewNarrowsType.ts @@ -0,0 +1,5 @@ +var obj: Object; +if (ArrayBuffer.isView(obj)) { + // isView should be a guard that narrows type to ArrayBufferView. + var ab: ArrayBufferView = obj; +} \ No newline at end of file From e2c858fee625b728d2c809111dd7ddf0059208d2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 18 Oct 2015 19:07:57 -0700 Subject: [PATCH 22/25] Minor fixups. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9010b14311f..5c45580ff55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,7 +87,7 @@ These files support metadata tags in the format `// @metaDataName: value`. The * `comments`, `sourcemap`, `noimplicitany`, `declaration`: `true` or `false` (corresponds to the compiler command-line options of the same name) * `target`: `ES3`, `ES5`, `ES6`, `ES2015`, or `ES7` (same as compiler) * `outFile`, `out`, `outDir`: path (same as compiler) -* `module`: `local`, `commonjs`, or `amd`, `umd`, `system`, `es6` (local corresponds to not passing any compiler `--module` flag) +* `module`: `local`, `commonjs`, or `amd`, `umd`, `system`, `es6` (`local` corresponds to not passing any compiler `--module` flag) * `fileName`: path * These tags delimit sections of a file to be used as separate compilation units. They are useful for tests relating to modules. See below for examples. From 9fa268a44a527560fd2f096ab9e043e1375435e6 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 19 Oct 2015 10:15:59 -0700 Subject: [PATCH 23/25] addressed PR feedback --- src/compiler/commandLineParser.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 95583a19038..0c561ab06d8 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -460,16 +460,13 @@ namespace ts { export function convertCompilerOptionsFromJson(jsonOptions: any, basePath: string): { options: CompilerOptions, errors: Diagnostic[] } { let options: CompilerOptions = {}; - let optionNameMap: Map = {}; let errors: Diagnostic[] = []; if (!jsonOptions) { return { options, errors }; } - forEach(optionDeclarations, option => { - optionNameMap[option.name] = option; - }); + let optionNameMap = arrayToMap(optionDeclarations, opt => opt.name); for (let id in jsonOptions) { if (hasProperty(optionNameMap, id)) { From 174f8c3e6ef4f13b912e393cc03a0735454e6488 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 19 Oct 2015 11:49:21 -0700 Subject: [PATCH 24/25] Fixups. --- CONTRIBUTING.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5c45580ff55..b3588e7c601 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,8 @@ Your pull request should: * To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration ## Running the Tests -To run all tests, invoke the runtests target using jake: + +To run all tests, invoke the `runtests` target using jake: ```Shell jake runtests @@ -59,7 +60,7 @@ jake runtests tests=2dArrays ## Debugging the tests -To debug the tests, invoke the runtests-browser using jake. +To debug the tests, invoke the `runtests-browser` task from jake. You will probably only want to debug one test at a time: ```Shell @@ -80,7 +81,7 @@ jake runtests tests=2dArrays debug=true ## Adding a Test -To add a new testcase, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. +To add a new test case, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. These files support metadata tags in the format `// @metaDataName: value`. The supported names and values are: From 67d43ad75f1258254b452e27e7f28b9be592a750 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 19 Oct 2015 14:22:00 -0700 Subject: [PATCH 25/25] Just say all compiler options are supported. --- CONTRIBUTING.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b3588e7c601..2e2c28590c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,14 +83,11 @@ jake runtests tests=2dArrays debug=true To add a new test case, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making. -These files support metadata tags in the format `// @metaDataName: value`. The supported names and values are: - -* `comments`, `sourcemap`, `noimplicitany`, `declaration`: `true` or `false` (corresponds to the compiler command-line options of the same name) -* `target`: `ES3`, `ES5`, `ES6`, `ES2015`, or `ES7` (same as compiler) -* `outFile`, `out`, `outDir`: path (same as compiler) -* `module`: `local`, `commonjs`, or `amd`, `umd`, `system`, `es6` (`local` corresponds to not passing any compiler `--module` flag) -* `fileName`: path - * These tags delimit sections of a file to be used as separate compilation units. They are useful for tests relating to modules. See below for examples. +These files support metadata tags in the format `// @metaDataName: value`. +The supported names and values are the same as those supported in the compiler itself, with the addition of the `fileName` flag. +`fileName` tags delimit sections of a file to be used as separate compilation units. +They are useful for tests relating to modules. +See below for examples. **Note** that if you have a test corresponding to a specific spec compliance item, you can place it in `tests\cases\conformance` in an appropriately-named subfolder. **Note** that filenames here must be distinct from all other compiler testcase names, so you may have to work a bit to find a unique name if it's something common.