@ibyar/expressions 0.5.2 → 0.5.4

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 (147) hide show
  1. package/README.md +3 -3
  2. package/api/abstract.d.ts +3 -4
  3. package/api/abstract.js +1 -1
  4. package/api/abstract.js.map +1 -1
  5. package/api/class/class.d.ts +196 -0
  6. package/api/class/class.js +594 -0
  7. package/api/class/class.js.map +1 -0
  8. package/api/class/decorator.d.ts +20 -0
  9. package/api/class/decorator.js +48 -0
  10. package/api/class/decorator.js.map +1 -0
  11. package/api/computing/call.d.ts +3 -1
  12. package/api/computing/call.js +16 -4
  13. package/api/computing/call.js.map +1 -1
  14. package/api/computing/new.d.ts +2 -1
  15. package/api/computing/new.js +4 -0
  16. package/api/computing/new.js.map +1 -1
  17. package/api/computing/rest.d.ts +3 -3
  18. package/api/computing/rest.js +5 -2
  19. package/api/computing/rest.js.map +1 -1
  20. package/api/computing/return.d.ts +2 -1
  21. package/api/computing/return.js +3 -0
  22. package/api/computing/return.js.map +1 -1
  23. package/api/computing/spread.d.ts +2 -1
  24. package/api/computing/spread.js +5 -2
  25. package/api/computing/spread.js.map +1 -1
  26. package/api/computing/throw.d.ts +2 -1
  27. package/api/computing/throw.js +3 -0
  28. package/api/computing/throw.js.map +1 -1
  29. package/api/computing/yield.d.ts +2 -1
  30. package/api/computing/yield.js +3 -0
  31. package/api/computing/yield.js.map +1 -1
  32. package/api/definition/array.d.ts +6 -7
  33. package/api/definition/array.js +13 -13
  34. package/api/definition/array.js.map +1 -1
  35. package/api/definition/bind.d.ts +2 -2
  36. package/api/definition/bind.js +1 -1
  37. package/api/definition/bind.js.map +1 -1
  38. package/api/definition/function.d.ts +8 -8
  39. package/api/definition/function.js +25 -25
  40. package/api/definition/function.js.map +1 -1
  41. package/api/definition/member.d.ts +2 -2
  42. package/api/definition/member.js +1 -1
  43. package/api/definition/member.js.map +1 -1
  44. package/api/definition/object.d.ts +7 -7
  45. package/api/definition/object.js +9 -9
  46. package/api/definition/object.js.map +1 -1
  47. package/api/definition/statement.d.ts +2 -2
  48. package/api/definition/statement.js +2 -2
  49. package/api/definition/statement.js.map +1 -1
  50. package/api/definition/values.d.ts +5 -4
  51. package/api/definition/values.js +7 -4
  52. package/api/definition/values.js.map +1 -1
  53. package/api/expression.d.ts +9 -12
  54. package/api/expression.js.map +1 -1
  55. package/api/{app → module/app}/program.d.ts +8 -9
  56. package/api/module/app/program.js +45 -0
  57. package/api/module/app/program.js.map +1 -0
  58. package/api/module/export.d.ts +60 -25
  59. package/api/module/export.js +230 -60
  60. package/api/module/export.js.map +1 -1
  61. package/api/module/import.d.ts +66 -25
  62. package/api/module/import.js +236 -68
  63. package/api/module/import.js.map +1 -1
  64. package/api/operators/assignment.d.ts +2 -2
  65. package/api/operators/assignment.js +1 -1
  66. package/api/operators/assignment.js.map +1 -1
  67. package/api/operators/await.d.ts +2 -2
  68. package/api/operators/await.js +1 -1
  69. package/api/operators/await.js.map +1 -1
  70. package/api/operators/binary.d.ts +2 -2
  71. package/api/operators/binary.js +1 -1
  72. package/api/operators/binary.js.map +1 -1
  73. package/api/operators/chaining.d.ts +2 -2
  74. package/api/operators/chaining.js +1 -1
  75. package/api/operators/chaining.js.map +1 -1
  76. package/api/operators/comma.d.ts +2 -2
  77. package/api/operators/comma.js +2 -2
  78. package/api/operators/comma.js.map +1 -1
  79. package/api/operators/grouping.d.ts +2 -2
  80. package/api/operators/grouping.js +1 -1
  81. package/api/operators/grouping.js.map +1 -1
  82. package/api/operators/logical.d.ts +2 -2
  83. package/api/operators/logical.js +1 -1
  84. package/api/operators/logical.js.map +1 -1
  85. package/api/operators/pipeline.d.ts +2 -2
  86. package/api/operators/pipeline.js +1 -1
  87. package/api/operators/pipeline.js.map +1 -1
  88. package/api/operators/ternary.d.ts +2 -2
  89. package/api/operators/ternary.js +1 -1
  90. package/api/operators/ternary.js.map +1 -1
  91. package/api/operators/unary.d.ts +3 -3
  92. package/api/operators/unary.js +4 -3
  93. package/api/operators/unary.js.map +1 -1
  94. package/api/operators/update.d.ts +2 -2
  95. package/api/operators/update.js +1 -1
  96. package/api/operators/update.js.map +1 -1
  97. package/api/statement/control/block.d.ts +3 -3
  98. package/api/statement/control/block.js +2 -2
  99. package/api/statement/control/block.js.map +1 -1
  100. package/api/statement/control/empty.d.ts +1 -1
  101. package/api/statement/control/empty.js.map +1 -1
  102. package/api/statement/control/if.d.ts +2 -2
  103. package/api/statement/control/if.js +1 -1
  104. package/api/statement/control/if.js.map +1 -1
  105. package/api/statement/control/switch.d.ts +4 -5
  106. package/api/statement/control/switch.js +5 -6
  107. package/api/statement/control/switch.js.map +1 -1
  108. package/api/statement/control/terminate.d.ts +3 -3
  109. package/api/statement/control/terminate.js +2 -2
  110. package/api/statement/control/terminate.js.map +1 -1
  111. package/api/statement/declarations/declares.d.ts +12 -11
  112. package/api/statement/declarations/declares.js +23 -18
  113. package/api/statement/declarations/declares.js.map +1 -1
  114. package/api/statement/iterations/for.d.ts +5 -5
  115. package/api/statement/iterations/for.js +7 -7
  116. package/api/statement/iterations/for.js.map +1 -1
  117. package/api/statement/iterations/while.d.ts +3 -3
  118. package/api/statement/iterations/while.js +2 -2
  119. package/api/statement/iterations/while.js.map +1 -1
  120. package/api/utils.d.ts +3 -0
  121. package/api/utils.js +2 -0
  122. package/api/utils.js.map +1 -0
  123. package/package.json +4 -4
  124. package/scope/finalizer.d.ts +4 -0
  125. package/scope/finalizer.js +11 -0
  126. package/scope/finalizer.js.map +1 -0
  127. package/scope/proxy.d.ts +2 -1
  128. package/scope/proxy.js +18 -2
  129. package/scope/proxy.js.map +1 -1
  130. package/scope/scope.d.ts +40 -51
  131. package/scope/scope.js +67 -134
  132. package/scope/scope.js.map +1 -1
  133. package/scope/stack.d.ts +41 -24
  134. package/scope/stack.js +148 -102
  135. package/scope/stack.js.map +1 -1
  136. package/v8/parser.js +3 -2
  137. package/v8/parser.js.map +1 -1
  138. package/visit/visitor.js +4 -7
  139. package/visit/visitor.js.map +1 -1
  140. package/api/app/class.d.ts +0 -117
  141. package/api/app/class.js +0 -292
  142. package/api/app/class.js.map +0 -1
  143. package/api/app/program.js +0 -39
  144. package/api/app/program.js.map +0 -1
  145. package/api/module/module.d.ts +0 -26
  146. package/api/module/module.js +0 -63
  147. package/api/module/module.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA2DA,MAAM,OAAO,KAAK;IAmCjB,YAAsB,OAAU,EAAS,IAAe;QAAlC,YAAO,GAAP,OAAO,CAAG;QAAS,SAAI,GAAJ,IAAI,CAAW;QAD9C,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IACQ,CAAC;IAlC7D,MAAM,CAAC,GAAG,CAAyB,OAAU,EAAE,IAAe;QAC7D,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,CAAC,aAAa,CAAyB,OAAU;QACtD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAyB,OAAU;QACzD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IACD,MAAM,CAAC,aAAa,CAAyB,OAAU;QACtD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,cAAc,CAAyB,OAAU;QACvD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,cAAc,CAAyB,OAAU;QACvD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,UAAU;QAChB,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE,OAAO,CAAC,CAAC;IACp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I,CAAC,QAAQ,EAAE;YAClB,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;SAC5C;aAAM;YACN,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC;SACpC;IACF,CAAC;IACD,MAAM;QACL,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACvB,CAAC;IACD,QAAQ;QACP,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC;IACD,WAAW,CAAC,WAAqB,EAAE,aAAmB;QACrD,IAAI,WAAW,EAAE;YAChB,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YACvC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YACjD,OAAO;SACP;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAChD,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["\nexport type ScopeType = 'block' | 'function' | 'class' | 'module' | 'global';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * scope type\n\t */\n\ttype: ScopeType;\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tget(propertyKey: keyof T): any;\n\n\t/**\n\t * set the value of `propertyKey` in current context, could be instilled with `value`.\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: keyof T, value?: any, receiver?: any): boolean;\n\n\t/**\n\t * is current context has `propertyKey` in hash map keys\n\t * @param propertyKey \n\t */\n\thas(propertyKey: keyof T): boolean;\n\n\t/**\n\t * delete property from context\n\t * @param propertyKey \n\t */\n\tdelete(propertyKey: keyof T): boolean;\n\n\t/**\n\t * get current context object of this scope\n\t */\n\tgetContext(): T;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if the current value is not type od `object`, will return `undefined`.\n\t * @param propertyKey the name of the property\n\t */\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if no scope found in the cache, will create a new one, add this one to the map, return a reference.\n\t * @param propertyKey\n\t */\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;\n}\n\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new Scope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'global');\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tconstructor(protected context: T, public type: ScopeType) { }\n\tget(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: keyof T): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this.context, propertyKey);\n\t}\n\tgetContext(): T {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V> {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReadOnlyScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'global');\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>) { }\n\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 propertiesLock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.propertiesLock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this.subscribers.get(propertyKey);\n\t\tif (!subscribers) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.push(propertyKey);\n\t\tsubscribers?.forEach(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.propertiesLock.pop() !== propertyKey) {\n\t\t\tconsole.error('lock error');\n\t\t};\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\tconst subscription: ScopeSubscription<T> = new ScopeSubscription(propertyKey, this);\n\t\tlet propertySubscribers = this.subscribers.get(propertyKey);\n\t\tif (!propertySubscribers) {\n\t\t\tpropertySubscribers = new Map();\n\t\t\tthis.subscribers.set(propertyKey, propertySubscribers);\n\t\t}\n\t\tpropertySubscribers.set(subscription, { callback, 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 * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis.subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReactiveScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'global');\n\t}\n\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\n\tconstructor(context: T, type: ScopeType);\n\tconstructor(context: T, type: ScopeType, name: string, parent: ReactiveScope<any>);\n\tconstructor(context: T, type: ScopeType, protected name?: string, protected parent?: ReactiveScope<any>) {\n\t\tsuper(context, type);\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.emit(propertyKey, newValue, oldValue);\n\t\t}\n\t\treturn result;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this.context, propertyKey);\n\t\tif (isDelete && oldValue !== undefined) {\n\t\t\tthis.emit(propertyKey, undefined, oldValue);\n\t\t}\n\t\treturn isDelete;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, 'block', propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, 'block', propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tthis.observer.emit(propertyKey, newValue, oldValue);\n\t\tthis.parent?.emit(this.name!, this.context);\n\t}\n\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}\n\n/**\n * used control/notify/pause scope about changes in current context\n */\nexport interface ScopeControl<T extends ScopeContext> {\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\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReactiveScopeControl(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'global');\n\t}\n\n\tprotected attached: boolean = true;\n\tprotected marked: ScopeContext = {};\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 {\n\t\t\tthis.marked[propertyKey] = newValue;\n\t\t}\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\tObject.keys(latestChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, latestChanges[propertyKey]);\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA4DA,MAAM,OAAO,KAAK;IASjB,YAAsB,OAAU,EAAE,YAA0B;QAAtC,YAAO,GAAP,OAAO,CAAG;QAFtB,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;QAGnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE;YACrC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAoB,EAAW,EAAE;gBAC5C,OAAO,IAAI,CAAC,YAAa,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YACjD,CAAC,CAAC;SACF;IACF,CAAC;IAfD,MAAM,CAAC,GAAG,CAAyB,OAAU,EAAE,YAA0B;QACxE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,CAAC,UAAU,CAAyB,YAA0B;QACnE,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE,YAAY,CAAC,CAAC;IACzC,CAAC;IAWD,GAAG,CAAC,WAAoB;QACvB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,GA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AC;IACD,WAAW,CAAC,WAAqB,EAAE,aAAmB;QACrD,IAAI,WAAW,EAAE;YAChB,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YACvC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YACjD,OAAO;SACP;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAChD,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACJ,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,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;CACD;AACD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C;QACC,KAAK,CAAC,EAAmB,CAAC,CAAC;IAC5B,CAAC;IACD,aAAa,CAAC,OAAY;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD","sourcesContent":["import { TypeOf } from '../api/utils.js';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\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\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if no scope found in the cache, will create a new one, add this one to the map, return a reference.\n\t * @param propertyKey\n\t */\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;\n\n\tgetClass(): TypeOf<Scope<ScopeContext>>;\n}\n\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope({} as T, propertyKeys);\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tprotected propertyKeys?: (keyof T)[];\n\tconstructor(protected context: T, propertyKeys?: (keyof T)[]) {\n\t\tthis.propertyKeys = propertyKeys;\n\t\tif (Array.isArray(this.propertyKeys)) {\n\t\t\tthis.has = (propertyKey: keyof T): boolean => {\n\t\t\t\treturn this.propertyKeys!.includes(propertyKey);\n\t\t\t};\n\t\t}\n\t}\n\tget(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: keyof T): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this.context, propertyKey);\n\t}\n\tgetContext(): T {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V> {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetClass(): TypeOf<Scope<ScopeContext>> {\n\t\treturn Scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(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<ScopeContext>> {\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 propertiesLock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.propertiesLock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this.subscribers.get(propertyKey);\n\t\tif (!subscribers || subscribers.size == 0) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.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.propertiesLock.pop() !== propertyKey) {\n\t\t\tconsole.error('lock error');\n\t\t};\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\tconst subscription: ScopeSubscription<T> = new ScopeSubscription(propertyKey, this);\n\t\tlet propertySubscribers = this.subscribers.get(propertyKey);\n\t\tif (!propertySubscribers) {\n\t\t\tpropertySubscribers = new Map();\n\t\t\tthis.subscribers.set(propertyKey, propertySubscribers);\n\t\t}\n\t\tpropertySubscribers.set(subscription, { callback, 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 * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis.subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope({} as T, propertyKeys);\n\t}\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\tprotected name?: string;\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name: string, parent: ReactiveScope<any>, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name?: string | (keyof T)[], protected parent?: ReactiveScope<any>, propertyKeys?: (keyof T)[]) {\n\t\tsuper(context, Array.isArray(name) ? name : propertyKeys);\n\t\tif (typeof name == 'string') {\n\t\t\tthis.name = name;\n\t\t}\n\t\tif (Array.isArray(name)) {\n\t\t\tthis.propertyKeys = name;\n\t\t}\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.emit(propertyKey, newValue, oldValue);\n\t\t}\n\t\treturn result;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this.context, propertyKey);\n\t\tif (isDelete && oldValue !== undefined) {\n\t\t\tthis.emit(propertyKey, undefined, oldValue);\n\t\t}\n\t\treturn isDelete;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\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.context);\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\tgetClass(): TypeOf<ReactiveScope<ScopeContext>> {\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 ScopeContext> {\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\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl({} as T, propertyKeys);\n\t}\n\n\tprotected attached: boolean = true;\n\tprotected marked: ScopeContext = {};\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 {\n\t\t\tthis.marked[propertyKey] = newValue;\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\tObject.keys(latestChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, latestChanges[propertyKey]);\n\t\t});\n\t}\n\tgetClass(): TypeOf<ReactiveScopeControl<ScopeContext>> {\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 ScopeContext {\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.scopeMap.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.context = context;\n\t}\n}\n"]}
