@ibyar/expressions 0.5.2 → 0.5.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -3
- package/api/abstract.d.ts +5 -6
- package/api/abstract.js +8 -3
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +227 -0
- package/api/class/class.js +662 -0
- package/api/class/class.js.map +1 -0
- package/api/class/decorator.d.ts +20 -0
- package/api/class/decorator.js +48 -0
- package/api/class/decorator.js.map +1 -0
- package/api/computing/call.d.ts +3 -1
- package/api/computing/call.js +16 -4
- package/api/computing/call.js.map +1 -1
- package/api/computing/debugger.d.ts +15 -0
- package/api/computing/debugger.js +35 -0
- package/api/computing/debugger.js.map +1 -0
- package/api/computing/new.d.ts +2 -1
- package/api/computing/new.js +4 -0
- package/api/computing/new.js.map +1 -1
- package/api/computing/rest.d.ts +6 -6
- package/api/computing/rest.js +5 -2
- package/api/computing/rest.js.map +1 -1
- package/api/computing/return.d.ts +6 -1
- package/api/computing/return.js +8 -0
- package/api/computing/return.js.map +1 -1
- package/api/computing/spread.d.ts +2 -1
- package/api/computing/spread.js +5 -2
- package/api/computing/spread.js.map +1 -1
- package/api/computing/throw.d.ts +6 -1
- package/api/computing/throw.js +7 -0
- package/api/computing/throw.js.map +1 -1
- package/api/computing/yield.d.ts +2 -1
- package/api/computing/yield.js +3 -0
- package/api/computing/yield.js.map +1 -1
- package/api/definition/array.d.ts +12 -12
- package/api/definition/array.js +31 -25
- package/api/definition/array.js.map +1 -1
- package/api/definition/bind.d.ts +8 -2
- package/api/definition/bind.js +7 -1
- package/api/definition/bind.js.map +1 -1
- package/api/definition/function.d.ts +40 -51
- package/api/definition/function.js +292 -309
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.d.ts +2 -2
- package/api/definition/member.js +1 -1
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.d.ts +15 -12
- package/api/definition/object.js +43 -13
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +2 -2
- package/api/definition/statement.js +7 -3
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +44 -50
- package/api/definition/values.js +87 -149
- package/api/definition/values.js.map +1 -1
- package/api/deserialize/deserialize.d.ts +7 -1
- package/api/deserialize/deserialize.js +9 -1
- package/api/deserialize/deserialize.js.map +1 -1
- package/api/deserialize/type-store.d.ts +2 -2
- package/api/deserialize/type-store.js.map +1 -1
- package/api/expression.d.ts +159 -18
- package/api/expression.js.map +1 -1
- package/api/index.d.ts +2 -0
- package/api/index.js +2 -0
- package/api/index.js.map +1 -1
- package/api/module/common.d.ts +29 -0
- package/api/module/common.js +71 -0
- package/api/module/common.js.map +1 -0
- package/api/module/export.d.ts +129 -25
- package/api/module/export.js +333 -58
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +114 -25
- package/api/module/import.js +279 -68
- package/api/module/import.js.map +1 -1
- package/api/operators/assignment.d.ts +2 -2
- package/api/operators/assignment.js +1 -1
- package/api/operators/assignment.js.map +1 -1
- package/api/operators/await.d.ts +2 -2
- package/api/operators/await.js +1 -1
- package/api/operators/await.js.map +1 -1
- package/api/operators/binary.d.ts +2 -2
- package/api/operators/binary.js +1 -1
- package/api/operators/binary.js.map +1 -1
- package/api/operators/chaining.d.ts +2 -2
- package/api/operators/chaining.js +1 -1
- package/api/operators/chaining.js.map +1 -1
- package/api/operators/comma.d.ts +2 -2
- package/api/operators/comma.js +2 -2
- package/api/operators/comma.js.map +1 -1
- package/api/operators/grouping.d.ts +9 -2
- package/api/operators/grouping.js +8 -1
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/logical.d.ts +2 -2
- package/api/operators/logical.js +1 -1
- package/api/operators/logical.js.map +1 -1
- package/api/operators/pipeline.d.ts +14 -2
- package/api/operators/pipeline.js +13 -1
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/ternary.d.ts +2 -2
- package/api/operators/ternary.js +1 -1
- package/api/operators/ternary.js.map +1 -1
- package/api/operators/unary.d.ts +3 -3
- package/api/operators/unary.js +7 -3
- package/api/operators/unary.js.map +1 -1
- package/api/operators/update.d.ts +2 -2
- package/api/operators/update.js +1 -1
- package/api/operators/update.js.map +1 -1
- package/api/{app/program.d.ts → program.d.ts} +8 -9
- package/api/program.js +45 -0
- package/api/program.js.map +1 -0
- package/api/statement/control/block.d.ts +8 -5
- package/api/statement/control/block.js +26 -23
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +8 -1
- package/api/statement/control/empty.js +7 -0
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +7 -2
- package/api/statement/control/if.js +6 -1
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +10 -5
- package/api/statement/control/switch.js +22 -9
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +46 -13
- package/api/statement/control/terminate.js +89 -20
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/declarations/declares.d.ts +17 -16
- package/api/statement/declarations/declares.js +24 -19
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +10 -5
- package/api/statement/iterations/for.js +42 -23
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +9 -3
- package/api/statement/iterations/while.js +27 -13
- package/api/statement/iterations/while.js.map +1 -1
- package/api/utils.d.ts +5 -0
- package/api/utils.js +4 -0
- package/api/utils.js.map +1 -0
- package/package.json +5 -5
- package/scope/finalizer.d.ts +4 -0
- package/scope/finalizer.js +11 -0
- package/scope/finalizer.js.map +1 -0
- package/scope/proxy.d.ts +5 -3
- package/scope/proxy.js +26 -26
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +108 -51
- package/scope/scope.js +72 -134
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +117 -26
- package/scope/stack.js +154 -102
- package/scope/stack.js.map +1 -1
- package/v8/enums.d.ts +204 -0
- package/v8/enums.js +406 -0
- package/v8/enums.js.map +1 -0
- package/v8/index.d.ts +2 -1
- package/v8/index.js +2 -1
- package/v8/index.js.map +1 -1
- package/v8/inline.d.ts +213 -0
- package/v8/inline.js +2375 -0
- package/v8/inline.js.map +1 -0
- package/v8/nodes.d.ts +8 -7
- package/v8/nodes.js +39 -64
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +49 -151
- package/v8/parser.js +839 -1607
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +39 -3
- package/v8/stream.js +685 -171
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +244 -9
- package/v8/token.js +315 -47
- package/v8/token.js.map +1 -1
- package/visit/visitor.d.ts +3 -0
- package/visit/visitor.js +4 -7
- package/visit/visitor.js.map +1 -1
- package/api/app/class.d.ts +0 -117
- package/api/app/class.js +0 -292
- package/api/app/class.js.map +0 -1
- package/api/app/program.js +0 -39
- package/api/app/program.js.map +0 -1
- package/api/module/module.d.ts +0 -26
- package/api/module/module.js +0 -63
- package/api/module/module.js.map +0 -1
- package/v8/app.d.ts +0 -0
- package/v8/app.js +0 -2
- package/v8/app.js.map +0 -1
package/scope/stack.d.ts
CHANGED
|
@@ -1,57 +1,148 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { ReactiveScope, Scope, ScopeContext,
|
|
1
|
+
import type { DeclarationExpression } from '../api/expression.js';
|
|
2
|
+
import { ModuleScope, ReactiveScope, Scope, ScopeContext, WebModuleScope } from './scope.js';
|
|
3
3
|
export interface AwaitPromiseInfo {
|
|
4
4
|
promise: Promise<any>;
|
|
5
|
-
node:
|
|
5
|
+
node: DeclarationExpression;
|
|
6
6
|
declareVariable: boolean;
|
|
7
|
-
scopeType: ScopeType;
|
|
8
7
|
}
|
|
9
8
|
export interface AsyncIterableInfo {
|
|
10
9
|
iterable: AsyncIterable<any>;
|
|
11
10
|
forAwaitBody: (iterator: any) => any;
|
|
12
11
|
}
|
|
13
12
|
export interface Stack {
|
|
13
|
+
/**
|
|
14
|
+
* a list of promises to resolve in an 'async' scope as 'async function'
|
|
15
|
+
*/
|
|
14
16
|
awaitPromise: Array<AwaitPromiseInfo>;
|
|
17
|
+
/**
|
|
18
|
+
* resolve await promise in 'await for in' scope
|
|
19
|
+
*/
|
|
15
20
|
forAwaitAsyncIterable?: AsyncIterableInfo;
|
|
21
|
+
/**
|
|
22
|
+
* is this stack has a propertyKey
|
|
23
|
+
* @param propertyKey
|
|
24
|
+
*/
|
|
16
25
|
has(propertyKey: PropertyKey): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* get the first value for provided property key,
|
|
28
|
+
*
|
|
29
|
+
* will search current stack in all scope till find the first key, else undefined
|
|
30
|
+
* @param propertyKey
|
|
31
|
+
*/
|
|
17
32
|
get(propertyKey: PropertyKey): any;
|
|
33
|
+
/**
|
|
34
|
+
* set the value of `propertyKey` in its context provider with `value`.
|
|
35
|
+
* else define it in the first scope 'local scope'
|
|
36
|
+
* @param propertyKey
|
|
37
|
+
* @param value
|
|
38
|
+
* @param receiver
|
|
39
|
+
*/
|
|
18
40
|
set(propertyKey: PropertyKey, value: any, receiver?: any): boolean;
|
|
19
|
-
|
|
41
|
+
/**
|
|
42
|
+
* declare variable at last scope in the stack,
|
|
43
|
+
*
|
|
44
|
+
* @param propertyKey the name of property mey be string | number | symbol,
|
|
45
|
+
* @param propertyValue if not exist will be initialize with 'undefined' value
|
|
46
|
+
*/
|
|
47
|
+
declareVariable(propertyKey: PropertyKey, propertyValue?: any): any;
|
|
48
|
+
/**
|
|
49
|
+
* get context object of this provider,
|
|
50
|
+
* search for the first context object that has `propertyKey`.
|
|
51
|
+
*
|
|
52
|
+
* search for the first context that have property key,
|
|
53
|
+
* if not found will return the stack local scop as a default value
|
|
54
|
+
* @param propertyKey the property key
|
|
55
|
+
*/
|
|
20
56
|
findScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;
|
|
21
57
|
resolveAwait(value: AwaitPromiseInfo): void;
|
|
58
|
+
/**
|
|
59
|
+
* get a reference to the last scope in this stack
|
|
60
|
+
*/
|
|
22
61
|
lastScope<T extends ScopeContext>(): Scope<T>;
|
|
62
|
+
/**
|
|
63
|
+
* clear every thing after this scope, and even this scope
|
|
64
|
+
* @param scope
|
|
65
|
+
*/
|
|
23
66
|
clearTo<T extends ScopeContext>(scope: Scope<T>): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* clear every thing after this scope, but not this scope
|
|
69
|
+
* @param scope
|
|
70
|
+
*/
|
|
24
71
|
clearTill<T extends ScopeContext>(scope: Scope<T>): boolean;
|
|
25
72
|
popScope<T extends ScopeContext>(): Scope<T>;
|
|
26
73
|
removeScope<T extends ScopeContext>(scope: Scope<T>): void;
|
|
27
74
|
pushScope<T extends ScopeContext>(scope: Scope<T>): void;
|
|
28
75
|
pushBlockScope<T extends ScopeContext>(): Scope<T>;
|
|
29
|
-
pushFunctionScope<T extends ScopeContext>(): Scope<T>;
|
|
30
76
|
pushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
77
|
+
pushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
|
|
78
|
+
pushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
|
|
79
|
+
/**
|
|
80
|
+
* create new stack instance with the same reference to the current scope array
|
|
81
|
+
*/
|
|
36
82
|
copyStack(): Stack;
|
|
83
|
+
/**
|
|
84
|
+
* used when want to update ui-view like, you want to replace an array with another
|
|
85
|
+
* without reflect changes on view until reattached again.
|
|
86
|
+
*/
|
|
87
|
+
detach(): void;
|
|
88
|
+
/**
|
|
89
|
+
* apply all the not emitted changes, and continue emit in time.
|
|
90
|
+
*/
|
|
91
|
+
reattach(): void;
|
|
92
|
+
/**
|
|
93
|
+
* import module scope from another stack, by the help of ModuleScopeResolver.
|
|
94
|
+
*
|
|
95
|
+
* used with import statement
|
|
96
|
+
*/
|
|
97
|
+
importModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
|
|
98
|
+
/**
|
|
99
|
+
* get the current module for this stack.
|
|
100
|
+
*
|
|
101
|
+
* used with export statement
|
|
102
|
+
*/
|
|
103
|
+
getModule(): ModuleScope | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* register action to do on destroy this stack
|
|
106
|
+
*/
|
|
107
|
+
onDestroy(action: () => void): void;
|
|
37
108
|
}
|
|
38
109
|
export declare class Stack implements Stack {
|
|
39
|
-
static for(...contexts: Scope<
|
|
40
|
-
static forScopes(...scopes: Scope<
|
|
110
|
+
static for(...contexts: Scope<ScopeContext>[]): Stack;
|
|
111
|
+
static forScopes(...scopes: Scope<ScopeContext>[]): Stack;
|
|
112
|
+
static moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<ScopeContext>[]): Stack;
|
|
41
113
|
awaitPromise: AwaitPromiseInfo[];
|
|
42
114
|
forAwaitAsyncIterable?: AsyncIterableInfo | undefined;
|
|
43
115
|
protected readonly stack: Array<Scope<any>>;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
116
|
+
protected readonly moduleScope?: ModuleScope;
|
|
117
|
+
protected readonly moduleSource?: string;
|
|
118
|
+
protected readonly resolver?: ModuleScopeResolver;
|
|
119
|
+
protected readonly onDestroyActions: (() => void)[];
|
|
120
|
+
constructor();
|
|
121
|
+
constructor(globalScope: Scope<ScopeContext>);
|
|
122
|
+
constructor(globalScope: Scope<ScopeContext>, resolver: ModuleScopeResolver, moduleSource: string);
|
|
123
|
+
constructor(stack: Array<Scope<ScopeContext>>);
|
|
124
|
+
constructor(stack: Array<Scope<ScopeContext>>, resolver: ModuleScopeResolver, moduleSource: string);
|
|
125
|
+
private initModuleContext;
|
|
126
|
+
private getReactiveScopeControls;
|
|
127
|
+
}
|
|
128
|
+
export interface ModuleScopeResolver {
|
|
129
|
+
resolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;
|
|
130
|
+
resolveURL(specified: string, parent: string | URL): string;
|
|
131
|
+
}
|
|
132
|
+
export declare function createRootURL(source: string): URL;
|
|
133
|
+
export interface ResolverConfig {
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
*/
|
|
137
|
+
allowImportExternal?: boolean;
|
|
138
|
+
}
|
|
139
|
+
export declare class ModuleScopeResolver implements ModuleScopeResolver {
|
|
140
|
+
protected config?: ResolverConfig | undefined;
|
|
141
|
+
protected modules: [string, ModuleScope][];
|
|
142
|
+
constructor(config?: ResolverConfig | undefined);
|
|
143
|
+
register(source: string, moduleScope: ModuleScope): void;
|
|
144
|
+
protected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
|
|
145
|
+
protected findSourceByScope(moduleScope: ModuleScope): string;
|
|
146
|
+
protected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope;
|
|
147
|
+
protected readonly isValidHTTPUrl: (string: string) => boolean;
|
|
57
148
|
}
|
package/scope/stack.js
CHANGED
|
@@ -1,20 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { finalizerRegister } from './finalizer.js';
|
|
2
|
+
import { ModuleScope, ReactiveScope, ReactiveScopeControl, Scope, WebModuleScope } from './scope.js';
|
|
2
3
|
export class Stack {
|
|
3
|
-
constructor(
|
|
4
|
-
this.
|
|
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
|
+
// init module scope for import and export
|
|
19
|
+
this.moduleScope = new ModuleScope(this.initModuleContext());
|
|
20
|
+
this.pushScope(this.moduleScope);
|
|
21
|
+
// for the rest of module body
|
|
22
|
+
this.pushReactiveScope();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// not a module scope
|
|
26
|
+
this.pushBlockScope();
|
|
27
|
+
}
|
|
28
|
+
finalizerRegister(this, this.onDestroyActions, this);
|
|
5
29
|
}
|
|
6
30
|
static for(...contexts) {
|
|
7
31
|
if (contexts.length === 0) {
|
|
8
32
|
return new Stack();
|
|
9
33
|
}
|
|
10
|
-
return new Stack(contexts.map(context => new Scope(context
|
|
34
|
+
return new Stack(contexts.map(context => new Scope(context)));
|
|
11
35
|
}
|
|
12
36
|
static forScopes(...scopes) {
|
|
13
37
|
if (scopes.length === 0) {
|
|
14
|
-
scopes.push(Scope.
|
|
38
|
+
scopes.push(Scope.blockScope());
|
|
15
39
|
}
|
|
16
40
|
return new Stack(scopes);
|
|
17
41
|
}
|
|
42
|
+
static moduleScope(resolver, moduleSource, ...globalScopes) {
|
|
43
|
+
return new Stack(globalScopes, resolver, moduleSource);
|
|
44
|
+
}
|
|
45
|
+
initModuleContext() {
|
|
46
|
+
const importFunc = (path) => {
|
|
47
|
+
return this.importModule(path);
|
|
48
|
+
};
|
|
49
|
+
importFunc.meta = {
|
|
50
|
+
url: createRootURL(this.moduleSource),
|
|
51
|
+
resolve: (specified, parent) => {
|
|
52
|
+
return Promise.resolve(this.resolver.resolveURL(specified, parent ?? importFunc.meta.url));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const im = importFunc;
|
|
56
|
+
return { import: im };
|
|
57
|
+
}
|
|
18
58
|
has(propertyKey) {
|
|
19
59
|
return this.stack.find(context => context.has(propertyKey)) ? true : false;
|
|
20
60
|
}
|
|
@@ -24,18 +64,8 @@ export class Stack {
|
|
|
24
64
|
set(propertyKey, value, receiver) {
|
|
25
65
|
return this.findScope(propertyKey).set(propertyKey, value, receiver);
|
|
26
66
|
}
|
|
27
|
-
declareVariable(
|
|
28
|
-
|
|
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
|
-
}
|
|
67
|
+
declareVariable(propertyKey, propertyValue) {
|
|
68
|
+
return this.lastScope().set(propertyKey, propertyValue);
|
|
39
69
|
}
|
|
40
70
|
findScope(propertyKey) {
|
|
41
71
|
let lastIndex = this.stack.length;
|
|
@@ -65,98 +95,18 @@ export class Stack {
|
|
|
65
95
|
this.stack.push(scope);
|
|
66
96
|
return scope;
|
|
67
97
|
}
|
|
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
98
|
pushBlockScopeFor(context) {
|
|
89
|
-
const scope = Scope.
|
|
90
|
-
this.stack.push(scope);
|
|
91
|
-
return scope;
|
|
92
|
-
}
|
|
93
|
-
pushFunctionScopeFor(context) {
|
|
94
|
-
const scope = Scope.functionScopeFor(context);
|
|
99
|
+
const scope = Scope.for(context);
|
|
95
100
|
this.stack.push(scope);
|
|
96
101
|
return scope;
|
|
97
102
|
}
|
|
98
|
-
|
|
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() {
|
|
103
|
+
pushReactiveScope() {
|
|
114
104
|
const scope = ReactiveScope.blockScope();
|
|
115
105
|
this.stack.push(scope);
|
|
116
106
|
return scope;
|
|
117
107
|
}
|
|
118
|
-
|
|
119
|
-
const scope = ReactiveScope.
|
|
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);
|
|
108
|
+
pushReactiveScopeFor(context) {
|
|
109
|
+
const scope = ReactiveScope.for(context);
|
|
160
110
|
this.stack.push(scope);
|
|
161
111
|
return scope;
|
|
162
112
|
}
|
|
@@ -180,7 +130,109 @@ export class Stack {
|
|
|
180
130
|
return true;
|
|
181
131
|
}
|
|
182
132
|
copyStack() {
|
|
183
|
-
return new Stack(this.stack.slice());
|
|
133
|
+
return new Stack(this.stack.slice(), this.resolver, this.moduleSource);
|
|
134
|
+
}
|
|
135
|
+
detach() {
|
|
136
|
+
this.getReactiveScopeControls().forEach(scope => scope.detach());
|
|
137
|
+
}
|
|
138
|
+
reattach() {
|
|
139
|
+
this.getReactiveScopeControls().forEach(scope => scope.reattach());
|
|
140
|
+
}
|
|
141
|
+
getReactiveScopeControls() {
|
|
142
|
+
return this.stack.filter(scope => scope instanceof ReactiveScopeControl);
|
|
143
|
+
}
|
|
144
|
+
importModule(source, importCallOptions) {
|
|
145
|
+
if (!this.resolver || !this.moduleScope) {
|
|
146
|
+
// should o the parse and import the module
|
|
147
|
+
throw new Error('Module Resolver is undefined');
|
|
148
|
+
}
|
|
149
|
+
return this.resolver.resolve(source, this.moduleScope, importCallOptions);
|
|
150
|
+
}
|
|
151
|
+
getModule() {
|
|
152
|
+
return this.moduleScope;
|
|
153
|
+
}
|
|
154
|
+
onDestroy(action) {
|
|
155
|
+
this.onDestroyActions.push(action);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const ROOT_URL = 'https://root';
|
|
159
|
+
export function createRootURL(source) {
|
|
160
|
+
return new URL(source, ROOT_URL);
|
|
161
|
+
}
|
|
162
|
+
;
|
|
163
|
+
export class ModuleScopeResolver {
|
|
164
|
+
constructor(config) {
|
|
165
|
+
this.config = config;
|
|
166
|
+
this.modules = [];
|
|
167
|
+
this.isValidHTTPUrl = (string) => {
|
|
168
|
+
let url;
|
|
169
|
+
try {
|
|
170
|
+
url = new URL(string);
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
register(source, moduleScope) {
|
|
179
|
+
const stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);
|
|
180
|
+
if (stackInfo) {
|
|
181
|
+
stackInfo[1] = moduleScope;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
this.modules.push([source, moduleScope]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
resolve(source, moduleScope, importCallOptions) {
|
|
188
|
+
if (this.isValidHTTPUrl(source)) {
|
|
189
|
+
return this.resolveExternalModule(source, importCallOptions);
|
|
190
|
+
}
|
|
191
|
+
if (source.startsWith('/')) {
|
|
192
|
+
return this.findScopeBySource(source, importCallOptions);
|
|
193
|
+
}
|
|
194
|
+
const currentSource = this.findSourceByScope(moduleScope);
|
|
195
|
+
const absoluteUrl = this.resolveURL(source, currentSource);
|
|
196
|
+
return this.findScopeBySource(absoluteUrl, importCallOptions);
|
|
197
|
+
}
|
|
198
|
+
resolveURL(specified, parent) {
|
|
199
|
+
const currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;
|
|
200
|
+
const importedUrl = new URL(specified, currentUrl).href;
|
|
201
|
+
const absoluteUrl = importedUrl.replace(ROOT_URL, '');
|
|
202
|
+
return absoluteUrl;
|
|
203
|
+
}
|
|
204
|
+
findScopeBySource(source, importCallOptions) {
|
|
205
|
+
if (importCallOptions?.assert?.type) {
|
|
206
|
+
const type = importCallOptions.assert.type;
|
|
207
|
+
if (!source.endsWith(`.${type}`)) {
|
|
208
|
+
throw new Error(`Can't find module scope`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];
|
|
212
|
+
if (!importedScope) {
|
|
213
|
+
throw new Error(`Can't find module scope`);
|
|
214
|
+
}
|
|
215
|
+
return importedScope;
|
|
216
|
+
}
|
|
217
|
+
findSourceByScope(moduleScope) {
|
|
218
|
+
const importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];
|
|
219
|
+
if (!importedSource) {
|
|
220
|
+
throw new Error(`Can't resolve scope source`);
|
|
221
|
+
}
|
|
222
|
+
return importedSource;
|
|
223
|
+
}
|
|
224
|
+
resolveExternalModule(source, importCallOptions) {
|
|
225
|
+
if (!this.config?.allowImportExternal) {
|
|
226
|
+
throw new Error(`Error: Import External Module is not allowed.`);
|
|
227
|
+
}
|
|
228
|
+
const webScope = new WebModuleScope();
|
|
229
|
+
this.modules.push([source, webScope]);
|
|
230
|
+
// active later
|
|
231
|
+
// import(source, importCallOptions)
|
|
232
|
+
import(source).then(module => {
|
|
233
|
+
webScope.updateContext(module);
|
|
234
|
+
});
|
|
235
|
+
return webScope;
|
|
184
236
|
}
|
|
185
237
|
}
|
|
186
238
|
//# sourceMappingURL=stack.js.map
|
package/scope/stack.js.map
CHANGED
|
@@ -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,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M,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,SAAS,CAAyB,KAAe;QAChD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACjB,OAAO,KAAK,CAAC;SACb;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,SAAS;QACR,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC;CACD","sourcesContent":["import type { CanDeclareExpression } from '../api/expression.js';\nimport { ReactiveScope, Scope, ScopeContext, ScopeType } from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: CanDeclareExpression;\n\n\tdeclareVariable: boolean;\n\tscopeType: ScopeType;\n}\n\nexport interface AsyncIterableInfo {\n\titerable: AsyncIterable<any>;\n\tforAwaitBody: (iterator: any) => any;\n}\n\nexport interface Stack {\n\t/**\n\t * a list of promises to resolve in an 'async' scope as 'async function'\n\t */\n\tawaitPromise: Array<AwaitPromiseInfo>;\n\n\t/**\n\t * resolve await promise in 'await for in' scope\n\t */\n\tforAwaitAsyncIterable?: AsyncIterableInfo;\n\n\t/**\n\t * is this stack has a propertyKey\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get the first value for provided property key,\n\t * \n\t * will search current stack in all scope till find the first key, else undefined\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in its context provider with `value`.\n\t * else define it in the first scope 'local scope'\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean;\n\n\t/**\n\t * declare variable in stack by scope type,\n\t * \n\t * 'block' for the first scop ==> may be 'block' or 'function' scope\n\t * \n\t * 'function' will search for the first scope with scope type 'function'\n\t * then define a property key with 'initial' value in thus scope\n\t * @param scopeType \"function\" | \"block\"\n\t * @param propertyKey the name of property mey be string | number | symbol, \n\t * @param propertyValue if not exist will be initialize with 'undefined' value\n\t */\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any): any;\n\n\n\t/**\n\t * get context object of this provider,\n\t * search for the first context object that has `propertyKey`.\n\t * \n\t * search for the first context that have property key,\n\t * if not found will return the stack local scop as a default value\n\t * @param propertyKey the property key\n\t */\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends ScopeContext>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends ScopeContext>(): Scope<T>;\n\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushFunctionScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\tpushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\n\tpushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\tpushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\tcopyStack(): Stack;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Scope<any>[]): Stack {\n\t\tif (contexts.length === 0) {\n\t\t\treturn new Stack();\n\t\t}\n\t\treturn new Stack(contexts.map(context => new Scope(context, 'global')));\n\t}\n\tstatic forScopes(...scopes: Scope<any>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.functionScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tawaitPromise: AwaitPromiseInfo[];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\n\tconstructor(stack?: Array<Scope<any>>) {\n\t\tthis.stack = stack ?? [Scope.functionScope()];\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn this.stack.find(context => context.has(propertyKey)) ? true : false;\n\t}\n\tget(propertyKey: PropertyKey) {\n\t\treturn this.findScope<ScopeContext>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<ScopeContext>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any) {\n\t\tif (scopeType === 'block') {\n\t\t\treturn this.lastScope<ScopeContext>().set(propertyKey, propertyValue);\n\t\t}\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.type === scopeType) {\n\t\t\t\tscope.set(propertyKey, propertyValue);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.classScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.functionScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushClassReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.classScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushModuleReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.moduleScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushGlobalReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = ReactiveScope.globalScopeFor(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice());\n\t}\n}\n"]}
|
|
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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C,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, ScopeContext, 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 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"]}
|