@dcloudio/uni-cli-shared 3.0.0-5010520260709002 → 3.0.0-5020320260806002

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.
Files changed (56) hide show
  1. package/dist/dom2/vue.d.ts +0 -1
  2. package/dist/dom2/vue.js +1 -14
  3. package/dist/hbx/alias.js +16 -18
  4. package/dist/json/app/pages/definePage.js +3 -1
  5. package/dist/json/mp/index.d.ts +2 -0
  6. package/dist/json/mp/index.js +23 -1
  7. package/dist/json/mp/jsonFile.d.ts +3 -2
  8. package/dist/json/mp/jsonFile.js +83 -13
  9. package/dist/json/mp/pages.d.ts +1 -0
  10. package/dist/json/mp/pages.js +6 -2
  11. package/dist/json/mp/subpackage.d.ts +26 -0
  12. package/dist/json/mp/subpackage.js +236 -0
  13. package/dist/logs/console.js +4 -1
  14. package/dist/messages/en.d.ts +2 -0
  15. package/dist/messages/en.js +2 -0
  16. package/dist/messages/index.d.ts +4 -0
  17. package/dist/messages/zh_CN.d.ts +2 -0
  18. package/dist/messages/zh_CN.js +2 -0
  19. package/dist/mp/usingComponents.d.ts +7 -5
  20. package/dist/mp/usingComponents.js +63 -34
  21. package/dist/resolve.d.ts +1 -0
  22. package/dist/resolve.js +9 -2
  23. package/dist/uts.d.ts +0 -1
  24. package/dist/uts.js +1 -31
  25. package/dist/vite/plugins/cssScoped.js +11 -2
  26. package/dist/vite/plugins/easycom.js +3 -1
  27. package/dist/vite/plugins/inject.js +7 -2
  28. package/dist/vite/plugins/jsonJs.js +41 -3
  29. package/dist/vite/plugins/sfc.js +4 -1
  30. package/dist/vite/plugins/vitejs/plugins/asset.js +14 -1
  31. package/dist/vite/plugins/vitejs/plugins/css.js +35 -1
  32. package/dist/vue/transforms/index.js +1 -1
  33. package/dist/x.d.ts +1 -0
  34. package/dist/x.js +5 -1
  35. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +11 -9
  36. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +11 -9
  37. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +13 -1
  38. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +8 -7
  39. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +1 -1
  40. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +1 -1
  41. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +8 -7
  42. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
  43. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +1 -1
  44. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +8 -7
  45. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
  46. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +4772 -1513
  47. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +3209 -1754
  48. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +1471 -395
  49. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +143 -119
  50. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +1576 -470
  51. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  52. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +77 -2
  53. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +77 -2
  54. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +89 -2
  55. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +74 -3
  56. package/package.json +5 -5
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-vapor v3.6.0-beta.12
2
+ * @vue/compiler-vapor v3.6.0-beta.17
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);
@@ -53,6 +54,11 @@ const camelizeReplacer = (_, c) => c ? c.toUpperCase() : "";
53
54
  * @private
54
55
  */
55
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());
56
62
  /**
57
63
  * @private
58
64
  */
