From e15eab9d9961cbd978389e2e0504e366e648f020 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 15:11:04 -0700 Subject: [PATCH 01/36] Add basic check for use super before this Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts --- src/compiler/checker.ts | 13 +++++++++++++ src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/types.ts | 1 + 3 files changed, 18 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7f20c542128..5238a4780e2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6866,6 +6866,11 @@ namespace ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; case SyntaxKind.Constructor: + // TODO(yuisu): Comments + if ((container).hasSeenSuperBeforeThis === undefined) { + (container).hasSeenSuperBeforeThis = false; + } + if (isInConstructorArgumentInitializer(node, container)) { error(node, Diagnostics.this_cannot_be_referenced_in_constructor_arguments); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks @@ -9588,6 +9593,10 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { + let containgFunction = getContainingFunction(node.expression); + if (containgFunction && containgFunction.kind === SyntaxKind.Constructor && (containgFunction).hasSeenSuperBeforeThis === undefined) { + (containgFunction).hasSeenSuperBeforeThis = true; + } return voidType; } if (node.kind === SyntaxKind.NewExpression) { @@ -11182,6 +11191,10 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } + else if (!node.hasSeenSuperBeforeThis) { + // TODO: comment + error(node, Diagnostics.super_has_to_be_called_before_this_accessing); + } } else if (baseConstructorType !== nullType) { error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 62661706373..51a4e2c6c8f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2539,5 +2539,9 @@ "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": { "category": "Error", "code": 17007 + }, + "'super' has to be called before 'this' accessing.": { + "category": "Error", + "code": 17006 } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f8b26ddaa6d..5a216f8bbcd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -695,6 +695,7 @@ namespace ts { // @kind(SyntaxKind.Constructor) export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement { body?: FunctionBody; + hasSeenSuperBeforeThis: boolean; // TODDO (yuisu): comment } // For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. From 653deaa2e207b7f4f3e996483a1b6ab61a3fcb65 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 16:42:04 -0700 Subject: [PATCH 02/36] Fix where to report on error. Move from constructor node to just super node Conflicts: src/compiler/checker.ts --- src/compiler/checker.ts | 59 ++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5238a4780e2..b328a4c8366 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6848,6 +6848,22 @@ namespace ts { let container = getThisContainer(node, /* includeArrowFunctions */ true); 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(); + // } + if ((container).hasSeenSuperBeforeThis === undefined) { + (container).hasSeenSuperBeforeThis = false; + } + } + // Now skip arrow functions to get the "real" owner of 'this'. if (container.kind === SyntaxKind.ArrowFunction) { container = getThisContainer(container, /* includeArrowFunctions */ false); @@ -6866,11 +6882,6 @@ namespace ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; case SyntaxKind.Constructor: - // TODO(yuisu): Comments - if ((container).hasSeenSuperBeforeThis === undefined) { - (container).hasSeenSuperBeforeThis = false; - } - if (isInConstructorArgumentInitializer(node, container)) { error(node, Diagnostics.this_cannot_be_referenced_in_constructor_arguments); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks @@ -11154,8 +11165,25 @@ namespace ts { const containingClassSymbol = getSymbolOfNode(containingClassDecl); const containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); const baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); + const statements = (node.body).statements; + let superCallStatement: ExpressionStatement; + let isSuperCallFirstStatment: boolean; - if (containsSuperCall(node.body)) { + for (const statement of statements) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + superCallStatement = statement; + if (isSuperCallFirstStatment === undefined) { + isSuperCallFirstStatment = true; + } + } + else if (isSuperCallFirstStatment === undefined && !isPrologueDirective(statement)) { + isSuperCallFirstStatment = false; + } + } + + // The main different between looping through each statement in constructor and calling containsSuperCall is that, + // containsSuperCall will consider "super" inside computed-property for inner class declaration + if (superCallStatement || containsSuperCall(node.body)) { if (baseConstructorType === nullType) { error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } @@ -11172,19 +11200,8 @@ namespace ts { // Skip past any prologue directives to find the first statement // to ensure that it was a super call. if (superCallShouldBeFirst) { - const statements = (node.body).statements; - let superCallStatement: ExpressionStatement; - for (const statement of statements) { - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { - superCallStatement = statement; - break; - } - if (!isPrologueDirective(statement)) { - break; - } - } - if (!superCallStatement) { - error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); + if (!isSuperCallFirstStatment) { + error(superCallStatement, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { // In such a required super call, it is a compile-time error for argument expressions to reference this. @@ -11192,8 +11209,8 @@ namespace ts { } } else if (!node.hasSeenSuperBeforeThis) { - // TODO: comment - error(node, Diagnostics.super_has_to_be_called_before_this_accessing); + // In ES6, super inside constructor of class-declaration has to precede "this" accessing + error(superCallStatement, Diagnostics.super_has_to_be_called_before_this_accessing); } } else if (baseConstructorType !== nullType) { From eaa2846348c82d69caf78a50b2efa58e660bdea9 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 17:17:30 -0700 Subject: [PATCH 03/36] Add tests --- .../checkSuperCallBeforeThisAccessing1.ts | 10 ++++++++++ .../checkSuperCallBeforeThisAccessing2.ts | 10 ++++++++++ .../checkSuperCallBeforeThisAccessing3.ts | 15 +++++++++++++++ .../checkSuperCallBeforeThisAccessing4.ts | 19 +++++++++++++++++++ .../checkSuperCallBeforeThisAccessing5.ts | 7 +++++++ .../checkSuperCallBeforeThisAccessing6.ts | 10 ++++++++++ .../checkSuperCallBeforeThisAccessing7.ts | 9 +++++++++ 7 files changed, 80 insertions(+) create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts new file mode 100644 index 00000000000..e8dd78ef546 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts @@ -0,0 +1,10 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + super(); + this; + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts new file mode 100644 index 00000000000..e6545f24288 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts @@ -0,0 +1,10 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts new file mode 100644 index 00000000000..fd9de120b05 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts @@ -0,0 +1,15 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + class innver { + public y: boolean; + constructor() { + this.y = true; + } + } + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts new file mode 100644 index 00000000000..1fdee00c2f8 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts @@ -0,0 +1,19 @@ +class Based { } +class Derived extends Based { + public x: number; + constructor() { + (() => { + this; // No error + }); + () => { + this; // No error + }; + (() => { + this; // No error + })(); + super(); + super(); + this.x = 10; + var that = this; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts new file mode 100644 index 00000000000..65d1db6df75 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts @@ -0,0 +1,7 @@ +class Based { constructor(...arg) { } } +class Derived extends Based { + public x: number; + constructor() { + super(this.x); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts new file mode 100644 index 00000000000..2cdcb9ad3a8 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts @@ -0,0 +1,10 @@ +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + (() => this); // No Error + super(); + } +} \ No newline at end of file diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts new file mode 100644 index 00000000000..1c4af98f0a2 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts @@ -0,0 +1,9 @@ +class Base { + constructor(func: ()=>Base) { + } +} +class Super extends Base { + constructor() { + super((() => this)); // No error + } +} \ No newline at end of file From c2fb6944041c5d5d3c05cd041518059782839d30 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 17:19:03 -0700 Subject: [PATCH 04/36] Update baselines --- .../checkSuperCallBeforeThisAccessing1.js | 33 +++++++++++ ...checkSuperCallBeforeThisAccessing1.symbols | 28 ++++++++++ .../checkSuperCallBeforeThisAccessing1.types | 31 ++++++++++ ...ckSuperCallBeforeThisAccessing2.errors.txt | 16 ++++++ .../checkSuperCallBeforeThisAccessing2.js | 33 +++++++++++ .../checkSuperCallBeforeThisAccessing3.js | 43 ++++++++++++++ ...checkSuperCallBeforeThisAccessing3.symbols | 38 +++++++++++++ .../checkSuperCallBeforeThisAccessing3.types | 43 ++++++++++++++ .../checkSuperCallBeforeThisAccessing4.js | 52 +++++++++++++++++ ...checkSuperCallBeforeThisAccessing4.symbols | 43 ++++++++++++++ .../checkSuperCallBeforeThisAccessing4.types | 56 +++++++++++++++++++ ...ckSuperCallBeforeThisAccessing5.errors.txt | 13 +++++ .../checkSuperCallBeforeThisAccessing5.js | 31 ++++++++++ .../checkSuperCallBeforeThisAccessing6.js | 36 ++++++++++++ ...checkSuperCallBeforeThisAccessing6.symbols | 20 +++++++ .../checkSuperCallBeforeThisAccessing6.types | 23 ++++++++ .../checkSuperCallBeforeThisAccessing7.js | 30 ++++++++++ ...checkSuperCallBeforeThisAccessing7.symbols | 19 +++++++ .../checkSuperCallBeforeThisAccessing7.types | 22 ++++++++ ...ckSuperCallBeforeThisAccessing8.errors.txt | 16 ++++++ .../checkSuperCallBeforeThisAccessing8.js | 35 ++++++++++++ .../reference/classUpdateTests.errors.txt | 18 ++---- ...derivedClassParameterProperties.errors.txt | 45 ++++++--------- .../derivedClassParameterProperties.js | 4 +- ...rivedClassSuperCallsWithThisArg.errors.txt | 5 +- .../strictModeInConstructor.errors.txt | 12 ++-- .../thisInInvalidContexts.errors.txt | 5 +- .../reference/thisInInvalidContexts.js | 4 +- ...InInvalidContextsExternalModule.errors.txt | 5 +- .../thisInInvalidContextsExternalModule.js | 4 +- .../reference/thisInSuperCall.errors.txt | 7 ++- tests/baselines/reference/thisInSuperCall.js | 4 +- .../reference/thisInSuperCall2.errors.txt | 7 ++- tests/baselines/reference/thisInSuperCall2.js | 4 +- tests/cases/compiler/thisInSuperCall.ts | 2 +- tests/cases/compiler/thisInSuperCall2.ts | 2 +- .../derivedClassParameterProperties.ts | 2 +- .../thisKeyword/thisInInvalidContexts.ts | 2 +- .../thisInInvalidContextsExternalModule.ts | 2 +- 39 files changed, 725 insertions(+), 70 deletions(-) create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js new file mode 100644 index 00000000000..ec6e6e39ee8 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.js @@ -0,0 +1,33 @@ +//// [checkSuperCallBeforeThisAccessing1.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + super(); + this; + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing1.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 Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + _super.call(this); + this; + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols new file mode 100644 index 00000000000..008d1156b56 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) + + constructor() { + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 0)) + + this; +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing1.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing1.ts, 7, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing1.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types new file mode 100644 index 00000000000..f6114d28997 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing1.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + super(); +>super() : void +>super : typeof Based + + this; +>this : Derived + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : Derived +>x : number +>10 : number + + var that = this; +>that : Derived +>this : Derived + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt new file mode 100644 index 00000000000..2c9473976a4 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: 'super' has to be called before 'this' accessing. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== + class Based { } + class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + ~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. + this.x = 10; + var that = this; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js new file mode 100644 index 00000000000..eb58afd820b --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.js @@ -0,0 +1,33 @@ +//// [checkSuperCallBeforeThisAccessing2.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + this.x = 100; + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing2.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 Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + this.x = 100; + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js new file mode 100644 index 00000000000..2c5652cf95f --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.js @@ -0,0 +1,43 @@ +//// [checkSuperCallBeforeThisAccessing3.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + class innver { + public y: boolean; + constructor() { + this.y = true; + } + } + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing3.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 Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + var innver = (function () { + function innver() { + this.y = true; + } + return innver; + })(); + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols new file mode 100644 index 00000000000..8dd68fc3b74 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.symbols @@ -0,0 +1,38 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) + + constructor() { + class innver { +>innver : Symbol(innver, Decl(checkSuperCallBeforeThisAccessing3.ts, 3, 19)) + + public y: boolean; +>y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) + + constructor() { + this.y = true; +>this.y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) +>this : Symbol(innver, Decl(checkSuperCallBeforeThisAccessing3.ts, 3, 19)) +>y : Symbol(y, Decl(checkSuperCallBeforeThisAccessing3.ts, 4, 22)) + } + } + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 0)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing3.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing3.ts, 12, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing3.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types new file mode 100644 index 00000000000..45077a6fe5e --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing3.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + class innver { +>innver : innver + + public y: boolean; +>y : boolean + + constructor() { + this.y = true; +>this.y = true : boolean +>this.y : boolean +>this : innver +>y : boolean +>true : boolean + } + } + super(); +>super() : void +>super : typeof Based + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : Derived +>x : number +>10 : number + + var that = this; +>that : Derived +>this : Derived + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js new file mode 100644 index 00000000000..eacec00c438 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.js @@ -0,0 +1,52 @@ +//// [checkSuperCallBeforeThisAccessing4.ts] +class Based { } +class Derived extends Based { + public x: number; + constructor() { + (() => { + this; // No error + }); + () => { + this; // No error + }; + (() => { + this; // No error + })(); + super(); + super(); + this.x = 10; + var that = this; + } +} + +//// [checkSuperCallBeforeThisAccessing4.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 Based = (function () { + function Based() { + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + var _this = this; + (function () { + _this; // No error + }); + (function () { + _this; // No error + }); + (function () { + _this; // No error + })(); + _super.call(this); + _super.call(this); + this.x = 10; + var that = this; + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols new file mode 100644 index 00000000000..7101280358d --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts === +class Based { } +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + +class Derived extends Based { +>Derived : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) +>Based : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + public x: number; +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) + + constructor() { + (() => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + }); + () => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + }; + (() => { + this; // No error +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + + })(); + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + super(); +>super : Symbol(Based, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 0)) + + this.x = 10; +>this.x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) +>x : Symbol(x, Decl(checkSuperCallBeforeThisAccessing4.ts, 1, 29)) + + var that = this; +>that : Symbol(that, Decl(checkSuperCallBeforeThisAccessing4.ts, 16, 11)) +>this : Symbol(Derived, Decl(checkSuperCallBeforeThisAccessing4.ts, 0, 15)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types new file mode 100644 index 00000000000..965d09a4109 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing4.ts === +class Based { } +>Based : Based + +class Derived extends Based { +>Derived : Derived +>Based : Based + + public x: number; +>x : number + + constructor() { + (() => { +>(() => { this; // No error }) : () => void +>() => { this; // No error } : () => void + + this; // No error +>this : Derived + + }); + () => { +>() => { this; // No error } : () => void + + this; // No error +>this : Derived + + }; + (() => { +>(() => { this; // No error })() : void +>(() => { this; // No error }) : () => void +>() => { this; // No error } : () => void + + this; // No error +>this : Derived + + })(); + super(); +>super() : void +>super : typeof Based + + super(); +>super() : void +>super : typeof Based + + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : Derived +>x : number +>10 : number + + var that = this; +>that : Derived +>this : Derived + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt new file mode 100644 index 00000000000..fa5cfd524cb --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: 'super' has to be called before 'this' accessing. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== + class Based { constructor(...arg) { } } + class Derived extends Based { + public x: number; + constructor() { + super(this.x); + ~~~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js new file mode 100644 index 00000000000..489c7200050 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.js @@ -0,0 +1,31 @@ +//// [checkSuperCallBeforeThisAccessing5.ts] +class Based { constructor(...arg) { } } +class Derived extends Based { + public x: number; + constructor() { + super(this.x); + } +} + +//// [checkSuperCallBeforeThisAccessing5.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 Based = (function () { + function Based() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Based; +})(); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + _super.call(this, this.x); + } + return Derived; +})(Based); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js new file mode 100644 index 00000000000..6ad9773bc5f --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.js @@ -0,0 +1,36 @@ +//// [checkSuperCallBeforeThisAccessing6.ts] +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + (() => this); // No Error + super(); + } +} + +//// [checkSuperCallBeforeThisAccessing6.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 Base = (function () { + function Base() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Base; +})(); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var _this = this; + (function () { return _this; }); // No Error + _super.call(this); + } + return Super; +})(Base); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols new file mode 100644 index 00000000000..84bac5775ec --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts === +class Base { +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + + constructor(...arg) { +>arg : Symbol(arg, Decl(checkSuperCallBeforeThisAccessing6.ts, 1, 16)) + } +} +class Super extends Base { +>Super : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing6.ts, 3, 1)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + + constructor() { + (() => this); // No Error +>this : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing6.ts, 3, 1)) + + super(); +>super : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing6.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types new file mode 100644 index 00000000000..8e2d285d85b --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing6.ts === +class Base { +>Base : Base + + constructor(...arg) { +>arg : any[] + } +} +class Super extends Base { +>Super : Super +>Base : Base + + constructor() { + (() => this); // No Error +>(() => this) : () => Super +>() => this : () => Super +>this : Super + + super(); +>super() : void +>super : typeof Base + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js new file mode 100644 index 00000000000..eafc662085f --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.js @@ -0,0 +1,30 @@ +//// [checkSuperCallBeforeThisAccessing7.ts] +class Base { + constructor(func: ()=>Base) { + } +} +class Super extends Base { + constructor() { + super((() => this)); // No error + } +} + +//// [checkSuperCallBeforeThisAccessing7.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 Base = (function () { + function Base(func) { + } + return Base; +})(); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var _this = this; + _super.call(this, (function () { return _this; })); // No error + } + return Super; +})(Base); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols new file mode 100644 index 00000000000..3611429d2b2 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts === +class Base { +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + + constructor(func: ()=>Base) { +>func : Symbol(func, Decl(checkSuperCallBeforeThisAccessing7.ts, 1, 16)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + } +} +class Super extends Base { +>Super : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing7.ts, 3, 1)) +>Base : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) + + constructor() { + super((() => this)); // No error +>super : Symbol(Base, Decl(checkSuperCallBeforeThisAccessing7.ts, 0, 0)) +>this : Symbol(Super, Decl(checkSuperCallBeforeThisAccessing7.ts, 3, 1)) + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types new file mode 100644 index 00000000000..fa5e7dbe857 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/checkSuperCallBeforeThisAccessing7.ts === +class Base { +>Base : Base + + constructor(func: ()=>Base) { +>func : () => Base +>Base : Base + } +} +class Super extends Base { +>Super : Super +>Base : Base + + constructor() { + super((() => this)); // No error +>super((() => this)) : void +>super : typeof Base +>(() => this) : () => Super +>() => this : () => Super +>this : Super + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt new file mode 100644 index 00000000000..f7c763ee708 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. + + +==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== + class Base { + constructor(...arg) { + } + } + class Super extends Base { + constructor() { + var that = this; + super(); + ~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js new file mode 100644 index 00000000000..4675d328b38 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.js @@ -0,0 +1,35 @@ +//// [checkSuperCallBeforeThisAccessing8.ts] +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + var that = this; + super(); + } +} + +//// [checkSuperCallBeforeThisAccessing8.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 Base = (function () { + function Base() { + var arg = []; + for (var _i = 0; _i < arguments.length; _i++) { + arg[_i - 0] = arguments[_i]; + } + } + return Base; +})(); +var Super = (function (_super) { + __extends(Super, _super); + function Super() { + var that = this; + _super.call(this); + } + return Super; +})(Base); diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index 59e9bc9ced1..55965756410 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/classUpdateTests.ts(34,2): error TS2377: Constructors for derived classes must contain a 'super' call. tests/cases/compiler/classUpdateTests.ts(43,18): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/compiler/classUpdateTests.ts(57,2): 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/compiler/classUpdateTests.ts(59,3): 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/compiler/classUpdateTests.ts(63,7): error TS2415: Class 'L' incorrectly extends base class 'G'. Property 'p1' is private in type 'L' but not in type 'G'. tests/cases/compiler/classUpdateTests.ts(69,7): error TS2415: Class 'M' incorrectly extends base class 'G'. Property 'p1' is private in type 'M' but not in type 'G'. -tests/cases/compiler/classUpdateTests.ts(70,2): 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/compiler/classUpdateTests.ts(72,3): 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/compiler/classUpdateTests.ts(93,3): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(95,1): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(99,3): error TS1128: Declaration or statement expected. @@ -80,14 +80,11 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st class K extends G { constructor(public p1:number) { // ERROR - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; - ~~~~~~~~~~~~ super(); - ~~~~~~~~~~ - } - ~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + } } class L extends G { @@ -104,14 +101,11 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st !!! error TS2415: Class 'M' incorrectly extends base class 'G'. !!! error TS2415: Property 'p1' is private in type 'M' but not in type 'G'. constructor(private p1:number) { // ERROR - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; - ~~~~~~~~~~~~ super(); - ~~~~~~~~~~ - } - ~~ + ~~~~~~~~ !!! 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/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 0dba0d24cb0..7b57951d493 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,10 +1,11 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(15,5): 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(30,5): 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(56,5): 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(79,5): 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(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 TS17006: 'super' has to be called before 'this' accessing. +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(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 (4 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts (5 errors) ==== // ordering of super calls in derived constructors matters depending on other class contents class Base { @@ -20,14 +21,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived2 extends Base { constructor(public y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = 1; - ~~~~~~~~~~~~~~~~~~ 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. + } } class Derived3 extends Base { @@ -40,14 +38,11 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived4 extends Base { a = 1; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ var b = 2; - ~~~~~~~~~~~~~~~~~~ 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. + } } class Derived5 extends Base { @@ -63,7 +58,9 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing + ~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } @@ -71,16 +68,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; - ~~~~~~~~~~~~~~~~~~~ this.b = 3; - ~~~~~~~~~~~~~~~~~~~ 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. + } } class Derived8 extends Base { @@ -100,16 +93,12 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { - ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; - ~~~~~~~~~~~~~~~~~~~ this.b = 3; - ~~~~~~~~~~~~~~~~~~~ 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. + } } class Derived10 extends Base2 { diff --git a/tests/baselines/reference/derivedClassParameterProperties.js b/tests/baselines/reference/derivedClassParameterProperties.js index 55c0a312b71..0d4a476af12 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.js +++ b/tests/baselines/reference/derivedClassParameterProperties.js @@ -47,7 +47,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing } } @@ -155,7 +155,7 @@ var Derived6 = (function (_super) { function Derived6(y) { this.a = 1; var b = 2; - _super.call(this); // ok + _super.call(this); // error: "super" has to be called before "this" accessing } return Derived6; })(Base); diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index ef43d1d6f52..d8b724e3d0f 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,8 +1,9 @@ +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. 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(20,21): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (2 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (3 errors) ==== class Base { x: string; constructor(a) { } @@ -11,6 +12,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived extends Base { constructor() { super(this); // ok + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index 9a80732842a..3c38530cc12 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/strictModeInConstructor.ts(27,5): 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/compiler/strictModeInConstructor.ts(29,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/compiler/strictModeInConstructor.ts (1 errors) ==== @@ -29,16 +29,12 @@ tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' c public s: number = 9; constructor () { - ~~~~~~~~~~~~~~~~ var x = 1; // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ - "use strict"; - ~~~~~~~~~~~~~~~~~~~~~ - } - ~~~~~ + ~~~~~~~~ !!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + "use strict"; + } } class Bs extends A { diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 76b90ed7c20..0200ae6f84c 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,4 +1,5 @@ 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 TS17006: 'super' has to be called before 'this' accessing. 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(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. @@ -23,7 +24,9 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInInvalidContexts.js b/tests/baselines/reference/thisInInvalidContexts.js index d5ba69ff536..66cbdb9682c 100644 --- a/tests/baselines/reference/thisInInvalidContexts.js +++ b/tests/baselines/reference/thisInInvalidContexts.js @@ -12,7 +12,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error } } @@ -70,7 +70,7 @@ var ClassWithNoInitializer = (function (_super) { __extends(ClassWithNoInitializer, _super); //'this' in optional super call function ClassWithNoInitializer() { - _super.call(this, this); // OK + _super.call(this, this); // Error } return ClassWithNoInitializer; })(BaseErrClass); diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 2aa474d4cdc..ced387a453b 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,4 +1,5 @@ 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 TS17006: 'super' has to be called before 'this' accessing. 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(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. @@ -24,7 +25,9 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.js b/tests/baselines/reference/thisInInvalidContextsExternalModule.js index 31a2e995a18..df3abd156de 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.js +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.js @@ -12,7 +12,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing } } @@ -71,7 +71,7 @@ var ClassWithNoInitializer = (function (_super) { __extends(ClassWithNoInitializer, _super); //'this' in optional super call function ClassWithNoInitializer() { - _super.call(this, this); // OK + _super.call(this, this); // error: "super" has to be called before "this" accessing } return ClassWithNoInitializer; })(BaseErrClass); diff --git a/tests/baselines/reference/thisInSuperCall.errors.txt b/tests/baselines/reference/thisInSuperCall.errors.txt index 57255aa9582..d0be13d8adc 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,15 +1,18 @@ +tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: 'super' has to be called before 'this' accessing. tests/cases/compiler/thisInSuperCall.ts(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/compiler/thisInSuperCall.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== class Base { constructor(x: any) {} } class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInSuperCall.js b/tests/baselines/reference/thisInSuperCall.js index f7d7ca4e4fd..0bcaf35fcbf 100644 --- a/tests/baselines/reference/thisInSuperCall.js +++ b/tests/baselines/reference/thisInSuperCall.js @@ -5,7 +5,7 @@ class Base { class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } @@ -36,7 +36,7 @@ var Base = (function () { var Foo = (function (_super) { __extends(Foo, _super); function Foo() { - _super.call(this, this); // no error + _super.call(this, this); // error: "super" has to be called before "this" accessing } return Foo; })(Base); diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index d3a94f79487..0559f83eb90 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,7 +1,8 @@ +tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/compiler/thisInSuperCall2.ts (1 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -9,7 +10,9 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing + ~~~~~~~~~~~~ +!!! error TS17006: 'super' has to be called before 'this' accessing. } } diff --git a/tests/baselines/reference/thisInSuperCall2.js b/tests/baselines/reference/thisInSuperCall2.js index a9bbeda9fe7..8957a089210 100644 --- a/tests/baselines/reference/thisInSuperCall2.js +++ b/tests/baselines/reference/thisInSuperCall2.js @@ -6,7 +6,7 @@ class Base { class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } @@ -33,7 +33,7 @@ var Base = (function () { var Foo = (function (_super) { __extends(Foo, _super); function Foo() { - _super.call(this, this); // no error + _super.call(this, this); // error: "super" has to be called before "this" accessing } return Foo; })(Base); diff --git a/tests/cases/compiler/thisInSuperCall.ts b/tests/cases/compiler/thisInSuperCall.ts index 6a54e9ac6f1..b7df7cbafad 100644 --- a/tests/cases/compiler/thisInSuperCall.ts +++ b/tests/cases/compiler/thisInSuperCall.ts @@ -4,7 +4,7 @@ class Base { class Foo extends Base { constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/compiler/thisInSuperCall2.ts b/tests/cases/compiler/thisInSuperCall2.ts index 5de7c34cf32..2869ab9a805 100644 --- a/tests/cases/compiler/thisInSuperCall2.ts +++ b/tests/cases/compiler/thisInSuperCall2.ts @@ -5,7 +5,7 @@ class Base { class Foo extends Base { public x: number; constructor() { - super(this); // no error + super(this); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts index edfd7ab4f8c..a054ed0f683 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts @@ -46,7 +46,7 @@ class Derived6 extends Base { constructor(y: string) { this.a = 1; var b = 2; - super(); // ok + super(); // error: "super" has to be called before "this" accessing } } diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts index 0afbc450040..2b929318c13 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts @@ -11,7 +11,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // Error } } diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts index 513e56977df..e3d8ce9f5fc 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts @@ -11,7 +11,7 @@ class ClassWithNoInitializer extends BaseErrClass { t; //'this' in optional super call constructor() { - super(this); // OK + super(this); // error: "super" has to be called before "this" accessing } } From 680a8932203ea345f74c7e81b87077fab225f128 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 15 Sep 2015 17:19:19 -0700 Subject: [PATCH 05/36] Add tests --- .../compiler/checkSuperCallBeforeThisAccessing8.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts new file mode 100644 index 00000000000..230b40fc24d --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts @@ -0,0 +1,10 @@ +class Base { + constructor(...arg) { + } +} +class Super extends Base { + constructor() { + var that = this; + super(); + } +} \ No newline at end of file From a7688592b2aef3678f10ef246d0f2e49854ae1d1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 6 Oct 2015 19:46:46 -0700 Subject: [PATCH 06/36] Address PR feedback Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/types.ts --- src/compiler/checker.ts | 17 ++++++++++------- src/compiler/diagnosticMessages.json | 4 ++-- src/compiler/types.ts | 3 ++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b328a4c8366..fb47d6bd57c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6859,9 +6859,8 @@ namespace ts { // (()=>this); // No Error // super(); // } - if ((container).hasSeenSuperBeforeThis === undefined) { - (container).hasSeenSuperBeforeThis = false; - } + let nodeLinks = getNodeLinks(container); + nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; } // Now skip arrow functions to get the "real" owner of 'this'. @@ -9605,8 +9604,12 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { let containgFunction = getContainingFunction(node.expression); - if (containgFunction && containgFunction.kind === SyntaxKind.Constructor && (containgFunction).hasSeenSuperBeforeThis === undefined) { - (containgFunction).hasSeenSuperBeforeThis = true; + + if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { + let nodeLinks = getNodeLinks(containgFunction); + if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { + nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; + } } return voidType; } @@ -11208,9 +11211,9 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!node.hasSeenSuperBeforeThis) { + else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)){ // In ES6, super inside constructor of class-declaration has to precede "this" accessing - error(superCallStatement, Diagnostics.super_has_to_be_called_before_this_accessing); + error(superCallStatement, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class); } } else if (baseConstructorType !== nullType) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 51a4e2c6c8f..4bf83bd3e45 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2540,8 +2540,8 @@ "category": "Error", "code": 17007 }, - "'super' has to be called before 'this' accessing.": { + "'super' must be called before accessing 'this' in the constructor of a derived class.": { "category": "Error", - "code": 17006 + "code": 17008 } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5a216f8bbcd..9aded35059a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -695,7 +695,6 @@ namespace ts { // @kind(SyntaxKind.Constructor) export interface ConstructorDeclaration extends FunctionLikeDeclaration, ClassElement { body?: FunctionBody; - hasSeenSuperBeforeThis: boolean; // TODDO (yuisu): comment } // For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. @@ -2031,6 +2030,8 @@ 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 the 'super' is used before 'this' in constructor function + HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' } /* @internal */ From c0f818f1a2c0025a0e06983698ee354ffe6ab862 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 6 Oct 2015 19:47:17 -0700 Subject: [PATCH 07/36] Update baseline for new message --- .../reference/checkSuperCallBeforeThisAccessing2.errors.txt | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing5.errors.txt | 4 ++-- .../reference/checkSuperCallBeforeThisAccessing8.errors.txt | 4 ++-- .../reference/derivedClassParameterProperties.errors.txt | 4 ++-- .../reference/derivedClassSuperCallsWithThisArg.errors.txt | 4 ++-- tests/baselines/reference/thisInInvalidContexts.errors.txt | 4 ++-- .../reference/thisInInvalidContextsExternalModule.errors.txt | 4 ++-- tests/baselines/reference/thisInSuperCall.errors.txt | 4 ++-- tests/baselines/reference/thisInSuperCall2.errors.txt | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt index 2c9473976a4..6fdb2e3e394 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 TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts (1 errors) ==== @@ -9,7 +9,7 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: this.x = 100; super(); ~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. this.x = 10; var that = this; } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt index fa5cfd524cb..edd7745a03c 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 TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts (1 errors) ==== @@ -8,6 +8,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: constructor() { super(this.x); ~~~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: '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 f7c763ee708..39db87d41a1 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 TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. ==== tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: var that = this; super(); ~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: '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/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index 7b57951d493..c5d853dec56 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,6 +1,6 @@ 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 TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(49,9): error TS17006: '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(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. @@ -60,7 +60,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP var b = 2; super(); // error: "super" has to be called before "this" accessing ~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index d8b724e3d0f..e72dbe293e9 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: '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(20,21): error TS2332: 'this' cannot be referenced in current location. @@ -13,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS constructor() { super(this); // ok ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: '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 0200ae6f84c..09fa952e2c2 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,5 +1,5 @@ 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 TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,9): error TS17006: '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(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. @@ -26,7 +26,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): constructor() { super(this); // Error ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: '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 ced387a453b..9909c0cbfe9 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,5 +1,5 @@ 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 TS17006: 'super' has to be called before 'this' accessing. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,9): error TS17006: '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(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. @@ -27,7 +27,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: '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 d0be13d8adc..ea4b6fd742a 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: '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(20,15): error TS2332: 'this' cannot be referenced in current location. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 0559f83eb90..7130ee8deb8 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: 'super' has to be called before 'this' accessing. +tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: '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. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' has to be called before 'this' accessing. +!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. } } From 319a9cd4309f69e3dcac367eb87e3a1e46dbf6a5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 30 Nov 2015 10:30:03 -0800 Subject: [PATCH 08/36] Update baseline with new error message number and fix space and comment --- src/compiler/checker.ts | 9 ++++----- src/compiler/types.ts | 2 +- .../checkSuperCallBeforeThisAccessing1.types | 8 ++++---- .../checkSuperCallBeforeThisAccessing2.errors.txt | 4 ++-- .../checkSuperCallBeforeThisAccessing3.types | 8 ++++---- .../checkSuperCallBeforeThisAccessing4.types | 12 ++++++------ .../checkSuperCallBeforeThisAccessing5.errors.txt | 4 ++-- .../checkSuperCallBeforeThisAccessing6.types | 6 +++--- .../checkSuperCallBeforeThisAccessing7.types | 6 +++--- .../checkSuperCallBeforeThisAccessing8.errors.txt | 4 ++-- .../derivedClassParameterProperties.errors.txt | 4 ++-- .../derivedClassSuperCallsWithThisArg.errors.txt | 4 ++-- .../reference/thisInInvalidContexts.errors.txt | 6 +++--- .../thisInInvalidContextsExternalModule.errors.txt | 6 +++--- tests/baselines/reference/thisInSuperCall.errors.txt | 4 ++-- .../baselines/reference/thisInSuperCall2.errors.txt | 4 ++-- 16 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fb47d6bd57c..0488b1b6dd1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6848,7 +6848,6 @@ namespace ts { let container = getThisContainer(node, /* includeArrowFunctions */ true); 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 @@ -6859,7 +6858,7 @@ namespace ts { // (()=>this); // No Error // super(); // } - let nodeLinks = getNodeLinks(container); + const nodeLinks = getNodeLinks(container); nodeLinks.flags |= NodeCheckFlags.HasSeenThisCall; } @@ -9603,10 +9602,10 @@ namespace ts { const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { - let containgFunction = getContainingFunction(node.expression); + const containgFunction = getContainingFunction(node.expression); if (containgFunction && containgFunction.kind === SyntaxKind.Constructor) { - let nodeLinks = getNodeLinks(containgFunction); + const nodeLinks = getNodeLinks(containgFunction); if (!(nodeLinks.flags & NodeCheckFlags.HasSeenThisCall)) { nodeLinks.flags |= NodeCheckFlags.HasSeenSuperBeforeThis; } @@ -11211,7 +11210,7 @@ namespace ts { markThisReferencesAsErrors(superCallStatement.expression); } } - else if (!(getNodeCheckFlags(node) & NodeCheckFlags.HasSeenSuperBeforeThis)){ + 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); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9aded35059a..9a82891df77 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2030,7 +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 the 'super' is used before 'this' in constructor function + HasSeenSuperBeforeThis = 0x00020000, // Set during the binding if 'super' is used before 'this' in constructor function HasSeenThisCall = 0x00040000, // Set during the binding when encounter 'this' } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types index f6114d28997..d734b0c6ad0 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing1.types @@ -15,17 +15,17 @@ class Derived extends Based { >super : typeof Based this; ->this : Derived +>this : this this.x = 10; >this.x = 10 : number >this.x : number ->this : Derived +>this : this >x : number >10 : number var that = this; ->that : Derived ->this : Derived +>that : this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing2.errors.txt index 6fdb2e3e394..e48f43c8662 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 TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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 (1 errors) ==== @@ -9,7 +9,7 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing2.ts(6,9): error TS17006: this.x = 100; super(); ~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. this.x = 10; var that = this; } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types index 45077a6fe5e..c4e9e15ed8e 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing3.types @@ -20,7 +20,7 @@ class Derived extends Based { this.y = true; >this.y = true : boolean >this.y : boolean ->this : innver +>this : this >y : boolean >true : boolean } @@ -32,12 +32,12 @@ class Derived extends Based { this.x = 10; >this.x = 10 : number >this.x : number ->this : Derived +>this : this >x : number >10 : number var that = this; ->that : Derived ->this : Derived +>that : this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types index 965d09a4109..f42a0ac8563 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing4.types @@ -15,14 +15,14 @@ class Derived extends Based { >() => { this; // No error } : () => void this; // No error ->this : Derived +>this : this }); () => { >() => { this; // No error } : () => void this; // No error ->this : Derived +>this : this }; (() => { @@ -31,7 +31,7 @@ class Derived extends Based { >() => { this; // No error } : () => void this; // No error ->this : Derived +>this : this })(); super(); @@ -45,12 +45,12 @@ class Derived extends Based { this.x = 10; >this.x = 10 : number >this.x : number ->this : Derived +>this : this >x : number >10 : number var that = this; ->that : Derived ->this : Derived +>that : this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing5.errors.txt index edd7745a03c..1258101cffc 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 TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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 (1 errors) ==== @@ -8,6 +8,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing5.ts(5,9): error TS17006: constructor() { super(this.x); ~~~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! 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/checkSuperCallBeforeThisAccessing6.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types index 8e2d285d85b..826dab0c400 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing6.types @@ -12,9 +12,9 @@ class Super extends Base { constructor() { (() => this); // No Error ->(() => this) : () => Super ->() => this : () => Super ->this : Super +>(() => this) : () => this +>() => this : () => this +>this : this super(); >super() : void diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types index fa5e7dbe857..11d2ab26d20 100644 --- a/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing7.types @@ -15,8 +15,8 @@ class Super extends Base { super((() => this)); // No error >super((() => this)) : void >super : typeof Base ->(() => this) : () => Super ->() => this : () => Super ->this : Super +>(() => this) : () => this +>() => this : () => this +>this : this } } diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing8.errors.txt index 39db87d41a1..7a00a4f0130 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 TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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 (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/compiler/checkSuperCallBeforeThisAccessing8.ts(8,9): error TS17006: var that = this; super(); ~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! 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/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index c5d853dec56..37f272db082 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,6 +1,6 @@ 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 TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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(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(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. @@ -60,7 +60,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP var b = 2; super(); // error: "super" has to be called before "this" accessing ~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index e72dbe293e9..0190a659166 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(20,21): error TS2332: 'this' cannot be referenced in current location. @@ -13,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS constructor() { super(this); // ok ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! 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 09fa952e2c2..d74db892019 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,5 +1,5 @@ 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 TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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(22,15): error TS2332: 'this' cannot be referenced in current location. 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. @@ -8,7 +8,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 (7 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -26,7 +26,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): constructor() { super(this); // Error ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! 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 9909c0cbfe9..c4188993eee 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,5 +1,5 @@ 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 TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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(22,15): error TS2332: 'this' cannot be referenced in current location. 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. @@ -9,7 +9,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 (8 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -27,7 +27,7 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! 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 ea4b6fd742a..f0fc5854123 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall.ts(7,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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(14,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be referenced in current location. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS2332: 'this' cannot be r constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 7130ee8deb8..11ea23d020c 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/thisInSuperCall2.ts(8,9): error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +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(16,15): error TS2332: 'this' cannot be referenced in current location. @@ -12,7 +12,7 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS2332: 'this' cannot be constructor() { super(this); // error: "super" has to be called before "this" accessing ~~~~~~~~~~~~ -!!! error TS17006: 'super' must be called before accessing 'this' in the constructor of a derived class. +!!! error TS17008: 'super' must be called before accessing 'this' in the constructor of a derived class. } } From 7ad3cb74d4806a6deb6ea44c5c1a8d5d329ea52e Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 16 Dec 2015 18:13:15 -0800 Subject: [PATCH 09/36] 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 ce2495f39812ec51402ddb3f8881b5f189eed17c Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 17 Dec 2015 17:21:21 -0800 Subject: [PATCH 10/36] 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 From 4d3f6e76b8bf4155c78fe849c917c61db40cf3a3 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 25 Jan 2016 10:32:34 -0800 Subject: [PATCH 11/36] Error for Promise redeclaration in module with async --- src/compiler/checker.ts | 74 ++++++++++++++++--- src/compiler/diagnosticMessages.json | 6 +- src/compiler/emitter.ts | 8 +- .../asyncAliasReturnType_es6.errors.txt | 10 --- .../reference/asyncAliasReturnType_es6.js | 2 +- .../asyncAliasReturnType_es6.symbols | 11 +++ .../reference/asyncAliasReturnType_es6.types | 11 +++ .../reference/asyncArrowFunction1_es6.js | 2 +- .../reference/asyncArrowFunction6_es6.js | 2 +- .../reference/asyncArrowFunction7_es6.js | 4 +- .../reference/asyncArrowFunction8_es6.js | 2 +- ...asyncArrowFunctionCapturesArguments_es6.js | 2 +- .../asyncArrowFunctionCapturesThis_es6.js | 2 +- .../asyncAwaitIsolatedModules_es6.js | 48 ++++++------ tests/baselines/reference/asyncAwait_es6.js | 48 ++++++------ .../asyncFunctionDeclaration11_es6.js | 2 +- .../asyncFunctionDeclaration13_es6.js | 2 +- .../asyncFunctionDeclaration14_es6.js | 2 +- .../asyncFunctionDeclaration15_es6.errors.txt | 17 +---- .../asyncFunctionDeclaration15_es6.js | 38 +++++----- .../asyncFunctionDeclaration1_es6.js | 2 +- .../asyncFunctionDeclaration6_es6.js | 2 +- .../asyncFunctionDeclaration7_es6.js | 4 +- .../asyncFunctionDeclaration9_es6.js | 2 +- .../reference/asyncFunctionsAcrossFiles.js | 8 +- .../reference/asyncImportedPromise_es6.js | 5 +- .../reference/asyncMethodWithSuper_es6.js | 4 +- tests/baselines/reference/asyncMultiFile.js | 4 +- .../reference/asyncQualifiedReturnType_es6.js | 2 +- .../reference/awaitBinaryExpression1_es6.js | 2 +- .../reference/awaitBinaryExpression2_es6.js | 2 +- .../reference/awaitBinaryExpression3_es6.js | 2 +- .../reference/awaitBinaryExpression4_es6.js | 2 +- .../reference/awaitBinaryExpression5_es6.js | 2 +- .../reference/awaitCallExpression1_es6.js | 2 +- .../reference/awaitCallExpression2_es6.js | 2 +- .../reference/awaitCallExpression3_es6.js | 2 +- .../reference/awaitCallExpression4_es6.js | 2 +- .../reference/awaitCallExpression5_es6.js | 2 +- .../reference/awaitCallExpression6_es6.js | 2 +- .../reference/awaitCallExpression7_es6.js | 2 +- .../reference/awaitCallExpression8_es6.js | 2 +- tests/baselines/reference/awaitUnion_es6.js | 2 +- .../reference/reachabilityChecks7.js | 12 +-- 44 files changed, 212 insertions(+), 154 deletions(-) delete mode 100644 tests/baselines/reference/asyncAliasReturnType_es6.errors.txt create mode 100644 tests/baselines/reference/asyncAliasReturnType_es6.symbols create mode 100644 tests/baselines/reference/asyncAliasReturnType_es6.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ca41e509664..b3876b9732d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -376,8 +376,8 @@ namespace ts { const moduleAugmentation = moduleName.parent; if (moduleAugmentation.symbol.valueDeclaration !== moduleAugmentation) { // this is a combined symbol for multiple augmentations within the same file. - // its symbol already has accumulated information for all declarations - // so we need to add it just once - do the work only for first declaration + // its symbol already has accumulated information for all declarations + // so we need to add it just once - do the work only for first declaration Debug.assert(moduleAugmentation.symbol.declarations.length > 1); return; } @@ -386,7 +386,7 @@ namespace ts { mergeSymbolTable(globals, moduleAugmentation.symbol.exports); } else { - // find a module that about to be augmented + // find a module that about to be augmented let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found); if (!mainModule) { return; @@ -810,7 +810,7 @@ namespace ts { } // No static member is present. - // Check if we're in an instance method and look for a relevant instance member. + // Check if we're in an instance method and look for a relevant instance member. if (location === container && !(location.flags & NodeFlags.Static)) { const instanceType = (getDeclaredTypeOfSymbol(classSymbol)).thisType; if (getPropertyOfType(instanceType, name)) { @@ -1161,7 +1161,7 @@ namespace ts { return getMergedSymbol(sourceFile.symbol); } if (moduleNotFoundError) { - // report errors only if it was requested + // report errors only if it was requested error(moduleReferenceLiteral, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); } return undefined; @@ -2471,10 +2471,21 @@ namespace ts { function getDeclarationContainer(node: Node): Node { node = getRootDeclaration(node); + while (node) { + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.VariableDeclarationList: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.NamedImports: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportClause: + node = node.parent; + break; - // Parent chain: - // VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container' - return node.kind === SyntaxKind.VariableDeclaration ? node.parent.parent.parent : node.parent; + default: + return node.parent; + } + } } function getTypeOfPrototypeProperty(prototype: Symbol): Type { @@ -11359,6 +11370,9 @@ namespace ts { checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); } } + else if (isAsyncFunctionLike(node)) { + checkAsyncFunctionReturnType(node); + } } } @@ -12283,6 +12297,21 @@ namespace ts { return unknownType; } + if (languageVersion >= ScriptTarget.ES6) { + const promisedType = getPromisedType(promiseType); + if (!promisedType) { + error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType)); + return unknownType; + } + + const promiseInstantiation = createPromiseType(promisedType); + if (!checkTypeAssignableTo(promiseInstantiation, promiseType, node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) { + return unknownType; + } + + return promisedType; + } + const promiseConstructor = getNodeLinks(node.type).resolvedSymbol; if (!promiseConstructor || !symbolIsValue(promiseConstructor)) { const typeName = promiseConstructor @@ -12457,6 +12486,7 @@ namespace ts { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } @@ -12641,6 +12671,25 @@ namespace ts { } } + function checkCollisionWithGlobalPromiseInGeneratedCode(node: Node, name: Identifier): void { + if (!needCollisionCheckForIdentifier(node, name, "Promise")) { + return; + } + + // Uninstantiated modules shouldnt do this check + if (node.kind === SyntaxKind.ModuleDeclaration && getModuleInstanceState(node) !== ModuleInstanceState.Instantiated) { + return; + } + + // In case of variable declaration, node.parent is variable statement so look at the variable statement's parent + const parent = getDeclarationContainer(node); + if (parent.kind === SyntaxKind.SourceFile && isExternalOrCommonJsModule(parent) && parent.flags & NodeFlags.HasAsyncFunctions) { + // If the declaration happens to be in external module, report error that require and exports are reserved keywords + error(name, Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module_containing_async_functions, + declarationNameToString(name), declarationNameToString(name)); + } + } + function checkVarDeclaredNamesNotShadowed(node: VariableDeclaration | BindingElement) { // - ScriptBody : StatementList // It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList @@ -12819,6 +12868,7 @@ namespace ts { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } @@ -13584,6 +13634,7 @@ namespace ts { checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } checkTypeParameters(node.typeParameters); checkExportsOnMergedDeclarations(node); @@ -14090,6 +14141,7 @@ namespace ts { checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); @@ -14194,6 +14246,7 @@ namespace ts { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); const symbol = getSymbolOfNode(node); @@ -14224,10 +14277,10 @@ namespace ts { if (isAmbientExternalModule) { if (isExternalModuleAugmentation(node)) { // body of the augmentation should be checked for consistency only if augmentation was applied to its target (either global scope or module) - // otherwise we'll be swamped in cascading errors. + // otherwise we'll be swamped in cascading errors. // We can detect if augmentation was applied using following rules: // - augmentation for a global scope is always applied - // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). + // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). const checkBody = isGlobalAugmentation || (getSymbolOfNode(node).flags & SymbolFlags.Merged); if (checkBody) { // body of ambient external module is always a module block @@ -14386,6 +14439,7 @@ namespace ts { function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkAliasSymbol(node); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8fd40f7b421..b8defa6325b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -794,7 +794,7 @@ "A decorator can only decorate a method implementation, not an overload.": { "category": "Error", "code": 1249 - }, + }, "'with' statements are not allowed in an async function block.": { "category": "Error", "code": 1300 @@ -1687,6 +1687,10 @@ "category": "Error", "code": 2528 }, + "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of a module containing async functions.": { + "category": "Error", + "code": 2529 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 762b491155b..e85b76160c7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -320,7 +320,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { const awaiterHelper = ` var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } @@ -4541,11 +4541,11 @@ const _super = (function (geti, seti) { write(", void 0, "); } - if (promiseConstructor) { - emitEntityNameAsExpression(promiseConstructor, /*useFallback*/ false); + if (languageVersion >= ScriptTarget.ES6 || !promiseConstructor) { + write("void 0"); } else { - write("Promise"); + emitEntityNameAsExpression(promiseConstructor, /*useFallback*/ false); } // Emit the call to __awaiter. diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt b/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt deleted file mode 100644 index ec532d1380d..00000000000 --- a/tests/baselines/reference/asyncAliasReturnType_es6.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts(3,16): error TS1055: Type 'PromiseAlias' is not a valid async function return type. - - -==== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts (1 errors) ==== - type PromiseAlias = Promise; - - async function f(): PromiseAlias { - ~ -!!! error TS1055: Type 'PromiseAlias' is not a valid async function return type. - } \ No newline at end of file diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.js b/tests/baselines/reference/asyncAliasReturnType_es6.js index 0af63b0bfa6..45fe3228f6e 100644 --- a/tests/baselines/reference/asyncAliasReturnType_es6.js +++ b/tests/baselines/reference/asyncAliasReturnType_es6.js @@ -6,6 +6,6 @@ async function f(): PromiseAlias { //// [asyncAliasReturnType_es6.js] function f() { - return __awaiter(this, void 0, PromiseAlias, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.symbols b/tests/baselines/reference/asyncAliasReturnType_es6.symbols new file mode 100644 index 00000000000..4d6db6a1ef4 --- /dev/null +++ b/tests/baselines/reference/asyncAliasReturnType_es6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts === +type PromiseAlias = Promise; +>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0)) +>T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18)) +>Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(asyncAliasReturnType_es6.ts, 0, 18)) + +async function f(): PromiseAlias { +>f : Symbol(f, Decl(asyncAliasReturnType_es6.ts, 0, 34)) +>PromiseAlias : Symbol(PromiseAlias, Decl(asyncAliasReturnType_es6.ts, 0, 0)) +} diff --git a/tests/baselines/reference/asyncAliasReturnType_es6.types b/tests/baselines/reference/asyncAliasReturnType_es6.types new file mode 100644 index 00000000000..8426d2a3542 --- /dev/null +++ b/tests/baselines/reference/asyncAliasReturnType_es6.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/async/es6/asyncAliasReturnType_es6.ts === +type PromiseAlias = Promise; +>PromiseAlias : Promise +>T : T +>Promise : Promise +>T : T + +async function f(): PromiseAlias { +>f : () => Promise +>PromiseAlias : Promise +} diff --git a/tests/baselines/reference/asyncArrowFunction1_es6.js b/tests/baselines/reference/asyncArrowFunction1_es6.js index 4f03acc5ced..0026cd91a7e 100644 --- a/tests/baselines/reference/asyncArrowFunction1_es6.js +++ b/tests/baselines/reference/asyncArrowFunction1_es6.js @@ -4,5 +4,5 @@ var foo = async (): Promise => { }; //// [asyncArrowFunction1_es6.js] -var foo = () => __awaiter(this, void 0, Promise, function* () { +var foo = () => __awaiter(this, void 0, void 0, function* () { }); diff --git a/tests/baselines/reference/asyncArrowFunction6_es6.js b/tests/baselines/reference/asyncArrowFunction6_es6.js index 54b8aa1f6b1..a01e53f5b11 100644 --- a/tests/baselines/reference/asyncArrowFunction6_es6.js +++ b/tests/baselines/reference/asyncArrowFunction6_es6.js @@ -4,5 +4,5 @@ var foo = async (a = await): Promise => { } //// [asyncArrowFunction6_es6.js] -var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () { +var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { }); diff --git a/tests/baselines/reference/asyncArrowFunction7_es6.js b/tests/baselines/reference/asyncArrowFunction7_es6.js index ac68a8fd2f8..fab705c0b76 100644 --- a/tests/baselines/reference/asyncArrowFunction7_es6.js +++ b/tests/baselines/reference/asyncArrowFunction7_es6.js @@ -7,8 +7,8 @@ var bar = async (): Promise => { } //// [asyncArrowFunction7_es6.js] -var bar = () => __awaiter(this, void 0, Promise, function* () { +var bar = () => __awaiter(this, void 0, void 0, function* () { // 'await' here is an identifier, and not an await expression. - var foo = (a = yield ) => __awaiter(this, void 0, Promise, function* () { + var foo = (a = yield ) => __awaiter(this, void 0, void 0, function* () { }); }); diff --git a/tests/baselines/reference/asyncArrowFunction8_es6.js b/tests/baselines/reference/asyncArrowFunction8_es6.js index 9cee5ee1525..0c33cfcfa2d 100644 --- a/tests/baselines/reference/asyncArrowFunction8_es6.js +++ b/tests/baselines/reference/asyncArrowFunction8_es6.js @@ -5,6 +5,6 @@ var foo = async (): Promise => { } //// [asyncArrowFunction8_es6.js] -var foo = () => __awaiter(this, void 0, Promise, function* () { +var foo = () => __awaiter(this, void 0, void 0, function* () { var v = { [yield ]: foo }; }); diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js index fdaa365836d..ca79eed6c8e 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js +++ b/tests/baselines/reference/asyncArrowFunctionCapturesArguments_es6.js @@ -11,6 +11,6 @@ class C { class C { method() { function other() { } - var fn = () => __awaiter(this, arguments, Promise, function* () { return yield other.apply(this, arguments); }); + var fn = () => __awaiter(this, arguments, void 0, function* () { return yield other.apply(this, arguments); }); } } diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js index 0f09e366ef3..de7eb23ed78 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.js @@ -9,6 +9,6 @@ class C { //// [asyncArrowFunctionCapturesThis_es6.js] class C { method() { - var fn = () => __awaiter(this, void 0, Promise, function* () { return yield this; }); + var fn = () => __awaiter(this, void 0, void 0, function* () { return yield this; }); } } diff --git a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js index 213ecfd53a6..4022fde7f54 100644 --- a/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js +++ b/tests/baselines/reference/asyncAwaitIsolatedModules_es6.js @@ -41,7 +41,7 @@ module M { //// [asyncAwaitIsolatedModules_es6.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } @@ -49,65 +49,65 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; function f0() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } let f4 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f5 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f6 = function () { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; -let f7 = () => __awaiter(this, void 0, Promise, function* () { }); -let f8 = () => __awaiter(this, void 0, Promise, function* () { }); -let f9 = () => __awaiter(this, void 0, MyPromise, function* () { }); -let f10 = () => __awaiter(this, void 0, Promise, function* () { return p; }); -let f11 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; }); +let f7 = () => __awaiter(this, void 0, void 0, function* () { }); +let f8 = () => __awaiter(this, void 0, void 0, function* () { }); +let f9 = () => __awaiter(this, void 0, void 0, function* () { }); +let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; }); +let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; }); let o = { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } }; class C { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m4() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m5() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m6() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } } var M; (function (M) { function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } M.f1 = f1; })(M || (M = {})); diff --git a/tests/baselines/reference/asyncAwait_es6.js b/tests/baselines/reference/asyncAwait_es6.js index 14dfc7fc9aa..be2eb90e3e4 100644 --- a/tests/baselines/reference/asyncAwait_es6.js +++ b/tests/baselines/reference/asyncAwait_es6.js @@ -41,7 +41,7 @@ module M { //// [asyncAwait_es6.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } @@ -49,65 +49,65 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; function f0() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } function f3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } let f4 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f5 = function () { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; let f6 = function () { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }; -let f7 = () => __awaiter(this, void 0, Promise, function* () { }); -let f8 = () => __awaiter(this, void 0, Promise, function* () { }); -let f9 = () => __awaiter(this, void 0, MyPromise, function* () { }); -let f10 = () => __awaiter(this, void 0, Promise, function* () { return p; }); -let f11 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f12 = () => __awaiter(this, void 0, Promise, function* () { return mp; }); -let f13 = () => __awaiter(this, void 0, MyPromise, function* () { return p; }); +let f7 = () => __awaiter(this, void 0, void 0, function* () { }); +let f8 = () => __awaiter(this, void 0, void 0, function* () { }); +let f9 = () => __awaiter(this, void 0, void 0, function* () { }); +let f10 = () => __awaiter(this, void 0, void 0, function* () { return p; }); +let f11 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f12 = () => __awaiter(this, void 0, void 0, function* () { return mp; }); +let f13 = () => __awaiter(this, void 0, void 0, function* () { return p; }); let o = { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); }, m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } }; class C { m1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } m3() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m4() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m5() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } static m6() { - return __awaiter(this, void 0, MyPromise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } } var M; (function (M) { function f1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } M.f1 = f1; })(M || (M = {})); diff --git a/tests/baselines/reference/asyncFunctionDeclaration11_es6.js b/tests/baselines/reference/asyncFunctionDeclaration11_es6.js index a44343cef78..6fe8921434c 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration11_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration11_es6.js @@ -4,6 +4,6 @@ async function await(): Promise { //// [asyncFunctionDeclaration11_es6.js] function await() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration13_es6.js b/tests/baselines/reference/asyncFunctionDeclaration13_es6.js index 4257c8691c2..6fab6c39947 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration13_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration13_es6.js @@ -7,7 +7,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration13_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { // Legal to use 'await' in a type context. var v; }); diff --git a/tests/baselines/reference/asyncFunctionDeclaration14_es6.js b/tests/baselines/reference/asyncFunctionDeclaration14_es6.js index f32d106f92e..f584f917842 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration14_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration14_es6.js @@ -5,7 +5,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration14_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { return; }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt index bc1ef24127a..d014f9eecf3 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt @@ -1,17 +1,12 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,16): error TS1055: Type '{}' is not a valid async function return type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,16): error TS1055: Type 'any' is not a valid async function return type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,16): error TS1055: Type 'number' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,16): error TS1055: Type 'PromiseLike' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'typeof Thenable' is not a valid async function return type. - Type 'Thenable' is not assignable to type 'PromiseLike'. - Types of property 'then' are incompatible. - Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. - Type 'void' is not assignable to type 'PromiseLike'. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'Thenable' is not a valid async function return type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member. -==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (7 errors) ==== +==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (6 errors) ==== declare class Thenable { then(): void; } declare let a: any; declare let obj: { then: string; }; @@ -27,15 +22,9 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1 ~~~ !!! error TS1055: Type 'number' is not a valid async function return type. async function fn5(): PromiseLike { } // error - ~~~ -!!! error TS1055: Type 'PromiseLike' is not a valid async function return type. async function fn6(): Thenable { } // error ~~~ -!!! error TS1055: Type 'typeof Thenable' is not a valid async function return type. -!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike'. -!!! error TS1055: Types of property 'then' are incompatible. -!!! error TS1055: Type '() => void' is not assignable to type '{ (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; (onfulfilled?: (value: any) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; }'. -!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike'. +!!! error TS1055: Type 'Thenable' is not a valid async function return type. async function fn7() { return; } // valid: Promise async function fn8() { return 1; } // valid: Promise async function fn9() { return null; } // valid: Promise diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.js b/tests/baselines/reference/asyncFunctionDeclaration15_es6.js index c72062e24b2..174a95d6f66 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.js @@ -26,59 +26,59 @@ async function fn19() { await thenable; } // error //// [asyncFunctionDeclaration15_es6.js] function fn1() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // valid: Promise function fn2() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn3() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn4() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn5() { - return __awaiter(this, void 0, PromiseLike, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn6() { - return __awaiter(this, void 0, Thenable, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } // error function fn7() { - return __awaiter(this, void 0, Promise, function* () { return; }); + return __awaiter(this, void 0, void 0, function* () { return; }); } // valid: Promise function fn8() { - return __awaiter(this, void 0, Promise, function* () { return 1; }); + return __awaiter(this, void 0, void 0, function* () { return 1; }); } // valid: Promise function fn9() { - return __awaiter(this, void 0, Promise, function* () { return null; }); + return __awaiter(this, void 0, void 0, function* () { return null; }); } // valid: Promise function fn10() { - return __awaiter(this, void 0, Promise, function* () { return undefined; }); + return __awaiter(this, void 0, void 0, function* () { return undefined; }); } // valid: Promise function fn11() { - return __awaiter(this, void 0, Promise, function* () { return a; }); + return __awaiter(this, void 0, void 0, function* () { return a; }); } // valid: Promise function fn12() { - return __awaiter(this, void 0, Promise, function* () { return obj; }); + return __awaiter(this, void 0, void 0, function* () { return obj; }); } // valid: Promise<{ then: string; }> function fn13() { - return __awaiter(this, void 0, Promise, function* () { return thenable; }); + return __awaiter(this, void 0, void 0, function* () { return thenable; }); } // error function fn14() { - return __awaiter(this, void 0, Promise, function* () { yield 1; }); + return __awaiter(this, void 0, void 0, function* () { yield 1; }); } // valid: Promise function fn15() { - return __awaiter(this, void 0, Promise, function* () { yield null; }); + return __awaiter(this, void 0, void 0, function* () { yield null; }); } // valid: Promise function fn16() { - return __awaiter(this, void 0, Promise, function* () { yield undefined; }); + return __awaiter(this, void 0, void 0, function* () { yield undefined; }); } // valid: Promise function fn17() { - return __awaiter(this, void 0, Promise, function* () { yield a; }); + return __awaiter(this, void 0, void 0, function* () { yield a; }); } // valid: Promise function fn18() { - return __awaiter(this, void 0, Promise, function* () { yield obj; }); + return __awaiter(this, void 0, void 0, function* () { yield obj; }); } // valid: Promise function fn19() { - return __awaiter(this, void 0, Promise, function* () { yield thenable; }); + return __awaiter(this, void 0, void 0, function* () { yield thenable; }); } // error diff --git a/tests/baselines/reference/asyncFunctionDeclaration1_es6.js b/tests/baselines/reference/asyncFunctionDeclaration1_es6.js index 263e27fa35e..e92d55dc0e2 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration1_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration1_es6.js @@ -4,6 +4,6 @@ async function foo(): Promise { //// [asyncFunctionDeclaration1_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js index 8c37968ab4c..a70316989b3 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration6_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration6_es6.js @@ -4,6 +4,6 @@ async function foo(a = await): Promise { //// [asyncFunctionDeclaration6_es6.js] function foo(a = yield ) { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js index ef66df4e413..0d360fa866c 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration7_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration7_es6.js @@ -7,10 +7,10 @@ async function bar(): Promise { //// [asyncFunctionDeclaration7_es6.js] function bar() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { // 'await' here is an identifier, and not a yield expression. function foo(a = yield ) { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } }); diff --git a/tests/baselines/reference/asyncFunctionDeclaration9_es6.js b/tests/baselines/reference/asyncFunctionDeclaration9_es6.js index 9723a69f2a2..c57c0eb395a 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration9_es6.js +++ b/tests/baselines/reference/asyncFunctionDeclaration9_es6.js @@ -5,7 +5,7 @@ async function foo(): Promise { //// [asyncFunctionDeclaration9_es6.js] function foo() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { var v = { [yield ]: foo }; }); } diff --git a/tests/baselines/reference/asyncFunctionsAcrossFiles.js b/tests/baselines/reference/asyncFunctionsAcrossFiles.js index 7e8a58205e2..94ccff2358c 100644 --- a/tests/baselines/reference/asyncFunctionsAcrossFiles.js +++ b/tests/baselines/reference/asyncFunctionsAcrossFiles.js @@ -17,7 +17,7 @@ export const b = { //// [b.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } @@ -26,13 +26,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; import { a } from './a'; export const b = { - f: () => __awaiter(this, void 0, Promise, function* () { + f: () => __awaiter(this, void 0, void 0, function* () { yield a.f(); }) }; //// [a.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } @@ -41,7 +41,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; import { b } from './b'; export const a = { - f: () => __awaiter(this, void 0, Promise, function* () { + f: () => __awaiter(this, void 0, void 0, function* () { yield b.f(); }) }; diff --git a/tests/baselines/reference/asyncImportedPromise_es6.js b/tests/baselines/reference/asyncImportedPromise_es6.js index dd64c797931..56a41b0283f 100644 --- a/tests/baselines/reference/asyncImportedPromise_es6.js +++ b/tests/baselines/reference/asyncImportedPromise_es6.js @@ -17,16 +17,15 @@ exports.Task = Task; //// [test.js] "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments)).next()); }); }; -var task_1 = require("./task"); class Test { example() { - return __awaiter(this, void 0, task_1.Task, function* () { return; }); + return __awaiter(this, void 0, void 0, function* () { return; }); } } diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.js b/tests/baselines/reference/asyncMethodWithSuper_es6.js index 74d4de79881..eacb0a882b2 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es6.js +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.js @@ -59,7 +59,7 @@ class B extends A { // async method with only call/get on 'super' does not require a binding simple() { const _super = name => super[name]; - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { // call with property access _super("x").call(this); // call with element access @@ -76,7 +76,7 @@ class B extends A { const cache = Object.create(null); return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); })(name => super[name], (name, value) => super[name] = value); - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { const f = () => { }; // call with property access _super("x").value.call(this); diff --git a/tests/baselines/reference/asyncMultiFile.js b/tests/baselines/reference/asyncMultiFile.js index 6229c29f02c..cbf3445ecc9 100644 --- a/tests/baselines/reference/asyncMultiFile.js +++ b/tests/baselines/reference/asyncMultiFile.js @@ -7,7 +7,7 @@ function g() { } //// [a.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } @@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; function f() { - return __awaiter(this, void 0, Promise, function* () { }); + return __awaiter(this, void 0, void 0, function* () { }); } //// [b.js] function g() { } diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.js b/tests/baselines/reference/asyncQualifiedReturnType_es6.js index 1da37946254..4d5aa87bbff 100644 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.js +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.js @@ -15,6 +15,6 @@ var X; X.MyPromise = MyPromise; })(X || (X = {})); function f() { - return __awaiter(this, void 0, X.MyPromise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } diff --git a/tests/baselines/reference/awaitBinaryExpression1_es6.js b/tests/baselines/reference/awaitBinaryExpression1_es6.js index 8deb771f5ab..a19e94353d5 100644 --- a/tests/baselines/reference/awaitBinaryExpression1_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression1_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression1_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield p) || a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression2_es6.js b/tests/baselines/reference/awaitBinaryExpression2_es6.js index 506af50a0ef..7fb1a70446b 100644 --- a/tests/baselines/reference/awaitBinaryExpression2_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression2_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression2_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield p) && a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression3_es6.js b/tests/baselines/reference/awaitBinaryExpression3_es6.js index 4b298d7b947..f845ce12421 100644 --- a/tests/baselines/reference/awaitBinaryExpression3_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression3_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression3_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield p) + a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression4_es6.js b/tests/baselines/reference/awaitBinaryExpression4_es6.js index 4d313588984..b6e14c82487 100644 --- a/tests/baselines/reference/awaitBinaryExpression4_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression4_es6.js @@ -9,7 +9,7 @@ async function func(): Promise { //// [awaitBinaryExpression4_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = yield p, a; "after"; diff --git a/tests/baselines/reference/awaitBinaryExpression5_es6.js b/tests/baselines/reference/awaitBinaryExpression5_es6.js index 01d6c50f6f0..65a5bbfee77 100644 --- a/tests/baselines/reference/awaitBinaryExpression5_es6.js +++ b/tests/baselines/reference/awaitBinaryExpression5_es6.js @@ -10,7 +10,7 @@ async function func(): Promise { //// [awaitBinaryExpression5_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var o; o.a = yield p; diff --git a/tests/baselines/reference/awaitCallExpression1_es6.js b/tests/baselines/reference/awaitCallExpression1_es6.js index f9dad87a8b6..aeeb598e3bf 100644 --- a/tests/baselines/reference/awaitCallExpression1_es6.js +++ b/tests/baselines/reference/awaitCallExpression1_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression1_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression2_es6.js b/tests/baselines/reference/awaitCallExpression2_es6.js index 87d99cd0793..b41735275a8 100644 --- a/tests/baselines/reference/awaitCallExpression2_es6.js +++ b/tests/baselines/reference/awaitCallExpression2_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression2_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = fn(yield p, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression3_es6.js b/tests/baselines/reference/awaitCallExpression3_es6.js index f397d83c3a1..74dee3e7e42 100644 --- a/tests/baselines/reference/awaitCallExpression3_es6.js +++ b/tests/baselines/reference/awaitCallExpression3_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression3_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = fn(a, yield p, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression4_es6.js b/tests/baselines/reference/awaitCallExpression4_es6.js index d8824d7e7a0..682a1776ac5 100644 --- a/tests/baselines/reference/awaitCallExpression4_es6.js +++ b/tests/baselines/reference/awaitCallExpression4_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression4_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield pfn)(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression5_es6.js b/tests/baselines/reference/awaitCallExpression5_es6.js index f39a633765d..30889b35011 100644 --- a/tests/baselines/reference/awaitCallExpression5_es6.js +++ b/tests/baselines/reference/awaitCallExpression5_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression5_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = o.fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression6_es6.js b/tests/baselines/reference/awaitCallExpression6_es6.js index de8477fa938..55d86119d64 100644 --- a/tests/baselines/reference/awaitCallExpression6_es6.js +++ b/tests/baselines/reference/awaitCallExpression6_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression6_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = o.fn(yield p, a, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression7_es6.js b/tests/baselines/reference/awaitCallExpression7_es6.js index 24edc3b9393..df805266ff3 100644 --- a/tests/baselines/reference/awaitCallExpression7_es6.js +++ b/tests/baselines/reference/awaitCallExpression7_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression7_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = o.fn(a, yield p, a); "after"; diff --git a/tests/baselines/reference/awaitCallExpression8_es6.js b/tests/baselines/reference/awaitCallExpression8_es6.js index 8bee6112a7a..8d7bb4b83ce 100644 --- a/tests/baselines/reference/awaitCallExpression8_es6.js +++ b/tests/baselines/reference/awaitCallExpression8_es6.js @@ -13,7 +13,7 @@ async function func(): Promise { //// [awaitCallExpression8_es6.js] function func() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { "before"; var b = (yield po).fn(a, a, a); "after"; diff --git a/tests/baselines/reference/awaitUnion_es6.js b/tests/baselines/reference/awaitUnion_es6.js index 80c68f811ef..9603454b969 100644 --- a/tests/baselines/reference/awaitUnion_es6.js +++ b/tests/baselines/reference/awaitUnion_es6.js @@ -14,7 +14,7 @@ async function f() { //// [awaitUnion_es6.js] function f() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { let await_a = yield a; let await_b = yield b; let await_c = yield c; diff --git a/tests/baselines/reference/reachabilityChecks7.js b/tests/baselines/reference/reachabilityChecks7.js index 75338742700..0a6b5b0dac7 100644 --- a/tests/baselines/reference/reachabilityChecks7.js +++ b/tests/baselines/reference/reachabilityChecks7.js @@ -32,7 +32,7 @@ let x1 = () => { use("Test"); } //// [reachabilityChecks7.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new P(function (resolve, reject) { + return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } @@ -41,26 +41,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; // async function without return type annotation - error function f1() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } let x = function () { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); }; // async function with which promised type is void - return can be omitted function f2() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } function f3(x) { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { if (x) return 10; }); } function f4() { - return __awaiter(this, void 0, Promise, function* () { + return __awaiter(this, void 0, void 0, function* () { }); } function voidFunc() { From 35044d1293edf8fdec5a406a8a502bf84a860e6b Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 26 Jan 2016 12:47:53 -0800 Subject: [PATCH 12/36] Added error when return type is not the global Promise --- src/compiler/checker.ts | 57 ++++++++++++++++++---------- src/compiler/diagnosticMessages.json | 4 ++ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bc4fcb5aa1e..140099938c8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2629,7 +2629,7 @@ namespace ts { } } else if (declaration.kind === SyntaxKind.Parameter) { - // If it's a parameter, see if the parent has a jsdoc comment with an @param + // If it's a parameter, see if the parent has a jsdoc comment with an @param // annotation. const paramTag = getCorrespondingJSDocParameterTag(declaration); if (paramTag && paramTag.typeExpression) { @@ -2644,7 +2644,7 @@ namespace ts { function getTypeForVariableLikeDeclaration(declaration: VariableLikeDeclaration): Type { if (declaration.parserContextFlags & ParserContextFlags.JavaScriptFile) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has - // one as its type), otherwise fallback to the below standard TS codepaths to + // one as its type), otherwise fallback to the below standard TS codepaths to // try to figure it out. const type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -4069,7 +4069,7 @@ namespace ts { const isJSConstructSignature = isJSDocConstructSignature(declaration); let returnType: Type = undefined; - // If this is a JSDoc construct signature, then skip the first parameter in the + // If this is a JSDoc construct signature, then skip the first parameter in the // parameter list. The first parameter represents the return type of the construct // signature. for (let i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) { @@ -4472,7 +4472,7 @@ namespace ts { } if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) { - // A JSDocTypeReference may have resolved to a value (as opposed to a type). In + // A JSDocTypeReference may have resolved to a value (as opposed to a type). In // that case, the type of this reference is just the type of the value we resolved // to. return getTypeOfSymbol(symbol); @@ -10479,7 +10479,7 @@ namespace ts { /* *TypeScript Specification 1.0 (6.3) - July 2014 - * An explicitly typed function whose return type isn't the Void type, + * An explicitly typed function whose return type isn't the Void type, * the Any type, or a union type containing the Void or Any type as a constituent * must have at least one return statement somewhere in its body. * An exception to this rule is if the function implementation consists of a single 'throw' statement. @@ -12508,6 +12508,33 @@ namespace ts { } } + /** + * Checks that the return type provided is an instantiation of the global Promise type + * and returns the awaited type of the return type. + */ + function checkCorrectPromiseType(returnType: Type, location: Node) { + if (returnType === unknownType) { + // The return type already had some other error, so we ignore and return + // the unknown type. + return unknownType; + } + + const globalPromiseType = getGlobalPromiseType(); + if (globalPromiseType === emptyGenericType + || globalPromiseType === getTargetType(returnType)) { + // Either we couldn't resolve the global promise type, which would have already + // reported an error, or we could resolve it and the return type is a valid type + // reference to the global type. In either case, we return the awaited type for + // the return type. + return checkAwaitedType(returnType, location, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + } + + // The promise type was not a valid type reference to the global promise type, so we + // report an error and return the unknown type. + error(location, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T); + return unknownType; + } + /** * Checks the return type of an async function to ensure it is a compatible * Promise implementation. @@ -12522,6 +12549,11 @@ namespace ts { * callable `then` signature. */ function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type { + if (languageVersion >= ScriptTarget.ES6) { + const returnType = getTypeFromTypeNode(node.type); + return checkCorrectPromiseType(returnType, node.type); + } + const globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType(); if (globalPromiseConstructorLikeType === emptyObjectType) { // If we couldn't resolve the global PromiseConstructorLike type we cannot verify @@ -12563,21 +12595,6 @@ namespace ts { return unknownType; } - if (languageVersion >= ScriptTarget.ES6) { - const promisedType = getPromisedType(promiseType); - if (!promisedType) { - error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType)); - return unknownType; - } - - const promiseInstantiation = createPromiseType(promisedType); - if (!checkTypeAssignableTo(promiseInstantiation, promiseType, node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) { - return unknownType; - } - - return promisedType; - } - const promiseConstructor = getNodeLinks(node.type).resolvedSymbol; if (!promiseConstructor || !symbolIsValue(promiseConstructor)) { const typeName = promiseConstructor diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b8defa6325b..f5e6254a040 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -195,6 +195,10 @@ "category": "Error", "code": 1063 }, + "The return type of an async function or method must be the global Promise.": { + "category": "Error", + "code": 1064 + }, "In ambient enum declarations member initializer must be constant expression.": { "category": "Error", "code": 1066 From c20a70529ea49574ac929e1eb49fe93ee40d962c Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 26 Jan 2016 14:51:07 -0800 Subject: [PATCH 13/36] Updated baselines --- .../asyncFunctionDeclaration15_es6.errors.txt | 29 ++++++++++--------- .../asyncImportedPromise_es6.errors.txt | 13 +++++++++ .../reference/asyncImportedPromise_es6.js | 8 ++--- .../asyncImportedPromise_es6.symbols | 20 ------------- .../reference/asyncImportedPromise_es6.types | 20 ------------- .../asyncQualifiedReturnType_es6.errors.txt | 13 +++++++++ .../asyncQualifiedReturnType_es6.symbols | 17 ----------- .../asyncQualifiedReturnType_es6.types | 17 ----------- 8 files changed, 46 insertions(+), 91 deletions(-) create mode 100644 tests/baselines/reference/asyncImportedPromise_es6.errors.txt delete mode 100644 tests/baselines/reference/asyncImportedPromise_es6.symbols delete mode 100644 tests/baselines/reference/asyncImportedPromise_es6.types create mode 100644 tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt delete mode 100644 tests/baselines/reference/asyncQualifiedReturnType_es6.symbols delete mode 100644 tests/baselines/reference/asyncQualifiedReturnType_es6.types diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt index d014f9eecf3..7b682f9dcde 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt @@ -1,30 +1,33 @@ -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,16): error TS1055: Type '{}' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,16): error TS1055: Type 'any' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,16): error TS1055: Type 'number' is not a valid async function return type. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,16): error TS1055: Type 'Thenable' is not a valid async function return type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member. -==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (6 errors) ==== +==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts (7 errors) ==== declare class Thenable { then(): void; } declare let a: any; declare let obj: { then: string; }; declare let thenable: Thenable; async function fn1() { } // valid: Promise async function fn2(): { } { } // error - ~~~ -!!! error TS1055: Type '{}' is not a valid async function return type. + ~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise. async function fn3(): any { } // error - ~~~ -!!! error TS1055: Type 'any' is not a valid async function return type. + ~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise. async function fn4(): number { } // error - ~~~ -!!! error TS1055: Type 'number' is not a valid async function return type. + ~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise. async function fn5(): PromiseLike { } // error + ~~~~~~~~~~~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise. async function fn6(): Thenable { } // error - ~~~ -!!! error TS1055: Type 'Thenable' is not a valid async function return type. + ~~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise. async function fn7() { return; } // valid: Promise async function fn8() { return 1; } // valid: Promise async function fn9() { return null; } // valid: Promise diff --git a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt new file mode 100644 index 00000000000..994445dbedd --- /dev/null +++ b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise. + + +==== tests/cases/conformance/async/es6/task.ts (0 errors) ==== + export class Task extends Promise { } + +==== tests/cases/conformance/async/es6/test.ts (1 errors) ==== + import { Task } from "./task"; + class Test { + async example(): Task { return; } + ~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncImportedPromise_es6.js b/tests/baselines/reference/asyncImportedPromise_es6.js index a97d59f7e64..56a41b0283f 100644 --- a/tests/baselines/reference/asyncImportedPromise_es6.js +++ b/tests/baselines/reference/asyncImportedPromise_es6.js @@ -1,12 +1,12 @@ //// [tests/cases/conformance/async/es6/asyncImportedPromise_es6.ts] //// //// [task.ts] -export class Task extends Promise { } +export class Task extends Promise { } //// [test.ts] -import { Task } from "./task"; -class Test { - async example(): Task { return; } +import { Task } from "./task"; +class Test { + async example(): Task { return; } } //// [task.js] diff --git a/tests/baselines/reference/asyncImportedPromise_es6.symbols b/tests/baselines/reference/asyncImportedPromise_es6.symbols deleted file mode 100644 index 45cf47d2b45..00000000000 --- a/tests/baselines/reference/asyncImportedPromise_es6.symbols +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/conformance/async/es6/task.ts === -export class Task extends Promise { } ->Task : Symbol(Task, Decl(task.ts, 0, 0)) ->T : Symbol(T, Decl(task.ts, 0, 18)) ->Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->T : Symbol(T, Decl(task.ts, 0, 18)) - -=== tests/cases/conformance/async/es6/test.ts === -import { Task } from "./task"; ->Task : Symbol(Task, Decl(test.ts, 0, 8)) - -class Test { ->Test : Symbol(Test, Decl(test.ts, 0, 30)) - - async example(): Task { return; } ->example : Symbol(example, Decl(test.ts, 1, 12)) ->T : Symbol(T, Decl(test.ts, 2, 18)) ->Task : Symbol(Task, Decl(test.ts, 0, 8)) ->T : Symbol(T, Decl(test.ts, 2, 18)) -} diff --git a/tests/baselines/reference/asyncImportedPromise_es6.types b/tests/baselines/reference/asyncImportedPromise_es6.types deleted file mode 100644 index 424f14b34d3..00000000000 --- a/tests/baselines/reference/asyncImportedPromise_es6.types +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/conformance/async/es6/task.ts === -export class Task extends Promise { } ->Task : Task ->T : T ->Promise : Promise ->T : T - -=== tests/cases/conformance/async/es6/test.ts === -import { Task } from "./task"; ->Task : typeof Task - -class Test { ->Test : Test - - async example(): Task { return; } ->example : () => Task ->T : T ->Task : Task ->T : T -} diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt new file mode 100644 index 00000000000..f1d01bb2a7a --- /dev/null +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise. + + +==== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts (1 errors) ==== + namespace X { + export class MyPromise extends Promise { + } + } + + async function f(): X.MyPromise { + ~~~~~~~~~~~~~~~~~ +!!! error TS1064: The return type of an async function or method must be the global Promise. + } \ No newline at end of file diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols b/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols deleted file mode 100644 index 5d27d04ea3b..00000000000 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.symbols +++ /dev/null @@ -1,17 +0,0 @@ -=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts === -namespace X { ->X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0)) - - export class MyPromise extends Promise { ->MyPromise : Symbol(MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13)) ->T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27)) ->Promise : Symbol(Promise, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->T : Symbol(T, Decl(asyncQualifiedReturnType_es6.ts, 1, 27)) - } -} - -async function f(): X.MyPromise { ->f : Symbol(f, Decl(asyncQualifiedReturnType_es6.ts, 3, 1)) ->X : Symbol(X, Decl(asyncQualifiedReturnType_es6.ts, 0, 0)) ->MyPromise : Symbol(X.MyPromise, Decl(asyncQualifiedReturnType_es6.ts, 0, 13)) -} diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.types b/tests/baselines/reference/asyncQualifiedReturnType_es6.types deleted file mode 100644 index 3b438eb93b6..00000000000 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.types +++ /dev/null @@ -1,17 +0,0 @@ -=== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts === -namespace X { ->X : typeof X - - export class MyPromise extends Promise { ->MyPromise : MyPromise ->T : T ->Promise : Promise ->T : T - } -} - -async function f(): X.MyPromise { ->f : () => X.MyPromise ->X : any ->MyPromise : X.MyPromise -} From 39c75fd438ba22371be0072effa9fe89731938ce Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 26 Jan 2016 15:34:53 -0800 Subject: [PATCH 14/36] Simplify giving error message and remove unnecessary error --- src/compiler/checker.ts | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 927e00faf8c..e52982576b6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11471,25 +11471,8 @@ namespace ts { const containingClassSymbol = getSymbolOfNode(containingClassDecl); const containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); const baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); - const statements = (node.body).statements; - let superCallStatement: ExpressionStatement; - let isSuperCallFirstStatment: boolean; - for (const statement of statements) { - if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { - superCallStatement = statement; - if (isSuperCallFirstStatment === undefined) { - isSuperCallFirstStatment = true; - } - } - else if (isSuperCallFirstStatment === undefined && !isPrologueDirective(statement)) { - isSuperCallFirstStatment = false; - } - } - - // The main different between looping through each statement in constructor and calling containsSuperCall is that, - // containsSuperCall will consider "super" inside computed-property for inner class declaration - if (superCallStatement || containsSuperCall(node.body)) { + if (containsSuperCall(node.body)) { if (baseConstructorType === nullType) { error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } @@ -11506,12 +11489,19 @@ namespace ts { // Skip past any prologue directives to find the first statement // to ensure that it was a super call. if (superCallShouldBeFirst) { - if (!isSuperCallFirstStatment) { - error(superCallStatement, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); + const statements = (node.body).statements; + let superCallStatement: ExpressionStatement; + for (const statement of statements) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + superCallStatement = statement; + break; + } + if (!isPrologueDirective(statement)) { + break; + } } - else { - // In such a required super call, it is a compile-time error for argument expressions to reference this. - markThisReferencesAsErrors(superCallStatement.expression); + if (!superCallStatement) { + error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } } } From f4290e1538c21baff189b813dcc0e1c64c3f9a71 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 26 Jan 2016 15:37:19 -0800 Subject: [PATCH 15/36] Update baselines --- .../baselines/reference/baseCheck.errors.txt | 11 +----- .../reference/classUpdateTests.errors.txt | 18 ++++++--- ...derivedClassParameterProperties.errors.txt | 38 +++++++++++++------ ...rivedClassSuperCallsWithThisArg.errors.txt | 8 +--- .../strictModeInConstructor.errors.txt | 10 +++-- .../thisInInvalidContexts.errors.txt | 5 +-- ...InInvalidContextsExternalModule.errors.txt | 5 +-- .../reference/thisInSuperCall.errors.txt | 8 +--- .../reference/thisInSuperCall1.errors.txt | 5 +-- .../reference/thisInSuperCall2.errors.txt | 5 +-- .../reference/thisInSuperCall3.errors.txt | 5 +-- 11 files changed, 53 insertions(+), 65 deletions(-) diff --git a/tests/baselines/reference/baseCheck.errors.txt b/tests/baselines/reference/baseCheck.errors.txt index d4af255c972..c31ba95476a 100644 --- a/tests/baselines/reference/baseCheck.errors.txt +++ b/tests/baselines/reference/baseCheck.errors.txt @@ -1,18 +1,15 @@ 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 TS17009: '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 TS17009: '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 TS17009: '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 (12 errors) ==== +==== tests/cases/compiler/baseCheck.ts (9 errors) ==== class C { constructor(x: number, y: number) { } } class ELoc extends C { constructor(x: number) { @@ -35,20 +32,14 @@ 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 TS17009: '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 TS17009: '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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. function f() { diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index 55965756410..59e9bc9ced1 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -1,11 +1,11 @@ tests/cases/compiler/classUpdateTests.ts(34,2): error TS2377: Constructors for derived classes must contain a 'super' call. tests/cases/compiler/classUpdateTests.ts(43,18): error TS2335: 'super' can only be referenced in a derived class. -tests/cases/compiler/classUpdateTests.ts(59,3): 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/compiler/classUpdateTests.ts(57,2): 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/compiler/classUpdateTests.ts(63,7): error TS2415: Class 'L' incorrectly extends base class 'G'. Property 'p1' is private in type 'L' but not in type 'G'. tests/cases/compiler/classUpdateTests.ts(69,7): error TS2415: Class 'M' incorrectly extends base class 'G'. Property 'p1' is private in type 'M' but not in type 'G'. -tests/cases/compiler/classUpdateTests.ts(72,3): 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/compiler/classUpdateTests.ts(70,2): 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/compiler/classUpdateTests.ts(93,3): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(95,1): error TS1128: Declaration or statement expected. tests/cases/compiler/classUpdateTests.ts(99,3): error TS1128: Declaration or statement expected. @@ -80,11 +80,14 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st class K extends G { constructor(public p1:number) { // ERROR + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; + ~~~~~~~~~~~~ super(); - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~ } + ~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class L extends G { @@ -101,11 +104,14 @@ tests/cases/compiler/classUpdateTests.ts(113,1): error TS1128: Declaration or st !!! error TS2415: Class 'M' incorrectly extends base class 'G'. !!! error TS2415: Property 'p1' is private in type 'M' but not in type 'G'. constructor(private p1:number) { // ERROR + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; + ~~~~~~~~~~~~ super(); - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~ } + ~~ +!!! 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/derivedClassParameterProperties.errors.txt b/tests/baselines/reference/derivedClassParameterProperties.errors.txt index fcaae2ecd22..27bb9af63a1 100644 --- a/tests/baselines/reference/derivedClassParameterProperties.errors.txt +++ b/tests/baselines/reference/derivedClassParameterProperties.errors.txt @@ -1,12 +1,12 @@ -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(15,5): 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(30,5): 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(47,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassParameterProperties.ts(56,5): 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(57,9): error TS17009: '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 TS17009: '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(79,5): 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 TS17009: '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 TS17009: '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 (9 errors) ==== @@ -25,11 +25,14 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived2 extends Base { constructor(public y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = 1; + ~~~~~~~~~~~~~~~~~~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived3 extends Base { @@ -42,11 +45,14 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP class Derived4 extends Base { a = 1; constructor(y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~ var b = 2; + ~~~~~~~~~~~~~~~~~~ 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. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived5 extends Base { @@ -72,16 +78,20 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: '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. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived8 extends Base { @@ -101,16 +111,20 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassP a = 1; b: number; constructor(y: string) { + ~~~~~~~~~~~~~~~~~~~~~~~~ this.a = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. this.b = 3; + ~~~~~~~~~~~~~~~~~~~ ~~~~ !!! error TS17009: '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. + ~~~~~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Derived10 extends Base2 { diff --git a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt index 450d954289a..d381eff17dc 100644 --- a/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt +++ b/tests/baselines/reference/derivedClassSuperCallsWithThisArg.errors.txt @@ -1,10 +1,8 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts(8,15): error TS17009: '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 TS17009: '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 (4 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassSuperCallsWithThisArg.ts (2 errors) ==== class Base { x: string; constructor(a) { } @@ -22,8 +20,6 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS constructor(public a: string) { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -31,8 +27,6 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassS class Derived3 extends Base { constructor(public a: string) { super(() => this); // error - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. } } diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index 3c38530cc12..9a80732842a 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/strictModeInConstructor.ts(29,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/compiler/strictModeInConstructor.ts(27,5): 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/compiler/strictModeInConstructor.ts (1 errors) ==== @@ -29,12 +29,16 @@ tests/cases/compiler/strictModeInConstructor.ts(29,9): error TS2376: A 'super' c public s: number = 9; constructor () { + ~~~~~~~~~~~~~~~~ var x = 1; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. + ~~~~~~~~~~~~~~~~ "use strict"; + ~~~~~~~~~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class Bs extends A { diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 6e4f665a782..d33260fa108 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,6 +1,5 @@ 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,15): error TS17009: '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 TS17009: '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. @@ -9,7 +8,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 (9 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -37,8 +36,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): constructor() { super(this); // Error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: '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 9c8d4748ed0..6c1a257b5ea 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,6 +1,5 @@ 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,15): error TS17009: '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 TS17009: '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. @@ -10,7 +9,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. Consider setting the 'module' compiler option in a 'tsconfig.json' file. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (10 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (9 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -38,8 +37,6 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod constructor() { super(this); // Error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: '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 37a28513cd4..d1eeb1d2b2b 100644 --- a/tests/baselines/reference/thisInSuperCall.errors.txt +++ b/tests/baselines/reference/thisInSuperCall.errors.txt @@ -1,11 +1,9 @@ tests/cases/compiler/thisInSuperCall.ts(7,15): error TS17009: '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 TS17009: '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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall.ts (5 errors) ==== +==== tests/cases/compiler/thisInSuperCall.ts (3 errors) ==== class Base { constructor(x: any) {} } @@ -23,8 +21,6 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17009: 'super' must be c constructor() { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } @@ -33,8 +29,6 @@ tests/cases/compiler/thisInSuperCall.ts(20,15): error TS17009: 'super' must be c constructor(public p) { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: '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 752b0d5c0dc..20bc502ab79 100644 --- a/tests/baselines/reference/thisInSuperCall1.errors.txt +++ b/tests/baselines/reference/thisInSuperCall1.errors.txt @@ -1,8 +1,7 @@ -tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall1.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall1.ts (1 errors) ==== class Base { constructor(a: any) {} } @@ -11,8 +10,6 @@ tests/cases/compiler/thisInSuperCall1.ts(7,15): error TS17009: 'super' must be c constructor(public x: number) { super(this); ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall2.errors.txt b/tests/baselines/reference/thisInSuperCall2.errors.txt index 8e7d49aa7b9..4e4e9b50a8e 100644 --- a/tests/baselines/reference/thisInSuperCall2.errors.txt +++ b/tests/baselines/reference/thisInSuperCall2.errors.txt @@ -1,9 +1,8 @@ tests/cases/compiler/thisInSuperCall2.ts(8,15): error TS17009: '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 TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall2.ts (3 errors) ==== +==== tests/cases/compiler/thisInSuperCall2.ts (2 errors) ==== class Base { constructor(a: any) {} } @@ -23,8 +22,6 @@ tests/cases/compiler/thisInSuperCall2.ts(16,15): error TS17009: 'super' must be constructor() { super(this); // error ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } diff --git a/tests/baselines/reference/thisInSuperCall3.errors.txt b/tests/baselines/reference/thisInSuperCall3.errors.txt index dd54d689562..27a7dc8b25d 100644 --- a/tests/baselines/reference/thisInSuperCall3.errors.txt +++ b/tests/baselines/reference/thisInSuperCall3.errors.txt @@ -1,8 +1,7 @@ -tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS2332: 'this' cannot be referenced in current location. tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -==== tests/cases/compiler/thisInSuperCall3.ts (2 errors) ==== +==== tests/cases/compiler/thisInSuperCall3.ts (1 errors) ==== class Base { constructor(a: any) {} } @@ -13,8 +12,6 @@ tests/cases/compiler/thisInSuperCall3.ts(9,15): error TS17009: 'super' must be c constructor() { super(this); ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - ~~~~ !!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. } } From 655d5c934c2bf258393457551698c7377e3f1faa Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 26 Jan 2016 16:04:40 -0800 Subject: [PATCH 16/36] Comments and messages --- src/compiler/checker.ts | 5 ++++- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 140099938c8..c7de964cdbd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12511,6 +12511,9 @@ namespace ts { /** * Checks that the return type provided is an instantiation of the global Promise type * and returns the awaited type of the return type. + * + * @param returnType The return type of a FunctionLikeDeclaration + * @param location The node on which to report the error. */ function checkCorrectPromiseType(returnType: Type, location: Node) { if (returnType === unknownType) { @@ -12967,7 +12970,7 @@ namespace ts { // In case of variable declaration, node.parent is variable statement so look at the variable statement's parent const parent = getDeclarationContainer(node); if (parent.kind === SyntaxKind.SourceFile && isExternalOrCommonJsModule(parent) && parent.flags & NodeFlags.HasAsyncFunctions) { - // If the declaration happens to be in external module, report error that require and exports are reserved keywords + // If the declaration happens to be in external module, report error that Promise is a reserved identifier. error(name, Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module_containing_async_functions, declarationNameToString(name), declarationNameToString(name)); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f5e6254a040..27ce11f5286 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -195,7 +195,7 @@ "category": "Error", "code": 1063 }, - "The return type of an async function or method must be the global Promise.": { + "The return type of an async function or method must be the global Promise type.": { "category": "Error", "code": 1064 }, From e4ab2db9fb88520e81427e2c6f252fdbb717dcf8 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 26 Jan 2016 10:51:10 -0800 Subject: [PATCH 17/36] Fix find all references for salsa --- src/compiler/checker.ts | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 645b3835b93..a3052d1f124 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -376,8 +376,8 @@ namespace ts { const moduleAugmentation = moduleName.parent; if (moduleAugmentation.symbol.valueDeclaration !== moduleAugmentation) { // this is a combined symbol for multiple augmentations within the same file. - // its symbol already has accumulated information for all declarations - // so we need to add it just once - do the work only for first declaration + // its symbol already has accumulated information for all declarations + // so we need to add it just once - do the work only for first declaration Debug.assert(moduleAugmentation.symbol.declarations.length > 1); return; } @@ -386,7 +386,7 @@ namespace ts { mergeSymbolTable(globals, moduleAugmentation.symbol.exports); } else { - // find a module that about to be augmented + // find a module that about to be augmented let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found); if (!mainModule) { return; @@ -812,7 +812,7 @@ namespace ts { } // No static member is present. - // Check if we're in an instance method and look for a relevant instance member. + // Check if we're in an instance method and look for a relevant instance member. if (location === container && !(location.flags & NodeFlags.Static)) { const instanceType = (getDeclaredTypeOfSymbol(classSymbol)).thisType; if (getPropertyOfType(instanceType, name)) { @@ -1163,7 +1163,7 @@ namespace ts { return getMergedSymbol(sourceFile.symbol); } if (moduleNotFoundError) { - // report errors only if it was requested + // report errors only if it was requested error(moduleReferenceLiteral, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); } return undefined; @@ -2618,7 +2618,7 @@ namespace ts { } } else if (declaration.kind === SyntaxKind.Parameter) { - // If it's a parameter, see if the parent has a jsdoc comment with an @param + // If it's a parameter, see if the parent has a jsdoc comment with an @param // annotation. const paramTag = getCorrespondingJSDocParameterTag(declaration); if (paramTag && paramTag.typeExpression) { @@ -2633,7 +2633,7 @@ namespace ts { function getTypeForVariableLikeDeclaration(declaration: VariableLikeDeclaration): Type { if (declaration.parserContextFlags & ParserContextFlags.JavaScriptFile) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has - // one as its type), otherwise fallback to the below standard TS codepaths to + // one as its type), otherwise fallback to the below standard TS codepaths to // try to figure it out. const type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -4058,7 +4058,7 @@ namespace ts { const isJSConstructSignature = isJSDocConstructSignature(declaration); let returnType: Type = undefined; - // If this is a JSDoc construct signature, then skip the first parameter in the + // If this is a JSDoc construct signature, then skip the first parameter in the // parameter list. The first parameter represents the return type of the construct // signature. for (let i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) { @@ -4461,7 +4461,7 @@ namespace ts { } if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) { - // A JSDocTypeReference may have resolved to a value (as opposed to a type). In + // A JSDocTypeReference may have resolved to a value (as opposed to a type). In // that case, the type of this reference is just the type of the value we resolved // to. return getTypeOfSymbol(symbol); @@ -10404,7 +10404,7 @@ namespace ts { /* *TypeScript Specification 1.0 (6.3) - July 2014 - * An explicitly typed function whose return type isn't the Void type, + * An explicitly typed function whose return type isn't the Void type, * the Any type, or a union type containing the Void or Any type as a constituent * must have at least one return statement somewhere in its body. * An exception to this rule is if the function implementation consists of a single 'throw' statement. @@ -14426,10 +14426,10 @@ namespace ts { if (isAmbientExternalModule) { if (isExternalModuleAugmentation(node)) { // body of the augmentation should be checked for consistency only if augmentation was applied to its target (either global scope or module) - // otherwise we'll be swamped in cascading errors. + // otherwise we'll be swamped in cascading errors. // We can detect if augmentation was applied using following rules: // - augmentation for a global scope is always applied - // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). + // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). const checkBody = isGlobalAugmentation || (getSymbolOfNode(node).flags & SymbolFlags.Merged); if (checkBody) { // body of ambient external module is always a module block @@ -15200,6 +15200,18 @@ namespace ts { return getSymbolOfNode(entityName.parent); } + if (isInJavaScriptFile(entityName) && entityName.parent.kind === SyntaxKind.PropertyAccessExpression) { + const specialPropertyAssignmentKind = getSpecialPropertyAssignmentKind(entityName.parent.parent); + switch (specialPropertyAssignmentKind) { + case SpecialPropertyAssignmentKind.ExportsProperty: + case SpecialPropertyAssignmentKind.ThisProperty: + case SpecialPropertyAssignmentKind.PrototypeProperty: + return getSymbolOfNode(entityName.parent); + case SpecialPropertyAssignmentKind.ModuleExports: + return getSymbolOfNode(entityName.parent.parent); + } + } + if (entityName.parent.kind === SyntaxKind.ExportAssignment) { return resolveEntityName(entityName, /*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); From e4c0c0028704f637a6417b67879132343532a261 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 26 Jan 2016 17:34:30 -0800 Subject: [PATCH 18/36] Fixed typo in diagnostic message name --- 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 c7de964cdbd..5b5196e1210 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12534,7 +12534,7 @@ namespace ts { // The promise type was not a valid type reference to the global promise type, so we // report an error and return the unknown type. - error(location, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T); + error(location, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type); return unknownType; } From b389e9c61984f1ac303e3382b2d3ceaa9a8e0b84 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 27 Jan 2016 12:43:31 -0800 Subject: [PATCH 19/36] Fix for thisProperty --- 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 a3052d1f124..d590f715ed5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15204,9 +15204,9 @@ namespace ts { const specialPropertyAssignmentKind = getSpecialPropertyAssignmentKind(entityName.parent.parent); switch (specialPropertyAssignmentKind) { case SpecialPropertyAssignmentKind.ExportsProperty: - case SpecialPropertyAssignmentKind.ThisProperty: case SpecialPropertyAssignmentKind.PrototypeProperty: return getSymbolOfNode(entityName.parent); + case SpecialPropertyAssignmentKind.ThisProperty: case SpecialPropertyAssignmentKind.ModuleExports: return getSymbolOfNode(entityName.parent.parent); } From 9a6815f3c7887c757cbe5a56dc6f6b4e67f6d2bc Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 27 Jan 2016 13:26:41 -0800 Subject: [PATCH 20/36] add tests --- tests/cases/fourslash/renameJsExports.ts | 12 ++++++++++++ tests/cases/fourslash/renameJsPrototypeProperty.ts | 12 ++++++++++++ tests/cases/fourslash/renameJsThisProperty.ts | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/cases/fourslash/renameJsExports.ts create mode 100644 tests/cases/fourslash/renameJsPrototypeProperty.ts create mode 100644 tests/cases/fourslash/renameJsThisProperty.ts diff --git a/tests/cases/fourslash/renameJsExports.ts b/tests/cases/fourslash/renameJsExports.ts new file mode 100644 index 00000000000..227eebe4a0d --- /dev/null +++ b/tests/cases/fourslash/renameJsExports.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports.[|area|] = function (r) { return r * r; } + +// @Filename: b.js +////var mod = require('./a'); +////var t = mod./**/[|area|](10); + +goTo.marker(); +verify.renameLocations(false, false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsPrototypeProperty.ts b/tests/cases/fourslash/renameJsPrototypeProperty.ts new file mode 100644 index 00000000000..651514859cc --- /dev/null +++ b/tests/cases/fourslash/renameJsPrototypeProperty.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +////} +////bar.prototype.[|x|] = 10; +////var t = new bar(); +////t./**/[|x|] = 11; + +goTo.marker(); +verify.renameLocations(false, false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsThisProperty.ts b/tests/cases/fourslash/renameJsThisProperty.ts new file mode 100644 index 00000000000..aed59d298b1 --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +//// this.[|x|] = 10; +////} +////var t = new bar(); +////t./**/[|x|] = 11; + +goTo.marker(); +verify.renameLocations(false, false); \ No newline at end of file From 646e46e022cddbfe31655ce5f0a40b7603dcca0b Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 27 Jan 2016 13:38:42 -0800 Subject: [PATCH 21/36] Fix build error --- .../asyncFunctionDeclaration15_es6.errors.txt | 20 +++++++++---------- .../asyncImportedPromise_es6.errors.txt | 2 +- .../asyncQualifiedReturnType_es6.errors.txt | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt index 7b682f9dcde..e8d3e7d79b1 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member. @@ -15,19 +15,19 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1 async function fn1() { } // valid: Promise async function fn2(): { } { } // error ~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn3(): any { } // error ~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn4(): number { } // error ~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn5(): PromiseLike { } // error ~~~~~~~~~~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn6(): Thenable { } // error ~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn7() { return; } // valid: Promise async function fn8() { return 1; } // valid: Promise async function fn9() { return null; } // valid: Promise diff --git a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt index 994445dbedd..881b36704a5 100644 --- a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt +++ b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise type. ==== tests/cases/conformance/async/es6/task.ts (0 errors) ==== diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt index f1d01bb2a7a..205ea016736 100644 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise type. ==== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error T async function f(): X.MyPromise { ~~~~~~~~~~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. } \ No newline at end of file From 6648403a8ee56efad0bb47617fd40cee91130d02 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 27 Jan 2016 14:31:21 -0800 Subject: [PATCH 22/36] Updated test baselines --- .../asyncFunctionDeclaration15_es6.errors.txt | 20 +++++++++---------- .../asyncImportedPromise_es6.errors.txt | 4 ++-- .../asyncQualifiedReturnType_es6.errors.txt | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt index 7b682f9dcde..e8d3e7d79b1 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es6.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise. -tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(6,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(7,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(8,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(9,23): error TS1064: The return type of an async function or method must be the global Promise type. +tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(10,23): error TS1064: The return type of an async function or method must be the global Promise type. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(17,16): error TS1059: Return expression in async function does not have a valid callable 'then' member. tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration15_es6.ts(23,25): error TS1058: Operand for 'await' does not have a valid callable 'then' member. @@ -15,19 +15,19 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1 async function fn1() { } // valid: Promise async function fn2(): { } { } // error ~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn3(): any { } // error ~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn4(): number { } // error ~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn5(): PromiseLike { } // error ~~~~~~~~~~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn6(): Thenable { } // error ~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. async function fn7() { return; } // valid: Promise async function fn8() { return 1; } // valid: Promise async function fn9() { return null; } // valid: Promise diff --git a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt index 994445dbedd..43b45482644 100644 --- a/tests/baselines/reference/asyncImportedPromise_es6.errors.txt +++ b/tests/baselines/reference/asyncImportedPromise_es6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type of an async function or method must be the global Promise type. ==== tests/cases/conformance/async/es6/task.ts (0 errors) ==== @@ -9,5 +9,5 @@ tests/cases/conformance/async/es6/test.ts(3,25): error TS1064: The return type o class Test { async example(): Task { return; } ~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. } \ No newline at end of file diff --git a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt index f1d01bb2a7a..205ea016736 100644 --- a/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt +++ b/tests/baselines/reference/asyncQualifiedReturnType_es6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise. +tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error TS1064: The return type of an async function or method must be the global Promise type. ==== tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/conformance/async/es6/asyncQualifiedReturnType_es6.ts(6,21): error T async function f(): X.MyPromise { ~~~~~~~~~~~~~~~~~ -!!! error TS1064: The return type of an async function or method must be the global Promise. +!!! error TS1064: The return type of an async function or method must be the global Promise type. } \ No newline at end of file From 5b68d6559a8e126fac23388e199be29c3dab9a97 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 27 Jan 2016 15:27:11 -0800 Subject: [PATCH 23/36] strip quotes from module names during deduplication --- src/compiler/emitter.ts | 14 ++++++-- .../deduplicateImportsInSystem.errors.txt | 32 ++++++++++++++++++ .../reference/deduplicateImportsInSystem.js | 33 +++++++++++++++++++ .../compiler/deduplicateImportsInSystem.ts | 9 +++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/deduplicateImportsInSystem.errors.txt create mode 100644 tests/baselines/reference/deduplicateImportsInSystem.js create mode 100644 tests/cases/compiler/deduplicateImportsInSystem.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0a40047f686..4d771bd2538 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -7068,14 +7068,22 @@ const _super = (function (geti, seti) { for (let i = 0; i < externalImports.length; i++) { const text = getExternalModuleNameText(externalImports[i], emitRelativePathAsModuleName); - if (hasProperty(groupIndices, text)) { + if (text === undefined) { + continue; + } + + // text should be quoted string + // for deduplication purposes in key remove leading and trailing quotes so 'a' and "a" will be considered the same + const key = text.substr(1, text.length - 2); + + if (hasProperty(groupIndices, key)) { // deduplicate/group entries in dependency list by the dependency name - const groupIndex = groupIndices[text]; + const groupIndex = groupIndices[key]; dependencyGroups[groupIndex].push(externalImports[i]); continue; } else { - groupIndices[text] = dependencyGroups.length; + groupIndices[key] = dependencyGroups.length; dependencyGroups.push([externalImports[i]]); } diff --git a/tests/baselines/reference/deduplicateImportsInSystem.errors.txt b/tests/baselines/reference/deduplicateImportsInSystem.errors.txt new file mode 100644 index 00000000000..d1bfe88160e --- /dev/null +++ b/tests/baselines/reference/deduplicateImportsInSystem.errors.txt @@ -0,0 +1,32 @@ +tests/cases/compiler/deduplicateImportsInSystem.ts(1,17): error TS2307: Cannot find module 'f1'. +tests/cases/compiler/deduplicateImportsInSystem.ts(2,17): error TS2307: Cannot find module 'f2'. +tests/cases/compiler/deduplicateImportsInSystem.ts(3,17): error TS2307: Cannot find module 'f3'. +tests/cases/compiler/deduplicateImportsInSystem.ts(4,17): error TS2307: Cannot find module 'f2'. +tests/cases/compiler/deduplicateImportsInSystem.ts(5,17): error TS2307: Cannot find module 'f2'. +tests/cases/compiler/deduplicateImportsInSystem.ts(6,17): error TS2307: Cannot find module 'f1'. +tests/cases/compiler/deduplicateImportsInSystem.ts(8,1): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/deduplicateImportsInSystem.ts (7 errors) ==== + import {A} from "f1"; + ~~~~ +!!! error TS2307: Cannot find module 'f1'. + import {B} from "f2"; + ~~~~ +!!! error TS2307: Cannot find module 'f2'. + import {C} from "f3"; + ~~~~ +!!! error TS2307: Cannot find module 'f3'. + import {D} from 'f2'; + ~~~~ +!!! error TS2307: Cannot find module 'f2'. + import {E} from "f2"; + ~~~~ +!!! error TS2307: Cannot find module 'f2'. + import {F} from 'f1'; + ~~~~ +!!! error TS2307: Cannot find module 'f1'. + + console.log(A + B + C + D + E + F) + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. \ No newline at end of file diff --git a/tests/baselines/reference/deduplicateImportsInSystem.js b/tests/baselines/reference/deduplicateImportsInSystem.js new file mode 100644 index 00000000000..956d293cad1 --- /dev/null +++ b/tests/baselines/reference/deduplicateImportsInSystem.js @@ -0,0 +1,33 @@ +//// [deduplicateImportsInSystem.ts] +import {A} from "f1"; +import {B} from "f2"; +import {C} from "f3"; +import {D} from 'f2'; +import {E} from "f2"; +import {F} from 'f1'; + +console.log(A + B + C + D + E + F) + +//// [deduplicateImportsInSystem.js] +System.register(["f1", "f2", "f3"], function(exports_1) { + "use strict"; + var f1_1, f2_1, f3_1, f2_2, f2_3, f1_2; + return { + setters:[ + function (f1_1_1) { + f1_1 = f1_1_1; + f1_2 = f1_1_1; + }, + function (f2_1_1) { + f2_1 = f2_1_1; + f2_2 = f2_1_1; + f2_3 = f2_1_1; + }, + function (f3_1_1) { + f3_1 = f3_1_1; + }], + execute: function() { + console.log(f1_1.A + f2_1.B + f3_1.C + f2_2.D + f2_3.E + f1_2.F); + } + } +}); diff --git a/tests/cases/compiler/deduplicateImportsInSystem.ts b/tests/cases/compiler/deduplicateImportsInSystem.ts new file mode 100644 index 00000000000..2fcbc16be05 --- /dev/null +++ b/tests/cases/compiler/deduplicateImportsInSystem.ts @@ -0,0 +1,9 @@ +// @module: system +import {A} from "f1"; +import {B} from "f2"; +import {C} from "f3"; +import {D} from 'f2'; +import {E} from "f2"; +import {F} from 'f1'; + +console.log(A + B + C + D + E + F) \ No newline at end of file From c353252c8e7d914dbf23539633f07951213a1026 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 27 Jan 2016 19:51:43 -0800 Subject: [PATCH 24/36] Update authors for release 1.8 --- AUTHORS.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 486a15bf47f..0501514d758 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -2,9 +2,11 @@ TypeScript is authored by: * Adam Freidin * Ahmad Farid +* Akshar Patel * Anders Hejlsberg * Arnav Singh * Arthur Ozga +* Asad Saeeduddin * Basarat Ali Syed * Ben Duffield * Bill Ticehurst @@ -15,30 +17,39 @@ TypeScript is authored by: * Colby Russell * Colin Snover * Cyrus Najmabadi +* Dan Corder * Dan Quirk * Daniel Rosenwasser +* @dashaus * David Li * Denis Nedelyaev * Dick van den Brink * Dirk Bäumer +* Dirk Holtwick * Eyas Sharaiha +* @falsandtru * Frank Wallis * Gabriel Isenberg * Gilad Peleg * Graeme Wicksted * Guillaume Salles +* Guy Bedford * Harald Niesche +* Iain Monro * Ingvar Stepanyan * Ivo Gabe de Wolff * James Whitney * Jason Freeman +* Jason Killian * Jason Ramsay * Jed Mao +* Jeffrey Morlan * Johannes Rieken * John Vilk * Jonathan Bond-Caron * Jonathan Park * Jonathan Turner +* Jonathon Smith * Josh Kalderimis * Julian Williams * Kagami Sascha Rosylight @@ -46,21 +57,27 @@ TypeScript is authored by: * Ken Howard * Kenji Imamula * Lorant Pinter +* Lucien Greathouse * Martin Všetička * Masahiro Wakame +* Mattias Buelens * Max Deepfield * Micah Zoltu * Mohamed Hegazy * Nathan Shively-Sanders +* Nathan Yee * Oleg Mihailik * Oleksandr Chekhovskyi * Paul van Brenk +* @pcbro * Pedro Maltez * Philip Bulley * piloopin * @progre * Punya Biswal +* Richard Sentino * Ron Buckton +* Rowan Wyborn * Ryan Cavanaugh * Ryohei Ikegami * Sébastien Arod @@ -71,7 +88,9 @@ TypeScript is authored by: * Solal Pirelli * Stan Thomas * Steve Lucco +* Thomas Loubiou * Tien Hoanhtien +* Tim Perry * Tingan Ho * togru * Tomas Grubliauskas @@ -81,5 +100,6 @@ TypeScript is authored by: * Wesley Wigham * York Yao * Yui Tanglertsampan +* Yuichi Nukiyama * Zev Spitz * Zhengbo Li From 301901709336b23ee3a4762855cd516a7229b6d6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Jan 2016 10:39:54 -0800 Subject: [PATCH 25/36] Emit readonly in declaration files --- src/compiler/declarationEmitter.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 9a57b4b1a37..7a8db9f90ed 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -648,6 +648,9 @@ namespace ts { if (node.flags & NodeFlags.Static) { write("static "); } + if (node.flags & NodeFlags.Readonly) { + write("readonly "); + } if (node.flags & NodeFlags.Abstract) { write("abstract "); } @@ -1342,15 +1345,17 @@ namespace ts { const prevEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = node; - // Construct signature or constructor type write new Signature - if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { - write("new "); - } - emitTypeParameters(node.typeParameters); if (node.kind === SyntaxKind.IndexSignature) { + // Index signature can have readonly modifier + emitClassMemberDeclarationFlags(node); write("["); } else { + // Construct signature or constructor type write new Signature + if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { + write("new "); + } + emitTypeParameters(node.typeParameters); write("("); } From 371811ab5b795ce0abb2a0c81e96098c09768652 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Jan 2016 10:40:08 -0800 Subject: [PATCH 26/36] Adding test --- .../reference/readonlyInDeclarationFile.js | 83 +++++++++++++++++++ .../readonlyInDeclarationFile.symbols | 76 +++++++++++++++++ .../reference/readonlyInDeclarationFile.types | 83 +++++++++++++++++++ .../compiler/readonlyInDeclarationFile.ts | 36 ++++++++ 4 files changed, 278 insertions(+) create mode 100644 tests/baselines/reference/readonlyInDeclarationFile.js create mode 100644 tests/baselines/reference/readonlyInDeclarationFile.symbols create mode 100644 tests/baselines/reference/readonlyInDeclarationFile.types create mode 100644 tests/cases/compiler/readonlyInDeclarationFile.ts diff --git a/tests/baselines/reference/readonlyInDeclarationFile.js b/tests/baselines/reference/readonlyInDeclarationFile.js new file mode 100644 index 00000000000..d2a20280e0f --- /dev/null +++ b/tests/baselines/reference/readonlyInDeclarationFile.js @@ -0,0 +1,83 @@ +//// [readonlyInDeclarationFile.ts] + +interface Foo { + readonly x: number; + readonly [x: string]: Object; +} + +class C { + protected readonly y: number; + readonly [x: string]: Object; + private static readonly a = "foo"; + protected static readonly b = "foo"; + public static readonly c = "foo"; +} + +var z: { + readonly a: string; + readonly [x: string]: Object; +} + +function f() { + return { + get x() { return 1; }, + get y() { return 1; }, + set y(value) { } + } +} + +function g() { + var x: { + readonly a: string; + readonly [x: string]: Object; + } + return x; +} + +//// [readonlyInDeclarationFile.js] +var C = (function () { + function C() { + } + C.a = "foo"; + C.b = "foo"; + C.c = "foo"; + return C; +}()); +var z; +function f() { + return { + get x() { return 1; }, + get y() { return 1; }, + set y(value) { } + }; +} +function g() { + var x; + return x; +} + + +//// [readonlyInDeclarationFile.d.ts] +interface Foo { + readonly x: number; + readonly [x: string]: Object; +} +declare class C { + protected readonly y: number; + readonly [x: string]: Object; + private static readonly a; + protected static readonly b: string; + static readonly c: string; +} +declare var z: { + readonly a: string; + readonly [x: string]: Object; +}; +declare function f(): { + readonly x: number; + y: number; +}; +declare function g(): { + readonly [x: string]: Object; + readonly a: string; +}; diff --git a/tests/baselines/reference/readonlyInDeclarationFile.symbols b/tests/baselines/reference/readonlyInDeclarationFile.symbols new file mode 100644 index 00000000000..f7bbf19a0ae --- /dev/null +++ b/tests/baselines/reference/readonlyInDeclarationFile.symbols @@ -0,0 +1,76 @@ +=== tests/cases/compiler/readonlyInDeclarationFile.ts === + +interface Foo { +>Foo : Symbol(Foo, Decl(readonlyInDeclarationFile.ts, 0, 0)) + + readonly x: number; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 1, 15)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 3, 14)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +class C { +>C : Symbol(C, Decl(readonlyInDeclarationFile.ts, 4, 1)) + + protected readonly y: number; +>y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 6, 9)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 8, 14)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + private static readonly a = "foo"; +>a : Symbol(C.a, Decl(readonlyInDeclarationFile.ts, 8, 33)) + + protected static readonly b = "foo"; +>b : Symbol(C.b, Decl(readonlyInDeclarationFile.ts, 9, 38)) + + public static readonly c = "foo"; +>c : Symbol(C.c, Decl(readonlyInDeclarationFile.ts, 10, 40)) +} + +var z: { +>z : Symbol(z, Decl(readonlyInDeclarationFile.ts, 14, 3)) + + readonly a: string; +>a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 14, 8)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 16, 14)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f() { +>f : Symbol(f, Decl(readonlyInDeclarationFile.ts, 17, 1)) + + return { + get x() { return 1; }, +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 20, 12)) + + get y() { return 1; }, +>y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 21, 30), Decl(readonlyInDeclarationFile.ts, 22, 30)) + + set y(value) { } +>y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 21, 30), Decl(readonlyInDeclarationFile.ts, 22, 30)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 23, 14)) + } +} + +function g() { +>g : Symbol(g, Decl(readonlyInDeclarationFile.ts, 25, 1)) + + var x: { +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 28, 7)) + + readonly a: string; +>a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 28, 12)) + + readonly [x: string]: Object; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 30, 18)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + } + return x; +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 28, 7)) +} diff --git a/tests/baselines/reference/readonlyInDeclarationFile.types b/tests/baselines/reference/readonlyInDeclarationFile.types new file mode 100644 index 00000000000..9b2f9d51d99 --- /dev/null +++ b/tests/baselines/reference/readonlyInDeclarationFile.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/readonlyInDeclarationFile.ts === + +interface Foo { +>Foo : Foo + + readonly x: number; +>x : number + + readonly [x: string]: Object; +>x : string +>Object : Object +} + +class C { +>C : C + + protected readonly y: number; +>y : number + + readonly [x: string]: Object; +>x : string +>Object : Object + + private static readonly a = "foo"; +>a : string +>"foo" : string + + protected static readonly b = "foo"; +>b : string +>"foo" : string + + public static readonly c = "foo"; +>c : string +>"foo" : string +} + +var z: { +>z : { readonly [x: string]: Object; readonly a: string; } + + readonly a: string; +>a : string + + readonly [x: string]: Object; +>x : string +>Object : Object +} + +function f() { +>f : () => { readonly x: number; y: number; } + + return { +>{ get x() { return 1; }, get y() { return 1; }, set y(value) { } } : { readonly x: number; y: number; } + + get x() { return 1; }, +>x : number +>1 : number + + get y() { return 1; }, +>y : number +>1 : number + + set y(value) { } +>y : number +>value : number + } +} + +function g() { +>g : () => { readonly [x: string]: Object; readonly a: string; } + + var x: { +>x : { readonly [x: string]: Object; readonly a: string; } + + readonly a: string; +>a : string + + readonly [x: string]: Object; +>x : string +>Object : Object + } + return x; +>x : { readonly [x: string]: Object; readonly a: string; } +} diff --git a/tests/cases/compiler/readonlyInDeclarationFile.ts b/tests/cases/compiler/readonlyInDeclarationFile.ts new file mode 100644 index 00000000000..99241b8c0c0 --- /dev/null +++ b/tests/cases/compiler/readonlyInDeclarationFile.ts @@ -0,0 +1,36 @@ +// @target: es5 +// @declaration: true + +interface Foo { + readonly x: number; + readonly [x: string]: Object; +} + +class C { + protected readonly y: number; + readonly [x: string]: Object; + private static readonly a = "foo"; + protected static readonly b = "foo"; + public static readonly c = "foo"; +} + +var z: { + readonly a: string; + readonly [x: string]: Object; +} + +function f() { + return { + get x() { return 1; }, + get y() { return 1; }, + set y(value) { } + } +} + +function g() { + var x: { + readonly a: string; + readonly [x: string]: Object; + } + return x; +} \ No newline at end of file From 364b08854bc1face5c9b38301bb83c7346f1ccce Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 28 Jan 2016 11:02:49 -0800 Subject: [PATCH 27/36] Recognize the RHS of assignments as the JSDoc target expression Fixes #6552 --- src/compiler/parser.ts | 6 +++--- src/compiler/utilities.ts | 14 ++++++++++++- .../fourslash/getJavaScriptCompletions18.ts | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/getJavaScriptCompletions18.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 57bd9860d12..7806df795d2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4051,7 +4051,7 @@ namespace ts { setDecoratorContext(/*val*/ true); } - return finishNode(node); + return addJSDocComment(finishNode(node)); } function parseOptionalIdentifier() { @@ -4335,13 +4335,13 @@ namespace ts { const labeledStatement = createNode(SyntaxKind.LabeledStatement, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); - return finishNode(labeledStatement); + return addJSDocComment(finishNode(labeledStatement)); } else { const expressionStatement = createNode(SyntaxKind.ExpressionStatement, fullStart); expressionStatement.expression = expression; parseSemicolon(); - return finishNode(expressionStatement); + return addJSDocComment(finishNode(expressionStatement)); } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4bf1422e888..0856cb55477 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1186,7 +1186,19 @@ namespace ts { node.parent.parent.parent.kind === SyntaxKind.VariableStatement; const variableStatementNode = isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : undefined; - return variableStatementNode && variableStatementNode.jsDocComment; + if (variableStatementNode) { + return variableStatementNode.jsDocComment; + } + + // Also recognize when the node is the RHS of an assignment expression + const isSourceOfAssignmentExpressionStatement = + node.parent && node.parent.parent && + node.parent.kind === SyntaxKind.BinaryExpression && + (node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && + node.parent.parent.kind === SyntaxKind.ExpressionStatement; + if (isSourceOfAssignmentExpressionStatement) { + return node.parent.parent.jsDocComment; + } } return undefined; diff --git a/tests/cases/fourslash/getJavaScriptCompletions18.ts b/tests/cases/fourslash/getJavaScriptCompletions18.ts new file mode 100644 index 00000000000..a30d4943f4f --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions18.ts @@ -0,0 +1,21 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// /** +//// * @param {number} a +//// * @param {string} b +//// */ +//// exports.foo = function(a, b) { +//// a/*a*/; +//// b/*b*/ +//// }; + +goTo.marker('a'); +edit.insert('.'); +verify.completionListContains('toFixed', undefined, undefined, 'method'); + + +goTo.marker('b'); +edit.insert('.'); +verify.completionListContains('substr', undefined, undefined, 'method'); From bf897c29393e7e7ee92a71e123e502ca3d0ba12f Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 28 Jan 2016 11:26:32 -0800 Subject: [PATCH 28/36] Add more tests and comments --- src/compiler/checker.ts | 2 ++ tests/cases/fourslash/renameCrossJsTs01.ts | 12 ++++++++++++ tests/cases/fourslash/renameCrossJsTs02.ts | 12 ++++++++++++ .../{renameJsExports.ts => renameJsExports01.ts} | 2 +- tests/cases/fourslash/renameJsExports02.ts | 12 ++++++++++++ ...ypeProperty.ts => renameJsPrototypeProperty01.ts} | 2 +- tests/cases/fourslash/renameJsPrototypeProperty02.ts | 12 ++++++++++++ ...meJsThisProperty.ts => renameJsThisProperty01.ts} | 2 +- tests/cases/fourslash/renameJsThisProperty02.ts | 12 ++++++++++++ 9 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/renameCrossJsTs01.ts create mode 100644 tests/cases/fourslash/renameCrossJsTs02.ts rename tests/cases/fourslash/{renameJsExports.ts => renameJsExports01.ts} (72%) create mode 100644 tests/cases/fourslash/renameJsExports02.ts rename tests/cases/fourslash/{renameJsPrototypeProperty.ts => renameJsPrototypeProperty01.ts} (69%) create mode 100644 tests/cases/fourslash/renameJsPrototypeProperty02.ts rename tests/cases/fourslash/{renameJsThisProperty.ts => renameJsThisProperty01.ts} (68%) create mode 100644 tests/cases/fourslash/renameJsThisProperty02.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b3792a97988..758c5bbb4ad 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15367,6 +15367,8 @@ namespace ts { case SpecialPropertyAssignmentKind.ThisProperty: case SpecialPropertyAssignmentKind.ModuleExports: return getSymbolOfNode(entityName.parent.parent); + default: + // Fall through if it is not a special property assignment } } diff --git a/tests/cases/fourslash/renameCrossJsTs01.ts b/tests/cases/fourslash/renameCrossJsTs01.ts new file mode 100644 index 00000000000..52cb4c587d1 --- /dev/null +++ b/tests/cases/fourslash/renameCrossJsTs01.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports.[|area|] = function (r) { return r * r; } + +// @Filename: b.ts +////import { [|area|] } from './a'; +////var t = /**/[|area|](10); + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameCrossJsTs02.ts b/tests/cases/fourslash/renameCrossJsTs02.ts new file mode 100644 index 00000000000..7ff1ae96ff3 --- /dev/null +++ b/tests/cases/fourslash/renameCrossJsTs02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports./**/[|area|] = function (r) { return r * r; } + +// @Filename: b.ts +////import { [|area|] } from './a'; +////var t = [|area|](10); + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsExports.ts b/tests/cases/fourslash/renameJsExports01.ts similarity index 72% rename from tests/cases/fourslash/renameJsExports.ts rename to tests/cases/fourslash/renameJsExports01.ts index 227eebe4a0d..923d30eedf9 100644 --- a/tests/cases/fourslash/renameJsExports.ts +++ b/tests/cases/fourslash/renameJsExports01.ts @@ -9,4 +9,4 @@ ////var t = mod./**/[|area|](10); goTo.marker(); -verify.renameLocations(false, false); \ No newline at end of file +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsExports02.ts b/tests/cases/fourslash/renameJsExports02.ts new file mode 100644 index 00000000000..86b0471dc1f --- /dev/null +++ b/tests/cases/fourslash/renameJsExports02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////exports./**/[|area|] = function (r) { return r * r; } + +// @Filename: b.js +////var mod = require('./a'); +////var t = mod.[|area|](10); + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsPrototypeProperty.ts b/tests/cases/fourslash/renameJsPrototypeProperty01.ts similarity index 69% rename from tests/cases/fourslash/renameJsPrototypeProperty.ts rename to tests/cases/fourslash/renameJsPrototypeProperty01.ts index 651514859cc..f756f57edbf 100644 --- a/tests/cases/fourslash/renameJsPrototypeProperty.ts +++ b/tests/cases/fourslash/renameJsPrototypeProperty01.ts @@ -9,4 +9,4 @@ ////t./**/[|x|] = 11; goTo.marker(); -verify.renameLocations(false, false); \ No newline at end of file +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsPrototypeProperty02.ts b/tests/cases/fourslash/renameJsPrototypeProperty02.ts new file mode 100644 index 00000000000..721dc312eb6 --- /dev/null +++ b/tests/cases/fourslash/renameJsPrototypeProperty02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +////} +////bar.prototype./**/[|x|] = 10; +////var t = new bar(); +////t.[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsThisProperty.ts b/tests/cases/fourslash/renameJsThisProperty01.ts similarity index 68% rename from tests/cases/fourslash/renameJsThisProperty.ts rename to tests/cases/fourslash/renameJsThisProperty01.ts index aed59d298b1..91338e0431d 100644 --- a/tests/cases/fourslash/renameJsThisProperty.ts +++ b/tests/cases/fourslash/renameJsThisProperty01.ts @@ -9,4 +9,4 @@ ////t./**/[|x|] = 11; goTo.marker(); -verify.renameLocations(false, false); \ No newline at end of file +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsThisProperty02.ts b/tests/cases/fourslash/renameJsThisProperty02.ts new file mode 100644 index 00000000000..8398507c9ca --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty02.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function bar() { +//// this./**/[|x|] = 10; +////} +////var t = new bar(); +////t.[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); \ No newline at end of file From da6e82f639a7cc96887fde34391a9c8c654fa301 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 28 Jan 2016 11:39:19 -0800 Subject: [PATCH 29/36] Use union types in the return type of functions in the error case Fixes #6663 --- src/compiler/checker.ts | 3 ++- .../fourslash/getJavaScriptCompletions19.ts | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getJavaScriptCompletions19.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61c05d7688c..55587ca683c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10390,7 +10390,8 @@ namespace ts { } else { error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); - return unknownType; + // Defer to unioning the return types so we get a) downstream errors earlier and b) better Salsa experience + return getUnionType(types); } } diff --git a/tests/cases/fourslash/getJavaScriptCompletions19.ts b/tests/cases/fourslash/getJavaScriptCompletions19.ts new file mode 100644 index 00000000000..5a361930e86 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions19.ts @@ -0,0 +1,25 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// function fn() { +//// if (foo) { +//// return 0; +//// } else { +//// return '0'; +//// } +//// } +//// let x = fn(); +//// if(typeof x === 'string') { +//// x/*str*/ +//// } else { +//// x/*num*/ +//// } + +goTo.marker('str'); +edit.insert('.'); +verify.completionListContains('substr', undefined, undefined, 'method'); + +goTo.marker('num'); +edit.insert('.'); +verify.completionListContains('toFixed', undefined, undefined, 'method'); From a88ff9c2ad9a2476ede5148b67b20d70684e3af8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Jan 2016 13:28:49 -0800 Subject: [PATCH 30/36] Emit readonly in declaration file for get-only accessors in classes --- src/compiler/declarationEmitter.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 7a8db9f90ed..ab0b16947fc 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -637,21 +637,21 @@ namespace ts { } } - function emitClassMemberDeclarationFlags(node: Declaration) { - if (node.flags & NodeFlags.Private) { + function emitClassMemberDeclarationFlags(flags: NodeFlags) { + if (flags & NodeFlags.Private) { write("private "); } - else if (node.flags & NodeFlags.Protected) { + else if (flags & NodeFlags.Protected) { write("protected "); } - if (node.flags & NodeFlags.Static) { + if (flags & NodeFlags.Static) { write("static "); } - if (node.flags & NodeFlags.Readonly) { + if (flags & NodeFlags.Readonly) { write("readonly "); } - if (node.flags & NodeFlags.Abstract) { + if (flags & NodeFlags.Abstract) { write("abstract "); } } @@ -1077,7 +1077,7 @@ namespace ts { } emitJsDocComments(node); - emitClassMemberDeclarationFlags(node); + emitClassMemberDeclarationFlags(node.flags); emitVariableDeclaration(node); write(";"); writeLine(); @@ -1230,7 +1230,7 @@ namespace ts { if (node === accessors.firstAccessor) { emitJsDocComments(accessors.getAccessor); emitJsDocComments(accessors.setAccessor); - emitClassMemberDeclarationFlags(node); + emitClassMemberDeclarationFlags(node.flags | (accessors.setAccessor ? 0 : NodeFlags.Readonly)); writeTextOfNode(currentText, node.name); if (!(node.flags & NodeFlags.Private)) { accessorWithTypeAnnotation = node; @@ -1317,7 +1317,7 @@ namespace ts { emitModuleElementDeclarationFlags(node); } else if (node.kind === SyntaxKind.MethodDeclaration) { - emitClassMemberDeclarationFlags(node); + emitClassMemberDeclarationFlags(node.flags); } if (node.kind === SyntaxKind.FunctionDeclaration) { write("function "); @@ -1347,7 +1347,7 @@ namespace ts { if (node.kind === SyntaxKind.IndexSignature) { // Index signature can have readonly modifier - emitClassMemberDeclarationFlags(node); + emitClassMemberDeclarationFlags(node.flags); write("["); } else { From 898797fceef1b9a5653c01091ee3647faad53977 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Jan 2016 13:29:20 -0800 Subject: [PATCH 31/36] Adding more test cases --- .../compiler/readonlyInDeclarationFile.ts | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/cases/compiler/readonlyInDeclarationFile.ts b/tests/cases/compiler/readonlyInDeclarationFile.ts index 99241b8c0c0..03e643782f0 100644 --- a/tests/cases/compiler/readonlyInDeclarationFile.ts +++ b/tests/cases/compiler/readonlyInDeclarationFile.ts @@ -7,11 +7,31 @@ interface Foo { } class C { - protected readonly y: number; readonly [x: string]: Object; - private static readonly a = "foo"; - protected static readonly b = "foo"; - public static readonly c = "foo"; + private readonly a1: number; + protected readonly a2: number; + public readonly a3: number; + private get b1() { return 1 } + protected get b2() { return 1 } + public get b3() { return 1 } + private get c1() { return 1 } + private set c1(value) { } + protected get c2() { return 1 } + protected set c2(value) { } + public get c3() { return 1 } + public set c3(value) { } + private static readonly s1: number; + protected static readonly s2: number; + public static readonly s3: number; + private static get t1() { return 1 } + protected static get t2() { return 1 } + public static get t3() { return 1 } + private static get u1() { return 1 } + private static set u1(value) { } + protected static get u2() { return 1 } + protected static set u2(value) { } + public static get u3() { return 1 } + public static set u3(value) { } } var z: { From c00d239c00e3785f5cd1ac3f75b26242ff3e60ba Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 28 Jan 2016 13:29:58 -0800 Subject: [PATCH 32/36] Accepting new baselines --- tests/baselines/reference/classdecl.js | 4 +- .../reference/commentsClassMembers.js | 4 +- .../reference/commentsInheritance.js | 12 +- .../baselines/reference/declFileAccessors.js | 4 +- .../reference/declFilePrivateStatic.js | 4 +- .../declarationEmit_protectedMembers.js | 4 +- tests/baselines/reference/giant.js | 24 ++-- .../isDeclarationVisibleNodeKinds.js | 2 +- tests/baselines/reference/moduledecl.js | 4 +- .../reference/readonlyInDeclarationFile.js | 119 ++++++++++++++++-- .../readonlyInDeclarationFile.symbols | 112 +++++++++++++---- .../reference/readonlyInDeclarationFile.types | 99 +++++++++++++-- .../reference/symbolDeclarationEmit13.js | 2 +- .../reference/symbolDeclarationEmit14.js | 4 +- .../reference/typeGuardOfFormThisMember.js | 2 +- .../typeGuardOfFormThisMemberErrors.js | 2 +- 16 files changed, 320 insertions(+), 82 deletions(-) diff --git a/tests/baselines/reference/classdecl.js b/tests/baselines/reference/classdecl.js index 710c5166d30..a8a440fa17d 100644 --- a/tests/baselines/reference/classdecl.js +++ b/tests/baselines/reference/classdecl.js @@ -211,12 +211,12 @@ declare class a { pgF(): void; pv: any; d: number; - static p2: { + static readonly p2: { x: number; y: number; }; private static d2(); - private static p3; + private static readonly p3; private pv3; private foo(n); private foo(s); diff --git a/tests/baselines/reference/commentsClassMembers.js b/tests/baselines/reference/commentsClassMembers.js index fe2dc0a63d0..dacbde7a276 100644 --- a/tests/baselines/reference/commentsClassMembers.js +++ b/tests/baselines/reference/commentsClassMembers.js @@ -568,8 +568,8 @@ declare var i1_c: typeof c1; declare class cProperties { private val; /** getter only property*/ - p1: number; - nc_p1: number; + readonly p1: number; + readonly nc_p1: number; /**setter only property*/ p2: number; nc_p2: number; diff --git a/tests/baselines/reference/commentsInheritance.js b/tests/baselines/reference/commentsInheritance.js index b9d84b2475a..42df3cca389 100644 --- a/tests/baselines/reference/commentsInheritance.js +++ b/tests/baselines/reference/commentsInheritance.js @@ -316,19 +316,19 @@ declare class c2 { /** c2 c2_f1*/ c2_f1(): void; /** c2 c2_prop*/ - c2_prop: number; + readonly c2_prop: number; c2_nc_p1: number; c2_nc_f1(): void; - c2_nc_prop: number; + readonly c2_nc_prop: number; /** c2 p1*/ p1: number; /** c2 f1*/ f1(): void; /** c2 prop*/ - prop: number; + readonly prop: number; nc_p1: number; nc_f1(): void; - nc_prop: number; + readonly nc_prop: number; /** c2 constructor*/ constructor(a: number); } @@ -339,10 +339,10 @@ declare class c3 extends c2 { /** c3 f1*/ f1(): void; /** c3 prop*/ - prop: number; + readonly prop: number; nc_p1: number; nc_f1(): void; - nc_prop: number; + readonly nc_prop: number; } declare var c2_i: c2; declare var c3_i: c3; diff --git a/tests/baselines/reference/declFileAccessors.js b/tests/baselines/reference/declFileAccessors.js index e3616c79e38..2bd51bfbfb2 100644 --- a/tests/baselines/reference/declFileAccessors.js +++ b/tests/baselines/reference/declFileAccessors.js @@ -284,7 +284,7 @@ export declare class c1 { nc_p3: number; private nc_pp3; static nc_s3: string; - onlyGetter: number; + readonly onlyGetter: number; onlySetter: number; } //// [declFileAccessors_1.d.ts] @@ -302,6 +302,6 @@ declare class c2 { nc_p3: number; private nc_pp3; static nc_s3: string; - onlyGetter: number; + readonly onlyGetter: number; onlySetter: number; } diff --git a/tests/baselines/reference/declFilePrivateStatic.js b/tests/baselines/reference/declFilePrivateStatic.js index dd81d94b3c5..30cd85444cf 100644 --- a/tests/baselines/reference/declFilePrivateStatic.js +++ b/tests/baselines/reference/declFilePrivateStatic.js @@ -52,8 +52,8 @@ declare class C { static y: number; private static a(); static b(): void; - private static c; - static d: number; + private static readonly c; + static readonly d: number; private static e; static f: any; } diff --git a/tests/baselines/reference/declarationEmit_protectedMembers.js b/tests/baselines/reference/declarationEmit_protectedMembers.js index 5aad004939d..192f0647ed6 100644 --- a/tests/baselines/reference/declarationEmit_protectedMembers.js +++ b/tests/baselines/reference/declarationEmit_protectedMembers.js @@ -135,7 +135,7 @@ declare class C1 { protected static sx: number; protected static sf(): number; protected static staticSetter: number; - protected static staticGetter: number; + protected static readonly staticGetter: number; } declare class C2 extends C1 { protected f(): number; @@ -146,7 +146,7 @@ declare class C3 extends C2 { static sx: number; f(): number; static sf(): number; - static staticGetter: number; + static readonly staticGetter: number; } declare class C4 { protected a: number; diff --git a/tests/baselines/reference/giant.js b/tests/baselines/reference/giant.js index 2a04541ef28..149a975d413 100644 --- a/tests/baselines/reference/giant.js +++ b/tests/baselines/reference/giant.js @@ -1120,11 +1120,11 @@ export declare class eC { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1132,7 +1132,7 @@ export declare class eC { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } export interface eI { (): any; @@ -1172,11 +1172,11 @@ export declare module eM { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1184,7 +1184,7 @@ export declare module eM { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } interface eI { (): any; @@ -1239,11 +1239,11 @@ export declare module eM { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1251,7 +1251,7 @@ export declare module eM { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } module eaM { var V: any; @@ -1281,11 +1281,11 @@ export declare class eaC { pF(): void; private rF(); pgF(): void; - pgF: any; + readonly pgF: any; psF(param: any): void; psF: any; private rgF(); - private rgF; + private readonly rgF; private rsF(param); private rsF; static tV: any; @@ -1293,7 +1293,7 @@ export declare class eaC { static tsF(param: any): void; static tsF: any; static tgF(): void; - static tgF: any; + static readonly tgF: any; } export declare module eaM { var V: any; diff --git a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js index 99e1ac72acd..e24032eb858 100644 --- a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js +++ b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js @@ -193,7 +193,7 @@ declare module schema { } declare module schema { class T { - createValidator9: (data: T) => T; + readonly createValidator9: (data: T) => T; createValidator10: (data: T) => T; } } diff --git a/tests/baselines/reference/moduledecl.js b/tests/baselines/reference/moduledecl.js index 2e765e512d8..f4efbadbf3e 100644 --- a/tests/baselines/reference/moduledecl.js +++ b/tests/baselines/reference/moduledecl.js @@ -459,10 +459,10 @@ declare module exportTests { class C3_public { private getC2_private(); private setC2_private(arg); - private c2; + private readonly c2; getC1_public(): C1_public; setC1_public(arg: C1_public): void; - c1: C1_public; + readonly c1: C1_public; } } declare module mAmbient { diff --git a/tests/baselines/reference/readonlyInDeclarationFile.js b/tests/baselines/reference/readonlyInDeclarationFile.js index d2a20280e0f..71e48272ecc 100644 --- a/tests/baselines/reference/readonlyInDeclarationFile.js +++ b/tests/baselines/reference/readonlyInDeclarationFile.js @@ -6,11 +6,31 @@ interface Foo { } class C { - protected readonly y: number; readonly [x: string]: Object; - private static readonly a = "foo"; - protected static readonly b = "foo"; - public static readonly c = "foo"; + private readonly a1: number; + protected readonly a2: number; + public readonly a3: number; + private get b1() { return 1 } + protected get b2() { return 1 } + public get b3() { return 1 } + private get c1() { return 1 } + private set c1(value) { } + protected get c2() { return 1 } + protected set c2(value) { } + public get c3() { return 1 } + public set c3(value) { } + private static readonly s1: number; + protected static readonly s2: number; + public static readonly s3: number; + private static get t1() { return 1 } + protected static get t2() { return 1 } + public static get t3() { return 1 } + private static get u1() { return 1 } + private static set u1(value) { } + protected static get u2() { return 1 } + protected static set u2(value) { } + public static get u3() { return 1 } + public static set u3(value) { } } var z: { @@ -38,9 +58,72 @@ function g() { var C = (function () { function C() { } - C.a = "foo"; - C.b = "foo"; - C.c = "foo"; + Object.defineProperty(C.prototype, "b1", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "b2", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "b3", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "c1", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "c2", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "c3", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "t1", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "t2", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "t3", { + get: function () { return 1; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "u1", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "u2", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C, "u3", { + get: function () { return 1; }, + set: function (value) { }, + enumerable: true, + configurable: true + }); return C; }()); var z; @@ -63,11 +146,25 @@ interface Foo { readonly [x: string]: Object; } declare class C { - protected readonly y: number; readonly [x: string]: Object; - private static readonly a; - protected static readonly b: string; - static readonly c: string; + private readonly a1; + protected readonly a2: number; + readonly a3: number; + private readonly b1; + protected readonly b2: number; + readonly b3: number; + private c1; + protected c2: number; + c3: number; + private static readonly s1; + protected static readonly s2: number; + static readonly s3: number; + private static readonly t1; + protected static readonly t2: number; + static readonly t3: number; + private static u1; + protected static u2: number; + static u3: number; } declare var z: { readonly a: string; diff --git a/tests/baselines/reference/readonlyInDeclarationFile.symbols b/tests/baselines/reference/readonlyInDeclarationFile.symbols index f7bbf19a0ae..af979e4dacd 100644 --- a/tests/baselines/reference/readonlyInDeclarationFile.symbols +++ b/tests/baselines/reference/readonlyInDeclarationFile.symbols @@ -14,63 +14,129 @@ interface Foo { class C { >C : Symbol(C, Decl(readonlyInDeclarationFile.ts, 4, 1)) - protected readonly y: number; ->y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 6, 9)) - readonly [x: string]: Object; ->x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 8, 14)) +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 7, 14)) >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) - private static readonly a = "foo"; ->a : Symbol(C.a, Decl(readonlyInDeclarationFile.ts, 8, 33)) + private readonly a1: number; +>a1 : Symbol(a1, Decl(readonlyInDeclarationFile.ts, 7, 33)) - protected static readonly b = "foo"; ->b : Symbol(C.b, Decl(readonlyInDeclarationFile.ts, 9, 38)) + protected readonly a2: number; +>a2 : Symbol(a2, Decl(readonlyInDeclarationFile.ts, 8, 32)) - public static readonly c = "foo"; ->c : Symbol(C.c, Decl(readonlyInDeclarationFile.ts, 10, 40)) + public readonly a3: number; +>a3 : Symbol(a3, Decl(readonlyInDeclarationFile.ts, 9, 34)) + + private get b1() { return 1 } +>b1 : Symbol(b1, Decl(readonlyInDeclarationFile.ts, 10, 31)) + + protected get b2() { return 1 } +>b2 : Symbol(b2, Decl(readonlyInDeclarationFile.ts, 11, 33)) + + public get b3() { return 1 } +>b3 : Symbol(b3, Decl(readonlyInDeclarationFile.ts, 12, 35)) + + private get c1() { return 1 } +>c1 : Symbol(c1, Decl(readonlyInDeclarationFile.ts, 13, 32), Decl(readonlyInDeclarationFile.ts, 14, 33)) + + private set c1(value) { } +>c1 : Symbol(c1, Decl(readonlyInDeclarationFile.ts, 13, 32), Decl(readonlyInDeclarationFile.ts, 14, 33)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 15, 19)) + + protected get c2() { return 1 } +>c2 : Symbol(c2, Decl(readonlyInDeclarationFile.ts, 15, 29), Decl(readonlyInDeclarationFile.ts, 16, 35)) + + protected set c2(value) { } +>c2 : Symbol(c2, Decl(readonlyInDeclarationFile.ts, 15, 29), Decl(readonlyInDeclarationFile.ts, 16, 35)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 17, 21)) + + public get c3() { return 1 } +>c3 : Symbol(c3, Decl(readonlyInDeclarationFile.ts, 17, 31), Decl(readonlyInDeclarationFile.ts, 18, 32)) + + public set c3(value) { } +>c3 : Symbol(c3, Decl(readonlyInDeclarationFile.ts, 17, 31), Decl(readonlyInDeclarationFile.ts, 18, 32)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 19, 18)) + + private static readonly s1: number; +>s1 : Symbol(C.s1, Decl(readonlyInDeclarationFile.ts, 19, 28)) + + protected static readonly s2: number; +>s2 : Symbol(C.s2, Decl(readonlyInDeclarationFile.ts, 20, 39)) + + public static readonly s3: number; +>s3 : Symbol(C.s3, Decl(readonlyInDeclarationFile.ts, 21, 41)) + + private static get t1() { return 1 } +>t1 : Symbol(C.t1, Decl(readonlyInDeclarationFile.ts, 22, 38)) + + protected static get t2() { return 1 } +>t2 : Symbol(C.t2, Decl(readonlyInDeclarationFile.ts, 23, 40)) + + public static get t3() { return 1 } +>t3 : Symbol(C.t3, Decl(readonlyInDeclarationFile.ts, 24, 42)) + + private static get u1() { return 1 } +>u1 : Symbol(C.u1, Decl(readonlyInDeclarationFile.ts, 25, 39), Decl(readonlyInDeclarationFile.ts, 26, 40)) + + private static set u1(value) { } +>u1 : Symbol(C.u1, Decl(readonlyInDeclarationFile.ts, 25, 39), Decl(readonlyInDeclarationFile.ts, 26, 40)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 27, 26)) + + protected static get u2() { return 1 } +>u2 : Symbol(C.u2, Decl(readonlyInDeclarationFile.ts, 27, 36), Decl(readonlyInDeclarationFile.ts, 28, 42)) + + protected static set u2(value) { } +>u2 : Symbol(C.u2, Decl(readonlyInDeclarationFile.ts, 27, 36), Decl(readonlyInDeclarationFile.ts, 28, 42)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 29, 28)) + + public static get u3() { return 1 } +>u3 : Symbol(C.u3, Decl(readonlyInDeclarationFile.ts, 29, 38), Decl(readonlyInDeclarationFile.ts, 30, 39)) + + public static set u3(value) { } +>u3 : Symbol(C.u3, Decl(readonlyInDeclarationFile.ts, 29, 38), Decl(readonlyInDeclarationFile.ts, 30, 39)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 31, 25)) } var z: { ->z : Symbol(z, Decl(readonlyInDeclarationFile.ts, 14, 3)) +>z : Symbol(z, Decl(readonlyInDeclarationFile.ts, 34, 3)) readonly a: string; ->a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 14, 8)) +>a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 34, 8)) readonly [x: string]: Object; ->x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 16, 14)) +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 36, 14)) >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) } function f() { ->f : Symbol(f, Decl(readonlyInDeclarationFile.ts, 17, 1)) +>f : Symbol(f, Decl(readonlyInDeclarationFile.ts, 37, 1)) return { get x() { return 1; }, ->x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 20, 12)) +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 40, 12)) get y() { return 1; }, ->y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 21, 30), Decl(readonlyInDeclarationFile.ts, 22, 30)) +>y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 41, 30), Decl(readonlyInDeclarationFile.ts, 42, 30)) set y(value) { } ->y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 21, 30), Decl(readonlyInDeclarationFile.ts, 22, 30)) ->value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 23, 14)) +>y : Symbol(y, Decl(readonlyInDeclarationFile.ts, 41, 30), Decl(readonlyInDeclarationFile.ts, 42, 30)) +>value : Symbol(value, Decl(readonlyInDeclarationFile.ts, 43, 14)) } } function g() { ->g : Symbol(g, Decl(readonlyInDeclarationFile.ts, 25, 1)) +>g : Symbol(g, Decl(readonlyInDeclarationFile.ts, 45, 1)) var x: { ->x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 28, 7)) +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 48, 7)) readonly a: string; ->a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 28, 12)) +>a : Symbol(a, Decl(readonlyInDeclarationFile.ts, 48, 12)) readonly [x: string]: Object; ->x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 30, 18)) +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 50, 18)) >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) } return x; ->x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 28, 7)) +>x : Symbol(x, Decl(readonlyInDeclarationFile.ts, 48, 7)) } diff --git a/tests/baselines/reference/readonlyInDeclarationFile.types b/tests/baselines/reference/readonlyInDeclarationFile.types index 9b2f9d51d99..7a3e11577c8 100644 --- a/tests/baselines/reference/readonlyInDeclarationFile.types +++ b/tests/baselines/reference/readonlyInDeclarationFile.types @@ -14,24 +14,99 @@ interface Foo { class C { >C : C - protected readonly y: number; ->y : number - readonly [x: string]: Object; >x : string >Object : Object - private static readonly a = "foo"; ->a : string ->"foo" : string + private readonly a1: number; +>a1 : number - protected static readonly b = "foo"; ->b : string ->"foo" : string + protected readonly a2: number; +>a2 : number - public static readonly c = "foo"; ->c : string ->"foo" : string + public readonly a3: number; +>a3 : number + + private get b1() { return 1 } +>b1 : number +>1 : number + + protected get b2() { return 1 } +>b2 : number +>1 : number + + public get b3() { return 1 } +>b3 : number +>1 : number + + private get c1() { return 1 } +>c1 : number +>1 : number + + private set c1(value) { } +>c1 : number +>value : number + + protected get c2() { return 1 } +>c2 : number +>1 : number + + protected set c2(value) { } +>c2 : number +>value : number + + public get c3() { return 1 } +>c3 : number +>1 : number + + public set c3(value) { } +>c3 : number +>value : number + + private static readonly s1: number; +>s1 : number + + protected static readonly s2: number; +>s2 : number + + public static readonly s3: number; +>s3 : number + + private static get t1() { return 1 } +>t1 : number +>1 : number + + protected static get t2() { return 1 } +>t2 : number +>1 : number + + public static get t3() { return 1 } +>t3 : number +>1 : number + + private static get u1() { return 1 } +>u1 : number +>1 : number + + private static set u1(value) { } +>u1 : number +>value : number + + protected static get u2() { return 1 } +>u2 : number +>1 : number + + protected static set u2(value) { } +>u2 : number +>value : number + + public static get u3() { return 1 } +>u3 : number +>1 : number + + public static set u3(value) { } +>u3 : number +>value : number } var z: { diff --git a/tests/baselines/reference/symbolDeclarationEmit13.js b/tests/baselines/reference/symbolDeclarationEmit13.js index 8111672866a..bbd2c15cfcd 100644 --- a/tests/baselines/reference/symbolDeclarationEmit13.js +++ b/tests/baselines/reference/symbolDeclarationEmit13.js @@ -13,6 +13,6 @@ class C { //// [symbolDeclarationEmit13.d.ts] declare class C { - [Symbol.toPrimitive]: string; + readonly [Symbol.toPrimitive]: string; [Symbol.toStringTag]: any; } diff --git a/tests/baselines/reference/symbolDeclarationEmit14.js b/tests/baselines/reference/symbolDeclarationEmit14.js index b8a6b3e4092..d4ae3eeb43c 100644 --- a/tests/baselines/reference/symbolDeclarationEmit14.js +++ b/tests/baselines/reference/symbolDeclarationEmit14.js @@ -13,6 +13,6 @@ class C { //// [symbolDeclarationEmit14.d.ts] declare class C { - [Symbol.toPrimitive]: string; - [Symbol.toStringTag]: string; + readonly [Symbol.toPrimitive]: string; + readonly [Symbol.toStringTag]: string; } diff --git a/tests/baselines/reference/typeGuardOfFormThisMember.js b/tests/baselines/reference/typeGuardOfFormThisMember.js index 2f983d2cdf8..9d71613ed8f 100644 --- a/tests/baselines/reference/typeGuardOfFormThisMember.js +++ b/tests/baselines/reference/typeGuardOfFormThisMember.js @@ -170,7 +170,7 @@ declare namespace Test { path: string; isFSO: this is FileSystemObject; isFile: this is File; - isDirectory: this is Directory; + readonly isDirectory: this is Directory; isNetworked: this is (Networked & this); constructor(path: string); } diff --git a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js index 6f681ab09cf..5991fdd3169 100644 --- a/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js +++ b/tests/baselines/reference/typeGuardOfFormThisMemberErrors.js @@ -95,7 +95,7 @@ declare namespace Test { path: string; isFSO: this is FileSystemObject; isFile: this is File; - isDirectory: this is Directory; + readonly isDirectory: this is Directory; isNetworked: this is (Networked & this); constructor(path: string); } From 3661b66be41a9724ba08d01a2b02aec548f1f7e9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 28 Jan 2016 14:18:23 -0800 Subject: [PATCH 33/36] add extra argument to 'isRequireCall' to check if argument is string literal --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 2 +- src/compiler/program.ts | 2 +- src/compiler/utilities.ts | 5 +++-- tests/baselines/reference/dynamicRequire.js | 10 ++++++++++ tests/baselines/reference/dynamicRequire.symbols | 10 ++++++++++ tests/baselines/reference/dynamicRequire.types | 14 ++++++++++++++ tests/cases/compiler/dynamicRequire.ts | 8 ++++++++ 8 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/dynamicRequire.js create mode 100644 tests/baselines/reference/dynamicRequire.symbols create mode 100644 tests/baselines/reference/dynamicRequire.types create mode 100644 tests/cases/compiler/dynamicRequire.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 88a1a62ce4c..cc81f92fbfc 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1462,7 +1462,7 @@ namespace ts { function bindCallExpression(node: CallExpression) { // We're only inspecting call expressions to detect CommonJS modules, so we can skip // this check if we've already seen the module indicator - if (!file.commonJsModuleIndicator && isRequireCall(node)) { + if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/false)) { setCommonJsModuleIndicator(node); } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 784d3ef67e8..91f3561d829 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10239,7 +10239,7 @@ namespace ts { } // In JavaScript files, calls to any identifier 'require' are treated as external module imports - if (isInJavaScriptFile(node) && isRequireCall(node)) { + if (isInJavaScriptFile(node) && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { return resolveExternalModuleTypeByLiteral(node.arguments[0]); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4187177fa48..803ae47b0fd 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1328,7 +1328,7 @@ namespace ts { } function collectRequireCalls(node: Node): void { - if (isRequireCall(node)) { + if (isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { (imports || (imports = [])).push((node).arguments[0]); } else { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 33ad24d7f56..67dd9844ca7 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1086,12 +1086,13 @@ namespace ts { * exactly one argument. * This function does not test if the node is in a JavaScript file or not. */ - export function isRequireCall(expression: Node): expression is CallExpression { + export function isRequireCall(expression: Node, checkArgumentIsStringLiteral: boolean): expression is CallExpression { // of the form 'require("name")' - return expression.kind === SyntaxKind.CallExpression && + const isRequire = expression.kind === SyntaxKind.CallExpression && (expression).expression.kind === SyntaxKind.Identifier && ((expression).expression).text === "require" && (expression).arguments.length === 1; + return isRequire && (!checkArgumentIsStringLiteral || (expression).arguments[0].kind === SyntaxKind.StringLiteral); } /// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property diff --git a/tests/baselines/reference/dynamicRequire.js b/tests/baselines/reference/dynamicRequire.js new file mode 100644 index 00000000000..28b35970601 --- /dev/null +++ b/tests/baselines/reference/dynamicRequire.js @@ -0,0 +1,10 @@ +//// [a.js] + +function foo(name) { + var s = require("t/" + name) +} + +//// [a_out.js] +function foo(name) { + var s = require("t/" + name); +} diff --git a/tests/baselines/reference/dynamicRequire.symbols b/tests/baselines/reference/dynamicRequire.symbols new file mode 100644 index 00000000000..c307d578de7 --- /dev/null +++ b/tests/baselines/reference/dynamicRequire.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/a.js === + +function foo(name) { +>foo : Symbol(foo, Decl(a.js, 0, 0)) +>name : Symbol(name, Decl(a.js, 1, 13)) + + var s = require("t/" + name) +>s : Symbol(s, Decl(a.js, 2, 7)) +>name : Symbol(name, Decl(a.js, 1, 13)) +} diff --git a/tests/baselines/reference/dynamicRequire.types b/tests/baselines/reference/dynamicRequire.types new file mode 100644 index 00000000000..43eea88a05b --- /dev/null +++ b/tests/baselines/reference/dynamicRequire.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/a.js === + +function foo(name) { +>foo : (name: any) => void +>name : any + + var s = require("t/" + name) +>s : any +>require("t/" + name) : any +>require : any +>"t/" + name : string +>"t/" : string +>name : any +} diff --git a/tests/cases/compiler/dynamicRequire.ts b/tests/cases/compiler/dynamicRequire.ts new file mode 100644 index 00000000000..8d72a37dceb --- /dev/null +++ b/tests/cases/compiler/dynamicRequire.ts @@ -0,0 +1,8 @@ +// @allowJs: true +// @module: amd +// @out: a_out.js + +// @filename: a.js +function foo(name) { + var s = require("t/" + name) +} \ No newline at end of file From b3eaef17e9fb9675e36dad37445b41cc67d25c1e Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 28 Jan 2016 14:21:04 -0800 Subject: [PATCH 34/36] fix linter issues --- src/compiler/utilities.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 67dd9844ca7..bab66eb0688 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1089,10 +1089,11 @@ namespace ts { export function isRequireCall(expression: Node, checkArgumentIsStringLiteral: boolean): expression is CallExpression { // of the form 'require("name")' const isRequire = expression.kind === SyntaxKind.CallExpression && - (expression).expression.kind === SyntaxKind.Identifier && - ((expression).expression).text === "require" && - (expression).arguments.length === 1; - return isRequire && (!checkArgumentIsStringLiteral || (expression).arguments[0].kind === SyntaxKind.StringLiteral); + (expression).expression.kind === SyntaxKind.Identifier && + ((expression).expression).text === "require" && + (expression).arguments.length === 1; + + return isRequire && (!checkArgumentIsStringLiteral || (expression).arguments[0].kind === SyntaxKind.StringLiteral); } /// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property From 94fe3e0fb27f2b9480e98620c13ef90197ae0e8f Mon Sep 17 00:00:00 2001 From: guybedford Date: Thu, 28 Jan 2016 12:56:38 +0200 Subject: [PATCH 35/36] set __moduleName from context.id argument --- src/compiler/emitter.ts | 9 ++- .../reference/aliasesInSystemModule1.js | 3 +- .../reference/aliasesInSystemModule2.js | 3 +- .../allowSyntheticDefaultImports2.js | 6 +- .../allowSyntheticDefaultImports3.js | 6 +- .../allowSyntheticDefaultImports5.js | 3 +- .../allowSyntheticDefaultImports6.js | 3 +- .../anonymousDefaultExportsSystem.js | 6 +- .../reference/capturedLetConstInLoop4.js | 3 +- ...ecoratedDefaultExportsGetExportedSystem.js | 6 +- .../reference/deduplicateImportsInSystem.js | 3 +- .../defaultExportsGetExportedSystem.js | 6 +- tests/baselines/reference/es5-system.js | 3 +- .../exportNonInitializedVariablesSystem.js | 3 +- .../reference/exportStarForValues10.js | 9 ++- .../reference/exportStarForValues6.js | 6 +- .../reference/exportStarForValuesInSystem.js | 6 +- .../isolatedModulesPlainFile-System.js | 3 +- .../reference/modulePrologueSystem.js | 3 +- .../outFilerootDirModuleNamesSystem.js | 6 +- .../reference/outModuleConcatSystem.js | 6 +- .../reference/outModuleConcatSystem.js.map | 2 +- .../outModuleConcatSystem.sourcemap.txt | 70 ++++++++++--------- ...prefixUnaryOperatorsOnExportedVariables.js | 3 +- .../reference/systemExportAssignment.js | 3 +- .../reference/systemExportAssignment2.js | 6 +- .../reference/systemExportAssignment3.js | 3 +- tests/baselines/reference/systemModule1.js | 3 +- tests/baselines/reference/systemModule10.js | 3 +- .../baselines/reference/systemModule10_ES5.js | 3 +- tests/baselines/reference/systemModule11.js | 15 ++-- tests/baselines/reference/systemModule12.js | 3 +- tests/baselines/reference/systemModule13.js | 3 +- tests/baselines/reference/systemModule14.js | 3 +- tests/baselines/reference/systemModule15.js | 12 ++-- tests/baselines/reference/systemModule16.js | 3 +- tests/baselines/reference/systemModule17.js | 6 +- tests/baselines/reference/systemModule2.js | 3 +- tests/baselines/reference/systemModule3.js | 12 ++-- tests/baselines/reference/systemModule4.js | 3 +- tests/baselines/reference/systemModule5.js | 3 +- tests/baselines/reference/systemModule6.js | 3 +- tests/baselines/reference/systemModule7.js | 3 +- tests/baselines/reference/systemModule8.js | 3 +- tests/baselines/reference/systemModule9.js | 3 +- .../systemModuleAmbientDeclarations.js | 18 +++-- .../reference/systemModuleConstEnums.js | 3 +- ...stemModuleConstEnumsSeparateCompilation.js | 3 +- .../systemModuleDeclarationMerging.js | 3 +- .../reference/systemModuleExportDefault.js | 12 ++-- .../systemModuleNonTopLevelModuleMembers.js | 3 +- .../reference/systemModuleWithSuperClass.js | 6 +- tests/cases/unittests/transpile.ts | 8 ++- 53 files changed, 213 insertions(+), 119 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4d771bd2538..d01843eddb4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -477,6 +477,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // => // var x;... exporter("x", x = 1) let exportFunctionForFile: string; + let contextObjectForFile: string; let generatedNameSet: Map; let nodeToGeneratedName: string[]; @@ -557,6 +558,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge currentText = undefined; currentLineMap = undefined; exportFunctionForFile = undefined; + contextObjectForFile = undefined; generatedNameSet = undefined; nodeToGeneratedName = undefined; computedPropertyNamesToGeneratedNames = undefined; @@ -585,6 +587,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge currentText = sourceFile.text; currentLineMap = getLineStarts(sourceFile); exportFunctionForFile = undefined; + contextObjectForFile = undefined; isEs6Module = sourceFile.symbol && sourceFile.symbol.exports && !!sourceFile.symbol.exports["___esModule"]; renamedDependencies = sourceFile.renamedDependencies; currentFileIdentifiers = sourceFile.identifiers; @@ -7058,6 +7061,7 @@ const _super = (function (geti, seti) { Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); + contextObjectForFile = makeUniqueName("context"); writeLine(); write("System.register("); writeModuleName(node, emitRelativePathAsModuleName); @@ -7093,10 +7097,13 @@ const _super = (function (geti, seti) { write(text); } - write(`], function(${exportFunctionForFile}) {`); + write(`], function(${exportFunctionForFile}, ${contextObjectForFile}) {`); writeLine(); increaseIndent(); const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true); + writeLine(); + write(`var __moduleName = ${contextObjectForFile} && ${contextObjectForFile}.id;`); + writeLine(); emitEmitHelpers(node); emitCaptureThisForNodeIfNecessary(node); emitSystemModuleBody(node, dependencyGroups, startIndex); diff --git a/tests/baselines/reference/aliasesInSystemModule1.js b/tests/baselines/reference/aliasesInSystemModule1.js index 43037c7634c..46d2b061dd3 100644 --- a/tests/baselines/reference/aliasesInSystemModule1.js +++ b/tests/baselines/reference/aliasesInSystemModule1.js @@ -17,8 +17,9 @@ module M { //// [aliasesInSystemModule1.js] -System.register(['foo'], function(exports_1) { +System.register(['foo'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var alias; var cls, cls2, x, y, z, M; return { diff --git a/tests/baselines/reference/aliasesInSystemModule2.js b/tests/baselines/reference/aliasesInSystemModule2.js index 7effb2721be..e30ba4fea56 100644 --- a/tests/baselines/reference/aliasesInSystemModule2.js +++ b/tests/baselines/reference/aliasesInSystemModule2.js @@ -16,8 +16,9 @@ module M { } //// [aliasesInSystemModule2.js] -System.register(["foo"], function(exports_1) { +System.register(["foo"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var foo_1; var cls, cls2, x, y, z, M; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.js b/tests/baselines/reference/allowSyntheticDefaultImports2.js index fcc029415cf..87e47f9c9a1 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports2.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.js @@ -10,8 +10,9 @@ export class Foo { } //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -26,8 +27,9 @@ System.register([], function(exports_1) { } }); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports3.js b/tests/baselines/reference/allowSyntheticDefaultImports3.js index b14d25dbd61..348ce42a60a 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports3.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports3.js @@ -11,8 +11,9 @@ export class Foo { //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -27,8 +28,9 @@ System.register([], function(exports_1) { } }); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports5.js b/tests/baselines/reference/allowSyntheticDefaultImports5.js index c9121512b61..f59226e152d 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports5.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports5.js @@ -12,8 +12,9 @@ export var x = new Foo(); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports6.js b/tests/baselines/reference/allowSyntheticDefaultImports6.js index 64d52e70af9..d2f25e538c5 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports6.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports6.js @@ -12,8 +12,9 @@ export var x = new Foo(); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var b_1; var x; return { diff --git a/tests/baselines/reference/anonymousDefaultExportsSystem.js b/tests/baselines/reference/anonymousDefaultExportsSystem.js index 74913a57a99..f9ff71dec06 100644 --- a/tests/baselines/reference/anonymousDefaultExportsSystem.js +++ b/tests/baselines/reference/anonymousDefaultExportsSystem.js @@ -7,8 +7,9 @@ export default class {} export default function() {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var default_1; return { setters:[], @@ -20,8 +21,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function default_1() { } exports_1("default", default_1); return { diff --git a/tests/baselines/reference/capturedLetConstInLoop4.js b/tests/baselines/reference/capturedLetConstInLoop4.js index 160be3ccaef..04f514b01e8 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.js +++ b/tests/baselines/reference/capturedLetConstInLoop4.js @@ -144,8 +144,9 @@ for (const y = 0; y < 1;) { //// [capturedLetConstInLoop4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var v0, v00, v1, v2, v3, v4, v5, v6, v7, v8, v0_c, v00_c, v1_c, v2_c, v3_c, v4_c, v5_c, v6_c, v7_c, v8_c; //======let function exportedFoo() { diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js index ed322374799..ca4bb52a32b 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js @@ -13,8 +13,9 @@ var decorator: ClassDecorator; export default class {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); @@ -35,8 +36,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); diff --git a/tests/baselines/reference/deduplicateImportsInSystem.js b/tests/baselines/reference/deduplicateImportsInSystem.js index 956d293cad1..accc4954e65 100644 --- a/tests/baselines/reference/deduplicateImportsInSystem.js +++ b/tests/baselines/reference/deduplicateImportsInSystem.js @@ -9,8 +9,9 @@ import {F} from 'f1'; console.log(A + B + C + D + E + F) //// [deduplicateImportsInSystem.js] -System.register(["f1", "f2", "f3"], function(exports_1) { +System.register(["f1", "f2", "f3"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var f1_1, f2_1, f3_1, f2_2, f2_3, f1_2; return { setters:[ diff --git a/tests/baselines/reference/defaultExportsGetExportedSystem.js b/tests/baselines/reference/defaultExportsGetExportedSystem.js index 67dc47f4bd5..eac3d3c7c43 100644 --- a/tests/baselines/reference/defaultExportsGetExportedSystem.js +++ b/tests/baselines/reference/defaultExportsGetExportedSystem.js @@ -8,8 +8,9 @@ export default function foo() {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -21,8 +22,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("default", foo); return { diff --git a/tests/baselines/reference/es5-system.js b/tests/baselines/reference/es5-system.js index a9633352b8b..9cf5ea87f1f 100644 --- a/tests/baselines/reference/es5-system.js +++ b/tests/baselines/reference/es5-system.js @@ -15,8 +15,9 @@ export default class A //// [es5-system.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var A; return { setters:[], diff --git a/tests/baselines/reference/exportNonInitializedVariablesSystem.js b/tests/baselines/reference/exportNonInitializedVariablesSystem.js index b5674bf5ce3..2a8e2022c95 100644 --- a/tests/baselines/reference/exportNonInitializedVariablesSystem.js +++ b/tests/baselines/reference/exportNonInitializedVariablesSystem.js @@ -35,8 +35,9 @@ export let h1: D = new D; //// [exportNonInitializedVariablesSystem.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var a, b, c, d, A, e, f, B, C, a1, b1, c1, d1, D, e1, f1, g1, h1; return { setters:[], diff --git a/tests/baselines/reference/exportStarForValues10.js b/tests/baselines/reference/exportStarForValues10.js index dca5dad9b7a..d37ca3304f3 100644 --- a/tests/baselines/reference/exportStarForValues10.js +++ b/tests/baselines/reference/exportStarForValues10.js @@ -13,8 +13,9 @@ export * from "file1"; var x = 1; //// [file0.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var v; return { setters:[], @@ -24,8 +25,9 @@ System.register([], function(exports_1) { } }); //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -33,8 +35,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register(["file0"], function(exports_1) { +System.register(["file0"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; function exportStar_1(m) { var exports = {}; diff --git a/tests/baselines/reference/exportStarForValues6.js b/tests/baselines/reference/exportStarForValues6.js index 69357d87ee0..8c31f6b4d16 100644 --- a/tests/baselines/reference/exportStarForValues6.js +++ b/tests/baselines/reference/exportStarForValues6.js @@ -9,8 +9,9 @@ export * from "file1" export var x = 1; //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -18,8 +19,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/exportStarForValuesInSystem.js b/tests/baselines/reference/exportStarForValuesInSystem.js index a33465f7e2e..49c6877377a 100644 --- a/tests/baselines/reference/exportStarForValuesInSystem.js +++ b/tests/baselines/reference/exportStarForValuesInSystem.js @@ -9,8 +9,9 @@ export * from "file1" var x = 1; //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -18,8 +19,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/isolatedModulesPlainFile-System.js b/tests/baselines/reference/isolatedModulesPlainFile-System.js index b66bd497810..39320759740 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-System.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-System.js @@ -5,8 +5,9 @@ run(1); //// [isolatedModulesPlainFile-System.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/modulePrologueSystem.js b/tests/baselines/reference/modulePrologueSystem.js index 80a46fb27fc..13f7d35b001 100644 --- a/tests/baselines/reference/modulePrologueSystem.js +++ b/tests/baselines/reference/modulePrologueSystem.js @@ -4,8 +4,9 @@ export class Foo {} //// [modulePrologueSystem.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], diff --git a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js index 298ad52689f..eb1ef2a4a54 100644 --- a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js +++ b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js @@ -11,8 +11,9 @@ export default function foo() { new Foo(); } //// [output.js] -System.register("b", ["a"], function(exports_1) { +System.register("b", ["a"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var a_1; function foo() { new a_1.default(); } exports_1("default", foo); @@ -25,8 +26,9 @@ System.register("b", ["a"], function(exports_1) { } } }); -System.register("a", ["b"], function(exports_2) { +System.register("a", ["b"], function(exports_2, context_2) { "use strict"; + var __moduleName = context_2 && context_2.id; var b_1; var Foo; return { diff --git a/tests/baselines/reference/outModuleConcatSystem.js b/tests/baselines/reference/outModuleConcatSystem.js index d4552d33167..59bbb363022 100644 --- a/tests/baselines/reference/outModuleConcatSystem.js +++ b/tests/baselines/reference/outModuleConcatSystem.js @@ -14,8 +14,9 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -System.register("ref/a", [], function(exports_1) { +System.register("ref/a", [], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var A; return { setters:[], @@ -29,8 +30,9 @@ System.register("ref/a", [], function(exports_1) { } } }); -System.register("b", ["ref/a"], function(exports_2) { +System.register("b", ["ref/a"], function(exports_2, context_2) { "use strict"; + var __moduleName = context_2 && context_2.id; var a_1; var B; return { diff --git a/tests/baselines/reference/outModuleConcatSystem.js.map b/tests/baselines/reference/outModuleConcatSystem.js.map index 47d3ba2d39c..be6e66c3cf4 100644 --- a/tests/baselines/reference/outModuleConcatSystem.js.map +++ b/tests/baselines/reference/outModuleConcatSystem.js.map @@ -1,2 +1,2 @@ //// [all.js.map] -{"version":3,"file":"all.js","sourceRoot":"","sources":["tests/cases/compiler/ref/a.ts","tests/cases/compiler/b.ts"],"names":[],"mappings":";;;;;;;;;;;YACA;gBAAA;gBAAiB,CAAC;gBAAD,QAAC;YAAD,CAAC,AAAlB,IAAkB;YAAlB,iBAAkB,CAAA;;;;;;;;;;;;;;YCAlB;gBAAuB,qBAAC;gBAAxB;oBAAuB,8BAAC;gBAAG,CAAC;gBAAD,QAAC;YAAD,CAAC,AAA5B,CAAuB,KAAC,GAAI;YAA5B,iBAA4B,CAAA"} \ No newline at end of file +{"version":3,"file":"all.js","sourceRoot":"","sources":["tests/cases/compiler/ref/a.ts","tests/cases/compiler/b.ts"],"names":[],"mappings":";;;;;;;;;;;;YACA;gBAAA;gBAAiB,CAAC;gBAAD,QAAC;YAAD,CAAC,AAAlB,IAAkB;YAAlB,iBAAkB,CAAA;;;;;;;;;;;;;;;YCAlB;gBAAuB,qBAAC;gBAAxB;oBAAuB,8BAAC;gBAAG,CAAC;gBAAD,QAAC;YAAD,CAAC,AAA5B,CAAuB,KAAC,GAAI;YAA5B,iBAA4B,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt b/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt index e3f521c828c..0281bdec5bd 100644 --- a/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt +++ b/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt @@ -13,8 +13,9 @@ sourceFile:tests/cases/compiler/ref/a.ts >>> function __() { this.constructor = d; } >>> d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); >>>}; ->>>System.register("ref/a", [], function(exports_1) { +>>>System.register("ref/a", [], function(exports_1, context_1) { >>> "use strict"; +>>> var __moduleName = context_1 && context_1.id; >>> var A; >>> return { >>> setters:[], @@ -24,13 +25,13 @@ sourceFile:tests/cases/compiler/ref/a.ts 2 > ^^^^^^^^^^^^^^^^^^^-> 1 > > -1 >Emitted(12, 13) Source(2, 1) + SourceIndex(0) +1 >Emitted(13, 13) Source(2, 1) + SourceIndex(0) --- >>> function A() { 1->^^^^^^^^^^^^^^^^ 2 > ^^-> 1-> -1->Emitted(13, 17) Source(2, 1) + SourceIndex(0) +1->Emitted(14, 17) Source(2, 1) + SourceIndex(0) --- >>> } 1->^^^^^^^^^^^^^^^^ @@ -38,16 +39,16 @@ sourceFile:tests/cases/compiler/ref/a.ts 3 > ^^^^^^^^^-> 1->export class A { 2 > } -1->Emitted(14, 17) Source(2, 18) + SourceIndex(0) -2 >Emitted(14, 18) Source(2, 19) + SourceIndex(0) +1->Emitted(15, 17) Source(2, 18) + SourceIndex(0) +2 >Emitted(15, 18) Source(2, 19) + SourceIndex(0) --- >>> return A; 1->^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^ 1-> 2 > } -1->Emitted(15, 17) Source(2, 18) + SourceIndex(0) -2 >Emitted(15, 25) Source(2, 19) + SourceIndex(0) +1->Emitted(16, 17) Source(2, 18) + SourceIndex(0) +2 >Emitted(16, 25) Source(2, 19) + SourceIndex(0) --- >>> }()); 1 >^^^^^^^^^^^^ @@ -59,10 +60,10 @@ sourceFile:tests/cases/compiler/ref/a.ts 2 > } 3 > 4 > export class A { } -1 >Emitted(16, 13) Source(2, 18) + SourceIndex(0) -2 >Emitted(16, 14) Source(2, 19) + SourceIndex(0) -3 >Emitted(16, 14) Source(2, 1) + SourceIndex(0) -4 >Emitted(16, 18) Source(2, 19) + SourceIndex(0) +1 >Emitted(17, 13) Source(2, 18) + SourceIndex(0) +2 >Emitted(17, 14) Source(2, 19) + SourceIndex(0) +3 >Emitted(17, 14) Source(2, 1) + SourceIndex(0) +4 >Emitted(17, 18) Source(2, 19) + SourceIndex(0) --- >>> exports_1("A", A); 1->^^^^^^^^^^^^ @@ -71,9 +72,9 @@ sourceFile:tests/cases/compiler/ref/a.ts 1-> 2 > export class A { } 3 > -1->Emitted(17, 13) Source(2, 1) + SourceIndex(0) -2 >Emitted(17, 30) Source(2, 19) + SourceIndex(0) -3 >Emitted(17, 31) Source(2, 19) + SourceIndex(0) +1->Emitted(18, 13) Source(2, 1) + SourceIndex(0) +2 >Emitted(18, 30) Source(2, 19) + SourceIndex(0) +3 >Emitted(18, 31) Source(2, 19) + SourceIndex(0) --- ------------------------------------------------------------------- emittedFile:all.js @@ -82,8 +83,9 @@ sourceFile:tests/cases/compiler/b.ts >>> } >>> } >>>}); ->>>System.register("b", ["ref/a"], function(exports_2) { +>>>System.register("b", ["ref/a"], function(exports_2, context_2) { >>> "use strict"; +>>> var __moduleName = context_2 && context_2.id; >>> var a_1; >>> var B; >>> return { @@ -97,29 +99,29 @@ sourceFile:tests/cases/compiler/b.ts 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 >import {A} from "./ref/a"; > -1 >Emitted(31, 13) Source(2, 1) + SourceIndex(1) +1 >Emitted(33, 13) Source(2, 1) + SourceIndex(1) --- >>> __extends(B, _super); 1->^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^ 1->export class B extends 2 > A -1->Emitted(32, 17) Source(2, 24) + SourceIndex(1) -2 >Emitted(32, 38) Source(2, 25) + SourceIndex(1) +1->Emitted(34, 17) Source(2, 24) + SourceIndex(1) +2 >Emitted(34, 38) Source(2, 25) + SourceIndex(1) --- >>> function B() { 1 >^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > -1 >Emitted(33, 17) Source(2, 1) + SourceIndex(1) +1 >Emitted(35, 17) Source(2, 1) + SourceIndex(1) --- >>> _super.apply(this, arguments); 1->^^^^^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1->export class B extends 2 > A -1->Emitted(34, 21) Source(2, 24) + SourceIndex(1) -2 >Emitted(34, 51) Source(2, 25) + SourceIndex(1) +1->Emitted(36, 21) Source(2, 24) + SourceIndex(1) +2 >Emitted(36, 51) Source(2, 25) + SourceIndex(1) --- >>> } 1 >^^^^^^^^^^^^^^^^ @@ -127,16 +129,16 @@ sourceFile:tests/cases/compiler/b.ts 3 > ^^^^^^^^^-> 1 > { 2 > } -1 >Emitted(35, 17) Source(2, 28) + SourceIndex(1) -2 >Emitted(35, 18) Source(2, 29) + SourceIndex(1) +1 >Emitted(37, 17) Source(2, 28) + SourceIndex(1) +2 >Emitted(37, 18) Source(2, 29) + SourceIndex(1) --- >>> return B; 1->^^^^^^^^^^^^^^^^ 2 > ^^^^^^^^ 1-> 2 > } -1->Emitted(36, 17) Source(2, 28) + SourceIndex(1) -2 >Emitted(36, 25) Source(2, 29) + SourceIndex(1) +1->Emitted(38, 17) Source(2, 28) + SourceIndex(1) +2 >Emitted(38, 25) Source(2, 29) + SourceIndex(1) --- >>> }(a_1.A)); 1 >^^^^^^^^^^^^ @@ -152,12 +154,12 @@ sourceFile:tests/cases/compiler/b.ts 4 > export class B extends 5 > A 6 > { } -1 >Emitted(37, 13) Source(2, 28) + SourceIndex(1) -2 >Emitted(37, 14) Source(2, 29) + SourceIndex(1) -3 >Emitted(37, 14) Source(2, 1) + SourceIndex(1) -4 >Emitted(37, 15) Source(2, 24) + SourceIndex(1) -5 >Emitted(37, 20) Source(2, 25) + SourceIndex(1) -6 >Emitted(37, 23) Source(2, 29) + SourceIndex(1) +1 >Emitted(39, 13) Source(2, 28) + SourceIndex(1) +2 >Emitted(39, 14) Source(2, 29) + SourceIndex(1) +3 >Emitted(39, 14) Source(2, 1) + SourceIndex(1) +4 >Emitted(39, 15) Source(2, 24) + SourceIndex(1) +5 >Emitted(39, 20) Source(2, 25) + SourceIndex(1) +6 >Emitted(39, 23) Source(2, 29) + SourceIndex(1) --- >>> exports_2("B", B); 1->^^^^^^^^^^^^ @@ -166,9 +168,9 @@ sourceFile:tests/cases/compiler/b.ts 1-> 2 > export class B extends A { } 3 > -1->Emitted(38, 13) Source(2, 1) + SourceIndex(1) -2 >Emitted(38, 30) Source(2, 29) + SourceIndex(1) -3 >Emitted(38, 31) Source(2, 29) + SourceIndex(1) +1->Emitted(40, 13) Source(2, 1) + SourceIndex(1) +2 >Emitted(40, 30) Source(2, 29) + SourceIndex(1) +3 >Emitted(40, 31) Source(2, 29) + SourceIndex(1) --- >>> } >>> } diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js index 5d414c97d05..cf88f4e9ba6 100644 --- a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js @@ -31,8 +31,9 @@ if (++y) { } //// [prefixUnaryOperatorsOnExportedVariables.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y; return { setters:[], diff --git a/tests/baselines/reference/systemExportAssignment.js b/tests/baselines/reference/systemExportAssignment.js index 72962cf835c..1e87af1ca22 100644 --- a/tests/baselines/reference/systemExportAssignment.js +++ b/tests/baselines/reference/systemExportAssignment.js @@ -10,8 +10,9 @@ import * as a from "a"; //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemExportAssignment2.js b/tests/baselines/reference/systemExportAssignment2.js index 0f4dd712493..177f36f23d2 100644 --- a/tests/baselines/reference/systemExportAssignment2.js +++ b/tests/baselines/reference/systemExportAssignment2.js @@ -10,8 +10,9 @@ import * as a from "a"; //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var a; return { setters:[], @@ -21,8 +22,9 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemExportAssignment3.js b/tests/baselines/reference/systemExportAssignment3.js index ca2492a54e1..78e330c6467 100644 --- a/tests/baselines/reference/systemExportAssignment3.js +++ b/tests/baselines/reference/systemExportAssignment3.js @@ -12,8 +12,9 @@ import * as a from "a"; //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemModule1.js b/tests/baselines/reference/systemModule1.js index 52f3b482069..2b7e3e2c4dc 100644 --- a/tests/baselines/reference/systemModule1.js +++ b/tests/baselines/reference/systemModule1.js @@ -3,8 +3,9 @@ export var x = 1; //// [systemModule1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/systemModule10.js b/tests/baselines/reference/systemModule10.js index ac32c4948e7..0c171ab6cc1 100644 --- a/tests/baselines/reference/systemModule10.js +++ b/tests/baselines/reference/systemModule10.js @@ -10,8 +10,9 @@ export {n2} export {n2 as n3} //// [systemModule10.js] -System.register(['file1', 'file2'], function(exports_1) { +System.register(['file1', 'file2'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var file1_1, n2; return { setters:[ diff --git a/tests/baselines/reference/systemModule10_ES5.js b/tests/baselines/reference/systemModule10_ES5.js index 0c98df6ba99..711ca3ed7a3 100644 --- a/tests/baselines/reference/systemModule10_ES5.js +++ b/tests/baselines/reference/systemModule10_ES5.js @@ -10,8 +10,9 @@ export {n2} export {n2 as n3} //// [systemModule10_ES5.js] -System.register(['file1', 'file2'], function(exports_1) { +System.register(['file1', 'file2'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var file1_1, n2; return { setters:[ diff --git a/tests/baselines/reference/systemModule11.js b/tests/baselines/reference/systemModule11.js index 92b0576b919..f7d47db1d7f 100644 --- a/tests/baselines/reference/systemModule11.js +++ b/tests/baselines/reference/systemModule11.js @@ -42,8 +42,9 @@ export * from 'a'; //// [file1.js] // set of tests cases that checks generation of local storage for exported names -System.register(['bar'], function(exports_1) { +System.register(['bar'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; function foo() { } exports_1("foo", foo); @@ -68,8 +69,9 @@ System.register(['bar'], function(exports_1) { } }); //// [file2.js] -System.register(['bar'], function(exports_1) { +System.register(['bar'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y; var exportedNames_1 = { 'x': true, @@ -94,8 +96,9 @@ System.register(['bar'], function(exports_1) { } }); //// [file3.js] -System.register(['a', 'bar'], function(exports_1) { +System.register(['a', 'bar'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("default", foo); var exportedNames_1 = { @@ -125,8 +128,9 @@ System.register(['a', 'bar'], function(exports_1) { } }); //// [file4.js] -System.register(['a'], function(exports_1) { +System.register(['a'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, z, z1; function foo() { } exports_1("foo", foo); @@ -147,8 +151,9 @@ System.register(['a'], function(exports_1) { } }); //// [file5.js] -System.register(['a'], function(exports_1) { +System.register(['a'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } function exportStar_1(m) { var exports = {}; diff --git a/tests/baselines/reference/systemModule12.js b/tests/baselines/reference/systemModule12.js index d8961c3b001..45e7beaf218 100644 --- a/tests/baselines/reference/systemModule12.js +++ b/tests/baselines/reference/systemModule12.js @@ -5,8 +5,9 @@ import n from 'file1' //// [systemModule12.js] -System.register("NamedModule", [], function(exports_1) { +System.register("NamedModule", [], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemModule13.js b/tests/baselines/reference/systemModule13.js index 0b81a946de4..e3ed2daf3a6 100644 --- a/tests/baselines/reference/systemModule13.js +++ b/tests/baselines/reference/systemModule13.js @@ -5,8 +5,9 @@ export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; for ([x] of [[1]]) {} //// [systemModule13.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y, z, z0, z1; return { setters:[], diff --git a/tests/baselines/reference/systemModule14.js b/tests/baselines/reference/systemModule14.js index 2ec8fc600f4..5eaafd9ba6b 100644 --- a/tests/baselines/reference/systemModule14.js +++ b/tests/baselines/reference/systemModule14.js @@ -11,8 +11,9 @@ var x = 1; export {foo as b} //// [systemModule14.js] -System.register(["foo"], function(exports_1) { +System.register(["foo"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var foo_1; var x; function foo() { diff --git a/tests/baselines/reference/systemModule15.js b/tests/baselines/reference/systemModule15.js index f8dc11b0ac7..f2fefb344ac 100644 --- a/tests/baselines/reference/systemModule15.js +++ b/tests/baselines/reference/systemModule15.js @@ -34,8 +34,9 @@ export default value; export var value2 = "v"; //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var value; return { setters:[], @@ -46,8 +47,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var value2; return { setters:[], @@ -57,8 +59,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register(["./file3"], function(exports_1) { +System.register(["./file3"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var moduleCStar, file3_1, file3_2; return { setters:[ @@ -75,8 +78,9 @@ System.register(["./file3"], function(exports_1) { } }); //// [file1.js] -System.register(["./file2"], function(exports_1) { +System.register(["./file2"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var moduleB; return { setters:[ diff --git a/tests/baselines/reference/systemModule16.js b/tests/baselines/reference/systemModule16.js index 76fb85cd3ae..27fa77b9c76 100644 --- a/tests/baselines/reference/systemModule16.js +++ b/tests/baselines/reference/systemModule16.js @@ -13,8 +13,9 @@ x,y,a1,b1,d1; //// [systemModule16.js] -System.register(["foo", "bar"], function(exports_1) { +System.register(["foo", "bar"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y, foo_1; var exportedNames_1 = { 'x': true, diff --git a/tests/baselines/reference/systemModule17.js b/tests/baselines/reference/systemModule17.js index 6daa119d287..6bf1ce25b84 100644 --- a/tests/baselines/reference/systemModule17.js +++ b/tests/baselines/reference/systemModule17.js @@ -42,8 +42,9 @@ export {II}; export {II as II1}; //// [f1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var A; return { setters:[], @@ -58,8 +59,9 @@ System.register([], function(exports_1) { } }); //// [f2.js] -System.register(["f1"], function(exports_1) { +System.register(["f1"], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var f1_1; var x, N, IX; return { diff --git a/tests/baselines/reference/systemModule2.js b/tests/baselines/reference/systemModule2.js index ee3dfd327ec..95755421eaa 100644 --- a/tests/baselines/reference/systemModule2.js +++ b/tests/baselines/reference/systemModule2.js @@ -4,8 +4,9 @@ var x = 1; export = x; //// [systemModule2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x; return { setters:[], diff --git a/tests/baselines/reference/systemModule3.js b/tests/baselines/reference/systemModule3.js index dbef74f3036..7800c8c220e 100644 --- a/tests/baselines/reference/systemModule3.js +++ b/tests/baselines/reference/systemModule3.js @@ -18,8 +18,9 @@ export default class C {} export default class {} //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function default_1() { } exports_1("default", default_1); return { @@ -29,8 +30,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function f() { } exports_1("default", f); return { @@ -40,8 +42,9 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var C; return { setters:[], @@ -56,8 +59,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var default_1; return { setters:[], diff --git a/tests/baselines/reference/systemModule4.js b/tests/baselines/reference/systemModule4.js index 192c87d49ea..67990c63a58 100644 --- a/tests/baselines/reference/systemModule4.js +++ b/tests/baselines/reference/systemModule4.js @@ -4,8 +4,9 @@ export var x = 1; export var y; //// [systemModule4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y; return { setters:[], diff --git a/tests/baselines/reference/systemModule5.js b/tests/baselines/reference/systemModule5.js index 4a455f25b13..d0b1f79b2f7 100644 --- a/tests/baselines/reference/systemModule5.js +++ b/tests/baselines/reference/systemModule5.js @@ -4,8 +4,9 @@ export function foo() {} //// [systemModule5.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("foo", foo); return { diff --git a/tests/baselines/reference/systemModule6.js b/tests/baselines/reference/systemModule6.js index 51c8fbc68fb..4848c82f738 100644 --- a/tests/baselines/reference/systemModule6.js +++ b/tests/baselines/reference/systemModule6.js @@ -7,8 +7,9 @@ function foo() { //// [systemModule6.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var C; function foo() { new C(); diff --git a/tests/baselines/reference/systemModule7.js b/tests/baselines/reference/systemModule7.js index d76d86a3b0f..60114b54400 100644 --- a/tests/baselines/reference/systemModule7.js +++ b/tests/baselines/reference/systemModule7.js @@ -11,8 +11,9 @@ export module M { } //// [systemModule7.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var M; return { setters:[], diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js index b6cdd677f00..f099628facb 100644 --- a/tests/baselines/reference/systemModule8.js +++ b/tests/baselines/reference/systemModule8.js @@ -31,8 +31,9 @@ export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; for ([x] of [[1]]) {} //// [systemModule8.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var x, y, z0, z1; function foo() { exports_1("x", x = 100); diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js index 137dd019a02..940b9e5975b 100644 --- a/tests/baselines/reference/systemModule9.js +++ b/tests/baselines/reference/systemModule9.js @@ -22,8 +22,9 @@ export {x}; export {y as z}; //// [systemModule9.js] -System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1) { +System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var ns, file2_1, file3_1, file5_1, ns3; var x, y; var exportedNames_1 = { diff --git a/tests/baselines/reference/systemModuleAmbientDeclarations.js b/tests/baselines/reference/systemModuleAmbientDeclarations.js index 9bdde23a842..91bad620b77 100644 --- a/tests/baselines/reference/systemModuleAmbientDeclarations.js +++ b/tests/baselines/reference/systemModuleAmbientDeclarations.js @@ -29,8 +29,9 @@ export declare module M { var v: number; } //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var promise, foo, c, e; return { setters:[], @@ -44,8 +45,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -53,8 +55,9 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -62,8 +65,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -71,8 +75,9 @@ System.register([], function(exports_1) { } }); //// [file5.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { @@ -80,8 +85,9 @@ System.register([], function(exports_1) { } }); //// [file6.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; return { setters:[], execute: function() { diff --git a/tests/baselines/reference/systemModuleConstEnums.js b/tests/baselines/reference/systemModuleConstEnums.js index 8b8707768d9..08df549a87b 100644 --- a/tests/baselines/reference/systemModuleConstEnums.js +++ b/tests/baselines/reference/systemModuleConstEnums.js @@ -13,8 +13,9 @@ module M { } //// [systemModuleConstEnums.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { use(0 /* X */); use(0 /* X */); diff --git a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js index 8466d399ac9..be2f07cc59e 100644 --- a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js +++ b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js @@ -13,8 +13,9 @@ module M { } //// [systemModuleConstEnumsSeparateCompilation.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var TopLevelConstEnum, M; function foo() { use(TopLevelConstEnum.X); diff --git a/tests/baselines/reference/systemModuleDeclarationMerging.js b/tests/baselines/reference/systemModuleDeclarationMerging.js index 5ed029a769a..1196aa8898d 100644 --- a/tests/baselines/reference/systemModuleDeclarationMerging.js +++ b/tests/baselines/reference/systemModuleDeclarationMerging.js @@ -10,8 +10,9 @@ export enum E {} export module E { var x; } //// [systemModuleDeclarationMerging.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var F, C, E; function F() { } exports_1("F", F); diff --git a/tests/baselines/reference/systemModuleExportDefault.js b/tests/baselines/reference/systemModuleExportDefault.js index cf1a99a4ad7..eaa4e6ddaa7 100644 --- a/tests/baselines/reference/systemModuleExportDefault.js +++ b/tests/baselines/reference/systemModuleExportDefault.js @@ -16,8 +16,9 @@ export default class C {} //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function default_1() { } exports_1("default", default_1); return { @@ -27,8 +28,9 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; function foo() { } exports_1("default", foo); return { @@ -38,8 +40,9 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var default_1; return { setters:[], @@ -54,8 +57,9 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var C; return { setters:[], diff --git a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js index ee9858a7fec..1cf993baec0 100644 --- a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js +++ b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js @@ -13,8 +13,9 @@ export module TopLevelModule2 { } //// [systemModuleNonTopLevelModuleMembers.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var TopLevelClass, TopLevelModule, TopLevelEnum, TopLevelModule2; function TopLevelFunction() { } exports_1("TopLevelFunction", TopLevelFunction); diff --git a/tests/baselines/reference/systemModuleWithSuperClass.js b/tests/baselines/reference/systemModuleWithSuperClass.js index fe9c2742f2d..0aab851cc57 100644 --- a/tests/baselines/reference/systemModuleWithSuperClass.js +++ b/tests/baselines/reference/systemModuleWithSuperClass.js @@ -13,8 +13,9 @@ export class Bar extends Foo { } //// [foo.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; var Foo; return { setters:[], @@ -29,8 +30,9 @@ System.register([], function(exports_1) { } }); //// [bar.js] -System.register(['./foo'], function(exports_1) { +System.register(['./foo'], function(exports_1, context_1) { "use strict"; + var __moduleName = context_1 && context_1.id; 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; } diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index 513d37673bb..d9fdaeb32ec 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -134,7 +134,10 @@ var x = 0;`, it("Sets module name", () => { let output = - `System.register("NamedModule", [], function(exports_1) {\n "use strict";\n var x;\n` + + `System.register("NamedModule", [], function(exports_1, context_1) {\n` + + ` "use strict";\n` + + ` var __moduleName = context_1 && context_1.id;\n` + + ` var x;\n` + ` return {\n` + ` setters:[],\n` + ` execute: function() {\n` + @@ -159,8 +162,9 @@ var x = 0;`, `declare function use(a: any);\n` + `use(foo);` let output = - `System.register(["SomeOtherName"], function(exports_1) {\n` + + `System.register(["SomeOtherName"], function(exports_1, context_1) {\n` + ` "use strict";\n` + + ` var __moduleName = context_1 && context_1.id;\n` + ` var SomeName_1;\n` + ` return {\n` + ` setters:[\n` + From 56355d1d17545084f1c77c32997481d073e81d45 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 29 Jan 2016 13:28:27 -0800 Subject: [PATCH 36/36] fix access check issues when declaration is in multiple files --- src/compiler/checker.ts | 2 +- .../reference/declarationMerging1.js | 21 ++++++++++++ .../reference/declarationMerging1.symbols | 21 ++++++++++++ .../reference/declarationMerging1.types | 21 ++++++++++++ .../reference/declarationMerging2.js | 32 +++++++++++++++++++ .../reference/declarationMerging2.symbols | 25 +++++++++++++++ .../reference/declarationMerging2.types | 25 +++++++++++++++ tests/cases/compiler/declarationMerging1.ts | 10 ++++++ tests/cases/compiler/declarationMerging2.ts | 15 +++++++++ 9 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/declarationMerging1.js create mode 100644 tests/baselines/reference/declarationMerging1.symbols create mode 100644 tests/baselines/reference/declarationMerging1.types create mode 100644 tests/baselines/reference/declarationMerging2.js create mode 100644 tests/baselines/reference/declarationMerging2.symbols create mode 100644 tests/baselines/reference/declarationMerging2.types create mode 100644 tests/cases/compiler/declarationMerging1.ts create mode 100644 tests/cases/compiler/declarationMerging2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a0040982356..9f4845fae02 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8776,7 +8776,7 @@ namespace ts { */ function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean { const flags = getDeclarationFlagsFromSymbol(prop); - const declaringClass = getDeclaredTypeOfSymbol(prop.parent); + const declaringClass = getDeclaredTypeOfSymbol(getMergedSymbol(prop.parent)); if (left.kind === SyntaxKind.SuperKeyword) { const errorNode = node.kind === SyntaxKind.PropertyAccessExpression ? diff --git a/tests/baselines/reference/declarationMerging1.js b/tests/baselines/reference/declarationMerging1.js new file mode 100644 index 00000000000..6b863def1c7 --- /dev/null +++ b/tests/baselines/reference/declarationMerging1.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/declarationMerging1.ts] //// + +//// [file1.ts] +class A { + protected _f: number; + getF() { return this._f; } +} + +//// [file2.ts] +interface A { + run(); +} + +//// [file1.js] +var A = (function () { + function A() { + } + A.prototype.getF = function () { return this._f; }; + return A; +}()); +//// [file2.js] diff --git a/tests/baselines/reference/declarationMerging1.symbols b/tests/baselines/reference/declarationMerging1.symbols new file mode 100644 index 00000000000..08fe0d4c1fd --- /dev/null +++ b/tests/baselines/reference/declarationMerging1.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/file1.ts === +class A { +>A : Symbol(A, Decl(file1.ts, 0, 0), Decl(file2.ts, 0, 0)) + + protected _f: number; +>_f : Symbol(_f, Decl(file1.ts, 0, 9)) + + getF() { return this._f; } +>getF : Symbol(getF, Decl(file1.ts, 1, 25)) +>this._f : Symbol(_f, Decl(file1.ts, 0, 9)) +>this : Symbol(A, Decl(file1.ts, 0, 0), Decl(file2.ts, 0, 0)) +>_f : Symbol(_f, Decl(file1.ts, 0, 9)) +} + +=== tests/cases/compiler/file2.ts === +interface A { +>A : Symbol(A, Decl(file1.ts, 0, 0), Decl(file2.ts, 0, 0)) + + run(); +>run : Symbol(run, Decl(file2.ts, 0, 13)) +} diff --git a/tests/baselines/reference/declarationMerging1.types b/tests/baselines/reference/declarationMerging1.types new file mode 100644 index 00000000000..9802d2ab542 --- /dev/null +++ b/tests/baselines/reference/declarationMerging1.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/file1.ts === +class A { +>A : A + + protected _f: number; +>_f : number + + getF() { return this._f; } +>getF : () => number +>this._f : number +>this : this +>_f : number +} + +=== tests/cases/compiler/file2.ts === +interface A { +>A : A + + run(); +>run : () => any +} diff --git a/tests/baselines/reference/declarationMerging2.js b/tests/baselines/reference/declarationMerging2.js new file mode 100644 index 00000000000..3157445fa36 --- /dev/null +++ b/tests/baselines/reference/declarationMerging2.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/declarationMerging2.ts] //// + +//// [a.ts] + +export class A { + protected _f: number; + getF() { return this._f; } +} + +//// [b.ts] +export {} +declare module "./a" { + interface A { + run(); + } +} + +//// [a.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + A.prototype.getF = function () { return this._f; }; + return A; + }()); + exports.A = A; +}); +//// [b.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); diff --git a/tests/baselines/reference/declarationMerging2.symbols b/tests/baselines/reference/declarationMerging2.symbols new file mode 100644 index 00000000000..b3891374d32 --- /dev/null +++ b/tests/baselines/reference/declarationMerging2.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/a.ts === + +export class A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22)) + + protected _f: number; +>_f : Symbol(_f, Decl(a.ts, 1, 16)) + + getF() { return this._f; } +>getF : Symbol(getF, Decl(a.ts, 2, 25)) +>this._f : Symbol(_f, Decl(a.ts, 1, 16)) +>this : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22)) +>_f : Symbol(_f, Decl(a.ts, 1, 16)) +} + +=== tests/cases/compiler/b.ts === +export {} +declare module "./a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(b.ts, 1, 22)) + + run(); +>run : Symbol(run, Decl(b.ts, 2, 17)) + } +} diff --git a/tests/baselines/reference/declarationMerging2.types b/tests/baselines/reference/declarationMerging2.types new file mode 100644 index 00000000000..79e2818cf52 --- /dev/null +++ b/tests/baselines/reference/declarationMerging2.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/a.ts === + +export class A { +>A : A + + protected _f: number; +>_f : number + + getF() { return this._f; } +>getF : () => number +>this._f : number +>this : this +>_f : number +} + +=== tests/cases/compiler/b.ts === +export {} +declare module "./a" { + interface A { +>A : A + + run(); +>run : () => any + } +} diff --git a/tests/cases/compiler/declarationMerging1.ts b/tests/cases/compiler/declarationMerging1.ts new file mode 100644 index 00000000000..256cacf4a52 --- /dev/null +++ b/tests/cases/compiler/declarationMerging1.ts @@ -0,0 +1,10 @@ +// @filename: file1.ts +class A { + protected _f: number; + getF() { return this._f; } +} + +// @filename: file2.ts +interface A { + run(); +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationMerging2.ts b/tests/cases/compiler/declarationMerging2.ts new file mode 100644 index 00000000000..6be5f4d0e4d --- /dev/null +++ b/tests/cases/compiler/declarationMerging2.ts @@ -0,0 +1,15 @@ +// @module: amd + +// @filename: a.ts +export class A { + protected _f: number; + getF() { return this._f; } +} + +// @filename: b.ts +export {} +declare module "./a" { + interface A { + run(); + } +} \ No newline at end of file