Skip to content

Commit 8035e99

Browse files
author
Andy Hanson
committed
Given import * of an export = module, raise an error but still return a symbol.
1 parent abb2b82 commit 8035e99

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,10 +1684,9 @@ namespace ts {
16841684
// references a symbol that is at least declared as a module or a variable. The target of the 'export =' may
16851685
// combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
16861686
function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression, dontResolveAlias: boolean): Symbol {
1687-
let symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias);
1687+
const symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias);
16881688
if (!dontResolveAlias && symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) {
16891689
error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
1690-
symbol = undefined;
16911690
}
16921691
return symbol;
16931692
}

tests/baselines/reference/es6ExportEqualsInterop.errors.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ tests/cases/compiler/main.ts(36,8): error TS1192: Module '"class-module"' has no
1414
tests/cases/compiler/main.ts(39,21): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
1515
tests/cases/compiler/main.ts(45,21): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
1616
tests/cases/compiler/main.ts(47,21): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
17+
tests/cases/compiler/main.ts(50,1): error TS2693: 'y1' only refers to a type, but is being used as a value here.
18+
tests/cases/compiler/main.ts(56,4): error TS2339: Property 'a' does not exist on type '() => any'.
19+
tests/cases/compiler/main.ts(58,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'.
20+
tests/cases/compiler/main.ts(62,10): error TS2305: Module '"interface"' has no exported member 'a'.
1721
tests/cases/compiler/main.ts(62,25): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
22+
tests/cases/compiler/main.ts(68,10): error TS2305: Module '"function"' has no exported member 'a'.
1823
tests/cases/compiler/main.ts(68,25): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
24+
tests/cases/compiler/main.ts(70,10): error TS2305: Module '"class"' has no exported member 'a'.
1925
tests/cases/compiler/main.ts(70,25): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
26+
tests/cases/compiler/main.ts(85,10): error TS2305: Module '"interface"' has no exported member 'a'.
2027
tests/cases/compiler/main.ts(85,25): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
28+
tests/cases/compiler/main.ts(91,10): error TS2305: Module '"function"' has no exported member 'a'.
2129
tests/cases/compiler/main.ts(91,25): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
30+
tests/cases/compiler/main.ts(93,10): error TS2305: Module '"class"' has no exported member 'a'.
2231
tests/cases/compiler/main.ts(93,25): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
2332
tests/cases/compiler/main.ts(97,15): error TS2498: Module '"interface"' uses 'export =' and cannot be used with 'export *'.
2433
tests/cases/compiler/main.ts(98,15): error TS2498: Module '"variable"' uses 'export =' and cannot be used with 'export *'.
@@ -32,7 +41,7 @@ tests/cases/compiler/main.ts(105,15): error TS2498: Module '"class"' uses 'expor
3241
tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses 'export =' and cannot be used with 'export *'.
3342

3443

35-
==== tests/cases/compiler/main.ts (32 errors) ====
44+
==== tests/cases/compiler/main.ts (41 errors) ====
3645
/// <reference path="modules.d.ts"/>
3746

3847
// import-equals
@@ -115,18 +124,26 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
115124
import * as y0 from "class-module";
116125

117126
y1.a;
127+
~~
128+
!!! error TS2693: 'y1' only refers to a type, but is being used as a value here.
118129
y2.a;
119130
y3.a;
120131
y4.a;
121132
y5.a;
122133
y6.a;
123134
y7.a;
135+
~
136+
!!! error TS2339: Property 'a' does not exist on type '() => any'.
124137
y8.a;
125138
y9.a;
139+
~
140+
!!! error TS2339: Property 'a' does not exist on type 'typeof Foo'.
126141
y0.a;
127142

128143
// named import
129144
import { a as a1 } from "interface";
145+
~
146+
!!! error TS2305: Module '"interface"' has no exported member 'a'.
130147
~~~~~~~~~~~
131148
!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
132149
import { a as a2 } from "variable";
@@ -135,10 +152,14 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
135152
import { a as a5 } from "interface-module";
136153
import { a as a6 } from "variable-module";
137154
import { a as a7 } from "function";
155+
~
156+
!!! error TS2305: Module '"function"' has no exported member 'a'.
138157
~~~~~~~~~~
139158
!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
140159
import { a as a8 } from "function-module";
141160
import { a as a9 } from "class";
161+
~
162+
!!! error TS2305: Module '"class"' has no exported member 'a'.
142163
~~~~~~~
143164
!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
144165
import { a as a0 } from "class-module";
@@ -156,6 +177,8 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
156177

157178
// named export
158179
export { a as a1 } from "interface";
180+
~
181+
!!! error TS2305: Module '"interface"' has no exported member 'a'.
159182
~~~~~~~~~~~
160183
!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct.
161184
export { a as a2 } from "variable";
@@ -164,10 +187,14 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
164187
export { a as a5 } from "interface-module";
165188
export { a as a6 } from "variable-module";
166189
export { a as a7 } from "function";
190+
~
191+
!!! error TS2305: Module '"function"' has no exported member 'a'.
167192
~~~~~~~~~~
168193
!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct.
169194
export { a as a8 } from "function-module";
170195
export { a as a9 } from "class";
196+
~
197+
!!! error TS2305: Module '"class"' has no exported member 'a'.
171198
~~~~~~~
172199
!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct.
173200
export { a as a0 } from "class-module";

tests/baselines/reference/es6ExportEqualsInterop.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ z7.a;
232232
z8.a;
233233
z9.a;
234234
z0.a;
235-
// namespace import
236-
var y1 = require("interface");
237235
var y2 = require("variable");
238236
var y3 = require("interface-variable");
239237
var y4 = require("module");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @allowJs: true
4+
5+
// @Filename: /node_modules/@types/abs/index.d.ts
6+
////declare function abs(str: string): string;
7+
////export = abs;
8+
9+
// @Filename: /a.js
10+
////import * as abs from "abs";
11+
////abs/**/;
12+
13+
goTo.marker();
14+
edit.insert('(');
15+
verify.currentSignatureHelpIs('abs(str: string): string');

0 commit comments

Comments
 (0)