From b760fc0ae0415948fe1b09055cbcc9c756f9c366 Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Thu, 25 Feb 2016 17:06:31 -0800 Subject: [PATCH] Fixed es2015 imports from export= (cherry picked from commit 9e46c180b4063e56eb947928615a3ebd46ecbe5e) --- src/compiler/checker.ts | 10 +++++++++- tests/cases/fourslash/javascriptModules20.ts | 13 ++++++++++++ tests/cases/fourslash/javascriptModules21.ts | 14 +++++++++++++ tests/cases/fourslash/javascriptModules22.ts | 13 ++++++++++++ tests/cases/fourslash/javascriptModules23.ts | 12 +++++++++++ tests/cases/fourslash/javascriptModules24.ts | 21 ++++++++++++++++++++ 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/javascriptModules20.ts create mode 100644 tests/cases/fourslash/javascriptModules21.ts create mode 100644 tests/cases/fourslash/javascriptModules22.ts create mode 100644 tests/cases/fourslash/javascriptModules23.ts create mode 100644 tests/cases/fourslash/javascriptModules24.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b0d0e2cbcdb..7ef8578d959 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -964,8 +964,16 @@ namespace ts { if (targetSymbol) { const name = specifier.propertyName || specifier.name; if (name.text) { + let symbolFromVariable: Symbol; + // First check if module was specified with "export=". If so, get the member from the resolved type + if (moduleSymbol && moduleSymbol.exports && moduleSymbol.exports["export="]) { + const members = (getTypeOfSymbol(targetSymbol) as ResolvedType).members; + symbolFromVariable = members && members[name.text]; + } + else { + symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text); + } const symbolFromModule = getExportOfModule(targetSymbol, name.text); - const symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text); const symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; diff --git a/tests/cases/fourslash/javascriptModules20.ts b/tests/cases/fourslash/javascriptModules20.ts new file mode 100644 index 00000000000..7ef5c73e1c3 --- /dev/null +++ b/tests/cases/fourslash/javascriptModules20.ts @@ -0,0 +1,13 @@ +/// +// @allowJs: true + +// @Filename: mod.js +//// function foo() { return {a: true}; } +//// module.exports = foo(); + +// @Filename: app.js +//// import * as mod from "./mod" +//// mod./**/ + +goTo.marker(); +verify.completionListContains('a'); diff --git a/tests/cases/fourslash/javascriptModules21.ts b/tests/cases/fourslash/javascriptModules21.ts new file mode 100644 index 00000000000..3a046515924 --- /dev/null +++ b/tests/cases/fourslash/javascriptModules21.ts @@ -0,0 +1,14 @@ +/// +// @allowJs: true +// @module: system + +// @Filename: mod.js +//// function foo() { return {a: true}; } +//// module.exports = foo(); + +// @Filename: app.js +//// import mod from "./mod" +//// mod./**/ + +goTo.marker(); +verify.completionListContains('a'); diff --git a/tests/cases/fourslash/javascriptModules22.ts b/tests/cases/fourslash/javascriptModules22.ts new file mode 100644 index 00000000000..67e3423ec40 --- /dev/null +++ b/tests/cases/fourslash/javascriptModules22.ts @@ -0,0 +1,13 @@ +/// +// @allowJs: true + +// @Filename: mod.js +//// function foo() { return {a: "hello, world"}; } +//// module.exports = foo(); + +// @Filename: app.js +//// import {a} from "./mod" +//// a./**/ + +goTo.marker(); +verify.completionListContains('toString'); diff --git a/tests/cases/fourslash/javascriptModules23.ts b/tests/cases/fourslash/javascriptModules23.ts new file mode 100644 index 00000000000..eafbea87baa --- /dev/null +++ b/tests/cases/fourslash/javascriptModules23.ts @@ -0,0 +1,12 @@ +/// + +// @Filename: mod.ts +//// var foo = {a: "test"}; +//// export = foo; + +// @Filename: app.ts +//// import {a} from "./mod" +//// a./**/ + +goTo.marker(); +verify.completionListContains('toString'); diff --git a/tests/cases/fourslash/javascriptModules24.ts b/tests/cases/fourslash/javascriptModules24.ts new file mode 100644 index 00000000000..5a0dd892db7 --- /dev/null +++ b/tests/cases/fourslash/javascriptModules24.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: mod.ts +//// function foo() { return 42; } +//// namespace foo { +//// export function bar (a: string) { return a; } +//// } +//// export = foo; + +// @Filename: app.ts +//// import * as foo from "./mod" +//// foo/*1*/(); +//// foo.bar(/*2*/"test"); + +goTo.marker('1'); + +/**** BUG: Should be an error to invoke a call signature on a namespace import ****/ +//verify.errorExistsBeforeMarker('1'); +verify.quickInfoIs("(alias) foo(): number\nimport foo"); +goTo.marker('2'); +verify.signatureHelpArgumentCountIs(1);