@@ -84,6 +90,43 @@ function canSetValueDirectly(tagName) {
84
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");
85
91
  //#endregion
86
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
+ }
87
130
  function normalizeClass(value) {
88
131
  let res = "";
89
132
  if (isString(value)) res = value;
@@ -146,6 +189,17 @@ const isInlineTag = /* @__PURE__ */ makeMap(INLINE_TAGS);
146
189
  * Do NOT use in runtime code paths unless behind `__DEV__` flag.
147
190
  */
148
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
+ }
149
203
  function shouldSetAsAttr(tagName, key) {
150
204
  if (key === "spellcheck" || key === "draggable" || key === "translate" || key === "autocorrect") return true;
151
205
  if (key === "form") return true;
@@ -15932,20 +15986,6 @@ function toValidAssetId(name, type) {
15932
15986
  return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
15933
15987
  })}`;
15934
15988
  }
15935
- function filterNonCommentChildren(node) {
15936
- return node.children.filter((n) => !isCommentOrWhitespace(n));
15937
- }
15938
- function hasSingleChild(node) {
15939
- return filterNonCommentChildren(node).length === 1;
15940
- }
15941
- function isSingleIfBlock(parent) {
15942
- let hasEncounteredIf = false;
15943
- for (const c of filterNonCommentChildren(parent)) if (c.type === 9 || c.type === 1 && findDir$1(c, "if")) {
15944
- if (hasEncounteredIf) return false;
15945
- hasEncounteredIf = true;
15946
- } else if (!hasEncounteredIf || !(c.type === 1 && findDir$1(c, /^else(-if)?$/, true))) return false;
15947
- return true;
15948
- }
15949
15989
  const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
15950
15990
  function isAllWhitespace(str) {
15951
15991
  for (let i = 0; i < str.length; i++) if (!isWhitespace(str.charCodeAt(i))) return false;
@@ -16194,7 +16234,7 @@ const tokenizer = new Tokenizer(stack, {
16194
16234
  }
16195
16235
  },
16196
16236
  oncdata(start, end) {
16197
- if (stack[0].ns !== 0) onText(getSlice(start, end), start, end);
16237
+ if ((stack[0] ? stack[0].ns : currentOptions.ns) !== 0) onText(getSlice(start, end), start, end);
16198
16238
  else emitError(1, start - 9);
16199
16239
  },
16200
16240
  onprocessinginstruction(start) {
@@ -19074,6 +19114,12 @@ function resolveExpression(exp, isComponent) {
19074
19114
  }
19075
19115
  return exp;
19076
19116
  }
19117
+ function parseStaticAttrBooleanExpression(exp) {
19118
+ try {
19119
+ return includeBooleanAttr(exp.isStatic ? exp.content : new Function(`return ${exp.content}`)());
19120
+ } catch (e) {}
19121
+ return null;
19122
+ }
19077
19123
  function getLiteralExpressionValue(exp, excludeNumber) {
19078
19124
  if (exp.ast) {
19079
19125
  if (exp.ast.type === "StringLiteral") return exp.ast.value;
@@ -19093,6 +19139,13 @@ function getLiteralExpressionValue(exp, excludeNumber) {
19093
19139
  }
19094
19140
  return exp.isStatic ? exp.content : null;
19095
19141
  }
19142
+ function isInTransition(context) {
19143
+ const parentNode = context.parent && context.parent.node;
19144
+ return !!(parentNode && isTransitionNode(parentNode));
19145
+ }
19146
+ function isTransitionNode(node) {
19147
+ return node.type === 1 && isTransitionTag(node.tag);
19148
+ }
19096
19149
  function isTransitionTag(tag) {
19097
19150
  tag = tag.toLowerCase();
19098
19151
  return tag === "transition" || tag === "vaportransition";
@@ -19123,6 +19176,7 @@ function getBlockShape(block) {
19123
19176
  //#endregion
19124
19177
  //#region packages/compiler-vapor/src/transform.ts
19125
19178
  const generatedVarRE = /^[nxr](\d+)$/;
19179
+ const childContextInfoCache = /* @__PURE__ */ new WeakMap();
19126
19180
  var TransformContext = class TransformContext {
19127
19181
  constructor(ir, node, options = {}) {
19128
19182
  this.ir = ir;
@@ -19148,6 +19202,7 @@ var TransformContext = class TransformContext {
19148
19202
  this.operationIndex = this.block.operation.length;
19149
19203
  this.isLastEffectiveChild = true;
19150
19204
  this.isOnRightmostPath = true;
19205
+ this.isSingleRoot = false;
19151
19206
  this.templateCloseTags = void 0;
19152
19207
  this.templateCloseBlocks = false;
19153
19208
  this.globalId = 0;
@@ -19281,8 +19336,10 @@ var TransformContext = class TransformContext {
19281
19336
  create(node, index) {
19282
19337
  let effectiveParent = this;
19283
19338
  while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
19284
- const isLastEffectiveChild = this.isEffectivelyLastChild(index);
19339
+ const childInfo = this.getChildContextInfo();
19340
+ const isLastEffectiveChild = childInfo.isLastEffectiveChild[index];
19285
19341
  const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
19342
+ const isSingleRoot = this.isSingleRootChild(childInfo);
19286
19343
  return Object.assign(Object.create(TransformContext.prototype), this, {
19287
19344
  node,
19288
19345
  parent: this,
@@ -19297,6 +19354,7 @@ var TransformContext = class TransformContext {
19297
19354
  effectiveParent,
19298
19355
  isLastEffectiveChild,
19299
19356
  isOnRightmostPath,
19357
+ isSingleRoot,
19300
19358
  templateCloseTags: this.templateCloseTags,
19301
19359
  templateCloseBlocks: this.templateCloseBlocks
19302
19360
  });
@@ -19311,12 +19369,59 @@ var TransformContext = class TransformContext {
19311
19369
  if (operation && isBlockOperation(operation) && operation.operationIndex !== void 0 && operation.operationIndex >= index) operation.operationIndex += offset;
19312
19370
  for (const child of dynamic.children) this.shiftOperationBoundaries(index, offset, child);
19313
19371
  }
19314
- isEffectivelyLastChild(index) {
19315
- const children = this.node.children;
19316
- if (!children) return true;
19317
- return children.every((c, i) => i <= index || c.type === 1 && c.tagType === 1);
19372
+ getChildContextInfo() {
19373
+ const node = this.node;
19374
+ if (node.type !== 0 && node.type !== 1) return {
19375
+ node,
19376
+ hasSingleRootChild: true,
19377
+ isLastEffectiveChild: []
19378
+ };
19379
+ const cached = childContextInfoCache.get(this);
19380
+ if (cached && cached.node === node) return cached;
19381
+ const { children } = node;
19382
+ const isLastEffectiveChild = new Array(children.length);
19383
+ let hasFollowingEffectiveChild = false;
19384
+ for (let i = children.length - 1; i >= 0; i--) {
19385
+ isLastEffectiveChild[i] = !hasFollowingEffectiveChild;
19386
+ if (!isComponentChild(children[i])) hasFollowingEffectiveChild = true;
19387
+ }
19388
+ const childInfo = {
19389
+ node,
19390
+ hasSingleRootChild: hasSingleRootChild(children),
19391
+ isLastEffectiveChild
19392
+ };
19393
+ childContextInfoCache.set(this, childInfo);
19394
+ return childInfo;
19395
+ }
19396
+ isSingleRootChild(childInfo) {
19397
+ if (this.inVFor || !childInfo.hasSingleRootChild) return false;
19398
+ if (this.node.type === 0) return true;
19399
+ return this.node.type === 1 && this.node.tagType === 3 && !!this.parent && this.isSingleRoot;
19318
19400
  }
19319
19401
  };
19402
+ function hasSingleRootChild(children) {
19403
+ let nonCommentChildren = 0;
19404
+ let hasEncounteredIf = false;
19405
+ let isSingleIfBlock = true;
19406
+ for (const child of children) {
19407
+ if (isCommentOrWhitespace(child)) continue;
19408
+ nonCommentChildren++;
19409
+ if (isIfChild(child)) {
19410
+ if (hasEncounteredIf) isSingleIfBlock = false;
19411
+ hasEncounteredIf = true;
19412
+ } else if (!hasEncounteredIf || !isElseChild(child)) isSingleIfBlock = false;
19413
+ }
19414
+ return nonCommentChildren === 1 || isSingleIfBlock;
19415
+ }
19416
+ function isComponentChild(child) {
19417
+ return child.type === 1 && child.tagType === 1;
19418
+ }
19419
+ function isIfChild(child) {
19420
+ return child.type === 9 || child.type === 1 && !!findDir$1(child, "if");
19421
+ }
19422
+ function isElseChild(child) {
19423
+ return child.type === 1 && !!findDir$1(child, /^else(-if)?$/, true);
19424
+ }
19320
19425
  const defaultOptions = {
19321
19426
  filename: "",
19322
19427
  prefixIdentifiers: true,
@@ -19340,6 +19445,7 @@ const defaultOptions = {
19340
19445
  bindingMetadata: EMPTY_OBJ,
19341
19446
  inline: false,
19342
19447
  isTS: false,
19448
+ eventDelegation: true,
19343
19449
  onError: defaultOnError,
19344
19450
  onWarn: defaultOnWarn
19345
19451
  };
@@ -19577,9 +19683,73 @@ function genPrependNode(oper, { helper }) {
19577
19683
  return [NEWLINE, ...genCall(helper("prepend"), `n${oper.parent}`, ...oper.elements.map((el) => `n${el}`))];
19578
19684
  }
19579
19685
  //#endregion
19686
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
19687
+ function _typeof(o) {
19688
+ "@babel/helpers - typeof";
19689
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
19690
+ return typeof o;
19691
+ } : function(o) {
19692
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
19693
+ }, _typeof(o);
19694
+ }
19695
+ //#endregion
19696
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
19697
+ function toPrimitive(t, r) {
19698
+ if ("object" != _typeof(t) || !t) return t;
19699
+ var e = t[Symbol.toPrimitive];
19700
+ if (void 0 !== e) {
19701
+ var i = e.call(t, r || "default");
19702
+ if ("object" != _typeof(i)) return i;
19703
+ throw new TypeError("@@toPrimitive must return a primitive value.");
19704
+ }
19705
+ return ("string" === r ? String : Number)(t);
19706
+ }
19707
+ //#endregion
19708
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
19709
+ function toPropertyKey(t) {
19710
+ var i = toPrimitive(t, "string");
19711
+ return "symbol" == _typeof(i) ? i : i + "";
19712
+ }
19713
+ //#endregion
19714
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
19715
+ function _defineProperty(e, r, t) {
19716
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
19717
+ value: t,
19718
+ enumerable: !0,
19719
+ configurable: !0,
19720
+ writable: !0
19721
+ }) : e[r] = t, e;
19722
+ }
19723
+ //#endregion
19724
+ //#region \0@oxc-project+runtime@0.129.0/helpers/objectSpread2.js
19725
+ function ownKeys(e, r) {
19726
+ var t = Object.keys(e);
19727
+ if (Object.getOwnPropertySymbols) {
19728
+ var o = Object.getOwnPropertySymbols(e);
19729
+ r && (o = o.filter(function(r) {
19730
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
19731
+ })), t.push.apply(t, o);
19732
+ }
19733
+ return t;
19734
+ }
19735
+ function _objectSpread2(e) {
19736
+ for (var r = 1; r < arguments.length; r++) {
19737
+ var t = null != arguments[r] ? arguments[r] : {};
19738
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
19739
+ _defineProperty(e, r, t[r]);
19740
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
19741
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
19742
+ });
19743
+ }
19744
+ return e;
19745
+ }
19746
+ //#endregion
19580
19747
  //#region packages/compiler-vapor/src/generators/expression.ts
19581
19748
  function genExpression(node, context, assignment) {
19749
+ node = context.getExpressionReplacement(node);
19582
19750
  const { content, ast, isStatic, loc } = node;
19751
+ const { options } = context;
19752
+ const { inline } = options;
19583
19753
  if (isStatic) return [[
19584
19754
  JSON.stringify(content),
19585
19755
  -2,
@@ -19601,23 +19771,31 @@ function genExpression(node, context, assignment) {
19601
19771
  let hasMemberExpression = false;
19602
19772
  if (ids.length) {
19603
19773
  const [frag, push] = buildCodeFragment();
19604
- ids.sort((a, b) => a.start - b.start).forEach((id, i) => {
19605
- const start = id.start - 1;
19606
- const end = id.end - 1;
19607
- const last = ids[i - 1];
19608
- const leadingText = content.slice(last ? last.end - 1 : 0, start);
19609
- if (leadingText.length) push([leadingText, -3]);
19610
- const source = content.slice(start, end);
19774
+ let lastEnd = 0;
19775
+ ids.sort((a, b) => a.start - b.start).forEach((id) => {
19776
+ const idStart = id.start - 1;
19777
+ const idEnd = id.end - 1;
19778
+ const source = content.slice(idStart, idEnd);
19611
19779
  const parentStack = parentStackMap.get(id);
19612
19780
  const parent = parentStack[parentStack.length - 1];
19781
+ let start = idStart;
19782
+ let end = idEnd;
19783
+ if (inline && options.bindingMetadata && options.bindingMetadata[source] === "setup-let" && parent && parent.type === "UpdateExpression" && parent.argument === id) {
19784
+ start = parent.start - 1;
19785
+ end = parent.end - 1;
19786
+ }
19787
+ if (start < lastEnd) return;
19788
+ const leadingText = content.slice(lastEnd, start);
19789
+ if (leadingText.length) push([leadingText, -3]);
19613
19790
  hasMemberExpression || (hasMemberExpression = parent && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression"));
19614
19791
  push(...genIdentifier(source, context, {
19615
19792
  start: advancePositionWithClone(node.loc.start, source, start),
19616
19793
  end: advancePositionWithClone(node.loc.start, source, end),
19617
19794
  source
19618
- }, hasMemberExpression ? void 0 : assignment, id, parent, parentStack));
19619
- if (i === ids.length - 1 && end < content.length) push([content.slice(end), -3]);
19795
+ }, hasMemberExpression ? void 0 : assignment, id, parent, parentStack, node));
19796
+ lastEnd = end;
19620
19797
  });
19798
+ if (lastEnd < content.length) push([content.slice(lastEnd), -3]);
19621
19799
  if (assignment && hasMemberExpression) push(` = ${assignment}`);
19622
19800
  return frag;
19623
19801
  } else return [[
@@ -19626,7 +19804,7 @@ function genExpression(node, context, assignment) {
19626
19804
  loc
19627
19805
  ]];
19628
19806
  }
19629
- function genIdentifier(raw, context, loc, assignment, id, parent, parentStack) {
19807
+ function genIdentifier(raw, context, loc, assignment, id, parent, parentStack, sourceNode) {
19630
19808
  const { options, helper, identifiers } = context;
19631
19809
  const { inline, bindingMetadata } = options;
19632
19810
  let name = raw;
@@ -19646,19 +19824,49 @@ function genIdentifier(raw, context, loc, assignment, id, parent, parentStack) {
19646
19824
  else return genExpression(replacement, context, assignment);
19647
19825
  }
19648
19826
  let prefix;
19649
- if (isStaticProperty(parent) && parent.shorthand) prefix = `${raw}: `;
19650
19827
  const type = bindingMetadata && bindingMetadata[raw];
19828
+ const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack || []);
19829
+ const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
19830
+ const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
19831
+ if (isStaticProperty(parent) && parent.shorthand && !(inline && type === "setup-let" && isDestructureAssignment)) prefix = `${raw}: `;
19651
19832
  if (inline) switch (type) {
19652
19833
  case "setup-let":
19653
- name = raw = assignment ? `_isRef(${raw}) ? (${raw}.value = ${assignment}) : (${raw} = ${assignment})` : unref();
19834
+ if (isAssignmentLVal) {
19835
+ const { right, operator } = parent;
19836
+ const source = sourceNode;
19837
+ const sourceContent = source.content;
19838
+ const rightStart = right.start - 1;
19839
+ const rightEnd = right.end - 1;
19840
+ const rightContent = sourceContent.slice(rightStart, rightEnd);
19841
+ const rightExp = createSimpleExpression(rightContent, false, {
19842
+ start: advancePositionWithClone(source.loc.start, sourceContent, rightStart),
19843
+ end: advancePositionWithClone(source.loc.start, sourceContent, rightEnd),
19844
+ source: rightContent
19845
+ });
19846
+ rightExp.ast = parseExp(context, rightContent);
19847
+ return [
19848
+ prefix,
19849
+ `${helper("isRef")}(${raw}) ? ${raw}.value ${operator} `,
19850
+ ...genExpression(rightExp, context),
19851
+ ` : `,
19852
+ [
19853
+ raw,
19854
+ -2,
19855
+ loc,
19856
+ name
19857
+ ]
19858
+ ];
19859
+ } else if (isUpdateArg) {
19860
+ const { prefix: isPrefix, operator } = parent;
19861
+ const updatePrefix = isPrefix ? operator : ``;
19862
+ const updatePostfix = isPrefix ? `` : operator;
19863
+ raw = `${helper("isRef")}(${raw}) ? ${updatePrefix}${raw}.value${updatePostfix} : ${updatePrefix}${raw}${updatePostfix}`;
19864
+ } else if (!isDestructureAssignment) name = raw = assignment ? `${helper("isRef")}(${raw}) ? (${raw}.value = ${assignment}) : (${raw} = ${assignment})` : unref();
19654
19865
  break;
19655
19866
  case "setup-ref":
19656
19867
  name = raw = withAssignment(`${raw}.value`);
19657
19868
  break;
19658
19869
  case "setup-maybe-ref":
19659
- const isDestructureAssignment = parent && isInDestructureAssignment(parent, parentStack || []);
19660
- const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
19661
- const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
19662
19870
  raw = isAssignmentLVal || isUpdateArg || isDestructureAssignment ? name = `${raw}.value` : assignment ? `${helper("isRef")}(${raw}) ? (${raw}.value = ${assignment}) : null` : unref();
19663
19871
  break;
19664
19872
  case "props":
@@ -19693,28 +19901,32 @@ function canPrefix(name) {
19693
19901
  return true;
19694
19902
  }
19695
19903
  function processExpressions(context, expressions, shouldDeclare) {
19696
- const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
19904
+ const expressionReplacements = /* @__PURE__ */ new Map();
19905
+ const { seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
19697
19906
  const reservedNames = new Set(seenIdentifier);
19698
- const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
19699
- const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
19700
- return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
19907
+ const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable, reservedNames, expressionReplacements);
19908
+ const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expressionRecords, reservedNames, expressionReplacements);
19909
+ return _objectSpread2(_objectSpread2({}, genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare)), {}, { expressionReplacements });
19701
19910
  }
19702
19911
  function analyzeExpressions(expressions) {
19703
19912
  const seenVariable = Object.create(null);
19704
19913
  const variableToExpMap = /* @__PURE__ */ new Map();
19705
- const expToVariableMap = /* @__PURE__ */ new Map();
19914
+ const expressionRecords = /* @__PURE__ */ new Map();
19706
19915
  const seenIdentifier = /* @__PURE__ */ new Set();
19707
19916
  const updatedVariable = /* @__PURE__ */ new Set();
19917
+ const getRecord = (exp) => {
19918
+ let record = expressionRecords.get(exp);
19919
+ if (!record) expressionRecords.set(exp, record = { variables: [] });
19920
+ return record;
19921
+ };
19708
19922
  const registerVariable = (name, exp, isIdentifier, loc, parentStack = []) => {
19709
19923
  if (isIdentifier) seenIdentifier.add(name);
19710
19924
  seenVariable[name] = (seenVariable[name] || 0) + 1;
19711
19925
  variableToExpMap.set(name, (variableToExpMap.get(name) || /* @__PURE__ */ new Set()).add(exp));
19712
- const variables = expToVariableMap.get(exp) || [];
19713
- variables.push({
19926
+ getRecord(exp).variables.push({
19714
19927
  name,
19715
19928
  loc
19716
19929
  });
19717
- expToVariableMap.set(exp, variables);
19718
19930
  if (parentStack.some((p) => p.type === "UpdateExpression" || p.type === "AssignmentExpression")) updatedVariable.add(name);
19719
19931
  };
19720
19932
  for (const exp of expressions) {
@@ -19751,13 +19963,20 @@ function analyzeExpressions(expressions) {
19751
19963
  seenVariable,
19752
19964
  seenIdentifier,
19753
19965
  variableToExpMap,
19754
- expToVariableMap,
19966
+ expressionRecords,
19755
19967
  updatedVariable
19756
19968
  };
19757
19969
  }
19758
- function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames) {
19970
+ function getProcessedExpression(exp, expressionReplacements) {
19971
+ return expressionReplacements.get(exp) || exp;
19972
+ }
19973
+ function setExpressionReplacement(expressionReplacements, exp, content, ast) {
19974
+ expressionReplacements.set(exp, extend({ ast }, createSimpleExpression(content, exp.isStatic, exp.loc, exp.constType)));
19975
+ }
19976
+ function processRepeatedVariables(context, seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
19759
19977
  const declarations = [];
19760
- const expToReplacementMap = /* @__PURE__ */ new Map();
19978
+ const declaredNames = /* @__PURE__ */ new Set();
19979
+ const replacementPlan = /* @__PURE__ */ new Map();
19761
19980
  for (const [name, exps] of variableToExpMap) {
19762
19981
  if (updatedVariable.has(name)) continue;
19763
19982
  if (isGloballyAllowed(name)) continue;
@@ -19766,95 +19985,201 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
19766
19985
  const varName = isIdentifier ? name : getUniqueDeclarationName(genVarName(name), reservedNames);
19767
19986
  exps.forEach((node) => {
19768
19987
  if (node.ast && varName !== name) {
19769
- const replacements = expToReplacementMap.get(node) || [];
19770
- replacements.push({
19771
- name: varName,
19772
- locs: expToVariableMap.get(node).reduce((locs, v) => {
19773
- if (v.name === name && v.loc) locs.push(v.loc);
19774
- return locs;
19775
- }, [])
19988
+ for (const variable of getExpressionVariables(expressionRecords, node)) if (variable.name === name && variable.loc) queueContentReplacement(replacementPlan, node, {
19989
+ start: variable.loc.start - 1,
19990
+ end: variable.loc.end - 1,
19991
+ content: varName
19776
19992
  });
19777
- expToReplacementMap.set(node, replacements);
19778
19993
  }
19779
19994
  });
19780
- if (!declarations.some((d) => d.name === varName) && (!isIdentifier || shouldDeclareVariable(name, expToVariableMap, exps))) declarations.push({
19781
- name: varName,
19782
- isIdentifier,
19783
- value: extend({ ast: isIdentifier ? null : parseExp(context, name) }, createSimpleExpression(name)),
19784
- rawName: name,
19785
- exps,
19786
- seenCount: seenVariable[name]
19787
- });
19995
+ if (!declaredNames.has(varName) && (!isIdentifier || shouldDeclareVariable(name, expressionRecords, exps))) {
19996
+ declaredNames.add(varName);
19997
+ declarations.push({
19998
+ name: varName,
19999
+ isIdentifier,
20000
+ value: extend({ ast: isIdentifier ? null : parseExp(context, name) }, createSimpleExpression(name)),
20001
+ rawName: name,
20002
+ exps,
20003
+ seenCount: seenVariable[name]
20004
+ });
20005
+ }
19788
20006
  }
19789
20007
  }
19790
- for (const [exp, replacements] of expToReplacementMap) {
19791
- replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
19792
- start,
19793
- end,
19794
- name
19795
- }))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
19796
- exp.content = exp.content.slice(0, start - 1) + name + exp.content.slice(end - 1);
19797
- });
19798
- exp.ast = parseExp(context, exp.content);
19799
- }
20008
+ applyReplacementPlan(context, expressionReplacements, replacementPlan);
19800
20009
  return declarations;
19801
20010
  }
19802
- function shouldDeclareVariable(name, expToVariableMap, exps) {
19803
- const vars = Array.from(exps, (exp) => expToVariableMap.get(exp).map((v) => v.name));
19804
- if (vars.every((v) => v.length === 1)) return true;
19805
- if (vars.some((v) => v.filter((e) => e === name).length > 1)) return true;
19806
- const first = vars[0];
19807
- if (vars.some((v) => v.length !== first.length)) {
19808
- if (vars.some((v) => v.length > first.length && v.every((e) => first.includes(e))) || vars.some((v) => first.length > v.length && first.every((e) => v.includes(e)))) return false;
20011
+ function shouldDeclareVariable(name, expressionRecords, exps) {
20012
+ const variableUsages = [];
20013
+ let allSingleVariable = true;
20014
+ let hasRepeatedName = false;
20015
+ let hasDifferentLength = false;
20016
+ outer: for (const exp of exps) {
20017
+ const variables = getExpressionVariables(expressionRecords, exp);
20018
+ if (allSingleVariable && variables.length !== 1) allSingleVariable = false;
20019
+ if (!hasDifferentLength && variableUsages.length > 0 && variables.length !== variableUsages[0].length) hasDifferentLength = true;
20020
+ let nameCount = 0;
20021
+ for (const variable of variables) if (variable.name === name && ++nameCount > 1) {
20022
+ hasRepeatedName = true;
20023
+ break outer;
20024
+ }
20025
+ variableUsages.push(variables);
20026
+ }
20027
+ if (allSingleVariable) return true;
20028
+ if (hasRepeatedName) return true;
20029
+ const first = variableUsages[0];
20030
+ if (hasDifferentLength) {
20031
+ for (const variables of variableUsages) {
20032
+ if (variables.length === first.length) continue;
20033
+ const longer = variables.length > first.length ? variables : first;
20034
+ const shorter = variables.length > first.length ? first : variables;
20035
+ const shorterNames = /* @__PURE__ */ new Set();
20036
+ for (const variable of shorter) shorterNames.add(variable.name);
20037
+ let isSubset = true;
20038
+ for (const variable of longer) if (!shorterNames.has(variable.name)) {
20039
+ isSubset = false;
20040
+ break;
20041
+ }
20042
+ if (isSubset) return false;
20043
+ }
19809
20044
  return true;
19810
20045
  }
19811
- if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
19812
- return true;
20046
+ for (const variables of variableUsages) for (let i = 0; i < variables.length; i++) if (variables[i].name !== first[i].name) return true;
20047
+ return false;
19813
20048
  }
19814
- function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
20049
+ function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expressionRecords, reservedNames, expressionReplacements) {
19815
20050
  const declarations = [];
19816
- const seenExp = expressions.reduce((acc, exp) => {
19817
- const vars = expToVariableMap.get(exp);
19818
- if (!vars) return acc;
19819
- const variables = vars.map((v) => v.name);
19820
- if (exp.ast && exp.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v))) && !variables.some((v) => isGloballyAllowed(v))) acc[exp.content] = (acc[exp.content] || 0) + 1;
19821
- return acc;
19822
- }, Object.create(null));
19823
- Object.entries(seenExp).forEach(([content, count]) => {
19824
- if (count > 1) {
19825
- const delVars = {};
19826
- for (let i = varDeclarations.length - 1; i >= 0; i--) {
19827
- const item = varDeclarations[i];
19828
- if (!item.exps || !item.seenCount) continue;
19829
- if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
19830
- delVars[item.name] = item.rawName;
19831
- reservedNames.delete(item.name);
19832
- varDeclarations.splice(i, 1);
19833
- }
19834
- }
19835
- const value = extend({}, expressions.find((exp) => exp.content === content));
19836
- Object.keys(delVars).forEach((name) => {
19837
- value.content = value.content.replace(name, delVars[name]);
19838
- if (value.ast) value.ast = parseExp(context, value.content);
19839
- });
19840
- const varName = getUniqueDeclarationName(genVarName(content), reservedNames);
19841
- declarations.push({
19842
- name: varName,
19843
- value
20051
+ const seenExp = /* @__PURE__ */ new Map();
20052
+ for (const exp of expressions) {
20053
+ var _expressionRecords$ge;
20054
+ const vars = (_expressionRecords$ge = expressionRecords.get(exp)) === null || _expressionRecords$ge === void 0 ? void 0 : _expressionRecords$ge.variables;
20055
+ if (!vars) continue;
20056
+ const processed = getProcessedExpression(exp, expressionReplacements);
20057
+ if (canCacheExpression(processed, vars, updatedVariable)) {
20058
+ const seen = seenExp.get(processed.content);
20059
+ if (seen) seen.count++;
20060
+ else seenExp.set(processed.content, {
20061
+ count: 1,
20062
+ first: exp
19844
20063
  });
19845
- expressions.forEach((exp) => {
19846
- if (exp.content === content) {
19847
- exp.content = varName;
19848
- exp.ast = null;
19849
- } else if (exp.content.includes(content)) {
19850
- exp.content = exp.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
19851
- exp.ast = parseExp(context, exp.content);
20064
+ }
20065
+ }
20066
+ const repeatedExpressions = [...seenExp].sort(([contentA], [contentB]) => contentB.length - contentA.length);
20067
+ for (const [content, { count, first }] of repeatedExpressions) if (count > 1) {
20068
+ const removedDeclarations = [];
20069
+ for (let i = varDeclarations.length - 1; i >= 0; i--) {
20070
+ const item = varDeclarations[i];
20071
+ if (!item.exps || !item.seenCount) continue;
20072
+ if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
20073
+ removedDeclarations.push({
20074
+ name: item.name,
20075
+ rawName: item.rawName
20076
+ });
20077
+ reservedNames.delete(item.name);
20078
+ varDeclarations.splice(i, 1);
20079
+ }
20080
+ }
20081
+ const value = extend({}, getProcessedExpression(first, expressionReplacements));
20082
+ const restorePlan = [];
20083
+ for (const { name, rawName } of removedDeclarations) restorePlan.push(...findIdentifierReplacements(value, name, rawName));
20084
+ if (restorePlan.length) {
20085
+ value.content = applyContentReplacements(value.content, restorePlan);
20086
+ if (value.ast) value.ast = parseExp(context, value.content);
20087
+ }
20088
+ const varName = getUniqueDeclarationName(genVarName(content), reservedNames);
20089
+ declarations.push({
20090
+ name: varName,
20091
+ value
20092
+ });
20093
+ for (const exp of expressions) {
20094
+ const processed = getProcessedExpression(exp, expressionReplacements);
20095
+ if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
20096
+ else if (processed.content.includes(content)) {
20097
+ const replacements = findContentReplacements(processed, content, varName);
20098
+ if (replacements.length) {
20099
+ const replacedContent = applyContentReplacements(processed.content, replacements);
20100
+ setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
19852
20101
  }
19853
- });
20102
+ }
19854
20103
  }
19855
- });
20104
+ }
19856
20105
  return declarations;
19857
20106
  }
20107
+ function canCacheExpression(processed, vars, updatedVariable) {
20108
+ if (!processed.ast || processed.ast.type === "Identifier") return false;
20109
+ for (const { name } of vars) if (updatedVariable.has(name) || isGloballyAllowed(name)) return false;
20110
+ return true;
20111
+ }
20112
+ function getExpressionVariables(expressionRecords, exp) {
20113
+ var _expressionRecords$ge2;
20114
+ return ((_expressionRecords$ge2 = expressionRecords.get(exp)) === null || _expressionRecords$ge2 === void 0 ? void 0 : _expressionRecords$ge2.variables) || [];
20115
+ }
20116
+ function queueContentReplacement(replacementPlan, exp, replacement) {
20117
+ const replacements = replacementPlan.get(exp);
20118
+ if (replacements) replacements.push(replacement);
20119
+ else replacementPlan.set(exp, [replacement]);
20120
+ }
20121
+ function applyReplacementPlan(context, expressionReplacements, replacementPlan) {
20122
+ for (const [exp, replacements] of replacementPlan) {
20123
+ if (!replacements.length) continue;
20124
+ const content = applyContentReplacements(getProcessedExpression(exp, expressionReplacements).content, replacements);
20125
+ setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
20126
+ }
20127
+ }
20128
+ function findContentReplacements(exp, content, replacement) {
20129
+ const identifiers = getIdentifierRanges(exp);
20130
+ if (!identifiers.length) return [];
20131
+ const replacements = [];
20132
+ let searchStart = 0;
20133
+ let start = exp.content.indexOf(content, searchStart);
20134
+ while (start !== -1) {
20135
+ const end = start + content.length;
20136
+ let canReplace = false;
20137
+ for (const identifier of identifiers) {
20138
+ if (start >= identifier.end || end <= identifier.start) continue;
20139
+ if (start > identifier.start || end < identifier.end) {
20140
+ canReplace = false;
20141
+ break;
20142
+ }
20143
+ canReplace = true;
20144
+ }
20145
+ if (canReplace) {
20146
+ replacements.push({
20147
+ start,
20148
+ end,
20149
+ content: replacement
20150
+ });
20151
+ searchStart = end;
20152
+ } else searchStart = start + 1;
20153
+ start = exp.content.indexOf(content, searchStart);
20154
+ }
20155
+ return replacements;
20156
+ }
20157
+ function findIdentifierReplacements(exp, name, replacement) {
20158
+ const replacements = [];
20159
+ for (const { start, end } of getIdentifierRanges(exp)) if (exp.content.slice(start, end) === name) replacements.push({
20160
+ start,
20161
+ end,
20162
+ content: replacement
20163
+ });
20164
+ return replacements;
20165
+ }
20166
+ function getIdentifierRanges(exp) {
20167
+ if (!exp.ast || typeof exp.ast !== "object") return [];
20168
+ const identifiers = [];
20169
+ walkIdentifiers(exp.ast, (id) => {
20170
+ identifiers.push({
20171
+ start: id.start - 1,
20172
+ end: id.end - 1
20173
+ });
20174
+ }, false);
20175
+ return identifiers;
20176
+ }
20177
+ function applyContentReplacements(content, replacements) {
20178
+ replacements.sort((a, b) => b.start - a.start).forEach(({ start, end, content: replacement }) => {
20179
+ content = content.slice(0, start) + replacement + content.slice(end);
20180
+ });
20181
+ return content;
20182
+ }
19858
20183
  function genDeclarations(declarations, context, shouldDeclare) {
19859
20184
  const [frag, push] = buildCodeFragment();
19860
20185
  const ids = Object.create(null);
@@ -19882,9 +20207,6 @@ function genDeclarations(declarations, context, shouldDeclare) {
19882
20207
  varNames: [...varNames]
19883
20208
  };
19884
20209
  }
19885
- function escapeRegExp(string) {
19886
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19887
- }
19888
20210
  function parseExp(context, content, loc) {
19889
20211
  try {
19890
20212
  return (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
@@ -19937,22 +20259,31 @@ const isMemberExpression = (node) => {
19937
20259
  function genSetEvent(oper, context) {
19938
20260
  const { helper } = context;
19939
20261
  const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
19940
- const name = genName();
19941
- const handler = [
19942
- `${context.helper("createInvoker")}(`,
19943
- ...genEventHandler(context, [value], modifiers),
19944
- `)`
19945
- ];
19946
- const eventOptions = genEventOptions();
20262
+ let handler;
19947
20263
  if (delegate) {
19948
20264
  context.delegates.add(key.content);
19949
20265
  if (!context.block.operation.some(isSameDelegateEvent)) return [
19950
20266
  NEWLINE,
19951
20267
  `n${element}.$evt${key.content} = `,
19952
- ...handler
20268
+ ...genDirectHandler()
20269
+ ];
20270
+ }
20271
+ const name = genName();
20272
+ const eventOptions = genEventOptions();
20273
+ return [NEWLINE, ...genCall(helper(effect ? "onBinding" : delegate ? "delegate" : "on"), `n${element}`, name, genHandler(), eventOptions)];
20274
+ function genHandler() {
20275
+ return handler || (handler = genEventHandler(context, [value], modifiers));
20276
+ }
20277
+ function genInvoker() {
20278
+ return [
20279
+ `${helper("createInvoker")}(`,
20280
+ ...genHandler(),
20281
+ `)`
19953
20282
  ];
19954
20283
  }
19955
- return [NEWLINE, ...genCall(helper(delegate ? "delegate" : "on"), `n${element}`, name, handler, eventOptions)];
20284
+ function genDirectHandler() {
20285
+ return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
20286
+ }
19956
20287
  function genName() {
19957
20288
  const expr = genExpression(key, context);
19958
20289
  if (keyOverride) {
@@ -19972,8 +20303,8 @@ function genSetEvent(oper, context) {
19972
20303
  }
19973
20304
  function genEventOptions() {
19974
20305
  let { options } = modifiers;
19975
- if (!options.length && !effect) return;
19976
- return genMulti(DELIMITERS_OBJECT_NEWLINE, effect && ["effect: true"], ...options.map((option) => [`${option}: true`]));
20306
+ if (!options.length) return;
20307
+ return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
19977
20308
  }
19978
20309
  function isSameDelegateEvent(op) {
19979
20310
  if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
@@ -19986,7 +20317,9 @@ function genSetDynamicEvents(oper, context) {
19986
20317
  function genEventHandler(context, values, modifiers = {
19987
20318
  nonKeys: [],
19988
20319
  keys: []
19989
- }, asComponentProp = false, extraWrap = false) {
20320
+ }, options = {}) {
20321
+ const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
20322
+ const useVaporModifierHelper = modifierHelper === "vapor";
19990
20323
  let handlerExp = [];
19991
20324
  if (values) {
19992
20325
  values.forEach((value, index) => {
@@ -20027,16 +20360,16 @@ function genEventHandler(context, values, modifiers = {
20027
20360
  }
20028
20361
  if (handlerExp.length === 0) handlerExp = ["() => {}"];
20029
20362
  const { keys, nonKeys } = modifiers;
20030
- if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
20031
- if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
20363
+ if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys, useVaporModifierHelper && !keys.length);
20364
+ if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys, useVaporModifierHelper);
20032
20365
  if (extraWrap) handlerExp.unshift(`() => `);
20033
20366
  return handlerExp;
20034
20367
  }
20035
- function genWithModifiers(context, handler, nonKeys) {
20036
- return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
20368
+ function genWithModifiers(context, handler, nonKeys, useVaporHelper = false) {
20369
+ return genCall(context.helper(useVaporHelper ? "withVaporModifiers" : "withModifiers"), handler, JSON.stringify(nonKeys));
20037
20370
  }
20038
- function genWithKeys(context, handler, keys) {
20039
- return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
20371
+ function genWithKeys(context, handler, keys, useVaporHelper = false) {
20372
+ return genCall(context.helper(useVaporHelper ? "withVaporKeys" : "withKeys"), handler, JSON.stringify(keys));
20040
20373
  }
20041
20374
  function isConstantBinding(value, context) {
20042
20375
  if (value.ast === null) {
@@ -20047,7 +20380,7 @@ function isConstantBinding(value, context) {
20047
20380
  //#region packages/compiler-vapor/src/generators/for.ts
20048
20381
  function genFor(oper, context) {
20049
20382
  const { helper } = context;
20050
- const { source, value, key, index, render, keyProp, once, id, component, onlyChild } = oper;
20383
+ const { source, value, key, index, render, keyProp, once, id, component, onlyChild, slotRoot } = oper;
20051
20384
  const rawValue = value && value.content;
20052
20385
  const rawKey = key && key.content;
20053
20386
  const rawIndex = index && index.content;
@@ -20074,7 +20407,7 @@ function genFor(oper, context) {
20074
20407
  idMap[rawIndex] = `${indexVar}.value`;
20075
20408
  idMap[indexVar] = null;
20076
20409
  }
20077
- const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap, context);
20410
+ const { selectorPatterns, keyOnlyBindingPatterns, skippedEffectIndexes } = matchPatterns(render, keyProp, idMap, context);
20078
20411
  const selectorDeclarations = [];
20079
20412
  const selectorName = (i) => selectorPatterns.length > 1 ? `_selector${id}_${i}` : `_selector${id}`;
20080
20413
  for (let i = 0; i < selectorPatterns.length; i++) {
@@ -20094,23 +20427,20 @@ function genFor(oper, context) {
20094
20427
  }
20095
20428
  for (const { effect } of keyOnlyBindingPatterns) for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
20096
20429
  return patternFrag;
20097
- }));
20430
+ }, skippedEffectIndexes));
20098
20431
  else frag.push(...genBlockContent(render, context));
20099
20432
  frag.push(INDENT_END, NEWLINE, "}");
20100
20433
  return frag;
20101
20434
  }, idMap);
20102
20435
  exitScope();
20103
- let flags = 0;
20104
- if (onlyChild) flags |= 1;
20105
- if (component) flags |= 2;
20106
- if (once) flags |= 4;
20436
+ const flags = genForFlags(onlyChild, component, isFragmentBlock(render), !component && isSingleNodeBlock(render), once, slotRoot);
20107
20437
  const onResetCalls = [];
20108
20438
  for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
20109
20439
  return [
20110
20440
  NEWLINE,
20111
20441
  ...selectorDeclarations,
20112
20442
  `const n${id} = `,
20113
- ...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0),
20443
+ ...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags),
20114
20444
  ...onResetCalls
20115
20445
  ];
20116
20446
  function genCallback(expr) {
@@ -20135,6 +20465,51 @@ function genFor(oper, context) {
20135
20465
  return idMap;
20136
20466
  }
20137
20467
  }
20468
+ function genForFlags(onlyChild, component, isFragment, isSingleNode, once, slotRoot) {
20469
+ let flags = 0;
20470
+ const names = [];
20471
+ if (onlyChild) {
20472
+ flags |= 1;
20473
+ names.push("FAST_REMOVE");
20474
+ }
20475
+ if (component) {
20476
+ flags |= 2;
20477
+ names.push("IS_COMPONENT");
20478
+ }
20479
+ if (isFragment) {
20480
+ flags |= 16;
20481
+ names.push("IS_FRAGMENT");
20482
+ }
20483
+ if (isSingleNode) {
20484
+ flags |= 8;
20485
+ names.push("IS_SINGLE_NODE");
20486
+ }
20487
+ if (once) {
20488
+ flags |= 4;
20489
+ names.push("ONCE");
20490
+ }
20491
+ if (slotRoot) {
20492
+ flags |= 32;
20493
+ names.push("SLOT_ROOT");
20494
+ }
20495
+ if (!flags) return;
20496
+ return `${flags} /* ${names.join(", ")} */`;
20497
+ }
20498
+ function isSingleNodeBlock(block) {
20499
+ const child = getSingleReturnedChild(block);
20500
+ return !!child && child.template != null;
20501
+ }
20502
+ function isFragmentBlock(block) {
20503
+ const child = getSingleReturnedChild(block);
20504
+ const operation = child && child.operation;
20505
+ if (!operation) return false;
20506
+ return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
20507
+ }
20508
+ function getSingleReturnedChild(block) {
20509
+ if (block.returns.length !== 1) return;
20510
+ const id = block.returns[0];
20511
+ for (const child of block.dynamic.children) if (child.id === id) return child;
20512
+ }
20138
20513
  function parseValueDestructure(value, context) {
20139
20514
  const map = /* @__PURE__ */ new Map();
20140
20515
  if (value) {
@@ -20172,7 +20547,8 @@ function parseValueDestructure(value, context) {
20172
20547
  if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
20173
20548
  isDynamic = true;
20174
20549
  helper = isDom2 ? context.helper("getSharedDataDefaultValue") : context.helper("getDefaultValue");
20175
- helperArgs = rawValue.slice(child.right.start - 1, child.right.end - 1);
20550
+ const rawDefault = rawValue.slice(child.right.start - 1, child.right.end - 1);
20551
+ helperArgs = isDom2 ? rawDefault : `() => (${rawDefault})`;
20176
20552
  }
20177
20553
  }
20178
20554
  map.set(id.name, {
@@ -20208,39 +20584,35 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
20208
20584
  function matchPatterns(render, keyProp, idMap, context) {
20209
20585
  const selectorPatterns = [];
20210
20586
  const keyOnlyBindingPatterns = [];
20211
- const removedEffectIndexes = [];
20212
- render.effect = render.effect.filter((effect, index) => {
20213
- if (keyProp !== void 0) {
20214
- const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
20215
- if (selector) {
20216
- selectorPatterns.push(selector);
20217
- removedEffectIndexes.push(index);
20218
- return false;
20219
- }
20220
- const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
20221
- if (keyOnly) {
20222
- keyOnlyBindingPatterns.push(keyOnly);
20223
- removedEffectIndexes.push(index);
20224
- return false;
20225
- }
20587
+ let skippedEffectIndexes;
20588
+ if (keyProp === void 0) return {
20589
+ keyOnlyBindingPatterns,
20590
+ selectorPatterns,
20591
+ skippedEffectIndexes
20592
+ };
20593
+ for (let index = 0; index < render.effect.length; index++) {
20594
+ const effect = render.effect[index];
20595
+ const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
20596
+ if (selector) {
20597
+ selectorPatterns.push(selector);
20598
+ skipEffect(index);
20599
+ continue;
20226
20600
  }
20227
- return true;
20228
- });
20229
- if (removedEffectIndexes.length) shiftEffectBoundaries(render.dynamic, removedEffectIndexes);
20601
+ const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
20602
+ if (keyOnly) {
20603
+ keyOnlyBindingPatterns.push(keyOnly);
20604
+ skipEffect(index);
20605
+ }
20606
+ }
20230
20607
  return {
20231
20608
  keyOnlyBindingPatterns,
20232
- selectorPatterns
20609
+ selectorPatterns,
20610
+ skippedEffectIndexes
20233
20611
  };
20234
- }
20235
- function shiftEffectBoundaries(dynamic, removedEffectIndexes) {
20236
- const operation = dynamic.operation;
20237
- if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0) {
20238
- let offset = 0;
20239
- for (const removedIndex of removedEffectIndexes) if (removedIndex < operation.effectIndex) offset++;
20240
- else break;
20241
- operation.effectIndex -= offset;
20612
+ function skipEffect(index) {
20613
+ if (!skippedEffectIndexes) skippedEffectIndexes = /* @__PURE__ */ new Set();
20614
+ skippedEffectIndexes.add(index);
20242
20615
  }
20243
- for (const child of dynamic.children) shiftEffectBoundaries(child, removedEffectIndexes);
20244
20616
  }
20245
20617
  function matchKeyOnlyBindingPattern(effect, key) {
20246
20618
  if (effect.expressions.length === 1) {
@@ -20320,8 +20692,9 @@ function genSetHtml(oper, context) {
20320
20692
  //#region packages/compiler-vapor/src/generators/if.ts
20321
20693
  function genIf(oper, context, isNested = false) {
20322
20694
  const { helper } = context;
20323
- const { condition, positive, negative, once, index, blockShape } = oper;
20695
+ const { condition, positive, negative, once, slotRoot, index, blockShape } = oper;
20324
20696
  const [frag, push] = buildCodeFragment();
20697
+ const flags = genIfFlags(blockShape, once, slotRoot, negative ? index : void 0);
20325
20698
  const conditionExpr = [
20326
20699
  "() => (",
20327
20700
  ...genExpression(condition, context),
@@ -20332,9 +20705,37 @@ function genIf(oper, context, isNested = false) {
20332
20705
  if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
20333
20706
  else negativeArg = ["() => ", ...genIf(negative, context, true)];
20334
20707
  if (!isNested) push(NEWLINE, `const n${oper.id} = `);
20335
- push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, String(blockShape), once && "true", index !== void 0 && negative && String(index)));
20708
+ push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
20336
20709
  return frag;
20337
20710
  }
20711
+ function genIfFlags(blockShape, once, slotRoot, index) {
20712
+ let flags = blockShape;
20713
+ if (slotRoot) flags |= 128;
20714
+ if (once) flags |= 16;
20715
+ else if (index !== void 0) flags |= index + 1 << 8;
20716
+ if (flags === 1) return false;
20717
+ return `${flags} /* ${genIfFlagNames(once, slotRoot, index, blockShape)} */`;
20718
+ }
20719
+ function genIfFlagNames(once, slotRoot, index, blockShape) {
20720
+ const names = [`TRUE_${genBlockShapeName(blockShape)}`];
20721
+ const falseShape = blockShape >> 2;
20722
+ const hasFalseBranch = (falseShape & 3) !== 0;
20723
+ if (hasFalseBranch) names.push(`FALSE_${genBlockShapeName(falseShape)}`);
20724
+ if (blockShape & 32) names.push("TRUE_NO_SCOPE");
20725
+ if (hasFalseBranch && blockShape & 64) names.push("FALSE_NO_SCOPE");
20726
+ if (once) names.push("ONCE");
20727
+ if (slotRoot) names.push("SLOT_ROOT");
20728
+ if (!once && index !== void 0) names.push(`KEYED_INDEX_${index}`);
20729
+ return names.join(", ");
20730
+ }
20731
+ function genBlockShapeName(flags) {
20732
+ switch (flags & 3) {
20733
+ case 0: return "EMPTY";
20734
+ case 1: return "SINGLE_ROOT";
20735
+ case 2: return "MULTI_ROOT";
20736
+ }
20737
+ return "UNKNOWN";
20738
+ }
20338
20739
  //#endregion
20339
20740
  //#region packages/compiler-vapor/src/generators/prop.ts
20340
20741
  const helpers = {
@@ -20384,15 +20785,16 @@ function resolveClassName(values, context) {
20384
20785
  const entries = [];
20385
20786
  let sawDynamic = false;
20386
20787
  let sawSuffix = false;
20387
- for (const value of values) {
20788
+ for (const rawValue of values) {
20789
+ const value = context.getExpressionReplacement(rawValue);
20388
20790
  const staticValue = getLiteralExpressionValue(value, true);
20389
20791
  if (staticValue != null) {
20390
20792
  const normalized = normalizeClass(staticValue);
20391
- if (normalized) if (sawSuffix) suffix = appendClass(suffix, normalized);
20793
+ if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
20392
20794
  else if (sawDynamic) {
20393
20795
  sawSuffix = true;
20394
- suffix = appendClass(suffix, normalized);
20395
- } else prefix = appendClass(prefix, normalized);
20796
+ suffix = appendClass$1(suffix, normalized);
20797
+ } else prefix = appendClass$1(prefix, normalized);
20396
20798
  continue;
20397
20799
  }
20398
20800
  const ast = value.ast;
@@ -20413,7 +20815,7 @@ function resolveClassName(values, context) {
20413
20815
  function resolveObjectClassName(source, ast, entries, context) {
20414
20816
  for (const prop of ast.properties) {
20415
20817
  if (prop.type !== "ObjectProperty" || prop.computed) return false;
20416
- const rawClassName = getObjectPropertyName(prop);
20818
+ const rawClassName = getObjectPropertyName$1(prop);
20417
20819
  if (rawClassName == null) return false;
20418
20820
  const className = normalizeClass(rawClassName);
20419
20821
  if (!className) continue;
@@ -20458,10 +20860,10 @@ function genClassFlags(entries, context) {
20458
20860
  });
20459
20861
  return values;
20460
20862
  }
20461
- function appendClass(base, value) {
20863
+ function appendClass$1(base, value) {
20462
20864
  return base ? value ? `${base} ${value}` : base : value;
20463
20865
  }
20464
- function getObjectPropertyName(prop) {
20866
+ function getObjectPropertyName$1(prop) {
20465
20867
  const key = prop.key;
20466
20868
  if (key.type === "Identifier") return key.name;
20467
20869
  else if (key.type === "StringLiteral") return key.value;
@@ -20515,7 +20917,12 @@ function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModi
20515
20917
  if (runtimeCamelize) {
20516
20918
  key.push(" || \"\"");
20517
20919
  key = genCall(helper("camelize"), key);
20518
- }
20920
+ } else if (modifier) key = [
20921
+ "(",
20922
+ ...key,
20923
+ " || \"\"",
20924
+ ")"
20925
+ ];
20519
20926
  if (handler) key = genCall(helper("toHandlerKey"), key);
20520
20927
  return [
20521
20928
  "[",
@@ -20553,8 +20960,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
20553
20960
  const setTemplateRefIdent = `_setTemplateRef`;
20554
20961
  function genSetTemplateRef(oper, context) {
20555
20962
  const [refValue, refKey] = genRefValue(oper.value, context);
20963
+ if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
20964
+ context.needsTemplateRefSetter = true;
20556
20965
  return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
20557
20966
  }
20967
+ function genSetStaticTemplateRef(oper, refValue, refKey, context) {
20968
+ return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
20969
+ }
20970
+ function genSetTemplateRefBinding(oper, context) {
20971
+ const [refValue, refKey] = genRefValue(oper.value, context);
20972
+ const setter = context.inSlotBlock && setTemplateRefIdent;
20973
+ if (context.inSlotBlock) context.needsTemplateRefSetter = true;
20974
+ return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
20975
+ setter,
20976
+ oper.refFor && "true",
20977
+ refKey
20978
+ ] : [])];
20979
+ }
20558
20980
  function genRefValue(value, context) {
20559
20981
  if (value && context.options.inline) {
20560
20982
  const binding = context.options.bindingMetadata[value.content];
@@ -20592,6 +21014,11 @@ function genVShow(oper, context) {
20592
21014
  ])];
20593
21015
  }
20594
21016
  //#endregion
21017
+ //#region packages/compiler-vapor/src/generators/modifier.ts
21018
+ function genDirectiveModifiers(modifiers) {
21019
+ return modifiers.map((value) => `${isSimpleIdentifier(value) ? value : JSON.stringify(value)}: true`).join(", ");
21020
+ }
21021
+ //#endregion
20595
21022
  //#region packages/compiler-vapor/src/generators/vModel.ts
20596
21023
  const helperMap = {
20597
21024
  text: "applyTextModel",
@@ -20606,7 +21033,7 @@ function genVModel(oper, context) {
20606
21033
  `() => (`,
20607
21034
  ...genExpression(exp, context),
20608
21035
  `)`
20609
- ], genModelHandler(exp, context), modifiers.length ? `{ ${modifiers.map((e) => e.content + ": true").join(",")} }` : void 0)];
21036
+ ], genModelHandler(exp, context), modifiers.length ? `{ ${genDirectiveModifiers(modifiers.map((e) => e.content))} }` : void 0)];
20610
21037
  }
20611
21038
  function genModelHandler(exp, context) {
20612
21039
  return [
@@ -20648,25 +21075,31 @@ function genCustomDirectives(opers, context) {
20648
21075
  return genMulti(DELIMITERS_ARRAY.concat("void 0"), directiveVar, value, argument, modifiers);
20649
21076
  }
20650
21077
  }
20651
- function genDirectiveModifiers(modifiers) {
20652
- return modifiers.map((value) => `${isSimpleIdentifier(value) ? value : JSON.stringify(value)}: true`).join(", ");
20653
- }
20654
21078
  function filterCustomDirectives(id, operations) {
20655
21079
  return operations.filter((oper) => oper.type === 14 && oper.element === id && !oper.builtin);
20656
21080
  }
20657
21081
  //#endregion
20658
21082
  //#region packages/compiler-vapor/src/generators/component.ts
21083
+ function genStaticModifierPropKey(name) {
21084
+ const key = getModifierPropName(name);
21085
+ return [isSimpleIdentifier(key) ? key : JSON.stringify(key)];
21086
+ }
20659
21087
  function genCreateComponent(operation, context) {
20660
21088
  const { helper } = context;
21089
+ const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
21090
+ const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
21091
+ const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
20661
21092
  const tag = genTag();
20662
- const { root, props, slots, once } = operation;
21093
+ const { root, props, slots, once, slotRoot } = operation;
21094
+ const isRuntimeDynamicComponent = !!(operation.dynamic && !operation.dynamic.isStatic);
21095
+ const dynamicComponentFlags = isRuntimeDynamicComponent ? genDynamicComponentFlags(root, once, slotRoot) : false;
20663
21096
  const rawSlots = genRawSlots(slots, context);
20664
21097
  const [ids, handlers] = processInlineHandlers(props, context);
20665
- const rawProps = context.withId(() => genRawProps(props, context), ids);
21098
+ const rawProps = context.withId(() => genRawProps(props, context, true), ids);
20666
21099
  return [
20667
21100
  NEWLINE,
20668
21101
  ...handlers.reduce((acc, { name, value }) => {
20669
- const handler = genEventHandler(context, [value], void 0, false, false);
21102
+ const handler = genEventHandler(context, [value]);
20670
21103
  return [
20671
21104
  ...acc,
20672
21105
  `const ${name} = `,
@@ -20675,7 +21108,7 @@ function genCreateComponent(operation, context) {
20675
21108
  ];
20676
21109
  }, []),
20677
21110
  `const n${operation.id} = `,
20678
- ...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"),
21111
+ ...genCall(isRuntimeDynamicComponent ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : useAssetComponentHelper ? helper("createAssetComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, isRuntimeDynamicComponent ? dynamicComponentFlags : root ? "true" : false, isRuntimeDynamicComponent ? false : once && "true", isRuntimeDynamicComponent ? false : maybeSelfReference && "true"),
20679
21112
  ...genDirectivesForElement(operation.id, context)
20680
21113
  ];
20681
21114
  function genTag() {
@@ -20686,7 +21119,10 @@ function genCreateComponent(operation, context) {
20686
21119
  ...genExpression(operation.dynamic, context),
20687
21120
  ")"
20688
21121
  ];
20689
- else if (operation.asset) return toValidAssetId(operation.tag, "component");
21122
+ else if (useAssetComponentHelper) {
21123
+ const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
21124
+ return JSON.stringify(name);
21125
+ } else if (operation.asset) return toValidAssetId(operation.tag, "component");
20690
21126
  else {
20691
21127
  const { tag } = operation;
20692
21128
  const builtInTag = isBuiltInComponent(tag);
@@ -20698,6 +21134,28 @@ function genCreateComponent(operation, context) {
20698
21134
  }
20699
21135
  }
20700
21136
  }
21137
+ function genDynamicComponentFlags(root, once, slotRoot, extraFlags) {
21138
+ let flags = 0;
21139
+ const names = [];
21140
+ if (root) {
21141
+ flags |= 1;
21142
+ names.push("SINGLE_ROOT");
21143
+ }
21144
+ if (once) {
21145
+ flags |= 2;
21146
+ names.push("ONCE");
21147
+ }
21148
+ if (slotRoot) {
21149
+ flags |= 4;
21150
+ names.push("SLOT_ROOT");
21151
+ }
21152
+ if (extraFlags) for (const [flag, name] of extraFlags) {
21153
+ flags |= flag;
21154
+ names.push(name);
21155
+ }
21156
+ if (!flags) return false;
21157
+ return `${flags} /* ${names.join(", ")} */`;
21158
+ }
20701
21159
  function getUniqueHandlerName(context, name) {
20702
21160
  const { seenInlineHandlerNames } = context;
20703
21161
  name = genVarName(name);
@@ -20726,14 +21184,14 @@ function processInlineHandlers(props, context) {
20726
21184
  }
20727
21185
  return [ids, handlers];
20728
21186
  }
20729
- function genRawProps(props, context) {
21187
+ function genRawProps(props, context, directStaticLiteralProps = false) {
20730
21188
  const staticProps = props[0];
20731
21189
  if (isArray$1(staticProps)) {
20732
21190
  if (!staticProps.length && props.length === 1) return;
20733
- return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
20734
- } else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
21191
+ return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
21192
+ } else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
20735
21193
  }
20736
- function genStaticProps(props, context, dynamicProps) {
21194
+ function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
20737
21195
  const args = [];
20738
21196
  const handlerGroups = /* @__PURE__ */ new Map();
20739
21197
  const ensureHandlerGroup = (keyName, keyFrag) => {
@@ -20766,11 +21224,11 @@ function genStaticProps(props, context, dynamicProps) {
20766
21224
  continue;
20767
21225
  }
20768
21226
  const keyFrag = genPropKey(prop, context);
20769
- 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, false));
20770
- else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true, false));
21227
+ 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 }));
21228
+ else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
20771
21229
  continue;
20772
21230
  }
20773
- args.push(genProp(prop, context, true));
21231
+ args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
20774
21232
  if (prop.model) {
20775
21233
  if (prop.key.isStatic) {
20776
21234
  const keyName = `onUpdate:${camelize(prop.key.content)}`;
@@ -20789,13 +21247,13 @@ function genStaticProps(props, context, dynamicProps) {
20789
21247
  }
20790
21248
  const { key, modelModifiers } = prop;
20791
21249
  if (modelModifiers && modelModifiers.length) {
20792
- const modifiersKey = key.isStatic ? [getModifierPropName(key.content)] : [
21250
+ const modifiersKey = key.isStatic ? genStaticModifierPropKey(key.content) : [
20793
21251
  "[",
20794
21252
  ...genExpression(key, context),
20795
21253
  " + \"Modifiers\"]"
20796
21254
  ];
20797
21255
  const modifiersVal = genDirectiveModifiers(modelModifiers);
20798
- args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
21256
+ args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
20799
21257
  }
20800
21258
  }
20801
21259
  }
@@ -20810,13 +21268,13 @@ function genStaticProps(props, context, dynamicProps) {
20810
21268
  if (dynamicProps) args.push([`$: `, ...dynamicProps]);
20811
21269
  return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
20812
21270
  }
20813
- function genDynamicProps(props, context) {
21271
+ function genDynamicProps(props, context, directStaticLiteralProps = false) {
20814
21272
  const { helper } = context;
20815
21273
  const frags = [];
20816
21274
  for (const p of props) {
20817
21275
  let expr;
20818
21276
  if (isArray$1(p)) {
20819
- if (p.length) frags.push(genStaticProps(p, context));
21277
+ if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
20820
21278
  continue;
20821
21279
  } else if (p.kind === 1) if (p.model) {
20822
21280
  const entries = [genProp(p, context)];
@@ -20832,7 +21290,7 @@ function genDynamicProps(props, context) {
20832
21290
  ]);
20833
21291
  const { modelModifiers } = p;
20834
21292
  if (modelModifiers && modelModifiers.length) {
20835
- const modifiersKey = p.key.isStatic ? [getModifierPropName(p.key.content)] : [
21293
+ const modifiersKey = p.key.isStatic ? genStaticModifierPropKey(p.key.content) : [
20836
21294
  "[",
20837
21295
  ...genExpression(p.key, context),
20838
21296
  " + \"Modifiers\"]"
@@ -20854,27 +21312,79 @@ function genDynamicProps(props, context) {
20854
21312
  }
20855
21313
  if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
20856
21314
  }
20857
- function genProp(prop, context, isStatic, wrapHandler = true) {
21315
+ function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
20858
21316
  const values = genPropValue(prop.values, context);
20859
21317
  return [
20860
21318
  ...genPropKey(prop, context),
20861
21319
  ": ",
20862
- ...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, true, wrapHandler) : isStatic ? [
21320
+ ...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
21321
+ asComponentProp: true,
21322
+ extraWrap: wrapHandler
21323
+ }) : isStatic ? directStaticLiteral ? values : [
20863
21324
  "() => (",
20864
21325
  ...values,
20865
21326
  ")"
20866
21327
  ] : values
20867
21328
  ];
20868
21329
  }
21330
+ /**
21331
+ * Static literal values are safe to emit directly because reading them cannot
21332
+ * touch reactive state. Keep handlers, v-model values, and dynamic expressions
21333
+ * as getter sources to preserve lazy access and merge semantics.
21334
+ */
21335
+ function isDirectStaticLiteralProp(prop, context) {
21336
+ return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
21337
+ }
21338
+ function isDirectConstantValue(value, context) {
21339
+ value = context.getExpressionReplacement(value);
21340
+ if (value.isStatic) return true;
21341
+ const ast = value.ast;
21342
+ if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
21343
+ if (!ast) return false;
21344
+ return isDirectConstantAst(ast);
21345
+ }
21346
+ function isDirectConstantAst(node) {
21347
+ switch (node.type) {
21348
+ case "StringLiteral":
21349
+ case "NumericLiteral":
21350
+ case "BooleanLiteral":
21351
+ case "NullLiteral":
21352
+ case "BigIntLiteral": return true;
21353
+ case "Identifier": return node.name === "undefined";
21354
+ case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
21355
+ case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
21356
+ case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
21357
+ }
21358
+ return false;
21359
+ }
21360
+ function isDirectTemplateConstantAst(node) {
21361
+ switch (node.type) {
21362
+ case "StringLiteral":
21363
+ case "NumericLiteral":
21364
+ case "BooleanLiteral":
21365
+ case "NullLiteral":
21366
+ case "BigIntLiteral": return true;
21367
+ case "Identifier": return node.name === "undefined";
21368
+ case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
21369
+ }
21370
+ return false;
21371
+ }
20869
21372
  function genRawSlots(slots, context) {
20870
21373
  if (!slots.length) return;
20871
21374
  const staticSlots = slots[0];
20872
- if (staticSlots.slotType === 0) return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
20873
- else return genStaticSlots({
21375
+ if (staticSlots.slotType === 0) {
21376
+ const defaultSlot = getSingleDefaultSlot(staticSlots);
21377
+ if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
21378
+ return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
21379
+ } else return genStaticSlots({
20874
21380
  slotType: 0,
20875
21381
  slots: {}
20876
21382
  }, context, slots);
20877
21383
  }
21384
+ function getSingleDefaultSlot({ slots }) {
21385
+ const names = Object.keys(slots);
21386
+ return names.length === 1 && names[0] === "default" ? slots.default : void 0;
21387
+ }
20878
21388
  function genStaticSlots({ slots }, context, dynamicSlots) {
20879
21389
  const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
20880
21390
  if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
@@ -20897,26 +21407,15 @@ function genDynamicSlot(slot, context, withFunction = false) {
20897
21407
  break;
20898
21408
  }
20899
21409
  if (!withFunction) return frag;
20900
- return needsDynamicSlotSourceCtx(slot) ? [
20901
- `${context.helper("withVaporCtx")}(() => (`,
20902
- ...frag,
20903
- "))"
20904
- ] : [
21410
+ return [
20905
21411
  "() => (",
20906
21412
  ...frag,
20907
21413
  ")"
20908
21414
  ];
20909
21415
  }
20910
- function needsDynamicSlotSourceCtx(slot) {
20911
- switch (slot.slotType) {
20912
- case 1: return needsVaporCtx(slot.fn);
20913
- case 2: return needsVaporCtx(slot.fn);
20914
- case 3: return needsDynamicSlotSourceCtx(slot.positive) || (slot.negative ? needsDynamicSlotSourceCtx(slot.negative) : false);
20915
- }
20916
- }
20917
21416
  function genBasicDynamicSlot(slot, context) {
20918
21417
  const { name, fn } = slot;
20919
- return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context)]);
21418
+ return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context, false)]);
20920
21419
  }
20921
21420
  function genLoopSlot(slot, context) {
20922
21421
  const { name, fn, loop } = slot;
@@ -20928,7 +21427,7 @@ function genLoopSlot(slot, context) {
20928
21427
  if (rawValue) idMap[rawValue] = rawValue;
20929
21428
  if (rawKey) idMap[rawKey] = rawKey;
20930
21429
  if (rawIndex) idMap[rawIndex] = rawIndex;
20931
- const slotExpr = genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...context.withId(() => genExpression(name, context), idMap)], ["fn: ", ...context.withId(() => genSlotBlockWithProps(fn, context), idMap)]);
21430
+ const slotExpr = genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...context.withId(() => genExpression(name, context), idMap)], ["fn: ", ...context.withId(() => genSlotBlockWithProps(fn, context, false), idMap)]);
20932
21431
  return [...genCall(context.helper("createForSlots"), genExpression(source, context), [
20933
21432
  ...genMulti([
20934
21433
  "(",
@@ -20954,11 +21453,11 @@ function genConditionalSlot(slot, context) {
20954
21453
  INDENT_END
20955
21454
  ];
20956
21455
  }
20957
- function genSlotBlockWithProps(oper, context) {
21456
+ function genSlotBlockWithProps(oper, context, emitNonStableFlag = true) {
20958
21457
  let propsName;
20959
21458
  let exitScope;
20960
21459
  let depth;
20961
- const { props, node } = oper;
21460
+ const { props } = oper;
20962
21461
  const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
20963
21462
  if (props) if (props.ast) {
20964
21463
  [depth, exitScope] = context.enterScope();
@@ -20966,36 +21465,70 @@ function genSlotBlockWithProps(oper, context) {
20966
21465
  } else propsName = props.content;
20967
21466
  const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
20968
21467
  if (propsName) idMap[propsName] = null;
21468
+ const exitSlotBlock = context.enterSlotBlock();
21469
+ const hasStableRoot = hasStableSlotRoot(oper, context);
21470
+ if (!hasStableRoot) markSlotRootOperations(oper);
20969
21471
  let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
21472
+ if (emitNonStableFlag && !hasStableRoot) blockFn = genCall(context.helper("extend"), blockFn, [`{ _: ${genSlotFlags$1(8)} }`]);
21473
+ exitSlotBlock();
20970
21474
  exitScope && exitScope();
20971
- if (node.type === 1) {
20972
- if (needsVaporCtx(oper)) blockFn = [
20973
- `${context.helper("withVaporCtx")}(`,
20974
- ...blockFn,
20975
- `)`
20976
- ];
20977
- }
20978
21475
  return blockFn;
20979
21476
  }
20980
- /**
20981
- * Check if a slot block needs withVaporCtx wrapper.
20982
- * Returns true if the block contains:
20983
- * - Component creation (needs scopeId inheritance)
20984
- * - Slot outlet (needs rawSlots from slot owner)
20985
- */
20986
- function needsVaporCtx(block) {
20987
- return hasComponentOrSlotInBlock(block);
20988
- }
20989
- function hasComponentOrSlotInBlock(block) {
20990
- if (hasComponentOrSlotInOperations(block.operation)) return true;
20991
- return hasComponentOrSlotInDynamic(block.dynamic);
20992
- }
20993
- function hasComponentOrSlotInDynamic(dynamic) {
20994
- if (dynamic.operation) {
20995
- const type = dynamic.operation.type;
20996
- if (type === 12 || type === 13) return true;
20997
- if (type === 15) {
20998
- if (hasComponentOrSlotInIf(dynamic.operation)) return true;
21477
+ function genSlotFlags$1(flags) {
21478
+ const names = [];
21479
+ if (flags & 1) names.push("NO_SLOTTED");
21480
+ if (flags & 2) names.push("ONCE");
21481
+ if (flags & 4) names.push("SLOT_ROOT");
21482
+ if (flags & 8) names.push("NON_STABLE");
21483
+ return `${flags} /* ${names.join(", ")} */`;
21484
+ }
21485
+ const commentOnlyTemplateRE = /^(?:<!--[\s\S]*?-->)+$/;
21486
+ function hasStableSlotRoot(block, context) {
21487
+ let hasValidRoot = false;
21488
+ for (let i = 0; i < block.returns.length; i++) {
21489
+ const id = block.returns[i];
21490
+ const child = findReturnedDynamic$1(block, id);
21491
+ const operation = child && child.operation;
21492
+ if (!operation) {
21493
+ if (child && isStableTemplateSlotRoot(child, context)) hasValidRoot = true;
21494
+ continue;
21495
+ }
21496
+ switch (operation.type) {
21497
+ case 12:
21498
+ if (!operation.dynamic || operation.dynamic.isStatic) {
21499
+ hasValidRoot = true;
21500
+ continue;
21501
+ }
21502
+ continue;
21503
+ case 17:
21504
+ if (hasStableSlotRoot(operation.block, context)) {
21505
+ hasValidRoot = true;
21506
+ continue;
21507
+ }
21508
+ continue;
21509
+ default: continue;
21510
+ }
21511
+ }
21512
+ return hasValidRoot;
21513
+ }
21514
+ function isStableTemplateSlotRoot(child, context) {
21515
+ if (child.template == null) return false;
21516
+ const content = context.ir.template.entries[child.template].content;
21517
+ return content !== "" && !commentOnlyTemplateRE.test(content.trim());
21518
+ }
21519
+ function needsVaporCtx(block) {
21520
+ return hasComponentOrSlotInBlock(block);
21521
+ }
21522
+ function hasComponentOrSlotInBlock(block) {
21523
+ if (hasComponentOrSlotInOperations(block.operation)) return true;
21524
+ return hasComponentOrSlotInDynamic(block.dynamic);
21525
+ }
21526
+ function hasComponentOrSlotInDynamic(dynamic) {
21527
+ if (dynamic.operation) {
21528
+ const type = dynamic.operation.type;
21529
+ if (type === 12 || type === 13) return true;
21530
+ if (type === 15) {
21531
+ if (hasComponentOrSlotInIf(dynamic.operation)) return true;
20999
21532
  }
21000
21533
  if (type === 16) {
21001
21534
  if (hasComponentOrSlotInBlock(dynamic.operation.render)) return true;
@@ -21027,18 +21560,31 @@ function hasComponentOrSlotInIf(node) {
21027
21560
  //#region packages/compiler-vapor/src/generators/slotOutlet.ts
21028
21561
  function genSlotOutlet(oper, context) {
21029
21562
  const { helper } = context;
21030
- const { id, name, fallback, noSlotted, once } = oper;
21563
+ const { id, name, fallback, flags } = oper;
21031
21564
  const [frag, push] = buildCodeFragment();
21032
- const nameExpr = name.isStatic ? genExpression(name, context) : [
21565
+ let fallbackArg;
21566
+ if (fallback) {
21567
+ if (context.inSlotBlock) markSlotRootOperations(fallback);
21568
+ fallbackArg = genBlock(fallback, context);
21569
+ }
21570
+ const createSlot = helper("createSlot");
21571
+ const rawPropsArg = genRawProps(oper.props, context, true);
21572
+ const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
21033
21573
  "() => (",
21034
21574
  ...genExpression(name, context),
21035
21575
  ")"
21036
21576
  ];
21037
- let fallbackArg;
21038
- if (fallback) fallbackArg = genBlock(fallback, context);
21039
- push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
21577
+ push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, genSlotFlags(flags)));
21040
21578
  return frag;
21041
21579
  }
21580
+ function genSlotFlags(flags) {
21581
+ if (!flags) return;
21582
+ const names = [];
21583
+ if (flags & 1) names.push("NO_SLOTTED");
21584
+ if (flags & 2) names.push("ONCE");
21585
+ if (flags & 4) names.push("SLOT_ROOT");
21586
+ return `${flags} /* ${names.join(", ")} */`;
21587
+ }
21042
21588
  //#endregion
21043
21589
  //#region packages/compiler-vapor/src/generators/key.ts
21044
21590
  function genKey(oper, context) {
@@ -21098,28 +21644,35 @@ function genEffects(effects, context, genExtraFrag) {
21098
21644
  const [frag, push, unshift] = buildCodeFragment();
21099
21645
  const shouldDeclare = genExtraFrag === void 0;
21100
21646
  let operationsCount = 0;
21101
- const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
21102
- push(...declarationFrags);
21103
- for (let i = 0; i < effects.length; i++) {
21104
- const effect = effects[i];
21105
- operationsCount += effect.operations.length;
21106
- const frags = context.withId(() => genEffect(effect, context), ids);
21107
- i > 0 && push(NEWLINE);
21108
- if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
21109
- push(...frags);
21110
- }
21111
- if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
21112
- unshift(`{`, INDENT_START, NEWLINE);
21113
- push(INDENT_END, NEWLINE, "}");
21114
- if (!effects.length) unshift(NEWLINE);
21115
- }
21116
- if (effects.length) {
21117
- unshift(NEWLINE, `${helper("renderEffect")}(() => `);
21118
- push(`)`);
21119
- }
21120
- if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
21121
- if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
21122
- return frag;
21647
+ const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
21648
+ if (shouldDeclare && !declarationFrags.length && !varNames.length) {
21649
+ const effect = effects.length === 1 ? effects[0] : void 0;
21650
+ const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
21651
+ if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
21652
+ }
21653
+ return context.withExpressionReplacements(expressionReplacements, () => {
21654
+ push(...declarationFrags);
21655
+ for (let i = 0; i < effects.length; i++) {
21656
+ const effect = effects[i];
21657
+ operationsCount += effect.operations.length;
21658
+ const frags = context.withId(() => genEffect(effect, context), ids);
21659
+ i > 0 && push(NEWLINE);
21660
+ if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
21661
+ push(...frags);
21662
+ }
21663
+ if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
21664
+ unshift(`{`, INDENT_START, NEWLINE);
21665
+ push(INDENT_END, NEWLINE, "}");
21666
+ if (!effects.length) unshift(NEWLINE);
21667
+ }
21668
+ if (effects.length) {
21669
+ unshift(NEWLINE, `${helper("renderEffect")}(() => `);
21670
+ push(`)`);
21671
+ }
21672
+ if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
21673
+ if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
21674
+ return frag;
21675
+ });
21123
21676
  }
21124
21677
  function genEffect({ operations }, context) {
21125
21678
  const [frag, push] = buildCodeFragment();
@@ -21138,9 +21691,8 @@ function genTemplates(templates, context) {
21138
21691
  const result = [];
21139
21692
  templates.forEach(({ content, ns, root, static: isStatic }, i) => {
21140
21693
  let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
21141
- if (root) args += ", true";
21142
- else if (isStatic || ns) args += ", false";
21143
- if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
21694
+ const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
21695
+ if (flags || ns) args += `, ${flags}`;
21144
21696
  if (ns) args += `, ${ns}`;
21145
21697
  result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
21146
21698
  });
@@ -21158,10 +21710,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
21158
21710
  return frag;
21159
21711
  }
21160
21712
  function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
21161
- const { helper } = context;
21162
21713
  const [frag, push] = buildCodeFragment();
21163
21714
  const { children } = dynamic;
21164
21715
  let offset = 0;
21716
+ /**
21717
+ * `reusable` means the previous access target is a p* cursor that can be
21718
+ * reassigned by the next lookup. Referenced n* variables must stay stable.
21719
+ */
21165
21720
  let prev;
21166
21721
  for (const [index, child] of children.entries()) {
21167
21722
  if (child.flags & 2) offset--;
@@ -21178,27 +21733,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
21178
21733
  }
21179
21734
  const elementIndex = index + offset;
21180
21735
  const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
21181
- const variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
21182
- pushBlock(NEWLINE, `const ${variable} = `);
21183
- if (prev) if (elementIndex - prev[1] === 1) pushBlock(...genCall(helper("next"), prev[0], logicalIndex));
21184
- else pushBlock(...genCall(helper("nthChild"), from, String(elementIndex), logicalIndex));
21185
- else if (elementIndex === 0) pushBlock(...genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0));
21186
- else {
21187
- let init = genCall(helper("child"), from);
21188
- if (elementIndex === 1) init = genCall(helper("next"), init, logicalIndex);
21189
- else if (elementIndex > 1) init = genCall(helper("nthChild"), from, String(elementIndex), logicalIndex);
21190
- pushBlock(...init);
21736
+ const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
21737
+ const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
21738
+ if (inlinePlaceholder) {
21739
+ if (prev && prev[2]) {
21740
+ push(...genChildren(child, context, pushBlock, [
21741
+ "(",
21742
+ prev[0],
21743
+ " = ",
21744
+ ...accessPath,
21745
+ ")"
21746
+ ], flushBeforeDynamic));
21747
+ prev = [
21748
+ prev[0],
21749
+ elementIndex,
21750
+ true
21751
+ ];
21752
+ continue;
21753
+ }
21754
+ if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
21755
+ push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
21756
+ continue;
21757
+ }
21758
+ }
21759
+ let variable;
21760
+ if (id === void 0 && prev && prev[2]) {
21761
+ variable = prev[0];
21762
+ pushBlock(NEWLINE, `${variable} = `, ...accessPath);
21763
+ } else {
21764
+ variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
21765
+ pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
21191
21766
  }
21192
21767
  if (id === child.anchor && !child.hasDynamicChild) {
21193
21768
  flushBeforeDynamic && flushBeforeDynamic(child, push);
21194
21769
  push(...genSelf(child, context, flushBeforeDynamic));
21195
21770
  }
21196
21771
  if (id !== void 0) push(...genDirectivesForElement(id, context));
21197
- prev = [variable, elementIndex];
21772
+ prev = [
21773
+ variable,
21774
+ elementIndex,
21775
+ id === void 0
21776
+ ];
21198
21777
  push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
21199
21778
  }
21200
21779
  return frag;
21201
21780
  }
21781
+ /**
21782
+ * Build one DOM lookup path while preserving the fast sibling walk:
21783
+ * adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
21784
+ */
21785
+ function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
21786
+ if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
21787
+ if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
21788
+ const firstChild = genCall(helper("child"), from);
21789
+ return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
21790
+ }
21791
+ /**
21792
+ * Only inline a placeholder when materializing it would not save a parent
21793
+ * lookup. If its child tree needs the parent more than once, keep p* so the
21794
+ * generated code does not duplicate _child/_nthChild work.
21795
+ */
21796
+ function canInlinePlaceholder(dynamic) {
21797
+ return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
21798
+ }
21799
+ /**
21800
+ * A following access can reuse the current placeholder cursor only when it is
21801
+ * the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
21802
+ */
21803
+ function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
21804
+ let futureOffset = offset;
21805
+ for (let i = index + 1; i < children.length; i++) {
21806
+ const child = children[i];
21807
+ if (child.flags & 2) futureOffset--;
21808
+ if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
21809
+ }
21810
+ return false;
21811
+ }
21812
+ /**
21813
+ * Mirrors genChildren's traversal closely enough to count how many emitted
21814
+ * access paths would start from this placeholder's parent. This is the guard
21815
+ * that keeps inline placeholders from duplicating parent lookups.
21816
+ */
21817
+ function countParentAccessUsages(dynamic) {
21818
+ let usages = 0;
21819
+ let offset = 0;
21820
+ let prev;
21821
+ for (const [index, child] of dynamic.children.entries()) {
21822
+ if (child.flags & 2) offset--;
21823
+ if (child.flags & 4 && child.template != null) continue;
21824
+ const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
21825
+ if (id === void 0 && !child.hasDynamicChild) continue;
21826
+ const elementIndex = index + offset;
21827
+ const usesParent = !prev || elementIndex - prev[0] !== 1;
21828
+ if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
21829
+ if (prev && prev[1]) {
21830
+ if (usesParent) usages++;
21831
+ prev = [elementIndex, true];
21832
+ continue;
21833
+ }
21834
+ if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
21835
+ if (usesParent) usages++;
21836
+ continue;
21837
+ }
21838
+ }
21839
+ if (usesParent) usages++;
21840
+ prev = [elementIndex, id === void 0];
21841
+ }
21842
+ return usages;
21843
+ }
21844
+ function genNthChild(nthChild, from, elementIndex, logicalIndex) {
21845
+ const index = String(elementIndex);
21846
+ return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
21847
+ }
21202
21848
  //#endregion
21203
21849
  //#region packages/compiler-vapor/src/generators/block.ts
21204
21850
  function genBlock(oper, context, args = [], root) {
@@ -21213,12 +21859,16 @@ function genBlock(oper, context, args = [], root) {
21213
21859
  "}"
21214
21860
  ];
21215
21861
  }
21216
- function genBlockContent(block, context, root, genEffectsExtraFrag) {
21862
+ function genBlockContent(block, context, root, genEffectsExtraFrag, skippedEffectIndexes) {
21217
21863
  const [frag, push] = buildCodeFragment();
21218
21864
  const { dynamic, effect, operation, returns } = block;
21219
21865
  const resetBlock = context.enterBlock(block);
21866
+ const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
21867
+ const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
21868
+ if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
21220
21869
  if (root) {
21221
21870
  for (let name of context.ir.component) {
21871
+ if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
21222
21872
  const id = toValidAssetId(name, "component");
21223
21873
  const maybeSelfReference = name.endsWith("__self");
21224
21874
  if (maybeSelfReference) name = name.slice(0, -6);
@@ -21234,7 +21884,7 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
21234
21884
  operationIndex++;
21235
21885
  }
21236
21886
  if (effectIndex < effectEnd) {
21237
- push(...genEffects(effect.slice(effectIndex, effectEnd), context));
21887
+ push(...genEffectRange(effectIndex, effectEnd));
21238
21888
  effectIndex = effectEnd;
21239
21889
  }
21240
21890
  };
@@ -21248,21 +21898,145 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
21248
21898
  }
21249
21899
  for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`, flushBeforeDynamic));
21250
21900
  if (operationIndex < operation.length) push(...genOperations(operation.slice(operationIndex), context));
21251
- if (effectIndex < effect.length) push(...genEffects(effect.slice(effectIndex), context, genEffectsExtraFrag));
21901
+ if (effectIndex < effect.length) push(...genEffectRange(effectIndex, effect.length, genEffectsExtraFrag));
21252
21902
  else if (genEffectsExtraFrag) push(...genEffects([], context, genEffectsExtraFrag));
21253
21903
  push(NEWLINE, `return `);
21254
21904
  const returnNodes = returns.map((n) => `n${n}`);
21255
- push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
21905
+ push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "[]"]);
21256
21906
  resetBlock();
