@madenowhere/phaze-compile 0.0.3

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rohan Rehman
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.
@@ -0,0 +1,8 @@
1
+ import type { PluginObj, PluginPass } from '@babel/core';
2
+ import type * as t from '@babel/types';
3
+ interface Babel {
4
+ types: typeof t;
5
+ }
6
+ declare const phaseCompile: (babel: Babel) => PluginObj<PluginPass>;
7
+ export default phaseCompile;
8
+ //# sourceMappingURL=babel-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin.d.ts","sourceRoot":"","sources":["../src/babel-plugin.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAA;AAItC,UAAU,KAAK;IACb,KAAK,EAAE,OAAO,CAAC,CAAA;CAChB;AAED,QAAA,MAAM,YAAY,GAAI,OAAO,KAAK,KAAG,SAAS,CAAC,UAAU,CA4BxD,CAAA;AAqJD,eAAe,YAAY,CAAA"}
@@ -0,0 +1,200 @@
1
+ // @madenowhere/phaze-compile — Babel plugin.
2
+ //
3
+ // Phaze's runtime evaluates JSX leaf-first (post-order): when a parent
4
+ // component receives `children`, those children have already been
5
+ // constructed. For flow components like <Catch>, <Switch>, <Portal>,
6
+ // <Dynamic>, that's wrong — the parent needs to control *when* children
7
+ // construct (to install error handlers, push child effects, lazily
8
+ // evaluate branches, etc.).
9
+ //
10
+ // Without a compiler, users wrote the explicit thunk form:
11
+ //
12
+ // <Catch>{() => <App/>}</Catch>
13
+ //
14
+ // This plugin removes that wart. JSX children of a component element
15
+ // are wrapped in an arrow function automatically:
16
+ //
17
+ // <Catch><App/></Catch>
18
+ // ↓
19
+ // <Catch>{() => <App/>}</Catch>
20
+ //
21
+ // Same applies to JSX-valued props (e.g. `fallback={<X/>}` on Catch).
22
+ //
23
+ // What's a "component"? Any JSX type that's:
24
+ // 1. A capitalized identifier (`Foo`, `MyComponent`)
25
+ // 2. A member expression (`Foo.Bar` — though Phaze removed Provider,
26
+ // this stays generic)
27
+ //
28
+ // Lowercase JSX (`<div>`, `<span>`) is host-element JSX and stays eager
29
+ // — Phaze's runtime appendChildren handles host children directly.
30
+ //
31
+ // The plugin runs BEFORE the JSX-to-jsx() transform. It produces JSX
32
+ // AST output, which downstream tooling (esbuild/swc/babel-jsx-transform)
33
+ // converts to function calls.
34
+ // @ts-expect-error - no published types for the plugin module
35
+ import jsxSyntax from '@babel/plugin-syntax-jsx';
36
+ const phaseCompile = (babel) => {
37
+ const { types } = babel;
38
+ return {
39
+ name: '@madenowhere/phaze-compile',
40
+ inherits: jsxSyntax.default ?? jsxSyntax,
41
+ visitor: {
42
+ JSXElement(path) {
43
+ const opening = path.node.openingElement;
44
+ if (isComponentJSX(opening.name)) {
45
+ // Component children — wrap unconditionally so the parent
46
+ // controls construction timing (error scopes, etc.).
47
+ wrapJSXChildren(path.node, types);
48
+ wrapJSXValuedProps(opening, types);
49
+ }
50
+ else {
51
+ // Host element — wrap individual expression-container
52
+ // children when the expression is conditional / logical /
53
+ // contains JSX. This makes `{cond ? <A/> : <B/>}` reactive
54
+ // without the user writing an explicit thunk.
55
+ wrapHostExpressionChildren(path.node, types);
56
+ }
57
+ },
58
+ JSXFragment(path) {
59
+ // Same expression-children rule for fragments.
60
+ wrapHostExpressionChildren(path.node, types);
61
+ },
62
+ },
63
+ };
64
+ };
65
+ const isComponentJSX = (name) => {
66
+ if (name.type === 'JSXIdentifier') {
67
+ // Capitalized identifier = component. (Lowercase = HTML host element.)
68
+ return /^[A-Z]/.test(name.name);
69
+ }
70
+ // Member expression like `Foo.Bar` — always treat as component.
71
+ return name.type === 'JSXMemberExpression';
72
+ };
73
+ const wrapJSXChildren = (el, types) => {
74
+ const children = el.children;
75
+ // Strip pure-whitespace JSXText (artifacts of JSX formatting).
76
+ const meaningful = children.filter((c) => {
77
+ if (c.type === 'JSXText' && c.value.trim() === '')
78
+ return false;
79
+ return true;
80
+ });
81
+ if (meaningful.length === 0)
82
+ return;
83
+ // If the only meaningful child is already a function expression,
84
+ // skip — user wrote the explicit form, leave it alone.
85
+ if (meaningful.length === 1) {
86
+ const only = meaningful[0];
87
+ if (only.type === 'JSXExpressionContainer') {
88
+ const expr = only.expression;
89
+ if (expr.type === 'ArrowFunctionExpression' ||
90
+ expr.type === 'FunctionExpression') {
91
+ return;
92
+ }
93
+ }
94
+ }
95
+ // Determine the body of the wrapping arrow:
96
+ // single non-text child → use that child directly as body
97
+ // multiple children → wrap in a JSX fragment
98
+ let body;
99
+ if (meaningful.length === 1) {
100
+ const only = meaningful[0];
101
+ if (only.type === 'JSXElement' || only.type === 'JSXFragment') {
102
+ body = only;
103
+ }
104
+ else if (only.type === 'JSXExpressionContainer') {
105
+ // {expr} as the only child — body is the expression
106
+ body = only.expression;
107
+ }
108
+ else if (only.type === 'JSXText') {
109
+ body = types.stringLiteral(only.value);
110
+ }
111
+ else {
112
+ // JSXSpreadChild — fall through to fragment
113
+ body = types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), children);
114
+ }
115
+ }
116
+ else {
117
+ body = types.jsxFragment(types.jsxOpeningFragment(), types.jsxClosingFragment(), children);
118
+ }
119
+ const arrow = types.arrowFunctionExpression([], body);
120
+ el.children = [types.jsxExpressionContainer(arrow)];
121
+ };
122
+ const wrapJSXValuedProps = (opening, types) => {
123
+ for (const attr of opening.attributes) {
124
+ if (attr.type !== 'JSXAttribute')
125
+ continue;
126
+ const val = attr.value;
127
+ if (!val)
128
+ continue;
129
+ if (val.type === 'JSXExpressionContainer') {
130
+ const expr = val.expression;
131
+ // JSXEmptyExpression is the placeholder Babel uses for things like
132
+ // `prop={}` — skip.
133
+ if (expr.type === 'JSXEmptyExpression')
134
+ continue;
135
+ // If the prop value is JSX, wrap it.
136
+ if (expr.type === 'JSXElement' || expr.type === 'JSXFragment') {
137
+ val.expression = types.arrowFunctionExpression([], expr);
138
+ }
139
+ }
140
+ // val could also be a StringLiteral (`prop="x"`) — leave untouched.
141
+ }
142
+ };
143
+ // Wrap host-element expression-container children when the expression
144
+ // looks like reactive control flow:
145
+ // {a ? <X/> : <Y/>} → {() => a ? <X/> : <Y/>}
146
+ // {a && <X/>} → {() => a && <X/>}
147
+ // {<X/>} → {() => <X/>}
148
+ // {fn() && data} → {() => fn() && data}
149
+ //
150
+ // Simple identifier / member / literal / call expressions stay
151
+ // unwrapped so `<div>{count}</div>` keeps its setText fast path
152
+ // (count is a signal — a function the runtime auto-detects and calls).
153
+ const wrapHostExpressionChildren = (el, types) => {
154
+ for (const child of el.children) {
155
+ if (child.type !== 'JSXExpressionContainer')
156
+ continue;
157
+ const expr = child.expression;
158
+ if (expr.type === 'JSXEmptyExpression')
159
+ continue;
160
+ // Already a function — leave it alone (idempotent).
161
+ if (expr.type === 'ArrowFunctionExpression' ||
162
+ expr.type === 'FunctionExpression') {
163
+ continue;
164
+ }
165
+ if (shouldWrapExpression(expr)) {
166
+ child.expression = types.arrowFunctionExpression([], expr);
167
+ }
168
+ }
169
+ };
170
+ const shouldWrapExpression = (expr) => {
171
+ if (expr.type === 'ConditionalExpression')
172
+ return true;
173
+ if (expr.type === 'LogicalExpression')
174
+ return true;
175
+ if (expr.type === 'JSXElement' || expr.type === 'JSXFragment')
176
+ return true;
177
+ return containsJSX(expr);
178
+ };
179
+ const containsJSX = (node) => {
180
+ if (!node || typeof node !== 'object')
181
+ return false;
182
+ if (Array.isArray(node)) {
183
+ for (const n of node)
184
+ if (containsJSX(n))
185
+ return true;
186
+ return false;
187
+ }
188
+ const n = node;
189
+ if (n.type === 'JSXElement' || n.type === 'JSXFragment')
190
+ return true;
191
+ for (const key of Object.keys(n)) {
192
+ if (key === 'loc' || key === 'start' || key === 'end' || key.startsWith('_'))
193
+ continue;
194
+ if (containsJSX(n[key]))
195
+ return true;
196
+ }
197
+ return false;
198
+ };
199
+ export default phaseCompile;
200
+ //# sourceMappingURL=babel-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin.js","sourceRoot":"","sources":["../src/babel-plugin.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,EAAE;AACF,uEAAuE;AACvE,kEAAkE;AAClE,qEAAqE;AACrE,wEAAwE;AACxE,mEAAmE;AACnE,4BAA4B;AAC5B,EAAE;AACF,2DAA2D;AAC3D,EAAE;AACF,kCAAkC;AAClC,EAAE;AACF,qEAAqE;AACrE,kDAAkD;AAClD,EAAE;AACF,0BAA0B;AAC1B,MAAM;AACN,kCAAkC;AAClC,EAAE;AACF,sEAAsE;AACtE,EAAE;AACF,6CAA6C;AAC7C,uDAAuD;AACvD,uEAAuE;AACvE,2BAA2B;AAC3B,EAAE;AACF,wEAAwE;AACxE,mEAA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MAAM,WAAW,GAAG,CAAC,IAAa,EAAW,EAAE;IAC7C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,IAAI,IAAI;YAAE,IAAI,WAAW,CAAC,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAA;QACrD,OAAO,KAAK,CAAA;IACd,CAAC;IACD,MAAM,CAAC,GAAG,IAA+C,CAAA;IACzD,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,aAAa;QAAE,OAAO,IAAI,CAAA;IACpE,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAQ;QACtF,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAAE,OAAO,IAAI,CAAA;IACtC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { default } from './babel-plugin.js';
2
+ export { default as vite } from './vite-plugin.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Public entry — re-exports both the Babel plugin (default) and the
2
+ // Vite plugin (named). Most users want the Vite plugin; library authors
3
+ // integrating with other build tools can import the Babel plugin
4
+ // directly from `@madenowhere/phaze-compile/babel-plugin`.
5
+ export { default } from './babel-plugin.js';
6
+ export { default as vite } from './vite-plugin.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,wEAAwE;AACxE,iEAAiE;AACjE,2DAA2D;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,11 @@
1
+ interface VitePlugin {
2
+ name: string;
3
+ enforce?: 'pre' | 'post';
4
+ transform: (code: string, id: string) => {
5
+ code: string;
6
+ map?: unknown;
7
+ } | null;
8
+ }
9
+ export default function phaseVitePlugin(): VitePlugin;
10
+ export {};
11
+ //# sourceMappingURL=vite-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAcA,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACxB,SAAS,EAAE,CACT,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,KACP;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;CAC5C;AAED,MAAM,CAAC,OAAO,UAAU,eAAe,IAAI,UAAU,CAwBpD"}
@@ -0,0 +1,38 @@
1
+ // Vite plugin wrapper around the Babel plugin.
2
+ //
3
+ // Runs before esbuild's JSX-to-jsx() transform (`enforce: 'pre'`) so by
4
+ // the time esbuild gets the source, component-JSX children have already
5
+ // been hoisted to thunks. Esbuild then converts the resulting JSX into
6
+ // `jsx()` calls as normal.
7
+ //
8
+ // File-scope: `.tsx` / `.jsx` only. Other files (`.ts`, `.js`, `.astro`)
9
+ // pass through untouched. The Babel parser is configured for both JSX
10
+ // and TypeScript syntax so `.tsx` works.
11
+ import { transformSync } from '@babel/core';
12
+ import phaseCompile from './babel-plugin.js';
13
+ export default function phaseVitePlugin() {
14
+ return {
15
+ name: '@madenowhere/phaze-compile',
16
+ enforce: 'pre',
17
+ transform(code, id) {
18
+ // Strip query strings (`?import`, `?worker`, etc.).
19
+ const path = id.split('?')[0] ?? id;
20
+ if (!/\.(tsx|jsx)$/.test(path))
21
+ return null;
22
+ const out = transformSync(code, {
23
+ babelrc: false,
24
+ configFile: false,
25
+ plugins: [phaseCompile],
26
+ parserOpts: { plugins: ['jsx', 'typescript'] },
27
+ // Keep JSX intact in the output — esbuild will run its own
28
+ // JSX-to-jsx() pass downstream.
29
+ filename: path,
30
+ sourceMaps: true,
31
+ });
32
+ if (!out?.code)
33
+ return null;
34
+ return { code: out.code, map: out.map ?? undefined };
35
+ },
36
+ };
37
+ }
38
+ //# sourceMappingURL=vite-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,uEAAuE;AACvE,2BAA2B;AAC3B,EAAE;AACF,yEAAyE;AACzE,sEAAsE;AACtE,yCAAyC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAW5C,MAAM,CAAC,OAAO,UAAU,eAAe;IACrC,OAAO;QACL,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,oDAAoD;YACpD,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;YACnC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAA;YAE3C,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,EAAE;gBAC9B,OAAO,EAAE,KAAK;gBACd,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,YAAY,CAAC;gBACvB,UAAU,EAAE,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE;gBAC9C,2DAA2D;gBAC3D,gCAAgC;gBAChC,QAAQ,EAAE,IAAI;gBACd,UAAU,EAAE,IAAI;aACjB,CAAC,CAAA;YAEF,IAAI,CAAC,GAAG,EAAE,IAAI;gBAAE,OAAO,IAAI,CAAA;YAC3B,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,SAAS,EAAE,CAAA;QACtD,CAAC;KACF,CAAA;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@madenowhere/phaze-compile",
3
+ "version": "0.0.3",
4
+ "description": "Compiler for Phaze JSX — hoists component children to thunks so user code matches React/Preact JSX shape",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "madenowhere",
8
+ "homepage": "https://phaze.build",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/madenowhere/phaze.git",
12
+ "directory": "packages/compile"
13
+ },
14
+ "bugs": "https://github.com/madenowhere/phaze/issues",
15
+ "sideEffects": false,
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ },
24
+ "./babel-plugin": {
25
+ "types": "./dist/babel-plugin.d.ts",
26
+ "import": "./dist/babel-plugin.js"
27
+ },
28
+ "./vite": {
29
+ "types": "./dist/vite-plugin.d.ts",
30
+ "import": "./dist/vite-plugin.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "engines": {
39
+ "node": ">=25"
40
+ },
41
+ "dependencies": {
42
+ "@babel/core": "^7.26.0",
43
+ "@babel/plugin-syntax-jsx": "^7.25.9"
44
+ },
45
+ "devDependencies": {
46
+ "@babel/preset-typescript": "^7.26.0",
47
+ "@babel/types": "^7.26.0",
48
+ "@types/babel__core": "^7.20.5"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc -p tsconfig.json",
52
+ "dev": "tsc -p tsconfig.json --watch"
53
+ }
54
+ }