Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto api better query #1010

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions apps/website/auto-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ const parser = new Parser();

/**
* Tree-Sitter query docs: https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax
* Pay particular attention to the following sections: capturing nodes, wildcard nodes, and anchors.
* Pay particular attention to the following sections: capturing nodes, wildcard nodes,predicates,alternations, and anchors.
*
* 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
* the command below and you'll have the file's AST viewer open in real-time: `:InspectTree`
**/

const commentPropType = `
(object_type
(comment) @comment
.
(property_signature
name: (_) @prop
type: (type_annotation (_) @type)
)
)`;
const nestedTypeDef = `(_ ${commentPropType})`;
const query = new Query(
TS.tsx,
`(type_alias_declaration
name: (type_identifier) @subComponentName
(intersection_type
(object_type
(comment) @comment
.
(property_signature
name: (_) @prop
type: (type_annotation (_) @type)
)
)
)
)
name: (type_identifier) @subComponentName (#match? @subComponentName "^Public")
[
(${nestedTypeDef})
(${commentPropType})
]
)
`,
);

Expand Down
3 changes: 2 additions & 1 deletion apps/website/src/components/api-table/auto-api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const currentHeader = $(() => {
});

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