From 6cd5a4dac9599122eff78d016a82ac0d362850ab Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 10 Dec 2015 11:03:45 -0800 Subject: [PATCH 01/17] Compare enums semi-structurally. 1. Unqualified names must match. 2. Target contains members with same names as all source members. --- src/compiler/checker.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50a3aee9955..0f04daf2983 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5040,6 +5040,11 @@ namespace ts { if (source === undefinedType) return Ternary.True; if (source === nullType && target !== undefinedType) return Ternary.True; if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; + if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) { + if (result = enumRelatedTo(source, target)) { + return result; + } + } if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; if (relation === assignableRelation) { if (isTypeAny(source)) return Ternary.True; @@ -5750,6 +5755,25 @@ namespace ts { } return Ternary.False; } + + function enumRelatedTo(source: Type, target: Type) { + if (source.symbol.name !== target.symbol.name) { + return Ternary.False; + } + const sourceDecl = getMergedSymbol(source.symbol).valueDeclaration; + const targetDecl = getMergedSymbol(target.symbol).valueDeclaration; + const targetMembers = arrayToMap(targetDecl.members, member => getTextOfPropertyName(member.name)); + for (const member of sourceDecl.members) { + const name = getTextOfPropertyName(member.name); + if (!targetMembers[name]) { + reportError(Diagnostics.Property_0_is_missing_in_type_1, + name, + typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); + return Ternary.False; + } + } + return Ternary.True; + } } // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case From 6ed5b59f751f57532e43cbc0ac71ff097bcc899b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 10 Dec 2015 11:05:25 -0800 Subject: [PATCH 02/17] Add test case and accept baseline --- .../enumAssignmentCompat3.errors.txt | 75 ++++++++++++ .../reference/enumAssignmentCompat3.js | 115 ++++++++++++++++++ tests/cases/compiler/enumAssignmentCompat3.ts | 45 +++++++ 3 files changed, 235 insertions(+) create mode 100644 tests/baselines/reference/enumAssignmentCompat3.errors.txt create mode 100644 tests/baselines/reference/enumAssignmentCompat3.js create mode 100644 tests/cases/compiler/enumAssignmentCompat3.ts diff --git a/tests/baselines/reference/enumAssignmentCompat3.errors.txt b/tests/baselines/reference/enumAssignmentCompat3.errors.txt new file mode 100644 index 00000000000..d82a4b7d490 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat3.errors.txt @@ -0,0 +1,75 @@ +tests/cases/compiler/enumAssignmentCompat3.ts(37,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(39,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(40,1): error TS2322: Type 'Nope' is not assignable to type 'E'. +tests/cases/compiler/enumAssignmentCompat3.ts(43,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. + Property 'c' is missing in type 'Ab.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(44,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. + Property 'a' is missing in type 'Cd.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(45,1): error TS2322: Type 'E' is not assignable to type 'Nope'. + + +==== tests/cases/compiler/enumAssignmentCompat3.ts (6 errors) ==== + namespace First { + export enum E { + a, b, c, + } + } + namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } + } + namespace Abcd { + export enum E { + a, b, c, d, + } + } + namespace Ab { + export enum E { + a, b, + } + } + namespace Cd { + export enum E { + c, d, + } + } + + var abc: First.E; + var secondAbc: Abc.E; + var secondAbcd: Abcd.E; + var secondAb: Ab.E; + var secondCd: Cd.E; + var nope: Abc.Nope; + abc = secondAbc; // ok + abc = secondAbcd; // missing 'd' + ~~~ +!!! error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + abc = secondAb; // ok + abc = secondCd; // missing 'd' + ~~~ +!!! error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + abc = nope; // nope! + ~~~ +!!! error TS2322: Type 'Nope' is not assignable to type 'E'. + secondAbc = abc; // ok + secondAbcd = abc; // ok + secondAb = abc; // missing 'c' + ~~~~~~~~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. +!!! error TS2322: Property 'c' is missing in type 'Ab.E'. + secondCd = abc; // missing 'a' and 'b' + ~~~~~~~~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. +!!! error TS2322: Property 'a' is missing in type 'Cd.E'. + nope = abc; // nope! + ~~~~ +!!! error TS2322: Type 'E' is not assignable to type 'Nope'. + \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat3.js b/tests/baselines/reference/enumAssignmentCompat3.js new file mode 100644 index 00000000000..33cfdd28e88 --- /dev/null +++ b/tests/baselines/reference/enumAssignmentCompat3.js @@ -0,0 +1,115 @@ +//// [enumAssignmentCompat3.ts] +namespace First { + export enum E { + a, b, c, + } +} +namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } +} +namespace Abcd { + export enum E { + a, b, c, d, + } +} +namespace Ab { + export enum E { + a, b, + } +} +namespace Cd { + export enum E { + c, d, + } +} + +var abc: First.E; +var secondAbc: Abc.E; +var secondAbcd: Abcd.E; +var secondAb: Ab.E; +var secondCd: Cd.E; +var nope: Abc.Nope; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! + + +//// [enumAssignmentCompat3.js] +var First; +(function (First) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(First.E || (First.E = {})); + var E = First.E; +})(First || (First = {})); +var Abc; +(function (Abc) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(Abc.E || (Abc.E = {})); + var E = Abc.E; + (function (Nope) { + Nope[Nope["a"] = 0] = "a"; + Nope[Nope["b"] = 1] = "b"; + Nope[Nope["c"] = 2] = "c"; + })(Abc.Nope || (Abc.Nope = {})); + var Nope = Abc.Nope; +})(Abc || (Abc = {})); +var Abcd; +(function (Abcd) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + E[E["d"] = 3] = "d"; + })(Abcd.E || (Abcd.E = {})); + var E = Abcd.E; +})(Abcd || (Abcd = {})); +var Ab; +(function (Ab) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + })(Ab.E || (Ab.E = {})); + var E = Ab.E; +})(Ab || (Ab = {})); +var Cd; +(function (Cd) { + (function (E) { + E[E["c"] = 0] = "c"; + E[E["d"] = 1] = "d"; + })(Cd.E || (Cd.E = {})); + var E = Cd.E; +})(Cd || (Cd = {})); +var abc; +var secondAbc; +var secondAbcd; +var secondAb; +var secondCd; +var nope; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! diff --git a/tests/cases/compiler/enumAssignmentCompat3.ts b/tests/cases/compiler/enumAssignmentCompat3.ts new file mode 100644 index 00000000000..94a22c7f346 --- /dev/null +++ b/tests/cases/compiler/enumAssignmentCompat3.ts @@ -0,0 +1,45 @@ +namespace First { + export enum E { + a, b, c, + } +} +namespace Abc { + export enum E { + a, b, c, + } + export enum Nope { + a, b, c, + } +} +namespace Abcd { + export enum E { + a, b, c, d, + } +} +namespace Ab { + export enum E { + a, b, + } +} +namespace Cd { + export enum E { + c, d, + } +} + +var abc: First.E; +var secondAbc: Abc.E; +var secondAbcd: Abcd.E; +var secondAb: Ab.E; +var secondCd: Cd.E; +var nope: Abc.Nope; +abc = secondAbc; // ok +abc = secondAbcd; // missing 'd' +abc = secondAb; // ok +abc = secondCd; // missing 'd' +abc = nope; // nope! +secondAbc = abc; // ok +secondAbcd = abc; // ok +secondAb = abc; // missing 'c' +secondCd = abc; // missing 'a' and 'b' +nope = abc; // nope! From cc1d8cf395eebdf5e1f6e2f9ddb90111fbad95b7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 10 Dec 2015 13:47:18 -0800 Subject: [PATCH 03/17] Address review comments --- src/compiler/checker.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0f04daf2983..857fa97ca06 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5757,15 +5757,17 @@ namespace ts { } function enumRelatedTo(source: Type, target: Type) { - if (source.symbol.name !== target.symbol.name) { + if (source.symbol.name !== target.symbol.name || + source.symbol.flags & SymbolFlags.ConstEnum || + target.symbol.flags & SymbolFlags.ConstEnum) { return Ternary.False; } - const sourceDecl = getMergedSymbol(source.symbol).valueDeclaration; - const targetDecl = getMergedSymbol(target.symbol).valueDeclaration; + const sourceDecl = getDeclarationOfKind(source.symbol, SyntaxKind.EnumDeclaration); + const targetDecl = getDeclarationOfKind(target.symbol, SyntaxKind.EnumDeclaration); const targetMembers = arrayToMap(targetDecl.members, member => getTextOfPropertyName(member.name)); for (const member of sourceDecl.members) { const name = getTextOfPropertyName(member.name); - if (!targetMembers[name]) { + if (!hasProperty(targetMembers, name)) { reportError(Diagnostics.Property_0_is_missing_in_type_1, name, typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); From ff0138878ddbe5823df3d37073e875758f23ec18 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 10 Dec 2015 13:47:31 -0800 Subject: [PATCH 04/17] Add tests from review --- .../enumAssignmentCompat3.errors.txt | 38 +++++++++++++++---- .../reference/enumAssignmentCompat3.js | 28 ++++++++++++++ tests/cases/compiler/enumAssignmentCompat3.ts | 18 +++++++++ 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/tests/baselines/reference/enumAssignmentCompat3.errors.txt b/tests/baselines/reference/enumAssignmentCompat3.errors.txt index d82a4b7d490..b9ab92adec1 100644 --- a/tests/baselines/reference/enumAssignmentCompat3.errors.txt +++ b/tests/baselines/reference/enumAssignmentCompat3.errors.txt @@ -1,16 +1,18 @@ -tests/cases/compiler/enumAssignmentCompat3.ts(37,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(49,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(39,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(51,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(40,1): error TS2322: Type 'Nope' is not assignable to type 'E'. -tests/cases/compiler/enumAssignmentCompat3.ts(43,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(52,1): error TS2322: Type 'Nope' is not assignable to type 'E'. +tests/cases/compiler/enumAssignmentCompat3.ts(56,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. Property 'c' is missing in type 'Ab.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(44,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(57,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. Property 'a' is missing in type 'Cd.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(45,1): error TS2322: Type 'E' is not assignable to type 'Nope'. +tests/cases/compiler/enumAssignmentCompat3.ts(58,1): error TS2322: Type 'E' is not assignable to type 'Nope'. +tests/cases/compiler/enumAssignmentCompat3.ts(62,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(63,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. -==== tests/cases/compiler/enumAssignmentCompat3.ts (6 errors) ==== +==== tests/cases/compiler/enumAssignmentCompat3.ts (8 errors) ==== namespace First { export enum E { a, b, c, @@ -39,6 +41,16 @@ tests/cases/compiler/enumAssignmentCompat3.ts(45,1): error TS2322: Type 'E' is n c, d, } } + namespace Const { + export const enum E { + a, b, c, + } + } + namespace Decl { + export declare enum E { + a, b, c = 3, + } + } var abc: First.E; var secondAbc: Abc.E; @@ -46,6 +58,8 @@ tests/cases/compiler/enumAssignmentCompat3.ts(45,1): error TS2322: Type 'E' is n var secondAb: Ab.E; var secondCd: Cd.E; var nope: Abc.Nope; + var k: Const.E; + var decl: Decl.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' ~~~ @@ -59,6 +73,7 @@ tests/cases/compiler/enumAssignmentCompat3.ts(45,1): error TS2322: Type 'E' is n abc = nope; // nope! ~~~ !!! error TS2322: Type 'Nope' is not assignable to type 'E'. + abc = decl; // ok secondAbc = abc; // ok secondAbcd = abc; // ok secondAb = abc; // missing 'c' @@ -72,4 +87,13 @@ tests/cases/compiler/enumAssignmentCompat3.ts(45,1): error TS2322: Type 'E' is n nope = abc; // nope! ~~~~ !!! error TS2322: Type 'E' is not assignable to type 'Nope'. + decl = abc; // ok + + k = k; // const is only assignable to itself + abc = k; // error + ~~~ +!!! error TS2322: Type 'Const.E' is not assignable to type 'First.E'. + k = abc; + ~ +!!! error TS2322: Type 'First.E' is not assignable to type 'Const.E'. \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat3.js b/tests/baselines/reference/enumAssignmentCompat3.js index 33cfdd28e88..1173bfa1812 100644 --- a/tests/baselines/reference/enumAssignmentCompat3.js +++ b/tests/baselines/reference/enumAssignmentCompat3.js @@ -27,6 +27,16 @@ namespace Cd { c, d, } } +namespace Const { + export const enum E { + a, b, c, + } +} +namespace Decl { + export declare enum E { + a, b, c = 3, + } +} var abc: First.E; var secondAbc: Abc.E; @@ -34,16 +44,24 @@ var secondAbcd: Abcd.E; var secondAb: Ab.E; var secondCd: Cd.E; var nope: Abc.Nope; +var k: Const.E; +var decl: Decl.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok abc = secondCd; // missing 'd' abc = nope; // nope! +abc = decl; // ok secondAbc = abc; // ok secondAbcd = abc; // ok secondAb = abc; // missing 'c' secondCd = abc; // missing 'a' and 'b' nope = abc; // nope! +decl = abc; // ok + +k = k; // const is only assignable to itself +abc = k; // error +k = abc; //// [enumAssignmentCompat3.js] @@ -97,19 +115,29 @@ var Cd; })(Cd.E || (Cd.E = {})); var E = Cd.E; })(Cd || (Cd = {})); +var Decl; +(function (Decl) { +})(Decl || (Decl = {})); var abc; var secondAbc; var secondAbcd; var secondAb; var secondCd; var nope; +var k; +var decl; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok abc = secondCd; // missing 'd' abc = nope; // nope! +abc = decl; // ok secondAbc = abc; // ok secondAbcd = abc; // ok secondAb = abc; // missing 'c' secondCd = abc; // missing 'a' and 'b' nope = abc; // nope! +decl = abc; // ok +k = k; // const is only assignable to itself +abc = k; // error +k = abc; diff --git a/tests/cases/compiler/enumAssignmentCompat3.ts b/tests/cases/compiler/enumAssignmentCompat3.ts index 94a22c7f346..aaaf96b69c8 100644 --- a/tests/cases/compiler/enumAssignmentCompat3.ts +++ b/tests/cases/compiler/enumAssignmentCompat3.ts @@ -26,6 +26,16 @@ namespace Cd { c, d, } } +namespace Const { + export const enum E { + a, b, c, + } +} +namespace Decl { + export declare enum E { + a, b, c = 3, + } +} var abc: First.E; var secondAbc: Abc.E; @@ -33,13 +43,21 @@ var secondAbcd: Abcd.E; var secondAb: Ab.E; var secondCd: Cd.E; var nope: Abc.Nope; +var k: Const.E; +var decl: Decl.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok abc = secondCd; // missing 'd' abc = nope; // nope! +abc = decl; // ok secondAbc = abc; // ok secondAbcd = abc; // ok secondAb = abc; // missing 'c' secondCd = abc; // missing 'a' and 'b' nope = abc; // nope! +decl = abc; // ok + +k = k; // const is only assignable to itself +abc = k; // error +k = abc; From a995b23e4a00e252de81cdf0d1685700314eefa6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 10 Dec 2015 14:28:29 -0800 Subject: [PATCH 05/17] Handle merged enums --- src/compiler/checker.ts | 23 ++++++++++++++++++----- src/compiler/utilities.ts | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 857fa97ca06..2fb0296c1c7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5762,12 +5762,11 @@ namespace ts { target.symbol.flags & SymbolFlags.ConstEnum) { return Ternary.False; } - const sourceDecl = getDeclarationOfKind(source.symbol, SyntaxKind.EnumDeclaration); - const targetDecl = getDeclarationOfKind(target.symbol, SyntaxKind.EnumDeclaration); - const targetMembers = arrayToMap(targetDecl.members, member => getTextOfPropertyName(member.name)); - for (const member of sourceDecl.members) { + const targetMembers = getEnumMembers(target.symbol); + const targetNames = arrayToMap(targetMembers, member => getTextOfPropertyName(member.name)); + for (const member of getEnumMembers(source.symbol)) { const name = getTextOfPropertyName(member.name); - if (!hasProperty(targetMembers, name)) { + if (!hasProperty(targetNames, name)) { reportError(Diagnostics.Property_0_is_missing_in_type_1, name, typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); @@ -5778,6 +5777,20 @@ namespace ts { } } + function getEnumMembers(symbol: Symbol): EnumMember[] { + const declarations = getDeclarationsOfKind(symbol, SyntaxKind.EnumDeclaration); + if (!declarations) { + return emptyArray; + } + const members: EnumMember[] = []; + for (const declaration of declarations) { + for (const member of (declaration).members) { + members.push(member); + } + } + return members; + } + // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case // when structural type comparisons have been started for 10 or more instantiations of the same generic type. It is possible, // though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely expanding. diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 95bf4ff7fa3..24e2149ab3e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -27,6 +27,21 @@ namespace ts { return undefined; } + export function getDeclarationsOfKind(symbol: Symbol, kind: SyntaxKind): Declaration[] { + const declarations = symbol.declarations; + if (declarations) { + const declarationsOfKind: Declaration[] = []; + for (const declaration of declarations) { + if (declaration.kind === kind) { + declarationsOfKind.push(declaration); + } + } + return declarationsOfKind; + } + + return undefined; + } + export interface StringSymbolWriter extends SymbolWriter { string(): string; } From 75304096959652551cdeed4140753f44940e45b6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 10 Dec 2015 14:28:46 -0800 Subject: [PATCH 06/17] Add merged enum test --- .../enumAssignmentCompat3.errors.txt | 40 ++++++++++++++----- .../reference/enumAssignmentCompat3.js | 37 +++++++++++++++-- tests/cases/compiler/enumAssignmentCompat3.ts | 16 +++++++- 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/tests/baselines/reference/enumAssignmentCompat3.errors.txt b/tests/baselines/reference/enumAssignmentCompat3.errors.txt index b9ab92adec1..c34ad434347 100644 --- a/tests/baselines/reference/enumAssignmentCompat3.errors.txt +++ b/tests/baselines/reference/enumAssignmentCompat3.errors.txt @@ -1,18 +1,20 @@ -tests/cases/compiler/enumAssignmentCompat3.ts(49,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(58,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(51,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(60,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(52,1): error TS2322: Type 'Nope' is not assignable to type 'E'. -tests/cases/compiler/enumAssignmentCompat3.ts(56,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(61,1): error TS2322: Type 'Nope' is not assignable to type 'E'. +tests/cases/compiler/enumAssignmentCompat3.ts(65,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. Property 'c' is missing in type 'Ab.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(57,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(66,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. Property 'a' is missing in type 'Cd.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(58,1): error TS2322: Type 'E' is not assignable to type 'Nope'. -tests/cases/compiler/enumAssignmentCompat3.ts(62,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(63,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(67,1): error TS2322: Type 'E' is not assignable to type 'Nope'. +tests/cases/compiler/enumAssignmentCompat3.ts(72,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(73,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. + Property 'd' is missing in type 'First.E'. -==== tests/cases/compiler/enumAssignmentCompat3.ts (8 errors) ==== +==== tests/cases/compiler/enumAssignmentCompat3.ts (9 errors) ==== namespace First { export enum E { a, b, c, @@ -51,6 +53,14 @@ tests/cases/compiler/enumAssignmentCompat3.ts(63,1): error TS2322: Type 'First.E a, b, c = 3, } } + namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } + } var abc: First.E; var secondAbc: Abc.E; @@ -60,6 +70,7 @@ tests/cases/compiler/enumAssignmentCompat3.ts(63,1): error TS2322: Type 'First.E var nope: Abc.Nope; var k: Const.E; var decl: Decl.E; + var merged: Merged.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' ~~~ @@ -89,11 +100,18 @@ tests/cases/compiler/enumAssignmentCompat3.ts(63,1): error TS2322: Type 'First.E !!! error TS2322: Type 'E' is not assignable to type 'Nope'. decl = abc; // ok - k = k; // const is only assignable to itself + // const is only assignable to itself + k = k; abc = k; // error ~~~ !!! error TS2322: Type 'Const.E' is not assignable to type 'First.E'. k = abc; ~ !!! error TS2322: Type 'First.E' is not assignable to type 'Const.E'. - \ No newline at end of file + + // merged enums compare all their members + abc = merged; // missing 'd' + ~~~ +!!! error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. +!!! error TS2322: Property 'd' is missing in type 'First.E'. + merged = abc; // ok \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat3.js b/tests/baselines/reference/enumAssignmentCompat3.js index 1173bfa1812..e43874911ce 100644 --- a/tests/baselines/reference/enumAssignmentCompat3.js +++ b/tests/baselines/reference/enumAssignmentCompat3.js @@ -37,6 +37,14 @@ namespace Decl { a, b, c = 3, } } +namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } +} var abc: First.E; var secondAbc: Abc.E; @@ -46,6 +54,7 @@ var secondCd: Cd.E; var nope: Abc.Nope; var k: Const.E; var decl: Decl.E; +var merged: Merged.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok @@ -59,10 +68,14 @@ secondCd = abc; // missing 'a' and 'b' nope = abc; // nope! decl = abc; // ok -k = k; // const is only assignable to itself +// const is only assignable to itself +k = k; abc = k; // error k = abc; - + +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok //// [enumAssignmentCompat3.js] var First; @@ -118,6 +131,19 @@ var Cd; var Decl; (function (Decl) { })(Decl || (Decl = {})); +var Merged; +(function (Merged) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + })(Merged.E || (Merged.E = {})); + var E = Merged.E; + (function (E) { + E[E["c"] = 3] = "c"; + E[E["d"] = 4] = "d"; + })(Merged.E || (Merged.E = {})); + var E = Merged.E; +})(Merged || (Merged = {})); var abc; var secondAbc; var secondAbcd; @@ -126,6 +152,7 @@ var secondCd; var nope; var k; var decl; +var merged; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok @@ -138,6 +165,10 @@ secondAb = abc; // missing 'c' secondCd = abc; // missing 'a' and 'b' nope = abc; // nope! decl = abc; // ok -k = k; // const is only assignable to itself +// const is only assignable to itself +k = k; abc = k; // error k = abc; +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok diff --git a/tests/cases/compiler/enumAssignmentCompat3.ts b/tests/cases/compiler/enumAssignmentCompat3.ts index aaaf96b69c8..33070572661 100644 --- a/tests/cases/compiler/enumAssignmentCompat3.ts +++ b/tests/cases/compiler/enumAssignmentCompat3.ts @@ -36,6 +36,14 @@ namespace Decl { a, b, c = 3, } } +namespace Merged { + export enum E { + a, b, + } + export enum E { + c = 3, d, + } +} var abc: First.E; var secondAbc: Abc.E; @@ -45,6 +53,7 @@ var secondCd: Cd.E; var nope: Abc.Nope; var k: Const.E; var decl: Decl.E; +var merged: Merged.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok @@ -58,6 +67,11 @@ secondCd = abc; // missing 'a' and 'b' nope = abc; // nope! decl = abc; // ok -k = k; // const is only assignable to itself +// const is only assignable to itself +k = k; abc = k; // error k = abc; + +// merged enums compare all their members +abc = merged; // missing 'd' +merged = abc; // ok \ No newline at end of file From da8e19e191ef508d18f400db62c9297e44002da7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 10 Dec 2015 15:25:01 -0800 Subject: [PATCH 07/17] Use typeof enum to resolve members. Use getTypeOfSymbol >> resolveStructuredTypeMembers >> properties instead of looking at declarations. --- src/compiler/checker.ts | 26 ++++++-------------------- src/compiler/utilities.ts | 15 --------------- 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2fb0296c1c7..bccbede909b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5762,13 +5762,13 @@ namespace ts { target.symbol.flags & SymbolFlags.ConstEnum) { return Ternary.False; } - const targetMembers = getEnumMembers(target.symbol); - const targetNames = arrayToMap(targetMembers, member => getTextOfPropertyName(member.name)); - for (const member of getEnumMembers(source.symbol)) { - const name = getTextOfPropertyName(member.name); - if (!hasProperty(targetNames, name)) { + const sourceMembers = resolveStructuredTypeMembers(getTypeOfSymbol(source.symbol)).properties; + const targetMembers = resolveStructuredTypeMembers(getTypeOfSymbol(target.symbol)).properties; + const targetNames = arrayToMap(targetMembers, member => member.name); + for (const member of sourceMembers) { + if (!hasProperty(targetNames, member.name)) { reportError(Diagnostics.Property_0_is_missing_in_type_1, - name, + member.name, typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); return Ternary.False; } @@ -5777,20 +5777,6 @@ namespace ts { } } - function getEnumMembers(symbol: Symbol): EnumMember[] { - const declarations = getDeclarationsOfKind(symbol, SyntaxKind.EnumDeclaration); - if (!declarations) { - return emptyArray; - } - const members: EnumMember[] = []; - for (const declaration of declarations) { - for (const member of (declaration).members) { - members.push(member); - } - } - return members; - } - // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case // when structural type comparisons have been started for 10 or more instantiations of the same generic type. It is possible, // though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely expanding. diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 24e2149ab3e..95bf4ff7fa3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -27,21 +27,6 @@ namespace ts { return undefined; } - export function getDeclarationsOfKind(symbol: Symbol, kind: SyntaxKind): Declaration[] { - const declarations = symbol.declarations; - if (declarations) { - const declarationsOfKind: Declaration[] = []; - for (const declaration of declarations) { - if (declaration.kind === kind) { - declarationsOfKind.push(declaration); - } - } - return declarationsOfKind; - } - - return undefined; - } - export interface StringSymbolWriter extends SymbolWriter { string(): string; } From 8202576ab2d503258dbd18b7ebc1035607ebd173 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 11 Dec 2015 09:56:13 -0800 Subject: [PATCH 08/17] Filter for enum members only. --- src/compiler/checker.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bccbede909b..9944cebf54a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5762,10 +5762,8 @@ namespace ts { target.symbol.flags & SymbolFlags.ConstEnum) { return Ternary.False; } - const sourceMembers = resolveStructuredTypeMembers(getTypeOfSymbol(source.symbol)).properties; - const targetMembers = resolveStructuredTypeMembers(getTypeOfSymbol(target.symbol)).properties; - const targetNames = arrayToMap(targetMembers, member => member.name); - for (const member of sourceMembers) { + const targetNames = arrayToMap(getEnumMembersOfEnumType(target), member => member.name); + for (const member of getEnumMembersOfEnumType(source)) { if (!hasProperty(targetNames, member.name)) { reportError(Diagnostics.Property_0_is_missing_in_type_1, member.name, @@ -5775,6 +5773,11 @@ namespace ts { } return Ternary.True; } + + function getEnumMembersOfEnumType(type: Type) { + return filter(resolveStructuredTypeMembers(getTypeOfSymbol(type.symbol)).properties, + property => !!(property.flags & SymbolFlags.EnumMember)); + } } // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case From dc9d307f137dc2a7b812cea42aac6927711b419a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 11 Dec 2015 10:08:01 -0800 Subject: [PATCH 09/17] Fix lint --- 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 9944cebf54a..8d9fe1f7ba5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5775,7 +5775,7 @@ namespace ts { } function getEnumMembersOfEnumType(type: Type) { - return filter(resolveStructuredTypeMembers(getTypeOfSymbol(type.symbol)).properties, + return filter(resolveStructuredTypeMembers(getTypeOfSymbol(type.symbol)).properties, property => !!(property.flags & SymbolFlags.EnumMember)); } } From b44f6e47d653419b1f47baf6734bd0942a3f15d0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 12 Dec 2015 15:56:43 -0800 Subject: [PATCH 10/17] Simplify deferred checking of function, class, and accessor bodies. --- src/compiler/checker.ts | 155 +++++++++++----------------------------- 1 file changed, 40 insertions(+), 115 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ea23255472d..e4cf101946a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -161,6 +161,8 @@ namespace ts { let jsxElementClassType: Type; + let deferredNodes: Node[]; + const tupleTypes: Map = {}; const unionTypes: Map = {}; const intersectionTypes: Map = {}; @@ -10123,6 +10125,7 @@ namespace ts { if (!contextChecked) { checkSignatureDeclaration(node); + checkNodeDeferred(node); } } } @@ -10135,7 +10138,7 @@ namespace ts { return type; } - function checkFunctionExpressionOrObjectLiteralMethodBody(node: ArrowFunction | FunctionExpression | MethodDeclaration) { + function checkFunctionExpressionOrObjectLiteralMethodDeferred(node: ArrowFunction | FunctionExpression | MethodDeclaration) { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); const isAsync = isAsyncFunctionLike(node); @@ -10178,8 +10181,6 @@ namespace ts { checkTypeAssignableTo(exprType, returnOrPromisedType, node.body); } } - - checkFunctionAndClassExpressionBodies(node.body); } } } @@ -11428,13 +11429,13 @@ namespace ts { if (node.parent.kind !== SyntaxKind.ObjectLiteralExpression) { checkSourceElement(node.body); } + else { + checkNodeDeferred(node); + } } - function checkObjectLiteralAccessorBody(node: AccessorDeclaration) { - if (node.body) { - checkSourceElement(node.body); - checkFunctionAndClassExpressionBodies(node.body); - } + function checkAccessorDeferred(node: AccessorDeclaration) { + checkSourceElement(node.body); } function checkMissingDeclaration(node: Node) { @@ -12373,11 +12374,7 @@ namespace ts { if (node.kind === SyntaxKind.Block) { checkGrammarStatementInAmbientContext(node); } - forEach(node.statements, checkSourceElement); - if (isFunctionBlock(node) || node.kind === SyntaxKind.ModuleBlock) { - checkFunctionAndClassExpressionBodies(node); - } } function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { @@ -13406,15 +13403,19 @@ namespace ts { function checkClassExpression(node: ClassExpression): Type { checkClassLikeDeclaration(node); + checkNodeDeferred(node); return getTypeOfSymbol(getSymbolOfNode(node)); } + function checkClassExpressionDeferred(node: ClassExpression) { + forEach(node.members, checkSourceElement); + } + function checkClassDeclaration(node: ClassDeclaration) { if (!node.name && !(node.flags & NodeFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } checkClassLikeDeclaration(node); - forEach(node.members, checkSourceElement); } @@ -14478,107 +14479,29 @@ namespace ts { // Here, performing a full type check of the body of the function expression whilst in the process of // determining the type of foo would cause foo to be given type any because of the recursive reference. // Delaying the type check of the body ensures foo has been assigned a type. - function checkFunctionAndClassExpressionBodies(node: Node): void { - switch (node.kind) { - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - checkFunctionExpressionOrObjectLiteralMethodBody(node); - break; - case SyntaxKind.ClassExpression: - forEach((node).members, checkSourceElement); - forEachChild(node, checkFunctionAndClassExpressionBodies); - break; - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - forEach(node.decorators, checkFunctionAndClassExpressionBodies); - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - if (isObjectLiteralMethod(node)) { - checkFunctionExpressionOrObjectLiteralMethodBody(node); - } - break; - case SyntaxKind.Constructor: - case SyntaxKind.FunctionDeclaration: - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - break; - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - forEach((node).parameters, checkFunctionAndClassExpressionBodies); - if (node.parent.kind === SyntaxKind.ObjectLiteralExpression) { - checkObjectLiteralAccessorBody(node); - } - break; - case SyntaxKind.WithStatement: - checkFunctionAndClassExpressionBodies((node).expression); - break; - case SyntaxKind.Decorator: - case SyntaxKind.Parameter: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - case SyntaxKind.ObjectBindingPattern: - case SyntaxKind.ArrayBindingPattern: - case SyntaxKind.BindingElement: - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.PropertyAssignment: - case SyntaxKind.PropertyAccessExpression: - case SyntaxKind.ElementAccessExpression: - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - case SyntaxKind.TaggedTemplateExpression: - case SyntaxKind.TemplateExpression: - case SyntaxKind.TemplateSpan: - case SyntaxKind.TypeAssertionExpression: - case SyntaxKind.AsExpression: - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.TypeOfExpression: - case SyntaxKind.VoidExpression: - case SyntaxKind.AwaitExpression: - case SyntaxKind.DeleteExpression: - case SyntaxKind.PrefixUnaryExpression: - case SyntaxKind.PostfixUnaryExpression: - case SyntaxKind.BinaryExpression: - case SyntaxKind.ConditionalExpression: - case SyntaxKind.SpreadElementExpression: - case SyntaxKind.YieldExpression: - case SyntaxKind.Block: - case SyntaxKind.ModuleBlock: - case SyntaxKind.VariableStatement: - case SyntaxKind.ExpressionStatement: - case SyntaxKind.IfStatement: - case SyntaxKind.DoStatement: - case SyntaxKind.WhileStatement: - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - case SyntaxKind.ContinueStatement: - case SyntaxKind.BreakStatement: - case SyntaxKind.ReturnStatement: - case SyntaxKind.SwitchStatement: - case SyntaxKind.CaseBlock: - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - case SyntaxKind.LabeledStatement: - case SyntaxKind.ThrowStatement: - case SyntaxKind.TryStatement: - case SyntaxKind.CatchClause: - case SyntaxKind.VariableDeclaration: - case SyntaxKind.VariableDeclarationList: - case SyntaxKind.ClassDeclaration: - case SyntaxKind.HeritageClause: - case SyntaxKind.ExpressionWithTypeArguments: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.EnumMember: - case SyntaxKind.ExportAssignment: - case SyntaxKind.SourceFile: - case SyntaxKind.JsxExpression: - case SyntaxKind.JsxElement: - case SyntaxKind.JsxSelfClosingElement: - case SyntaxKind.JsxAttribute: - case SyntaxKind.JsxSpreadAttribute: - case SyntaxKind.JsxOpeningElement: - forEachChild(node, checkFunctionAndClassExpressionBodies); - break; + function checkNodeDeferred(node: Node) { + if (deferredNodes) { + deferredNodes.push(node); + } + } + + function checkDeferredNodes() { + for (const node of deferredNodes) { + switch (node.kind) { + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + checkFunctionExpressionOrObjectLiteralMethodDeferred(node); + break; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + checkAccessorDeferred(node); + break; + case SyntaxKind.ClassExpression: + checkClassExpressionDeferred(node); + break; + } } } @@ -14613,8 +14536,10 @@ namespace ts { emitAwaiter = false; potentialThisCollisions.length = 0; + deferredNodes = []; forEach(node.statements, checkSourceElement); - checkFunctionAndClassExpressionBodies(node); + checkDeferredNodes(); + deferredNodes = undefined; if (isExternalOrCommonJsModule(node)) { checkExternalModuleExports(node); From 91b93439f12a911bc83fbc3399a9a739a619721a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 12 Dec 2015 15:57:39 -0800 Subject: [PATCH 11/17] Accepting new baselines --- ...nePropertyAccessAndArrowFunctionIndent1.errors.txt | 11 +---------- .../multiLinePropertyAccessAndArrowFunctionIndent1.js | 3 +-- ...atementIsNotAMemberVariableDeclaration1.errors.txt | 5 +---- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt index abf11dc9dba..48a1da7d22c 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt @@ -1,20 +1,11 @@ tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. -tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'. -tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'. -tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'. -==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ==== +==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (1 errors) ==== return this.edit(role) ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. - ~~~~ -!!! error TS2304: Cannot find name 'role'. .then((role: Role) => - ~~~~ -!!! error TS2304: Cannot find name 'Role'. this.roleService.add(role) .then((data: ng.IHttpPromiseCallbackArg) => data.data)); - ~~ -!!! error TS2503: Cannot find namespace 'ng'. \ No newline at end of file diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js index 2ada9f1bb52..4821f1fe69c 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.js @@ -6,9 +6,8 @@ return this.edit(role) //// [multiLinePropertyAccessAndArrowFunctionIndent1.js] -var _this = this; return this.edit(role) .then(function (role) { - return _this.roleService.add(role) + return this.roleService.add(role) .then(function (data) { return data.data; }); }); diff --git a/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt index 72cfee58e54..0532fd28d63 100644 --- a/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt +++ b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts(6,5): error TS2304: Cannot find name 'private'. -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (1 errors) ==== return { ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. @@ -11,8 +10,6 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMe // 'private' should not be considered a member variable here. private[key] = value; - ~~~~~~~ -!!! error TS2304: Cannot find name 'private'. } From aa1a7664e73c444a5c9ecf147d85b856f94eee79 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 16 Dec 2015 12:11:24 -0800 Subject: [PATCH 12/17] Add enum/module merge test --- .../enumAssignmentCompat3.errors.txt | 32 +++++++++++++------ .../reference/enumAssignmentCompat3.js | 30 ++++++++++++++++- tests/cases/compiler/enumAssignmentCompat3.ts | 14 +++++++- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/enumAssignmentCompat3.errors.txt b/tests/baselines/reference/enumAssignmentCompat3.errors.txt index c34ad434347..02cb4314777 100644 --- a/tests/baselines/reference/enumAssignmentCompat3.errors.txt +++ b/tests/baselines/reference/enumAssignmentCompat3.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/enumAssignmentCompat3.ts(58,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(68,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(60,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(70,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(61,1): error TS2322: Type 'Nope' is not assignable to type 'E'. -tests/cases/compiler/enumAssignmentCompat3.ts(65,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(71,1): error TS2322: Type 'Nope' is not assignable to type 'E'. +tests/cases/compiler/enumAssignmentCompat3.ts(75,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'. Property 'c' is missing in type 'Ab.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(66,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'First.E' is not assignable to type 'Cd.E'. Property 'a' is missing in type 'Cd.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(67,1): error TS2322: Type 'E' is not assignable to type 'Nope'. -tests/cases/compiler/enumAssignmentCompat3.ts(72,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(73,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. -tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(77,1): error TS2322: Type 'E' is not assignable to type 'Nope'. +tests/cases/compiler/enumAssignmentCompat3.ts(82,1): error TS2322: Type 'Const.E' is not assignable to type 'First.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(83,1): error TS2322: Type 'First.E' is not assignable to type 'Const.E'. +tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. Property 'd' is missing in type 'First.E'. @@ -62,6 +62,15 @@ tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'Merged. } } + namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } + } + var abc: First.E; var secondAbc: Abc.E; var secondAbcd: Abcd.E; @@ -71,6 +80,7 @@ tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'Merged. var k: Const.E; var decl: Decl.E; var merged: Merged.E; + var merged2: Merged2.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' ~~~ @@ -114,4 +124,6 @@ tests/cases/compiler/enumAssignmentCompat3.ts(76,1): error TS2322: Type 'Merged. ~~~ !!! error TS2322: Type 'Merged.E' is not assignable to type 'First.E'. !!! error TS2322: Property 'd' is missing in type 'First.E'. - merged = abc; // ok \ No newline at end of file + merged = abc; // ok + abc = merged2; // ok + merged2 = abc; // ok \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignmentCompat3.js b/tests/baselines/reference/enumAssignmentCompat3.js index e43874911ce..74f74ab1652 100644 --- a/tests/baselines/reference/enumAssignmentCompat3.js +++ b/tests/baselines/reference/enumAssignmentCompat3.js @@ -46,6 +46,15 @@ namespace Merged { } } +namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } +} + var abc: First.E; var secondAbc: Abc.E; var secondAbcd: Abcd.E; @@ -55,6 +64,7 @@ var nope: Abc.Nope; var k: Const.E; var decl: Decl.E; var merged: Merged.E; +var merged2: Merged2.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok @@ -75,7 +85,9 @@ k = abc; // merged enums compare all their members abc = merged; // missing 'd' -merged = abc; // ok +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok //// [enumAssignmentCompat3.js] var First; @@ -144,6 +156,19 @@ var Merged; })(Merged.E || (Merged.E = {})); var E = Merged.E; })(Merged || (Merged = {})); +var Merged2; +(function (Merged2) { + (function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; + E[E["c"] = 2] = "c"; + })(Merged2.E || (Merged2.E = {})); + var E = Merged2.E; + var E; + (function (E) { + E.d = 5; + })(E = Merged2.E || (Merged2.E = {})); +})(Merged2 || (Merged2 = {})); var abc; var secondAbc; var secondAbcd; @@ -153,6 +178,7 @@ var nope; var k; var decl; var merged; +var merged2; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok @@ -172,3 +198,5 @@ k = abc; // merged enums compare all their members abc = merged; // missing 'd' merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok diff --git a/tests/cases/compiler/enumAssignmentCompat3.ts b/tests/cases/compiler/enumAssignmentCompat3.ts index 33070572661..97a136468e3 100644 --- a/tests/cases/compiler/enumAssignmentCompat3.ts +++ b/tests/cases/compiler/enumAssignmentCompat3.ts @@ -45,6 +45,15 @@ namespace Merged { } } +namespace Merged2 { + export enum E { + a, b, c + } + export module E { + export let d = 5; + } +} + var abc: First.E; var secondAbc: Abc.E; var secondAbcd: Abcd.E; @@ -54,6 +63,7 @@ var nope: Abc.Nope; var k: Const.E; var decl: Decl.E; var merged: Merged.E; +var merged2: Merged2.E; abc = secondAbc; // ok abc = secondAbcd; // missing 'd' abc = secondAb; // ok @@ -74,4 +84,6 @@ k = abc; // merged enums compare all their members abc = merged; // missing 'd' -merged = abc; // ok \ No newline at end of file +merged = abc; // ok +abc = merged2; // ok +merged2 = abc; // ok \ No newline at end of file From 7ad3cb74d4806a6deb6ea44c5c1a8d5d329ea52e Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 16 Dec 2015 18:13:15 -0800 Subject: [PATCH 13/17] Address comments --- src/compiler/checker.ts | 25 +++++-------------- src/compiler/types.ts | 3 +-- .../baselines/reference/baseCheck.errors.txt | 11 +++++++- tests/baselines/reference/bases.errors.txt | 5 +++- ...ckSuperCallBeforeThisAccessing2.errors.txt | 6 ++--- ...ckSuperCallBeforeThisAccessing5.errors.txt | 4 +-- ...ckSuperCallBeforeThisAccessing8.errors.txt | 6 ++--- ...derivedClassParameterProperties.errors.txt | 20 ++++++++++++--- ...rivedClassSuperCallsWithThisArg.errors.txt | 9 ++++--- .../thisInInvalidContexts.errors.txt | 9 ++++--- ...InInvalidContextsExternalModule.errors.txt | 9 ++++--- .../reference/thisInSuperCall.errors.txt | 12 ++++++--- .../reference/thisInSuperCall1.errors.txt | 5 +++- .../reference/thisInSuperCall2.errors.txt | 9 ++++--- .../reference/thisInSuperCall3.errors.txt | 5 +++- 15 files changed, 86 insertions(+), 52 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0488b1b6dd1..07fdec43c71 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6849,17 +6849,11 @@ namespace ts { let needToCaptureLexicalThis = false; if (container.kind === SyntaxKind.Constructor) { - // Keep track of whether we have seen "super" before encounter "this" so that - // we can report appropriate error later in checkConstructorDeclaration - // We have to do the check here to make sure we won't give false error when - // "this" is used in arrow functions - // For example: - // constructor() { - // (()=>this); // No Error - // super(); - // } - const nodeLinks = getNodeLinks(container); - nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; + const baseTypeNode = getClassExtendsHeritageClauseElement(container.parent); + if (baseTypeNode && !(getNodeCheckFlags(container) & NodeCheckFlags.HasSeenSuperCall)) { + // In ES6, super inside constructor of class-declaration has to precede "this" accessing + error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); + } } // Now skip arrow functions to get the "real" owner of 'this'. @@ -9605,10 +9599,7 @@ namespace ts { const containgFunction = getContainingFunction(node.expression); if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { - const nodeLinks = getNodeLinks(containgFunction); - if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { - nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; - } + getNodeLinks(containgFunction).flags |= NodeCheckFlags.HasSeenSuperCall; } return voidType; } @@ -11210,10 +11201,6 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)) { - // In ES6, super inside constructor of class-declaration has to precede "this" accessing - error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); - } } else if (baseConstructorType !== nullType) { error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9a82891df77..de706229915 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2030,8 +2030,7 @@ namespace ts { BlockScopedBindingInLoop = 0x00004000, LexicalModuleMergesWithClass = 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration. LoopWithBlockScopedBindingCapturedInFunction = 0x00010000, // Loop that contains block scoped variable captured in closure - HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if 'super' is used before 'this' in constructor function - HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' + HasSeenSuperCall = 0x00040000, // Set during the binding when encounter 'super' } /* @internal */ diff --git a/tests/baselines/reference/baseCheck.errors.txt b/tests/baselines/reference/baseCheck.errors.txt index f52ba4b3dbd..0b4e9fd61b1 100644 --- a/tests/baselines/reference/baseCheck.errors.txt +++ b/tests/baselines/reference/baseCheck.errors.txt @@ -1,15 +1,18 @@ tests/cases/compiler/baseCheck.ts(9,18): error TS2304: Cannot find name 'loc'. tests/cases/compiler/baseCheck.ts(17,53): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/baseCheck.ts(17,59): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(17,59): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(18,62): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(18,62): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(19,59): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/compiler/baseCheck.ts(19,68): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/baseCheck.ts(19,68): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/baseCheck.ts(22,9): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(23,7): error TS2304: Cannot find name 'x'. tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. -==== tests/cases/compiler/baseCheck.ts (9 errors) ==== +==== tests/cases/compiler/baseCheck.ts (12 errors) ==== class C { constructor(x: number, y: number) { } } class ELoc extends C { constructor(x: number) { @@ -33,14 +36,20 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'. !!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. class E extends C { constructor(public z: number) { super(0, this.z) } } ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type ~~~~~~~ !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. function f() { if (x<10) { diff --git a/tests/baselines/reference/bases.errors.txt b/tests/baselines/reference/bases.errors.txt index c03a47d7532..7c48c977b2d 100644 --- a/tests/baselines/reference/bases.errors.txt +++ b/tests/baselines/reference/bases.errors.txt @@ -4,6 +4,7 @@ tests/cases/compiler/bases.ts(7,17): error TS2304: Cannot find name 'any'. tests/cases/compiler/bases.ts(11,7): error TS2420: Class 'C' incorrectly implements interface 'I'. Property 'x' is missing in type 'C'. tests/cases/compiler/bases.ts(12,5): error TS2377: Constructors for derived classes must contain a 'super' call. +tests/cases/compiler/bases.ts(13,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/bases.ts(13,14): error TS2339: Property 'x' does not exist on type 'C'. tests/cases/compiler/bases.ts(13,15): error TS1005: ';' expected. tests/cases/compiler/bases.ts(13,17): error TS2304: Cannot find name 'any'. @@ -11,7 +12,7 @@ tests/cases/compiler/bases.ts(17,9): error TS2339: Property 'x' does not exist o tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'. -==== tests/cases/compiler/bases.ts (10 errors) ==== +==== tests/cases/compiler/bases.ts (11 errors) ==== interface I { x; } @@ -36,6 +37,8 @@ tests/cases/compiler/bases.ts(18,9): error TS2339: Property 'y' does not exist o ~~~~~~~~~~~~~~~ this.x: any; ~~~~~~~~~~~~~~~~~~~~ + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ~ !!! error TS2339: Property 'x' does not exist on type 'C'. ~ diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt index e48f43c8662..c8aa356fd4f 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(5,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== @@ -7,9 +7,9 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17008: public x: number; constructor() { this.x = 100; - super(); - ~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); this.x = 10; var that = this; } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt index 1258101cffc..8ffed5961a3 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== @@ -7,7 +7,7 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17008: public x: number; constructor() { super(this.x); - ~~~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt index 7a00a4f0130..2b37f740331 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(7,20): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== @@ -9,8 +9,8 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17008: class Super extends Base { constructor() { var that = this; - super(); - ~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. + super(); } } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 37f272db082..c54ef2a02b7 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,11 +1,15 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(17,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(32,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(47,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(57,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(58,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(59,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(80,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(81,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(82,9): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (5 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (9 errors) ==== // ordering of super calls in derived constructors matters depending on other class contents class Base { @@ -57,10 +61,10 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a: number; constructor(y: string) { this.a = 1; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. var b = 2; super(); // error: "super" has to be called before "this" accessing - ~~~~~~~~ -!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -69,7 +73,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP b: number; constructor(y: string) { this.a = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. @@ -94,7 +102,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP b: number; constructor(y: string) { this.a = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. super(); // error ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index 0190a659166..7439c81be85 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,9 +1,10 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (3 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (4 errors) ==== class Base { x: string; constructor(a) { } @@ -12,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived extends Base { constructor() { super(this); // ok - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -22,6 +23,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index d74db892019..ccf6a015bd9 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -8,7 +9,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -25,7 +26,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): //'this' in optional super call constructor() { super(this); // Error - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -37,6 +38,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): super(this); // Error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index c4188993eee..449f3ede56a 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'any' is not a constructor function type. @@ -9,7 +10,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(48,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (10 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -26,7 +27,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod //'this' in optional super call constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -38,6 +39,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod super(this); // Error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index f0fc5854123..000c2074892 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall.ts(7,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall.ts(14,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (5 errors) ==== class Base { constructor(x: any) {} } @@ -11,7 +13,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r class Foo extends Base { constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -22,6 +24,8 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -30,5 +34,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall1.errors.txt b/tests/baselines/reference/thisInSuperCall1.errors.txt index 7efc66d1666..98d8ee123ae 100644 --- a/tests/baselines/reference/thisInSuperCall1.errors.txt +++ b/tests/baselines/reference/thisInSuperCall1.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall1.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall1.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -11,6 +12,8 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be r super(this); ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 11ea23d020c..4047bcb9a06 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,8 +1,9 @@ -tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/compiler/thisInSuperCall2.ts(8,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (3 errors) ==== class Base { constructor(a: any) {} } @@ -11,7 +12,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be public x: number; constructor() { super(this); // error: "super" has to be called before "this" accessing - ~~~~~~~~~~~~ + ~~~~ !!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -23,6 +24,8 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be super(this); // error ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file diff --git a/tests/baselines/reference/thisInSuperCall3.errors.txt b/tests/baselines/reference/thisInSuperCall3.errors.txt index df5c5f8b5a2..0e7d1575096 100644 --- a/tests/baselines/reference/thisInSuperCall3.errors.txt +++ b/tests/baselines/reference/thisInSuperCall3.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be referenced in current location. +tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall3.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall3.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -13,6 +14,8 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be r super(this); ~~~~ !!! error TS2332: 'this' cannot be referenced in current location. + ~~~~ +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } \ No newline at end of file From 3558d7d423c6d7837c5a0e7a304ec7edcf100eb0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Dec 2015 11:34:54 -0800 Subject: [PATCH 14/17] Added README.md to 'doc' folder. --- doc/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 doc/README.md diff --git a/doc/README.md b/doc/README.md new file mode 100644 index 00000000000..164fb69ee20 --- /dev/null +++ b/doc/README.md @@ -0,0 +1,7 @@ +This directory contains miscellaneous documentation such as the TypeScript language specification and logo. +If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook). + +# Spec Contributions + +The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats. +Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests. \ No newline at end of file From d59831b4e86b102a28ca045ee0a61778873df1c8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 17 Dec 2015 15:38:02 -0800 Subject: [PATCH 15/17] Get rid of list and map abstractions to reduce GC pressure --- src/compiler/checker.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8d9fe1f7ba5..488549cb180 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5762,22 +5762,19 @@ namespace ts { target.symbol.flags & SymbolFlags.ConstEnum) { return Ternary.False; } - const targetNames = arrayToMap(getEnumMembersOfEnumType(target), member => member.name); - for (const member of getEnumMembersOfEnumType(source)) { - if (!hasProperty(targetNames, member.name)) { - reportError(Diagnostics.Property_0_is_missing_in_type_1, - member.name, - typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); - return Ternary.False; + for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) { + if (property.flags & SymbolFlags.EnumMember) { + const targetProperty = getPropertyOfType(getTypeOfSymbol(target.symbol), property.name); + if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) { + reportError(Diagnostics.Property_0_is_missing_in_type_1, + property.name, + typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); + return Ternary.False; + } } } return Ternary.True; } - - function getEnumMembersOfEnumType(type: Type) { - return filter(resolveStructuredTypeMembers(getTypeOfSymbol(type.symbol)).properties, - property => !!(property.flags & SymbolFlags.EnumMember)); - } } // Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case From b04bd66bb2a11ddfe7a7c17d35ea87ea4e9160cb Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 17 Dec 2015 16:18:55 -0800 Subject: [PATCH 16/17] Get type of target enum outside the lookup loop --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 488549cb180..f65a10b266a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5762,9 +5762,10 @@ namespace ts { target.symbol.flags & SymbolFlags.ConstEnum) { return Ternary.False; } + const targetEnumType = getTypeOfSymbol(target.symbol); for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) { if (property.flags & SymbolFlags.EnumMember) { - const targetProperty = getPropertyOfType(getTypeOfSymbol(target.symbol), property.name); + const targetProperty = getPropertyOfType(targetEnumType, property.name); if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) { reportError(Diagnostics.Property_0_is_missing_in_type_1, property.name, From ce2495f39812ec51402ddb3f8881b5f189eed17c Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 17 Dec 2015 17:21:21 -0800 Subject: [PATCH 17/17] Update baseline from merging master --- .../reference/checkSuperCallBeforeThisAccessing1.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing2.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing3.js | 6 +++--- .../reference/checkSuperCallBeforeThisAccessing4.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing5.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing6.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing7.js | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing8.js | 4 ++-- .../thisInInvalidContextsExternalModule.errors.txt | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js index ec6e6e39ee8..cfb5726dac1 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js @@ -20,7 +20,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -30,4 +30,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js index eb58afd820b..afbc15cf912 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js @@ -20,7 +20,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -30,4 +30,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js index 2c5652cf95f..7e9c23c1f83 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js @@ -25,7 +25,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -34,10 +34,10 @@ var Derived = (function (_super) { this.y = true; } return innver; - })(); + }()); _super.call(this); this.x = 10; var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js index eacec00c438..1257b446ccb 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js @@ -29,7 +29,7 @@ var Based = (function () { function Based() { } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { @@ -49,4 +49,4 @@ var Derived = (function (_super) { var that = this; } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js index 489c7200050..1889ee998ca 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js @@ -21,11 +21,11 @@ var Based = (function () { } } return Based; -})(); +}()); var Derived = (function (_super) { __extends(Derived, _super); function Derived() { _super.call(this, this.x); } return Derived; -})(Based); +}(Based)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js index 6ad9773bc5f..39db4dec174 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js @@ -24,7 +24,7 @@ var Base = (function () { } } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -33,4 +33,4 @@ var Super = (function (_super) { _super.call(this); } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js index eafc662085f..d071c05db5d 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js @@ -19,7 +19,7 @@ var Base = (function () { function Base(func) { } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -27,4 +27,4 @@ var Super = (function (_super) { _super.call(this, (function () { return _this; })); // No error } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js index 4675d328b38..f334cc7f42b 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js @@ -24,7 +24,7 @@ var Base = (function () { } } return Base; -})(); +}()); var Super = (function (_super) { __extends(Super, _super); function Super() { @@ -32,4 +32,4 @@ var Super = (function (_super) { _super.call(this); } return Super; -})(Base); +}(Base)); diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 25ee8cbe122..bc671b2fdbe 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -78,4 +78,4 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod export = this; // Should be an error ~~~~~~~~~~~~~~ -!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. +!!! error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. \ No newline at end of file