mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
isMethodLike recognises prototype-assignment methods (#22935)
* isMethodLike recognises prototype-assignment methods * Require js prototype methods to be in JS files
This commit is contained in:
committed by
GitHub
parent
66bf5b4e9d
commit
adf30dd694
@@ -16103,7 +16103,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isMethodLike(symbol: Symbol) {
|
||||
return !!(symbol.flags & SymbolFlags.Method || getCheckFlags(symbol) & CheckFlags.SyntheticMethod);
|
||||
return !!(symbol.flags & SymbolFlags.Method ||
|
||||
getCheckFlags(symbol) & CheckFlags.SyntheticMethod ||
|
||||
isInJavaScriptFile(symbol.valueDeclaration) && isFunctionLikeDeclaration(getAssignedJavascriptInitializer(symbol.valueDeclaration)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/conformance/salsa/a.js ===
|
||||
class Ex {
|
||||
>Ex : Symbol(Ex, Decl(a.js, 0, 0))
|
||||
|
||||
foo() {
|
||||
>foo : Symbol(Ex.foo, Decl(a.js, 0, 10))
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass extends Ex {
|
||||
>MyClass : Symbol(MyClass, Decl(a.js, 3, 1))
|
||||
>Ex : Symbol(Ex, Decl(a.js, 0, 0))
|
||||
|
||||
}
|
||||
|
||||
// this override should be fine (even if it's a little odd)
|
||||
MyClass.prototype.foo = function() {
|
||||
>MyClass.prototype.foo : Symbol(MyClass.foo, Decl(a.js, 7, 1))
|
||||
>MyClass.prototype : Symbol(MyClass.foo, Decl(a.js, 7, 1))
|
||||
>MyClass : Symbol(MyClass, Decl(a.js, 3, 1))
|
||||
>prototype : Symbol(MyClass.prototype)
|
||||
>foo : Symbol(MyClass.foo, Decl(a.js, 7, 1))
|
||||
}
|
||||
|
||||
26
tests/baselines/reference/typeFromPropertyAssignment23.types
Normal file
26
tests/baselines/reference/typeFromPropertyAssignment23.types
Normal file
@@ -0,0 +1,26 @@
|
||||
=== tests/cases/conformance/salsa/a.js ===
|
||||
class Ex {
|
||||
>Ex : Ex
|
||||
|
||||
foo() {
|
||||
>foo : () => void
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass extends Ex {
|
||||
>MyClass : MyClass
|
||||
>Ex : Ex
|
||||
|
||||
}
|
||||
|
||||
// this override should be fine (even if it's a little odd)
|
||||
MyClass.prototype.foo = function() {
|
||||
>MyClass.prototype.foo = function() {} : () => void
|
||||
>MyClass.prototype.foo : () => void
|
||||
>MyClass.prototype : MyClass
|
||||
>MyClass : typeof MyClass
|
||||
>prototype : MyClass
|
||||
>foo : () => void
|
||||
>function() {} : () => void
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// @noEmit: true
|
||||
// @strict: true
|
||||
// @checkJs: true
|
||||
// @allowJs: true
|
||||
// @Filename: a.js
|
||||
class Ex {
|
||||
foo() {
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass extends Ex {
|
||||
|
||||
}
|
||||
|
||||
// this override should be fine (even if it's a little odd)
|
||||
MyClass.prototype.foo = function() {
|
||||
}
|
||||
Reference in New Issue
Block a user