@vue-jsx-vapor/compiler 0.0.1 → 0.0.3

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.d.cts CHANGED
@@ -71,15 +71,16 @@ declare enum IRNodeTypes {
71
71
  SET_HTML = 7,
72
72
  SET_TEMPLATE_REF = 8,
73
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
74
+ SET_INHERIT_ATTRS = 10,
75
+ INSERT_NODE = 11,
76
+ PREPEND_NODE = 12,
77
+ CREATE_TEXT_NODE = 13,
78
+ CREATE_COMPONENT_NODE = 14,
79
+ SLOT_OUTLET_NODE = 15,
80
+ WITH_DIRECTIVE = 16,
81
+ DECLARE_OLD_REF = 17,// consider make it more general
82
+ IF = 18,
83
+ FOR = 19
83
84
  }
84
85
  interface BaseIRNode {
85
86
  type: IRNodeTypes;
@@ -133,16 +134,20 @@ interface ForIRNode extends BaseIRNode, IRFor {
133
134
  keyProp?: SimpleExpressionNode;
134
135
  render: BlockIRNode;
135
136
  once: boolean;
137
+ container?: number;
136
138
  }
137
139
  interface SetPropIRNode extends BaseIRNode {
138
140
  type: IRNodeTypes.SET_PROP;
139
141
  element: number;
140
142
  prop: IRProp;
143
+ root: boolean;
144
+ tag: string;
141
145
  }
142
146
  interface SetDynamicPropsIRNode extends BaseIRNode {
143
147
  type: IRNodeTypes.SET_DYNAMIC_PROPS;
144
148
  element: number;
145
149
  props: IRProps[];
150
+ root: boolean;
146
151
  }
147
152
  interface SetDynamicEventsIRNode extends BaseIRNode {
148
153
  type: IRNodeTypes.SET_DYNAMIC_EVENTS;
@@ -190,6 +195,11 @@ interface SetModelValueIRNode extends BaseIRNode {
190
195
  bindingType?: BindingTypes;
191
196
  isComponent: boolean;
192
197
  }
198
+ interface SetInheritAttrsIRNode extends BaseIRNode {
199
+ type: IRNodeTypes.SET_INHERIT_ATTRS;
200
+ staticProps: boolean;
201
+ dynamicProps: true | string[];
202
+ }
193
203
  interface CreateTextNodeIRNode extends BaseIRNode {
194
204
  type: IRNodeTypes.CREATE_TEXT_NODE;
195
205
  id: number;
@@ -237,7 +247,7 @@ interface SlotOutletIRNode extends BaseIRNode {
237
247
  fallback?: BlockIRNode;
238
248
  }
239
249
  type IRNode = OperationNode | RootIRNode;
240
- type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | SetModelValueIRNode | CreateTextNodeIRNode | InsertNodeIRNode | PrependNodeIRNode | WithDirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode;
250
+ type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | SetModelValueIRNode | SetInheritAttrsIRNode | CreateTextNodeIRNode | InsertNodeIRNode | PrependNodeIRNode | WithDirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode;
241
251
  declare enum DynamicFlag {
242
252
  NONE = 0,
243
253
  /**
@@ -262,7 +272,12 @@ interface IRDynamicInfo {
262
272
  }
263
273
  interface IREffect {
264
274
  expressions: SimpleExpressionNode[];
275
+ identifiers: string[];
265
276
  operations: OperationNode[];
277
+ declareNames: Set<string>;
278
+ rewrittenNames: Set<string>;
279
+ earlyCheckExps: string[];
280
+ inVFor: boolean;
266
281
  }
267
282
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & Pick<U, Extract<keyof U, keyof T>>;
268
283
  type HackOptions<T> = Prettify<Overwrite<T, {
@@ -350,4 +365,4 @@ declare const transformVShow: DirectiveTransform;
350
365
 
351
366
  declare const transformVHtml: DirectiveTransform;
352
367
 
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 };
368
+ 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 SetInheritAttrsIRNode, 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 CHANGED
@@ -71,15 +71,16 @@ declare enum IRNodeTypes {
71
71
  SET_HTML = 7,
72
72
  SET_TEMPLATE_REF = 8,
73
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
74
+ SET_INHERIT_ATTRS = 10,
75
+ INSERT_NODE = 11,
76
+ PREPEND_NODE = 12,
77
+ CREATE_TEXT_NODE = 13,
78
+ CREATE_COMPONENT_NODE = 14,
79
+ SLOT_OUTLET_NODE = 15,
80
+ WITH_DIRECTIVE = 16,
81
+ DECLARE_OLD_REF = 17,// consider make it more general
82
+ IF = 18,
83
+ FOR = 19
83
84
  }
84
85
  interface BaseIRNode {
85
86
  type: IRNodeTypes;
@@ -133,16 +134,20 @@ interface ForIRNode extends BaseIRNode, IRFor {
133
134
  keyProp?: SimpleExpressionNode;
134
135
  render: BlockIRNode;
135
136
  once: boolean;
137
+ container?: number;
136
138
  }
137
139
  interface SetPropIRNode extends BaseIRNode {
138
140
  type: IRNodeTypes.SET_PROP;
139
141
  element: number;
140
142
  prop: IRProp;
143
+ root: boolean;
144
+ tag: string;
141
145
  }
142
146
  interface SetDynamicPropsIRNode extends BaseIRNode {
143
147
  type: IRNodeTypes.SET_DYNAMIC_PROPS;
144
148
  element: number;
145
149
  props: IRProps[];
150
+ root: boolean;
146
151
  }
147
152
  interface SetDynamicEventsIRNode extends BaseIRNode {
148
153
  type: IRNodeTypes.SET_DYNAMIC_EVENTS;
@@ -190,6 +195,11 @@ interface SetModelValueIRNode extends BaseIRNode {
190
195
  bindingType?: BindingTypes;
191
196
  isComponent: boolean;
192
197
  }
198
+ interface SetInheritAttrsIRNode extends BaseIRNode {
199
+ type: IRNodeTypes.SET_INHERIT_ATTRS;
200
+ staticProps: boolean;
201
+ dynamicProps: true | string[];
202
+ }
193
203
  interface CreateTextNodeIRNode extends BaseIRNode {
194
204
  type: IRNodeTypes.CREATE_TEXT_NODE;
195
205
  id: number;
@@ -237,7 +247,7 @@ interface SlotOutletIRNode extends BaseIRNode {
237
247
  fallback?: BlockIRNode;
238
248
  }
239
249
  type IRNode = OperationNode | RootIRNode;
240
- type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | SetModelValueIRNode | CreateTextNodeIRNode | InsertNodeIRNode | PrependNodeIRNode | WithDirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode;
250
+ type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | SetModelValueIRNode | SetInheritAttrsIRNode | CreateTextNodeIRNode | InsertNodeIRNode | PrependNodeIRNode | WithDirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode;
241
251
  declare enum DynamicFlag {
242
252
  NONE = 0,
243
253
  /**
@@ -262,7 +272,12 @@ interface IRDynamicInfo {
262
272
  }
263
273
  interface IREffect {
264
274
  expressions: SimpleExpressionNode[];
275
+ identifiers: string[];
265
276
  operations: OperationNode[];
277
+ declareNames: Set<string>;
278
+ rewrittenNames: Set<string>;
279
+ earlyCheckExps: string[];
280
+ inVFor: boolean;
266
281
  }
267
282
  type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & Pick<U, Extract<keyof U, keyof T>>;
268
283
  type HackOptions<T> = Prettify<Overwrite<T, {
@@ -350,4 +365,4 @@ declare const transformVShow: DirectiveTransform;
350
365
 
351
366
  declare const transformVHtml: DirectiveTransform;
352
367
 
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 };
368
+ 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 SetInheritAttrsIRNode, 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.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.1",
3
+ "version": "0.0.3",
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
  }