diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile.js b/tests/baselines/reference/emitClassExpressionInDeclarationFile.js index 423546bcd4e..ab64fe003be 100644 --- a/tests/baselines/reference/emitClassExpressionInDeclarationFile.js +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile.js @@ -95,18 +95,12 @@ export declare var simpleExample: { new (): { tags(): void; }; - prototype: { - tags(): void; - }; getTags(): void; }; export declare var circularReference: { new (): { tags(c: any): any; }; - prototype: { - tags(c: any): any; - }; getTags(c: { tags(c: any): any; }): { @@ -124,11 +118,6 @@ export declare function WithTags>(Base: T): { foo(): void; name?: string; }; - prototype: { - tags(): void; - foo(): void; - name?: string; - }; getTags(): void; } & T; declare const Test_base: { @@ -137,11 +126,6 @@ declare const Test_base: { foo(): void; name?: string; }; - prototype: { - tags(): void; - foo(): void; - name?: string; - }; getTags(): void; } & typeof FooItem; export declare class Test extends Test_base { diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.errors.txt b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.errors.txt new file mode 100644 index 00000000000..4541cf2a58a --- /dev/null +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.errors.txt @@ -0,0 +1,41 @@ +tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts(1,12): error TS4094: Property 'p' of exported class expression may not be private or protected. +tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts(1,12): error TS4094: Property 'ps' of exported class expression may not be private or protected. +tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts(16,17): error TS4094: Property 'property' of exported class expression may not be private or protected. + + +==== tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts (3 errors) ==== + export var noPrivates = class { + ~~~~~~~~~~ +!!! error TS4094: Property 'p' of exported class expression may not be private or protected. + ~~~~~~~~~~ +!!! error TS4094: Property 'ps' of exported class expression may not be private or protected. + static getTags() { } + tags() { } + private static ps = -1 + private p = 12 + } + + // altered repro from #15066 to add private property + export class FooItem { + foo(): void { } + name?: string; + private property = "capitalism" + } + + export type Constructor = new(...args: any[]) => T; + export function WithTags>(Base: T) { + ~~~~~~~~ +!!! error TS4094: Property 'property' of exported class expression may not be private or protected. + return class extends Base { + static getTags(): void { } + tags(): void { } + } + } + + export class Test extends WithTags(FooItem) {} + + const test = new Test(); + + Test.getTags() + test.tags(); + \ No newline at end of file diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.js b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.js new file mode 100644 index 00000000000..e3a0aa4cb99 --- /dev/null +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.js @@ -0,0 +1,87 @@ +//// [emitClassExpressionInDeclarationFile2.ts] +export var noPrivates = class { + static getTags() { } + tags() { } + private static ps = -1 + private p = 12 +} + +// altered repro from #15066 to add private property +export class FooItem { + foo(): void { } + name?: string; + private property = "capitalism" +} + +export type Constructor = new(...args: any[]) => T; +export function WithTags>(Base: T) { + return class extends Base { + static getTags(): void { } + tags(): void { } + } +} + +export class Test extends WithTags(FooItem) {} + +const test = new Test(); + +Test.getTags() +test.tags(); + + +//// [emitClassExpressionInDeclarationFile2.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +exports.noPrivates = (_a = (function () { + function class_1() { + this.p = 12; + } + class_1.getTags = function () { }; + class_1.prototype.tags = function () { }; + return class_1; + }()), + _a.ps = -1, + _a); +// altered repro from #15066 to add private property +var FooItem = (function () { + function FooItem() { + this.property = "capitalism"; + } + FooItem.prototype.foo = function () { }; + return FooItem; +}()); +exports.FooItem = FooItem; +function WithTags(Base) { + return (function (_super) { + __extends(class_2, _super); + function class_2() { + return _super !== null && _super.apply(this, arguments) || this; + } + class_2.getTags = function () { }; + class_2.prototype.tags = function () { }; + return class_2; + }(Base)); +} +exports.WithTags = WithTags; +var Test = (function (_super) { + __extends(Test, _super); + function Test() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Test; +}(WithTags(FooItem))); +exports.Test = Test; +var test = new Test(); +Test.getTags(); +test.tags(); +var _a; diff --git a/tests/cases/compiler/emitClassExpressionInDeclarationFile.ts b/tests/cases/compiler/emitClassExpressionInDeclarationFile.ts index 4268f237044..f99bcbd7efd 100644 --- a/tests/cases/compiler/emitClassExpressionInDeclarationFile.ts +++ b/tests/cases/compiler/emitClassExpressionInDeclarationFile.ts @@ -2,19 +2,12 @@ export var simpleExample = class { static getTags() { } tags() { } - private static ps = -1 - private p = 12 } export var circularReference = class C { static getTags(c: C): C { return c } tags(c: C): C { return c } } -class Base { } -export function foo() { - return class extends Base { } -} - // repro from #15066 export class FooItem { foo(): void { } diff --git a/tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts b/tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts new file mode 100644 index 00000000000..3175f2afce7 --- /dev/null +++ b/tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts @@ -0,0 +1,29 @@ +// @declaration: true +export var noPrivates = class { + static getTags() { } + tags() { } + private static ps = -1 + private p = 12 +} + +// altered repro from #15066 to add private property +export class FooItem { + foo(): void { } + name?: string; + private property = "capitalism" +} + +export type Constructor = new(...args: any[]) => T; +export function WithTags>(Base: T) { + return class extends Base { + static getTags(): void { } + tags(): void { } + } +} + +export class Test extends WithTags(FooItem) {} + +const test = new Test(); + +Test.getTags() +test.tags();