Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xeho91/js-ast

Do some fun with AST, using JavaScript.
https://github.com/xeho91/js-ast

ast print svelte

Last synced: 6 days ago
JSON representation

Do some fun with AST, using JavaScript.

Awesome Lists containing this project

README

        

# `js-ast`

This is a monorepo with packages to **boost the [DX]** of working with [AST] _(using [JavaScript] programming language)_ related to:

- ![JavaScript icon][icon-js] [JavaScript]
- ![TypeScript icon][icon-ts] [TypeScript]
- ![Svelte icon][icon-svelte] [Svelte]

---

## Core goals

1. [DX] friendly.
1. **Cross-runtime** friendlyβ€”πŸ‘ˆ this also means [ESM] only.
1. [e18e] friendly.
1. **No build step**β€”meaning you can debug/edit source code inside `node_modules` as it is.
1. Extensive tests.

---

## Packages

In order to work with AST, the following processes are recognized:

1. [Building](#build) programmatically the [AST] node(s), or an entire object.
1. [Parsing](#parse) _stringified_ code syntax into [AST] object.
1. [Traversing](#traverse) the [AST] object.
1. [Printing](#print) the [AST] object back into _stringified_ code syntax.

> [!IMPORTANT]
>
> The following lists of packages contains **what you can combine together - based on shared [AST] node interface format - aligned with [ESTree] specification**.

> [!NOTE]
>
> Not all of these packages are part of this monorepo.

### Build

Sometimes you need to do some code transformation...

| Name | Languages | In this repository? |
| -------------------- | -------------- | ------------------- |
| [`js-ast-build`] | ![icon-js] | βœ… |
| [`ts-ast-build`] | ![icon-ts] | βœ… |
| [`svelte-ast-build`] | ![icon-svelte] | βœ… |

### Parse

Getting the [AST] object from stringified code syntax.

| Name | Languages | In this repository? |
| ------------------- | -------------------- | ------------------- |
| [`@swc/core`] | ![icon-js]![icon-ts] | ❌ |
| [`svelte/compiler`] | ![icon-svelte] | ❌ |

### Traverse

In other words, _walk_ on the AST object.

| Name | Languages | In this repository? |
| --------------- | ---------------------------------- | ------------------- |
| [`zimmerframe`] | ![icon-js]![icon-ts]![icon-svelte] | ❌ |

### Print

Print the [AST] object or nodes into stringified code syntax.

| Name | Languages | In this repository? |
| -------------------- | ---------------------------------- | ------------------- |
| [`esrap`] | ![icon-js]![icon-ts] | ❌ |
| [`svelte-ast-print`] | ![icon-js]![icon-ts]![icon-svelte] | βœ… |

---

## Contributing

If you can offer your time - refer to [Contribution Guide](/.github/CONTRIBUTING.md).

Otherwise, consider [sponsoring me](https://github.com/sponsors/xeho91).

## Author

Mateusz "[xeho91](https://github.com/xeho91)" Kadlubowski

[icon-js]: https://api.iconify.design/logos:javascript.svg
[icon-ts]: https://api.iconify.design/logos:typescript-icon-round.svg
[icon-svelte]: https://api.iconify.design/logos:svelte-icon.svg
[AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
[DX]: https://en.wikipedia.org/wiki/User_experience#Developer_experience
[ESTree]: https://github.com/estree/estree
[e18e]: https://github.com/e18e/e18e
[ESM]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
[`js-ast-build`]: ./pkgs/js-ast-build
[`ts-ast-build`]: ./pkgs/ts-ast-build
[`svelte-ast-build`]: ./pkgs/svelte-ast-build
[`svelte-ast-print`]: ./pkgs/svelte-ast-print
[`@swc/core`]: https://github.com/swc-project/swc
[`svelte/compiler`]: https://github.com/sveltejs/svelte
[`zimmerframe`]: https://github.com/Rich-Harris/zimmerframe
[`esrap`]: https://github.com/sveltejs/esrap
[Svelte]: https://github.com/sveltejs/svelte
[TypeScript]: https://github.com/microsoft/TypeScript
[JavaScript]: https://en.wikipedia.org/wiki/JavaScript