@ibyar/expressions 0.8.2-dev.20221008 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/api/abstract.d.ts +0 -3
  2. package/api/abstract.js +0 -4
  3. package/api/abstract.js.map +1 -1
  4. package/api/class/class.d.ts +85 -43
  5. package/api/class/class.js +237 -173
  6. package/api/class/class.js.map +1 -1
  7. package/api/class/decorator.d.ts +0 -2
  8. package/api/class/decorator.js +0 -3
  9. package/api/class/decorator.js.map +1 -1
  10. package/api/computing/call.d.ts +0 -2
  11. package/api/computing/call.js +0 -3
  12. package/api/computing/call.js.map +1 -1
  13. package/api/computing/debugger.d.ts +0 -2
  14. package/api/computing/debugger.js +0 -2
  15. package/api/computing/debugger.js.map +1 -1
  16. package/api/computing/new.d.ts +0 -2
  17. package/api/computing/new.js +0 -3
  18. package/api/computing/new.js.map +1 -1
  19. package/api/computing/rest.d.ts +0 -2
  20. package/api/computing/rest.js +0 -3
  21. package/api/computing/rest.js.map +1 -1
  22. package/api/computing/return.d.ts +0 -2
  23. package/api/computing/return.js +0 -3
  24. package/api/computing/return.js.map +1 -1
  25. package/api/computing/spread.d.ts +0 -2
  26. package/api/computing/spread.js +0 -3
  27. package/api/computing/spread.js.map +1 -1
  28. package/api/computing/throw.d.ts +0 -4
  29. package/api/computing/throw.js +0 -5
  30. package/api/computing/throw.js.map +1 -1
  31. package/api/computing/yield.d.ts +0 -2
  32. package/api/computing/yield.js +0 -3
  33. package/api/computing/yield.js.map +1 -1
  34. package/api/definition/array.d.ts +0 -3
  35. package/api/definition/array.js +0 -4
  36. package/api/definition/array.js.map +1 -1
  37. package/api/definition/bind.d.ts +0 -1
  38. package/api/definition/bind.js +0 -1
  39. package/api/definition/bind.js.map +1 -1
  40. package/api/definition/comment.d.ts +0 -2
  41. package/api/definition/comment.js +0 -1
  42. package/api/definition/comment.js.map +1 -1
  43. package/api/definition/function.d.ts +3 -11
  44. package/api/definition/function.js +33 -56
  45. package/api/definition/function.js.map +1 -1
  46. package/api/definition/member.d.ts +0 -1
  47. package/api/definition/member.js +1 -2
  48. package/api/definition/member.js.map +1 -1
  49. package/api/definition/object.d.ts +1 -5
  50. package/api/definition/object.js +2 -8
  51. package/api/definition/object.js.map +1 -1
  52. package/api/definition/statement.d.ts +0 -2
  53. package/api/definition/statement.js +0 -3
  54. package/api/definition/statement.js.map +1 -1
  55. package/api/definition/values.d.ts +0 -3
  56. package/api/definition/values.js +0 -5
  57. package/api/definition/values.js.map +1 -1
  58. package/api/expression.d.ts +0 -20
  59. package/api/expression.js.map +1 -1
  60. package/api/module/common.d.ts +1 -2
  61. package/api/module/common.js +3 -3
  62. package/api/module/common.js.map +1 -1
  63. package/api/module/export.d.ts +0 -5
  64. package/api/module/export.js +5 -9
  65. package/api/module/export.js.map +1 -1
  66. package/api/module/import.d.ts +2 -6
  67. package/api/module/import.js +4 -9
  68. package/api/module/import.js.map +1 -1
  69. package/api/operators/await.d.ts +0 -2
  70. package/api/operators/await.js +0 -3
  71. package/api/operators/await.js.map +1 -1
  72. package/api/operators/chaining.d.ts +0 -1
  73. package/api/operators/chaining.js +0 -1
  74. package/api/operators/chaining.js.map +1 -1
  75. package/api/operators/comma.d.ts +0 -2
  76. package/api/operators/comma.js +0 -3
  77. package/api/operators/comma.js.map +1 -1
  78. package/api/operators/grouping.d.ts +0 -2
  79. package/api/operators/grouping.js +0 -3
  80. package/api/operators/grouping.js.map +1 -1
  81. package/api/operators/pipeline.d.ts +1 -3
  82. package/api/operators/pipeline.js +0 -7
  83. package/api/operators/pipeline.js.map +1 -1
  84. package/api/operators/ternary.d.ts +0 -2
  85. package/api/operators/ternary.js +0 -5
  86. package/api/operators/ternary.js.map +1 -1
  87. package/api/operators/unary.d.ts +0 -2
  88. package/api/operators/unary.js +0 -3
  89. package/api/operators/unary.js.map +1 -1
  90. package/api/operators/update.d.ts +0 -2
  91. package/api/operators/update.js +0 -3
  92. package/api/operators/update.js.map +1 -1
  93. package/api/program.d.ts +0 -2
  94. package/api/program.js +0 -1
  95. package/api/program.js.map +1 -1
  96. package/api/statement/control/block.d.ts +0 -2
  97. package/api/statement/control/block.js +3 -8
  98. package/api/statement/control/block.js.map +1 -1
  99. package/api/statement/control/empty.d.ts +0 -2
  100. package/api/statement/control/empty.js +0 -1
  101. package/api/statement/control/empty.js.map +1 -1
  102. package/api/statement/control/if.d.ts +0 -2
  103. package/api/statement/control/if.js +0 -5
  104. package/api/statement/control/if.js.map +1 -1
  105. package/api/statement/control/switch.d.ts +0 -3
  106. package/api/statement/control/switch.js +0 -8
  107. package/api/statement/control/switch.js.map +1 -1
  108. package/api/statement/control/terminate.d.ts +0 -3
  109. package/api/statement/control/terminate.js +0 -4
  110. package/api/statement/control/terminate.js.map +1 -1
  111. package/api/statement/declarations/declares.d.ts +1 -4
  112. package/api/statement/declarations/declares.js +0 -6
  113. package/api/statement/declarations/declares.js.map +1 -1
  114. package/api/statement/iterations/for.d.ts +1 -6
  115. package/api/statement/iterations/for.js +0 -18
  116. package/api/statement/iterations/for.js.map +1 -1
  117. package/api/statement/iterations/while.d.ts +0 -3
  118. package/api/statement/iterations/while.js +0 -8
  119. package/api/statement/iterations/while.js.map +1 -1
  120. package/package.json +2 -2
  121. package/scope/scope.d.ts +6 -22
  122. package/scope/scope.js +12 -59
  123. package/scope/scope.js.map +1 -1
  124. package/scope/stack.d.ts +15 -3
  125. package/scope/stack.js +26 -9
  126. package/scope/stack.js.map +1 -1
  127. package/v8/inline.d.ts +3 -1
  128. package/v8/inline.js +29 -16
  129. package/v8/inline.js.map +1 -1
  130. package/v8/nodes.d.ts +1 -1
