gitnexus 1.6.2-rc.17 → 1.6.2-rc.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,6 +7,9 @@ import { compilePatterns, runCompiledPatterns, unquoteLiteral, } from '../tree-s
|
|
|
7
7
|
* - Express `router.get(...)` / `app.post(...)` providers
|
|
8
8
|
* - `fetch(url)` / `fetch(url, { method: 'POST' })` consumers
|
|
9
9
|
* - `axios.get(url)` / `axios.delete(url)` consumers
|
|
10
|
+
* - `axios({ method, url })` object-form consumers
|
|
11
|
+
* - jQuery `$.get(url)` / `$.post(url, ...)` shorthand consumers
|
|
12
|
+
* - jQuery `$.ajax({ url, method | type })` consumers
|
|
10
13
|
*
|
|
11
14
|
* Because the JavaScript and TypeScript tree-sitter grammars share
|
|
12
15
|
* node type names for every construct we query, pattern sources are
|
|
@@ -86,6 +89,45 @@ const AXIOS_SPEC = {
|
|
|
86
89
|
arguments: (arguments . [(string) (template_string)] @path))
|
|
87
90
|
`,
|
|
88
91
|
};
|
|
92
|
+
// ─── Consumer: jQuery shorthand $.get(url) / $.post(url, ...) ────────
|
|
93
|
+
// `$` is a valid JS identifier, so tree-sitter parses `$.get(...)` as a
|
|
94
|
+
// call_expression whose function is a member_expression on identifier `$`.
|
|
95
|
+
const JQUERY_SHORTHAND_SPEC = {
|
|
96
|
+
meta: {},
|
|
97
|
+
query: `
|
|
98
|
+
(call_expression
|
|
99
|
+
function: (member_expression
|
|
100
|
+
object: (identifier) @obj (#eq? @obj "$")
|
|
101
|
+
property: (property_identifier) @http_method (#match? @http_method "^(get|post)$"))
|
|
102
|
+
arguments: (arguments . [(string) (template_string)] @path))
|
|
103
|
+
`,
|
|
104
|
+
};
|
|
105
|
+
// ─── Consumer: jQuery $.ajax({ url, method|type }) ───────────────────
|
|
106
|
+
// The query captures the options object only; key/value pairs are read
|
|
107
|
+
// programmatically via `readStringProp` below, which tolerates any key
|
|
108
|
+
// order and accepts either `method:` or `type:` (jQuery supports both).
|
|
109
|
+
const JQUERY_AJAX_SPEC = {
|
|
110
|
+
meta: {},
|
|
111
|
+
query: `
|
|
112
|
+
(call_expression
|
|
113
|
+
function: (member_expression
|
|
114
|
+
object: (identifier) @obj (#eq? @obj "$")
|
|
115
|
+
property: (property_identifier) @fn (#eq? @fn "ajax"))
|
|
116
|
+
arguments: (arguments (object) @options))
|
|
117
|
+
`,
|
|
118
|
+
};
|
|
119
|
+
// ─── Consumer: axios({ method, url }) object form ────────────────────
|
|
120
|
+
// Distinct from AXIOS_SPEC above because the call target is an identifier
|
|
121
|
+
// (`axios`) rather than a member expression (`axios.get`). As with the
|
|
122
|
+
// jQuery ajax form, option keys are resolved programmatically.
|
|
123
|
+
const AXIOS_OBJECT_SPEC = {
|
|
124
|
+
meta: {},
|
|
125
|
+
query: `
|
|
126
|
+
(call_expression
|
|
127
|
+
function: (identifier) @fn (#eq? @fn "axios")
|
|
128
|
+
arguments: (arguments (object) @options))
|
|
129
|
+
`,
|
|
130
|
+
};
|
|
89
131
|
function compileBundle(language, name) {
|
|
90
132
|
const mk = (spec, suffix) => compilePatterns({
|
|
91
133
|
name: `${name}-${suffix}`,
|
|
@@ -99,6 +141,9 @@ function compileBundle(language, name) {
|
|
|
99
141
|
fetchNoOptions: mk(FETCH_NO_OPTIONS_SPEC, 'fetch-no-options'),
|
|
100
142
|
fetchWithOptions: mk(FETCH_WITH_OPTIONS_SPEC, 'fetch-with-options'),
|
|
101
143
|
axios: mk(AXIOS_SPEC, 'axios'),
|
|
144
|
+
jqueryShorthand: mk(JQUERY_SHORTHAND_SPEC, 'jquery-shorthand'),
|
|
145
|
+
jqueryAjax: mk(JQUERY_AJAX_SPEC, 'jquery-ajax'),
|
|
146
|
+
axiosObject: mk(AXIOS_OBJECT_SPEC, 'axios-object'),
|
|
102
147
|
};
|
|
103
148
|
}
|
|
104
149
|
const JAVASCRIPT_BUNDLE = compileBundle(JavaScript, 'javascript-http');
|
|
@@ -130,6 +175,32 @@ function joinPath(prefix, sub) {
|
|
|
130
175
|
return `/${cleanSub}`;
|
|
131
176
|
return `/${cleanPrefix}/${cleanSub}`;
|
|
132
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Walk `pair` children of an `object` literal and return the unquoted
|
|
180
|
+
* string/template_string value for the first pair whose key matches one
|
|
181
|
+
* of `keyNames`. Returns null when no matching pair is present or the
|
|
182
|
+
* value is not a string literal. Used by the jQuery ajax / axios object
|
|
183
|
+
* consumers to resolve `url` / `method` / `type` keys in any order.
|
|
184
|
+
*/
|
|
185
|
+
function readStringProp(objectNode, keyNames) {
|
|
186
|
+
for (let i = 0; i < objectNode.namedChildCount; i++) {
|
|
187
|
+
const pair = objectNode.namedChild(i);
|
|
188
|
+
if (!pair || pair.type !== 'pair')
|
|
189
|
+
continue;
|
|
190
|
+
const keyNode = pair.childForFieldName('key');
|
|
191
|
+
const valueNode = pair.childForFieldName('value');
|
|
192
|
+
if (!keyNode || !valueNode)
|
|
193
|
+
continue;
|
|
194
|
+
if (!keyNames.includes(keyNode.text))
|
|
195
|
+
continue;
|
|
196
|
+
if (valueNode.type !== 'string' && valueNode.type !== 'template_string')
|
|
197
|
+
continue;
|
|
198
|
+
const lit = unquoteLiteral(valueNode.text);
|
|
199
|
+
if (lit !== null)
|
|
200
|
+
return lit;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
133
204
|
/**
|
|
134
205
|
* For a standalone `decorator` node (child of class_body / program),
|
|
135
206
|
* find the related `class_declaration` node that it decorates. In
|
|
@@ -335,6 +406,65 @@ function scanBundle(bundle, tree) {
|
|
|
335
406
|
confidence: 0.7,
|
|
336
407
|
});
|
|
337
408
|
}
|
|
409
|
+
// Consumer: jQuery shorthand $.get(url) / $.post(url, ...)
|
|
410
|
+
for (const match of runCompiledPatterns(bundle.jqueryShorthand, tree)) {
|
|
411
|
+
const methodNode = match.captures.http_method;
|
|
412
|
+
const pathNode = match.captures.path;
|
|
413
|
+
if (!methodNode || !pathNode)
|
|
414
|
+
continue;
|
|
415
|
+
const path = unquoteLiteral(pathNode.text);
|
|
416
|
+
if (path === null)
|
|
417
|
+
continue;
|
|
418
|
+
out.push({
|
|
419
|
+
role: 'consumer',
|
|
420
|
+
framework: 'jquery',
|
|
421
|
+
method: methodNode.text.toUpperCase(),
|
|
422
|
+
path,
|
|
423
|
+
name: null,
|
|
424
|
+
confidence: 0.7,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
// Consumer: jQuery $.ajax({ url, method|type }). jQuery accepts either
|
|
428
|
+
// `method:` or `type:`; both default to GET when absent.
|
|
429
|
+
for (const match of runCompiledPatterns(bundle.jqueryAjax, tree)) {
|
|
430
|
+
const optionsNode = match.captures.options;
|
|
431
|
+
if (!optionsNode)
|
|
432
|
+
continue;
|
|
433
|
+
const path = readStringProp(optionsNode, ['url']);
|
|
434
|
+
if (path === null)
|
|
435
|
+
continue;
|
|
436
|
+
const rawMethod = readStringProp(optionsNode, ['method', 'type']);
|
|
437
|
+
const method = (rawMethod ?? 'GET').toUpperCase();
|
|
438
|
+
out.push({
|
|
439
|
+
role: 'consumer',
|
|
440
|
+
framework: 'jquery',
|
|
441
|
+
method,
|
|
442
|
+
path,
|
|
443
|
+
name: null,
|
|
444
|
+
confidence: 0.7,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
// Consumer: axios({ method, url }) object form. Structurally distinct
|
|
448
|
+
// from axios.<verb>(url) (identifier vs member_expression call), so no
|
|
449
|
+
// dedup against the member-form loop above is required.
|
|
450
|
+
for (const match of runCompiledPatterns(bundle.axiosObject, tree)) {
|
|
451
|
+
const optionsNode = match.captures.options;
|
|
452
|
+
if (!optionsNode)
|
|
453
|
+
continue;
|
|
454
|
+
const path = readStringProp(optionsNode, ['url']);
|
|
455
|
+
if (path === null)
|
|
456
|
+
continue;
|
|
457
|
+
const rawMethod = readStringProp(optionsNode, ['method']);
|
|
458
|
+
const method = (rawMethod ?? 'GET').toUpperCase();
|
|
459
|
+
out.push({
|
|
460
|
+
role: 'consumer',
|
|
461
|
+
framework: 'axios',
|
|
462
|
+
method,
|
|
463
|
+
path,
|
|
464
|
+
name: null,
|
|
465
|
+
confidence: 0.7,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
338
468
|
return out;
|
|
339
469
|
}
|
|
340
470
|
export const JAVASCRIPT_HTTP_PLUGIN = {
|
package/package.json
CHANGED