MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / findLayerModuleName

Function findLayerModuleName

internal/layergraph/extract.go:364–412  ·  view source on GitHub ↗

findLayerModuleName resolves the imported identifier name for the "Layer" export from the "effect" package. Falls back to "Layer" if not found.

(sf *ast.SourceFile)

Source from the content-addressed store, hash-verified

362// findLayerModuleName resolves the imported identifier name for the "Layer" export
363// from the "effect" package. Falls back to "Layer" if not found.
364func findLayerModuleName(sf *ast.SourceFile) string {
365 if sf == nil {
366 return "Layer"
367 }
368 for _, stmt := range sf.Statements.Nodes {
369 if stmt.Kind != ast.KindImportDeclaration {
370 continue
371 }
372 importDecl := stmt.AsImportDeclaration()
373 if importDecl.ModuleSpecifier == nil {
374 continue
375 }
376 moduleName := scanner.GetTextOfNode(importDecl.ModuleSpecifier)
377 // Strip quotes from module specifier.
378 if len(moduleName) >= 2 && (moduleName[0] == '"' || moduleName[0] == '\'') {
379 moduleName = moduleName[1 : len(moduleName)-1]
380 }
381 if moduleName != "effect" {
382 continue
383 }
384 // Look for named imports.
385 if importDecl.ImportClause == nil {
386 continue
387 }
388 clause := importDecl.ImportClause.AsImportClause()
389 if clause.NamedBindings == nil || clause.NamedBindings.Kind != ast.KindNamedImports {
390 continue
391 }
392 namedImports := clause.NamedBindings.AsNamedImports()
393 if namedImports.Elements == nil {
394 continue
395 }
396 for _, elem := range namedImports.Elements.Nodes {
397 spec := elem.AsImportSpecifier()
398 // The "real" name is PropertyName if set (import { Layer as X }),
399 // otherwise Name.
400 importedName := ""
401 if spec.PropertyName != nil {
402 importedName = scanner.GetTextOfNode(spec.PropertyName)
403 } else {
404 importedName = scanner.GetTextOfNode(spec.Name())
405 }
406 if importedName == "Layer" {
407 return scanner.GetTextOfNode(spec.Name())
408 }
409 }
410 }
411 return "Layer"
412}
413
414// collectChildIndices gathers graph node indices for the given AST nodes,
415// filtering out nodes that aren't in the graph.

Callers 1

ExtractLayerGraphFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected