MCPcopy
hub / github.com/BishopFox/jsluice / CollapsedString

Method CollapsedString

tree.go:179–195  ·  view source on GitHub ↗

CollapsedString takes a node representing a URL and attempts to make it at least somewhat easily parseable. It's common to build URLs out of variables and function calls so we want to turn something like: './upload.php?profile='+res.id+'&show='+$('.participate_modal_container').attr('data-val') In

()

Source from the content-addressed store, hash-verified

177//
178// The value of ExpressionPlaceholder is used as a placeholder, defaulting to 'EXPR'
179func (n *Node) CollapsedString() string {
180 if !n.IsValid() {
181 return ""
182 }
183 switch n.Type() {
184 case "binary_expression":
185 return fmt.Sprintf(
186 "%s%s",
187 n.ChildByFieldName("left").CollapsedString(),
188 n.ChildByFieldName("right").CollapsedString(),
189 )
190 case "string":
191 return n.RawString()
192 default:
193 return ExpressionPlaceholder
194 }
195}
196
197// IsValid returns true if the *Node and the underlying
198// tree-sitter node are both not nil.

Callers 4

matchJQueryFunction · 0.80
AllURLMatchersFunction · 0.80
matchXHRFunction · 0.80
TestCollapsedStringFunction · 0.80

Calls 4

IsValidMethod · 0.95
TypeMethod · 0.95
ChildByFieldNameMethod · 0.95
RawStringMethod · 0.95

Tested by 1

TestCollapsedStringFunction · 0.64