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

Function getModuleInstanceStateWorker

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

Source from the content-addressed store, hash-verified

2331}
2332
2333func getModuleInstanceStateWorker(node *Node, ancestors []*Node, visited map[NodeId]ModuleInstanceState) ModuleInstanceState {
2334 // A module is uninstantiated if it contains only
2335 switch node.Kind {
2336 case KindInterfaceDeclaration, KindTypeAliasDeclaration, KindJSTypeAliasDeclaration:
2337 return ModuleInstanceStateNonInstantiated
2338 case KindEnumDeclaration:
2339 if IsEnumConst(node) {
2340 return ModuleInstanceStateConstEnumOnly
2341 }
2342 case KindImportDeclaration, KindJSImportDeclaration, KindImportEqualsDeclaration:
2343 if !HasSyntacticModifier(node, ModifierFlagsExport) {
2344 return ModuleInstanceStateNonInstantiated
2345 }
2346 case KindExportDeclaration:
2347 decl := node.AsExportDeclaration()
2348 if decl.ModuleSpecifier == nil && decl.ExportClause != nil && decl.ExportClause.Kind == KindNamedExports {
2349 state := ModuleInstanceStateNonInstantiated
2350 ancestors = pushAncestor(ancestors, node)
2351 ancestors = pushAncestor(ancestors, decl.ExportClause)
2352 for _, specifier := range decl.ExportClause.Elements() {
2353 specifierState := getModuleInstanceStateForAliasTarget(specifier, ancestors, visited)
2354 if specifierState > state {
2355 state = specifierState
2356 }
2357 if state == ModuleInstanceStateInstantiated {
2358 return state
2359 }
2360 }
2361 return state
2362 }
2363 case KindModuleBlock:
2364 state := ModuleInstanceStateNonInstantiated
2365 ancestors = pushAncestor(ancestors, node)
2366 node.ForEachChild(func(n *Node) bool {
2367 childState := getModuleInstanceStateCached(n, ancestors, visited)
2368 switch childState {
2369 case ModuleInstanceStateNonInstantiated:
2370 return false
2371 case ModuleInstanceStateConstEnumOnly:
2372 state = ModuleInstanceStateConstEnumOnly
2373 return false
2374 case ModuleInstanceStateInstantiated:
2375 state = ModuleInstanceStateInstantiated
2376 return true
2377 }
2378 panic("Unhandled case in getModuleInstanceStateWorker")
2379 })
2380 return state
2381 case KindModuleDeclaration:
2382 return getModuleInstanceState(node, ancestors, visited)
2383 }
2384 return ModuleInstanceStateInstantiated
2385}
2386
2387func getModuleInstanceStateForAliasTarget(node *Node, ancestors []*Node, visited map[NodeId]ModuleInstanceState) ModuleInstanceState {
2388 name := node.PropertyNameOrName()

Callers 1

Calls 10

IsEnumConstFunction · 0.85
HasSyntacticModifierFunction · 0.85
pushAncestorFunction · 0.85
panicFunction · 0.85
getModuleInstanceStateFunction · 0.85
AsExportDeclarationMethod · 0.80
ForEachChildMethod · 0.65
ElementsMethod · 0.45

Tested by

no test coverage detected