@vue-jsx-vapor/compiler 0.0.0 → 0.0.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
@@ -20,6 +20,7 @@ var _parser = require('@babel/parser');
20
20
 
21
21
 
22
22
 
23
+
23
24
  // src/transforms/utils.ts
24
25
 
25
26
 
@@ -288,15 +289,16 @@ var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
288
289
  IRNodeTypes2[IRNodeTypes2["SET_HTML"] = 7] = "SET_HTML";
289
290
  IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
290
291
  IRNodeTypes2[IRNodeTypes2["SET_MODEL_VALUE"] = 9] = "SET_MODEL_VALUE";
291
- IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 10] = "INSERT_NODE";
292
- IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 11] = "PREPEND_NODE";
293
- IRNodeTypes2[IRNodeTypes2["CREATE_TEXT_NODE"] = 12] = "CREATE_TEXT_NODE";
294
- IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 13] = "CREATE_COMPONENT_NODE";
295
- IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 14] = "SLOT_OUTLET_NODE";
296
- IRNodeTypes2[IRNodeTypes2["WITH_DIRECTIVE"] = 15] = "WITH_DIRECTIVE";
297
- IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 16] = "DECLARE_OLD_REF";
298
- IRNodeTypes2[IRNodeTypes2["IF"] = 17] = "IF";
299
- IRNodeTypes2[IRNodeTypes2["FOR"] = 18] = "FOR";
292
+ IRNodeTypes2[IRNodeTypes2["SET_INHERIT_ATTRS"] = 10] = "SET_INHERIT_ATTRS";
293
+ IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 11] = "INSERT_NODE";
294
+ IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 12] = "PREPEND_NODE";
295
+ IRNodeTypes2[IRNodeTypes2["CREATE_TEXT_NODE"] = 13] = "CREATE_TEXT_NODE";
296
+ IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 14] = "CREATE_COMPONENT_NODE";
297
+ IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 15] = "SLOT_OUTLET_NODE";
298
+ IRNodeTypes2[IRNodeTypes2["WITH_DIRECTIVE"] = 16] = "WITH_DIRECTIVE";
299
+ IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 17] = "DECLARE_OLD_REF";
300
+ IRNodeTypes2[IRNodeTypes2["IF"] = 18] = "IF";
301
+ IRNodeTypes2[IRNodeTypes2["FOR"] = 19] = "FOR";
300
302
  return IRNodeTypes2;
301
303
  })(IRNodeTypes || {});
302
304
  var DynamicFlag2 = /* @__PURE__ */ ((DynamicFlag3) => {
@@ -391,21 +393,24 @@ var TransformContext = class _TransformContext {
391
393
  if (this.inVOnce || expressions.length === 0) {
392
394
  return this.registerOperation(...operations);
393
395
  }
396
+ const ids = /* @__PURE__ */ new Set();
397
+ expressions.forEach((exp) => extractIdentifiers(ids, exp));
394
398
  const existing = this.block.effect.find(
395
- (e) => isSameExpression(e.expressions, expressions)
399
+ (e) => _shared.looseEqual.call(void 0, e.identifiers, Array.from(ids))
396
400
  );
397
401
  if (existing) {
398
402
  existing.operations.push(...operations);
399
403
  } else {
400
404
  this.block.effect.push({
401
405
  expressions,
402
- operations
406
+ operations,
407
+ earlyCheckExps: [],
408
+ declareNames: /* @__PURE__ */ new Set(),
409
+ rewrittenNames: /* @__PURE__ */ new Set(),
410
+ inVFor: this.inVFor > 0,
411
+ identifiers: Array.from(ids)
403
412
  });
404
413
  }
405
- function isSameExpression(a, b) {
406
- if (a.length !== b.length) return false;
407
- return a.every((exp, i) => exp.content === b[i].content);
408
- }
409
414
  }
410
415
  registerOperation(...node) {
411
416
  this.block.operation.push(...node);
@@ -463,6 +468,13 @@ function transformNode(context) {
463
468
  context.registerTemplate();
464
469
  }
465
470
  }
471
+ function extractIdentifiers(ids, node) {
472
+ if (node.ast) {
473
+ _compilerdom.walkIdentifiers.call(void 0, node.ast, (n) => ids.add(n.name), true);
474
+ } else if (node.ast === null) {
475
+ ids.add(node.content);
476
+ }
477
+ }
466
478
 
467
479
  // src/transforms/transformElement.ts
468
480
 
@@ -663,14 +675,16 @@ var transformElement = (node, context) => {
663
675
  context,
664
676
  isComponent
665
677
  );
678
+ const singleRoot = context.root === context.parent && context.parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
666
679
  (isComponent ? transformComponentElement : transformNativeElement)(
667
680
  tag,
668
681
  propsResult,
682
+ singleRoot,
669
683
  context
670
684
  );
671
685
  };
672
686
  };
