11package ast
22
33import (
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
396398func 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
413416func (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