@ibyar/expressions 2.5.0 → 3.1.1

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/scope/signal.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { skipChangeDetection } from './cd.js';
1
2
  import { ReactiveScope } from './scope.js';
2
3
  function compute(updateFn) {
3
4
  try {
@@ -16,30 +17,20 @@ export class SignalScope extends ReactiveScope {
16
17
  constructor() {
17
18
  super([]);
18
19
  }
19
- createSignal(initValue, signalType = Signal) {
20
- const signal = new signalType(this, this.getContext().length, initValue);
21
- signalType.bindNode(signal);
22
- return signal;
20
+ getNextKey() {
21
+ return this.getContext().length;
23
22
  }
24
- createSignalFn(initValue, signalType = Signal) {
25
- const signal = new signalType(this, this.getContext().length, initValue);
26
- return signalType.toReactiveSignal(signal);
23
+ createSignal(initValue) {
24
+ return new Signal(this, this.getContext().length, initValue);
27
25
  }
28
26
  createLazy(updateFn) {
29
- const lazy = new Lazy(this, this.getContext().length, updateFn);
30
- Lazy.bindNode(lazy);
31
- return lazy;
32
- }
33
- createLazyFn(updateFn) {
34
- const lazy = new Lazy(this, this.getContext().length, updateFn);
35
- return Lazy.toReactiveSignal(lazy);
27
+ return new Lazy(this, this.getContext().length, updateFn);
36
28
  }
37
29
  createComputed(updateFn) {
38
30
  const index = this.getContext().length;
39
31
  this.watchState();
40
32
  const value = compute(updateFn);
41
33
  const computed = new Computed(this, index, value);
42
- Computed.bindNode(computed);
43
34
  const observeComputed = () => {
44
35
  this.watchState();
45
36
  const value = compute(updateFn);
@@ -58,10 +49,6 @@ export class SignalScope extends ReactiveScope {
58
49
  this.restoreState();
59
50
  return computed;
60
51
  }
61
- createComputedFn(updateFn) {
62
- const computed = this.createComputed(updateFn);
63
- return Computed.toReactiveSignal(computed);
64
- }
65
52
  createEffect(effectFn) {
66
53
  let cleanupFn;
67
54
  let isCleanupRegistered = false;
@@ -131,45 +118,25 @@ export class SignalScope extends ReactiveScope {
131
118
  export class ReactiveNode {
132
119
  scope;
133
120
  index;
134
- static bindNode(instance) {
135
- instance.get = instance.get.bind(instance);
136
- }
137
- static toReactiveSignal(instance) {
138
- const fn = () => instance.get();
139
- fn[SIGNAL] = instance;
140
- return fn;
141
- }
142
121
  constructor(scope, index) {
143
122
  this.scope = scope;
144
123
  this.index = index;
124
+ skipChangeDetection(this);
145
125
  }
146
126
  get() {
147
127
  this.scope.observeIndex(this.index);
148
128
  return this.scope.get(this.index);
149
129
  }
150
130
  getScope() {
151
- this.scope;
131
+ return this.scope;
152
132
  }
153
133
  getIndex() {
154
- this.index;
134
+ return this.index;
155
135
  }
156
136
  subscribe(callback) {
157
137
  return this.scope.subscribe(this.index, callback);
158
138
  }
159
139
  }
160
- const SIGNAL = Symbol('Signal');
161
- export function isReactive(value) {
162
- const node = value?.[SIGNAL];
163
- return node !== undefined && node instanceof ReactiveNode;
164
- }
165
- export function getReactiveNode(value) {
166
- if (value instanceof ReactiveNode) {
167
- return value;
168
- }
169
- else if (isReactive(value)) {
170
- return value[SIGNAL];
171
- }
172
- }
173
140
  export class Computed extends ReactiveNode {
174
141
  constructor(scope, index, initValue) {
175
142
  super(scope, index);
@@ -190,18 +157,6 @@ export class Lazy extends ReactiveNode {
190
157
  }
191
158
  }
192
159
  export class Signal extends ReactiveNode {
193
- static bindNode(signal) {
194
- signal.get = signal.get.bind(signal);
195
- signal.set = signal.set.bind(signal);
196
- signal.update = signal.update.bind(signal);
197
- }
198
- static toReactiveSignal(signal) {
199
- const fn = () => signal.get();
200
- fn.set = (value) => signal.set(value);
201
- fn.update = (updateFn) => signal.update(updateFn);
202
- fn[SIGNAL] = signal;
203
- return fn;
204
- }
205
160
  constructor(scope, index, initValue) {
206
161
  super(scope, index);
207
162
  scope.set(index, initValue);
@@ -213,23 +168,24 @@ export class Signal extends ReactiveNode {
213
168
  this.set(updateFn(this.get()));
214
169
  }
215
170
  asReadonly() {
216
- return ReadOnlySignal.toReactiveSignal(new ReadOnlySignal(this.scope, this.index));
217
- }
218
- asReadonlyNode() {
219
- const node = new ReadOnlySignal(this.scope, this.index);
220
- ReadOnlySignal.bindNode(node);
221
- return node;
171
+ return new ReadOnlySignal(this.scope, this.index);
222
172
  }
223
173
  }
224
174
  export class ReadOnlySignal extends ReactiveNode {
225
175
  }
226
- export class SignalValueScope extends ReactiveScope {
227
- constructor() {
228
- super({});
229
- }
230
- watchSignal(propertyKey, node) {
231
- this.set(propertyKey, node.get());
232
- return node.subscribe(value => this.set(propertyKey, value));
233
- }
176
+ export function isSignal(signal) {
177
+ return signal instanceof Signal;
178
+ }
179
+ export function isComputed(signal) {
180
+ return signal instanceof Computed;
181
+ }
182
+ export function isLazy(signal) {
183
+ return signal instanceof Lazy;
184
+ }
185
+ export function isReadOnlySignal(signal) {
186
+ return signal instanceof ReadOnlySignal;
187
+ }
188
+ export function isReactive(signal) {
189
+ return signal instanceof ReactiveNode;
234
190
  }
235
191
  //# sourceMappingURL=signal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signal.js","sourceRoot":"","sources":["../../../src/expressions/scope/signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAwB,MAAM,YAAY,CAAC;AAKjE,SAAS,OAAO,CAAI,QAAiB;IACpC,IAAI,CAAC;QACJ,OAAO,QAAQ,EAAE,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED,MAAM,OAAO,WAAY,SAAQ,aAAyB;IAEzD,MAAM,CAAC,MAAM;QACZ,OAAO,IAAI,WAAW,EAAE,CAAC;IAC1B,CAAC;IAEO,KAAK,GAAe,EAAE,CAAC;IACvB,KAAK,GAAG,IAAI,CAAC;IAErB;QACC,KAAK,CAAC,EAAE,CAAC,CAAC;IACX,CAAC;IAED,YAAY,CAAgC,SAAa,EAAE,aAAa,MAAW;QAClF,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,IAAI,CAA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angedCallback } from './scope.js';\n\ntype CleanupFn = () => void;\ntype CleanupRegister = (cleanupFn?: CleanupFn) => void;\n\nfunction compute<T>(updateFn: () => T): T | unknown {\n\ttry {\n\t\treturn updateFn();\n\t} catch (error) {\n\t\treturn error;\n\t}\n}\n\nexport class SignalScope extends ReactiveScope<Array<any>> {\n\n\tstatic create() {\n\t\treturn new SignalScope();\n\t}\n\n\tprivate state: number[][] = [];\n\tprivate watch = true;\n\n\tconstructor() {\n\t\tsuper([]);\n\t}\n\n\tcreateSignal<T, S extends typeof Signal<T>>(initValue?: T, signalType = Signal as S): InstanceType<S> {\n\t\tconst signal = new signalType(this, this.getContext().length, initValue) as InstanceType<S>;\n\t\tsignalType.bindNode(signal);\n\t\treturn signal;\n\t}\n\n\tcreateSignalFn<T, S extends typeof Signal<T>>(initValue: T, signalType = Signal as S) {\n\t\tconst signal = new signalType(this, this.getContext().length, initValue);\n\t\treturn signalType.toReactiveSignal(signal);\n\t}\n\n\tcreateLazy<T>(updateFn: () => T): Lazy<T> {\n\t\tconst lazy = new Lazy<T>(this, this.getContext().length, updateFn);\n\t\tLazy.bindNode(lazy);\n\t\treturn lazy;\n\t}\n\n\tcreateLazyFn<T>(updateFn: () => T) {\n\t\tconst lazy = new Lazy<T>(this, this.getContext().length, updateFn);\n\t\treturn Lazy.toReactiveSignal(lazy);\n\t}\n\n\tcreateComputed<T>(updateFn: () => T): Computed<T> {\n\t\tconst index = this.getContext().length;\n\t\tthis.watchState();\n\t\tconst value = compute(updateFn);\n\t\tconst computed = new Computed<T>(this, index, value as T);\n\t\tComputed.bindNode(computed);\n\t\tconst observeComputed = () => {\n\t\t\tthis.watchState();\n\t\t\tconst value = compute(updateFn);\n\t\t\tconst state = this.readState();\n\t\t\tthis.restoreState();\n\t\t\tObject.keys(subscriptions)\n\t\t\t\t.filter(index => !state.includes(+index))\n\t\t\t\t.forEach(index => subscriptions[index].pause());\n\t\t\tstate.forEach(index => {\n\t\t\t\tsubscriptions[index]?.resume();\n\t\t\t\tsubscriptions[index] ??= this.subscribe(index, observeComputed);\n\t\t\t});\n\t\t\tthis.set(index, value);\n\t\t};\n\t\tconst subscriptions = this.observeState(observeComputed);\n\t\tthis.restoreState();\n\t\treturn computed;\n\t}\n\n\tcreateComputedFn<T>(updateFn: () => T) {\n\t\tconst computed = this.createComputed(updateFn);\n\t\treturn Computed.toReactiveSignal(computed);\n\t}\n\n\tcreateEffect(effectFn: (onCleanup?: CleanupFn) => void): { destroy(): void } {\n\t\tlet cleanupFn: (() => void) | undefined;\n\t\tlet isCleanupRegistered = false;\n\t\tconst cleanupRegister: CleanupRegister = onClean => {\n\t\t\tcleanupFn = onClean;\n\t\t\tisCleanupRegistered = true;\n\t\t};\n\t\tconst callback = () => {\n\t\t\tisCleanupRegistered = false;\n\t\t\tconst error = compute(() => effectFn(cleanupRegister)) as any;\n\t\t\tif (error instanceof Error) {\n\t\t\t\tconsole.error(error);\n\t\t\t}\n\t\t\tif (!isCleanupRegistered) {\n\t\t\t\tcleanupFn = undefined;\n\t\t\t}\n\t\t};\n\t\tthis.watchState();\n\t\tcallback();\n\t\tconst observeComputed = () => {\n\t\t\tcleanupFn?.();\n\t\t\tthis.watchState();\n\t\t\tcallback();\n\t\t\tconst state = this.readState();\n\t\t\tthis.restoreState();\n\t\t\tObject.keys(subscriptions)\n\t\t\t\t.filter(index => !state.includes(+index))\n\t\t\t\t.forEach(index => subscriptions[index].pause());\n\t\t\tstate.forEach(index => {\n\t\t\t\tsubscriptions[index]?.resume();\n\t\t\t\tsubscriptions[index] ??= this.subscribe(index, observeComputed);\n\t\t\t});\n\t\t};\n\t\tconst subscriptions = this.observeState(observeComputed);\n\t\tthis.restoreState();\n\t\treturn {\n\t\t\tdestroy: () => {\n\t\t\t\tObject.values(subscriptions).forEach(sub => sub.unsubscribe());\n\t\t\t\tcleanupFn?.();\n\t\t\t},\n\t\t};\n\t}\n\n\twatchState() {\n\t\tthis.state.push([]);\n\t}\n\n\tuntrack() {\n\t\tthis.watch = false;\n\t}\n\n\tobserveIndex(index: number) {\n\t\tif (this.watch) {\n\t\t\tthis.state.at(-1)?.push(index);\n\t\t}\n\t}\n\n\ttrack() {\n\t\tthis.watch = true;\n\t}\n\n\treadState() {\n\t\treturn this.state.at(-1) ?? [];\n\t}\n\n\tobserveState(updateFn: () => void) {\n\t\treturn Object.fromEntries(this.readState().map(index => [index, this.subscribe(index, updateFn)]));\n\t}\n\n\trestoreState() {\n\t\tthis.state.pop();\n\t}\n\n}\n\nexport abstract class ReactiveNode<T> {\n\n\tstatic bindNode<T>(instance: ReactiveNode<T>) {\n\t\tinstance.get = instance.get.bind(instance);\n\t}\n\n\tstatic toReactiveSignal<T>(instance: ReadOnlySignal<T>): ReactiveSignal<T> {\n\t\tconst fn = () => instance.get();\n\t\tfn[SIGNAL] = instance;\n\t\treturn fn as ReactiveSignal<T>;\n\t}\n\n\tconstructor(protected scope: SignalScope, protected index: number) { }\n\n\tget(): T {\n\t\tthis.scope.observeIndex(this.index);\n\t\treturn this.scope.get(this.index);\n\t}\n\n\tgetScope() {\n\t\tthis.scope;\n\t}\n\n\tgetIndex() {\n\t\tthis.index;\n\t}\n\n\tsubscribe(callback: ValueChangedCallback) {\n\t\treturn this.scope.subscribe(this.index, callback);\n\t}\n\n}\n\nconst SIGNAL = Symbol('Signal');\n\nexport interface Reactive<T> {\n\t[SIGNAL]: ReactiveNode<T>;\n}\n\nexport function isReactive<T = any>(value: unknown): value is Reactive<T> {\n\tconst node = (value as Partial<Reactive<T>>)?.[SIGNAL];\n\treturn node !== undefined && node instanceof ReactiveNode;\n}\n\nexport function getReactiveNode<T = any>(value: unknown): ReactiveNode<T> | void {\n\tif (value instanceof ReactiveNode) {\n\t\treturn value;\n\t} else if (isReactive(value)) {\n\t\treturn value[SIGNAL];\n\t}\n}\n\nexport type ReactiveSignal<T> = (() => T) & {\n\t/**\n\t * original node that can access value from scope\n\t */\n\t[SIGNAL]: unknown;\n};\n\nexport class Computed<T> extends ReactiveNode<T> {\n\n\tconstructor(scope: SignalScope, index: number, initValue: T) {\n\t\tsuper(scope, index);\n\t\tscope.set(index, initValue);\n\t}\n\n}\n\nexport class Lazy<T> extends ReactiveNode<T> {\n\n\tprivate updateFn: () => T;\n\n\tconstructor(scope: SignalScope, index: number, updateFn: () => T) {\n\t\tsuper(scope, index);\n\t\tthis.updateFn = updateFn;\n\t\tscope.set(index, compute(updateFn) as T);\n\t}\n\n\toverride get(): T {\n\t\tconst value = compute(this.updateFn);\n\t\tthis.scope.set(this.index, value);\n\t\treturn super.get();\n\t}\n\n}\n\nexport type WritableSignal<T> = ReactiveSignal<T> & {\n\tset(value: T): void;\n\tupdate(updateFn: (value: T) => T): void;\n};\n\nexport class Signal<T> extends ReactiveNode<T> {\n\n\tstatic bindNode<T>(signal: Signal<T>) {\n\t\tsignal.get = signal.get.bind(signal);\n\t\tsignal.set = signal.set.bind(signal);\n\t\tsignal.update = signal.update.bind(signal);\n\t}\n\n\tstatic toReactiveSignal<T>(signal: Signal<T>): WritableSignal<T> {\n\t\tconst fn = () => signal.get();\n\t\tfn.set = (value: T) => signal.set(value);\n\t\tfn.update = (updateFn: (value: T) => T) => signal.update(updateFn);\n\t\tfn[SIGNAL] = signal;\n\t\treturn fn as WritableSignal<T>;\n\t}\n\n\tconstructor(scope: SignalScope, index: number, initValue?: T) {\n\t\tsuper(scope, index);\n\t\tscope.set(index, initValue);\n\t}\n\n\tset(value: T) {\n\t\tthis.scope.set(this.index, value);\n\t}\n\n\tupdate(updateFn: (value: T) => T): void {\n\t\tthis.set(updateFn(this.get()));\n\t}\n\n\tasReadonly() {\n\t\treturn ReadOnlySignal.toReactiveSignal(new ReadOnlySignal(this.scope, this.index));\n\t}\n\n\tasReadonlyNode() {\n\t\tconst node = new ReadOnlySignal(this.scope, this.index);\n\t\tReadOnlySignal.bindNode(node)\n\t\treturn node;\n\t}\n\n}\n\nexport class ReadOnlySignal<T> extends ReactiveNode<T> {\n\n}\n\nexport class SignalValueScope<T> extends ReactiveScope<Record<PropertyKey, any>> {\n\tconstructor() {\n\t\tsuper({});\n\t}\n\n\twatchSignal(propertyKey: keyof T, node: ReactiveNode<any>) {\n\t\tthis.set(propertyKey, node.get());\n\t\treturn node.subscribe(value => this.set(propertyKey, value));\n\t}\n\n}\n"]}
1
+ {"version":3,"file":"signal.js","sourceRoot":"","sources":["../../../src/expressions/scope/signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAwB,MAAM,YAAY,CAAC;AAMjE,SAAS,OAAO,CAAI,QAAiB;IACpC,IAAI,CAAC;QACJ,OAAO,QAAQ,EAAE,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED,MAAM,OAAO,WAAY,SAAQ,aAAyB;IAEzD,MAAM,CAAC,MAAM;QACZ,OAAO,IAAI,WAAW,EAAE,CAAC;IAC1B,CAAC;IAEO,KAAK,GAAe,EAAE,CAAC;IACvB,KAAK,GAAG,IAAI,CAAC;IAErB;QACC,KAAK,CAAC,EAAE,CAAC,CAAC;IACX,CAAC;IAED,UAAU;QACT,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,YAAY,CAAI,SAAa;QAC5B,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,UAAU,CAAI,QAAiB;QAC9B,OAAO,IAAI,IAAI,CAAI,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAED,cAAc,CAAI,QAAiB;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC;QACvC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,MAA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AE,KAAK,CAAC,CAAC;QACpB,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,GAAG,CAAC,KAAQ;QACX,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,QAAyB;QAC/B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,UAAU;QACT,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;CAED;AAED,MAAM,OAAO,cAAkB,SAAQ,YAAe;CAErD;AAED,MAAM,UAAU,QAAQ,CAAU,MAAe;IAChD,OAAO,MAAM,YAAY,MAAM,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,UAAU,CAAU,MAAe;IAClD,OAAO,MAAM,YAAY,QAAQ,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,MAAM,CAAU,MAAe;IAC9C,OAAO,MAAM,YAAY,IAAI,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAU,MAAe;IACxD,OAAO,MAAM,YAAY,cAAc,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,UAAU,CAAU,MAAe;IAClD,OAAO,MAAM,YAAY,YAAY,CAAC;AACvC,CAAC","sourcesContent":["import { skipChangeDetection } from './cd.js';\nimport { ReactiveScope, ValueChangedCallback } from './scope.js';\n\nexport type CleanupFn = () => void;\nexport type CleanupRegister = (cleanupFn?: CleanupFn) => void;\nexport type SignalDestroyRef = { destroy(): void };\n\nfunction compute<T>(updateFn: () => T): T | unknown {\n\ttry {\n\t\treturn updateFn();\n\t} catch (error) {\n\t\treturn error;\n\t}\n}\n\nexport class SignalScope extends ReactiveScope<Array<any>> {\n\n\tstatic create() {\n\t\treturn new SignalScope();\n\t}\n\n\tprivate state: number[][] = [];\n\tprivate watch = true;\n\n\tconstructor() {\n\t\tsuper([]);\n\t}\n\n\tgetNextKey() {\n\t\treturn this.getContext().length;\n\t}\n\n\tcreateSignal<T>(initValue?: T): Signal<T> {\n\t\treturn new Signal(this, this.getContext().length, initValue);\n\t}\n\n\tcreateLazy<T>(updateFn: () => T): Lazy<T> {\n\t\treturn new Lazy<T>(this, this.getContext().length, updateFn);\n\t}\n\n\tcreateComputed<T>(updateFn: () => T): Computed<T> {\n\t\tconst index = this.getContext().length;\n\t\tthis.watchState();\n\t\tconst value = compute(updateFn);\n\t\tconst computed = new Computed<T>(this, index, value as T);\n\t\tconst observeComputed = () => {\n\t\t\tthis.watchState();\n\t\t\tconst value = compute(updateFn);\n\t\t\tconst state = this.readState();\n\t\t\tthis.restoreState();\n\t\t\tObject.keys(subscriptions)\n\t\t\t\t.filter(index => !state.includes(+index))\n\t\t\t\t.forEach(index => subscriptions[index].pause());\n\t\t\tstate.forEach(index => {\n\t\t\t\tsubscriptions[index]?.resume();\n\t\t\t\tsubscriptions[index] ??= this.subscribe(index, observeComputed);\n\t\t\t});\n\t\t\tthis.set(index, value);\n\t\t};\n\t\tconst subscriptions = this.observeState(observeComputed);\n\t\tthis.restoreState();\n\t\treturn computed;\n\t}\n\n\tcreateEffect(effectFn: (onCleanup?: CleanupFn) => void): SignalDestroyRef {\n\t\tlet cleanupFn: (() => void) | undefined;\n\t\tlet isCleanupRegistered = false;\n\t\tconst cleanupRegister: CleanupRegister = onClean => {\n\t\t\tcleanupFn = onClean;\n\t\t\tisCleanupRegistered = true;\n\t\t};\n\t\tconst callback = () => {\n\t\t\tisCleanupRegistered = false;\n\t\t\tconst error = compute(() => effectFn(cleanupRegister)) as any;\n\t\t\tif (error instanceof Error) {\n\t\t\t\tconsole.error(error);\n\t\t\t}\n\t\t\tif (!isCleanupRegistered) {\n\t\t\t\tcleanupFn = undefined;\n\t\t\t}\n\t\t};\n\t\tthis.watchState();\n\t\tcallback();\n\t\tconst observeComputed = () => {\n\t\t\tcleanupFn?.();\n\t\t\tthis.watchState();\n\t\t\tcallback();\n\t\t\tconst state = this.readState();\n\t\t\tthis.restoreState();\n\t\t\tObject.keys(subscriptions)\n\t\t\t\t.filter(index => !state.includes(+index))\n\t\t\t\t.forEach(index => subscriptions[index].pause());\n\t\t\tstate.forEach(index => {\n\t\t\t\tsubscriptions[index]?.resume();\n\t\t\t\tsubscriptions[index] ??= this.subscribe(index, observeComputed);\n\t\t\t});\n\t\t};\n\t\tconst subscriptions = this.observeState(observeComputed);\n\t\tthis.restoreState();\n\t\treturn {\n\t\t\tdestroy: () => {\n\t\t\t\tObject.values(subscriptions).forEach(sub => sub.unsubscribe());\n\t\t\t\tcleanupFn?.();\n\t\t\t},\n\t\t};\n\t}\n\n\twatchState() {\n\t\tthis.state.push([]);\n\t}\n\n\tuntrack() {\n\t\tthis.watch = false;\n\t}\n\n\tobserveIndex(index: number) {\n\t\tif (this.watch) {\n\t\t\tthis.state.at(-1)?.push(index);\n\t\t}\n\t}\n\n\ttrack() {\n\t\tthis.watch = true;\n\t}\n\n\treadState() {\n\t\treturn this.state.at(-1) ?? [];\n\t}\n\n\tobserveState(updateFn: () => void) {\n\t\treturn Object.fromEntries(this.readState().map(index => [index, this.subscribe(index, updateFn)]));\n\t}\n\n\trestoreState() {\n\t\tthis.state.pop();\n\t}\n\n}\n\nexport abstract class ReactiveNode<T> {\n\n\tconstructor(protected scope: SignalScope, protected index: number) {\n\t\tskipChangeDetection(this);\n\t}\n\n\tget(): T {\n\t\tthis.scope.observeIndex(this.index);\n\t\treturn this.scope.get(this.index);\n\t}\n\n\tgetScope(): SignalScope {\n\t\treturn this.scope;\n\t}\n\n\tgetIndex(): number {\n\t\treturn this.index;\n\t}\n\n\tsubscribe(callback: ValueChangedCallback) {\n\t\treturn this.scope.subscribe(this.index, callback);\n\t}\n\n}\n\nexport class Computed<T> extends ReactiveNode<T> {\n\n\tconstructor(scope: SignalScope, index: number, initValue: T) {\n\t\tsuper(scope, index);\n\t\tscope.set(index, initValue);\n\t}\n\n}\n\nexport class Lazy<T> extends ReactiveNode<T> {\n\n\tprivate updateFn: () => T;\n\n\tconstructor(scope: SignalScope, index: number, updateFn: () => T) {\n\t\tsuper(scope, index);\n\t\tthis.updateFn = updateFn;\n\t\tscope.set(index, compute(updateFn) as T);\n\t}\n\n\toverride get(): T {\n\t\tconst value = compute(this.updateFn);\n\t\tthis.scope.set(this.index, value);\n\t\treturn super.get();\n\t}\n\n}\n\nexport class Signal<T> extends ReactiveNode<T> {\n\n\tconstructor(scope: SignalScope, index: number, initValue?: T) {\n\t\tsuper(scope, index);\n\t\tscope.set(index, initValue);\n\t}\n\n\tset(value: T) {\n\t\tthis.scope.set(this.index, value);\n\t}\n\n\tupdate(updateFn: (value: T) => T): void {\n\t\tthis.set(updateFn(this.get()));\n\t}\n\n\tasReadonly() {\n\t\treturn new ReadOnlySignal(this.scope, this.index);\n\t}\n\n}\n\nexport class ReadOnlySignal<T> extends ReactiveNode<T> {\n\n}\n\nexport function isSignal<T = any>(signal: unknown): signal is Signal<T> {\n\treturn signal instanceof Signal;\n}\n\nexport function isComputed<T = any>(signal: unknown): signal is Computed<T> {\n\treturn signal instanceof Computed;\n}\n\nexport function isLazy<T = any>(signal: unknown): signal is Lazy<T> {\n\treturn signal instanceof Lazy;\n}\n\nexport function isReadOnlySignal<T = any>(signal: unknown): signal is ReadOnlySignal<T> {\n\treturn signal instanceof ReadOnlySignal;\n}\n\nexport function isReactive<T = any>(signal: unknown): signal is ReactiveNode<T> {\n\treturn signal instanceof ReactiveNode;\n}\n"]}
package/scope/stack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { LanguageMode } from '../v8/language.js';
2
2
  import { JavaScriptParser } from '../v8/parser.js';
3
3
  import { finalizerRegister } from './finalizer.js';
4
- import { ModuleScope, ReactiveScope, ReactiveScopeControl, Scope, WebModuleScope } from './scope.js';
4
+ import { ModuleScope, ReactiveScope, ReactiveControlScope, Scope, WebModuleScope } from './scope.js';
5
5
  export class Stack {
6
6
  static for(...contexts) {
7
7
  if (contexts.length === 0) {
@@ -157,7 +157,7 @@ export class Stack {
157
157
  this.getReactiveScope().forEach(scope => scope.detectChanges());
158
158
  }
159
159
  getReactiveScopeControls() {
160
- return this.stack.filter(scope => scope instanceof ReactiveScopeControl);
160
+ return this.stack.filter(scope => scope instanceof ReactiveControlScope);
161
161
  }
162
162
  getReactiveScope() {
163
163
  return this.stack.filter(scope => scope instanceof ReactiveScope);
@@ -1 +1 @@
1
- {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACuB,WAAW,EAAE,aAAa,EACvD,oBAAoB,EAAE,KAAK,EAAW,cAAc,EACpD,MAAM,YAAY,CAAC;AAyIpB,MAAM,OAAO,KAAK;IACjB,MAAM,CAAC,GAAG,CAAC,GAAG,QAAmB;QAChC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,KAAK,EAAE,CAAC;QACpB,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,KAAK,CAAU,OAAO,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAwB;QAC3C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IACD,MAAM,CAAC,WAAW,CAAC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IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtC,OAAO,QAAQ,CAAC;IACjB,CAAC;IACkB,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE;QACtD,IAAI,GAAQ,CAAC;QACb,IAAI,CAAC;YACJ,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC9D,CAAC,CAAA;CACD","sourcesContent":["import type { DeclarationExpression } from '../api/expression.js';\nimport { LanguageMode } from '../v8/language.js';\nimport { JavaScriptParser } from '../v8/parser.js';\nimport { finalizerRegister } from './finalizer.js';\nimport {\n\tModuleContext, ModuleImport, ModuleScope, ReactiveScope,\n\tReactiveScopeControl, Scope, Context, WebModuleScope\n} from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: DeclarationExpression;\n\n\tdeclareVariable: boolean;\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 at last scope in the stack,\n\t * \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(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 Context>(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 Context>(): 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 Context>(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 Context>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends Context>(): Scope<T>;\n\n\tremoveScope<T extends Context>(scope: Scope<T>): void;\n\n\tpushScope<T extends Context>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends Context>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends Context>(context: T): Scope<T>;\n\n\tpushReactiveScope<T extends Context>(): ReactiveScope<T>;\n\n\tpushReactiveScopeFor<T extends Context>(context: T): ReactiveScope<T>;\n\n\t/**\n\t * create new stack instance with the same reference to the current scope array\n\t */\n\tcopyStack(): Stack;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * import module scope from another stack, by the help of ModuleScopeResolver.\n\t * \n\t * used with import statement\n\t */\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;\n\n\t/**\n\t * get the current module for this stack.\n\t * \n\t * used with export statement\n\t */\n\tgetModule(): ModuleScope | undefined;\n\n\t/**\n\t * register action to do on destroy this stack\n\t */\n\tonDestroy(action: () => void): void;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Context[]): 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>(context)));\n\t}\n\tstatic forScopes(...scopes: Scope<Context>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.blockScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tstatic moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<Context>[]) {\n\t\treturn new Stack(globalScopes, resolver, moduleSource);\n\t}\n\tawaitPromise: AwaitPromiseInfo[] = [];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\tprotected readonly moduleScope?: ModuleScope;\n\tprotected readonly moduleSource?: string;\n\tprotected readonly resolver?: ModuleScopeResolver;\n\n\tprotected readonly onDestroyActions: (() => void)[] = [];\n\n\tconstructor();\n\tconstructor(globalScope: Scope<Context>);\n\tconstructor(globalScope: Scope<Context>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Array<Scope<Context>>);\n\tconstructor(stack: Array<Scope<Context>>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Stack);\n\tconstructor(stack: Stack, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(globals?: Stack | Array<Scope<Context>> | Scope<Context>, resolver?: ModuleScopeResolver, moduleSource?: string) {\n\t\tif (Array.isArray(globals)) {\n\t\t\tthis.stack = globals.slice();\n\t\t} else if (globals instanceof Stack) {\n\t\t\tthis.stack = globals.stack.slice();\n\t\t} else if (typeof globals == 'object') {\n\t\t\tthis.stack = [globals];\n\t\t} else {\n\t\t\tthis.stack = [];\n\t\t}\n\t\tif (resolver && moduleSource) {\n\t\t\tthis.resolver = resolver;\n\t\t\tthis.moduleSource = moduleSource;\n\t\t\t// init module scope for import and export\n\t\t\tthis.moduleScope = new ModuleScope(this.initModuleContext());\n\t\t\tthis.pushScope(this.moduleScope);\n\t\t\t// for the rest of module body\n\t\t\tthis.pushReactiveScope();\n\t\t} else if (this.stack.length === 0) {\n\t\t\t// not a module scope\n\t\t\tthis.pushBlockScope();\n\t\t}\n\t\tfinalizerRegister(this, this.onDestroyActions, this);\n\t}\n\tprivate initModuleContext(): ModuleContext {\n\t\tconst importFunc = (path: string) => {\n\t\t\tconst module = this.importModule(path);\n\t\t\tif (module instanceof WebModuleScope) {\n\t\t\t\treturn module.resolveImport();\n\t\t\t}\n\t\t\treturn Promise.resolve(module.getContext());\n\t\t};\n\t\timportFunc.meta = {\n\t\t\turl: createRootURL(this.moduleSource!),\n\t\t\tresolve: (specified: string, parent?: string | URL): Promise<string> => {\n\t\t\t\treturn Promise.resolve(this.resolver!.resolveURL(specified, parent ?? importFunc.meta.url));\n\t\t\t}\n\t\t};\n\t\tconst im: ModuleImport & ((path: string) => Promise<any>) = importFunc as any;\n\t\treturn { import: im };\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<Context>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<Context>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any) {\n\t\treturn this.lastScope<Context>().set(propertyKey, propertyValue);\n\t}\n\tfindScope<T extends Context>(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 Context>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends Context>(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 Context>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends Context>(propertyKeys?: (keyof T)[]): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>(propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends Context>(context: T, propertyKeys?: (keyof T)[]): Scope<T> {\n\t\tconst scope = Scope.for<T>(context, propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScope<T extends Context>(propertyKeys?: (keyof T)[]): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>(propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScopeFor<T extends Context>(context: T, propertyKeys?: (keyof T)[]): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.for(context, propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends Context>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends Context>(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 Context>(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(), this.resolver!, this.moduleSource!);\n\t}\n\tdetach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.detach());\n\t}\n\treattach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.reattach());\n\t}\n\tdetectChanges() {\n\t\tthis.getReactiveScope().forEach(scope => scope.detectChanges());\n\t}\n\tprivate getReactiveScopeControls(): ReactiveScopeControl<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScopeControl) as ReactiveScopeControl<any>[];\n\t}\n\tprivate getReactiveScope(): ReactiveScope<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScope) as ReactiveScope<any>[];\n\t}\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (!this.resolver || !this.moduleScope) {\n\t\t\t// should o the parse and import the module\n\t\t\tthrow new Error('Module Resolver is undefined');\n\t\t}\n\t\treturn this.resolver.resolve(source, this.moduleScope, importCallOptions);\n\t}\n\tgetModule(): ModuleScope | undefined {\n\t\treturn this.moduleScope;\n\t}\n\n\tonDestroy(action: () => void): void {\n\t\tthis.onDestroyActions.push(action);\n\t}\n}\n\n\nexport interface ModuleScopeResolver {\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;\n\tresolveURL(specified: string, parent: string | URL): string;\n}\n\nconst ROOT_URL = 'https://root';\nexport function createRootURL(source: string): URL {\n\treturn new URL(source, ROOT_URL);\n}\n\n\nexport interface ResolverConfig {\n\t/**\n\t * allow import modules from external http(s) module\n\t */\n\tallowImportExternal?: boolean;\n\n};\n\n/**\n * file system provider\n */\nexport interface ModuleSourceProvider {\n\t[url: string]: string;\n}\n\nexport class ModuleScopeResolver implements ModuleScopeResolver {\n\tprotected modules: [string, ModuleScope][] = [];\n\n\tconstructor(protected globalStack: Stack, protected provider: ModuleSourceProvider, protected config?: ResolverConfig) { }\n\tprivate register(source: string, moduleScope: ModuleScope) {\n\t\tconst stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);\n\t\tif (stackInfo) {\n\t\t\tstackInfo[1] = moduleScope;\n\t\t} else {\n\t\t\tthis.modules.push([source, moduleScope]);\n\t\t}\n\t}\n\tresolve(source: keyof ModuleSourceProvider): ModuleScope;\n\tresolve(source: keyof ModuleSourceProvider, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;\n\tresolve(source: string, moduleScope?: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (this.isValidHTTPUrl(source)) {\n\t\t\treturn this.resolveExternalModule(source, importCallOptions);\n\t\t}\n\t\tif (source.startsWith('/')) {\n\t\t\treturn this.findScopeBySource(source, importCallOptions);\n\t\t}\n\t\tconst currentSource = this.findSourceByScope(moduleScope!);\n\t\tconst absoluteUrl = this.resolveURL(source, currentSource);\n\t\treturn this.findScopeBySource(absoluteUrl, importCallOptions);\n\t}\n\tresolveURL(specified: string, parent: string | URL): string {\n\t\tconst currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;\n\t\tconst importedUrl = new URL(specified, currentUrl).href;\n\t\tconst absoluteUrl = importedUrl.replace(ROOT_URL, '');\n\t\treturn absoluteUrl;\n\t}\n\tprotected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (importCallOptions?.assert?.type) {\n\t\t\tconst type = importCallOptions.assert.type;\n\t\t\tif (!source.endsWith(`.${type}`)) {\n\t\t\t\tthrow new Error(`Can't find module scope`);\n\t\t\t}\n\t\t}\n\t\tconst importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];\n\t\tif (!importedScope) {\n\t\t\t// search in the file system provider\n\t\t\tconst javascriptSource = this.provider[source];\n\t\t\tif (javascriptSource || javascriptSource == '') {\n\t\t\t\t// module exists\n\t\t\t\tconst moduleProgram = JavaScriptParser.parse(javascriptSource, { mode: LanguageMode.Strict });\n\t\t\t\tconst stack = new Stack(this.globalStack, this, source);\n\t\t\t\t// register with absoluteUrl\n\t\t\t\tthis.register(source, stack.getModule()!);\n\t\t\t\tmoduleProgram.get(stack);\n\t\t\t\treturn stack.getModule()!;\n\t\t\t}\n\t\t\tthrow new Error(`Can't find module scope`);\n\t\t}\n\t\treturn importedScope;\n\t}\n\tprotected findSourceByScope(moduleScope: ModuleScope): string {\n\t\tconst importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];\n\t\tif (!importedSource) {\n\t\t\tthrow new Error(`Can't resolve scope source`);\n\t\t}\n\t\treturn importedSource;\n\t}\n\tprotected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope {\n\t\tif (!this.config?.allowImportExternal) {\n\t\t\tthrow new Error(`Error: Import External Module is not allowed.`);\n\t\t}\n\t\tconst webScope = new WebModuleScope(source, importCallOptions);\n\t\tthis.modules.push([source, webScope]);\n\t\treturn webScope;\n\t}\n\tprotected readonly isValidHTTPUrl = (string: string) => {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(string);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn url.protocol === 'http:' || url.protocol === 'https:';\n\t}\n}\n"]}
1
+ {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACuB,WAAW,EAAE,aAAa,EACvD,oBAAoB,EAAE,KAAK,EAAW,cAAc,EACpD,MAAM,YAAY,CAAC;AAyIpB,MAAM,OAAO,KAAK;IACjB,MAAM,CAAC,GAAG,CAAC,GAAG,QAAmB;QAChC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,KAAK,EAAE,CAAC;QACpB,CAAC;QACD,O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I,CAAC,cAAc,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,cAAc,CAAC;IACvB,CAAC;IACS,qBAAqB,CAAC,MAAc,EAAE,iBAAqC;QACpF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtC,OAAO,QAAQ,CAAC;IACjB,CAAC;IACkB,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE;QACtD,IAAI,GAAQ,CAAC;QACb,IAAI,CAAC;YACJ,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC9D,CAAC,CAAA;CACD","sourcesContent":["import type { DeclarationExpression } from '../api/expression.js';\nimport { LanguageMode } from '../v8/language.js';\nimport { JavaScriptParser } from '../v8/parser.js';\nimport { finalizerRegister } from './finalizer.js';\nimport {\n\tModuleContext, ModuleImport, ModuleScope, ReactiveScope,\n\tReactiveControlScope, Scope, Context, WebModuleScope\n} from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: DeclarationExpression;\n\n\tdeclareVariable: boolean;\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 at last scope in the stack,\n\t * \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(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 Context>(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 Context>(): 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 Context>(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 Context>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends Context>(): Scope<T>;\n\n\tremoveScope<T extends Context>(scope: Scope<T>): void;\n\n\tpushScope<T extends Context>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends Context>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends Context>(context: T): Scope<T>;\n\n\tpushReactiveScope<T extends Context>(): ReactiveScope<T>;\n\n\tpushReactiveScopeFor<T extends Context>(context: T): ReactiveScope<T>;\n\n\t/**\n\t * create new stack instance with the same reference to the current scope array\n\t */\n\tcopyStack(): Stack;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * import module scope from another stack, by the help of ModuleScopeResolver.\n\t * \n\t * used with import statement\n\t */\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;\n\n\t/**\n\t * get the current module for this stack.\n\t * \n\t * used with export statement\n\t */\n\tgetModule(): ModuleScope | undefined;\n\n\t/**\n\t * register action to do on destroy this stack\n\t */\n\tonDestroy(action: () => void): void;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Context[]): 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>(context)));\n\t}\n\tstatic forScopes(...scopes: Scope<Context>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.blockScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tstatic moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<Context>[]) {\n\t\treturn new Stack(globalScopes, resolver, moduleSource);\n\t}\n\tawaitPromise: AwaitPromiseInfo[] = [];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\tprotected readonly moduleScope?: ModuleScope;\n\tprotected readonly moduleSource?: string;\n\tprotected readonly resolver?: ModuleScopeResolver;\n\n\tprotected readonly onDestroyActions: (() => void)[] = [];\n\n\tconstructor();\n\tconstructor(globalScope: Scope<Context>);\n\tconstructor(globalScope: Scope<Context>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Array<Scope<Context>>);\n\tconstructor(stack: Array<Scope<Context>>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Stack);\n\tconstructor(stack: Stack, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(globals?: Stack | Array<Scope<Context>> | Scope<Context>, resolver?: ModuleScopeResolver, moduleSource?: string) {\n\t\tif (Array.isArray(globals)) {\n\t\t\tthis.stack = globals.slice();\n\t\t} else if (globals instanceof Stack) {\n\t\t\tthis.stack = globals.stack.slice();\n\t\t} else if (typeof globals == 'object') {\n\t\t\tthis.stack = [globals];\n\t\t} else {\n\t\t\tthis.stack = [];\n\t\t}\n\t\tif (resolver && moduleSource) {\n\t\t\tthis.resolver = resolver;\n\t\t\tthis.moduleSource = moduleSource;\n\t\t\t// init module scope for import and export\n\t\t\tthis.moduleScope = new ModuleScope(this.initModuleContext());\n\t\t\tthis.pushScope(this.moduleScope);\n\t\t\t// for the rest of module body\n\t\t\tthis.pushReactiveScope();\n\t\t} else if (this.stack.length === 0) {\n\t\t\t// not a module scope\n\t\t\tthis.pushBlockScope();\n\t\t}\n\t\tfinalizerRegister(this, this.onDestroyActions, this);\n\t}\n\tprivate initModuleContext(): ModuleContext {\n\t\tconst importFunc = (path: string) => {\n\t\t\tconst module = this.importModule(path);\n\t\t\tif (module instanceof WebModuleScope) {\n\t\t\t\treturn module.resolveImport();\n\t\t\t}\n\t\t\treturn Promise.resolve(module.getContext());\n\t\t};\n\t\timportFunc.meta = {\n\t\t\turl: createRootURL(this.moduleSource!),\n\t\t\tresolve: (specified: string, parent?: string | URL): Promise<string> => {\n\t\t\t\treturn Promise.resolve(this.resolver!.resolveURL(specified, parent ?? importFunc.meta.url));\n\t\t\t}\n\t\t};\n\t\tconst im: ModuleImport & ((path: string) => Promise<any>) = importFunc as any;\n\t\treturn { import: im };\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<Context>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<Context>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any) {\n\t\treturn this.lastScope<Context>().set(propertyKey, propertyValue);\n\t}\n\tfindScope<T extends Context>(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 Context>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends Context>(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 Context>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends Context>(propertyKeys?: (keyof T)[]): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>(propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends Context>(context: T, propertyKeys?: (keyof T)[]): Scope<T> {\n\t\tconst scope = Scope.for<T>(context, propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScope<T extends Context>(propertyKeys?: (keyof T)[]): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>(propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScopeFor<T extends Context>(context: T, propertyKeys?: (keyof T)[]): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.for(context, propertyKeys);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends Context>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends Context>(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 Context>(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(), this.resolver!, this.moduleSource!);\n\t}\n\tdetach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.detach());\n\t}\n\treattach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.reattach());\n\t}\n\tdetectChanges() {\n\t\tthis.getReactiveScope().forEach(scope => scope.detectChanges());\n\t}\n\tprivate getReactiveScopeControls(): ReactiveControlScope<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveControlScope) as ReactiveControlScope<any>[];\n\t}\n\tprivate getReactiveScope(): ReactiveScope<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScope) as ReactiveScope<any>[];\n\t}\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (!this.resolver || !this.moduleScope) {\n\t\t\t// should o the parse and import the module\n\t\t\tthrow new Error('Module Resolver is undefined');\n\t\t}\n\t\treturn this.resolver.resolve(source, this.moduleScope, importCallOptions);\n\t}\n\tgetModule(): ModuleScope | undefined {\n\t\treturn this.moduleScope;\n\t}\n\n\tonDestroy(action: () => void): void {\n\t\tthis.onDestroyActions.push(action);\n\t}\n}\n\n\nexport interface ModuleScopeResolver {\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;\n\tresolveURL(specified: string, parent: string | URL): string;\n}\n\nconst ROOT_URL = 'https://root';\nexport function createRootURL(source: string): URL {\n\treturn new URL(source, ROOT_URL);\n}\n\n\nexport interface ResolverConfig {\n\t/**\n\t * allow import modules from external http(s) module\n\t */\n\tallowImportExternal?: boolean;\n\n};\n\n/**\n * file system provider\n */\nexport interface ModuleSourceProvider {\n\t[url: string]: string;\n}\n\nexport class ModuleScopeResolver implements ModuleScopeResolver {\n\tprotected modules: [string, ModuleScope][] = [];\n\n\tconstructor(protected globalStack: Stack, protected provider: ModuleSourceProvider, protected config?: ResolverConfig) { }\n\tprivate register(source: string, moduleScope: ModuleScope) {\n\t\tconst stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);\n\t\tif (stackInfo) {\n\t\t\tstackInfo[1] = moduleScope;\n\t\t} else {\n\t\t\tthis.modules.push([source, moduleScope]);\n\t\t}\n\t}\n\tresolve(source: keyof ModuleSourceProvider): ModuleScope;\n\tresolve(source: keyof ModuleSourceProvider, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;\n\tresolve(source: string, moduleScope?: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (this.isValidHTTPUrl(source)) {\n\t\t\treturn this.resolveExternalModule(source, importCallOptions);\n\t\t}\n\t\tif (source.startsWith('/')) {\n\t\t\treturn this.findScopeBySource(source, importCallOptions);\n\t\t}\n\t\tconst currentSource = this.findSourceByScope(moduleScope!);\n\t\tconst absoluteUrl = this.resolveURL(source, currentSource);\n\t\treturn this.findScopeBySource(absoluteUrl, importCallOptions);\n\t}\n\tresolveURL(specified: string, parent: string | URL): string {\n\t\tconst currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;\n\t\tconst importedUrl = new URL(specified, currentUrl).href;\n\t\tconst absoluteUrl = importedUrl.replace(ROOT_URL, '');\n\t\treturn absoluteUrl;\n\t}\n\tprotected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (importCallOptions?.assert?.type) {\n\t\t\tconst type = importCallOptions.assert.type;\n\t\t\tif (!source.endsWith(`.${type}`)) {\n\t\t\t\tthrow new Error(`Can't find module scope`);\n\t\t\t}\n\t\t}\n\t\tconst importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];\n\t\tif (!importedScope) {\n\t\t\t// search in the file system provider\n\t\t\tconst javascriptSource = this.provider[source];\n\t\t\tif (javascriptSource || javascriptSource == '') {\n\t\t\t\t// module exists\n\t\t\t\tconst moduleProgram = JavaScriptParser.parse(javascriptSource, { mode: LanguageMode.Strict });\n\t\t\t\tconst stack = new Stack(this.globalStack, this, source);\n\t\t\t\t// register with absoluteUrl\n\t\t\t\tthis.register(source, stack.getModule()!);\n\t\t\t\tmoduleProgram.get(stack);\n\t\t\t\treturn stack.getModule()!;\n\t\t\t}\n\t\t\tthrow new Error(`Can't find module scope`);\n\t\t}\n\t\treturn importedScope;\n\t}\n\tprotected findSourceByScope(moduleScope: ModuleScope): string {\n\t\tconst importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];\n\t\tif (!importedSource) {\n\t\t\tthrow new Error(`Can't resolve scope source`);\n\t\t}\n\t\treturn importedSource;\n\t}\n\tprotected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope {\n\t\tif (!this.config?.allowImportExternal) {\n\t\t\tthrow new Error(`Error: Import External Module is not allowed.`);\n\t\t}\n\t\tconst webScope = new WebModuleScope(source, importCallOptions);\n\t\tthis.modules.push([source, webScope]);\n\t\treturn webScope;\n\t}\n\tprotected readonly isValidHTTPUrl = (string: string) => {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(string);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn url.protocol === 'http:' || url.protocol === 'https:';\n\t}\n}\n"]}
package/v8/stream.js CHANGED
@@ -1608,8 +1608,8 @@ export class TokenStreamImpl extends TokenStream {
1608
1608
  this.current = this.newToken(Token.SWITCH, [this.pos, (this.pos += 6)]);
1609
1609
  return true;
1610
1610
  }
1611
- if (/static\s/.test(this.expression.substring(this.pos, this.pos + 7))) {
1612
- this.current = this.newToken(Token.STATIC, [this.pos, (this.pos += 7)]);
1611
+ if (/static(\s|\{)/.test(this.expression.substring(this.pos, this.pos + 7))) {
1612
+ this.current = this.newToken(Token.STATIC, [this.pos, (this.pos += 6)]);
1613
1613
  return true;
1614
1614
  }
1615
1615
  if (/set\s/.test(this.expression.substring(this.pos, this.pos + 4))) {