ast-search-python 1.5.0 → 1.6.0
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.
- package/LICENSE +21 -0
- package/build/shorthands.js +24 -8
- package/package.json +7 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Michael Shiplet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build/shorthands.js
CHANGED
|
@@ -41,14 +41,27 @@ export const PYTHON_SHORTHANDS = {
|
|
|
41
41
|
decorated: "(decorated_definition) @_",
|
|
42
42
|
};
|
|
43
43
|
export function expandShorthands(selector) {
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
44
|
+
// Expand shorthand words to their tree-sitter S-expression equivalents, outside
|
|
45
|
+
// quoted strings. Two expansion contexts:
|
|
46
|
+
//
|
|
47
|
+
// 1. Inside S-expressions — after `(`: expand to just the node type name so that
|
|
48
|
+
// `(fn body: ...)` becomes `(function_definition body: ...)`. Shorthands whose
|
|
49
|
+
// name already matches the tree-sitter node type (call, await, yield, lambda,
|
|
50
|
+
// decorator) are no-ops here — expanding `call` → `call` is harmless.
|
|
51
|
+
//
|
|
52
|
+
// 2. Standalone — not preceded by `(` or `@`: expand to the full S-expression
|
|
53
|
+
// so that bare `fn` becomes `(function_definition) @_`.
|
|
54
|
+
//
|
|
55
|
+
// Capture names like `@fn` are left untouched by both patterns.
|
|
50
56
|
const keys = Object.keys(PYTHON_SHORTHANDS);
|
|
51
|
-
|
|
57
|
+
// Map each shorthand to its bare node type name: "(function_definition) @_" → "function_definition"
|
|
58
|
+
const nodeTypes = {};
|
|
59
|
+
for (const [key, val] of Object.entries(PYTHON_SHORTHANDS)) {
|
|
60
|
+
const m = val.match(/^\((\w+)\)\s*@_$/);
|
|
61
|
+
nodeTypes[key] = m ? m[1] : key;
|
|
62
|
+
}
|
|
63
|
+
const innerPattern = new RegExp(`(?<=\\()\\b(${keys.join("|")})\\b`, "g");
|
|
64
|
+
const standalonePattern = new RegExp(`(?<![@(])\\b(${keys.join("|")})\\b`, "g");
|
|
52
65
|
const parts = [];
|
|
53
66
|
let i = 0;
|
|
54
67
|
while (i < selector.length) {
|
|
@@ -63,7 +76,10 @@ export function expandShorthands(selector) {
|
|
|
63
76
|
else {
|
|
64
77
|
const nextQuote = selector.slice(i).search(/['"]/);
|
|
65
78
|
const segment = nextQuote === -1 ? selector.slice(i) : selector.slice(i, i + nextQuote);
|
|
66
|
-
|
|
79
|
+
// Inner pass first: (fn → (function_definition
|
|
80
|
+
const afterInner = segment.replace(innerPattern, (m) => { var _a; return (_a = nodeTypes[m]) !== null && _a !== void 0 ? _a : m; });
|
|
81
|
+
// Standalone pass: bare fn → (function_definition) @_
|
|
82
|
+
parts.push(afterInner.replace(standalonePattern, (m) => { var _a; return (_a = PYTHON_SHORTHANDS[m]) !== null && _a !== void 0 ? _a : m; }));
|
|
67
83
|
i = nextQuote === -1 ? selector.length : i + nextQuote;
|
|
68
84
|
}
|
|
69
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ast-search-python",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Python language plugin for ast-search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -10,11 +10,6 @@
|
|
|
10
10
|
"types": "./build/index.d.ts"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc",
|
|
15
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
16
|
-
"prepublishOnly": "tsc"
|
|
17
|
-
},
|
|
18
13
|
"author": "shiplet",
|
|
19
14
|
"license": "MIT",
|
|
20
15
|
"repository": {
|
|
@@ -47,6 +42,10 @@
|
|
|
47
42
|
"typescript": "^5.4.5"
|
|
48
43
|
},
|
|
49
44
|
"peerDependencies": {
|
|
50
|
-
"ast-search-js": "1.
|
|
45
|
+
"ast-search-js": "1.10.0-beta.1"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
}
|