-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Declaration-emit class expressions as type literals #15932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5a5fee3
Declaration-emit class expressions as type literals
sandersn e770249
Test:decl emit for class expressions as type lits
sandersn a0fa8ae
Address most PR comments
sandersn 860e8e8
Add error for class exprs w/private properties
sandersn ecaf44d
Add more tests and update baselines
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
tests/baselines/reference/declarationEmitExpressionInExtends4.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
tests/baselines/reference/emitClassExpressionInDeclarationFile.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| //// [emitClassExpressionInDeclarationFile.ts] | ||
| export var simpleExample = class { | ||
| static getTags() { } | ||
| tags() { } | ||
| } | ||
| export var circularReference = class C { | ||
| static getTags(c: C): C { return c } | ||
| tags(c: C): C { return c } | ||
| } | ||
|
|
||
| // repro from #15066 | ||
| export class FooItem { | ||
| foo(): void { } | ||
| name?: string; | ||
| } | ||
|
|
||
| export type Constructor<T> = new(...args: any[]) => T; | ||
| export function WithTags<T extends Constructor<FooItem>>(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(); | ||
|
|
||
|
|
||
| //// [emitClassExpressionInDeclarationFile.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.simpleExample = (function () { | ||
| function class_1() { | ||
| } | ||
| class_1.getTags = function () { }; | ||
| class_1.prototype.tags = function () { }; | ||
| return class_1; | ||
| }()); | ||
| exports.circularReference = (function () { | ||
| function C() { | ||
| } | ||
| C.getTags = function (c) { return c; }; | ||
| C.prototype.tags = function (c) { return c; }; | ||
| return C; | ||
| }()); | ||
| // repro from #15066 | ||
| var FooItem = (function () { | ||
| function FooItem() { | ||
| } | ||
| 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(); | ||
|
|
||
|
|
||
| //// [emitClassExpressionInDeclarationFile.d.ts] | ||
| 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; | ||
| }): { | ||
| tags(c: any): any; | ||
| }; | ||
| }; | ||
| export declare class FooItem { | ||
| foo(): void; | ||
| name?: string; | ||
| } | ||
| export declare type Constructor<T> = new (...args: any[]) => T; | ||
| export declare function WithTags<T extends Constructor<FooItem>>(Base: T): { | ||
| new (...args: any[]): { | ||
| tags(): void; | ||
| foo(): void; | ||
| name?: string; | ||
| }; | ||
| prototype: { | ||
| tags(): void; | ||
| foo(): void; | ||
| name?: string; | ||
| }; | ||
| getTags(): void; | ||
| } & T; | ||
| declare const Test_base: { | ||
| new (...args: any[]): { | ||
| tags(): void; | ||
| foo(): void; | ||
| name?: string; | ||
| }; | ||
| prototype: { | ||
| tags(): void; | ||
| foo(): void; | ||
| name?: string; | ||
| }; | ||
| getTags(): void; | ||
| } & typeof FooItem; | ||
| export declare class Test extends Test_base { | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
tests/baselines/reference/emitClassExpressionInDeclarationFile.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| === tests/cases/compiler/emitClassExpressionInDeclarationFile.ts === | ||
| export var simpleExample = class { | ||
| >simpleExample : Symbol(simpleExample, Decl(emitClassExpressionInDeclarationFile.ts, 0, 10)) | ||
|
|
||
| static getTags() { } | ||
| >getTags : Symbol(simpleExample.getTags, Decl(emitClassExpressionInDeclarationFile.ts, 0, 34)) | ||
|
|
||
| tags() { } | ||
| >tags : Symbol(simpleExample.tags, Decl(emitClassExpressionInDeclarationFile.ts, 1, 24)) | ||
| } | ||
| export var circularReference = class C { | ||
| >circularReference : Symbol(circularReference, Decl(emitClassExpressionInDeclarationFile.ts, 4, 10)) | ||
| >C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30)) | ||
|
|
||
| static getTags(c: C): C { return c } | ||
| >getTags : Symbol(C.getTags, Decl(emitClassExpressionInDeclarationFile.ts, 4, 40)) | ||
| >c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 5, 19)) | ||
| >C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30)) | ||
| >C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30)) | ||
| >c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 5, 19)) | ||
|
|
||
| tags(c: C): C { return c } | ||
| >tags : Symbol(C.tags, Decl(emitClassExpressionInDeclarationFile.ts, 5, 40)) | ||
| >c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 6, 9)) | ||
| >C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30)) | ||
| >C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30)) | ||
| >c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 6, 9)) | ||
| } | ||
|
|
||
| // repro from #15066 | ||
| export class FooItem { | ||
| >FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile.ts, 7, 1)) | ||
|
|
||
| foo(): void { } | ||
| >foo : Symbol(FooItem.foo, Decl(emitClassExpressionInDeclarationFile.ts, 10, 22)) | ||
|
|
||
| name?: string; | ||
| >name : Symbol(FooItem.name, Decl(emitClassExpressionInDeclarationFile.ts, 11, 19)) | ||
| } | ||
|
|
||
| export type Constructor<T> = new(...args: any[]) => T; | ||
| >Constructor : Symbol(Constructor, Decl(emitClassExpressionInDeclarationFile.ts, 13, 1)) | ||
| >T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 15, 24)) | ||
| >args : Symbol(args, Decl(emitClassExpressionInDeclarationFile.ts, 15, 33)) | ||
| >T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 15, 24)) | ||
|
|
||
| export function WithTags<T extends Constructor<FooItem>>(Base: T) { | ||
| >WithTags : Symbol(WithTags, Decl(emitClassExpressionInDeclarationFile.ts, 15, 54)) | ||
| >T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 16, 25)) | ||
| >Constructor : Symbol(Constructor, Decl(emitClassExpressionInDeclarationFile.ts, 13, 1)) | ||
| >FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile.ts, 7, 1)) | ||
| >Base : Symbol(Base, Decl(emitClassExpressionInDeclarationFile.ts, 16, 57)) | ||
| >T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 16, 25)) | ||
|
|
||
| return class extends Base { | ||
| >Base : Symbol(Base, Decl(emitClassExpressionInDeclarationFile.ts, 16, 57)) | ||
|
|
||
| static getTags(): void { } | ||
| >getTags : Symbol((Anonymous class).getTags, Decl(emitClassExpressionInDeclarationFile.ts, 17, 31)) | ||
|
|
||
| tags(): void { } | ||
| >tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile.ts, 18, 34)) | ||
| } | ||
| } | ||
|
|
||
| export class Test extends WithTags(FooItem) {} | ||
| >Test : Symbol(Test, Decl(emitClassExpressionInDeclarationFile.ts, 21, 1)) | ||
| >WithTags : Symbol(WithTags, Decl(emitClassExpressionInDeclarationFile.ts, 15, 54)) | ||
| >FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile.ts, 7, 1)) | ||
|
|
||
| const test = new Test(); | ||
| >test : Symbol(test, Decl(emitClassExpressionInDeclarationFile.ts, 25, 5)) | ||
| >Test : Symbol(Test, Decl(emitClassExpressionInDeclarationFile.ts, 21, 1)) | ||
|
|
||
| Test.getTags() | ||
| >Test.getTags : Symbol((Anonymous class).getTags, Decl(emitClassExpressionInDeclarationFile.ts, 17, 31)) | ||
| >Test : Symbol(Test, Decl(emitClassExpressionInDeclarationFile.ts, 21, 1)) | ||
| >getTags : Symbol((Anonymous class).getTags, Decl(emitClassExpressionInDeclarationFile.ts, 17, 31)) | ||
|
|
||
| test.tags(); | ||
| >test.tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile.ts, 18, 34)) | ||
| >test : Symbol(test, Decl(emitClassExpressionInDeclarationFile.ts, 25, 5)) | ||
| >tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile.ts, 18, 34)) | ||
|
|
91 changes: 91 additions & 0 deletions
91
tests/baselines/reference/emitClassExpressionInDeclarationFile.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| === tests/cases/compiler/emitClassExpressionInDeclarationFile.ts === | ||
| export var simpleExample = class { | ||
| >simpleExample : typeof simpleExample | ||
| >class { static getTags() { } tags() { }} : typeof simpleExample | ||
|
|
||
| static getTags() { } | ||
| >getTags : () => void | ||
|
|
||
| tags() { } | ||
| >tags : () => void | ||
| } | ||
| export var circularReference = class C { | ||
| >circularReference : typeof C | ||
| >class C { static getTags(c: C): C { return c } tags(c: C): C { return c }} : typeof C | ||
| >C : typeof C | ||
|
|
||
| static getTags(c: C): C { return c } | ||
| >getTags : (c: C) => C | ||
| >c : C | ||
| >C : C | ||
| >C : C | ||
| >c : C | ||
|
|
||
| tags(c: C): C { return c } | ||
| >tags : (c: C) => C | ||
| >c : C | ||
| >C : C | ||
| >C : C | ||
| >c : C | ||
| } | ||
|
|
||
| // repro from #15066 | ||
| export class FooItem { | ||
| >FooItem : FooItem | ||
|
|
||
| foo(): void { } | ||
| >foo : () => void | ||
|
|
||
| name?: string; | ||
| >name : string | ||
| } | ||
|
|
||
| export type Constructor<T> = new(...args: any[]) => T; | ||
| >Constructor : Constructor<T> | ||
| >T : T | ||
| >args : any[] | ||
| >T : T | ||
|
|
||
| export function WithTags<T extends Constructor<FooItem>>(Base: T) { | ||
| >WithTags : <T extends Constructor<FooItem>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithTags<any>.(Anonymous class); getTags(): void; } & T | ||
| >T : T | ||
| >Constructor : Constructor<T> | ||
| >FooItem : FooItem | ||
| >Base : T | ||
| >T : T | ||
|
|
||
| return class extends Base { | ||
| >class extends Base { static getTags(): void { } tags(): void { } } : { new (...args: any[]): (Anonymous class); prototype: WithTags<any>.(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<typeof FooItem>.(Anonymous class) & FooItem | ||
| >WithTags : <T extends Constructor<FooItem>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithTags<any>.(Anonymous class); getTags(): void; } & T | ||
| >FooItem : typeof FooItem | ||
|
|
||
| const test = new Test(); | ||
| >test : Test | ||
| >new Test() : Test | ||
| >Test : typeof Test | ||
|
|
||
| Test.getTags() | ||
| >Test.getTags() : void | ||
| >Test.getTags : () => void | ||
| >Test : typeof Test | ||
| >getTags : () => void | ||
|
|
||
| test.tags(); | ||
| >test.tags() : void | ||
| >test.tags : () => void | ||
| >test : Test | ||
| >tags : () => void | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kinda weird that we keep this property. can we filter
prototypeout?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done