Skip to content

Commit 973c3ca

Browse files
committed
When unidirectionally merging symbols, do so recursively
1 parent d69f9f3 commit 973c3ca

File tree

5 files changed

+97
-4
lines changed

5 files changed

+97
-4
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,11 +918,12 @@ namespace ts {
918918
addRange(target.declarations, source.declarations);
919919
if (source.members) {
920920
if (!target.members) target.members = createSymbolTable();
921-
mergeSymbolTable(target.members, source.members);
921+
mergeSymbolTable(target.members, source.members, unidirectional);
922922
}
923923
if (source.exports) {
924924
if (!target.exports) target.exports = createSymbolTable();
925-
mergeSymbolTable(target.exports, source.exports);
925+
mergeSymbolTable(target.exports, source.exports, unidirectional
926+
);
926927
}
927928
if (!unidirectional) {
928929
recordMergedSymbol(target, source);
@@ -993,10 +994,10 @@ namespace ts {
993994
return combined;
994995
}
995996

996-
function mergeSymbolTable(target: SymbolTable, source: SymbolTable) {
997+
function mergeSymbolTable(target: SymbolTable, source: SymbolTable, unidirectional = false) {
997998
source.forEach((sourceSymbol, id) => {
998999
const targetSymbol = target.get(id);
999-
target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol) : sourceSymbol);
1000+
target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol, unidirectional) : sourceSymbol);
10001001
});
10011002
}
10021003

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests/cases/conformance/ambient/test.ts(6,6): error TS2339: Property 'a' does not exist on type 'OhNo'.
2+
3+
4+
==== tests/cases/conformance/ambient/types.ts (0 errors) ====
5+
declare module "*.foo" {
6+
export interface OhNo { star: string }
7+
}
8+
9+
==== tests/cases/conformance/ambient/test.ts (1 errors) ====
10+
declare module "a.foo" {
11+
export interface OhNo { a: string }
12+
}
13+
import { OhNo } from "b.foo"
14+
declare let ohno: OhNo;
15+
ohno.a // oh no
16+
~
17+
!!! error TS2339: Property 'a' does not exist on type 'OhNo'.
18+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/conformance/ambient/ambientDeclarationsPatterns_merging3.ts] ////
2+
3+
//// [types.ts]
4+
declare module "*.foo" {
5+
export interface OhNo { star: string }
6+
}
7+
8+
//// [test.ts]
9+
declare module "a.foo" {
10+
export interface OhNo { a: string }
11+
}
12+
import { OhNo } from "b.foo"
13+
declare let ohno: OhNo;
14+
ohno.a // oh no
15+
16+
17+
//// [types.js]
18+
//// [test.js]
19+
"use strict";
20+
exports.__esModule = true;
21+
ohno.a; // oh no
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/conformance/ambient/types.ts ===
2+
declare module "*.foo" {
3+
>"*.foo" : Symbol("*.foo", Decl(types.ts, 0, 0))
4+
5+
export interface OhNo { star: string }
6+
>OhNo : Symbol(OhNo, Decl(types.ts, 0, 24))
7+
>star : Symbol(OhNo.star, Decl(types.ts, 1, 25))
8+
}
9+
10+
=== tests/cases/conformance/ambient/test.ts ===
11+
declare module "a.foo" {
12+
>"a.foo" : Symbol("a.foo", Decl(test.ts, 0, 0), Decl(types.ts, 0, 0))
13+
14+
export interface OhNo { a: string }
15+
>OhNo : Symbol(OhNo, Decl(test.ts, 0, 24), Decl(types.ts, 0, 24))
16+
>a : Symbol(OhNo.a, Decl(test.ts, 1, 25))
17+
}
18+
import { OhNo } from "b.foo"
19+
>OhNo : Symbol(OhNo, Decl(test.ts, 3, 8))
20+
21+
declare let ohno: OhNo;
22+
>ohno : Symbol(ohno, Decl(test.ts, 4, 11))
23+
>OhNo : Symbol(OhNo, Decl(test.ts, 3, 8))
24+
25+
ohno.a // oh no
26+
>ohno : Symbol(ohno, Decl(test.ts, 4, 11))
27+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/ambient/types.ts ===
2+
declare module "*.foo" {
3+
>"*.foo" : typeof import("*.foo")
4+
5+
export interface OhNo { star: string }
6+
>star : string
7+
}
8+
9+
=== tests/cases/conformance/ambient/test.ts ===
10+
declare module "a.foo" {
11+
>"a.foo" : typeof import("a.foo")
12+
13+
export interface OhNo { a: string }
14+
>a : string
15+
}
16+
import { OhNo } from "b.foo"
17+
>OhNo : any
18+
19+
declare let ohno: OhNo;
20+
>ohno : OhNo
21+
22+
ohno.a // oh no
23+
>ohno.a : any
24+
>ohno : OhNo
25+
>a : any
26+

0 commit comments

Comments
 (0)