21907
+ context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
21257
21908
  return frag;
21909
+ function genEffectRange(start, end, genExtraFrag) {
21910
+ if (!skippedEffectIndexes) return genEffects(effect.slice(start, end), context, genExtraFrag);
21911
+ const effects = [];
21912
+ for (let i = start; i < end; i++) if (!skippedEffectIndexes.has(i)) effects.push(effect[i]);
21913
+ if (effects.length || genExtraFrag) return genEffects(effects, context, genExtraFrag);
21914
+ return [];
21915
+ }
21258
21916
  function genResolveAssets(kind, helper) {
21259
21917
  for (const name of context.ir[kind]) push(NEWLINE, `const ${toValidAssetId(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
21260
21918
  }
21261
21919
  }
21920
+ function markSlotRootOperations(block) {
21921
+ for (let i = 0; i < block.returns.length; i++) {
21922
+ const child = findReturnedDynamic$1(block, block.returns[i]);
21923
+ const operation = child && child.operation;
21924
+ if (!operation) continue;
21925
+ if (operation.type === 15) markSlotRootIf(operation);
21926
+ else if (operation.type === 16) markSlotRootFor(operation);
21927
+ else if (operation.type === 12) markSlotRootComponent(operation);
21928
+ }
21929
+ }
21930
+ function markSlotRootIf(operation) {
21931
+ if (!operation.once) operation.slotRoot = true;
21932
+ markSlotRootOperations(operation.positive);
21933
+ const negative = operation.negative;
21934
+ if (!negative) return;
21935
+ if (negative.type === 15) markSlotRootIf(negative);
21936
+ else markSlotRootOperations(negative);
21937
+ }
21938
+ function markSlotRootFor(operation) {
21939
+ if (!operation.once) operation.slotRoot = true;
21940
+ markSlotRootOperations(operation.render);
21941
+ }
21942
+ function markSlotRootComponent(operation) {
21943
+ if (!operation.once && operation.dynamic && !operation.dynamic.isStatic) operation.slotRoot = true;
21944
+ }
21945
+ function findReturnedDynamic$1(block, id) {
21946
+ for (let i = 0; i < block.dynamic.children.length; i++) {
21947
+ const child = block.dynamic.children[i];
21948
+ if (child.id === id) return child;
21949
+ }
21950
+ }
21951
+ function collectSingleUseAssetComponents(block) {
21952
+ const usageMap = /* @__PURE__ */ new Map();
21953
+ const seenOperations = /* @__PURE__ */ new Set();
21954
+ visitBlock(block, true);
21955
+ const names = /* @__PURE__ */ new Set();
21956
+ for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
21957
+ return names;
21958
+ function visitBlock(block, rootCandidate) {
21959
+ visitDynamic(block.dynamic, rootCandidate);
21960
+ for (const operation of block.operation) visitOperation(operation, rootCandidate);
21961
+ for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
21962
+ }
21963
+ function visitDynamic(dynamic, rootCandidate) {
21964
+ if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
21965
+ for (const child of dynamic.children) visitDynamic(child, rootCandidate);
21966
+ }
21967
+ function visitOperation(operation, rootCandidate) {
21968
+ if (seenOperations.has(operation)) return;
21969
+ seenOperations.add(operation);
21970
+ if (operation.type === 12) {
21971
+ if (operation.asset) {
21972
+ const usage = usageMap.get(operation.tag) || {
21973
+ count: 0,
21974
+ root: false
21975
+ };
21976
+ usage.count++;
21977
+ if (rootCandidate) usage.root = true;
21978
+ usageMap.set(operation.tag, usage);
21979
+ }
21980
+ visitSlots(operation.slots);
21981
+ return;
21982
+ }
21983
+ switch (operation.type) {
21984
+ case 15:
21985
+ visitBlock(operation.positive, false);
21986
+ if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
21987
+ else visitBlock(operation.negative, false);
21988
+ break;
21989
+ case 16:
21990
+ visitBlock(operation.render, false);
21991
+ break;
21992
+ case 17:
21993
+ visitBlock(operation.block, false);
21994
+ break;
21995
+ case 13:
21996
+ if (operation.fallback) visitBlock(operation.fallback, false);
21997
+ break;
21998
+ }
21999
+ }
22000
+ function visitSlots(slots) {
22001
+ for (const slot of slots) switch (slot.slotType) {
22002
+ case 0:
22003
+ for (const name in slot.slots) visitBlock(slot.slots[name], false);
22004
+ break;
22005
+ case 1:
22006
+ case 2:
22007
+ visitBlock(slot.fn, false);
22008
+ break;
22009
+ case 3:
22010
+ visitSlots([slot.positive]);
22011
+ if (slot.negative) visitSlots([slot.negative]);
22012
+ break;
22013
+ }
22014
+ }
22015
+ }
21262
22016
  //#endregion
21263
22017
  //#region packages/compiler-vapor/src/generate.ts
21264
22018
  const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
22019
+ const helperNameAliases = {
22020
+ withVaporKeys: "withKeys",
22021
+ withVaporModifiers: "withModifiers"
22022
+ };
21265
22023
  var CodegenContext = class {
22024
+ withExpressionReplacements(map, fn) {
22025
+ if (map.size === 0) return fn();
22026
+ this.expressionReplacements.unshift(map);
22027
+ try {
22028
+ return fn();
22029
+ } finally {
22030
+ remove(this.expressionReplacements, map);
22031
+ }
22032
+ }
22033
+ getExpressionReplacement(node) {
22034
+ for (const map of this.expressionReplacements) {
22035
+ const replacement = map.get(node);
22036
+ if (replacement) return replacement;
22037
+ }
22038
+ return node;
22039
+ }
21266
22040
  withId(fn, map) {
21267
22041
  const { identifiers } = this;
21268
22042
  const ids = Object.keys(map);
@@ -21279,9 +22053,19 @@ var CodegenContext = class {
21279
22053
  this.block = block;
21280
22054
  return () => this.block = parent;
21281
22055
  }
22056
+ enterSlotBlock() {
22057
+ const parent = this.inSlotBlock;
22058
+ this.inSlotBlock = true;
22059
+ return () => this.inSlotBlock = parent;
22060
+ }
21282
22061
  enterScope() {
21283
22062
  return [this.scopeLevel++, () => this.scopeLevel--];
21284
22063
  }
22064
+ isHelperNameAvailable(name) {
22065
+ if (this.bindingNames.has(name)) return false;
22066
+ for (const alias of this.helpers.values()) if (alias === name) return false;
22067
+ return true;
22068
+ }
21285
22069
  initNextIdMap() {
21286
22070
  if (this.bindingNames.size === 0) return;
21287
22071
  const map = /* @__PURE__ */ new Map();
@@ -21316,19 +22100,29 @@ var CodegenContext = class {
21316
22100
  this.ir = ir;
21317
22101
  this.bindingNames = /* @__PURE__ */ new Set();
21318
22102
  this.helpers = /* @__PURE__ */ new Map();
22103
+ this.needsTemplateRefSetter = false;
22104
+ this.inSlotBlock = false;
21319
22105
  this.helper = (name) => {
21320
22106
  if (this.helpers.has(name)) return this.helpers.get(name);
21321
- const base = `_${name}`;
21322
- if (this.bindingNames.size === 0 || !this.bindingNames.has(base)) {
22107
+ const base = `_${helperNameAliases[name] || name}`;
22108
+ if (this.isHelperNameAvailable(base)) {
21323
22109
  this.helpers.set(name, base);
21324
22110
  return base;
21325
22111
  }
21326
- const alias = `${base}${getNextId(this.nextIdMap.get(base), 1)}`;
21327
- this.helpers.set(name, alias);
21328
- return alias;
22112
+ const map = this.nextIdMap.get(base);
22113
+ let next = 1;
22114
+ while (true) {
22115
+ const alias = `${base}${getNextId(map, next)}`;
22116
+ if (this.isHelperNameAvailable(alias)) {
22117
+ this.helpers.set(name, alias);
22118
+ return alias;
22119
+ }
22120
+ next++;
22121
+ }
21329
22122
  };
21330
22123
  this.delegates = /* @__PURE__ */ new Set();
21331
22124
  this.identifiers = Object.create(null);
22125
+ this.expressionReplacements = [];
21332
22126
  this.seenInlineHandlerNames = Object.create(null);
21333
22127
  this.scopeLevel = 0;
21334
22128
  this.templateVars = /* @__PURE__ */ new Map();
@@ -21355,6 +22149,7 @@ var CodegenContext = class {
21355
22149
  this.block = ir.block;
21356
22150
  this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
21357
22151
  this.initNextIdMap();
22152
+ this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
21358
22153
  }
21359
22154
  };
21360
22155
  function generate(ir, options = {}) {
@@ -21367,8 +22162,11 @@ function generate(ir, options = {}) {
21367
22162
  const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
21368
22163
  if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
21369
22164
  push(INDENT_START);
21370
- if (ir.hasTemplateRef) push(NEWLINE, `const ${setTemplateRefIdent} = ${context.helper("createTemplateRefSetter")}()`);
21371
- push(...genBlockContent(ir.block, context, true));
22165
+ const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
22166
+ const body = genBlockContent(ir.block, context, true);
22167
+ if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
22168
+ else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
22169
+ push(...body);
21372
22170
  push(INDENT_END, NEWLINE);
21373
22171
  if (!inline) push("}");
21374
22172
  const delegates = genDelegates(context);
@@ -21403,6 +22201,11 @@ function genAssetImports({ ir }) {
21403
22201
  }
21404
22202
  return imports;
21405
22203
  }
22204
+ function getStaticTemplateRefHelperCandidate(block) {
22205
+ if (block.operation.length !== 1) return;
22206
+ const operation = block.operation[0];
22207
+ if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
22208
+ }
21406
22209
  //#endregion
21407
22210
  //#region packages/compiler-vapor/src/transforms/vBind.ts
21408
22211
  function normalizeBindShorthand(arg, context) {
@@ -21441,66 +22244,48 @@ const transformVBind = (dir, node, context) => {
21441
22244
  };
21442
22245
  };
21443
22246
  //#endregion
21444
- //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
21445
- function _typeof(o) {
21446
- "@babel/helpers - typeof";
21447
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
21448
- return typeof o;
21449
- } : function(o) {
21450
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
21451
- }, _typeof(o);
22247
+ //#region packages/compiler-vapor/src/transforms/vHtml.ts
22248
+ function ignoreVHtmlChildren(node, context, clear) {
22249
+ if (!node.children.length) return;
22250
+ const dir = findDir$1(node, "html");
22251
+ if (!dir) return;
22252
+ context.options.onError(createDOMCompilerError(55, dir.loc));
22253
+ if (clear === "node") node.children.length = 0;
22254
+ else context.childrenTemplate.length = 0;
21452
22255
  }
21453
- //#endregion
21454
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
21455
- function toPrimitive(t, r) {
21456
- if ("object" != _typeof(t) || !t) return t;
21457
- var e = t[Symbol.toPrimitive];
21458
- if (void 0 !== e) {
21459
- var i = e.call(t, r || "default");
21460
- if ("object" != _typeof(i)) return i;
21461
- throw new TypeError("@@toPrimitive must return a primitive value.");
22256
+ const transformVHtml = (dir, node, context) => {
22257
+ let { exp, loc } = dir;
22258
+ if (!exp) {
22259
+ context.options.onError(createDOMCompilerError(54, loc));
22260
+ exp = EMPTY_EXPRESSION;
21462
22261
  }
21463
- return ("string" === r ? String : Number)(t);
21464
- }
21465
- //#endregion
21466
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
21467
- function toPropertyKey(t) {
21468
- var i = toPrimitive(t, "string");
21469
- return "symbol" == _typeof(i) ? i : i + "";
21470
- }
21471
- //#endregion
21472
- //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
21473
- function _defineProperty(e, r, t) {
21474
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
21475
- value: t,
21476
- enumerable: !0,
21477
- configurable: !0,
21478
- writable: !0
21479
- }) : e[r] = t, e;
21480
- }
22262
+ ignoreVHtmlChildren(node, context, "template");
22263
+ context.registerEffect([exp], {
22264
+ type: 8,
22265
+ node,
22266
+ element: context.reference(),
22267
+ value: exp,
22268
+ isComponent: node.tagType === 1
22269
+ });
22270
+ };
21481
22271
  //#endregion
21482
- //#region \0@oxc-project+runtime@0.129.0/helpers/objectSpread2.js
21483
- function ownKeys(e, r) {
21484
- var t = Object.keys(e);
21485
- if (Object.getOwnPropertySymbols) {
21486
- var o = Object.getOwnPropertySymbols(e);
21487
- r && (o = o.filter(function(r) {
21488
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
21489
- })), t.push.apply(t, o);
21490
- }
21491
- return t;
21492
- }
21493
- function _objectSpread2(e) {
21494
- for (var r = 1; r < arguments.length; r++) {
21495
- var t = null != arguments[r] ? arguments[r] : {};
21496
- r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
21497
- _defineProperty(e, r, t[r]);
21498
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
21499
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
21500
- });
21501
- }
21502
- return e;
22272
+ //#region packages/compiler-vapor/src/errors.ts
22273
+ function createVaporCompilerError(code, loc) {
22274
+ return createCompilerError(code, loc, VaporErrorMessages);
21503
22275
  }
22276
+ const VaporErrorCodes = {
22277
+ "X_V_PLACEHOLDER": 100,
22278
+ "100": "X_V_PLACEHOLDER",
22279
+ "X_DYNAMIC_FLATTEN_NOT_SUPPORTED": 101,
22280
+ "101": "X_DYNAMIC_FLATTEN_NOT_SUPPORTED",
22281
+ "__EXTEND_POINT__": 102,
22282
+ "102": "__EXTEND_POINT__"
22283
+ };
22284
+ const VaporErrorMessages = {
22285
+ [100]: `[placeholder]`,
22286
+ [101]: "The value of flatten attribute must be a static boolean value.",
22287
+ [102]: ``
22288
+ };
21504
22289
  //#endregion
21505
22290
  //#region packages/compiler-vapor/src/transforms/transformElement.ts
21506
22291
  const isReservedProp = /* @__PURE__ */ makeMap(",key,ref,ref_for,ref_key,");
@@ -21509,6 +22294,7 @@ const transformElement = (node, context) => {
21509
22294
  const getEffectIndex = () => effectIndex++;
21510
22295
  let operationIndex = context.block.operation.length;
21511
22296
  const getOperationIndex = () => operationIndex++;
22297
+ if (node.type === 1 && node.children.length) ignoreVHtmlChildren(node, context, "node");
21512
22298
  let parentSlots;
21513
22299
  if (node.type === 1 && (node.tagType === 1 || context.options.isCustomElement(node.tag))) {
21514
22300
  parentSlots = context.slots;
@@ -21522,7 +22308,7 @@ const transformElement = (node, context) => {
21522
22308
  const isDynamicComponent = isComponentTag(node.tag);
21523
22309
  const staticKey = resolveStaticKey(node, context, isComponent);
21524
22310
  const propsResult = buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex);
21525
- const singleRoot = isSingleRoot(context);
22311
+ const singleRoot = context.isSingleRoot;
21526
22312
  if (isComponent) transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement);
21527
22313
  else transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context), getOperationIndex);
21528
22314
  if (parentSlots) context.slots = parentSlots;
@@ -21561,16 +22347,6 @@ function isInSameTemplateAsParent(context) {
21561
22347
  if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
21562
22348
  return !shouldUseCreateElement(parentNode, parent) && isValidHTMLNesting(parentNode.tag, node.tag);
21563
22349
  }
21564
- function isSingleRoot(context) {
21565
- if (context.inVFor) return false;
21566
- let { parent } = context;
21567
- if (parent && !(hasSingleChild(parent.node) || isSingleIfBlock(parent.node))) return false;
21568
- while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
21569
- parent = parent.parent;
21570
- if (!(hasSingleChild(parent.node) || isSingleIfBlock(parent.node))) return false;
21571
- }
21572
- return context.root === parent;
21573
- }
21574
22350
  function transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement) {
21575
22351
  const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
21576
22352
  let { tag } = node;
@@ -21605,6 +22381,7 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
21605
22381
  }
21606
22382
  context.dynamic.flags |= 6;
21607
22383
  const id = context.reference();
22384
+ const flatten = extractElementFlatten(node, propsResult, context);
21608
22385
  context.dynamic.operation = _objectSpread2(_objectSpread2({
21609
22386
  type: 12,
21610
22387
  node,
@@ -21617,11 +22394,38 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
21617
22394
  slots: [...context.slots],
21618
22395
  once: context.inVOnce,
21619
22396
  dynamic: dynamicComponent,
21620
- useCreateElement
22397
+ useCreateElement,
22398
+ flatten
21621
22399
  });
21622
22400
  if (staticKey) context.registerOperation(createSetBlockKey(id, staticKey, node));
21623
22401
  context.slots = [];
21624
22402
  }
22403
+ function extractElementFlatten(node, propsResult, context) {
22404
+ if (!context.options.platform) return;
22405
+ const flatten = extractStaticBooleanProp(propsResult, "flatten", (loc) => {
22406
+ context.options.onError(createVaporCompilerError(101, loc));
22407
+ });
22408
+ if (flatten != null) node.flatten = flatten;
22409
+ return flatten;
22410
+ }
22411
+ function extractStaticBooleanProp(propsResult, name, onInvalid) {
22412
+ const groups = propsResult[0] ? propsResult[1] : [propsResult[1]];
22413
+ for (const props of groups) {
22414
+ if (!Array.isArray(props)) continue;
22415
+ for (let i = 0; i < props.length; i++) {
22416
+ const prop = props[i];
22417
+ if (prop.key.isStatic && prop.key.content === name && !prop.handler && !prop.model) {
22418
+ const value = parseStaticAttrBooleanExpression(prop.values[0]);
22419
+ props.splice(i, 1);
22420
+ if (value == null) {
22421
+ onInvalid && onInvalid(prop.values[0].loc);
22422
+ return;
22423
+ }
22424
+ return value;
22425
+ }
22426
+ }
22427
+ }
22428
+ }
21625
22429
  function resolveDynamicComponent(node) {
21626
22430
  const isProp = findProp(node, "is", false, true);
21627
22431
  if (!isProp) return;
@@ -21637,9 +22441,15 @@ function resolveSetupReference(name, context) {
21637
22441
  }
21638
22442
  const dynamicKeys = ["indeterminate"];
21639
22443
  const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
22444
+ const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
22445
+ function isDataProp(prop) {
22446
+ const name = prop.key.content;
22447
+ return prop.key.isStatic && name.length > 5 && name.startsWith("data-");
22448
+ }
21640
22449
  function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag, getOperationIndex) {
21641
22450
  const isDom2 = !!context.options.platform;
21642
22451
  if (isDom2) omitEndTag = false;
22452
+ if (isDom2) extractElementFlatten(node, propsResult, context);
21643
22453
  const { tag } = node;
21644
22454
  const { scopeId } = context.options;
21645
22455
  let template = "";
@@ -21655,6 +22465,7 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
21655
22465
  if (context.options.rootElementFromUniModule) template += ` gen-root-custom-native="${rootElementTagName}"`;
21656
22466
  }
21657
22467
  }
22468
+ if (node.flatten) template += ` flatten`;
21658
22469
  }
21659
22470
  const dynamicProps = [];
21660
22471
  if (propsResult[0]) {
@@ -21677,8 +22488,9 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
21677
22488
  const props = propsResult[1];
21678
22489
  const indicesToRemove = [];
21679
22490
  for (let i = 0; i < props.length; i++) {
21680
- const { key, values } = props[i];
21681
- if (key.content.startsWith("change:") || changeProps.includes(key.content)) continue;
22491
+ const prop = props[i];
22492
+ const { key, values } = prop;
22493
+ if (isDataProp(prop) || key.content.startsWith("change:") || changeProps.includes(key.content)) continue;
21682
22494
  if (key.isStatic && values.length === 1 && !["class", "style"].includes(key.content)) {
21683
22495
  let endLoc = values[0].loc;
21684
22496
  if (endLoc === locStub) endLoc = key.loc;
@@ -21695,9 +22507,23 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
21695
22507
  let hasClass = false;
21696
22508
  const datasetProps = [];
21697
22509
  let prevWasQuoted = false;
22510
+ const appendTemplateProp = (key, value = "", generated = false) => {
22511
+ if (!prevWasQuoted) template += ` `;
22512
+ template += key;
22513
+ if (value) {
22514
+ const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, "&quot;");
22515
+ template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
22516
+ } else prevWasQuoted = false;
22517
+ };
21698
22518
  for (const prop of propsResult[1]) {
21699
22519
  const { key, values } = prop;
22520
+ const canStringifyAttrName = key.isStatic && !UNSAFE_ATTR_NAME_RE.test(key.content);
22521
+ let foldedValue;
21700
22522
  if (isDom2) {
22523
+ if (isDataProp(prop)) {
22524
+ datasetProps.push(prop);
22525
+ continue;
22526
+ }
21701
22527
  if (key.content.startsWith("change:")) {
21702
22528
  dynamicProps.push(key.content);
21703
22529
  values[0].isStatic = false;
@@ -21710,11 +22536,11 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
21710
22536
  }
21711
22537
  if (key.content === "class") hasClass = true;
21712
22538
  }
21713
- if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
22539
+ if (canStringifyAttrName && context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
21714
22540
  if (!prevWasQuoted) template += ` `;
21715
22541
  template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
21716
22542
  prevWasQuoted = true;
21717
- } else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
22543
+ } else if (canStringifyAttrName && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
21718
22544
  if (isDom2 && key.content === "style") {
21719
22545
  hasStaticStyle = true;
21720
22546
  const checkStaticStyle = context.options.checkStaticStyle;
@@ -21734,22 +22560,20 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
21734
22560
  }, getEffectIndex, getOperationIndex);
21735
22561
  continue;
21736
22562
  }
21737
- if (!prevWasQuoted) template += ` `;
21738
22563
  const value = values[0].content === "''" ? "" : values[0].content;
21739
- template += key.content;
21740
- if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, "&quot;")}"` : `=${value}`;
21741
- else prevWasQuoted = false;
21742
- } else {
21743
- dynamicProps.push(key.content);
21744
- context.registerEffect(values, {
21745
- type: 3,
21746
- node,
21747
- isChangeProp: changeProps.includes(key.content),
21748
- element: context.reference(),
21749
- prop,
21750
- tag
21751
- }, getEffectIndex);
21752
- }
22564
+ appendTemplateProp(key.content, value);
22565
+ } else if (canStringifyAttrName && !prop.modifier && isBooleanAttr(key.content) && (foldedValue = foldBooleanAttrValue(values)) != null) {
22566
+ if (foldedValue) appendTemplateProp(key.content);
22567
+ } else if (canStringifyAttrName && !prop.modifier && !isDom2 && hasBoundValue(values) && (foldedValue = key.content === "class" ? foldClassValues(values) : key.content === "style" ? foldStyleValues(values) : void 0) != null) {
22568
+ if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
22569
+ } else context.registerEffect(values, {
22570
+ type: 3,
22571
+ node,
22572
+ isChangeProp: changeProps.includes(key.content),
22573
+ element: context.reference(),
22574
+ prop,
22575
+ tag
22576
+ }, getEffectIndex);
21753
22577
  }
