From ba8b1680cbf5fa5763fe1d6000a36ac05d8bdb43 Mon Sep 17 00:00:00 2001 From: AbubakerB Date: Sun, 14 Feb 2016 21:16:12 +0000 Subject: [PATCH] Included previously ignored baseline .js file and slight refactoring --- src/compiler/checker.ts | 7 +- .../classConstructorAccessibility4.js | 93 +++++++++++++++++++ 2 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/classConstructorAccessibility4.js diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 533fffda805..f775f562695 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15412,14 +15412,13 @@ namespace ts { function isNodeWithinClass(node: Node, classDeclaration: ClassLikeDeclaration) { while (true) { - const containingClass = getContainingClass(node); - if (!containingClass) { + node = getContainingClass(node); + if (!node) { return false; } - if (containingClass === classDeclaration) { + if (node === classDeclaration) { return true; } - node = containingClass; } } diff --git a/tests/baselines/reference/classConstructorAccessibility4.js b/tests/baselines/reference/classConstructorAccessibility4.js new file mode 100644 index 00000000000..6342facae21 --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility4.js @@ -0,0 +1,93 @@ +//// [classConstructorAccessibility4.ts] + +class A { + private constructor() { } + + method() { + class B { + method() { + new A(); // OK + } + } + + class C extends A { // OK + } + } +} + +class D { + protected constructor() { } + + method() { + class E { + method() { + new D(); // OK + } + } + + class F extends D { // OK + } + } +} + +//// [classConstructorAccessibility4.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 A = (function () { + function A() { + } + A.prototype.method = function () { + var B = (function () { + function B() { + } + B.prototype.method = function () { + new A(); // OK + }; + return B; + }()); + var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; + }(A)); + }; + return A; +}()); +var D = (function () { + function D() { + } + D.prototype.method = function () { + var E = (function () { + function E() { + } + E.prototype.method = function () { + new D(); // OK + }; + return E; + }()); + var F = (function (_super) { + __extends(F, _super); + function F() { + _super.apply(this, arguments); + } + return F; + }(D)); + }; + return D; +}()); + + +//// [classConstructorAccessibility4.d.ts] +declare class A { + private constructor(); + method(): void; +} +declare class D { + protected constructor(); + method(): void; +}