@vue-jsx-vapor/compiler 0.2.4 → 0.2.5

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
@@ -59,47 +59,13 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
59
59
  })(DynamicFlag || {});
60
60
 
61
61
  // src/transforms/utils.ts
62
- import { createSimpleExpression } from "@vue/compiler-dom";
62
+ import { createSimpleExpression as createSimpleExpression2 } from "@vue/compiler-dom";
63
63
  import {
64
64
  jsxClosingFragment,
65
65
  jsxExpressionContainer,
66
66
  jsxFragment,
67
67
  jsxOpeningFragment
68
68
  } from "@babel/types";
69
- function newDynamic() {
70
- return {
71
- flags: 1 /* REFERENCED */,
72
- children: []
73
- };
74
- }
75
- function newBlock(node) {
76
- return {
77
- type: 1,
78
- node,
79
- dynamic: newDynamic(),
80
- effect: [],
81
- operation: [],
82
- returns: [],
83
- expressions: [],
84
- tempId: 0
85
- };
86
- }
87
- function createBranch(node, context, isVFor) {
88
- context.node = node = wrapFragment(node);
89
- const branch = newBlock(node);
90
- const exitBlock = context.enterBlock(branch, isVFor);
91
- context.reference();
92
- return [branch, exitBlock];
93
- }
94
- function wrapFragment(node) {
95
- if (node.type === "JSXFragment") {
96
- return node;
97
- }
98
- return jsxFragment(jsxOpeningFragment(), jsxClosingFragment(), [
99
- node.type === "JSXElement" ? node : jsxExpressionContainer(node)
100
- ]);
101
- }
102
- var EMPTY_EXPRESSION = createSimpleExpression("", true);
103
69
 
104
70
  // src/utils.ts
105
71
  import { isGloballyAllowed, isHTMLTag, isSVGTag, isString } from "@vue/shared";
@@ -107,13 +73,14 @@ import {
107
73
  ElementTypes,
108
74
  Namespaces,
109
75
  NodeTypes,
110
- createSimpleExpression as createSimpleExpression2,
76
+ createSimpleExpression,
111
77
  isLiteralWhitelisted,
112
78
  walkIdentifiers
113
79
  } from "@vue/compiler-dom";
114
80
  import {
115
81
  isLiteral
116
82
  } from "@babel/types";
83
+ import { parseExpression } from "@babel/parser";
117
84
  function propToExpression(prop, context) {
118
85
  return prop.type === "JSXAttribute" && prop.value?.type === "JSXExpressionContainer" ? resolveExpression(prop.value.expression, context) : EMPTY_EXPRESSION;
119
86
  }
