diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 80b61edd3657a..67c7fb2634353 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7316,8 +7316,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (propertySymbol.flags & SymbolFlags.Prototype) { continue; } - if (getDeclarationModifierFlagsFromSymbol(propertySymbol) & (ModifierFlags.Private | ModifierFlags.Protected) && context.tracker.reportPrivateInBaseOfClassExpression) { - context.tracker.reportPrivateInBaseOfClassExpression(unescapeLeadingUnderscores(propertySymbol.escapedName)); + if ((getDeclarationModifierFlagsFromSymbol(propertySymbol) & (ModifierFlags.Private | ModifierFlags.Protected) || propertySymbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(propertySymbol.valueDeclaration)) && context.tracker.reportPrivateInBaseOfClassExpression) { + context.tracker.reportPrivateInBaseOfClassExpression(symbolToString(propertySymbol)); } } if (checkTruncationLength(context) && (i + 2 < properties.length - 1)) { diff --git a/tests/baselines/reference/declarationEmitMixinPrivateField1.errors.txt b/tests/baselines/reference/declarationEmitMixinPrivateField1.errors.txt new file mode 100644 index 0000000000000..c7ddfa5e088c7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitMixinPrivateField1.errors.txt @@ -0,0 +1,30 @@ +another.ts(7,1): error TS4094: Property '#onDispose' of exported anonymous class type may not be private or protected. +first.ts(7,1): error TS4094: Property '#onDispose' of exported anonymous class type may not be private or protected. +first.ts(8,14): error TS4094: Property '#onDispose' of exported anonymous class type may not be private or protected. + + +==== first.ts (2 errors) ==== + declare function mix(mixin: TMix): TMix; + + const DisposableMixin = class { + #onDispose() {} + }; + + export default mix(DisposableMixin); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4094: Property '#onDispose' of exported anonymous class type may not be private or protected. + export class Monitor extends mix(DisposableMixin) {} + ~~~~~~~ +!!! error TS4094: Property '#onDispose' of exported anonymous class type may not be private or protected. + +==== another.ts (1 errors) ==== + declare function mix(mixin: TMix): TMix; + + const DisposableMixin = class { + #onDispose() {} + }; + + export default class extends mix(DisposableMixin) {} + ~~~~~~ +!!! error TS4094: Property '#onDispose' of exported anonymous class type may not be private or protected. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitMixinPrivateField1.js b/tests/baselines/reference/declarationEmitMixinPrivateField1.js new file mode 100644 index 0000000000000..86eba3f5e5bf1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitMixinPrivateField1.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/declarationEmitMixinPrivateField1.ts] //// + +//// [first.ts] +declare function mix(mixin: TMix): TMix; + +const DisposableMixin = class { + #onDispose() {} +}; + +export default mix(DisposableMixin); +export class Monitor extends mix(DisposableMixin) {} + +//// [another.ts] +declare function mix(mixin: TMix): TMix; + +const DisposableMixin = class { + #onDispose() {} +}; + +export default class extends mix(DisposableMixin) {} + + +//// [first.js] +const DisposableMixin = class { + #onDispose() { } +}; +export default mix(DisposableMixin); +export class Monitor extends mix(DisposableMixin) { +} +//// [another.js] +const DisposableMixin = class { + #onDispose() { } +}; +export default class extends mix(DisposableMixin) { +} diff --git a/tests/baselines/reference/declarationEmitMixinPrivateField1.symbols b/tests/baselines/reference/declarationEmitMixinPrivateField1.symbols new file mode 100644 index 0000000000000..c8f54a8419421 --- /dev/null +++ b/tests/baselines/reference/declarationEmitMixinPrivateField1.symbols @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/declarationEmitMixinPrivateField1.ts] //// + +=== first.ts === +declare function mix(mixin: TMix): TMix; +>mix : Symbol(mix, Decl(first.ts, 0, 0)) +>TMix : Symbol(TMix, Decl(first.ts, 0, 21)) +>mixin : Symbol(mixin, Decl(first.ts, 0, 27)) +>TMix : Symbol(TMix, Decl(first.ts, 0, 21)) +>TMix : Symbol(TMix, Decl(first.ts, 0, 21)) + +const DisposableMixin = class { +>DisposableMixin : Symbol(DisposableMixin, Decl(first.ts, 2, 5)) + + #onDispose() {} +>#onDispose : Symbol(DisposableMixin.#onDispose, Decl(first.ts, 2, 31)) + +}; + +export default mix(DisposableMixin); +>mix : Symbol(mix, Decl(first.ts, 0, 0)) +>DisposableMixin : Symbol(DisposableMixin, Decl(first.ts, 2, 5)) + +export class Monitor extends mix(DisposableMixin) {} +>Monitor : Symbol(Monitor, Decl(first.ts, 6, 36)) +>mix : Symbol(mix, Decl(first.ts, 0, 0)) +>DisposableMixin : Symbol(DisposableMixin, Decl(first.ts, 2, 5)) + +=== another.ts === +declare function mix(mixin: TMix): TMix; +>mix : Symbol(mix, Decl(another.ts, 0, 0)) +>TMix : Symbol(TMix, Decl(another.ts, 0, 21)) +>mixin : Symbol(mixin, Decl(another.ts, 0, 27)) +>TMix : Symbol(TMix, Decl(another.ts, 0, 21)) +>TMix : Symbol(TMix, Decl(another.ts, 0, 21)) + +const DisposableMixin = class { +>DisposableMixin : Symbol(DisposableMixin, Decl(another.ts, 2, 5)) + + #onDispose() {} +>#onDispose : Symbol(DisposableMixin.#onDispose, Decl(another.ts, 2, 31)) + +}; + +export default class extends mix(DisposableMixin) {} +>mix : Symbol(mix, Decl(another.ts, 0, 0)) +>DisposableMixin : Symbol(DisposableMixin, Decl(another.ts, 2, 5)) + diff --git a/tests/baselines/reference/declarationEmitMixinPrivateField1.types b/tests/baselines/reference/declarationEmitMixinPrivateField1.types new file mode 100644 index 0000000000000..7e505b724a975 --- /dev/null +++ b/tests/baselines/reference/declarationEmitMixinPrivateField1.types @@ -0,0 +1,66 @@ +//// [tests/cases/compiler/declarationEmitMixinPrivateField1.ts] //// + +=== first.ts === +declare function mix(mixin: TMix): TMix; +>mix : (mixin: TMix) => TMix +> : ^ ^^ ^^ ^^^^^ +>mixin : TMix +> : ^^^^ + +const DisposableMixin = class { +>DisposableMixin : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ +>class { #onDispose() {}} : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ + + #onDispose() {} +>#onDispose : () => void +> : ^^^^^^^^^^ + +}; + +export default mix(DisposableMixin); +>mix(DisposableMixin) : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ +>mix : (mixin: TMix) => TMix +> : ^ ^^ ^^ ^^^^^ +>DisposableMixin : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ + +export class Monitor extends mix(DisposableMixin) {} +>Monitor : Monitor +> : ^^^^^^^ +>mix(DisposableMixin) : DisposableMixin +> : ^^^^^^^^^^^^^^^ +>mix : (mixin: TMix) => TMix +> : ^ ^^ ^^ ^^^^^ +>DisposableMixin : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ + +=== another.ts === +declare function mix(mixin: TMix): TMix; +>mix : (mixin: TMix) => TMix +> : ^ ^^ ^^ ^^^^^ +>mixin : TMix +> : ^^^^ + +const DisposableMixin = class { +>DisposableMixin : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ +>class { #onDispose() {}} : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ + + #onDispose() {} +>#onDispose : () => void +> : ^^^^^^^^^^ + +}; + +export default class extends mix(DisposableMixin) {} +>mix(DisposableMixin) : DisposableMixin +> : ^^^^^^^^^^^^^^^ +>mix : (mixin: TMix) => TMix +> : ^ ^^ ^^ ^^^^^ +>DisposableMixin : typeof DisposableMixin +> : ^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.errors.txt b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.errors.txt index e755cfdfa259b..bd1a2fbb10cc0 100644 --- a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.errors.txt +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.errors.txt @@ -2,9 +2,10 @@ emitClassExpressionInDeclarationFile2.ts(1,12): error TS4094: Property 'p' of ex emitClassExpressionInDeclarationFile2.ts(1,12): error TS4094: Property 'ps' of exported anonymous class type may not be private or protected. emitClassExpressionInDeclarationFile2.ts(16,17): error TS4094: Property 'property' of exported anonymous class type may not be private or protected. emitClassExpressionInDeclarationFile2.ts(23,14): error TS4094: Property 'property' of exported anonymous class type may not be private or protected. +emitClassExpressionInDeclarationFile2.ts(31,3): error TS4094: Property 'prop' of exported anonymous class type may not be private or protected. -==== emitClassExpressionInDeclarationFile2.ts (4 errors) ==== +==== emitClassExpressionInDeclarationFile2.ts (5 errors) ==== export var noPrivates = class { ~~~~~~~~~~ !!! error TS4094: Property 'p' of exported anonymous class type may not be private or protected. @@ -43,4 +44,12 @@ emitClassExpressionInDeclarationFile2.ts(23,14): error TS4094: Property 'propert Test.getTags() test.tags(); + + export class Test2 { + nested = class { + ~~~~~~ +!!! error TS4094: Property 'prop' of exported anonymous class type may not be private or protected. + private prop = 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.js b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.js index 7448d7496af59..7232fe1224364 100644 --- a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.js +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.js @@ -29,6 +29,12 @@ const test = new Test(); Test.getTags() test.tags(); + +export class Test2 { + nested = class { + private prop = 42; + } +} //// [emitClassExpressionInDeclarationFile2.js] @@ -54,7 +60,7 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p }; var _a; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Test = exports.FooItem = exports.noPrivates = void 0; +exports.Test2 = exports.Test = exports.FooItem = exports.noPrivates = void 0; exports.WithTags = WithTags; exports.noPrivates = (_a = /** @class */ (function () { function class_1() { @@ -98,3 +104,15 @@ exports.Test = Test; var test = new Test(); Test.getTags(); test.tags(); +var Test2 = /** @class */ (function () { + function Test2() { + this.nested = /** @class */ (function () { + function class_3() { + this.prop = 42; + } + return class_3; + }()); + } + return Test2; +}()); +exports.Test2 = Test2; diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.symbols b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.symbols index 167ec73bdbabc..086e3075444cd 100644 --- a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.symbols +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.symbols @@ -75,3 +75,14 @@ test.tags(); >test : Symbol(test, Decl(emitClassExpressionInDeclarationFile2.ts, 24, 5)) >tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile2.ts, 17, 34)) +export class Test2 { +>Test2 : Symbol(Test2, Decl(emitClassExpressionInDeclarationFile2.ts, 27, 12)) + + nested = class { +>nested : Symbol(Test2.nested, Decl(emitClassExpressionInDeclarationFile2.ts, 29, 20)) + + private prop = 42; +>prop : Symbol((Anonymous class).prop, Decl(emitClassExpressionInDeclarationFile2.ts, 30, 18)) + } +} + diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.types b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.types index b0365b56e6053..f4cc7ec5c4ad4 100644 --- a/tests/baselines/reference/emitClassExpressionInDeclarationFile2.types +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile2.types @@ -116,3 +116,21 @@ test.tags(); >tags : () => void > : ^^^^^^ +export class Test2 { +>Test2 : Test2 +> : ^^^^^ + + nested = class { +>nested : typeof (Anonymous class) +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>class { private prop = 42; } : typeof (Anonymous class) +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + + private prop = 42; +>prop : number +> : ^^^^^^ +>42 : 42 +> : ^^ + } +} + diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile3.errors.txt b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.errors.txt new file mode 100644 index 0000000000000..ec0e87b9aa6e2 --- /dev/null +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.errors.txt @@ -0,0 +1,49 @@ +emitClassExpressionInDeclarationFile3.ts(1,12): error TS4094: Property '#p' of exported anonymous class type may not be private or protected. +emitClassExpressionInDeclarationFile3.ts(1,12): error TS4094: Property '#ps' of exported anonymous class type may not be private or protected. +emitClassExpressionInDeclarationFile3.ts(15,17): error TS4094: Property '#property' of exported anonymous class type may not be private or protected. +emitClassExpressionInDeclarationFile3.ts(22,14): error TS4094: Property '#property' of exported anonymous class type may not be private or protected. +emitClassExpressionInDeclarationFile3.ts(25,3): error TS4094: Property '#prop' of exported anonymous class type may not be private or protected. + + +==== emitClassExpressionInDeclarationFile3.ts (5 errors) ==== + export var noPrivates = class { + ~~~~~~~~~~ +!!! error TS4094: Property '#p' of exported anonymous class type may not be private or protected. +!!! related TS9027 emitClassExpressionInDeclarationFile3.ts:1:12: Add a type annotation to the variable noPrivates. + ~~~~~~~~~~ +!!! error TS4094: Property '#ps' of exported anonymous class type may not be private or protected. +!!! related TS9027 emitClassExpressionInDeclarationFile3.ts:1:12: Add a type annotation to the variable noPrivates. + static getTags() { } + tags() { } + static #ps = -1 + #p = 12 + } + + export class FooItem { + foo(): void { } + name?: string; + #property = "capitalism" + } + + export type Constructor = new(...args: any[]) => T; + export function WithTags>(Base: T) { + ~~~~~~~~ +!!! error TS4094: Property '#property' of exported anonymous class type may not be private or protected. + return class extends Base { + static getTags(): void { } + tags(): void { } + } + } + + export class Test extends WithTags(FooItem) {} + ~~~~ +!!! error TS4094: Property '#property' of exported anonymous class type may not be private or protected. + + export class Test2 { + nested = class { + ~~~~~~ +!!! error TS4094: Property '#prop' of exported anonymous class type may not be private or protected. + #prop = 42; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile3.js b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.js new file mode 100644 index 0000000000000..75fd92209ca14 --- /dev/null +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.js @@ -0,0 +1,58 @@ +//// [tests/cases/compiler/emitClassExpressionInDeclarationFile3.ts] //// + +//// [emitClassExpressionInDeclarationFile3.ts] +export var noPrivates = class { + static getTags() { } + tags() { } + static #ps = -1 + #p = 12 +} + +export class FooItem { + foo(): void { } + name?: string; + #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) {} + +export class Test2 { + nested = class { + #prop = 42; + } +} + + +//// [emitClassExpressionInDeclarationFile3.js] +export var noPrivates = class { + static getTags() { } + tags() { } + static #ps = -1; + #p = 12; +}; +export class FooItem { + foo() { } + name; + #property = "capitalism"; +} +export function WithTags(Base) { + return class extends Base { + static getTags() { } + tags() { } + }; +} +export class Test extends WithTags(FooItem) { +} +export class Test2 { + nested = class { + #prop = 42; + }; +} diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile3.symbols b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.symbols new file mode 100644 index 0000000000000..dbb2854de4360 --- /dev/null +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.symbols @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/emitClassExpressionInDeclarationFile3.ts] //// + +=== emitClassExpressionInDeclarationFile3.ts === +export var noPrivates = class { +>noPrivates : Symbol(noPrivates, Decl(emitClassExpressionInDeclarationFile3.ts, 0, 10)) + + static getTags() { } +>getTags : Symbol(noPrivates.getTags, Decl(emitClassExpressionInDeclarationFile3.ts, 0, 31)) + + tags() { } +>tags : Symbol(noPrivates.tags, Decl(emitClassExpressionInDeclarationFile3.ts, 1, 24)) + + static #ps = -1 +>#ps : Symbol(noPrivates.#ps, Decl(emitClassExpressionInDeclarationFile3.ts, 2, 14)) + + #p = 12 +>#p : Symbol(noPrivates.#p, Decl(emitClassExpressionInDeclarationFile3.ts, 3, 19)) +} + +export class FooItem { +>FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile3.ts, 5, 1)) + + foo(): void { } +>foo : Symbol(FooItem.foo, Decl(emitClassExpressionInDeclarationFile3.ts, 7, 22)) + + name?: string; +>name : Symbol(FooItem.name, Decl(emitClassExpressionInDeclarationFile3.ts, 8, 19)) + + #property = "capitalism" +>#property : Symbol(FooItem.#property, Decl(emitClassExpressionInDeclarationFile3.ts, 9, 18)) +} + +export type Constructor = new(...args: any[]) => T; +>Constructor : Symbol(Constructor, Decl(emitClassExpressionInDeclarationFile3.ts, 11, 1)) +>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile3.ts, 13, 24)) +>args : Symbol(args, Decl(emitClassExpressionInDeclarationFile3.ts, 13, 33)) +>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile3.ts, 13, 24)) + +export function WithTags>(Base: T) { +>WithTags : Symbol(WithTags, Decl(emitClassExpressionInDeclarationFile3.ts, 13, 54)) +>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile3.ts, 14, 25)) +>Constructor : Symbol(Constructor, Decl(emitClassExpressionInDeclarationFile3.ts, 11, 1)) +>FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile3.ts, 5, 1)) +>Base : Symbol(Base, Decl(emitClassExpressionInDeclarationFile3.ts, 14, 57)) +>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile3.ts, 14, 25)) + + return class extends Base { +>Base : Symbol(Base, Decl(emitClassExpressionInDeclarationFile3.ts, 14, 57)) + + static getTags(): void { } +>getTags : Symbol((Anonymous class).getTags, Decl(emitClassExpressionInDeclarationFile3.ts, 15, 31)) + + tags(): void { } +>tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile3.ts, 16, 34)) + } +} + +export class Test extends WithTags(FooItem) {} +>Test : Symbol(Test, Decl(emitClassExpressionInDeclarationFile3.ts, 19, 1)) +>WithTags : Symbol(WithTags, Decl(emitClassExpressionInDeclarationFile3.ts, 13, 54)) +>FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile3.ts, 5, 1)) + +export class Test2 { +>Test2 : Symbol(Test2, Decl(emitClassExpressionInDeclarationFile3.ts, 21, 46)) + + nested = class { +>nested : Symbol(Test2.nested, Decl(emitClassExpressionInDeclarationFile3.ts, 23, 20)) + + #prop = 42; +>#prop : Symbol((Anonymous class).#prop, Decl(emitClassExpressionInDeclarationFile3.ts, 24, 18)) + } +} + diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile3.types b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.types new file mode 100644 index 0000000000000..d72a88b2f0a2a --- /dev/null +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile3.types @@ -0,0 +1,107 @@ +//// [tests/cases/compiler/emitClassExpressionInDeclarationFile3.ts] //// + +=== emitClassExpressionInDeclarationFile3.ts === +export var noPrivates = class { +>noPrivates : typeof noPrivates +> : ^^^^^^^^^^^^^^^^^ +>class { static getTags() { } tags() { } static #ps = -1 #p = 12} : typeof noPrivates +> : ^^^^^^^^^^^^^^^^^ + + static getTags() { } +>getTags : () => void +> : ^^^^^^^^^^ + + tags() { } +>tags : () => void +> : ^^^^^^^^^^ + + static #ps = -1 +>#ps : number +> : ^^^^^^ +>-1 : -1 +> : ^^ +>1 : 1 +> : ^ + + #p = 12 +>#p : number +> : ^^^^^^ +>12 : 12 +> : ^^ +} + +export class FooItem { +>FooItem : FooItem +> : ^^^^^^^ + + foo(): void { } +>foo : () => void +> : ^^^^^^ + + name?: string; +>name : string +> : ^^^^^^ + + #property = "capitalism" +>#property : string +> : ^^^^^^ +>"capitalism" : "capitalism" +> : ^^^^^^^^^^^^ +} + +export type Constructor = new(...args: any[]) => T; +>Constructor : Constructor +> : ^^^^^^^^^^^^^^ +>args : any[] +> : ^^^^^ + +export function WithTags>(Base: T) { +>WithTags : >(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithTags.(Anonymous class); getTags(): void; } & T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^ +>Base : T +> : ^ + + return class extends Base { +>class extends Base { static getTags(): void { } tags(): void { } } : { new (...args: any[]): (Anonymous class); prototype: WithTags.(Anonymous class); getTags(): void; } & T +> : ^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^ +>Base : FooItem +> : ^^^^^^^ + + static getTags(): void { } +>getTags : () => void +> : ^^^^^^ + + tags(): void { } +>tags : () => void +> : ^^^^^^ + } +} + +export class Test extends WithTags(FooItem) {} +>Test : Test +> : ^^^^ +>WithTags(FooItem) : WithTags.(Anonymous class) & FooItem +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>WithTags : >(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithTags.(Anonymous class); getTags(): void; } & T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^ +>FooItem : typeof FooItem +> : ^^^^^^^^^^^^^^ + +export class Test2 { +>Test2 : Test2 +> : ^^^^^ + + nested = class { +>nested : typeof (Anonymous class) +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>class { #prop = 42; } : typeof (Anonymous class) +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + + #prop = 42; +>#prop : number +> : ^^^^^^ +>42 : 42 +> : ^^ + } +} + diff --git a/tests/cases/compiler/declarationEmitMixinPrivateField1.ts b/tests/cases/compiler/declarationEmitMixinPrivateField1.ts new file mode 100644 index 0000000000000..93a062f8ce8a7 --- /dev/null +++ b/tests/cases/compiler/declarationEmitMixinPrivateField1.ts @@ -0,0 +1,20 @@ +// @target: esnext +// @declaration: true +// @filename: first.ts +declare function mix(mixin: TMix): TMix; + +const DisposableMixin = class { + #onDispose() {} +}; + +export default mix(DisposableMixin); +export class Monitor extends mix(DisposableMixin) {} + +// @filename: another.ts +declare function mix(mixin: TMix): TMix; + +const DisposableMixin = class { + #onDispose() {} +}; + +export default class extends mix(DisposableMixin) {} diff --git a/tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts b/tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts index 3175f2afce7df..853986f4a2e19 100644 --- a/tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts +++ b/tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts @@ -27,3 +27,9 @@ const test = new Test(); Test.getTags() test.tags(); + +export class Test2 { + nested = class { + private prop = 42; + } +} diff --git a/tests/cases/compiler/emitClassExpressionInDeclarationFile3.ts b/tests/cases/compiler/emitClassExpressionInDeclarationFile3.ts new file mode 100644 index 0000000000000..205e782cddad1 --- /dev/null +++ b/tests/cases/compiler/emitClassExpressionInDeclarationFile3.ts @@ -0,0 +1,31 @@ +// @target: esnext +// @declaration: true + +export var noPrivates = class { + static getTags() { } + tags() { } + static #ps = -1 + #p = 12 +} + +export class FooItem { + foo(): void { } + name?: string; + #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) {} + +export class Test2 { + nested = class { + #prop = 42; + } +}