@vue-jsx-vapor/compiler 1.6.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,16 +1,9 @@
1
1
  // src/compile.ts
2
- import { extend as extend5, isString as isString3 } from "@vue/shared";
2
+ import { parse } from "@babel/parser";
3
3
  import {
4
4
  generate
5
5
  } from "@vue/compiler-vapor";
6
- import { parse } from "@babel/parser";
7
-
8
- // src/transform.ts
9
- import {
10
- defaultOnError,
11
- defaultOnWarn
12
- } from "@vue/compiler-dom";
13
- import { EMPTY_OBJ, NOOP, extend, isArray, isString as isString2 } from "@vue/shared";
6
+ import { extend as extend5, isString as isString3 } from "@vue/shared";
14
7
 
15
8
  // src/ir/component.ts
16
9
  var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
@@ -58,29 +51,36 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
58
51
  return DynamicFlag2;
59
52
  })(DynamicFlag || {});
60
53
 
54
+ // src/transform.ts
55
+ import {
56
+ defaultOnError,
57
+ defaultOnWarn
58
+ } from "@vue/compiler-dom";
59
+ import { EMPTY_OBJ, extend, isArray, isString as isString2, NOOP } from "@vue/shared";
60
+
61
61
  // src/transforms/utils.ts
62
- import { createSimpleExpression as createSimpleExpression2 } from "@vue/compiler-dom";
63
62
  import {
64
63
  jsxClosingFragment,
65
64
  jsxExpressionContainer,
66
65
  jsxFragment,
67
66
  jsxOpeningFragment
68
67
  } from "@babel/types";
68
+ import { createSimpleExpression as createSimpleExpression2 } from "@vue/compiler-dom";
69
69
 
70
70
  // src/utils.ts
71
- import { isGloballyAllowed, isHTMLTag, isSVGTag, isString } from "@vue/shared";
71
+ import { parseExpression } from "@babel/parser";
72
+ import {
73
+ isLiteral
74
+ } from "@babel/types";
72
75
  import {
76
+ createSimpleExpression,
73
77
  ElementTypes,
78
+ isLiteralWhitelisted,
74
79
  Namespaces,
75
80
  NodeTypes,
76
- createSimpleExpression,
77
- isLiteralWhitelisted,
78
81
  walkIdentifiers
79
82
  } from "@vue/compiler-dom";
80
- import {
81
- isLiteral
82
- } from "@babel/types";
83
- import { parseExpression } from "@babel/parser";
83
+ import { isGloballyAllowed, isHTMLTag, isString, isSVGTag } from "@vue/shared";
84
84
  function propToExpression(prop, context) {
85
85
  return prop.type === "JSXAttribute" && prop.value?.type === "JSXExpressionContainer" ? resolveExpression(prop.value.expression, context) : EMPTY_EXPRESSION;
86
86
  }
@@ -118,11 +118,11 @@ var isConstant = (node) => {
118
118
  }
119
119
  return false;
120
120
  };
