Skip to content

Commit d40d5e1

Browse files
committed
merge symbol fix
1 parent a11c0f7 commit d40d5e1

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

internal/ast/symbol.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package ast
22

33
import (
4+
"fmt"
45
"iter"
56
"maps"
7+
"os"
68
"strings"
79
"sync/atomic"
810

@@ -394,6 +396,7 @@ func (c *DenoForkContext) GetGlobalsForName(name string) SymbolTable {
394396
}
395397

396398
func isTypesNodePkgPath(path tspath.Path) bool {
399+
fmt.Fprintf(os.Stderr, "isTypesNodePkgPath %s\n", path)
397400
return strings.HasSuffix(string(path), ".d.ts") && strings.Contains(string(path), "/@types/node/")
398401
}
399402

@@ -411,6 +414,14 @@ func symbolHasAnyTypesNodePkgDecl(symbol *Symbol, hasNodeSourceFile func(*Node)
411414
}
412415

413416
func (c *DenoForkContext) MergeGlobalSymbolTable(node *Node, source SymbolTable, unidirectional bool) {
417+
name := ""
418+
if node != nil {
419+
decl := node.Name()
420+
if decl != nil {
421+
name = decl.Text()
422+
}
423+
}
424+
fmt.Fprintf(os.Stderr, "MergeGlobalSymbolTable %s\n", name)
414425
sourceFile := GetSourceFileOfNode(node)
415426
isNodeFile := c.HasNodeSourceFile(node)
416427
isTypesNodeSourceFile := isNodeFile && isTypesNodePkgPath(sourceFile.Path())
@@ -423,10 +434,18 @@ func (c *DenoForkContext) MergeGlobalSymbolTable(node *Node, source SymbolTable,
423434
target = c.globals
424435
}
425436
targetSymbol := target.Get(id)
437+
if isTypesNodeSourceFile {
438+
fmt.Fprintf(os.Stderr, "isTypesNodeSourceFile %s\n", id)
439+
}
426440
if isTypesNodeSourceFile && targetSymbol != nil && TypesNodeIgnorableNames.Has(id) && !symbolHasAnyTypesNodePkgDecl(targetSymbol, c.HasNodeSourceFile) {
441+
fmt.Fprintf(os.Stderr, "ignoring %s\n", id)
427442
continue
428443
}
429-
target.Set(id, sourceSymbol)
444+
sym := sourceSymbol
445+
if targetSymbol != nil {
446+
sym = c.mergeSymbol(targetSymbol, sourceSymbol, unidirectional)
447+
}
448+
target.Set(id, sym)
430449
}
431450
}
432451

0 commit comments

Comments
 (0)