From b7cda24731955e3bbd568351fdc57b0437f9cb46 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 27 Mar 2018 16:22:27 -0700 Subject: [PATCH 1/2] isMethodLike recognises prototype-assignment methods --- src/compiler/checker.ts | 2 +- .../typeFromPropertyAssignment23.symbols | 24 +++++++++++++++++ .../typeFromPropertyAssignment23.types | 26 +++++++++++++++++++ .../salsa/typeFromPropertyAssignment23.ts | 17 ++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/typeFromPropertyAssignment23.symbols create mode 100644 tests/baselines/reference/typeFromPropertyAssignment23.types create mode 100644 tests/cases/conformance/salsa/typeFromPropertyAssignment23.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cc17e30e0e098..20419e4a0e221 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16103,7 +16103,7 @@ namespace ts { } function isMethodLike(symbol: Symbol) { - return !!(symbol.flags & SymbolFlags.Method || getCheckFlags(symbol) & CheckFlags.SyntheticMethod); + return !!(symbol.flags & SymbolFlags.Method || getCheckFlags(symbol) & CheckFlags.SyntheticMethod || isFunctionLikeDeclaration(getAssignedJavascriptInitializer(symbol.valueDeclaration))); } /** diff --git a/tests/baselines/reference/typeFromPropertyAssignment23.symbols b/tests/baselines/reference/typeFromPropertyAssignment23.symbols new file mode 100644 index 0000000000000..879685fc357f3 --- /dev/null +++ b/tests/baselines/reference/typeFromPropertyAssignment23.symbols @@ -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)) +} + diff --git a/tests/baselines/reference/typeFromPropertyAssignment23.types b/tests/baselines/reference/typeFromPropertyAssignment23.types new file mode 100644 index 0000000000000..093d681032b70 --- /dev/null +++ b/tests/baselines/reference/typeFromPropertyAssignment23.types @@ -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 +} + diff --git a/tests/cases/conformance/salsa/typeFromPropertyAssignment23.ts b/tests/cases/conformance/salsa/typeFromPropertyAssignment23.ts new file mode 100644 index 0000000000000..c96d3b4ebdc6e --- /dev/null +++ b/tests/cases/conformance/salsa/typeFromPropertyAssignment23.ts @@ -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() { +} From f16874696fe3b5d874f419430fe030256ea72fdf Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 28 Mar 2018 10:25:28 -0700 Subject: [PATCH 2/2] Require js prototype methods to be in JS files --- src/compiler/checker.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 20419e4a0e221..57a75696ded46 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16103,7 +16103,9 @@ namespace ts { } function isMethodLike(symbol: Symbol) { - return !!(symbol.flags & SymbolFlags.Method || getCheckFlags(symbol) & CheckFlags.SyntheticMethod || isFunctionLikeDeclaration(getAssignedJavascriptInitializer(symbol.valueDeclaration))); + return !!(symbol.flags & SymbolFlags.Method || + getCheckFlags(symbol) & CheckFlags.SyntheticMethod || + isInJavaScriptFile(symbol.valueDeclaration) && isFunctionLikeDeclaration(getAssignedJavascriptInitializer(symbol.valueDeclaration))); } /**