@ibyar/expressions 0.5.1 → 0.5.6
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 +5 -4
- package/api/abstract.d.ts +5 -6
- package/api/abstract.js +3 -3
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +202 -0
- package/api/class/class.js +635 -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 +2 -1
- package/api/computing/return.js +3 -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 +2 -1
- package/api/computing/throw.js +3 -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 +2 -2
- package/api/definition/bind.js +1 -1
- package/api/definition/bind.js.map +1 -1
- package/api/definition/function.d.ts +40 -51
- package/api/definition/function.js +291 -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 +35 -50
- package/api/definition/values.js +66 -149
- package/api/definition/values.js.map +1 -1
- package/api/deserialize/deserialize.d.ts +2 -1
- package/api/deserialize/deserialize.js +4 -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 +13 -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 +66 -25
- package/api/module/export.js +270 -58
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +61 -25
- package/api/module/import.js +226 -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 +2 -2
- package/api/operators/grouping.js +1 -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 +2 -2
- package/api/operators/pipeline.js +1 -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 +4 -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 +4 -5
- package/api/statement/control/block.js +22 -23
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +1 -1
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +2 -2
- package/api/statement/control/if.js +1 -1
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +4 -5
- package/api/statement/control/switch.js +13 -9
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +38 -13
- package/api/statement/control/terminate.js +81 -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 +5 -5
- package/api/statement/iterations/for.js +29 -23
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +3 -3
- package/api/statement/iterations/while.js +17 -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/event.d.ts +2 -2
- package/scope/event.js +8 -14
- package/scope/event.js.map +1 -1
- 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 +2 -3
- package/scope/proxy.js +22 -26
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +42 -53
- package/scope/scope.js +73 -143
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +43 -26
- package/scope/stack.js +148 -102
- package/scope/stack.js.map +1 -1
- package/v8/enums.d.ts +204 -0
- package/v8/enums.js +375 -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 +177 -0
- package/v8/inline.js +1973 -0
- package/v8/inline.js.map +1 -0
- package/v8/nodes.d.ts +8 -7
- package/v8/nodes.js +37 -63
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +41 -151
- package/v8/parser.js +507 -1578
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +35 -3
- package/v8/stream.js +616 -164
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +15 -9
- package/v8/token.js +79 -46
- package/v8/token.js.map +1 -1
- 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.js
CHANGED
|
@@ -1,20 +1,57 @@
|
|
|
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
|
+
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
|
|
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.
|
|
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(
|
|
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
|
-
}
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
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
|
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,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC/C,CAAC;IAnBD,MAAM,CAAC,GAAG,CAAC,GAAG,QAAsB;QACnC,IAAI,QAAQ,CAAC,M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,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,IAAI,WAAW,CAAC,IAAI,C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AAM,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 { 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"]}
|
package/v8/enums.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { AccessorProperty, MethodDefinition, PropertyDefinition, StaticBlock } from '../api/class/class.js';
|
|
2
|
+
import { ExpressionNode } from '../api/expression.js';
|
|
3
|
+
import { VariableDeclarator } from '../api/statement/declarations/declares.js';
|
|
4
|
+
import { Token } from './token.js';
|
|
5
|
+
export declare function isInRange(num: number, start: number, end: number): boolean;
|
|
6
|
+
export declare enum ParsingArrowHeadFlag {
|
|
7
|
+
CertainlyNotArrowHead = 0,
|
|
8
|
+
MaybeArrowHead = 1,
|
|
9
|
+
AsyncArrowFunction = 2
|
|
10
|
+
}
|
|
11
|
+
export declare enum PropertyKind {
|
|
12
|
+
Value = 0,
|
|
13
|
+
Shorthand = 1,
|
|
14
|
+
ShorthandOrClassField = 2,
|
|
15
|
+
Assign = 3,
|
|
16
|
+
Method = 4,
|
|
17
|
+
ClassField = 5,
|
|
18
|
+
AccessorGetter = 6,
|
|
19
|
+
AccessorSetter = 7,
|
|
20
|
+
Spread = 8,
|
|
21
|
+
NotSet = 9
|
|
22
|
+
}
|
|
23
|
+
export declare function isAccessor(kind: PropertyKind): boolean;
|
|
24
|
+
export declare enum PropertyPosition {
|
|
25
|
+
ObjectLiteral = 0,
|
|
26
|
+
ClassLiteral = 1
|
|
27
|
+
}
|
|
28
|
+
export declare class PropertyKindInfo {
|
|
29
|
+
name: string;
|
|
30
|
+
position: PropertyPosition;
|
|
31
|
+
funcFlag: ParseFunctionFlag;
|
|
32
|
+
kind: PropertyKind;
|
|
33
|
+
isComputedName: boolean;
|
|
34
|
+
isPrivate: boolean;
|
|
35
|
+
isStatic: boolean;
|
|
36
|
+
isRest: boolean;
|
|
37
|
+
parsePropertyKindFromToken(token: Token): boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare type FunctionInfo = {
|
|
40
|
+
rest?: boolean;
|
|
41
|
+
};
|
|
42
|
+
export declare enum PreParserIdentifierType {
|
|
43
|
+
NullIdentifier = 0,
|
|
44
|
+
UnknownIdentifier = 1,
|
|
45
|
+
EvalIdentifier = 2,
|
|
46
|
+
ArgumentsIdentifier = 3,
|
|
47
|
+
ConstructorIdentifier = 4,
|
|
48
|
+
AwaitIdentifier = 5,
|
|
49
|
+
AsyncIdentifier = 6,
|
|
50
|
+
NameIdentifier = 7,
|
|
51
|
+
PrivateNameIdentifier = 8
|
|
52
|
+
}
|
|
53
|
+
export declare enum FunctionBodyType {
|
|
54
|
+
EXPRESSION = 0,
|
|
55
|
+
BLOCK = 1
|
|
56
|
+
}
|
|
57
|
+
export declare enum ParseFunctionFlag {
|
|
58
|
+
IsNormal = 0,
|
|
59
|
+
IsGenerator = 1,
|
|
60
|
+
IsAsync = 2
|
|
61
|
+
}
|
|
62
|
+
export declare enum FunctionKind {
|
|
63
|
+
NormalFunction = 0,
|
|
64
|
+
Module = 1,
|
|
65
|
+
AsyncModule = 2,
|
|
66
|
+
BaseConstructor = 3,
|
|
67
|
+
DefaultBaseConstructor = 4,
|
|
68
|
+
DefaultDerivedConstructor = 5,
|
|
69
|
+
DerivedConstructor = 6,
|
|
70
|
+
GetterFunction = 7,
|
|
71
|
+
StaticGetterFunction = 8,
|
|
72
|
+
SetterFunction = 9,
|
|
73
|
+
StaticSetterFunction = 10,
|
|
74
|
+
ArrowFunction = 11,
|
|
75
|
+
AsyncArrowFunction = 12,
|
|
76
|
+
AsyncFunction = 13,
|
|
77
|
+
AsyncConciseMethod = 14,
|
|
78
|
+
StaticAsyncConciseMethod = 15,
|
|
79
|
+
AsyncConciseGeneratorMethod = 16,
|
|
80
|
+
StaticAsyncConciseGeneratorMethod = 17,
|
|
81
|
+
AsyncGeneratorFunction = 18,
|
|
82
|
+
GeneratorFunction = 19,
|
|
83
|
+
ConciseGeneratorMethod = 20,
|
|
84
|
+
StaticConciseGeneratorMethod = 21,
|
|
85
|
+
ConciseMethod = 22,
|
|
86
|
+
StaticConciseMethod = 23,
|
|
87
|
+
ClassMembersInitializerFunction = 24,
|
|
88
|
+
ClassStaticInitializerFunction = 25,
|
|
89
|
+
Invalid = 26,
|
|
90
|
+
LastFunctionKind = 25
|
|
91
|
+
}
|
|
92
|
+
export declare enum SubFunctionKind {
|
|
93
|
+
NormalFunction = 0,
|
|
94
|
+
NonStaticMethod = 1,
|
|
95
|
+
StaticMethod = 2
|
|
96
|
+
}
|
|
97
|
+
export declare enum StaticFlag {
|
|
98
|
+
NotStatic = 0,
|
|
99
|
+
Static = 1
|
|
100
|
+
}
|
|
101
|
+
export declare function functionKindForImpl(subFunctionKind: SubFunctionKind, flags: ParseFunctionFlag): FunctionKind;
|
|
102
|
+
export declare function functionKindFor(isGenerator: boolean, isAsync: boolean): FunctionKind;
|
|
103
|
+
export declare function methodKindFor(isStatic: boolean, isGenerator: boolean, isAsync: boolean): FunctionKind;
|
|
104
|
+
export declare enum FunctionSyntaxKind {
|
|
105
|
+
AnonymousExpression = 0,
|
|
106
|
+
NamedExpression = 1,
|
|
107
|
+
Declaration = 2,
|
|
108
|
+
AccessorOrMethod = 3,
|
|
109
|
+
Wrapped = 4,
|
|
110
|
+
LastFunctionSyntaxKind = 4
|
|
111
|
+
}
|
|
112
|
+
export declare function isArrowFunction(kind: FunctionKind): boolean;
|
|
113
|
+
export declare function isModule(kind: FunctionKind): boolean;
|
|
114
|
+
export declare function isAsyncModule(kind: FunctionKind): boolean;
|
|
115
|
+
export declare function isAsyncGeneratorFunction(kind: FunctionKind): boolean;
|
|
116
|
+
export declare function isGeneratorFunction(kind: FunctionKind): boolean;
|
|
117
|
+
export declare function isAsyncFunction(kind: FunctionKind): boolean;
|
|
118
|
+
export declare function isResumableFunction(kind: FunctionKind): boolean;
|
|
119
|
+
export declare function isConciseMethod(kind: FunctionKind): boolean;
|
|
120
|
+
export declare function isStrictFunctionWithoutPrototype(kind: FunctionKind): boolean;
|
|
121
|
+
export declare function isGetterFunction(kind: FunctionKind): boolean;
|
|
122
|
+
export declare function isSetterFunction(kind: FunctionKind): boolean;
|
|
123
|
+
export declare function isAccessorFunction(kind: FunctionKind): boolean;
|
|
124
|
+
export declare function isDefaultConstructor(kind: FunctionKind): boolean;
|
|
125
|
+
export declare function isBaseConstructor(kind: FunctionKind): boolean;
|
|
126
|
+
export declare function isDerivedConstructor(kind: FunctionKind): boolean;
|
|
127
|
+
export declare function isClassConstructor(kind: FunctionKind): boolean;
|
|
128
|
+
export declare function isClassMembersInitializerFunction(kind: FunctionKind): boolean;
|
|
129
|
+
export declare function isConstructable(kind: FunctionKind): boolean;
|
|
130
|
+
export declare function isStatic(kind: FunctionKind): boolean;
|
|
131
|
+
export declare function bindsSuper(kind: FunctionKind): boolean;
|
|
132
|
+
export declare function isAwaitAsIdentifierDisallowed(kind: FunctionKind): boolean;
|
|
133
|
+
export declare function functionKind2String(kind: FunctionKind): string;
|
|
134
|
+
export declare type ClassInfo = {
|
|
135
|
+
extends?: ExpressionNode;
|
|
136
|
+
publicMembers: (MethodDefinition | PropertyDefinition)[];
|
|
137
|
+
privateMembers: (MethodDefinition | PropertyDefinition)[];
|
|
138
|
+
staticElements: (MethodDefinition | PropertyDefinition | AccessorProperty | StaticBlock)[];
|
|
139
|
+
instanceFields: (MethodDefinition | PropertyDefinition | AccessorProperty)[];
|
|
140
|
+
constructor: MethodDefinition | undefined;
|
|
141
|
+
hasSeenConstructor: boolean;
|
|
142
|
+
hasStaticComputedNames: boolean;
|
|
143
|
+
hasStaticElements: boolean;
|
|
144
|
+
hasStaticPrivateMethods: boolean;
|
|
145
|
+
hasStaticBlocks: boolean;
|
|
146
|
+
hasInstanceMembers: boolean;
|
|
147
|
+
requiresBrand: boolean;
|
|
148
|
+
isAnonymous: boolean;
|
|
149
|
+
hasPrivateMethods: boolean;
|
|
150
|
+
computedFieldCount: number;
|
|
151
|
+
homeObjectVariable?: VariableDeclarator;
|
|
152
|
+
staticHomeObjectVariable?: VariableDeclarator;
|
|
153
|
+
};
|
|
154
|
+
export declare function createClassInfo(): ClassInfo;
|
|
155
|
+
export declare enum FunctionNameValidity {
|
|
156
|
+
FunctionNameIsStrictReserved = "FunctionNameIsStrictReserved",
|
|
157
|
+
SkipFunctionNameCheck = "SkipFunctionNameCheck",
|
|
158
|
+
FunctionNameValidityUnknown = "FunctionNameValidityUnknown"
|
|
159
|
+
}
|
|
160
|
+
export declare enum ObjectLiteralPropertyKind {
|
|
161
|
+
CONSTANT = "CONSTANT",
|
|
162
|
+
COMPUTED = "COMPUTED",
|
|
163
|
+
MATERIALIZED_LITERAL = "MATERIALIZED_LITERAL",
|
|
164
|
+
GETTER = "GETTER",
|
|
165
|
+
SETTER = "SETTER",
|
|
166
|
+
PROTOTYPE = "PROTOTYPE",
|
|
167
|
+
SPREAD = "SPREAD"
|
|
168
|
+
}
|
|
169
|
+
export declare class ObjectLiteralProperty {
|
|
170
|
+
static Kind: typeof ObjectLiteralPropertyKind;
|
|
171
|
+
}
|
|
172
|
+
export declare enum ClassLiteralPropertyKind {
|
|
173
|
+
METHOD = "METHOD",
|
|
174
|
+
GETTER = "GETTER",
|
|
175
|
+
SETTER = "SETTER",
|
|
176
|
+
FIELD = "FIELD"
|
|
177
|
+
}
|
|
178
|
+
export declare class ClassLiteralProperty {
|
|
179
|
+
static Kind: typeof ClassLiteralPropertyKind;
|
|
180
|
+
}
|
|
181
|
+
export declare function classPropertyKindFor(kind: PropertyKind): ClassLiteralPropertyKind;
|
|
182
|
+
export declare enum VariableMode {
|
|
183
|
+
Const = "Const",
|
|
184
|
+
PrivateMethod = "PrivateMethod",
|
|
185
|
+
PrivateGetterOnly = "PrivateGetterOnly",
|
|
186
|
+
PrivateSetterOnly = "PrivateSetterOnly"
|
|
187
|
+
}
|
|
188
|
+
export declare function getVariableMode(kind: ClassLiteralPropertyKind): VariableMode;
|
|
189
|
+
export declare enum LanguageMode {
|
|
190
|
+
Sloppy = 0,
|
|
191
|
+
Strict = 1
|
|
192
|
+
}
|
|
193
|
+
export declare function isSloppy(mode: LanguageMode): boolean;
|
|
194
|
+
export declare function isStrict(mode: LanguageMode): boolean;
|
|
195
|
+
export declare function getLanguageMode(isModule: boolean): LanguageMode;
|
|
196
|
+
export declare enum VariableDeclarationContext {
|
|
197
|
+
StatementListItem = 0,
|
|
198
|
+
Statement = 1,
|
|
199
|
+
ForStatement = 2
|
|
200
|
+
}
|
|
201
|
+
export declare enum AllowLabelledFunctionStatement {
|
|
202
|
+
AllowLabelledFunctionStatement = 0,
|
|
203
|
+
DisallowLabelledFunctionStatement = 1
|
|
204
|
+
}
|