babel-plugin-essor 0.0.17-beta.7 → 0.0.17
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/index.cjs +207 -95
- package/dist/index.js +207 -95
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -148,6 +148,7 @@ function createCompileContext(options, programPath) {
|
|
|
148
148
|
delegateEvents: /* @__PURE__ */ new Set(),
|
|
149
149
|
imports: /* @__PURE__ */ new Set(),
|
|
150
150
|
importIdentifiers: createImportIdentifiers(programPath, options.mode),
|
|
151
|
+
signalBindings: /* @__PURE__ */ new WeakSet(),
|
|
151
152
|
declarations: /* @__PURE__ */ new Map(),
|
|
152
153
|
hmrComponents: /* @__PURE__ */ new Set(),
|
|
153
154
|
hmrSignatures: /* @__PURE__ */ new Map(),
|
|
@@ -261,35 +262,46 @@ function createImport(path) {
|
|
|
261
262
|
}
|
|
262
263
|
|
|
263
264
|
// ../shared/dist/shared.js
|
|
264
|
-
var
|
|
265
|
+
var g = (e) => e !== null && typeof e == "object";
|
|
266
|
+
var m = Array.isArray;
|
|
265
267
|
function i(e) {
|
|
266
268
|
return typeof e == "string";
|
|
267
269
|
}
|
|
268
|
-
function
|
|
270
|
+
function d(e) {
|
|
269
271
|
return typeof e == "number";
|
|
270
272
|
}
|
|
271
|
-
function
|
|
273
|
+
function T(e) {
|
|
272
274
|
return e === null;
|
|
273
275
|
}
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
+
var F = (e) => {
|
|
277
|
+
if (u.call(e) !== "[object Object]") return false;
|
|
278
|
+
let t13 = Object.getPrototypeOf(e);
|
|
279
|
+
return t13 === null || t13 === Object.prototype;
|
|
280
|
+
};
|
|
281
|
+
function A(e) {
|
|
276
282
|
return typeof e == "boolean";
|
|
277
283
|
}
|
|
278
|
-
function
|
|
284
|
+
function U(e) {
|
|
279
285
|
return typeof e == "bigint";
|
|
280
286
|
}
|
|
281
287
|
var u = Object.prototype.toString;
|
|
288
|
+
var f = (e) => {
|
|
289
|
+
let t13 = /* @__PURE__ */ Object.create(null);
|
|
290
|
+
return ((n) => t13[n] || (t13[n] = e(n)));
|
|
291
|
+
};
|
|
292
|
+
var ne = /\B([A-Z])/g;
|
|
293
|
+
var b = f((e) => e.replaceAll(ne, "-$1").toLowerCase());
|
|
282
294
|
function x(e, t13) {
|
|
283
295
|
return i(e) ? e.indexOf(t13) === 0 : false;
|
|
284
296
|
}
|
|
285
|
-
function
|
|
297
|
+
function se(e, ...t13) {
|
|
286
298
|
console.warn(`[Essor warn]: ${e}`, ...t13);
|
|
287
299
|
}
|
|
288
|
-
var
|
|
289
|
-
function
|
|
290
|
-
let t13 = `${e}`, n =
|
|
300
|
+
var ce = /["&'<>]/;
|
|
301
|
+
function pe(e) {
|
|
302
|
+
let t13 = `${e}`, n = ce.exec(t13);
|
|
291
303
|
if (!n) return t13;
|
|
292
|
-
let o = "", r, s,
|
|
304
|
+
let o = "", r, s, l = 0;
|
|
293
305
|
for (s = n.index; s < t13.length; s++) {
|
|
294
306
|
switch (t13.charCodeAt(s)) {
|
|
295
307
|
case 34:
|
|
@@ -310,35 +322,71 @@ function le(e) {
|
|
|
310
322
|
default:
|
|
311
323
|
continue;
|
|
312
324
|
}
|
|
313
|
-
|
|
325
|
+
l !== s && (o += t13.slice(l, s)), l = s + 1, o += r;
|
|
314
326
|
}
|
|
315
|
-
return
|
|
327
|
+
return l !== s ? o + t13.slice(l, s) : o;
|
|
316
328
|
}
|
|
317
329
|
function a(e) {
|
|
318
330
|
let t13 = /* @__PURE__ */ Object.create(null);
|
|
319
331
|
for (let n of e.split(",")) t13[n] = 1;
|
|
320
332
|
return (n) => n in t13;
|
|
321
333
|
}
|
|
322
|
-
var
|
|
323
|
-
a(
|
|
324
|
-
a(`${
|
|
325
|
-
var
|
|
334
|
+
var N = "itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly";
|
|
335
|
+
a(N);
|
|
336
|
+
a(`${N},async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`);
|
|
337
|
+
var ke = { acceptCharset: "accept-charset", className: "class", htmlFor: "for", httpEquiv: "http-equiv" };
|
|
326
338
|
a("accept,accept-charset,accesskey,action,align,allow,alt,async,autocapitalize,autocomplete,autofocus,autoplay,background,bgcolor,border,buffered,capture,challenge,charset,checked,cite,class,code,codebase,color,cols,colspan,content,contenteditable,contextmenu,controls,coords,crossorigin,csp,data,datetime,decoding,default,defer,dir,dirname,disabled,download,draggable,dropzone,enctype,enterkeyhint,for,form,formaction,formenctype,formmethod,formnovalidate,formtarget,headers,height,hidden,high,href,hreflang,http-equiv,icon,id,importance,inert,integrity,ismap,itemprop,keytype,kind,label,lang,language,loading,list,loop,low,manifest,max,maxlength,minlength,media,min,multiple,muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,preload,radiogroup,readonly,referrerpolicy,rel,required,reversed,rows,rowspan,sandbox,scope,scoped,selected,shape,size,sizes,slot,span,spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,target,title,translate,type,usemap,value,width,wrap");
|
|
327
339
|
a("xmlns,accent-height,accumulate,additive,alignment-baseline,alphabetic,amplitude,arabic-form,ascent,attributeName,attributeType,azimuth,baseFrequency,baseline-shift,baseProfile,bbox,begin,bias,by,calcMode,cap-height,class,clip,clipPathUnits,clip-path,clip-rule,color,color-interpolation,color-interpolation-filters,color-profile,color-rendering,contentScriptType,contentStyleType,crossorigin,cursor,cx,cy,d,decelerate,descent,diffuseConstant,direction,display,divisor,dominant-baseline,dur,dx,dy,edgeMode,elevation,enable-background,end,exponent,fill,fill-opacity,fill-rule,filter,filterRes,filterUnits,flood-color,flood-opacity,font-family,font-size,font-size-adjust,font-stretch,font-style,font-variant,font-weight,format,from,fr,fx,fy,g1,g2,glyph-name,glyph-orientation-horizontal,glyph-orientation-vertical,glyphRef,gradientTransform,gradientUnits,hanging,height,href,hreflang,horiz-adv-x,horiz-origin-x,id,ideographic,image-rendering,in,in2,intercept,k,k1,k2,k3,k4,kernelMatrix,kernelUnitLength,kerning,keyPoints,keySplines,keyTimes,lang,lengthAdjust,letter-spacing,lighting-color,limitingConeAngle,local,marker-end,marker-mid,marker-start,markerHeight,markerUnits,markerWidth,mask,maskContentUnits,maskUnits,mathematical,max,media,method,min,mode,name,numOctaves,offset,opacity,operator,order,orient,orientation,origin,overflow,overline-position,overline-thickness,panose-1,paint-order,path,pathLength,patternContentUnits,patternTransform,patternUnits,ping,pointer-events,points,pointsAtX,pointsAtY,pointsAtZ,preserveAlpha,preserveAspectRatio,primitiveUnits,r,radius,referrerPolicy,refX,refY,rel,rendering-intent,repeatCount,repeatDur,requiredExtensions,requiredFeatures,restart,result,rotate,rx,ry,scale,seed,shape-rendering,slope,spacing,specularConstant,specularExponent,speed,spreadMethod,startOffset,stdDeviation,stemh,stemv,stitchTiles,stop-color,stop-opacity,strikethrough-position,strikethrough-thickness,string,stroke,stroke-dasharray,stroke-dashoffset,stroke-linecap,stroke-linejoin,stroke-miterlimit,stroke-opacity,stroke-width,style,surfaceScale,systemLanguage,tabindex,tableValues,target,targetX,targetY,text-anchor,text-decoration,text-rendering,textLength,to,transform,transform-origin,type,u1,u2,underline-position,underline-thickness,unicode,unicode-bidi,unicode-range,units-per-em,v-alphabetic,v-hanging,v-ideographic,v-mathematical,values,vector-effect,version,vert-adv-y,vert-origin-x,vert-origin-y,viewBox,viewTarget,visibility,width,widths,word-spacing,writing-mode,x,x-height,x1,x2,xChannelSelector,xlink:actuate,xlink:arcrole,xlink:href,xlink:role,xlink:show,xlink:title,xlink:type,xmlns:xlink,xml:base,xml:lang,xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan");
|
|
328
|
-
var
|
|
329
|
-
var
|
|
330
|
-
var
|
|
331
|
-
var
|
|
332
|
-
var
|
|
333
|
-
a(we);
|
|
334
|
-
var Ne = a(Te);
|
|
340
|
+
var Se = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
|
|
341
|
+
var ve = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
|
|
342
|
+
var Ae = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
|
|
343
|
+
var Ee = "beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart";
|
|
344
|
+
var Ne = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
|
335
345
|
a(Se);
|
|
336
|
-
var Ce = a(
|
|
337
|
-
|
|
338
|
-
var Re =
|
|
339
|
-
var ze =
|
|
340
|
-
|
|
341
|
-
|
|
346
|
+
var Ce = a(ve);
|
|
347
|
+
a(Ae);
|
|
348
|
+
var Re = a(Ne);
|
|
349
|
+
var ze = a(Ee);
|
|
350
|
+
var je = "data-hk-idx";
|
|
351
|
+
var He = "_$spread$";
|
|
352
|
+
var $e = /;(?![^(]*\))/g;
|
|
353
|
+
var Ue = /:([\s\S]+)/;
|
|
354
|
+
var Ge = /\/\*[\s\S]*?\*\//g;
|
|
355
|
+
function k(e) {
|
|
356
|
+
let t13 = {};
|
|
357
|
+
return e.replaceAll(Ge, "").split($e).forEach((n) => {
|
|
358
|
+
if (n) {
|
|
359
|
+
let o = n.split(Ue);
|
|
360
|
+
o.length > 1 && (t13[o[0].trim()] = o[1].trim());
|
|
361
|
+
}
|
|
362
|
+
}), t13;
|
|
363
|
+
}
|
|
364
|
+
function w(e) {
|
|
365
|
+
if (m(e)) {
|
|
366
|
+
let t13 = {};
|
|
367
|
+
for (let n of e) {
|
|
368
|
+
let o = i(n) ? k(n) : w(n);
|
|
369
|
+
if (o) for (let r in o) t13[r] = o[r];
|
|
370
|
+
}
|
|
371
|
+
return t13;
|
|
372
|
+
}
|
|
373
|
+
if (i(e)) return e;
|
|
374
|
+
if (g(e)) {
|
|
375
|
+
let t13 = {};
|
|
376
|
+
for (let n in e) {
|
|
377
|
+
let o = e[n];
|
|
378
|
+
if (i(o) || d(o)) {
|
|
379
|
+
t13[n] = o;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
let r = w(o);
|
|
383
|
+
if (!r) continue;
|
|
384
|
+
let s = i(r) ? k(r) : r;
|
|
385
|
+
for (let l in s) t13[l] = s[l];
|
|
386
|
+
}
|
|
387
|
+
return t13;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
342
390
|
function isAnyFunctionPath(path) {
|
|
343
391
|
return path.isFunctionDeclaration() || path.isFunctionExpression() || path.isArrowFunctionExpression();
|
|
344
392
|
}
|
|
@@ -400,7 +448,7 @@ function serializeStaticAttrs(attrs) {
|
|
|
400
448
|
const merged = [];
|
|
401
449
|
let classValue;
|
|
402
450
|
for (const attr of attrs) {
|
|
403
|
-
const name = (_a =
|
|
451
|
+
const name = (_a = ke[attr.name]) != null ? _a : attr.name;
|
|
404
452
|
if (name === "class") {
|
|
405
453
|
classValue = classValue ? `${classValue} ${attr.value}` : String(attr.value);
|
|
406
454
|
} else {
|
|
@@ -410,7 +458,7 @@ function serializeStaticAttrs(attrs) {
|
|
|
410
458
|
if (classValue) merged.unshift({ name: "class", value: classValue });
|
|
411
459
|
return merged.map((attr) => {
|
|
412
460
|
if (attr.value === true) return ` ${attr.name}`;
|
|
413
|
-
return ` ${attr.name}="${
|
|
461
|
+
return ` ${attr.name}="${pe(attr.value)}"`;
|
|
414
462
|
}).join("");
|
|
415
463
|
}
|
|
416
464
|
function resolveComponentCallee(tag, fallback) {
|
|
@@ -429,16 +477,16 @@ function isSerializableStaticValue(value) {
|
|
|
429
477
|
const stack = [value];
|
|
430
478
|
while (stack.length > 0) {
|
|
431
479
|
const current = stack.pop();
|
|
432
|
-
if (
|
|
480
|
+
if (T(current) || A(current) || d(current) || i(current) || U(current)) {
|
|
433
481
|
continue;
|
|
434
482
|
}
|
|
435
|
-
if (
|
|
483
|
+
if (m(current)) {
|
|
436
484
|
for (const item of current) {
|
|
437
485
|
stack.push(item);
|
|
438
486
|
}
|
|
439
487
|
continue;
|
|
440
488
|
}
|
|
441
|
-
if (!
|
|
489
|
+
if (!F(current)) {
|
|
442
490
|
return false;
|
|
443
491
|
}
|
|
444
492
|
const values = Object.values(current);
|
|
@@ -449,21 +497,29 @@ function isSerializableStaticValue(value) {
|
|
|
449
497
|
return true;
|
|
450
498
|
}
|
|
451
499
|
function styleToString(style) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
500
|
+
const normalized = w(style);
|
|
501
|
+
if (!normalized) return void 0;
|
|
502
|
+
if (i(normalized)) return normalized;
|
|
503
|
+
const parts = [];
|
|
504
|
+
for (const key in normalized) {
|
|
505
|
+
const value = normalized[key];
|
|
506
|
+
if (i(value) || d(value)) {
|
|
507
|
+
const prop = x(key, "--") ? key : b(key);
|
|
508
|
+
parts.push(`${prop}:${value}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return parts.join(";");
|
|
456
512
|
}
|
|
457
513
|
function shouldResolveStaticCollection(attrName) {
|
|
458
514
|
return attrName !== "ref" && !x(attrName, "bind:") && !normalizeEventName(attrName);
|
|
459
515
|
}
|
|
460
516
|
function normalizeTemplateAttrName(attrName) {
|
|
461
517
|
var _a;
|
|
462
|
-
return (_a =
|
|
518
|
+
return (_a = ke[attrName]) != null ? _a : attrName;
|
|
463
519
|
}
|
|
464
520
|
function createStaticAttr(attrName, value, order) {
|
|
465
521
|
return {
|
|
466
|
-
attr: { name: attrName, value },
|
|
522
|
+
attr: { name: attrName, value, order },
|
|
467
523
|
order,
|
|
468
524
|
templateName: normalizeTemplateAttrName(attrName)
|
|
469
525
|
};
|
|
@@ -474,7 +530,8 @@ function createDynamicAttr(attrPath, attrName, value, effectKind, order) {
|
|
|
474
530
|
path: attrPath,
|
|
475
531
|
name: attrName,
|
|
476
532
|
value,
|
|
477
|
-
effectKind
|
|
533
|
+
effectKind,
|
|
534
|
+
order
|
|
478
535
|
},
|
|
479
536
|
order,
|
|
480
537
|
templateName: normalizeTemplateAttrName(attrName)
|
|
@@ -489,13 +546,15 @@ function resolveStaticExpressionValue(attrName, expressionPath) {
|
|
|
489
546
|
return void 0;
|
|
490
547
|
}
|
|
491
548
|
let value = evaluated.value;
|
|
492
|
-
if (attrName === "style"
|
|
493
|
-
|
|
549
|
+
if (attrName === "style") {
|
|
550
|
+
const style = styleToString(value);
|
|
551
|
+
if (style === void 0) return void 0;
|
|
552
|
+
value = style;
|
|
494
553
|
}
|
|
495
|
-
if (i(value) ||
|
|
554
|
+
if (i(value) || A(value)) {
|
|
496
555
|
return value;
|
|
497
556
|
}
|
|
498
|
-
if (
|
|
557
|
+
if (d(value)) {
|
|
499
558
|
return String(value);
|
|
500
559
|
}
|
|
501
560
|
return void 0;
|
|
@@ -548,7 +607,8 @@ function parseAttributes(path) {
|
|
|
548
607
|
if (attrPath.isJSXSpreadAttribute()) {
|
|
549
608
|
spreadAttrs.push({
|
|
550
609
|
value: attrPath.node.argument,
|
|
551
|
-
effectKind: classifyAttrValue(attrPath.node.argument).kind
|
|
610
|
+
effectKind: classifyAttrValue(attrPath.node.argument).kind,
|
|
611
|
+
order
|
|
552
612
|
});
|
|
553
613
|
continue;
|
|
554
614
|
}
|
|
@@ -636,7 +696,7 @@ function unwrapTopLevelDeclaration(statementPath) {
|
|
|
636
696
|
}
|
|
637
697
|
if (statementPath.isExportNamedDeclaration() || statementPath.isExportDefaultDeclaration()) {
|
|
638
698
|
const declarationPath = statementPath.get("declaration");
|
|
639
|
-
if (declarationPath && !
|
|
699
|
+
if (declarationPath && !m(declarationPath) && (declarationPath.isFunctionDeclaration() || declarationPath.isVariableDeclaration())) {
|
|
640
700
|
return declarationPath;
|
|
641
701
|
}
|
|
642
702
|
}
|
|
@@ -1045,7 +1105,7 @@ function patternHasSignalBinding(node) {
|
|
|
1045
1105
|
if (core.types.isIdentifier(node)) return isSignal(node.name);
|
|
1046
1106
|
if (core.types.isObjectPattern(node)) {
|
|
1047
1107
|
return node.properties.some(
|
|
1048
|
-
(
|
|
1108
|
+
(p) => core.types.isRestElement(p) ? patternHasSignalBinding(p.argument) : patternHasSignalBinding(p.value)
|
|
1049
1109
|
);
|
|
1050
1110
|
}
|
|
1051
1111
|
if (core.types.isArrayPattern(node)) {
|
|
@@ -1193,9 +1253,9 @@ function isAlreadyValueAccess(path) {
|
|
|
1193
1253
|
if (!core.types.isParenthesizedExpression(parent) && !core.types.isTSAsExpression(parent) && !core.types.isTSNonNullExpression(parent)) {
|
|
1194
1254
|
return false;
|
|
1195
1255
|
}
|
|
1196
|
-
const ancestor = path.findParent((
|
|
1197
|
-
if (!isMemberLike(
|
|
1198
|
-
return isMemberAccessingProperty(
|
|
1256
|
+
const ancestor = path.findParent((p) => {
|
|
1257
|
+
if (!isMemberLike(p.node)) return false;
|
|
1258
|
+
return isMemberAccessingProperty(p.node, "value");
|
|
1199
1259
|
});
|
|
1200
1260
|
return !!ancestor;
|
|
1201
1261
|
}
|
|
@@ -1290,7 +1350,7 @@ function collectObjectPattern(pattern, base, leaves, rests) {
|
|
|
1290
1350
|
continue;
|
|
1291
1351
|
}
|
|
1292
1352
|
const { keyExpr, computed, excludeKey } = resolveKey(prop);
|
|
1293
|
-
if (excludeKey
|
|
1353
|
+
if (!T(excludeKey)) excludeKeys.push(excludeKey);
|
|
1294
1354
|
const access = core.types.memberExpression(clone2(base), keyExpr, computed);
|
|
1295
1355
|
collectTarget(prop.value, access, leaves, rests);
|
|
1296
1356
|
}
|
|
@@ -1322,7 +1382,7 @@ function ensureBlockBody(path) {
|
|
|
1322
1382
|
return block;
|
|
1323
1383
|
}
|
|
1324
1384
|
function isInsidePattern(ref, pattern) {
|
|
1325
|
-
return !!ref.findParent((
|
|
1385
|
+
return !!ref.findParent((p) => p.node === pattern);
|
|
1326
1386
|
}
|
|
1327
1387
|
function accessorFor(pattern, base, name) {
|
|
1328
1388
|
var _a;
|
|
@@ -1342,7 +1402,7 @@ function transformFnProps(path) {
|
|
|
1342
1402
|
collectObjectPattern(firstParam, base, initLeaves, initRests);
|
|
1343
1403
|
const conflicts = [...initLeaves, ...initRests].map((b2) => b2.name).filter((name) => x(name, signalPrefix));
|
|
1344
1404
|
if (conflicts.length > 0) {
|
|
1345
|
-
|
|
1405
|
+
se("transformProps", "Property names cannot start with signal prefix", conflicts);
|
|
1346
1406
|
}
|
|
1347
1407
|
if (initLeaves.length === 0 && initRests.length === 1 && firstParam.properties.length === 1 && core.types.isRestElement(firstParam.properties[0])) {
|
|
1348
1408
|
path.node.params[0] = core.types.identifier(initRests[0].name);
|
|
@@ -1450,6 +1510,18 @@ function hasDynamicBoundary(children, index) {
|
|
|
1450
1510
|
const isDynamic = (n) => (n == null ? void 0 : n.type) === 3 /* EXPRESSION */ || (n == null ? void 0 : n.type) === 1 /* COMPONENT */ || (n == null ? void 0 : n.type) === 4 /* FOR */;
|
|
1451
1511
|
return isText(prev) || isText(next) || isDynamic(prev) || isDynamic(next);
|
|
1452
1512
|
}
|
|
1513
|
+
function getDynamicAnchorKind(children, index, mode) {
|
|
1514
|
+
if (!hasDynamicBoundary(children, index)) {
|
|
1515
|
+
const next = children[index + 1];
|
|
1516
|
+
if ((mode === "hydrate" || mode === "server") && (next == null ? void 0 : next.type) === 0 /* ELEMENT */) {
|
|
1517
|
+
return "element";
|
|
1518
|
+
}
|
|
1519
|
+
if (!next) {
|
|
1520
|
+
return "tail";
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
return "comment";
|
|
1524
|
+
}
|
|
1453
1525
|
function buildIR(path, ctx) {
|
|
1454
1526
|
if (path.isJSXFragment()) {
|
|
1455
1527
|
useImport("Fragment");
|
|
@@ -1466,14 +1538,14 @@ function buildElementIR(tag, path, ctx) {
|
|
|
1466
1538
|
const node = {
|
|
1467
1539
|
type: 0 /* ELEMENT */,
|
|
1468
1540
|
tag,
|
|
1469
|
-
isSVG:
|
|
1541
|
+
isSVG: Ce(tag),
|
|
1470
1542
|
staticAttrs,
|
|
1471
1543
|
dynamicAttrs: [],
|
|
1472
1544
|
events: [],
|
|
1473
|
-
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind })),
|
|
1545
|
+
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind, order: s.order })),
|
|
1474
1546
|
binds: [],
|
|
1475
1547
|
children: [],
|
|
1476
|
-
selfClosing:
|
|
1548
|
+
selfClosing: Re(tag),
|
|
1477
1549
|
loc: path.node.loc
|
|
1478
1550
|
};
|
|
1479
1551
|
for (const attr of dynamicAttrs) {
|
|
@@ -1493,7 +1565,8 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1493
1565
|
props.push({
|
|
1494
1566
|
name: attr.name,
|
|
1495
1567
|
value: i(attr.value) ? core.types.stringLiteral(attr.value) : core.types.booleanLiteral(attr.value),
|
|
1496
|
-
kind: "static"
|
|
1568
|
+
kind: "static",
|
|
1569
|
+
order: attr.order
|
|
1497
1570
|
});
|
|
1498
1571
|
}
|
|
1499
1572
|
for (const attr of dynamicAttrs) {
|
|
@@ -1502,7 +1575,8 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1502
1575
|
props.push({
|
|
1503
1576
|
name: attr.name,
|
|
1504
1577
|
value: attr.value,
|
|
1505
|
-
kind: attr.effectKind
|
|
1578
|
+
kind: attr.effectKind,
|
|
1579
|
+
order: attr.order
|
|
1506
1580
|
});
|
|
1507
1581
|
} else if (x(attr.name, "bind:")) {
|
|
1508
1582
|
const binding = attr.name.slice("bind:".length);
|
|
@@ -1513,18 +1587,21 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1513
1587
|
props.push({
|
|
1514
1588
|
name: binding,
|
|
1515
1589
|
value: core.types.cloneNode(valueExpr),
|
|
1516
|
-
kind: attr.effectKind
|
|
1590
|
+
kind: attr.effectKind,
|
|
1591
|
+
order: attr.order
|
|
1517
1592
|
});
|
|
1518
1593
|
props.push({
|
|
1519
1594
|
name: `update:${binding}`,
|
|
1520
1595
|
value: createBindingSetter(valueExpr),
|
|
1521
|
-
kind: "static"
|
|
1596
|
+
kind: "static",
|
|
1597
|
+
order: attr.order
|
|
1522
1598
|
});
|
|
1523
1599
|
} else {
|
|
1524
1600
|
props.push({
|
|
1525
1601
|
name: attr.name,
|
|
1526
1602
|
value: attr.value,
|
|
1527
|
-
kind: attr.effectKind
|
|
1603
|
+
kind: attr.effectKind,
|
|
1604
|
+
order: attr.order
|
|
1528
1605
|
});
|
|
1529
1606
|
}
|
|
1530
1607
|
}
|
|
@@ -1532,7 +1609,7 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1532
1609
|
type: 1 /* COMPONENT */,
|
|
1533
1610
|
tag,
|
|
1534
1611
|
props,
|
|
1535
|
-
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind })),
|
|
1612
|
+
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind, order: s.order })),
|
|
1536
1613
|
children: buildChildren(path, ctx),
|
|
1537
1614
|
loc: path.node.loc
|
|
1538
1615
|
};
|
|
@@ -1541,7 +1618,7 @@ function applyDynamicAttr(node, attr, ctx) {
|
|
|
1541
1618
|
const { name, value, effectKind, path } = attr;
|
|
1542
1619
|
const eventName = normalizeEventName(name);
|
|
1543
1620
|
if (eventName) {
|
|
1544
|
-
const delegated = !!(ctx.options.delegateEvents &&
|
|
1621
|
+
const delegated = !!(ctx.options.delegateEvents && ze(eventName));
|
|
1545
1622
|
node.events.push({
|
|
1546
1623
|
name: eventName,
|
|
1547
1624
|
handler: value,
|
|
@@ -1629,7 +1706,7 @@ function isPropsChildrenExpression(expression) {
|
|
|
1629
1706
|
const binding = expression.scope.getBinding(node.object.name);
|
|
1630
1707
|
const bindingPath = binding == null ? void 0 : binding.path;
|
|
1631
1708
|
if (!(bindingPath == null ? void 0 : bindingPath.isIdentifier())) return false;
|
|
1632
|
-
const owner = bindingPath.findParent((
|
|
1709
|
+
const owner = bindingPath.findParent((p) => isAnyFunctionPath(p));
|
|
1633
1710
|
if (!owner) return false;
|
|
1634
1711
|
const fn = owner.node;
|
|
1635
1712
|
const componentName = getEnclosingFunctionName(owner);
|
|
@@ -1692,6 +1769,7 @@ function buildForIR(expression, ctx) {
|
|
|
1692
1769
|
};
|
|
1693
1770
|
}
|
|
1694
1771
|
function extractKeyExpression(path) {
|
|
1772
|
+
if (path.isJSXFragment()) return extractFragmentKeyExpression(path);
|
|
1695
1773
|
if (!path.isJSXElement()) return null;
|
|
1696
1774
|
for (const attrPath of path.get("openingElement.attributes")) {
|
|
1697
1775
|
if (!attrPath.isJSXAttribute()) continue;
|
|
@@ -1706,7 +1784,7 @@ function extractKeyExpression(path) {
|
|
|
1706
1784
|
return core.types.stringLiteral(value.value);
|
|
1707
1785
|
}
|
|
1708
1786
|
const valuePath = attrPath.get("value");
|
|
1709
|
-
if (!
|
|
1787
|
+
if (!m(valuePath) && valuePath.isJSXExpressionContainer()) {
|
|
1710
1788
|
const expressionPath = valuePath.get("expression");
|
|
1711
1789
|
attrPath.remove();
|
|
1712
1790
|
if (expressionPath.isJSXEmptyExpression()) return null;
|
|
@@ -1717,9 +1795,16 @@ function extractKeyExpression(path) {
|
|
|
1717
1795
|
}
|
|
1718
1796
|
return null;
|
|
1719
1797
|
}
|
|
1798
|
+
function extractFragmentKeyExpression(path) {
|
|
1799
|
+
const children = path.get("children").filter(isValidChild);
|
|
1800
|
+
if (children.length !== 1) return null;
|
|
1801
|
+
const child = children[0];
|
|
1802
|
+
if (!child.isJSXElement() && !child.isJSXFragment()) return null;
|
|
1803
|
+
return extractKeyExpression(child);
|
|
1804
|
+
}
|
|
1720
1805
|
function getForCallbackBody(callback) {
|
|
1721
1806
|
const bodyPath = callback.get("body");
|
|
1722
|
-
if (
|
|
1807
|
+
if (m(bodyPath)) return null;
|
|
1723
1808
|
if (bodyPath.isJSXElement() || bodyPath.isJSXFragment()) {
|
|
1724
1809
|
return {
|
|
1725
1810
|
path: bodyPath,
|
|
@@ -1736,7 +1821,7 @@ function getForCallbackBody(callback) {
|
|
|
1736
1821
|
continue;
|
|
1737
1822
|
}
|
|
1738
1823
|
const argument = statement.get("argument");
|
|
1739
|
-
if (
|
|
1824
|
+
if (m(argument) || !argument.node) {
|
|
1740
1825
|
prelude.push(statement.node);
|
|
1741
1826
|
continue;
|
|
1742
1827
|
}
|
|
@@ -1812,16 +1897,55 @@ function createPropNode(name, value, kind, options) {
|
|
|
1812
1897
|
function composePropsExpression(props, spreads, options) {
|
|
1813
1898
|
if (spreads.length === 0) {
|
|
1814
1899
|
if (props.length === 0) return core.types.objectExpression([]);
|
|
1815
|
-
return core.types.objectExpression(props.map((
|
|
1900
|
+
return core.types.objectExpression(props.map((p) => createPropNode(p.name, p.value, p.kind, options)));
|
|
1901
|
+
}
|
|
1902
|
+
if (props.some((prop) => prop.order == null) || spreads.some((spread) => spread.order == null)) {
|
|
1903
|
+
return composeUnorderedPropsExpression(props, spreads, options);
|
|
1904
|
+
}
|
|
1905
|
+
const ordered = [
|
|
1906
|
+
...props.map((prop, sequence) => ({
|
|
1907
|
+
type: "prop",
|
|
1908
|
+
order: prop.order,
|
|
1909
|
+
sequence,
|
|
1910
|
+
prop
|
|
1911
|
+
})),
|
|
1912
|
+
...spreads.map((spread, sequence) => ({
|
|
1913
|
+
type: "spread",
|
|
1914
|
+
order: spread.order,
|
|
1915
|
+
sequence,
|
|
1916
|
+
spread
|
|
1917
|
+
}))
|
|
1918
|
+
].sort((a2, b2) => a2.order - b2.order || a2.sequence - b2.sequence);
|
|
1919
|
+
const parts = [];
|
|
1920
|
+
let propNodes = [];
|
|
1921
|
+
const flushProps = () => {
|
|
1922
|
+
if (propNodes.length === 0) return;
|
|
1923
|
+
parts.push(core.types.objectExpression(propNodes));
|
|
1924
|
+
propNodes = [];
|
|
1925
|
+
};
|
|
1926
|
+
for (const entry of ordered) {
|
|
1927
|
+
if (entry.type === "prop") {
|
|
1928
|
+
propNodes.push(createPropNode(entry.prop.name, entry.prop.value, entry.prop.kind, options));
|
|
1929
|
+
continue;
|
|
1930
|
+
}
|
|
1931
|
+
flushProps();
|
|
1932
|
+
parts.push(cloneValue(entry.spread.value, options.cloneValues));
|
|
1816
1933
|
}
|
|
1934
|
+
flushProps();
|
|
1935
|
+
return composeAssignParts(parts);
|
|
1936
|
+
}
|
|
1937
|
+
function composeUnorderedPropsExpression(props, spreads, options) {
|
|
1817
1938
|
const parts = [];
|
|
1818
|
-
const propNodes = props.map((
|
|
1939
|
+
const propNodes = props.map((p) => createPropNode(p.name, p.value, p.kind, options));
|
|
1819
1940
|
if (propNodes.length > 0) {
|
|
1820
1941
|
parts.push(core.types.objectExpression(propNodes));
|
|
1821
1942
|
}
|
|
1822
1943
|
for (const spread of spreads) {
|
|
1823
1944
|
parts.push(cloneValue(spread.value, options.cloneValues));
|
|
1824
1945
|
}
|
|
1946
|
+
return composeAssignParts(parts);
|
|
1947
|
+
}
|
|
1948
|
+
function composeAssignParts(parts) {
|
|
1825
1949
|
if (parts.length === 0) return core.types.objectExpression([]);
|
|
1826
1950
|
if (parts.length === 1) return parts[0];
|
|
1827
1951
|
return core.types.callExpression(core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")), [
|
|
@@ -2093,7 +2217,7 @@ function generateServerFor(node, ctx) {
|
|
|
2093
2217
|
return buildForCall(node, bodyExpr);
|
|
2094
2218
|
}
|
|
2095
2219
|
function generateServerElement(node, ctx, withHydrationKey = true, staticIndex, options = {}) {
|
|
2096
|
-
var _a
|
|
2220
|
+
var _a;
|
|
2097
2221
|
const dynamicAttrExprs = [...(_a = options.prependAttrExprs) != null ? _a : []];
|
|
2098
2222
|
for (const attr of node.dynamicAttrs) {
|
|
2099
2223
|
let expr;
|
|
@@ -2121,7 +2245,7 @@ function generateServerElement(node, ctx, withHydrationKey = true, staticIndex,
|
|
|
2121
2245
|
}
|
|
2122
2246
|
const templates = [];
|
|
2123
2247
|
const expressions = [];
|
|
2124
|
-
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name:
|
|
2248
|
+
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name: je, value: String(staticIndex) }];
|
|
2125
2249
|
const attrs = serializeStaticAttrs(staticAttrs);
|
|
2126
2250
|
const textareaValueBind = node.tag === "textarea" ? findBind(node, "value") : null;
|
|
2127
2251
|
let currentStr = `<${node.tag}`;
|
|
@@ -2152,11 +2276,11 @@ function generateServerElement(node, ctx, withHydrationKey = true, staticIndex,
|
|
|
2152
2276
|
if (child.type === 2 /* TEXT */) {
|
|
2153
2277
|
currentStr += escapeServerTemplateText(child.value);
|
|
2154
2278
|
} else if (child.type === 3 /* EXPRESSION */ || child.type === 1 /* COMPONENT */ || child.type === 4 /* FOR */) {
|
|
2155
|
-
const
|
|
2279
|
+
const anchorKind = getDynamicAnchorKind(node.children, i2, "server");
|
|
2156
2280
|
const slotIndex = markerIndex++;
|
|
2157
2281
|
templates.push(currentStr);
|
|
2158
|
-
currentStr =
|
|
2159
|
-
if (
|
|
2282
|
+
currentStr = anchorKind === "comment" ? `<!--${slotIndex}-->` : "";
|
|
2283
|
+
if (anchorKind === "element") {
|
|
2160
2284
|
pendingAnchorIndex = slotIndex;
|
|
2161
2285
|
}
|
|
2162
2286
|
expressions.push(generateServerNode(child, ctx));
|
|
@@ -2179,7 +2303,7 @@ function generateServerElement(node, ctx, withHydrationKey = true, staticIndex,
|
|
|
2179
2303
|
}
|
|
2180
2304
|
}
|
|
2181
2305
|
const staticHTML = buildStaticServerHTML(child, anchorIndex);
|
|
2182
|
-
if (staticHTML
|
|
2306
|
+
if (!T(staticHTML)) {
|
|
2183
2307
|
currentStr += staticHTML;
|
|
2184
2308
|
} else {
|
|
2185
2309
|
templates.push(currentStr);
|
|
@@ -2224,7 +2348,7 @@ function buildStaticServerHTML(node, staticIndex) {
|
|
|
2224
2348
|
if (node.binds.length > 0 || node.dynamicAttrs.length > 0 || node.spreads.length > 0) {
|
|
2225
2349
|
return null;
|
|
2226
2350
|
}
|
|
2227
|
-
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name:
|
|
2351
|
+
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name: je, value: String(staticIndex) }];
|
|
2228
2352
|
const attrs = serializeStaticAttrs(staticAttrs);
|
|
2229
2353
|
if (node.selfClosing) {
|
|
2230
2354
|
return `<${node.tag}${attrs} />`;
|
|
@@ -2236,7 +2360,7 @@ function buildStaticServerHTML(node, staticIndex) {
|
|
|
2236
2360
|
} else if (child.type === 0 /* ELEMENT */) {
|
|
2237
2361
|
if (child.binds.length > 0) return null;
|
|
2238
2362
|
const nested = buildStaticServerHTML(child);
|
|
2239
|
-
if (nested
|
|
2363
|
+
if (T(nested)) return null;
|
|
2240
2364
|
html += nested;
|
|
2241
2365
|
} else {
|
|
2242
2366
|
return null;
|
|
@@ -2274,18 +2398,6 @@ function shouldCloseTag(element, isLastElement, hasClosingParent, options) {
|
|
|
2274
2398
|
function closeTag(element, isLastElement, hasClosingParent, options) {
|
|
2275
2399
|
return shouldCloseTag(element, isLastElement, hasClosingParent, options) ? `</${element.tag}>` : "";
|
|
2276
2400
|
}
|
|
2277
|
-
function getDynamicAnchorKind(children, index, mode) {
|
|
2278
|
-
if ((mode === "client" || mode === "hydrate") && !hasDynamicBoundary(children, index)) {
|
|
2279
|
-
const next = children[index + 1];
|
|
2280
|
-
if (mode === "hydrate" && (next == null ? void 0 : next.type) === 0 /* ELEMENT */) {
|
|
2281
|
-
return "element";
|
|
2282
|
-
}
|
|
2283
|
-
if (!next) {
|
|
2284
|
-
return "tail";
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2287
|
-
return "comment";
|
|
2288
|
-
}
|
|
2289
2401
|
function findLastOmittableElementIndex(children, mode) {
|
|
2290
2402
|
for (let i2 = children.length - 1; i2 >= 0; i2--) {
|
|
2291
2403
|
const child = children[i2];
|
|
@@ -2310,7 +2422,7 @@ function buildTemplateAndFlatten(root, mode) {
|
|
|
2310
2422
|
const myId = nextId++;
|
|
2311
2423
|
const staticAttrs = mode === "hydrate" && forcedStaticIndex !== void 0 ? [
|
|
2312
2424
|
...element.staticAttrs,
|
|
2313
|
-
{ name:
|
|
2425
|
+
{ name: je, value: String(forcedStaticIndex) }
|
|
2314
2426
|
] : element.staticAttrs;
|
|
2315
2427
|
const attrs = serializeStaticAttrs(staticAttrs);
|
|
2316
2428
|
if (element.selfClosing) {
|
|
@@ -2349,7 +2461,7 @@ function buildTemplateAndFlatten(root, mode) {
|
|
|
2349
2461
|
const child = element.children[i2];
|
|
2350
2462
|
switch (child.type) {
|
|
2351
2463
|
case 2 /* TEXT */:
|
|
2352
|
-
template += mode === "hydrate" ? child.value :
|
|
2464
|
+
template += mode === "hydrate" ? child.value : pe(child.value);
|
|
2353
2465
|
nodes.push({
|
|
2354
2466
|
id: nextId++,
|
|
2355
2467
|
kind: "text",
|
|
@@ -2416,7 +2528,7 @@ function buildStaticTemplateString(node, mode) {
|
|
|
2416
2528
|
function visit(current, isLastElement, hasClosingParent) {
|
|
2417
2529
|
switch (current.type) {
|
|
2418
2530
|
case 2 /* TEXT */:
|
|
2419
|
-
return mode === "hydrate" ? current.value :
|
|
2531
|
+
return mode === "hydrate" ? current.value : pe(current.value);
|
|
2420
2532
|
case 0 /* ELEMENT */: {
|
|
2421
2533
|
const attrs = serializeStaticAttrs(current.staticAttrs);
|
|
2422
2534
|
if (current.selfClosing) return selfClosingTag(current, attrs);
|
|
@@ -2719,7 +2831,7 @@ function emitDynamicAttr(attr, target, body, state, pendingMemoPatches) {
|
|
|
2719
2831
|
function emitSpread(spread, target, body, state, pendingMemoPatches) {
|
|
2720
2832
|
emitPatchOrEffect(
|
|
2721
2833
|
target,
|
|
2722
|
-
|
|
2834
|
+
He,
|
|
2723
2835
|
spread.value,
|
|
2724
2836
|
spread.kind,
|
|
2725
2837
|
body,
|
package/dist/index.js
CHANGED
|
@@ -146,6 +146,7 @@ function createCompileContext(options, programPath) {
|
|
|
146
146
|
delegateEvents: /* @__PURE__ */ new Set(),
|
|
147
147
|
imports: /* @__PURE__ */ new Set(),
|
|
148
148
|
importIdentifiers: createImportIdentifiers(programPath, options.mode),
|
|
149
|
+
signalBindings: /* @__PURE__ */ new WeakSet(),
|
|
149
150
|
declarations: /* @__PURE__ */ new Map(),
|
|
150
151
|
hmrComponents: /* @__PURE__ */ new Set(),
|
|
151
152
|
hmrSignatures: /* @__PURE__ */ new Map(),
|
|
@@ -259,35 +260,46 @@ function createImport(path) {
|
|
|
259
260
|
}
|
|
260
261
|
|
|
261
262
|
// ../shared/dist/shared.js
|
|
262
|
-
var
|
|
263
|
+
var g = (e) => e !== null && typeof e == "object";
|
|
264
|
+
var m = Array.isArray;
|
|
263
265
|
function i(e) {
|
|
264
266
|
return typeof e == "string";
|
|
265
267
|
}
|
|
266
|
-
function
|
|
268
|
+
function d(e) {
|
|
267
269
|
return typeof e == "number";
|
|
268
270
|
}
|
|
269
|
-
function
|
|
271
|
+
function T(e) {
|
|
270
272
|
return e === null;
|
|
271
273
|
}
|
|
272
|
-
var
|
|
273
|
-
|
|
274
|
+
var F = (e) => {
|
|
275
|
+
if (u.call(e) !== "[object Object]") return false;
|
|
276
|
+
let t13 = Object.getPrototypeOf(e);
|
|
277
|
+
return t13 === null || t13 === Object.prototype;
|
|
278
|
+
};
|
|
279
|
+
function A(e) {
|
|
274
280
|
return typeof e == "boolean";
|
|
275
281
|
}
|
|
276
|
-
function
|
|
282
|
+
function U(e) {
|
|
277
283
|
return typeof e == "bigint";
|
|
278
284
|
}
|
|
279
285
|
var u = Object.prototype.toString;
|
|
286
|
+
var f = (e) => {
|
|
287
|
+
let t13 = /* @__PURE__ */ Object.create(null);
|
|
288
|
+
return ((n) => t13[n] || (t13[n] = e(n)));
|
|
289
|
+
};
|
|
290
|
+
var ne = /\B([A-Z])/g;
|
|
291
|
+
var b = f((e) => e.replaceAll(ne, "-$1").toLowerCase());
|
|
280
292
|
function x(e, t13) {
|
|
281
293
|
return i(e) ? e.indexOf(t13) === 0 : false;
|
|
282
294
|
}
|
|
283
|
-
function
|
|
295
|
+
function se(e, ...t13) {
|
|
284
296
|
console.warn(`[Essor warn]: ${e}`, ...t13);
|
|
285
297
|
}
|
|
286
|
-
var
|
|
287
|
-
function
|
|
288
|
-
let t13 = `${e}`, n =
|
|
298
|
+
var ce = /["&'<>]/;
|
|
299
|
+
function pe(e) {
|
|
300
|
+
let t13 = `${e}`, n = ce.exec(t13);
|
|
289
301
|
if (!n) return t13;
|
|
290
|
-
let o = "", r, s,
|
|
302
|
+
let o = "", r, s, l = 0;
|
|
291
303
|
for (s = n.index; s < t13.length; s++) {
|
|
292
304
|
switch (t13.charCodeAt(s)) {
|
|
293
305
|
case 34:
|
|
@@ -308,35 +320,71 @@ function le(e) {
|
|
|
308
320
|
default:
|
|
309
321
|
continue;
|
|
310
322
|
}
|
|
311
|
-
|
|
323
|
+
l !== s && (o += t13.slice(l, s)), l = s + 1, o += r;
|
|
312
324
|
}
|
|
313
|
-
return
|
|
325
|
+
return l !== s ? o + t13.slice(l, s) : o;
|
|
314
326
|
}
|
|
315
327
|
function a(e) {
|
|
316
328
|
let t13 = /* @__PURE__ */ Object.create(null);
|
|
317
329
|
for (let n of e.split(",")) t13[n] = 1;
|
|
318
330
|
return (n) => n in t13;
|
|
319
331
|
}
|
|
320
|
-
var
|
|
321
|
-
a(
|
|
322
|
-
a(`${
|
|
323
|
-
var
|
|
332
|
+
var N = "itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly";
|
|
333
|
+
a(N);
|
|
334
|
+
a(`${N},async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`);
|
|
335
|
+
var ke = { acceptCharset: "accept-charset", className: "class", htmlFor: "for", httpEquiv: "http-equiv" };
|
|
324
336
|
a("accept,accept-charset,accesskey,action,align,allow,alt,async,autocapitalize,autocomplete,autofocus,autoplay,background,bgcolor,border,buffered,capture,challenge,charset,checked,cite,class,code,codebase,color,cols,colspan,content,contenteditable,contextmenu,controls,coords,crossorigin,csp,data,datetime,decoding,default,defer,dir,dirname,disabled,download,draggable,dropzone,enctype,enterkeyhint,for,form,formaction,formenctype,formmethod,formnovalidate,formtarget,headers,height,hidden,high,href,hreflang,http-equiv,icon,id,importance,inert,integrity,ismap,itemprop,keytype,kind,label,lang,language,loading,list,loop,low,manifest,max,maxlength,minlength,media,min,multiple,muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,preload,radiogroup,readonly,referrerpolicy,rel,required,reversed,rows,rowspan,sandbox,scope,scoped,selected,shape,size,sizes,slot,span,spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,target,title,translate,type,usemap,value,width,wrap");
|
|
325
337
|
a("xmlns,accent-height,accumulate,additive,alignment-baseline,alphabetic,amplitude,arabic-form,ascent,attributeName,attributeType,azimuth,baseFrequency,baseline-shift,baseProfile,bbox,begin,bias,by,calcMode,cap-height,class,clip,clipPathUnits,clip-path,clip-rule,color,color-interpolation,color-interpolation-filters,color-profile,color-rendering,contentScriptType,contentStyleType,crossorigin,cursor,cx,cy,d,decelerate,descent,diffuseConstant,direction,display,divisor,dominant-baseline,dur,dx,dy,edgeMode,elevation,enable-background,end,exponent,fill,fill-opacity,fill-rule,filter,filterRes,filterUnits,flood-color,flood-opacity,font-family,font-size,font-size-adjust,font-stretch,font-style,font-variant,font-weight,format,from,fr,fx,fy,g1,g2,glyph-name,glyph-orientation-horizontal,glyph-orientation-vertical,glyphRef,gradientTransform,gradientUnits,hanging,height,href,hreflang,horiz-adv-x,horiz-origin-x,id,ideographic,image-rendering,in,in2,intercept,k,k1,k2,k3,k4,kernelMatrix,kernelUnitLength,kerning,keyPoints,keySplines,keyTimes,lang,lengthAdjust,letter-spacing,lighting-color,limitingConeAngle,local,marker-end,marker-mid,marker-start,markerHeight,markerUnits,markerWidth,mask,maskContentUnits,maskUnits,mathematical,max,media,method,min,mode,name,numOctaves,offset,opacity,operator,order,orient,orientation,origin,overflow,overline-position,overline-thickness,panose-1,paint-order,path,pathLength,patternContentUnits,patternTransform,patternUnits,ping,pointer-events,points,pointsAtX,pointsAtY,pointsAtZ,preserveAlpha,preserveAspectRatio,primitiveUnits,r,radius,referrerPolicy,refX,refY,rel,rendering-intent,repeatCount,repeatDur,requiredExtensions,requiredFeatures,restart,result,rotate,rx,ry,scale,seed,shape-rendering,slope,spacing,specularConstant,specularExponent,speed,spreadMethod,startOffset,stdDeviation,stemh,stemv,stitchTiles,stop-color,stop-opacity,strikethrough-position,strikethrough-thickness,string,stroke,stroke-dasharray,stroke-dashoffset,stroke-linecap,stroke-linejoin,stroke-miterlimit,stroke-opacity,stroke-width,style,surfaceScale,systemLanguage,tabindex,tableValues,target,targetX,targetY,text-anchor,text-decoration,text-rendering,textLength,to,transform,transform-origin,type,u1,u2,underline-position,underline-thickness,unicode,unicode-bidi,unicode-range,units-per-em,v-alphabetic,v-hanging,v-ideographic,v-mathematical,values,vector-effect,version,vert-adv-y,vert-origin-x,vert-origin-y,viewBox,viewTarget,visibility,width,widths,word-spacing,writing-mode,x,x-height,x1,x2,xChannelSelector,xlink:actuate,xlink:arcrole,xlink:href,xlink:role,xlink:show,xlink:title,xlink:type,xmlns:xlink,xml:base,xml:lang,xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan");
|
|
326
|
-
var
|
|
327
|
-
var
|
|
328
|
-
var
|
|
329
|
-
var
|
|
330
|
-
var
|
|
331
|
-
a(we);
|
|
332
|
-
var Ne = a(Te);
|
|
338
|
+
var Se = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
|
|
339
|
+
var ve = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
|
|
340
|
+
var Ae = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
|
|
341
|
+
var Ee = "beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart";
|
|
342
|
+
var Ne = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
|
333
343
|
a(Se);
|
|
334
|
-
var Ce = a(
|
|
335
|
-
|
|
336
|
-
var Re =
|
|
337
|
-
var ze =
|
|
338
|
-
|
|
339
|
-
|
|
344
|
+
var Ce = a(ve);
|
|
345
|
+
a(Ae);
|
|
346
|
+
var Re = a(Ne);
|
|
347
|
+
var ze = a(Ee);
|
|
348
|
+
var je = "data-hk-idx";
|
|
349
|
+
var He = "_$spread$";
|
|
350
|
+
var $e = /;(?![^(]*\))/g;
|
|
351
|
+
var Ue = /:([\s\S]+)/;
|
|
352
|
+
var Ge = /\/\*[\s\S]*?\*\//g;
|
|
353
|
+
function k(e) {
|
|
354
|
+
let t13 = {};
|
|
355
|
+
return e.replaceAll(Ge, "").split($e).forEach((n) => {
|
|
356
|
+
if (n) {
|
|
357
|
+
let o = n.split(Ue);
|
|
358
|
+
o.length > 1 && (t13[o[0].trim()] = o[1].trim());
|
|
359
|
+
}
|
|
360
|
+
}), t13;
|
|
361
|
+
}
|
|
362
|
+
function w(e) {
|
|
363
|
+
if (m(e)) {
|
|
364
|
+
let t13 = {};
|
|
365
|
+
for (let n of e) {
|
|
366
|
+
let o = i(n) ? k(n) : w(n);
|
|
367
|
+
if (o) for (let r in o) t13[r] = o[r];
|
|
368
|
+
}
|
|
369
|
+
return t13;
|
|
370
|
+
}
|
|
371
|
+
if (i(e)) return e;
|
|
372
|
+
if (g(e)) {
|
|
373
|
+
let t13 = {};
|
|
374
|
+
for (let n in e) {
|
|
375
|
+
let o = e[n];
|
|
376
|
+
if (i(o) || d(o)) {
|
|
377
|
+
t13[n] = o;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
let r = w(o);
|
|
381
|
+
if (!r) continue;
|
|
382
|
+
let s = i(r) ? k(r) : r;
|
|
383
|
+
for (let l in s) t13[l] = s[l];
|
|
384
|
+
}
|
|
385
|
+
return t13;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
340
388
|
function isAnyFunctionPath(path) {
|
|
341
389
|
return path.isFunctionDeclaration() || path.isFunctionExpression() || path.isArrowFunctionExpression();
|
|
342
390
|
}
|
|
@@ -398,7 +446,7 @@ function serializeStaticAttrs(attrs) {
|
|
|
398
446
|
const merged = [];
|
|
399
447
|
let classValue;
|
|
400
448
|
for (const attr of attrs) {
|
|
401
|
-
const name = (_a =
|
|
449
|
+
const name = (_a = ke[attr.name]) != null ? _a : attr.name;
|
|
402
450
|
if (name === "class") {
|
|
403
451
|
classValue = classValue ? `${classValue} ${attr.value}` : String(attr.value);
|
|
404
452
|
} else {
|
|
@@ -408,7 +456,7 @@ function serializeStaticAttrs(attrs) {
|
|
|
408
456
|
if (classValue) merged.unshift({ name: "class", value: classValue });
|
|
409
457
|
return merged.map((attr) => {
|
|
410
458
|
if (attr.value === true) return ` ${attr.name}`;
|
|
411
|
-
return ` ${attr.name}="${
|
|
459
|
+
return ` ${attr.name}="${pe(attr.value)}"`;
|
|
412
460
|
}).join("");
|
|
413
461
|
}
|
|
414
462
|
function resolveComponentCallee(tag, fallback) {
|
|
@@ -427,16 +475,16 @@ function isSerializableStaticValue(value) {
|
|
|
427
475
|
const stack = [value];
|
|
428
476
|
while (stack.length > 0) {
|
|
429
477
|
const current = stack.pop();
|
|
430
|
-
if (
|
|
478
|
+
if (T(current) || A(current) || d(current) || i(current) || U(current)) {
|
|
431
479
|
continue;
|
|
432
480
|
}
|
|
433
|
-
if (
|
|
481
|
+
if (m(current)) {
|
|
434
482
|
for (const item of current) {
|
|
435
483
|
stack.push(item);
|
|
436
484
|
}
|
|
437
485
|
continue;
|
|
438
486
|
}
|
|
439
|
-
if (!
|
|
487
|
+
if (!F(current)) {
|
|
440
488
|
return false;
|
|
441
489
|
}
|
|
442
490
|
const values = Object.values(current);
|
|
@@ -447,21 +495,29 @@ function isSerializableStaticValue(value) {
|
|
|
447
495
|
return true;
|
|
448
496
|
}
|
|
449
497
|
function styleToString(style) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
498
|
+
const normalized = w(style);
|
|
499
|
+
if (!normalized) return void 0;
|
|
500
|
+
if (i(normalized)) return normalized;
|
|
501
|
+
const parts = [];
|
|
502
|
+
for (const key in normalized) {
|
|
503
|
+
const value = normalized[key];
|
|
504
|
+
if (i(value) || d(value)) {
|
|
505
|
+
const prop = x(key, "--") ? key : b(key);
|
|
506
|
+
parts.push(`${prop}:${value}`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return parts.join(";");
|
|
454
510
|
}
|
|
455
511
|
function shouldResolveStaticCollection(attrName) {
|
|
456
512
|
return attrName !== "ref" && !x(attrName, "bind:") && !normalizeEventName(attrName);
|
|
457
513
|
}
|
|
458
514
|
function normalizeTemplateAttrName(attrName) {
|
|
459
515
|
var _a;
|
|
460
|
-
return (_a =
|
|
516
|
+
return (_a = ke[attrName]) != null ? _a : attrName;
|
|
461
517
|
}
|
|
462
518
|
function createStaticAttr(attrName, value, order) {
|
|
463
519
|
return {
|
|
464
|
-
attr: { name: attrName, value },
|
|
520
|
+
attr: { name: attrName, value, order },
|
|
465
521
|
order,
|
|
466
522
|
templateName: normalizeTemplateAttrName(attrName)
|
|
467
523
|
};
|
|
@@ -472,7 +528,8 @@ function createDynamicAttr(attrPath, attrName, value, effectKind, order) {
|
|
|
472
528
|
path: attrPath,
|
|
473
529
|
name: attrName,
|
|
474
530
|
value,
|
|
475
|
-
effectKind
|
|
531
|
+
effectKind,
|
|
532
|
+
order
|
|
476
533
|
},
|
|
477
534
|
order,
|
|
478
535
|
templateName: normalizeTemplateAttrName(attrName)
|
|
@@ -487,13 +544,15 @@ function resolveStaticExpressionValue(attrName, expressionPath) {
|
|
|
487
544
|
return void 0;
|
|
488
545
|
}
|
|
489
546
|
let value = evaluated.value;
|
|
490
|
-
if (attrName === "style"
|
|
491
|
-
|
|
547
|
+
if (attrName === "style") {
|
|
548
|
+
const style = styleToString(value);
|
|
549
|
+
if (style === void 0) return void 0;
|
|
550
|
+
value = style;
|
|
492
551
|
}
|
|
493
|
-
if (i(value) ||
|
|
552
|
+
if (i(value) || A(value)) {
|
|
494
553
|
return value;
|
|
495
554
|
}
|
|
496
|
-
if (
|
|
555
|
+
if (d(value)) {
|
|
497
556
|
return String(value);
|
|
498
557
|
}
|
|
499
558
|
return void 0;
|
|
@@ -546,7 +605,8 @@ function parseAttributes(path) {
|
|
|
546
605
|
if (attrPath.isJSXSpreadAttribute()) {
|
|
547
606
|
spreadAttrs.push({
|
|
548
607
|
value: attrPath.node.argument,
|
|
549
|
-
effectKind: classifyAttrValue(attrPath.node.argument).kind
|
|
608
|
+
effectKind: classifyAttrValue(attrPath.node.argument).kind,
|
|
609
|
+
order
|
|
550
610
|
});
|
|
551
611
|
continue;
|
|
552
612
|
}
|
|
@@ -634,7 +694,7 @@ function unwrapTopLevelDeclaration(statementPath) {
|
|
|
634
694
|
}
|
|
635
695
|
if (statementPath.isExportNamedDeclaration() || statementPath.isExportDefaultDeclaration()) {
|
|
636
696
|
const declarationPath = statementPath.get("declaration");
|
|
637
|
-
if (declarationPath && !
|
|
697
|
+
if (declarationPath && !m(declarationPath) && (declarationPath.isFunctionDeclaration() || declarationPath.isVariableDeclaration())) {
|
|
638
698
|
return declarationPath;
|
|
639
699
|
}
|
|
640
700
|
}
|
|
@@ -1043,7 +1103,7 @@ function patternHasSignalBinding(node) {
|
|
|
1043
1103
|
if (types.isIdentifier(node)) return isSignal(node.name);
|
|
1044
1104
|
if (types.isObjectPattern(node)) {
|
|
1045
1105
|
return node.properties.some(
|
|
1046
|
-
(
|
|
1106
|
+
(p) => types.isRestElement(p) ? patternHasSignalBinding(p.argument) : patternHasSignalBinding(p.value)
|
|
1047
1107
|
);
|
|
1048
1108
|
}
|
|
1049
1109
|
if (types.isArrayPattern(node)) {
|
|
@@ -1191,9 +1251,9 @@ function isAlreadyValueAccess(path) {
|
|
|
1191
1251
|
if (!types.isParenthesizedExpression(parent) && !types.isTSAsExpression(parent) && !types.isTSNonNullExpression(parent)) {
|
|
1192
1252
|
return false;
|
|
1193
1253
|
}
|
|
1194
|
-
const ancestor = path.findParent((
|
|
1195
|
-
if (!isMemberLike(
|
|
1196
|
-
return isMemberAccessingProperty(
|
|
1254
|
+
const ancestor = path.findParent((p) => {
|
|
1255
|
+
if (!isMemberLike(p.node)) return false;
|
|
1256
|
+
return isMemberAccessingProperty(p.node, "value");
|
|
1197
1257
|
});
|
|
1198
1258
|
return !!ancestor;
|
|
1199
1259
|
}
|
|
@@ -1288,7 +1348,7 @@ function collectObjectPattern(pattern, base, leaves, rests) {
|
|
|
1288
1348
|
continue;
|
|
1289
1349
|
}
|
|
1290
1350
|
const { keyExpr, computed, excludeKey } = resolveKey(prop);
|
|
1291
|
-
if (excludeKey
|
|
1351
|
+
if (!T(excludeKey)) excludeKeys.push(excludeKey);
|
|
1292
1352
|
const access = types.memberExpression(clone2(base), keyExpr, computed);
|
|
1293
1353
|
collectTarget(prop.value, access, leaves, rests);
|
|
1294
1354
|
}
|
|
@@ -1320,7 +1380,7 @@ function ensureBlockBody(path) {
|
|
|
1320
1380
|
return block;
|
|
1321
1381
|
}
|
|
1322
1382
|
function isInsidePattern(ref, pattern) {
|
|
1323
|
-
return !!ref.findParent((
|
|
1383
|
+
return !!ref.findParent((p) => p.node === pattern);
|
|
1324
1384
|
}
|
|
1325
1385
|
function accessorFor(pattern, base, name) {
|
|
1326
1386
|
var _a;
|
|
@@ -1340,7 +1400,7 @@ function transformFnProps(path) {
|
|
|
1340
1400
|
collectObjectPattern(firstParam, base, initLeaves, initRests);
|
|
1341
1401
|
const conflicts = [...initLeaves, ...initRests].map((b2) => b2.name).filter((name) => x(name, signalPrefix));
|
|
1342
1402
|
if (conflicts.length > 0) {
|
|
1343
|
-
|
|
1403
|
+
se("transformProps", "Property names cannot start with signal prefix", conflicts);
|
|
1344
1404
|
}
|
|
1345
1405
|
if (initLeaves.length === 0 && initRests.length === 1 && firstParam.properties.length === 1 && types.isRestElement(firstParam.properties[0])) {
|
|
1346
1406
|
path.node.params[0] = types.identifier(initRests[0].name);
|
|
@@ -1448,6 +1508,18 @@ function hasDynamicBoundary(children, index) {
|
|
|
1448
1508
|
const isDynamic = (n) => (n == null ? void 0 : n.type) === 3 /* EXPRESSION */ || (n == null ? void 0 : n.type) === 1 /* COMPONENT */ || (n == null ? void 0 : n.type) === 4 /* FOR */;
|
|
1449
1509
|
return isText(prev) || isText(next) || isDynamic(prev) || isDynamic(next);
|
|
1450
1510
|
}
|
|
1511
|
+
function getDynamicAnchorKind(children, index, mode) {
|
|
1512
|
+
if (!hasDynamicBoundary(children, index)) {
|
|
1513
|
+
const next = children[index + 1];
|
|
1514
|
+
if ((mode === "hydrate" || mode === "server") && (next == null ? void 0 : next.type) === 0 /* ELEMENT */) {
|
|
1515
|
+
return "element";
|
|
1516
|
+
}
|
|
1517
|
+
if (!next) {
|
|
1518
|
+
return "tail";
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
return "comment";
|
|
1522
|
+
}
|
|
1451
1523
|
function buildIR(path, ctx) {
|
|
1452
1524
|
if (path.isJSXFragment()) {
|
|
1453
1525
|
useImport("Fragment");
|
|
@@ -1464,14 +1536,14 @@ function buildElementIR(tag, path, ctx) {
|
|
|
1464
1536
|
const node = {
|
|
1465
1537
|
type: 0 /* ELEMENT */,
|
|
1466
1538
|
tag,
|
|
1467
|
-
isSVG:
|
|
1539
|
+
isSVG: Ce(tag),
|
|
1468
1540
|
staticAttrs,
|
|
1469
1541
|
dynamicAttrs: [],
|
|
1470
1542
|
events: [],
|
|
1471
|
-
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind })),
|
|
1543
|
+
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind, order: s.order })),
|
|
1472
1544
|
binds: [],
|
|
1473
1545
|
children: [],
|
|
1474
|
-
selfClosing:
|
|
1546
|
+
selfClosing: Re(tag),
|
|
1475
1547
|
loc: path.node.loc
|
|
1476
1548
|
};
|
|
1477
1549
|
for (const attr of dynamicAttrs) {
|
|
@@ -1491,7 +1563,8 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1491
1563
|
props.push({
|
|
1492
1564
|
name: attr.name,
|
|
1493
1565
|
value: i(attr.value) ? types.stringLiteral(attr.value) : types.booleanLiteral(attr.value),
|
|
1494
|
-
kind: "static"
|
|
1566
|
+
kind: "static",
|
|
1567
|
+
order: attr.order
|
|
1495
1568
|
});
|
|
1496
1569
|
}
|
|
1497
1570
|
for (const attr of dynamicAttrs) {
|
|
@@ -1500,7 +1573,8 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1500
1573
|
props.push({
|
|
1501
1574
|
name: attr.name,
|
|
1502
1575
|
value: attr.value,
|
|
1503
|
-
kind: attr.effectKind
|
|
1576
|
+
kind: attr.effectKind,
|
|
1577
|
+
order: attr.order
|
|
1504
1578
|
});
|
|
1505
1579
|
} else if (x(attr.name, "bind:")) {
|
|
1506
1580
|
const binding = attr.name.slice("bind:".length);
|
|
@@ -1511,18 +1585,21 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1511
1585
|
props.push({
|
|
1512
1586
|
name: binding,
|
|
1513
1587
|
value: types.cloneNode(valueExpr),
|
|
1514
|
-
kind: attr.effectKind
|
|
1588
|
+
kind: attr.effectKind,
|
|
1589
|
+
order: attr.order
|
|
1515
1590
|
});
|
|
1516
1591
|
props.push({
|
|
1517
1592
|
name: `update:${binding}`,
|
|
1518
1593
|
value: createBindingSetter(valueExpr),
|
|
1519
|
-
kind: "static"
|
|
1594
|
+
kind: "static",
|
|
1595
|
+
order: attr.order
|
|
1520
1596
|
});
|
|
1521
1597
|
} else {
|
|
1522
1598
|
props.push({
|
|
1523
1599
|
name: attr.name,
|
|
1524
1600
|
value: attr.value,
|
|
1525
|
-
kind: attr.effectKind
|
|
1601
|
+
kind: attr.effectKind,
|
|
1602
|
+
order: attr.order
|
|
1526
1603
|
});
|
|
1527
1604
|
}
|
|
1528
1605
|
}
|
|
@@ -1530,7 +1607,7 @@ function buildComponentIR(tag, path, ctx) {
|
|
|
1530
1607
|
type: 1 /* COMPONENT */,
|
|
1531
1608
|
tag,
|
|
1532
1609
|
props,
|
|
1533
|
-
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind })),
|
|
1610
|
+
spreads: spreadAttrs.map((s) => ({ value: s.value, kind: s.effectKind, order: s.order })),
|
|
1534
1611
|
children: buildChildren(path, ctx),
|
|
1535
1612
|
loc: path.node.loc
|
|
1536
1613
|
};
|
|
@@ -1539,7 +1616,7 @@ function applyDynamicAttr(node, attr, ctx) {
|
|
|
1539
1616
|
const { name, value, effectKind, path } = attr;
|
|
1540
1617
|
const eventName = normalizeEventName(name);
|
|
1541
1618
|
if (eventName) {
|
|
1542
|
-
const delegated = !!(ctx.options.delegateEvents &&
|
|
1619
|
+
const delegated = !!(ctx.options.delegateEvents && ze(eventName));
|
|
1543
1620
|
node.events.push({
|
|
1544
1621
|
name: eventName,
|
|
1545
1622
|
handler: value,
|
|
@@ -1627,7 +1704,7 @@ function isPropsChildrenExpression(expression) {
|
|
|
1627
1704
|
const binding = expression.scope.getBinding(node.object.name);
|
|
1628
1705
|
const bindingPath = binding == null ? void 0 : binding.path;
|
|
1629
1706
|
if (!(bindingPath == null ? void 0 : bindingPath.isIdentifier())) return false;
|
|
1630
|
-
const owner = bindingPath.findParent((
|
|
1707
|
+
const owner = bindingPath.findParent((p) => isAnyFunctionPath(p));
|
|
1631
1708
|
if (!owner) return false;
|
|
1632
1709
|
const fn = owner.node;
|
|
1633
1710
|
const componentName = getEnclosingFunctionName(owner);
|
|
@@ -1690,6 +1767,7 @@ function buildForIR(expression, ctx) {
|
|
|
1690
1767
|
};
|
|
1691
1768
|
}
|
|
1692
1769
|
function extractKeyExpression(path) {
|
|
1770
|
+
if (path.isJSXFragment()) return extractFragmentKeyExpression(path);
|
|
1693
1771
|
if (!path.isJSXElement()) return null;
|
|
1694
1772
|
for (const attrPath of path.get("openingElement.attributes")) {
|
|
1695
1773
|
if (!attrPath.isJSXAttribute()) continue;
|
|
@@ -1704,7 +1782,7 @@ function extractKeyExpression(path) {
|
|
|
1704
1782
|
return types.stringLiteral(value.value);
|
|
1705
1783
|
}
|
|
1706
1784
|
const valuePath = attrPath.get("value");
|
|
1707
|
-
if (!
|
|
1785
|
+
if (!m(valuePath) && valuePath.isJSXExpressionContainer()) {
|
|
1708
1786
|
const expressionPath = valuePath.get("expression");
|
|
1709
1787
|
attrPath.remove();
|
|
1710
1788
|
if (expressionPath.isJSXEmptyExpression()) return null;
|
|
@@ -1715,9 +1793,16 @@ function extractKeyExpression(path) {
|
|
|
1715
1793
|
}
|
|
1716
1794
|
return null;
|
|
1717
1795
|
}
|
|
1796
|
+
function extractFragmentKeyExpression(path) {
|
|
1797
|
+
const children = path.get("children").filter(isValidChild);
|
|
1798
|
+
if (children.length !== 1) return null;
|
|
1799
|
+
const child = children[0];
|
|
1800
|
+
if (!child.isJSXElement() && !child.isJSXFragment()) return null;
|
|
1801
|
+
return extractKeyExpression(child);
|
|
1802
|
+
}
|
|
1718
1803
|
function getForCallbackBody(callback) {
|
|
1719
1804
|
const bodyPath = callback.get("body");
|
|
1720
|
-
if (
|
|
1805
|
+
if (m(bodyPath)) return null;
|
|
1721
1806
|
if (bodyPath.isJSXElement() || bodyPath.isJSXFragment()) {
|
|
1722
1807
|
return {
|
|
1723
1808
|
path: bodyPath,
|
|
@@ -1734,7 +1819,7 @@ function getForCallbackBody(callback) {
|
|
|
1734
1819
|
continue;
|
|
1735
1820
|
}
|
|
1736
1821
|
const argument = statement.get("argument");
|
|
1737
|
-
if (
|
|
1822
|
+
if (m(argument) || !argument.node) {
|
|
1738
1823
|
prelude.push(statement.node);
|
|
1739
1824
|
continue;
|
|
1740
1825
|
}
|
|
@@ -1810,16 +1895,55 @@ function createPropNode(name, value, kind, options) {
|
|
|
1810
1895
|
function composePropsExpression(props, spreads, options) {
|
|
1811
1896
|
if (spreads.length === 0) {
|
|
1812
1897
|
if (props.length === 0) return types.objectExpression([]);
|
|
1813
|
-
return types.objectExpression(props.map((
|
|
1898
|
+
return types.objectExpression(props.map((p) => createPropNode(p.name, p.value, p.kind, options)));
|
|
1899
|
+
}
|
|
1900
|
+
if (props.some((prop) => prop.order == null) || spreads.some((spread) => spread.order == null)) {
|
|
1901
|
+
return composeUnorderedPropsExpression(props, spreads, options);
|
|
1902
|
+
}
|
|
1903
|
+
const ordered = [
|
|
1904
|
+
...props.map((prop, sequence) => ({
|
|
1905
|
+
type: "prop",
|
|
1906
|
+
order: prop.order,
|
|
1907
|
+
sequence,
|
|
1908
|
+
prop
|
|
1909
|
+
})),
|
|
1910
|
+
...spreads.map((spread, sequence) => ({
|
|
1911
|
+
type: "spread",
|
|
1912
|
+
order: spread.order,
|
|
1913
|
+
sequence,
|
|
1914
|
+
spread
|
|
1915
|
+
}))
|
|
1916
|
+
].sort((a2, b2) => a2.order - b2.order || a2.sequence - b2.sequence);
|
|
1917
|
+
const parts = [];
|
|
1918
|
+
let propNodes = [];
|
|
1919
|
+
const flushProps = () => {
|
|
1920
|
+
if (propNodes.length === 0) return;
|
|
1921
|
+
parts.push(types.objectExpression(propNodes));
|
|
1922
|
+
propNodes = [];
|
|
1923
|
+
};
|
|
1924
|
+
for (const entry of ordered) {
|
|
1925
|
+
if (entry.type === "prop") {
|
|
1926
|
+
propNodes.push(createPropNode(entry.prop.name, entry.prop.value, entry.prop.kind, options));
|
|
1927
|
+
continue;
|
|
1928
|
+
}
|
|
1929
|
+
flushProps();
|
|
1930
|
+
parts.push(cloneValue(entry.spread.value, options.cloneValues));
|
|
1814
1931
|
}
|
|
1932
|
+
flushProps();
|
|
1933
|
+
return composeAssignParts(parts);
|
|
1934
|
+
}
|
|
1935
|
+
function composeUnorderedPropsExpression(props, spreads, options) {
|
|
1815
1936
|
const parts = [];
|
|
1816
|
-
const propNodes = props.map((
|
|
1937
|
+
const propNodes = props.map((p) => createPropNode(p.name, p.value, p.kind, options));
|
|
1817
1938
|
if (propNodes.length > 0) {
|
|
1818
1939
|
parts.push(types.objectExpression(propNodes));
|
|
1819
1940
|
}
|
|
1820
1941
|
for (const spread of spreads) {
|
|
1821
1942
|
parts.push(cloneValue(spread.value, options.cloneValues));
|
|
1822
1943
|
}
|
|
1944
|
+
return composeAssignParts(parts);
|
|
1945
|
+
}
|
|
1946
|
+
function composeAssignParts(parts) {
|
|
1823
1947
|
if (parts.length === 0) return types.objectExpression([]);
|
|
1824
1948
|
if (parts.length === 1) return parts[0];
|
|
1825
1949
|
return types.callExpression(types.memberExpression(types.identifier("Object"), types.identifier("assign")), [
|
|
@@ -2091,7 +2215,7 @@ function generateServerFor(node, ctx) {
|
|
|
2091
2215
|
return buildForCall(node, bodyExpr);
|
|
2092
2216
|
}
|
|
2093
2217
|
function generateServerElement(node, ctx, withHydrationKey = true, staticIndex, options = {}) {
|
|
2094
|
-
var _a
|
|
2218
|
+
var _a;
|
|
2095
2219
|
const dynamicAttrExprs = [...(_a = options.prependAttrExprs) != null ? _a : []];
|
|
2096
2220
|
for (const attr of node.dynamicAttrs) {
|
|
2097
2221
|
let expr;
|
|
@@ -2119,7 +2243,7 @@ function generateServerElement(node, ctx, withHydrationKey = true, staticIndex,
|
|
|
2119
2243
|
}
|
|
2120
2244
|
const templates = [];
|
|
2121
2245
|
const expressions = [];
|
|
2122
|
-
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name:
|
|
2246
|
+
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name: je, value: String(staticIndex) }];
|
|
2123
2247
|
const attrs = serializeStaticAttrs(staticAttrs);
|
|
2124
2248
|
const textareaValueBind = node.tag === "textarea" ? findBind(node, "value") : null;
|
|
2125
2249
|
let currentStr = `<${node.tag}`;
|
|
@@ -2150,11 +2274,11 @@ function generateServerElement(node, ctx, withHydrationKey = true, staticIndex,
|
|
|
2150
2274
|
if (child.type === 2 /* TEXT */) {
|
|
2151
2275
|
currentStr += escapeServerTemplateText(child.value);
|
|
2152
2276
|
} else if (child.type === 3 /* EXPRESSION */ || child.type === 1 /* COMPONENT */ || child.type === 4 /* FOR */) {
|
|
2153
|
-
const
|
|
2277
|
+
const anchorKind = getDynamicAnchorKind(node.children, i2, "server");
|
|
2154
2278
|
const slotIndex = markerIndex++;
|
|
2155
2279
|
templates.push(currentStr);
|
|
2156
|
-
currentStr =
|
|
2157
|
-
if (
|
|
2280
|
+
currentStr = anchorKind === "comment" ? `<!--${slotIndex}-->` : "";
|
|
2281
|
+
if (anchorKind === "element") {
|
|
2158
2282
|
pendingAnchorIndex = slotIndex;
|
|
2159
2283
|
}
|
|
2160
2284
|
expressions.push(generateServerNode(child, ctx));
|
|
@@ -2177,7 +2301,7 @@ function generateServerElement(node, ctx, withHydrationKey = true, staticIndex,
|
|
|
2177
2301
|
}
|
|
2178
2302
|
}
|
|
2179
2303
|
const staticHTML = buildStaticServerHTML(child, anchorIndex);
|
|
2180
|
-
if (staticHTML
|
|
2304
|
+
if (!T(staticHTML)) {
|
|
2181
2305
|
currentStr += staticHTML;
|
|
2182
2306
|
} else {
|
|
2183
2307
|
templates.push(currentStr);
|
|
@@ -2222,7 +2346,7 @@ function buildStaticServerHTML(node, staticIndex) {
|
|
|
2222
2346
|
if (node.binds.length > 0 || node.dynamicAttrs.length > 0 || node.spreads.length > 0) {
|
|
2223
2347
|
return null;
|
|
2224
2348
|
}
|
|
2225
|
-
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name:
|
|
2349
|
+
const staticAttrs = staticIndex === void 0 ? node.staticAttrs : [...node.staticAttrs, { name: je, value: String(staticIndex) }];
|
|
2226
2350
|
const attrs = serializeStaticAttrs(staticAttrs);
|
|
2227
2351
|
if (node.selfClosing) {
|
|
2228
2352
|
return `<${node.tag}${attrs} />`;
|
|
@@ -2234,7 +2358,7 @@ function buildStaticServerHTML(node, staticIndex) {
|
|
|
2234
2358
|
} else if (child.type === 0 /* ELEMENT */) {
|
|
2235
2359
|
if (child.binds.length > 0) return null;
|
|
2236
2360
|
const nested = buildStaticServerHTML(child);
|
|
2237
|
-
if (nested
|
|
2361
|
+
if (T(nested)) return null;
|
|
2238
2362
|
html += nested;
|
|
2239
2363
|
} else {
|
|
2240
2364
|
return null;
|
|
@@ -2272,18 +2396,6 @@ function shouldCloseTag(element, isLastElement, hasClosingParent, options) {
|
|
|
2272
2396
|
function closeTag(element, isLastElement, hasClosingParent, options) {
|
|
2273
2397
|
return shouldCloseTag(element, isLastElement, hasClosingParent, options) ? `</${element.tag}>` : "";
|
|
2274
2398
|
}
|
|
2275
|
-
function getDynamicAnchorKind(children, index, mode) {
|
|
2276
|
-
if ((mode === "client" || mode === "hydrate") && !hasDynamicBoundary(children, index)) {
|
|
2277
|
-
const next = children[index + 1];
|
|
2278
|
-
if (mode === "hydrate" && (next == null ? void 0 : next.type) === 0 /* ELEMENT */) {
|
|
2279
|
-
return "element";
|
|
2280
|
-
}
|
|
2281
|
-
if (!next) {
|
|
2282
|
-
return "tail";
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
return "comment";
|
|
2286
|
-
}
|
|
2287
2399
|
function findLastOmittableElementIndex(children, mode) {
|
|
2288
2400
|
for (let i2 = children.length - 1; i2 >= 0; i2--) {
|
|
2289
2401
|
const child = children[i2];
|
|
@@ -2308,7 +2420,7 @@ function buildTemplateAndFlatten(root, mode) {
|
|
|
2308
2420
|
const myId = nextId++;
|
|
2309
2421
|
const staticAttrs = mode === "hydrate" && forcedStaticIndex !== void 0 ? [
|
|
2310
2422
|
...element.staticAttrs,
|
|
2311
|
-
{ name:
|
|
2423
|
+
{ name: je, value: String(forcedStaticIndex) }
|
|
2312
2424
|
] : element.staticAttrs;
|
|
2313
2425
|
const attrs = serializeStaticAttrs(staticAttrs);
|
|
2314
2426
|
if (element.selfClosing) {
|
|
@@ -2347,7 +2459,7 @@ function buildTemplateAndFlatten(root, mode) {
|
|
|
2347
2459
|
const child = element.children[i2];
|
|
2348
2460
|
switch (child.type) {
|
|
2349
2461
|
case 2 /* TEXT */:
|
|
2350
|
-
template += mode === "hydrate" ? child.value :
|
|
2462
|
+
template += mode === "hydrate" ? child.value : pe(child.value);
|
|
2351
2463
|
nodes.push({
|
|
2352
2464
|
id: nextId++,
|
|
2353
2465
|
kind: "text",
|
|
@@ -2414,7 +2526,7 @@ function buildStaticTemplateString(node, mode) {
|
|
|
2414
2526
|
function visit(current, isLastElement, hasClosingParent) {
|
|
2415
2527
|
switch (current.type) {
|
|
2416
2528
|
case 2 /* TEXT */:
|
|
2417
|
-
return mode === "hydrate" ? current.value :
|
|
2529
|
+
return mode === "hydrate" ? current.value : pe(current.value);
|
|
2418
2530
|
case 0 /* ELEMENT */: {
|
|
2419
2531
|
const attrs = serializeStaticAttrs(current.staticAttrs);
|
|
2420
2532
|
if (current.selfClosing) return selfClosingTag(current, attrs);
|
|
@@ -2717,7 +2829,7 @@ function emitDynamicAttr(attr, target, body, state, pendingMemoPatches) {
|
|
|
2717
2829
|
function emitSpread(spread, target, body, state, pendingMemoPatches) {
|
|
2718
2830
|
emitPatchOrEffect(
|
|
2719
2831
|
target,
|
|
2720
|
-
|
|
2832
|
+
He,
|
|
2721
2833
|
spread.value,
|
|
2722
2834
|
spread.kind,
|
|
2723
2835
|
body,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-essor",
|
|
3
|
-
"version": "0.0.17
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/core": "^8.0.1",
|
|
36
36
|
"@babel/generator": "^8.0.0",
|
|
37
|
-
"@estjs/shared": "0.0.17
|
|
37
|
+
"@estjs/shared": "0.0.17"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@babel/traverse": "^8.0.0",
|