From c84b7caa25a1239d103e8762350838cdc81409c2 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 12 Feb 2018 13:02:47 -0800 Subject: [PATCH] Fix emit when binder treats exported const as namespace --- src/compiler/checker.ts | 2 +- .../typeFromPropertyAssignmentWithExport.js | 18 +++++++++++++++ ...peFromPropertyAssignmentWithExport.symbols | 13 +++++++++++ ...typeFromPropertyAssignmentWithExport.types | 22 +++++++++++++++++++ .../typeFromPropertyAssignmentWithExport.ts | 12 ++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/typeFromPropertyAssignmentWithExport.js create mode 100644 tests/baselines/reference/typeFromPropertyAssignmentWithExport.symbols create mode 100644 tests/baselines/reference/typeFromPropertyAssignmentWithExport.types create mode 100644 tests/cases/conformance/salsa/typeFromPropertyAssignmentWithExport.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2426c7b9508..4b24ff15ef7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25054,7 +25054,7 @@ namespace ts { // we prefix depends on the kind of entity. SymbolFlags.ExportHasLocal encompasses all the // kinds that we do NOT prefix. const exportSymbol = getMergedSymbol(symbol.exportSymbol); - if (!prefixLocals && exportSymbol.flags & SymbolFlags.ExportHasLocal) { + if (!prefixLocals && exportSymbol.flags & SymbolFlags.ExportHasLocal && !(exportSymbol.flags & SymbolFlags.Variable)) { return undefined; } symbol = exportSymbol; diff --git a/tests/baselines/reference/typeFromPropertyAssignmentWithExport.js b/tests/baselines/reference/typeFromPropertyAssignmentWithExport.js new file mode 100644 index 00000000000..34fbd5fd53e --- /dev/null +++ b/tests/baselines/reference/typeFromPropertyAssignmentWithExport.js @@ -0,0 +1,18 @@ +//// [a.js] +// this is a javascript file... + +export const Adapter = {}; + +Adapter.prop = {}; + +// comment this out, and it works +Adapter.asyncMethod = function() {} + +//// [a.js] +"use strict"; +// this is a javascript file... +exports.__esModule = true; +exports.Adapter = {}; +exports.Adapter.prop = {}; +// comment this out, and it works +exports.Adapter.asyncMethod = function () { }; diff --git a/tests/baselines/reference/typeFromPropertyAssignmentWithExport.symbols b/tests/baselines/reference/typeFromPropertyAssignmentWithExport.symbols new file mode 100644 index 00000000000..060018acdeb --- /dev/null +++ b/tests/baselines/reference/typeFromPropertyAssignmentWithExport.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/salsa/a.js === +// this is a javascript file... + +export const Adapter = {}; +>Adapter : Symbol(Adapter, Decl(a.js, 2, 12), Decl(a.js, 4, 18)) + +Adapter.prop = {}; +>Adapter : Symbol(Adapter, Decl(a.js, 2, 12), Decl(a.js, 4, 18)) + +// comment this out, and it works +Adapter.asyncMethod = function() {} +>Adapter : Symbol(Adapter, Decl(a.js, 2, 12), Decl(a.js, 4, 18)) + diff --git a/tests/baselines/reference/typeFromPropertyAssignmentWithExport.types b/tests/baselines/reference/typeFromPropertyAssignmentWithExport.types new file mode 100644 index 00000000000..82b0e0b48f9 --- /dev/null +++ b/tests/baselines/reference/typeFromPropertyAssignmentWithExport.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/salsa/a.js === +// this is a javascript file... + +export const Adapter = {}; +>Adapter : { [x: string]: any; } +>{} : { [x: string]: any; } + +Adapter.prop = {}; +>Adapter.prop = {} : {} +>Adapter.prop : any +>Adapter : { [x: string]: any; } +>prop : any +>{} : {} + +// comment this out, and it works +Adapter.asyncMethod = function() {} +>Adapter.asyncMethod = function() {} : () => void +>Adapter.asyncMethod : any +>Adapter : { [x: string]: any; } +>asyncMethod : any +>function() {} : () => void + diff --git a/tests/cases/conformance/salsa/typeFromPropertyAssignmentWithExport.ts b/tests/cases/conformance/salsa/typeFromPropertyAssignmentWithExport.ts new file mode 100644 index 00000000000..ed4ca168bf7 --- /dev/null +++ b/tests/cases/conformance/salsa/typeFromPropertyAssignmentWithExport.ts @@ -0,0 +1,12 @@ +// @allowJs: true +// @checkJs: true +// @Filename: a.js +// @outDir: dist +// this is a javascript file... + +export const Adapter = {}; + +Adapter.prop = {}; + +// comment this out, and it works +Adapter.asyncMethod = function() {} \ No newline at end of file