@repometry/tree-sitter 0.4.0 → 0.5.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/tree-sitter",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "The tree-sitter language plugin engine for Repometry",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "prepack": "npm run build"
39
39
  },
40
40
  "dependencies": {
41
- "@repometry/core": "0.5.0",
41
+ "@repometry/core": "0.7.0",
42
42
  "web-tree-sitter": "0.27.2"
43
43
  }
44
44
  }
@@ -65,6 +65,8 @@ export interface Grammar {
65
65
  readonly logicalOperators: ReadonlySet<string>;
66
66
  /** Match named operator tokens by source spelling. */
67
67
  readonly logicalOperatorSpelling?: true;
68
+ /** Logical operator tokens are named direct children and use their node types. */
69
+ readonly namedLogicalOperators?: true;
68
70
  readonly logicalCognitive: 'parent' | 'sequence';
69
71
  /** A parameters field with one of these node types is a single parameter. */
70
72
  readonly singleParameterTypes?: ReadonlySet<string>;
@@ -1,7 +1,8 @@
1
1
  export function logicalOperator(node, grammar) {
2
2
  if (!grammar.logicalTypes.has(node.type))
3
3
  return undefined;
4
- const operator = node.childForFieldName('operator') ?? node.children.find(child => !child.isNamed);
4
+ const operator = node.childForFieldName('operator') ?? node.children.find(child => grammar.namedLogicalOperators
5
+ ? grammar.logicalOperators.has(child.type) : !child.isNamed);
5
6
  if (!operator)
6
7
  return undefined;
7
8
  const spelling = grammar.logicalOperatorSpelling ? operator.text : operator.type;
@@ -26,7 +27,8 @@ function operatorWork(node, grammar) {
26
27
  const operator = logicalOperator(node, grammar);
27
28
  if (operator === undefined)
28
29
  return [];
29
- const children = node.namedChildren.filter(child => !grammar.comments.has(child.type) && !grammar.extras.has(child.type));
30
+ const children = node.namedChildren.filter(child => !grammar.comments.has(child.type) && !grammar.extras.has(child.type)
31
+ && !(grammar.namedLogicalOperators && grammar.logicalOperators.has(child.type)));
30
32
  const first = node.childForFieldName('left') ?? children[0];
31
33
  const second = node.childForFieldName('right') ?? children[1];
32
34
  return [...(second ? [second] : []), operator, ...(first ? [first] : [])];