@fluixi/compiler 1.0.0-alpha.75 → 1.0.0-alpha.76
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/intrinsics.cjs +1 -0
- package/dist/analyze/intrinsics.d.ts +67 -0
- package/dist/analyze/intrinsics.d.ts.map +1 -0
- package/dist/analyze/intrinsics.js +91 -0
- package/dist/analyze/intrinsics.mjs +1 -0
- package/dist/analyze/props-destructure.cjs +1 -0
- package/dist/analyze/props-destructure.d.ts +84 -0
- package/dist/analyze/props-destructure.d.ts.map +1 -0
- package/dist/analyze/props-destructure.js +272 -0
- package/dist/analyze/props-destructure.mjs +1 -0
- package/dist/analyze/reactive-bindings.cjs +1 -0
- package/dist/analyze/reactive-bindings.d.ts +34 -0
- package/dist/analyze/reactive-bindings.d.ts.map +1 -0
- package/dist/analyze/reactive-bindings.js +153 -0
- package/dist/analyze/reactive-bindings.mjs +1 -0
- package/dist/{babel-GXO3KAVI.mjs → babel-YQ42WUS3.mjs} +1 -1
- package/dist/chunk-545LMC5W.mjs +1 -0
- package/dist/{chunk-TIE4XNAM.mjs → chunk-L2QPV25P.mjs} +1 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1 -1
- package/dist/frontend/babel/build-ir-lit.mjs +1 -1
- package/dist/frontend/babel/build-ir.cjs +1 -1
- package/dist/frontend/babel/build-ir.mjs +1 -1
- package/dist/frontend/babel/index.cjs +1 -1
- package/dist/frontend/babel/index.mjs +1 -1
- package/dist/frontend/babel/lower-template.cjs +1 -1
- package/dist/frontend/babel/lower-template.mjs +1 -1
- package/dist/frontend/babel/plugin.cjs +1 -1
- package/dist/frontend/babel/plugin.mjs +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.mjs +9 -9
- package/dist/integrations.cjs +18 -14
- package/dist/integrations.d.ts +14 -0
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +16 -1
- package/dist/integrations.mjs +11 -11
- package/dist/lower/compile-template.cjs +1 -1
- package/dist/lower/compile-template.mjs +1 -1
- package/dist/lower/template.cjs +1 -1
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +7 -5
- package/dist/lower/template.mjs +1 -1
- package/dist/resolve/component-globals.cjs +9 -9
- package/dist/resolve/component-globals.d.ts +8 -0
- package/dist/resolve/component-globals.d.ts.map +1 -1
- package/dist/resolve/component-globals.js +17 -3
- package/dist/resolve/component-globals.mjs +9 -9
- package/dist/resolve/write-globals.cjs +9 -9
- package/dist/resolve/write-globals.mjs +9 -9
- package/dist/transform/index.cjs +5 -1
- package/dist/transform/index.d.ts +4 -0
- package/dist/transform/index.d.ts.map +1 -1
- package/dist/transform/index.js +2 -0
- package/dist/transform/index.mjs +14 -10
- package/dist/transform/intrinsics.cjs +3 -0
- package/dist/transform/intrinsics.d.ts +22 -0
- package/dist/transform/intrinsics.d.ts.map +1 -0
- package/dist/transform/intrinsics.js +78 -0
- package/dist/transform/intrinsics.mjs +3 -0
- package/dist/transform/props.cjs +3 -0
- package/dist/transform/props.d.ts +46 -0
- package/dist/transform/props.d.ts.map +1 -0
- package/dist/transform/props.js +221 -0
- package/dist/transform/props.mjs +12 -0
- package/dist/transform/templates.cjs +4 -1
- package/dist/transform/templates.d.ts +20 -0
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +41 -6
- package/dist/transform/templates.mjs +13 -10
- package/dist/transform-ZWIHEZVN.mjs +7 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/transform-PJX2GNSV.mjs +0 -3
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite destructured component props into property reads.
|
|
3
|
+
*
|
|
4
|
+
* `function Card({ title, size = 'md' })` becomes `function Card(props)` with `title`
|
|
5
|
+
* rewritten to `props.title` wherever it's used, so the reads stay live. What can't be
|
|
6
|
+
* rewritten is left alone and reported — see analyze/props-destructure for the rules.
|
|
7
|
+
*
|
|
8
|
+
* Source in, source out, spans spliced with magic-string, so the author's formatting
|
|
9
|
+
* survives and the map comes out of the splice. It runs before templates are compiled,
|
|
10
|
+
* which is what makes JSX and html`` behave the same: both end up reading `props.title`
|
|
11
|
+
* from the same rewritten body, and neither one needs to know this happened.
|
|
12
|
+
*/
|
|
13
|
+
import { parse } from '@babel/parser';
|
|
14
|
+
import MagicString from 'magic-string';
|
|
15
|
+
import { planPropsDestructure, explainBail } from '../analyze/props-destructure.js';
|
|
16
|
+
import { moduleBindings } from './bindings.js';
|
|
17
|
+
/** Walk everything under a node. Skips TS annotations, where a name isn't a value. */
|
|
18
|
+
function walk(root, visit, parent = null) {
|
|
19
|
+
if (!root || typeof root !== 'object' || typeof root.type !== 'string')
|
|
20
|
+
return;
|
|
21
|
+
if (root.type.startsWith('TS'))
|
|
22
|
+
return;
|
|
23
|
+
if (visit(root, parent) === false)
|
|
24
|
+
return;
|
|
25
|
+
for (const key of Object.keys(root)) {
|
|
26
|
+
if (key === 'loc' || key === 'leadingComments' || key === 'trailingComments')
|
|
27
|
+
continue;
|
|
28
|
+
const value = root[key];
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
for (const item of value)
|
|
31
|
+
walk(item, visit, root);
|
|
32
|
+
}
|
|
33
|
+
else if (value && typeof value === 'object') {
|
|
34
|
+
walk(value, visit, root);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** A component by the same rule JSX uses: a capitalised name. */
|
|
39
|
+
function isComponentName(name) {
|
|
40
|
+
return !!name && name[0] >= 'A' && name[0] <= 'Z';
|
|
41
|
+
}
|
|
42
|
+
/** Component functions in a module, paired with the name they were declared under. */
|
|
43
|
+
function componentFunctions(program) {
|
|
44
|
+
const found = [];
|
|
45
|
+
walk(program, (node) => {
|
|
46
|
+
if (node.type === 'FunctionDeclaration' && isComponentName(node.id?.name)) {
|
|
47
|
+
found.push(node);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (node.type === 'VariableDeclarator' && isComponentName(node.id?.name)) {
|
|
51
|
+
const init = node.init;
|
|
52
|
+
if (init && (init.type === 'ArrowFunctionExpression' || init.type === 'FunctionExpression'))
|
|
53
|
+
found.push(init);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return found;
|
|
57
|
+
}
|
|
58
|
+
/** Names used anywhere in a function, so the parameter we introduce doesn't collide. */
|
|
59
|
+
function usedNames(fn) {
|
|
60
|
+
const names = new Set();
|
|
61
|
+
walk(fn, (node) => {
|
|
62
|
+
if (node.type === 'Identifier')
|
|
63
|
+
names.add(node.name);
|
|
64
|
+
});
|
|
65
|
+
return names;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Positions where an identifier isn't a reference to the binding: a property name, a
|
|
69
|
+
* non-computed object key, a label. A shorthand property is handled by the caller,
|
|
70
|
+
* since it needs the key written out.
|
|
71
|
+
*/
|
|
72
|
+
function isReferencePosition(node, parent) {
|
|
73
|
+
if (!parent)
|
|
74
|
+
return true;
|
|
75
|
+
switch (parent.type) {
|
|
76
|
+
case 'MemberExpression':
|
|
77
|
+
case 'OptionalMemberExpression':
|
|
78
|
+
return !(parent.property === node && !parent.computed);
|
|
79
|
+
case 'ObjectProperty':
|
|
80
|
+
case 'ObjectMethod':
|
|
81
|
+
case 'ClassProperty':
|
|
82
|
+
case 'ClassMethod':
|
|
83
|
+
return !(parent.key === node && !parent.computed);
|
|
84
|
+
case 'LabeledStatement':
|
|
85
|
+
case 'BreakStatement':
|
|
86
|
+
case 'ContinueStatement':
|
|
87
|
+
return parent.label !== node;
|
|
88
|
+
case 'ImportSpecifier':
|
|
89
|
+
case 'ExportSpecifier':
|
|
90
|
+
return false;
|
|
91
|
+
default:
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Work out the edits without applying them, so a caller that already has the source in a
|
|
97
|
+
* MagicString can fold them into its own. That's how the template transform picks this
|
|
98
|
+
* up: one string, one map, and holes get the rewrite because it slices them with the
|
|
99
|
+
* edits applied.
|
|
100
|
+
*/
|
|
101
|
+
export function collectPropsEdits(program, code, options = {}) {
|
|
102
|
+
const edits = [];
|
|
103
|
+
const diagnostics = [];
|
|
104
|
+
const used = new Set();
|
|
105
|
+
for (const fn of componentFunctions(program)) {
|
|
106
|
+
const pattern = fn.params?.[0];
|
|
107
|
+
if (pattern?.type !== 'ObjectPattern')
|
|
108
|
+
continue;
|
|
109
|
+
const plan = planPropsDestructure(pattern, fn.body);
|
|
110
|
+
for (const b of plan.bails) {
|
|
111
|
+
diagnostics.push({ name: b.name, reason: b.reason, message: explainBail(b.reason), start: pattern.start });
|
|
112
|
+
}
|
|
113
|
+
// Whole function or nothing: half a rewrite would read as if the rest were fine too.
|
|
114
|
+
if (plan.bails.length > 0)
|
|
115
|
+
continue;
|
|
116
|
+
if (plan.reads.length === 0 && !plan.rest)
|
|
117
|
+
continue;
|
|
118
|
+
const taken = usedNames(fn);
|
|
119
|
+
let parameter = options.parameterName ?? 'props';
|
|
120
|
+
while (taken.has(parameter))
|
|
121
|
+
parameter = `_${parameter}`;
|
|
122
|
+
const replacement = new Map();
|
|
123
|
+
for (const read of plan.reads) {
|
|
124
|
+
const access = `${parameter}.${read.path.join('.')}`;
|
|
125
|
+
const fallback = read.fallback;
|
|
126
|
+
// A default only applies to `undefined`, so this can't collapse to `??`.
|
|
127
|
+
replacement.set(read.name, fallback ? `(${access} === undefined ? ${code.slice(fallback.start, fallback.end)} : ${access})` : access);
|
|
128
|
+
}
|
|
129
|
+
// The pattern's range covers its type annotation, so overwriting the whole span
|
|
130
|
+
// would take `: { title: string }` with it. Stop at the annotation and the type
|
|
131
|
+
// stays exactly as written.
|
|
132
|
+
const annotation = pattern.typeAnnotation;
|
|
133
|
+
edits.push({ start: pattern.start, end: annotation?.start ?? pattern.end, code: parameter });
|
|
134
|
+
// `...rest` becomes the splitProps call the author would have written. splitProps
|
|
135
|
+
// carries the getters over instead of reading them, which is the whole reason a
|
|
136
|
+
// plain rest can't be rewritten — so this hands the job to the runtime helper that
|
|
137
|
+
// does it properly rather than refusing the pattern.
|
|
138
|
+
if (plan.rest) {
|
|
139
|
+
const keys = plan.rest.keys.map((k) => JSON.stringify(k)).join(', ');
|
|
140
|
+
const body = fn.body;
|
|
141
|
+
edits.push({
|
|
142
|
+
start: body.start + 1,
|
|
143
|
+
end: body.start + 1,
|
|
144
|
+
code: `\n const [, ${plan.rest.name}] = splitProps(${parameter}, [${keys}]);`,
|
|
145
|
+
});
|
|
146
|
+
used.add('splitProps');
|
|
147
|
+
}
|
|
148
|
+
// Collect first, rewrite after: turning a node into a member below gives it new
|
|
149
|
+
// children, and a walk still in progress would descend into them and match again.
|
|
150
|
+
const matches = [];
|
|
151
|
+
walk(fn.body, (node, parent) => {
|
|
152
|
+
if (node.type !== 'Identifier')
|
|
153
|
+
return undefined;
|
|
154
|
+
const text = replacement.get(node.name);
|
|
155
|
+
if (!text)
|
|
156
|
+
return undefined;
|
|
157
|
+
const shorthand = parent?.type === 'ObjectProperty' && parent.shorthand && parent.value === node;
|
|
158
|
+
if (!shorthand && !isReferencePosition(node, parent))
|
|
159
|
+
return undefined;
|
|
160
|
+
const path = plan.reads.find((r) => r.name === node.name).path;
|
|
161
|
+
matches.push({ node, parent: shorthand ? parent : null, text, property: path[path.length - 1] });
|
|
162
|
+
return undefined;
|
|
163
|
+
});
|
|
164
|
+
for (const match of matches) {
|
|
165
|
+
if (match.parent) {
|
|
166
|
+
// `{ name }` needs the key spelled out, or the result isn't an object literal.
|
|
167
|
+
edits.push({ start: match.parent.start, end: match.parent.end, code: `${match.node.name}: ${match.text}` });
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
edits.push({ start: match.node.start, end: match.node.end, code: match.text });
|
|
171
|
+
}
|
|
172
|
+
// Say it in the AST too, not only in the text. Whether a hole is wired reactively
|
|
173
|
+
// is decided from the expression's shape, and a bare identifier is not reactive —
|
|
174
|
+
// so leaving the node as an Identifier emits `props.text` read once, which is the
|
|
175
|
+
// bug this whole pass exists to remove. A member read is reactive, which is what
|
|
176
|
+
// the emitted code now is.
|
|
177
|
+
asMemberRead(match.node, parameter, match.property);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return { edits, diagnostics, used };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Rewrite an identifier node into `<parameter>.<property>` in place, keeping its span so
|
|
184
|
+
* the text it maps to is unchanged. The synthetic children are zero-width at the node's
|
|
185
|
+
* own edges: nothing slices them, and they exist so shape analysis sees a member.
|
|
186
|
+
*/
|
|
187
|
+
function asMemberRead(node, parameter, property) {
|
|
188
|
+
node.type = 'MemberExpression';
|
|
189
|
+
node.computed = false;
|
|
190
|
+
node.optional = false;
|
|
191
|
+
node.object = { type: 'Identifier', name: parameter, start: node.start, end: node.start };
|
|
192
|
+
node.property = { type: 'Identifier', name: property, start: node.end, end: node.end };
|
|
193
|
+
delete node['name'];
|
|
194
|
+
}
|
|
195
|
+
/** Run the rewrite on its own. The template transform folds the edits in instead. */
|
|
196
|
+
export function transformProps(code, filename = 'module.tsx', options = {}) {
|
|
197
|
+
const ast = parse(code, {
|
|
198
|
+
sourceType: 'module',
|
|
199
|
+
plugins: ['typescript', 'jsx'],
|
|
200
|
+
errorRecovery: true,
|
|
201
|
+
});
|
|
202
|
+
const { edits, diagnostics, used } = collectPropsEdits(ast.program, code, options);
|
|
203
|
+
const source = new MagicString(code);
|
|
204
|
+
for (const e of edits) {
|
|
205
|
+
if (e.start === e.end)
|
|
206
|
+
source.appendLeft(e.start, e.code);
|
|
207
|
+
else
|
|
208
|
+
source.overwrite(e.start, e.end, e.code);
|
|
209
|
+
}
|
|
210
|
+
// Standalone, there's no prologue to join, so the import goes in here — unless the
|
|
211
|
+
// module already has the name bound.
|
|
212
|
+
if (used.has('splitProps') && !moduleBindings(ast.program).has('splitProps')) {
|
|
213
|
+
source.prepend(`import { splitProps } from ${JSON.stringify(options.runtimeModule ?? '@fluixi/dom')};\n`);
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
code: source.toString(),
|
|
217
|
+
map: source.generateMap({ source: filename, includeContent: true, hires: true }),
|
|
218
|
+
diagnostics,
|
|
219
|
+
rewritten: edits.filter((e) => e.code !== (options.parameterName ?? 'props')).length,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{parse as se}from"@babel/parser";var W=44,z=59,_="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",D=new Uint8Array(64),H=new Uint8Array(128);for(let s=0;s<_.length;s++){let e=_.charCodeAt(s);D[s]=e,H[e]=s}function b(s,e,t){let n=e-t;n=n<0?-n<<1|1:n<<1;do{let i=n&31;n>>>=5,n>0&&(i|=32),s.write(D[i])}while(n>0);return e}var j=1024*16,A=typeof TextDecoder<"u"?new TextDecoder:typeof Buffer<"u"?{decode(s){return Buffer.from(s.buffer,s.byteOffset,s.byteLength).toString()}}:{decode(s){let e="";for(let t=0;t<s.length;t++)e+=String.fromCharCode(s[t]);return e}},Y=class{constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(j)}write(s){let{buffer:e}=this;e[this.pos++]=s,this.pos===j&&(this.out+=A.decode(e),this.pos=0)}flush(){let{buffer:s,out:e,pos:t}=this;return t>0?e+A.decode(s.subarray(0,t)):e}};function $(s){let e=new Y,t=0,n=0,i=0,r=0;for(let o=0;o<s.length;o++){let a=s[o];if(o>0&&e.write(z),a.length===0)continue;let l=0;for(let u=0;u<a.length;u++){let h=a[u];u>0&&e.write(W),l=b(e,h[0],l),h.length!==1&&(t=b(e,h[1],t),n=b(e,h[2],n),i=b(e,h[3],i),h.length!==4&&(r=b(e,h[4],r)))}}return e.flush()}var C=class s{constructor(e){this.bits=e instanceof s?e.bits.slice():[]}add(e){this.bits[e>>5]|=1<<(e&31)}has(e){return!!(this.bits[e>>5]&1<<(e&31))}},x=class s{constructor(e,t,n){this.start=e,this.end=t,this.original=n,this.intro="",this.outro="",this.content=n,this.storeName=!1,this.edited=!1,this.previous=null,this.next=null}appendLeft(e){this.outro+=e}appendRight(e){this.intro=this.intro+e}clone(){let e=new s(this.start,this.end,this.original);return e.intro=this.intro,e.outro=this.outro,e.content=this.content,e.storeName=this.storeName,e.edited=this.edited,e}contains(e){return this.start<e&&e<this.end}eachNext(e){let t=this;for(;t;)e(t),t=t.next}eachPrevious(e){let t=this;for(;t;)e(t),t=t.previous}edit(e,t,n){return this.content=e,n||(this.intro="",this.outro=""),this.storeName=t,this.edited=!0,this}prependLeft(e){this.outro=e+this.outro}prependRight(e){this.intro=e+this.intro}reset(){this.intro="",this.outro="",this.edited&&(this.content=this.original,this.storeName=!1,this.edited=!1)}split(e){let t=e-this.start,n=this.original.slice(0,t),i=this.original.slice(t);this.original=n;let r=new s(e,this.end,i);return r.outro=this.outro,this.outro="",this.end=e,this.edited?(r.edit("",!1),this.content=""):this.content=n,r.next=this.next,r.next&&(r.next.previous=r),r.previous=this,this.next=r,r}toString(){return this.intro+this.content+this.outro}trimEnd(e){if(this.outro=this.outro.replace(e,""),this.outro.length)return!0;let t=this.content.replace(e,"");if(t.length)return t!==this.content&&(this.split(this.start+t.length).edit("",void 0,!0),this.edited&&this.edit(t,this.storeName,!0)),!0;if(this.edit("",void 0,!0),this.intro=this.intro.replace(e,""),this.intro.length)return!0}trimStart(e){if(this.intro=this.intro.replace(e,""),this.intro.length)return!0;let t=this.content.replace(e,"");if(t.length){if(t!==this.content){let n=this.split(this.end-t.length);this.edited&&n.edit(t,this.storeName,!0),this.edit("",void 0,!0)}return!0}else if(this.edit("",void 0,!0),this.outro=this.outro.replace(e,""),this.outro.length)return!0}};function Z(){return typeof globalThis<"u"&&typeof globalThis.btoa=="function"?s=>globalThis.btoa(unescape(encodeURIComponent(s))):typeof Buffer=="function"?s=>Buffer.from(s,"utf-8").toString("base64"):()=>{throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.")}}var K=Z(),k=class{constructor(e){this.version=3,this.file=e.file,this.sources=e.sources,this.sourcesContent=e.sourcesContent,this.names=e.names,this.mappings=$(e.mappings),typeof e.x_google_ignoreList<"u"&&(this.x_google_ignoreList=e.x_google_ignoreList),typeof e.debugId<"u"&&(this.debugId=e.debugId)}toString(){return JSON.stringify(this)}toUrl(){return"data:application/json;charset=utf-8;base64,"+K(this.toString())}};function Q(s){let e=s.split(`
|
|
2
|
+
`),t=e.filter(r=>/^\t+/.test(r)),n=e.filter(r=>/^ {2,}/.test(r));if(t.length===0&&n.length===0)return null;if(t.length>=n.length)return" ";let i=n.reduce((r,o)=>{let a=/^ +/.exec(o)[0].length;return Math.min(a,r)},1/0);return new Array(i+1).join(" ")}function X(s,e){let t=s.split(/[/\\]/),n=e.split(/[/\\]/);for(t.pop();t[0]===n[0];)t.shift(),n.shift();if(t.length){let i=t.length;for(;i--;)t[i]=".."}return t.concat(n).join("/")}var V=Object.prototype.toString;function ee(s){return V.call(s)==="[object Object]"}function B(s){let e=s.split(`
|
|
3
|
+
`),t=[];for(let n=0,i=0;n<e.length;n++)t.push(i),i+=e[n].length+1;return function(i){let r=0,o=t.length;for(;r<o;){let u=r+o>>1;i<t[u]?o=u:r=u+1}let a=r-1,l=i-t[a];return{line:a,column:l}}}var te=/\w/,L=class{constructor(e){this.hires=e,this.generatedCodeLine=0,this.generatedCodeColumn=0,this.raw=[],this.rawSegments=this.raw[this.generatedCodeLine]=[],this.pending=null}addEdit(e,t,n,i){if(t.length){let r=t.length-1,o=t.indexOf(`
|
|
4
|
+
`,0),a=-1;for(;o>=0&&r>o;){let u=[this.generatedCodeColumn,e,n.line,n.column];i>=0&&u.push(i),this.rawSegments.push(u),this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=o,o=t.indexOf(`
|
|
5
|
+
`,o+1)}let l=[this.generatedCodeColumn,e,n.line,n.column];i>=0&&l.push(i),this.rawSegments.push(l),this.advance(t.slice(a+1))}else this.pending&&(this.rawSegments.push(this.pending),this.advance(t));this.pending=null}addUneditedChunk(e,t,n,i,r){let o=t.start,a=!0,l=!1;for(;o<t.end;){if(n[o]===`
|
|
6
|
+
`)i.line+=1,i.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=!0,l=!1;else{if(this.hires||a||r.has(o)){let u=[this.generatedCodeColumn,e,i.line,i.column];this.hires==="boundary"?te.test(n[o])?l||(this.rawSegments.push(u),l=!0):(this.rawSegments.push(u),l=!1):this.rawSegments.push(u)}i.column+=1,this.generatedCodeColumn+=1,a=!1}o+=1}this.pending=null}advance(e){if(!e)return;let t=e.split(`
|
|
7
|
+
`);if(t.length>1){for(let n=0;n<t.length-1;n++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=t[t.length-1].length}},y=`
|
|
8
|
+
`,w={insertLeft:!1,insertRight:!1,storeName:!1},N=class s{constructor(e,t={}){let n=new x(0,e.length,e);Object.defineProperties(this,{original:{writable:!0,value:e},outro:{writable:!0,value:""},intro:{writable:!0,value:""},firstChunk:{writable:!0,value:n},lastChunk:{writable:!0,value:n},lastSearchedChunk:{writable:!0,value:n},byStart:{writable:!0,value:{}},byEnd:{writable:!0,value:{}},filename:{writable:!0,value:t.filename},indentExclusionRanges:{writable:!0,value:t.indentExclusionRanges},sourcemapLocations:{writable:!0,value:new C},storedNames:{writable:!0,value:{}},indentStr:{writable:!0,value:void 0},ignoreList:{writable:!0,value:t.ignoreList},offset:{writable:!0,value:t.offset||0}}),this.byStart[0]=n,this.byEnd[e.length]=n}addSourcemapLocation(e){this.sourcemapLocations.add(e)}append(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.outro+=e,this}appendLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byEnd[e];return n?n.appendLeft(t):this.intro+=t,this}appendRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byStart[e];return n?n.appendRight(t):this.outro+=t,this}clone(){let e=new s(this.original,{filename:this.filename,offset:this.offset}),t=this.firstChunk,n=e.firstChunk=e.lastSearchedChunk=t.clone();for(;t;){e.byStart[n.start]=n,e.byEnd[n.end]=n;let i=t.next,r=i&&i.clone();r&&(n.next=r,r.previous=n,n=r),t=i}return e.lastChunk=n,this.indentExclusionRanges&&(e.indentExclusionRanges=this.indentExclusionRanges.slice()),e.sourcemapLocations=new C(this.sourcemapLocations),e.intro=this.intro,e.outro=this.outro,e}generateDecodedMap(e){e=e||{};let t=0,n=Object.keys(this.storedNames),i=new L(e.hires),r=B(this.original);return this.intro&&i.advance(this.intro),this.firstChunk.eachNext(o=>{let a=r(o.start);o.intro.length&&i.advance(o.intro),o.edited?i.addEdit(t,o.content,a,o.storeName?n.indexOf(o.original):-1):i.addUneditedChunk(t,o,this.original,a,this.sourcemapLocations),o.outro.length&&i.advance(o.outro)}),this.outro&&i.advance(this.outro),{file:e.file?e.file.split(/[/\\]/).pop():void 0,sources:[e.source?X(e.file||"",e.source):e.file||""],sourcesContent:e.includeContent?[this.original]:void 0,names:n,mappings:i.raw,x_google_ignoreList:this.ignoreList?[t]:void 0}}generateMap(e){return new k(this.generateDecodedMap(e))}_ensureindentStr(){this.indentStr===void 0&&(this.indentStr=Q(this.original))}_getRawIndentString(){return this._ensureindentStr(),this.indentStr}getIndentString(){return this._ensureindentStr(),this.indentStr===null?" ":this.indentStr}indent(e,t){let n=/^[^\r\n]/gm;if(ee(e)&&(t=e,e=void 0),e===void 0&&(this._ensureindentStr(),e=this.indentStr||" "),e==="")return this;t=t||{};let i={};t.exclude&&(typeof t.exclude[0]=="number"?[t.exclude]:t.exclude).forEach(h=>{for(let f=h[0];f<h[1];f+=1)i[f]=!0});let r=t.indentStart!==!1,o=u=>r?`${e}${u}`:(r=!0,u);this.intro=this.intro.replace(n,o);let a=0,l=this.firstChunk;for(;l;){let u=l.end;if(l.edited)i[a]||(l.content=l.content.replace(n,o),l.content.length&&(r=l.content[l.content.length-1]===`
|
|
9
|
+
`));else for(a=l.start;a<u;){if(!i[a]){let h=this.original[a];h===`
|
|
10
|
+
`?r=!0:h!=="\r"&&r&&(r=!1,a===l.start||(this._splitChunk(l,a),l=l.next),l.prependRight(e))}a+=1}a=l.end,l=l.next}return this.outro=this.outro.replace(n,o),this}insert(){throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)")}insertLeft(e,t){return w.insertLeft||(console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"),w.insertLeft=!0),this.appendLeft(e,t)}insertRight(e,t){return w.insertRight||(console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"),w.insertRight=!0),this.prependRight(e,t)}move(e,t,n){if(e=e+this.offset,t=t+this.offset,n=n+this.offset,n>=e&&n<=t)throw new Error("Cannot move a selection inside itself");this._split(e),this._split(t),this._split(n);let i=this.byStart[e],r=this.byEnd[t],o=i.previous,a=r.next,l=this.byStart[n];if(!l&&r===this.lastChunk)return this;let u=l?l.previous:this.lastChunk;return o&&(o.next=a),a&&(a.previous=o),u&&(u.next=i),l&&(l.previous=r),i.previous||(this.firstChunk=r.next),r.next||(this.lastChunk=i.previous,this.lastChunk.next=null),i.previous=u,r.next=l||null,u||(this.firstChunk=i),l||(this.lastChunk=r),this}overwrite(e,t,n,i){return i=i||{},this.update(e,t,n,{...i,overwrite:!i.contentOnly})}update(e,t,n,i){if(e=e+this.offset,t=t+this.offset,typeof n!="string")throw new TypeError("replacement content must be a string");if(this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(t>this.original.length)throw new Error("end is out of bounds");if(e===t)throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");this._split(e),this._split(t),i===!0&&(w.storeName||(console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"),w.storeName=!0),i={storeName:!0});let r=i!==void 0?i.storeName:!1,o=i!==void 0?i.overwrite:!1;if(r){let u=this.original.slice(e,t);Object.defineProperty(this.storedNames,u,{writable:!0,value:!0,enumerable:!0})}let a=this.byStart[e],l=this.byEnd[t];if(a){let u=a;for(;u!==l;){if(u.next!==this.byStart[u.end])throw new Error("Cannot overwrite across a split point");u=u.next,u.edit("",!1)}a.edit(n,r,!o)}else{let u=new x(e,t,"").edit(n,r);l.next=u,u.previous=l}return this}prepend(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.intro=e+this.intro,this}prependLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byEnd[e];return n?n.prependLeft(t):this.intro=t+this.intro,this}prependRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let n=this.byStart[e];return n?n.prependRight(t):this.outro=t+this.outro,this}remove(e,t){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.intro="",n.outro="",n.edit(""),n=t>n.end?this.byStart[n.end]:null;return this}reset(e,t){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.reset(),n=t>n.end?this.byStart[n.end]:null;return this}lastChar(){if(this.outro.length)return this.outro[this.outro.length-1];let e=this.lastChunk;do{if(e.outro.length)return e.outro[e.outro.length-1];if(e.content.length)return e.content[e.content.length-1];if(e.intro.length)return e.intro[e.intro.length-1]}while(e=e.previous);return this.intro.length?this.intro[this.intro.length-1]:""}lastLine(){let e=this.outro.lastIndexOf(y);if(e!==-1)return this.outro.substr(e+1);let t=this.outro,n=this.lastChunk;do{if(n.outro.length>0){if(e=n.outro.lastIndexOf(y),e!==-1)return n.outro.substr(e+1)+t;t=n.outro+t}if(n.content.length>0){if(e=n.content.lastIndexOf(y),e!==-1)return n.content.substr(e+1)+t;t=n.content+t}if(n.intro.length>0){if(e=n.intro.lastIndexOf(y),e!==-1)return n.intro.substr(e+1)+t;t=n.intro+t}}while(n=n.previous);return e=this.intro.lastIndexOf(y),e!==-1?this.intro.substr(e+1)+t:this.intro+t}slice(e=0,t=this.original.length-this.offset){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}let n="",i=this.firstChunk;for(;i&&(i.start>e||i.end<=e);){if(i.start<t&&i.end>=t)return n;i=i.next}if(i&&i.edited&&i.start!==e)throw new Error(`Cannot use replaced character ${e} as slice start anchor.`);let r=i;for(;i;){i.intro&&(r!==i||i.start===e)&&(n+=i.intro);let o=i.start<t&&i.end>=t;if(o&&i.edited&&i.end!==t)throw new Error(`Cannot use replaced character ${t} as slice end anchor.`);let a=r===i?e-i.start:0,l=o?i.content.length+t-i.end:i.content.length;if(n+=i.content.slice(a,l),i.outro&&(!o||i.end===t)&&(n+=i.outro),o)break;i=i.next}return n}snip(e,t){let n=this.clone();return n.remove(0,e),n.remove(t,n.original.length),n}_split(e){if(this.byStart[e]||this.byEnd[e])return;let t=this.lastSearchedChunk,n=t,i=e>t.end;for(;t;){if(t.contains(e))return this._splitChunk(t,e);if(t=i?this.byStart[t.end]:this.byEnd[t.start],t===n)return;n=t}}_splitChunk(e,t){if(e.edited&&e.content.length){let i=B(this.original)(t);throw new Error(`Cannot split a chunk that has already been edited (${i.line}:${i.column} – "${e.original}")`)}let n=e.split(t);return this.byEnd[t]=e,this.byStart[t]=n,this.byEnd[n.end]=n,e===this.lastChunk&&(this.lastChunk=n),this.lastSearchedChunk=e,!0}toString(){let e=this.intro,t=this.firstChunk;for(;t;)e+=t.toString(),t=t.next;return e+this.outro}isEmpty(){let e=this.firstChunk;do if(e.intro.length&&e.intro.trim()||e.content.length&&e.content.trim()||e.outro.length&&e.outro.trim())return!1;while(e=e.next);return!0}length(){let e=this.firstChunk,t=0;do t+=e.intro.length+e.content.length+e.outro.length;while(e=e.next);return t}trimLines(){return this.trim("[\\r\\n]")}trim(e){return this.trimStart(e).trimEnd(e)}trimEndAborted(e){let t=new RegExp((e||"\\s")+"+$");if(this.outro=this.outro.replace(t,""),this.outro.length)return!0;let n=this.lastChunk;do{let i=n.end,r=n.trimEnd(t);if(n.end!==i&&(this.lastChunk===n&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.previous}while(n);return!1}trimEnd(e){return this.trimEndAborted(e),this}trimStartAborted(e){let t=new RegExp("^"+(e||"\\s")+"+");if(this.intro=this.intro.replace(t,""),this.intro.length)return!0;let n=this.firstChunk;do{let i=n.end,r=n.trimStart(t);if(n.end!==i&&(n===this.lastChunk&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.next}while(n);return!1}trimStart(e){return this.trimStartAborted(e),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(e,t){function n(r,o){return typeof t=="string"?t.replace(/\$(\$|&|\d+)/g,(a,l)=>l==="$"?"$":l==="&"?r[0]:+l<r.length?r[+l]:`$${l}`):t(...r,r.index,o,r.groups)}function i(r,o){let a,l=[];for(;a=r.exec(o);)l.push(a);return l}if(e.global)i(e,this.original).forEach(o=>{if(o.index!=null){let a=n(o,this.original);a!==o[0]&&this.overwrite(o.index,o.index+o[0].length,a)}});else{let r=this.original.match(e);if(r&&r.index!=null){let o=n(r,this.original);o!==r[0]&&this.overwrite(r.index,r.index+r[0].length,o)}}return this}_replaceString(e,t){let{original:n}=this,i=n.indexOf(e);return i!==-1&&(typeof t=="function"&&(t=t(e,i,n)),e!==t&&this.overwrite(i,i+e.length,t)),this}replace(e,t){return typeof e=="string"?this._replaceString(e,t):this._replaceRegexp(e,t)}_replaceAllString(e,t){let{original:n}=this,i=e.length;for(let r=n.indexOf(e);r!==-1;r=n.indexOf(e,r+i)){let o=n.slice(r,r+i),a=t;typeof t=="function"&&(a=t(o,r,n)),o!==a&&this.overwrite(r,r+i,a)}return this}replaceAll(e,t){if(typeof e=="string")return this._replaceAllString(e,t);if(!e.global)throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");return this._replaceRegexp(e,t)}};function g(s,e){if(s)switch(s.type){case"Identifier":e.add(s.name);return;case"ObjectPattern":for(let t of s.properties)t.type==="RestElement"?g(t.argument,e):g(t.value,e);return;case"ArrayPattern":for(let t of s.elements)g(t,e);return;case"AssignmentPattern":g(s.left,e);return;case"RestElement":g(s.argument,e);return}}function R(s){switch(s.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return s.expressions.every(R);case"UnaryExpression":return R(s.argument);case"MemberExpression":return!1;default:return!1}}function v(s,e){if(!(!s||typeof s!="object")){e(s);for(let t of Object.keys(s)){if(t==="loc"||t==="range"||t==="leadingComments"||t==="trailingComments")continue;let n=s[t];if(Array.isArray(n))for(let i of n)i&&typeof i=="object"&&v(i,e);else n&&typeof n=="object"&&typeof n.type=="string"&&v(n,e)}}}function ne(s){let e=new Set;return v(s,t=>{if(t.type==="AssignmentExpression")g(t.left,e);else if(t.type==="UpdateExpression"){let n=t.argument;n?.type==="Identifier"&&e.add(n.name)}}),e}function ie(s,e){let t=new Set,n=i=>{let r=new Set;g(i,r);for(let o of r)e.has(o)&&t.add(o)};return v(s,i=>{switch(i.type){case"VariableDeclarator":n(i.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":n(i.id);for(let r of i.params??[])n(r);return;case"CatchClause":n(i.param);return;case"ClassDeclaration":case"ClassExpression":n(i.id);return}}),t}function M(s,e,t){for(let n of s.properties??[]){if(n.type==="RestElement"){let h=n.argument;if(h?.type!=="Identifier"||e.length>0){let f=new Set;g(h,f);for(let E of f)t.bails.push({name:E,reason:"rest"});continue}t.rest={name:h.name,keys:[]};continue}if(n.computed){let h=new Set;g(n.value,h);for(let f of h)t.bails.push({name:f,reason:"computed"});continue}let i=n.key,r=i.type==="Identifier"?i.name:i.value,o=n.value,a;o.type==="AssignmentPattern"&&(a=o.right,o=o.left);let l=[...e,r];if(o.type==="Identifier"){if(a&&!R(a)){t.bails.push({name:o.name,reason:"unsafe-default"});continue}t.reads.push({name:o.name,path:l,...a?{fallback:a}:{}});continue}if(o.type==="ObjectPattern"){if(a){let h=new Set;g(o,h);for(let f of h)t.bails.push({name:f,reason:"unsafe-default"});continue}M(o,l,t);continue}let u=new Set;g(o,u);for(let h of u)t.bails.push({name:h,reason:"computed"})}}function T(s,e){let t={reads:[],bails:[]};if(s?.type!=="ObjectPattern"||(M(s,[],t),t.rest&&(e?.type!=="BlockStatement"?(t.bails.push({name:t.rest.name,reason:"rest"}),delete t.rest):t.rest.keys=(s.properties??[]).filter(a=>a.type!=="RestElement"&&!a.computed).map(a=>{let l=a.key;return l.type==="Identifier"?l.name:l.value})),t.reads.length===0&&!t.rest))return t;let n=new Set(t.reads.map(a=>a.name));t.rest&&n.add(t.rest.name);let i=ne(e),r=ie(e,n),o=[];for(let a of t.reads)i.has(a.name)?t.bails.push({name:a.name,reason:"reassigned"}):r.has(a.name)?t.bails.push({name:a.name,reason:"shadowed"}):o.push(a);return t.reads=o,t.rest&&i.has(t.rest.name)?(t.bails.push({name:t.rest.name,reason:"reassigned"}),delete t.rest):t.rest&&r.has(t.rest.name)&&(t.bails.push({name:t.rest.name,reason:"shadowed"}),delete t.rest),t}function F(s){switch(s){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function m(s,e){if(s)switch(s.type){case"Identifier":e.add(s.name);return;case"ObjectPattern":for(let t of s.properties)t.type==="RestElement"?m(t.argument,e):m(t.value,e);return;case"ArrayPattern":for(let t of s.elements)m(t,e);return;case"AssignmentPattern":m(s.left,e);return;case"RestElement":m(s.argument,e);return}}function U(s,e){switch(s.type){case"ImportDeclaration":for(let t of s.specifiers)m(t.local,e);return;case"VariableDeclaration":for(let t of s.declarations)m(t.id,e);return;case"FunctionDeclaration":case"ClassDeclaration":m(s.id,e);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":s.declaration&&U(s.declaration,e);return}}function q(s){let e=new Set;for(let t of s.body)U(t,e);return e}function S(s,e,t=null){if(!(!s||typeof s!="object"||typeof s.type!="string")&&!s.type.startsWith("TS")&&e(s,t)!==!1)for(let n of Object.keys(s)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let i=s[n];if(Array.isArray(i))for(let r of i)S(r,e,s);else i&&typeof i=="object"&&S(i,e,s)}}function G(s){return!!s&&s[0]>="A"&&s[0]<="Z"}function re(s){let e=[];return S(s,t=>{if(t.type==="FunctionDeclaration"&&G(t.id?.name)){e.push(t);return}if(t.type==="VariableDeclarator"&&G(t.id?.name)){let n=t.init;n&&(n.type==="ArrowFunctionExpression"||n.type==="FunctionExpression")&&e.push(n)}}),e}function oe(s){let e=new Set;return S(s,t=>{t.type==="Identifier"&&e.add(t.name)}),e}function ae(s,e){if(!e)return!0;switch(e.type){case"MemberExpression":case"OptionalMemberExpression":return!(e.property===s&&!e.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(e.key===s&&!e.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return e.label!==s;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function le(s,e,t={}){let n=[],i=[],r=new Set;for(let o of re(s)){let a=o.params?.[0];if(a?.type!=="ObjectPattern")continue;let l=T(a,o.body);for(let c of l.bails)i.push({name:c.name,reason:c.reason,message:F(c.reason),start:a.start});if(l.bails.length>0||l.reads.length===0&&!l.rest)continue;let u=oe(o),h=t.parameterName??"props";for(;u.has(h);)h=`_${h}`;let f=new Map;for(let c of l.reads){let d=`${h}.${c.path.join(".")}`,p=c.fallback;f.set(c.name,p?`(${d} === undefined ? ${e.slice(p.start,p.end)} : ${d})`:d)}let E=a.typeAnnotation;if(n.push({start:a.start,end:E?.start??a.end,code:h}),l.rest){let c=l.rest.keys.map(p=>JSON.stringify(p)).join(", "),d=o.body;n.push({start:d.start+1,end:d.start+1,code:`
|
|
11
|
+
const [, ${l.rest.name}] = splitProps(${h}, [${c}]);`}),r.add("splitProps")}let I=[];S(o.body,(c,d)=>{if(c.type!=="Identifier")return;let p=f.get(c.name);if(!p)return;let P=d?.type==="ObjectProperty"&&d.shorthand&&d.value===c;if(!P&&!ae(c,d))return;let O=l.reads.find(J=>J.name===c.name).path;I.push({node:c,parent:P?d:null,text:p,property:O[O.length-1]})});for(let c of I)c.parent?n.push({start:c.parent.start,end:c.parent.end,code:`${c.node.name}: ${c.text}`}):n.push({start:c.node.start,end:c.node.end,code:c.text}),ue(c.node,h,c.property)}return{edits:n,diagnostics:i,used:r}}function ue(s,e,t){s.type="MemberExpression",s.computed=!1,s.optional=!1,s.object={type:"Identifier",name:e,start:s.start,end:s.start},s.property={type:"Identifier",name:t,start:s.end,end:s.end},delete s.name}function Se(s,e="module.tsx",t={}){let n=se(s,{sourceType:"module",plugins:["typescript","jsx"],errorRecovery:!0}),{edits:i,diagnostics:r,used:o}=le(n.program,s,t),a=new N(s);for(let l of i)l.start===l.end?a.appendLeft(l.start,l.code):a.overwrite(l.start,l.end,l.code);return o.has("splitProps")&&!q(n.program).has("splitProps")&&a.prepend(`import { splitProps } from ${JSON.stringify(t.runtimeModule??"@fluixi/dom")};
|
|
12
|
+
`),{code:a.toString(),map:a.generateMap({source:e,includeContent:!0,hires:!0}),diagnostics:r,rewritten:i.filter(l=>l.code!==(t.parameterName??"props")).length}}export{le as collectPropsEdits,Se as transformProps};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
"use strict";var je=Object.create;var L=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Fe=Object.prototype.hasOwnProperty;var He=(e,t)=>{for(var n in t)L(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _e(t))!Fe.call(e,r)&&r!==n&&L(e,r,{get:()=>t[r],enumerable:!(o=De(t,r))||o.enumerable});return e};var Xe=(e,t,n)=>(n=e!=null?je(Be(e)):{},se(t||!e||!e.__esModule?L(n,"default",{value:e,enumerable:!0}):n,e)),ze=e=>se(L({},"__esModule",{value:!0}),e);var jt={};He(jt,{transformTemplates:()=>At});module.exports=ze(jt);var Pe=require("@babel/parser"),Ae=Xe(require("magic-string"),1);function qe(e){switch(e.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function x(e){let t=[],n=new Map,o=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of r.children)o(s);return!1;case"fragment":for(let s of r.children)o(s);return!1;case"element":{let s=!0;for(let a of r.children)o(a)||(s=!1);let i;for(let a of r.props)if(i=qe(a),i)break;return!i&&!s&&(i=Ve(r)),r.static=!i,i?n.set(r,i):t.push(r),r.static}default:return!1}};for(let r of Array.isArray(e)?e:[e])o(r);return{staticElements:t,reasons:n}}function Ve(e){for(let t of e.children){if(t.kind==="expr")return"expression-child";if(t.kind==="component")return"component-child";if(t.kind==="control")return"control-child";if(t.kind==="element"&&!t.static||t.kind==="fragment")return"expression-child"}return"expression-child"}var J={kind:"eager"},We=["pointerdown","focusin","keydown"],ae=new Set(["eager","idle","visible","interaction","media","never"]),v=class extends Error{};function U(e){return e.startsWith("load:")}function j(e,t){let n=e.slice(5);if(!ae.has(n))throw new v(`Unknown load strategy 'load:${n}'. Expected one of ${[...ae].join(", ")}.`);switch(n){case"eager":return J;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return t?{kind:"visible",rootMargin:t}:{kind:"visible"};case"interaction":return{kind:"interaction",events:t?Ue(t):[...We]};case"media":if(!t)throw new v(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new v(`Unhandled load strategy '${n}'.`)}}function Ue(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new v("'load:interaction' was given no event names.");return t}function D(e){return e.kind!=="eager"&&e.kind!=="never"}var b=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],C=["Suspense","SuspenseList","Await"],N=["Router","Outlet","Redirect","Link"],Ft=[...b,...C,...N],G=new Set([...b,...C]);function le(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router-next"}=e,r={};for(let s of b)r[s]=t;for(let s of C)r[s]=n;for(let s of N)r[s]=o;return r}function _(e,t={}){let{resolver:n,isBound:o,modules:r,strategyFor:s}=t,i=le(r),a=new Map,l=new Set,c=d=>{let{name:p}=d;if(!p||p.includes(".")||o?.(p))return;let f=u(p);if(!f){l.add(p);return}let g=f.origin==="builtin"&&G.has(p)?J:s?.(d)??J;d.source={...f,loading:g},a.set(p,d.source)},u=d=>{if(G.has(d))return{module:i[d],export:d,origin:"builtin"};let p=n?.resolve(d);if(p)return{module:p.module,export:p.export,origin:"rule"};if(N.includes(d))return{module:i[d],export:d,origin:"builtin"}};return B(e,d=>{d.kind==="component"&&c(d)}),{resolved:a,unresolved:[...l]}}function B(e,t){let n=Array.isArray(e)?e:[e];for(let o of n){t(o);let r=o.children;r&&B(r,t)}}function F(e){let t=[];B(e,s=>{s.kind==="component"&&s.source&&t.push(s)});let n=new Set,o=new Set;for(let s of t){let{module:i,loading:a}=s.source;a.kind==="eager"&&n.add(i),a.kind==="never"&&o.add(i)}let r=new Map;for(let s of t){let i=s.source;D(i.loading)&&n.has(i.module)&&(i.loading={kind:"eager"},r.set(i.module,(r.get(i.module)??0)+1))}return{collapsed:r,conflicted:[...o].filter(s=>n.has(s))}}var Ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ce={className:"class",htmlFor:"for"},Ke=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Ye=new Set(["script","style","textarea","title"]);function K(e){return Ye.has(e)}function pe(e){return ce[e]??e}function I(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!Ke.has(e.name)}function Y(e){if(!e.static||K(e.tag))return!1;for(let t of e.props)if(!I(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&Y(t)))return!1;return!0}function w(e){let t=e.props.map(Qe).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return Ge.has(e.tag)?n:`${n}${e.children.map(Ze).join("")}</${e.tag}>`}function Ze(e){if(e.kind==="text")return tt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return w(e)}function Qe(e){let t=ce[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${et(String(n))}"`}function et(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function tt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var nt="<!--fx-->",rt="<!--fx/-->";function X(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function ot(e){return e.kind==="text"||e.kind==="element"&&ue(e)}function ue(e){return e.svg||K(e.tag)||!e.props.every(t=>I(t))?!1:e.children.every(t=>ot(t)||X(t))}function H(e){if(X(e))return!0;let t=e.children;return t?t.some(H):!1}function de(e){for(let t=0;t<e.children.length;t++){let n=e.children[t];if(n.kind==="text"&&(n.value===""||e.children[t+1]?.kind==="text"))return!1}return e.children.every(t=>t.kind!=="element"||de(t))}function me(e){if(!ue(e)||!de(e)||!e.children.some(H))return null;let t=[],n=[],o=0,r=i=>{let a=`_n$${o++}`;return t.push({ref:a,expr:i}),a};return s(e,"_el$"),{html:it(e),tag:e.tag,steps:t,holes:n};function s(i,a){let l=-1;i.children.forEach((u,d)=>{H(u)&&(l=d)});let c=null;for(let u=0;u<=l;u++){let d=i.children[u],p=c?`${c}.nextSibling`:`${a}.firstChild`;if(X(d)){let g=r(p),P=r(`holeEnd(${g})`);n.push({parentRef:a,startRef:g,endRef:P,node:d}),c=P;continue}let f=r(p);d.kind==="element"&&H(d)&&s(d,f),c=f}}}function it(e){return w(fe(e)).split(ge).join(nt+rt)}function fe(e){return{...e,children:e.children.map(t=>X(t)?{kind:"text",value:ge}:t.kind==="element"?fe(t):t)}}var ge="\0fx-hole\0";var Z={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Zt={version:2,module:"@fluixi/dom",symbols:[...Z.symbols,"template","cloneTemplate","walk"]};var st={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function at(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function ve(e){return at(e)?e:JSON.stringify(e)}function lt(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function ct(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function pt(e,t,n){let o=e.filter(a=>a.kind==="spread"),s=e.filter(a=>a.kind!=="spread").map(a=>`${ve(a.name)}: ${lt(a)}`);t!=null&&s.push(`children: ${t}`);let i=`{ ${s.join(", ")} }`;return o.length>0?(n.add("mergeProps"),`mergeProps(${o.map(a=>a.expr).join(", ")}, ${i})`):i}function Re(e,t,n){return e.length===1?T(e[0],t,n):`[${e.map(o=>T(o,t,n)).join(", ")}]`}function he(e,t,n,o,r){o.add("createMemo"),o.add("createComponent");let s=t.filter(c=>c.kind==="spread"),a=t.filter(c=>c.kind!=="spread").map(c=>`get ${ve(c.name)}() { return ${ct(c)}; }`);n.length>0&&a.push(`get children() { return ${Re(n,o,r)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(o.add("mergeProps"),l=`mergeProps(${s.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function ut(e,t){let n=pe(t.name),o=t.literal;return o===!0||o===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:o===!1||o===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(o))});`}var ye=!1;function T(e,t,n){switch(e.kind){case"text":return JSON.stringify(e.value);case"expr":return e.reactive?`() => (${e.code})`:`(${e.code})`;case"fragment":return e.children.length===0?"null":Re(e.children,t,n);case"component":return he(e.name,e.props,e.children,t,n);case"control":{let o=st[e.control]??e.control;return t.add(o),he(o,e.props,e.children,t,n)}case"element":{if(n&&e.static&&!e.svg&&Y(e)){t.add("templateNode");let a=`_tmpl$${n.length}`;return n.push({id:a,html:w(e),tag:e.tag,svg:!1}),`templateNode(${a}, ${JSON.stringify(e.tag)})`}if(n&&ye){let a=me(e);if(a){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:a.html,tag:a.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(a.tag)}, true);`];for(let u of a.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of a.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${T(u.node,t,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}t.add("createNativeElement");let o=JSON.stringify(e.tag),r="_el$",s=[],i=e.svg?`${o}, true`:o;if(s.push(`const ${r} = createNativeElement(${i});`),e.props.length>0)if(!e.svg&&e.props.every(I))for(let a of e.props)s.push(ut(r,a));else{t.add("spread");let a=e.svg?", isSVG: true":"";s.push(`spread({ element: ${r}, props: ${pt(e.props,null,t)}${a} });`)}for(let a of e.children){t.add("insert");let l=T(a,t,n),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(c?`insert(${r}, ${l}, null);`:`insert(${r}, ${l});`)}return s.push(`return ${r};`),`(() => { ${s.join(" ")} })()`}}}function z(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(o=>[o.id,JSON.stringify(o.html)]));return e.replace(/_tmpl\$\d+/g,o=>n.get(o)??o)}var k={name:"imperative",contract:Z,emit(e,t){let n=new Set,o=t?.templateClone!==!1?[]:void 0;return ye=t?.partialTemplates===!0,{code:T(e,n,o),imports:Array.from(n),templates:o}}};var dt=e=>"components"in e;function xe(e,t){return e.replace(/\$(\d+)/g,(n,o)=>t[Number(o)]??n)}function mt(e,t){return typeof t=="string"?{module:t,export:e}:t}function q(e=[]){let t=new Map,n=[],o=[];for(let i of e){if(!dt(i)){o.push(i);continue}for(let[a,l]of Object.entries(i.components)){let c=mt(a,l),u=t.get(a);if(u&&u.module!==c.module){let d=n.find(p=>p.name===a);d?d.modules.push(c.module):n.push({name:a,modules:[u.module,c.module]});continue}t.set(a,c)}}let r=new Map;return{resolve:i=>{if(r.has(i))return r.get(i);let a=t.get(i);if(!a)for(let l of o){let c=i.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){a={module:xe(l.module,c),export:l.export?xe(l.export,c):i};break}}return r.set(i,a),a},names:()=>[...t.keys()],conflicts:()=>n}}var Ee=require("@fluixi/template-parser");function $(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let r=0;r<t.length;r++)/[^ \t]/.test(t[r])&&(n=r);let o="";for(let r=0;r<t.length;r++){let s=t[r].replace(/\t/g," ");r!==0&&(s=s.replace(/^ +/,"")),r!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(r!==n&&(s+=" "),o+=s)}return o}var Ne=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function ft(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ke(e){return e.charAt(0).toUpperCase()+e.slice(1)}var Q=class{constructor(t,n){this.holes=t;this.used=n}hole(t){return this.holes[t]??{code:"undefined",reactive:!1}}emit(t){let{code:n,imports:o,templates:r}=k.emit(t,{});for(let s of o)this.used.add(s);return z(n,r)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let o=0;o<t.length;o++){let r=t[o];if(r.kind==="Element"||r.kind==="Component"){let i=r.attributes.find(a=>a.kind==="IfDirective");if(i&&i.kind==="IfDirective"){let a=o+1;a<t.length&&this.isBlankText(t[a])&&a++;let l=t[a],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");n.push(this.lowerIf(r,i.hole,c?l:null)),c&&(o=a);continue}if(r.attributes.some(a=>a.kind==="EachDirective")){n.push(this.lowerEach(r));continue}}let s=this.lowerNode(r);s&&n.push(s)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&$(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=$(t.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(t.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(t.children)};case"Element":return this.lowerElement(t);case"Component":return this.lowerComponent(t);default:return null}}lowerElement(t){let n=t.attributes.find(o=>o.kind==="Attribute"&&o.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let o=t.attributes.filter(s=>s!==n),r=this.lowerComponent({...t,kind:"Component",tag:"Dynamic",tagHole:null,attributes:o});return r.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),r}return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:this.lowerAttributes(t.attributes),children:this.lowerChildren(t.children),static:!1}}lowerComponent(t){let n=t.tagHole!=null?this.hole(t.tagHole).code:t.tag,o=this.lowerAttributes(t.attributes),{slots:r,rest:s}=this.partitionSlots(t.children);for(let[l,c]of r){let u=c.length===1?c[0]:{kind:"fragment",children:c},d={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},p=o.findIndex(f=>f.name===l);p>=0?o[p]=d:o.push(d)}let i=t.attributes.find(l=>l.kind==="LoadDirective"),a=i?j(`load:${i.strategy}`,i.modifier):void 0;return{kind:"component",name:n,props:o,children:this.lowerChildren(s),...a?{load:a}:{}}}partitionSlots(t){let n=new Map,o=[];for(let r of t){if(r.kind==="Element"||r.kind==="Component"){let s=r.attributes.find(i=>i.kind==="Attribute"&&i.name==="slot");if(s&&s.value&&s.value.kind==="static"){let i={...r,attributes:r.attributes.filter(c=>c!==s)},a=i.kind==="Element"?this.lowerElement(i):this.lowerComponent(i),l=n.get(s.value.value)??[];l.push(a),n.set(s.value.value,l);continue}}o.push(r)}return{slots:n,rest:o}}lowerIf(t,n,o){let r=this.hole(n),s=[{name:"when",kind:"attr",expr:r.code,reactive:r.reactive}];if(o){let a=this.stripAndLower(o,l=>l.kind==="ElseDirective");s.push({name:"fallback",kind:"attr",expr:this.emit(a),jsxElement:!0})}let i=this.stripAndLower(t,a=>a.kind==="IfDirective");return{kind:"component",name:"Show",props:s,children:[i]}}lowerEach(t){let n=t.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let o=this.hole(n.hole),r=[{name:"each",kind:"attr",expr:o.code,reactive:o.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:l})}let s=this.itemArrow(t),i;if(s){let l={kind:"expr",code:s.body,reactive:s.bodyReactive},c=this.rebuildWithChildren(t,[l]);i=`(${s.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(t,c=>c.kind==="EachDirective");i=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:r,children:[{kind:"expr",code:i,reactive:!1}]}}itemArrow(t){let n=t.children.filter(o=>!this.isBlankText(o));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(t,n){let o={...t,attributes:t.attributes.filter(r=>!n(r))};return o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o)}rebuildWithChildren(t,n){let o=this.lowerAttributes(t.attributes.filter(r=>r.kind!=="EachDirective"));return t.kind==="Element"?{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:o,children:n,static:!1}:{kind:"component",name:t.tag,props:o,children:n}}lowerAttributes(t){let n=[],o=[],r=!1,s=[],i=!1,a=[];for(let l of t)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${c.code}`),r=r||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);s.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;a.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:r}),s.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${s.join(", ")} }`,reactive:i}),a.length>0&&n.push({name:"use",kind:"attr",expr:`[${a.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),o=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+ke(t.name),kind:"event",event:{name:n,delegated:Ne.has(n)},expr:o};let s=this.wrapHandler(o,t.modifiers),i=this.eventOptions(t.modifiers),a=i?`[${s}, ${i}]`:s;return{name:"on:"+n,kind:"attr",expr:a}}wrapHandler(t,n){let o=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",r=[];return n.includes("prevent")&&r.push("e.preventDefault();"),n.includes("stop")&&r.push("e.stopPropagation();"),!o&&r.length===0?t:`(e) => { ${o}${r.join(" ")} return (${t})(e); }`}eventOptions(t){let n=[];return t.includes("capture")&&n.push("capture: true"),t.includes("once")&&n.push("once: true"),t.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(t,n){let o=t==="checked",r=o?"change":"input",s=o?"checked":"value",i=`(${n})`;return[{name:t,kind:"attr",expr:`${i}[0]()`,reactive:!0},{name:"on"+ke(r),kind:"event",event:{name:r,delegated:Ne.has(r)},expr:`(e) => ${i}[1](e.target.${s})`}]}plainAttr(t){let n=t.value,o=t.name;t.name==="class"?o=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":t.name==="html"&&(o="innerHTML");let s={name:o,kind:"attr"};if(n==null)return s.literal=!0,s;if(n.kind==="static")return s.literal=n.value,s;if(n.kind==="hole"){let l=this.hole(n.hole);return s.expr=l.code,s.reactive=l.reactive,s}let i=!1,a=n.parts.map(l=>{if("text"in l)return ft(l.text);let c=this.hole(l.hole);return i=i||c.reactive,"${"+c.code+"}"}).join("");return s.expr="`"+a+"`",s.reactive=i,s}};function Se(e,t,n,o={}){let{root:r}=(0,Ee.parseTemplate)(e,{svg:o.svg});return new Q(t,n).lowerRoot(r.children)}function be(e,t,n={}){let o=new Set,r=Se(e,[...t],o,{svg:n.svg});x(r),_(r,{resolver:q(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router-next"},strategyFor:l=>l.load}),F(r);let{code:s,imports:i,templates:a}=k.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of i)o.add(l);return n.hoistTemplates?{code:s,imports:[...o],ir:r,templates:a}:{code:z(s,a),imports:[...o],ir:r}}var gt="children";function E(e){switch(e.kind){case"call":return!0;case"member":return e.property!==gt;case"compound":return e.parts.some(E);case"opaque":return!1}}var ht=new Set(["CallExpression","OptionalCallExpression"]),vt=new Set(["MemberExpression","OptionalMemberExpression"]);function S(e){if(!e)return{kind:"opaque"};if(ht.has(e.type))return{kind:"call"};if(vt.has(e.type)){let t=e.property;return{kind:"member",property:!(e.computed===!0)&&t?.type==="Identifier"?t.name:null}}return e.type==="ConditionalExpression"?{kind:"compound",parts:[e.test,e.consequent,e.alternate].map(M)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(M)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(M)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>M(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(M)}:{kind:"opaque"}}var M=e=>S(e);var Rt=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),yt=/^on[A-Z]/,xt=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),we=e=>E(S(e));function O(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral"||e.type==="Literal"&&(typeof e.value=="string"||typeof e.value=="number"||typeof e.value=="boolean"))return e.value}var ee=e=>!!e&&typeof O(e)=="string";function Nt(e,t){return e.type==="JSXIdentifier"?{tag:e.name,component:e.name[0]!==e.name[0].toLowerCase()}:e.type==="JSXMemberExpression"?{tag:t.code(e),component:!0}:e.type==="JSXNamespacedName"?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function te(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function kt(e,t){let n=te(e.name),o=yt.test(n),r=o||n.startsWith("on:")||n==="ref",i={name:n,kind:o?"event":"attr"};if(o){let l=n.slice(2).toLowerCase();i.event={name:l,delegated:xt.has(l)}}let a=e.value;if(a==null)return i.literal=!0,i;if(ee(a))return i.literal=O(a),i;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let l=a.expression,c=O(l);return c!==void 0?(i.literal=c,i):(i.expr=t.code(l),i.reactive=r?!1:we(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(i.jsxElement=!0),i)}return i.literal=!0,i}function Ce(e,t){let n=e.value;return n==null?null:ee(n)?JSON.stringify(O(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function Et(e,t){let n=[],o=[];for(let r of e){if(r.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(r.argument)});continue}if(r.type!=="JSXAttribute"||U(te(r.name)))continue;let s=r.name.type==="JSXNamespacedName"?r.name.namespace.name:null;if(s==="use"){let i=r.name.name.name;t.used.add(i);let a=Ce(r,t);o.push(a!=null?`[${i}, () => (${a})]`:`[${i}]`);continue}if(s==="oncapture"){let i=r.name.name.name.toLowerCase(),a=Ce(r,t)??"undefined";n.push({name:"on:"+i,kind:"attr",expr:`[${a}, { capture: true }]`});continue}n.push(kt(r,t))}return o.length>0&&n.push({name:"use",kind:"attr",expr:`[${o.join(", ")}]`}),n}function Ie(e,t){let n=[];for(let o of e)if(o.type==="JSXText"){let r=$(o.value);r&&n.push({kind:"text",value:r})}else if(o.type==="JSXExpressionContainer"){if(o.expression?.type!=="JSXEmptyExpression"){let r=o.expression;n.push({kind:"expr",code:t.code(r),reactive:we(r)})}}else o.type==="JSXElement"||o.type==="JSXFragment"?n.push(Te(o,t)):o.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(o.expression),reactive:!1});return n}function St(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=te(t.name);if(U(n)){if(t.value&&!ee(t.value))throw new v(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return j(n,t.value?O(t.value):null)}}}function Te(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:Ie(e.children,t)};let{tag:n,component:o}=Nt(e.openingElement.name,t),r=Et(e.openingElement.attributes,t),s=Ie(e.children,t);if(o){let i=St(e.openingElement.attributes);return{kind:"component",name:n,props:r,children:s,...i?{load:i}:{}}}return{kind:"element",tag:n,svg:Rt.has(n),props:r,children:s,static:!1}}function $e(e,t){let n=Te(e,t);return x(n),n}function R(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?R(n.argument,t):R(n.value,t);return;case"ArrayPattern":for(let n of e.elements)R(n,t);return;case"AssignmentPattern":R(e.left,t);return;case"RestElement":R(e.argument,t);return}}function Me(e,t){switch(e.type){case"ImportDeclaration":for(let n of e.specifiers)R(n.local,t);return;case"VariableDeclaration":for(let n of e.declarations)R(n.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":R(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&Me(e.declaration,t);return}}function Oe(e){let t=new Set;for(let n of e.body)Me(n,t);return t}var bt=new Set(b),Ct=new Set(C),It=new Set(N),wt=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function ne(e,t,n=null,o=""){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let r of e)ne(r,t,n,o);return}typeof e.type=="string"&&t(e,n,o);for(let r of Object.keys(e))r==="loc"||r==="leadingComments"||r==="trailingComments"||ne(e[r],t,typeof e.type=="string"?e:n,r)}}var re=e=>e.type==="JSXElement"||e.type==="JSXFragment";function Tt(e,t,n){return re(e)?!(t&&re(t)&&n==="children"):!1}function $t(e,t){return e.type==="TaggedTemplateExpression"&&e.tag?.type==="Identifier"&&(e.tag.name===t||e.tag.name==="svg")}function Le(e){return e.filter(t=>!e.some(n=>n!==t&&n.start<=t.start&&n.end>=t.end&&n.end-n.start>t.end-t.start))}function V(e,t,n,o){let r=Le(o.filter(i=>i.start>=t&&i.end<=n)).sort((i,a)=>a.start-i.start),s=e.slice(t,n);for(let i of r)s=s.slice(0,i.start-t)+i.code+s.slice(i.end-t);return s}function Mt(e,t,n){let o={code:V(e,t.start,t.end,n),reactive:E(S(t))};return t.type==="ArrowFunctionExpression"&&t.body?.type!=="BlockStatement"&&(o.arrow={params:t.params.map(r=>V(e,r.start,r.end,n)),body:V(e,t.body.start,t.body.end,n),bodyReactive:E(S(t.body))}),t.type==="ObjectExpression"&&(o.object=!0),o}function Je(e,t,n){if(!t||t.length===0)return e;let o=new Map;for(let r of t){let s=`${r.svg?"svg:":""}${r.html}`,i=n.get(s);i||(i=`_fxTmpl$${n.size}`,n.set(s,i)),o.set(r.id,i)}return e.replace(/_tmpl\$\d+/g,r=>o.get(r)??r)}function oe(e,t){if(e.kind==="component"&&e.source){let n=e.source;n.origin==="builtin"?t.builtins.add(e.name):D(n.loading)&&!t.resolved.has(e.name)?t.deferred.set(e.name,n):(t.deferred.delete(e.name),t.resolved.set(e.name,n))}if("props"in e&&e.props)for(let n of e.props)n.kind==="event"&&n.event?.delegated&&t.delegatedEvents.add(n.event.name);if("children"in e&&e.children)for(let n of e.children)oe(n,t)}function Ot(e){let t=[`kind: ${JSON.stringify(e.kind)}`];return e.kind==="visible"&&e.rootMargin&&t.push(`rootMargin: ${JSON.stringify(e.rootMargin)}`),e.kind==="interaction"&&t.push(`events: ${JSON.stringify(e.events)}`),e.kind==="media"&&t.push(`query: ${JSON.stringify(e.query)}`),`{ ${t.join(", ")} }`}function Pt(e){let t=[];return e.quasi.quasis.forEach((n,o)=>{if(t.push({kind:"static",text:n.value.cooked??n.value.raw,start:n.start}),o<e.quasi.expressions.length){let r=e.quasi.expressions[o];t.push({kind:"hole",index:o,start:r.start,end:r.end})}}),t}function At(e,t,n={}){let o=n.litTag??"html",r=n.format??"both",s=r!=="jsx",i=r!=="lit";if(!(s&&(e.includes(`${o}\``)||e.includes("svg`")))&&!(i&&e.includes("<")))return null;let l=(0,Pe.parse)(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),c=[];if(ne(l.program,(m,y,W)=>{(s&&$t(m,o)||i&&Tt(m,y,W))&&c.push(m)}),c.length===0)return null;c.sort((m,y)=>y.start-m.start||m.end-y.end);let u=new Set,d={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set},p=new Map,f=[];for(let m of c){let y=c.some(h=>h!==m&&h.start<=m.start&&h.end>=m.end&&h.end-h.start>m.end-m.start);if(re(m)){f.push({start:m.start,end:m.end,code:Lt(e,m,f,y,u,d,p,n)});continue}let W=m.quasi.expressions.map(h=>Mt(e,h,f)),A=be(Pt(m),W,{...n,hoistTemplates:!0,templateClone:n.templateClone??!0,partialTemplates:y?!1:n.partialTemplates??!0,svg:m.tag.name==="svg"});for(let h of A.imports)u.add(h);oe(A.ir,d),f.push({start:m.start,end:m.end,code:Je(A.code,A.templates,p)})}let g=new Ae.default(e);for(let m of Le(f))g.overwrite(m.start,m.end,m.code);let P=Oe(l.program),ie=Jt(u,d,p,P,n);ie&&g.prepend(ie);for(let m of l.program.body)m.type==="ImportDeclaration"&&m.source?.value==="@fluixi/core/rx"&&g.overwrite(m.source.start,m.source.end,JSON.stringify("@fluixi/reactive"));return{code:g.toString(),map:g.generateMap({source:t,includeContent:!0,hires:!0})}}function Lt(e,t,n,o,r,s,i,a){let l=$e(t,{code:u=>V(e,u.start,u.end,n),used:r});x(l),_(l,{resolver:q(a.resolve??[]),modules:{controlFlowModule:a.controlFlowModule??a.runtimeModule??"@fluixi/dom",coreModule:a.coreModule??"@fluixi/core",routerModule:a.routerModule??"@fluixi/core/router-next"},strategyFor:u=>u.load}),F(l);let c=k.emit(l,{templateClone:a.templateClone??!0,partialTemplates:o?!1:a.partialTemplates??!0});for(let u of c.imports)r.add(u);return oe(l,s),Je(c.code,c.templates,i)}function Jt(e,t,n,o,r){let s=r.runtimeModule??"@fluixi/dom",i=r.coreModule??"@fluixi/core",a=new Map,l=(p,f)=>a.set(p,[...a.get(p)??[],f]),c=new Set(e);for(let p of t.builtins)c.add(p);t.delegatedEvents.size>0&&c.add("delegateEvents");for(let p of[...c].sort())o.has(p)||(wt.has(p)?l(r.reactiveModule??"@fluixi/reactive/signal",p):It.has(p)?l(r.routerModule??"@fluixi/core/router-next",p):Ct.has(p)?l(i,p):bt.has(p)?l(r.controlFlowModule??s,p):l(s,p));for(let[p,f]of t.resolved)o.has(p)||l(f.module,f.export==="default"?`default as ${p}`:p===f.export?p:`${f.export} as ${p}`);let u=[];for(let[p,f]of a)u.push(`import { ${f.join(", ")} } from ${JSON.stringify(p)};`);let d=[...t.deferred].filter(([p])=>!o.has(p));if(d.length>0){o.has("deferred")||u.push(`import { deferred } from ${JSON.stringify(i)};`);for(let[p,f]of d)u.push(`const ${p} = deferred(() => import(${JSON.stringify(f.module)}), { strategy: ${Ot(f.loading)}, export: ${JSON.stringify(f.export)} });`)}for(let[p,f]of n)u.push(`const ${f} = ${JSON.stringify(p.startsWith("svg:")?p.slice(4):p)};`);return t.delegatedEvents.size>0&&u.push(`delegateEvents(${JSON.stringify([...t.delegatedEvents])});`),u.length>0?u.join(`
|
|
1
|
+
"use strict";var pt=Object.create;var V=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var ft=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty;var gt=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},Re=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ut(t))!mt.call(e,s)&&s!==n&&V(e,s,{get:()=>t[s],enumerable:!(r=dt(t,s))||r.enumerable});return e};var ke=(e,t,n)=>(n=e!=null?pt(ft(e)):{},Re(t||!e||!e.__esModule?V(n,"default",{value:e,enumerable:!0}):n,e)),ht=e=>Re(V({},"__esModule",{value:!0}),e);var kn={};gt(kn,{transformTemplates:()=>vn});module.exports=ht(kn);var ot=require("@babel/parser"),at=ke(require("magic-string"),1);function yt(e){switch(e.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function C(e){let t=[],n=new Map,r=s=>{switch(s.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let i of s.children)r(i);return!1;case"fragment":for(let i of s.children)r(i);return!1;case"element":{let i=!0;for(let a of s.children)r(a)||(i=!1);let o;for(let a of s.props)if(o=yt(a),o)break;return!o&&!i&&(o=Nt(s)),s.static=!o,o?n.set(s,o):t.push(s),s.static}default:return!1}};for(let s of Array.isArray(e)?e:[e])r(s);return{staticElements:t,reasons:n}}function Nt(e){for(let t of e.children){if(t.kind==="expr")return"expression-child";if(t.kind==="component")return"component-child";if(t.kind==="control")return"control-child";if(t.kind==="element"&&!t.static||t.kind==="fragment")return"expression-child"}return"expression-child"}var z={kind:"eager"},vt=["pointerdown","focusin","keydown"],be=new Set(["eager","idle","visible","interaction","media","never"]),b=class extends Error{};function ie(e){return e.startsWith("load:")}function U(e,t){let n=e.slice(5);if(!be.has(n))throw new b(`Unknown load strategy 'load:${n}'. Expected one of ${[...be].join(", ")}.`);switch(n){case"eager":return z;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return t?{kind:"visible",rootMargin:t}:{kind:"visible"};case"interaction":return{kind:"interaction",events:t?xt(t):[...vt]};case"media":if(!t)throw new b(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new b(`Unhandled load strategy '${n}'.`)}}function xt(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new b("'load:interaction' was given no event names.");return t}function W(e){return e.kind!=="eager"&&e.kind!=="never"}var O=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],D=["Suspense","SuspenseList","Await"],T=["Router","Outlet","Redirect","Link"],In=[...O,...D,...T],oe=new Set([...O,...D]);function Se(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:r="@fluixi/core/router-next"}=e,s={};for(let i of O)s[i]=t;for(let i of D)s[i]=n;for(let i of T)s[i]=r;return s}function q(e,t={}){let{resolver:n,isBound:r,modules:s,strategyFor:i}=t,o=Se(s),a=new Map,l=new Set,c=u=>{let{name:d}=u;if(!d||d.includes(".")||r?.(d))return;let g=p(d);if(!g){l.add(d);return}let f=g.origin==="builtin"&&oe.has(d)?z:i?.(u)??z;u.source={...g,loading:f},a.set(d,u.source)},p=u=>{if(oe.has(u))return{module:o[u],export:u,origin:"builtin"};let d=n?.resolve(u);if(d)return{module:d.module,export:d.export,origin:"rule"};if(T.includes(u))return{module:o[u],export:u,origin:"builtin"}};return K(e,u=>{u.kind==="component"&&c(u)}),{resolved:a,unresolved:[...l]}}function K(e,t){let n=Array.isArray(e)?e:[e];for(let r of n){t(r);let s=r.children;s&&K(s,t)}}function G(e){let t=[];K(e,i=>{i.kind==="component"&&i.source&&t.push(i)});let n=new Set,r=new Set;for(let i of t){let{module:o,loading:a}=i.source;a.kind==="eager"&&n.add(o),a.kind==="never"&&r.add(o)}let s=new Map;for(let i of t){let o=i.source;W(o.loading)&&n.has(o.module)&&(o.loading={kind:"eager"},s.set(o.module,(s.get(o.module)??0)+1))}return{collapsed:s,conflicted:[...r].filter(i=>n.has(i))}}var Rt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ee={className:"class",htmlFor:"for"},kt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),bt=new Set(["script","style","textarea","title"]);function ae(e){return bt.has(e)}function Ie(e){return Ee[e]??e}function A(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!kt.has(e.name)}function le(e){if(!e.static||ae(e.tag))return!1;for(let t of e.props)if(!A(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&le(t)))return!1;return!0}function j(e){let t=e.props.map(Et).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return Rt.has(e.tag)?n:`${n}${e.children.map(St).join("")}</${e.tag}>`}function St(e){if(e.kind==="text")return wt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return j(e)}function Et(e){let t=Ee[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${It(String(n))}"`}function It(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function wt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var Ct="<!--fx-->",Tt="<!--fx/-->";function Y(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function $t(e){return e.kind==="text"||e.kind==="element"&&we(e)}function we(e){return e.svg||ae(e.tag)||!e.props.every(t=>A(t))?!1:e.children.every(t=>$t(t)||Y(t))}function Z(e){if(Y(e))return!0;let t=e.children;return t?t.some(Z):!1}function Ce(e){for(let t=0;t<e.children.length;t++){let n=e.children[t];if(n.kind==="text"&&(n.value===""||e.children[t+1]?.kind==="text"))return!1}return e.children.every(t=>t.kind!=="element"||Ce(t))}function Te(e){if(!we(e)||!Ce(e)||!e.children.some(Z))return null;let t=[],n=[],r=0,s=o=>{let a=`_n$${r++}`;return t.push({ref:a,expr:o}),a};return i(e,"_el$"),{html:Pt(e),tag:e.tag,steps:t,holes:n};function i(o,a){let l=-1;o.children.forEach((p,u)=>{Z(p)&&(l=u)});let c=null;for(let p=0;p<=l;p++){let u=o.children[p],d=c?`${c}.nextSibling`:`${a}.firstChild`;if(Y(u)){let f=s(d),h=s(`holeEnd(${f})`);n.push({parentRef:a,startRef:f,endRef:h,node:u}),c=h;continue}let g=s(d);u.kind==="element"&&Z(u)&&i(u,g),c=g}}}function Pt(e){return j($e(e)).split(Pe).join(Ct+Tt)}function $e(e){return{...e,children:e.children.map(t=>Y(t)?{kind:"text",value:Pe}:t.kind==="element"?$e(t):t)}}var Pe="\0fx-hole\0";var ce={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Ln={version:2,module:"@fluixi/dom",symbols:[...ce.symbols,"template","cloneTemplate","walk"]};var Mt={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Ot(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function Oe(e){return Ot(e)?e:JSON.stringify(e)}function Dt(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function At(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function jt(e,t,n){let r=e.filter(a=>a.kind==="spread"),i=e.filter(a=>a.kind!=="spread").map(a=>`${Oe(a.name)}: ${Dt(a)}`);t!=null&&i.push(`children: ${t}`);let o=`{ ${i.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(a=>a.expr).join(", ")}, ${o})`):o}function De(e,t,n){return e.length===1?L(e[0],t,n):`[${e.map(r=>L(r,t,n)).join(", ")}]`}function Me(e,t,n,r,s){r.add("createMemo"),r.add("createComponent");let i=t.filter(c=>c.kind==="spread"),a=t.filter(c=>c.kind!=="spread").map(c=>`get ${Oe(c.name)}() { return ${At(c)}; }`);n.length>0&&a.push(`get children() { return ${De(n,r,s)}; }`);let l=`{ ${a.join(", ")} }`;return i.length>0&&(r.add("mergeProps"),l=`mergeProps(${i.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function Lt(e,t){let n=Ie(t.name),r=t.literal;return r===!0||r===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var Ae=!1;function L(e,t,n){switch(e.kind){case"text":return JSON.stringify(e.value);case"expr":return e.reactive?`() => (${e.code})`:`(${e.code})`;case"fragment":return e.children.length===0?"null":De(e.children,t,n);case"component":return Me(e.name,e.props,e.children,t,n);case"control":{let r=Mt[e.control]??e.control;return t.add(r),Me(r,e.props,e.children,t,n)}case"element":{if(n&&e.static&&!e.svg&&le(e)){t.add("templateNode");let a=`_tmpl$${n.length}`;return n.push({id:a,html:j(e),tag:e.tag,svg:!1}),`templateNode(${a}, ${JSON.stringify(e.tag)})`}if(n&&Ae){let a=Te(e);if(a){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:a.html,tag:a.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(a.tag)}, true);`];for(let p of a.steps)c.push(`const ${p.ref} = ${p.expr};`);for(let p of a.holes)c.push(`insert(${p.parentRef}, holeScope(${p.startRef}, () => (${L(p.node,t,n)})), ${p.endRef}, holeContent(${p.startRef}, ${p.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}t.add("createNativeElement");let r=JSON.stringify(e.tag),s="_el$",i=[],o=e.svg?`${r}, true`:r;if(i.push(`const ${s} = createNativeElement(${o});`),e.props.length>0)if(!e.svg&&e.props.every(A))for(let a of e.props)i.push(Lt(s,a));else{t.add("spread");let a=e.svg?", isSVG: true":"";i.push(`spread({ element: ${s}, props: ${jt(e.props,null,t)}${a} });`)}for(let a of e.children){t.add("insert");let l=L(a,t,n),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";i.push(c?`insert(${s}, ${l}, null);`:`insert(${s}, ${l});`)}return i.push(`return ${s};`),`(() => { ${i.join(" ")} })()`}}}function Q(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(r=>[r.id,JSON.stringify(r.html)]));return e.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var $={name:"imperative",contract:ce,emit(e,t){let n=new Set,r=t?.templateClone!==!1?[]:void 0;return Ae=t?.partialTemplates===!0,{code:L(e,n,r),imports:Array.from(n),templates:r}}};var Jt=e=>"components"in e;function je(e,t){return e.replace(/\$(\d+)/g,(n,r)=>t[Number(r)]??n)}function _t(e,t){return typeof t=="string"?{module:t,export:e}:t}function ee(e=[]){let t=new Map,n=[],r=[];for(let o of e){if(!Jt(o)){r.push(o);continue}for(let[a,l]of Object.entries(o.components)){let c=_t(a,l),p=t.get(a);if(p&&p.module!==c.module){let u=n.find(d=>d.name===a);u?u.modules.push(c.module):n.push({name:a,modules:[p.module,c.module]});continue}t.set(a,c)}}let s=new Map;return{resolve:o=>{if(s.has(o))return s.get(o);let a=t.get(o);if(!a)for(let l of r){let c=o.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){a={module:je(l.module,c),export:l.export?je(l.export,c):o};break}}return s.set(o,a),a},names:()=>[...t.keys()],conflicts:()=>n}}var _e=require("@fluixi/template-parser");function J(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let s=0;s<t.length;s++)/[^ \t]/.test(t[s])&&(n=s);let r="";for(let s=0;s<t.length;s++){let i=t[s].replace(/\t/g," ");s!==0&&(i=i.replace(/^ +/,"")),s!==t.length-1&&(i=i.replace(/ +$/,"")),i&&(s!==n&&(i+=" "),r+=i)}return r}var Le=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Bt(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Je(e){return e.charAt(0).toUpperCase()+e.slice(1)}var pe=class{constructor(t,n){this.holes=t;this.used=n}hole(t){return this.holes[t]??{code:"undefined",reactive:!1}}emit(t){let{code:n,imports:r,templates:s}=$.emit(t,{});for(let i of r)this.used.add(i);return Q(n,s)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let r=0;r<t.length;r++){let s=t[r];if(s.kind==="Element"||s.kind==="Component"){let o=s.attributes.find(a=>a.kind==="IfDirective");if(o&&o.kind==="IfDirective"){let a=r+1;a<t.length&&this.isBlankText(t[a])&&a++;let l=t[a],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(p=>p.kind==="ElseDirective");n.push(this.lowerIf(s,o.hole,c?l:null)),c&&(r=a);continue}if(s.attributes.some(a=>a.kind==="EachDirective")){n.push(this.lowerEach(s));continue}}let i=this.lowerNode(s);i&&n.push(i)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&J(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=J(t.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(t.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(t.children)};case"Element":return this.lowerElement(t);case"Component":return this.lowerComponent(t);default:return null}}lowerElement(t){let n=t.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=t.attributes.filter(i=>i!==n),s=this.lowerComponent({...t,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return s.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),s}return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:this.lowerAttributes(t.attributes),children:this.lowerChildren(t.children),static:!1}}lowerComponent(t){let n=t.tagHole!=null?this.hole(t.tagHole).code:t.tag,r=this.lowerAttributes(t.attributes),{slots:s,rest:i}=this.partitionSlots(t.children);for(let[l,c]of s){let p=c.length===1?c[0]:{kind:"fragment",children:c},u={name:l,kind:"attr",expr:this.emit(p),jsxElement:!0},d=r.findIndex(g=>g.name===l);d>=0?r[d]=u:r.push(u)}let o=t.attributes.find(l=>l.kind==="LoadDirective"),a=o?U(`load:${o.strategy}`,o.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(i),...a?{load:a}:{}}}partitionSlots(t){let n=new Map,r=[];for(let s of t){if(s.kind==="Element"||s.kind==="Component"){let i=s.attributes.find(o=>o.kind==="Attribute"&&o.name==="slot");if(i&&i.value&&i.value.kind==="static"){let o={...s,attributes:s.attributes.filter(c=>c!==i)},a=o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o),l=n.get(i.value.value)??[];l.push(a),n.set(i.value.value,l);continue}}r.push(s)}return{slots:n,rest:r}}lowerIf(t,n,r){let s=this.hole(n),i=[{name:"when",kind:"attr",expr:s.code,reactive:s.reactive}];if(r){let a=this.stripAndLower(r,l=>l.kind==="ElseDirective");i.push({name:"fallback",kind:"attr",expr:this.emit(a),jsxElement:!0})}let o=this.stripAndLower(t,a=>a.kind==="IfDirective");return{kind:"component",name:"Show",props:i,children:[o]}}lowerEach(t){let n=t.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let r=this.hole(n.hole),s=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;s.push({name:"by",kind:"attr",expr:l})}let i=this.itemArrow(t),o;if(i){let l={kind:"expr",code:i.body,reactive:i.bodyReactive},c=this.rebuildWithChildren(t,[l]);o=`(${i.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(t,c=>c.kind==="EachDirective");o=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:s,children:[{kind:"expr",code:o,reactive:!1}]}}itemArrow(t){let n=t.children.filter(r=>!this.isBlankText(r));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(t,n){let r={...t,attributes:t.attributes.filter(s=>!n(s))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(t,n){let r=this.lowerAttributes(t.attributes.filter(s=>s.kind!=="EachDirective"));return t.kind==="Element"?{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:t.tag,props:r,children:n}}lowerAttributes(t){let n=[],r=[],s=!1,i=[],o=!1,a=[];for(let l of t)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);r.push(`${JSON.stringify(l.name)}: ${c.code}`),s=s||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);i.push(`${JSON.stringify(l.name)}: ${c.code}`),o=o||c.reactive;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;a.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:s}),i.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${i.join(", ")} }`,reactive:o}),a.length>0&&n.push({name:"use",kind:"attr",expr:`[${a.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),r=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+Je(t.name),kind:"event",event:{name:n,delegated:Le.has(n)},expr:r};let i=this.wrapHandler(r,t.modifiers),o=this.eventOptions(t.modifiers),a=o?`[${i}, ${o}]`:i;return{name:"on:"+n,kind:"attr",expr:a}}wrapHandler(t,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",s=[];return n.includes("prevent")&&s.push("e.preventDefault();"),n.includes("stop")&&s.push("e.stopPropagation();"),!r&&s.length===0?t:`(e) => { ${r}${s.join(" ")} return (${t})(e); }`}eventOptions(t){let n=[];return t.includes("capture")&&n.push("capture: true"),t.includes("once")&&n.push("once: true"),t.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(t,n){let r=t==="checked",s=r?"change":"input",i=r?"checked":"value";this.used.add("bindPair");let o=`bindPair(${n})`;return[{name:t,kind:"attr",expr:`${o}[0]()`,reactive:!0},{name:"on"+Je(s),kind:"event",event:{name:s,delegated:Le.has(s)},expr:`(e) => ${o}[1](e.target.${i})`}]}plainAttr(t){let n=t.value,r=t.name;t.name==="class"?r=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":t.name==="html"&&(r="innerHTML");let i={name:r,kind:"attr"};if(n==null)return i.literal=!0,i;if(n.kind==="static")return i.literal=n.value,i;if(n.kind==="hole"){let l=this.hole(n.hole);return i.expr=l.code,i.reactive=l.reactive,i}let o=!1,a=n.parts.map(l=>{if("text"in l)return Bt(l.text);let c=this.hole(l.hole);return o=o||c.reactive,"${"+c.code+"}"}).join("");return i.expr="`"+a+"`",i.reactive=o,i}};function Be(e,t,n,r={}){let{root:s}=(0,_e.parseTemplate)(e,{svg:r.svg});return new pe(t,n).lowerRoot(s.children)}function Fe(e,t,n={}){let r=new Set,s=Be(e,[...t],r,{svg:n.svg});C(s),q(s,{resolver:ee(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router-next"},strategyFor:l=>l.load}),G(s);let{code:i,imports:o,templates:a}=$.emit(s,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of o)r.add(l);return n.hoistTemplates?{code:i,imports:[...r],ir:s,templates:a}:{code:Q(i,a),imports:[...r],ir:s}}var Ft="children";function P(e){switch(e.kind){case"call":return!0;case"member":return e.property!==Ft;case"compound":return e.parts.some(P);case"opaque":return!1}}var Ht=new Set(["CallExpression","OptionalCallExpression"]),Xt=new Set(["MemberExpression","OptionalMemberExpression"]);function M(e){if(!e)return{kind:"opaque"};if(Ht.has(e.type))return{kind:"call"};if(Xt.has(e.type)){let t=e.property;return{kind:"member",property:!(e.computed===!0)&&t?.type==="Identifier"?t.name:null}}return e.type==="ConditionalExpression"?{kind:"compound",parts:[e.test,e.consequent,e.alternate].map(_)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(_)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(_)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>_(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(_)}:{kind:"opaque"}}var _=e=>M(e);var Vt=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),zt=/^on[A-Z]/,Ut=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),Ve=e=>P(M(e));function B(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral"||e.type==="Literal"&&(typeof e.value=="string"||typeof e.value=="number"||typeof e.value=="boolean"))return e.value}var de=e=>!!e&&typeof B(e)=="string";function Wt(e,t){return e.type==="JSXIdentifier"?{tag:e.name,component:e.name[0]!==e.name[0].toLowerCase()}:e.type==="JSXMemberExpression"?{tag:t.code(e),component:!0}:e.type==="JSXNamespacedName"?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function ue(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function qt(e,t){let n=ue(e.name),r=zt.test(n),s=r||n.startsWith("on:")||n==="ref",o={name:n,kind:r?"event":"attr"};if(r){let l=n.slice(2).toLowerCase();o.event={name:l,delegated:Ut.has(l)}}let a=e.value;if(a==null)return o.literal=!0,o;if(de(a))return o.literal=B(a),o;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let l=a.expression,c=B(l);return c!==void 0?(o.literal=c,o):(o.expr=t.code(l),o.reactive=s?!1:Ve(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(o.jsxElement=!0),o)}return o.literal=!0,o}function He(e,t){let n=e.value;return n==null?null:de(n)?JSON.stringify(B(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function Kt(e,t){let n=[],r=[];for(let s of e){if(s.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(s.argument)});continue}if(s.type!=="JSXAttribute"||ie(ue(s.name)))continue;let i=s.name.type==="JSXNamespacedName"?s.name.namespace.name:null;if(i==="use"){let o=s.name.name.name;t.used.add(o);let a=He(s,t);r.push(a!=null?`[${o}, () => (${a})]`:`[${o}]`);continue}if(i==="oncapture"){let o=s.name.name.name.toLowerCase(),a=He(s,t)??"undefined";n.push({name:"on:"+o,kind:"attr",expr:`[${a}, { capture: true }]`});continue}n.push(qt(s,t))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function Xe(e,t){let n=[];for(let r of e)if(r.type==="JSXText"){let s=J(r.value);s&&n.push({kind:"text",value:s})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let s=r.expression;n.push({kind:"expr",code:t.code(s),reactive:Ve(s)})}}else r.type==="JSXElement"||r.type==="JSXFragment"?n.push(ze(r,t)):r.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(r.expression),reactive:!1});return n}function Gt(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=ue(t.name);if(ie(n)){if(t.value&&!de(t.value))throw new b(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return U(n,t.value?B(t.value):null)}}}function ze(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:Xe(e.children,t)};let{tag:n,component:r}=Wt(e.openingElement.name,t),s=Kt(e.openingElement.attributes,t),i=Xe(e.children,t);if(r){let o=Gt(e.openingElement.attributes);return{kind:"component",name:n,props:s,children:i,...o?{load:o}:{}}}return{kind:"element",tag:n,svg:Vt.has(n),props:s,children:i,static:!1}}function Ue(e,t){let n=ze(e,t);return C(n),n}function S(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?S(n.argument,t):S(n.value,t);return;case"ArrayPattern":for(let n of e.elements)S(n,t);return;case"AssignmentPattern":S(e.left,t);return;case"RestElement":S(e.argument,t);return}}function We(e,t){switch(e.type){case"ImportDeclaration":for(let n of e.specifiers)S(n.local,t);return;case"VariableDeclaration":for(let n of e.declarations)S(n.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":S(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&We(e.declaration,t);return}}function fe(e){let t=new Set;for(let n of e.body)We(n,t);return t}var Qt=require("@babel/parser"),en=ke(require("magic-string"),1);function N(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?N(n.argument,t):N(n.value,t);return;case"ArrayPattern":for(let n of e.elements)N(n,t);return;case"AssignmentPattern":N(e.left,t);return;case"RestElement":N(e.argument,t);return}}function me(e){switch(e.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return e.expressions.every(me);case"UnaryExpression":return me(e.argument);case"MemberExpression":return!1;default:return!1}}function te(e,t){if(!(!e||typeof e!="object")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="range"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let s of r)s&&typeof s=="object"&&te(s,t);else r&&typeof r=="object"&&typeof r.type=="string"&&te(r,t)}}}function Zt(e){let t=new Set;return te(e,n=>{if(n.type==="AssignmentExpression")N(n.left,t);else if(n.type==="UpdateExpression"){let r=n.argument;r?.type==="Identifier"&&t.add(r.name)}}),t}function Yt(e,t){let n=new Set,r=s=>{let i=new Set;N(s,i);for(let o of i)t.has(o)&&n.add(o)};return te(e,s=>{switch(s.type){case"VariableDeclarator":r(s.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":r(s.id);for(let i of s.params??[])r(i);return;case"CatchClause":r(s.param);return;case"ClassDeclaration":case"ClassExpression":r(s.id);return}}),n}function qe(e,t,n){for(let r of e.properties??[]){if(r.type==="RestElement"){let p=r.argument;if(p?.type!=="Identifier"||t.length>0){let u=new Set;N(p,u);for(let d of u)n.bails.push({name:d,reason:"rest"});continue}n.rest={name:p.name,keys:[]};continue}if(r.computed){let p=new Set;N(r.value,p);for(let u of p)n.bails.push({name:u,reason:"computed"});continue}let s=r.key,i=s.type==="Identifier"?s.name:s.value,o=r.value,a;o.type==="AssignmentPattern"&&(a=o.right,o=o.left);let l=[...t,i];if(o.type==="Identifier"){if(a&&!me(a)){n.bails.push({name:o.name,reason:"unsafe-default"});continue}n.reads.push({name:o.name,path:l,...a?{fallback:a}:{}});continue}if(o.type==="ObjectPattern"){if(a){let p=new Set;N(o,p);for(let u of p)n.bails.push({name:u,reason:"unsafe-default"});continue}qe(o,l,n);continue}let c=new Set;N(o,c);for(let p of c)n.bails.push({name:p,reason:"computed"})}}function Ke(e,t){let n={reads:[],bails:[]};if(e?.type!=="ObjectPattern"||(qe(e,[],n),n.rest&&(t?.type!=="BlockStatement"?(n.bails.push({name:n.rest.name,reason:"rest"}),delete n.rest):n.rest.keys=(e.properties??[]).filter(a=>a.type!=="RestElement"&&!a.computed).map(a=>{let l=a.key;return l.type==="Identifier"?l.name:l.value})),n.reads.length===0&&!n.rest))return n;let r=new Set(n.reads.map(a=>a.name));n.rest&&r.add(n.rest.name);let s=Zt(t),i=Yt(t,r),o=[];for(let a of n.reads)s.has(a.name)?n.bails.push({name:a.name,reason:"reassigned"}):i.has(a.name)?n.bails.push({name:a.name,reason:"shadowed"}):o.push(a);return n.reads=o,n.rest&&s.has(n.rest.name)?(n.bails.push({name:n.rest.name,reason:"reassigned"}),delete n.rest):n.rest&&i.has(n.rest.name)&&(n.bails.push({name:n.rest.name,reason:"shadowed"}),delete n.rest),n}function Ge(e){switch(e){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function F(e,t,n=null){if(!(!e||typeof e!="object"||typeof e.type!="string")&&!e.type.startsWith("TS")&&t(e,n)!==!1)for(let r of Object.keys(e)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let s=e[r];if(Array.isArray(s))for(let i of s)F(i,t,e);else s&&typeof s=="object"&&F(s,t,e)}}function Ze(e){return!!e&&e[0]>="A"&&e[0]<="Z"}function tn(e){let t=[];return F(e,n=>{if(n.type==="FunctionDeclaration"&&Ze(n.id?.name)){t.push(n);return}if(n.type==="VariableDeclarator"&&Ze(n.id?.name)){let r=n.init;r&&(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")&&t.push(r)}}),t}function nn(e){let t=new Set;return F(e,n=>{n.type==="Identifier"&&t.add(n.name)}),t}function rn(e,t){if(!t)return!0;switch(t.type){case"MemberExpression":case"OptionalMemberExpression":return!(t.property===e&&!t.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(t.key===e&&!t.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return t.label!==e;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function Ye(e,t,n={}){let r=[],s=[],i=new Set;for(let o of tn(e)){let a=o.params?.[0];if(a?.type!=="ObjectPattern")continue;let l=Ke(a,o.body);for(let f of l.bails)s.push({name:f.name,reason:f.reason,message:Ge(f.reason),start:a.start});if(l.bails.length>0||l.reads.length===0&&!l.rest)continue;let c=nn(o),p=n.parameterName??"props";for(;c.has(p);)p=`_${p}`;let u=new Map;for(let f of l.reads){let h=`${p}.${f.path.join(".")}`,y=f.fallback;u.set(f.name,y?`(${h} === undefined ? ${t.slice(y.start,y.end)} : ${h})`:h)}let d=a.typeAnnotation;if(r.push({start:a.start,end:d?.start??a.end,code:p}),l.rest){let f=l.rest.keys.map(y=>JSON.stringify(y)).join(", "),h=o.body;r.push({start:h.start+1,end:h.start+1,code:`
|
|
2
|
+
const [, ${l.rest.name}] = splitProps(${p}, [${f}]);`}),i.add("splitProps")}let g=[];F(o.body,(f,h)=>{if(f.type!=="Identifier")return;let y=u.get(f.name);if(!y)return;let k=h?.type==="ObjectProperty"&&h.shorthand&&h.value===f;if(!k&&!rn(f,h))return;let v=l.reads.find(H=>H.name===f.name).path;g.push({node:f,parent:k?h:null,text:y,property:v[v.length-1]})});for(let f of g)f.parent?r.push({start:f.parent.start,end:f.parent.end,code:`${f.node.name}: ${f.text}`}):r.push({start:f.node.start,end:f.node.end,code:f.text}),sn(f.node,p,f.property)}return{edits:r,diagnostics:s,used:i}}function sn(e,t,n){e.type="MemberExpression",e.computed=!1,e.optional=!1,e.object={type:"Identifier",name:t,start:e.start,end:e.start},e.property={type:"Identifier",name:n,start:e.end,end:e.end},delete e.name}var I="@fluixi/reactive/signal",w={$signal:{export:"signal",module:I,returns:"signal-handle"},$memo:{export:"memo",module:I,returns:"memo-handle"},$effect:{export:"effect",module:I,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:I,returns:"resource-handle"},$selector:{export:"createSelector",module:I,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:I,returns:"memo-accessor"},$untrack:{export:"untrack",module:I,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}},Qe={signal:"signal-handle",memo:"memo-handle",effect:"effect",store:"store-handle",createSignal:["signal-accessor","signal-setter"],createMemo:"memo-accessor",createEffect:"effect",createRenderEffect:"effect",createStore:"reactive-object",resource:"resource-handle",createResource:"reactive-object",createSelector:"memo-accessor",createDeferred:"memo-accessor"},on=["@fluixi/reactive","@fluixi/reactive/signal","@fluixi/reactive/signal-next","@fluixi/reactive/store","@fluixi/core","@fluixi/core/rx"],an=new RegExp(`\\$(?:${Object.keys(w).map(e=>e.slice(1)).join("|")})\\s*\\(`);function et(e){return an.test(e)}function tt(e){return Object.prototype.hasOwnProperty.call(w,e)}function nt(e){return on.includes(e)}function x(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties??[])n.type==="RestElement"?x(n.argument,t):x(n.value,t);return;case"ArrayPattern":for(let n of e.elements??[])x(n,t);return;case"AssignmentPattern":x(e.left,t);return;case"RestElement":x(e.argument,t);return}}function ne(e,t){if(!(!e||typeof e!="object"||typeof e.type!="string")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let s of r)ne(s,t);else r&&typeof r=="object"&&ne(r,t)}}}function ln(e,t){if(e.type!=="CallExpression")return;let n=e.callee;if(n?.type!=="Identifier")return;let r=n.name,s=t.primitives.get(r);if(s)return s;let i=w[r];if(i&&!t.shadowed.has(r))return i.returns}function cn(e,t,n){if(Array.isArray(t)){e.type==="ArrayPattern"&&e.elements.forEach((r,s)=>{let i=t[s];r?.type==="Identifier"&&i&&n.set(r.name,i)});return}e.type==="Identifier"&&n.set(e.name,t)}function rt(e){let t={kinds:new Map,primitives:new Map,shadowed:new Set},n=e;ne(n,r=>{let s=new Set;if(r.type==="VariableDeclarator")x(r.id,s);else if(r.type==="FunctionDeclaration"||r.type==="ClassDeclaration")x(r.id,s);else if(r.type==="ImportDefaultSpecifier"||r.type==="ImportNamespaceSpecifier")x(r.local,s);else if(r.type==="ImportSpecifier")x(r.local,s);else if(r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression"||r.type==="FunctionDeclaration")for(let i of r.params??[])x(i,s);for(let i of s)w[i]&&t.shadowed.add(i)});for(let r of n.body??[])if(r.type==="ImportDeclaration"&&nt(r.source?.value))for(let s of r.specifiers??[]){if(s.type!=="ImportSpecifier")continue;let i=s.imported,o=i.type==="Identifier"?i.name:i.value,a=Qe[o];a&&t.primitives.set(s.local.name,a)}return ne(n,r=>{if(r.type!=="VariableDeclarator"||!r.init)return;let s=ln(r.init,t);s&&cn(r.id,s,t.kinds)}),t}function ge(e,t){if(!(!e||typeof e!="object"||typeof e.type!="string")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let s of r)ge(s,t);else r&&typeof r=="object"&&ge(r,t)}}}function st(e){let t=[],n=[],r=new Map,s=new Set,{shadowed:i}=rt(e);return ge(e,o=>{if(o.type!=="CallExpression")return;let a=o.callee;if(a?.type!=="Identifier")return;let l=a.name;if(!tt(l))return;if(i.has(l)){s.has(l)||(s.add(l),n.push({name:l,message:`${l} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,start:a.start}));return}let c=w[l];t.push({start:a.start,end:a.end,code:c.export});let p=r.get(c.module)??new Set;p.add(c.export),r.set(c.module,p)}),{edits:t,diagnostics:n,imports:r}}function it(e,t){let n=[];for(let[r,s]of[...e.imports].sort(([i],[o])=>i.localeCompare(o))){let i=[...s].filter(o=>!t.has(o)).sort();i.length&&n.push(`import { ${i.join(", ")} } from ${JSON.stringify(r)};`)}return n.length?`${n.join(`
|
|
3
|
+
`)}
|
|
4
|
+
`:""}var pn=new Set(O),dn=new Set(D),un=new Set(T),fn=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function he(e,t,n=null,r=""){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let s of e)he(s,t,n,r);return}typeof e.type=="string"&&t(e,n,r);for(let s of Object.keys(e))s==="loc"||s==="leadingComments"||s==="trailingComments"||he(e[s],t,typeof e.type=="string"?e:n,s)}}var ye=e=>e.type==="JSXElement"||e.type==="JSXFragment";function mn(e,t,n){return ye(e)?!(t&&ye(t)&&n==="children"):!1}function gn(e,t){return e.type==="TaggedTemplateExpression"&&e.tag?.type==="Identifier"&&(e.tag.name===t||e.tag.name==="svg")}function lt(e){return e.filter(t=>!e.some(n=>n!==t&&n.start<=t.start&&n.end>=t.end&&n.end-n.start>t.end-t.start))}function re(e,t,n,r){let s=lt(r.filter(o=>o.start>=t&&o.end<=n)).sort((o,a)=>a.start-o.start),i=e.slice(t,n);for(let o of s)i=i.slice(0,o.start-t)+o.code+i.slice(o.end-t);return i}function hn(e,t,n){let r={code:re(e,t.start,t.end,n),reactive:P(M(t))};return t.type==="ArrowFunctionExpression"&&t.body?.type!=="BlockStatement"&&(r.arrow={params:t.params.map(s=>re(e,s.start,s.end,n)),body:re(e,t.body.start,t.body.end,n),bodyReactive:P(M(t.body))}),t.type==="ObjectExpression"&&(r.object=!0),r}function ct(e,t,n){if(!t||t.length===0)return e;let r=new Map;for(let s of t){let i=`${s.svg?"svg:":""}${s.html}`,o=n.get(i);o||(o=`_fxTmpl$${n.size}`,n.set(i,o)),r.set(s.id,o)}return e.replace(/_tmpl\$\d+/g,s=>r.get(s)??s)}function Ne(e,t){if(e.kind==="component"&&e.source){let n=e.source;n.origin==="builtin"?t.builtins.add(e.name):W(n.loading)&&!t.resolved.has(e.name)?t.deferred.set(e.name,n):(t.deferred.delete(e.name),t.resolved.set(e.name,n))}if("props"in e&&e.props)for(let n of e.props)n.kind==="event"&&n.event?.delegated&&t.delegatedEvents.add(n.event.name);if("children"in e&&e.children)for(let n of e.children)Ne(n,t)}function yn(e){let t=[`kind: ${JSON.stringify(e.kind)}`];return e.kind==="visible"&&e.rootMargin&&t.push(`rootMargin: ${JSON.stringify(e.rootMargin)}`),e.kind==="interaction"&&t.push(`events: ${JSON.stringify(e.events)}`),e.kind==="media"&&t.push(`query: ${JSON.stringify(e.query)}`),`{ ${t.join(", ")} }`}function Nn(e){let t=[];return e.quasi.quasis.forEach((n,r)=>{if(t.push({kind:"static",text:n.value.cooked??n.value.raw,start:n.start}),r<e.quasi.expressions.length){let s=e.quasi.expressions[r];t.push({kind:"hole",index:r,start:s.start,end:s.end})}}),t}function vn(e,t,n={}){let r=n.litTag??"html",s=n.format??"both",i=s!=="jsx",o=s!=="lit",a=i&&(e.includes(`${r}\``)||e.includes("svg`")),l=n.intrinsics!==!1&&et(e);if(!a&&!(o&&e.includes("<"))&&!l)return null;let c=(0,ot.parse)(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),p=[];he(c.program,(m,E,se)=>{(i&&gn(m,r)||o&&mn(m,E,se))&&p.push(m)});let u=n.propsDestructure?Ye(c.program,e,{runtimeModule:n.runtimeModule}):{edits:[],diagnostics:[],used:new Set},d=n.intrinsics===!1?{edits:[],diagnostics:[],imports:new Map}:st(c.program);if(p.length===0&&u.edits.length===0&&d.edits.length===0&&d.diagnostics.length===0&&u.diagnostics.length===0)return null;p.sort((m,E)=>E.start-m.start||m.end-E.end);let f=new Set(u.used),h={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set},y=new Map,k=[...u.edits,...d.edits];for(let m of p){let E=p.some(R=>R!==m&&R.start<=m.start&&R.end>=m.end&&R.end-R.start>m.end-m.start);if(ye(m)){k.push({start:m.start,end:m.end,code:xn(e,m,k,E,f,h,y,n)});continue}let se=m.quasi.expressions.map(R=>hn(e,R,k)),X=Fe(Nn(m),se,{...n,hoistTemplates:!0,templateClone:n.templateClone??!0,partialTemplates:E?!1:n.partialTemplates??!0,svg:m.tag.name==="svg"});for(let R of X.imports)f.add(R);Ne(X.ir,h),k.push({start:m.start,end:m.end,code:ct(X.code,X.templates,y)})}let v=new at.default(e);for(let m of lt(k))m.start===m.end?v.appendLeft(m.start,m.code):v.overwrite(m.start,m.end,m.code);let H=fe(c.program),ve=Rn(f,h,y,H,n);ve&&v.prepend(ve);let xe=it(d,H);xe&&v.prepend(xe);for(let m of c.program.body)m.type==="ImportDeclaration"&&m.source?.value==="@fluixi/core/rx"&&v.overwrite(m.source.start,m.source.end,JSON.stringify("@fluixi/reactive"));return{code:v.toString(),map:v.generateMap({source:t,includeContent:!0,hires:!0}),...u.diagnostics.length?{propsDiagnostics:u.diagnostics}:{},...d.diagnostics.length?{intrinsicDiagnostics:d.diagnostics}:{}}}function xn(e,t,n,r,s,i,o,a){let l=Ue(t,{code:p=>re(e,p.start,p.end,n),used:s});C(l),q(l,{resolver:ee(a.resolve??[]),modules:{controlFlowModule:a.controlFlowModule??a.runtimeModule??"@fluixi/dom",coreModule:a.coreModule??"@fluixi/core",routerModule:a.routerModule??"@fluixi/core/router-next"},strategyFor:p=>p.load}),G(l);let c=$.emit(l,{templateClone:a.templateClone??!0,partialTemplates:r?!1:a.partialTemplates??!0});for(let p of c.imports)s.add(p);return Ne(l,i),ct(c.code,c.templates,o)}function Rn(e,t,n,r,s){let i=s.runtimeModule??"@fluixi/dom",o=s.coreModule??"@fluixi/core",a=new Map,l=(d,g)=>a.set(d,[...a.get(d)??[],g]),c=new Set(e);for(let d of t.builtins)c.add(d);t.delegatedEvents.size>0&&c.add("delegateEvents");for(let d of[...c].sort())r.has(d)||(fn.has(d)?l(s.reactiveModule??"@fluixi/reactive/signal",d):un.has(d)?l(s.routerModule??"@fluixi/core/router-next",d):dn.has(d)?l(o,d):pn.has(d)?l(s.controlFlowModule??i,d):l(i,d));for(let[d,g]of t.resolved)r.has(d)||l(g.module,g.export==="default"?`default as ${d}`:d===g.export?d:`${g.export} as ${d}`);let p=[];for(let[d,g]of a)p.push(`import { ${g.join(", ")} } from ${JSON.stringify(d)};`);let u=[...t.deferred].filter(([d])=>!r.has(d));if(u.length>0){r.has("deferred")||p.push(`import { deferred } from ${JSON.stringify(o)};`);for(let[d,g]of u)p.push(`const ${d} = deferred(() => import(${JSON.stringify(g.module)}), { strategy: ${yn(g.loading)}, export: ${JSON.stringify(g.export)} });`)}for(let[d,g]of n)p.push(`const ${g} = ${JSON.stringify(d.startsWith("svg:")?d.slice(4):d)};`);return t.delegatedEvents.size>0&&p.push(`delegateEvents(${JSON.stringify([...t.delegatedEvents])});`),p.length>0?p.join(`
|
|
2
5
|
`)+`
|
|
3
6
|
`:null}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import MagicString from 'magic-string';
|
|
2
2
|
import { type CompileTemplateOptions } from '../lower/compile-template.js';
|
|
3
|
+
import { type PropsDiagnostic } from './props.js';
|
|
4
|
+
import { type IntrinsicDiagnostic } from './intrinsics.js';
|
|
3
5
|
export interface TransformOptions extends CompileTemplateOptions {
|
|
4
6
|
/**
|
|
5
7
|
* Which authoring syntaxes to compile. Both lower to the same IR, so this is
|
|
@@ -13,10 +15,28 @@ export interface TransformOptions extends CompileTemplateOptions {
|
|
|
13
15
|
runtimeModule?: string;
|
|
14
16
|
/** Where reactive primitives come from. @default '@fluixi/reactive/signal' */
|
|
15
17
|
reactiveModule?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Rewrite a component's destructured props into property reads, so
|
|
20
|
+
* `function Card({ title })` keeps updating instead of reading `title` once.
|
|
21
|
+
* The edits go into the same string as the template edits, so the map still points
|
|
22
|
+
* at what the author wrote.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
propsDestructure?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Compile the `$` reactive intrinsics — `$signal`, `$memo`, `$effect`, `$store` — into
|
|
28
|
+
* the runtime calls they stand for, importing what they need.
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
intrinsics?: boolean;
|
|
16
32
|
}
|
|
17
33
|
export interface TransformResult {
|
|
18
34
|
code: string;
|
|
19
35
|
map: ReturnType<MagicString['generateMap']>;
|
|
36
|
+
/** Props patterns the rewrite refused, when `propsDestructure` is on. */
|
|
37
|
+
propsDiagnostics?: PropsDiagnostic[];
|
|
38
|
+
/** `$` names the module bound itself, so the intrinsic did not fire. */
|
|
39
|
+
intrinsicDiagnostics?: IntrinsicDiagnostic[];
|
|
20
40
|
}
|
|
21
41
|
/**
|
|
22
42
|
* Compile every template in `code`. Returns null when the module has none, so a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/transform/templates.ts"],"names":[],"mappings":"AASA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/transform/templates.ts"],"names":[],"mappings":"AASA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAc1F,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAA2C,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAkBpG,MAAM,WAAW,gBAAiB,SAAQ,sBAAsB;IAC9D;;;;OAIG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAChC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5C,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,wEAAwE;IACxE,oBAAoB,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAC9C;AAkLD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,gBAAqB,GAC7B,eAAe,GAAG,IAAI,CA4GxB"}
|