@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
  **/
@@ -158,7 +158,7 @@ const TEXT_NODE_PLACEHOLDER = "__vapor_dom2_text_node_placeholder__";
158
158
  //#region packages/compiler-vapor/src/utils.ts
159
159
  const findProp$1 = _vue_compiler_dom.findProp;
160
160
  /** find directive */
161
- const findDir$2 = _vue_compiler_dom.findDir;
161
+ const findDir$4 = _vue_compiler_dom.findDir;
162
162
  function propToExpression(prop) {
163
163
  return prop.type === 6 ? prop.value ? (0, _vue_compiler_dom.createSimpleExpression)(prop.value.content, true, prop.value.loc) : EMPTY_EXPRESSION : prop.exp;
164
164
  }
@@ -180,6 +180,12 @@ function resolveExpression(exp, isComponent) {
180
180
  }
181
181
  return exp;
182
182
  }
183
+ function parseStaticAttrBooleanExpression(exp) {
184
+ try {
185
+ return (0, _vue_shared.includeBooleanAttr)(exp.isStatic ? exp.content : new Function(`return ${exp.content}`)());
186
+ } catch (e) {}
187
+ return null;
188
+ }
183
189
  function getLiteralExpressionValue(exp, excludeNumber) {
184
190
  if (exp.ast) {
185
191
  if (exp.ast.type === "StringLiteral") return exp.ast.value;
@@ -199,6 +205,13 @@ function getLiteralExpressionValue(exp, excludeNumber) {
199
205
  }
200
206
  return exp.isStatic ? exp.content : null;
201
207
  }
208
+ function isInTransition(context) {
209
+ const parentNode = context.parent && context.parent.node;
210
+ return !!(parentNode && isTransitionNode(parentNode));
211
+ }
212
+ function isTransitionNode(node) {
213
+ return node.type === 1 && isTransitionTag(node.tag);
214
+ }
202
215
  function isTransitionTag(tag) {
203
216
  tag = tag.toLowerCase();
204
217
  return tag === "transition" || tag === "vaportransition";
@@ -229,6 +242,7 @@ function getBlockShape(block) {
229
242
  //#endregion
230
243
  //#region packages/compiler-vapor/src/transform.ts
231
244
  const generatedVarRE = /^[nxr](\d+)$/;
245
+ const childContextInfoCache = /* @__PURE__ */ new WeakMap();
232
246
  var TransformContext = class TransformContext {
233
247
  constructor(ir, node, options = {}) {
234
248
  this.ir = ir;
@@ -254,6 +268,7 @@ var TransformContext = class TransformContext {
254
268
  this.operationIndex = this.block.operation.length;
255
269
  this.isLastEffectiveChild = true;
256
270
  this.isOnRightmostPath = true;
271
+ this.isSingleRoot = false;
257
272
  this.templateCloseTags = void 0;
258
273
  this.templateCloseBlocks = false;
259
274
  this.globalId = 0;
@@ -387,8 +402,10 @@ var TransformContext = class TransformContext {
387
402
  create(node, index) {
388
403
  let effectiveParent = this;
389
404
  while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
390
- const isLastEffectiveChild = this.isEffectivelyLastChild(index);
405
+ const childInfo = this.getChildContextInfo();
406
+ const isLastEffectiveChild = childInfo.isLastEffectiveChild[index];
391
407
  const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
408
+ const isSingleRoot = this.isSingleRootChild(childInfo);
392
409
  return Object.assign(Object.create(TransformContext.prototype), this, {
393
410
  node,
394
411
  parent: this,
@@ -403,6 +420,7 @@ var TransformContext = class TransformContext {
403
420
  effectiveParent,
404
421
  isLastEffectiveChild,
405
422
  isOnRightmostPath,
423
+ isSingleRoot,
406
424
  templateCloseTags: this.templateCloseTags,
407
425
  templateCloseBlocks: this.templateCloseBlocks
408
426
  });
@@ -417,12 +435,59 @@ var TransformContext = class TransformContext {
417
435
  if (operation && isBlockOperation(operation) && operation.operationIndex !== void 0 && operation.operationIndex >= index) operation.operationIndex += offset;
418
436
  for (const child of dynamic.children) this.shiftOperationBoundaries(index, offset, child);
419
437
  }
420
- isEffectivelyLastChild(index) {
421
- const children = this.node.children;
422
- if (!children) return true;
423
- return children.every((c, i) => i <= index || c.type === 1 && c.tagType === 1);
438
+ getChildContextInfo() {
439
+ const node = this.node;
440
+ if (node.type !== 0 && node.type !== 1) return {
441
+ node,
442
+ hasSingleRootChild: true,
443
+ isLastEffectiveChild: []
444
+ };
445
+ const cached = childContextInfoCache.get(this);
446
+ if (cached && cached.node === node) return cached;
447
+ const { children } = node;
448
+ const isLastEffectiveChild = new Array(children.length);
449
+ let hasFollowingEffectiveChild = false;
450
+ for (let i = children.length - 1; i >= 0; i--) {
451
+ isLastEffectiveChild[i] = !hasFollowingEffectiveChild;
452
+ if (!isComponentChild(children[i])) hasFollowingEffectiveChild = true;
453
+ }
454
+ const childInfo = {
455
+ node,
456
+ hasSingleRootChild: hasSingleRootChild(children),
457
+ isLastEffectiveChild
458
+ };
459
+ childContextInfoCache.set(this, childInfo);
460
+ return childInfo;
461
+ }
462
+ isSingleRootChild(childInfo) {
463
+ if (this.inVFor || !childInfo.hasSingleRootChild) return false;
464
+ if (this.node.type === 0) return true;
465
+ return this.node.type === 1 && this.node.tagType === 3 && !!this.parent && this.isSingleRoot;
424
466
  }
425
467
  };
468
+ function hasSingleRootChild(children) {
469
+ let nonCommentChildren = 0;
470
+ let hasEncounteredIf = false;
471
+ let isSingleIfBlock = true;
472
+ for (const child of children) {
473
+ if ((0, _vue_compiler_dom.isCommentOrWhitespace)(child)) continue;
474
+ nonCommentChildren++;
475
+ if (isIfChild(child)) {
476
+ if (hasEncounteredIf) isSingleIfBlock = false;
477
+ hasEncounteredIf = true;
478
+ } else if (!hasEncounteredIf || !isElseChild(child)) isSingleIfBlock = false;
479
+ }
480
+ return nonCommentChildren === 1 || isSingleIfBlock;
481
+ }
482
+ function isComponentChild(child) {
483
+ return child.type === 1 && child.tagType === 1;
484
+ }
485
+ function isIfChild(child) {
486
+ return child.type === 9 || child.type === 1 && !!(0, _vue_compiler_dom.findDir)(child, "if");
487
+ }
488
+ function isElseChild(child) {
489
+ return child.type === 1 && !!(0, _vue_compiler_dom.findDir)(child, /^else(-if)?$/, true);
490
+ }
426
491
  const defaultOptions = {
427
492
  filename: "",
428
493
  prefixIdentifiers: true,
@@ -446,6 +511,7 @@ const defaultOptions = {
446
511
  bindingMetadata: _vue_shared.EMPTY_OBJ,
447
512
  inline: false,
448
513
  isTS: false,
514
+ eventDelegation: true,
449
515
  onError: _vue_compiler_dom.defaultOnError,
450
516
  onWarn: _vue_compiler_dom.defaultOnWarn
451
517
  };
@@ -684,7 +750,10 @@ function genPrependNode(oper, { helper }) {
684
750
  //#endregion
685
751
  //#region packages/compiler-vapor/src/generators/expression.ts
686
752
  function genExpression(node, context, assignment) {
753
+ node = context.getExpressionReplacement(node);
687
754
  const { content, ast, isStatic, loc } = node;
755
+ const { options } = context;
756
+ const { inline } = options;
688
757
  if (isStatic) return [[
689
758
  JSON.stringify(content),
690
759
  -2,
@@ -706,23 +775,31 @@ function genExpression(node, context, assignment) {
706
775
  let hasMemberExpression = false;
707
776
  if (ids.length) {
708
777
  const [frag, push] = buildCodeFragment();
709
- ids.sort((a, b) => a.start - b.start).forEach((id, i) => {
710
- const start = id.start - 1;
711
- const end = id.end - 1;
712
- const last = ids[i - 1];
713
- const leadingText = content.slice(last ? last.end - 1 : 0, start);
714
- if (leadingText.length) push([leadingText, -3]);
715
- const source = content.slice(start, end);
778
+ let lastEnd = 0;
779
+ ids.sort((a, b) => a.start - b.start).forEach((id) => {
780
+ const idStart = id.start - 1;
781
+ const idEnd = id.end - 1;
782
+ const source = content.slice(idStart, idEnd);
716
783
  const parentStack = parentStackMap.get(id);
717
784
  const parent = parentStack[parentStack.length - 1];
785
+ let start = idStart;
786
+ let end = idEnd;
787
+ if (inline && options.bindingMetadata && options.bindingMetadata[source] === "setup-let" && parent && parent.type === "UpdateExpression" && parent.argument === id) {
788
+ start = parent.start - 1;
789
+ end = parent.end - 1;
790
+ }
791
+ if (start < lastEnd) return;
792
+ const leadingText = content.slice(lastEnd, start);
793
+ if (leadingText.length) push([leadingText, -3]);
718
794
  hasMemberExpression || (hasMemberExpression = parent && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression"));
719
795
  push(...genIdentifier(source, context, {
720
796
  start: (0, _vue_compiler_dom.advancePositionWithClone)(node.loc.start, source, start),
721
797
  end: (0, _vue_compiler_dom.advancePositionWithClone)(node.loc.start, source, end),
722
798
  source
723
- }, hasMemberExpression ? void 0 : assignment, id, parent, parentStack));
724
- if (i === ids.length - 1 && end < content.length) push([content.slice(end), -3]);
799
+ }, hasMemberExpression ? void 0 : assignment, id, parent, parentStack, node));
800
+ lastEnd = end;
725
801
  });
802
+ if (lastEnd < content.length) push([content.slice(lastEnd), -3]);
726
803
  if (assignment && hasMemberExpression) push(` = ${assignment}`);
727
804
  return frag;
728
805
  } else return [[
@@ -731,7 +808,7 @@ function genExpression(node, context, assignment) {
731
808
  loc
732
809
  ]];
733
810
  }
734
- function genIdentifier(raw, context, loc, assignment, id, parent, parentStack) {
811
+ function genIdentifier(raw, context, loc, assignment, id, parent, parentStack, sourceNode) {
735
812
  const { options, helper, identifiers } = context;
736
813
  const { inline, bindingMetadata } = options;
737
814
  let name = raw;
@@ -751,19 +828,49 @@ function genIdentifier(raw, context, loc, assignment, id, parent, parentStack) {
751
828
  else return genExpression(replacement, context, assignment);
752
829
  }
753
830
  let prefix;
754
- if ((0, _vue_compiler_dom.isStaticProperty)(parent) && parent.shorthand) prefix = `${raw}: `;
755
831
  const type = bindingMetadata && bindingMetadata[raw];
832
+ const isDestructureAssignment = parent && (0, _vue_compiler_dom.isInDestructureAssignment)(parent, parentStack || []);
833
+ const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
834
+ const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
835
+ if ((0, _vue_compiler_dom.isStaticProperty)(parent) && parent.shorthand && !(inline && type === "setup-let" && isDestructureAssignment)) prefix = `${raw}: `;
756
836
  if (inline) switch (type) {
757
837
  case "setup-let":
758
- name = raw = assignment ? `_isRef(${raw}) ? (${raw}.value = ${assignment}) : (${raw} = ${assignment})` : unref();
838
+ if (isAssignmentLVal) {
839
+ const { right, operator } = parent;
840
+ const source = sourceNode;
841
+ const sourceContent = source.content;
842
+ const rightStart = right.start - 1;
843
+ const rightEnd = right.end - 1;
844
+ const rightContent = sourceContent.slice(rightStart, rightEnd);
845
+ const rightExp = (0, _vue_compiler_dom.createSimpleExpression)(rightContent, false, {
846
+ start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, sourceContent, rightStart),
847
+ end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, sourceContent, rightEnd),
848
+ source: rightContent
849
+ });
850
+ rightExp.ast = parseExp(context, rightContent);
851
+ return [
852
+ prefix,
853
+ `${helper("isRef")}(${raw}) ? ${raw}.value ${operator} `,
854
+ ...genExpression(rightExp, context),
855
+ ` : `,
856
+ [
857
+ raw,
858
+ -2,
859
+ loc,
860
+ name
861
+ ]
862
+ ];
863
+ } else if (isUpdateArg) {
864
+ const { prefix: isPrefix, operator } = parent;
865
+ const updatePrefix = isPrefix ? operator : ``;
866
+ const updatePostfix = isPrefix ? `` : operator;
867
+ raw = `${helper("isRef")}(${raw}) ? ${updatePrefix}${raw}.value${updatePostfix} : ${updatePrefix}${raw}${updatePostfix}`;
868
+ } else if (!isDestructureAssignment) name = raw = assignment ? `${helper("isRef")}(${raw}) ? (${raw}.value = ${assignment}) : (${raw} = ${assignment})` : unref();
759
869
  break;
760
870
  case "setup-ref":
761
871
  name = raw = withAssignment(`${raw}.value`);
762
872
  break;
763
873
  case "setup-maybe-ref":
764
- const isDestructureAssignment = parent && (0, _vue_compiler_dom.isInDestructureAssignment)(parent, parentStack || []);
765
- const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
766
- const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
767
874
  raw = isAssignmentLVal || isUpdateArg || isDestructureAssignment ? name = `${raw}.value` : assignment ? `${helper("isRef")}(${raw}) ? (${raw}.value = ${assignment}) : null` : unref();
768
875
  break;
769
876
  case "props":
@@ -798,28 +905,35 @@ function canPrefix(name) {
798
905
  return true;
799
906
  }
800
907
  function processExpressions(context, expressions, shouldDeclare) {
801
- const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
908
+ const expressionReplacements = /* @__PURE__ */ new Map();
909
+ const { seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
802
910
  const reservedNames = new Set(seenIdentifier);
803
- const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
804
- const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
805
- return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
911
+ const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable, reservedNames, expressionReplacements);
912
+ const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expressionRecords, reservedNames, expressionReplacements);
913
+ return {
914
+ ...genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare),
915
+ expressionReplacements
916
+ };
806
917
  }
807
918
  function analyzeExpressions(expressions) {
808
919
  const seenVariable = Object.create(null);
809
920
  const variableToExpMap = /* @__PURE__ */ new Map();
810
- const expToVariableMap = /* @__PURE__ */ new Map();
921
+ const expressionRecords = /* @__PURE__ */ new Map();
811
922
  const seenIdentifier = /* @__PURE__ */ new Set();
812
923
  const updatedVariable = /* @__PURE__ */ new Set();
924
+ const getRecord = (exp) => {
925
+ let record = expressionRecords.get(exp);
926
+ if (!record) expressionRecords.set(exp, record = { variables: [] });
927
+ return record;
928
+ };
813
929
  const registerVariable = (name, exp, isIdentifier, loc, parentStack = []) => {
814
930
  if (isIdentifier) seenIdentifier.add(name);
815
931
  seenVariable[name] = (seenVariable[name] || 0) + 1;
816
932
  variableToExpMap.set(name, (variableToExpMap.get(name) || /* @__PURE__ */ new Set()).add(exp));
817
- const variables = expToVariableMap.get(exp) || [];
818
- variables.push({
933
+ getRecord(exp).variables.push({
819
934
  name,
820
935
  loc
821
936
  });
822
- expToVariableMap.set(exp, variables);
823
937
  if (parentStack.some((p) => p.type === "UpdateExpression" || p.type === "AssignmentExpression")) updatedVariable.add(name);
824
938
  };
825
939
  for (const exp of expressions) {
@@ -856,13 +970,20 @@ function analyzeExpressions(expressions) {
856
970
  seenVariable,
857
971
  seenIdentifier,
858
972
  variableToExpMap,
859
- expToVariableMap,
973
+ expressionRecords,
860
974
  updatedVariable
861
975
  };
862
976
  }
863
- function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames) {
977
+ function getProcessedExpression(exp, expressionReplacements) {
978
+ return expressionReplacements.get(exp) || exp;
979
+ }
980
+ function setExpressionReplacement(expressionReplacements, exp, content, ast) {
981
+ expressionReplacements.set(exp, (0, _vue_shared.extend)({ ast }, (0, _vue_compiler_dom.createSimpleExpression)(content, exp.isStatic, exp.loc, exp.constType)));
982
+ }
983
+ function processRepeatedVariables(context, seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
864
984
  const declarations = [];
865
- const expToReplacementMap = /* @__PURE__ */ new Map();
985
+ const declaredNames = /* @__PURE__ */ new Set();
986
+ const replacementPlan = /* @__PURE__ */ new Map();
866
987
  for (const [name, exps] of variableToExpMap) {
867
988
  if (updatedVariable.has(name)) continue;
868
989
  if ((0, _vue_shared.isGloballyAllowed)(name)) continue;
@@ -871,95 +992,201 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
871
992
  const varName = isIdentifier ? name : getUniqueDeclarationName(genVarName(name), reservedNames);
872
993
  exps.forEach((node) => {
873
994
  if (node.ast && varName !== name) {
874
- const replacements = expToReplacementMap.get(node) || [];
875
- replacements.push({
876
- name: varName,
877
- locs: expToVariableMap.get(node).reduce((locs, v) => {
878
- if (v.name === name && v.loc) locs.push(v.loc);
879
- return locs;
880
- }, [])
995
+ for (const variable of getExpressionVariables(expressionRecords, node)) if (variable.name === name && variable.loc) queueContentReplacement(replacementPlan, node, {
996
+ start: variable.loc.start - 1,
997
+ end: variable.loc.end - 1,
998
+ content: varName
881
999
  });
882
- expToReplacementMap.set(node, replacements);
883
1000
  }
884
1001
  });
885
- if (!declarations.some((d) => d.name === varName) && (!isIdentifier || shouldDeclareVariable(name, expToVariableMap, exps))) declarations.push({
886
- name: varName,
887
- isIdentifier,
888
- value: (0, _vue_shared.extend)({ ast: isIdentifier ? null : parseExp(context, name) }, (0, _vue_compiler_dom.createSimpleExpression)(name)),
889
- rawName: name,
890
- exps,
891
- seenCount: seenVariable[name]
892
- });
1002
+ if (!declaredNames.has(varName) && (!isIdentifier || shouldDeclareVariable(name, expressionRecords, exps))) {
1003
+ declaredNames.add(varName);
1004
+ declarations.push({
1005
+ name: varName,
1006
+ isIdentifier,
1007
+ value: (0, _vue_shared.extend)({ ast: isIdentifier ? null : parseExp(context, name) }, (0, _vue_compiler_dom.createSimpleExpression)(name)),
1008
+ rawName: name,
1009
+ exps,
1010
+ seenCount: seenVariable[name]
1011
+ });
1012
+ }
893
1013
  }
894
1014
  }
895
- for (const [exp, replacements] of expToReplacementMap) {
896
- replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
897
- start,
898
- end,
899
- name
900
- }))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
901
- exp.content = exp.content.slice(0, start - 1) + name + exp.content.slice(end - 1);
902
- });
903
- exp.ast = parseExp(context, exp.content);
904
- }
1015
+ applyReplacementPlan(context, expressionReplacements, replacementPlan);
905
1016
  return declarations;
906
1017
  }
907
- function shouldDeclareVariable(name, expToVariableMap, exps) {
908
- const vars = Array.from(exps, (exp) => expToVariableMap.get(exp).map((v) => v.name));
909
- if (vars.every((v) => v.length === 1)) return true;
910
- if (vars.some((v) => v.filter((e) => e === name).length > 1)) return true;
911
- const first = vars[0];
912
- if (vars.some((v) => v.length !== first.length)) {
913
- 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;
1018
+ function shouldDeclareVariable(name, expressionRecords, exps) {
1019
+ const variableUsages = [];
1020
+ let allSingleVariable = true;
1021
+ let hasRepeatedName = false;
1022
+ let hasDifferentLength = false;
1023
+ outer: for (const exp of exps) {
1024
+ const variables = getExpressionVariables(expressionRecords, exp);
1025
+ if (allSingleVariable && variables.length !== 1) allSingleVariable = false;
1026
+ if (!hasDifferentLength && variableUsages.length > 0 && variables.length !== variableUsages[0].length) hasDifferentLength = true;
1027
+ let nameCount = 0;
1028
+ for (const variable of variables) if (variable.name === name && ++nameCount > 1) {
1029
+ hasRepeatedName = true;
1030
+ break outer;
1031
+ }
1032
+ variableUsages.push(variables);
1033
+ }
1034
+ if (allSingleVariable) return true;
1035
+ if (hasRepeatedName) return true;
1036
+ const first = variableUsages[0];
1037
+ if (hasDifferentLength) {
1038
+ for (const variables of variableUsages) {
1039
+ if (variables.length === first.length) continue;
1040
+ const longer = variables.length > first.length ? variables : first;
1041
+ const shorter = variables.length > first.length ? first : variables;
1042
+ const shorterNames = /* @__PURE__ */ new Set();
1043
+ for (const variable of shorter) shorterNames.add(variable.name);
1044
+ let isSubset = true;
1045
+ for (const variable of longer) if (!shorterNames.has(variable.name)) {
1046
+ isSubset = false;
1047
+ break;
1048
+ }
1049
+ if (isSubset) return false;
1050
+ }
914
1051
  return true;
915
1052
  }
916
- if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
917
- return true;
1053
+ for (const variables of variableUsages) for (let i = 0; i < variables.length; i++) if (variables[i].name !== first[i].name) return true;
1054
+ return false;
918
1055
  }
919
- function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
1056
+ function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expressionRecords, reservedNames, expressionReplacements) {
920
1057
  const declarations = [];
921
- const seenExp = expressions.reduce((acc, exp) => {
922
- const vars = expToVariableMap.get(exp);
923
- if (!vars) return acc;
924
- const variables = vars.map((v) => v.name);
925
- if (exp.ast && exp.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v))) && !variables.some((v) => (0, _vue_shared.isGloballyAllowed)(v))) acc[exp.content] = (acc[exp.content] || 0) + 1;
926
- return acc;
927
- }, Object.create(null));
928
- Object.entries(seenExp).forEach(([content, count]) => {
929
- if (count > 1) {
930
- const delVars = {};
931
- for (let i = varDeclarations.length - 1; i >= 0; i--) {
932
- const item = varDeclarations[i];
933
- if (!item.exps || !item.seenCount) continue;
934
- if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
935
- delVars[item.name] = item.rawName;
936
- reservedNames.delete(item.name);
937
- varDeclarations.splice(i, 1);
938
- }
939
- }
940
- const value = (0, _vue_shared.extend)({}, expressions.find((exp) => exp.content === content));
941
- Object.keys(delVars).forEach((name) => {
942
- value.content = value.content.replace(name, delVars[name]);
943
- if (value.ast) value.ast = parseExp(context, value.content);
944
- });
945
- const varName = getUniqueDeclarationName(genVarName(content), reservedNames);
946
- declarations.push({
947
- name: varName,
948
- value
1058
+ const seenExp = /* @__PURE__ */ new Map();
1059
+ for (const exp of expressions) {
1060
+ var _expressionRecords$ge;
1061
+ const vars = (_expressionRecords$ge = expressionRecords.get(exp)) === null || _expressionRecords$ge === void 0 ? void 0 : _expressionRecords$ge.variables;
1062
+ if (!vars) continue;
1063
+ const processed = getProcessedExpression(exp, expressionReplacements);
1064
+ if (canCacheExpression(processed, vars, updatedVariable)) {
1065
+ const seen = seenExp.get(processed.content);
1066
+ if (seen) seen.count++;
1067
+ else seenExp.set(processed.content, {
1068
+ count: 1,
1069
+ first: exp
949
1070
  });
950
- expressions.forEach((exp) => {
951
- if (exp.content === content) {
952
- exp.content = varName;
953
- exp.ast = null;
954
- } else if (exp.content.includes(content)) {
955
- exp.content = exp.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
956
- exp.ast = parseExp(context, exp.content);
1071
+ }
1072
+ }
1073
+ const repeatedExpressions = [...seenExp].sort(([contentA], [contentB]) => contentB.length - contentA.length);
1074
+ for (const [content, { count, first }] of repeatedExpressions) if (count > 1) {
1075
+ const removedDeclarations = [];
1076
+ for (let i = varDeclarations.length - 1; i >= 0; i--) {
1077
+ const item = varDeclarations[i];
1078
+ if (!item.exps || !item.seenCount) continue;
1079
+ if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
1080
+ removedDeclarations.push({
1081
+ name: item.name,
1082
+ rawName: item.rawName
1083
+ });
1084
+ reservedNames.delete(item.name);
1085
+ varDeclarations.splice(i, 1);
1086
+ }
1087
+ }
1088
+ const value = (0, _vue_shared.extend)({}, getProcessedExpression(first, expressionReplacements));
1089
+ const restorePlan = [];
1090
+ for (const { name, rawName } of removedDeclarations) restorePlan.push(...findIdentifierReplacements(value, name, rawName));
1091
+ if (restorePlan.length) {
1092
+ value.content = applyContentReplacements(value.content, restorePlan);
1093
+ if (value.ast) value.ast = parseExp(context, value.content);
1094
+ }
1095
+ const varName = getUniqueDeclarationName(genVarName(content), reservedNames);
1096
+ declarations.push({
1097
+ name: varName,
1098
+ value
1099
+ });
1100
+ for (const exp of expressions) {
1101
+ const processed = getProcessedExpression(exp, expressionReplacements);
1102
+ if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
1103
+ else if (processed.content.includes(content)) {
1104
+ const replacements = findContentReplacements(processed, content, varName);
1105
+ if (replacements.length) {
1106
+ const replacedContent = applyContentReplacements(processed.content, replacements);
1107
+ setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
957
1108
  }
958
- });
1109
+ }
959
1110
  }
960
- });
1111
+ }
961
1112
  return declarations;
962
1113
  }
1114
+ function canCacheExpression(processed, vars, updatedVariable) {
1115
+ if (!processed.ast || processed.ast.type === "Identifier") return false;
1116
+ for (const { name } of vars) if (updatedVariable.has(name) || (0, _vue_shared.isGloballyAllowed)(name)) return false;
1117
+ return true;
1118
+ }
1119
+ function getExpressionVariables(expressionRecords, exp) {
1120
+ var _expressionRecords$ge2;
1121
+ return ((_expressionRecords$ge2 = expressionRecords.get(exp)) === null || _expressionRecords$ge2 === void 0 ? void 0 : _expressionRecords$ge2.variables) || [];
1122
+ }
1123
+ function queueContentReplacement(replacementPlan, exp, replacement) {
1124
+ const replacements = replacementPlan.get(exp);
1125
+ if (replacements) replacements.push(replacement);
1126
+ else replacementPlan.set(exp, [replacement]);
1127
+ }
1128
+ function applyReplacementPlan(context, expressionReplacements, replacementPlan) {
1129
+ for (const [exp, replacements] of replacementPlan) {
1130
+ if (!replacements.length) continue;
1131
+ const content = applyContentReplacements(getProcessedExpression(exp, expressionReplacements).content, replacements);
1132
+ setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
1133
+ }
1134
+ }
1135
+ function findContentReplacements(exp, content, replacement) {
1136
+ const identifiers = getIdentifierRanges(exp);
1137
+ if (!identifiers.length) return [];
1138
+ const replacements = [];
1139
+ let searchStart = 0;
1140
+ let start = exp.content.indexOf(content, searchStart);
1141
+ while (start !== -1) {
1142
+ const end = start + content.length;
1143
+ let canReplace = false;
1144
+ for (const identifier of identifiers) {
1145
+ if (start >= identifier.end || end <= identifier.start) continue;
1146
+ if (start > identifier.start || end < identifier.end) {
1147
+ canReplace = false;
1148
+ break;
1149
+ }
1150
+ canReplace = true;
1151
+ }
1152
+ if (canReplace) {
1153
+ replacements.push({
1154
+ start,
1155
+ end,
1156
+ content: replacement
1157
+ });
1158
+ searchStart = end;
1159
+ } else searchStart = start + 1;
1160
+ start = exp.content.indexOf(content, searchStart);
1161
+ }
1162
+ return replacements;
1163
+ }
1164
+ function findIdentifierReplacements(exp, name, replacement) {
1165
+ const replacements = [];
1166
+ for (const { start, end } of getIdentifierRanges(exp)) if (exp.content.slice(start, end) === name) replacements.push({
1167
+ start,
1168
+ end,
1169
+ content: replacement
1170
+ });
1171
+ return replacements;
1172
+ }
1173
+ function getIdentifierRanges(exp) {
1174
+ if (!exp.ast || typeof exp.ast !== "object") return [];
1175
+ const identifiers = [];
1176
+ (0, _vue_compiler_dom.walkIdentifiers)(exp.ast, (id) => {
1177
+ identifiers.push({
1178
+ start: id.start - 1,
1179
+ end: id.end - 1
1180
+ });
1181
+ }, false);
1182
+ return identifiers;
1183
+ }
1184
+ function applyContentReplacements(content, replacements) {
1185
+ replacements.sort((a, b) => b.start - a.start).forEach(({ start, end, content: replacement }) => {
1186
+ content = content.slice(0, start) + replacement + content.slice(end);
1187
+ });
1188
+ return content;
1189
+ }
963
1190
  function genDeclarations(declarations, context, shouldDeclare) {
964
1191
  const [frag, push] = buildCodeFragment();
965
1192
  const ids = Object.create(null);
@@ -987,9 +1214,6 @@ function genDeclarations(declarations, context, shouldDeclare) {
987
1214
  varNames: [...varNames]
988
1215
  };
989
1216
  }
990
- function escapeRegExp(string) {
991
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
992
- }
993
1217
  function parseExp(context, content, loc) {
994
1218
  try {
995
1219
  return (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
@@ -1042,22 +1266,31 @@ const isMemberExpression$3 = (node) => {
1042
1266
  function genSetEvent(oper, context) {
1043
1267
  const { helper } = context;
1044
1268
  const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
1045
- const name = genName();
1046
- const handler = [
1047
- `${context.helper("createInvoker")}(`,
1048
- ...genEventHandler(context, [value], modifiers),
1049
- `)`
1050
- ];
1051
- const eventOptions = genEventOptions();
1269
+ let handler;
1052
1270
  if (delegate) {
1053
1271
  context.delegates.add(key.content);
1054
1272
  if (!context.block.operation.some(isSameDelegateEvent)) return [
1055
1273
  NEWLINE,
1056
1274
  `n${element}.$evt${key.content} = `,
1057
- ...handler
1275
+ ...genDirectHandler()
1058
1276
  ];
1059
1277
  }
1060
- return [NEWLINE, ...genCall(helper(delegate ? "delegate" : "on"), `n${element}`, name, handler, eventOptions)];
1278
+ const name = genName();
1279
+ const eventOptions = genEventOptions();
1280
+ return [NEWLINE, ...genCall(helper(effect ? "onBinding" : delegate ? "delegate" : "on"), `n${element}`, name, genHandler(), eventOptions)];
1281
+ function genHandler() {
1282
+ return handler || (handler = genEventHandler(context, [value], modifiers));
1283
+ }
1284
+ function genInvoker() {
1285
+ return [
1286
+ `${helper("createInvoker")}(`,
1287
+ ...genHandler(),
1288
+ `)`
1289
+ ];
1290
+ }
1291
+ function genDirectHandler() {
1292
+ return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
1293
+ }
1061
1294
  function genName() {
1062
1295
  const expr = genExpression(key, context);
1063
1296
  if (keyOverride) {
@@ -1077,8 +1310,8 @@ function genSetEvent(oper, context) {
1077
1310
  }
1078
1311
  function genEventOptions() {
1079
1312
  let { options } = modifiers;
1080
- if (!options.length && !effect) return;
1081
- return genMulti(DELIMITERS_OBJECT_NEWLINE, effect && ["effect: true"], ...options.map((option) => [`${option}: true`]));
1313
+ if (!options.length) return;
1314
+ return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
1082
1315
  }
1083
1316
  function isSameDelegateEvent(op) {
1084
1317
  if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
@@ -1091,7 +1324,9 @@ function genSetDynamicEvents(oper, context) {
1091
1324
  function genEventHandler(context, values, modifiers = {
1092
1325
  nonKeys: [],
1093
1326
  keys: []
1094
- }, asComponentProp = false, extraWrap = false) {
1327
+ }, options = {}) {
1328
+ const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
1329
+ const useVaporModifierHelper = modifierHelper === "vapor";
1095
1330
  let handlerExp = [];
1096
1331
  if (values) {
1097
1332
  values.forEach((value, index) => {
@@ -1132,16 +1367,16 @@ function genEventHandler(context, values, modifiers = {
1132
1367
  }
1133
1368
  if (handlerExp.length === 0) handlerExp = ["() => {}"];
1134
1369
  const { keys, nonKeys } = modifiers;
1135
- if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
1136
- if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
1370
+ if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys, useVaporModifierHelper && !keys.length);
1371
+ if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys, useVaporModifierHelper);
1137
1372
  if (extraWrap) handlerExp.unshift(`() => `);
1138
1373
  return handlerExp;
1139
1374
  }
1140
- function genWithModifiers(context, handler, nonKeys) {
1141
- return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
1375
+ function genWithModifiers(context, handler, nonKeys, useVaporHelper = false) {
1376
+ return genCall(context.helper(useVaporHelper ? "withVaporModifiers" : "withModifiers"), handler, JSON.stringify(nonKeys));
1142
1377
  }
1143
- function genWithKeys(context, handler, keys) {
1144
- return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
1378
+ function genWithKeys(context, handler, keys, useVaporHelper = false) {
1379
+ return genCall(context.helper(useVaporHelper ? "withVaporKeys" : "withKeys"), handler, JSON.stringify(keys));
1145
1380
  }
1146
1381
  function isConstantBinding(value, context) {
1147
1382
  if (value.ast === null) {
@@ -1152,7 +1387,7 @@ function isConstantBinding(value, context) {
1152
1387
  //#region packages/compiler-vapor/src/generators/for.ts
1153
1388
  function genFor(oper, context) {
1154
1389
  const { helper } = context;
1155
- const { source, value, key, index, render, keyProp, once, id, component, onlyChild } = oper;
1390
+ const { source, value, key, index, render, keyProp, once, id, component, onlyChild, slotRoot } = oper;
1156
1391
  const rawValue = value && value.content;
1157
1392
  const rawKey = key && key.content;
1158
1393
  const rawIndex = index && index.content;
@@ -1179,7 +1414,7 @@ function genFor(oper, context) {
1179
1414
  idMap[rawIndex] = `${indexVar}.value`;
1180
1415
  idMap[indexVar] = null;
1181
1416
  }
1182
- const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap, context);
1417
+ const { selectorPatterns, keyOnlyBindingPatterns, skippedEffectIndexes } = matchPatterns(render, keyProp, idMap, context);
1183
1418
  const selectorDeclarations = [];
1184
1419
  const selectorName = (i) => selectorPatterns.length > 1 ? `_selector${id}_${i}` : `_selector${id}`;
1185
1420
  for (let i = 0; i < selectorPatterns.length; i++) {
@@ -1199,23 +1434,20 @@ function genFor(oper, context) {
1199
1434
  }
1200
1435
  for (const { effect } of keyOnlyBindingPatterns) for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
1201
1436
  return patternFrag;
1202
- }));
1437
+ }, skippedEffectIndexes));
1203
1438
  else frag.push(...genBlockContent(render, context));
1204
1439
  frag.push(INDENT_END, NEWLINE, "}");
1205
1440
  return frag;
1206
1441
  }, idMap);
1207
1442
  exitScope();
1208
- let flags = 0;
1209
- if (onlyChild) flags |= 1;
1210
- if (component) flags |= 2;
1211
- if (once) flags |= 4;
1443
+ const flags = genForFlags(onlyChild, component, isFragmentBlock(render), !component && isSingleNodeBlock(render), once, slotRoot);
1212
1444
  const onResetCalls = [];
1213
1445
  for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
1214
1446
  return [
1215
1447
  NEWLINE,
1216
1448
  ...selectorDeclarations,
1217
1449
  `const n${id} = `,
1218
- ...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0),
1450
+ ...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags),
1219
1451
  ...onResetCalls
1220
1452
  ];
1221
1453
  function genCallback(expr) {
@@ -1240,6 +1472,51 @@ function genFor(oper, context) {
1240
1472
  return idMap;
1241
1473
  }
1242
1474
  }
1475
+ function genForFlags(onlyChild, component, isFragment, isSingleNode, once, slotRoot) {
1476
+ let flags = 0;
1477
+ const names = [];
1478
+ if (onlyChild) {
1479
+ flags |= 1;
1480
+ names.push("FAST_REMOVE");
1481
+ }
1482
+ if (component) {
1483
+ flags |= 2;
1484
+ names.push("IS_COMPONENT");
1485
+ }
1486
+ if (isFragment) {
1487
+ flags |= 16;
1488
+ names.push("IS_FRAGMENT");
1489
+ }
1490
+ if (isSingleNode) {
1491
+ flags |= 8;
1492
+ names.push("IS_SINGLE_NODE");
1493
+ }
1494
+ if (once) {
1495
+ flags |= 4;
1496
+ names.push("ONCE");
1497
+ }
1498
+ if (slotRoot) {
1499
+ flags |= 32;
1500
+ names.push("SLOT_ROOT");
1501
+ }
1502
+ if (!flags) return;
1503
+ return `${flags} /* ${names.join(", ")} */`;
1504
+ }
1505
+ function isSingleNodeBlock(block) {
1506
+ const child = getSingleReturnedChild(block);
1507
+ return !!child && child.template != null;
1508
+ }
1509
+ function isFragmentBlock(block) {
1510
+ const child = getSingleReturnedChild(block);
1511
+ const operation = child && child.operation;
1512
+ if (!operation) return false;
1513
+ return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
1514
+ }
1515
+ function getSingleReturnedChild(block) {
1516
+ if (block.returns.length !== 1) return;
1517
+ const id = block.returns[0];
1518
+ for (const child of block.dynamic.children) if (child.id === id) return child;
1519
+ }
1243
1520
  function parseValueDestructure(value, context) {
1244
1521
  const map = /* @__PURE__ */ new Map();
1245
1522
  if (value) {
@@ -1277,7 +1554,8 @@ function parseValueDestructure(value, context) {
1277
1554
  if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
1278
1555
  isDynamic = true;
1279
1556
  helper = isDom2 ? context.helper("getSharedDataDefaultValue") : context.helper("getDefaultValue");
1280
- helperArgs = rawValue.slice(child.right.start - 1, child.right.end - 1);
1557
+ const rawDefault = rawValue.slice(child.right.start - 1, child.right.end - 1);
1558
+ helperArgs = isDom2 ? rawDefault : `() => (${rawDefault})`;
1281
1559
  }
1282
1560
  }
1283
1561
  map.set(id.name, {
@@ -1313,39 +1591,35 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
1313
1591
  function matchPatterns(render, keyProp, idMap, context) {
1314
1592
  const selectorPatterns = [];
1315
1593
  const keyOnlyBindingPatterns = [];
1316
- const removedEffectIndexes = [];
1317
- render.effect = render.effect.filter((effect, index) => {
1318
- if (keyProp !== void 0) {
1319
- const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
1320
- if (selector) {
1321
- selectorPatterns.push(selector);
1322
- removedEffectIndexes.push(index);
1323
- return false;
1324
- }
1325
- const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
1326
- if (keyOnly) {
1327
- keyOnlyBindingPatterns.push(keyOnly);
1328
- removedEffectIndexes.push(index);
1329
- return false;
1330
- }
1594
+ let skippedEffectIndexes;
1595
+ if (keyProp === void 0) return {
1596
+ keyOnlyBindingPatterns,
1597
+ selectorPatterns,
1598
+ skippedEffectIndexes
1599
+ };
1600
+ for (let index = 0; index < render.effect.length; index++) {
1601
+ const effect = render.effect[index];
1602
+ const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
1603
+ if (selector) {
1604
+ selectorPatterns.push(selector);
1605
+ skipEffect(index);
1606
+ continue;
1331
1607
  }
1332
- return true;
1333
- });
1334
- if (removedEffectIndexes.length) shiftEffectBoundaries(render.dynamic, removedEffectIndexes);
1608
+ const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
1609
+ if (keyOnly) {
1610
+ keyOnlyBindingPatterns.push(keyOnly);
1611
+ skipEffect(index);
1612
+ }
1613
+ }
1335
1614
  return {
1336
1615
  keyOnlyBindingPatterns,
1337
- selectorPatterns
1616
+ selectorPatterns,
1617
+ skippedEffectIndexes
1338
1618
  };
1339
- }
1340
- function shiftEffectBoundaries(dynamic, removedEffectIndexes) {
1341
- const operation = dynamic.operation;
1342
- if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0) {
1343
- let offset = 0;
1344
- for (const removedIndex of removedEffectIndexes) if (removedIndex < operation.effectIndex) offset++;
1345
- else break;
1346
- operation.effectIndex -= offset;
1619
+ function skipEffect(index) {
1620
+ if (!skippedEffectIndexes) skippedEffectIndexes = /* @__PURE__ */ new Set();
1621
+ skippedEffectIndexes.add(index);
1347
1622
  }
1348
- for (const child of dynamic.children) shiftEffectBoundaries(child, removedEffectIndexes);
1349
1623
  }
1350
1624
  function matchKeyOnlyBindingPattern(effect, key) {
1351
1625
  if (effect.expressions.length === 1) {
@@ -1425,8 +1699,9 @@ function genSetHtml(oper, context) {
1425
1699
  //#region packages/compiler-vapor/src/generators/if.ts
1426
1700
  function genIf(oper, context, isNested = false) {
1427
1701
  const { helper } = context;
1428
- const { condition, positive, negative, once, index, blockShape } = oper;
1702
+ const { condition, positive, negative, once, slotRoot, index, blockShape } = oper;
1429
1703
  const [frag, push] = buildCodeFragment();
1704
+ const flags = genIfFlags(blockShape, once, slotRoot, negative ? index : void 0);
1430
1705
  const conditionExpr = [
1431
1706
  "() => (",
1432
1707
  ...genExpression(condition, context),
@@ -1437,9 +1712,37 @@ function genIf(oper, context, isNested = false) {
1437
1712
  if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
1438
1713
  else negativeArg = ["() => ", ...genIf(negative, context, true)];
1439
1714
  if (!isNested) push(NEWLINE, `const n${oper.id} = `);
1440
- push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, String(blockShape), once && "true", index !== void 0 && negative && String(index)));
1715
+ push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
1441
1716
  return frag;
1442
1717
  }
1718
+ function genIfFlags(blockShape, once, slotRoot, index) {
1719
+ let flags = blockShape;
1720
+ if (slotRoot) flags |= 128;
1721
+ if (once) flags |= 16;
1722
+ else if (index !== void 0) flags |= index + 1 << 8;
1723
+ if (flags === 1) return false;
1724
+ return `${flags} /* ${genIfFlagNames(once, slotRoot, index, blockShape)} */`;
1725
+ }
1726
+ function genIfFlagNames(once, slotRoot, index, blockShape) {
1727
+ const names = [`TRUE_${genBlockShapeName(blockShape)}`];
1728
+ const falseShape = blockShape >> 2;
1729
+ const hasFalseBranch = (falseShape & 3) !== 0;
1730
+ if (hasFalseBranch) names.push(`FALSE_${genBlockShapeName(falseShape)}`);
1731
+ if (blockShape & 32) names.push("TRUE_NO_SCOPE");
1732
+ if (hasFalseBranch && blockShape & 64) names.push("FALSE_NO_SCOPE");
1733
+ if (once) names.push("ONCE");
1734
+ if (slotRoot) names.push("SLOT_ROOT");
1735
+ if (!once && index !== void 0) names.push(`KEYED_INDEX_${index}`);
1736
+ return names.join(", ");
1737
+ }
1738
+ function genBlockShapeName(flags) {
1739
+ switch (flags & 3) {
1740
+ case 0: return "EMPTY";
1741
+ case 1: return "SINGLE_ROOT";
1742
+ case 2: return "MULTI_ROOT";
1743
+ }
1744
+ return "UNKNOWN";
1745
+ }
1443
1746
  //#endregion
1444
1747
  //#region packages/compiler-vapor/src/generators/prop.ts
1445
1748
  const helpers = {
@@ -1489,15 +1792,16 @@ function resolveClassName(values, context) {
1489
1792
  const entries = [];
1490
1793
  let sawDynamic = false;
1491
1794
  let sawSuffix = false;
1492
- for (const value of values) {
1795
+ for (const rawValue of values) {
1796
+ const value = context.getExpressionReplacement(rawValue);
1493
1797
  const staticValue = getLiteralExpressionValue(value, true);
1494
1798
  if (staticValue != null) {
1495
1799
  const normalized = (0, _vue_shared.normalizeClass)(staticValue);
1496
- if (normalized) if (sawSuffix) suffix = appendClass(suffix, normalized);
1800
+ if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
1497
1801
  else if (sawDynamic) {
1498
1802
  sawSuffix = true;
1499
- suffix = appendClass(suffix, normalized);
1500
- } else prefix = appendClass(prefix, normalized);
1803
+ suffix = appendClass$1(suffix, normalized);
1804
+ } else prefix = appendClass$1(prefix, normalized);
1501
1805
  continue;
1502
1806
  }
1503
1807
  const ast = value.ast;
@@ -1518,7 +1822,7 @@ function resolveClassName(values, context) {
1518
1822
  function resolveObjectClassName(source, ast, entries, context) {
1519
1823
  for (const prop of ast.properties) {
1520
1824
  if (prop.type !== "ObjectProperty" || prop.computed) return false;
1521
- const rawClassName = getObjectPropertyName(prop);
1825
+ const rawClassName = getObjectPropertyName$1(prop);
1522
1826
  if (rawClassName == null) return false;
1523
1827
  const className = (0, _vue_shared.normalizeClass)(rawClassName);
1524
1828
  if (!className) continue;
@@ -1563,10 +1867,10 @@ function genClassFlags(entries, context) {
1563
1867
  });
1564
1868
  return values;
1565
1869
  }
1566
- function appendClass(base, value) {
1870
+ function appendClass$1(base, value) {
1567
1871
  return base ? value ? `${base} ${value}` : base : value;
1568
1872
  }
1569
- function getObjectPropertyName(prop) {
1873
+ function getObjectPropertyName$1(prop) {
1570
1874
  const key = prop.key;
1571
1875
  if (key.type === "Identifier") return key.name;
1572
1876
  else if (key.type === "StringLiteral") return key.value;
@@ -1620,7 +1924,12 @@ function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModi
1620
1924
  if (runtimeCamelize) {
1621
1925
  key.push(" || \"\"");
1622
1926
  key = genCall(helper("camelize"), key);
1623
- }
1927
+ } else if (modifier) key = [
1928
+ "(",
1929
+ ...key,
1930
+ " || \"\"",
1931
+ ")"
1932
+ ];
1624
1933
  if (handler) key = genCall(helper("toHandlerKey"), key);
1625
1934
  return [
1626
1935
  "[",
@@ -1658,8 +1967,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
1658
1967
  const setTemplateRefIdent = `_setTemplateRef`;
1659
1968
  function genSetTemplateRef(oper, context) {
1660
1969
  const [refValue, refKey] = genRefValue(oper.value, context);
1970
+ if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
1971
+ context.needsTemplateRefSetter = true;
1661
1972
  return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
1662
1973
  }
1974
+ function genSetStaticTemplateRef(oper, refValue, refKey, context) {
1975
+ return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
1976
+ }
1977
+ function genSetTemplateRefBinding(oper, context) {
1978
+ const [refValue, refKey] = genRefValue(oper.value, context);
1979
+ const setter = context.inSlotBlock && setTemplateRefIdent;
1980
+ if (context.inSlotBlock) context.needsTemplateRefSetter = true;
1981
+ return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
1982
+ setter,
1983
+ oper.refFor && "true",
1984
+ refKey
1985
+ ] : [])];
1986
+ }
1663
1987
  function genRefValue(value, context) {
1664
1988
  if (value && context.options.inline) {
1665
1989
  const binding = context.options.bindingMetadata[value.content];
@@ -1697,6 +2021,11 @@ function genVShow(oper, context) {
1697
2021
  ])];
1698
2022
  }
1699
2023
  //#endregion
2024
+ //#region packages/compiler-vapor/src/generators/modifier.ts
2025
+ function genDirectiveModifiers(modifiers) {
2026
+ return modifiers.map((value) => `${(0, _vue_compiler_dom.isSimpleIdentifier)(value) ? value : JSON.stringify(value)}: true`).join(", ");
2027
+ }
2028
+ //#endregion
1700
2029
  //#region packages/compiler-vapor/src/generators/vModel.ts
1701
2030
  const helperMap = {
1702
2031
  text: "applyTextModel",
@@ -1711,7 +2040,7 @@ function genVModel(oper, context) {
1711
2040
  `() => (`,
1712
2041
  ...genExpression(exp, context),
1713
2042
  `)`
1714
- ], genModelHandler(exp, context), modifiers.length ? `{ ${modifiers.map((e) => e.content + ": true").join(",")} }` : void 0)];
2043
+ ], genModelHandler(exp, context), modifiers.length ? `{ ${genDirectiveModifiers(modifiers.map((e) => e.content))} }` : void 0)];
1715
2044
  }
1716
2045
  function genModelHandler(exp, context) {
1717
2046
  return [
@@ -1753,25 +2082,31 @@ function genCustomDirectives(opers, context) {
1753
2082
  return genMulti(DELIMITERS_ARRAY.concat("void 0"), directiveVar, value, argument, modifiers);
1754
2083
  }
1755
2084
  }
1756
- function genDirectiveModifiers(modifiers) {
1757
- return modifiers.map((value) => `${(0, _vue_compiler_dom.isSimpleIdentifier)(value) ? value : JSON.stringify(value)}: true`).join(", ");
1758
- }
1759
2085
  function filterCustomDirectives(id, operations) {
1760
2086
  return operations.filter((oper) => oper.type === 14 && oper.element === id && !oper.builtin);
1761
2087
  }
1762
2088
  //#endregion
1763
2089
  //#region packages/compiler-vapor/src/generators/component.ts
2090
+ function genStaticModifierPropKey(name) {
2091
+ const key = (0, _vue_shared.getModifierPropName)(name);
2092
+ return [(0, _vue_compiler_dom.isSimpleIdentifier)(key) ? key : JSON.stringify(key)];
2093
+ }
1764
2094
  function genCreateComponent(operation, context) {
1765
2095
  const { helper } = context;
2096
+ const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
2097
+ const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
2098
+ const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
1766
2099
  const tag = genTag();
1767
- const { root, props, slots, once } = operation;
2100
+ const { root, props, slots, once, slotRoot } = operation;
2101
+ const isRuntimeDynamicComponent = !!(operation.dynamic && !operation.dynamic.isStatic);
2102
+ const dynamicComponentFlags = isRuntimeDynamicComponent ? genDynamicComponentFlags(root, once, slotRoot) : false;
1768
2103
  const rawSlots = genRawSlots(slots, context);
1769
2104
  const [ids, handlers] = processInlineHandlers(props, context);
1770
- const rawProps = context.withId(() => genRawProps(props, context), ids);
2105
+ const rawProps = context.withId(() => genRawProps(props, context, true), ids);
1771
2106
  return [
1772
2107
  NEWLINE,
1773
2108
  ...handlers.reduce((acc, { name, value }) => {
1774
- const handler = genEventHandler(context, [value], void 0, false, false);
2109
+ const handler = genEventHandler(context, [value]);
1775
2110
  return [
1776
2111
  ...acc,
1777
2112
  `const ${name} = `,
@@ -1780,7 +2115,7 @@ function genCreateComponent(operation, context) {
1780
2115
  ];
1781
2116
  }, []),
1782
2117
  `const n${operation.id} = `,
1783
- ...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"),
2118
+ ...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"),
1784
2119
  ...genDirectivesForElement(operation.id, context)
1785
2120
  ];
1786
2121
  function genTag() {
@@ -1791,7 +2126,10 @@ function genCreateComponent(operation, context) {
1791
2126
  ...genExpression(operation.dynamic, context),
1792
2127
  ")"
1793
2128
  ];
1794
- else if (operation.asset) return (0, _vue_compiler_dom.toValidAssetId)(operation.tag, "component");
2129
+ else if (useAssetComponentHelper) {
2130
+ const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
2131
+ return JSON.stringify(name);
2132
+ } else if (operation.asset) return (0, _vue_compiler_dom.toValidAssetId)(operation.tag, "component");
1795
2133
  else {
1796
2134
  const { tag } = operation;
1797
2135
  const builtInTag = isBuiltInComponent(tag);
@@ -1803,6 +2141,28 @@ function genCreateComponent(operation, context) {
1803
2141
  }
1804
2142
  }
1805
2143
  }
2144
+ function genDynamicComponentFlags(root, once, slotRoot, extraFlags) {
2145
+ let flags = 0;
2146
+ const names = [];
2147
+ if (root) {
2148
+ flags |= 1;
2149
+ names.push("SINGLE_ROOT");
2150
+ }
2151
+ if (once) {
2152
+ flags |= 2;
2153
+ names.push("ONCE");
2154
+ }
2155
+ if (slotRoot) {
2156
+ flags |= 4;
2157
+ names.push("SLOT_ROOT");
2158
+ }
2159
+ if (extraFlags) for (const [flag, name] of extraFlags) {
2160
+ flags |= flag;
2161
+ names.push(name);
2162
+ }
2163
+ if (!flags) return false;
2164
+ return `${flags} /* ${names.join(", ")} */`;
2165
+ }
1806
2166
  function getUniqueHandlerName(context, name) {
1807
2167
  const { seenInlineHandlerNames } = context;
1808
2168
  name = genVarName(name);
@@ -1831,14 +2191,14 @@ function processInlineHandlers(props, context) {
1831
2191
  }
1832
2192
  return [ids, handlers];
1833
2193
  }
1834
- function genRawProps(props, context) {
2194
+ function genRawProps(props, context, directStaticLiteralProps = false) {
1835
2195
  const staticProps = props[0];
1836
2196
  if ((0, _vue_shared.isArray)(staticProps)) {
1837
2197
  if (!staticProps.length && props.length === 1) return;
1838
- return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
1839
- } else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
2198
+ return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
2199
+ } else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
1840
2200
  }
1841
- function genStaticProps(props, context, dynamicProps) {
2201
+ function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
1842
2202
  const args = [];
1843
2203
  const handlerGroups = /* @__PURE__ */ new Map();
1844
2204
  const ensureHandlerGroup = (keyName, keyFrag) => {
@@ -1871,11 +2231,11 @@ function genStaticProps(props, context, dynamicProps) {
1871
2231
  continue;
1872
2232
  }
1873
2233
  const keyFrag = genPropKey(prop, context);
1874
- 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));
1875
- else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true, false));
2234
+ 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 }));
2235
+ else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
1876
2236
  continue;
1877
2237
  }
1878
- args.push(genProp(prop, context, true));
2238
+ args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
1879
2239
  if (prop.model) {
1880
2240
  if (prop.key.isStatic) {
1881
2241
  const keyName = `onUpdate:${(0, _vue_shared.camelize)(prop.key.content)}`;
@@ -1894,13 +2254,13 @@ function genStaticProps(props, context, dynamicProps) {
1894
2254
  }
1895
2255
  const { key, modelModifiers } = prop;
1896
2256
  if (modelModifiers && modelModifiers.length) {
1897
- const modifiersKey = key.isStatic ? [(0, _vue_shared.getModifierPropName)(key.content)] : [
2257
+ const modifiersKey = key.isStatic ? genStaticModifierPropKey(key.content) : [
1898
2258
  "[",
1899
2259
  ...genExpression(key, context),
1900
2260
  " + \"Modifiers\"]"
1901
2261
  ];
1902
2262
  const modifiersVal = genDirectiveModifiers(modelModifiers);
1903
- args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
2263
+ args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
1904
2264
  }
1905
2265
  }
1906
2266
  }
@@ -1915,13 +2275,13 @@ function genStaticProps(props, context, dynamicProps) {
1915
2275
  if (dynamicProps) args.push([`$: `, ...dynamicProps]);
1916
2276
  return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
1917
2277
  }
1918
- function genDynamicProps(props, context) {
2278
+ function genDynamicProps(props, context, directStaticLiteralProps = false) {
1919
2279
  const { helper } = context;
1920
2280
  const frags = [];
1921
2281
  for (const p of props) {
1922
2282
  let expr;
1923
2283
  if ((0, _vue_shared.isArray)(p)) {
1924
- if (p.length) frags.push(genStaticProps(p, context));
2284
+ if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
1925
2285
  continue;
1926
2286
  } else if (p.kind === 1) if (p.model) {
1927
2287
  const entries = [genProp(p, context)];
@@ -1937,7 +2297,7 @@ function genDynamicProps(props, context) {
1937
2297
  ]);
1938
2298
  const { modelModifiers } = p;
1939
2299
  if (modelModifiers && modelModifiers.length) {
1940
- const modifiersKey = p.key.isStatic ? [(0, _vue_shared.getModifierPropName)(p.key.content)] : [
2300
+ const modifiersKey = p.key.isStatic ? genStaticModifierPropKey(p.key.content) : [
1941
2301
  "[",
1942
2302
  ...genExpression(p.key, context),
1943
2303
  " + \"Modifiers\"]"
@@ -1959,27 +2319,79 @@ function genDynamicProps(props, context) {
1959
2319
  }
1960
2320
  if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
1961
2321
  }
1962
- function genProp(prop, context, isStatic, wrapHandler = true) {
2322
+ function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
1963
2323
  const values = genPropValue(prop.values, context);
1964
2324
  return [
1965
2325
  ...genPropKey(prop, context),
1966
2326
  ": ",
1967
- ...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, true, wrapHandler) : isStatic ? [
2327
+ ...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
2328
+ asComponentProp: true,
2329
+ extraWrap: wrapHandler
2330
+ }) : isStatic ? directStaticLiteral ? values : [
1968
2331
  "() => (",
1969
2332
  ...values,
1970
2333
  ")"
1971
2334
  ] : values
1972
2335
  ];
1973
2336
  }
2337
+ /**
2338
+ * Static literal values are safe to emit directly because reading them cannot
2339
+ * touch reactive state. Keep handlers, v-model values, and dynamic expressions
2340
+ * as getter sources to preserve lazy access and merge semantics.
2341
+ */
2342
+ function isDirectStaticLiteralProp(prop, context) {
2343
+ return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
2344
+ }
2345
+ function isDirectConstantValue(value, context) {
2346
+ value = context.getExpressionReplacement(value);
2347
+ if (value.isStatic) return true;
2348
+ const ast = value.ast;
2349
+ if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
2350
+ if (!ast) return false;
2351
+ return isDirectConstantAst(ast);
2352
+ }
2353
+ function isDirectConstantAst(node) {
2354
+ switch (node.type) {
2355
+ case "StringLiteral":
2356
+ case "NumericLiteral":
2357
+ case "BooleanLiteral":
2358
+ case "NullLiteral":
2359
+ case "BigIntLiteral": return true;
2360
+ case "Identifier": return node.name === "undefined";
2361
+ case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
2362
+ case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
2363
+ case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
2364
+ }
2365
+ return false;
2366
+ }
2367
+ function isDirectTemplateConstantAst(node) {
2368
+ switch (node.type) {
2369
+ case "StringLiteral":
2370
+ case "NumericLiteral":
2371
+ case "BooleanLiteral":
2372
+ case "NullLiteral":
2373
+ case "BigIntLiteral": return true;
2374
+ case "Identifier": return node.name === "undefined";
2375
+ case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
2376
+ }
2377
+ return false;
2378
+ }
1974
2379
  function genRawSlots(slots, context) {
1975
2380
  if (!slots.length) return;
1976
2381
  const staticSlots = slots[0];
1977
- if (staticSlots.slotType === 0) return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
1978
- else return genStaticSlots({
2382
+ if (staticSlots.slotType === 0) {
2383
+ const defaultSlot = getSingleDefaultSlot(staticSlots);
2384
+ if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
2385
+ return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
2386
+ } else return genStaticSlots({
1979
2387
  slotType: 0,
1980
2388
  slots: {}
1981
2389
  }, context, slots);
1982
2390
  }
2391
+ function getSingleDefaultSlot({ slots }) {
2392
+ const names = Object.keys(slots);
2393
+ return names.length === 1 && names[0] === "default" ? slots.default : void 0;
2394
+ }
1983
2395
  function genStaticSlots({ slots }, context, dynamicSlots) {
1984
2396
  const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
1985
2397
  if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
@@ -2002,26 +2414,15 @@ function genDynamicSlot(slot, context, withFunction = false) {
2002
2414
  break;
2003
2415
  }
2004
2416
  if (!withFunction) return frag;
2005
- return needsDynamicSlotSourceCtx(slot) ? [
2006
- `${context.helper("withVaporCtx")}(() => (`,
2007
- ...frag,
2008
- "))"
2009
- ] : [
2417
+ return [
2010
2418
  "() => (",
2011
2419
  ...frag,
2012
2420
  ")"
2013
2421
  ];
2014
2422
  }
2015
- function needsDynamicSlotSourceCtx(slot) {
2016
- switch (slot.slotType) {
2017
- case 1: return needsVaporCtx(slot.fn);
2018
- case 2: return needsVaporCtx(slot.fn);
2019
- case 3: return needsDynamicSlotSourceCtx(slot.positive) || (slot.negative ? needsDynamicSlotSourceCtx(slot.negative) : false);
2020
- }
2021
- }
2022
2423
  function genBasicDynamicSlot(slot, context) {
2023
2424
  const { name, fn } = slot;
2024
- return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context)]);
2425
+ return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context, false)]);
2025
2426
  }
2026
2427
  function genLoopSlot(slot, context) {
2027
2428
  const { name, fn, loop } = slot;
@@ -2033,7 +2434,7 @@ function genLoopSlot(slot, context) {
2033
2434
  if (rawValue) idMap[rawValue] = rawValue;
2034
2435
  if (rawKey) idMap[rawKey] = rawKey;
2035
2436
  if (rawIndex) idMap[rawIndex] = rawIndex;
2036
- const slotExpr = genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...context.withId(() => genExpression(name, context), idMap)], ["fn: ", ...context.withId(() => genSlotBlockWithProps(fn, context), idMap)]);
2437
+ const slotExpr = genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...context.withId(() => genExpression(name, context), idMap)], ["fn: ", ...context.withId(() => genSlotBlockWithProps(fn, context, false), idMap)]);
2037
2438
  return [...genCall(context.helper("createForSlots"), genExpression(source, context), [
2038
2439
  ...genMulti([
2039
2440
  "(",
@@ -2059,11 +2460,11 @@ function genConditionalSlot(slot, context) {
2059
2460
  INDENT_END
2060
2461
  ];
2061
2462
  }
2062
- function genSlotBlockWithProps(oper, context) {
2463
+ function genSlotBlockWithProps(oper, context, emitNonStableFlag = true) {
2063
2464
  let propsName;
2064
2465
  let exitScope;
2065
2466
  let depth;
2066
- const { props, node } = oper;
2467
+ const { props } = oper;
2067
2468
  const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
2068
2469
  if (props) if (props.ast) {
2069
2470
  [depth, exitScope] = context.enterScope();
@@ -2071,23 +2472,57 @@ function genSlotBlockWithProps(oper, context) {
2071
2472
  } else propsName = props.content;
2072
2473
  const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
2073
2474
  if (propsName) idMap[propsName] = null;
2475
+ const exitSlotBlock = context.enterSlotBlock();
2476
+ const hasStableRoot = hasStableSlotRoot(oper, context);
2477
+ if (!hasStableRoot) markSlotRootOperations(oper);
2074
2478
  let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
2479
+ if (emitNonStableFlag && !hasStableRoot) blockFn = genCall(context.helper("extend"), blockFn, [`{ _: ${genSlotFlags$1(8)} }`]);
2480
+ exitSlotBlock();
2075
2481
  exitScope && exitScope();
2076
- if (node.type === 1) {
2077
- if (needsVaporCtx(oper)) blockFn = [
2078
- `${context.helper("withVaporCtx")}(`,
2079
- ...blockFn,
2080
- `)`
2081
- ];
2082
- }
2083
2482
  return blockFn;
2084
2483
  }
2085
- /**
2086
- * Check if a slot block needs withVaporCtx wrapper.
2087
- * Returns true if the block contains:
2088
- * - Component creation (needs scopeId inheritance)
2089
- * - Slot outlet (needs rawSlots from slot owner)
2090
- */
2484
+ function genSlotFlags$1(flags) {
2485
+ const names = [];
2486
+ if (flags & 1) names.push("NO_SLOTTED");
2487
+ if (flags & 2) names.push("ONCE");
2488
+ if (flags & 4) names.push("SLOT_ROOT");
2489
+ if (flags & 8) names.push("NON_STABLE");
2490
+ return `${flags} /* ${names.join(", ")} */`;
2491
+ }
2492
+ const commentOnlyTemplateRE = /^(?:<!--[\s\S]*?-->)+$/;
2493
+ function hasStableSlotRoot(block, context) {
2494
+ let hasValidRoot = false;
2495
+ for (let i = 0; i < block.returns.length; i++) {
2496
+ const id = block.returns[i];
2497
+ const child = findReturnedDynamic$1(block, id);
2498
+ const operation = child && child.operation;
2499
+ if (!operation) {
2500
+ if (child && isStableTemplateSlotRoot(child, context)) hasValidRoot = true;
2501
+ continue;
2502
+ }
2503
+ switch (operation.type) {
2504
+ case 12:
2505
+ if (!operation.dynamic || operation.dynamic.isStatic) {
2506
+ hasValidRoot = true;
2507
+ continue;
2508
+ }
2509
+ continue;
2510
+ case 17:
2511
+ if (hasStableSlotRoot(operation.block, context)) {
2512
+ hasValidRoot = true;
2513
+ continue;
2514
+ }
2515
+ continue;
2516
+ default: continue;
2517
+ }
2518
+ }
2519
+ return hasValidRoot;
2520
+ }
2521
+ function isStableTemplateSlotRoot(child, context) {
2522
+ if (child.template == null) return false;
2523
+ const content = context.ir.template.entries[child.template].content;
2524
+ return content !== "" && !commentOnlyTemplateRE.test(content.trim());
2525
+ }
2091
2526
  function needsVaporCtx(block) {
2092
2527
  return hasComponentOrSlotInBlock(block);
2093
2528
  }
@@ -2132,18 +2567,31 @@ function hasComponentOrSlotInIf(node) {
2132
2567
  //#region packages/compiler-vapor/src/generators/slotOutlet.ts
2133
2568
  function genSlotOutlet(oper, context) {
2134
2569
  const { helper } = context;
2135
- const { id, name, fallback, noSlotted, once } = oper;
2570
+ const { id, name, fallback, flags } = oper;
2136
2571
  const [frag, push] = buildCodeFragment();
2137
- const nameExpr = name.isStatic ? genExpression(name, context) : [
2572
+ let fallbackArg;
2573
+ if (fallback) {
2574
+ if (context.inSlotBlock) markSlotRootOperations(fallback);
2575
+ fallbackArg = genBlock(fallback, context);
2576
+ }
2577
+ const createSlot = helper("createSlot");
2578
+ const rawPropsArg = genRawProps(oper.props, context, true);
2579
+ const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
2138
2580
  "() => (",
2139
2581
  ...genExpression(name, context),
2140
2582
  ")"
2141
2583
  ];
2142
- let fallbackArg;
2143
- if (fallback) fallbackArg = genBlock(fallback, context);
2144
- push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
2584
+ push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, genSlotFlags(flags)));
2145
2585
  return frag;
2146
2586
  }
2587
+ function genSlotFlags(flags) {
2588
+ if (!flags) return;
2589
+ const names = [];
2590
+ if (flags & 1) names.push("NO_SLOTTED");
2591
+ if (flags & 2) names.push("ONCE");
2592
+ if (flags & 4) names.push("SLOT_ROOT");
2593
+ return `${flags} /* ${names.join(", ")} */`;
2594
+ }
2147
2595
  //#endregion
2148
2596
  //#region packages/compiler-vapor/src/generators/key.ts
2149
2597
  function genKey(oper, context) {
@@ -2203,28 +2651,35 @@ function genEffects(effects, context, genExtraFrag) {
2203
2651
  const [frag, push, unshift] = buildCodeFragment();
2204
2652
  const shouldDeclare = genExtraFrag === void 0;
2205
2653
  let operationsCount = 0;
2206
- const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
2207
- push(...declarationFrags);
2208
- for (let i = 0; i < effects.length; i++) {
2209
- const effect = effects[i];
2210
- operationsCount += effect.operations.length;
2211
- const frags = context.withId(() => genEffect(effect, context), ids);
2212
- i > 0 && push(NEWLINE);
2213
- if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
2214
- push(...frags);
2215
- }
2216
- if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
2217
- unshift(`{`, INDENT_START, NEWLINE);
2218
- push(INDENT_END, NEWLINE, "}");
2219
- if (!effects.length) unshift(NEWLINE);
2220
- }
2221
- if (effects.length) {
2222
- unshift(NEWLINE, `${helper("renderEffect")}(() => `);
2223
- push(`)`);
2224
- }
2225
- if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
2226
- if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
2227
- return frag;
2654
+ const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
2655
+ if (shouldDeclare && !declarationFrags.length && !varNames.length) {
2656
+ const effect = effects.length === 1 ? effects[0] : void 0;
2657
+ const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
2658
+ if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
2659
+ }
2660
+ return context.withExpressionReplacements(expressionReplacements, () => {
2661
+ push(...declarationFrags);
2662
+ for (let i = 0; i < effects.length; i++) {
2663
+ const effect = effects[i];
2664
+ operationsCount += effect.operations.length;
2665
+ const frags = context.withId(() => genEffect(effect, context), ids);
2666
+ i > 0 && push(NEWLINE);
2667
+ if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
2668
+ push(...frags);
2669
+ }
2670
+ if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
2671
+ unshift(`{`, INDENT_START, NEWLINE);
2672
+ push(INDENT_END, NEWLINE, "}");
2673
+ if (!effects.length) unshift(NEWLINE);
2674
+ }
2675
+ if (effects.length) {
2676
+ unshift(NEWLINE, `${helper("renderEffect")}(() => `);
2677
+ push(`)`);
2678
+ }
2679
+ if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
2680
+ if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
2681
+ return frag;
2682
+ });
2228
2683
  }
2229
2684
  function genEffect({ operations }, context) {
2230
2685
  const [frag, push] = buildCodeFragment();
@@ -2243,9 +2698,8 @@ function genTemplates(templates, context) {
2243
2698
  const result = [];
2244
2699
  templates.forEach(({ content, ns, root, static: isStatic }, i) => {
2245
2700
  let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
2246
- if (root) args += ", true";
2247
- else if (isStatic || ns) args += ", false";
2248
- if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
2701
+ const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
2702
+ if (flags || ns) args += `, ${flags}`;
2249
2703
  if (ns) args += `, ${ns}`;
2250
2704
  result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
2251
2705
  });
@@ -2263,10 +2717,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
2263
2717
  return frag;
2264
2718
  }
2265
2719
  function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
2266
- const { helper } = context;
2267
2720
  const [frag, push] = buildCodeFragment();
2268
2721
  const { children } = dynamic;
2269
2722
  let offset = 0;
2723
+ /**
2724
+ * `reusable` means the previous access target is a p* cursor that can be
2725
+ * reassigned by the next lookup. Referenced n* variables must stay stable.
2726
+ */
2270
2727
  let prev;
2271
2728
  for (const [index, child] of children.entries()) {
2272
2729
  if (child.flags & 2) offset--;
@@ -2283,27 +2740,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
2283
2740
  }
2284
2741
  const elementIndex = index + offset;
2285
2742
  const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
2286
- const variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
2287
- pushBlock(NEWLINE, `const ${variable} = `);
2288
- if (prev) if (elementIndex - prev[1] === 1) pushBlock(...genCall(helper("next"), prev[0], logicalIndex));
2289
- else pushBlock(...genCall(helper("nthChild"), from, String(elementIndex), logicalIndex));
2290
- else if (elementIndex === 0) pushBlock(...genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0));
2291
- else {
2292
- let init = genCall(helper("child"), from);
2293
- if (elementIndex === 1) init = genCall(helper("next"), init, logicalIndex);
2294
- else if (elementIndex > 1) init = genCall(helper("nthChild"), from, String(elementIndex), logicalIndex);
2295
- pushBlock(...init);
2743
+ const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
2744
+ const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
2745
+ if (inlinePlaceholder) {
2746
+ if (prev && prev[2]) {
2747
+ push(...genChildren(child, context, pushBlock, [
2748
+ "(",
2749
+ prev[0],
2750
+ " = ",
2751
+ ...accessPath,
2752
+ ")"
2753
+ ], flushBeforeDynamic));
2754
+ prev = [
2755
+ prev[0],
2756
+ elementIndex,
2757
+ true
2758
+ ];
2759
+ continue;
2760
+ }
2761
+ if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
2762
+ push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
2763
+ continue;
2764
+ }
2765
+ }
2766
+ let variable;
2767
+ if (id === void 0 && prev && prev[2]) {
2768
+ variable = prev[0];
2769
+ pushBlock(NEWLINE, `${variable} = `, ...accessPath);
2770
+ } else {
2771
+ variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
2772
+ pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
2296
2773
  }
2297
2774
  if (id === child.anchor && !child.hasDynamicChild) {
2298
2775
  flushBeforeDynamic && flushBeforeDynamic(child, push);
2299
2776
  push(...genSelf(child, context, flushBeforeDynamic));
2300
2777
  }
2301
2778
  if (id !== void 0) push(...genDirectivesForElement(id, context));
2302
- prev = [variable, elementIndex];
2779
+ prev = [
2780
+ variable,
2781
+ elementIndex,
2782
+ id === void 0
2783
+ ];
2303
2784
  push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
2304
2785
  }
2305
2786
  return frag;
2306
2787
  }
2788
+ /**
2789
+ * Build one DOM lookup path while preserving the fast sibling walk:
2790
+ * adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
2791
+ */
2792
+ function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
2793
+ if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
2794
+ if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
2795
+ const firstChild = genCall(helper("child"), from);
2796
+ return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
2797
+ }
2798
+ /**
2799
+ * Only inline a placeholder when materializing it would not save a parent
2800
+ * lookup. If its child tree needs the parent more than once, keep p* so the
2801
+ * generated code does not duplicate _child/_nthChild work.
2802
+ */
2803
+ function canInlinePlaceholder(dynamic) {
2804
+ return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
2805
+ }
2806
+ /**
2807
+ * A following access can reuse the current placeholder cursor only when it is
2808
+ * the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
2809
+ */
2810
+ function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
2811
+ let futureOffset = offset;
2812
+ for (let i = index + 1; i < children.length; i++) {
2813
+ const child = children[i];
2814
+ if (child.flags & 2) futureOffset--;
2815
+ if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
2816
+ }
2817
+ return false;
2818
+ }
2819
+ /**
2820
+ * Mirrors genChildren's traversal closely enough to count how many emitted
2821
+ * access paths would start from this placeholder's parent. This is the guard
2822
+ * that keeps inline placeholders from duplicating parent lookups.
2823
+ */
2824
+ function countParentAccessUsages(dynamic) {
2825
+ let usages = 0;
2826
+ let offset = 0;
2827
+ let prev;
2828
+ for (const [index, child] of dynamic.children.entries()) {
2829
+ if (child.flags & 2) offset--;
2830
+ if (child.flags & 4 && child.template != null) continue;
2831
+ const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
2832
+ if (id === void 0 && !child.hasDynamicChild) continue;
2833
+ const elementIndex = index + offset;
2834
+ const usesParent = !prev || elementIndex - prev[0] !== 1;
2835
+ if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
2836
+ if (prev && prev[1]) {
2837
+ if (usesParent) usages++;
2838
+ prev = [elementIndex, true];
2839
+ continue;
2840
+ }
2841
+ if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
2842
+ if (usesParent) usages++;
2843
+ continue;
2844
+ }
2845
+ }
2846
+ if (usesParent) usages++;
2847
+ prev = [elementIndex, id === void 0];
2848
+ }
2849
+ return usages;
2850
+ }
2851
+ function genNthChild(nthChild, from, elementIndex, logicalIndex) {
2852
+ const index = String(elementIndex);
2853
+ return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
2854
+ }
2307
2855
  //#endregion
2308
2856
  //#region packages/compiler-vapor/src/generators/block.ts
2309
2857
  function genBlock(oper, context, args = [], root) {
@@ -2318,12 +2866,16 @@ function genBlock(oper, context, args = [], root) {
2318
2866
  "}"
2319
2867
  ];
2320
2868
  }
2321
- function genBlockContent(block, context, root, genEffectsExtraFrag) {
2869
+ function genBlockContent(block, context, root, genEffectsExtraFrag, skippedEffectIndexes) {
2322
2870
  const [frag, push] = buildCodeFragment();
2323
2871
  const { dynamic, effect, operation, returns } = block;
2324
2872
  const resetBlock = context.enterBlock(block);
2873
+ const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
2874
+ const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
2875
+ if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
2325
2876
  if (root) {
2326
2877
  for (let name of context.ir.component) {
2878
+ if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
2327
2879
  const id = (0, _vue_compiler_dom.toValidAssetId)(name, "component");
2328
2880
  const maybeSelfReference = name.endsWith("__self");
2329
2881
  if (maybeSelfReference) name = name.slice(0, -6);
@@ -2339,7 +2891,7 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
2339
2891
  operationIndex++;
2340
2892
  }
2341
2893
  if (effectIndex < effectEnd) {
2342
- push(...genEffects(effect.slice(effectIndex, effectEnd), context));
2894
+ push(...genEffectRange(effectIndex, effectEnd));
2343
2895
  effectIndex = effectEnd;
2344
2896
  }
2345
2897
  };
@@ -2353,21 +2905,145 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
2353
2905
  }
2354
2906
  for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`, flushBeforeDynamic));
2355
2907
  if (operationIndex < operation.length) push(...genOperations(operation.slice(operationIndex), context));
2356
- if (effectIndex < effect.length) push(...genEffects(effect.slice(effectIndex), context, genEffectsExtraFrag));
2908
+ if (effectIndex < effect.length) push(...genEffectRange(effectIndex, effect.length, genEffectsExtraFrag));
2357
2909
  else if (genEffectsExtraFrag) push(...genEffects([], context, genEffectsExtraFrag));
2358
2910
  push(NEWLINE, `return `);
2359
2911
  const returnNodes = returns.map((n) => `n${n}`);
2360
- push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
2912
+ push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "[]"]);
2361
2913
  resetBlock();
2914
+ context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
2362
2915
  return frag;
2916
+ function genEffectRange(start, end, genExtraFrag) {
2917
+ if (!skippedEffectIndexes) return genEffects(effect.slice(start, end), context, genExtraFrag);
2918
+ const effects = [];
2919
+ for (let i = start; i < end; i++) if (!skippedEffectIndexes.has(i)) effects.push(effect[i]);
2920
+ if (effects.length || genExtraFrag) return genEffects(effects, context, genExtraFrag);
2921
+ return [];
2922
+ }
2363
2923
  function genResolveAssets(kind, helper) {
2364
2924
  for (const name of context.ir[kind]) push(NEWLINE, `const ${(0, _vue_compiler_dom.toValidAssetId)(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
2365
2925
  }
2366
2926
  }
2927
+ function markSlotRootOperations(block) {
2928
+ for (let i = 0; i < block.returns.length; i++) {
2929
+ const child = findReturnedDynamic$1(block, block.returns[i]);
2930
+ const operation = child && child.operation;
2931
+ if (!operation) continue;
2932
+ if (operation.type === 15) markSlotRootIf(operation);
2933
+ else if (operation.type === 16) markSlotRootFor(operation);
2934
+ else if (operation.type === 12) markSlotRootComponent(operation);
2935
+ }
2936
+ }
2937
+ function markSlotRootIf(operation) {
2938
+ if (!operation.once) operation.slotRoot = true;
2939
+ markSlotRootOperations(operation.positive);
2940
+ const negative = operation.negative;
2941
+ if (!negative) return;
2942
+ if (negative.type === 15) markSlotRootIf(negative);
2943
+ else markSlotRootOperations(negative);
2944
+ }
2945
+ function markSlotRootFor(operation) {
2946
+ if (!operation.once) operation.slotRoot = true;
2947
+ markSlotRootOperations(operation.render);
2948
+ }
2949
+ function markSlotRootComponent(operation) {
2950
+ if (!operation.once && operation.dynamic && !operation.dynamic.isStatic) operation.slotRoot = true;
2951
+ }
2952
+ function findReturnedDynamic$1(block, id) {
2953
+ for (let i = 0; i < block.dynamic.children.length; i++) {
2954
+ const child = block.dynamic.children[i];
2955
+ if (child.id === id) return child;
2956
+ }
2957
+ }
2958
+ function collectSingleUseAssetComponents(block) {
2959
+ const usageMap = /* @__PURE__ */ new Map();
2960
+ const seenOperations = /* @__PURE__ */ new Set();
2961
+ visitBlock(block, true);
2962
+ const names = /* @__PURE__ */ new Set();
2963
+ for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
2964
+ return names;
2965
+ function visitBlock(block, rootCandidate) {
2966
+ visitDynamic(block.dynamic, rootCandidate);
2967
+ for (const operation of block.operation) visitOperation(operation, rootCandidate);
2968
+ for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
2969
+ }
2970
+ function visitDynamic(dynamic, rootCandidate) {
2971
+ if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
2972
+ for (const child of dynamic.children) visitDynamic(child, rootCandidate);
2973
+ }
2974
+ function visitOperation(operation, rootCandidate) {
2975
+ if (seenOperations.has(operation)) return;
2976
+ seenOperations.add(operation);
2977
+ if (operation.type === 12) {
2978
+ if (operation.asset) {
2979
+ const usage = usageMap.get(operation.tag) || {
2980
+ count: 0,
2981
+ root: false
2982
+ };
2983
+ usage.count++;
2984
+ if (rootCandidate) usage.root = true;
2985
+ usageMap.set(operation.tag, usage);
2986
+ }
2987
+ visitSlots(operation.slots);
2988
+ return;
2989
+ }
2990
+ switch (operation.type) {
2991
+ case 15:
2992
+ visitBlock(operation.positive, false);
2993
+ if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
2994
+ else visitBlock(operation.negative, false);
2995
+ break;
2996
+ case 16:
2997
+ visitBlock(operation.render, false);
2998
+ break;
2999
+ case 17:
3000
+ visitBlock(operation.block, false);
3001
+ break;
3002
+ case 13:
3003
+ if (operation.fallback) visitBlock(operation.fallback, false);
3004
+ break;
3005
+ }
3006
+ }
3007
+ function visitSlots(slots) {
3008
+ for (const slot of slots) switch (slot.slotType) {
3009
+ case 0:
3010
+ for (const name in slot.slots) visitBlock(slot.slots[name], false);
3011
+ break;
3012
+ case 1:
3013
+ case 2:
3014
+ visitBlock(slot.fn, false);
3015
+ break;
3016
+ case 3:
3017
+ visitSlots([slot.positive]);
3018
+ if (slot.negative) visitSlots([slot.negative]);
3019
+ break;
3020
+ }
3021
+ }
3022
+ }
2367
3023
  //#endregion
2368
3024
  //#region packages/compiler-vapor/src/generate.ts
2369
3025
  const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
3026
+ const helperNameAliases = {
3027
+ withVaporKeys: "withKeys",
3028
+ withVaporModifiers: "withModifiers"
3029
+ };
2370
3030
  var CodegenContext = class {
3031
+ withExpressionReplacements(map, fn) {
3032
+ if (map.size === 0) return fn();
3033
+ this.expressionReplacements.unshift(map);
3034
+ try {
3035
+ return fn();
3036
+ } finally {
3037
+ (0, _vue_shared.remove)(this.expressionReplacements, map);
3038
+ }
3039
+ }
3040
+ getExpressionReplacement(node) {
3041
+ for (const map of this.expressionReplacements) {
3042
+ const replacement = map.get(node);
3043
+ if (replacement) return replacement;
3044
+ }
3045
+ return node;
3046
+ }
2371
3047
  withId(fn, map) {
2372
3048
  const { identifiers } = this;
2373
3049
  const ids = Object.keys(map);
@@ -2384,9 +3060,19 @@ var CodegenContext = class {
2384
3060
  this.block = block;
2385
3061
  return () => this.block = parent;
2386
3062
  }
3063
+ enterSlotBlock() {
3064
+ const parent = this.inSlotBlock;
3065
+ this.inSlotBlock = true;
3066
+ return () => this.inSlotBlock = parent;
3067
+ }
2387
3068
  enterScope() {
2388
3069
  return [this.scopeLevel++, () => this.scopeLevel--];
2389
3070
  }
3071
+ isHelperNameAvailable(name) {
3072
+ if (this.bindingNames.has(name)) return false;
3073
+ for (const alias of this.helpers.values()) if (alias === name) return false;
3074
+ return true;
3075
+ }
2390
3076
  initNextIdMap() {
2391
3077
  if (this.bindingNames.size === 0) return;
2392
3078
  const map = /* @__PURE__ */ new Map();
@@ -2421,19 +3107,29 @@ var CodegenContext = class {
2421
3107
  this.ir = ir;
2422
3108
  this.bindingNames = /* @__PURE__ */ new Set();
2423
3109
  this.helpers = /* @__PURE__ */ new Map();
3110
+ this.needsTemplateRefSetter = false;
3111
+ this.inSlotBlock = false;
2424
3112
  this.helper = (name) => {
2425
3113
  if (this.helpers.has(name)) return this.helpers.get(name);
2426
- const base = `_${name}`;
2427
- if (this.bindingNames.size === 0 || !this.bindingNames.has(base)) {
3114
+ const base = `_${helperNameAliases[name] || name}`;
3115
+ if (this.isHelperNameAvailable(base)) {
2428
3116
  this.helpers.set(name, base);
2429
3117
  return base;
2430
3118
  }
2431
- const alias = `${base}${getNextId(this.nextIdMap.get(base), 1)}`;
2432
- this.helpers.set(name, alias);
2433
- return alias;
3119
+ const map = this.nextIdMap.get(base);
3120
+ let next = 1;
3121
+ while (true) {
3122
+ const alias = `${base}${getNextId(map, next)}`;
3123
+ if (this.isHelperNameAvailable(alias)) {
3124
+ this.helpers.set(name, alias);
3125
+ return alias;
3126
+ }
3127
+ next++;
3128
+ }
2434
3129
  };
2435
3130
  this.delegates = /* @__PURE__ */ new Set();
2436
3131
  this.identifiers = Object.create(null);
3132
+ this.expressionReplacements = [];
2437
3133
  this.seenInlineHandlerNames = Object.create(null);
2438
3134
  this.scopeLevel = 0;
2439
3135
  this.templateVars = /* @__PURE__ */ new Map();
@@ -2460,6 +3156,7 @@ var CodegenContext = class {
2460
3156
  this.block = ir.block;
2461
3157
  this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
2462
3158
  this.initNextIdMap();
3159
+ this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
2463
3160
  }
2464
3161
  };
2465
3162
  function generate(ir, options = {}) {
@@ -2472,8 +3169,11 @@ function generate(ir, options = {}) {
2472
3169
  const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
2473
3170
  if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
2474
3171
  push(INDENT_START);
2475
- if (ir.hasTemplateRef) push(NEWLINE, `const ${setTemplateRefIdent} = ${context.helper("createTemplateRefSetter")}()`);
2476
- push(...genBlockContent(ir.block, context, true));
3172
+ const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
3173
+ const body = genBlockContent(ir.block, context, true);
3174
+ if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
3175
+ else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
3176
+ push(...body);
2477
3177
  push(INDENT_END, NEWLINE);
2478
3178
  if (!inline) push("}");
2479
3179
  const delegates = genDelegates(context);
@@ -2508,6 +3208,11 @@ function genAssetImports({ ir }) {
2508
3208
  }
2509
3209
  return imports;
2510
3210
  }
3211
+ function getStaticTemplateRefHelperCandidate(block) {
3212
+ if (block.operation.length !== 1) return;
3213
+ const operation = block.operation[0];
3214
+ if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
3215
+ }
2511
3216
  //#endregion
2512
3217
  //#region packages/compiler-vapor/src/transforms/vBind.ts
2513
3218
  function normalizeBindShorthand(arg, context) {
@@ -2546,6 +3251,49 @@ const transformVBind = (dir, node, context) => {
2546
3251
  };
2547
3252
  };
2548
3253
  //#endregion
3254
+ //#region packages/compiler-vapor/src/transforms/vHtml.ts
3255
+ function ignoreVHtmlChildren(node, context, clear) {
3256
+ if (!node.children.length) return;
3257
+ const dir = (0, _vue_compiler_dom.findDir)(node, "html");
3258
+ if (!dir) return;
3259
+ context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(55, dir.loc));
3260
+ if (clear === "node") node.children.length = 0;
3261
+ else context.childrenTemplate.length = 0;
3262
+ }
3263
+ const transformVHtml = (dir, node, context) => {
3264
+ let { exp, loc } = dir;
3265
+ if (!exp) {
3266
+ context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(54, loc));
3267
+ exp = EMPTY_EXPRESSION;
3268
+ }
3269
+ ignoreVHtmlChildren(node, context, "template");
3270
+ context.registerEffect([exp], {
3271
+ type: 8,
3272
+ node,
3273
+ element: context.reference(),
3274
+ value: exp,
3275
+ isComponent: node.tagType === 1
3276
+ });
3277
+ };
3278
+ //#endregion
3279
+ //#region packages/compiler-vapor/src/errors.ts
3280
+ function createVaporCompilerError(code, loc) {
3281
+ return (0, _vue_compiler_dom.createCompilerError)(code, loc, VaporErrorMessages);
3282
+ }
3283
+ const VaporErrorCodes = {
3284
+ "X_V_PLACEHOLDER": 100,
3285
+ "100": "X_V_PLACEHOLDER",
3286
+ "X_DYNAMIC_FLATTEN_NOT_SUPPORTED": 101,
3287
+ "101": "X_DYNAMIC_FLATTEN_NOT_SUPPORTED",
3288
+ "__EXTEND_POINT__": 102,
3289
+ "102": "__EXTEND_POINT__"
3290
+ };
3291
+ const VaporErrorMessages = {
3292
+ [100]: `[placeholder]`,
3293
+ [101]: "The value of flatten attribute must be a static boolean value.",
3294
+ [102]: ``
3295
+ };
3296
+ //#endregion
2549
3297
  //#region packages/compiler-vapor/src/transforms/transformElement.ts
2550
3298
  const isReservedProp = /* @__PURE__ */ (0, _vue_shared.makeMap)(",key,ref,ref_for,ref_key,");
2551
3299
  const transformElement = (node, context) => {
@@ -2553,6 +3301,7 @@ const transformElement = (node, context) => {
2553
3301
  const getEffectIndex = () => effectIndex++;
2554
3302
  let operationIndex = context.block.operation.length;
2555
3303
  const getOperationIndex = () => operationIndex++;
3304
+ if (node.type === 1 && node.children.length) ignoreVHtmlChildren(node, context, "node");
2556
3305
  let parentSlots;
2557
3306
  if (node.type === 1 && (node.tagType === 1 || context.options.isCustomElement(node.tag))) {
2558
3307
  parentSlots = context.slots;
@@ -2566,7 +3315,7 @@ const transformElement = (node, context) => {
2566
3315
  const isDynamicComponent = isComponentTag(node.tag);
2567
3316
  const staticKey = resolveStaticKey(node, context, isComponent);
2568
3317
  const propsResult = buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex);
2569
- const singleRoot = isSingleRoot(context);
3318
+ const singleRoot = context.isSingleRoot;
2570
3319
  if (isComponent) transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement);
2571
3320
  else transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context), getOperationIndex);
2572
3321
  if (parentSlots) context.slots = parentSlots;
@@ -2605,16 +3354,6 @@ function isInSameTemplateAsParent(context) {
2605
3354
  if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
2606
3355
  return !shouldUseCreateElement(parentNode, parent) && (0, _vue_compiler_dom.isValidHTMLNesting)(parentNode.tag, node.tag);
2607
3356
  }
2608
- function isSingleRoot(context) {
2609
- if (context.inVFor) return false;
2610
- let { parent } = context;
2611
- if (parent && !((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
2612
- while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
2613
- parent = parent.parent;
2614
- if (!((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
2615
- }
2616
- return context.root === parent;
2617
- }
2618
3357
  function transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement) {
2619
3358
  const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
2620
3359
  let { tag } = node;
@@ -2649,6 +3388,7 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
2649
3388
  }
2650
3389
  context.dynamic.flags |= 6;
2651
3390
  const id = context.reference();
3391
+ const flatten = extractElementFlatten(node, propsResult, context);
2652
3392
  context.dynamic.operation = {
2653
3393
  type: 12,
2654
3394
  node,
@@ -2661,11 +3401,38 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
2661
3401
  slots: [...context.slots],
2662
3402
  once: context.inVOnce,
2663
3403
  dynamic: dynamicComponent,
2664
- useCreateElement
3404
+ useCreateElement,
3405
+ flatten
2665
3406
  };
2666
3407
  if (staticKey) context.registerOperation(createSetBlockKey(id, staticKey, node));
2667
3408
  context.slots = [];
2668
3409
  }
3410
+ function extractElementFlatten(node, propsResult, context) {
3411
+ if (!context.options.platform) return;
3412
+ const flatten = extractStaticBooleanProp(propsResult, "flatten", (loc) => {
3413
+ context.options.onError(createVaporCompilerError(101, loc));
3414
+ });
3415
+ if (flatten != null) node.flatten = flatten;
3416
+ return flatten;
3417
+ }
3418
+ function extractStaticBooleanProp(propsResult, name, onInvalid) {
3419
+ const groups = propsResult[0] ? propsResult[1] : [propsResult[1]];
3420
+ for (const props of groups) {
3421
+ if (!Array.isArray(props)) continue;
3422
+ for (let i = 0; i < props.length; i++) {
3423
+ const prop = props[i];
3424
+ if (prop.key.isStatic && prop.key.content === name && !prop.handler && !prop.model) {
3425
+ const value = parseStaticAttrBooleanExpression(prop.values[0]);
3426
+ props.splice(i, 1);
3427
+ if (value == null) {
3428
+ onInvalid && onInvalid(prop.values[0].loc);
3429
+ return;
3430
+ }
3431
+ return value;
3432
+ }
3433
+ }
3434
+ }
3435
+ }
2669
3436
  function resolveDynamicComponent(node) {
2670
3437
  const isProp = findProp$1(node, "is", false, true);
2671
3438
  if (!isProp) return;
@@ -2681,9 +3448,15 @@ function resolveSetupReference(name, context) {
2681
3448
  }
2682
3449
  const dynamicKeys = ["indeterminate"];
2683
3450
  const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
3451
+ const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
3452
+ function isDataProp(prop) {
3453
+ const name = prop.key.content;
3454
+ return prop.key.isStatic && name.length > 5 && name.startsWith("data-");
3455
+ }
2684
3456
  function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag, getOperationIndex) {
2685
3457
  const isDom2 = !!context.options.platform;
2686
3458
  if (isDom2) omitEndTag = false;
3459
+ if (isDom2) extractElementFlatten(node, propsResult, context);
2687
3460
  const { tag } = node;
2688
3461
  const { scopeId } = context.options;
2689
3462
  let template = "";
@@ -2699,6 +3472,7 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
2699
3472
  if (context.options.rootElementFromUniModule) template += ` gen-root-custom-native="${rootElementTagName}"`;
2700
3473
  }
2701
3474
  }
3475
+ if (node.flatten) template += ` flatten`;
2702
3476
  }
2703
3477
  const dynamicProps = [];
2704
3478
  if (propsResult[0]) {
@@ -2721,8 +3495,9 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
2721
3495
  const props = propsResult[1];
2722
3496
  const indicesToRemove = [];
2723
3497
  for (let i = 0; i < props.length; i++) {
2724
- const { key, values } = props[i];
2725
- if (key.content.startsWith("change:") || changeProps.includes(key.content)) continue;
3498
+ const prop = props[i];
3499
+ const { key, values } = prop;
3500
+ if (isDataProp(prop) || key.content.startsWith("change:") || changeProps.includes(key.content)) continue;
2726
3501
  if (key.isStatic && values.length === 1 && !["class", "style"].includes(key.content)) {
2727
3502
  let endLoc = values[0].loc;
2728
3503
  if (endLoc === _vue_compiler_dom.locStub) endLoc = key.loc;
@@ -2739,9 +3514,23 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
2739
3514
  let hasClass = false;
2740
3515
  const datasetProps = [];
2741
3516
  let prevWasQuoted = false;
3517
+ const appendTemplateProp = (key, value = "", generated = false) => {
3518
+ if (!prevWasQuoted) template += ` `;
3519
+ template += key;
3520
+ if (value) {
3521
+ const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, "&quot;");
3522
+ template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
3523
+ } else prevWasQuoted = false;
3524
+ };
2742
3525
  for (const prop of propsResult[1]) {
2743
3526
  const { key, values } = prop;
3527
+ const canStringifyAttrName = key.isStatic && !UNSAFE_ATTR_NAME_RE.test(key.content);
3528
+ let foldedValue;
2744
3529
  if (isDom2) {
3530
+ if (isDataProp(prop)) {
3531
+ datasetProps.push(prop);
3532
+ continue;
3533
+ }
2745
3534
  if (key.content.startsWith("change:")) {
2746
3535
  dynamicProps.push(key.content);
2747
3536
  values[0].isStatic = false;
@@ -2754,11 +3543,11 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
2754
3543
  }
2755
3544
  if (key.content === "class") hasClass = true;
2756
3545
  }
2757
- if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
3546
+ if (canStringifyAttrName && context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
2758
3547
  if (!prevWasQuoted) template += ` `;
2759
3548
  template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
2760
3549
  prevWasQuoted = true;
2761
- } else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
3550
+ } else if (canStringifyAttrName && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
2762
3551
  if (isDom2 && key.content === "style") {
2763
3552
  hasStaticStyle = true;
2764
3553
  const checkStaticStyle = context.options.checkStaticStyle;
@@ -2778,22 +3567,20 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
2778
3567
  }, getEffectIndex, getOperationIndex);
2779
3568
  continue;
2780
3569
  }
2781
- if (!prevWasQuoted) template += ` `;
2782
3570
  const value = values[0].content === "''" ? "" : values[0].content;
2783
- template += key.content;
2784
- if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, "&quot;")}"` : `=${value}`;
2785
- else prevWasQuoted = false;
2786
- } else {
2787
- dynamicProps.push(key.content);
2788
- context.registerEffect(values, {
2789
- type: 3,
2790
- node,
2791
- isChangeProp: changeProps.includes(key.content),
2792
- element: context.reference(),
2793
- prop,
2794
- tag
2795
- }, getEffectIndex);
2796
- }
3571
+ appendTemplateProp(key.content, value);
3572
+ } else if (canStringifyAttrName && !prop.modifier && (0, _vue_shared.isBooleanAttr)(key.content) && (foldedValue = foldBooleanAttrValue(values)) != null) {
3573
+ if (foldedValue) appendTemplateProp(key.content);
3574
+ } else if (canStringifyAttrName && !prop.modifier && !isDom2 && hasBoundValue(values) && (foldedValue = key.content === "class" ? foldClassValues(values) : key.content === "style" ? foldStyleValues(values) : void 0) != null) {
3575
+ if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
3576
+ } else context.registerEffect(values, {
3577
+ type: 3,
3578
+ node,
3579
+ isChangeProp: changeProps.includes(key.content),
3580
+ element: context.reference(),
3581
+ prop,
3582
+ tag
3583
+ }, getEffectIndex);
2797
3584
  }
2798
3585
  if (hasStaticStyle && hasClass) template += ` ext:style`;
2799
3586
  if (datasetProps.length) {
@@ -2821,6 +3608,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
2821
3608
  } else context.template += template;
2822
3609
  if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey, node));
2823
3610
  }
3611
+ function escapeGeneratedAttrValue(value) {
3612
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
3613
+ }
3614
+ function foldBooleanAttrValue(values) {
3615
+ if (values.length !== 1) return;
3616
+ const evaluated = evaluateConstantExpression(values[0]);
3617
+ if (!evaluated) return;
3618
+ const value = evaluated.value;
3619
+ if (value === true || value === false || value == null) return (0, _vue_shared.includeBooleanAttr)(value);
3620
+ }
3621
+ function foldStyleValues(values) {
3622
+ const evaluatedValues = [];
3623
+ for (const value of values) {
3624
+ const evaluated = evaluateConstantExpression(value);
3625
+ if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
3626
+ evaluatedValues.push(evaluated.value);
3627
+ }
3628
+ return (0, _vue_shared.stringifyStyle)((0, _vue_shared.normalizeStyle)(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
3629
+ }
3630
+ function isStaticStyleValue(value) {
3631
+ if (typeof value === "string") return true;
3632
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
3633
+ for (const key in value) {
3634
+ const propValue = value[key];
3635
+ if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
3636
+ }
3637
+ return true;
3638
+ }
3639
+ function isSafeStylePropertyName(key) {
3640
+ return !!key && !/[;:]/.test(key);
3641
+ }
3642
+ function isSafeStylePropertyValue(value) {
3643
+ return typeof value === "number" || typeof value === "string" && !value.includes(";");
3644
+ }
3645
+ function hasBoundValue(values) {
3646
+ return values.some((value) => !value.isStatic && value.content !== "''");
3647
+ }
3648
+ function foldClassValues(values) {
3649
+ let templateValue = "";
3650
+ let changed = false;
3651
+ for (const value of values) {
3652
+ const evaluated = evaluateConstantExpression(value);
3653
+ if (evaluated) {
3654
+ const normalized = (0, _vue_shared.normalizeClass)(evaluated.value);
3655
+ if (normalized) templateValue = appendClass(templateValue, normalized);
3656
+ else changed = true;
3657
+ continue;
3658
+ }
3659
+ return;
3660
+ }
3661
+ return changed || templateValue ? templateValue : void 0;
3662
+ }
3663
+ function appendClass(base, value) {
3664
+ return base ? value ? `${base} ${value}` : base : value;
3665
+ }
3666
+ function getObjectPropertyName(prop) {
3667
+ const key = prop.key;
3668
+ if (key.type === "Identifier") return key.name;
3669
+ else if (key.type === "StringLiteral") return key.value;
3670
+ else if (key.type === "NumericLiteral") return String(key.value);
3671
+ }
3672
+ function evaluateConstantExpression(node) {
3673
+ if (node.isStatic) return { value: node.content };
3674
+ const ast = node.ast;
3675
+ if (ast === null) {
3676
+ if (node.content === "true") return { value: true };
3677
+ else if (node.content === "false") return { value: false };
3678
+ else if (node.content === "null") return { value: null };
3679
+ else if (node.content === "undefined") return { value: void 0 };
3680
+ }
3681
+ if (!ast) return;
3682
+ return evaluateConstantAst(ast);
3683
+ }
3684
+ function evaluateConstantAst(node) {
3685
+ switch (node.type) {
3686
+ case "StringLiteral": return { value: node.value };
3687
+ case "NumericLiteral": return { value: node.value };
3688
+ case "BooleanLiteral": return { value: node.value };
3689
+ case "NullLiteral": return { value: null };
3690
+ case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
3691
+ case "UnaryExpression":
3692
+ if (node.operator === "void") return { value: void 0 };
3693
+ else if (node.operator === "-") {
3694
+ const value = evaluateConstantAst(node.argument);
3695
+ return value && typeof value.value === "number" ? { value: -value.value } : void 0;
3696
+ }
3697
+ return;
3698
+ case "TemplateLiteral": return evaluateTemplateLiteral(node);
3699
+ case "ObjectExpression": return evaluateObjectExpression(node);
3700
+ }
3701
+ }
3702
+ function evaluateTemplateLiteral(node) {
3703
+ if (node.type !== "TemplateLiteral") return;
3704
+ let value = "";
3705
+ for (const [index, quasi] of node.quasis.entries()) {
3706
+ value += quasi.value.cooked || "";
3707
+ const expression = node.expressions[index];
3708
+ if (expression) {
3709
+ const evaluated = evaluateConstantAst(expression);
3710
+ if (!evaluated) return;
3711
+ value += evaluated.value;
3712
+ }
3713
+ }
3714
+ return { value };
3715
+ }
3716
+ function evaluateObjectExpression(node) {
3717
+ const value = {};
3718
+ for (const prop of node.properties) {
3719
+ if (prop.type !== "ObjectProperty" || prop.computed) return;
3720
+ const key = getObjectPropertyName(prop);
3721
+ if (key == null) return;
3722
+ const evaluated = evaluateConstantAst(prop.value);
3723
+ if (!evaluated) return;
3724
+ value[key] = evaluated.value;
3725
+ }
3726
+ return { value };
3727
+ }
2824
3728
  function resolveStaticKey(node, context, isComponent) {
2825
3729
  const keyProp = findProp$1(node, "key", false, true);
2826
3730
  if (!keyProp) return;
@@ -2848,27 +3752,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
2848
3752
  results = [];
2849
3753
  }
2850
3754
  }
3755
+ function pushStaticObjectLiteralProps(props) {
3756
+ if (dynamicArgs.length) {
3757
+ pushMergeArg();
3758
+ dynamicArgs.push(props);
3759
+ } else results.push(...props.map(toDirectiveResult));
3760
+ }
2851
3761
  for (const prop of props) {
2852
3762
  if (prop.type === 7 && !prop.arg) {
2853
3763
  if (prop.name === "bind") {
2854
3764
  if (prop.exp) {
2855
- dynamicExpr.push(prop.exp);
2856
- pushMergeArg();
2857
- dynamicArgs.push({
2858
- kind: 0,
2859
- value: prop.exp
2860
- });
3765
+ const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
3766
+ if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
3767
+ else results.push(...objectLiteralProps.map(toDirectiveResult));
3768
+ else {
3769
+ dynamicExpr.push(prop.exp);
3770
+ pushMergeArg();
3771
+ dynamicArgs.push({
3772
+ kind: 0,
3773
+ value: prop.exp
3774
+ });
3775
+ }
2861
3776
  } else context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, prop.loc));
2862
3777
  continue;
2863
3778
  } else if (prop.name === "on") {
2864
3779
  if (prop.exp) if (isComponent) {
2865
- dynamicExpr.push(prop.exp);
2866
- pushMergeArg();
2867
- dynamicArgs.push({
2868
- kind: 0,
2869
- value: prop.exp,
2870
- handler: true
2871
- });
3780
+ const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
3781
+ if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
3782
+ else {
3783
+ dynamicExpr.push(prop.exp);
3784
+ pushMergeArg();
3785
+ dynamicArgs.push({
3786
+ kind: 0,
3787
+ value: prop.exp,
3788
+ handler: true
3789
+ });
3790
+ }
2872
3791
  } else context.registerEffect([prop.exp], {
2873
3792
  type: 7,
2874
3793
  node,
@@ -2899,6 +3818,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
2899
3818
  }
2900
3819
  return [false, dedupeProperties(results)];
2901
3820
  }
3821
+ function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
3822
+ const ast = exp.ast;
3823
+ if (!ast || ast.type !== "ObjectExpression") return;
3824
+ const props = [];
3825
+ const knownKeys = /* @__PURE__ */ new Set();
3826
+ for (const property of ast.properties) {
3827
+ if (property.type !== "ObjectProperty" || property.computed) return;
3828
+ let key = getObjectPropertyName(property);
3829
+ if (key == null || key === "__proto__") return;
3830
+ if (isValidKey && !isValidKey(key)) return;
3831
+ if (keyTransform) key = keyTransform(key);
3832
+ if (knownKeys.has(key)) return;
3833
+ knownKeys.add(key);
3834
+ props.push({
3835
+ key: (0, _vue_compiler_dom.createSimpleExpression)(key, true),
3836
+ values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
3837
+ });
3838
+ }
3839
+ return props;
3840
+ }
3841
+ function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
3842
+ const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
3843
+ if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
3844
+ return props;
3845
+ }
3846
+ function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
3847
+ const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
3848
+ if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
3849
+ return props;
3850
+ }
3851
+ function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
3852
+ const props = resolveObjectLiteralProps(exp, context, _vue_shared.toHandlerKey);
3853
+ if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
3854
+ return props;
3855
+ }
3856
+ function isSafeNativeObjectLiteralBindKey(key) {
3857
+ return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !(0, _vue_shared.isOn)(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
3858
+ }
3859
+ function isSafeObjectLiteralBindKey(key) {
3860
+ return !isReservedProp(key);
3861
+ }
3862
+ function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
3863
+ const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
3864
+ for (const prop of props) {
3865
+ if (prop === currentProp) continue;
3866
+ let key;
3867
+ if (prop.type === 6) key = prop.name;
3868
+ else if (prop.name === "bind") {
3869
+ if (!prop.arg) {
3870
+ const bindKeys = getObjectLiteralKeys(prop.exp);
3871
+ if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
3872
+ continue;
3873
+ }
3874
+ key = getStaticBindKey(prop);
3875
+ } else if (prop.name === "on") key = getStaticHandlerKey(prop);
3876
+ else if (prop.name === "model") {
3877
+ if (hasComponentModelKey(keys, prop)) return true;
3878
+ }
3879
+ if (key && hasComponentKey(keys, key)) return true;
3880
+ }
3881
+ return false;
3882
+ }
3883
+ function hasComponentModelKey(keys, prop) {
3884
+ const { arg } = prop;
3885
+ if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
3886
+ const key = arg ? arg.content : "modelValue";
3887
+ return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${(0, _vue_shared.camelize)(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, (0, _vue_shared.getModifierPropName)(key));
3888
+ }
3889
+ function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
3890
+ const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
3891
+ for (const prop of props) {
3892
+ if (prop === currentProp) continue;
3893
+ let key;
3894
+ if (prop.type === 6) key = prop.name;
3895
+ else if (prop.name === "bind") {
3896
+ if (!prop.arg) return true;
3897
+ key = getStaticBindKey(prop);
3898
+ if (!key) return true;
3899
+ }
3900
+ if (key && keys.has(key)) return true;
3901
+ }
3902
+ return false;
3903
+ }
3904
+ function getStaticBindKey(prop) {
3905
+ const { arg } = prop;
3906
+ if (!arg || arg.type !== 4 || !arg.isStatic) return;
3907
+ let key = arg.content;
3908
+ if (isReservedProp(key)) return;
3909
+ if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = (0, _vue_shared.camelize)(key);
3910
+ return key;
3911
+ }
3912
+ function getStaticHandlerKey(prop) {
3913
+ const { arg } = prop;
3914
+ if (!arg || arg.type !== 4 || !arg.isStatic) return;
3915
+ let key = arg.content;
3916
+ if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
3917
+ const { nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(`on${key}`, prop.modifiers, null, prop.loc);
3918
+ if (key.toLowerCase() === "click") {
3919
+ if (nonKeyModifiers.includes("middle")) key = "mouseup";
3920
+ if (nonKeyModifiers.includes("right")) key = "contextmenu";
3921
+ }
3922
+ key = (0, _vue_shared.toHandlerKey)((0, _vue_shared.camelize)(key));
3923
+ const optionPostfix = eventOptionModifiers.map(_vue_shared.capitalize).join("");
3924
+ if (optionPostfix) key += optionPostfix;
3925
+ return key;
3926
+ }
3927
+ function getObjectLiteralKeys(exp) {
3928
+ const ast = exp && exp.ast;
3929
+ if (!ast || ast.type !== "ObjectExpression") return;
3930
+ const keys = /* @__PURE__ */ new Set();
3931
+ for (const property of ast.properties) {
3932
+ if (property.type !== "ObjectProperty" || property.computed) return;
3933
+ const key = getObjectPropertyName(property);
3934
+ if (key == null) return;
3935
+ keys.add(key);
3936
+ }
3937
+ return keys;
3938
+ }
3939
+ function createComponentConflictKeySet(keys) {
3940
+ const normalized = /* @__PURE__ */ new Set();
3941
+ for (const key of keys) {
3942
+ normalized.add(key);
3943
+ normalized.add((0, _vue_shared.camelize)(key));
3944
+ }
3945
+ return normalized;
3946
+ }
3947
+ function hasComponentKey(keys, key) {
3948
+ return keys.has(key) || keys.has((0, _vue_shared.camelize)(key));
3949
+ }
3950
+ function hasComponentKeyOverlap(left, right) {
3951
+ for (const key of right) if (hasComponentKey(left, key)) return true;
3952
+ return false;
3953
+ }
3954
+ function createObjectBindSubExpression(source, node, context) {
3955
+ const start = node.start == null ? 0 : node.start - 1;
3956
+ const end = node.end == null ? source.content.length : node.end - 1;
3957
+ const content = source.content.slice(start, end);
3958
+ const expression = (0, _vue_compiler_dom.createSimpleExpression)(content, false, {
3959
+ start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, start),
3960
+ end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, end),
3961
+ source: content
3962
+ });
3963
+ expression.ast = (0, _vue_compiler_dom.isSimpleIdentifier)(content) ? null : (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
3964
+ return expression;
3965
+ }
2902
3966
  function transformProp(prop, node, context) {
2903
3967
  let { name } = prop;
2904
3968
  if (prop.type === 6) {
@@ -2950,6 +4014,12 @@ function resolveDirectiveResult(prop) {
2950
4014
  values: [prop.value]
2951
4015
  });
2952
4016
  }
4017
+ function toDirectiveResult(prop) {
4018
+ return (0, _vue_shared.extend)({}, prop, {
4019
+ values: void 0,
4020
+ value: prop.values[0]
4021
+ });
4022
+ }
2953
4023
  function mergePropValues(existing, incoming) {
2954
4024
  const newValues = incoming.values;
2955
4025
  existing.values.push(...newValues);
@@ -3044,26 +4114,6 @@ const transformVOnce = (node, context) => {
3044
4114
  if (node.type === 1 && (0, _vue_compiler_dom.findDir)(node, "once", true)) context.inVOnce = true;
3045
4115
  };
3046
4116
  //#endregion
3047
- //#region packages/compiler-vapor/src/transforms/vHtml.ts
3048
- const transformVHtml = (dir, node, context) => {
3049
- let { exp, loc } = dir;
3050
- if (!exp) {
3051
- context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(54, loc));
3052
- exp = EMPTY_EXPRESSION;
3053
- }
3054
- if (node.children.length) {
3055
- context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(55, loc));
3056
- context.childrenTemplate.length = 0;
3057
- }
3058
- context.registerEffect([exp], {
3059
- type: 8,
3060
- node,
3061
- element: context.reference(),
3062
- value: exp,
3063
- isComponent: node.tagType === 1
3064
- });
3065
- };
3066
- //#endregion
3067
4117
  //#region packages/shared/src/makeMap.ts
3068
4118
  /**
3069
4119
  * Make a map and return a function for checking if a key
@@ -3129,13 +4179,7 @@ const transformText = (node, context) => {
3129
4179
  };
3130
4180
  function processInterpolation(context) {
3131
4181
  const parentNode = context.parent.node;
3132
- const children = parentNode.children;
3133
- const nexts = children.slice(context.index);
3134
- const idx = nexts.findIndex((n) => !isTextLike(n));
3135
- const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
3136
- const prev = children[context.index - 1];
3137
- if (prev && prev.type === 2) nodes.unshift(prev);
3138
- const values = processTextLikeChildren(nodes, context);
4182
+ const values = processTextLikeChildren(collectAdjacentText(context), context);
3139
4183
  if (values.length === 0 && parentNode.type !== 0) return;
3140
4184
  const literalValues = values.map((v) => getLiteralExpressionValue(v));
3141
4185
  if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
@@ -3171,6 +4215,18 @@ function processInterpolation(context) {
3171
4215
  values
3172
4216
  });
3173
4217
  }
4218
+ function collectAdjacentText(context) {
4219
+ const children = context.parent.node.children;
4220
+ const nodes = [];
4221
+ const prev = children[context.index - 1];
4222
+ let index = prev && prev.type === 2 ? context.index - 1 : context.index;
4223
+ for (; index < children.length; index++) {
4224
+ const child = children[index];
4225
+ if (!isTextLike(child)) break;
4226
+ nodes.push(child);
4227
+ }
4228
+ return nodes;
4229
+ }
3174
4230
  function processTextContainer(children, context) {
3175
4231
  const values = processTextLikeChildren(children, context);
3176
4232
  const literals = values.map((value) => getLiteralExpressionValue(value));
@@ -3303,12 +4359,10 @@ const transformVOn = (dir, node, context) => {
3303
4359
  const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(arg.isStatic ? `on${arg.content}` : arg, modifiers, null, loc);
3304
4360
  let keyOverride;
3305
4361
  const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
3306
- if (nonKeyModifiers.includes("middle")) {
3307
- if (keyOverride) {}
3308
- if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "mouseup"];
3309
- }
3310
4362
  if (nonKeyModifiers.includes("right")) {
3311
4363
  if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "contextmenu"];
4364
+ } else if (nonKeyModifiers.includes("middle")) {
4365
+ if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "mouseup"];
3312
4366
  }
3313
4367
  arg = normalizeStaticEventArg(arg, nonKeyModifiers);
3314
4368
  if (keyModifiers.length && (0, _vue_compiler_dom.isStaticExp)(arg) && !(0, _vue_compiler_dom.isKeyboardEvent)(`on${arg.content.toLowerCase()}`)) keyModifiers.length = 0;
@@ -3322,7 +4376,7 @@ const transformVOn = (dir, node, context) => {
3322
4376
  options: eventOptionModifiers
3323
4377
  }
3324
4378
  };
3325
- const delegate = arg.isStatic && !eventOptionModifiers.length && !hasStopHandlerForStaticEvent(node, arg.content) && delegatedEvents(arg.content);
4379
+ const delegate = context.options.eventDelegation && arg.isStatic && !eventOptionModifiers.length && !hasStopHandlerForStaticEvent(node, arg.content) && delegatedEvents(arg.content);
3326
4380
  const operation = {
3327
4381
  type: 6,
3328
4382
  node,
@@ -3344,8 +4398,8 @@ function normalizeStaticEventArg(arg, nonKeyModifiers) {
3344
4398
  if (!arg.isStatic) return arg;
3345
4399
  let normalized = arg;
3346
4400
  const isStaticClick = arg.content.toLowerCase() === "click";
3347
- if (nonKeyModifiers.includes("middle") && isStaticClick) normalized = (0, _vue_shared.extend)({}, normalized, { content: "mouseup" });
3348
4401
  if (nonKeyModifiers.includes("right") && isStaticClick) normalized = (0, _vue_shared.extend)({}, normalized, { content: "contextmenu" });
4402
+ else if (nonKeyModifiers.includes("middle") && isStaticClick) normalized = (0, _vue_shared.extend)({}, normalized, { content: "mouseup" });
3349
4403
  return normalized;
3350
4404
  }
3351
4405
  function hasStopHandlerForStaticEvent(node, eventName) {
@@ -3513,6 +4567,7 @@ function processIf(node, dir, context) {
3513
4567
  }
3514
4568
  context.dynamic.flags |= 2;
3515
4569
  const forceMultiRoot = shouldForceMultiRoot(context);
4570
+ const allowNoScope = context.block === context.root.block;
3516
4571
  if (dir.name === "if") {
3517
4572
  const id = context.reference();
3518
4573
  context.dynamic.flags |= 4;
@@ -3524,7 +4579,7 @@ function processIf(node, dir, context) {
3524
4579
  node,
3525
4580
  id,
3526
4581
  ...context.effectBoundary(),
3527
- blockShape: encodeIfBlockShape(branch, forceMultiRoot),
4582
+ blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
3528
4583
  condition: dir.exp,
3529
4584
  positive: branch,
3530
4585
  index: context.root.nextIfIndex(),
@@ -3548,11 +4603,14 @@ function processIf(node, dir, context) {
3548
4603
  }
3549
4604
  while (lastIfNode.negative && lastIfNode.negative.type === 15) lastIfNode = lastIfNode.negative;
3550
4605
  if (dir.name === "else-if" && lastIfNode.negative) context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, node.loc));
3551
- if (context.root.comment.length) {
3552
- node = wrapTemplate(node, ["else-if", "else"]);
3553
- context.node = node = (0, _vue_shared.extend)({}, node, { children: [...context.comment, ...node.children] });
4606
+ const comments = context.comment;
4607
+ if (comments.length) {
4608
+ if (!isInTransition(context)) {
4609
+ node = wrapTemplate(node, ["else-if", "else"]);
4610
+ context.node = node = (0, _vue_shared.extend)({}, node, { children: [...comments, ...node.children] });
4611
+ }
4612
+ comments.length = 0;
3554
4613
  }
3555
- context.root.comment = [];
3556
4614
  const [branch, onExit] = createIfBranch(node, context);
3557
4615
  if (dir.name === "else") lastIfNode.negative = branch;
3558
4616
  else lastIfNode.negative = {
@@ -3567,8 +4625,8 @@ function processIf(node, dir, context) {
3567
4625
  };
3568
4626
  return () => {
3569
4627
  onExit();
3570
- if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
3571
- lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
4628
+ if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
4629
+ lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
3572
4630
  };
3573
4631
  }
3574
4632
  }
@@ -3583,14 +4641,38 @@ function createIfBranch(node, context) {
3583
4641
  context.reference();
3584
4642
  return [branch, exitBlock];
3585
4643
  }
3586
- function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
4644
+ function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
3587
4645
  if (forceMultiRoot) return 10;
3588
- return getBlockShape(positive) | getNegativeBlockShape(negative) << 2;
4646
+ const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
4647
+ const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
4648
+ return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
3589
4649
  }
3590
- function getNegativeBlockShape(negative) {
4650
+ function getNegativeIfBranchShape(negative) {
3591
4651
  if (!negative) return 0;
3592
4652
  return negative.type === 15 ? 1 : getBlockShape(negative);
3593
4653
  }
4654
+ function canSkipIfBranchScope(block) {
4655
+ if (block.effect.length || block.operation.length) return false;
4656
+ if (!isStaticBranch(block.node)) return false;
4657
+ if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
4658
+ return block.returns.every((id) => {
4659
+ const returned = findReturnedDynamic(block, id);
4660
+ return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
4661
+ });
4662
+ }
4663
+ function findReturnedDynamic(block, id) {
4664
+ return block.dynamic.children.find((child) => child.id === id);
4665
+ }
4666
+ function isStaticBranch(node) {
4667
+ if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
4668
+ return node.children.every((child) => isStaticTemplateNode(child));
4669
+ }
4670
+ function isStaticTemplateNode(node) {
4671
+ if (node.type === 2 || node.type === 3) return true;
4672
+ if (node.type !== 1 || node.tagType !== 0) return false;
4673
+ for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
4674
+ return node.children.every((child) => isStaticTemplateNode(child));
4675
+ }
3594
4676
  function shouldForceMultiRoot(context) {
3595
4677
  const parent = context.parent && context.parent.node;
3596
4678
  return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
@@ -3679,6 +4761,9 @@ const transformSlotOutlet = (node, context) => {
3679
4761
  }
3680
4762
  return () => {
3681
4763
  exitBlock && exitBlock();
4764
+ let flags = 0;
4765
+ if (context.options.scopeId && !context.options.slotted) flags |= 1;
4766
+ if (context.inVOnce) flags |= 2;
3682
4767
  context.dynamic.operation = {
3683
4768
  type: 13,
3684
4769
  node,
@@ -3687,8 +4772,7 @@ const transformSlotOutlet = (node, context) => {
3687
4772
  name: slotName,
3688
4773
  props: irProps,
3689
4774
  fallback,
3690
- noSlotted: !!(context.options.scopeId && !context.options.slotted),
3691
- once: context.inVOnce
4775
+ flags
3692
4776
  };
3693
4777
  };
3694
4778
  };
@@ -3710,7 +4794,7 @@ function createFallback(node, context) {
3710
4794
  //#region packages/compiler-vapor/src/transforms/vSlot.ts
3711
4795
  const transformVSlot = (node, context) => {
3712
4796
  if (node.type !== 1) return;
3713
- const dir = findDir$2(node, "slot", true);
4797
+ const dir = findDir$4(node, "slot", true);
3714
4798
  const { tagType, children } = node;
3715
4799
  const { parent } = context;
3716
4800
  const isComponent = tagType === 1;
@@ -3761,9 +4845,9 @@ function transformTemplateSlot(node, dir, context) {
3761
4845
  const resolvedArg = dir.arg && resolveExpression(dir.arg);
3762
4846
  let arg = resolvedArg;
3763
4847
  if (!arg) arg = (0, _vue_compiler_dom.createSimpleExpression)("default", true);
3764
- const vFor = findDir$2(node, "for");
3765
- const vIf = findDir$2(node, "if");
3766
- const vElse = findDir$2(node, /^else(-if)?$/, true);
4848
+ const vFor = findDir$4(node, "for");
4849
+ const vIf = findDir$4(node, "if");
4850
+ const vElse = findDir$4(node, /^else(-if)?$/, true);
3767
4851
  const { slots } = context;
3768
4852
  const [block, onExit] = createSlotBlock(node, dir, context);
3769
4853
  if (!vFor && !vIf && !vElse) {
@@ -3781,7 +4865,7 @@ function transformTemplateSlot(node, dir, context) {
3781
4865
  });
3782
4866
  else if (vElse) {
3783
4867
  const vIfSlot = slots[slots.length - 1];
3784
- if (vIfSlot.slotType === 3) {
4868
+ if (vIfSlot && vIfSlot.slotType === 3) {
3785
4869
  let ifNode = vIfSlot;
3786
4870
  while (ifNode.negative && ifNode.negative.slotType === 3) ifNode = ifNode.negative;
3787
4871
  const negative = vElse.exp ? {
@@ -3844,7 +4928,7 @@ function isNonWhitespaceContent(node) {
3844
4928
  return !!node.content.trim();
3845
4929
  }
3846
4930
  function isSlotTemplateChild(node) {
3847
- return node.type === 1 && (0, _vue_compiler_dom.isTemplateNode)(node) && !!findDir$2(node, "slot", true);
4931
+ return node.type === 1 && (0, _vue_compiler_dom.isTemplateNode)(node) && !!findDir$4(node, "slot", true);
3848
4932
  }
3849
4933
  //#endregion
3850
4934
  //#region packages/compiler-vapor/src/transforms/transformTransition.ts
@@ -3857,17 +4941,17 @@ function hasMultipleChildren(node) {
3857
4941
  const children = node.children = node.children.filter((c) => c.type !== 3 && !(c.type === 2 && !c.content.trim()));
3858
4942
  const first = children[0];
3859
4943
  if (children.length === 1 && first.type === 1) {
3860
- if (findDir$2(first, "for")) return true;
4944
+ if (findDir$4(first, "for")) return true;
3861
4945
  if ((0, _vue_compiler_dom.isTemplateNode)(first)) return hasMultipleChildren(first);
3862
4946
  }
3863
- const hasElse = (node) => findDir$2(node, "else-if") || findDir$2(node, "else", true);
3864
- if (children.length > 0 && children.every((c, index) => c.type === 1 && (!(0, _vue_compiler_dom.isTemplateNode)(c) || !hasMultipleChildren(c)) && !findDir$2(c, "for") && (index === 0 ? findDir$2(c, "if") : hasElse(c)))) return false;
4947
+ const hasElse = (node) => findDir$4(node, "else-if") || findDir$4(node, "else", true);
4948
+ if (children.length > 0 && children.every((c, index) => c.type === 1 && (!(0, _vue_compiler_dom.isTemplateNode)(c) || !hasMultipleChildren(c)) && !findDir$4(c, "for") && (index === 0 ? findDir$4(c, "if") : hasElse(c)))) return false;
3865
4949
  return children.length !== 1;
3866
4950
  }
3867
4951
  //#endregion
3868
4952
  //#region packages/compiler-vapor/src/transforms/transformKey.ts
3869
4953
  const transformKey = (node, context) => {
3870
- if (node.type !== 1 || context.inVOnce || findDir$2(node, "for")) return;
4954
+ if (node.type !== 1 || context.inVOnce || findDir$4(node, "for")) return;
3871
4955
  const dir = findProp$1(node, "key", true, true);
3872
4956
  if (!dir || dir.type === 6) return;
3873
4957
  let value;
@@ -3932,21 +5016,6 @@ function getBaseTransformPreset() {
3932
5016
  }];
3933
5017
  }
3934
5018
  //#endregion
3935
- //#region packages/compiler-vapor/src/errors.ts
3936
- function createVaporCompilerError(code, loc) {
3937
- return (0, _vue_compiler_dom.createCompilerError)(code, loc, VaporErrorMessages);
3938
- }
3939
- const VaporErrorCodes = {
3940
- "X_V_PLACEHOLDER": 100,
3941
- "100": "X_V_PLACEHOLDER",
3942
- "__EXTEND_POINT__": 101,
3943
- "101": "__EXTEND_POINT__"
3944
- };
3945
- const VaporErrorMessages = {
3946
- [100]: `[placeholder]`,
3947
- [101]: ``
3948
- };
3949
- //#endregion
3950
5019
  exports.CodegenContext = CodegenContext;
3951
5020
  exports.DELIMITERS_ARRAY = DELIMITERS_ARRAY;
3952
5021
  exports.DELIMITERS_ARRAY_NEWLINE = DELIMITERS_ARRAY_NEWLINE;
@@ -3976,23 +5045,30 @@ exports.compile = compile;
3976
5045
  exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
3977
5046
  exports.createVaporCompilerError = createVaporCompilerError;
3978
5047
  exports.genCall = genCall;
5048
+ exports.genDirectiveModifiers = genDirectiveModifiers;
5049
+ exports.genDynamicComponentFlags = genDynamicComponentFlags;
3979
5050
  exports.genMulti = genMulti;
5051
+ exports.genSlotFlags = genSlotFlags;
3980
5052
  exports.generate = generate;
3981
5053
  exports.getBaseTransformPreset = getBaseTransformPreset;
3982
5054
  exports.getLiteralExpressionValue = getLiteralExpressionValue;
3983
5055
  exports.getParserOptions = getParserOptions;
5056
+ exports.hasStableSlotRoot = hasStableSlotRoot;
3984
5057
  exports.isBlockOperation = isBlockOperation;
3985
5058
  exports.isBuiltInComponent = isBuiltInComponent;
3986
5059
  exports.isConstantExpression = isConstantExpression;
5060
+ exports.isDirectStaticLiteralProp = isDirectStaticLiteralProp;
3987
5061
  exports.isKeepAliveTag = isKeepAliveTag;
3988
5062
  exports.isStaticExpression = isStaticExpression;
3989
5063
  exports.isTeleportTag = isTeleportTag;
3990
5064
  exports.isTransitionGroupTag = isTransitionGroupTag;
3991
5065
  exports.isTransitionTag = isTransitionTag;
5066
+ exports.markSlotRootOperations = markSlotRootOperations;
3992
5067
  exports.matchKeyOnlyBindingPattern = matchKeyOnlyBindingPattern;
3993
5068
  exports.matchSelectorPattern = matchSelectorPattern;
3994
5069
  exports.needsVaporCtx = needsVaporCtx;
3995
5070
  exports.parse = _vue_compiler_dom.parse;
5071
+ exports.parseStaticAttrBooleanExpression = parseStaticAttrBooleanExpression;
3996
5072
  exports.parseValueDestructure = parseValueDestructure;
3997
5073
  exports.propToExpression = propToExpression;
3998
5074
  exports.transform = transform;