bobe 0.0.33 → 0.0.35

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.d.ts CHANGED
@@ -146,11 +146,11 @@ declare enum FakeType {
146
146
  }
147
147
  type NodeSortBit = number;
148
148
  type BaseType = string | number | boolean | undefined | null;
149
- interface SourceLocation {
149
+ type SourceLocation = {
150
150
  start: Position;
151
151
  end: Position;
152
152
  source: string;
153
- }
153
+ };
154
154
  interface Position {
155
155
  line: number;
156
156
  column: number;
@@ -369,21 +369,21 @@ interface DynamicValue extends BaseNode {
369
369
  }
370
370
  interface ConditionalNode extends BaseNode {
371
371
  type: NodeType.If | NodeType.Else | NodeType.Fail;
372
- condition: string;
372
+ condition: PropertyValue;
373
373
  consequent: TemplateNode[];
374
374
  children?: TemplateNode[];
375
375
  }
376
376
  interface LoopNode extends BaseNode {
377
377
  type: NodeType.For;
378
- collection: string;
379
- item: string;
380
- index?: string;
381
- key?: string;
378
+ collection: PropertyValue;
379
+ item: PropertyValue;
380
+ index?: PropertyValue;
381
+ key?: PropertyValue;
382
382
  children: TemplateNode[];
383
383
  }
384
384
  interface ComponentNode extends BaseNode {
385
385
  type: NodeType.Component;
386
- componentName: string;
386
+ componentName: PropertyValue;
387
387
  props: Property[];
388
388
  children?: TemplateNode[];
389
389
  }
@@ -438,6 +438,10 @@ declare class Compiler {
438
438
  * 根据值类型创建属性值节点
439
439
  */
440
440
  parsePropertyValue(node?: PropertyValue): PropertyValue;
441
+ /**
442
+ * 根据值类型创建名称
443
+ */
444
+ parseName(node?: PropertyValue): PropertyValue;
441
445
  }
442
446
  type PickParseProps<T> = {
443
447
  [K in keyof T as K extends `parse${string}` ? K : never]: T[K];
@@ -455,4 +459,4 @@ declare function bobe(fragments: TemplateStringsArray, ...values: any[]): BobeUI
455
459
  declare function customRender(option: CustomRenderConf): <T>(Ctor: typeof Store, root: any) => (ComponentNode$1 | Store)[];
456
460
 
457
461
  export { Compiler, NodeType, Tokenizer, bobe, customRender };
458
- export type { ASTNodeType, BaseNode, ComponentNode, ConditionalNode, DynamicValue, ElementNode, FragmentNode, InterpolationNode, LoopNode, Program, Property, PropertyKeyNode, PropertyValue, StaticValue, TemplateNode, TextNode };
462
+ export type { ASTNodeType, BaseNode, ComponentNode, ConditionalNode, DynamicValue, ElementNode, FragmentNode, InterpolationNode, LoopNode, Program, Property, PropertyKeyNode, PropertyValue, SourceLocation, StaticValue, TemplateNode, TextNode };
package/dist/index.umd.js CHANGED
@@ -600,24 +600,6 @@
600
600
  }
601
601
  }
602
602
 
603
- var NodeType = function (NodeType) {
604
- NodeType["Element"] = "Element";
605
- NodeType["Text"] = "Text";
606
- NodeType["Interpolation"] = "Interpolation";
607
- NodeType["Property"] = "Property";
608
- NodeType["PropertyKey"] = "PropertyKey";
609
- NodeType["StaticValue"] = "StaticValue";
610
- NodeType["DynamicValue"] = "DynamicValue";
611
- NodeType["Program"] = "Program";
612
- NodeType["If"] = "If";
613
- NodeType["Else"] = "Else";
614
- NodeType["Fail"] = "Fail";
615
- NodeType["For"] = "For";
616
- NodeType["Component"] = "Component";
617
- NodeType["Fragment"] = "Fragment";
618
- return NodeType;
619
- }(NodeType || {});
620
-
621
603
  function _applyDecs2311(e, t, n, r, o, i) {
622
604
  var a,
623
605
  c,
@@ -834,10 +816,28 @@
834
816
  }
835
817
  }
836
818
 
819
+ var NodeType = function (NodeType) {
820
+ NodeType["Element"] = "Element";
821
+ NodeType["Text"] = "Text";
822
+ NodeType["Interpolation"] = "Interpolation";
823
+ NodeType["Property"] = "Property";
824
+ NodeType["PropertyKey"] = "PropertyKey";
825
+ NodeType["StaticValue"] = "StaticValue";
826
+ NodeType["DynamicValue"] = "DynamicValue";
827
+ NodeType["Program"] = "Program";
828
+ NodeType["If"] = "If";
829
+ NodeType["Else"] = "Else";
830
+ NodeType["Fail"] = "Fail";
831
+ NodeType["For"] = "For";
832
+ NodeType["Component"] = "Component";
833
+ NodeType["Fragment"] = "Fragment";
834
+ return NodeType;
835
+ }(NodeType || {});
836
+
837
837
  let _initProto;
