ast-search-python 1.0.4 → 1.0.5

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/build/query.js CHANGED
@@ -10,7 +10,11 @@ function assertValidPattern(pattern) {
10
10
  export function runTreeSitterQuery(ast, pattern, source, filePath, language) {
11
11
  assertValidPattern(pattern);
12
12
  const tree = ast;
13
- const q = language.query(pattern);
13
+ // captures() only returns nodes that have a capture name (@something).
14
+ // If the user wrote a bare S-expression like (function_definition), add @_
15
+ // so results are returned.
16
+ const queryPattern = pattern.includes("@") ? pattern : `${pattern} @_`;
17
+ const q = language.query(queryPattern);
14
18
  const captures = q.captures(tree.rootNode);
15
19
  // web-tree-sitter may return different JS objects for the same node when
16
20
  // multiple capture names match it, so deduplicate by position instead of identity.
@@ -41,11 +41,14 @@ export const PYTHON_SHORTHANDS = {
41
41
  decorated: "(decorated_definition) @_",
42
42
  };
43
43
  export function expandShorthands(selector) {
44
- // Replace bare shorthand words (not inside quotes and not preceded by @)
45
- // with their S-expression. The negative lookbehind prevents expanding
46
- // capture names like @fn into @(function_definition) @_.
44
+ // Replace bare shorthand words (not inside quotes and not preceded by @ or ()
45
+ // with their S-expression. The negative lookbehind prevents expanding:
46
+ // - capture names like @fn into @(function_definition) @_
47
+ // - node type names inside S-expressions like (call ...) into ((call) @_ ...)
48
+ // which matters for shorthands whose name matches the tree-sitter node type
49
+ // exactly (call, await, yield, lambda, decorator).
47
50
  const keys = Object.keys(PYTHON_SHORTHANDS);
48
- const pattern = new RegExp(`(?<!@)\\b(${keys.join("|")})\\b`, "g");
51
+ const pattern = new RegExp(`(?<![@(])\\b(${keys.join("|")})\\b`, "g");
49
52
  const parts = [];
50
53
  let i = 0;
51
54
  while (i < selector.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ast-search-python",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Python language plugin for ast-search",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",