21754
22578
  if (hasStaticStyle && hasClass) template += ` ext:style`;
21755
22579
  if (datasetProps.length) {
@@ -21774,6 +22598,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
21774
22598
  } else context.template += template;
21775
22599
  if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey, node));
21776
22600
  }
22601
+ function escapeGeneratedAttrValue(value) {
22602
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
22603
+ }
22604
+ function foldBooleanAttrValue(values) {
22605
+ if (values.length !== 1) return;
22606
+ const evaluated = evaluateConstantExpression(values[0]);
22607
+ if (!evaluated) return;
22608
+ const value = evaluated.value;
22609
+ if (value === true || value === false || value == null) return includeBooleanAttr(value);
22610
+ }
22611
+ function foldStyleValues(values) {
22612
+ const evaluatedValues = [];
22613
+ for (const value of values) {
22614
+ const evaluated = evaluateConstantExpression(value);
22615
+ if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
22616
+ evaluatedValues.push(evaluated.value);
22617
+ }
22618
+ return stringifyStyle(normalizeStyle(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
22619
+ }
22620
+ function isStaticStyleValue(value) {
22621
+ if (typeof value === "string") return true;
22622
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
22623
+ for (const key in value) {
22624
+ const propValue = value[key];
22625
+ if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
22626
+ }
22627
+ return true;
22628
+ }
22629
+ function isSafeStylePropertyName(key) {
22630
+ return !!key && !/[;:]/.test(key);
22631
+ }
22632
+ function isSafeStylePropertyValue(value) {
22633
+ return typeof value === "number" || typeof value === "string" && !value.includes(";");
22634
+ }
22635
+ function hasBoundValue(values) {
22636
+ return values.some((value) => !value.isStatic && value.content !== "''");
22637
+ }
22638
+ function foldClassValues(values) {
22639
+ let templateValue = "";
22640
+ let changed = false;
22641
+ for (const value of values) {
22642
+ const evaluated = evaluateConstantExpression(value);
22643
+ if (evaluated) {
22644
+ const normalized = normalizeClass(evaluated.value);
22645
+ if (normalized) templateValue = appendClass(templateValue, normalized);
22646
+ else changed = true;
22647
+ continue;
22648
+ }
22649
+ return;
22650
+ }
22651
+ return changed || templateValue ? templateValue : void 0;
22652
+ }
22653
+ function appendClass(base, value) {
22654
+ return base ? value ? `${base} ${value}` : base : value;
22655
+ }
22656
+ function getObjectPropertyName(prop) {
22657
+ const key = prop.key;
22658
+ if (key.type === "Identifier") return key.name;
22659
+ else if (key.type === "StringLiteral") return key.value;
22660
+ else if (key.type === "NumericLiteral") return String(key.value);
22661
+ }
22662
+ function evaluateConstantExpression(node) {
22663
+ if (node.isStatic) return { value: node.content };
22664
+ const ast = node.ast;
22665
+ if (ast === null) {
22666
+ if (node.content === "true") return { value: true };
22667
+ else if (node.content === "false") return { value: false };
22668
+ else if (node.content === "null") return { value: null };
22669
+ else if (node.content === "undefined") return { value: void 0 };
22670
+ }
22671
+ if (!ast) return;
22672
+ return evaluateConstantAst(ast);
22673
+ }
22674
+ function evaluateConstantAst(node) {
22675
+ switch (node.type) {
22676
+ case "StringLiteral": return { value: node.value };
22677
+ case "NumericLiteral": return { value: node.value };
22678
+ case "BooleanLiteral": return { value: node.value };
22679
+ case "NullLiteral": return { value: null };
22680
+ case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
22681
+ case "UnaryExpression":
22682
+ if (node.operator === "void") return { value: void 0 };
22683
+ else if (node.operator === "-") {
22684
+ const value = evaluateConstantAst(node.argument);
22685
+ return value && typeof value.value === "number" ? { value: -value.value } : void 0;
22686
+ }
22687
+ return;
22688
+ case "TemplateLiteral": return evaluateTemplateLiteral(node);
22689
+ case "ObjectExpression": return evaluateObjectExpression(node);
22690
+ }
22691
+ }
22692
+ function evaluateTemplateLiteral(node) {
22693
+ if (node.type !== "TemplateLiteral") return;
22694
+ let value = "";
22695
+ for (const [index, quasi] of node.quasis.entries()) {
22696
+ value += quasi.value.cooked || "";
22697
+ const expression = node.expressions[index];
22698
+ if (expression) {
22699
+ const evaluated = evaluateConstantAst(expression);
22700
+ if (!evaluated) return;
22701
+ value += evaluated.value;
22702
+ }
22703
+ }
22704
+ return { value };
22705
+ }
22706
+ function evaluateObjectExpression(node) {
22707
+ const value = {};
22708
+ for (const prop of node.properties) {
22709
+ if (prop.type !== "ObjectProperty" || prop.computed) return;
22710
+ const key = getObjectPropertyName(prop);
22711
+ if (key == null) return;
22712
+ const evaluated = evaluateConstantAst(prop.value);
22713
+ if (!evaluated) return;
22714
+ value[key] = evaluated.value;
22715
+ }
22716
+ return { value };
22717
+ }
21777
22718
  function resolveStaticKey(node, context, isComponent) {
21778
22719
  const keyProp = findProp(node, "key", false, true);
21779
22720
  if (!keyProp) return;
@@ -21801,27 +22742,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
21801
22742
  results = [];
21802
22743
  }
21803
22744
  }
22745
+ function pushStaticObjectLiteralProps(props) {
22746
+ if (dynamicArgs.length) {
22747
+ pushMergeArg();
22748
+ dynamicArgs.push(props);
22749
+ } else results.push(...props.map(toDirectiveResult));
22750
+ }
21804
22751
  for (const prop of props) {
21805
22752
  if (prop.type === 7 && !prop.arg) {
21806
22753
  if (prop.name === "bind") {
21807
22754
  if (prop.exp) {
21808
- dynamicExpr.push(prop.exp);
21809
- pushMergeArg();
21810
- dynamicArgs.push({
21811
- kind: 0,
21812
- value: prop.exp
21813
- });
22755
+ const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
22756
+ if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
22757
+ else results.push(...objectLiteralProps.map(toDirectiveResult));
22758
+ else {
22759
+ dynamicExpr.push(prop.exp);
22760
+ pushMergeArg();
22761
+ dynamicArgs.push({
22762
+ kind: 0,
22763
+ value: prop.exp
22764
+ });
22765
+ }
21814
22766
  } else context.options.onError(createCompilerError(34, prop.loc));
21815
22767
  continue;
21816
22768
  } else if (prop.name === "on") {
21817
22769
  if (prop.exp) if (isComponent) {
21818
- dynamicExpr.push(prop.exp);
21819
- pushMergeArg();
21820
- dynamicArgs.push({
21821
- kind: 0,
21822
- value: prop.exp,
21823
- handler: true
21824
- });
22770
+ const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
22771
+ if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
22772
+ else {
22773
+ dynamicExpr.push(prop.exp);
22774
+ pushMergeArg();
22775
+ dynamicArgs.push({
22776
+ kind: 0,
22777
+ value: prop.exp,
22778
+ handler: true
22779
+ });
22780
+ }
21825
22781
  } else context.registerEffect([prop.exp], {
21826
22782
  type: 7,
21827
22783
  node,
@@ -21852,6 +22808,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
21852
22808
  }
21853
22809
  return [false, dedupeProperties(results)];
21854
22810
  }
22811
+ function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
22812
+ const ast = exp.ast;
22813
+ if (!ast || ast.type !== "ObjectExpression") return;
22814
+ const props = [];
22815
+ const knownKeys = /* @__PURE__ */ new Set();
22816
+ for (const property of ast.properties) {
22817
+ if (property.type !== "ObjectProperty" || property.computed) return;
22818
+ let key = getObjectPropertyName(property);
22819
+ if (key == null || key === "__proto__") return;
22820
+ if (isValidKey && !isValidKey(key)) return;
22821
+ if (keyTransform) key = keyTransform(key);
22822
+ if (knownKeys.has(key)) return;
22823
+ knownKeys.add(key);
22824
+ props.push({
22825
+ key: createSimpleExpression(key, true),
22826
+ values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
22827
+ });
22828
+ }
22829
+ return props;
22830
+ }
22831
+ function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
22832
+ const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
22833
+ if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
22834
+ return props;
22835
+ }
22836
+ function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
22837
+ const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
22838
+ if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
22839
+ return props;
22840
+ }
22841
+ function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
22842
+ const props = resolveObjectLiteralProps(exp, context, toHandlerKey);
22843
+ if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
22844
+ return props;
22845
+ }
22846
+ function isSafeNativeObjectLiteralBindKey(key) {
22847
+ return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !isOn(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
22848
+ }
22849
+ function isSafeObjectLiteralBindKey(key) {
22850
+ return !isReservedProp(key);
22851
+ }
22852
+ function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
22853
+ const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
22854
+ for (const prop of props) {
22855
+ if (prop === currentProp) continue;
22856
+ let key;
22857
+ if (prop.type === 6) key = prop.name;
22858
+ else if (prop.name === "bind") {
22859
+ if (!prop.arg) {
22860
+ const bindKeys = getObjectLiteralKeys(prop.exp);
22861
+ if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
22862
+ continue;
22863
+ }
22864
+ key = getStaticBindKey(prop);
22865
+ } else if (prop.name === "on") key = getStaticHandlerKey(prop);
22866
+ else if (prop.name === "model") {
22867
+ if (hasComponentModelKey(keys, prop)) return true;
22868
+ }
22869
+ if (key && hasComponentKey(keys, key)) return true;
22870
+ }
22871
+ return false;
22872
+ }
22873
+ function hasComponentModelKey(keys, prop) {
22874
+ const { arg } = prop;
22875
+ if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
22876
+ const key = arg ? arg.content : "modelValue";
22877
+ return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${camelize(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, getModifierPropName(key));
22878
+ }
22879
+ function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
22880
+ const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
22881
+ for (const prop of props) {
22882
+ if (prop === currentProp) continue;
22883
+ let key;
22884
+ if (prop.type === 6) key = prop.name;
22885
+ else if (prop.name === "bind") {
22886
+ if (!prop.arg) return true;
22887
+ key = getStaticBindKey(prop);
22888
+ if (!key) return true;
22889
+ }
22890
+ if (key && keys.has(key)) return true;
22891
+ }
22892
+ return false;
22893
+ }
22894
+ function getStaticBindKey(prop) {
22895
+ const { arg } = prop;
22896
+ if (!arg || arg.type !== 4 || !arg.isStatic) return;
22897
+ let key = arg.content;
22898
+ if (isReservedProp(key)) return;
22899
+ if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = camelize(key);
22900
+ return key;
22901
+ }
22902
+ function getStaticHandlerKey(prop) {
22903
+ const { arg } = prop;
22904
+ if (!arg || arg.type !== 4 || !arg.isStatic) return;
22905
+ let key = arg.content;
22906
+ if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
22907
+ const { nonKeyModifiers, eventOptionModifiers } = resolveModifiers(`on${key}`, prop.modifiers, null, prop.loc);
22908
+ if (key.toLowerCase() === "click") {
22909
+ if (nonKeyModifiers.includes("middle")) key = "mouseup";
22910
+ if (nonKeyModifiers.includes("right")) key = "contextmenu";
22911
+ }
22912
+ key = toHandlerKey(camelize(key));
22913
+ const optionPostfix = eventOptionModifiers.map(capitalize).join("");
22914
+ if (optionPostfix) key += optionPostfix;
22915
+ return key;
22916
+ }
22917
+ function getObjectLiteralKeys(exp) {
22918
+ const ast = exp && exp.ast;
22919
+ if (!ast || ast.type !== "ObjectExpression") return;
22920
+ const keys = /* @__PURE__ */ new Set();
22921
+ for (const property of ast.properties) {
22922
+ if (property.type !== "ObjectProperty" || property.computed) return;
22923
+ const key = getObjectPropertyName(property);
22924
+ if (key == null) return;
22925
+ keys.add(key);
22926
+ }
22927
+ return keys;
22928
+ }
22929
+ function createComponentConflictKeySet(keys) {
22930
+ const normalized = /* @__PURE__ */ new Set();
22931
+ for (const key of keys) {
22932
+ normalized.add(key);
22933
+ normalized.add(camelize(key));
22934
+ }
22935
+ return normalized;
22936
+ }
22937
+ function hasComponentKey(keys, key) {
22938
+ return keys.has(key) || keys.has(camelize(key));
22939
+ }
22940
+ function hasComponentKeyOverlap(left, right) {
22941
+ for (const key of right) if (hasComponentKey(left, key)) return true;
22942
+ return false;
22943
+ }
22944
+ function createObjectBindSubExpression(source, node, context) {
22945
+ const start = node.start == null ? 0 : node.start - 1;
22946
+ const end = node.end == null ? source.content.length : node.end - 1;
22947
+ const content = source.content.slice(start, end);
22948
+ const expression = createSimpleExpression(content, false, {
22949
+ start: advancePositionWithClone(source.loc.start, source.content, start),
22950
+ end: advancePositionWithClone(source.loc.start, source.content, end),
22951
+ source: content
22952
+ });
22953
+ expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
22954
+ return expression;
22955
+ }
21855
22956
  function transformProp(prop, node, context) {
21856
22957
  let { name } = prop;
21857
22958
  if (prop.type === 6) {
@@ -21903,6 +23004,12 @@ function resolveDirectiveResult(prop) {
21903
23004
  values: [prop.value]
21904
23005
  });
21905
23006
  }