121
- var EMPTY_TEXT_REGEX = /^\s*[\n\r]\s*$/;
121
+ var EMPTY_TEXT_REGEX = /^[\t\v\f \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*[\n\r]\s*$/;
122
122
  var START_EMPTY_TEXT_REGEX = /^\s*[\n\r]/;
123
123
  var END_EMPTY_TEXT_REGEX = /[\n\r]\s*$/;
124
124
  function resolveJSXText(node) {
125
- if (EMPTY_TEXT_REGEX.test(`${node.extra?.raw}`)) {
125
+ if (EMPTY_TEXT_REGEX.test(String(node.extra?.raw))) {
126
126
  return "";
127
127
  }
128
128
  let value = node.value;
@@ -135,13 +135,13 @@ function resolveJSXText(node) {
135
135
  return value;
136
136
  }
137
137
  function isEmptyText(node) {
138
- return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(`${node.extra?.raw}`) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
138
+ return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(String(node.extra?.raw)) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
139
139
  }
140
140
  function resolveSimpleExpressionNode(exp) {
141
141
  if (!exp.isStatic) {
142
142
  const value = getLiteralExpressionValue(exp);
143
143
  if (value !== null) {
144
- return createSimpleExpression(`${value}`, true, exp.loc);
144
+ return createSimpleExpression(String(value), true, exp.loc);
145
145
  }
146
146
  }
147
147
  return exp;
@@ -222,7 +222,7 @@ function resolveNode(node, context) {
222
222
  } else {
223
223
  result.push({
224
224
  type: NodeTypes.ATTRIBUTE,
225
- name: `${attr.name.name}`,
225
+ name: String(attr.name.name),
226
226
  nameLoc: resolveLocation(attr.name.loc, context),
227
227
  value: resolveValue(attr.value, context),
228
228
  loc: resolveLocation(attr.loc, context)
@@ -542,11 +542,78 @@ function createStructuralDirectiveTransform(name, fn) {
542
542
  };
543
543
  }
544
544
 
545
+ // src/transforms/transformChildren.ts
546
+ var transformChildren = (node, context) => {
547
+ const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
548
+ if (node.type !== "JSXElement" && !isFragment) return;
549
+ for (const [i, child] of node.children.entries()) {
550
+ const childContext = context.create(child, i);
551
+ transformNode(childContext);
552
+ const childDynamic = childContext.dynamic;
553
+ if (isFragment) {
554
+ childContext.reference();
555
+ childContext.registerTemplate();
556
+ if (!(childDynamic.flags & 2 /* NON_TEMPLATE */) || childDynamic.flags & 4 /* INSERT */) {
557
+ context.block.returns.push(childDynamic.id);
558
+ }
559
+ } else {
560
+ context.childrenTemplate.push(childContext.template);
561
+ }
562
+ if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 /* NON_TEMPLATE */ || childDynamic.flags & 4 /* INSERT */) {
563
+ context.dynamic.hasDynamicChild = true;
564
+ }
565
+ context.dynamic.children[i] = childContext.dynamic;
566
+ }
567
+ if (!isFragment) {
568
+ processDynamicChildren(context);
569
+ }
570
+ };
571
+ function processDynamicChildren(context) {
572
+ let prevDynamics = [];
573
+ let hasStaticTemplate = false;
574
+ const children = context.dynamic.children;
575
+ for (const [index, child] of children.entries()) {
576
+ if (child.flags & 4 /* INSERT */) {
577
+ prevDynamics.push(child);
578
+ }
579
+ if (!(child.flags & 2 /* NON_TEMPLATE */)) {
580
+ if (prevDynamics.length) {
581
+ if (hasStaticTemplate) {
582
+ context.childrenTemplate[index - prevDynamics.length] = `<!>`;
583
+ prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
584
+ const anchor = prevDynamics[0].anchor = context.increaseId();
585
+ context.registerOperation({
586
+ type: 9 /* INSERT_NODE */,
587
+ elements: prevDynamics.map((child2) => child2.id),
588
+ parent: context.reference(),
589
+ anchor
590
+ });
591
+ } else {
592
+ context.registerOperation({
593
+ type: 10 /* PREPEND_NODE */,
594
+ elements: prevDynamics.map((child2) => child2.id),
595
+ parent: context.reference()
596
+ });
597
+ }
598
+ prevDynamics = [];
599
+ }
600
+ hasStaticTemplate = true;
601
+ }
602
+ }
603
+ if (prevDynamics.length) {
604
+ context.registerOperation({
605
+ type: 9 /* INSERT_NODE */,
606
+ elements: prevDynamics.map((child) => child.id),
607
+ parent: context.reference()
608
+ });
609
+ }
610
+ }
611
+
545
612
  // src/transforms/transformElement.ts
546
- import { extend as extend2, isBuiltInDirective, isVoidTag, makeMap } from "@vue/shared";
547
613
  import {
548
614
  isValidHTMLNesting
549
615
  } from "@vue/compiler-dom";
616
+ import { extend as extend2, isBuiltInDirective, isVoidTag, makeMap } from "@vue/shared";
550
617
  var isReservedProp = /* @__PURE__ */ makeMap(
551
618
  // the leading comma is intentional so empty string "" is also included
552
619
  ",key,ref,ref_for,ref_key,"
@@ -762,73 +829,6 @@ function mergePropValues(existing, incoming) {
762
829
  existing.values.push(...newValues);
763
830
  }
764
831
 
765
- // src/transforms/transformChildren.ts
766
- var transformChildren = (node, context) => {
767
- const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
768
- if (node.type !== "JSXElement" && !isFragment) return;
769
- for (const [i, child] of node.children.entries()) {
770
- const childContext = context.create(child, i);
771
- transformNode(childContext);
772
- const childDynamic = childContext.dynamic;
773
- if (isFragment) {
774
- childContext.reference();
775
- childContext.registerTemplate();
776
- if (!(childDynamic.flags & 2 /* NON_TEMPLATE */) || childDynamic.flags & 4 /* INSERT */) {
777
- context.block.returns.push(childDynamic.id);
778
- }
779
- } else {
780
- context.childrenTemplate.push(childContext.template);
781
- }
782
- if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 /* NON_TEMPLATE */ || childDynamic.flags & 4 /* INSERT */) {
783
- context.dynamic.hasDynamicChild = true;
784
- }
785
- context.dynamic.children[i] = childContext.dynamic;
786
- }
787
- if (!isFragment) {
788
- processDynamicChildren(context);
789
- }
790
- };
791
- function processDynamicChildren(context) {
792
- let prevDynamics = [];
793
- let hasStaticTemplate = false;
794
- const children = context.dynamic.children;
795
- for (const [index, child] of children.entries()) {
796
- if (child.flags & 4 /* INSERT */) {
797
- prevDynamics.push(child);
798
- }
799
- if (!(child.flags & 2 /* NON_TEMPLATE */)) {
800
- if (prevDynamics.length) {
801
- if (hasStaticTemplate) {
802
- context.childrenTemplate[index - prevDynamics.length] = `<!>`;
803
- prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
804
- const anchor = prevDynamics[0].anchor = context.increaseId();
805
- context.registerOperation({
806
- type: 9 /* INSERT_NODE */,
807
- elements: prevDynamics.map((child2) => child2.id),
808
- parent: context.reference(),
809
- anchor
810
- });
811
- } else {
812
- context.registerOperation({
813
- type: 10 /* PREPEND_NODE */,
814
- elements: prevDynamics.map((child2) => child2.id),
815
- parent: context.reference()
816
- });
817
- }
818
- prevDynamics = [];
819
- }
820
- hasStaticTemplate = true;
821
- }
822
- }
823
- if (prevDynamics.length) {
824
- context.registerOperation({
825
- type: 9 /* INSERT_NODE */,
826
- elements: prevDynamics.map((child) => child.id),
827
- parent: context.reference()
828
- });
829
- }
830
- }
831
-
832
832
  // src/transforms/transformTemplateRef.ts
833
833
  var transformTemplateRef = (node, context) => {
834
834
  if (node.type !== "JSXElement") return;
@@ -948,7 +948,7 @@ var transformText = (node, context) => {
948
948
  function processTextLike(context) {
949
949
  const nexts = context.parent.node.children?.slice(context.index);
950
950
  const idx = nexts.findIndex((n) => !isTextLike(n));
951
- const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
951
+ const nodes = idx !== -1 ? nexts.slice(0, idx) : nexts;
952
952
  const values = createTextLikeExpressions(nodes, context);
953
953
  if (!values.length) {
954
954
  context.dynamic.flags |= 2 /* NON_TEMPLATE */;
@@ -991,7 +991,7 @@ function isAllTextLike(children) {
991
991
  children.some((n) => n.type === "JSXExpressionContainer");
992
992
  }
993
993
  function isTextLike(node) {
994
- return node.type === "JSXExpressionContainer" && !(node.expression.type === "ConditionalExpression" || node.expression.type === "LogicalExpression") || node.type === "JSXText";
994
+ return node.type === "JSXExpressionContainer" && node.expression.type !== "ConditionalExpression" && node.expression.type !== "LogicalExpression" || node.type === "JSXText";
995
995
  }
996
996
 
997
997
  // src/transforms/vBind.ts
@@ -1020,93 +1020,10 @@ var transformVBind = (dir, node, context) => {
1020
1020
  };
1021
1021
  };
1022
1022
 
1023
- // src/transforms/vOn.ts
1024
- import {
1025
- ErrorCodes,
1026
- createCompilerError,
1027
- createSimpleExpression as createSimpleExpression3,
1028
- resolveModifiers
1029
- } from "@vue/compiler-dom";
1030
- import { extend as extend4, makeMap as makeMap2 } from "@vue/shared";
1031
- var delegatedEvents = /* @__PURE__ */ makeMap2(
1032
- "beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart"
1033
- );
1034
- var transformVOn = (dir, node, context) => {
1035
- const { name, loc, value } = dir;
1036
- if (name.type === "JSXNamespacedName") return;
1037
- const isComponent = isJSXComponent(node);
1038
- const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
1039
- if (!value && !modifiers.length) {
1040
- context.options.onError(
1041
- createCompilerError(
1042
- ErrorCodes.X_V_ON_NO_EXPRESSION,
1043
- resolveLocation(loc, context)
1044
- )
1045
- );
1046
- }
1047
- let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
1048
- const exp = resolveExpression(dir.value, context);
1049
- const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(
1050
- arg.isStatic ? `on${nameString}` : arg,
1051
- modifiers.map((modifier) => createSimpleExpression3(modifier)),
1052
- null,
1053
- resolveLocation(loc, context)
1054
- );
1055
- let keyOverride;
1056
- const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
1057
- if (nonKeyModifiers.includes("middle")) {
1058
- if (keyOverride) {
1059
- }
1060
- if (isStaticClick) {
1061
- arg = extend4({}, arg, { content: "mouseup" });
1062
- } else if (!arg.isStatic) {
1063
- keyOverride = ["click", "mouseup"];
1064
- }
1065
- }
1066
- if (nonKeyModifiers.includes("right")) {
1067
- if (isStaticClick) {
1068
- arg = extend4({}, arg, { content: "contextmenu" });
1069
- } else if (!arg.isStatic) {
1070
- keyOverride = ["click", "contextmenu"];
1071
- }
1072
- }
1073
- if (isComponent) {
1074
- const handler = exp || EMPTY_EXPRESSION;
1075
- return {
1076
- key: arg,
1077
- value: handler,
1078
- handler: true,
1079
- handlerModifiers: eventOptionModifiers
1080
- };
1081
- }
1082
- const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
1083
- const operation = {
1084
- type: 5 /* SET_EVENT */,
1085
- element: context.reference(),
1086
- key: arg,
1087
- value: exp,
1088
- modifiers: {
1089
- keys: keyModifiers,
1090
- nonKeys: nonKeyModifiers,
1091
- options: eventOptionModifiers
1092
- },
1093
- keyOverride,
1094
- delegate,
1095
- effect: !arg.isStatic
1096
- };
1097
- context.registerEffect([arg], operation);
1098
- };
1099
-
1100
- // src/transforms/vSlot.ts
1101
- import {
1102
- ErrorCodes as ErrorCodes3,
1103
- createCompilerError as createCompilerError3
1104
- } from "@vue/compiler-dom";
1105
-
1106
1023
  // src/transforms/vFor.ts
1107
1024
  import {
1108
- ErrorCodes as ErrorCodes2,
1109
- createCompilerError as createCompilerError2,
1025
+ createCompilerError,
1026
+ ErrorCodes,
1110
1027
  isConstantNode
1111
1028
  } from "@vue/compiler-dom";
1112
1029
  var transformVFor = createStructuralDirectiveTransform(
@@ -1117,8 +1034,8 @@ function processFor(node, dir, context) {
1117
1034
  const { value, index, key, source } = getForParseResult(dir, context);
1118
1035
  if (!source) {
1119
1036
  context.options.onError(
1120
- createCompilerError2(
1121
- ErrorCodes2.X_V_FOR_MALFORMED_EXPRESSION,
1037
+ createCompilerError(
1038
+ ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION,
1122
1039
  resolveLocation(dir.loc, context)
1123
1040
  )
1124
1041
  );
@@ -1165,8 +1082,8 @@ function getForParseResult(dir, context) {
1165
1082
  }
1166
1083
  } else {
1167
1084
  context.options.onError(
1168
- createCompilerError2(
1169
- ErrorCodes2.X_V_FOR_NO_EXPRESSION,
1085
+ createCompilerError(
1086
+ ErrorCodes.X_V_FOR_NO_EXPRESSION,
1170
1087
  resolveLocation(dir.loc, context)
1171
1088
  )
1172
1089
  );
@@ -1179,10 +1096,229 @@ function getForParseResult(dir, context) {
1179
1096
  };
1180
1097
  }
1181
1098
 
1182
- // src/transforms/vSlot.ts
1183
- var transformVSlot = (node, context) => {
1184
- if (node.type !== "JSXElement") return;
1185
- const { children } = node;
1099
+ // src/transforms/vHtml.ts
1100
+ import { transformVHtml as _transformVHtml } from "@vue/compiler-vapor";
1101
+ var transformVHtml = (dir, node, context) => {
1102
+ return _transformVHtml(
1103
+ resolveDirectiveNode(dir, context),
1104
+ resolveNode(node, context),
1105
+ context
1106
+ );
1107
+ };
1108
+
1109
+ // src/transforms/vIf.ts
1110
+ import {
1111
+ createCompilerError as createCompilerError2,
1112
+ createSimpleExpression as createSimpleExpression3,
1113
+ ErrorCodes as ErrorCodes2,
1114
+ isConstantNode as isConstantNode2
1115
+ } from "@vue/compiler-dom";
1116
+ var transformVIf = createStructuralDirectiveTransform(
1117
+ ["if", "else", "else-if"],
1118
+ processIf
1119
+ );
1120
+ var transformedIfNode = /* @__PURE__ */ new WeakMap();
1121
+ function processIf(node, attribute, context) {
1122
+ const dir = resolveDirectiveNode(attribute, context);
1123
+ if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
1124
+ const loc = dir.exp ? dir.exp.loc : resolveLocation(node.loc, context);
1125
+ context.options.onError(
1126
+ createCompilerError2(ErrorCodes2.X_V_IF_NO_EXPRESSION, dir.loc)
1127
+ );
1128
+ dir.exp = createSimpleExpression3(`true`, false, loc);
1129
+ }
1130
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1131
+ transformedIfNode.set(node, dir);
1132
+ if (dir.name === "if") {
1133
+ const id = context.reference();
1134
+ context.dynamic.flags |= 4 /* INSERT */;
1135
+ const [branch, onExit] = createBranch(node, context);
1136
+ return () => {
1137
+ onExit();
1138
+ context.registerOperation({
1139
+ type: 16 /* IF */,
1140
+ id,
1141
+ condition: dir.exp,
1142
+ positive: branch,
1143
+ once: context.inVOnce || isConstantNode2(attribute.value, context.options.bindingMetadata)
1144
+ });
1145
+ };
1146
+ } else {
1147
+ const siblingIf = getSiblingIf(context);
1148
+ const { operation } = context.block;
1149
+ let lastIfNode = operation.at(-1);
1150
+ if (
1151
+ // check if v-if is the sibling node
1152
+ !siblingIf || // check if IfNode is the last operation and get the root IfNode
1153
+ !lastIfNode || lastIfNode.type !== 16 /* IF */
1154
+ ) {
1155
+ context.options.onError(
1156
+ createCompilerError2(
1157
+ ErrorCodes2.X_V_ELSE_NO_ADJACENT_IF,
1158
+ resolveLocation(node.loc, context)
1159
+ )
1160
+ );
1161
+ return;
1162
+ }
1163
+ while (lastIfNode.negative && lastIfNode.negative.type === 16 /* IF */) {
1164
+ lastIfNode = lastIfNode.negative;
1165
+ }
1166
+ if (dir.name === "else-if" && lastIfNode.negative) {
1167
+ context.options.onError(
1168
+ createCompilerError2(
1169
+ ErrorCodes2.X_V_ELSE_NO_ADJACENT_IF,
1170
+ resolveLocation(node.loc, context)
1171
+ )
1172
+ );
1173
+ }
1174
+ context.root.comment = [];
1175
+ const [branch, onExit] = createBranch(node, context);
1176
+ if (dir.name === "else") {
1177
+ lastIfNode.negative = branch;
1178
+ } else {
1179
+ lastIfNode.negative = {
1180
+ type: 16 /* IF */,
1181
+ id: -1,
1182
+ condition: dir.exp,
1183
+ positive: branch,
1184
+ once: context.inVOnce
1185
+ };
1186
+ }
1187
+ return () => onExit();
1188
+ }
1189
+ }
1190
+ function getSiblingIf(context) {
1191
+ const parent = context.parent;
1192
+ if (!parent) return;
1193
+ const siblings = parent.node.children;
1194
+ let sibling;
1195
+ let i = siblings.indexOf(context.node);
1196
+ while (--i >= 0) {
1197
+ if (!isEmptyText(siblings[i])) {
1198
+ sibling = siblings[i];
1199
+ break;
1200
+ }
1201
+ }
1202
+ if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) {
1203
+ return sibling;
1204
+ }
1205
+ }
1206
+
1207
+ // src/transforms/vModel.ts
1208
+ import { transformVModel as _transformVModel } from "@vue/compiler-vapor";
1209
+ var transformVModel = (dir, node, context) => {
1210
+ return _transformVModel(
1211
+ resolveDirectiveNode(dir, context),
1212
+ resolveNode(node, context),
1213
+ context
1214
+ );
1215
+ };
1216
+
1217
+ // src/transforms/vOn.ts
1218
+ import {
1219
+ createCompilerError as createCompilerError3,
1220
+ createSimpleExpression as createSimpleExpression4,
1221
+ ErrorCodes as ErrorCodes3,
1222
+ resolveModifiers
1223
+ } from "@vue/compiler-dom";
1224
+ import { extend as extend4, makeMap as makeMap2 } from "@vue/shared";
1225
+ var delegatedEvents = /* @__PURE__ */ makeMap2(
1226
+ "beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart"
1227
+ );
1228
+ var transformVOn = (dir, node, context) => {
1229
+ const { name, loc, value } = dir;
1230
+ if (name.type === "JSXNamespacedName") return;
1231
+ const isComponent = isJSXComponent(node);
1232
+ const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
1233
+ if (!value && !modifiers.length) {
1234
+ context.options.onError(
1235
+ createCompilerError3(
1236
+ ErrorCodes3.X_V_ON_NO_EXPRESSION,
1237
+ resolveLocation(loc, context)
1238
+ )
1239
+ );
1240
+ }
1241
+ let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
1242
+ const exp = resolveExpression(dir.value, context);
1243
+ const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(
1244
+ arg.isStatic ? `on${nameString}` : arg,
1245
+ modifiers.map((modifier) => createSimpleExpression4(modifier)),
1246
+ null,
1247
+ resolveLocation(loc, context)
1248
+ );
1249
+ let keyOverride;
1250
+ const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
1251
+ if (nonKeyModifiers.includes("middle")) {
1252
+ if (keyOverride) {
1253
+ }
1254
+ if (isStaticClick) {
1255
+ arg = extend4({}, arg, { content: "mouseup" });
1256
+ } else if (!arg.isStatic) {
1257
+ keyOverride = ["click", "mouseup"];
1258
+ }
1259
+ }
1260
+ if (nonKeyModifiers.includes("right")) {
1261
+ if (isStaticClick) {
1262
+ arg = extend4({}, arg, { content: "contextmenu" });
1263
+ } else if (!arg.isStatic) {
1264
+ keyOverride = ["click", "contextmenu"];
1265
+ }
1266
+ }
1267
+ if (isComponent) {
1268
+ const handler = exp || EMPTY_EXPRESSION;
1269
+ return {
1270
+ key: arg,
1271
+ value: handler,
1272
+ handler: true,
1273
+ handlerModifiers: eventOptionModifiers
1274
+ };
1275
+ }
1276
+ const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
1277
+ const operation = {
1278
+ type: 5 /* SET_EVENT */,
1279
+ element: context.reference(),
1280
+ key: arg,
1281
+ value: exp,
1282
+ modifiers: {
1283
+ keys: keyModifiers,
1284
+ nonKeys: nonKeyModifiers,
1285
+ options: eventOptionModifiers
1286
+ },
1287
+ keyOverride,
1288
+ delegate,
1289
+ effect: !arg.isStatic
1290
+ };
1291
+ context.registerEffect([arg], operation);
1292
+ };
1293
+
1294
+ // src/transforms/vOnce.ts
1295
+ var transformVOnce = (node, context) => {
1296
+ if (
1297
+ // !context.inSSR &&
1298
+ node.type === "JSXElement" && findProp(node, "v-once")
1299
+ ) {
1300
+ context.inVOnce = true;
1301
+ }
1302
+ };
1303
+
1304
+ // src/transforms/vShow.ts
1305
+ import { transformVShow as _transformVShow } from "@vue/compiler-vapor";
1306
+ var transformVShow = (dir, node, context) => {
1307
+ return _transformVShow(
1308
+ resolveDirectiveNode(dir, context),
1309
+ resolveNode(node, context),
1310
+ context
1311
+ );
1312
+ };
1313
+
1314
+ // src/transforms/vSlot.ts
1315
+ import {
1316
+ createCompilerError as createCompilerError4,
1317
+ ErrorCodes as ErrorCodes4
1318
+ } from "@vue/compiler-dom";
1319
+ var transformVSlot = (node, context) => {
1320
+ if (node.type !== "JSXElement") return;
1321
+ const { children } = node;
1186
1322
  const dir = findProp(node, "v-slot");
1187
1323
  const resolvedDirective = dir ? resolveDirectiveNode(dir, context, true) : void 0;
1188
1324
  const { parent } = context;
@@ -1194,8 +1330,8 @@ var transformVSlot = (node, context) => {
1194
1330
  return transformTemplateSlot(node, resolvedDirective, context);
1195
1331
  } else if (!isComponent && dir) {
1196
1332
  context.options.onError(
1197
- createCompilerError3(
1198
- ErrorCodes3.X_V_SLOT_MISPLACED,
1333
+ createCompilerError4(
1334
+ ErrorCodes4.X_V_SLOT_MISPLACED,
1199
1335
  resolveLocation(dir.loc, context)
1200
1336
  )
1201
1337
  );
@@ -1205,7 +1341,7 @@ function transformComponentSlot(node, dir, context) {
1205
1341
  const { children } = node;
1206
1342
  const arg = dir && dir.arg;
1207
1343
  const nonSlotTemplateChildren = children.filter(
1208
- (n) => !isEmptyText(n) && !(n.type === "JSXElement" && findProp(n, "v-slot"))
1344
+ (n) => !isEmptyText(n) && (n.type !== "JSXElement" || !findProp(n, "v-slot"))
1209
1345
  );
1210
1346
  const [block, onExit] = createSlotBlock(node, dir, context);
1211
1347
  const { slots } = context;
@@ -1214,15 +1350,15 @@ function transformComponentSlot(node, dir, context) {
1214
1350
  const hasOtherSlots = !!slots.length;
1215
1351
  if (dir && hasOtherSlots) {
1216
1352
  context.options.onError(
1217
- createCompilerError3(ErrorCodes3.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc)
1353
+ createCompilerError4(ErrorCodes4.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc)
1218
1354
  );
1219
1355
  return;
1220
1356
  }
1221
1357
  if (nonSlotTemplateChildren.length) {
1222
1358
  if (hasStaticSlot(slots, "default")) {
1223
1359
  context.options.onError(
1224
- createCompilerError3(
1225
- ErrorCodes3.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
1360
+ createCompilerError4(
1361
+ ErrorCodes4.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
1226
1362
  resolveLocation(nonSlotTemplateChildren[0].loc, context)
1227
1363
  )
1228
1364
  );
@@ -1248,7 +1384,7 @@ function transformTemplateSlot(node, dir, context) {
1248
1384
  const slotName = arg ? arg.isStatic && arg.content : "default";
1249
1385
  if (slotName && hasStaticSlot(slots, slotName)) {
1250
1386
  context.options.onError(
1251
- createCompilerError3(ErrorCodes3.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc)
1387
+ createCompilerError4(ErrorCodes4.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc)
1252
1388
  );
1253
1389
  } else {
1254
1390
  registerSlot(slots, arg, block);
@@ -1287,7 +1423,7 @@ function transformTemplateSlot(node, dir, context) {
1287
1423
  ifNode.negative = negative;
1288
1424
  } else {
1289
1425
  context.options.onError(
1290
- createCompilerError3(ErrorCodes3.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc)
1426
+ createCompilerError4(ErrorCodes4.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc)
1291
1427
  );
1292
1428
  }
1293
1429
  } else if (vFor) {
@@ -1344,7 +1480,7 @@ function createSlotBlock(slotNode, dir, context) {
1344
1480
  }
1345
1481
 
1346
1482
  // src/transforms/vSlots.ts
1347
- import { ErrorCodes as ErrorCodes4, createCompilerError as createCompilerError4 } from "@vue/compiler-dom";
1483
+ import { createCompilerError as createCompilerError5, ErrorCodes as ErrorCodes5 } from "@vue/compiler-dom";
1348
1484
  var transformVSlots = (node, context) => {
1349
1485
  if (node.type !== "JSXElement" || !isJSXComponent(node)) return;
1350
1486
  const {
@@ -1365,8 +1501,8 @@ var transformVSlots = (node, context) => {
1365
1501
  ];
1366
1502
  if (children.length) {
1367
1503
  context.options.onError(
1368
- createCompilerError4(
1369
- ErrorCodes4.X_V_SLOT_MIXED_SLOT_USAGE,
1504
+ createCompilerError5(
1505
+ ErrorCodes5.X_V_SLOT_MIXED_SLOT_USAGE,
1370
1506
  resolveLocation(children[0].loc, context)
1371
1507
  )
1372
1508
  );
@@ -1374,144 +1510,6 @@ var transformVSlots = (node, context) => {
1374
1510
  }
1375
1511
  };
1376
1512
 
1377
- // src/transforms/vModel.ts
1378
- import { transformVModel as _transformVModel } from "@vue/compiler-vapor";
1379
- var transformVModel = (dir, node, context) => {
1380
- return _transformVModel(
1381
- resolveDirectiveNode(dir, context),
1382
- resolveNode(node, context),
1383
- context
1384
- );
1385
- };
1386
-
1387
- // src/transforms/vShow.ts
1388
- import { transformVShow as _transformVShow } from "@vue/compiler-vapor";
1389
- var transformVShow = (dir, node, context) => {
1390
- return _transformVShow(
1391
- resolveDirectiveNode(dir, context),
1392
- resolveNode(node, context),
1393
- context
1394
- );
1395
- };
1396
-
1397
- // src/transforms/vHtml.ts
1398
- import { transformVHtml as _transformVHtml } from "@vue/compiler-vapor";
1399
- var transformVHtml = (dir, node, context) => {
1400
- return _transformVHtml(
1401
- resolveDirectiveNode(dir, context),
1402
- resolveNode(node, context),
1403
- context
1404
- );
1405
- };
1406
-
1407
- // src/transforms/vOnce.ts
1408
- var transformVOnce = (node, context) => {
1409
- if (
1410
- // !context.inSSR &&
1411
- node.type === "JSXElement" && findProp(node, "v-once")
1412
- ) {
1413
- context.inVOnce = true;
1414
- }
1415
- };
1416
-
1417
- // src/transforms/vIf.ts
1418
- import {
1419
- ErrorCodes as ErrorCodes5,
1420
- createCompilerError as createCompilerError5,
1421
- createSimpleExpression as createSimpleExpression4,
1422
- isConstantNode as isConstantNode2
1423
- } from "@vue/compiler-dom";
1424
- var transformVIf = createStructuralDirectiveTransform(
1425
- ["if", "else", "else-if"],
1426
- processIf
1427
- );
1428
- var transformedIfNode = /* @__PURE__ */ new WeakMap();
1429
- function processIf(node, attribute, context) {
1430
- const dir = resolveDirectiveNode(attribute, context);
1431
- if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
1432
- const loc = dir.exp ? dir.exp.loc : resolveLocation(node.loc, context);
1433
- context.options.onError(
1434
- createCompilerError5(ErrorCodes5.X_V_IF_NO_EXPRESSION, dir.loc)
1435
- );
1436
- dir.exp = createSimpleExpression4(`true`, false, loc);
1437
- }
1438
- context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1439
- transformedIfNode.set(node, dir);
1440
- if (dir.name === "if") {
1441
- const id = context.reference();
1442
- context.dynamic.flags |= 4 /* INSERT */;
1443
- const [branch, onExit] = createBranch(node, context);
1444
- return () => {
1445
- onExit();
1446
- context.registerOperation({
1447
- type: 16 /* IF */,
1448
- id,
1449
- condition: dir.exp,
1450
- positive: branch,
1451
- once: context.inVOnce || isConstantNode2(attribute.value, context.options.bindingMetadata)
1452
- });
1453
- };
1454
- } else {
1455
- const siblingIf = getSiblingIf(context);
1456
- const { operation } = context.block;
1457
- let lastIfNode = operation.at(-1);
1458
- if (
1459
- // check if v-if is the sibling node
1460
- !siblingIf || // check if IfNode is the last operation and get the root IfNode
1461
- !lastIfNode || lastIfNode.type !== 16 /* IF */
1462
- ) {
1463
- context.options.onError(
1464
- createCompilerError5(
1465
- ErrorCodes5.X_V_ELSE_NO_ADJACENT_IF,
1466
- resolveLocation(node.loc, context)
1467
- )
1468
- );
1469
- return;
1470
- }
1471
- while (lastIfNode.negative && lastIfNode.negative.type === 16 /* IF */) {
1472
- lastIfNode = lastIfNode.negative;
1473
- }
1474
- if (dir.name === "else-if" && lastIfNode.negative) {
1475
- context.options.onError(
1476
- createCompilerError5(
1477
- ErrorCodes5.X_V_ELSE_NO_ADJACENT_IF,
1478
- resolveLocation(node.loc, context)
1479
- )
1480
- );
1481
- }
1482
- context.root.comment = [];
1483
- const [branch, onExit] = createBranch(node, context);
1484
- if (dir.name === "else") {
1485
- lastIfNode.negative = branch;
1486
- } else {
1487
- lastIfNode.negative = {
1488
- type: 16 /* IF */,
1489
- id: -1,
1490
- condition: dir.exp,
1491
- positive: branch,
1492
- once: context.inVOnce
1493
- };
1494
- }
1495
- return () => onExit();
1496
- }
1497
- }
1498
- function getSiblingIf(context) {
1499
- const parent = context.parent;
1500
- if (!parent) return;
1501
- const siblings = parent.node.children;
1502
- let sibling;
1503
- let i = siblings.indexOf(context.node);
1504
- while (--i >= 0) {
1505
- if (!isEmptyText(siblings[i])) {
1506
- sibling = siblings[i];
1507
- break;
1508
- }
1509
- }
1510
- if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) {
1511
- return sibling;
1512
- }
1513
- }
1514
-
1515
1513
  // src/compile.ts
1516
1514
  function compile(source, options = {}) {
1517
1515
  const resolvedOptions = extend5({}, options, {