@@ -170,6 +137,15 @@ function resolveJSXText(node) {
170
137
  function isEmptyText(node) {
171
138
  return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(`${node.extra?.raw}`) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
172
139
  }
140
+ function resolveSimpleExpressionNode(exp) {
141
+ if (!exp.isStatic) {
142
+ const value = getLiteralExpressionValue(exp);
143
+ if (value !== null) {
144
+ return createSimpleExpression(`${value}`, true, exp.loc);
145
+ }
146
+ }
147
+ return exp;
148
+ }
173
149
  function resolveExpression(node, context, effect = false) {
174
150
  node = node?.type === "JSXExpressionContainer" ? node.expression : node;
175
151
  const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
@@ -197,7 +173,7 @@ function resolveExpression(node, context, effect = false) {
197
173
  return resolveSimpleExpression(source, isStatic, location, node);
198
174
  }
199
175
  function resolveSimpleExpression(source, isStatic, location, ast) {
200
- const result = createSimpleExpression2(
176
+ const result = createSimpleExpression(
201
177
  source,
202
178
  isStatic,
203
179
  resolveLocation(location, source)
@@ -269,23 +245,54 @@ function resolveNode(node, context) {
269
245
  codegenNode: void 0
270
246
  };
271
247
  }
272
- function resolveDirectiveNode(node, context) {
248
+ var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
249
+ function resolveDirectiveNode(node, context, withFn = false) {
273
250
  const { value, name } = node;
274
- const nameString = name.type === "JSXIdentifier" ? name.name : "";
275
- const argString = name.type === "JSXNamespacedName" ? name.namespace.name : "";
276
- const arg = name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, true, name.namespace.loc) : void 0;
277
- const exp = value ? resolveExpression(value, context) : void 0;
278
- const [tag, ...modifiers] = argString.split("_");
251
+ const nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
252
+ let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
253
+ if (name.type !== "JSXNamespacedName" && !argString) {
254
+ const [, modifiers2] = nameString.split("_");
255
+ argString = `_${modifiers2}`;
256
+ }
257
+ let modifiers = [];
258
+ let isStatic = true;
259
+ const result = argString.match(namespaceRE);
260
+ if (result) {
261
+ let modifierString = "";
262
+ [, argString, modifierString] = result;
263
+ if (argString) {
264
+ argString = argString.replaceAll("_", ".");
265
+ isStatic = false;
266
+ if (modifierString && modifierString.startsWith("_"))
267
+ modifiers = modifierString.slice(1).split("_");
268
+ } else if (modifierString) {
269
+ ;
270
+ [argString, ...modifiers] = modifierString.split("_");
271
+ }
272
+ }
273
+ const arg = argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0;
274
+ const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
279
275
  return {
280
276
  type: NodeTypes.DIRECTIVE,
281
277
  name: nameString,
282
- rawName: `${name}:${tag}`,
278
+ rawName: `${nameString}:${argString}`,
283
279
  exp,
284
280
  arg,
285
281
  loc: resolveLocation(node.loc, context),
286
- modifiers: modifiers.map((modifier) => createSimpleExpression2(modifier))
282
+ modifiers: modifiers.map((modifier) => createSimpleExpression(modifier))
287
283
  };
288
284
  }
285
+ function resolveExpressionWithFn(node, context) {
286
+ const text = getText(node, context);
287
+ return node.type === "Identifier" ? resolveSimpleExpression(text, false, node.loc) : resolveSimpleExpression(
288
+ text,
289
+ false,
290
+ node.loc,
291
+ parseExpression(`(${text})=>{}`, {
292
+ plugins: ["typescript"]
293
+ })
294
+ );
295
+ }
289
296
  function isJSXComponent(node) {
290
297
  if (node.type !== "JSXElement") return false;
291
298
  const { openingElement } = node;
@@ -299,7 +306,8 @@ function isJSXComponent(node) {
299
306
  function findProp(expression, key) {
300
307
  if (expression?.type === "JSXElement") {
301
308
  for (const attr of expression.openingElement.attributes) {
302
- if (attr.type === "JSXAttribute" && attr.name.name === key) {
309
+ const name = attr.type === "JSXAttribute" && (attr.name.type === "JSXIdentifier" ? attr.name.name : attr.name.type === "JSXNamespacedName" ? attr.name.namespace.name : "").split("_")[0];
310
+ if (name && (isString(key) ? name === key : key.test(name))) {
303
311
  return attr;
304
312
  }
305
313
  }
@@ -308,6 +316,47 @@ function findProp(expression, key) {
308
316
  function getText(node, content) {
309
317
  return content.ir.source.slice(node.start, node.end);
310
318
  }
319
+ function isTemplate(node) {
320
+ if (node.type === "JSXElement" && node.openingElement.name.type === "JSXIdentifier") {
321
+ return node.openingElement.name.name === "template";
322
+ }
323
+ }
324
+
325
+ // src/transforms/utils.ts
326
+ function newDynamic() {
327
+ return {
328
+ flags: 1 /* REFERENCED */,
329
+ children: []
330
+ };
331
+ }
332
+ function newBlock(node) {
333
+ return {
334
+ type: 1,
335
+ node,
336
+ dynamic: newDynamic(),
337
+ effect: [],
338
+ operation: [],
339
+ returns: [],
340
+ expressions: [],
341
+ tempId: 0
342
+ };
343
+ }
344
+ function createBranch(node, context, isVFor) {
345
+ context.node = node = wrapFragment(node);
346
+ const branch = newBlock(node);
347
+ const exitBlock = context.enterBlock(branch, isVFor);
348
+ context.reference();
349
+ return [branch, exitBlock];
350
+ }
351
+ function wrapFragment(node) {
352
+ if (node.type === "JSXFragment" || isTemplate(node)) {
353
+ return node;
354
+ }
355
+ return jsxFragment(jsxOpeningFragment(), jsxClosingFragment(), [
356
+ node.type === "JSXElement" ? node : jsxExpressionContainer(node)
357
+ ]);
358
+ }
359
+ var EMPTY_EXPRESSION = createSimpleExpression2("", true);
311
360
 
312
361
  // src/transform.ts
313
362
  var defaultOptions = {
@@ -471,9 +520,9 @@ function createStructuralDirectiveTransform(name, fn) {
471
520
  return (node, context) => {
472
521
  if (node.type === "JSXElement") {
473
522
  const {
474
- openingElement: { attributes, name: name2 }
523
+ openingElement: { attributes }
475
524
  } = node;
476
- if (getText(name2, context) === "template" && findProp(node, "v-slot")) {
525
+ if (isTemplate(node) && findProp(node, "v-slot")) {
477
526
  return;
478
527
  }
479
528
  const exitFns = [];
@@ -507,7 +556,7 @@ var transformElement = (node, context) => {
507
556
  return function postTransformElement() {
508
557
  ;
509
558
  ({ node } = context);
510
- if (node.type !== "JSXElement") return;
559
+ if (node.type !== "JSXElement" || isTemplate(node)) return;
511
560
  const {
512
561
  openingElement: { name }
513
562
  } = node;
@@ -518,7 +567,11 @@ var transformElement = (node, context) => {
518
567
  context,
519
568
  isComponent
520
569
  );
521
- const singleRoot = context.root === context.parent && context.parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
570
+ let { parent } = context;
571
+ while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) {
572
+ parent = parent.parent;
573
+ }
574
+ const singleRoot = context.root === parent && parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
522
575
  (isComponent ? transformComponentElement : transformNativeElement)(
523
576
  tag,
524
577
  propsResult,
@@ -653,6 +706,7 @@ function buildProps(node, context, isComponent) {
653
706
  function transformProp(prop, node, context) {
654
707
  if (prop.type === "JSXSpreadAttribute") return;
655
708
  let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
709
+ name = name.split("_")[0];
656
710
  if (!isDirectiveRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
657
711
  if (isReservedProp(name)) return;
658
712
  return {
@@ -709,7 +763,7 @@ function mergePropValues(existing, incoming) {
709
763
 
710
764
  // src/transforms/transformChildren.ts
711
765
  var transformChildren = (node, context) => {
712
- const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || isJSXComponent(node);
766
+ const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
713
767
  if (node.type !== "JSXElement" && !isFragment) return;
714
768
  for (const [i, child] of node.children.entries()) {
715
769
  const childContext = context.create(child, i);
@@ -868,7 +922,7 @@ var transformText = (node, context) => {
868
922
  context.dynamic.flags |= 2 /* NON_TEMPLATE */;
869
923
  return;
870
924
  }
871
- if (node.type === "JSXElement" && !isJSXComponent(node) && isAllTextLike(node.children)) {
925
+ if (node.type === "JSXElement" && !isTemplate(node) && !isJSXComponent(node) && isAllTextLike(node.children)) {
872
926
  processTextLikeContainer(
873
927
  node.children,
874
928
  context
@@ -1037,42 +1091,211 @@ var transformVOn = (dir, node, context) => {
1037
1091
  };
1038
1092
 
1039
1093
  // src/transforms/vSlot.ts
1040
- var transformVSlot = (node, context) => {
1041
- if (node.type !== "JSXElement") return;
1042
- if (!isJSXComponent(node)) return;
1043
- const { openingElement, children } = node;
1044
- const vSlotsIndex = openingElement.attributes.findIndex(
1045
- (attr) => attr.type === "JSXAttribute" && ["v-slots", "vSlots"].includes(attr.name.name.toString())
1046
- );
1047
- const vSlotsDir = openingElement.attributes[vSlotsIndex];
1048
- if (vSlotsDir && vSlotsDir.value?.type === "JSXExpressionContainer") {
1049
- node.openingElement.attributes.splice(vSlotsIndex, 1);
1050
- context.slots = [
1051
- {
1052
- slotType: 4 /* EXPRESSION */,
1053
- slots: resolveExpression(vSlotsDir.value.expression, context)
1094
+ import {
1095
+ ErrorCodes as ErrorCodes3,
1096
+ createCompilerError as createCompilerError3
1097
+ } from "@vue/compiler-dom";
1098
+
1099
+ // src/transforms/vFor.ts
1100
+ import {
1101
+ ErrorCodes as ErrorCodes2,
1102
+ createCompilerError as createCompilerError2,
1103
+ isConstantNode
1104
+ } from "@vue/compiler-dom";
1105
+ var transformVFor = createStructuralDirectiveTransform(
1106
+ "for",
1107
+ processFor
1108
+ );
1109
+ function processFor(node, dir, context) {
1110
+ const { value, index, key, source } = getForParseResult(dir, context);
1111
+ if (!source) {
1112
+ context.options.onError(
1113
+ createCompilerError2(
1114
+ ErrorCodes2.X_V_FOR_MALFORMED_EXPRESSION,
1115
+ resolveLocation(dir.loc, context)
1116
+ )
1117
+ );
1118
+ return;
1119
+ }
1120
+ const keyProp = findProp(node, "key");
1121
+ const keyProperty = keyProp && propToExpression(keyProp, context);
1122
+ const isComponent = isJSXComponent(node);
1123
+ const id = context.reference();
1124
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1125
+ const [render, exitBlock] = createBranch(node, context, true);
1126
+ return () => {
1127
+ exitBlock();
1128
+ const { parent } = context;
1129
+ const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
1130
+ context.registerOperation({
1131
+ type: 17 /* FOR */,
1132
+ id,
1133
+ source,
1134
+ value,
1135
+ key,
1136
+ index,
1137
+ keyProp: keyProperty,
1138
+ render,
1139
+ once: context.inVOnce || !!(source.ast && isConstantNode(source.ast, {})),
1140
+ component: isComponent,
1141
+ onlyChild: !!isOnlyChild
1142
+ });
1143
+ };
1144
+ }
1145
+ function getForParseResult(dir, context) {
1146
+ let value, index, key, source;
1147
+ if (dir.value) {
1148
+ if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
1149
+ if (dir.value.expression.left.type === "SequenceExpression") {
1150
+ const expressions = dir.value.expression.left.expressions;
1151
+ value = expressions[0] && resolveExpressionWithFn(expressions[0], context);
1152
+ key = expressions[1] && resolveExpression(expressions[1], context);
1153
+ index = expressions[2] && resolveExpression(expressions[2], context);
1154
+ } else {
1155
+ value = resolveExpressionWithFn(dir.value.expression.left, context);
1054
1156
  }
1055
- ];
1157
+ source = resolveExpression(dir.value.expression.right, context);
1158
+ }
1159
+ } else {
1160
+ context.options.onError(
1161
+ createCompilerError2(
1162
+ ErrorCodes2.X_V_FOR_NO_EXPRESSION,
1163
+ resolveLocation(dir.loc, context)
1164
+ )
1165
+ );
1056
1166
  }
1057
- if (children.length) {
1058
- return transformComponentSlot(node, context);
1167
+ return {
1168
+ value,
1169
+ index,
1170
+ key,
1171
+ source
1172
+ };
1173
+ }
1174
+
1175
+ // src/transforms/vSlot.ts
1176
+ var transformVSlot = (node, context) => {
1177
+ if (node.type !== "JSXElement") return;
1178
+ const { children } = node;
1179
+ const dir = findProp(node, "v-slot");
1180
+ const resolvedDirective = dir ? resolveDirectiveNode(dir, context, true) : void 0;
1181
+ const { parent } = context;
1182
+ const isComponent = isJSXComponent(node);
1183
+ const isSlotTemplate = isTemplate(node) && parent && parent.node.type === "JSXElement" && isJSXComponent(parent.node);
1184
+ if (isComponent && children.length) {
1185
+ return transformComponentSlot(node, resolvedDirective, context);
1186
+ } else if (isSlotTemplate && resolvedDirective) {
1187
+ return transformTemplateSlot(node, resolvedDirective, context);
1188
+ } else if (!isComponent && dir) {
1189
+ context.options.onError(
1190
+ createCompilerError3(
1191
+ ErrorCodes3.X_V_SLOT_MISPLACED,
1192
+ resolveLocation(dir.loc, context)
1193
+ )
1194
+ );
1059
1195
  }
1060
1196
  };
1061
- function transformComponentSlot(node, context) {
1197
+ function transformComponentSlot(node, dir, context) {
1062
1198
  const { children } = node;
1063
- const nonWhitespaceChildren = children.filter(
1064
- () => isNonWhitespaceContent(node)
1199
+ const arg = dir && dir.arg;
1200
+ const nonSlotTemplateChildren = children.filter(
1201
+ (n) => isNonWhitespaceContent(n) && !(n.type === "JSXElement" && findProp(n, "v-slot"))
1065
1202
  );
1066
- const [block, onExit] = createSlotBlock(node, context);
1203
+ const [block, onExit] = createSlotBlock(node, dir, context);
1067
1204
  const { slots } = context;
1068
1205
  return () => {
1069
1206
  onExit();
1070
- if (nonWhitespaceChildren.length) {
1071
- registerSlot(slots, block);
1207
+ const hasOtherSlots = !!slots.length;
1208
+ if (dir && hasOtherSlots) {
1209
+ context.options.onError(
1210
+ createCompilerError3(ErrorCodes3.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc)
1211
+ );
1212
+ return;
1213
+ }
1214
+ if (nonSlotTemplateChildren.length) {
1215
+ if (hasStaticSlot(slots, "default")) {
1216
+ context.options.onError(
1217
+ createCompilerError3(
1218
+ ErrorCodes3.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
1219
+ resolveLocation(nonSlotTemplateChildren[0].loc, context)
1220
+ )
1221
+ );
1222
+ } else {
1223
+ registerSlot(slots, arg, block);
1224
+ context.slots = slots;
1225
+ }
1226
+ } else if (hasOtherSlots) {
1072
1227
  context.slots = slots;
1073
1228
  }
1074
1229
  };
1075
1230
  }
1231
+ var elseIfRE = /^else(-if)?$/;
1232
+ function transformTemplateSlot(node, dir, context) {
1233
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1234
+ const arg = dir.arg && resolveSimpleExpressionNode(dir.arg);
1235
+ const vFor = findProp(node, "v-for");
1236
+ const vIf = findProp(node, "v-if");
1237
+ const vElse = findProp(node, elseIfRE);
1238
+ const { slots } = context;
1239
+ const [block, onExit] = createSlotBlock(node, dir, context);
1240
+ if (!vFor && !vIf && !vElse) {
1241
+ const slotName = arg ? arg.isStatic && arg.content : "default";
1242
+ if (slotName && hasStaticSlot(slots, slotName)) {
1243
+ context.options.onError(
1244
+ createCompilerError3(ErrorCodes3.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc)
1245
+ );
1246
+ } else {
1247
+ registerSlot(slots, arg, block);
1248
+ }
1249
+ } else if (vIf) {
1250
+ const vIfDir = resolveDirectiveNode(vIf, context);
1251
+ registerDynamicSlot(slots, {
1252
+ slotType: 3 /* CONDITIONAL */,
1253
+ condition: vIfDir.exp,
1254
+ positive: {
1255
+ slotType: 1 /* DYNAMIC */,
1256
+ name: arg,
1257
+ fn: block
1258
+ }
1259
+ });
1260
+ } else if (vElse) {
1261
+ const vElseDir = resolveDirectiveNode(vElse, context);
1262
+ const vIfSlot = slots.at(-1);
1263
+ if (vIfSlot.slotType === 3 /* CONDITIONAL */) {
1264
+ let ifNode = vIfSlot;
1265
+ while (ifNode.negative && ifNode.negative.slotType === 3 /* CONDITIONAL */)
1266
+ ifNode = ifNode.negative;
1267
+ const negative = vElseDir.exp ? {
1268
+ slotType: 3 /* CONDITIONAL */,
1269
+ condition: vElseDir.exp,
1270
+ positive: {
1271
+ slotType: 1 /* DYNAMIC */,
1272
+ name: arg,
1273
+ fn: block
1274
+ }
1275
+ } : {
1276
+ slotType: 1 /* DYNAMIC */,
1277
+ name: arg,
1278
+ fn: block
1279
+ };
1280
+ ifNode.negative = negative;
1281
+ } else {
1282
+ context.options.onError(
1283
+ createCompilerError3(ErrorCodes3.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc)
1284
+ );
1285
+ }
1286
+ } else if (vFor) {
1287
+ const forParseResult = getForParseResult(vFor, context);
1288
+ if (forParseResult.source) {
1289
+ registerDynamicSlot(slots, {
1290
+ slotType: 2 /* LOOP */,
1291
+ name: arg,
1292
+ fn: block,
1293
+ loop: forParseResult
1294
+ });
1295
+ }
1296
+ }
1297
+ return onExit;
1298
+ }
1076
1299
  function ensureStaticSlots(slots) {
1077
1300
  let lastSlots = slots.at(-1);
1078
1301
  if (!slots.length || lastSlots.slotType !== 0 /* STATIC */) {
@@ -1083,14 +1306,32 @@ function ensureStaticSlots(slots) {
1083
1306
  }
1084
1307
  );
1085
1308
  }
1086
- return lastSlots;
1309
+ return lastSlots.slots;
1310
+ }
1311
+ function registerSlot(slots, name, block) {
1312
+ const isStatic = !name || name.isStatic;
1313
+ if (isStatic) {
1314
+ const staticSlots = ensureStaticSlots(slots);
1315
+ staticSlots[name ? name.content : "default"] = block;
1316
+ } else {
1317
+ slots.push({
1318
+ slotType: 1 /* DYNAMIC */,
1319
+ name,
1320
+ fn: block
1321
+ });
1322
+ }
1087
1323
  }
1088
- function registerSlot(slots, block) {
1089
- const staticSlots = ensureStaticSlots(slots);
1090
- staticSlots.slots.default = block;
1324
+ function registerDynamicSlot(allSlots, dynamic) {
1325
+ allSlots.push(dynamic);
1091
1326
  }
1092
- function createSlotBlock(slotNode, context) {
1327
+ function hasStaticSlot(slots, name) {
1328
+ return slots.some(
1329
+ (slot) => slot.slotType === 0 /* STATIC */ ? !!slot.slots[name] : false
1330
+ );
1331
+ }
1332
+ function createSlotBlock(slotNode, dir, context) {
1093
1333
  const block = newBlock(slotNode);
1334
+ block.props = dir && dir.exp;
1094
1335
  const exitBlock = context.enterBlock(block);
1095
1336
  return [block, exitBlock];
1096
1337
  }
@@ -1099,6 +1340,37 @@ function isNonWhitespaceContent(node) {
1099
1340
  return !!node.value.trim();
1100
1341
  }
1101
1342
 
1343
+ // src/transforms/vSlots.ts
1344
+ import { ErrorCodes as ErrorCodes4, createCompilerError as createCompilerError4 } from "@vue/compiler-dom";
1345
+ var transformVSlots = (node, context) => {
1346
+ if (node.type !== "JSXElement" || !isJSXComponent(node)) return;
1347
+ const {
1348
+ openingElement: { attributes },
1349
+ children
1350
+ } = node;
1351
+ const vSlotsIndex = attributes.findIndex(
1352
+ (attr) => attr.type === "JSXAttribute" && attr.name.name.toString() === "v-slots"
1353
+ );
1354
+ const vSlotsDir = attributes[vSlotsIndex];
1355
+ if (vSlotsDir && vSlotsDir.value?.type === "JSXExpressionContainer") {
1356
+ attributes.splice(vSlotsIndex, 1);
1357
+ context.slots = [
1358
+ {
1359
+ slotType: 4 /* EXPRESSION */,
1360
+ slots: resolveExpression(vSlotsDir.value.expression, context)
1361
+ }
1362
+ ];
1363
+ if (children.length) {
1364
+ context.options.onError(
1365
+ createCompilerError4(
1366
+ ErrorCodes4.X_V_SLOT_MIXED_SLOT_USAGE,
1367
+ resolveLocation(children[0].loc, context)
1368
+ )
1369
+ );
1370
+ }
1371
+ }
1372
+ };
1373
+
1102
1374
  // src/transforms/vModel.ts
1103
1375
  import { transformVModel as _transformVModel } from "@vue/compiler-vapor";
1104
1376
  var transformVModel = (dir, node, context) => {
@@ -1129,86 +1401,6 @@ var transformVHtml = (dir, node, context) => {
1129
1401
  );
1130
1402
  };
1131
1403
 
1132
- // src/transforms/vFor.ts
1133
- import {
1134
- ErrorCodes as ErrorCodes2,
1135
- createCompilerError as createCompilerError2,
1136
- forAliasRE,
1137
- isConstantNode
1138
- } from "@vue/compiler-dom";
1139
- import { parseExpression } from "@babel/parser";
1140
- var transformVFor = createStructuralDirectiveTransform(
1141
- "for",
1142
- processFor
1143
- );
1144
- function processFor(node, dir, context) {
1145
- if (!dir.value) {
1146
- context.options.onError(
1147
- createCompilerError2(
1148
- ErrorCodes2.X_V_FOR_NO_EXPRESSION,
1149
- resolveLocation(dir.loc, context)
1150
- )
1151
- );
1152
- return;
1153
- }
1154
- if (!forAliasRE) {
1155
- context.options.onError(
1156
- createCompilerError2(
1157
- ErrorCodes2.X_V_FOR_MALFORMED_EXPRESSION,
1158
- resolveLocation(dir.loc, context)
1159
- )
1160
- );
1161
- return;
1162
- }
1163
- let value, index, key, source;
1164
- if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
1165
- if (dir.value.expression.left.type === "SequenceExpression") {
1166
- const expressions = dir.value.expression.left.expressions;
1167
- value = expressions[0] && resolveValueExpression(expressions[0], context);
1168
- key = expressions[1] && resolveExpression(expressions[1], context);
1169
- index = expressions[2] && resolveExpression(expressions[2], context);
1170
- } else {
1171
- value = resolveValueExpression(dir.value.expression.left, context);
1172
- }
1173
- source = resolveExpression(dir.value.expression.right, context);
1174
- }
1175
- const keyProp = findProp(node, "key");
1176
- const keyProperty = keyProp && propToExpression(keyProp, context);
1177
- const isComponent = isJSXComponent(node);
1178
- const id = context.reference();
1179
- context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1180
- const [render, exitBlock] = createBranch(node, context, true);
1181
- return () => {
1182
- exitBlock();
1183
- const { parent } = context;
1184
- const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
1185
- context.registerOperation({
1186
- type: 17 /* FOR */,
1187
- id,
1188
- source,
1189
- value,
1190
- key,
1191
- index,
1192
- keyProp: keyProperty,
1193
- render,
1194
- once: context.inVOnce || !!(source.ast && isConstantNode(source.ast, {})),
1195
- component: isComponent,
1196
- onlyChild: !!isOnlyChild
1197
- });
1198
- };
1199
- }
1200
- function resolveValueExpression(node, context) {
1201
- const text = getText(node, context);
1202
- return node.type === "Identifier" ? resolveSimpleExpression(text, false, node.loc) : resolveSimpleExpression(
1203
- text,
1204
- false,
1205
- node.loc,
1206
- parseExpression(`(${text})=>{}`, {
1207
- plugins: ["typescript"]
1208
- })
1209
- );
1210
- }
1211
-
1212
1404
  // src/compile.ts
1213
1405
  function compile(source, options = {}) {
1214
1406
  const resolvedOptions = extend5({}, options, {
@@ -1264,6 +1456,7 @@ function getBaseTransformPreset() {
1264
1456
  transformTemplateRef,
1265
1457
  transformText,
1266
1458
  transformElement,
1459
+ transformVSlots,
1267
1460
  transformVSlot,
1268
1461
  transformChildren
1269
1462
  ],
@@ -1299,5 +1492,6 @@ export {
1299
1492
  transformVModel,
1300
1493
  transformVOn,
1301
1494
  transformVShow,
1302
- transformVSlot
1495
+ transformVSlot,
1496
+ transformVSlots
1303
1497
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-jsx-vapor/compiler",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Vue JSX Vapor Compiler",
5
5
  "type": "module",
6
6
  "keywords": [