Repository: microsoft/typescript-go (go)

Issue:
[bug] `tsgo` failing to resolve custom declaration files
The company I work for has a TS project with over 90k+ files. I recently ran `tsgo` against this project and was very impressed with how quick it was. However, it failed to resolve **our custom declaration files** resulting in a huge number of type errors like this:

```
Cannot find module './some_file.css' or its corresponding type declarations
...
Found 30381 errors in 16139 files
```

For example, we use CSS modules and have an associated `css_modules.d.ts` file of form:

```typescript
declare type HtmlEncodedCssList = ...;

declare module '*.css' {
  ...
}
```

When I run `tsgo -listFilesOnly` this declarations file does show up:

```
./typescript-go/built/local/tsgo -p <omitted>/web/tsconfig.json -listFilesOnly | grep css_modules
<omitted>/declarations/css_modules.d.ts
```

Pull request description:
Fix pattern ambient modules
Fixes #697

A lot of this function hasn't been implemented but this seems to do the trick for pattern-based ambient modules.

Patch:
diff --git a/internal/ast/ast.go b/internal/ast/ast.go
index d98ffd7bf..961cf2cd6 100644
--- a/internal/ast/ast.go
+++ b/internal/ast/ast.go
@@ -9689,7 +9689,7 @@ type SourceFile struct {
 	EndFlowNode               *FlowNode
 	SymbolCount               int
 	ClassifiableNames         core.Set[string]
-	PatternAmbientModules     []PatternAmbientModule
+	PatternAmbientModules     []*PatternAmbientModule
 
 	// Fields set by LineMap
 
diff --git a/internal/binder/binder.go b/internal/binder/binder.go
index 8822989d5..e5927d771 100644
--- a/internal/binder/binder.go
+++ b/internal/binder/binder.go
@@ -799,7 +799,7 @@ func (b *Binder) bindModuleDeclaration(node *ast.Node) {
 			}
 			symbol := b.declareSymbolAndAddToSymbolTable(node, ast.SymbolFlagsValueModule, ast.SymbolFlagsValueModuleExcludes)
 			if pattern.StarIndex >= 0 {
-				b.file.PatternAmbientModules = append(b.file.PatternAmbientModules, ast.PatternAmbientModule{Pattern: pattern, Symbol: symbol})
+				b.file.PatternAmbientModules = append(b.file.PatternAmbientModules, &ast.PatternAmbientModule{Pattern: pattern, Symbol: symbol})
 			}
 		}
 	} else {
diff --git a/internal/checker/checker.go b/internal/checker/checker.go
index 751befba6..26ac5c689 100644
--- a/internal/checker/checker.go
+++ b/internal/checker/checker.go
@@ -703,7 +703,7 @@ type Checker struct {
 	resolvingSignature                         *Signature
 	silentNeverSignature                       *Signature
 	enumNumberIndexInfo                        *IndexInfo
-	patternAmbientModules                      []ast.PatternAmbientModule
+	patternAmbientModules                      []*ast.PatternAmbientModule
 	patternAmbientModuleAugmentations          ast.SymbolTable
 	globalObjectType                           *Type
 	globalFunctionType                         *Type
@@ -1299,7 +1299,7 @@ func (c *Checker) mergeModuleAugmentation(moduleName *ast.Node) {
 			// the pattern ('*.foo'), so that 'getMergedSymbol()' on a.foo gives you
 			// all the exports both from the pattern and from the augmentation, but
 			// 'getMergedSymbol()' on *.foo only gives you exports from *.foo.
-			if core.Some(c.patternAmbientModules, func(module ast.PatternAmbientModule) bool {
+			if core.Some(c.patternAmbientModules, func(module *ast.PatternAmbientModule) bool {
 				return mainModule == module.Symbol
 			}) {
 				merged := c.mergeSymbol(moduleAugmentation.Symbol, mainModule, true /*unidirectional*/)
@@ -14208,6 +14208,7 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
 	// !!! The following only implements simple module resolution
 	sourceFile := c.program.GetResolvedModule(ast.GetSourceFileOfNode(location), moduleReference)
 	if sourceFile != nil {
+		// !!!
 		if sourceFile.Symbol != nil {
 			return c.getMergedSymbol(sourceFile.Symbol)
 		}
@@ -14216,9 +14217,29 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
 		}
 		return nil
 	}
-	if errorNode != nil && moduleNotFoundError != nil {
+
+	if len(c.patternAmbientModules) != 0 {
+		pattern := core.FindBestPatternMatch(c.patternAmbientModules, func(v *ast.PatternAmbientModule) core.Pattern { return v.Pattern }, moduleReference)
+		if pattern != nil {
+			augmentation := c.patternAmbientModuleAugmentations[moduleReference]
+			if augmentation != nil {
+				return c.getMergedSymbol(augmentation)
+			}
+			return c.getMergedSymbol(pattern.Symbol)
+		}
+	}
+
+	if errorNode == nil {
+		return nil
+	}
+
+	// !!!
+
+	if moduleNotFoundError != nil {
+		// !!!
 		c.error(errorNode, moduleNotFoundError, moduleReference)
 	}
+
 	return nil
 }
 
diff --git a/internal/compiler/module/resolver.go b/internal/compiler/module/resolver.go
index 380ccaf14..0ef1194f6 100644
--- a/internal/compiler/module/resolver.go
+++ b/internal/compiler/module/resolver.go
@@ -1775,7 +1775,7 @@ func matchPatternOrExact(patterns *parsedPatterns, candidate string) core.Patter
 	if len(patterns.patterns) == 0 {
 		return core.Pattern{}
 	}
-	return core.FindBestPatternMatch(patterns.patterns, candidate)
+	return core.FindBestPatternMatch(patterns.patterns, core.Identity, candidate)
 }
 
 // If you import from "." inside a containing directory "/foo", the result of `tspath.NormalizePath`
diff --git a/internal/core/pattern.go b/internal/core/pattern.go
index a082d1136..883dbe662 100644
--- a/internal/core/pattern.go
+++ b/internal/core/pattern.go
@@ -38,12 +38,13 @@ func (p *Pattern) MatchedText(candidate string) string {
 	return candidate[p.StarIndex : len(candidate)-len(p.Text)+p.StarIndex+1]
 }
 
-func FindBestPatternMatch(patterns []Pattern, candidate string) Pattern {
-	var bestPattern Pattern
+func FindBestPatternMatch[T any](values []T, getPattern func(v T) Pattern, candidate string) T {
+	var bestPattern T
 	longestMatchPrefixLength := -1
-	for _, pattern := range patterns {
+	for _, value := range values {
+		pattern := getPattern(value)
 		if (pattern.StarIndex == -1 || pattern.StarIndex > longestMatchPrefixLength) && pattern.Matches(candidate) {
-			bestPattern = pattern
+			bestPattern = value
 			longestMatchPrefixLength = pattern.StarIndex
 		}
 	}


Test patch:
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.errors.txt b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.errors.txt
deleted file mode 100644
index b3126661c..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.errors.txt
+++ /dev/null
@@ -1,42 +0,0 @@
-user.ts(2,24): error TS2307: Cannot find module 'foobarbaz' or its corresponding type declarations.
-user.ts(5,20): error TS2307: Cannot find module 'foosball' or its corresponding type declarations.
-user.ts(9,22): error TS2307: Cannot find module './file!text' or its corresponding type declarations.
-
-
-==== user.ts (3 errors) ====
-    ///<reference path="declarations.d.ts" />
-    import {foo, baz} from "foobarbaz";
-                           ~~~~~~~~~~~
-!!! error TS2307: Cannot find module 'foobarbaz' or its corresponding type declarations.
-    foo(baz);
-    
-    import {foos} from "foosball";
-                       ~~~~~~~~~~
-!!! error TS2307: Cannot find module 'foosball' or its corresponding type declarations.
-    foo(foos);
-    
-    // Works with relative file name
-    import fileText from "./file!text";
-                         ~~~~~~~~~~~~~
-!!! error TS2307: Cannot find module './file!text' or its corresponding type declarations.
-    foo(fileText);
-    
-==== declarations.d.ts (0 errors) ====
-    declare module "foo*baz" {
-        export function foo(s: string): void;
-    }
-    // Augmentations still work
-    declare module "foo*baz" {
-        export const baz: string;
-    }
-    
-    // Longest prefix wins
-    declare module "foos*" {
-        export const foos: string;
-    }
-    
-    declare module "*!text" {
-        const x: string;
-        export default x;
-    }
-    
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.errors.txt.diff
deleted file mode 100644
index ff2bbaaea..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.errors.txt.diff
+++ /dev/null
@@ -1,47 +0,0 @@
---- old.ambientDeclarationsPatterns.errors.txt
-+++ new.ambientDeclarationsPatterns.errors.txt
-@@= skipped -0, +-1 lines =@@
--<no content>
-@@= skipped --1, +1 lines =@@
-+user.ts(2,24): error TS2307: Cannot find module 'foobarbaz' or its corresponding type declarations.
-+user.ts(5,20): error TS2307: Cannot find module 'foosball' or its corresponding type declarations.
-+user.ts(9,22): error TS2307: Cannot find module './file!text' or its corresponding type declarations.
-+
-+
-+==== user.ts (3 errors) ====
-+    ///<reference path="declarations.d.ts" />
-+    import {foo, baz} from "foobarbaz";
-+                           ~~~~~~~~~~~
-+!!! error TS2307: Cannot find module 'foobarbaz' or its corresponding type declarations.
-+    foo(baz);
-+    
-+    import {foos} from "foosball";
-+                       ~~~~~~~~~~
-+!!! error TS2307: Cannot find module 'foosball' or its corresponding type declarations.
-+    foo(foos);
-+    
-+    // Works with relative file name
-+    import fileText from "./file!text";
-+                         ~~~~~~~~~~~~~
-+!!! error TS2307: Cannot find module './file!text' or its corresponding type declarations.
-+    foo(fileText);
-+    
-+==== declarations.d.ts (0 errors) ====
-+    declare module "foo*baz" {
-+        export function foo(s: string): void;
-+    }
-+    // Augmentations still work
-+    declare module "foo*baz" {
-+        export const baz: string;
-+    }
-+    
-+    // Longest prefix wins
-+    declare module "foos*" {
-+        export const foos: string;
-+    }
-+    
-+    declare module "*!text" {
-+        const x: string;
-+        export default x;
-+    }
-+    
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.types b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.types
index a06261d66..79fed70a9 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.types
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.types
@@ -3,30 +3,30 @@
 === user.ts ===
 ///<reference path="declarations.d.ts" />
 import {foo, baz} from "foobarbaz";
->foo : any
->baz : any
+>foo : (s: string) => void
+>baz : string
 
 foo(baz);
->foo(baz) : any
->foo : any
->baz : any
+>foo(baz) : void
+>foo : (s: string) => void
+>baz : string
 
 import {foos} from "foosball";
->foos : any
+>foos : string
 
 foo(foos);
->foo(foos) : any
->foo : any
->foos : any
+>foo(foos) : void
+>foo : (s: string) => void
+>foos : string
 
 // Works with relative file name
 import fileText from "./file!text";
->fileText : any
+>fileText : string
 
 foo(fileText);
->foo(fileText) : any
->foo : any
->fileText : any
+>foo(fileText) : void
+>foo : (s: string) => void
+>fileText : string
 
 === declarations.d.ts ===
 declare module "foo*baz" {
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.types.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.types.diff
deleted file mode 100644
index d235bacbe..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns.types.diff
+++ /dev/null
@@ -1,46 +0,0 @@
---- old.ambientDeclarationsPatterns.types
-+++ new.ambientDeclarationsPatterns.types
-@@= skipped -2, +2 lines =@@
- === user.ts ===
- ///<reference path="declarations.d.ts" />
- import {foo, baz} from "foobarbaz";
-->foo : (s: string) => void
-->baz : string
-+>foo : any
-+>baz : any
- 
- foo(baz);
-->foo(baz) : void
-->foo : (s: string) => void
-->baz : string
-+>foo(baz) : any
-+>foo : any
-+>baz : any
- 
- import {foos} from "foosball";
-->foos : string
-+>foos : any
- 
- foo(foos);
-->foo(foos) : void
-->foo : (s: string) => void
-->foos : string
-+>foo(foos) : any
-+>foo : any
-+>foos : any
- 
- // Works with relative file name
- import fileText from "./file!text";
-->fileText : string
-+>fileText : any
- 
- foo(fileText);
-->foo(fileText) : void
-->foo : (s: string) => void
-->fileText : string
-+>foo(fileText) : any
-+>foo : any
-+>fileText : any
- 
- === declarations.d.ts ===
- declare module "foo*baz" {
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.errors.txt b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.errors.txt
index 468a76283..fb1f34c02 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.errors.txt
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.errors.txt
@@ -1,6 +1,4 @@
-testA.ts(1,37): error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
-testA.ts(2,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-testB.ts(1,37): error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
+testB.ts(1,22): error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
 
 
 ==== types.ts (0 errors) ====
@@ -9,18 +7,14 @@ testB.ts(1,37): error TS2307: Cannot find module 'b.foo' or its corresponding ty
     }
     
     
-==== testA.ts (2 errors) ====
+==== testA.ts (0 errors) ====
     import { everywhere, onlyInA } from "a.foo";
-                                        ~~~~~~~
-!!! error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
     declare module "a.foo" {
-                   ~~~~~~~
-!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
       let onlyInA: number;
     }
     
 ==== testB.ts (1 errors) ====
     import { everywhere, onlyInA } from "b.foo"; // Error
-                                        ~~~~~~~
-!!! error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
+                         ~~~~~~~
+!!! error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
     
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.errors.txt.diff
deleted file mode 100644
index c5d0097c9..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.errors.txt.diff
+++ /dev/null
@@ -1,32 +0,0 @@
---- old.ambientDeclarationsPatterns_merging1.errors.txt
-+++ new.ambientDeclarationsPatterns_merging1.errors.txt
-@@= skipped -0, +0 lines =@@
--testB.ts(1,22): error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
-+testA.ts(1,37): error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
-+testA.ts(2,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-+testB.ts(1,37): error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
- 
- 
- ==== types.ts (0 errors) ====
-@@= skipped -6, +8 lines =@@
-     }
-     
-     
--==== testA.ts (0 errors) ====
-+==== testA.ts (2 errors) ====
-     import { everywhere, onlyInA } from "a.foo";
-+                                        ~~~~~~~
-+!!! error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
-     declare module "a.foo" {
-+                   ~~~~~~~
-+!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-       let onlyInA: number;
-     }
-     
- ==== testB.ts (1 errors) ====
-     import { everywhere, onlyInA } from "b.foo"; // Error
--                         ~~~~~~~
--!!! error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
-+                                        ~~~~~~~
-+!!! error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
-     
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.symbols b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.symbols
index 5a61e010f..c83976c66 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.symbols
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.symbols
@@ -15,7 +15,7 @@ import { everywhere, onlyInA } from "a.foo";
 >onlyInA : Symbol(onlyInA, Decl(testA.ts, 0, 20))
 
 declare module "a.foo" {
->"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 44))
+>"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 44), Decl(types.ts, 0, 0))
 
   let onlyInA: number;
 >onlyInA : Symbol(onlyInA, Decl(testA.ts, 2, 5))
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.symbols.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.symbols.diff
deleted file mode 100644
index b1fe1678b..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.symbols.diff
+++ /dev/null
@@ -1,11 +0,0 @@
---- old.ambientDeclarationsPatterns_merging1.symbols
-+++ new.ambientDeclarationsPatterns_merging1.symbols
-@@= skipped -14, +14 lines =@@
- >onlyInA : Symbol(onlyInA, Decl(testA.ts, 0, 20))
- 
- declare module "a.foo" {
-->"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 44), Decl(types.ts, 0, 0))
-+>"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 44))
- 
-   let onlyInA: number;
- >onlyInA : Symbol(onlyInA, Decl(testA.ts, 2, 5))
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.types b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.types
index c199426e7..29bca2435 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.types
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.types
@@ -11,8 +11,8 @@ declare module "*.foo" {
 
 === testA.ts ===
 import { everywhere, onlyInA } from "a.foo";
->everywhere : any
->onlyInA : any
+>everywhere : string
+>onlyInA : number
 
 declare module "a.foo" {
 >"a.foo" : typeof import("a.foo")
@@ -23,6 +23,6 @@ declare module "a.foo" {
 
 === testB.ts ===
 import { everywhere, onlyInA } from "b.foo"; // Error
->everywhere : any
+>everywhere : string
 >onlyInA : any
 
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.types.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.types.diff
deleted file mode 100644
index 478922b37..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging1.types.diff
+++ /dev/null
@@ -1,21 +0,0 @@
---- old.ambientDeclarationsPatterns_merging1.types
-+++ new.ambientDeclarationsPatterns_merging1.types
-@@= skipped -10, +10 lines =@@
- 
- === testA.ts ===
- import { everywhere, onlyInA } from "a.foo";
-->everywhere : string
-->onlyInA : number
-+>everywhere : any
-+>onlyInA : any
- 
- declare module "a.foo" {
- >"a.foo" : typeof import("a.foo")
-@@= skipped -12, +12 lines =@@
- 
- === testB.ts ===
- import { everywhere, onlyInA } from "b.foo"; // Error
-->everywhere : string
-+>everywhere : any
- >onlyInA : any
- 
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.errors.txt b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.errors.txt
index 4dee8c733..3ebb73ba0 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.errors.txt
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.errors.txt
@@ -1,7 +1,5 @@
-testA.ts(1,50): error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
-testA.ts(2,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-testB.ts(1,50): error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
-testB.ts(2,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
+testB.ts(1,22): error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
+testB.ts(1,31): error TS2305: Module '"*.foo"' has no exported member 'alsoOnlyInA'.
 
 
 ==== types.ts (0 errors) ====
@@ -10,22 +8,18 @@ testB.ts(2,16): error TS2664: Invalid module name in augmentation, module 'a.foo
     }
     
     
-==== testA.ts (2 errors) ====
+==== testA.ts (0 errors) ====
     import { everywhere, onlyInA, alsoOnlyInA } from "a.foo";
-                                                     ~~~~~~~
-!!! error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
     declare module "a.foo" {
-                   ~~~~~~~
-!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
       let onlyInA: number;
     }
     
 ==== testB.ts (2 errors) ====
     import { everywhere, onlyInA, alsoOnlyInA } from "b.foo"; // Error
-                                                     ~~~~~~~
-!!! error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
+                         ~~~~~~~
+!!! error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
+                                  ~~~~~~~~~~~
+!!! error TS2305: Module '"*.foo"' has no exported member 'alsoOnlyInA'.
     declare module "a.foo" {
-                   ~~~~~~~
-!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
       let alsoOnlyInA: number;
     }
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.errors.txt.diff
deleted file mode 100644
index 54dff49ef..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.errors.txt.diff
+++ /dev/null
@@ -1,40 +0,0 @@
---- old.ambientDeclarationsPatterns_merging2.errors.txt
-+++ new.ambientDeclarationsPatterns_merging2.errors.txt
-@@= skipped -0, +0 lines =@@
--testB.ts(1,22): error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
--testB.ts(1,31): error TS2305: Module '"*.foo"' has no exported member 'alsoOnlyInA'.
-+testA.ts(1,50): error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
-+testA.ts(2,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-+testB.ts(1,50): error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
-+testB.ts(2,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
- 
- 
- ==== types.ts (0 errors) ====
-@@= skipped -7, +9 lines =@@
-     }
-     
-     
--==== testA.ts (0 errors) ====
-+==== testA.ts (2 errors) ====
-     import { everywhere, onlyInA, alsoOnlyInA } from "a.foo";
-+                                                     ~~~~~~~
-+!!! error TS2307: Cannot find module 'a.foo' or its corresponding type declarations.
-     declare module "a.foo" {
-+                   ~~~~~~~
-+!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-       let onlyInA: number;
-     }
-     
- ==== testB.ts (2 errors) ====
-     import { everywhere, onlyInA, alsoOnlyInA } from "b.foo"; // Error
--                         ~~~~~~~
--!!! error TS2305: Module '"*.foo"' has no exported member 'onlyInA'.
--                                  ~~~~~~~~~~~
--!!! error TS2305: Module '"*.foo"' has no exported member 'alsoOnlyInA'.
-+                                                     ~~~~~~~
-+!!! error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
-     declare module "a.foo" {
-+                   ~~~~~~~
-+!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-       let alsoOnlyInA: number;
-     }
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.symbols b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.symbols
index 002052bf9..924967823 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.symbols
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.symbols
@@ -16,7 +16,7 @@ import { everywhere, onlyInA, alsoOnlyInA } from "a.foo";
 >alsoOnlyInA : Symbol(alsoOnlyInA, Decl(testA.ts, 0, 29))
 
 declare module "a.foo" {
->"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 57))
+>"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 57), Decl(types.ts, 0, 0), Decl(testB.ts, 0, 57))
 
   let onlyInA: number;
 >onlyInA : Symbol(onlyInA, Decl(testA.ts, 2, 5))
@@ -29,7 +29,7 @@ import { everywhere, onlyInA, alsoOnlyInA } from "b.foo"; // Error
 >alsoOnlyInA : Symbol(alsoOnlyInA, Decl(testB.ts, 0, 29))
 
 declare module "a.foo" {
->"a.foo" : Symbol("a.foo", Decl(testB.ts, 0, 57))
+>"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 57), Decl(types.ts, 0, 0), Decl(testB.ts, 0, 57))
 
   let alsoOnlyInA: number;
 >alsoOnlyInA : Symbol(alsoOnlyInA, Decl(testB.ts, 2, 5))
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.symbols.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.symbols.diff
deleted file mode 100644
index bcd3a62ab..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.symbols.diff
+++ /dev/null
@@ -1,20 +0,0 @@
---- old.ambientDeclarationsPatterns_merging2.symbols
-+++ new.ambientDeclarationsPatterns_merging2.symbols
-@@= skipped -15, +15 lines =@@
- >alsoOnlyInA : Symbol(alsoOnlyInA, Decl(testA.ts, 0, 29))
- 
- declare module "a.foo" {
-->"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 57), Decl(types.ts, 0, 0), Decl(testB.ts, 0, 57))
-+>"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 57))
- 
-   let onlyInA: number;
- >onlyInA : Symbol(onlyInA, Decl(testA.ts, 2, 5))
-@@= skipped -13, +13 lines =@@
- >alsoOnlyInA : Symbol(alsoOnlyInA, Decl(testB.ts, 0, 29))
- 
- declare module "a.foo" {
-->"a.foo" : Symbol("a.foo", Decl(testA.ts, 0, 57), Decl(types.ts, 0, 0), Decl(testB.ts, 0, 57))
-+>"a.foo" : Symbol("a.foo", Decl(testB.ts, 0, 57))
- 
-   let alsoOnlyInA: number;
- >alsoOnlyInA : Symbol(alsoOnlyInA, Decl(testB.ts, 2, 5))
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.types b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.types
index cc1e4c34e..e044aff6b 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.types
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.types
@@ -11,9 +11,9 @@ declare module "*.foo" {
 
 === testA.ts ===
 import { everywhere, onlyInA, alsoOnlyInA } from "a.foo";
->everywhere : any
->onlyInA : any
->alsoOnlyInA : any
+>everywhere : string
+>onlyInA : number
+>alsoOnlyInA : number
 
 declare module "a.foo" {
 >"a.foo" : typeof import("a.foo")
@@ -24,7 +24,7 @@ declare module "a.foo" {
 
 === testB.ts ===
 import { everywhere, onlyInA, alsoOnlyInA } from "b.foo"; // Error
->everywhere : any
+>everywhere : string
 >onlyInA : any
 >alsoOnlyInA : any
 
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.types.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.types.diff
deleted file mode 100644
index d49ba1002..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging2.types.diff
+++ /dev/null
@@ -1,24 +0,0 @@
---- old.ambientDeclarationsPatterns_merging2.types
-+++ new.ambientDeclarationsPatterns_merging2.types
-@@= skipped -10, +10 lines =@@
- 
- === testA.ts ===
- import { everywhere, onlyInA, alsoOnlyInA } from "a.foo";
-->everywhere : string
-->onlyInA : number
-->alsoOnlyInA : number
-+>everywhere : any
-+>onlyInA : any
-+>alsoOnlyInA : any
- 
- declare module "a.foo" {
- >"a.foo" : typeof import("a.foo")
-@@= skipped -13, +13 lines =@@
- 
- === testB.ts ===
- import { everywhere, onlyInA, alsoOnlyInA } from "b.foo"; // Error
-->everywhere : string
-+>everywhere : any
- >onlyInA : any
- >alsoOnlyInA : any
- 
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.errors.txt b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.errors.txt
index 692249c74..78ed9d816 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.errors.txt
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.errors.txt
@@ -1,5 +1,4 @@
-test.ts(1,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-test.ts(4,22): error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
+test.ts(6,6): error TS2339: Property 'a' does not exist on type 'OhNo'.
 
 
 ==== types.ts (0 errors) ====
@@ -7,15 +6,13 @@ test.ts(4,22): error TS2307: Cannot find module 'b.foo' or its corresponding typ
       export interface OhNo { star: string }
     }
     
-==== test.ts (2 errors) ====
+==== test.ts (1 errors) ====
     declare module "a.foo" {
-                   ~~~~~~~
-!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
       export interface OhNo { a: string }
     }
     import { OhNo } from "b.foo"
-                         ~~~~~~~
-!!! error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
     declare let ohno: OhNo;
     ohno.a // oh no
+         ~
+!!! error TS2339: Property 'a' does not exist on type 'OhNo'.
     
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.errors.txt.diff
deleted file mode 100644
index 9e4bd5c7e..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.errors.txt.diff
+++ /dev/null
@@ -1,28 +0,0 @@
---- old.ambientDeclarationsPatterns_merging3.errors.txt
-+++ new.ambientDeclarationsPatterns_merging3.errors.txt
-@@= skipped -0, +0 lines =@@
--test.ts(6,6): error TS2339: Property 'a' does not exist on type 'OhNo'.
-+test.ts(1,16): error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-+test.ts(4,22): error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
- 
- 
- ==== types.ts (0 errors) ====
-@@= skipped -5, +6 lines =@@
-       export interface OhNo { star: string }
-     }
-     
--==== test.ts (1 errors) ====
-+==== test.ts (2 errors) ====
-     declare module "a.foo" {
-+                   ~~~~~~~
-+!!! error TS2664: Invalid module name in augmentation, module 'a.foo' cannot be found.
-       export interface OhNo { a: string }
-     }
-     import { OhNo } from "b.foo"
-+                         ~~~~~~~
-+!!! error TS2307: Cannot find module 'b.foo' or its corresponding type declarations.
-     declare let ohno: OhNo;
-     ohno.a // oh no
--         ~
--!!! error TS2339: Property 'a' does not exist on type 'OhNo'.
-     
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols
index 01315d669..a4a90e305 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols
@@ -11,10 +11,10 @@ declare module "*.foo" {
 
 === test.ts ===
 declare module "a.foo" {
->"a.foo" : Symbol("a.foo", Decl(test.ts, 0, 0))
+>"a.foo" : Symbol("*.foo", Decl(test.ts, 0, 0), Decl(types.ts, 0, 0))
 
   export interface OhNo { a: string }
->OhNo : Symbol(OhNo, Decl(test.ts, 0, 24))
+>OhNo : Symbol(OhNo, Decl(test.ts, 0, 24), Decl(types.ts, 0, 24))
 >a : Symbol(a, Decl(test.ts, 1, 25))
 }
 import { OhNo } from "b.foo"
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols.diff
index 991943017..357ed3037 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols.diff
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.symbols.diff
@@ -11,12 +11,11 @@
  === test.ts ===
  declare module "a.foo" {
 ->"a.foo" : Symbol("a.foo", Decl(test.ts, 0, 0), Decl(types.ts, 0, 0))
-+>"a.foo" : Symbol("a.foo", Decl(test.ts, 0, 0))
++>"a.foo" : Symbol("*.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))
+ >OhNo : Symbol(OhNo, Decl(test.ts, 0, 24), Decl(types.ts, 0, 24))
 ->a : Symbol(OhNo.a, Decl(test.ts, 1, 25))
-+>OhNo : Symbol(OhNo, Decl(test.ts, 0, 24))
 +>a : Symbol(a, Decl(test.ts, 1, 25))
  }
  import { OhNo } from "b.foo"
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.types b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.types
index 1bd141fff..94a9ba9ce 100644
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.types
+++ b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.types
@@ -10,7 +10,7 @@ declare module "*.foo" {
 
 === test.ts ===
 declare module "a.foo" {
->"a.foo" : any
+>"a.foo" : typeof import("a.foo")
 
   export interface OhNo { a: string }
 >a : string
diff --git a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.types.diff b/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.types.diff
deleted file mode 100644
index 5220474f2..000000000
--- a/testdata/baselines/reference/submodule/conformance/ambientDeclarationsPatterns_merging3.types.diff
+++ /dev/null
@@ -1,11 +0,0 @@
---- old.ambientDeclarationsPatterns_merging3.types
-+++ new.ambientDeclarationsPatterns_merging3.types
-@@= skipped -9, +9 lines =@@
- 
- === test.ts ===
- declare module "a.foo" {
-->"a.foo" : typeof import("a.foo")
-+>"a.foo" : any
- 
-   export interface OhNo { a: string }
- >a : string