bobe 0.0.16 → 0.0.17

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.umd.js CHANGED
@@ -110,30 +110,34 @@
110
110
  var _a;
111
111
  return (_a = this.top) == null ? void 0 : _a.value;
112
112
  }
113
- /**
114
- * 1. 全局向前遍历 (不分类)
115
- * 从栈顶开始,沿着全局链条向栈底遍历
116
- */
117
- forEach(callback) {
118
- let current = this.top;
119
- while (current !== null) {
120
- const shouldBreak = callback(current.value, current.types);
121
- if (shouldBreak) break;
122
- current = current.prevGlobal;
123
- }
124
- }
125
- /**
126
- * 2. 按类别向前遍历
127
- * 仅遍历属于指定类别 cat 的节点
128
- */
129
- forEachByType(cat, callback) {
130
- let current = this.typeTops[cat];
131
- while (current) {
132
- const shouldBreak = callback(current.value);
133
- if (shouldBreak) break;
134
- current = current.prevByType[cat];
135
- }
136
- }
113
+ // /**
114
+ // * 1. 全局向前遍历 (不分类)
115
+ // * 从栈顶开始,沿着全局链条向栈底遍历
116
+ // */
117
+ // forEach(callback: (value: T, types: number) => any): void {
118
+ // let current = this.top;
119
+ // while (current !== null) {
120
+ // // 执行回调,如果返回 false 则立即停止
121
+ // const shouldBreak = callback(current.value, current.types);
122
+ // if (shouldBreak) break;
123
+ // current = current.prevGlobal;
124
+ // }
125
+ // }
126
+ // /**
127
+ // * 2. 按类别向前遍历
128
+ // * 仅遍历属于指定类别 cat 的节点
129
+ // */
130
+ // forEachByType(cat: number, callback: (value: T) => any): void {
131
+ // // 从该类别的当前“顶端”节点开始
132
+ // let current = this.typeTops[cat];
133
+ // while (current) {
134
+ // const shouldBreak = callback(current.value);
135
+ // if (shouldBreak) break;
136
+ // // 关键点:直接跳向该节点记录的“上一个同类节点”
137
+ // // 这比遍历全局栈再筛选类别要快得多 (O(m) vs O(n))
138
+ // current = current.prevByType[cat];
139
+ // }
140
+ // }
137
141
  }
138
142
 
139
143
  const tap = new bobeShared.BaseEvent();
