Skip to content

Commit 800166b

Browse files
authored
feat: Add initial *-ast-analyze packages (#115)
1 parent d12a8b3 commit 800166b

File tree

126 files changed

+3433
-2108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+3433
-2108
lines changed

.changeset/flat-parrots-battle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-ast-print": minor
3+
---
4+
5+
feat: Use `svelte-ast-analyze` as dependency

.changeset/happy-dingos-speak.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-ast-analyze": minor
3+
---
4+
5+
feat: Add initial type-guards and schemas

.changeset/nervous-grapes-grow.md

-5
This file was deleted.

.changeset/wicked-rockets-fold.md

-5
This file was deleted.

.github/labeler.yml

+20
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,31 @@
33
- any-glob-to-any-file:
44
- ".github/workflows/**"
55

6+
"pkg:js-ast-analyze":
7+
- changed-files:
8+
- any-glob-to-any-file:
9+
- "pkgs/js-ast-analyze/**"
10+
611
"pkg:js-ast-build":
712
- changed-files:
813
- any-glob-to-any-file:
914
- "pkgs/js-ast-build/**"
1015

16+
"pkg:ts-ast-analyze":
17+
- changed-files:
18+
- any-glob-to-any-file:
19+
- "pkgs/ts-ast-analyze/**"
20+
1121
"pkg:ts-ast-build":
1222
- changed-files:
1323
- any-glob-to-any-file:
1424
- "pkgs/ts-ast-build/**"
1525

26+
"pkg:svelte-ast-analyze":
27+
- changed-files:
28+
- any-glob-to-any-file:
29+
- "pkgs/svelte-ast-analyze/**"
30+
1631
"pkg:svelte-ast-build":
1732
- changed-files:
1833
- any-glob-to-any-file:
@@ -22,3 +37,8 @@
2237
- changed-files:
2338
- any-glob-to-any-file:
2439
- "pkgs/svelte-ast-print/**"
40+
41+
"tests":
42+
- changed-files:
43+
- any-glob-to-any-file:
44+
- "**/*.test.ts"

.gitignore

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# Dependencies which are downloadable
2-
node_modules/
3-
4-
# Documentation output (auto-generated)
5-
docs/
6-
71
# Logs
82
pnpm-debug.log*
93

@@ -13,5 +7,17 @@ pnpm-debug.log*
137
# Sensitive data
148
.env
159

10+
# TypeScript build caching
11+
tsconfig.tsbuildinfo
12+
13+
# Build output with TypeScript
14+
dist/
15+
1616
# Tests coverage (auto-generated)
1717
coverage/
18+
19+
# Documentation output (auto-generated)
20+
docs/
21+
22+
# Dependencies which are downloadable
23+
node_modules/

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ This is a monorepo with packages to **boost the [DX]** of working with [AST] _(u
1313
1. [DX] friendly.
1414
1. **Cross-runtime** friendly—👈 this also means [ESM] only.
1515
1. [e18e] friendly.
16-
1. **No build step**—meaning you can debug/edit source code inside `node_modules` as it is.
17-
1. Extensive tests.
16+
1. Extensive tests and benchmarks.
1817

1918
---
2019

@@ -25,6 +24,7 @@ In order to work with AST, the following processes are recognized:
2524
1. [Building](#build) programmatically the [AST] node(s), or an entire object.
2625
1. [Parsing](#parse) _stringified_ code syntax into [AST] object.
2726
1. [Traversing](#traverse) the [AST] object.
27+
1. [Analyzing](#analyze) the [AST] object(s).
2828
1. [Printing](#print) the [AST] object back into _stringified_ code syntax.
2929

3030
> [!IMPORTANT]
@@ -62,6 +62,16 @@ In other words, _walk_ on the AST object.
6262
| --------------- | ---------------------------------- | ------------------- |
6363
| [`zimmerframe`] | ![icon-js]![icon-ts]![icon-svelte] ||
6464

65+
### Analyze
66+
67+
Analyze the received [AST] object(s). Contains type-guards and utilities.
68+
69+
| Name | Languages | In this repository? |
70+
| ---------------------- | ---------------------------------- | ------------------- |
71+
| [`js-ast-analyze`] | ![icon-js] ||
72+
| [`ts-ast-analyze`] | ![icon-js]![icon-ts] ||
73+
| [`svelte-ast-analyze`] | ![icon-js]![icon-ts]![icon-svelte] ||
74+
6575
### Print
6676

6777
Print the [AST] object or nodes into stringified code syntax.
@@ -93,10 +103,13 @@ Mateusz "[xeho91](https://github.com/xeho91)" Kadlubowski
93103
[ESTree]: https://github.com/estree/estree
94104
[e18e]: https://github.com/e18e/e18e
95105
[ESM]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
106+
[`js-ast-analyze`]: ./pkgs/js-ast-build
96107
[`js-ast-build`]: ./pkgs/js-ast-build
97-
[`ts-ast-build`]: ./pkgs/ts-ast-build
108+
[`svelte-ast-analyze`]: ./pkgs/js-ast-build
98109
[`svelte-ast-build`]: ./pkgs/svelte-ast-build
99110
[`svelte-ast-print`]: ./pkgs/svelte-ast-print
111+
[`ts-ast-analyze`]: ./pkgs/js-ast-build
112+
[`ts-ast-build`]: ./pkgs/ts-ast-build
100113
[`@swc/core`]: https://github.com/swc-project/swc
101114
[`svelte/compiler`]: https://github.com/sveltejs/svelte
102115
[`zimmerframe`]: https://github.com/Rich-Harris/zimmerframe

knip.json

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,32 @@
88
},
99
"vite": false
1010
},
11+
"pkgs/js-ast-analyze": {
12+
"entry": ["src/lib.ts"],
13+
"project": ["**/*.{json,js,ts}"]
14+
},
1115
"pkgs/js-ast-build": {
12-
"entry": ["src/lib.js"],
16+
"entry": ["src/lib.ts"],
17+
"project": ["**/*.{json,js,ts}"]
18+
},
19+
"pkgs/ts-ast-analyze": {
20+
"entry": ["src/lib.ts"],
1321
"project": ["**/*.{json,js,ts}"]
1422
},
1523
"pkgs/ts-ast-build": {
16-
"entry": ["src/lib.js"],
24+
"entry": ["src/lib.ts"],
25+
"project": ["**/*.{json,js,ts}"]
26+
},
27+
"pkgs/svelte-ast-analyze": {
28+
"entry": ["src/lib.ts"],
1729
"project": ["**/*.{json,js,ts}"]
1830
},
1931
"pkgs/svelte-ast-build": {
20-
"entry": ["src/lib.js"],
32+
"entry": ["src/lib.ts"],
2133
"project": ["**/*.{json,js,ts}"]
2234
},
2335
"pkgs/svelte-ast-print": {
24-
"entry": ["src/lib.js"],
36+
"entry": ["src/lib.ts"],
2537
"project": ["**/*.{json,js,ts}"]
2638
}
2739
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
"@biomejs/biome": "^1.9.0",
3333
"@changesets/changelog-github": "^0.5.0",
3434
"@changesets/cli": "^2.27.0",
35-
"@types/node": "^22.13.0",
35+
"@types/node": "^22.0.0",
3636
"@vitest/coverage-v8": "^3.0.5",
3737
"@vitest/ui": "^3.0.5",
38-
"knip": "^5.43.0",
38+
"knip": "^5.44.0",
3939
"serve": "^14.2.0",
4040
"typedoc": "^0.27.0",
4141
"typedoc-plugin-coverage": "^3.4.0",
42-
"typedoc-plugin-dt-links": "^1.1.10",
42+
"typedoc-plugin-dt-links": "^1.1.0",
4343
"typedoc-plugin-mdn-links": "^4.0.0",
4444
"typedoc-plugin-missing-exports": "^3.1.0",
4545
"typescript": "catalog:",

pkgs/js-ast-analyze/LICENSE.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# MIT License
2+
3+
Copyright (c) 2024-present [these people](https://github.com/xeho91/svelte-ast-print/graphs/contributors)
4+
5+
Permission is hereby granted, free of charge,
6+
to any person obtaining a copy of this software and associated documentation files (the "Software"),
7+
to deal in the Software without restriction,
8+
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
and/or sell copies of the Software,
10+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pkgs/js-ast-analyze/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# `ts-ast-analyze`
2+
3+
![NPM Version](https://img.shields.io/npm/v/ts-ast-analyze?style=for-the-badge&logo=npm)
4+
5+
> [!CAUTION]
6+
> 🚧 Work In Progress 🚧
7+
8+
---
9+
10+
## Author
11+
12+
Mateusz "[xeho91](https://github.com/xeho91)" Kadlubowski
13+
14+
<!-- LINKS -->
15+
16+
[AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
17+
[Svelte]: https://github.com/sveltejs/svelte

pkgs/js-ast-analyze/package.json

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"$schema": "https://json.schemastore.org/package",
3+
"name": "js-ast-analyze",
4+
"version": "0.0.1",
5+
"type": "module",
6+
"description": "Analyze JavaScript AST nodes conveniently.",
7+
"keywords": ["ast", "analyze", "javascript"],
8+
"license": "MIT",
9+
"author": {
10+
"name": "Mateusz Kadlubowski",
11+
"email": "[email protected]",
12+
"url": "https://github.com/xeho91"
13+
},
14+
"homepage": "https://github.com/xeho91/js-ast",
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/xeho91/js-ast.git",
18+
"directory": "pkgs/js-ast-analyze"
19+
},
20+
"bugs": "https://github.com/xeho91/js-ast/issues",
21+
"funding": [
22+
{
23+
"type": "github",
24+
"url": "https://github.com/sponsors/xeho91"
25+
},
26+
{
27+
"type": "opencollective",
28+
"url": "https://opencollective.com/xeho91"
29+
}
30+
],
31+
"publishConfig": {
32+
"access": "public",
33+
"provenance": true
34+
},
35+
"engines": {
36+
"node": ">=18"
37+
},
38+
"files": ["dist/"],
39+
"exports": {
40+
".": {
41+
"development": "./src/lib.ts",
42+
"types": "./dist/lib.d.ts",
43+
"default": "./dist/lib.js"
44+
},
45+
"./package.json": "./package.json"
46+
},
47+
"scripts": {
48+
"build": "pnpm run \"/^build:.*/\" ",
49+
"build:doc": "typedoc",
50+
"build:pkg": "tsc",
51+
"check": "tsc --noEmit",
52+
"clean": "pnpm run \"/^clean:.*/\"; rm -rf \"./**/node_modules\" ",
53+
"clean:build": "rm -rf \"./dist\" && rm -f \"tsconfig.tsbuildinfo\" ",
54+
"clean:cache": "rm -rf \"./node_modules/.cache\" ",
55+
"clean:doc": "rm -rf \"./docs\" ",
56+
"clean:test": "rm -rf \"./coverage\" ",
57+
"dev": "pnpm run \"/^dev:.*/\" ",
58+
"dev:doc": "typedoc --watch",
59+
"dev:test": "pnpm vitest watch --passWithNoTests --ui",
60+
"fix": "pnpm run \"/^fix:.*/\" ",
61+
"fix:biome": "biome check . --verbose --write",
62+
"fix:format": "biome format . --verbose --write",
63+
"fix:js": "biome lint . --verbose --fix --unsafe",
64+
"lint": "pnpm run \"/^lint:.*/\" ",
65+
"lint:biome": "biome check . --verbose",
66+
"lint:format": "biome format . --verbose",
67+
"lint:js": "biome lint . --verbose",
68+
"prepublishOnly": "pnpm --filter js-ast-analyze run --parallel \"/^lint|^test|^build:pkg/\"",
69+
"serve:doc": "serve \"./docs\" ",
70+
"test": "vitest run . --passWithNoTests"
71+
}
72+
}
File renamed without changes.

pkgs/js-ast-analyze/tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": ["../../tsconfig.json"],
4+
"compilerOptions": {
5+
"rootDir": "src/",
6+
"outDir": "dist/"
7+
},
8+
"exclude": ["src/**/*.test.ts", "tests/"],
9+
"include": ["src/"]
10+
}

pkgs/js-ast-analyze/typedoc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://typedoc.org/schema.json",
3+
"extends": ["../../typedoc.base.json"],
4+
"exclude": ["src/**/*.test.ts", "tests/"],
5+
"entryPoints": ["src/**/*.ts"]
6+
}

pkgs/js-ast-build/package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,22 @@
3535
"engines": {
3636
"node": ">=18"
3737
},
38-
"files": ["src/", "types.d.ts"],
38+
"files": ["dist/"],
3939
"exports": {
4040
".": {
41-
"types": "./types.d.ts",
42-
"default": "./src/mod.js"
41+
"development": "./src/lib.ts",
42+
"types": "./dist/lib.d.ts",
43+
"default": "./dist/lib.js"
4344
},
4445
"./package.json": "./package.json"
4546
},
4647
"scripts": {
4748
"build": "pnpm run \"/^build:.*/\" ",
4849
"build:doc": "typedoc",
50+
"build:pkg": "tsc",
4951
"check": "tsc --noEmit",
5052
"clean": "pnpm run \"/^clean:.*/\"; rm -rf \"./**/node_modules\" ",
53+
"clean:build": "rm -rf \"./dist\" && rm -f \"tsconfig.tsbuildinfo\" ",
5154
"clean:cache": "rm -rf \"./node_modules/.cache\" ",
5255
"clean:doc": "rm -rf \"./docs\" ",
5356
"clean:test": "rm -rf \"./coverage\" ",
@@ -62,7 +65,7 @@
6265
"lint:biome": "biome check . --verbose",
6366
"lint:format": "biome format . --verbose",
6467
"lint:js": "biome lint . --verbose",
65-
"prepublishOnly": "pnpm lint && pnpm test",
68+
"prepublishOnly": "pnpm --filter js-ast-build run --parallel \"/^lint|^test|^build:pkg/\"",
6669
"serve:doc": "serve \"./docs\" ",
6770
"test": "vitest run . --passWithNoTests"
6871
}
File renamed without changes.

pkgs/js-ast-build/tsconfig.json

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": ["../../tsconfig.json"],
34
"compilerOptions": {
4-
"allowJs": true,
5-
"allowImportingTsExtensions": true,
6-
"allowSyntheticDefaultImports": true,
7-
"checkJs": true,
8-
"lib": ["ESNext"],
9-
"module": "ESNext",
10-
"moduleResolution": "bundler",
11-
"noEmit": true,
12-
"noEmitOnError": true,
13-
"noErrorTruncation": true,
14-
"resolveJsonModule": true,
15-
"skipLibCheck": true,
16-
"strict": true,
17-
"target": "ESNext",
18-
"verbatimModuleSyntax": true
5+
"rootDir": "src/",
6+
"outDir": "dist/"
197
},
8+
"exclude": ["src/**/*.test.ts", "tests/"],
209
"include": ["src/"]
2110
}

pkgs/js-ast-build/typedoc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "https://typedoc.org/schema.json",
33
"extends": ["../../typedoc.base.json"],
4-
"entryPoints": ["src/**/*"]
4+
"exclude": ["src/**/*.test.ts", "tests/"],
5+
"entryPoints": ["src/**/*.ts"]
56
}

0 commit comments

Comments
 (0)