23007
+ function toDirectiveResult(prop) {
23008
+ return extend({}, prop, {
23009
+ values: void 0,
23010
+ value: prop.values[0]
23011
+ });
23012
+ }
21906
23013
  function mergePropValues(existing, incoming) {
21907
23014
  const newValues = incoming.values;
21908
23015
  existing.values.push(...newValues);
@@ -21997,26 +23104,6 @@ const transformVOnce = (node, context) => {
21997
23104
  if (node.type === 1 && findDir$1(node, "once", true)) context.inVOnce = true;
21998
23105
  };
21999
23106
  //#endregion
22000
- //#region packages/compiler-vapor/src/transforms/vHtml.ts
22001
- const transformVHtml = (dir, node, context) => {
22002
- let { exp, loc } = dir;
22003
- if (!exp) {
22004
- context.options.onError(createDOMCompilerError(54, loc));
22005
- exp = EMPTY_EXPRESSION;
22006
- }
22007
- if (node.children.length) {
22008
- context.options.onError(createDOMCompilerError(55, loc));
22009
- context.childrenTemplate.length = 0;
22010
- }
22011
- context.registerEffect([exp], {
22012
- type: 8,
22013
- node,
22014
- element: context.reference(),
22015
- value: exp,
22016
- isComponent: node.tagType === 1
22017
- });
22018
- };
22019
- //#endregion
22020
23107
  //#region packages/compiler-vapor/src/transforms/transformText.ts
22021
23108
  const seen = /* @__PURE__ */ new WeakMap();
22022
23109
  function markNonTemplate(node, context) {
@@ -22062,13 +23149,7 @@ const transformText = (node, context) => {
22062
23149
  };
22063
23150
  function processInterpolation(context) {
22064
23151
  const parentNode = context.parent.node;
22065
- const children = parentNode.children;
22066
- const nexts = children.slice(context.index);
22067
- const idx = nexts.findIndex((n) => !isTextLike(n));
22068
- const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
22069
- const prev = children[context.index - 1];
22070
- if (prev && prev.type === 2) nodes.unshift(prev);
22071
- const values = processTextLikeChildren(nodes, context);
23152
+ const values = processTextLikeChildren(collectAdjacentText(context), context);
22072
23153
  if (values.length === 0 && parentNode.type !== 0) return;
22073
23154
  const literalValues = values.map((v) => getLiteralExpressionValue(v));
22074
23155
  if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
@@ -22104,6 +23185,18 @@ function processInterpolation(context) {
22104
23185
  values
22105
23186
  });
22106
23187
  }
23188
+ function collectAdjacentText(context) {
23189
+ const children = context.parent.node.children;
23190
+ const nodes = [];
23191
+ const prev = children[context.index - 1];
23192
+ let index = prev && prev.type === 2 ? context.index - 1 : context.index;
23193
+ for (; index < children.length; index++) {
23194
+ const child = children[index];
23195
+ if (!isTextLike(child)) break;
23196
+ nodes.push(child);
23197
+ }
23198
+ return nodes;
23199
+ }
22107
23200
  function processTextContainer(children, context) {
22108
23201
  const values = processTextLikeChildren(children, context);
22109
23202
  const literals = values.map((value) => getLiteralExpressionValue(value));
@@ -22236,12 +23329,10 @@ const transformVOn = (dir, node, context) => {
22236
23329
  const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(arg.isStatic ? `on${arg.content}` : arg, modifiers, null, loc);
22237
23330
  let keyOverride;
22238
23331
  const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
22239
- if (nonKeyModifiers.includes("middle")) {
22240
- if (keyOverride) {}
22241
- if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "mouseup"];
22242
- }
22243
23332
  if (nonKeyModifiers.includes("right")) {
22244
23333
  if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "contextmenu"];
23334
+ } else if (nonKeyModifiers.includes("middle")) {
23335
+ if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "mouseup"];
22245
23336
  }