838
838
  class Compiler {
839
839
  static {
840
- var _applyDecs$e = _slicedToArray(_applyDecs2311(this, [], [[NodeHook, 2, "parseProgram"], [[NodeHook, NodeLoc], 2, "parseComponentNode"], [[NodeHook, NodeLoc], 2, "parseElementNode"], [[NodeHook, NodeLoc], 2, "parseConditionalNode"], [[NodeHook, NodeLoc], 2, "parseLoopNode"], [NodeHook, 2, "parseProperty"], [[NodeHook, TokenLoc], 2, "parsePropertyKey"], [[NodeHook, TokenLoc], 2, "parsePropertyValue"]]).e, 1);
840
+ var _applyDecs$e = _slicedToArray(_applyDecs2311(this, [], [[NodeHook, 2, "parseProgram"], [[NodeHook, NodeLoc], 2, "parseComponentNode"], [[NodeHook, NodeLoc], 2, "parseElementNode"], [[NodeHook, NodeLoc], 2, "parseConditionalNode"], [[NodeHook, NodeLoc], 2, "parseLoopNode"], [NodeHook, 2, "parseProperty"], [[NodeHook, TokenLoc], 2, "parsePropertyKey"], [[NodeHook, TokenLoc], 2, "parsePropertyValue"], [[NodeHook, TokenLoc], 2, "parseName"]]).e, 1);
841
841
  _initProto = _applyDecs$e[0];
842
842
  }
843
843
  constructor(tokenizer, hooks = {}) {
@@ -906,12 +906,11 @@
906
906
  return this.parseElementNode();
907
907
  }
908
908
  parseComponentNode(node) {
909
- const tagToken = this.tokenizer.token;
910
- const tagName = tagToken.value;
909
+ const name = this.parseName();
911
910
  this.tokenizer.nextToken();
912
911
  const props = this.headerLineAndExtensions();
913
912
  node.type = NodeType.Component;
914
- node.componentName = tagName;
913
+ node.componentName = name;
915
914
  node.props = props;
916
915
  this.hooks.parseComponentNode?.propsAdded?.call(this, node);
917
916
  const children = this.handleChildren();
@@ -933,8 +932,8 @@
933
932
  }
934
933
  parseConditionalNode(node) {
935
934
  const keyword = this.tokenizer.token.value;
936
- const conditionToken = this.tokenizer.condExp();
937
- const condition = conditionToken.value;
935
+ this.tokenizer.condExp();
936
+ const condition = this.parsePropertyValue();
938
937
  this.tokenizer.nextToken();
939
938
  this.tokenizer.nextToken();
940
939
  node.type = keyword === 'if' ? NodeType.If : keyword === 'else' ? NodeType.Else : NodeType.Fail;
@@ -945,22 +944,33 @@
945
944
  return node;
946
945
  }
947
946
  parseLoopNode(node) {
948
- const collection = this.tokenizer.nextToken().value;
947
+ this.tokenizer.nextToken();
948
+ const collection = this.parsePropertyValue();
949
949
  this.tokenizer.nextToken();
950
950
  const itemToken = this.tokenizer.nextToken();
951
951
  const isDestruct = itemToken.type === TokenType.InsertionExp;
952
- let item = isDestruct ? `{${itemToken.value}}` : itemToken.value;
952
+ if (isDestruct) {
953
+ itemToken.value = '{' + itemToken.value + '}';
954
+ }
955
+ const item = this.parsePropertyValue();
953
956
  let char = this.tokenizer.peekChar(),
954
957
  key,
955
958
  index;
956
959
  if (char === ';') {
957
960
  this.tokenizer.nextToken();
958
- if (this.tokenizer.peekChar() !== '\n') key = this.tokenizer.jsExp().value;
961
+ if (this.tokenizer.peekChar() !== '\n') {
962
+ this.tokenizer.jsExp();
963
+ key = this.parsePropertyValue();
964
+ }
959
965
  } else if (char === '\n') ; else {
960
- index = this.tokenizer.nextToken().value;
966
+ this.tokenizer.nextToken();
967
+ index = this.parsePropertyValue();
961
968
  if (this.tokenizer.peekChar() === ';') {
962
969
  this.tokenizer.nextToken();
963
- if (this.tokenizer.peekChar() !== '\n') key = this.tokenizer.jsExp().value;
970
+ if (this.tokenizer.peekChar() !== '\n') {
971
+ this.tokenizer.jsExp();
972
+ key = this.parsePropertyValue();
973
+ }
964
974
  }
965
975
  }
966
976
  this.tokenizer.nextToken();
@@ -1025,6 +1035,15 @@
1025
1035
  node.value = value;
1026
1036
  return node;
1027
1037
  }
1038
+ parseName(node) {
1039
+ const _this$tokenizer$_hook5 = this.tokenizer._hook({}),
1040
+ _this$tokenizer$_hook6 = _slicedToArray(_this$tokenizer$_hook5, 2),
1041
+ hookType = _this$tokenizer$_hook6[0],
1042
+ value = _this$tokenizer$_hook6[1];
1043
+ node.type = hookType === 'dynamic' ? NodeType.DynamicValue : NodeType.StaticValue;
1044
+ node.value = value;
1045
+ return node;
1046
+ }
1028
1047
  }
1029
1048
  function NodeLoc(target, context) {
1030
1049
  return function (_node) {