673
- function transformComponentElement(tag, propsResult, context) {
687
+ function transformComponentElement(tag, propsResult, singleRoot, context) {
674
688
  let asset = true;
675
689
  if (!__BROWSER__2) {
676
690
  const fromSetup = resolveSetupReference(tag, context);
@@ -691,14 +705,13 @@ function transformComponentElement(tag, propsResult, context) {
691
705
  context.component.add(tag);
692
706
  }
693
707
  context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
694
- const root = context.root === context.parent && context.parent.node.children.length === 1;
695
708
  context.registerOperation({
696
- type: 13 /* CREATE_COMPONENT_NODE */,
709
+ type: 14 /* CREATE_COMPONENT_NODE */,
697
710
  id: context.reference(),
698
711
  tag,
699
712
  props: propsResult[0] ? propsResult[1] : [propsResult[1]],
700
713
  asset,
701
- root,
714
+ root: singleRoot,
702
715
  slots: context.slots,
703
716
  once: context.inVOnce
704
717
  });
@@ -714,33 +727,47 @@ function resolveSetupReference(name, context) {
714
727
  const PascalName = _shared.capitalize.call(void 0, camelName);
715
728
  return bindings[name] ? name : bindings[camelName] ? camelName : bindings[PascalName] ? PascalName : void 0;
716
729
  }
717
- function transformNativeElement(tag, propsResult, context) {
730
+ function transformNativeElement(tag, propsResult, singleRoot, context) {
718
731
  const { scopeId } = context.options;
719
732
  let template = "";
720
733
  template += `<${tag}`;
721
734
  if (scopeId) template += ` ${scopeId}`;
735
+ let staticProps = false;
736
+ const dynamicProps = [];
722
737
  if (propsResult[0]) {
723
738
  const [, dynamicArgs, expressions] = propsResult;
724
739
  context.registerEffect(expressions, {
725
740
  type: 3 /* SET_DYNAMIC_PROPS */,
726
741
  element: context.reference(),
727
- props: dynamicArgs
742
+ props: dynamicArgs,
743
+ root: singleRoot
728
744
  });
729
745
  } else {
730
746
  for (const prop of propsResult[1]) {
731
747
  const { key, values } = prop;
732
748
  if (key.isStatic && values.length === 1 && values[0].isStatic) {
749
+ staticProps = true;
733
750
  template += ` ${key.content}`;
734
751
  if (values[0].content) template += `="${values[0].content}"`;
735
752
  } else {
753
+ dynamicProps.push(key.content);
736
754
  context.registerEffect(values, {
737
755
  type: 2 /* SET_PROP */,
738
756
  element: context.reference(),
739
- prop
757
+ prop,
758
+ tag,
759
+ root: singleRoot
740
760
  });
741
761
  }
742
762
  }
743
763
  }
764
+ if (singleRoot) {
765
+ context.registerOperation({
766
+ type: 10 /* SET_INHERIT_ATTRS */,
767
+ staticProps,
768
+ dynamicProps: propsResult[0] ? true : dynamicProps
769
+ });
770
+ }
744
771
  template += `>${context.childrenTemplate.join("")}`;
745
772
  if (!_shared.isVoidTag.call(void 0, tag)) {
746
773
  template += `</${tag}>`;
@@ -902,14 +929,14 @@ function processDynamicChildren(context) {
902
929
  prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
903
930
  const anchor = prevDynamics[0].anchor = context.increaseId();
904
931
  context.registerOperation({
905
- type: 10 /* INSERT_NODE */,
932
+ type: 11 /* INSERT_NODE */,
906
933
  elements: prevDynamics.map((child2) => child2.id),
907
934
  parent: context.reference(),
908
935
  anchor
909
936
  });
910
937
  } else {
911
938
  context.registerOperation({
912
- type: 11 /* PREPEND_NODE */,
939
+ type: 12 /* PREPEND_NODE */,
913
940
  elements: prevDynamics.map((child2) => child2.id),
914
941
  parent: context.reference()
915
942
  });
@@ -921,7 +948,7 @@ function processDynamicChildren(context) {
921
948
  }
922
949
  if (prevDynamics.length) {
923
950
  context.registerOperation({
924
- type: 10 /* INSERT_NODE */,
951
+ type: 11 /* INSERT_NODE */,
925
952
  elements: prevDynamics.map((child) => child.id),
926
953
  parent: context.reference()
927
954
  });
@@ -938,7 +965,7 @@ var transformTemplateRef = (node, context) => {
938
965
  const id = context.reference();
939
966
  const effect = !isConstantExpression(value);
940
967
  effect && context.registerOperation({
941
- type: 16 /* DECLARE_OLD_REF */,
968
+ type: 17 /* DECLARE_OLD_REF */,
942
969
  id
943
970
  });
944
971
  context.registerEffect([value], {
@@ -959,7 +986,7 @@ function processConditionalExpression(node, context) {
959
986
  const condition = resolveExpression(test, context);
960
987
  const [branch, onExit] = createBranch(consequent, context);
961
988
  const operation = {
962
- type: 17 /* IF */,
989
+ type: 18 /* IF */,
963
990
  id,
964
991
  condition,
965
992
  positive: branch,
@@ -989,7 +1016,7 @@ function processLogicalExpression(node, context) {
989
1016
  context
990
1017
  );
991
1018
  const operation = {
992
- type: 17 /* IF */,
1019
+ type: 18 /* IF */,
993
1020
  id,
994
1021
  condition,
995
1022
  positive: branch,
@@ -1032,8 +1059,13 @@ function processMapCallExpression(node, context) {
1032
1059
  const keyProperty = keyProp && resolveExpression(keyProp.value, context);
1033
1060
  return () => {
1034
1061
  exitBlock();
1062
+ const { parent } = context;
1063
+ let container;
1064
+ if (parent && parent.block.node !== parent.node && parent.node.children.length === 1) {
1065
+ container = parent.reference();
1066
+ }
1035
1067
  context.registerOperation({
1036
- type: 18 /* FOR */,
1068
+ type: 19 /* FOR */,
1037
1069
  id,
1038
1070
  source,
1039
1071
  value,
@@ -1041,7 +1073,8 @@ function processMapCallExpression(node, context) {
1041
1073
  index,
1042
1074
  keyProp: keyProperty,
1043
1075
  render,
1044
- once: context.inVOnce
1076
+ once: context.inVOnce,
1077
+ container
1045
1078
  });
1046
1079
  };
1047
1080
  }
@@ -1085,7 +1118,7 @@ function processTextLike(context) {
1085
1118
  const values = nodes.map((node) => createTextLikeExpression(node, context));
1086
1119
  context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
1087
1120
  context.registerOperation({
1088
- type: 12 /* CREATE_TEXT_NODE */,
1121
+ type: 13 /* CREATE_TEXT_NODE */,
1089
1122
  id,
1090
1123
  values,
1091
1124
  effect: !values.every(isConstantExpression) && !context.inVOnce
@@ -1122,7 +1155,7 @@ function processCallExpression(node, context) {
1122
1155
  const root = context.root === context.parent && context.parent.node.children.length === 1;
1123
1156
  const tag = `() => ${context.ir.source.slice(node.start, node.end)}`;
1124
1157
  context.registerOperation({
1125
- type: 13 /* CREATE_COMPONENT_NODE */,
1158
+ type: 14 /* CREATE_COMPONENT_NODE */,
1126
1159
  id: context.reference(),
1127
1160
  tag,
1128
1161
  props: [],
package/dist/index.js CHANGED
@@ -16,9 +16,10 @@ import { parse } from "@babel/parser";
16
16
  // src/transform.ts
17
17
  import {
18
18
  defaultOnError,
19
- defaultOnWarn
19
+ defaultOnWarn,
20
+ walkIdentifiers
20
21
  } from "@vue/compiler-dom";
21
- import { EMPTY_OBJ, NOOP, extend, isArray } from "@vue/shared";
22
+ import { EMPTY_OBJ, NOOP, extend, isArray, looseEqual } from "@vue/shared";
22
23
 
23
24
  // src/transforms/utils.ts
24
25
  import {
@@ -288,15 +289,16 @@ var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
288
289
  IRNodeTypes2[IRNodeTypes2["SET_HTML"] = 7] = "SET_HTML";
289
290
  IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
290
291
  IRNodeTypes2[IRNodeTypes2["SET_MODEL_VALUE"] = 9] = "SET_MODEL_VALUE";
291
- IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 10] = "INSERT_NODE";
292
- IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 11] = "PREPEND_NODE";
293
- IRNodeTypes2[IRNodeTypes2["CREATE_TEXT_NODE"] = 12] = "CREATE_TEXT_NODE";
294
- IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 13] = "CREATE_COMPONENT_NODE";
295
- IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 14] = "SLOT_OUTLET_NODE";
296
- IRNodeTypes2[IRNodeTypes2["WITH_DIRECTIVE"] = 15] = "WITH_DIRECTIVE";
297
- IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 16] = "DECLARE_OLD_REF";
298
- IRNodeTypes2[IRNodeTypes2["IF"] = 17] = "IF";
299
- IRNodeTypes2[IRNodeTypes2["FOR"] = 18] = "FOR";
292
+ IRNodeTypes2[IRNodeTypes2["SET_INHERIT_ATTRS"] = 10] = "SET_INHERIT_ATTRS";
293
+ IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 11] = "INSERT_NODE";
294
+ IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 12] = "PREPEND_NODE";
295
+ IRNodeTypes2[IRNodeTypes2["CREATE_TEXT_NODE"] = 13] = "CREATE_TEXT_NODE";
296
+ IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 14] = "CREATE_COMPONENT_NODE";
297
+ IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 15] = "SLOT_OUTLET_NODE";
298
+ IRNodeTypes2[IRNodeTypes2["WITH_DIRECTIVE"] = 16] = "WITH_DIRECTIVE";
299
+ IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 17] = "DECLARE_OLD_REF";
300
+ IRNodeTypes2[IRNodeTypes2["IF"] = 18] = "IF";
301
+ IRNodeTypes2[IRNodeTypes2["FOR"] = 19] = "FOR";
300
302
  return IRNodeTypes2;
301
303
  })(IRNodeTypes || {});
302
304
  var DynamicFlag2 = /* @__PURE__ */ ((DynamicFlag3) => {
@@ -391,21 +393,24 @@ var TransformContext = class _TransformContext {
391
393
  if (this.inVOnce || expressions.length === 0) {
392
394
  return this.registerOperation(...operations);
393
395
  }
396
+ const ids = /* @__PURE__ */ new Set();
397
+ expressions.forEach((exp) => extractIdentifiers(ids, exp));
394
398
  const existing = this.block.effect.find(
395
- (e) => isSameExpression(e.expressions, expressions)
399
+ (e) => looseEqual(e.identifiers, Array.from(ids))
396
400
  );
397
401
  if (existing) {
398
402
  existing.operations.push(...operations);
399
403
  } else {
400
404
  this.block.effect.push({
401
405
  expressions,
402
- operations
406
+ operations,
407
+ earlyCheckExps: [],
408
+ declareNames: /* @__PURE__ */ new Set(),
409
+ rewrittenNames: /* @__PURE__ */ new Set(),
410
+ inVFor: this.inVFor > 0,
411
+ identifiers: Array.from(ids)
403
412
  });
404
413
  }
405
- function isSameExpression(a, b) {
406
- if (a.length !== b.length) return false;
407
- return a.every((exp, i) => exp.content === b[i].content);
408
- }
409
414
  }
410
415
  registerOperation(...node) {
411
416
  this.block.operation.push(...node);
@@ -463,6 +468,13 @@ function transformNode(context) {
463
468
  context.registerTemplate();
464
469
  }
465
470
  }
471
+ function extractIdentifiers(ids, node) {
472
+ if (node.ast) {
473
+ walkIdentifiers(node.ast, (n) => ids.add(n.name), true);
474
+ } else if (node.ast === null) {
475
+ ids.add(node.content);
476
+ }
477
+ }
466
478
 
467
479
  // src/transforms/transformElement.ts
468
480
  import {
@@ -663,14 +675,16 @@ var transformElement = (node, context) => {
663
675
  context,
664
676
  isComponent
665
677
  );
678
+ const singleRoot = context.root === context.parent && context.parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
666
679
  (isComponent ? transformComponentElement : transformNativeElement)(
667
680
  tag,
668
681
  propsResult,
682
+ singleRoot,
669
683
  context
670
684
  );
671
685
  };
672
686
  };
673
- function transformComponentElement(tag, propsResult, context) {
687
+ function transformComponentElement(tag, propsResult, singleRoot, context) {
674
688
  let asset = true;
675
689
  if (!__BROWSER__2) {
676
690
  const fromSetup = resolveSetupReference(tag, context);
@@ -691,14 +705,13 @@ function transformComponentElement(tag, propsResult, context) {
691
705
  context.component.add(tag);
692
706
  }
693
707
  context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
694
- const root = context.root === context.parent && context.parent.node.children.length === 1;
695
708
  context.registerOperation({
696
- type: 13 /* CREATE_COMPONENT_NODE */,
709
+ type: 14 /* CREATE_COMPONENT_NODE */,
697
710
  id: context.reference(),
698
711
  tag,
699
712
  props: propsResult[0] ? propsResult[1] : [propsResult[1]],
700
713
  asset,
701
- root,
714
+ root: singleRoot,
702
715
  slots: context.slots,
703
716
  once: context.inVOnce
704
717
  });
@@ -714,33 +727,47 @@ function resolveSetupReference(name, context) {
714
727
  const PascalName = capitalize(camelName);
715
728
  return bindings[name] ? name : bindings[camelName] ? camelName : bindings[PascalName] ? PascalName : void 0;
716
729
  }
717
- function transformNativeElement(tag, propsResult, context) {
730
+ function transformNativeElement(tag, propsResult, singleRoot, context) {
718
731
  const { scopeId } = context.options;
719
732
  let template = "";
720
733
  template += `<${tag}`;
721
734
  if (scopeId) template += ` ${scopeId}`;
735
+ let staticProps = false;
736
+ const dynamicProps = [];
722
737
  if (propsResult[0]) {
723
738
  const [, dynamicArgs, expressions] = propsResult;
724
739
  context.registerEffect(expressions, {
725
740
  type: 3 /* SET_DYNAMIC_PROPS */,
726
741
  element: context.reference(),
727
- props: dynamicArgs
742
+ props: dynamicArgs,
743
+ root: singleRoot
728
744
  });
729
745
  } else {
730
746
  for (const prop of propsResult[1]) {
731
747
  const { key, values } = prop;
732
748
  if (key.isStatic && values.length === 1 && values[0].isStatic) {
749
+ staticProps = true;
733
750
  template += ` ${key.content}`;
734
751
  if (values[0].content) template += `="${values[0].content}"`;
735
752
  } else {
753
+ dynamicProps.push(key.content);
736
754
  context.registerEffect(values, {
737
755
  type: 2 /* SET_PROP */,
738
756
  element: context.reference(),
739
- prop
757
+ prop,
758
+ tag,
759
+ root: singleRoot
740
760
  });
741
761
  }
742
762
  }
743
763
  }
764
+ if (singleRoot) {
765
+ context.registerOperation({
766
+ type: 10 /* SET_INHERIT_ATTRS */,
767
+ staticProps,
768
+ dynamicProps: propsResult[0] ? true : dynamicProps
769
+ });
770
+ }
744
771
  template += `>${context.childrenTemplate.join("")}`;
745
772
  if (!isVoidTag(tag)) {
746
773
  template += `</${tag}>`;
@@ -902,14 +929,14 @@ function processDynamicChildren(context) {
902
929
  prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
903
930
  const anchor = prevDynamics[0].anchor = context.increaseId();
904
931
  context.registerOperation({
905
- type: 10 /* INSERT_NODE */,
932
+ type: 11 /* INSERT_NODE */,
906
933
  elements: prevDynamics.map((child2) => child2.id),
907
934
  parent: context.reference(),
908
935
  anchor
909
936
  });
910
937
  } else {
911
938
  context.registerOperation({
912
- type: 11 /* PREPEND_NODE */,
939
+ type: 12 /* PREPEND_NODE */,
913
940
  elements: prevDynamics.map((child2) => child2.id),
914
941
  parent: context.reference()
915
942
  });
@@ -921,7 +948,7 @@ function processDynamicChildren(context) {
921
948
  }
922
949
  if (prevDynamics.length) {
923
950
  context.registerOperation({
924
- type: 10 /* INSERT_NODE */,
951
+ type: 11 /* INSERT_NODE */,
925
952
  elements: prevDynamics.map((child) => child.id),
926
953
  parent: context.reference()
927
954
  });
@@ -938,7 +965,7 @@ var transformTemplateRef = (node, context) => {
938
965
  const id = context.reference();
939
966
  const effect = !isConstantExpression(value);
940
967
  effect && context.registerOperation({
941
- type: 16 /* DECLARE_OLD_REF */,
968
+ type: 17 /* DECLARE_OLD_REF */,
942
969
  id
943
970
  });
944
971
  context.registerEffect([value], {
@@ -959,7 +986,7 @@ function processConditionalExpression(node, context) {
959
986
  const condition = resolveExpression(test, context);
960
987
  const [branch, onExit] = createBranch(consequent, context);
961
988
  const operation = {
962
- type: 17 /* IF */,
989
+ type: 18 /* IF */,
963
990
  id,
964
991
  condition,
965
992
  positive: branch,
@@ -989,7 +1016,7 @@ function processLogicalExpression(node, context) {
989
1016
  context
990
1017
  );
991
1018
  const operation = {
992
- type: 17 /* IF */,
1019
+ type: 18 /* IF */,
993
1020
  id,
994
1021
  condition,
995
1022
  positive: branch,
@@ -1032,8 +1059,13 @@ function processMapCallExpression(node, context) {
1032
1059
  const keyProperty = keyProp && resolveExpression(keyProp.value, context);
1033
1060
  return () => {
1034
1061
  exitBlock();
1062
+ const { parent } = context;
1063
+ let container;
1064
+ if (parent && parent.block.node !== parent.node && parent.node.children.length === 1) {
1065
+ container = parent.reference();
1066
+ }
1035
1067
  context.registerOperation({
1036
- type: 18 /* FOR */,
1068
+ type: 19 /* FOR */,
1037
1069
  id,
1038
1070
  source,
1039
1071
  value,
@@ -1041,7 +1073,8 @@ function processMapCallExpression(node, context) {
1041
1073
  index,
1042
1074
  keyProp: keyProperty,
1043
1075
  render,
1044
- once: context.inVOnce
1076
+ once: context.inVOnce,
1077
+ container
1045
1078
  });
1046
1079
  };
1047
1080
  }
@@ -1085,7 +1118,7 @@ function processTextLike(context) {
1085
1118
  const values = nodes.map((node) => createTextLikeExpression(node, context));
1086
1119
  context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
1087
1120
  context.registerOperation({
1088
- type: 12 /* CREATE_TEXT_NODE */,
1121
+ type: 13 /* CREATE_TEXT_NODE */,
1089
1122
  id,
1090
1123
  values,
1091
1124
  effect: !values.every(isConstantExpression) && !context.inVOnce
@@ -1122,7 +1155,7 @@ function processCallExpression(node, context) {
1122
1155
  const root = context.root === context.parent && context.parent.node.children.length === 1;
1123
1156
  const tag = `() => ${context.ir.source.slice(node.start, node.end)}`;
1124
1157
  context.registerOperation({
1125
- type: 13 /* CREATE_COMPONENT_NODE */,
1158
+ type: 14 /* CREATE_COMPONENT_NODE */,
1126
1159
  id: context.reference(),
1127
1160
  tag,
1128
1161
  props: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-jsx-vapor/compiler",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "Vue JSX Vapor Compiler",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -48,19 +48,18 @@
48
48
  "./*": "./*"
49
49
  },
50
50
  "dependencies": {
51
- "@babel/parser": "^7.24.7",
52
- "@babel/types": "^7.24.7",
51
+ "@babel/parser": "^7.26.3",
52
+ "@babel/types": "^7.26.3",
53
53
  "@vue-macros/common": "^1.10.4",
54
- "@vue/compiler-core": "https://pkg.pr.new/vuejs/core-vapor/@vue/compiler-core@2eae25e",
55
- "@vue/compiler-dom": "https://pkg.pr.new/vuejs/core-vapor/@vue/compiler-dom@2eae25e",
56
- "@vue/compiler-vapor": "https://pkg.pr.new/vuejs/core-vapor/@vue/compiler-vapor@2eae25e",
57
- "@vue/runtime-vapor": "https://pkg.pr.new/vuejs/core-vapor/@vue/runtime-vapor@2eae25e",
58
- "@vue/shared": "https://pkg.pr.new/vuejs/core-vapor/@vue/shared@2eae25e"
54
+ "@vue/compiler-core": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-core@9f73dbf",
55
+ "@vue/compiler-dom": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-dom@9f73dbf",
56
+ "@vue/compiler-vapor": "https://pkg.pr.new/vuejs/vue-vapor/@vue/compiler-vapor@9f73dbf",
57
+ "@vue/runtime-vapor": "https://pkg.pr.new/vuejs/vue-vapor/@vue/runtime-vapor@9f73dbf",
58
+ "@vue/shared": "https://pkg.pr.new/vuejs/vue-vapor/@vue/shared@9f73dbf"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "tsup",
62
62
  "dev": "DEV=true tsup",
63
- "typecheck": "tsc --noEmit",
64
63
  "release": "bumpp && npm publish",
65
64
  "test": "vitest"
66
65
  }
package/dist/index.d.cts DELETED
@@ -1,353 +0,0 @@
1
- import { IRFor as IRFor$1, VaporCodegenResult as VaporCodegenResult$1 } from '@vue/compiler-vapor';
2
- export { generate } from '@vue/compiler-vapor';
3
- import { SimpleExpressionNode, BindingTypes, DirectiveNode, CompoundExpressionNode, TransformOptions as TransformOptions$1, CompilerCompatOptions, CommentNode, CompilerOptions as CompilerOptions$1, ElementNode } from '@vue/compiler-dom';
4
- import * as _vue_runtime_vapor from '@vue/runtime-vapor';
5
- import { JSXFragment, Node, JSXAttribute, JSXElement, Program } from '@babel/types';
6
- import { Prettify } from '@vue/shared';
7
-
8
- interface IRProp extends Omit<DirectiveTransformResult, 'value'> {
9
- values: SimpleExpressionNode[];
10
- }
11
- declare enum IRDynamicPropsKind {
12
- EXPRESSION = 0,// v-bind="value"
13
- ATTRIBUTE = 1
14
- }
15
- type IRPropsStatic = IRProp[];
16
- interface IRPropsDynamicExpression {
17
- kind: IRDynamicPropsKind.EXPRESSION;
18
- value: SimpleExpressionNode;
19
- handler?: boolean;
20
- }
21
- interface IRPropsDynamicAttribute extends IRProp {
22
- kind: IRDynamicPropsKind.ATTRIBUTE;
23
- }
24
- type IRProps = IRPropsStatic | IRPropsDynamicAttribute | IRPropsDynamicExpression;
25
- interface SlotBlockIRNode extends BlockIRNode {
26
- props?: SimpleExpressionNode;
27
- }
28
- declare enum IRSlotType {
29
- STATIC = 0,
30
- DYNAMIC = 1,
31
- LOOP = 2,
32
- CONDITIONAL = 3,
33
- EXPRESSION = 4
34
- }
35
- interface IRSlotsStatic {
36
- slotType: IRSlotType.STATIC;
37
- slots: Record<string, SlotBlockIRNode>;
38
- }
39
- interface IRSlotDynamicBasic {
40
- slotType: IRSlotType.DYNAMIC;
41
- name: SimpleExpressionNode;
42
- fn: SlotBlockIRNode;
43
- }
44
- interface IRSlotDynamicLoop {
45
- slotType: IRSlotType.LOOP;
46
- name: SimpleExpressionNode;
47
- fn: SlotBlockIRNode;
48
- loop: IRFor$1;
49
- }
50
- interface IRSlotDynamicConditional {
51
- slotType: IRSlotType.CONDITIONAL;
52
- condition: SimpleExpressionNode;
53
- positive: IRSlotDynamicBasic;
54
- negative?: IRSlotDynamicBasic | IRSlotDynamicConditional;
55
- }
56
- interface IRSlotsExpression {
57
- slotType: IRSlotType.EXPRESSION;
58
- slots: SimpleExpressionNode;
59
- }
60
- type IRSlotDynamic = IRSlotDynamicBasic | IRSlotDynamicLoop | IRSlotDynamicConditional;
61
- type IRSlots = IRSlotsStatic | IRSlotDynamic | IRSlotsExpression;
62
-
63
- declare enum IRNodeTypes {
64
- ROOT = 0,
65
- BLOCK = 1,
66
- SET_PROP = 2,
67
- SET_DYNAMIC_PROPS = 3,
68
- SET_TEXT = 4,
69
- SET_EVENT = 5,
70
- SET_DYNAMIC_EVENTS = 6,
71
- SET_HTML = 7,
72
- SET_TEMPLATE_REF = 8,
73
- SET_MODEL_VALUE = 9,
74
- INSERT_NODE = 10,
75
- PREPEND_NODE = 11,
76
- CREATE_TEXT_NODE = 12,
77
- CREATE_COMPONENT_NODE = 13,
78
- SLOT_OUTLET_NODE = 14,
79
- WITH_DIRECTIVE = 15,
80
- DECLARE_OLD_REF = 16,// consider make it more general
81
- IF = 17,
82
- FOR = 18
83
- }
84
- interface BaseIRNode {
85
- type: IRNodeTypes;
86
- }
87
- type VaporHelper = keyof typeof _vue_runtime_vapor;
88
- interface RootNode {
89
- type: IRNodeTypes.ROOT;
90
- source: string;
91
- children: JSXFragment['children'];
92
- helpers: Set<symbol>;
93
- components: string[];
94
- directives: string[];
95
- temps: number;
96
- ssrHelpers?: symbol[];
97
- transformed?: boolean;
98
- }
99
- interface BlockIRNode extends BaseIRNode {
100
- type: IRNodeTypes.BLOCK;
101
- node: RootNode | Node;
102
- dynamic: IRDynamicInfo;
103
- effect: IREffect[];
104
- operation: OperationNode[];
105
- returns: number[];
106
- }
107
- interface RootIRNode {
108
- type: IRNodeTypes.ROOT;
109
- node: RootNode;
110
- source: string;
111
- template: string[];
112
- component: Set<string>;
113
- directive: Set<string>;
114
- block: BlockIRNode;
115
- }
116
- interface IfIRNode extends BaseIRNode {
117
- type: IRNodeTypes.IF;
118
- id: number;
119
- condition: SimpleExpressionNode;
120
- positive: BlockIRNode;
121
- negative?: BlockIRNode | IfIRNode;
122
- once?: boolean;
123
- }
124
- interface IRFor {
125
- source: SimpleExpressionNode;
126
- value?: SimpleExpressionNode;
127
- key?: SimpleExpressionNode;
128
- index?: SimpleExpressionNode;
129
- }
130
- interface ForIRNode extends BaseIRNode, IRFor {
131
- type: IRNodeTypes.FOR;
132
- id: number;
133
- keyProp?: SimpleExpressionNode;
134
- render: BlockIRNode;
135
- once: boolean;
136
- }
137
- interface SetPropIRNode extends BaseIRNode {
138
- type: IRNodeTypes.SET_PROP;
139
- element: number;
140
- prop: IRProp;
141
- }
142
- interface SetDynamicPropsIRNode extends BaseIRNode {
143
- type: IRNodeTypes.SET_DYNAMIC_PROPS;
144
- element: number;
145
- props: IRProps[];
146
- }
147
- interface SetDynamicEventsIRNode extends BaseIRNode {
148
- type: IRNodeTypes.SET_DYNAMIC_EVENTS;
149
- element: number;
150
- event: SimpleExpressionNode;
151
- }
152
- interface SetTextIRNode extends BaseIRNode {
153
- type: IRNodeTypes.SET_TEXT;
154
- element: number;
155
- values: SimpleExpressionNode[];
156
- }
157
- type KeyOverride = [find: string, replacement: string];
158
- interface SetEventIRNode extends BaseIRNode {
159
- type: IRNodeTypes.SET_EVENT;
160
- element: number;
161
- key: SimpleExpressionNode;
162
- value?: SimpleExpressionNode;
163
- modifiers: {
164
- options: string[];
165
- keys: string[];
166
- nonKeys: string[];
167
- };
168
- keyOverride?: KeyOverride;
169
- delegate: boolean;
170
- /** Whether it's in effect */
171
- effect: boolean;
172
- }
173
- interface SetHtmlIRNode extends BaseIRNode {
174
- type: IRNodeTypes.SET_HTML;
175
- element: number;
176
- value: SimpleExpressionNode;
177
- }
178
- interface SetTemplateRefIRNode extends BaseIRNode {
179
- type: IRNodeTypes.SET_TEMPLATE_REF;
180
- element: number;
181
- value: SimpleExpressionNode;
182
- refFor: boolean;
183
- effect: boolean;
184
- }
185
- interface SetModelValueIRNode extends BaseIRNode {
186
- type: IRNodeTypes.SET_MODEL_VALUE;
187
- element: number;
188
- key: SimpleExpressionNode;
189
- value: SimpleExpressionNode;
190
- bindingType?: BindingTypes;
191
- isComponent: boolean;
192
- }
193
- interface CreateTextNodeIRNode extends BaseIRNode {
194
- type: IRNodeTypes.CREATE_TEXT_NODE;
195
- id: number;
196
- values: SimpleExpressionNode[];
197
- effect: boolean;
198
- }
199
- interface InsertNodeIRNode extends BaseIRNode {
200
- type: IRNodeTypes.INSERT_NODE;
201
- elements: number[];
202
- parent: number;
203
- anchor?: number;
204
- }
205
- interface PrependNodeIRNode extends BaseIRNode {
206
- type: IRNodeTypes.PREPEND_NODE;
207
- elements: number[];
208
- parent: number;
209
- }
210
- interface WithDirectiveIRNode extends BaseIRNode {
211
- type: IRNodeTypes.WITH_DIRECTIVE;
212
- element: number;
213
- dir: VaporDirectiveNode;
214
- name: string;
215
- builtin?: boolean;
216
- asset?: boolean;
217
- }
218
- interface CreateComponentIRNode extends BaseIRNode {
219
- type: IRNodeTypes.CREATE_COMPONENT_NODE;
220
- id: number;
221
- tag: string;
222
- props: IRProps[];
223
- slots: IRSlots[];
224
- asset: boolean;
225
- root: boolean;
226
- once: boolean;
227
- }
228
- interface DeclareOldRefIRNode extends BaseIRNode {
229
- type: IRNodeTypes.DECLARE_OLD_REF;
230
- id: number;
231
- }
232
- interface SlotOutletIRNode extends BaseIRNode {
233
- type: IRNodeTypes.SLOT_OUTLET_NODE;
234
- id: number;
235
- name: SimpleExpressionNode;
236
- props: IRProps[];
237
- fallback?: BlockIRNode;
238
- }
239
- type IRNode = OperationNode | RootIRNode;
240
- type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | SetModelValueIRNode | CreateTextNodeIRNode | InsertNodeIRNode | PrependNodeIRNode | WithDirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode;
241
- declare enum DynamicFlag {
242
- NONE = 0,
243
- /**
244
- * This node is referenced and needs to be saved as a variable.
245
- */
246
- REFERENCED = 1,
247
- /**
248
- * This node is not generated from template, but is generated dynamically.
249
- */
250
- NON_TEMPLATE = 2,
251
- /**
252
- * This node needs to be inserted back into the template.
253
- */
254
- INSERT = 4
255
- }
256
- interface IRDynamicInfo {
257
- id?: number;
258
- flags: DynamicFlag;
259
- anchor?: number;
260
- children: IRDynamicInfo[];
261
- template?: number;
262
- }
263
- interface IREffect {
264
- expressions: SimpleExpressionNode[];
265
- operations: OperationNode[];
266
- }
267
- type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & Pick<U, Extract<keyof U, keyof T>>;
268
- type HackOptions<T> = Prettify<Overwrite<T, {
269
- nodeTransforms?: NodeTransform[];
270
- directiveTransforms?: Record<string, DirectiveTransform | undefined>;
271
- }>>;
272
- type VaporDirectiveNode = Overwrite<DirectiveNode, {
273
- exp: Exclude<DirectiveNode['exp'], CompoundExpressionNode>;
274
- arg: Exclude<DirectiveNode['arg'], CompoundExpressionNode>;
275
- }>;
276
-
277
- type NodeTransform = (node: BlockIRNode['node'], context: TransformContext<BlockIRNode['node']>) => void | (() => void) | (() => void)[];
278
- type DirectiveTransform = (dir: JSXAttribute, node: JSXElement, context: TransformContext<JSXElement>) => DirectiveTransformResult | void;
279
- interface DirectiveTransformResult {
280
- key: SimpleExpressionNode;
281
- value: SimpleExpressionNode;
282
- modifier?: '.' | '^';
283
- runtimeCamelize?: boolean;
284
- handler?: boolean;
285
- model?: boolean;
286
- modelModifiers?: string[];
287
- }
288
- type TransformOptions = HackOptions<TransformOptions$1>;
289
- declare class TransformContext<T extends BlockIRNode['node'] = BlockIRNode['node']> {
290
- ir: RootIRNode;
291
- node: T;
292
- parent: TransformContext<RootNode | JSXElement | JSXFragment> | null;
293
- root: TransformContext<RootNode>;
294
- index: number;
295
- block: BlockIRNode;
296
- options: Required<Omit<TransformOptions, 'filename' | keyof CompilerCompatOptions>>;
297
- template: string;
298
- childrenTemplate: (string | null)[];
299
- dynamic: IRDynamicInfo;
300
- inVOnce: boolean;
301
- inVFor: number;
302
- comment: CommentNode[];
303
- component: Set<string>;
304
- directive: Set<string>;
305
- slots: IRSlots[];
306
- private globalId;
307
- constructor(ir: RootIRNode, node: T, options?: TransformOptions);
308
- enterBlock(ir: BlockIRNode, isVFor?: boolean): () => void;
309
- increaseId: () => number;
310
- reference(): number;
311
- pushTemplate(content: string): number;
312
- registerTemplate(): number;
313
- registerEffect(expressions: SimpleExpressionNode[], ...operations: OperationNode[]): void;
314
- registerOperation(...node: OperationNode[]): void;
315
- create<E extends T>(node: E, index: number): TransformContext<E>;
316
- }
317
- declare function transform(node: RootNode, options?: TransformOptions): RootIRNode;
318
- declare function transformNode(context: TransformContext<BlockIRNode['node']>): void;
319
-
320
- interface VaporCodegenResult extends Omit<VaporCodegenResult$1, 'ast'> {
321
- ast: RootIRNode;
322
- }
323
- declare function compile(source: string | Program, options?: CompilerOptions): VaporCodegenResult;
324
- type CompilerOptions = HackOptions<CompilerOptions$1>;
325
- type TransformPreset = [
326
- NodeTransform[],
327
- Record<string, DirectiveTransform>
328
- ];
329
-
330
- declare function resolveNode(node: JSXElement, context: TransformContext): ElementNode;
331
- declare function resolveDirectiveNode(node: JSXAttribute, context: TransformContext): VaporDirectiveNode;
332
-
333
- declare const transformText: NodeTransform;
334
-
335
- declare const transformElement: NodeTransform;
336
-
337
- declare const transformChildren: NodeTransform;
338
-
339
- declare const transformTemplateRef: NodeTransform;
340
-
341
- declare const transformVBind: DirectiveTransform;
342
-
343
- declare const transformVOn: DirectiveTransform;
344
-
345
- declare const transformVSlot: NodeTransform;
346
-
347
- declare const transformVModel: DirectiveTransform;
348
-
349
- declare const transformVShow: DirectiveTransform;
350
-
351
- declare const transformVHtml: DirectiveTransform;
352
-
353
- export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type CreateTextNodeIRNode, type DeclareOldRefIRNode, type DirectiveTransform, type DirectiveTransformResult, DynamicFlag, type ForIRNode, type HackOptions, type IRDynamicInfo, IRDynamicPropsKind, type IREffect, type IRFor, type IRNode, IRNodeTypes, type IRProp, type IRProps, type IRPropsDynamicAttribute, type IRPropsDynamicExpression, type IRPropsStatic, type IRSlotDynamic, type IRSlotDynamicBasic, type IRSlotDynamicConditional, type IRSlotDynamicLoop, IRSlotType, type IRSlots, type IRSlotsExpression, type IRSlotsStatic, type IfIRNode, type InsertNodeIRNode, type KeyOverride, type NodeTransform, type OperationNode, type PrependNodeIRNode, type RootIRNode, type RootNode, type SetDynamicEventsIRNode, type SetDynamicPropsIRNode, type SetEventIRNode, type SetHtmlIRNode, type SetModelValueIRNode, type SetPropIRNode, type SetTemplateRefIRNode, type SetTextIRNode, type SlotBlockIRNode, type SlotOutletIRNode, TransformContext, type TransformOptions, type TransformPreset, type VaporDirectiveNode, type VaporHelper, type WithDirectiveIRNode, compile, resolveDirectiveNode, resolveNode, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVHtml, transformVModel, transformVOn, transformVShow, transformVSlot };
package/dist/index.d.ts DELETED
@@ -1,353 +0,0 @@
1
- import { IRFor as IRFor$1, VaporCodegenResult as VaporCodegenResult$1 } from '@vue/compiler-vapor';
2
- export { generate } from '@vue/compiler-vapor';
3
- import { SimpleExpressionNode, BindingTypes, DirectiveNode, CompoundExpressionNode, TransformOptions as TransformOptions$1, CompilerCompatOptions, CommentNode, CompilerOptions as CompilerOptions$1, ElementNode } from '@vue/compiler-dom';
4
- import * as _vue_runtime_vapor from '@vue/runtime-vapor';
5
- import { JSXFragment, Node, JSXAttribute, JSXElement, Program } from '@babel/types';
6
- import { Prettify } from '@vue/shared';
7
-
8
- interface IRProp extends Omit<DirectiveTransformResult, 'value'> {
9
- values: SimpleExpressionNode[];
10
- }
11
- declare enum IRDynamicPropsKind {
12
- EXPRESSION = 0,// v-bind="value"
13
- ATTRIBUTE = 1
14
- }
15
- type IRPropsStatic = IRProp[];
16
- interface IRPropsDynamicExpression {
17
- kind: IRDynamicPropsKind.EXPRESSION;
18
- value: SimpleExpressionNode;
19
- handler?: boolean;
20
- }
21
- interface IRPropsDynamicAttribute extends IRProp {
22
- kind: IRDynamicPropsKind.ATTRIBUTE;
23
- }
24
- type IRProps = IRPropsStatic | IRPropsDynamicAttribute | IRPropsDynamicExpression;
25
- interface SlotBlockIRNode extends BlockIRNode {
26
- props?: SimpleExpressionNode;
27
- }
28
- declare enum IRSlotType {
29
- STATIC = 0,
30
- DYNAMIC = 1,
31
- LOOP = 2,
32
- CONDITIONAL = 3,
33
- EXPRESSION = 4
34
- }
35
- interface IRSlotsStatic {
36
- slotType: IRSlotType.STATIC;
37
- slots: Record<string, SlotBlockIRNode>;
38
- }
39
- interface IRSlotDynamicBasic {
40
- slotType: IRSlotType.DYNAMIC;
41
- name: SimpleExpressionNode;
42
- fn: SlotBlockIRNode;
43
- }
44
- interface IRSlotDynamicLoop {
45
- slotType: IRSlotType.LOOP;
46
- name: SimpleExpressionNode;
47
- fn: SlotBlockIRNode;
48
- loop: IRFor$1;
49
- }
50
- interface IRSlotDynamicConditional {
51
- slotType: IRSlotType.CONDITIONAL;
52
- condition: SimpleExpressionNode;
53
- positive: IRSlotDynamicBasic;
54
- negative?: IRSlotDynamicBasic | IRSlotDynamicConditional;
55
- }
56
- interface IRSlotsExpression {
57
- slotType: IRSlotType.EXPRESSION;
58
- slots: SimpleExpressionNode;
59
- }
60
- type IRSlotDynamic = IRSlotDynamicBasic | IRSlotDynamicLoop | IRSlotDynamicConditional;
61
- type IRSlots = IRSlotsStatic | IRSlotDynamic | IRSlotsExpression;
62
-
63
- declare enum IRNodeTypes {
64
- ROOT = 0,
65
- BLOCK = 1,
66
- SET_PROP = 2,
67
- SET_DYNAMIC_PROPS = 3,
68
- SET_TEXT = 4,
69
- SET_EVENT = 5,
70
- SET_DYNAMIC_EVENTS = 6,
71
- SET_HTML = 7,
72
- SET_TEMPLATE_REF = 8,
73
- SET_MODEL_VALUE = 9,
74
- INSERT_NODE = 10,
75
- PREPEND_NODE = 11,
76
- CREATE_TEXT_NODE = 12,
77
- CREATE_COMPONENT_NODE = 13,
78
- SLOT_OUTLET_NODE = 14,
79
- WITH_DIRECTIVE = 15,
80
- DECLARE_OLD_REF = 16,// consider make it more general
81
- IF = 17,
82
- FOR = 18
83
- }
84
- interface BaseIRNode {
85
- type: IRNodeTypes;
86
- }
87
- type VaporHelper = keyof typeof _vue_runtime_vapor;
88
- interface RootNode {
89
- type: IRNodeTypes.ROOT;
90
- source: string;
91
- children: JSXFragment['children'];
92
- helpers: Set<symbol>;
93
- components: string[];
94
- directives: string[];
95
- temps: number;
96
- ssrHelpers?: symbol[];
97
- transformed?: boolean;
98
- }
99
- interface BlockIRNode extends BaseIRNode {
100
- type: IRNodeTypes.BLOCK;
101
- node: RootNode | Node;
102
- dynamic: IRDynamicInfo;
103
- effect: IREffect[];
104
- operation: OperationNode[];
105
- returns: number[];
106
- }
107
- interface RootIRNode {
108
- type: IRNodeTypes.ROOT;
109
- node: RootNode;
110
- source: string;
111
- template: string[];
112
- component: Set<string>;
113
- directive: Set<string>;
114
- block: BlockIRNode;
115
- }
116
- interface IfIRNode extends BaseIRNode {
117
- type: IRNodeTypes.IF;
118
- id: number;
119
- condition: SimpleExpressionNode;
120
- positive: BlockIRNode;
121
- negative?: BlockIRNode | IfIRNode;
122
- once?: boolean;
123
- }
124
- interface IRFor {
125
- source: SimpleExpressionNode;
126
- value?: SimpleExpressionNode;
127
- key?: SimpleExpressionNode;
128
- index?: SimpleExpressionNode;
129
- }
130
- interface ForIRNode extends BaseIRNode, IRFor {
131
- type: IRNodeTypes.FOR;
132
- id: number;
133
- keyProp?: SimpleExpressionNode;
134
- render: BlockIRNode;
135
- once: boolean;
136
- }
137
- interface SetPropIRNode extends BaseIRNode {
138
- type: IRNodeTypes.SET_PROP;
139
- element: number;
140
- prop: IRProp;
141
- }
142
- interface SetDynamicPropsIRNode extends BaseIRNode {
143
- type: IRNodeTypes.SET_DYNAMIC_PROPS;
144
- element: number;
145
- props: IRProps[];
146
- }
147
- interface SetDynamicEventsIRNode extends BaseIRNode {
148
- type: IRNodeTypes.SET_DYNAMIC_EVENTS;
149
- element: number;
150
- event: SimpleExpressionNode;
151
- }
152
- interface SetTextIRNode extends BaseIRNode {
153
- type: IRNodeTypes.SET_TEXT;
154
- element: number;
155
- values: SimpleExpressionNode[];
156
- }
157
- type KeyOverride = [find: string, replacement: string];
158
- interface SetEventIRNode extends BaseIRNode {
159
- type: IRNodeTypes.SET_EVENT;
160
- element: number;
161
- key: SimpleExpressionNode;
162
- value?: SimpleExpressionNode;
163
- modifiers: {
164
- options: string[];
165
- keys: string[];
166
- nonKeys: string[];
167
- };
168
- keyOverride?: KeyOverride;
169
- delegate: boolean;
170
- /** Whether it's in effect */
171
- effect: boolean;
172
- }
173
- interface SetHtmlIRNode extends BaseIRNode {
174
- type: IRNodeTypes.SET_HTML;
175
- element: number;
176
- value: SimpleExpressionNode;
177
- }
178
- interface SetTemplateRefIRNode extends BaseIRNode {
179
- type: IRNodeTypes.SET_TEMPLATE_REF;
180
- element: number;
181
- value: SimpleExpressionNode;
182
- refFor: boolean;
183
- effect: boolean;
184
- }
185
- interface SetModelValueIRNode extends BaseIRNode {
186
- type: IRNodeTypes.SET_MODEL_VALUE;
187
- element: number;
188
- key: SimpleExpressionNode;
189
- value: SimpleExpressionNode;
190
- bindingType?: BindingTypes;
191
- isComponent: boolean;
192
- }
193
- interface CreateTextNodeIRNode extends BaseIRNode {
194
- type: IRNodeTypes.CREATE_TEXT_NODE;
195
- id: number;
196
- values: SimpleExpressionNode[];
197
- effect: boolean;
198
- }
199
- interface InsertNodeIRNode extends BaseIRNode {
200
- type: IRNodeTypes.INSERT_NODE;
201
- elements: number[];
202
- parent: number;
203
- anchor?: number;
204
- }
205
- interface PrependNodeIRNode extends BaseIRNode {
206
- type: IRNodeTypes.PREPEND_NODE;
207
- elements: number[];
208
- parent: number;
209
- }
210
- interface WithDirectiveIRNode extends BaseIRNode {
211
- type: IRNodeTypes.WITH_DIRECTIVE;
212
- element: number;
213
- dir: VaporDirectiveNode;
214
- name: string;
215
- builtin?: boolean;
216
- asset?: boolean;
217
- }
218
- interface CreateComponentIRNode extends BaseIRNode {
219
- type: IRNodeTypes.CREATE_COMPONENT_NODE;
220
- id: number;
221
- tag: string;
222
- props: IRProps[];
223
- slots: IRSlots[];
224
- asset: boolean;
225
- root: boolean;
226
- once: boolean;
227
- }
228
- interface DeclareOldRefIRNode extends BaseIRNode {
229
- type: IRNodeTypes.DECLARE_OLD_REF;
230
- id: number;
231
- }
232
- interface SlotOutletIRNode extends BaseIRNode {
233
- type: IRNodeTypes.SLOT_OUTLET_NODE;
234
- id: number;
235
- name: SimpleExpressionNode;
236
- props: IRProps[];
237
- fallback?: BlockIRNode;
238
- }
239
- type IRNode = OperationNode | RootIRNode;
240
- type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | SetModelValueIRNode | CreateTextNodeIRNode | InsertNodeIRNode | PrependNodeIRNode | WithDirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode;
241
- declare enum DynamicFlag {
242
- NONE = 0,
243
- /**
244
- * This node is referenced and needs to be saved as a variable.
245
- */
246
- REFERENCED = 1,
247
- /**
248
- * This node is not generated from template, but is generated dynamically.
249
- */
250
- NON_TEMPLATE = 2,
251
- /**
252
- * This node needs to be inserted back into the template.
253
- */
254
- INSERT = 4
255
- }
256
- interface IRDynamicInfo {
257
- id?: number;
258
- flags: DynamicFlag;
259
- anchor?: number;
260
- children: IRDynamicInfo[];
261
- template?: number;
262
- }
263
- interface IREffect {
264
- expressions: SimpleExpressionNode[];
265
- operations: OperationNode[];
266
- }
267
- type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & Pick<U, Extract<keyof U, keyof T>>;
268
- type HackOptions<T> = Prettify<Overwrite<T, {
269
- nodeTransforms?: NodeTransform[];
270
- directiveTransforms?: Record<string, DirectiveTransform | undefined>;
271
- }>>;
272
- type VaporDirectiveNode = Overwrite<DirectiveNode, {
273
- exp: Exclude<DirectiveNode['exp'], CompoundExpressionNode>;
274
- arg: Exclude<DirectiveNode['arg'], CompoundExpressionNode>;
275
- }>;
276
-
277
- type NodeTransform = (node: BlockIRNode['node'], context: TransformContext<BlockIRNode['node']>) => void | (() => void) | (() => void)[];
278
- type DirectiveTransform = (dir: JSXAttribute, node: JSXElement, context: TransformContext<JSXElement>) => DirectiveTransformResult | void;
279
- interface DirectiveTransformResult {
280
- key: SimpleExpressionNode;
281
- value: SimpleExpressionNode;
282
- modifier?: '.' | '^';
283
- runtimeCamelize?: boolean;
284
- handler?: boolean;
285
- model?: boolean;
286
- modelModifiers?: string[];
287
- }
288
- type TransformOptions = HackOptions<TransformOptions$1>;
289
- declare class TransformContext<T extends BlockIRNode['node'] = BlockIRNode['node']> {
290
- ir: RootIRNode;
291
- node: T;
292
- parent: TransformContext<RootNode | JSXElement | JSXFragment> | null;
293
- root: TransformContext<RootNode>;
294
- index: number;
295
- block: BlockIRNode;
296
- options: Required<Omit<TransformOptions, 'filename' | keyof CompilerCompatOptions>>;
297
- template: string;
298
- childrenTemplate: (string | null)[];
299
- dynamic: IRDynamicInfo;
300
- inVOnce: boolean;
301
- inVFor: number;
302
- comment: CommentNode[];
303
- component: Set<string>;
304
- directive: Set<string>;
305
- slots: IRSlots[];
306
- private globalId;
307
- constructor(ir: RootIRNode, node: T, options?: TransformOptions);
308
- enterBlock(ir: BlockIRNode, isVFor?: boolean): () => void;
309
- increaseId: () => number;
310
- reference(): number;
311
- pushTemplate(content: string): number;
312
- registerTemplate(): number;
313
- registerEffect(expressions: SimpleExpressionNode[], ...operations: OperationNode[]): void;
314
- registerOperation(...node: OperationNode[]): void;
315
- create<E extends T>(node: E, index: number): TransformContext<E>;
316
- }
317
- declare function transform(node: RootNode, options?: TransformOptions): RootIRNode;
318
- declare function transformNode(context: TransformContext<BlockIRNode['node']>): void;
319
-
320
- interface VaporCodegenResult extends Omit<VaporCodegenResult$1, 'ast'> {
321
- ast: RootIRNode;
322
- }
323
- declare function compile(source: string | Program, options?: CompilerOptions): VaporCodegenResult;
324
- type CompilerOptions = HackOptions<CompilerOptions$1>;
325
- type TransformPreset = [
326
- NodeTransform[],
327
- Record<string, DirectiveTransform>
328
- ];
329
-
330
- declare function resolveNode(node: JSXElement, context: TransformContext): ElementNode;
331
- declare function resolveDirectiveNode(node: JSXAttribute, context: TransformContext): VaporDirectiveNode;
332
-
333
- declare const transformText: NodeTransform;
334
-
335
- declare const transformElement: NodeTransform;
336
-
337
- declare const transformChildren: NodeTransform;
338
-
339
- declare const transformTemplateRef: NodeTransform;
340
-
341
- declare const transformVBind: DirectiveTransform;
342
-
343
- declare const transformVOn: DirectiveTransform;
344
-
345
- declare const transformVSlot: NodeTransform;
346
-
347
- declare const transformVModel: DirectiveTransform;
348
-
349
- declare const transformVShow: DirectiveTransform;
350
-
351
- declare const transformVHtml: DirectiveTransform;
352
-
353
- export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type CreateTextNodeIRNode, type DeclareOldRefIRNode, type DirectiveTransform, type DirectiveTransformResult, DynamicFlag, type ForIRNode, type HackOptions, type IRDynamicInfo, IRDynamicPropsKind, type IREffect, type IRFor, type IRNode, IRNodeTypes, type IRProp, type IRProps, type IRPropsDynamicAttribute, type IRPropsDynamicExpression, type IRPropsStatic, type IRSlotDynamic, type IRSlotDynamicBasic, type IRSlotDynamicConditional, type IRSlotDynamicLoop, IRSlotType, type IRSlots, type IRSlotsExpression, type IRSlotsStatic, type IfIRNode, type InsertNodeIRNode, type KeyOverride, type NodeTransform, type OperationNode, type PrependNodeIRNode, type RootIRNode, type RootNode, type SetDynamicEventsIRNode, type SetDynamicPropsIRNode, type SetEventIRNode, type SetHtmlIRNode, type SetModelValueIRNode, type SetPropIRNode, type SetTemplateRefIRNode, type SetTextIRNode, type SlotBlockIRNode, type SlotOutletIRNode, TransformContext, type TransformOptions, type TransformPreset, type VaporDirectiveNode, type VaporHelper, type WithDirectiveIRNode, compile, resolveDirectiveNode, resolveNode, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVHtml, transformVModel, transformVOn, transformVShow, transformVSlot };