package/scope/scope.js CHANGED
@@ -53,64 +53,6 @@ export class Scope {
53
53
  return Scope;
54
54
  }
55
55
  }
56
- /**
57
- * a class scope used for class instance and private static properties
58
- */
59
- export class ClassScope extends Scope {
60
- constructor(context, propertyKeys, _pKeys) {
61
- super(context, propertyKeys);
62
- this._pKeys = _pKeys;
63
- this._private = {};
64
- }
65
- static for(ctx, propertyKeys, privateKeys) {
66
- return new ClassScope(ctx, propertyKeys, privateKeys);
67
- }
68
- static blockScope(propertyKeys, privateKeys) {
69
- return new ClassScope({}, propertyKeys, privateKeys);
70
- }
71
- static readOnlyScopeForThis(ctx, propertyKeys, privateKeys) {
72
- const thisScope = ClassScope.for(ctx, propertyKeys, privateKeys);
73
- const thisCtx = {
74
- 'this': ctx,
75
- };
76
- const rootScope = ReadOnlyScope.for(thisCtx, ['this']);
77
- rootScope.setInnerScope('this', thisScope);
78
- return rootScope;
79
- }
80
- getPrivateContext() {
81
- return this._private;
82
- }
83
- get(key) {
84
- if (this.isPrivateKey(key)) {
85
- return Reflect.get(this._private, key);
86
- }
87
- return super.get(key);
88
- }
89
- set(key, value, receiver) {
90
- if (this.isPrivateKey(key)) {
91
- return Reflect.set(this._private, key, value);
92
- }
93
- return super.set(key, value, receiver);
94
- }
95
- has(key) {
96
- if (this.isPrivateKey(key)) {
97
- return this._pKeys?.includes(key) ?? key in this._private;
98
- }
99
- return super.has(key);
100
- }
101
- delete(key) {
102
- if (this.isPrivateKey(key)) {
103
- return Reflect.deleteProperty(this._private, key);
104
- }
105
- return super.delete(key);
106
- }
107
- isPrivateKey(key) {
108
- return typeof key === 'string' && key.startsWith('#');
109
- }
110
- getClass() {
111
- return Scope;
112
- }
113
- }
114
56
  export class ReadOnlyScope extends Scope {
115
57
  static for(ctx, propertyKeys) {
116
58
  return new ReadOnlyScope(ctx, propertyKeys);
@@ -437,15 +379,26 @@ export class ModuleScope extends ReactiveScope {
437
379
  super(context, propertyKeys);
438
380
  }
439
381
  importModule(propertyKey, scope) {
382
+ this._ctx[propertyKey] = scope._ctx;
440
383
  this._inners.set(propertyKey, scope);
384
+ this.detectChanges();
441
385
  }
442
386
  }
443
387
  export class WebModuleScope extends ModuleScope {
444
- constructor() {
388
+ constructor(source, importCallOptions) {
445
389
  super({});
390
+ this.source = source;
391
+ this.importCallOptions = importCallOptions;
392
+ this.import = import(source
393
+ /*, { assert: importCallOptions?.assert } */ // TODO: update in future, node16, ESNEXT,ES2022, ES2023, ES2024
394
+ ).then(module => (this.updateContext(module))).then(() => this._ctx, () => this._ctx);
446
395
  }
447
396
  updateContext(context) {
448
397
  this._ctx = context;
398
+ this.detectChanges();
399
+ }
400
+ resolveImport() {
401
+ return this.import;
449
402
  }
450
403
  }
451
404
  //# sourceMappingURL=scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AAgEA,MAAM,OAAO,KAAK;IAWjB,YAAsB,IAAO,EAAY,KAAmB;QAAtC,SAAI,GAAJ,IAAI,CAAG;QAAY,UAAK,GAAL,KAAK,CAAc;QAHlD,YAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAGa,CAAC;IAVjE,MAAM,CAAC,GAAG,CAAoB,GAAM,EAAE,YAA0B;QAC/D,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,UAAU,CAAoB,YAA0B;QAC9D,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE,YAAY,CAAC,CAAC;IACzC,CAAC;IAMD,GAAG,CAAC,GAAY;QACf,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACpC,CAAC;IACD,GAAG,CAAC,GAAY,EAAE,KAAU,EAAE,QAAc;QAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,GAAG,CAAC,GAAY;QACf,OAAO,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC;IACtD,CAAC;IACD,MAAM,CAAC,GAAY;QAClB,OAAO,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,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CAAC,KAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IACD,aAAa;QACZ,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,KAAK,CAAC,aAAa,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,EAAE,CAAC;IACjB,CAAC;IACD,cAAc;QACb,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,KAAK,CAAC,aAAa,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;SAClD;IACF,CAAC;IACD,QAAQ;QACP,OAAO,oBAAoB,CAAC;IAC7B,CAAC;CACD;AAyBD,MAAM,OAAO,WAAY,SAAQ,aAA4B;IAC5D,YAAY,OAAsB,EAAE,YAAsC;QACzE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9B,CAAC;IACD,YAAY,CAAC,WAAgC,EAAE,KAAkB;QAChE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;CACD;AACD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C;QACC,KAAK,CAAC,EAAmB,CAAC,CAAC;IAC5B,CAAC;IACD,aAAa,CAAC,OAAY;QACzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;IACrB,CAAC;CACD","sourcesContent":["import { TypeOf } from '../api/utils.js';\n\nexport type Context = Record<PropertyKey, any>;\nexport interface Scope<T = Context> {\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 proxy of the current context object if exists. \n\t */\n\tgetContextProxy?(): 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\tgetInnerScope<S extends Scope<Context>>(propertyKey: keyof T): S | undefined;\n\n\t/**\n\t * create a scope with the same type of this scope\n\t */\n\tsetInnerScope<S extends Scope<Context>>(propertyKey: keyof T): S;\n\n\t/**\n\t * sc\n\t * @param propertyKey \n\t * @param scope \n\t */\n\tsetInnerScope<S extends Scope<Context>>(propertyKey: keyof T, scope?: S): S;\n\n\tgetClass(): TypeOf<Scope<Context>>;\n}\n\nexport class Scope<T extends Context> implements Scope<T> {\n\tstatic for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope(ctx, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope({} as T, propertyKeys);\n\t}\n\n\tprotected _inners = new Map<keyof T, Scope<any>>();\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[]);\n\tconstructor(protected _ctx: T, protected _keys?: (keyof T)[]) { }\n\tget(key: keyof T): any {\n\t\treturn Reflect.get(this._ctx, key);\n\t}\n\tset(key: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this._ctx, key, value);\n\t}\n\thas(key: keyof T): boolean {\n\t\treturn this._keys?.includes(key) ?? key in this._ctx;\n\t}\n\tdelete(key: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this._ctx, key);\n\t}\n\tgetContext(): T {\n\t\treturn this._ctx;\n\t}\n\tgetInnerScope<S extends Scope<Context>>(key: keyof T): S | undefined {\n\t\tconst ctx = this.get(key);\n\t\tlet scope = this._inners.get(key);\n\t\tif (scope) {\n\t\t\tscope._ctx = ctx;\n\t\t\treturn scope as S;\n\t\t}\n\t\tif (!(ctx && typeof ctx === 'object')) {\n\t\t\treturn;\n\t\t}\n\t\tscope = new (this.getClass())(ctx, undefined, key, this);\n\t\tthis._inners.set(key, scope);\n\t\treturn scope as S;\n\t}\n\tsetInnerScope<S extends Scope<Context>>(key: keyof T, scope?: S): S {\n\t\tif (scope) {\n\t\t\tthis._inners.set(key, scope);\n\t\t\treturn scope;\n\t\t}\n\t\tconst ctx = this.get(key);\n\t\tscope = new (this.getClass())(ctx, undefined, key, this) as S;\n\t\tthis._inners.set(key, scope);\n\t\treturn scope;\n\t}\n\tgetClass(): TypeOf<Scope<Context>> {\n\t\treturn Scope;\n\t}\n}\n\n/**\n * a class scope used for class instance and private static properties \n */\n\nexport class ClassScope<T extends Context> extends Scope<T> {\n\tstatic for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]) {\n\t\treturn new ClassScope(ctx, propertyKeys, privateKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]) {\n\t\treturn new ClassScope({} as T, propertyKeys, privateKeys);\n\t}\n\tstatic readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]) {\n\t\tconst thisScope = ClassScope.for(ctx, propertyKeys, privateKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = ReadOnlyScope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tprotected _private: Context = {};\n\tconstructor(context: T, propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]);\n\tconstructor(context: T, propertyKeys?: (keyof T)[], private _pKeys?: (keyof T)[]) {\n\t\tsuper(context, propertyKeys);\n\t}\n\tgetPrivateContext(): T {\n\t\treturn this._private;\n\t}\n\tget(key: keyof T): any {\n\t\tif (this.isPrivateKey(key)) {\n\t\t\treturn Reflect.get(this._private, key);\n\t\t}\n\t\treturn super.get(key);\n\t}\n\tset(key: keyof T, value: any, receiver?: any): boolean {\n\t\tif (this.isPrivateKey(key)) {\n\t\t\treturn Reflect.set(this._private, key, value);\n\t\t}\n\t\treturn super.set(key, value, receiver);\n\t}\n\thas(key: keyof T): boolean {\n\t\tif (this.isPrivateKey(key)) {\n\t\t\treturn this._pKeys?.includes(key) ?? key in this._private;\n\t\t}\n\t\treturn super.has(key);\n\t}\n\tdelete(key: keyof T): boolean {\n\t\tif (this.isPrivateKey(key)) {\n\t\t\treturn Reflect.deleteProperty(this._private, key);\n\t\t}\n\t\treturn super.delete(key);\n\t}\n\tprotected isPrivateKey(key: keyof T) {\n\t\treturn typeof key === 'string' && key.startsWith('#');\n\t}\n\tgetClass(): TypeOf<ReadOnlyScope<Context>> {\n\t\treturn Scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends Context> extends Scope<T> {\n\tstatic for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope(ctx, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope({} as T, propertyKeys);\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\tgetClass(): TypeOf<ReadOnlyScope<Context>> {\n\t\treturn ReadOnlyScope;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>) { }\n\tpause() {\n\t\tthis.observer.pause(this.propertyKey, this);\n\t}\n\tresume() {\n\t\tthis.observer.resume(this.propertyKey, this);\n\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\ntype SubscriptionInfo = { callback: ValueChangedCallback, enable: boolean };\n\nexport class ValueChangeObserver<T> {\n\tprivate _subscribers: Map<keyof T, Map<ScopeSubscription<T>, SubscriptionInfo>> = new Map();\n\tprivate _lock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this._lock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this._subscribers.get(propertyKey);\n\t\tif (!subscribers || subscribers.size == 0) {\n\t\t\treturn;\n\t\t}\n\t\tthis._lock.push(propertyKey);\n\t\tsubscribers?.forEach(subscriptionInfo => {\n\t\t\tif (!subscriptionInfo.enable) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tsubscriptionInfo.callback(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._lock.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, enable: true });\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\tpause(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this._subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = false);\n\t}\n\n\tresume(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this._subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = true);\n\t}\n\n\t/**\n\t * check if this Observer has any subscribers\n\t */\n\thasSubscribers(): boolean;\n\n\t/**\n\t * check if there is any subscribers registered by the propertyKey.\n\t * \n\t * @param propertyKey\n\t */\n\thasSubscribers(propertyKey: keyof T): boolean;\n\thasSubscribers(propertyKey?: keyof T): boolean {\n\t\tif (propertyKey) {\n\t\t\treturn (this._subscribers.get(propertyKey)?.size ?? 0) > 0;\n\t\t}\n\t\treturn this._subscribers.size > 0;\n\t}\n\n\t/**\n\t * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis._subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends Context> extends Scope<T> {\n\tstatic for<T extends Context>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope({} as T, propertyKeys);\n\t}\n\tstatic scopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScope.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = Scope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tstatic readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScope.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = ReadOnlyScope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tprotected _clone: T;\n\tdeclare protected _inners: Map<keyof T, ReactiveScope<any>>;\n\tprotected _observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[], protected _name?: keyof T, protected _parent?: ReactiveScope<any>) {\n\t\tsuper(context, propertyKeys);\n\t\tthis._clone = Object.assign({}, context);\n\t\tif (HTMLElement && context instanceof HTMLElement) {\n\t\t\tthis._keys = [];\n\t\t}\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this._ctx, propertyKey);\n\t\tconst result = Reflect.set(this._ctx, 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._ctx, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this._ctx, 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\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._ctx);\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this._observer.subscribe(propertyKey, callback);\n\t}\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\t\t\tthis._observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis._observer.destroy();\n\t\t}\n\t}\n\tdetectChanges() {\n\t\tconst previous = this._clone;\n\t\tconst current = this._ctx;\n\t\tif ((!!!previous && !!current) || (!!previous && !!!current)) {\n\t\t\tthis._parent?.emit(this._name!, current);\n\t\t\treturn;\n\t\t}\n\t\tconst keys = this._keys ?? this.getPropertyKeys(previous, current);\n\t\tkeys.forEach(key => {\n\t\t\tconst pv = previous[key];\n\t\t\tconst cv = current[key];\n\t\t\tconst pt = typeof pv;\n\t\t\tconst ct = typeof cv;\n\t\t\tif (pt === 'object') {\n\t\t\t\tif (ct === 'object') {\n\t\t\t\t\tthis.getInnerScope<ReactiveScope<Context>>(key)?.detectChanges();\n\t\t\t\t} else if (cv != pv) {\n\t\t\t\t\tthis.emit(key, cv, pv);\n\t\t\t\t}\n\t\t\t} else if (ct === 'object') {\n\t\t\t\tthis.emit(key, cv, pv);\n\t\t\t} else if (pv != cv) {\n\t\t\t\tthis.emit(key, cv, pv);\n\t\t\t}\n\t\t});\n\t\tthis._clone = Object.assign({}, this._ctx);\n\t}\n\tprotected getPropertyKeys<V extends Record<PropertyKey, any>>(...objs: V[]) {\n\t\tlet keys: (keyof V)[] = [];\n\t\tobjs.forEach(obj => {\n\t\t\tkeys.push(...Object.keys(obj));\n\t\t\tkeys.push(...Object.getOwnPropertySymbols(obj));\n\t\t});\n\t\tkeys = Array.from(new Set(keys));\n\t\tkeys = keys.filter(key => {\n\t\t\tswitch (typeof key) {\n\t\t\t\tcase 'string':\n\t\t\t\t\treturn !key.startsWith('_');\n\t\t\t\tcase 'symbol':\n\t\t\t\t\treturn !key.toString().startsWith('Symbol(_');\n\t\t\t\tdefault:\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t\treturn keys;\n\t}\n\tgetClass(): TypeOf<ReactiveScope<Context>> {\n\t\treturn ReactiveScope;\n\t}\n}\n\n/**\n * used control/notify/pause scope about changes in current context\n */\nexport interface ScopeControl<T extends Context> {\n\n\t/**\n\t * get current stacte of applying change detection.\n\t */\n\tisAttached(): boolean;\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 * apply changes now,\n\t * will not effect the state of the detector wither if attached ot not.\n\t * \n\t * if a propertyKey is provided, will emit this property only \n\t * @param propertyKey \n\t */\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void;\n\n\t/**\n\t * throw error if any changes has been made\n\t */\n\tcheckNoChanges(): void;\n}\n\nexport class ReactiveScopeControl<T extends Context> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends Context>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl({} as T, propertyKeys);\n\t}\n\tstatic scopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScopeControl.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = Scope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tstatic readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScopeControl.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = ReadOnlyScope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tstatic reactiveScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScope.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = Scope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\n\tprotected _attached: boolean = true;\n\tprotected _marked: { [key: keyof Context]: [any, any] } = {};\n\n\toverride emit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this._attached) {\n\t\t\tsuper.emit(propertyKey, newValue, oldValue);\n\t\t} else if (this._marked[propertyKey as string]) {\n\t\t\tif (newValue == this._marked[propertyKey as string][1]) {\n\t\t\t\tdelete this._marked[propertyKey as string];\n\t\t\t} else {\n\t\t\t\tthis._marked[propertyKey as string][0] = newValue;\n\t\t\t}\n\t\t} else {\n\t\t\tthis._marked[propertyKey as string] = [newValue, oldValue];\n\t\t}\n\t}\n\tisAttached(): boolean {\n\t\treturn this._attached;\n\t}\n\tdetach(): void {\n\t\tthis._attached = false;\n\t}\n\treattach(): void {\n\t\tthis._attached = true;\n\t\tthis.emitChanges();\n\t}\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void {\n\t\tif (propertyKey) {\n\t\t\tsuper.emit(propertyKey, propertyValue);\n\t\t\tReflect.deleteProperty(this._marked, propertyKey);\n\t\t\treturn;\n\t\t}\n\t\tconst latestChanges = this._marked;\n\t\tthis._marked = {};\n\t\tconst keys = this._keys ?? this.getPropertyKeys(latestChanges);\n\t\tkeys.forEach(propertyKey => {\n\t\t\tthis._observer.emit(propertyKey, latestChanges[propertyKey][0], latestChanges[propertyKey][1]);\n\t\t});\n\t\tkeys.length && this._parent?.emit(this._name!, this._ctx);\n\t}\n\tdetectChanges() {\n\t\tthis.detach();\n\t\tsuper.detectChanges();\n\t\tthis.reattach();\n\t}\n\tcheckNoChanges() {\n\t\tthis.detach();\n\t\tsuper.detectChanges();\n\t\tconst keys = Object.keys(this._marked);\n\t\tif (keys.length > 0) {\n\t\t\tthrow new Error(`Some Changes had been detected`);\n\t\t}\n\t}\n\tgetClass(): TypeOf<ReactiveScopeControl<Context>> {\n\t\treturn ReactiveScopeControl;\n\t}\n}\n\n\ninterface ImportMeta {\n\turl: URL;\n\t/**\n\t *\n\t * Provides a module-relative resolution function scoped to each module, returning\n\t * the URL string.\n\t *\n\t * @param specified The module specifier to resolve relative to `parent`.\n\t * @param parent The absolute parent module URL to resolve from. If none\n\t * is specified, the value of `import.meta.url` is used as the default.\n\t */\n\tresolve?(specified: string, parent?: string | URL): Promise<string>;\n}\n\nexport interface ModuleImport {\n\tmeta: ImportMeta\n}\n\nexport interface ModuleContext extends Context {\n\timport: ModuleImport & ((path: string) => Promise<any>);\n}\n\nexport class ModuleScope extends ReactiveScope<ModuleContext> {\n\tconstructor(context: ModuleContext, propertyKeys?: (keyof ModuleContext)[]) {\n\t\tsuper(context, propertyKeys);\n\t}\n\timportModule(propertyKey: keyof ModuleContext, scope: ModuleScope): void {\n\t\tthis._inners.set(propertyKey, scope);\n\t}\n}\nexport class WebModuleScope extends ModuleScope {\n\tconstructor() {\n\t\tsuper({} as ModuleContext);\n\t}\n\tupdateContext(context: any) {\n\t\tthis._ctx = context;\n\t}\n}\n"]}
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AAgEA,MAAM,OAAO,KAAK;IAWjB,YAAsB,IAAO,EAAY,KAAmB;QAAtC,SAAI,GAAJ,IAAI,CAAG;QAAY,UAAK,GAAL,KAAK,CAAc;QAHlD,YAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAGa,CAAC;IAVjE,MAAM,CAAC,GAAG,CAAoB,GAAM,EAAE,YAA0B;QAC/D,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,UAAU,CAAoB,YAA0B;QAC9D,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE,YAAY,CAAC,CAAC;IACzC,CAAC;IAMD,GAAG,CAAC,GAAY;QACf,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACpC,CAAC;IACD,GAAG,CAAC,GAAY,EAAE,KAAU,EAAE,QAAc;QAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAA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AgC,EAAE,KAAkB;QAChE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,aAAa,EAAE,CAAC;IACtB,CAAC;CACD;AACD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAI9C,YAAoB,MAAc,EAAU,iBAAqC;QAChF,KAAK,CAAC,EAAmB,CAAC,CAAC;QADR,WAAM,GAAN,MAAM,CAAQ;QAAU,sBAAiB,GAAjB,iBAAiB,CAAoB;QAEhF,IAAI,CAAC,MAAM,GAAG,MAAM,CACnB,MAAM;QACN,4CAA4C,CAAC,gEAAgE;SAC7G,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvF,CAAC;IACO,aAAa,CAAC,OAAY;QACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,aAAa,EAAE,CAAC;IACtB,CAAC;IAED,aAAa;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD","sourcesContent":["import { TypeOf } from '../api/utils.js';\n\nexport type Context = Record<PropertyKey, any>;\nexport interface Scope<T = Context> {\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 proxy of the current context object if exists. \n\t */\n\tgetContextProxy?(): 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\tgetInnerScope<S extends Scope<Context>>(propertyKey: keyof T): S | undefined;\n\n\t/**\n\t * create a scope with the same type of this scope\n\t */\n\tsetInnerScope<S extends Scope<Context>>(propertyKey: keyof T): S;\n\n\t/**\n\t * sc\n\t * @param propertyKey \n\t * @param scope \n\t */\n\tsetInnerScope<S extends Scope<Context>>(propertyKey: keyof T, scope?: S): S;\n\n\tgetClass(): TypeOf<Scope<Context>>;\n}\n\nexport class Scope<T extends Context> implements Scope<T> {\n\tstatic for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope(ctx, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope({} as T, propertyKeys);\n\t}\n\n\tprotected _inners = new Map<keyof T, Scope<any>>();\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[]);\n\tconstructor(protected _ctx: T, protected _keys?: (keyof T)[]) { }\n\tget(key: keyof T): any {\n\t\treturn Reflect.get(this._ctx, key);\n\t}\n\tset(key: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this._ctx, key, value);\n\t}\n\thas(key: keyof T): boolean {\n\t\treturn this._keys?.includes(key) ?? key in this._ctx;\n\t}\n\tdelete(key: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this._ctx, key);\n\t}\n\tgetContext(): T {\n\t\treturn this._ctx;\n\t}\n\tgetInnerScope<S extends Scope<Context>>(key: keyof T): S | undefined {\n\t\tconst ctx = this.get(key);\n\t\tlet scope = this._inners.get(key);\n\t\tif (scope) {\n\t\t\tscope._ctx = ctx;\n\t\t\treturn scope as S;\n\t\t}\n\t\tif (!(ctx && typeof ctx === 'object')) {\n\t\t\treturn;\n\t\t}\n\t\tscope = new (this.getClass())(ctx, undefined, key, this);\n\t\tthis._inners.set(key, scope);\n\t\treturn scope as S;\n\t}\n\tsetInnerScope<S extends Scope<Context>>(key: keyof T, scope?: S): S {\n\t\tif (scope) {\n\t\t\tthis._inners.set(key, scope);\n\t\t\treturn scope;\n\t\t}\n\t\tconst ctx = this.get(key);\n\t\tscope = new (this.getClass())(ctx, undefined, key, this) as S;\n\t\tthis._inners.set(key, scope);\n\t\treturn scope;\n\t}\n\tgetClass(): TypeOf<Scope<Context>> {\n\t\treturn Scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends Context> extends Scope<T> {\n\tstatic for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope(ctx, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope({} as T, propertyKeys);\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\tgetClass(): TypeOf<ReadOnlyScope<Context>> {\n\t\treturn ReadOnlyScope;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>) { }\n\tpause() {\n\t\tthis.observer.pause(this.propertyKey, this);\n\t}\n\tresume() {\n\t\tthis.observer.resume(this.propertyKey, this);\n\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\ntype SubscriptionInfo = { callback: ValueChangedCallback, enable: boolean };\n\nexport class ValueChangeObserver<T> {\n\tprivate _subscribers: Map<keyof T, Map<ScopeSubscription<T>, SubscriptionInfo>> = new Map();\n\tprivate _lock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this._lock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this._subscribers.get(propertyKey);\n\t\tif (!subscribers || subscribers.size == 0) {\n\t\t\treturn;\n\t\t}\n\t\tthis._lock.push(propertyKey);\n\t\tsubscribers?.forEach(subscriptionInfo => {\n\t\t\tif (!subscriptionInfo.enable) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tsubscriptionInfo.callback(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._lock.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, enable: true });\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\tpause(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this._subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = false);\n\t}\n\n\tresume(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this._subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = true);\n\t}\n\n\t/**\n\t * check if this Observer has any subscribers\n\t */\n\thasSubscribers(): boolean;\n\n\t/**\n\t * check if there is any subscribers registered by the propertyKey.\n\t * \n\t * @param propertyKey\n\t */\n\thasSubscribers(propertyKey: keyof T): boolean;\n\thasSubscribers(propertyKey?: keyof T): boolean {\n\t\tif (propertyKey) {\n\t\t\treturn (this._subscribers.get(propertyKey)?.size ?? 0) > 0;\n\t\t}\n\t\treturn this._subscribers.size > 0;\n\t}\n\n\t/**\n\t * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis._subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends Context> extends Scope<T> {\n\tstatic for<T extends Context>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope({} as T, propertyKeys);\n\t}\n\tstatic scopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScope.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = Scope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tstatic readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScope.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = ReadOnlyScope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tprotected _clone: T;\n\tdeclare protected _inners: Map<keyof T, ReactiveScope<any>>;\n\tprotected _observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[], protected _name?: keyof T, protected _parent?: ReactiveScope<any>) {\n\t\tsuper(context, propertyKeys);\n\t\tthis._clone = Object.assign({}, context);\n\t\tif (HTMLElement && context instanceof HTMLElement) {\n\t\t\tthis._keys = [];\n\t\t}\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this._ctx, propertyKey);\n\t\tconst result = Reflect.set(this._ctx, 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._ctx, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this._ctx, 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\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._ctx);\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this._observer.subscribe(propertyKey, callback);\n\t}\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\t\t\tthis._observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis._observer.destroy();\n\t\t}\n\t}\n\tdetectChanges() {\n\t\tconst previous = this._clone;\n\t\tconst current = this._ctx;\n\t\tif ((!!!previous && !!current) || (!!previous && !!!current)) {\n\t\t\tthis._parent?.emit(this._name!, current);\n\t\t\treturn;\n\t\t}\n\t\tconst keys = this._keys ?? this.getPropertyKeys(previous, current);\n\t\tkeys.forEach(key => {\n\t\t\tconst pv = previous[key];\n\t\t\tconst cv = current[key];\n\t\t\tconst pt = typeof pv;\n\t\t\tconst ct = typeof cv;\n\t\t\tif (pt === 'object') {\n\t\t\t\tif (ct === 'object') {\n\t\t\t\t\tthis.getInnerScope<ReactiveScope<Context>>(key)?.detectChanges();\n\t\t\t\t} else if (cv != pv) {\n\t\t\t\t\tthis.emit(key, cv, pv);\n\t\t\t\t}\n\t\t\t} else if (ct === 'object') {\n\t\t\t\tthis.emit(key, cv, pv);\n\t\t\t} else if (pv != cv) {\n\t\t\t\tthis.emit(key, cv, pv);\n\t\t\t}\n\t\t});\n\t\tthis._clone = Object.assign({}, this._ctx);\n\t}\n\tprotected getPropertyKeys<V extends Record<PropertyKey, any>>(...objs: V[]) {\n\t\tlet keys: (keyof V)[] = [];\n\t\tobjs.forEach(obj => {\n\t\t\tkeys.push(...Object.keys(obj));\n\t\t\tkeys.push(...Object.getOwnPropertySymbols(obj));\n\t\t});\n\t\tkeys = Array.from(new Set(keys));\n\t\tkeys = keys.filter(key => {\n\t\t\tswitch (typeof key) {\n\t\t\t\tcase 'string':\n\t\t\t\t\treturn !key.startsWith('_');\n\t\t\t\tcase 'symbol':\n\t\t\t\t\treturn !key.toString().startsWith('Symbol(_');\n\t\t\t\tdefault:\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t\treturn keys;\n\t}\n\tgetClass(): TypeOf<ReactiveScope<Context>> {\n\t\treturn ReactiveScope;\n\t}\n}\n\n/**\n * used control/notify/pause scope about changes in current context\n */\nexport interface ScopeControl<T extends Context> {\n\n\t/**\n\t * get current stacte of applying change detection.\n\t */\n\tisAttached(): boolean;\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 * apply changes now,\n\t * will not effect the state of the detector wither if attached ot not.\n\t * \n\t * if a propertyKey is provided, will emit this property only \n\t * @param propertyKey \n\t */\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void;\n\n\t/**\n\t * throw error if any changes has been made\n\t */\n\tcheckNoChanges(): void;\n}\n\nexport class ReactiveScopeControl<T extends Context> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends Context>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends Context>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl({} as T, propertyKeys);\n\t}\n\tstatic scopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScopeControl.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = Scope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tstatic readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScopeControl.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = ReadOnlyScope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\tstatic reactiveScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]) {\n\t\tconst thisScope = ReactiveScope.for(ctx, propertyKeys);\n\t\tconst thisCtx = {\n\t\t\t'this': ctx,\n\t\t};\n\t\tconst rootScope = Scope.for(thisCtx, ['this']);\n\t\trootScope.setInnerScope('this', thisScope);\n\t\treturn rootScope;\n\t}\n\n\tprotected _attached: boolean = true;\n\tprotected _marked: { [key: keyof Context]: [any, any] } = {};\n\n\toverride emit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this._attached) {\n\t\t\tsuper.emit(propertyKey, newValue, oldValue);\n\t\t} else if (this._marked[propertyKey as string]) {\n\t\t\tif (newValue == this._marked[propertyKey as string][1]) {\n\t\t\t\tdelete this._marked[propertyKey as string];\n\t\t\t} else {\n\t\t\t\tthis._marked[propertyKey as string][0] = newValue;\n\t\t\t}\n\t\t} else {\n\t\t\tthis._marked[propertyKey as string] = [newValue, oldValue];\n\t\t}\n\t}\n\tisAttached(): boolean {\n\t\treturn this._attached;\n\t}\n\tdetach(): void {\n\t\tthis._attached = false;\n\t}\n\treattach(): void {\n\t\tthis._attached = true;\n\t\tthis.emitChanges();\n\t}\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void {\n\t\tif (propertyKey) {\n\t\t\tsuper.emit(propertyKey, propertyValue);\n\t\t\tReflect.deleteProperty(this._marked, propertyKey);\n\t\t\treturn;\n\t\t}\n\t\tconst latestChanges = this._marked;\n\t\tthis._marked = {};\n\t\tconst keys = this._keys ?? this.getPropertyKeys(latestChanges);\n\t\tkeys.forEach(propertyKey => {\n\t\t\tthis._observer.emit(propertyKey, latestChanges[propertyKey][0], latestChanges[propertyKey][1]);\n\t\t});\n\t\tkeys.length && this._parent?.emit(this._name!, this._ctx);\n\t}\n\tdetectChanges() {\n\t\tthis.detach();\n\t\tsuper.detectChanges();\n\t\tthis.reattach();\n\t}\n\tcheckNoChanges() {\n\t\tthis.detach();\n\t\tsuper.detectChanges();\n\t\tconst keys = Object.keys(this._marked);\n\t\tif (keys.length > 0) {\n\t\t\tthrow new Error(`Some Changes had been detected`);\n\t\t}\n\t}\n\tgetClass(): TypeOf<ReactiveScopeControl<Context>> {\n\t\treturn ReactiveScopeControl;\n\t}\n}\n\n\ninterface ImportMeta {\n\turl: URL;\n\t/**\n\t *\n\t * Provides a module-relative resolution function scoped to each module, returning\n\t * the URL string.\n\t *\n\t * @param specified The module specifier to resolve relative to `parent`.\n\t * @param parent The absolute parent module URL to resolve from. If none\n\t * is specified, the value of `import.meta.url` is used as the default.\n\t */\n\tresolve?(specified: string, parent?: string | URL): Promise<string>;\n}\n\nexport interface ModuleImport {\n\tmeta: ImportMeta\n}\n\nexport interface ModuleContext extends Context {\n\timport: ModuleImport & ((path: string) => Promise<any>);\n}\n\nexport class ModuleScope extends ReactiveScope<ModuleContext> {\n\tconstructor(context: ModuleContext, propertyKeys?: (keyof ModuleContext)[]) {\n\t\tsuper(context, propertyKeys);\n\t}\n\timportModule(propertyKey: keyof ModuleContext, scope: ModuleScope): void {\n\t\tthis._ctx[propertyKey] = scope._ctx;\n\t\tthis._inners.set(propertyKey, scope);\n\t\tthis.detectChanges();\n\t}\n}\nexport class WebModuleScope extends ModuleScope {\n\n\t// private loaded = false;\n\tprivate import: Promise<any>;\n\tconstructor(private source: string, private importCallOptions?: ImportCallOptions) {\n\t\tsuper({} as ModuleContext);\n\t\tthis.import = import(\n\t\t\tsource\n\t\t\t/*, { assert: importCallOptions?.assert } */ // TODO: update in future, node16, ESNEXT,ES2022, ES2023, ES2024\n\t\t).then(module => (this.updateContext(module))).then(() => this._ctx, () => this._ctx);\n\t}\n\tprivate updateContext(context: any) {\n\t\tthis._ctx = context;\n\t\tthis.detectChanges();\n\t}\n\n\tresolveImport() {\n\t\treturn this.import;\n\t}\n}\n"]}
package/scope/stack.d.ts CHANGED
@@ -122,6 +122,8 @@ export declare class Stack implements Stack {
122
122
  constructor(globalScope: Scope<Context>, resolver: ModuleScopeResolver, moduleSource: string);
123
123
  constructor(stack: Array<Scope<Context>>);
124
124
  constructor(stack: Array<Scope<Context>>, resolver: ModuleScopeResolver, moduleSource: string);
125
+ constructor(stack: Stack);
126
+ constructor(stack: Stack, resolver: ModuleScopeResolver, moduleSource: string);
125
127
  private initModuleContext;
126
128
  detectChanges(): void;
127
129
  private getReactiveScopeControls;
@@ -134,15 +136,25 @@ export interface ModuleScopeResolver {
134
136
  export declare function createRootURL(source: string): URL;
135
137
  export interface ResolverConfig {
136
138
  /**
137
- *
139
+ * allow import modules from external http(s) module
138
140
  */
139
141
  allowImportExternal?: boolean;
140
142
  }
143
+ /**
144
+ * file system provider
145
+ */
146
+ export interface ModuleSourceProvider {
147
+ [url: string]: string;
148
+ }
141
149
  export declare class ModuleScopeResolver implements ModuleScopeResolver {
150
+ protected globalStack: Stack;
151
+ protected provider: ModuleSourceProvider;
142
152
  protected config?: ResolverConfig | undefined;
143
153
  protected modules: [string, ModuleScope][];
144
- constructor(config?: ResolverConfig | undefined);
145
- register(source: string, moduleScope: ModuleScope): void;
154
+ constructor(globalStack: Stack, provider: ModuleSourceProvider, config?: ResolverConfig | undefined);
155
+ private register;
156
+ resolve(source: keyof ModuleSourceProvider): ModuleScope;
157
+ resolve(source: keyof ModuleSourceProvider, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;
146
158
  protected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
147
159
  protected findSourceByScope(moduleScope: ModuleScope): string;
148
160
  protected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope;
package/scope/stack.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { LanguageMode } from '../v8/language.js';
2
+ import { JavaScriptParser } from '../v8/parser.js';
1
3
  import { finalizerRegister } from './finalizer.js';
2
4
  import { ModuleScope, ReactiveScope, ReactiveScopeControl, Scope, WebModuleScope } from './scope.js';
3
5
  export class Stack {
@@ -5,7 +7,10 @@ export class Stack {
5
7
  this.awaitPromise = [];
6
8
  this.onDestroyActions = [];
7
9
  if (Array.isArray(globals)) {
8
- this.stack = globals;
10
+ this.stack = globals.slice();
11
+ }
12
+ else if (globals instanceof Stack) {
13
+ this.stack = globals.stack.slice();
9
14
  }
10
15
  else if (typeof globals == 'object') {
11
16
  this.stack = [globals];
@@ -45,7 +50,11 @@ export class Stack {
45
50
  }
46
51
  initModuleContext() {
47
52
  const importFunc = (path) => {
48
- return this.importModule(path);
53
+ const module = this.importModule(path);
54
+ if (module instanceof WebModuleScope) {
55
+ return module.resolveImport();
56
+ }
57
+ return Promise.resolve(module.getContext());
49
58
  };
50
59
  importFunc.meta = {
51
60
  url: createRootURL(this.moduleSource),
@@ -168,7 +177,9 @@ export function createRootURL(source) {
168
177
  }
169
178
  ;
170
179
  export class ModuleScopeResolver {
171
- constructor(config) {
180
+ constructor(globalStack, provider, config) {
181
+ this.globalStack = globalStack;
182
+ this.provider = provider;
172
183
  this.config = config;
173
184
  this.modules = [];
174
185
  this.isValidHTTPUrl = (string) => {
@@ -217,6 +228,17 @@ export class ModuleScopeResolver {
217
228
  }
218
229
  const importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];
219
230
  if (!importedScope) {
231
+ // search in the file system provider
232
+ const javascriptSource = this.provider[source];
233
+ if (javascriptSource || javascriptSource == '') {
234
+ // module exists
235
+ const moduleProgram = JavaScriptParser.parse(javascriptSource, { mode: LanguageMode.Strict });
236
+ const stack = new Stack(this.globalStack, this, source);
237
+ // register with absoluteUrl
238
+ this.register(source, stack.getModule());
239
+ moduleProgram.get(stack);
240
+ return stack.getModule();
241
+ }
220
242
  throw new Error(`Can't find module scope`);
221
243
  }
222
244
  return importedScope;
@@ -232,13 +254,8 @@ export class ModuleScopeResolver {
232
254
  if (!this.config?.allowImportExternal) {
233
255
  throw new Error(`Error: Import External Module is not allowed.`);
234
256
  }
235
- const webScope = new WebModuleScope();
257
+ const webScope = new WebModuleScope(source, importCallOptions);
236
258
  this.modules.push([source, webScope]);
237
- // active later
238
- // import(source, importCallOptions)
239
- import(source).then(module => {
240
- webScope.updateContext(module);
241
- });
242
259
  return webScope;
243
260
  }
244
261
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,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;IAiCjB,YAAY,OAAgD,EAAE,QAA8B,EAAE,YAAqB;QAjBnH,iBAAY,GAAuB,EAAE,CAAC;QAQnB,qBAAgB,GAAmB,EAAE,CAAC;QAUxD,IAAI,KAAK,CAA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AE,CAAC,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,cAAc,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC9C;QACD,OAAO,cAAc,CAAC;IACvB,CAAC;IACS,qBAAqB,CAAC,MAAc,EAAE,iBAAqC;QACpF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SACjE;QACD,MAAM,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAA;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtC,eAAe;QACf,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YAC5B,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IACjB,CAAC;CAUD","sourcesContent":["import type { DeclarationExpression } from '../api/expression.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: Scope<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(globals?: Array<Scope<Context>> | Scope<Context>, resolver?: ModuleScopeResolver, moduleSource?: string) {\n\t\tif (Array.isArray(globals)) {\n\t\t\tthis.stack = globals;\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 {\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\treturn this.importModule(path);\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>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends Context>(context: T): Scope<T> {\n\t\tconst scope = Scope.for<T>(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScope<T extends Context>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScopeFor<T extends Context>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.for(context);\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 * \n\t */\n\tallowImportExternal?: boolean;\n\n};\nexport class ModuleScopeResolver implements ModuleScopeResolver {\n\tprotected modules: [string, ModuleScope][] = [];\n\tconstructor(protected config?: ResolverConfig) { }\n\tregister(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: 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\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()\n\t\tthis.modules.push([source, webScope]);\n\t\t// active later\n\t\t// import(source, importCallOptions)\n\t\timport(source).then(module => {\n\t\t\twebScope.updateContext(module);\n\t\t});\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;IAoCjB,YAAY,OAAwD,EAAE,QAA8B,EAAE,YAAqB;QApB3H,iBAAY,GAAuB,EAAE,CAAC;QAQnB,qBAAgB,GAAmB,EAAE,CAAC;QAaxD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;SAC7B;aAAM,IAAI,OAAO,YAAY,KAAK,EAAE;YACpC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;SACnC;aAAM,IAAI,OAAO,OAAO,IAAI,QAAQ,EAAE;YACtC,IAAI,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC;SACvB;aAAM;YACN,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;SAChB;QACD,IAAI,QAAQ,IAAI,YAAY,EAAE;YAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;YACjC,0CAA0C;YAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;YAC7D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACj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AAC,CAAC;gBACzB,OAAO,KAAK,CAAC,SAAS,EAAG,CAAC;aAC1B;YACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC3C;QACD,OAAO,aAAa,CAAC;IACtB,CAAC;IACS,iBAAiB,CAAC,WAAwB;QACnD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,cAAc,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC9C;QACD,OAAO,cAAc,CAAC;IACvB,CAAC;IACS,qBAAqB,CAAC,MAAc,EAAE,iBAAqC;QACpF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SACjE;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;CAUD","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: Scope<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 {\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>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends Context>(context: T): Scope<T> {\n\t\tconst scope = Scope.for<T>(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScope<T extends Context>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScopeFor<T extends Context>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.for(context);\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"]}
package/v8/inline.d.ts CHANGED
@@ -179,7 +179,9 @@ export declare class JavaScriptInlineParser extends AbstractParser {
179
179
  protected parseArguments(maybeArrow?: ParsingArrowHeadFlag): ExpressionNode[];
180
180
  protected parseAssignmentExpressionCoverGrammar(): ExpressionNode;
181
181
  protected parseAssignmentExpression(): ExpressionNode;
182
- protected parseArrowFunctionLiteral(parameters: ExpressionNode[], kind: FunctionKind): ExpressionNode;
182
+ private checkParamType;
183
+ private mapParams;
184
+ protected parseArrowFunctionLiteral(parameters: Param[], kind: FunctionKind): ExpressionNode;
183
185
  protected parseRegExpLiteral(): ExpressionNode;
184
186
  protected parseArrayLiteral(isPattern: boolean): ArrayExpression | ArrayPattern;
185
187
  protected parsePossibleDestructuringSubPattern(): ExpressionNode;
package/v8/inline.js CHANGED
@@ -1200,7 +1200,7 @@ export class JavaScriptInlineParser extends AbstractParser {
1200
1200
  // FormalParameter[Yield,GeneratorParameter] :
1201
1201
  // BindingElement[?Yield, ?GeneratorParameter]
1202
1202
  functionInfo.rest = this.check(Token.ELLIPSIS);
1203
- let pattern = this.parseBindingPattern(true);
1203
+ const pattern = this.parseBindingPattern(true);
1204
1204
  let initializer;
1205
1205
  if (this.check(Token.ASSIGN)) {
1206
1206
  if (functionInfo.rest) {
@@ -1209,10 +1209,10 @@ export class JavaScriptInlineParser extends AbstractParser {
1209
1209
  this.setAcceptIN(true);
1210
1210
  const value = this.parseAssignmentExpression();
1211
1211
  this.restoreAcceptIN();
1212
- initializer = new Param(pattern, value);
1212
+ initializer = new Param(this.checkParamType(pattern), value);
1213
1213
  }
1214
1214
  else {
1215
- initializer = new Param(pattern);
1215
+ initializer = new Param(this.checkParamType(pattern));
1216
1216
  }
1217
1217
  return initializer;
1218
1218
  }
@@ -1564,19 +1564,8 @@ export class JavaScriptInlineParser extends AbstractParser {
1564
1564
  this.setFunctionKind(kind);
1565
1565
  let arrow;
1566
1566
  if (expression instanceof SequenceExpression) {
1567
- const params = expression.getExpressions().map(expr => new Param(expr));
1568
- const last = params.at(-1)?.getIdentifier();
1569
- if (last instanceof SpreadElement) {
1570
- const arg = last.getArgument();
1571
- let param = arg;
1572
- if (arg instanceof ArrayExpression) {
1573
- param = new ArrayPattern(arg.getElements());
1574
- }
1575
- else if (arg instanceof ObjectExpression) {
1576
- param = new ObjectPattern(arg.getProperties());
1577
- }
1578
- params[params.length - 1] = new Param(new RestElement(param));
1579
- }
1567
+ const params = expression.getExpressions()
1568
+ .map(expr => new Param(expr));
1580
1569
  arrow = this.parseArrowFunctionLiteral(params, FunctionKind.NormalFunction);
1581
1570
  }
1582
1571
  else if (expression instanceof GroupingExpression) {
@@ -1620,7 +1609,31 @@ export class JavaScriptInlineParser extends AbstractParser {
1620
1609
  parseAssignmentExpression() {
1621
1610
  return this.parseAssignmentExpressionCoverGrammar();
1622
1611
  }
1612
+ checkParamType(identifier) {
1613
+ if (identifier instanceof ArrayExpression) {
1614
+ return new ArrayPattern(identifier.getElements());
1615
+ }
1616
+ else if (identifier instanceof ObjectExpression) {
1617
+ return new ObjectPattern(identifier.getProperties());
1618
+ }
1619
+ else if (identifier instanceof SpreadElement) {
1620
+ let arg = identifier.getArgument();
1621
+ // let param = arg;
1622
+ if (arg instanceof ArrayExpression) {
1623
+ arg = new ArrayPattern(arg.getElements());
1624
+ }
1625
+ else if (arg instanceof ObjectExpression) {
1626
+ arg = new ObjectPattern(arg.getProperties());
1627
+ }
1628
+ return new RestElement(arg);
1629
+ }
1630
+ return identifier;
1631
+ }
1632
+ mapParams(parameters) {
1633
+ return parameters.map(param => new Param(this.checkParamType(param.getIdentifier()), param.getDefaultValue()));
1634
+ }
1623
1635
  parseArrowFunctionLiteral(parameters, kind) {
1636
+ parameters = this.mapParams(parameters);
1624
1637
  if (this.peek().isNotType(Token.ARROW)) {
1625
1638
  throw new SyntaxError(this.errorMessage('SyntaxError Expecting Arrow Token'));
1626
1639
  }