@vue-jsx-vapor/compiler 2.1.0 → 2.1.2

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.cjs CHANGED
@@ -268,17 +268,25 @@ function resolveNode(node, context) {
268
268
  const props = node.openingElement.attributes.reduce(
269
269
  (result, attr) => {
270
270
  if (attr.type === "JSXAttribute") {
271
- if (tagType === _compilerdom.ElementTypes.COMPONENT) {
272
- result.push(resolveDirectiveNode(attr, context));
273
- } else {
274
- result.push({
271
+ result.push(
272
+ _optionalChain([attr, 'access', _9 => _9.value, 'optionalAccess', _10 => _10.type]) === "StringLiteral" ? {
275
273
  type: _compilerdom.NodeTypes.ATTRIBUTE,
276
274
  name: String(attr.name.name),
277
275
  nameLoc: resolveLocation(attr.name.loc, context),
278
276
  value: resolveValue(attr.value, context),
279
277
  loc: resolveLocation(attr.loc, context)
280
- });
281
- }
278
+ } : resolveDirectiveNode(attr, context)
279
+ );
280
+ } else if (attr.type === "JSXSpreadAttribute") {
281
+ result.push({
282
+ type: _compilerdom.NodeTypes.DIRECTIVE,
283
+ name: "bind",
284
+ rawName: getText(attr, context),
285
+ exp: resolveExpression(attr.argument, context),
286
+ arg: void 0,
287
+ loc: resolveLocation(node.loc, context),
288
+ modifiers: []
289
+ });
282
290
  }
283
291
  return result;
284
292
  },
@@ -300,34 +308,35 @@ var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
300
308
  function resolveDirectiveNode(node, context, withFn = false) {
301
309
  const { value, name } = node;
302
310
  let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
303
- let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
304
- if (name.type !== "JSXNamespacedName" && !argString) {
305
- const [newName, modifiers2] = nameString.split("_");
306
- nameString = newName;
307
- argString = `_${modifiers2}`;
308
- }
311
+ const isDirective = nameString.startsWith("v-");
309
312
  let modifiers = [];
310
313
  let isStatic = true;
311
- const result = argString.match(namespaceRE);
312
- if (result) {
313
- let modifierString = "";
314
- [, argString, modifierString] = result;
315
- if (argString) {
316
- argString = argString.replaceAll("_", ".");
317
- isStatic = false;
318
- if (modifierString && modifierString.startsWith("_"))
319
- modifiers = modifierString.slice(1).split("_");
320
- } else if (modifierString) {
321
- ;
322
- [argString, ...modifiers] = modifierString.split("_");
314
+ let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
315
+ if (name.type !== "JSXNamespacedName" && !argString) {
316
+ ;
317
+ [nameString, ...modifiers] = nameString.split("_");
318
+ } else {
319
+ const result = argString.match(namespaceRE);
320
+ if (result) {
321
+ let modifierString = "";
322
+ [, argString, modifierString] = result;
323
+ if (argString) {
324
+ argString = argString.replaceAll("_", ".");
325
+ isStatic = false;
326
+ if (modifierString && modifierString.startsWith("_"))
327
+ modifiers = modifierString.slice(1).split("_");
328
+ } else if (modifierString) {
329
+ ;
330
+ [argString, ...modifiers] = modifierString.split("_");
331
+ }
323
332
  }
324
333
  }
325
- const arg = argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0;
334
+ const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
326
335
  const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
327
336
  return {
328
337
  type: _compilerdom.NodeTypes.DIRECTIVE,
329
- name: nameString.slice(2),
330
- rawName: `${nameString}:${argString}`,
338
+ name: isDirective ? nameString.slice(2) : "bind",
339
+ rawName: getText(name, context),
331
340
  exp,
332
341
  arg,
333
342
  loc: resolveLocation(node.loc, context),
@@ -356,7 +365,7 @@ function isJSXComponent(node) {
356
365
  }
357
366
  }
358
367
  function findProp(expression, key) {
359
- if (_optionalChain([expression, 'optionalAccess', _9 => _9.type]) === "JSXElement") {
368
+ if (_optionalChain([expression, 'optionalAccess', _11 => _11.type]) === "JSXElement") {
360
369
  for (const attr of expression.openingElement.attributes) {
361
370
  const name = attr.type === "JSXAttribute" && (attr.name.type === "JSXIdentifier" ? attr.name.name : attr.name.type === "JSXNamespacedName" ? attr.name.namespace.name : "").split("_")[0];
362
371
  if (name && (_shared.isString.call(void 0, key) ? name === key : key.test(name))) {
@@ -649,11 +658,7 @@ function processDynamicChildren(context) {
649
658
  }
650
659
  }
651
660
  if (prevDynamics.length) {
652
- context.registerOperation({
653
- type: 9 /* INSERT_NODE */,
654
- elements: prevDynamics.map((child) => child.id),
655
- parent: context.reference()
656
- });
661
+ registerInsertion(prevDynamics, context);
657
662
  }
658
663
  }
659
664
  function registerInsertion(dynamics, context, anchor) {
@@ -665,13 +670,9 @@ function registerInsertion(dynamics, context, anchor) {
665
670
  parent: context.reference(),
666
671
  anchor
667
672
  });
668
- } else {
669
- for (const op of context.block.operation) {
670
- if (isBlockOperation(op) && op.id === child.id) {
671
- op.parent = context.reference();
672
- op.anchor = anchor;
673
- }
674
- }
673
+ } else if (child.operation && isBlockOperation(child.operation)) {
674
+ child.operation.parent = context.reference();
675
+ child.operation.anchor = anchor;
675
676
  }
676
677
  }
677
678
  }
@@ -842,7 +843,7 @@ function transformProp(prop, node, context) {
842
843
  if (prop.type === "JSXSpreadAttribute") return;
843
844
  let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
844
845
  name = name.split("_")[0];
845
- if (!isDirectiveRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
846
+ if (!isDirectiveRegex.test(name) && !isEventRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
846
847
  if (isReservedProp(name)) return;
847
848
  return {
848
849
  key: resolveSimpleExpression(name, true, prop.name.loc),
@@ -900,7 +901,7 @@ function mergePropValues(existing, incoming) {
900
901
  var transformTemplateRef = (node, context) => {
901
902
  if (node.type !== "JSXElement") return;
902
903
  const dir = findProp(node, "ref");
903
- if (!_optionalChain([dir, 'optionalAccess', _10 => _10.value])) return;
904
+ if (!_optionalChain([dir, 'optionalAccess', _12 => _12.value])) return;
904
905
  context.ir.hasTemplateRef = true;
905
906
  const value = resolveExpression(dir.value, context);
906
907
  return () => {
@@ -1046,7 +1047,6 @@ function processInterpolation(context) {
1046
1047
  }
1047
1048
  const id = context.reference();
1048
1049
  if (isFragmentNode(parent)) {
1049
- context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
1050
1050
  context.registerOperation({
1051
1051
  type: 18 /* CREATE_NODES */,
1052
1052
  id,
@@ -1597,7 +1597,7 @@ var transformVSlots = (node, context) => {
1597
1597
  (attr) => attr.type === "JSXAttribute" && attr.name.name.toString() === "v-slots"
1598
1598
  );
1599
1599
  const vSlotsDir = attributes[vSlotsIndex];
1600
- if (vSlotsDir && _optionalChain([vSlotsDir, 'access', _11 => _11.value, 'optionalAccess', _12 => _12.type]) === "JSXExpressionContainer") {
1600
+ if (vSlotsDir && _optionalChain([vSlotsDir, 'access', _13 => _13.value, 'optionalAccess', _14 => _14.type]) === "JSXExpressionContainer") {
1601
1601
  attributes.splice(vSlotsIndex, 1);
1602
1602
  context.slots = [
1603
1603
  {
package/dist/index.js CHANGED
@@ -268,17 +268,25 @@ function resolveNode(node, context) {
268
268
  const props = node.openingElement.attributes.reduce(
269
269
  (result, attr) => {
270
270
  if (attr.type === "JSXAttribute") {
271
- if (tagType === ElementTypes.COMPONENT) {
272
- result.push(resolveDirectiveNode(attr, context));
273
- } else {
274
- result.push({
271
+ result.push(
272
+ attr.value?.type === "StringLiteral" ? {
275
273
  type: NodeTypes.ATTRIBUTE,
276
274
  name: String(attr.name.name),
277
275
  nameLoc: resolveLocation(attr.name.loc, context),
278
276
  value: resolveValue(attr.value, context),
279
277
  loc: resolveLocation(attr.loc, context)
280
- });
281
- }
278
+ } : resolveDirectiveNode(attr, context)
279
+ );
280
+ } else if (attr.type === "JSXSpreadAttribute") {
281
+ result.push({
282
+ type: NodeTypes.DIRECTIVE,
283
+ name: "bind",
284
+ rawName: getText(attr, context),
285
+ exp: resolveExpression(attr.argument, context),
286
+ arg: void 0,
287
+ loc: resolveLocation(node.loc, context),
288
+ modifiers: []
289
+ });
282
290
  }
283
291
  return result;
284
292
  },
@@ -300,34 +308,35 @@ var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
300
308
  function resolveDirectiveNode(node, context, withFn = false) {
301
309
  const { value, name } = node;
302
310
  let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
303
- let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
304
- if (name.type !== "JSXNamespacedName" && !argString) {
305
- const [newName, modifiers2] = nameString.split("_");
306
- nameString = newName;
307
- argString = `_${modifiers2}`;
308
- }
311
+ const isDirective = nameString.startsWith("v-");
309
312
  let modifiers = [];
310
313
  let isStatic = true;
311
- const result = argString.match(namespaceRE);
312
- if (result) {
313
- let modifierString = "";
314
- [, argString, modifierString] = result;
315
- if (argString) {
316
- argString = argString.replaceAll("_", ".");
317
- isStatic = false;
318
- if (modifierString && modifierString.startsWith("_"))
319
- modifiers = modifierString.slice(1).split("_");
320
- } else if (modifierString) {
321
- ;
322
- [argString, ...modifiers] = modifierString.split("_");
314
+ let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
315
+ if (name.type !== "JSXNamespacedName" && !argString) {
316
+ ;
317
+ [nameString, ...modifiers] = nameString.split("_");
318
+ } else {
319
+ const result = argString.match(namespaceRE);
320
+ if (result) {
321
+ let modifierString = "";
322
+ [, argString, modifierString] = result;
323
+ if (argString) {
324
+ argString = argString.replaceAll("_", ".");
325
+ isStatic = false;
326
+ if (modifierString && modifierString.startsWith("_"))
327
+ modifiers = modifierString.slice(1).split("_");
328
+ } else if (modifierString) {
329
+ ;
330
+ [argString, ...modifiers] = modifierString.split("_");
331
+ }
323
332
  }
324
333
  }
325
- const arg = argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0;
334
+ const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
326
335
  const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
327
336
  return {
328
337
  type: NodeTypes.DIRECTIVE,
329
- name: nameString.slice(2),
330
- rawName: `${nameString}:${argString}`,
338
+ name: isDirective ? nameString.slice(2) : "bind",
339
+ rawName: getText(name, context),
331
340
  exp,
332
341
  arg,
333
342
  loc: resolveLocation(node.loc, context),
@@ -649,11 +658,7 @@ function processDynamicChildren(context) {
649
658
  }
650
659
  }
651
660
  if (prevDynamics.length) {
652
- context.registerOperation({
653
- type: 9 /* INSERT_NODE */,
654
- elements: prevDynamics.map((child) => child.id),
655
- parent: context.reference()
656
- });
661
+ registerInsertion(prevDynamics, context);
657
662
  }
658
663
  }
659
664
  function registerInsertion(dynamics, context, anchor) {
@@ -665,13 +670,9 @@ function registerInsertion(dynamics, context, anchor) {
665
670
  parent: context.reference(),
666
671
  anchor
667
672
  });
668
- } else {
669
- for (const op of context.block.operation) {
670
- if (isBlockOperation(op) && op.id === child.id) {
671
- op.parent = context.reference();
672
- op.anchor = anchor;
673
- }
674
- }
673
+ } else if (child.operation && isBlockOperation(child.operation)) {
674
+ child.operation.parent = context.reference();
675
+ child.operation.anchor = anchor;
675
676
  }
676
677
  }
677
678
  }
@@ -842,7 +843,7 @@ function transformProp(prop, node, context) {
842
843
  if (prop.type === "JSXSpreadAttribute") return;
843
844
  let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
844
845
  name = name.split("_")[0];
845
- if (!isDirectiveRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
846
+ if (!isDirectiveRegex.test(name) && !isEventRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
846
847
  if (isReservedProp(name)) return;
847
848
  return {
848
849
  key: resolveSimpleExpression(name, true, prop.name.loc),
@@ -1046,7 +1047,6 @@ function processInterpolation(context) {
1046
1047
  }
1047
1048
  const id = context.reference();
1048
1049
  if (isFragmentNode(parent)) {
1049
- context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
1050
1050
  context.registerOperation({
1051
1051
  type: 18 /* CREATE_NODES */,
1052
1052
  id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-jsx-vapor/compiler",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Vue JSX Vapor Compiler",
5
5
  "type": "module",
6
6
  "keywords": [