package/scope/stack.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import type { CanDeclareExpression } from '../api/expression.js';
2
- import { ReactiveScope, Scope, ScopeContext, ScopeType } from './scope.js';
2
+ import { ModuleScope, ReactiveScope, Scope, ScopeContext, WebModuleScope } from './scope.js';
3
3
  export interface AwaitPromiseInfo {
4
4
  promise: Promise<any>;
5
5
  node: CanDeclareExpression;
6
6
  declareVariable: boolean;
7
- scopeType: ScopeType;
8
7
  }
9
8
  export interface AsyncIterableInfo {
10
9
  iterable: AsyncIterable<any>;
@@ -16,7 +15,7 @@ export interface Stack {
16
15
  has(propertyKey: PropertyKey): boolean;
17
16
  get(propertyKey: PropertyKey): any;
18
17
  set(propertyKey: PropertyKey, value: any, receiver?: any): boolean;
19
- declareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any): any;
18
+ declareVariable(propertyKey: PropertyKey, propertyValue?: any): any;
20
19
  findScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;
21
20
  resolveAwait(value: AwaitPromiseInfo): void;
22
21
  lastScope<T extends ScopeContext>(): Scope<T>;
@@ -26,32 +25,50 @@ export interface Stack {
26
25
  removeScope<T extends ScopeContext>(scope: Scope<T>): void;
27
26
  pushScope<T extends ScopeContext>(scope: Scope<T>): void;
28
27
  pushBlockScope<T extends ScopeContext>(): Scope<T>;
29
- pushFunctionScope<T extends ScopeContext>(): Scope<T>;
30
28
  pushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;
31
- pushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T>;
32
- pushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
33
- pushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
34
- pushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
35
- pushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
29
+ pushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
30
+ pushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
36
31
  copyStack(): Stack;
32
+ detach(): void;
33
+ reattach(): void;
34
+ importModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
35
+ getModule(): ModuleScope | undefined;
36
+ onDestroy(action: () => void): void;
37
37
  }
38
38
  export declare class Stack implements Stack {
39
- static for(...contexts: Scope<any>[]): Stack;
40
- static forScopes(...scopes: Scope<any>[]): Stack;
39
+ static for(...contexts: Scope<ScopeContext>[]): Stack;
40
+ static forScopes(...scopes: Scope<ScopeContext>[]): Stack;
41
+ static moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<ScopeContext>[]): Stack;
41
42
  awaitPromise: AwaitPromiseInfo[];
42
43
  forAwaitAsyncIterable?: AsyncIterableInfo | undefined;
43
44
  protected readonly stack: Array<Scope<any>>;
44
- constructor(stack?: Array<Scope<any>>);
45
- pushClassScope<T extends ScopeContext>(): Scope<T>;
46
- pushModuleScope<T extends ScopeContext>(): Scope<T>;
47
- pushGlobalScope<T extends ScopeContext>(): Scope<T>;
48
- pushClassScopeFor<T extends ScopeContext>(context: T): Scope<T>;
49
- pushModuleScopeFor<T extends ScopeContext>(context: T): Scope<T>;
50
- pushGlobalScopeFor<T extends ScopeContext>(context: T): Scope<T>;
51
- pushClassReactiveScope<T extends ScopeContext>(): Scope<T>;
52
- pushModuleReactiveScope<T extends ScopeContext>(): Scope<T>;
53
- pushGlobalReactiveScope<T extends ScopeContext>(): Scope<T>;
54
- pushClassReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
55
- pushModuleReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
56
- pushGlobalReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
45
+ protected readonly moduleScope?: ModuleScope;
46
+ protected readonly moduleSource?: string;
47
+ protected readonly resolver?: ModuleScopeResolver;
48
+ protected readonly onDestroyActions: (() => void)[];
49
+ constructor();
50
+ constructor(globalScope: Scope<ScopeContext>);
51
+ constructor(globalScope: Scope<ScopeContext>, resolver: ModuleScopeResolver, moduleSource: string);
52
+ constructor(stack: Array<Scope<ScopeContext>>);
53
+ constructor(stack: Array<Scope<ScopeContext>>, resolver: ModuleScopeResolver, moduleSource: string);
54
+ private initModuleContext;
55
+ private getReactiveScopeControls;
56
+ }
57
+ export interface ModuleScopeResolver {
58
+ resolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;
59
+ resolveURL(specified: string, parent: string | URL): string;
60
+ }
61
+ export declare function createRootURL(source: string): URL;
62
+ export interface ResolverConfig {
63
+ allowImportExternal?: boolean;
64
+ }
65
+ export declare class ModuleScopeResolver implements ModuleScopeResolver {
66
+ protected config?: ResolverConfig | undefined;
67
+ protected modules: [string, ModuleScope][];
68
+ constructor(config?: ResolverConfig | undefined);
69
+ register(source: string, moduleScope: ModuleScope): void;
70
+ protected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
71
+ protected findSourceByScope(moduleScope: ModuleScope): string;
72
+ protected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope;
73
+ protected readonly isValidHTTPUrl: (string: string) => boolean;
57
74
  }