22246
23337
  arg = normalizeStaticEventArg(arg, nonKeyModifiers);
22247
23338
  if (keyModifiers.length && isStaticExp(arg) && !isKeyboardEvent(`on${arg.content.toLowerCase()}`)) keyModifiers.length = 0;
@@ -22255,7 +23346,7 @@ const transformVOn = (dir, node, context) => {
22255
23346
  options: eventOptionModifiers
22256
23347
  }
22257
23348
  };
22258
- const delegate = arg.isStatic && !eventOptionModifiers.length && !hasStopHandlerForStaticEvent(node, arg.content) && delegatedEvents(arg.content);
23349
+ const delegate = context.options.eventDelegation && arg.isStatic && !eventOptionModifiers.length && !hasStopHandlerForStaticEvent(node, arg.content) && delegatedEvents(arg.content);
22259
23350
  const operation = {
22260
23351
  type: 6,
22261
23352
  node,
@@ -22277,8 +23368,8 @@ function normalizeStaticEventArg(arg, nonKeyModifiers) {
22277
23368
  if (!arg.isStatic) return arg;
22278
23369
  let normalized = arg;
22279
23370
  const isStaticClick = arg.content.toLowerCase() === "click";
22280
- if (nonKeyModifiers.includes("middle") && isStaticClick) normalized = extend({}, normalized, { content: "mouseup" });
22281
23371
  if (nonKeyModifiers.includes("right") && isStaticClick) normalized = extend({}, normalized, { content: "contextmenu" });
23372
+ else if (nonKeyModifiers.includes("middle") && isStaticClick) normalized = extend({}, normalized, { content: "mouseup" });
22282
23373
  return normalized;
22283
23374
  }
22284
23375
  function hasStopHandlerForStaticEvent(node, eventName) {
@@ -22446,6 +23537,7 @@ function processIf(node, dir, context) {
22446
23537
  }
22447
23538
  context.dynamic.flags |= 2;
22448
23539
  const forceMultiRoot = shouldForceMultiRoot(context);
23540
+ const allowNoScope = context.block === context.root.block;
22449
23541
  if (dir.name === "if") {
22450
23542
  const id = context.reference();
22451
23543
  context.dynamic.flags |= 4;
@@ -22457,7 +23549,7 @@ function processIf(node, dir, context) {
22457
23549
  node,
22458
23550
  id
22459
23551
  }, context.effectBoundary()), {}, {
22460
- blockShape: encodeIfBlockShape(branch, forceMultiRoot),
23552
+ blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
22461
23553
  condition: dir.exp,
22462
23554
  positive: branch,
22463
23555
  index: context.root.nextIfIndex(),
@@ -22481,11 +23573,14 @@ function processIf(node, dir, context) {
22481
23573
  }
22482
23574
  while (lastIfNode.negative && lastIfNode.negative.type === 15) lastIfNode = lastIfNode.negative;
22483
23575
  if (dir.name === "else-if" && lastIfNode.negative) context.options.onError(createCompilerError(30, node.loc));
22484
- if (context.root.comment.length) {
22485
- node = wrapTemplate(node, ["else-if", "else"]);
22486
- context.node = node = extend({}, node, { children: [...context.comment, ...node.children] });
23576
+ const comments = context.comment;
23577
+ if (comments.length) {
23578
+ if (!isInTransition(context)) {
23579
+ node = wrapTemplate(node, ["else-if", "else"]);
23580
+ context.node = node = extend({}, node, { children: [...comments, ...node.children] });
23581
+ }
23582
+ comments.length = 0;
22487
23583
  }
22488
- context.root.comment = [];
22489
23584
  const [branch, onExit] = createIfBranch(node, context);
22490
23585
  if (dir.name === "else") lastIfNode.negative = branch;
22491
23586
  else lastIfNode.negative = {
@@ -22500,8 +23595,8 @@ function processIf(node, dir, context) {
22500
23595
  };
22501
23596
  return () => {
22502
23597
  onExit();
22503
- if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
22504
- lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
23598
+ if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
23599
+ lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
22505
23600
  };
22506
23601
  }
22507
23602
  }
@@ -22516,14 +23611,38 @@ function createIfBranch(node, context) {
22516
23611
  context.reference();
22517
23612
  return [branch, exitBlock];
22518
23613
  }
22519
- function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
23614
+ function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
22520
23615
  if (forceMultiRoot) return 10;
22521
- return getBlockShape(positive) | getNegativeBlockShape(negative) << 2;
23616
+ const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
23617
+ const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
23618
+ return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
22522
23619
  }
22523
- function getNegativeBlockShape(negative) {
23620
+ function getNegativeIfBranchShape(negative) {
22524
23621
  if (!negative) return 0;
22525
23622
  return negative.type === 15 ? 1 : getBlockShape(negative);
22526
23623
  }
23624
+ function canSkipIfBranchScope(block) {
23625
+ if (block.effect.length || block.operation.length) return false;
23626
+ if (!isStaticBranch(block.node)) return false;
23627
+ if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
23628
+ return block.returns.every((id) => {
23629
+ const returned = findReturnedDynamic(block, id);
23630
+ return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
23631
+ });
23632
+ }
23633
+ function findReturnedDynamic(block, id) {
23634
+ return block.dynamic.children.find((child) => child.id === id);
23635
+ }
23636
+ function isStaticBranch(node) {
23637
+ if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
23638
+ return node.children.every((child) => isStaticTemplateNode(child));
23639
+ }
23640
+ function isStaticTemplateNode(node) {
23641
+ if (node.type === 2 || node.type === 3) return true;
23642
+ if (node.type !== 1 || node.tagType !== 0) return false;
23643
+ for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
23644
+ return node.children.every((child) => isStaticTemplateNode(child));
23645
+ }
22527
23646
  function shouldForceMultiRoot(context) {
22528
23647
  const parent = context.parent && context.parent.node;
22529
23648
  return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
@@ -22612,6 +23731,9 @@ const transformSlotOutlet = (node, context) => {
22612
23731
  }
22613
23732
  return () => {
22614
23733
  exitBlock && exitBlock();
23734
+ let flags = 0;
23735
+ if (context.options.scopeId && !context.options.slotted) flags |= 1;
23736
+ if (context.inVOnce) flags |= 2;
22615
23737
  context.dynamic.operation = _objectSpread2(_objectSpread2({
22616
23738
  type: 13,
22617
23739
  node,
@@ -22620,8 +23742,7 @@ const transformSlotOutlet = (node, context) => {
22620
23742
  name: slotName,
22621
23743
  props: irProps,
22622
23744
  fallback,
22623
- noSlotted: !!(context.options.scopeId && !context.options.slotted),
22624
- once: context.inVOnce
23745
+ flags
22625
23746
  });
22626
23747
  };
22627
23748
  };
@@ -22714,7 +23835,7 @@ function transformTemplateSlot(node, dir, context) {
22714
23835
  });
22715
23836
  else if (vElse) {
22716
23837
  const vIfSlot = slots[slots.length - 1];
22717
- if (vIfSlot.slotType === 3) {
23838
+ if (vIfSlot && vIfSlot.slotType === 3) {
22718
23839
  let ifNode = vIfSlot;
22719
23840
  while (ifNode.negative && ifNode.negative.slotType === 3) ifNode = ifNode.negative;
22720
23841
  const negative = vElse.exp ? {
@@ -22865,19 +23986,4 @@ function getBaseTransformPreset() {
22865
23986
  }];
22866
23987
  }
22867
23988
  //#endregion
22868
- //#region packages/compiler-vapor/src/errors.ts
22869
- function createVaporCompilerError(code, loc) {
22870
- return createCompilerError(code, loc, VaporErrorMessages);
22871
- }
22872
- const VaporErrorCodes = {
22873
- "X_V_PLACEHOLDER": 100,
22874
- "100": "X_V_PLACEHOLDER",
22875
- "__EXTEND_POINT__": 101,
22876
- "101": "__EXTEND_POINT__"
22877
- };
22878
- const VaporErrorMessages = {
22879
- [100]: `[placeholder]`,
22880
- [101]: ``
22881
- };
22882
- //#endregion
22883
- export { CodegenContext, DELIMITERS_ARRAY, DELIMITERS_ARRAY_NEWLINE, DELIMITERS_OBJECT, DELIMITERS_OBJECT_NEWLINE, DynamicFlag, IMPORT_EXPR_RE, IMPORT_EXP_END, IMPORT_EXP_START, INDENT_END, INDENT_START, IRDynamicPropsKind, IRNodeTypes, IRSlotType, LF, NEWLINE, TEXT_NODE_PLACEHOLDER, TEXT_PLACEHOLDER, TemplateRegistry, VaporErrorCodes, VaporErrorMessages, analyzeExpressions, buildCodeFragment, buildDestructureIdMap, codeFragmentToString, compile, createStructuralDirectiveTransform, createVaporCompilerError, genCall, genMulti, generate, getBaseTransformPreset, getLiteralExpressionValue, getParserOptions, isBlockOperation, isBuiltInComponent, isConstantExpression, isKeepAliveTag, isStaticExpression, isTeleportTag, isTransitionGroupTag, isTransitionTag, matchKeyOnlyBindingPattern, matchSelectorPattern, needsVaporCtx, parse, parseValueDestructure, propToExpression, transform, transformChildren, transformComment, transformElement, transformKey, transformSlotOutlet, transformTemplateRef, transformText, transformVBind, transformVFor, transformVHtml, transformVIf, transformVModel, transformVOn, transformVOnce, transformVShow, transformVSlot, transformVText, wrapTemplate };
23989
+ export { CodegenContext, DELIMITERS_ARRAY, DELIMITERS_ARRAY_NEWLINE, DELIMITERS_OBJECT, DELIMITERS_OBJECT_NEWLINE, DynamicFlag, IMPORT_EXPR_RE, IMPORT_EXP_END, IMPORT_EXP_START, INDENT_END, INDENT_START, IRDynamicPropsKind, IRNodeTypes, IRSlotType, LF, NEWLINE, TEXT_NODE_PLACEHOLDER, TEXT_PLACEHOLDER, TemplateRegistry, VaporErrorCodes, VaporErrorMessages, analyzeExpressions, buildCodeFragment, buildDestructureIdMap, codeFragmentToString, compile, createStructuralDirectiveTransform, createVaporCompilerError, genCall, genDirectiveModifiers, genDynamicComponentFlags, genMulti, genSlotFlags, generate, getBaseTransformPreset, getLiteralExpressionValue, getParserOptions, hasStableSlotRoot, isBlockOperation, isBuiltInComponent, isConstantExpression, isDirectStaticLiteralProp, isKeepAliveTag, isStaticExpression, isTeleportTag, isTransitionGroupTag, isTransitionTag, markSlotRootOperations, matchKeyOnlyBindingPattern, matchSelectorPattern, needsVaporCtx, parse, parseStaticAttrBooleanExpression, parseValueDestructure, propToExpression, transform, transformChildren, transformComment, transformElement, transformKey, transformSlotOutlet, transformTemplateRef, transformText, transformVBind, transformVFor, transformVHtml, transformVIf, transformVModel, transformVOn, transformVOnce, transformVShow, transformVSlot, transformVText, wrapTemplate };