Skip to content

Commit

Permalink
When unidirectionally merging symbols, do so recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Apr 24, 2019
1 parent d69f9f3 commit 973c3ca
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/compiler/checker.ts
Expand Up @@ -918,11 +918,12 @@ namespace ts {
addRange(target.declarations, source.declarations);
if (source.members) {
if (!target.members) target.members = createSymbolTable();
mergeSymbolTable(target.members, source.members);
mergeSymbolTable(target.members, source.members, unidirectional);
}
if (source.exports) {
if (!target.exports) target.exports = createSymbolTable();
mergeSymbolTable(target.exports, source.exports);
mergeSymbolTable(target.exports, source.exports, unidirectional
);
}
if (!unidirectional) {
recordMergedSymbol(target, source);
Expand Down Expand Up @@ -993,10 +994,10 @@ namespace ts {
return combined;
}

function mergeSymbolTable(target: SymbolTable, source: SymbolTable) {
function mergeSymbolTable(target: SymbolTable, source: SymbolTable, unidirectional = false) {
source.forEach((sourceSymbol, id) => {
const targetSymbol = target.get(id);
target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol) : sourceSymbol);
target.set(id, targetSymbol ? mergeSymbol(targetSymbol, sourceSymbol, unidirectional) : sourceSymbol);
});
}

Expand Down
@@ -0,0 +1,18 @@
tests/cases/conformance/ambient/test.ts(6,6): error TS2339: Property 'a' does not exist on type 'OhNo'.


==== tests/cases/conformance/ambient/types.ts (0 errors) ====
declare module "*.foo" {
export interface OhNo { star: string }
}

==== tests/cases/conformance/ambient/test.ts (1 errors) ====
declare module "a.foo" {
export interface OhNo { a: string }
}
import { OhNo } from "b.foo"
declare let ohno: OhNo;
ohno.a // oh no
~
!!! error TS2339: Property 'a' does not exist on type 'OhNo'.

21 changes: 21 additions & 0 deletions tests/baselines/reference/ambientDeclarationsPatterns_merging3.js
@@ -0,0 +1,21 @@
//// [tests/cases/conformance/ambient/ambientDeclarationsPatterns_merging3.ts] ////

//// [types.ts]
declare module "*.foo" {
export interface OhNo { star: string }
}

//// [test.ts]
declare module "a.foo" {
export interface OhNo { a: string }
}
import { OhNo } from "b.foo"
declare let ohno: OhNo;
ohno.a // oh no


//// [types.js]
//// [test.js]
"use strict";
exports.__esModule = true;
ohno.a; // oh no
@@ -0,0 +1,27 @@
=== tests/cases/conformance/ambient/types.ts ===
declare module "*.foo" {
>"*.foo" : Symbol("*.foo", Decl(types.ts, 0, 0))

export interface OhNo { star: string }
>OhNo : Symbol(OhNo, Decl(types.ts, 0, 24))
>star : Symbol(OhNo.star, Decl(types.ts, 1, 25))
}

=== tests/cases/conformance/ambient/test.ts ===
declare module "a.foo" {
>"a.foo" : Symbol("a.foo", Decl(test.ts, 0, 0), Decl(types.ts, 0, 0))

export interface OhNo { a: string }
>OhNo : Symbol(OhNo, Decl(test.ts, 0, 24), Decl(types.ts, 0, 24))
>a : Symbol(OhNo.a, Decl(test.ts, 1, 25))
}
import { OhNo } from "b.foo"
>OhNo : Symbol(OhNo, Decl(test.ts, 3, 8))

declare let ohno: OhNo;
>ohno : Symbol(ohno, Decl(test.ts, 4, 11))
>OhNo : Symbol(OhNo, Decl(test.ts, 3, 8))

ohno.a // oh no
>ohno : Symbol(ohno, Decl(test.ts, 4, 11))

@@ -0,0 +1,26 @@
=== tests/cases/conformance/ambient/types.ts ===
declare module "*.foo" {
>"*.foo" : typeof import("*.foo")

export interface OhNo { star: string }
>star : string
}

=== tests/cases/conformance/ambient/test.ts ===
declare module "a.foo" {
>"a.foo" : typeof import("a.foo")

export interface OhNo { a: string }
>a : string
}
import { OhNo } from "b.foo"
>OhNo : any

declare let ohno: OhNo;
>ohno : OhNo

ohno.a // oh no
>ohno.a : any
>ohno : OhNo
>a : any

0 comments on commit 973c3ca

Please sign in to comment.