NewAnalyzer accepts a slice of bytes representing some JavaScript source code and returns a pointer to a new Analyzer
(source []byte)
| 21 | // NewAnalyzer accepts a slice of bytes representing some JavaScript |
| 22 | // source code and returns a pointer to a new Analyzer |
| 23 | func NewAnalyzer(source []byte) *Analyzer { |
| 24 | parser := sitter.NewParser() |
| 25 | |
| 26 | parser.SetLanguage(javascript.GetLanguage()) |
| 27 | |
| 28 | if isProbablyHTML(source) { |
| 29 | source = extractInlineJS(source) |
| 30 | } |
| 31 | |
| 32 | tree := parser.Parse(nil, source) |
| 33 | |
| 34 | // TODO: Align how URLMatcher and SecretMatcher slices |
| 35 | // are loaded. At the moment we load URLMatchers now, |
| 36 | // and SecretMatchers only when GetSecrets is called. |
| 37 | // This is mostly because URL matching was written first, |
| 38 | // and then secret matching was added later. |
| 39 | return &Analyzer{ |
| 40 | urlMatchers: AllURLMatchers(), |
| 41 | rootNode: NewNode(tree.RootNode(), source), |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Query peforms a tree-sitter query on the JavaScript being analyzed. |
| 46 | // The provided function is called once for every node that captured by the query. |