Skip to content

Commit

Permalink
Swap out babel with meriyah for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
eoftedal committed Feb 19, 2024
1 parent 4f405d5 commit c0ac287
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 151 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# babel-q
# ASTronomical

`babel-q` offers a way to query an babel AST to find specific patterns using a syntax somewhat similar to XPath.
`babel-q` was inspired by [astq](https://github.com/rse/astq), but offers some features that did not seem possible in `astq` and also has some limits compared to `astq`.
`astronomical` offers a way to query a JavaScript AST to find specific patterns using a syntax somewhat similar to XPath.
`astronomical` was inspired by [astq](https://github.com/rse/astq), but offers some features that did not seem possible in `astq` and also has some limits compared to `astq`.

Goals:

Expand Down Expand Up @@ -55,16 +55,16 @@ the object is bound to a parameter of the surrounding function, an return the as

## API

* `query(code: ParseResult<Babel.File> | string, query: string) : Result[]` - Runs the given query on the given code in the form of an already parsed AST or a string (which is parsed as `sourceType: "unambiguous"`), and returns the result.
* `multiQuery<T extends Record<string, string>>(code: ParseResult<Babel.File> | string, namedQueries: T) : Record<keyof T, Result[]>` - Runs the given set of named queries on the given code in the form of an already parsed AST or a string (which is parsed as `sourceType: "unambiguous"`), and returns a map of named results (one result array per named query).
* `query(code: string, query: string) : Result[]` - Runs the given query on the given code in the form of an already parsed AST or a string (which is parsed as `sourceType: "unambiguous"`), and returns the result.
* `multiQuery<T extends Record<string, string>>(code: string, namedQueries: T) : Record<keyof T, Result[]>` - Runs the given set of named queries on the given code in the form of an already parsed AST or a string (which is parsed as `sourceType: "unambiguous"`), and returns a map of named results (one result array per named query).

where `Result` is `Babel.Node | string | number | boolean;`


## Example code

```
import { query } from "babel-q";
import { query } from "astronomical";
import * as fs from "fs";
const contents = fs.readFileSync("some-file.js");
Expand Down
Loading

0 comments on commit c0ac287

Please sign in to comment.