Skip to content

Commit 4b4d50e

Browse files
authored
Auto api better query (#1010)
* fix(auto api): adds missing functionality * only matches types with Public prefix * query now accepts extended (think "&" operator) and simple types * fix(api-table/auto): removes Props suffix
1 parent 35d75f6 commit 4b4d50e

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

apps/website/auto-api.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,30 @@ const parser = new Parser();
88

99
/**
1010
* Tree-Sitter query docs: https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
11-
* Pay particular attention to the following sections: capturing nodes, wildcard nodes, and anchors.
11+
* Pay particular attention to the following sections: capturing nodes, wildcard nodes,predicates,alternations, and anchors.
1212
*
1313
* To have a way of being able to see the Tree-Sitter AST in real-time: the ideal setup comes included in Neovim. In ex mode, simply run
1414
* the command below and you'll have the file's AST viewer open in real-time: `:InspectTree`
1515
**/
16-
16+
const commentPropType = `
17+
(object_type
18+
(comment) @comment
19+
.
20+
(property_signature
21+
name: (_) @prop
22+
type: (type_annotation (_) @type)
23+
)
24+
)`;
25+
const nestedTypeDef = `(_ ${commentPropType})`;
1726
const query = new Query(
1827
TS.tsx,
1928
`(type_alias_declaration
20-
name: (type_identifier) @subComponentName
21-
(intersection_type
22-
(object_type
23-
(comment) @comment
24-
.
25-
(property_signature
26-
name: (_) @prop
27-
type: (type_annotation (_) @type)
28-
)
29-
)
30-
)
31-
)
29+
name: (type_identifier) @subComponentName (#match? @subComponentName "^Public")
30+
[
31+
(${nestedTypeDef})
32+
(${commentPropType})
33+
]
34+
)
3235
`,
3336
);
3437

apps/website/src/components/api-table/auto-api.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const currentHeader = $(() => {
3737
});
3838

3939
const currentSubHeader = $((text: string) => {
40-
let subHeader = text.replace(/(p|P)rops/, '');
40+
const removePublicPrefix = text.replace(/^Public/, '');
41+
let subHeader = removePublicPrefix.replace(/(p|P)rops/, '');
4142
const hasCapital = /[a-z][A-Z]/.exec(subHeader)?.index;
4243
if (hasCapital != undefined) {
4344
subHeader =

0 commit comments

Comments
 (0)