|
1 | 1 | package compiler
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "encoding/json" |
5 | 4 | "fmt"
|
6 | 5 | "slices"
|
7 | 6 | "strings"
|
@@ -179,11 +178,8 @@ func (p *Program) startParseTask(fileName string, wg *core.WorkGroup) {
|
179 | 178 | }
|
180 | 179 |
|
181 | 180 | func (p *Program) getResolvedModule(currentSourceFile *ast.SourceFile, moduleReference string) *ast.SourceFile {
|
182 |
| - directory := tspath.GetDirectoryPath(currentSourceFile.FileName()) |
183 |
| - if tspath.IsExternalModuleNameRelative(moduleReference) { |
184 |
| - return p.findSourceFile(tspath.CombinePaths(directory, moduleReference), FileIncludeReason{FileIncludeKindImport, 0}) |
185 |
| - } |
186 |
| - return p.findNodeModule(moduleReference) |
| 181 | + resolved := p.resolver.ResolveModuleName(moduleReference, currentSourceFile.FileName(), core.ModuleKindNodeNext, nil) |
| 182 | + return p.findSourceFile(resolved.ResolvedFileName, FileIncludeReason{FileIncludeKindImport, 0}) |
187 | 183 | }
|
188 | 184 |
|
189 | 185 | func (p *Program) findSourceFile(candidate string, reason FileIncludeReason) *ast.SourceFile {
|
@@ -262,38 +258,6 @@ func (p *Program) resolveImportsAndModuleAugmentations(file *ast.SourceFile) []s
|
262 | 258 | return toParse
|
263 | 259 | }
|
264 | 260 |
|
265 |
| -func (p *Program) findNodeModule(moduleReference string) *ast.SourceFile { |
266 |
| - if p.nodeModules == nil { |
267 |
| - p.nodeModules = make(map[string]*ast.SourceFile) |
268 |
| - } |
269 |
| - if sourceFile, ok := p.nodeModules[moduleReference]; ok { |
270 |
| - return sourceFile |
271 |
| - } |
272 |
| - sourceFile := p.tryLoadNodeModule(tspath.CombinePaths(p.rootPath, "node_modules", moduleReference)) |
273 |
| - if sourceFile == nil { |
274 |
| - sourceFile = p.tryLoadNodeModule(tspath.CombinePaths(p.rootPath, "node_modules/@types", moduleReference)) |
275 |
| - } |
276 |
| - p.nodeModules[moduleReference] = sourceFile |
277 |
| - return sourceFile |
278 |
| -} |
279 |
| - |
280 |
| -func (p *Program) tryLoadNodeModule(modulePath string) *ast.SourceFile { |
281 |
| - if packageJson, ok := p.host.FS().ReadFile(tspath.CombinePaths(modulePath, "package.json")); ok { |
282 |
| - var jsonMap map[string]any |
283 |
| - if json.Unmarshal([]byte(packageJson), &jsonMap) == nil { |
284 |
| - typesValue := jsonMap["types"] |
285 |
| - if typesValue == nil { |
286 |
| - typesValue = jsonMap["typings"] |
287 |
| - } |
288 |
| - if fileName, ok := typesValue.(string); ok { |
289 |
| - path := tspath.CombinePaths(modulePath, fileName) |
290 |
| - return p.filesByPath[tspath.ToPath(path, p.host.GetCurrentDirectory(), p.host.FS().UseCaseSensitiveFileNames())] |
291 |
| - } |
292 |
| - } |
293 |
| - } |
294 |
| - return nil |
295 |
| -} |
296 |
| - |
297 | 261 | func (p *Program) GetSyntacticDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
|
298 | 262 | return p.getDiagnosticsHelper(sourceFile, false /*ensureBound*/, p.getSyntaticDiagnosticsForFile)
|
299 | 263 | }
|
|
0 commit comments