Skip to content

Commit bc87faf

Browse files
committed
Only include asset:///lib.node.d.ts when no @types/node package exists
1 parent 1193afc commit bc87faf

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

internal/ast/symbol.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package ast
33
import (
44
"iter"
55
"maps"
6-
"strings"
76
"sync/atomic"
87

98
"github.com/microsoft/typescript-go/internal/collections"
9+
"github.com/microsoft/typescript-go/internal/deno"
1010
"github.com/microsoft/typescript-go/internal/tspath"
1111
)
1212

@@ -350,17 +350,13 @@ func (c *DenoForkContext) GetGlobalsForName(name string) SymbolTable {
350350
}
351351
}
352352

353-
func isTypesNodePkgPath(path tspath.Path) bool {
354-
return strings.HasSuffix(string(path), ".d.ts") && strings.Contains(string(path), "/@types/node/")
355-
}
356-
357353
func symbolHasAnyTypesNodePkgDecl(symbol *Symbol, hasNodeSourceFile func(*Node) bool) bool {
358354
if symbol == nil || symbol.Declarations == nil {
359355
return false
360356
}
361357
for _, decl := range symbol.Declarations {
362358
sourceFile := GetSourceFileOfNode(decl)
363-
if sourceFile != nil && hasNodeSourceFile(decl) && isTypesNodePkgPath(sourceFile.Path()) {
359+
if sourceFile != nil && hasNodeSourceFile(decl) && deno.IsTypesNodePkgPath(sourceFile.Path()) {
364360
return true
365361
}
366362
}
@@ -370,7 +366,7 @@ func symbolHasAnyTypesNodePkgDecl(symbol *Symbol, hasNodeSourceFile func(*Node)
370366
func (c *DenoForkContext) MergeGlobalSymbolTable(node *Node, source SymbolTable, unidirectional bool) {
371367
sourceFile := GetSourceFileOfNode(node)
372368
isNodeFile := c.HasNodeSourceFile(node)
373-
isTypesNodeSourceFile := isNodeFile && isTypesNodePkgPath(sourceFile.Path())
369+
isTypesNodeSourceFile := isNodeFile && deno.IsTypesNodePkgPath(sourceFile.Path())
374370

375371
for id, sourceSymbol := range source.Iter() {
376372
var target SymbolTable

internal/compiler/fileloader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func processAllProgramFiles(
104104
}
105105
loader.addProjectReferenceTasks(singleThreaded)
106106
loader.resolver = loader.opts.Host.MakeResolver(loader.projectReferenceFileMapper.host, compilerOptions, opts.TypingsLocation, opts.ProjectName)
107+
hadTypesNode := false
107108
for index, rootFile := range rootFiles {
108109
loader.addRootTask(rootFile, nil, &FileIncludeReason{kind: fileIncludeKindRootFile, data: index})
109110
}
@@ -117,6 +118,12 @@ func processAllProgramFiles(
117118
for index, lib := range compilerOptions.Lib {
118119
if name, ok := tsoptions.GetLibFileName(lib); ok {
119120
libFile := loader.pathForLibFile(name)
121+
// deno: we skip loading the lib.node.d.ts file if the @types/node package has been loaded
122+
// so defer loading this until after everything else
123+
if libFile.path == "asset:///lib.node.d.ts" {
124+
hadTypesNode = true
125+
continue
126+
}
120127
loader.addRootTask(libFile.path, libFile, &FileIncludeReason{kind: fileIncludeKindLibFile, data: index})
121128
}
122129
// !!! error on unknown name

internal/deno/deno.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package deno
2+
3+
import (
4+
"strings"
5+
6+
"github.com/microsoft/typescript-go/internal/tspath"
7+
)
8+
9+
func IsTypesNodePkgPath(path tspath.Path) bool {
10+
return strings.HasSuffix(string(path), ".d.ts") && strings.Contains(string(path), "/@types/node/")
11+
}

0 commit comments

Comments
 (0)