sinwan-compiler 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyze.d.ts +1 -1
- package/dist/ast/generate.d.ts +16 -0
- package/dist/ast/index.d.ts +8 -0
- package/dist/ast/node.d.ts +147 -0
- package/dist/ast/parse.d.ts +19 -0
- package/dist/ast/path.d.ts +116 -0
- package/dist/ast/traverse.d.ts +4 -0
- package/dist/ast/types.d.ts +267 -0
- package/dist/auto-cc.d.ts +1 -1
- package/dist/{chunk-sy6qf73w.js → chunk-rshqq0t3.js} +3801 -2505
- package/dist/cli.js +1 -1
- package/dist/exports.d.ts +2 -2
- package/dist/index.js +334 -132
- package/dist/live-cc-destructure.d.ts +1 -1
- package/dist/reactive-wrap.d.ts +2 -2
- package/dist/transform.d.ts +2 -0
- package/docs/api.md +2 -2
- package/docs/architecture.md +16 -0
- package/docs/transform.md +1 -1
- package/package.json +4 -8
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Nested patterns are left as snapshots. JSX spreads of the props (or rest)
|
|
9
9
|
* identifier use `getSpreadProps` so native attributes keep getter functions.
|
|
10
10
|
*/
|
|
11
|
-
import * as t from "
|
|
11
|
+
import * as t from "./ast/types";
|
|
12
12
|
/**
|
|
13
13
|
* Rewrite flat `cc` destructure and raw JSX spreads. Returns whether any
|
|
14
14
|
* helper imports are required.
|
package/dist/reactive-wrap.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* when the value changes.
|
|
7
7
|
*
|
|
8
8
|
* Supported reactive sources:
|
|
9
|
-
* - `createMutable` / `createStore` from `
|
|
9
|
+
* - `createMutable` / `createStore` from `sinway`
|
|
10
10
|
* - `signal` / `computed` from `sinwan/reactivity`
|
|
11
11
|
* - `useState` from `sinwan/react`
|
|
12
12
|
* - `.value` reads of signals returned from other modules (`useTheme`,
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* <p>{count.value}</p> → <p>{() => count.value}</p>
|
|
21
21
|
* <p>{getCount()}</p> → <p>{() => getCount()}</p>
|
|
22
22
|
*/
|
|
23
|
-
import * as t from "
|
|
23
|
+
import * as t from "./ast/types";
|
|
24
24
|
export interface ImportNames {
|
|
25
25
|
createMutable: Set<string>;
|
|
26
26
|
createStore: Set<string>;
|
package/dist/transform.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Static JSX elements are extracted to module-level template strings
|
|
6
6
|
* and replaced with optimized template creation calls.
|
|
7
7
|
*/
|
|
8
|
+
import { t } from "./ast";
|
|
8
9
|
export interface TransformOptions {
|
|
9
10
|
derivedLocals?: boolean;
|
|
10
11
|
/** Enable template hoisting (default: true) */
|
|
@@ -40,6 +41,7 @@ export declare const COMPILER_TEMPLATE_SLOT_PROTOCOL: {
|
|
|
40
41
|
encodeSlot(index: number): string;
|
|
41
42
|
decodeSlot(data: string): number | null;
|
|
42
43
|
};
|
|
44
|
+
export declare function jsxAttrName(attr: t.Node): string | undefined;
|
|
43
45
|
export declare function transformJSX(code: string, filename: string, options?: TransformOptions): {
|
|
44
46
|
code: string;
|
|
45
47
|
map?: any;
|
package/docs/api.md
CHANGED
|
@@ -29,11 +29,11 @@ See [Transform](transform.md) for wrapping rules and options.
|
|
|
29
29
|
|
|
30
30
|
### `autoWrapComponents(ast, filename?)`
|
|
31
31
|
|
|
32
|
-
Mutates
|
|
32
|
+
Mutates an ESTree AST (oxc-parser): wrap exported component-like functions with `cc(...)`. Returns `true` if anything changed. `transformJSX` already runs this.
|
|
33
33
|
|
|
34
34
|
### `rewriteLiveCcDestructure(ast)`
|
|
35
35
|
|
|
36
|
-
Mutates
|
|
36
|
+
Mutates an ESTree AST (oxc-parser): rewrite flat `cc(({ value }) => …)` params to a `props` identifier and `{...props}` spreads to `getSpreadProps(props)`. Nested destructure is left as a snapshot. `transformJSX` already runs this before reactive wrap.
|
|
37
37
|
|
|
38
38
|
## Analysis
|
|
39
39
|
|
package/docs/architecture.md
CHANGED
|
@@ -6,6 +6,7 @@ This page is for people changing the compiler. App authors can stay on [Transfor
|
|
|
6
6
|
|
|
7
7
|
```
|
|
8
8
|
src/
|
|
9
|
+
ast/ oxc parse, Path/Scope, esrap print
|
|
9
10
|
index.ts Public exports
|
|
10
11
|
auto-cc.ts Exported function → cc(...)
|
|
11
12
|
live-cc-destructure.ts Flat cc(({ value }) => …) → props.value
|
|
@@ -16,6 +17,21 @@ src/
|
|
|
16
17
|
exports.ts collectExportedComponents
|
|
17
18
|
```
|
|
18
19
|
|
|
20
|
+
## AST pipeline
|
|
21
|
+
|
|
22
|
+
`transformJSX` and analyze parse with **oxc-parser** (`parseSync`, ESTree / TS-ESTree). The compiler parses as TSX so JSX and TypeScript are accepted in `.js`, `.jsx`, `.ts`, and `.tsx`, matching the previous Babel plugin set. Comments are copied onto `leadingComments` / `trailingComments`. A JSX `{/* comment */}` stays on its empty expression. A comment that sits inside a function or object after the last child stays on that container. Rewrite passes walk a Babel-shaped **Path/Scope** facade built on oxc `visitorKeys` (parent pointers, `getBinding`, `replaceWith`). Print is **esrap** with `esrap/languages/tsx` and double quotes.
|
|
23
|
+
|
|
24
|
+
Babel is not used. oxc-parser JS/JSX matches Acorn ESTree; TS/TSX matches TS-ESTree. Passes must treat:
|
|
25
|
+
|
|
26
|
+
- `Literal` (not `StringLiteral` / `NumericLiteral`)
|
|
27
|
+
- `Property` (not `ObjectProperty`)
|
|
28
|
+
- `ChainExpression` around optional calls/members
|
|
29
|
+
- `ParenthesizedExpression` (`preserveParens` defaults true) — unwrap in reactive walks, do not require Babel’s implicit paren stripping
|
|
30
|
+
|
|
31
|
+
Print is esrap, not oxc-codegen or MagicString, so mutations stay on the tree. Acorn / acorn-walk cannot own this pipeline: Acorn does not parse TSX, and acorn-walk has no bindings or JSX/TS visitor keys. Bun.Transpiler and SWC are out of scope (no AST mutation API / not the primary engine).
|
|
32
|
+
|
|
33
|
+
`derivedLocals` uses the Path/Scope facade; a Rust rewrite of passes is not required while those tests pass.
|
|
34
|
+
|
|
19
35
|
## Data flow
|
|
20
36
|
|
|
21
37
|
```text
|
package/docs/transform.md
CHANGED
|
@@ -78,7 +78,7 @@ Tracked imports:
|
|
|
78
78
|
|
|
79
79
|
| Module | Names |
|
|
80
80
|
| ------------------- | ------------------------------ |
|
|
81
|
-
| `
|
|
81
|
+
| `sinway` | `createMutable`, `createStore` |
|
|
82
82
|
| `sinwan/reactivity` | `signal`, `computed` |
|
|
83
83
|
| `sinwan/react` | `useState` |
|
|
84
84
|
| `sinwan/hook` | `useFetch` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sinwan-compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Shared compiler core for Sinwan plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,16 +37,12 @@
|
|
|
37
37
|
"prepublishOnly": "bun run clean && bun run typecheck && bun run test && bun run build"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types
|
|
41
|
-
"@types/babel__traverse": "^7.28.0",
|
|
40
|
+
"@oxc-project/types": "^0.150.0",
|
|
42
41
|
"@types/bun": "latest"
|
|
43
42
|
},
|
|
44
43
|
"dependencies": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"@babel/parser": "^7.29.8",
|
|
48
|
-
"@babel/traverse": "^7.29.8",
|
|
49
|
-
"@babel/types": "^7.29.8"
|
|
44
|
+
"esrap": "^2.3.7",
|
|
45
|
+
"oxc-parser": "^0.150.0"
|
|
50
46
|
},
|
|
51
47
|
"peerDependencies": {
|
|
52
48
|
"typescript": ">=5.0.0 <8.0.0"
|