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:
Nathan Shively-Sanders
2018-03-28 10:41:24 -07:00
committed by GitHub
parent 66bf5b4e9d
commit adf30dd694
4 changed files with 70 additions and 1 deletions

View File

@@ -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)));
}
/**

View File

@@ -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))
}

View 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
}

View File

@@ -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() {
}