MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getModuleInstanceStateForAliasTarget

Function getModuleInstanceStateForAliasTarget

internal/ast/utilities.go:2387–2422  ·  view source on GitHub ↗
(node *Node, ancestors []*Node, visited map[NodeId]ModuleInstanceState)

Source from the content-addressed store, hash-verified

2385}
2386
2387func getModuleInstanceStateForAliasTarget(node *Node, ancestors []*Node, visited map[NodeId]ModuleInstanceState) ModuleInstanceState {
2388 name := node.PropertyNameOrName()
2389 if name.Kind != KindIdentifier {
2390 // Skip for invalid syntax like this: export { "x" }
2391 return ModuleInstanceStateInstantiated
2392 }
2393 for ancestors, p := popAncestor(ancestors, node); p != nil; ancestors, p = popAncestor(ancestors, p) {
2394 if IsBlock(p) || IsModuleBlock(p) || IsSourceFile(p) {
2395 found := ModuleInstanceStateUnknown
2396 statementsAncestors := pushAncestor(ancestors, p)
2397 for _, statement := range p.Statements() {
2398 if NodeHasName(statement, name) {
2399 state := getModuleInstanceStateCached(statement, statementsAncestors, visited)
2400 if found == ModuleInstanceStateUnknown || state > found {
2401 found = state
2402 }
2403 if found == ModuleInstanceStateInstantiated {
2404 return found
2405 }
2406 if statement.Kind == KindImportEqualsDeclaration {
2407 // Treat re-exports of import aliases as instantiated since they're ambiguous. This is consistent
2408 // with `export import x = mod.x` being treated as instantiated:
2409 // import x = mod.x;
2410 // export { x };
2411 found = ModuleInstanceStateInstantiated
2412 }
2413 }
2414 }
2415 if found != ModuleInstanceStateUnknown {
2416 return found
2417 }
2418 }
2419 }
2420 // Couldn't locate, assume could refer to a value
2421 return ModuleInstanceStateInstantiated
2422}
2423
2424func IsInstantiatedModule(node *Node, preserveConstEnums bool) bool {
2425 moduleState := GetModuleInstanceState(node)

Callers 1

Calls 9

popAncestorFunction · 0.85
IsBlockFunction · 0.85
IsModuleBlockFunction · 0.85
IsSourceFileFunction · 0.85
pushAncestorFunction · 0.85
NodeHasNameFunction · 0.85
PropertyNameOrNameMethod · 0.80
StatementsMethod · 0.80

Tested by

no test coverage detected