Ensure functions that have prototype properties assigned by Object.defineProperty get marked as classes (#34577)

* Ensure functions that have prototype properties assigned by Object.defineProperty get marked as classes

* Revert unneeded change
This commit is contained in:
Andrew Branch 2019-10-18 16:31:43 -07:00 committed by GitHub
parent cdf1ab2dec
commit 91196fc53f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 0 deletions

View File

@ -2788,6 +2788,10 @@ namespace ts {
function bindObjectDefinePrototypeProperty(node: BindableObjectDefinePropertyCall) {
const namespaceSymbol = lookupSymbolForPropertyAccess((node.arguments[0] as PropertyAccessExpression).expression as EntityNameExpression);
if (namespaceSymbol) {
// Ensure the namespace symbol becomes class-like
addDeclarationToSymbol(namespaceSymbol, namespaceSymbol.valueDeclaration, SymbolFlags.Class);
}
bindPotentiallyNewExpandoMemberToNamespace(node, namespaceSymbol, /*isPrototypeProperty*/ true);
}

View File

@ -0,0 +1,23 @@
=== /a.js ===
function Graphic() {
>Graphic : Symbol(Graphic, Decl(a.js, 0, 0))
}
Object.defineProperty(Graphic.prototype, "instance", {
>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --))
>Graphic.prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --))
>Graphic : Symbol(Graphic, Decl(a.js, 0, 0))
>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --))
>"instance" : Symbol(Graphic.instance, Decl(a.js, 1, 1))
get: function() {
>get : Symbol(get, Decl(a.js, 3, 54))
return this;
>this : Symbol(Graphic, Decl(a.js, 0, 0))
}
});

View File

@ -0,0 +1,26 @@
=== /a.js ===
function Graphic() {
>Graphic : typeof Graphic
}
Object.defineProperty(Graphic.prototype, "instance", {
>Object.defineProperty(Graphic.prototype, "instance", { get: function() { return this; }}) : any
>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any
>Object : ObjectConstructor
>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType<any>) => any
>Graphic.prototype : any
>Graphic : typeof Graphic
>prototype : any
>"instance" : "instance"
>{ get: function() { return this; }} : { get: () => this; }
get: function() {
>get : () => this
>function() { return this; } : () => this
return this;
>this : this
}
});

View File

@ -0,0 +1,14 @@
// @allowJs: true
// @checkJs: false
// @noEmit: true
// @Filename: /a.js
function Graphic() {
}
Object.defineProperty(Graphic.prototype, "instance", {
get: function() {
return this;
}
});