@@ -148,7 +152,7 @@
148
152
  program(root, componentNode, before) {
149
153
  var _a, _b;
150
154
  this.rootComponent = componentNode;
151
- this.tokenizer.consume();
155
+ this.tokenizer.nextToken();
152
156
  const stack = new MultiTypeStack();
153
157
  stack.push({ node: root, prev: null }, NodeSort.Real);
154
158
  stack.push(
@@ -171,7 +175,7 @@
171
175
  }
172
176
  const token = this.tokenizer.token;
173
177
  if (token.type & TokenType.Indent) {
174
- this.tokenizer.consume();
178
+ this.tokenizer.nextToken();
175
179
  const isLogicNode = this.isLogicNode(ctx.current);
176
180
  stack.push(
177
181
  {
@@ -200,7 +204,7 @@
200
204
  this.handleInsert(ctx.realParent, ctx.current, ctx.prevSibling);
201
205
  }
202
206
  if (this.tokenizer.token.type & TokenType.Dedent) {
203
- this.tokenizer.consume();
207
+ this.tokenizer.nextToken();
204
208
  const [{ node: parent, prev }, sort] = stack.pop();
205
209
  if (!parent.__logicType) {
206
210
  const prevSameType = stack.peekByType(NodeSort.Real);
@@ -305,7 +309,7 @@
305
309
  } else {
306
310
  _node = this.createNode(value);
307
311
  }
308
- this.tokenizer.consume();
312
+ this.tokenizer.nextToken();
309
313
  this.headerLine(_node);
310
314
  this.extensionLines(_node);
311
315
  if (_node.__logicType === FakeType.Component) {
@@ -394,7 +398,8 @@
394
398
  var _a;
395
399
  const { prevSibling } = ctx;
396
400
  const snapbackUp = this.tokenizer.snapshot();
397
- const keyWord = this.tokenizer.consume();
401
+ const keyWord = this.tokenizer.token;
402
+ this.tokenizer.nextToken();
398
403
  const noSelfCond = this.tokenizer.token.type === TokenType.NewLine;
399
404
  const [hookType, value] = this.tokenizer._hook({});
400
405
  const isElse = keyWord.value === "else";
@@ -475,9 +480,9 @@
475
480
  if (val) {
476
481
  if (ifNode.isFirstRender) {
477
482
  if (!noSelfCond) {
478
- this.tokenizer.consume();
483
+ this.tokenizer.nextToken();
479
484
  }
480
- this.tokenizer.consume();
485
+ this.tokenizer.nextToken();
481
486
  } else {
482
487
  this.tokenizer = ifNode.owner.tokenizer;
483
488
  this.tokenizer.resume(ifNode.snapshot);
@@ -512,15 +517,15 @@
512
517
  */
513
518
  extensionLines(_node) {
514
519
  while (1) {
515
- if (!(this.tokenizer.token.type & TokenType.Pipe)) {
520
+ if ((this.tokenizer.token.type & TokenType.Pipe) === 0) {
516
521
  return;
517
522
  }
518
- this.tokenizer.consume();
523
+ this.tokenizer.nextToken();
519
524
  this.attributeList(_node);
520
- if (!(this.tokenizer.token.type & TokenType.NewLine)) {
525
+ if ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
521
526
  return;
522
527
  }
523
- this.tokenizer.consume();
528
+ this.tokenizer.nextToken();
524
529
  }
525
530
  }
526
531
  /**
@@ -530,7 +535,7 @@
530
535
  */
531
536
  headerLine(_node) {
532
537
  this.attributeList(_node);
533
- this.tokenizer.consume();
538
+ this.tokenizer.nextToken();
534
539
  }
535
540
  /**
536
541
  * 属性列表:
@@ -540,19 +545,19 @@
540
545
  *
541
546
  * <attribute> ::= <key> = <value>
542
547
  * 1. 普通节点 执行 setProps 🪝
543
- * 2. 组件节点 收集映射关系,或通过 effect 直接设值
548
+ * 2. 组件节点 收集映射关系,或 产生 computed
544
549
  */
545
550
  attributeList(_node) {
546
551
  let key, eq;
547
552
  const data = this.getData();
548
- while (!(this.tokenizer.token.type & TokenType.NewLine)) {
553
+ while ((this.tokenizer.token.type & TokenType.NewLine) === 0) {
549
554
  if (key == null) {
550
555
  key = this.tokenizer.token.value;
551
556
  } else if (eq == null) {
552
557
  eq = "=";
553
558
  } else {
554
559
  const [hookType, value, hookI] = this.tokenizer._hook({});
555
- const rawVal = Reflect.get(data[aoye.Keys.Raw], value);
560
+ const rawVal = data[aoye.Keys.Raw][value];
556
561
  const isFn = typeof rawVal === "function";
557
562
  if (hookType === "dynamic") {
558
563
  const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
@@ -566,7 +571,7 @@
566
571
  key = null;
567
572
  eq = null;
568
573
  }
569
- this.tokenizer.consume();
574
+ this.tokenizer.nextToken();
570
575
  }
571
576
  }
572
577
  config(opt) {
@@ -726,16 +731,16 @@
726
731
  let skipFragment = ``;
727
732
  this.token = void 0;
728
733
  while (1) {
729
- const char = this.char;
734
+ const char = this.code[this.i];
730
735
  if (char === "\n") {
731
736
  needIndent = true;
732
737
  skipFragment += char;
733
- this.next();
738
+ this.i++;
734
739
  continue;
735
740
  }
736
741
  if (!needIndent) {
737
742
  skipFragment += char;
738
- this.next();
743
+ this.i++;
739
744
  continue;
740
745
  }
741
746
  needIndent = false;
@@ -788,21 +793,6 @@ ${_Tokenizer.EofId}`;
788
793
  if (!this.token) return false;
789
794
  return this.token.type & TokenType.Identifier && this.token.value === _Tokenizer.EofId;
790
795
  }
791
- get char() {
792
- return this.code[this.i];
793
- }
794
- get prev() {
795
- return this.code[this.i - 1];
796
- }
797
- get after() {
798
- return this.code[this.i + 1];
799
- }
800
- next() {
801
- const prev = this.code[this.i];
802
- this.i++;
803
- const curr = this.code[this.i];
804
- return [prev, curr];
805
- }
806
796
  setToken(type, value) {
807
797
  this.token = {
808
798
  type,
@@ -811,10 +801,6 @@ ${_Tokenizer.EofId}`;
811
801
  };
812
802
  this.isFirstToken = false;
813
803
  }
814
- testId(value) {
815
- if (typeof value !== "string") return false;
816
- return _Tokenizer.IdExp.test(value);
817
- }
818
804
  nextToken() {
819
805
  try {
820
806
  if (this.isEof()) {
@@ -830,7 +816,7 @@ ${_Tokenizer.EofId}`;
830
816
  if (this.needIndent) {
831
817
  this.dent();
832
818
  } else {
833
- let { char } = this;
819
+ const char = this.code[this.i];
834
820
  switch (char) {
835
821
  case " ":
836
822
  case " ":
@@ -861,12 +847,12 @@ ${_Tokenizer.EofId}`;
861
847
  this.number(char);
862
848
  break;
863
849
  }
864
- if (this.testId(char)) {
850
+ if (typeof char === "string" && bobeShared.matchIdStart(char)) {
865
851
  this.identifier(char);
866
852
  }
867
853
  break;
868
854
  }
869
- this.next();
855
+ this.i++;
870
856
  }
871
857
  if (this.token) {
872
858
  break;
@@ -875,6 +861,7 @@ ${_Tokenizer.EofId}`;
875
861
  return this.token;
876
862
  } catch (error) {
877
863
  console.error(error);
864
+ return this.token;
878
865
  } finally {
879
866
  this.handledTokens.push(this.token);
880
867
  }
@@ -886,17 +873,17 @@ ${_Tokenizer.EofId}`;
886
873
  this.setToken(TokenType.Pipe, "|");
887
874
  }
888
875
  dynamic(char) {
889
- let nextC = this.after;
876
+ let nextC = this.code[this.i + 1];
890
877
  if (nextC !== "{") {
891
878
  return false;
892
879
  }
893
- this.next();
880
+ this.i++;
894
881
  let value = "${";
895
882
  let innerBrace = 0;
896
883
  while (1) {
897
- nextC = this.after;
884
+ nextC = this.code[this.i + 1];
898
885
  value += nextC;
899
- this.next();
886
+ this.i++;
900
887
  if (nextC === "{") {
901
888
  innerBrace++;
902
889
  }
@@ -913,13 +900,14 @@ ${_Tokenizer.EofId}`;
913
900
  brace() {
914
901
  let inComment, inString, count = 0, value = "", backslashCount = 0;
915
902
  while (1) {
916
- const char = this.char;
917
- const nextChar = this.after;
903
+ const char = this.code[this.i];
904
+ const nextChar = this.code[this.i + 1];
918
905
  if (inComment === "single" && char === "\n") {
919
906
  inComment = null;
920
907
  } else if (inComment === "multi" && char === "*" && nextChar === "/") {
921
908
  inComment = null;
922
- value += this.next()[0];
909
+ value += this.code[this.i];
910
+ this.i++;
923
911
  } else if (inString) {
924
912
  if (char === inString && backslashCount % 2 === 0) {
925
913
  inString = null;
@@ -928,10 +916,12 @@ ${_Tokenizer.EofId}`;
928
916
  } else {
929
917
  if (char === "/" && nextChar === "/") {
930
918
  inComment = "single";
931
- value += this.next()[0];
919
+ value += this.code[this.i];
920
+ this.i++;
932
921
  } else if (char === "/" && nextChar === "*") {
933
922
  inComment = "multi";
934
- value += this.next()[0];
923
+ value += this.code[this.i];
924
+ this.i++;
935
925
  } else if (char === "'" || char === '"' || char === "`") {
936
926
  inString = char;
937
927
  } else if (char === "{") {
@@ -944,19 +934,20 @@ ${_Tokenizer.EofId}`;
944
934
  this.setToken(TokenType.InsertionExp, value.slice(1));
945
935
  return;
946
936
  }
947
- value += this.next()[0];
937
+ value += this.code[this.i];
938
+ this.i++;
948
939
  }
949
940
  }
950
941
  newLine() {
951
942
  let value = "\n";
952
943
  let nextC;
953
944
  while (1) {
954
- nextC = this.after;
945
+ nextC = this.code[this.i + 1];
955
946
  if (nextC !== "\n") {
956
947
  break;
957
948
  }
958
949
  value += nextC;
959
- this.next();
950
+ this.i++;
960
951
  }
961
952
  if (this.isFirstToken) {
962
953
  return;
@@ -968,7 +959,7 @@ ${_Tokenizer.EofId}`;
968
959
  let nextC;
969
960
  let isEmptyLine = false;
970
961
  while (1) {
971
- const nextChar = this.char;
962
+ const nextChar = this.code[this.i];
972
963
  switch (nextChar) {
973
964
  case " ":
974
965
  nextC = this.Tab;
@@ -991,7 +982,7 @@ ${_Tokenizer.EofId}`;
991
982
  break;
992
983
  }
993
984
  value += nextC;
994
- this.next();
985
+ this.i++;
995
986
  }
996
987
  return {
997
988
  value,
@@ -1014,7 +1005,7 @@ ${_Tokenizer.EofId}`;
1014
1005
  const prevLen = this.dentStack[this.dentStack.length - 1];
1015
1006
  if (currLen > prevLen) {
1016
1007
  this.dentStack.push(currLen);
1017
- this.setToken(TokenType.Indent, String(currLen));
1008
+ this.setToken(TokenType.Indent, currLen);
1018
1009
  return indentHasLen;
1019
1010
  }
1020
1011
  if (currLen < prevLen) {
@@ -1073,12 +1064,12 @@ ${_Tokenizer.EofId}`;
1073
1064
  let value = char;
1074
1065
  let nextC;
1075
1066
  while (1) {
1076
- nextC = this.after;
1077
- if (!this.testId(nextC)) {
1067
+ nextC = this.code[this.i + 1];
1068
+ if (typeof nextC !== "string" || !bobeShared.matchIdStart(nextC)) {
1078
1069
  break;
1079
1070
  }
1080
1071
  value += nextC;
1081
- this.next();
1072
+ this.i++;
1082
1073
  }
1083
1074
  if (value === _Tokenizer.EofId && this.isSubToken) {
1084
1075
  this.setToken(TokenType.Dedent, "");
@@ -1088,35 +1079,35 @@ ${_Tokenizer.EofId}`;
1088
1079
  this.setToken(TokenType.Identifier, realValue);
1089
1080
  }
1090
1081
  str(char) {
1091
- let value = '"';
1082
+ let value = "";
1092
1083
  let nextC;
1093
1084
  let continuousBackslashCount = 0;
1094
1085
  while (1) {
1095
- nextC = this.after;
1096
- value += nextC;
1086
+ nextC = this.code[this.i + 1];
1097
1087
  const memoCount = continuousBackslashCount;
1098
1088
  if (nextC === "\\") {
1099
1089
  continuousBackslashCount++;
1100
1090
  } else {
1101
1091
  continuousBackslashCount = 0;
1102
1092
  }
1103
- this.next();
1093
+ this.i++;
1104
1094
  if (nextC === char && memoCount % 2 === 0) {
1105
1095
  break;
1106
1096
  }
1097
+ value += nextC;
1107
1098
  }
1108
- this.setToken(TokenType.Identifier, JSON.parse(value.slice(0, -1) + '"'));
1099
+ this.setToken(TokenType.Identifier, value);
1109
1100
  }
1110
1101
  number(char) {
1111
1102
  let value = char;
1112
1103
  let nextC;
1113
1104
  while (1) {
1114
- nextC = this.after;
1105
+ nextC = this.code[this.i + 1];
1115
1106
  if (!bobeShared.isNum(nextC)) {
1116
1107
  break;
1117
1108
  }
1118
1109
  value += nextC;
1119
- this.next();
1110
+ this.i++;
1120
1111
  }
1121
1112
  this.setToken(TokenType.Identifier, Number(value));
1122
1113
  }
@@ -1136,8 +1127,6 @@ ${_Tokenizer.EofId}`;
1136
1127
  }
1137
1128
  }
1138
1129
  };
1139
- /** 匹配标识符 */
1140
- _Tokenizer.IdExp = /[\d\w\/]/;
1141
1130
  /** Eof 标识符的值 */
1142
1131
  _Tokenizer.EofId = `__EOF__${Date.now()}`;
1143
1132
  _Tokenizer.DedentId = `__DEDENT__${Date.now()}`;