@ibyar/expressions 0.3.8 → 0.5.0

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.
Files changed (164) hide show
  1. package/README.md +22 -12
  2. package/api/abstract.d.ts +20 -4
  3. package/api/abstract.js +54 -3
  4. package/api/abstract.js.map +1 -1
  5. package/api/app/class.d.ts +21 -11
  6. package/api/app/class.js +28 -10
  7. package/api/app/class.js.map +1 -1
  8. package/api/app/program.d.ts +6 -3
  9. package/api/app/program.js +7 -3
  10. package/api/app/program.js.map +1 -1
  11. package/api/computing/call.d.ts +5 -2
  12. package/api/computing/call.js +8 -2
  13. package/api/computing/call.js.map +1 -1
  14. package/api/computing/new.d.ts +5 -2
  15. package/api/computing/new.js +10 -2
  16. package/api/computing/new.js.map +1 -1
  17. package/api/computing/rest.d.ts +5 -2
  18. package/api/computing/rest.js +8 -2
  19. package/api/computing/rest.js.map +1 -1
  20. package/api/computing/return.d.ts +5 -2
  21. package/api/computing/return.js +8 -2
  22. package/api/computing/return.js.map +1 -1
  23. package/api/computing/spread.d.ts +5 -2
  24. package/api/computing/spread.js +8 -2
  25. package/api/computing/spread.js.map +1 -1
  26. package/api/computing/throw.d.ts +11 -4
  27. package/api/computing/throw.js +23 -6
  28. package/api/computing/throw.js.map +1 -1
  29. package/api/computing/yield.d.ts +18 -0
  30. package/api/computing/yield.js +51 -0
  31. package/api/computing/yield.js.map +1 -0
  32. package/api/definition/array.d.ts +10 -3
  33. package/api/definition/array.js +20 -4
  34. package/api/definition/array.js.map +1 -1
  35. package/api/definition/bind.d.ts +5 -2
  36. package/api/definition/bind.js +10 -9
  37. package/api/definition/bind.js.map +1 -1
  38. package/api/definition/comment.d.ts +5 -1
  39. package/api/definition/comment.js +6 -4
  40. package/api/definition/comment.js.map +1 -1
  41. package/api/definition/function.d.ts +26 -10
  42. package/api/definition/function.js +123 -54
  43. package/api/definition/function.js.map +1 -1
  44. package/api/definition/member.d.ts +5 -2
  45. package/api/definition/member.js +19 -7
  46. package/api/definition/member.js.map +1 -1
  47. package/api/definition/object.d.ts +14 -5
  48. package/api/definition/object.js +32 -6
  49. package/api/definition/object.js.map +1 -1
  50. package/api/definition/statement.d.ts +6 -2
  51. package/api/definition/statement.js +11 -2
  52. package/api/definition/statement.js.map +1 -1
  53. package/api/definition/values.d.ts +20 -7
  54. package/api/definition/values.js +37 -9
  55. package/api/definition/values.js.map +1 -1
  56. package/api/deserialize/deserialize.js +3 -3
  57. package/api/deserialize/deserialize.js.map +1 -1
  58. package/api/deserialize/type-store.d.ts +2 -0
  59. package/api/deserialize/type-store.js +2 -0
  60. package/api/deserialize/type-store.js.map +1 -0
  61. package/api/expression.d.ts +27 -5
  62. package/api/expression.js.map +1 -1
  63. package/api/index.d.ts +1 -0
  64. package/api/index.js +1 -0
  65. package/api/index.js.map +1 -1
  66. package/api/module/export.d.ts +7 -2
  67. package/api/module/export.js +15 -1
  68. package/api/module/export.js.map +1 -1
  69. package/api/module/import.d.ts +7 -2
  70. package/api/module/import.js +15 -1
  71. package/api/module/import.js.map +1 -1
  72. package/api/module/module.d.ts +6 -2
  73. package/api/module/module.js +11 -2
  74. package/api/module/module.js.map +1 -1
  75. package/api/operators/assignment.d.ts +2 -1
  76. package/api/operators/assignment.js +4 -0
  77. package/api/operators/assignment.js.map +1 -1
  78. package/api/operators/await.d.ts +6 -2
  79. package/api/operators/await.js +12 -3
  80. package/api/operators/await.js.map +1 -1
  81. package/api/operators/binary.d.ts +2 -1
  82. package/api/operators/binary.js +4 -0
  83. package/api/operators/binary.js.map +1 -1
  84. package/api/operators/chaining.d.ts +5 -2
  85. package/api/operators/chaining.js +9 -2
  86. package/api/operators/chaining.js.map +1 -1
  87. package/api/operators/comma.d.ts +6 -2
  88. package/api/operators/comma.js +11 -2
  89. package/api/operators/comma.js.map +1 -1
  90. package/api/operators/grouping.d.ts +6 -2
  91. package/api/operators/grouping.js +11 -2
  92. package/api/operators/grouping.js.map +1 -1
  93. package/api/operators/logical.d.ts +2 -1
  94. package/api/operators/logical.js +4 -0
  95. package/api/operators/logical.js.map +1 -1
  96. package/api/operators/pipeline.d.ts +6 -2
  97. package/api/operators/pipeline.js +21 -6
  98. package/api/operators/pipeline.js.map +1 -1
  99. package/api/operators/ternary.d.ts +6 -2
  100. package/api/operators/ternary.js +17 -2
  101. package/api/operators/ternary.js.map +1 -1
  102. package/api/operators/unary.d.ts +6 -2
  103. package/api/operators/unary.js +20 -5
  104. package/api/operators/unary.js.map +1 -1
  105. package/api/operators/update.d.ts +6 -2
  106. package/api/operators/update.js +11 -2
  107. package/api/operators/update.js.map +1 -1
  108. package/api/statement/control/block.d.ts +6 -2
  109. package/api/statement/control/block.js +11 -2
  110. package/api/statement/control/block.js.map +1 -1
  111. package/api/statement/control/empty.d.ts +5 -1
  112. package/api/statement/control/empty.js +5 -1
  113. package/api/statement/control/empty.js.map +1 -1
  114. package/api/statement/control/if.d.ts +6 -2
  115. package/api/statement/control/if.js +16 -2
  116. package/api/statement/control/if.js.map +1 -1
  117. package/api/statement/control/switch.d.ts +13 -3
  118. package/api/statement/control/switch.js +35 -9
  119. package/api/statement/control/switch.js.map +1 -1
  120. package/api/statement/control/terminate.d.ts +9 -4
  121. package/api/statement/control/terminate.js +11 -1
  122. package/api/statement/control/terminate.js.map +1 -1
  123. package/api/statement/declarations/declares.d.ts +10 -3
  124. package/api/statement/declarations/declares.js +25 -6
  125. package/api/statement/declarations/declares.js.map +1 -1
  126. package/api/statement/iterations/for.d.ts +18 -5
  127. package/api/statement/iterations/for.js +67 -8
  128. package/api/statement/iterations/for.js.map +1 -1
  129. package/api/statement/iterations/while.d.ts +10 -3
  130. package/api/statement/iterations/while.js +26 -4
  131. package/api/statement/iterations/while.js.map +1 -1
  132. package/index.d.ts +1 -0
  133. package/index.js +1 -0
  134. package/index.js.map +1 -1
  135. package/package.json +12 -4
  136. package/scope/event.d.ts +5 -0
  137. package/scope/event.js +41 -0
  138. package/scope/event.js.map +1 -0
  139. package/scope/index.d.ts +1 -0
  140. package/scope/index.js +1 -0
  141. package/scope/index.js.map +1 -1
  142. package/scope/proxy.d.ts +18 -6
  143. package/scope/proxy.js +57 -9
  144. package/scope/proxy.js.map +1 -1
  145. package/scope/scope.d.ts +71 -61
  146. package/scope/scope.js +104 -52
  147. package/scope/scope.js.map +1 -1
  148. package/scope/stack.d.ts +28 -28
  149. package/scope/stack.js.map +1 -1
  150. package/v8/nodes.d.ts +1 -1
  151. package/v8/parser.d.ts +2 -1
  152. package/v8/parser.js +16 -10
  153. package/v8/parser.js.map +1 -1
  154. package/v8/stream.d.ts +4 -2
  155. package/v8/stream.js +39 -17
  156. package/v8/stream.js.map +1 -1
  157. package/v8/token.d.ts +1 -1
  158. package/v8/token.js.map +1 -1
  159. package/visit/index.d.ts +1 -0
  160. package/visit/index.js +2 -0
  161. package/visit/index.js.map +1 -0
  162. package/visit/visitor.d.ts +11 -0
  163. package/visit/visitor.js +42 -0
  164. package/visit/visitor.js.map +1 -0
