@pyreon/compiler 0.1.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/LICENSE +21 -0
- package/README.md +67 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/index.js +547 -0
- package/lib/index.js.map +1 -0
- package/lib/types/index.d.ts +537 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index2.d.ts +57 -0
- package/lib/types/index2.d.ts.map +1 -0
- package/package.json +43 -0
- package/src/index.ts +4 -0
- package/src/jsx.ts +772 -0
- package/src/tests/jsx.test.ts +1009 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Vit Bokisch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @pyreon/compiler
|
|
2
|
+
|
|
3
|
+
JSX reactive transform for Pyreon. Automatically wraps dynamic expressions in reactive getters and hoists static JSX nodes to module scope.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pyreon/compiler
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { transformJSX } from "@pyreon/compiler"
|
|
15
|
+
|
|
16
|
+
const result = transformJSX(`
|
|
17
|
+
const App = () => <div class={color()}>{count()}</div>
|
|
18
|
+
`, "app.tsx")
|
|
19
|
+
|
|
20
|
+
console.log(result.code)
|
|
21
|
+
// Dynamic expressions are wrapped: {() => count()}, class={() => color()}
|
|
22
|
+
// Static JSX nodes are hoisted to module scope
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## What It Does
|
|
26
|
+
|
|
27
|
+
The compiler transforms JSX expression containers and props so the Pyreon runtime receives reactive getters instead of eagerly-evaluated values.
|
|
28
|
+
|
|
29
|
+
| Input | Output | Reason |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| `<div>{expr}</div>` | `<div>{() => expr}</div>` | Dynamic child |
|
|
32
|
+
| `<div class={expr}>` | `<div class={() => expr}>` | Dynamic prop |
|
|
33
|
+
| `<button onClick={fn}>` | unchanged | Event handler |
|
|
34
|
+
| `<div>{() => expr}</div>` | unchanged | Already wrapped |
|
|
35
|
+
| `<div>{"literal"}</div>` | unchanged | Static value |
|
|
36
|
+
|
|
37
|
+
### Static Hoisting
|
|
38
|
+
|
|
39
|
+
Fully static JSX subtrees inside expression containers are hoisted to module-level constants, so they are created once at module initialization rather than per-render.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// Before
|
|
43
|
+
const App = () => <div>{<span>Hello</span>}</div>
|
|
44
|
+
|
|
45
|
+
// After
|
|
46
|
+
const _$h0 = <span>Hello</span>
|
|
47
|
+
const App = () => <div>{_$h0}</div>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
- **`transformJSX(code: string, filename?: string): TransformResult`** -- Transforms JSX source code. Returns an object with the transformed `code` string.
|
|
53
|
+
|
|
54
|
+
### Types
|
|
55
|
+
|
|
56
|
+
- **`TransformResult`** -- `{ code: string }` -- The output of a transform pass.
|
|
57
|
+
|
|
58
|
+
## Implementation Notes
|
|
59
|
+
|
|
60
|
+
- Uses the TypeScript parser for AST positions and magic-string for source replacements.
|
|
61
|
+
- Props named `key` and `ref` are never wrapped.
|
|
62
|
+
- Props matching `on[A-Z]*` (event handlers) are never wrapped.
|
|
63
|
+
- No extra runtime dependencies beyond TypeScript (already a dev dependency).
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT
|