package/scope/stack.js CHANGED
@@ -1,20 +1,57 @@
1
- import { ReactiveScope, Scope } from './scope.js';
1
+ import { finalizerRegister } from './finalizer.js';
2
+ import { ModuleScope, ReactiveScope, ReactiveScopeControl, Scope, WebModuleScope } from './scope.js';
2
3
  export class Stack {
3
- constructor(stack) {
4
- this.stack = stack ?? [Scope.functionScope()];
4
+ constructor(globals, resolver, moduleSource) {
5
+ this.onDestroyActions = [];
6
+ if (Array.isArray(globals)) {
7
+ this.stack = globals;
8
+ }
9
+ else if (typeof globals == 'object') {
10
+ this.stack = [globals];
11
+ }
12
+ else {
13
+ this.stack = [];
14
+ }
15
+ if (resolver && moduleSource) {
16
+ this.resolver = resolver;
17
+ this.moduleSource = moduleSource;
18
+ this.moduleScope = new ModuleScope(this.initModuleContext());
19
+ this.pushScope(this.moduleScope);
20
+ this.pushReactiveScope();
21
+ }
22
+ else {
23
+ this.pushBlockScope();
24
+ }
25
+ finalizerRegister(this, this.onDestroyActions, this);
5
26
  }
6
27
  static for(...contexts) {
7
28
  if (contexts.length === 0) {
8
29
  return new Stack();
9
30
  }
10
- return new Stack(contexts.map(context => new Scope(context, 'global')));
31
+ return new Stack(contexts.map(context => new Scope(context)));
11
32
  }
12
33
  static forScopes(...scopes) {
13
34
  if (scopes.length === 0) {
14
- scopes.push(Scope.functionScope());
35
+ scopes.push(Scope.blockScope());
15
36
  }
16
37
  return new Stack(scopes);
17
38
  }
39
+ static moduleScope(resolver, moduleSource, ...globalScopes) {
40
+ return new Stack(globalScopes, resolver, moduleSource);
41
+ }
42
+ initModuleContext() {
43
+ const importFunc = (path) => {
44
+ return this.importModule(path);
45
+ };
46
+ importFunc.meta = {
47
+ url: createRootURL(this.moduleSource),
48
+ resolve: (specified, parent) => {
49
+ return Promise.resolve(this.resolver.resolveURL(specified, parent ?? importFunc.meta.url));
50
+ }
51
+ };
52
+ const im = importFunc;
53
+ return { import: im };
54
+ }
18
55
  has(propertyKey) {
19
56
  return this.stack.find(context => context.has(propertyKey)) ? true : false;
20
57
  }
@@ -24,18 +61,8 @@ export class Stack {
24
61
  set(propertyKey, value, receiver) {
25
62
  return this.findScope(propertyKey).set(propertyKey, value, receiver);
26
63
  }
27
- declareVariable(scopeType, propertyKey, propertyValue) {
28
- if (scopeType === 'block') {
29
- return this.lastScope().set(propertyKey, propertyValue);
30
- }
31
- let lastIndex = this.stack.length;
32
- while (lastIndex--) {
33
- const scope = this.stack[lastIndex];
34
- if (scope.type === scopeType) {
35
- scope.set(propertyKey, propertyValue);
36
- break;
37
- }
38
- }
64
+ declareVariable(propertyKey, propertyValue) {
65
+ return this.lastScope().set(propertyKey, propertyValue);
39
66
  }
40
67
  findScope(propertyKey) {
41
68
  let lastIndex = this.stack.length;
@@ -65,98 +92,18 @@ export class Stack {
65
92
  this.stack.push(scope);
66
93
  return scope;
67
94
  }
68
- pushFunctionScope() {
69
- const scope = Scope.functionScope();
70
- this.stack.push(scope);
71
- return scope;
72
- }
73
- pushClassScope() {
74
- const scope = Scope.classScope();
75
- this.stack.push(scope);
76
- return scope;
77
- }
78
- pushModuleScope() {
79
- const scope = Scope.moduleScope();
80
- this.stack.push(scope);
81
- return scope;
82
- }
83
- pushGlobalScope() {
84
- const scope = Scope.globalScope();
85
- this.stack.push(scope);
86
- return scope;
87
- }
88
95
  pushBlockScopeFor(context) {
89
- const scope = Scope.blockScopeFor(context);
90
- this.stack.push(scope);
91
- return scope;
92
- }
93
- pushFunctionScopeFor(context) {
94
- const scope = Scope.functionScopeFor(context);
96
+ const scope = Scope.for(context);
95
97
  this.stack.push(scope);
96
98
  return scope;
97
99
  }
98
- pushClassScopeFor(context) {
99
- const scope = Scope.classScopeFor(context);
100
- this.stack.push(scope);
101
- return scope;
102
- }
103
- pushModuleScopeFor(context) {
104
- const scope = Scope.moduleScopeFor(context);
105
- this.stack.push(scope);
106
- return scope;
107
- }
108
- pushGlobalScopeFor(context) {
109
- const scope = Scope.globalScopeFor(context);
110
- this.stack.push(scope);
111
- return scope;
112
- }
113
- pushBlockReactiveScope() {
100
+ pushReactiveScope() {
114
101
  const scope = ReactiveScope.blockScope();
115
102
  this.stack.push(scope);
116
103
  return scope;
117
104
  }
118
- pushFunctionReactiveScope() {
119
- const scope = ReactiveScope.functionScope();
120
- this.stack.push(scope);
121
- return scope;
122
- }
123
- pushClassReactiveScope() {
124
- const scope = ReactiveScope.classScope();
125
- this.stack.push(scope);
126
- return scope;
127
- }
128
- pushModuleReactiveScope() {
129
- const scope = ReactiveScope.moduleScope();
130
- this.stack.push(scope);
131
- return scope;
132
- }
133
- pushGlobalReactiveScope() {
134
- const scope = ReactiveScope.globalScope();
135
- this.stack.push(scope);
136
- return scope;
137
- }
138
- pushBlockReactiveScopeFor(context) {
139
- const scope = ReactiveScope.blockScopeFor(context);
140
- this.stack.push(scope);
141
- return scope;
142
- }
143
- pushFunctionReactiveScopeFor(context) {
144
- const scope = ReactiveScope.functionScopeFor(context);
145
- this.stack.push(scope);
146
- return scope;
147
- }
148
- pushClassReactiveScopeFor(context) {
149
- const scope = ReactiveScope.classScopeFor(context);
150
- this.stack.push(scope);
151
- return scope;
152
- }
153
- pushModuleReactiveScopeFor(context) {
154
- const scope = ReactiveScope.moduleScopeFor(context);
155
- this.stack.push(scope);
156
- return scope;
157
- }
158
- pushGlobalReactiveScopeFor(context) {
159
- const scope = ReactiveScope.globalScopeFor(context);
105
+ pushReactiveScopeFor(context) {
106
+ const scope = ReactiveScope.for(context);
160
107
  this.stack.push(scope);
161
108
  return scope;
162
109
  }
@@ -180,7 +127,106 @@ export class Stack {
180
127
  return true;
181
128
  }
182
129
  copyStack() {
183
- return new Stack(this.stack.slice());
130
+ return new Stack(this.stack.slice(), this.resolver, this.moduleSource);
131
+ }
132
+ detach() {
133
+ this.getReactiveScopeControls().forEach(scope => scope.detach());
134
+ }
135
+ reattach() {
136
+ this.getReactiveScopeControls().forEach(scope => scope.reattach());
137
+ }
138
+ getReactiveScopeControls() {
139
+ return this.stack.filter(scope => scope instanceof ReactiveScopeControl);
140
+ }
141
+ importModule(source, importCallOptions) {
142
+ if (!this.resolver || !this.moduleScope) {
143
+ throw new Error('Module Resolver is undefined');
144
+ }
145
+ return this.resolver.resolve(source, this.moduleScope, importCallOptions);
146
+ }
147
+ getModule() {
148
+ return this.moduleScope;
149
+ }
150
+ onDestroy(action) {
151
+ this.onDestroyActions.push(action);
152
+ }
153
+ }
154
+ const ROOT_URL = 'https://root';
155
+ export function createRootURL(source) {
156
+ return new URL(source, ROOT_URL);
157
+ }
158
+ ;
159
+ export class ModuleScopeResolver {
160
+ constructor(config) {
161
+ this.config = config;
162
+ this.modules = [];
163
+ this.isValidHTTPUrl = (string) => {
164
+ let url;
165
+ try {
166
+ url = new URL(string);
167
+ }
168
+ catch (e) {
169
+ return false;
170
+ }
171
+ return url.protocol === 'http:' || url.protocol === 'https:';
172
+ };
173
+ }
174
+ register(source, moduleScope) {
175
+ const stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);
176
+ if (stackInfo) {
177
+ stackInfo[1] = moduleScope;
178
+ }
179
+ else {
180
+ this.modules.push([source, moduleScope]);
181
+ }
182
+ }
183
+ resolve(source, moduleScope, importCallOptions) {
184
+ if (this.isValidHTTPUrl(source)) {
185
+ return this.resolveExternalModule(source, importCallOptions);
186
+ }
187
+ if (source.startsWith('/')) {
188
+ return this.findScopeBySource(source, importCallOptions);
189
+ }
190
+ const currentSource = this.findSourceByScope(moduleScope);
191
+ const absoluteUrl = this.resolveURL(source, currentSource);
192
+ return this.findScopeBySource(absoluteUrl, importCallOptions);
193
+ }
194
+ resolveURL(specified, parent) {
195
+ const currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;
196
+ const importedUrl = new URL(specified, currentUrl).href;
197
+ const absoluteUrl = importedUrl.replace(ROOT_URL, '');
198
+ return absoluteUrl;
199
+ }
200
+ findScopeBySource(source, importCallOptions) {
201
+ if (importCallOptions?.assert?.type) {
202
+ const type = importCallOptions.assert.type;
203
+ if (!source.endsWith(`.${type}`)) {
204
+ throw new Error(`Can't find module scope`);
205
+ }
206
+ }
207
+ const importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];
208
+ if (!importedScope) {
209
+ throw new Error(`Can't find module scope`);
210
+ }
211
+ return importedScope;
212
+ }
213
+ findSourceByScope(moduleScope) {
214
+ const importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];
215
+ if (!importedSource) {
216
+ throw new Error(`Can't resolve scope source`);
217
+ }
218
+ return importedSource;
219
+ }
220
+ resolveExternalModule(source, importCallOptions) {
221
+ if (!this.config?.allowImportExternal) {
222
+ throw new Error(`Error: Import External Module is not allowed.`);
223
+ }
224
+ const webScope = new WebModuleScope();
225
+ this.modules.push([source, webScope]);
226
+ import(source).then(module => {
227
+ webScope.updateContext(module);
228
+ });
229
+ return webScope;
184
230
  }
185
231
  }
186
232
  //# sourceMappingURL=stack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,EAA2B,MAAM,YAAY,CAAC;AAuH3E,MAAM,OAAO,KAAK;IAkBjB,YAAY,KAAyB;QACpC,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC/C,CAAC;IAnBD,MAAM,CAAC,GAAG,CAAC,GAAG,QAA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,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACjB,OAAO,KAAK,CAAC;SACb;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,SAAS;QACR,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC;CACD","sourcesContent":["import type { CanDeclareExpression } from '../api/expression.js';\nimport { ReactiveScope, Scope, ScopeContext, ScopeType } from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: CanDeclareExpression;\n\n\tdeclareVariable: boolean;\n\tscopeType: ScopeType;\n}\n\nexport interface AsyncIterableInfo {\n\titerable: AsyncIterable<any>;\n\tforAwaitBody: (iterator: any) => any;\n}\n\nexport interface Stack {\n\t/**\n\t * a list of promises to resolve in an 'async' scope as 'async function'\n\t */\n\tawaitPromise: Array<AwaitPromiseInfo>;\n\n\t/**\n\t * resolve await promise in 'await for in' scope\n\t */\n\tforAwaitAsyncIterable?: AsyncIterableInfo;\n\n\t/**\n\t * is this stack has a propertyKey\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get the first value for provided property key,\n\t * \n\t * will search current stack in all scope till find the first key, else undefined\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in its context provider with `value`.\n\t * else define it in the first scope 'local scope'\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean;\n\n\t/**\n\t * declare variable in stack by scope type,\n\t * \n\t * 'block' for the first scop ==> may be 'block' or 'function' scope\n\t * \n\t * 'function' will search for the first scope with scope type 'function'\n\t * then define a property key with 'initial' value in thus scope\n\t * @param scopeType \"function\" | \"block\"\n\t * @param propertyKey the name of property mey be string | number | symbol, \n\t * @param propertyValue if not exist will be initialize with 'undefined' value\n\t */\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any): any;\n\n\n\t/**\n\t * get context object of this provider,\n\t * search for the first context object that has `propertyKey`.\n\t * \n\t * search for the first context that have property key,\n\t * if not found will return the stack local scop as a default value\n\t * @param propertyKey the property key\n\t */\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends ScopeContext>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends ScopeContext>(): Scope<T>;\n\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushFunctionScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\tpushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\n\tpushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\tpushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\tcopyStack(): Stack;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Scope<any>[]): Stack {\n\t\tif (contexts.length === 0) {\n\t\t\treturn new Stack();\n\t\t}\n\t\treturn new Stack(contexts.map(context => new Scope(context, 'global')));\n\t}\n\tstatic forScopes(...scopes: Scope<any>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.functionScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tawaitPromise: AwaitPromiseInfo[];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\n\tconstructor(stack?: Array<Scope<any>>) {\n\t\tthis.stack = stack ?? [Scope.functionScope()];\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn this.stack.find(context => context.has(propertyKey)) ? true : false;\n\t}\n\tget(propertyKey: PropertyKey) {\n\t\treturn this.findScope<ScopeContext>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<ScopeContext>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any) {\n\t\tif (scopeType === 'block') {\n\t\t\treturn this.lastScope<ScopeContext>().set(propertyKey, propertyValue);\n\t\t}\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.type === scopeType) {\n\t\t\t\tscope.set(propertyKey, propertyValue);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice());\n\t}\n}\n"]}
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,EAAgB,cAAc,EACzD,MAAM,YAAY,CAAC;AAyIpB,MAAM,OAAO,KAAK;IAiCjB,YAAY,OAA0D,EAAE,QAA8B,EAAE,YAAqB;QAT1G,qBAAgB,GAAmB,EAAE,CAAC;QAUxD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;SACrB;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;YAEjC,IAAI,CAAC,WAAW,GAAG,IA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E,CAAC,EAAE;gBACjC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;aAC3C;SACD;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,aAAa,EAAE;YACnB,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,EAAE,CAAA;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QAGtC,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 { CanDeclareExpression } from '../api/expression.js';\nimport { finalizerRegister } from './finalizer.js';\nimport {\n\tModuleContext, ModuleImport, ModuleScope, ReactiveScope,\n\tReactiveScopeControl, Scope, ScopeContext, WebModuleScope\n} from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: CanDeclareExpression;\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 ScopeContext>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends ScopeContext>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends ScopeContext>(): Scope<T>;\n\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\tpushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushReactiveScopeFor<T extends ScopeContext>(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<ScopeContext>[]): 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<ScopeContext>(context)));\n\t}\n\tstatic forScopes(...scopes: Scope<ScopeContext>[]): 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<ScopeContext>[]) {\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<ScopeContext>);\n\tconstructor(globalScope: Scope<ScopeContext>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Array<Scope<ScopeContext>>);\n\tconstructor(stack: Array<Scope<ScopeContext>>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(globals?: Array<Scope<ScopeContext>> | Scope<ScopeContext>, 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<ScopeContext>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<ScopeContext>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any) {\n\t\treturn this.lastScope<ScopeContext>().set(propertyKey, propertyValue);\n\t}\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends ScopeContext>(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 ScopeContext>(): 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 ScopeContext>(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 ScopeContext>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice(), 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\tprivate getReactiveScopeControls(): ReactiveScopeControl<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScopeControl) as ReactiveScopeControl<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"]}
package/v8/parser.js CHANGED
@@ -21,7 +21,7 @@ import { SwitchCase, DefaultExpression, SwitchStatement } from '../api/statement
21
21
  import { BreakStatement, ContinueStatement } from '../api/statement/control/terminate.js';
22
22
  import { ReturnStatement } from '../api/computing/return.js';
23
23
  import { YieldExpression } from '../api/computing/yield.js';
24
- import { VariableNode, VariableDeclarationNode } from '../api/statement/declarations/declares.js';
24
+ import { VariableDeclarator, VariableDeclarationNode } from '../api/statement/declarations/declares.js';
25
25
  import { ForNode, ForOfNode, ForInNode, ForAwaitOfNode } from '../api/statement/iterations/for.js';
26
26
  import { ConditionalExpression } from '../api/operators/ternary.js';
27
27
  import { PipelineExpression } from '../api/operators/pipeline.js';
@@ -566,6 +566,7 @@ export class JavaScriptParser extends AbstractParser {
566
566
  case Token.VAR:
567
567
  this.consume(token);
568
568
  mode = 'var';
569
+ break;
569
570
  case Token.LET:
570
571
  default:
571
572
  this.consume(token);
@@ -593,7 +594,7 @@ export class JavaScriptParser extends AbstractParser {
593
594
  throw new Error(this.errorMessage(`Declaration Missing Initializer : ${this.position()}`));
594
595
  }
595
596
  }
596
- variables.push(new VariableNode(name, value));
597
+ variables.push(new VariableDeclarator(name, value));
597
598
  } while (this.check(Token.COMMA));
598
599
  return new VariableDeclarationNode(variables, mode);
599
600
  }