package/scope/scope.js CHANGED
@@ -35,7 +35,7 @@ export class Scope {
35
35
  return new Scope({}, 'module');
36
36
  }
37
37
  static globalScope() {
38
- return new this({}, 'global');
38
+ return new Scope({}, 'global');
39
39
  }
40
40
  get(propertyKey) {
41
41
  return Reflect.get(this.context, propertyKey);
@@ -46,22 +46,37 @@ export class Scope {
46
46
  has(propertyKey) {
47
47
  return propertyKey in this.context;
48
48
  }
49
+ delete(propertyKey) {
50
+ return Reflect.deleteProperty(this.context, propertyKey);
51
+ }
49
52
  getContext() {
50
53
  return this.context;
51
54
  }
52
55
  getScope(propertyKey) {
56
+ const scopeContext = this.get(propertyKey);
53
57
  let scope = this.scopeMap.get(propertyKey);
54
58
  if (scope) {
59
+ scope.context = scopeContext;
55
60
  return scope;
56
61
  }
57
- const scopeContext = this.get(propertyKey);
58
- if (typeof scopeContext === 'undefined') {
62
+ if (typeof scopeContext !== 'object') {
59
63
  return;
60
64
  }
61
65
  scope = new Scope(scopeContext, 'block');
62
66
  this.scopeMap.set(propertyKey, scope);
63
67
  return scope;
64
68
  }
69
+ getScopeOrCreat(propertyKey) {
70
+ const scopeContext = this.get(propertyKey);
71
+ let scope = this.scopeMap.get(propertyKey);
72
+ if (scope) {
73
+ scope.context = scopeContext;
74
+ return scope;
75
+ }
76
+ scope = new Scope(scopeContext, 'block');
77
+ this.scopeMap.set(propertyKey, scope);
78
+ return scope;
79
+ }
65
80
  }
66
81
  export class ReadOnlyScope extends Scope {
67
82
  static for(context, type) {
@@ -100,59 +115,74 @@ export class ReadOnlyScope extends Scope {
100
115
  set(propertyKey, value, receiver) {
101
116
  return false;
102
117
  }
118
+ delete(propertyKey) {
119
+ return false;
120
+ }
103
121
  }
104
- class Subscription {
105
- constructor(observer) {
122
+ export class ScopeSubscription {
123
+ constructor(propertyKey, observer) {
124
+ this.propertyKey = propertyKey;
106
125
  this.observer = observer;
107
126
  }
108
- add(subscription) {
109
- if (!this.othersSubscription) {
110
- this.othersSubscription = [];
111
- }
112
- this.othersSubscription.push(subscription);
113
- }
114
127
  unsubscribe() {
115
- this.observer.remove(this);
116
- if (this.othersSubscription) {
117
- this.othersSubscription.forEach((subscription) => {
118
- subscription.unsubscribe();
119
- });
120
- }
128
+ this.observer.unsubscribe(this.propertyKey, this);
121
129
  }
122
130
  }
123
131
  export class ValueChangeObserver {
124
- constructor(name) {
132
+ constructor() {
125
133
  this.subscribers = new Map();
134
+ this.propertiesLock = [];
126
135
  }
127
- emit(propertyKey, oldValue, newValue) {
128
- this.subscribers.forEach((subscribe) => {
136
+ emit(propertyKey, newValue, oldValue) {
137
+ if (this.propertiesLock.includes(propertyKey)) {
138
+ return;
139
+ }
140
+ const subscribers = this.subscribers.get(propertyKey);
141
+ if (!subscribers) {
142
+ return;
143
+ }
144
+ this.propertiesLock.push(propertyKey);
145
+ subscribers?.forEach((subscribe) => {
129
146
  try {
130
- subscribe(propertyKey, oldValue, newValue);
147
+ subscribe(newValue, oldValue);
131
148
  }
132
- catch (error) {
133
- console.error('error: handling event', error);
149
+ catch (e) {
150
+ console.error(e);
134
151
  }
135
152
  });
136
- }
137
- subscribe(callback) {
138
- const subscription = new Subscription(this);
139
- this.subscribers.set(subscription, callback);
153
+ if (this.propertiesLock.pop() !== propertyKey) {
154
+ console.error('lock error');
155
+ }
156
+ ;
157
+ }
158
+ subscribe(propertyKey, callback) {
159
+ const subscription = new ScopeSubscription(propertyKey, this);
160
+ let propertySubscribers = this.subscribers.get(propertyKey);
161
+ if (!propertySubscribers) {
162
+ propertySubscribers = new Map();
163
+ this.subscribers.set(propertyKey, propertySubscribers);
164
+ }
165
+ propertySubscribers.set(subscription, callback);
140
166
  return subscription;
141
167
  }
142
- remove(subscription) {
143
- this.subscribers.delete(subscription);
168
+ unsubscribe(propertyKey, subscription) {
169
+ if (subscription) {
170
+ this.subscribers.get(propertyKey)?.delete(subscription);
171
+ }
172
+ else {
173
+ this.subscribers.delete(propertyKey);
174
+ }
175
+ }
176
+ destroy() {
177
+ this.subscribers.clear();
144
178
  }
145
179
  }
146
180
  export class ReactiveScope extends Scope {
147
- constructor(context, type, name, observer) {
181
+ constructor(context, type, name, parent) {
148
182
  super(context, type);
149
183
  this.name = name;
150
- if (observer) {
151
- this.observer = observer;
152
- }
153
- else {
154
- this.observer = new ValueChangeObserver(name);
155
- }
184
+ this.parent = parent;
185
+ this.observer = new ValueChangeObserver();
156
186
  }
157
187
  static for(context, type) {
158
188
  return new ReactiveScope(context, type);
@@ -191,38 +221,60 @@ export class ReactiveScope extends Scope {
191
221
  const oldValue = Reflect.get(this.context, propertyKey);
192
222
  const result = Reflect.set(this.context, propertyKey, newValue);
193
223
  if (result) {
194
- this.observer?.emit(propertyKey, oldValue, newValue);
224
+ this.emit(propertyKey, newValue, oldValue);
195
225
  }
196
226
  return result;
197
227
  }
228
+ delete(propertyKey) {
229
+ const oldValue = Reflect.get(this.context, propertyKey);
230
+ const isDelete = Reflect.deleteProperty(this.context, propertyKey);
231
+ if (isDelete && oldValue !== undefined) {
232
+ this.emit(propertyKey, undefined, oldValue);
233
+ }
234
+ return isDelete;
235
+ }
198
236
  getScope(propertyKey) {
237
+ const scopeContext = this.get(propertyKey);
199
238
  let scope = this.scopeMap.get(propertyKey);
200
239
  if (scope) {
240
+ scope.context = scopeContext;
201
241
  return scope;
202
242
  }
203
- const scopeContext = this.get(propertyKey);
204
- if (typeof scopeContext === 'undefined') {
243
+ if (typeof scopeContext !== 'object') {
205
244
  return;
206
245
  }
207
- const childName = this.getEventName(propertyKey);
208
- scope = new ReactiveScope(scopeContext, 'block', childName, this.observer);
246
+ scope = new ReactiveScope(scopeContext, 'block', propertyKey, this);
209
247
  this.scopeMap.set(propertyKey, scope);
210
248
  return scope;
211
249
  }
212
- getEventName(child) {
213
- if (this.name) {
214
- if (typeof child === 'number' || typeof child === 'symbol') {
215
- return `${String(this.name)}['${String(child)}']`;
216
- }
217
- return `${String(this.name)}.${String(child)}`;
250
+ getScopeOrCreat(propertyKey) {
251
+ const scopeContext = this.get(propertyKey);
252
+ let scope = this.scopeMap.get(propertyKey);
253
+ if (scope) {
254
+ scope.context = scopeContext;
255
+ return scope;
218
256
  }
219
- return String(child);
257
+ scope = new ReactiveScope(scopeContext, 'block', propertyKey, this);
258
+ this.scopeMap.set(propertyKey, scope);
259
+ return scope;
260
+ }
261
+ emit(propertyKey, newValue, oldValue) {
262
+ this.observer.emit(propertyKey, newValue, oldValue);
263
+ this.parent?.emit(this.name, this.context);
220
264
  }
221
- subscribe(callback) {
222
- return this.observer.subscribe(callback);
265
+ subscribe(propertyKey, callback) {
266
+ return this.observer.subscribe(propertyKey, callback);
223
267
  }
224
- remove(subscription) {
225
- this.observer.remove(subscription);
268
+ unsubscribe(propertyKey, subscription) {
269
+ if (propertyKey && subscription) {
270
+ this.observer.unsubscribe(propertyKey, subscription);
271
+ }
272
+ else if (propertyKey) {
273
+ this.observer.unsubscribe(propertyKey);
274
+ }
275
+ else {
276
+ this.observer.destroy();
277
+ }
226
278
  }
227
279
  }
228
280
  //# sourceMappingURL=scope.js.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AAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC3D,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;aAClD;YACD,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;SAC/C;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED,SAAS,CAAC,QAA0E;QACnF,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,YAA6B;QACnC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC;CACD","sourcesContent":["\nexport type ScopeType = 'block' | 'function' | 'class' | 'module' | 'global';\n\nexport interface Scope<T> {\n\ttype: ScopeType;\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in current context, could be instilled with `value`.\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value?: any, receiver?: any): boolean;\n\n\t/**\n\t * is current context has `propertyKey` in hash map keys\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get current context object of this scope\n\t */\n\tgetContext(): T | undefined;\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tgetScope<V extends object>(propertyKey: PropertyKey): Scope<V> | undefined;\n}\n\nexport class Scope<T extends object> implements Scope<T> {\n\tstatic for<T extends object>(context: T, type: ScopeType) {\n\t\treturn new Scope(context, type);\n\t}\n\tstatic blockScopeFor<T extends object>(context: T) {\n\t\treturn new Scope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends object>(context: T) {\n\t\treturn new Scope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends object>(context: T) {\n\t\treturn new Scope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends object>(context: T) {\n\t\treturn new Scope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends object>(context: T) {\n\t\treturn new Scope(context, 'global');\n\t}\n\tstatic blockScope<T extends object>() {\n\t\treturn new Scope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends object>() {\n\t\treturn new Scope({} as T, 'function');\n\t}\n\tstatic classScope<T extends object>() {\n\t\treturn new Scope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends object>() {\n\t\treturn new Scope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends object>() {\n\t\treturn new this({} as T, 'global');\n\t}\n\tprotected scopeMap = new Map<PropertyKey, Scope<any>>();\n\tconstructor(protected context: T, public type: ScopeType) { }\n\tget(propertyKey: PropertyKey): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tgetContext(): T | undefined {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends object>(propertyKey: PropertyKey): Scope<V> | undefined {\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\treturn scope;\n\t\t}\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tif (typeof scopeContext === 'undefined') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends object> extends Scope<T> {\n\tstatic for<T extends object>(context: T, type: ScopeType) {\n\t\treturn new ReadOnlyScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends object>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends object>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends object>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends object>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends object>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'global');\n\t}\n\tstatic blockScope<T extends object>() {\n\t\treturn new ReadOnlyScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends object>() {\n\t\treturn new ReadOnlyScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends object>() {\n\t\treturn new ReadOnlyScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends object>() {\n\t\treturn new ReadOnlyScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends object>() {\n\t\treturn new ReadOnlyScope({} as T, 'global');\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n}\n\nclass Subscription<T> {\n\tprivate othersSubscription: Subscription<any>[];\n\tconstructor(private observer: ValueChangeObserver<T>) { }\n\tadd(subscription: Subscription<any>) {\n\t\tif (!this.othersSubscription) {\n\t\t\tthis.othersSubscription = [];\n\t\t}\n\t\tthis.othersSubscription.push(subscription);\n\t}\n\tunsubscribe(): void {\n\t\tthis.observer.remove(this);\n\t\tif (this.othersSubscription) {\n\t\t\tthis.othersSubscription.forEach((subscription) => {\n\t\t\t\tsubscription.unsubscribe();\n\t\t\t});\n\t\t}\n\t}\n}\n\nexport class ValueChangeObserver<T> {\n\tprivate subscribers: Map<Subscription<T>, (propertyKey: PropertyKey, oldValue: any, newValue: any) => void> = new Map();\n\tconstructor(name?: string) { }\n\temit(propertyKey: PropertyKey, oldValue: any, newValue: any): void {\n\t\tthis.subscribers.forEach((subscribe) => {\n\t\t\ttry {\n\t\t\t\tsubscribe(propertyKey, oldValue, newValue);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('error: handling event', error);\n\t\t\t}\n\t\t});\n\t}\n\tsubscribe(callback: (propertyKey: PropertyKey, oldValue: any, newValue: any) => void): Subscription<T> {\n\t\tconst subscription: Subscription<T> = new Subscription(this);\n\t\tthis.subscribers.set(subscription, callback);\n\t\treturn subscription;\n\t}\n\n\tremove(subscription: Subscription<T>) {\n\t\tthis.subscribers.delete(subscription);\n\t}\n}\n\n\nexport class ReactiveScope<T extends object> extends Scope<T> {\n\tstatic for<T extends object>(context: T, type: ScopeType) {\n\t\treturn new ReactiveScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends object>(context: T) {\n\t\treturn new ReactiveScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends object>(context: T) {\n\t\treturn new ReactiveScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends object>(context: T) {\n\t\treturn new ReactiveScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends object>(context: T) {\n\t\treturn new ReactiveScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends object>(context: T) {\n\t\treturn new ReactiveScope(context, 'global');\n\t}\n\tstatic blockScope<T extends object>() {\n\t\treturn new ReactiveScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends object>() {\n\t\treturn new ReactiveScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends object>() {\n\t\treturn new ReactiveScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends object>() {\n\t\treturn new ReactiveScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends object>() {\n\t\treturn new ReactiveScope({} as T, 'global');\n\t}\n\tprivate observer: ValueChangeObserver<T>;\n\tconstructor(context: T, type: ScopeType, protected name?: PropertyKey, observer?: ValueChangeObserver<T>) {\n\t\tsuper(context, type);\n\t\tif (observer) {\n\t\t\tthis.observer = observer;\n\t\t} else {\n\t\t\tthis.observer = new ValueChangeObserver(name as string);\n\t\t}\n\t}\n\tset(propertyKey: PropertyKey, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.observer?.emit(propertyKey, oldValue, newValue);\n\t\t}\n\t\treturn result;\n\t}\n\tgetScope<V extends object>(propertyKey: PropertyKey): ReactiveScope<V> | undefined {\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\treturn scope as ReactiveScope<V>;\n\t\t}\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tif (typeof scopeContext === 'undefined') {\n\t\t\treturn;\n\t\t}\n\t\tconst childName = this.getEventName(propertyKey);\n\t\tscope = new ReactiveScope(scopeContext, 'block', childName, this.observer);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope as ReactiveScope<V>;\n\t}\n\n\tprivate getEventName(child: PropertyKey): string {\n\t\tif (this.name) {\n\t\t\tif (typeof child === 'number' || typeof child === 'symbol') {\n\t\t\t\treturn `${String(this.name)}['${String(child)}']`;\n\t\t\t}\n\t\t\treturn `${String(this.name)}.${String(child)}`;\n\t\t}\n\t\treturn String(child);\n\t}\n\n\tsubscribe(callback: (propertyKey: PropertyKey, oldValue: any, newValue: any) => void): Subscription<T> {\n\t\treturn this.observer.subscribe(callback);\n\t}\n\n\tremove(subscription: Subscription<T>) {\n\t\tthis.observer.remove(subscription);\n\t}\n}\n"]}
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA2DA,MAAM,OAAO,KAAK;IAmCjB,YAAsB,OAAU,EAAS,IAAe;QAAlC,YAAO,GAAP,OAAO,CAAG;QAAS,SAAI,GAAJ,IAAI,CAAW;QAD9C,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IACQ,CAAC;IAlC7D,MAAM,CAAC,GAAG,CAAyB,OAAU,EAAE,IAAe;QAC7D,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,C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AAC,OAAO,GAAG,YAAY,CAAC;YAC7B,OAAO,KAAK,CAAC;SACb;QACD,KAAK,GAAG,IAAI,aAAa,CAAI,YAAY,EAAE,OAAO,EAAE,WAAqB,EAAE,IAAI,CAAC,CAAC;QACjF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,CAAC,WAAoB,EAAE,QAAa,EAAE,QAAc;QACvD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,SAAS,CAAC,WAAoB,EAAE,QAA8B;QAC7D,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACvD,CAAC;IAED,WAAW,CAAC,WAAqB,EAAE,YAAmC;QACrE,IAAI,WAAW,IAAI,YAAY,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;SACrD;aAAM,IAAI,WAAW,EAAE;YAEvB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;SACvC;aAAM;YACN,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;SACxB;IACF,CAAC;CACD","sourcesContent":["\nexport type ScopeType = 'block' | 'function' | 'class' | 'module' | 'global';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * scope type\n\t */\n\ttype: ScopeType;\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tget(propertyKey: keyof T): any;\n\n\t/**\n\t * set the value of `propertyKey` in current context, could be instilled with `value`.\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: keyof T, value?: any, receiver?: any): boolean;\n\n\t/**\n\t * is current context has `propertyKey` in hash map keys\n\t * @param propertyKey \n\t */\n\thas(propertyKey: keyof T): boolean;\n\n\t/**\n\t * delete property from context\n\t * @param propertyKey \n\t */\n\tdelete(propertyKey: keyof T): boolean;\n\n\t/**\n\t * get current context object of this scope\n\t */\n\tgetContext(): T;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if the current value is not type od `object`, will return `undefined`.\n\t * @param propertyKey the name of the property\n\t */\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if no scope found in the cache, will create a new one, add this one to the map, return a reference.\n\t * @param propertyKey\n\t */\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;\n}\n\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new Scope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'global');\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tconstructor(protected context: T, public type: ScopeType) { }\n\tget(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: keyof T): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this.context, propertyKey);\n\t}\n\tgetContext(): T {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V> {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReadOnlyScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'global');\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>,) { }\n\tunsubscribe(): void {\n\t\tthis.observer.unsubscribe(this.propertyKey, this);\n\t}\n}\n\nexport type ValueChangedCallback = (newValue: any, oldValue?: any) => void;\n\nexport class ValueChangeObserver<T> {\n\tprivate subscribers: Map<keyof T, Map<ScopeSubscription<T>, ValueChangedCallback>> = new Map();\n\tprivate propertiesLock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.propertiesLock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this.subscribers.get(propertyKey);\n\t\tif (!subscribers) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.push(propertyKey);\n\t\tsubscribers?.forEach((subscribe) => {\n\t\t\ttry {\n\t\t\t\tsubscribe(newValue, oldValue);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t}\n\t\t});\n\t\tif (this.propertiesLock.pop() !== propertyKey) {\n\t\t\tconsole.error('lock error');\n\t\t};\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\tconst subscription: ScopeSubscription<T> = new ScopeSubscription(propertyKey, this);\n\t\tlet propertySubscribers = this.subscribers.get(propertyKey);\n\t\tif (!propertySubscribers) {\n\t\t\tpropertySubscribers = new Map();\n\t\t\tthis.subscribers.set(propertyKey, propertySubscribers);\n\t\t}\n\t\tpropertySubscribers.set(subscription, callback);\n\t\treturn subscription;\n\t}\n\n\tunsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (subscription) {\n\t\t\tthis.subscribers.get(propertyKey)?.delete(subscription);\n\t\t} else {\n\t\t\tthis.subscribers.delete(propertyKey);\n\t\t}\n\t}\n\n\t/**\n\t * clear subscription map\n\t */\n\tdestroy() {\n\t\tthis.subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReactiveScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'global');\n\t}\n\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\n\tconstructor(context: T, type: ScopeType);\n\tconstructor(context: T, type: ScopeType, name: string, parent: ReactiveScope<any>);\n\tconstructor(context: T, type: ScopeType, protected name?: string, protected parent?: ReactiveScope<any>) {\n\t\tsuper(context, type);\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.emit(propertyKey, newValue, oldValue);\n\t\t}\n\t\treturn result;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this.context, propertyKey);\n\t\tif (isDelete && oldValue !== undefined) {\n\t\t\tthis.emit(propertyKey, undefined, oldValue);\n\t\t}\n\t\treturn isDelete;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, 'block', propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, 'block', propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tthis.observer.emit(propertyKey, newValue, oldValue);\n\t\tthis.parent?.emit(this.name!, this.context);\n\t}\n\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this.observer.subscribe(propertyKey, callback);\n\t}\n\n\tunsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (propertyKey && subscription) {\n\t\t\tthis.observer.unsubscribe(propertyKey, subscription);\n\t\t} else if (propertyKey) {\n\n\t\t\tthis.observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis.observer.destroy();\n\t\t}\n\t}\n}\n"]}
package/scope/stack.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { CanDeclareExpression } from '../api/expression.js';
2
- import { ReactiveScope, Scope, ScopeType } from './scope.js';
2
+ import { ReactiveScope, Scope, ScopeContext, ScopeType } from './scope.js';
3
3
  export interface AwaitPromiseInfo {
4
4
  promise: Promise<any>;
5
5
  node: CanDeclareExpression;
@@ -17,22 +17,22 @@ export interface Stack {
17
17
  get(propertyKey: PropertyKey): any;
18
18
  set(propertyKey: PropertyKey, value: any, receiver?: any): boolean;
19
19
  declareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any): any;
20
- findScope<T extends object>(propertyKey: PropertyKey): Scope<T>;
20
+ findScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;
21
21
  resolveAwait(value: AwaitPromiseInfo): void;
22
- lastScope<T extends object>(): Scope<T>;
23
- clearTo<T extends object>(scope: Scope<T>): boolean;
24
- clearTill<T extends object>(scope: Scope<T>): boolean;
25
- popScope<T extends object>(): Scope<T>;
26
- removeScope<T extends object>(scope: Scope<T>): void;
27
- pushScope<T extends object>(scope: Scope<T>): void;
28
- pushBlockScope<T extends object>(): Scope<T>;
29
- pushFunctionScope<T extends object>(): Scope<T>;
30
- pushBlockScopeFor<T extends object>(context: T): Scope<T>;
31
- pushFunctionScopeFor<T extends object>(context: T): Scope<T>;
32
- pushBlockReactiveScope<T extends object>(): ReactiveScope<T>;
33
- pushFunctionReactiveScope<T extends object>(): ReactiveScope<T>;
34
- pushBlockReactiveScopeFor<T extends object>(context: T): ReactiveScope<T>;
35
- pushFunctionReactiveScopeFor<T extends object>(context: T): ReactiveScope<T>;
22
+ lastScope<T extends ScopeContext>(): Scope<T>;
23
+ clearTo<T extends ScopeContext>(scope: Scope<T>): boolean;
24
+ clearTill<T extends ScopeContext>(scope: Scope<T>): boolean;
25
+ popScope<T extends ScopeContext>(): Scope<T>;
26
+ removeScope<T extends ScopeContext>(scope: Scope<T>): void;
27
+ pushScope<T extends ScopeContext>(scope: Scope<T>): void;
28
+ pushBlockScope<T extends ScopeContext>(): Scope<T>;
29
+ pushFunctionScope<T extends ScopeContext>(): Scope<T>;
30
+ pushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;
31
+ pushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T>;
32
+ pushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
33
+ pushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
34
+ pushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
35
+ pushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
36
36
  copyStack(): Stack;
37
37
  }
38
38
  export declare class Stack implements Stack {
@@ -42,16 +42,16 @@ export declare class Stack implements Stack {
42
42
  forAwaitAsyncIterable?: AsyncIterableInfo | undefined;
43
43
  protected readonly stack: Array<Scope<any>>;
44
44
  constructor(stack?: Array<Scope<any>>);
45
- pushClassScope<T extends object>(): Scope<T>;
46
- pushModuleScope<T extends object>(): Scope<T>;
47
- pushGlobalScope<T extends object>(): Scope<T>;
48
- pushClassScopeFor<T extends object>(context: T): Scope<T>;
49
- pushModuleScopeFor<T extends object>(context: T): Scope<T>;
50
- pushGlobalScopeFor<T extends object>(context: T): Scope<T>;
51
- pushClassReactiveScope<T extends object>(): Scope<T>;
52
- pushModuleReactiveScope<T extends object>(): Scope<T>;
53
- pushGlobalReactiveScope<T extends object>(): Scope<T>;
54
- pushClassReactiveScopeFor<T extends object>(context: T): Scope<T>;
55
- pushModuleReactiveScopeFor<T extends object>(context: T): Scope<T>;
56
- pushGlobalReactiveScopeFor<T extends object>(context: T): Scope<T>;
45
+ pushClassScope<T extends ScopeContext>(): Scope<T>;
46
+ pushModuleScope<T extends ScopeContext>(): Scope<T>;
47
+ pushGlobalScope<T extends ScopeContext>(): Scope<T>;
48
+ pushClassScopeFor<T extends ScopeContext>(context: T): Scope<T>;
49
+ pushModuleScopeFor<T extends ScopeContext>(context: T): Scope<T>;
50
+ pushGlobalScopeFor<T extends ScopeContext>(context: T): Scope<T>;
51
+ pushClassReactiveScope<T extends ScopeContext>(): Scope<T>;
52
+ pushModuleReactiveScope<T extends ScopeContext>(): Scope<T>;
53
+ pushGlobalReactiveScope<T extends ScopeContext>(): Scope<T>;
54
+ pushClassReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
55
+ pushModuleReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
56
+ pushGlobalReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
57
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAa,MAAM,YAAY,CAAC;AAuH7D,MAA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AC,CAAC,EAAE;YACjB,OAAO,KAAK,CAAC;SACb;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,SAAS,CAAmB,KAAe;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACjB,OAAO,KAAK,CAAC;SACb;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,SAAS;QACR,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC;CACD","sourcesContent":["import type { CanDeclareExpression } from '../api/expression.js';\nimport { ReactiveScope, Scope, ScopeType } from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: CanDeclareExpression;\n\n\tdeclareVariable: boolean;\n\tscopeType: ScopeType;\n}\n\nexport interface AsyncIterableInfo {\n\titerable: AsyncIterable<any>;\n\tforAwaitBody: (iterator: any) => any;\n}\n\nexport interface Stack {\n\t/**\n\t * a list of promises to resolve in an 'async' scope as 'async function'\n\t */\n\tawaitPromise: Array<AwaitPromiseInfo>;\n\n\t/**\n\t * resolve await promise in 'await for in' scope\n\t */\n\tforAwaitAsyncIterable?: AsyncIterableInfo;\n\n\t/**\n\t * is this stack has a propertyKey\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get the first value for provided property key,\n\t * \n\t * will search current stack in all scope till find the first key, else undefined\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in its context provider with `value`.\n\t * else define it in the first scope 'local scope'\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean;\n\n\t/**\n\t * declare variable in stack by scope type,\n\t * \n\t * 'block' for the first scop ==> may be 'block' or 'function' scope\n\t * \n\t * 'function' will search for the first scope with scope type 'function'\n\t * then define a property key with 'initial' value in thus scope\n\t * @param scopeType \"function\" | \"block\"\n\t * @param propertyKey the name of property mey be string | number | symbol, \n\t * @param propertyValue if not exist will be initialize with 'undefined' value\n\t */\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any): any;\n\n\n\t/**\n\t * get context object of this provider,\n\t * search for the first context object that has `propertyKey`.\n\t * \n\t * search for the first context that have property key,\n\t * if not found will return the stack local scop as a default value\n\t * @param propertyKey the property key\n\t */\n\tfindScope<T extends object>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends object>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends object>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends object>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends object>(): Scope<T>;\n\n\tremoveScope<T extends object>(scope: Scope<T>): void;\n\n\tpushScope<T extends object>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends object>(): Scope<T>;\n\n\tpushFunctionScope<T extends object>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends object>(context: T): Scope<T>;\n\n\tpushFunctionScopeFor<T extends object>(context: T): Scope<T>;\n\n\n\tpushBlockReactiveScope<T extends object>(): ReactiveScope<T>;\n\n\tpushFunctionReactiveScope<T extends object>(): ReactiveScope<T>;\n\n\tpushBlockReactiveScopeFor<T extends object>(context: T): ReactiveScope<T>;\n\n\tpushFunctionReactiveScopeFor<T extends object>(context: T): ReactiveScope<T>;\n\n\tcopyStack(): Stack;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Scope<any>[]): Stack {\n\t\tif (contexts.length === 0) {\n\t\t\treturn new Stack();\n\t\t}\n\t\treturn new Stack(contexts.map(context => new Scope(context, 'global')));\n\t}\n\tstatic forScopes(...scopes: Scope<any>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.functionScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tawaitPromise: AwaitPromiseInfo[];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\n\tconstructor(stack?: Array<Scope<any>>) {\n\t\tthis.stack = stack ?? [Scope.functionScope()];\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn this.stack.find(context => context.has(propertyKey)) ? true : false;\n\t}\n\tget(propertyKey: PropertyKey) {\n\t\treturn this.findScope(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any) {\n\t\tif (scopeType === 'block') {\n\t\t\treturn this.lastScope().set(propertyKey, propertyValue);\n\t\t}\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.type === scopeType) {\n\t\t\t\tscope.set(propertyKey, propertyValue);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tfindScope<T extends object>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends object>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends object>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends object>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends object>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScope<T extends object>(): Scope<T> {\n\t\tconst scope = Scope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScope<T extends object>(): Scope<T> {\n\t\tconst scope = Scope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScope<T extends object>(): Scope<T> {\n\t\tconst scope = Scope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScope<T extends object>(): Scope<T> {\n\t\tconst scope = Scope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = Scope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = Scope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = Scope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = Scope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = Scope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScope<T extends object>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScope<T extends object>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScope<T extends object>(): Scope<T> {\n\t\tconst scope = ReactiveScope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScope<T extends object>(): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScope<T extends object>(): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScopeFor<T extends object>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScopeFor<T extends object>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScopeFor<T extends object>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends object>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends object>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends object>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice());\n\t}\n}\n"]}
1
+ {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,EAA2B,MAAM,YAAY,CAAC;AAuH3E,MAAM,OAAO,KAAK;IAkBjB,YAAY,KAAyB;QACpC,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC/C,CAAC;IAnBD,MAAM,CAAC,GAAG,CAAC,GAAG,QAAsB;QACnC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YAC1B,OAAO,IAAI,KAAK,EAAE,CAAC;SACnB;QACD,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAoB;QACvC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;SACnC;QACD,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IASD,GAAG,CAAC,WAAwB;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO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KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;IACd,CAAC;IACD,0BAA0B,CAAyB,OAAU;QAC5D,MAAM,KAAK,GAAG,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;IACd,CAAC;IACD,SAAS;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,CAAyB,KAAe;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACjB,OAAO,KAAK,CAAC;SACb;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,SAAS,CAAyB,KAAe;QAChD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACjB,OAAO,KAAK,CAAC;SACb;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,SAAS;QACR,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC;CACD","sourcesContent":["import type { CanDeclareExpression } from '../api/expression.js';\nimport { ReactiveScope, Scope, ScopeContext, ScopeType } from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: CanDeclareExpression;\n\n\tdeclareVariable: boolean;\n\tscopeType: ScopeType;\n}\n\nexport interface AsyncIterableInfo {\n\titerable: AsyncIterable<any>;\n\tforAwaitBody: (iterator: any) => any;\n}\n\nexport interface Stack {\n\t/**\n\t * a list of promises to resolve in an 'async' scope as 'async function'\n\t */\n\tawaitPromise: Array<AwaitPromiseInfo>;\n\n\t/**\n\t * resolve await promise in 'await for in' scope\n\t */\n\tforAwaitAsyncIterable?: AsyncIterableInfo;\n\n\t/**\n\t * is this stack has a propertyKey\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get the first value for provided property key,\n\t * \n\t * will search current stack in all scope till find the first key, else undefined\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in its context provider with `value`.\n\t * else define it in the first scope 'local scope'\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean;\n\n\t/**\n\t * declare variable in stack by scope type,\n\t * \n\t * 'block' for the first scop ==> may be 'block' or 'function' scope\n\t * \n\t * 'function' will search for the first scope with scope type 'function'\n\t * then define a property key with 'initial' value in thus scope\n\t * @param scopeType \"function\" | \"block\"\n\t * @param propertyKey the name of property mey be string | number | symbol, \n\t * @param propertyValue if not exist will be initialize with 'undefined' value\n\t */\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any): any;\n\n\n\t/**\n\t * get context object of this provider,\n\t * search for the first context object that has `propertyKey`.\n\t * \n\t * search for the first context that have property key,\n\t * if not found will return the stack local scop as a default value\n\t * @param propertyKey the property key\n\t */\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends ScopeContext>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends ScopeContext>(): Scope<T>;\n\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushFunctionScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\tpushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\n\tpushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\tpushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\tcopyStack(): Stack;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Scope<any>[]): Stack {\n\t\tif (contexts.length === 0) {\n\t\t\treturn new Stack();\n\t\t}\n\t\treturn new Stack(contexts.map(context => new Scope(context, 'global')));\n\t}\n\tstatic forScopes(...scopes: Scope<any>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.functionScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tawaitPromise: AwaitPromiseInfo[];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\n\tconstructor(stack?: Array<Scope<any>>) {\n\t\tthis.stack = stack ?? [Scope.functionScope()];\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn this.stack.find(context => context.has(propertyKey)) ? true : false;\n\t}\n\tget(propertyKey: PropertyKey) {\n\t\treturn this.findScope<ScopeContext>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<ScopeContext>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any) {\n\t\tif (scopeType === 'block') {\n\t\t\treturn this.lastScope<ScopeContext>().set(propertyKey, propertyValue);\n\t\t}\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.type === scopeType) {\n\t\t\t\tscope.set(propertyKey, propertyValue);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice());\n\t}\n}\n"]}
package/v8/nodes.d.ts CHANGED
@@ -10,4 +10,4 @@ export declare function shortcutNumericLiteralBinaryExpression(x: ExpressionNode
10
10
  export declare function coverValue(value: any): false | StringLiteral | NumberLiteral | BigIntLiteral | BooleanLiteral | import("../api/definition/values.js").NullishLiteral;
11
11
  export declare function buildUnaryExpression(expression: ExpressionNode, op: Token): ExpressionNode;
12
12
  export declare function buildPostfixExpression(expression: ExpressionNode, op: Token): ExpressionNode;
13
- export declare function expressionFromLiteral(te: TokenExpression): ExpressionNode;
13
+ export declare function expressionFromLiteral(te: TokenExpression): ExpressionNode | BooleanLiteral | import("../api/definition/values.js").NullishLiteral;
package/v8/parser.d.ts CHANGED
@@ -82,7 +82,7 @@ export declare abstract class AbstractParser {
82
82
  protected errorMessage(message: string): string;
83
83
  }
84
84
  export declare class JavaScriptParser extends AbstractParser {
85
- static parse(app: string): ExpressionNode;
85
+ static parse(source: string | TokenExpression[] | TokenStream): ExpressionNode;
86
86
  scan(): ExpressionNode;
87
87
  protected parseStatement(): ExpressionNode;
88
88
  protected parseTryStatement(): ExpressionNode;
@@ -109,6 +109,7 @@ export declare class JavaScriptParser extends AbstractParser {
109
109
  protected parseIdentifier(): ExpressionNode | undefined;
110
110
  protected getIdentifier(): ExpressionNode;
111
111
  protected parseFunctionLiteral(flag: FunctionKind, name?: ExpressionNode): ExpressionNode;
112
+ protected parseArrowFunctionBody(): ExpressionNode | ExpressionNode[];
112
113
  protected parseFunctionBody(): ExpressionNode[];
113
114
  protected parseStatementList(endToken: Token): ExpressionNode[];
114
115
  protected parseFormalParameterList(functionInfo: FunctionInfo): ExpressionNode[];
package/v8/parser.js CHANGED
@@ -20,6 +20,7 @@ import { CatchClauseNode, ThrowStatement, TryCatchNode } from '../api/computing/
20
20
  import { SwitchCase, DefaultExpression, SwitchStatement } from '../api/statement/control/switch.js';
21
21
  import { BreakStatement, ContinueStatement } from '../api/statement/control/terminate.js';
22
22
  import { ReturnStatement } from '../api/computing/return.js';
23
+ import { YieldExpression } from '../api/computing/yield.js';
23
24
  import { VariableNode, VariableDeclarationNode } from '../api/statement/declarations/declares.js';
24
25
  import { ForNode, ForOfNode, ForInNode, ForAwaitOfNode } from '../api/statement/iterations/for.js';
25
26
  import { ConditionalExpression } from '../api/operators/ternary.js';
@@ -250,8 +251,10 @@ export class AbstractParser {
250
251
  }
251
252
  }
252
253
  export class JavaScriptParser extends AbstractParser {
253
- static parse(app) {
254
- const stream = TokenStream.getTokenStream(app);
254
+ static parse(source) {
255
+ const stream = (typeof source === 'string' || Array.isArray(source))
256
+ ? TokenStream.getTokenStream(source)
257
+ : source;
255
258
  const parser = new JavaScriptParser(stream);
256
259
  return parser.scan();
257
260
  }
@@ -757,19 +760,22 @@ export class JavaScriptParser extends AbstractParser {
757
760
  }
758
761
  return new FunctionExpression(formals, body, flag, name, functionInfo.rest);
759
762
  }
760
- parseFunctionBody() {
763
+ parseArrowFunctionBody() {
761
764
  const isExpression = this.peek().isNotType(Token.L_CURLY);
762
765
  if (isExpression) {
763
766
  const expression = this.parseAssignmentExpression();
764
- return [expression];
767
+ return expression;
765
768
  }
766
769
  else {
767
- this.expect(Token.L_CURLY);
768
- const list = this.parseStatementList(Token.R_CURLY);
769
- this.expect(Token.R_CURLY);
770
- return list;
770
+ return this.parseFunctionBody();
771
771
  }
772
772
  }
773
+ parseFunctionBody() {
774
+ this.expect(Token.L_CURLY);
775
+ const list = this.parseStatementList(Token.R_CURLY);
776
+ this.expect(Token.R_CURLY);
777
+ return list;
778
+ }
773
779
  parseStatementList(endToken) {
774
780
  const list = [];
775
781
  while (this.peek().isNotType(endToken)) {
@@ -1101,7 +1107,7 @@ export class JavaScriptParser extends AbstractParser {
1101
1107
  }
1102
1108
  parseArrowFunctionLiteral(parameters, flag, rest) {
1103
1109
  this.consume(Token.ARROW);
1104
- const body = this.parseFunctionBody();
1110
+ const body = this.parseArrowFunctionBody();
1105
1111
  return new ArrowFunctionExpression(parameters, body, flag, rest);
1106
1112
  }
1107
1113
  parseRegExpLiteral() {
@@ -1689,7 +1695,7 @@ export class JavaScriptParser extends AbstractParser {
1689
1695
  expression = this.parseAssignmentExpressionCoverGrammar();
1690
1696
  break;
1691
1697
  }
1692
- throw new Error(this.errorMessage(`Yield expression is not supported now.`));
1698
+ return new YieldExpression(delegating, expression);
1693
1699
  }
1694
1700
  parseNewTargetExpression() {
1695
1701
  throw new Error(this.errorMessage('Expression (new.target) not supported.'));