Skip to content

Commit 8f3f7b9

Browse files
committed
Merge pull request microsoft#1132 from Microsoft/elidedImport
Fix the incorrect eliding of import declaration
2 parents a54f974 + b1297b2 commit 8f3f7b9

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4474,7 +4474,7 @@ module ts {
44744474
if (symbol.flags & SymbolFlags.Import) {
44754475
// Mark the import as referenced so that we emit it in the final .js file.
44764476
// exception: identifiers that appear in type queries, const enums, modules that contain only const enums
4477-
getSymbolLinks(symbol).referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol));
4477+
getSymbolLinks(symbol).referenced = getSymbolLinks(symbol).referenced || (!isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)));
44784478
}
44794479

44804480
checkCollisionWithCapturedSuperVariable(node, node);

tests/baselines/reference/aliasUsageInIndexerOfClass.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var VisualizationModel = (function (_super) {
5050
})(Backbone.Model);
5151
exports.VisualizationModel = VisualizationModel;
5252
//// [aliasUsageInIndexerOfClass_main.js]
53+
var moduleA = require("aliasUsageInIndexerOfClass_moduleA");
5354
var N = (function () {
5455
function N() {
5556
this.x = moduleA;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/compiler/elidingImportNames.ts] ////
2+
3+
//// [elidingImportNames_test.ts]
4+
5+
import a = require('elidingImportNames_main'); // alias used in typeof
6+
var b = a;
7+
var x: typeof a;
8+
import a2 = require('elidingImportNames_main1'); // alias not used in typeof
9+
var b2 = a2;
10+
11+
12+
//// [elidingImportNames_main.ts]
13+
export var main = 10;
14+
15+
//// [elidingImportNames_main1.ts]
16+
export var main = 10;
17+
18+
//// [elidingImportNames_main.js]
19+
exports.main = 10;
20+
//// [elidingImportNames_main1.js]
21+
exports.main = 10;
22+
//// [elidingImportNames_test.js]
23+
var a = require('elidingImportNames_main'); // alias used in typeof
24+
var b = a;
25+
var x;
26+
var a2 = require('elidingImportNames_main1'); // alias not used in typeof
27+
var b2 = a2;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/elidingImportNames_test.ts ===
2+
3+
import a = require('elidingImportNames_main'); // alias used in typeof
4+
>a : typeof a
5+
6+
var b = a;
7+
>b : typeof a
8+
>a : typeof a
9+
10+
var x: typeof a;
11+
>x : typeof a
12+
>a : typeof a
13+
14+
import a2 = require('elidingImportNames_main1'); // alias not used in typeof
15+
>a2 : typeof a2
16+
17+
var b2 = a2;
18+
>b2 : typeof a2
19+
>a2 : typeof a2
20+
21+
22+
=== tests/cases/compiler/elidingImportNames_main.ts ===
23+
export var main = 10;
24+
>main : number
25+
26+
=== tests/cases/compiler/elidingImportNames_main1.ts ===
27+
export var main = 10;
28+
>main : number
29+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @module: commonjs
2+
3+
// @Filename: elidingImportNames_test.ts
4+
import a = require('elidingImportNames_main'); // alias used in typeof
5+
var b = a;
6+
var x: typeof a;
7+
import a2 = require('elidingImportNames_main1'); // alias not used in typeof
8+
var b2 = a2;
9+
10+
11+
// @Filename: elidingImportNames_main.ts
12+
export var main = 10;
13+
14+
// @Filename: elidingImportNames_main1.ts
15+
export var main = 10;

0 commit comments

Comments
 (0)