From 4dc827e22ade0a39db5c32beba2e0f22e09e2fe9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 31 Mar 2020 14:59:47 -0700 Subject: [PATCH] Fix emit of simple module.exports.C.prototype pattern (#37719) Extends the fix of #36108 so that the simple example gets correct emit; the complex test case I came up with still doesn't work correctly, but the actual code froma #35228 is fixed. --- src/compiler/checker.ts | 2 +- .../jsDeclarationsExportAssignedConstructorFunction.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eec6b03dddc..3ba610453c0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5648,7 +5648,7 @@ namespace ts { serializeEnum(symbol, symbolName, modifierFlags); } if (symbol.flags & SymbolFlags.Class) { - if (symbol.flags & SymbolFlags.Property) { + if (symbol.flags & SymbolFlags.Property && isBinaryExpression(symbol.valueDeclaration.parent) && isClassExpression(symbol.valueDeclaration.parent.right)) { // Looks like a `module.exports.Sub = class {}` - if we serialize `symbol` as a class, the result will have no members, // since the classiness is actually from the target of the effective alias the symbol is. yes. A BlockScopedVariable|Class|Property // _really_ acts like an Alias, and none of a BlockScopedVariable, Class, or Property. This is the travesty of JS binding today. diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedConstructorFunction.js b/tests/baselines/reference/jsDeclarationsExportAssignedConstructorFunction.js index aa2f0d2a0a9..747a2627d42 100644 --- a/tests/baselines/reference/jsDeclarationsExportAssignedConstructorFunction.js +++ b/tests/baselines/reference/jsDeclarationsExportAssignedConstructorFunction.js @@ -21,4 +21,6 @@ module.exports.MyClass.prototype = { //// [jsDeclarationsExportAssignedConstructorFunction.d.ts] -export {}; +export class MyClass { + a: () => void; +}