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

Function AnalyzeExtendsNativeError

internal/rules/extends_native_error.go:36–65  ·  view source on GitHub ↗
(tp *typeparser.TypeParser, c *checker.Checker, sf *ast.SourceFile)

Source from the content-addressed store, hash-verified

34}
35
36func AnalyzeExtendsNativeError(tp *typeparser.TypeParser, c *checker.Checker, sf *ast.SourceFile) []ExtendsNativeErrorMatch {
37 errorSymbol := c.ResolveName("Error", nil, ast.SymbolFlagsType, false)
38 if errorSymbol == nil {
39 return nil
40 }
41
42 var matches []ExtendsNativeErrorMatch
43
44 nodeToVisit := make([]*ast.Node, 0)
45 pushChild := func(child *ast.Node) bool {
46 nodeToVisit = append(nodeToVisit, child)
47 return false
48 }
49 sf.AsNode().ForEachChild(pushChild)
50
51 for len(nodeToVisit) > 0 {
52 node := nodeToVisit[len(nodeToVisit)-1]
53 nodeToVisit = nodeToVisit[:len(nodeToVisit)-1]
54
55 if node.Kind == ast.KindClassDeclaration {
56 if m := checkExtendsNativeError(tp, c, sf, node, errorSymbol); m != nil {
57 matches = append(matches, *m)
58 }
59 }
60
61 node.ForEachChild(pushChild)
62 }
63
64 return matches
65}
66
67func checkExtendsNativeError(tp *typeparser.TypeParser, c *checker.Checker, sf *ast.SourceFile, node *ast.Node, errorSymbol *ast.Symbol) *ExtendsNativeErrorMatch {
68 extendsElements := ast.GetExtendsHeritageClauseElements(node)

Callers 1

Calls 1

checkExtendsNativeErrorFunction · 0.85

Tested by

no test coverage detected