■ ■ ■ ■ ■ ■
new/language/implementation/javascript/javascript.go
1 | 1 | | package javascript |
2 | 2 | | |
3 | 3 | | import ( |
4 | | - | "errors" |
5 | 4 | | "fmt" |
6 | 5 | | "regexp" |
7 | 6 | | "strings" |
8 | 7 | | |
9 | | - | "github.com/smacker/go-tree-sitter/javascript" |
10 | 8 | | "github.com/ssoroka/slice" |
11 | 9 | | "golang.org/x/exp/slices" |
12 | 10 | | |
| skipped 3 lines |
16 | 14 | | |
17 | 15 | | patternquerytypes "github.com/bearer/bearer/new/language/patternquery/types" |
18 | 16 | | sitter "github.com/smacker/go-tree-sitter" |
| 17 | + | "github.com/smacker/go-tree-sitter/typescript/tsx" |
19 | 18 | | ) |
20 | 19 | | |
21 | 20 | | var ( |
| skipped 6 lines |
28 | 27 | | } |
29 | 28 | | |
30 | 29 | | anonymousPatternNodeParentTypes = []string{} |
31 | | - | patternMatchNodeContainerTypes = []string{} |
| 30 | + | patternMatchNodeContainerTypes = []string{"required_parameter"} |
32 | 31 | | |
33 | 32 | | // $<name:type> or $<name:type1|type2> or $<name> |
34 | 33 | | patternQueryVariableRegex = regexp.MustCompile(`\$<(?P<name>[^>:!\.]+)(?::(?P<types>[^>]+))?>`) |
| skipped 11 lines |
46 | 45 | | } |
47 | 46 | | |
48 | 47 | | func (implementation *javascriptImplementation) SitterLanguage() *sitter.Language { |
49 | | - | return javascript.GetLanguage() |
| 48 | + | return tsx.GetLanguage() |
50 | 49 | | } |
51 | 50 | | |
52 | 51 | | func (*javascriptImplementation) AnalyzeFlow(rootNode *tree.Node) error { |
| skipped 57 lines |
110 | 109 | | } |
111 | 110 | | } |
112 | 111 | | |
113 | | - | if parent.Type() == "formal_parameters" { |
| 112 | + | // typescript: different type of identifier |
| 113 | + | if parent.Type() == "required_parameter" { |
114 | 114 | | scope.Assign(node.Content(), node) |
| 115 | + | |
115 | 116 | | } |
116 | 117 | | case "property_identifier": |
117 | 118 | | parent := node.Parent() |
| skipped 48 lines |
166 | 167 | | return replaced, params, nil |
167 | 168 | | } |
168 | 169 | | |
169 | | - | // TODO: See if anything needs to be added here |
170 | | - | func (implementation *javascriptImplementation) ExtractPatternMatchNode(input string) (string, int, error) { |
171 | | - | inputBytes := []byte(input) |
172 | | - | matches := matchNodeRegex.FindAllIndex(inputBytes, -1) |
173 | | - | |
174 | | - | if len(matches) == 0 { |
175 | | - | return input, 0, nil |
176 | | - | } |
177 | | - | |
178 | | - | if len(matches) > 1 { |
179 | | - | return "", 0, errors.New("pattern must only contain a single match node") |
180 | | - | } |
181 | | - | |
182 | | - | match := matches[0] |
183 | | - | return string(inputBytes[0:match[0]]) + string(inputBytes[match[1]:]), match[0], nil |
184 | | - | } |
185 | | - | |
186 | 170 | | func produceDummyValue(i int, nodeType string) string { |
187 | 171 | | return "CurioVar" + fmt.Sprint(i) |
188 | 172 | | } |
| skipped 13 lines |
202 | 186 | | return ellipsisRegex.FindAllIndex(input, -1) |
203 | 187 | | } |
204 | 188 | | |
205 | | - | // TODO: See if anything needs to be added here |
206 | | - | func (implementation *javascriptImplementation) IsTerminalDetectionNode(node *tree.Node) bool { |
207 | | - | return false |
| 189 | + | func (implementation *javascriptImplementation) PatternMatchNodeContainerTypes() []string { |
| 190 | + | return patternMatchNodeContainerTypes |
208 | 191 | | } |
209 | 192 | | |
210 | | - | func (implementation *javascriptImplementation) PatternMatchNodeContainerTypes() []string { |
211 | | - | return patternMatchNodeContainerTypes |
| 193 | + | func (javascriptImplementation *javascriptImplementation) ShouldSkipNode(node *tree.Node) bool { |
| 194 | + | return node.Type() == "required_parameter" |
212 | 195 | | } |
213 | 196 | | |
214 | 197 | | func (*javascriptImplementation) PatternLeafContentTypes() []string { |
| skipped 1 lines |
216 | 199 | | // identifiers |
217 | 200 | | "identifier", "property_identifier", "shorthand_property_identifier", |
218 | 201 | | // datatypes/literals |
219 | | - | "template_string", "string", "number", "null", "true", "false", |
| 202 | + | "template_string", "string_fragment", "number", "null", "true", "false", |
220 | 203 | | } |
221 | 204 | | } |
222 | 205 | | |
| skipped 40 lines |