Skip to content

Commit adf30dd

Browse files
authored
isMethodLike recognises prototype-assignment methods (#22935)
* isMethodLike recognises prototype-assignment methods * Require js prototype methods to be in JS files
1 parent 66bf5b4 commit adf30dd

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16103,7 +16103,9 @@ namespace ts {
1610316103
}
1610416104

1610516105
function isMethodLike(symbol: Symbol) {
16106-
return !!(symbol.flags & SymbolFlags.Method || getCheckFlags(symbol) & CheckFlags.SyntheticMethod);
16106+
return !!(symbol.flags & SymbolFlags.Method ||
16107+
getCheckFlags(symbol) & CheckFlags.SyntheticMethod ||
16108+
isInJavaScriptFile(symbol.valueDeclaration) && isFunctionLikeDeclaration(getAssignedJavascriptInitializer(symbol.valueDeclaration)));
1610716109
}
1610816110

1610916111
/**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/salsa/a.js ===
2+
class Ex {
3+
>Ex : Symbol(Ex, Decl(a.js, 0, 0))
4+
5+
foo() {
6+
>foo : Symbol(Ex.foo, Decl(a.js, 0, 10))
7+
}
8+
}
9+
10+
class MyClass extends Ex {
11+
>MyClass : Symbol(MyClass, Decl(a.js, 3, 1))
12+
>Ex : Symbol(Ex, Decl(a.js, 0, 0))
13+
14+
}
15+
16+
// this override should be fine (even if it's a little odd)
17+
MyClass.prototype.foo = function() {
18+
>MyClass.prototype.foo : Symbol(MyClass.foo, Decl(a.js, 7, 1))
19+
>MyClass.prototype : Symbol(MyClass.foo, Decl(a.js, 7, 1))
20+
>MyClass : Symbol(MyClass, Decl(a.js, 3, 1))
21+
>prototype : Symbol(MyClass.prototype)
22+
>foo : Symbol(MyClass.foo, Decl(a.js, 7, 1))
23+
}
24+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/salsa/a.js ===
2+
class Ex {
3+
>Ex : Ex
4+
5+
foo() {
6+
>foo : () => void
7+
}
8+
}
9+
10+
class MyClass extends Ex {
11+
>MyClass : MyClass
12+
>Ex : Ex
13+
14+
}
15+
16+
// this override should be fine (even if it's a little odd)
17+
MyClass.prototype.foo = function() {
18+
>MyClass.prototype.foo = function() {} : () => void
19+
>MyClass.prototype.foo : () => void
20+
>MyClass.prototype : MyClass
21+
>MyClass : typeof MyClass
22+
>prototype : MyClass
23+
>foo : () => void
24+
>function() {} : () => void
25+
}
26+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @noEmit: true
2+
// @strict: true
3+
// @checkJs: true
4+
// @allowJs: true
5+
// @Filename: a.js
6+
class Ex {
7+
foo() {
8+
}
9+
}
10+
11+
class MyClass extends Ex {
12+
13+
}
14+
15+
// this override should be fine (even if it's a little odd)
16+
MyClass.prototype.foo = function() {
17+
}

0 commit comments

Comments
 (0)