@vue/compiler-vapor 3.6.0-beta.11 → 3.6.0-beta.13
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/compiler-vapor.cjs.js +1022 -166
- package/dist/compiler-vapor.d.ts +93 -40
- package/dist/compiler-vapor.esm-browser.js +1155 -227
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.13
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -32,6 +32,7 @@ const NOOP = () => {};
|
|
|
32
32
|
* Always return false.
|
|
33
33
|
*/
|
|
34
34
|
const NO = () => false;
|
|
35
|
+
const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
|
|
35
36
|
const extend = Object.assign;
|
|
36
37
|
const remove = (arr, el) => {
|
|
37
38
|
const i = arr.indexOf(el);
|
|
@@ -39,6 +40,7 @@ const remove = (arr, el) => {
|
|
|
39
40
|
};
|
|
40
41
|
const isArray$1 = Array.isArray;
|
|
41
42
|
const isString = (val) => typeof val === "string";
|
|
43
|
+
const isObject = (val) => val !== null && typeof val === "object";
|
|
42
44
|
const isBuiltInDirective = /* @__PURE__ */ makeMap("bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo");
|
|
43
45
|
const cacheStringFunction = (fn) => {
|
|
44
46
|
const cache = Object.create(null);
|
|
@@ -52,6 +54,11 @@ const camelizeReplacer = (_, c) => c ? c.toUpperCase() : "";
|
|
|
52
54
|
* @private
|
|
53
55
|
*/
|
|
54
56
|
const camelize = cacheStringFunction((str) => str.replace(camelizeRE, camelizeReplacer));
|
|
57
|
+
const hyphenateRE = /\B([A-Z])/g;
|
|
58
|
+
/**
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
55
62
|
/**
|
|
56
63
|
* @private
|
|
57
64
|
*/
|
|
@@ -82,6 +89,57 @@ function canSetValueDirectly(tagName) {
|
|
|
82
89
|
}
|
|
83
90
|
const isGloballyAllowed = /* @__PURE__ */ makeMap("Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol");
|
|
84
91
|
//#endregion
|
|
92
|
+
//#region packages/shared/src/normalizeProp.ts
|
|
93
|
+
function normalizeStyle(value) {
|
|
94
|
+
if (isArray$1(value)) {
|
|
95
|
+
const res = {};
|
|
96
|
+
for (let i = 0; i < value.length; i++) {
|
|
97
|
+
const item = value[i];
|
|
98
|
+
const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);
|
|
99
|
+
if (normalized) for (const key in normalized) res[key] = normalized[key];
|
|
100
|
+
}
|
|
101
|
+
return res;
|
|
102
|
+
} else if (isString(value) || isObject(value)) return value;
|
|
103
|
+
}
|
|
104
|
+
const listDelimiterRE = /;(?![^(]*\))/g;
|
|
105
|
+
const propertyDelimiterRE = /:([^]+)/;
|
|
106
|
+
const styleCommentRE = /\/\*[^]*?\*\//g;
|
|
107
|
+
function parseStringStyle(cssText) {
|
|
108
|
+
const ret = {};
|
|
109
|
+
cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
|
|
110
|
+
if (item) {
|
|
111
|
+
const tmp = item.split(propertyDelimiterRE);
|
|
112
|
+
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return ret;
|
|
116
|
+
}
|
|
117
|
+
function stringifyStyle(styles) {
|
|
118
|
+
if (!styles) return "";
|
|
119
|
+
if (isString(styles)) return styles;
|
|
120
|
+
let ret = "";
|
|
121
|
+
for (const key in styles) {
|
|
122
|
+
const value = styles[key];
|
|
123
|
+
if (isString(value) || typeof value === "number") {
|
|
124
|
+
const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
|
|
125
|
+
ret += `${normalizedKey}:${value};`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return ret;
|
|
129
|
+
}
|
|
130
|
+
function normalizeClass(value) {
|
|
131
|
+
let res = "";
|
|
132
|
+
if (isString(value)) res = value;
|
|
133
|
+
else if (isArray$1(value)) for (let i = 0; i < value.length; i++) {
|
|
134
|
+
const normalized = normalizeClass(value[i]);
|
|
135
|
+
if (normalized) res += normalized + " ";
|
|
136
|
+
}
|
|
137
|
+
else if (isObject(value)) {
|
|
138
|
+
for (const name in value) if (value[name]) res += name + " ";
|
|
139
|
+
}
|
|
140
|
+
return res.trim();
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
85
143
|
//#region packages/shared/src/domTagConfig.ts
|
|
86
144
|
const HTML_TAGS = "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";
|
|
87
145
|
const SVG_TAGS = "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";
|
|
@@ -131,6 +189,17 @@ const isInlineTag = /* @__PURE__ */ makeMap(INLINE_TAGS);
|
|
|
131
189
|
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
|
|
132
190
|
*/
|
|
133
191
|
const isBlockTag = /* @__PURE__ */ makeMap(BLOCK_TAGS);
|
|
192
|
+
/**
|
|
193
|
+
* The full list is needed during SSR to produce the correct initial markup.
|
|
194
|
+
*/
|
|
195
|
+
const isBooleanAttr = /* @__PURE__ */ makeMap("itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected");
|
|
196
|
+
/**
|
|
197
|
+
* Boolean attributes should be included if the value is truthy or ''.
|
|
198
|
+
* e.g. `<select multiple>` compiles to `{ multiple: '' }`
|
|
199
|
+
*/
|
|
200
|
+
function includeBooleanAttr(value) {
|
|
201
|
+
return !!value || value === "";
|
|
202
|
+
}
|
|
134
203
|
function shouldSetAsAttr(tagName, key) {
|
|
135
204
|
if (key === "spellcheck" || key === "draggable" || key === "translate" || key === "autocorrect") return true;
|
|
136
205
|
if (key === "form") return true;
|
|
@@ -515,6 +584,12 @@ var toString = {}.toString;
|
|
|
515
584
|
var isArray = Array.isArray || function(arr) {
|
|
516
585
|
return toString.call(arr) == "[object Array]";
|
|
517
586
|
};
|
|
587
|
+
/*!
|
|
588
|
+
* The buffer module from node.js, for the browser.
|
|
589
|
+
*
|
|
590
|
+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
591
|
+
* @license MIT
|
|
592
|
+
*/
|
|
518
593
|
/**
|
|
519
594
|
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
520
595
|
* === true Use Uint8Array implementation (fastest)
|
|
@@ -19114,7 +19189,8 @@ var TransformContext = class TransformContext {
|
|
|
19114
19189
|
this.operationIndex = this.block.operation.length;
|
|
19115
19190
|
this.isLastEffectiveChild = true;
|
|
19116
19191
|
this.isOnRightmostPath = true;
|
|
19117
|
-
this.
|
|
19192
|
+
this.templateCloseTags = void 0;
|
|
19193
|
+
this.templateCloseBlocks = false;
|
|
19118
19194
|
this.globalId = 0;
|
|
19119
19195
|
this.nextIdMap = null;
|
|
19120
19196
|
this.ifIndex = 0;
|
|
@@ -19240,11 +19316,6 @@ var TransformContext = class TransformContext {
|
|
|
19240
19316
|
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
19241
19317
|
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
19242
19318
|
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
19243
|
-
let hasInlineAncestorNeedingClose = this.hasInlineAncestorNeedingClose;
|
|
19244
|
-
if (this.node.type === 1) {
|
|
19245
|
-
if (this.node.tag === "template") hasInlineAncestorNeedingClose = false;
|
|
19246
|
-
else if (!hasInlineAncestorNeedingClose && !this.isOnRightmostPath && isInlineTag(this.node.tag)) hasInlineAncestorNeedingClose = true;
|
|
19247
|
-
}
|
|
19248
19319
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
19249
19320
|
node,
|
|
19250
19321
|
parent: this,
|
|
@@ -19259,7 +19330,8 @@ var TransformContext = class TransformContext {
|
|
|
19259
19330
|
effectiveParent,
|
|
19260
19331
|
isLastEffectiveChild,
|
|
19261
19332
|
isOnRightmostPath,
|
|
19262
|
-
|
|
19333
|
+
templateCloseTags: this.templateCloseTags,
|
|
19334
|
+
templateCloseBlocks: this.templateCloseBlocks
|
|
19263
19335
|
});
|
|
19264
19336
|
}
|
|
19265
19337
|
shiftEffectBoundaries(index, dynamic = this.dynamic) {
|
|
@@ -19453,6 +19525,9 @@ function genCall(name, ...frags) {
|
|
|
19453
19525
|
hasPlaceholder ? name[1] : "null"
|
|
19454
19526
|
], ...frags)];
|
|
19455
19527
|
}
|
|
19528
|
+
function getParserOptions(plugins) {
|
|
19529
|
+
return { plugins: plugins ? plugins.some((plugin) => plugin === "typescript") ? plugins : [...plugins, "typescript"] : ["typescript"] };
|
|
19530
|
+
}
|
|
19456
19531
|
function codeFragmentToString(code, context) {
|
|
19457
19532
|
const { options: { filename, sourceMap } } = context;
|
|
19458
19533
|
let map;
|
|
@@ -19526,8 +19601,70 @@ function genPrependNode(oper, { helper }) {
|
|
|
19526
19601
|
return [NEWLINE, ...genCall(helper("prepend"), `n${oper.parent}`, ...oper.elements.map((el) => `n${el}`))];
|
|
19527
19602
|
}
|
|
19528
19603
|
//#endregion
|
|
19604
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
19605
|
+
function _typeof(o) {
|
|
19606
|
+
"@babel/helpers - typeof";
|
|
19607
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
19608
|
+
return typeof o;
|
|
19609
|
+
} : function(o) {
|
|
19610
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
19611
|
+
}, _typeof(o);
|
|
19612
|
+
}
|
|
19613
|
+
//#endregion
|
|
19614
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
19615
|
+
function toPrimitive(t, r) {
|
|
19616
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
19617
|
+
var e = t[Symbol.toPrimitive];
|
|
19618
|
+
if (void 0 !== e) {
|
|
19619
|
+
var i = e.call(t, r || "default");
|
|
19620
|
+
if ("object" != _typeof(i)) return i;
|
|
19621
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19622
|
+
}
|
|
19623
|
+
return ("string" === r ? String : Number)(t);
|
|
19624
|
+
}
|
|
19625
|
+
//#endregion
|
|
19626
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
19627
|
+
function toPropertyKey(t) {
|
|
19628
|
+
var i = toPrimitive(t, "string");
|
|
19629
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
19630
|
+
}
|
|
19631
|
+
//#endregion
|
|
19632
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
19633
|
+
function _defineProperty(e, r, t) {
|
|
19634
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
19635
|
+
value: t,
|
|
19636
|
+
enumerable: !0,
|
|
19637
|
+
configurable: !0,
|
|
19638
|
+
writable: !0
|
|
19639
|
+
}) : e[r] = t, e;
|
|
19640
|
+
}
|
|
19641
|
+
//#endregion
|
|
19642
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/objectSpread2.js
|
|
19643
|
+
function ownKeys(e, r) {
|
|
19644
|
+
var t = Object.keys(e);
|
|
19645
|
+
if (Object.getOwnPropertySymbols) {
|
|
19646
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
19647
|
+
r && (o = o.filter(function(r) {
|
|
19648
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
19649
|
+
})), t.push.apply(t, o);
|
|
19650
|
+
}
|
|
19651
|
+
return t;
|
|
19652
|
+
}
|
|
19653
|
+
function _objectSpread2(e) {
|
|
19654
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
19655
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
19656
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
19657
|
+
_defineProperty(e, r, t[r]);
|
|
19658
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
19659
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
19660
|
+
});
|
|
19661
|
+
}
|
|
19662
|
+
return e;
|
|
19663
|
+
}
|
|
19664
|
+
//#endregion
|
|
19529
19665
|
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
19530
19666
|
function genExpression(node, context, assignment) {
|
|
19667
|
+
node = context.getExpressionReplacement(node);
|
|
19531
19668
|
const { content, ast, isStatic, loc } = node;
|
|
19532
19669
|
if (isStatic) return [[
|
|
19533
19670
|
JSON.stringify(content),
|
|
@@ -19642,11 +19779,12 @@ function canPrefix(name) {
|
|
|
19642
19779
|
return true;
|
|
19643
19780
|
}
|
|
19644
19781
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
19782
|
+
const expressionReplacements = /* @__PURE__ */ new Map();
|
|
19645
19783
|
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
19646
19784
|
const reservedNames = new Set(seenIdentifier);
|
|
19647
|
-
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
|
|
19648
|
-
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
|
|
19649
|
-
return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
|
|
19785
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements);
|
|
19786
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements);
|
|
19787
|
+
return _objectSpread2(_objectSpread2({}, genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare)), {}, { expressionReplacements });
|
|
19650
19788
|
}
|
|
19651
19789
|
function analyzeExpressions(expressions) {
|
|
19652
19790
|
const seenVariable = Object.create(null);
|
|
@@ -19704,7 +19842,13 @@ function analyzeExpressions(expressions) {
|
|
|
19704
19842
|
updatedVariable
|
|
19705
19843
|
};
|
|
19706
19844
|
}
|
|
19707
|
-
function
|
|
19845
|
+
function getProcessedExpression(exp, expressionReplacements) {
|
|
19846
|
+
return expressionReplacements.get(exp) || exp;
|
|
19847
|
+
}
|
|
19848
|
+
function setExpressionReplacement(expressionReplacements, exp, content, ast) {
|
|
19849
|
+
expressionReplacements.set(exp, extend({ ast }, createSimpleExpression(content, exp.isStatic, exp.loc, exp.constType)));
|
|
19850
|
+
}
|
|
19851
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
|
|
19708
19852
|
const declarations = [];
|
|
19709
19853
|
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
19710
19854
|
for (const [name, exps] of variableToExpMap) {
|
|
@@ -19737,14 +19881,15 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
|
|
|
19737
19881
|
}
|
|
19738
19882
|
}
|
|
19739
19883
|
for (const [exp, replacements] of expToReplacementMap) {
|
|
19884
|
+
let content = getProcessedExpression(exp, expressionReplacements).content;
|
|
19740
19885
|
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
19741
19886
|
start,
|
|
19742
19887
|
end,
|
|
19743
19888
|
name
|
|
19744
19889
|
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
19745
|
-
|
|
19890
|
+
content = content.slice(0, start - 1) + name + content.slice(end - 1);
|
|
19746
19891
|
});
|
|
19747
|
-
exp
|
|
19892
|
+
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
19748
19893
|
}
|
|
19749
19894
|
return declarations;
|
|
19750
19895
|
}
|
|
@@ -19760,13 +19905,14 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
|
19760
19905
|
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
19761
19906
|
return true;
|
|
19762
19907
|
}
|
|
19763
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
|
|
19908
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements) {
|
|
19764
19909
|
const declarations = [];
|
|
19765
19910
|
const seenExp = expressions.reduce((acc, exp) => {
|
|
19766
19911
|
const vars = expToVariableMap.get(exp);
|
|
19767
19912
|
if (!vars) return acc;
|
|
19913
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
19768
19914
|
const variables = vars.map((v) => v.name);
|
|
19769
|
-
if (
|
|
19915
|
+
if (processed.ast && processed.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v))) && !variables.some((v) => isGloballyAllowed(v))) acc[processed.content] = (acc[processed.content] || 0) + 1;
|
|
19770
19916
|
return acc;
|
|
19771
19917
|
}, Object.create(null));
|
|
19772
19918
|
Object.entries(seenExp).forEach(([content, count]) => {
|
|
@@ -19775,13 +19921,13 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
19775
19921
|
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
19776
19922
|
const item = varDeclarations[i];
|
|
19777
19923
|
if (!item.exps || !item.seenCount) continue;
|
|
19778
|
-
if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
|
|
19924
|
+
if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
|
|
19779
19925
|
delVars[item.name] = item.rawName;
|
|
19780
19926
|
reservedNames.delete(item.name);
|
|
19781
19927
|
varDeclarations.splice(i, 1);
|
|
19782
19928
|
}
|
|
19783
19929
|
}
|
|
19784
|
-
const value = extend({}, expressions.find((exp) => exp.content === content));
|
|
19930
|
+
const value = extend({}, getProcessedExpression(expressions.find((exp) => getProcessedExpression(exp, expressionReplacements).content === content), expressionReplacements));
|
|
19785
19931
|
Object.keys(delVars).forEach((name) => {
|
|
19786
19932
|
value.content = value.content.replace(name, delVars[name]);
|
|
19787
19933
|
if (value.ast) value.ast = parseExp(context, value.content);
|
|
@@ -19792,12 +19938,11 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
19792
19938
|
value
|
|
19793
19939
|
});
|
|
19794
19940
|
expressions.forEach((exp) => {
|
|
19795
|
-
|
|
19796
|
-
|
|
19797
|
-
|
|
19798
|
-
|
|
19799
|
-
|
|
19800
|
-
exp.ast = parseExp(context, exp.content);
|
|
19941
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
19942
|
+
if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
|
|
19943
|
+
else if (processed.content.includes(content)) {
|
|
19944
|
+
const replacedContent = processed.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
|
|
19945
|
+
setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
|
|
19801
19946
|
}
|
|
19802
19947
|
});
|
|
19803
19948
|
}
|
|
@@ -19835,9 +19980,7 @@ function escapeRegExp(string) {
|
|
|
19835
19980
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
19836
19981
|
}
|
|
19837
19982
|
function parseExp(context, content) {
|
|
19838
|
-
|
|
19839
|
-
const options = { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] };
|
|
19840
|
-
return (0, import_lib.parseExpression)(`(${content})`, options);
|
|
19983
|
+
return (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
19841
19984
|
}
|
|
19842
19985
|
function genVarName(exp) {
|
|
19843
19986
|
return `${exp.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/_+$/, "")}`;
|
|
@@ -19878,22 +20021,31 @@ const isMemberExpression = (node) => {
|
|
|
19878
20021
|
function genSetEvent(oper, context) {
|
|
19879
20022
|
const { helper } = context;
|
|
19880
20023
|
const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
|
|
19881
|
-
|
|
19882
|
-
const handler = [
|
|
19883
|
-
`${context.helper("createInvoker")}(`,
|
|
19884
|
-
...genEventHandler(context, [value], modifiers),
|
|
19885
|
-
`)`
|
|
19886
|
-
];
|
|
19887
|
-
const eventOptions = genEventOptions();
|
|
20024
|
+
let handler;
|
|
19888
20025
|
if (delegate) {
|
|
19889
20026
|
context.delegates.add(key.content);
|
|
19890
20027
|
if (!context.block.operation.some(isSameDelegateEvent)) return [
|
|
19891
20028
|
NEWLINE,
|
|
19892
20029
|
`n${element}.$evt${key.content} = `,
|
|
19893
|
-
...
|
|
20030
|
+
...genDirectHandler()
|
|
20031
|
+
];
|
|
20032
|
+
}
|
|
20033
|
+
const name = genName();
|
|
20034
|
+
const eventOptions = genEventOptions();
|
|
20035
|
+
return [NEWLINE, ...genCall(helper(effect ? "onBinding" : delegate ? "delegate" : "on"), `n${element}`, name, genHandler(), eventOptions)];
|
|
20036
|
+
function genHandler() {
|
|
20037
|
+
return handler || (handler = genEventHandler(context, [value], modifiers));
|
|
20038
|
+
}
|
|
20039
|
+
function genInvoker() {
|
|
20040
|
+
return [
|
|
20041
|
+
`${helper("createInvoker")}(`,
|
|
20042
|
+
...genHandler(),
|
|
20043
|
+
`)`
|
|
19894
20044
|
];
|
|
19895
20045
|
}
|
|
19896
|
-
|
|
20046
|
+
function genDirectHandler() {
|
|
20047
|
+
return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
|
|
20048
|
+
}
|
|
19897
20049
|
function genName() {
|
|
19898
20050
|
const expr = genExpression(key, context);
|
|
19899
20051
|
if (keyOverride) {
|
|
@@ -19913,8 +20065,8 @@ function genSetEvent(oper, context) {
|
|
|
19913
20065
|
}
|
|
19914
20066
|
function genEventOptions() {
|
|
19915
20067
|
let { options } = modifiers;
|
|
19916
|
-
if (!options.length
|
|
19917
|
-
return genMulti(DELIMITERS_OBJECT_NEWLINE,
|
|
20068
|
+
if (!options.length) return;
|
|
20069
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
|
|
19918
20070
|
}
|
|
19919
20071
|
function isSameDelegateEvent(op) {
|
|
19920
20072
|
if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
@@ -19927,7 +20079,9 @@ function genSetDynamicEvents(oper, context) {
|
|
|
19927
20079
|
function genEventHandler(context, values, modifiers = {
|
|
19928
20080
|
nonKeys: [],
|
|
19929
20081
|
keys: []
|
|
19930
|
-
},
|
|
20082
|
+
}, options = {}) {
|
|
20083
|
+
const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
|
|
20084
|
+
const useVaporModifierHelper = modifierHelper === "vapor";
|
|
19931
20085
|
let handlerExp = [];
|
|
19932
20086
|
if (values) {
|
|
19933
20087
|
values.forEach((value, index) => {
|
|
@@ -19968,16 +20122,16 @@ function genEventHandler(context, values, modifiers = {
|
|
|
19968
20122
|
}
|
|
19969
20123
|
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
19970
20124
|
const { keys, nonKeys } = modifiers;
|
|
19971
|
-
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
19972
|
-
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
|
|
20125
|
+
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys, useVaporModifierHelper && !keys.length);
|
|
20126
|
+
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys, useVaporModifierHelper);
|
|
19973
20127
|
if (extraWrap) handlerExp.unshift(`() => `);
|
|
19974
20128
|
return handlerExp;
|
|
19975
20129
|
}
|
|
19976
|
-
function genWithModifiers(context, handler, nonKeys) {
|
|
19977
|
-
return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
|
|
20130
|
+
function genWithModifiers(context, handler, nonKeys, useVaporHelper = false) {
|
|
20131
|
+
return genCall(context.helper(useVaporHelper ? "withVaporModifiers" : "withModifiers"), handler, JSON.stringify(nonKeys));
|
|
19978
20132
|
}
|
|
19979
|
-
function genWithKeys(context, handler, keys) {
|
|
19980
|
-
return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
|
|
20133
|
+
function genWithKeys(context, handler, keys, useVaporHelper = false) {
|
|
20134
|
+
return genCall(context.helper(useVaporHelper ? "withVaporKeys" : "withKeys"), handler, JSON.stringify(keys));
|
|
19981
20135
|
}
|
|
19982
20136
|
function isConstantBinding(value, context) {
|
|
19983
20137
|
if (value.ast === null) {
|
|
@@ -20015,16 +20169,12 @@ function genFor(oper, context) {
|
|
|
20015
20169
|
idMap[rawIndex] = `${indexVar}.value`;
|
|
20016
20170
|
idMap[indexVar] = null;
|
|
20017
20171
|
}
|
|
20018
|
-
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap);
|
|
20172
|
+
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap, context);
|
|
20019
20173
|
const selectorDeclarations = [];
|
|
20020
|
-
const
|
|
20174
|
+
const selectorName = (i) => selectorPatterns.length > 1 ? `_selector${id}_${i}` : `_selector${id}`;
|
|
20021
20175
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
20022
20176
|
const { selector } = selectorPatterns[i];
|
|
20023
|
-
const selectorName = `
|
|
20024
|
-
selectorDeclarations.push(`let ${selectorName}`, NEWLINE);
|
|
20025
|
-
if (i === 0) selectorSetup.push(`({ createSelector }) => {`, INDENT_START);
|
|
20026
|
-
selectorSetup.push(NEWLINE, `${selectorName} = `, ...genCall(`createSelector`, [`() => `, ...genExpression(selector, context)]));
|
|
20027
|
-
if (i === selectorPatterns.length - 1) selectorSetup.push(INDENT_END, NEWLINE, "}");
|
|
20177
|
+
selectorDeclarations.push(`const ${selectorName(i)} = `, ...genCall(helper("createSelector"), [`() => `, ...genExpression(selector, context)]), NEWLINE);
|
|
20028
20178
|
}
|
|
20029
20179
|
const blockFn = context.withId(() => {
|
|
20030
20180
|
const frag = [];
|
|
@@ -20033,7 +20183,7 @@ function genFor(oper, context) {
|
|
|
20033
20183
|
const patternFrag = [];
|
|
20034
20184
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
20035
20185
|
const { effect } = selectorPatterns[i];
|
|
20036
|
-
patternFrag.push(NEWLINE,
|
|
20186
|
+
patternFrag.push(NEWLINE, `${selectorName(i)}(`, ...genExpression(keyProp, context), `, () => {`, INDENT_START);
|
|
20037
20187
|
for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
20038
20188
|
patternFrag.push(INDENT_END, NEWLINE, `})`);
|
|
20039
20189
|
}
|
|
@@ -20048,12 +20198,17 @@ function genFor(oper, context) {
|
|
|
20048
20198
|
let flags = 0;
|
|
20049
20199
|
if (onlyChild) flags |= 1;
|
|
20050
20200
|
if (component) flags |= 2;
|
|
20201
|
+
if (isFragmentBlock(render)) flags |= 16;
|
|
20202
|
+
if (!component && isSingleNodeBlock(render)) flags |= 8;
|
|
20051
20203
|
if (once) flags |= 4;
|
|
20204
|
+
const onResetCalls = [];
|
|
20205
|
+
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
20052
20206
|
return [
|
|
20053
20207
|
NEWLINE,
|
|
20054
20208
|
...selectorDeclarations,
|
|
20055
20209
|
`const n${id} = `,
|
|
20056
|
-
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0,
|
|
20210
|
+
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0),
|
|
20211
|
+
...onResetCalls
|
|
20057
20212
|
];
|
|
20058
20213
|
function genCallback(expr) {
|
|
20059
20214
|
if (!expr) return false;
|
|
@@ -20077,6 +20232,21 @@ function genFor(oper, context) {
|
|
|
20077
20232
|
return idMap;
|
|
20078
20233
|
}
|
|
20079
20234
|
}
|
|
20235
|
+
function isSingleNodeBlock(block) {
|
|
20236
|
+
const child = getSingleReturnedChild(block);
|
|
20237
|
+
return !!child && child.template != null;
|
|
20238
|
+
}
|
|
20239
|
+
function isFragmentBlock(block) {
|
|
20240
|
+
const child = getSingleReturnedChild(block);
|
|
20241
|
+
const operation = child && child.operation;
|
|
20242
|
+
if (!operation) return false;
|
|
20243
|
+
return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
|
|
20244
|
+
}
|
|
20245
|
+
function getSingleReturnedChild(block) {
|
|
20246
|
+
if (block.returns.length !== 1) return;
|
|
20247
|
+
const id = block.returns[0];
|
|
20248
|
+
for (const child of block.dynamic.children) if (child.id === id) return child;
|
|
20249
|
+
}
|
|
20080
20250
|
function parseValueDestructure(value, context) {
|
|
20081
20251
|
const map = /* @__PURE__ */ new Map();
|
|
20082
20252
|
if (value) {
|
|
@@ -20139,19 +20309,19 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
|
20139
20309
|
}
|
|
20140
20310
|
if (pathInfo.dynamic) {
|
|
20141
20311
|
const node = idMap[id] = createSimpleExpression(path);
|
|
20142
|
-
node.ast = (0, import_lib.parseExpression)(`(${path})`,
|
|
20312
|
+
node.ast = (0, import_lib.parseExpression)(`(${path})`, getParserOptions(plugins));
|
|
20143
20313
|
} else idMap[id] = path;
|
|
20144
20314
|
} else idMap[id] = path;
|
|
20145
20315
|
});
|
|
20146
20316
|
return idMap;
|
|
20147
20317
|
}
|
|
20148
|
-
function matchPatterns(render, keyProp, idMap) {
|
|
20318
|
+
function matchPatterns(render, keyProp, idMap, context) {
|
|
20149
20319
|
const selectorPatterns = [];
|
|
20150
20320
|
const keyOnlyBindingPatterns = [];
|
|
20151
20321
|
const removedEffectIndexes = [];
|
|
20152
20322
|
render.effect = render.effect.filter((effect, index) => {
|
|
20153
20323
|
if (keyProp !== void 0) {
|
|
20154
|
-
const selector = matchSelectorPattern(effect, keyProp.content, idMap);
|
|
20324
|
+
const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
|
|
20155
20325
|
if (selector) {
|
|
20156
20326
|
selectorPatterns.push(selector);
|
|
20157
20327
|
removedEffectIndexes.push(index);
|
|
@@ -20190,7 +20360,7 @@ function matchKeyOnlyBindingPattern(effect, key) {
|
|
|
20190
20360
|
}
|
|
20191
20361
|
}
|
|
20192
20362
|
}
|
|
20193
|
-
function matchSelectorPattern(effect, key, idMap) {
|
|
20363
|
+
function matchSelectorPattern(effect, key, idMap, context) {
|
|
20194
20364
|
if (effect.expressions.length === 1) {
|
|
20195
20365
|
const { ast, content } = effect.expressions[0];
|
|
20196
20366
|
if (typeof ast === "object" && ast) {
|
|
@@ -20215,17 +20385,11 @@ function matchSelectorPattern(effect, key, idMap) {
|
|
|
20215
20385
|
}, false);
|
|
20216
20386
|
if (!hasExtraId) {
|
|
20217
20387
|
const name = content.slice(selector.start - 1, selector.end - 1);
|
|
20388
|
+
const selectorExpression = createSimpleExpression(name, false, selector.loc);
|
|
20389
|
+
selectorExpression.ast = (0, import_lib.parseExpression)(`(${name})`, getParserOptions(context.options.expressionPlugins));
|
|
20218
20390
|
return {
|
|
20219
20391
|
effect,
|
|
20220
|
-
selector:
|
|
20221
|
-
content: name,
|
|
20222
|
-
ast: extend({}, selector, {
|
|
20223
|
-
start: 1,
|
|
20224
|
-
end: name.length + 1
|
|
20225
|
-
}),
|
|
20226
|
-
loc: selector.loc,
|
|
20227
|
-
isStatic: false
|
|
20228
|
-
}
|
|
20392
|
+
selector: selectorExpression
|
|
20229
20393
|
};
|
|
20230
20394
|
}
|
|
20231
20395
|
}
|
|
@@ -20268,6 +20432,7 @@ function genIf(oper, context, isNested = false) {
|
|
|
20268
20432
|
const { helper } = context;
|
|
20269
20433
|
const { condition, positive, negative, once, index, blockShape } = oper;
|
|
20270
20434
|
const [frag, push] = buildCodeFragment();
|
|
20435
|
+
const flags = genIfFlags(blockShape, once, negative ? index : void 0);
|
|
20271
20436
|
const conditionExpr = [
|
|
20272
20437
|
"() => (",
|
|
20273
20438
|
...genExpression(condition, context),
|
|
@@ -20278,15 +20443,31 @@ function genIf(oper, context, isNested = false) {
|
|
|
20278
20443
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
20279
20444
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
20280
20445
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
20281
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg,
|
|
20446
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
|
|
20282
20447
|
return frag;
|
|
20283
20448
|
}
|
|
20449
|
+
function genIfFlags(blockShape, once, index) {
|
|
20450
|
+
let flags = blockShape;
|
|
20451
|
+
if (once) flags |= 16;
|
|
20452
|
+
else if (index !== void 0) flags |= index + 1 << 7;
|
|
20453
|
+
if (flags === 1) return false;
|
|
20454
|
+
return `${flags} /* ${genIfFlagNames(once, index, blockShape)} */`;
|
|
20455
|
+
}
|
|
20456
|
+
function genIfFlagNames(once, index, blockShape) {
|
|
20457
|
+
const names = ["BLOCK_SHAPE"];
|
|
20458
|
+
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
20459
|
+
if (blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
20460
|
+
if (once) names.push("ONCE");
|
|
20461
|
+
else if (index !== void 0) names.push("INDEX_SHIFT");
|
|
20462
|
+
return names.join(", ");
|
|
20463
|
+
}
|
|
20284
20464
|
//#endregion
|
|
20285
20465
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
20286
20466
|
const helpers = {
|
|
20287
20467
|
setText: { name: "setText" },
|
|
20288
20468
|
setHtml: { name: "setHtml" },
|
|
20289
20469
|
setClass: { name: "setClass" },
|
|
20470
|
+
setClassName: { name: "setClassName" },
|
|
20290
20471
|
setStyle: { name: "setStyle" },
|
|
20291
20472
|
setValue: { name: "setValue" },
|
|
20292
20473
|
setAttr: {
|
|
@@ -20306,9 +20487,133 @@ function genSetProp(oper, context) {
|
|
|
20306
20487
|
const { helper } = context;
|
|
20307
20488
|
const { prop: { key, values, modifier }, tag } = oper;
|
|
20308
20489
|
const resolvedHelper = getRuntimeHelper(tag, key.content, modifier);
|
|
20490
|
+
if (key.content === "class" && !resolvedHelper.isSVG && resolvedHelper.name === "setClass") {
|
|
20491
|
+
const className = genSetClassName(oper, context);
|
|
20492
|
+
if (className) return className;
|
|
20493
|
+
}
|
|
20309
20494
|
const propValue = genPropValue(values, context);
|
|
20310
20495
|
return [NEWLINE, ...genCall([helper(resolvedHelper.name), null], `n${oper.element}`, resolvedHelper.needKey ? genExpression(key, context) : false, propValue, resolvedHelper.isSVG && "true")];
|
|
20311
20496
|
}
|
|
20497
|
+
const MAX_CLASS_NAME_ENTRIES = 31;
|
|
20498
|
+
function genSetClassName(oper, context) {
|
|
20499
|
+
const info = resolveClassName(oper.prop.values, context);
|
|
20500
|
+
if (!info) return;
|
|
20501
|
+
const { helper } = context;
|
|
20502
|
+
const flags = genClassFlags(info.entries, context);
|
|
20503
|
+
const classFragments = info.entries.map((entry) => JSON.stringify(!info.prefix && info.entries.length === 1 ? entry.className : ` ${entry.className}`));
|
|
20504
|
+
const fragments = classFragments.length === 1 ? classFragments[0] : genMulti(DELIMITERS_ARRAY, ...classFragments);
|
|
20505
|
+
return [NEWLINE, ...genCall([helper("setClassName"), "\"\""], `n${oper.element}`, flags, fragments, info.prefix && JSON.stringify(info.prefix), info.suffix && JSON.stringify(info.suffix))];
|
|
20506
|
+
}
|
|
20507
|
+
function resolveClassName(values, context) {
|
|
20508
|
+
let prefix = "";
|
|
20509
|
+
let suffix = "";
|
|
20510
|
+
const entries = [];
|
|
20511
|
+
let sawDynamic = false;
|
|
20512
|
+
let sawSuffix = false;
|
|
20513
|
+
for (const rawValue of values) {
|
|
20514
|
+
const value = context.getExpressionReplacement(rawValue);
|
|
20515
|
+
const staticValue = getLiteralExpressionValue(value, true);
|
|
20516
|
+
if (staticValue != null) {
|
|
20517
|
+
const normalized = normalizeClass(staticValue);
|
|
20518
|
+
if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
|
|
20519
|
+
else if (sawDynamic) {
|
|
20520
|
+
sawSuffix = true;
|
|
20521
|
+
suffix = appendClass$1(suffix, normalized);
|
|
20522
|
+
} else prefix = appendClass$1(prefix, normalized);
|
|
20523
|
+
continue;
|
|
20524
|
+
}
|
|
20525
|
+
const ast = value.ast;
|
|
20526
|
+
if (!ast || sawSuffix) return;
|
|
20527
|
+
sawDynamic = true;
|
|
20528
|
+
if (ast.type === "ObjectExpression") {
|
|
20529
|
+
if (!resolveObjectClassName(value, ast, entries, context)) return;
|
|
20530
|
+
} else if (ast.type === "ConditionalExpression") {
|
|
20531
|
+
if (!resolveConditionalClassName(value, ast, entries, context)) return;
|
|
20532
|
+
} else return;
|
|
20533
|
+
}
|
|
20534
|
+
return entries.length && entries.length <= MAX_CLASS_NAME_ENTRIES ? {
|
|
20535
|
+
prefix,
|
|
20536
|
+
suffix,
|
|
20537
|
+
entries
|
|
20538
|
+
} : void 0;
|
|
20539
|
+
}
|
|
20540
|
+
function resolveObjectClassName(source, ast, entries, context) {
|
|
20541
|
+
for (const prop of ast.properties) {
|
|
20542
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
20543
|
+
const rawClassName = getObjectPropertyName$1(prop);
|
|
20544
|
+
if (rawClassName == null) return false;
|
|
20545
|
+
const className = normalizeClass(rawClassName);
|
|
20546
|
+
if (!className) continue;
|
|
20547
|
+
const value = getBooleanValue(prop.value);
|
|
20548
|
+
entries.push({
|
|
20549
|
+
className,
|
|
20550
|
+
value,
|
|
20551
|
+
condition: value == null ? createSubExpression(source, prop.value, context) : void 0
|
|
20552
|
+
});
|
|
20553
|
+
}
|
|
20554
|
+
return true;
|
|
20555
|
+
}
|
|
20556
|
+
function resolveConditionalClassName(source, ast, entries, context) {
|
|
20557
|
+
const consequent = getStringClassValue(ast.consequent);
|
|
20558
|
+
const alternate = getStringClassValue(ast.alternate);
|
|
20559
|
+
if (consequent && alternate === "") {
|
|
20560
|
+
entries.push({
|
|
20561
|
+
className: consequent,
|
|
20562
|
+
condition: createSubExpression(source, ast.test, context)
|
|
20563
|
+
});
|
|
20564
|
+
return true;
|
|
20565
|
+
} else if (alternate && consequent === "") {
|
|
20566
|
+
entries.push({
|
|
20567
|
+
className: alternate,
|
|
20568
|
+
condition: createSubExpression(source, ast.test, context),
|
|
20569
|
+
negate: true
|
|
20570
|
+
});
|
|
20571
|
+
return true;
|
|
20572
|
+
}
|
|
20573
|
+
return false;
|
|
20574
|
+
}
|
|
20575
|
+
function genClassFlags(entries, context) {
|
|
20576
|
+
const values = [];
|
|
20577
|
+
entries.forEach((entry, index) => {
|
|
20578
|
+
if (index) values.push(" | ");
|
|
20579
|
+
const bit = 1 << index;
|
|
20580
|
+
if (entry.value != null) {
|
|
20581
|
+
values.push(entry.value ? String(bit) : "0");
|
|
20582
|
+
return;
|
|
20583
|
+
}
|
|
20584
|
+
values.push("(", ...genExpression(entry.condition, context), entry.negate ? ` ? 0 : ${bit}` : ` ? ${bit} : 0`, ")");
|
|
20585
|
+
});
|
|
20586
|
+
return values;
|
|
20587
|
+
}
|
|
20588
|
+
function appendClass$1(base, value) {
|
|
20589
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
20590
|
+
}
|
|
20591
|
+
function getObjectPropertyName$1(prop) {
|
|
20592
|
+
const key = prop.key;
|
|
20593
|
+
if (key.type === "Identifier") return key.name;
|
|
20594
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
20595
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
20596
|
+
}
|
|
20597
|
+
function getStringClassValue(node) {
|
|
20598
|
+
if (node.type === "StringLiteral") return normalizeClass(node.value);
|
|
20599
|
+
else if (node.type === "TemplateLiteral" && node.expressions.length === 0) return normalizeClass(node.quasis[0].value.cooked || "");
|
|
20600
|
+
else if (node.type === "NullLiteral" || node.type === "BooleanLiteral" && !node.value) return "";
|
|
20601
|
+
}
|
|
20602
|
+
function getBooleanValue(node) {
|
|
20603
|
+
if (node.type === "BooleanLiteral") return node.value;
|
|
20604
|
+
}
|
|
20605
|
+
function createSubExpression(source, node, context) {
|
|
20606
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
20607
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
20608
|
+
const content = source.content.slice(start, end);
|
|
20609
|
+
const expression = createSimpleExpression(content, false, {
|
|
20610
|
+
start: advancePositionWithClone(source.loc.start, source.content, start),
|
|
20611
|
+
end: advancePositionWithClone(source.loc.start, source.content, end),
|
|
20612
|
+
source: content
|
|
20613
|
+
});
|
|
20614
|
+
expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
20615
|
+
return expression;
|
|
20616
|
+
}
|
|
20312
20617
|
function genDynamicProps$1(oper, context) {
|
|
20313
20618
|
const { helper } = context;
|
|
20314
20619
|
const isSVG = isSVGTag(oper.tag);
|
|
@@ -20375,8 +20680,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
20375
20680
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
20376
20681
|
function genSetTemplateRef(oper, context) {
|
|
20377
20682
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
20683
|
+
if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
|
|
20684
|
+
context.needsTemplateRefSetter = true;
|
|
20378
20685
|
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
20379
20686
|
}
|
|
20687
|
+
function genSetStaticTemplateRef(oper, refValue, refKey, context) {
|
|
20688
|
+
return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
20689
|
+
}
|
|
20690
|
+
function genSetTemplateRefBinding(oper, context) {
|
|
20691
|
+
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
20692
|
+
const setter = context.inSlotBlock && setTemplateRefIdent;
|
|
20693
|
+
if (context.inSlotBlock) context.needsTemplateRefSetter = true;
|
|
20694
|
+
return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
|
|
20695
|
+
setter,
|
|
20696
|
+
oper.refFor && "true",
|
|
20697
|
+
refKey
|
|
20698
|
+
] : [])];
|
|
20699
|
+
}
|
|
20380
20700
|
function genRefValue(value, context) {
|
|
20381
20701
|
if (value && context.options.inline) {
|
|
20382
20702
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -20480,15 +20800,18 @@ function filterCustomDirectives(id, operations) {
|
|
|
20480
20800
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
20481
20801
|
function genCreateComponent(operation, context) {
|
|
20482
20802
|
const { helper } = context;
|
|
20803
|
+
const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
20804
|
+
const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
|
|
20805
|
+
const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
|
|
20483
20806
|
const tag = genTag();
|
|
20484
20807
|
const { root, props, slots, once } = operation;
|
|
20485
20808
|
const rawSlots = genRawSlots(slots, context);
|
|
20486
20809
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
20487
|
-
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
20810
|
+
const rawProps = context.withId(() => genRawProps(props, context, true), ids);
|
|
20488
20811
|
return [
|
|
20489
20812
|
NEWLINE,
|
|
20490
20813
|
...handlers.reduce((acc, { name, value }) => {
|
|
20491
|
-
const handler = genEventHandler(context, [value]
|
|
20814
|
+
const handler = genEventHandler(context, [value]);
|
|
20492
20815
|
return [
|
|
20493
20816
|
...acc,
|
|
20494
20817
|
`const ${name} = `,
|
|
@@ -20497,7 +20820,7 @@ function genCreateComponent(operation, context) {
|
|
|
20497
20820
|
];
|
|
20498
20821
|
}, []),
|
|
20499
20822
|
`const n${operation.id} = `,
|
|
20500
|
-
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true"),
|
|
20823
|
+
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : useAssetComponentHelper ? helper("createAssetComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true", maybeSelfReference && "true"),
|
|
20501
20824
|
...genDirectivesForElement(operation.id, context)
|
|
20502
20825
|
];
|
|
20503
20826
|
function genTag() {
|
|
@@ -20508,7 +20831,10 @@ function genCreateComponent(operation, context) {
|
|
|
20508
20831
|
...genExpression(operation.dynamic, context),
|
|
20509
20832
|
")"
|
|
20510
20833
|
];
|
|
20511
|
-
else if (
|
|
20834
|
+
else if (useAssetComponentHelper) {
|
|
20835
|
+
const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
|
|
20836
|
+
return JSON.stringify(name);
|
|
20837
|
+
} else if (operation.asset) return toValidAssetId(operation.tag, "component");
|
|
20512
20838
|
else {
|
|
20513
20839
|
const { tag } = operation;
|
|
20514
20840
|
const builtInTag = isBuiltInComponent(tag);
|
|
@@ -20548,14 +20874,14 @@ function processInlineHandlers(props, context) {
|
|
|
20548
20874
|
}
|
|
20549
20875
|
return [ids, handlers];
|
|
20550
20876
|
}
|
|
20551
|
-
function genRawProps(props, context) {
|
|
20877
|
+
function genRawProps(props, context, directStaticLiteralProps = false) {
|
|
20552
20878
|
const staticProps = props[0];
|
|
20553
20879
|
if (isArray$1(staticProps)) {
|
|
20554
20880
|
if (!staticProps.length && props.length === 1) return;
|
|
20555
|
-
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
|
|
20556
|
-
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
|
|
20881
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
|
|
20882
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
|
|
20557
20883
|
}
|
|
20558
|
-
function genStaticProps(props, context, dynamicProps) {
|
|
20884
|
+
function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
|
|
20559
20885
|
const args = [];
|
|
20560
20886
|
const handlerGroups = /* @__PURE__ */ new Map();
|
|
20561
20887
|
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
@@ -20588,11 +20914,11 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
20588
20914
|
continue;
|
|
20589
20915
|
}
|
|
20590
20916
|
const keyFrag = genPropKey(prop, context);
|
|
20591
|
-
if (!!prop.handlerModifiers && (prop.handlerModifiers.keys.length > 0 || prop.handlerModifiers.nonKeys.length > 0) || prop.values.length <= 1) addHandler(keyName, keyFrag, genEventHandler(context, prop.values, prop.handlerModifiers, true
|
|
20592
|
-
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true
|
|
20917
|
+
if (!!prop.handlerModifiers && (prop.handlerModifiers.keys.length > 0 || prop.handlerModifiers.nonKeys.length > 0) || prop.values.length <= 1) addHandler(keyName, keyFrag, genEventHandler(context, prop.values, prop.handlerModifiers, { asComponentProp: true }));
|
|
20918
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
|
|
20593
20919
|
continue;
|
|
20594
20920
|
}
|
|
20595
|
-
args.push(genProp(prop, context, true));
|
|
20921
|
+
args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
|
|
20596
20922
|
if (prop.model) {
|
|
20597
20923
|
if (prop.key.isStatic) {
|
|
20598
20924
|
const keyName = `onUpdate:${camelize(prop.key.content)}`;
|
|
@@ -20617,7 +20943,7 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
20617
20943
|
" + \"Modifiers\"]"
|
|
20618
20944
|
];
|
|
20619
20945
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
20620
|
-
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
20946
|
+
args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
|
|
20621
20947
|
}
|
|
20622
20948
|
}
|
|
20623
20949
|
}
|
|
@@ -20632,13 +20958,13 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
20632
20958
|
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
20633
20959
|
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
20634
20960
|
}
|
|
20635
|
-
function genDynamicProps(props, context) {
|
|
20961
|
+
function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
20636
20962
|
const { helper } = context;
|
|
20637
20963
|
const frags = [];
|
|
20638
20964
|
for (const p of props) {
|
|
20639
20965
|
let expr;
|
|
20640
20966
|
if (isArray$1(p)) {
|
|
20641
|
-
if (p.length) frags.push(genStaticProps(p, context));
|
|
20967
|
+
if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
|
|
20642
20968
|
continue;
|
|
20643
20969
|
} else if (p.kind === 1) if (p.model) {
|
|
20644
20970
|
const entries = [genProp(p, context)];
|
|
@@ -20649,7 +20975,7 @@ function genDynamicProps(props, context) {
|
|
|
20649
20975
|
];
|
|
20650
20976
|
entries.push([
|
|
20651
20977
|
...updateKey,
|
|
20652
|
-
":
|
|
20978
|
+
": ",
|
|
20653
20979
|
...genModelHandler(p.values[0], context)
|
|
20654
20980
|
]);
|
|
20655
20981
|
const { modelModifiers } = p;
|
|
@@ -20660,10 +20986,10 @@ function genDynamicProps(props, context) {
|
|
|
20660
20986
|
" + \"Modifiers\"]"
|
|
20661
20987
|
];
|
|
20662
20988
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
20663
|
-
entries.push([...modifiersKey, `:
|
|
20989
|
+
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
20664
20990
|
}
|
|
20665
20991
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
20666
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
20992
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context, false, false));
|
|
20667
20993
|
else {
|
|
20668
20994
|
expr = genExpression(p.value, context);
|
|
20669
20995
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -20676,27 +21002,79 @@ function genDynamicProps(props, context) {
|
|
|
20676
21002
|
}
|
|
20677
21003
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
20678
21004
|
}
|
|
20679
|
-
function genProp(prop, context, isStatic) {
|
|
21005
|
+
function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
|
|
20680
21006
|
const values = genPropValue(prop.values, context);
|
|
20681
21007
|
return [
|
|
20682
21008
|
...genPropKey(prop, context),
|
|
20683
21009
|
": ",
|
|
20684
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
21010
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
|
|
21011
|
+
asComponentProp: true,
|
|
21012
|
+
extraWrap: wrapHandler
|
|
21013
|
+
}) : isStatic ? directStaticLiteral ? values : [
|
|
20685
21014
|
"() => (",
|
|
20686
21015
|
...values,
|
|
20687
21016
|
")"
|
|
20688
21017
|
] : values
|
|
20689
21018
|
];
|
|
20690
21019
|
}
|
|
21020
|
+
/**
|
|
21021
|
+
* Static literal values are safe to emit directly because reading them cannot
|
|
21022
|
+
* touch reactive state. Keep handlers, v-model values, and dynamic expressions
|
|
21023
|
+
* as getter sources to preserve lazy access and merge semantics.
|
|
21024
|
+
*/
|
|
21025
|
+
function isDirectStaticLiteralProp(prop, context) {
|
|
21026
|
+
return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
|
|
21027
|
+
}
|
|
21028
|
+
function isDirectConstantValue(value, context) {
|
|
21029
|
+
value = context.getExpressionReplacement(value);
|
|
21030
|
+
if (value.isStatic) return true;
|
|
21031
|
+
const ast = value.ast;
|
|
21032
|
+
if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
|
|
21033
|
+
if (!ast) return false;
|
|
21034
|
+
return isDirectConstantAst(ast);
|
|
21035
|
+
}
|
|
21036
|
+
function isDirectConstantAst(node) {
|
|
21037
|
+
switch (node.type) {
|
|
21038
|
+
case "StringLiteral":
|
|
21039
|
+
case "NumericLiteral":
|
|
21040
|
+
case "BooleanLiteral":
|
|
21041
|
+
case "NullLiteral":
|
|
21042
|
+
case "BigIntLiteral": return true;
|
|
21043
|
+
case "Identifier": return node.name === "undefined";
|
|
21044
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
21045
|
+
case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
|
|
21046
|
+
case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
|
|
21047
|
+
}
|
|
21048
|
+
return false;
|
|
21049
|
+
}
|
|
21050
|
+
function isDirectTemplateConstantAst(node) {
|
|
21051
|
+
switch (node.type) {
|
|
21052
|
+
case "StringLiteral":
|
|
21053
|
+
case "NumericLiteral":
|
|
21054
|
+
case "BooleanLiteral":
|
|
21055
|
+
case "NullLiteral":
|
|
21056
|
+
case "BigIntLiteral": return true;
|
|
21057
|
+
case "Identifier": return node.name === "undefined";
|
|
21058
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
21059
|
+
}
|
|
21060
|
+
return false;
|
|
21061
|
+
}
|
|
20691
21062
|
function genRawSlots(slots, context) {
|
|
20692
21063
|
if (!slots.length) return;
|
|
20693
21064
|
const staticSlots = slots[0];
|
|
20694
|
-
if (staticSlots.slotType === 0)
|
|
20695
|
-
|
|
21065
|
+
if (staticSlots.slotType === 0) {
|
|
21066
|
+
const defaultSlot = getSingleDefaultSlot(staticSlots);
|
|
21067
|
+
if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
|
|
21068
|
+
return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
21069
|
+
} else return genStaticSlots({
|
|
20696
21070
|
slotType: 0,
|
|
20697
21071
|
slots: {}
|
|
20698
21072
|
}, context, slots);
|
|
20699
21073
|
}
|
|
21074
|
+
function getSingleDefaultSlot({ slots }) {
|
|
21075
|
+
const names = Object.keys(slots);
|
|
21076
|
+
return names.length === 1 && names[0] === "default" ? slots.default : void 0;
|
|
21077
|
+
}
|
|
20700
21078
|
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
20701
21079
|
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
20702
21080
|
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
@@ -20718,11 +21096,23 @@ function genDynamicSlot(slot, context, withFunction = false) {
|
|
|
20718
21096
|
frag = genConditionalSlot(slot, context);
|
|
20719
21097
|
break;
|
|
20720
21098
|
}
|
|
20721
|
-
|
|
21099
|
+
if (!withFunction) return frag;
|
|
21100
|
+
return needsDynamicSlotSourceCtx(slot) ? [
|
|
21101
|
+
`${context.helper("withVaporCtx")}(() => (`,
|
|
21102
|
+
...frag,
|
|
21103
|
+
"))"
|
|
21104
|
+
] : [
|
|
20722
21105
|
"() => (",
|
|
20723
21106
|
...frag,
|
|
20724
21107
|
")"
|
|
20725
|
-
]
|
|
21108
|
+
];
|
|
21109
|
+
}
|
|
21110
|
+
function needsDynamicSlotSourceCtx(slot) {
|
|
21111
|
+
switch (slot.slotType) {
|
|
21112
|
+
case 1: return needsVaporCtx(slot.fn);
|
|
21113
|
+
case 2: return needsVaporCtx(slot.fn);
|
|
21114
|
+
case 3: return needsDynamicSlotSourceCtx(slot.positive) || (slot.negative ? needsDynamicSlotSourceCtx(slot.negative) : false);
|
|
21115
|
+
}
|
|
20726
21116
|
}
|
|
20727
21117
|
function genBasicDynamicSlot(slot, context) {
|
|
20728
21118
|
const { name, fn } = slot;
|
|
@@ -20776,7 +21166,9 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
20776
21166
|
} else propsName = props.content;
|
|
20777
21167
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
20778
21168
|
if (propsName) idMap[propsName] = null;
|
|
21169
|
+
const exitSlotBlock = context.enterSlotBlock();
|
|
20779
21170
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
21171
|
+
exitSlotBlock();
|
|
20780
21172
|
exitScope && exitScope();
|
|
20781
21173
|
if (node.type === 1) {
|
|
20782
21174
|
if (needsVaporCtx(oper)) blockFn = [
|
|
@@ -20837,16 +21229,18 @@ function hasComponentOrSlotInIf(node) {
|
|
|
20837
21229
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
20838
21230
|
function genSlotOutlet(oper, context) {
|
|
20839
21231
|
const { helper } = context;
|
|
20840
|
-
const { id, name, fallback,
|
|
21232
|
+
const { id, name, fallback, flags } = oper;
|
|
20841
21233
|
const [frag, push] = buildCodeFragment();
|
|
20842
|
-
|
|
21234
|
+
let fallbackArg;
|
|
21235
|
+
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
21236
|
+
const createSlot = helper("createSlot");
|
|
21237
|
+
const rawPropsArg = genRawProps(oper.props, context, true);
|
|
21238
|
+
const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
|
|
20843
21239
|
"() => (",
|
|
20844
21240
|
...genExpression(name, context),
|
|
20845
21241
|
")"
|
|
20846
21242
|
];
|
|
20847
|
-
|
|
20848
|
-
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
20849
|
-
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
21243
|
+
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, flags ? String(flags) : void 0));
|
|
20850
21244
|
return frag;
|
|
20851
21245
|
}
|
|
20852
21246
|
//#endregion
|
|
@@ -20906,28 +21300,35 @@ function genEffects(effects, context, genExtraFrag) {
|
|
|
20906
21300
|
const [frag, push, unshift] = buildCodeFragment();
|
|
20907
21301
|
const shouldDeclare = genExtraFrag === void 0;
|
|
20908
21302
|
let operationsCount = 0;
|
|
20909
|
-
const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
|
|
20910
|
-
|
|
20911
|
-
|
|
20912
|
-
const
|
|
20913
|
-
|
|
20914
|
-
|
|
20915
|
-
|
|
20916
|
-
|
|
20917
|
-
|
|
20918
|
-
|
|
20919
|
-
|
|
20920
|
-
|
|
20921
|
-
|
|
20922
|
-
|
|
20923
|
-
|
|
20924
|
-
|
|
20925
|
-
|
|
20926
|
-
|
|
20927
|
-
|
|
20928
|
-
|
|
20929
|
-
|
|
20930
|
-
|
|
21303
|
+
const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
|
|
21304
|
+
if (shouldDeclare && !declarationFrags.length && !varNames.length) {
|
|
21305
|
+
const effect = effects.length === 1 ? effects[0] : void 0;
|
|
21306
|
+
const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
|
|
21307
|
+
if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
|
|
21308
|
+
}
|
|
21309
|
+
return context.withExpressionReplacements(expressionReplacements, () => {
|
|
21310
|
+
push(...declarationFrags);
|
|
21311
|
+
for (let i = 0; i < effects.length; i++) {
|
|
21312
|
+
const effect = effects[i];
|
|
21313
|
+
operationsCount += effect.operations.length;
|
|
21314
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
21315
|
+
i > 0 && push(NEWLINE);
|
|
21316
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
21317
|
+
push(...frags);
|
|
21318
|
+
}
|
|
21319
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
21320
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
21321
|
+
push(INDENT_END, NEWLINE, "}");
|
|
21322
|
+
if (!effects.length) unshift(NEWLINE);
|
|
21323
|
+
}
|
|
21324
|
+
if (effects.length) {
|
|
21325
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
21326
|
+
push(`)`);
|
|
21327
|
+
}
|
|
21328
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
21329
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
21330
|
+
return frag;
|
|
21331
|
+
});
|
|
20931
21332
|
}
|
|
20932
21333
|
function genEffect({ operations }, context) {
|
|
20933
21334
|
const [frag, push] = buildCodeFragment();
|
|
@@ -20946,9 +21347,8 @@ function genTemplates(templates, context) {
|
|
|
20946
21347
|
const result = [];
|
|
20947
21348
|
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
20948
21349
|
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
20949
|
-
|
|
20950
|
-
|
|
20951
|
-
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
21350
|
+
const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
|
|
21351
|
+
if (flags || ns) args += `, ${flags}`;
|
|
20952
21352
|
if (ns) args += `, ${ns}`;
|
|
20953
21353
|
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
20954
21354
|
});
|
|
@@ -20966,10 +21366,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
|
20966
21366
|
return frag;
|
|
20967
21367
|
}
|
|
20968
21368
|
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
20969
|
-
const { helper } = context;
|
|
20970
21369
|
const [frag, push] = buildCodeFragment();
|
|
20971
21370
|
const { children } = dynamic;
|
|
20972
21371
|
let offset = 0;
|
|
21372
|
+
/**
|
|
21373
|
+
* `reusable` means the previous access target is a p* cursor that can be
|
|
21374
|
+
* reassigned by the next lookup. Referenced n* variables must stay stable.
|
|
21375
|
+
*/
|
|
20973
21376
|
let prev;
|
|
20974
21377
|
for (const [index, child] of children.entries()) {
|
|
20975
21378
|
if (child.flags & 2) offset--;
|
|
@@ -20986,27 +21389,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
|
|
|
20986
21389
|
}
|
|
20987
21390
|
const elementIndex = index + offset;
|
|
20988
21391
|
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
20989
|
-
const
|
|
20990
|
-
|
|
20991
|
-
if (
|
|
20992
|
-
|
|
20993
|
-
|
|
20994
|
-
|
|
20995
|
-
|
|
20996
|
-
|
|
20997
|
-
|
|
20998
|
-
|
|
21392
|
+
const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
|
|
21393
|
+
const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
|
|
21394
|
+
if (inlinePlaceholder) {
|
|
21395
|
+
if (prev && prev[2]) {
|
|
21396
|
+
push(...genChildren(child, context, pushBlock, [
|
|
21397
|
+
"(",
|
|
21398
|
+
prev[0],
|
|
21399
|
+
" = ",
|
|
21400
|
+
...accessPath,
|
|
21401
|
+
")"
|
|
21402
|
+
], flushBeforeDynamic));
|
|
21403
|
+
prev = [
|
|
21404
|
+
prev[0],
|
|
21405
|
+
elementIndex,
|
|
21406
|
+
true
|
|
21407
|
+
];
|
|
21408
|
+
continue;
|
|
21409
|
+
}
|
|
21410
|
+
if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
|
|
21411
|
+
push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
|
|
21412
|
+
continue;
|
|
21413
|
+
}
|
|
21414
|
+
}
|
|
21415
|
+
let variable;
|
|
21416
|
+
if (id === void 0 && prev && prev[2]) {
|
|
21417
|
+
variable = prev[0];
|
|
21418
|
+
pushBlock(NEWLINE, `${variable} = `, ...accessPath);
|
|
21419
|
+
} else {
|
|
21420
|
+
variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
21421
|
+
pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
|
|
20999
21422
|
}
|
|
21000
21423
|
if (id === child.anchor && !child.hasDynamicChild) {
|
|
21001
21424
|
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
21002
21425
|
push(...genSelf(child, context, flushBeforeDynamic));
|
|
21003
21426
|
}
|
|
21004
21427
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
21005
|
-
prev = [
|
|
21428
|
+
prev = [
|
|
21429
|
+
variable,
|
|
21430
|
+
elementIndex,
|
|
21431
|
+
id === void 0
|
|
21432
|
+
];
|
|
21006
21433
|
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
21007
21434
|
}
|
|
21008
21435
|
return frag;
|
|
21009
21436
|
}
|
|
21437
|
+
/**
|
|
21438
|
+
* Build one DOM lookup path while preserving the fast sibling walk:
|
|
21439
|
+
* adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
|
|
21440
|
+
*/
|
|
21441
|
+
function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
|
|
21442
|
+
if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
21443
|
+
if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
|
|
21444
|
+
const firstChild = genCall(helper("child"), from);
|
|
21445
|
+
return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
21446
|
+
}
|
|
21447
|
+
/**
|
|
21448
|
+
* Only inline a placeholder when materializing it would not save a parent
|
|
21449
|
+
* lookup. If its child tree needs the parent more than once, keep p* so the
|
|
21450
|
+
* generated code does not duplicate _child/_nthChild work.
|
|
21451
|
+
*/
|
|
21452
|
+
function canInlinePlaceholder(dynamic) {
|
|
21453
|
+
return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
|
|
21454
|
+
}
|
|
21455
|
+
/**
|
|
21456
|
+
* A following access can reuse the current placeholder cursor only when it is
|
|
21457
|
+
* the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
|
|
21458
|
+
*/
|
|
21459
|
+
function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
|
|
21460
|
+
let futureOffset = offset;
|
|
21461
|
+
for (let i = index + 1; i < children.length; i++) {
|
|
21462
|
+
const child = children[i];
|
|
21463
|
+
if (child.flags & 2) futureOffset--;
|
|
21464
|
+
if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
|
|
21465
|
+
}
|
|
21466
|
+
return false;
|
|
21467
|
+
}
|
|
21468
|
+
/**
|
|
21469
|
+
* Mirrors genChildren's traversal closely enough to count how many emitted
|
|
21470
|
+
* access paths would start from this placeholder's parent. This is the guard
|
|
21471
|
+
* that keeps inline placeholders from duplicating parent lookups.
|
|
21472
|
+
*/
|
|
21473
|
+
function countParentAccessUsages(dynamic) {
|
|
21474
|
+
let usages = 0;
|
|
21475
|
+
let offset = 0;
|
|
21476
|
+
let prev;
|
|
21477
|
+
for (const [index, child] of dynamic.children.entries()) {
|
|
21478
|
+
if (child.flags & 2) offset--;
|
|
21479
|
+
if (child.flags & 4 && child.template != null) continue;
|
|
21480
|
+
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
21481
|
+
if (id === void 0 && !child.hasDynamicChild) continue;
|
|
21482
|
+
const elementIndex = index + offset;
|
|
21483
|
+
const usesParent = !prev || elementIndex - prev[0] !== 1;
|
|
21484
|
+
if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
|
|
21485
|
+
if (prev && prev[1]) {
|
|
21486
|
+
if (usesParent) usages++;
|
|
21487
|
+
prev = [elementIndex, true];
|
|
21488
|
+
continue;
|
|
21489
|
+
}
|
|
21490
|
+
if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
|
|
21491
|
+
if (usesParent) usages++;
|
|
21492
|
+
continue;
|
|
21493
|
+
}
|
|
21494
|
+
}
|
|
21495
|
+
if (usesParent) usages++;
|
|
21496
|
+
prev = [elementIndex, id === void 0];
|
|
21497
|
+
}
|
|
21498
|
+
return usages;
|
|
21499
|
+
}
|
|
21500
|
+
function genNthChild(nthChild, from, elementIndex, logicalIndex) {
|
|
21501
|
+
const index = String(elementIndex);
|
|
21502
|
+
return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
|
|
21503
|
+
}
|
|
21010
21504
|
//#endregion
|
|
21011
21505
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
21012
21506
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -21025,8 +21519,12 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
21025
21519
|
const [frag, push] = buildCodeFragment();
|
|
21026
21520
|
const { dynamic, effect, operation, returns } = block;
|
|
21027
21521
|
const resetBlock = context.enterBlock(block);
|
|
21522
|
+
const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
|
|
21523
|
+
const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
21524
|
+
if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
|
|
21028
21525
|
if (root) {
|
|
21029
21526
|
for (let name of context.ir.component) {
|
|
21527
|
+
if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
|
|
21030
21528
|
const id = toValidAssetId(name, "component");
|
|
21031
21529
|
const maybeSelfReference = name.endsWith("__self");
|
|
21032
21530
|
if (maybeSelfReference) name = name.slice(0, -6);
|
|
@@ -21062,15 +21560,101 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
21062
21560
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
21063
21561
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
21064
21562
|
resetBlock();
|
|
21563
|
+
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
21065
21564
|
return frag;
|
|
21066
21565
|
function genResolveAssets(kind, helper) {
|
|
21067
21566
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${toValidAssetId(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
21068
21567
|
}
|
|
21069
21568
|
}
|
|
21569
|
+
function collectSingleUseAssetComponents(block) {
|
|
21570
|
+
const usageMap = /* @__PURE__ */ new Map();
|
|
21571
|
+
const seenOperations = /* @__PURE__ */ new Set();
|
|
21572
|
+
visitBlock(block, true);
|
|
21573
|
+
const names = /* @__PURE__ */ new Set();
|
|
21574
|
+
for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
|
|
21575
|
+
return names;
|
|
21576
|
+
function visitBlock(block, rootCandidate) {
|
|
21577
|
+
visitDynamic(block.dynamic, rootCandidate);
|
|
21578
|
+
for (const operation of block.operation) visitOperation(operation, rootCandidate);
|
|
21579
|
+
for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
|
|
21580
|
+
}
|
|
21581
|
+
function visitDynamic(dynamic, rootCandidate) {
|
|
21582
|
+
if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
|
|
21583
|
+
for (const child of dynamic.children) visitDynamic(child, rootCandidate);
|
|
21584
|
+
}
|
|
21585
|
+
function visitOperation(operation, rootCandidate) {
|
|
21586
|
+
if (seenOperations.has(operation)) return;
|
|
21587
|
+
seenOperations.add(operation);
|
|
21588
|
+
if (operation.type === 12) {
|
|
21589
|
+
if (operation.asset) {
|
|
21590
|
+
const usage = usageMap.get(operation.tag) || {
|
|
21591
|
+
count: 0,
|
|
21592
|
+
root: false
|
|
21593
|
+
};
|
|
21594
|
+
usage.count++;
|
|
21595
|
+
if (rootCandidate) usage.root = true;
|
|
21596
|
+
usageMap.set(operation.tag, usage);
|
|
21597
|
+
}
|
|
21598
|
+
visitSlots(operation.slots);
|
|
21599
|
+
return;
|
|
21600
|
+
}
|
|
21601
|
+
switch (operation.type) {
|
|
21602
|
+
case 15:
|
|
21603
|
+
visitBlock(operation.positive, false);
|
|
21604
|
+
if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
|
|
21605
|
+
else visitBlock(operation.negative, false);
|
|
21606
|
+
break;
|
|
21607
|
+
case 16:
|
|
21608
|
+
visitBlock(operation.render, false);
|
|
21609
|
+
break;
|
|
21610
|
+
case 17:
|
|
21611
|
+
visitBlock(operation.block, false);
|
|
21612
|
+
break;
|
|
21613
|
+
case 13:
|
|
21614
|
+
if (operation.fallback) visitBlock(operation.fallback, false);
|
|
21615
|
+
break;
|
|
21616
|
+
}
|
|
21617
|
+
}
|
|
21618
|
+
function visitSlots(slots) {
|
|
21619
|
+
for (const slot of slots) switch (slot.slotType) {
|
|
21620
|
+
case 0:
|
|
21621
|
+
for (const name in slot.slots) visitBlock(slot.slots[name], false);
|
|
21622
|
+
break;
|
|
21623
|
+
case 1:
|
|
21624
|
+
case 2:
|
|
21625
|
+
visitBlock(slot.fn, false);
|
|
21626
|
+
break;
|
|
21627
|
+
case 3:
|
|
21628
|
+
visitSlots([slot.positive]);
|
|
21629
|
+
if (slot.negative) visitSlots([slot.negative]);
|
|
21630
|
+
break;
|
|
21631
|
+
}
|
|
21632
|
+
}
|
|
21633
|
+
}
|
|
21070
21634
|
//#endregion
|
|
21071
21635
|
//#region packages/compiler-vapor/src/generate.ts
|
|
21072
21636
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
21637
|
+
const helperNameAliases = {
|
|
21638
|
+
withVaporKeys: "withKeys",
|
|
21639
|
+
withVaporModifiers: "withModifiers"
|
|
21640
|
+
};
|
|
21073
21641
|
var CodegenContext = class {
|
|
21642
|
+
withExpressionReplacements(map, fn) {
|
|
21643
|
+
if (map.size === 0) return fn();
|
|
21644
|
+
this.expressionReplacements.unshift(map);
|
|
21645
|
+
try {
|
|
21646
|
+
return fn();
|
|
21647
|
+
} finally {
|
|
21648
|
+
remove(this.expressionReplacements, map);
|
|
21649
|
+
}
|
|
21650
|
+
}
|
|
21651
|
+
getExpressionReplacement(node) {
|
|
21652
|
+
for (const map of this.expressionReplacements) {
|
|
21653
|
+
const replacement = map.get(node);
|
|
21654
|
+
if (replacement) return replacement;
|
|
21655
|
+
}
|
|
21656
|
+
return node;
|
|
21657
|
+
}
|
|
21074
21658
|
withId(fn, map) {
|
|
21075
21659
|
const { identifiers } = this;
|
|
21076
21660
|
const ids = Object.keys(map);
|
|
@@ -21087,9 +21671,19 @@ var CodegenContext = class {
|
|
|
21087
21671
|
this.block = block;
|
|
21088
21672
|
return () => this.block = parent;
|
|
21089
21673
|
}
|
|
21674
|
+
enterSlotBlock() {
|
|
21675
|
+
const parent = this.inSlotBlock;
|
|
21676
|
+
this.inSlotBlock = true;
|
|
21677
|
+
return () => this.inSlotBlock = parent;
|
|
21678
|
+
}
|
|
21090
21679
|
enterScope() {
|
|
21091
21680
|
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
21092
21681
|
}
|
|
21682
|
+
isHelperNameAvailable(name) {
|
|
21683
|
+
if (this.bindingNames.has(name)) return false;
|
|
21684
|
+
for (const alias of this.helpers.values()) if (alias === name) return false;
|
|
21685
|
+
return true;
|
|
21686
|
+
}
|
|
21093
21687
|
initNextIdMap() {
|
|
21094
21688
|
if (this.bindingNames.size === 0) return;
|
|
21095
21689
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -21124,19 +21718,29 @@ var CodegenContext = class {
|
|
|
21124
21718
|
this.ir = ir;
|
|
21125
21719
|
this.bindingNames = /* @__PURE__ */ new Set();
|
|
21126
21720
|
this.helpers = /* @__PURE__ */ new Map();
|
|
21721
|
+
this.needsTemplateRefSetter = false;
|
|
21722
|
+
this.inSlotBlock = false;
|
|
21127
21723
|
this.helper = (name) => {
|
|
21128
21724
|
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
21129
|
-
const base = `_${name}`;
|
|
21130
|
-
if (this.
|
|
21725
|
+
const base = `_${helperNameAliases[name] || name}`;
|
|
21726
|
+
if (this.isHelperNameAvailable(base)) {
|
|
21131
21727
|
this.helpers.set(name, base);
|
|
21132
21728
|
return base;
|
|
21133
21729
|
}
|
|
21134
|
-
const
|
|
21135
|
-
|
|
21136
|
-
|
|
21730
|
+
const map = this.nextIdMap.get(base);
|
|
21731
|
+
let next = 1;
|
|
21732
|
+
while (true) {
|
|
21733
|
+
const alias = `${base}${getNextId(map, next)}`;
|
|
21734
|
+
if (this.isHelperNameAvailable(alias)) {
|
|
21735
|
+
this.helpers.set(name, alias);
|
|
21736
|
+
return alias;
|
|
21737
|
+
}
|
|
21738
|
+
next++;
|
|
21739
|
+
}
|
|
21137
21740
|
};
|
|
21138
21741
|
this.delegates = /* @__PURE__ */ new Set();
|
|
21139
21742
|
this.identifiers = Object.create(null);
|
|
21743
|
+
this.expressionReplacements = [];
|
|
21140
21744
|
this.seenInlineHandlerNames = Object.create(null);
|
|
21141
21745
|
this.scopeLevel = 0;
|
|
21142
21746
|
this.templateVars = /* @__PURE__ */ new Map();
|
|
@@ -21163,6 +21767,7 @@ var CodegenContext = class {
|
|
|
21163
21767
|
this.block = ir.block;
|
|
21164
21768
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
21165
21769
|
this.initNextIdMap();
|
|
21770
|
+
this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
|
|
21166
21771
|
}
|
|
21167
21772
|
};
|
|
21168
21773
|
function generate(ir, options = {}) {
|
|
@@ -21175,8 +21780,11 @@ function generate(ir, options = {}) {
|
|
|
21175
21780
|
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
21176
21781
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
21177
21782
|
push(INDENT_START);
|
|
21178
|
-
|
|
21179
|
-
|
|
21783
|
+
const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
|
|
21784
|
+
const body = genBlockContent(ir.block, context, true);
|
|
21785
|
+
if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
|
|
21786
|
+
else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
|
|
21787
|
+
push(...body);
|
|
21180
21788
|
push(INDENT_END, NEWLINE);
|
|
21181
21789
|
if (!inline) push("}");
|
|
21182
21790
|
const delegates = genDelegates(context);
|
|
@@ -21211,6 +21819,11 @@ function genAssetImports({ ir }) {
|
|
|
21211
21819
|
}
|
|
21212
21820
|
return imports;
|
|
21213
21821
|
}
|
|
21822
|
+
function getStaticTemplateRefHelperCandidate(block) {
|
|
21823
|
+
if (block.operation.length !== 1) return;
|
|
21824
|
+
const operation = block.operation[0];
|
|
21825
|
+
if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
|
|
21826
|
+
}
|
|
21214
21827
|
//#endregion
|
|
21215
21828
|
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
21216
21829
|
function normalizeBindShorthand(arg, context) {
|
|
@@ -21248,67 +21861,6 @@ const transformVBind = (dir, node, context) => {
|
|
|
21248
21861
|
};
|
|
21249
21862
|
};
|
|
21250
21863
|
//#endregion
|
|
21251
|
-
//#region \0@oxc-project+runtime@0.128.0/helpers/typeof.js
|
|
21252
|
-
function _typeof(o) {
|
|
21253
|
-
"@babel/helpers - typeof";
|
|
21254
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
21255
|
-
return typeof o;
|
|
21256
|
-
} : function(o) {
|
|
21257
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
21258
|
-
}, _typeof(o);
|
|
21259
|
-
}
|
|
21260
|
-
//#endregion
|
|
21261
|
-
//#region \0@oxc-project+runtime@0.128.0/helpers/toPrimitive.js
|
|
21262
|
-
function toPrimitive(t, r) {
|
|
21263
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
21264
|
-
var e = t[Symbol.toPrimitive];
|
|
21265
|
-
if (void 0 !== e) {
|
|
21266
|
-
var i = e.call(t, r || "default");
|
|
21267
|
-
if ("object" != _typeof(i)) return i;
|
|
21268
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
21269
|
-
}
|
|
21270
|
-
return ("string" === r ? String : Number)(t);
|
|
21271
|
-
}
|
|
21272
|
-
//#endregion
|
|
21273
|
-
//#region \0@oxc-project+runtime@0.128.0/helpers/toPropertyKey.js
|
|
21274
|
-
function toPropertyKey(t) {
|
|
21275
|
-
var i = toPrimitive(t, "string");
|
|
21276
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
21277
|
-
}
|
|
21278
|
-
//#endregion
|
|
21279
|
-
//#region \0@oxc-project+runtime@0.128.0/helpers/defineProperty.js
|
|
21280
|
-
function _defineProperty(e, r, t) {
|
|
21281
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
21282
|
-
value: t,
|
|
21283
|
-
enumerable: !0,
|
|
21284
|
-
configurable: !0,
|
|
21285
|
-
writable: !0
|
|
21286
|
-
}) : e[r] = t, e;
|
|
21287
|
-
}
|
|
21288
|
-
//#endregion
|
|
21289
|
-
//#region \0@oxc-project+runtime@0.128.0/helpers/objectSpread2.js
|
|
21290
|
-
function ownKeys(e, r) {
|
|
21291
|
-
var t = Object.keys(e);
|
|
21292
|
-
if (Object.getOwnPropertySymbols) {
|
|
21293
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
21294
|
-
r && (o = o.filter(function(r) {
|
|
21295
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
21296
|
-
})), t.push.apply(t, o);
|
|
21297
|
-
}
|
|
21298
|
-
return t;
|
|
21299
|
-
}
|
|
21300
|
-
function _objectSpread2(e) {
|
|
21301
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
21302
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
21303
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
21304
|
-
_defineProperty(e, r, t[r]);
|
|
21305
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
21306
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
21307
|
-
});
|
|
21308
|
-
}
|
|
21309
|
-
return e;
|
|
21310
|
-
}
|
|
21311
|
-
//#endregion
|
|
21312
21864
|
//#region packages/compiler-vapor/src/transforms/transformElement.ts
|
|
21313
21865
|
const isReservedProp = /* @__PURE__ */ makeMap(",key,ref,ref_for,ref_key,");
|
|
21314
21866
|
const transformElement = (node, context) => {
|
|
@@ -21337,11 +21889,35 @@ function canOmitEndTag(node, context) {
|
|
|
21337
21889
|
const { block, parent } = context;
|
|
21338
21890
|
if (!parent) return false;
|
|
21339
21891
|
if (block !== parent.block) return true;
|
|
21892
|
+
if (context.templateCloseTags && (context.templateCloseTags.has(node.tag) || isAlwaysCloseTag(node.tag) || isFormattingTag(node.tag)) || context.templateCloseBlocks && isBlockTag(node.tag)) return false;
|
|
21340
21893
|
if (isAlwaysCloseTag(node.tag) && !context.isOnRightmostPath) return false;
|
|
21341
21894
|
if (isFormattingTag(node.tag) || parent.node.type === 1 && node.tag === parent.node.tag) return context.isOnRightmostPath;
|
|
21342
|
-
if (isBlockTag(node.tag) && context.hasInlineAncestorNeedingClose) return false;
|
|
21343
21895
|
return context.isLastEffectiveChild;
|
|
21344
21896
|
}
|
|
21897
|
+
function getChildTemplateCloseState(context) {
|
|
21898
|
+
const { node } = context;
|
|
21899
|
+
if (node.type !== 1 || node.tagType !== 0 || shouldUseCreateElement(node, context)) return;
|
|
21900
|
+
const inSameTemplateAsParent = isInSameTemplateAsParent(context);
|
|
21901
|
+
const inheritedTags = inSameTemplateAsParent ? context.templateCloseTags : void 0;
|
|
21902
|
+
const inheritedBlocks = inSameTemplateAsParent && context.templateCloseBlocks;
|
|
21903
|
+
if (context.root === context.effectiveParent || canOmitEndTag(node, context) || isVoidTag(node.tag)) return inheritedTags || inheritedBlocks ? {
|
|
21904
|
+
tags: inheritedTags,
|
|
21905
|
+
blocks: inheritedBlocks
|
|
21906
|
+
} : void 0;
|
|
21907
|
+
const tags = new Set(inheritedTags);
|
|
21908
|
+
tags.add(node.tag);
|
|
21909
|
+
return {
|
|
21910
|
+
tags,
|
|
21911
|
+
blocks: inheritedBlocks || isInlineTag(node.tag)
|
|
21912
|
+
};
|
|
21913
|
+
}
|
|
21914
|
+
function isInSameTemplateAsParent(context) {
|
|
21915
|
+
const { parent, node, block } = context;
|
|
21916
|
+
if (!parent || block !== parent.block) return false;
|
|
21917
|
+
const parentNode = parent.node;
|
|
21918
|
+
if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
|
|
21919
|
+
return !shouldUseCreateElement(parentNode, parent) && isValidHTMLNesting(parentNode.tag, node.tag);
|
|
21920
|
+
}
|
|
21345
21921
|
function isSingleRoot(context) {
|
|
21346
21922
|
if (context.inVFor) return false;
|
|
21347
21923
|
let { parent } = context;
|
|
@@ -21413,6 +21989,7 @@ function resolveSetupReference(name, context) {
|
|
|
21413
21989
|
}
|
|
21414
21990
|
const dynamicKeys = ["indeterminate"];
|
|
21415
21991
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
21992
|
+
const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
|
|
21416
21993
|
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
21417
21994
|
const { tag } = node;
|
|
21418
21995
|
const { scopeId } = context.options;
|
|
@@ -21430,18 +22007,55 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
21430
22007
|
}, getEffectIndex);
|
|
21431
22008
|
} else {
|
|
21432
22009
|
let prevWasQuoted = false;
|
|
22010
|
+
const appendTemplateProp = (key, value = "", generated = false) => {
|
|
22011
|
+
if (!prevWasQuoted) template += ` `;
|
|
22012
|
+
template += key;
|
|
22013
|
+
if (value) {
|
|
22014
|
+
const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, """);
|
|
22015
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
|
|
22016
|
+
} else prevWasQuoted = false;
|
|
22017
|
+
};
|
|
21433
22018
|
for (const prop of propsResult[1]) {
|
|
21434
22019
|
const { key, values } = prop;
|
|
21435
22020
|
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
21436
22021
|
if (!prevWasQuoted) template += ` `;
|
|
21437
22022
|
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
21438
22023
|
prevWasQuoted = true;
|
|
22024
|
+
} else if (key.isStatic && !prop.modifier && isBooleanAttr(key.content)) if (values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
22025
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
22026
|
+
appendTemplateProp(key.content, value);
|
|
22027
|
+
} else {
|
|
22028
|
+
const include = foldBooleanAttrValue(values);
|
|
22029
|
+
if (include != null) {
|
|
22030
|
+
if (include) appendTemplateProp(key.content);
|
|
22031
|
+
} else {
|
|
22032
|
+
dynamicProps.push(key.content);
|
|
22033
|
+
context.registerEffect(values, {
|
|
22034
|
+
type: 3,
|
|
22035
|
+
element: context.reference(),
|
|
22036
|
+
prop,
|
|
22037
|
+
tag
|
|
22038
|
+
}, getEffectIndex);
|
|
22039
|
+
}
|
|
22040
|
+
}
|
|
22041
|
+
else if (key.isStatic && !prop.modifier && hasBoundValue(values)) {
|
|
22042
|
+
let foldedValue;
|
|
22043
|
+
if (key.content === "class") foldedValue = foldClassValues(values);
|
|
22044
|
+
else if (key.content === "style") foldedValue = foldStyleValues(values);
|
|
22045
|
+
if (foldedValue != null) {
|
|
22046
|
+
if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
|
|
22047
|
+
} else {
|
|
22048
|
+
dynamicProps.push(key.content);
|
|
22049
|
+
context.registerEffect(values, {
|
|
22050
|
+
type: 3,
|
|
22051
|
+
element: context.reference(),
|
|
22052
|
+
prop,
|
|
22053
|
+
tag
|
|
22054
|
+
}, getEffectIndex);
|
|
22055
|
+
}
|
|
21439
22056
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
21440
|
-
if (!prevWasQuoted) template += ` `;
|
|
21441
22057
|
const value = values[0].content === "''" ? "" : values[0].content;
|
|
21442
|
-
|
|
21443
|
-
if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
21444
|
-
else prevWasQuoted = false;
|
|
22058
|
+
appendTemplateProp(key.content, value);
|
|
21445
22059
|
} else {
|
|
21446
22060
|
dynamicProps.push(key.content);
|
|
21447
22061
|
context.registerEffect(values, {
|
|
@@ -21463,6 +22077,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
21463
22077
|
} else context.template += template;
|
|
21464
22078
|
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey));
|
|
21465
22079
|
}
|
|
22080
|
+
function escapeGeneratedAttrValue(value) {
|
|
22081
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
22082
|
+
}
|
|
22083
|
+
function foldBooleanAttrValue(values) {
|
|
22084
|
+
if (values.length !== 1) return;
|
|
22085
|
+
const evaluated = evaluateConstantExpression(values[0]);
|
|
22086
|
+
if (!evaluated) return;
|
|
22087
|
+
const value = evaluated.value;
|
|
22088
|
+
if (value === true || value === false || value == null) return includeBooleanAttr(value);
|
|
22089
|
+
}
|
|
22090
|
+
function foldStyleValues(values) {
|
|
22091
|
+
const evaluatedValues = [];
|
|
22092
|
+
for (const value of values) {
|
|
22093
|
+
const evaluated = evaluateConstantExpression(value);
|
|
22094
|
+
if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
|
|
22095
|
+
evaluatedValues.push(evaluated.value);
|
|
22096
|
+
}
|
|
22097
|
+
return stringifyStyle(normalizeStyle(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
|
|
22098
|
+
}
|
|
22099
|
+
function isStaticStyleValue(value) {
|
|
22100
|
+
if (typeof value === "string") return true;
|
|
22101
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
22102
|
+
for (const key in value) {
|
|
22103
|
+
const propValue = value[key];
|
|
22104
|
+
if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
|
|
22105
|
+
}
|
|
22106
|
+
return true;
|
|
22107
|
+
}
|
|
22108
|
+
function isSafeStylePropertyName(key) {
|
|
22109
|
+
return !!key && !/[;:]/.test(key);
|
|
22110
|
+
}
|
|
22111
|
+
function isSafeStylePropertyValue(value) {
|
|
22112
|
+
return typeof value === "number" || typeof value === "string" && !value.includes(";");
|
|
22113
|
+
}
|
|
22114
|
+
function hasBoundValue(values) {
|
|
22115
|
+
return values.some((value) => !value.isStatic && value.content !== "''");
|
|
22116
|
+
}
|
|
22117
|
+
function foldClassValues(values) {
|
|
22118
|
+
let templateValue = "";
|
|
22119
|
+
let changed = false;
|
|
22120
|
+
for (const value of values) {
|
|
22121
|
+
const evaluated = evaluateConstantExpression(value);
|
|
22122
|
+
if (evaluated) {
|
|
22123
|
+
const normalized = normalizeClass(evaluated.value);
|
|
22124
|
+
if (normalized) templateValue = appendClass(templateValue, normalized);
|
|
22125
|
+
else changed = true;
|
|
22126
|
+
continue;
|
|
22127
|
+
}
|
|
22128
|
+
return;
|
|
22129
|
+
}
|
|
22130
|
+
return changed || templateValue ? templateValue : void 0;
|
|
22131
|
+
}
|
|
22132
|
+
function appendClass(base, value) {
|
|
22133
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
22134
|
+
}
|
|
22135
|
+
function getObjectPropertyName(prop) {
|
|
22136
|
+
const key = prop.key;
|
|
22137
|
+
if (key.type === "Identifier") return key.name;
|
|
22138
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
22139
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
22140
|
+
}
|
|
22141
|
+
function evaluateConstantExpression(node) {
|
|
22142
|
+
if (node.isStatic) return { value: node.content };
|
|
22143
|
+
const ast = node.ast;
|
|
22144
|
+
if (ast === null) {
|
|
22145
|
+
if (node.content === "true") return { value: true };
|
|
22146
|
+
else if (node.content === "false") return { value: false };
|
|
22147
|
+
else if (node.content === "null") return { value: null };
|
|
22148
|
+
else if (node.content === "undefined") return { value: void 0 };
|
|
22149
|
+
}
|
|
22150
|
+
if (!ast) return;
|
|
22151
|
+
return evaluateConstantAst(ast);
|
|
22152
|
+
}
|
|
22153
|
+
function evaluateConstantAst(node) {
|
|
22154
|
+
switch (node.type) {
|
|
22155
|
+
case "StringLiteral": return { value: node.value };
|
|
22156
|
+
case "NumericLiteral": return { value: node.value };
|
|
22157
|
+
case "BooleanLiteral": return { value: node.value };
|
|
22158
|
+
case "NullLiteral": return { value: null };
|
|
22159
|
+
case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
|
|
22160
|
+
case "UnaryExpression":
|
|
22161
|
+
if (node.operator === "void") return { value: void 0 };
|
|
22162
|
+
else if (node.operator === "-") {
|
|
22163
|
+
const value = evaluateConstantAst(node.argument);
|
|
22164
|
+
return value && typeof value.value === "number" ? { value: -value.value } : void 0;
|
|
22165
|
+
}
|
|
22166
|
+
return;
|
|
22167
|
+
case "TemplateLiteral": return evaluateTemplateLiteral(node);
|
|
22168
|
+
case "ObjectExpression": return evaluateObjectExpression(node);
|
|
22169
|
+
}
|
|
22170
|
+
}
|
|
22171
|
+
function evaluateTemplateLiteral(node) {
|
|
22172
|
+
if (node.type !== "TemplateLiteral") return;
|
|
22173
|
+
let value = "";
|
|
22174
|
+
for (const [index, quasi] of node.quasis.entries()) {
|
|
22175
|
+
value += quasi.value.cooked || "";
|
|
22176
|
+
const expression = node.expressions[index];
|
|
22177
|
+
if (expression) {
|
|
22178
|
+
const evaluated = evaluateConstantAst(expression);
|
|
22179
|
+
if (!evaluated) return;
|
|
22180
|
+
value += evaluated.value;
|
|
22181
|
+
}
|
|
22182
|
+
}
|
|
22183
|
+
return { value };
|
|
22184
|
+
}
|
|
22185
|
+
function evaluateObjectExpression(node) {
|
|
22186
|
+
const value = {};
|
|
22187
|
+
for (const prop of node.properties) {
|
|
22188
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return;
|
|
22189
|
+
const key = getObjectPropertyName(prop);
|
|
22190
|
+
if (key == null) return;
|
|
22191
|
+
const evaluated = evaluateConstantAst(prop.value);
|
|
22192
|
+
if (!evaluated) return;
|
|
22193
|
+
value[key] = evaluated.value;
|
|
22194
|
+
}
|
|
22195
|
+
return { value };
|
|
22196
|
+
}
|
|
21466
22197
|
function resolveStaticKey(node, context, isComponent) {
|
|
21467
22198
|
const keyProp = findProp(node, "key", false, true);
|
|
21468
22199
|
if (!keyProp) return;
|
|
@@ -21489,27 +22220,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
21489
22220
|
results = [];
|
|
21490
22221
|
}
|
|
21491
22222
|
}
|
|
22223
|
+
function pushStaticObjectLiteralProps(props) {
|
|
22224
|
+
if (dynamicArgs.length) {
|
|
22225
|
+
pushMergeArg();
|
|
22226
|
+
dynamicArgs.push(props);
|
|
22227
|
+
} else results.push(...props.map(toDirectiveResult));
|
|
22228
|
+
}
|
|
21492
22229
|
for (const prop of props) {
|
|
21493
22230
|
if (prop.type === 7 && !prop.arg) {
|
|
21494
22231
|
if (prop.name === "bind") {
|
|
21495
22232
|
if (prop.exp) {
|
|
21496
|
-
|
|
21497
|
-
|
|
21498
|
-
|
|
21499
|
-
|
|
21500
|
-
|
|
21501
|
-
|
|
22233
|
+
const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
|
|
22234
|
+
if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
22235
|
+
else results.push(...objectLiteralProps.map(toDirectiveResult));
|
|
22236
|
+
else {
|
|
22237
|
+
dynamicExpr.push(prop.exp);
|
|
22238
|
+
pushMergeArg();
|
|
22239
|
+
dynamicArgs.push({
|
|
22240
|
+
kind: 0,
|
|
22241
|
+
value: prop.exp
|
|
22242
|
+
});
|
|
22243
|
+
}
|
|
21502
22244
|
} else context.options.onError(createCompilerError(34, prop.loc));
|
|
21503
22245
|
continue;
|
|
21504
22246
|
} else if (prop.name === "on") {
|
|
21505
22247
|
if (prop.exp) if (isComponent) {
|
|
21506
|
-
|
|
21507
|
-
|
|
21508
|
-
|
|
21509
|
-
|
|
21510
|
-
|
|
21511
|
-
|
|
21512
|
-
|
|
22248
|
+
const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
|
|
22249
|
+
if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
22250
|
+
else {
|
|
22251
|
+
dynamicExpr.push(prop.exp);
|
|
22252
|
+
pushMergeArg();
|
|
22253
|
+
dynamicArgs.push({
|
|
22254
|
+
kind: 0,
|
|
22255
|
+
value: prop.exp,
|
|
22256
|
+
handler: true
|
|
22257
|
+
});
|
|
22258
|
+
}
|
|
21513
22259
|
} else context.registerEffect([prop.exp], {
|
|
21514
22260
|
type: 7,
|
|
21515
22261
|
element: context.reference(),
|
|
@@ -21539,6 +22285,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
21539
22285
|
}
|
|
21540
22286
|
return [false, dedupeProperties(results)];
|
|
21541
22287
|
}
|
|
22288
|
+
function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
|
|
22289
|
+
const ast = exp.ast;
|
|
22290
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
22291
|
+
const props = [];
|
|
22292
|
+
const knownKeys = /* @__PURE__ */ new Set();
|
|
22293
|
+
for (const property of ast.properties) {
|
|
22294
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
22295
|
+
let key = getObjectPropertyName(property);
|
|
22296
|
+
if (key == null || key === "__proto__") return;
|
|
22297
|
+
if (isValidKey && !isValidKey(key)) return;
|
|
22298
|
+
if (keyTransform) key = keyTransform(key);
|
|
22299
|
+
if (knownKeys.has(key)) return;
|
|
22300
|
+
knownKeys.add(key);
|
|
22301
|
+
props.push({
|
|
22302
|
+
key: createSimpleExpression(key, true),
|
|
22303
|
+
values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
|
|
22304
|
+
});
|
|
22305
|
+
}
|
|
22306
|
+
return props;
|
|
22307
|
+
}
|
|
22308
|
+
function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
22309
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
|
|
22310
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
22311
|
+
return props;
|
|
22312
|
+
}
|
|
22313
|
+
function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
22314
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
|
|
22315
|
+
if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
22316
|
+
return props;
|
|
22317
|
+
}
|
|
22318
|
+
function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
|
|
22319
|
+
const props = resolveObjectLiteralProps(exp, context, toHandlerKey);
|
|
22320
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
22321
|
+
return props;
|
|
22322
|
+
}
|
|
22323
|
+
function isSafeNativeObjectLiteralBindKey(key) {
|
|
22324
|
+
return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !isOn(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
|
|
22325
|
+
}
|
|
22326
|
+
function isSafeObjectLiteralBindKey(key) {
|
|
22327
|
+
return !isReservedProp(key);
|
|
22328
|
+
}
|
|
22329
|
+
function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
22330
|
+
const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
|
|
22331
|
+
for (const prop of props) {
|
|
22332
|
+
if (prop === currentProp) continue;
|
|
22333
|
+
let key;
|
|
22334
|
+
if (prop.type === 6) key = prop.name;
|
|
22335
|
+
else if (prop.name === "bind") {
|
|
22336
|
+
if (!prop.arg) {
|
|
22337
|
+
const bindKeys = getObjectLiteralKeys(prop.exp);
|
|
22338
|
+
if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
|
|
22339
|
+
continue;
|
|
22340
|
+
}
|
|
22341
|
+
key = getStaticBindKey(prop);
|
|
22342
|
+
} else if (prop.name === "on") key = getStaticHandlerKey(prop);
|
|
22343
|
+
else if (prop.name === "model") {
|
|
22344
|
+
if (hasComponentModelKey(keys, prop)) return true;
|
|
22345
|
+
}
|
|
22346
|
+
if (key && hasComponentKey(keys, key)) return true;
|
|
22347
|
+
}
|
|
22348
|
+
return false;
|
|
22349
|
+
}
|
|
22350
|
+
function hasComponentModelKey(keys, prop) {
|
|
22351
|
+
const { arg } = prop;
|
|
22352
|
+
if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
|
|
22353
|
+
const key = arg ? arg.content : "modelValue";
|
|
22354
|
+
return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${camelize(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, getModifierPropName(key));
|
|
22355
|
+
}
|
|
22356
|
+
function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
22357
|
+
const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
|
|
22358
|
+
for (const prop of props) {
|
|
22359
|
+
if (prop === currentProp) continue;
|
|
22360
|
+
let key;
|
|
22361
|
+
if (prop.type === 6) key = prop.name;
|
|
22362
|
+
else if (prop.name === "bind") {
|
|
22363
|
+
if (!prop.arg) return true;
|
|
22364
|
+
key = getStaticBindKey(prop);
|
|
22365
|
+
if (!key) return true;
|
|
22366
|
+
}
|
|
22367
|
+
if (key && keys.has(key)) return true;
|
|
22368
|
+
}
|
|
22369
|
+
return false;
|
|
22370
|
+
}
|
|
22371
|
+
function getStaticBindKey(prop) {
|
|
22372
|
+
const { arg } = prop;
|
|
22373
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
22374
|
+
let key = arg.content;
|
|
22375
|
+
if (isReservedProp(key)) return;
|
|
22376
|
+
if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = camelize(key);
|
|
22377
|
+
return key;
|
|
22378
|
+
}
|
|
22379
|
+
function getStaticHandlerKey(prop) {
|
|
22380
|
+
const { arg } = prop;
|
|
22381
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
22382
|
+
let key = arg.content;
|
|
22383
|
+
if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
|
|
22384
|
+
const { nonKeyModifiers, eventOptionModifiers } = resolveModifiers(`on${key}`, prop.modifiers, null, prop.loc);
|
|
22385
|
+
if (key.toLowerCase() === "click") {
|
|
22386
|
+
if (nonKeyModifiers.includes("middle")) key = "mouseup";
|
|
22387
|
+
if (nonKeyModifiers.includes("right")) key = "contextmenu";
|
|
22388
|
+
}
|
|
22389
|
+
key = toHandlerKey(camelize(key));
|
|
22390
|
+
const optionPostfix = eventOptionModifiers.map(capitalize).join("");
|
|
22391
|
+
if (optionPostfix) key += optionPostfix;
|
|
22392
|
+
return key;
|
|
22393
|
+
}
|
|
22394
|
+
function getObjectLiteralKeys(exp) {
|
|
22395
|
+
const ast = exp && exp.ast;
|
|
22396
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
22397
|
+
const keys = /* @__PURE__ */ new Set();
|
|
22398
|
+
for (const property of ast.properties) {
|
|
22399
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
22400
|
+
const key = getObjectPropertyName(property);
|
|
22401
|
+
if (key == null) return;
|
|
22402
|
+
keys.add(key);
|
|
22403
|
+
}
|
|
22404
|
+
return keys;
|
|
22405
|
+
}
|
|
22406
|
+
function createComponentConflictKeySet(keys) {
|
|
22407
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
22408
|
+
for (const key of keys) {
|
|
22409
|
+
normalized.add(key);
|
|
22410
|
+
normalized.add(camelize(key));
|
|
22411
|
+
}
|
|
22412
|
+
return normalized;
|
|
22413
|
+
}
|
|
22414
|
+
function hasComponentKey(keys, key) {
|
|
22415
|
+
return keys.has(key) || keys.has(camelize(key));
|
|
22416
|
+
}
|
|
22417
|
+
function hasComponentKeyOverlap(left, right) {
|
|
22418
|
+
for (const key of right) if (hasComponentKey(left, key)) return true;
|
|
22419
|
+
return false;
|
|
22420
|
+
}
|
|
22421
|
+
function createObjectBindSubExpression(source, node, context) {
|
|
22422
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
22423
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
22424
|
+
const content = source.content.slice(start, end);
|
|
22425
|
+
const expression = createSimpleExpression(content, false, {
|
|
22426
|
+
start: advancePositionWithClone(source.loc.start, source.content, start),
|
|
22427
|
+
end: advancePositionWithClone(source.loc.start, source.content, end),
|
|
22428
|
+
source: content
|
|
22429
|
+
});
|
|
22430
|
+
expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
22431
|
+
return expression;
|
|
22432
|
+
}
|
|
21542
22433
|
function transformProp(prop, node, context) {
|
|
21543
22434
|
let { name } = prop;
|
|
21544
22435
|
if (prop.type === 6) {
|
|
@@ -21589,6 +22480,12 @@ function resolveDirectiveResult(prop) {
|
|
|
21589
22480
|
values: [prop.value]
|
|
21590
22481
|
});
|
|
21591
22482
|
}
|
|
22483
|
+
function toDirectiveResult(prop) {
|
|
22484
|
+
return extend({}, prop, {
|
|
22485
|
+
values: void 0,
|
|
22486
|
+
value: prop.values[0]
|
|
22487
|
+
});
|
|
22488
|
+
}
|
|
21592
22489
|
function mergePropValues(existing, incoming) {
|
|
21593
22490
|
const newValues = incoming.values;
|
|
21594
22491
|
existing.values.push(...newValues);
|
|
@@ -21605,8 +22502,12 @@ const transformChildren = (node, context) => {
|
|
|
21605
22502
|
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
21606
22503
|
if (!isFragment && node.type !== 1) return;
|
|
21607
22504
|
const useCreateElement = node.type === 1 && shouldUseCreateElement(node, context);
|
|
22505
|
+
const childTemplateCloseState = !isFragment && !useCreateElement ? getChildTemplateCloseState(context) : void 0;
|
|
21608
22506
|
for (const [i, child] of node.children.entries()) {
|
|
21609
22507
|
const childContext = context.create(child, i);
|
|
22508
|
+
const isInSameTemplate = childTemplateCloseState && child.type === 1 && child.tagType === 0 && isInSameTemplateAsParent(childContext);
|
|
22509
|
+
childContext.templateCloseTags = isInSameTemplate ? childTemplateCloseState.tags : void 0;
|
|
22510
|
+
childContext.templateCloseBlocks = isInSameTemplate ? childTemplateCloseState.blocks : false;
|
|
21610
22511
|
transformNode(childContext);
|
|
21611
22512
|
const childDynamic = childContext.dynamic;
|
|
21612
22513
|
if (isFragment) {
|
|
@@ -22098,6 +22999,7 @@ function processIf(node, dir, context) {
|
|
|
22098
22999
|
}
|
|
22099
23000
|
context.dynamic.flags |= 2;
|
|
22100
23001
|
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
23002
|
+
const allowNoScope = context.block === context.root.block;
|
|
22101
23003
|
if (dir.name === "if") {
|
|
22102
23004
|
const id = context.reference();
|
|
22103
23005
|
context.dynamic.flags |= 4;
|
|
@@ -22108,7 +23010,7 @@ function processIf(node, dir, context) {
|
|
|
22108
23010
|
type: 15,
|
|
22109
23011
|
id
|
|
22110
23012
|
}, context.effectBoundary()), {}, {
|
|
22111
|
-
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
23013
|
+
blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
|
|
22112
23014
|
condition: dir.exp,
|
|
22113
23015
|
positive: branch,
|
|
22114
23016
|
index: context.root.nextIfIndex(),
|
|
@@ -22150,8 +23052,8 @@ function processIf(node, dir, context) {
|
|
|
22150
23052
|
};
|
|
22151
23053
|
return () => {
|
|
22152
23054
|
onExit();
|
|
22153
|
-
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
|
|
22154
|
-
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
|
|
23055
|
+
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
|
|
23056
|
+
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
|
|
22155
23057
|
};
|
|
22156
23058
|
}
|
|
22157
23059
|
}
|
|
@@ -22166,14 +23068,38 @@ function createIfBranch(node, context) {
|
|
|
22166
23068
|
context.reference();
|
|
22167
23069
|
return [branch, exitBlock];
|
|
22168
23070
|
}
|
|
22169
|
-
function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
|
|
23071
|
+
function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
|
|
22170
23072
|
if (forceMultiRoot) return 10;
|
|
22171
|
-
|
|
23073
|
+
const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
|
|
23074
|
+
const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
|
|
23075
|
+
return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
|
|
22172
23076
|
}
|
|
22173
|
-
function
|
|
23077
|
+
function getNegativeIfBranchShape(negative) {
|
|
22174
23078
|
if (!negative) return 0;
|
|
22175
23079
|
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
22176
23080
|
}
|
|
23081
|
+
function canSkipIfBranchScope(block) {
|
|
23082
|
+
if (block.effect.length || block.operation.length) return false;
|
|
23083
|
+
if (!isStaticBranch(block.node)) return false;
|
|
23084
|
+
if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
|
|
23085
|
+
return block.returns.every((id) => {
|
|
23086
|
+
const returned = findReturnedDynamic(block, id);
|
|
23087
|
+
return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
|
|
23088
|
+
});
|
|
23089
|
+
}
|
|
23090
|
+
function findReturnedDynamic(block, id) {
|
|
23091
|
+
return block.dynamic.children.find((child) => child.id === id);
|
|
23092
|
+
}
|
|
23093
|
+
function isStaticBranch(node) {
|
|
23094
|
+
if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
|
|
23095
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
23096
|
+
}
|
|
23097
|
+
function isStaticTemplateNode(node) {
|
|
23098
|
+
if (node.type === 2 || node.type === 3) return true;
|
|
23099
|
+
if (node.type !== 1 || node.tagType !== 0) return false;
|
|
23100
|
+
for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
|
|
23101
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
23102
|
+
}
|
|
22177
23103
|
function shouldForceMultiRoot(context) {
|
|
22178
23104
|
const parent = context.parent && context.parent.node;
|
|
22179
23105
|
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
@@ -22258,6 +23184,9 @@ const transformSlotOutlet = (node, context) => {
|
|
|
22258
23184
|
}
|
|
22259
23185
|
return () => {
|
|
22260
23186
|
exitBlock && exitBlock();
|
|
23187
|
+
let flags = 0;
|
|
23188
|
+
if (context.options.scopeId && !context.options.slotted) flags |= 1;
|
|
23189
|
+
if (context.inVOnce) flags |= 2;
|
|
22261
23190
|
context.dynamic.operation = _objectSpread2(_objectSpread2({
|
|
22262
23191
|
type: 13,
|
|
22263
23192
|
id
|
|
@@ -22265,8 +23194,7 @@ const transformSlotOutlet = (node, context) => {
|
|
|
22265
23194
|
name: slotName,
|
|
22266
23195
|
props: irProps,
|
|
22267
23196
|
fallback,
|
|
22268
|
-
|
|
22269
|
-
once: context.inVOnce
|
|
23197
|
+
flags
|
|
22270
23198
|
});
|
|
22271
23199
|
};
|
|
22272
23200
|
};
|