Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7608196

Browse filesBrowse files
authored
Merge pull request microsoft#16282 from Microsoft/fix16086
Fix emit when type import merges with local value
2 parents 70c1c57 + 2f6c6e6 commit 7608196
Copy full SHA for 7608196

6 files changed

+79-4Lines changed: 79 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Jakefile.js‎

Copy file name to clipboardExpand all lines: Jakefile.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
926926
}
927927
}
928928

929-
var defaultTestTimeout = 20000;
929+
var defaultTestTimeout = 22000;
930930
desc("Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true.");
931931
task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], function () {
932932
runConsoleTests('min', /*runInParallel*/ true);
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,8 +1473,15 @@ namespace ts {
14731473
}
14741474
}
14751475

1476+
/**
1477+
* Indicates that a symbol is an alias that does not merge with a local declaration.
1478+
*/
1479+
function isNonLocalAlias(symbol: Symbol, excludes = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace) {
1480+
return symbol && (symbol.flags & (SymbolFlags.Alias | excludes)) === SymbolFlags.Alias;
1481+
}
1482+
14761483
function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol {
1477-
const shouldResolve = !dontResolveAlias && symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace));
1484+
const shouldResolve = !dontResolveAlias && isNonLocalAlias(symbol);
14781485
return shouldResolve ? resolveAlias(symbol) : symbol;
14791486
}
14801487

@@ -12020,7 +12027,9 @@ namespace ts {
1202012027
return getTypeOfSymbol(symbol);
1202112028
}
1202212029

12023-
if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
12030+
// We should only mark aliases as referenced if there isn't a local value declaration
12031+
// for the symbol.
12032+
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
1202412033
markAliasSymbolAsReferenced(symbol);
1202512034
}
1202612035

@@ -22926,7 +22935,9 @@ namespace ts {
2292622935
node = getParseTreeNode(node, isIdentifier);
2292722936
if (node) {
2292822937
const symbol = getReferencedValueSymbol(node);
22929-
if (symbol && symbol.flags & SymbolFlags.Alias) {
22938+
// We should only get the declaration of an alias if there isn't a local value
22939+
// declaration for the symbol
22940+
if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value)) {
2293022941
return getDeclarationOfAliasSymbol(symbol);
2293122942
}
2293222943
}
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/compiler/symbolMergeValueAndImportedType.ts] ////
2+
3+
//// [main.ts]
4+
import { X } from "./other";
5+
const X = 42;
6+
console.log('X is ' + X);
7+
//// [other.ts]
8+
export type X = {};
9+
10+
//// [other.js]
11+
"use strict";
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
//// [main.js]
14+
"use strict";
15+
Object.defineProperty(exports, "__esModule", { value: true });
16+
const X = 42;
17+
console.log('X is ' + X);
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/main.ts ===
2+
import { X } from "./other";
3+
>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5))
4+
5+
const X = 42;
6+
>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5))
7+
8+
console.log('X is ' + X);
9+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
10+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
11+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
12+
>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5))
13+
14+
=== tests/cases/compiler/other.ts ===
15+
export type X = {};
16+
>X : Symbol(X, Decl(other.ts, 0, 0))
17+
Collapse file
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/compiler/main.ts ===
2+
import { X } from "./other";
3+
>X : 42
4+
5+
const X = 42;
6+
>X : 42
7+
>42 : 42
8+
9+
console.log('X is ' + X);
10+
>console.log('X is ' + X) : void
11+
>console.log : (message?: any, ...optionalParams: any[]) => void
12+
>console : Console
13+
>log : (message?: any, ...optionalParams: any[]) => void
14+
>'X is ' + X : string
15+
>'X is ' : "X is "
16+
>X : 42
17+
18+
=== tests/cases/compiler/other.ts ===
19+
export type X = {};
20+
>X : X
21+
Collapse file
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @target: es2015
2+
// @module: commonjs
3+
// @lib: es2015,dom
4+
// @filename: main.ts
5+
import { X } from "./other";
6+
const X = 42;
7+
console.log('X is ' + X);
8+
// @filename: other.ts
9+
export type X = {};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.