@ibyar/expressions 0.5.0 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +96 -1
  2. package/api/abstract.d.ts +3 -4
  3. package/api/abstract.js +1 -1
  4. package/api/abstract.js.map +1 -1
  5. package/api/class/class.d.ts +196 -0
  6. package/api/class/class.js +594 -0
  7. package/api/class/class.js.map +1 -0
  8. package/api/class/decorator.d.ts +20 -0
  9. package/api/class/decorator.js +48 -0
  10. package/api/class/decorator.js.map +1 -0
  11. package/api/computing/call.d.ts +3 -1
  12. package/api/computing/call.js +16 -4
  13. package/api/computing/call.js.map +1 -1
  14. package/api/computing/new.d.ts +2 -1
  15. package/api/computing/new.js +4 -0
  16. package/api/computing/new.js.map +1 -1
  17. package/api/computing/rest.d.ts +3 -3
  18. package/api/computing/rest.js +5 -2
  19. package/api/computing/rest.js.map +1 -1
  20. package/api/computing/return.d.ts +2 -1
  21. package/api/computing/return.js +3 -0
  22. package/api/computing/return.js.map +1 -1
  23. package/api/computing/spread.d.ts +2 -1
  24. package/api/computing/spread.js +5 -2
  25. package/api/computing/spread.js.map +1 -1
  26. package/api/computing/throw.d.ts +2 -1
  27. package/api/computing/throw.js +3 -0
  28. package/api/computing/throw.js.map +1 -1
  29. package/api/computing/yield.d.ts +2 -1
  30. package/api/computing/yield.js +3 -0
  31. package/api/computing/yield.js.map +1 -1
  32. package/api/definition/array.d.ts +6 -7
  33. package/api/definition/array.js +13 -13
  34. package/api/definition/array.js.map +1 -1
  35. package/api/definition/bind.d.ts +2 -2
  36. package/api/definition/bind.js +1 -1
  37. package/api/definition/bind.js.map +1 -1
  38. package/api/definition/function.d.ts +8 -8
  39. package/api/definition/function.js +25 -25
  40. package/api/definition/function.js.map +1 -1
  41. package/api/definition/member.d.ts +2 -2
  42. package/api/definition/member.js +1 -1
  43. package/api/definition/member.js.map +1 -1
  44. package/api/definition/object.d.ts +7 -7
  45. package/api/definition/object.js +9 -9
  46. package/api/definition/object.js.map +1 -1
  47. package/api/definition/statement.d.ts +2 -2
  48. package/api/definition/statement.js +2 -2
  49. package/api/definition/statement.js.map +1 -1
  50. package/api/definition/values.d.ts +5 -4
  51. package/api/definition/values.js +7 -4
  52. package/api/definition/values.js.map +1 -1
  53. package/api/expression.d.ts +9 -12
  54. package/api/expression.js.map +1 -1
  55. package/api/{app → module/app}/program.d.ts +8 -9
  56. package/api/module/app/program.js +45 -0
  57. package/api/module/app/program.js.map +1 -0
  58. package/api/module/export.d.ts +60 -25
  59. package/api/module/export.js +230 -60
  60. package/api/module/export.js.map +1 -1
  61. package/api/module/import.d.ts +66 -25
  62. package/api/module/import.js +236 -68
  63. package/api/module/import.js.map +1 -1
  64. package/api/operators/assignment.d.ts +2 -2
  65. package/api/operators/assignment.js +1 -1
  66. package/api/operators/assignment.js.map +1 -1
  67. package/api/operators/await.d.ts +2 -2
  68. package/api/operators/await.js +1 -1
  69. package/api/operators/await.js.map +1 -1
  70. package/api/operators/binary.d.ts +2 -2
  71. package/api/operators/binary.js +1 -1
  72. package/api/operators/binary.js.map +1 -1
  73. package/api/operators/chaining.d.ts +2 -2
  74. package/api/operators/chaining.js +1 -1
  75. package/api/operators/chaining.js.map +1 -1
  76. package/api/operators/comma.d.ts +2 -2
  77. package/api/operators/comma.js +2 -2
  78. package/api/operators/comma.js.map +1 -1
  79. package/api/operators/grouping.d.ts +2 -2
  80. package/api/operators/grouping.js +1 -1
  81. package/api/operators/grouping.js.map +1 -1
  82. package/api/operators/logical.d.ts +2 -2
  83. package/api/operators/logical.js +1 -1
  84. package/api/operators/logical.js.map +1 -1
  85. package/api/operators/pipeline.d.ts +2 -2
  86. package/api/operators/pipeline.js +1 -1
  87. package/api/operators/pipeline.js.map +1 -1
  88. package/api/operators/ternary.d.ts +2 -2
  89. package/api/operators/ternary.js +1 -1
  90. package/api/operators/ternary.js.map +1 -1
  91. package/api/operators/unary.d.ts +3 -3
  92. package/api/operators/unary.js +4 -3
  93. package/api/operators/unary.js.map +1 -1
  94. package/api/operators/update.d.ts +2 -2
  95. package/api/operators/update.js +1 -1
  96. package/api/operators/update.js.map +1 -1
  97. package/api/statement/control/block.d.ts +3 -3
  98. package/api/statement/control/block.js +2 -2
  99. package/api/statement/control/block.js.map +1 -1
  100. package/api/statement/control/empty.d.ts +1 -1
  101. package/api/statement/control/empty.js.map +1 -1
  102. package/api/statement/control/if.d.ts +2 -2
  103. package/api/statement/control/if.js +1 -1
  104. package/api/statement/control/if.js.map +1 -1
  105. package/api/statement/control/switch.d.ts +4 -5
  106. package/api/statement/control/switch.js +5 -6
  107. package/api/statement/control/switch.js.map +1 -1
  108. package/api/statement/control/terminate.d.ts +3 -3
  109. package/api/statement/control/terminate.js +2 -2
  110. package/api/statement/control/terminate.js.map +1 -1
  111. package/api/statement/declarations/declares.d.ts +13 -11
  112. package/api/statement/declarations/declares.js +26 -18
  113. package/api/statement/declarations/declares.js.map +1 -1
  114. package/api/statement/iterations/for.d.ts +5 -5
  115. package/api/statement/iterations/for.js +7 -7
  116. package/api/statement/iterations/for.js.map +1 -1
  117. package/api/statement/iterations/while.d.ts +3 -3
  118. package/api/statement/iterations/while.js +2 -2
  119. package/api/statement/iterations/while.js.map +1 -1
  120. package/api/utils.d.ts +3 -0
  121. package/api/utils.js +2 -0
  122. package/api/utils.js.map +1 -0
  123. package/package.json +4 -4
  124. package/scope/event.d.ts +2 -2
  125. package/scope/event.js +8 -14
  126. package/scope/event.js.map +1 -1
  127. package/scope/finalizer.d.ts +4 -0
  128. package/scope/finalizer.js +11 -0
  129. package/scope/finalizer.js.map +1 -0
  130. package/scope/proxy.d.ts +2 -1
  131. package/scope/proxy.js +18 -2
  132. package/scope/proxy.js.map +1 -1
  133. package/scope/scope.d.ts +57 -40
  134. package/scope/scope.js +123 -106
  135. package/scope/scope.js.map +1 -1
  136. package/scope/stack.d.ts +41 -24
  137. package/scope/stack.js +148 -102
  138. package/scope/stack.js.map +1 -1
  139. package/v8/app.js.map +1 -1
  140. package/v8/parser.d.ts +1 -1
  141. package/v8/parser.js +3 -2
  142. package/v8/parser.js.map +1 -1
  143. package/visit/visitor.js +4 -7
  144. package/visit/visitor.js.map +1 -1
  145. package/api/app/class.d.ts +0 -117
  146. package/api/app/class.js +0 -292
  147. package/api/app/class.js.map +0 -1
  148. package/api/app/program.js +0 -39
  149. package/api/app/program.js.map +0 -1
  150. package/api/module/module.d.ts +0 -26
  151. package/api/module/module.js +0 -63
  152. package/api/module/module.js.map +0 -1
package/scope/stack.js CHANGED
@@ -1,20 +1,57 @@
1
- import { ReactiveScope, Scope } from './scope.js';
1
+ import { finalizerRegister } from './finalizer.js';
2
+ import { ModuleScope, ReactiveScope, ReactiveScopeControl, Scope, WebModuleScope } from './scope.js';
2
3
  export class Stack {
3
- constructor(stack) {
4
- this.stack = stack ?? [Scope.functionScope()];
4
+ constructor(globals, resolver, moduleSource) {
5
+ this.onDestroyActions = [];
6
+ if (Array.isArray(globals)) {
7
+ this.stack = globals;
8
+ }
9
+ else if (typeof globals == 'object') {
10
+ this.stack = [globals];
11
+ }
12
+ else {
13
+ this.stack = [];
14
+ }
15
+ if (resolver && moduleSource) {
16
+ this.resolver = resolver;
17
+ this.moduleSource = moduleSource;
18
+ this.moduleScope = new ModuleScope(this.initModuleContext());
19
+ this.pushScope(this.moduleScope);
20
+ this.pushReactiveScope();
21
+ }
22
+ else {
23
+ this.pushBlockScope();
24
+ }
25
+ finalizerRegister(this, this.onDestroyActions, this);
5
26
  }
6
27
  static for(...contexts) {
7
28
  if (contexts.length === 0) {
8
29
  return new Stack();
9
30
  }
10
- return new Stack(contexts.map(context => new Scope(context, 'global')));
31
+ return new Stack(contexts.map(context => new Scope(context)));
11
32
  }
12
33
  static forScopes(...scopes) {
13
34
  if (scopes.length === 0) {
14
- scopes.push(Scope.functionScope());
35
+ scopes.push(Scope.blockScope());
15
36
  }
16
37
  return new Stack(scopes);
17
38
  }
39
+ static moduleScope(resolver, moduleSource, ...globalScopes) {
40
+ return new Stack(globalScopes, resolver, moduleSource);
41
+ }
42
+ initModuleContext() {
43
+ const importFunc = (path) => {
44
+ return this.importModule(path);
45
+ };
46
+ importFunc.meta = {
47
+ url: createRootURL(this.moduleSource),
48
+ resolve: (specified, parent) => {
49
+ return Promise.resolve(this.resolver.resolveURL(specified, parent ?? importFunc.meta.url));
50
+ }
51
+ };
52
+ const im = importFunc;
53
+ return { import: im };
54
+ }
18
55
  has(propertyKey) {
19
56
  return this.stack.find(context => context.has(propertyKey)) ? true : false;
20
57
  }
@@ -24,18 +61,8 @@ export class Stack {
24
61
  set(propertyKey, value, receiver) {
25
62
  return this.findScope(propertyKey).set(propertyKey, value, receiver);
26
63
  }
27
- declareVariable(scopeType, propertyKey, propertyValue) {
28
- if (scopeType === 'block') {
29
- return this.lastScope().set(propertyKey, propertyValue);
30
- }
31
- let lastIndex = this.stack.length;
32
- while (lastIndex--) {
33
- const scope = this.stack[lastIndex];
34
- if (scope.type === scopeType) {
35
- scope.set(propertyKey, propertyValue);
36
- break;
37
- }
38
- }
64
+ declareVariable(propertyKey, propertyValue) {
65
+ return this.lastScope().set(propertyKey, propertyValue);
39
66
  }
40
67
  findScope(propertyKey) {
41
68
  let lastIndex = this.stack.length;
@@ -65,98 +92,18 @@ export class Stack {
65
92
  this.stack.push(scope);
66
93
  return scope;
67
94
  }
68
- pushFunctionScope() {
69
- const scope = Scope.functionScope();
70
- this.stack.push(scope);
71
- return scope;
72
- }
73
- pushClassScope() {
74
- const scope = Scope.classScope();
75
- this.stack.push(scope);
76
- return scope;
77
- }
78
- pushModuleScope() {
79
- const scope = Scope.moduleScope();
80
- this.stack.push(scope);
81
- return scope;
82
- }
83
- pushGlobalScope() {
84
- const scope = Scope.globalScope();
85
- this.stack.push(scope);
86
- return scope;
87
- }
88
95
  pushBlockScopeFor(context) {
89
- const scope = Scope.blockScopeFor(context);
90
- this.stack.push(scope);
91
- return scope;
92
- }
93
- pushFunctionScopeFor(context) {
94
- const scope = Scope.functionScopeFor(context);
96
+ const scope = Scope.for(context);
95
97
  this.stack.push(scope);
96
98
  return scope;
97
99
  }
98
- pushClassScopeFor(context) {
99
- const scope = Scope.classScopeFor(context);
100
- this.stack.push(scope);
101
- return scope;
102
- }
103
- pushModuleScopeFor(context) {
104
- const scope = Scope.moduleScopeFor(context);
105
- this.stack.push(scope);
106
- return scope;
107
- }
108
- pushGlobalScopeFor(context) {
109
- const scope = Scope.globalScopeFor(context);
110
- this.stack.push(scope);
111
- return scope;
112
- }
113
- pushBlockReactiveScope() {
100
+ pushReactiveScope() {
114
101
  const scope = ReactiveScope.blockScope();
115
102
  this.stack.push(scope);
116
103
  return scope;
117
104
  }
118
- pushFunctionReactiveScope() {
119
- const scope = ReactiveScope.functionScope();
120
- this.stack.push(scope);
121
- return scope;
122
- }
123
- pushClassReactiveScope() {
124
- const scope = ReactiveScope.classScope();
125
- this.stack.push(scope);
126
- return scope;
127
- }
128
- pushModuleReactiveScope() {
129
- const scope = ReactiveScope.moduleScope();
130
- this.stack.push(scope);
131
- return scope;
132
- }
133
- pushGlobalReactiveScope() {
134
- const scope = ReactiveScope.globalScope();
135
- this.stack.push(scope);
136
- return scope;
137
- }
138
- pushBlockReactiveScopeFor(context) {
139
- const scope = ReactiveScope.blockScopeFor(context);
140
- this.stack.push(scope);
141
- return scope;
142
- }
143
- pushFunctionReactiveScopeFor(context) {
144
- const scope = ReactiveScope.functionScopeFor(context);
145
- this.stack.push(scope);
146
- return scope;
147
- }
148
- pushClassReactiveScopeFor(context) {
149
- const scope = ReactiveScope.classScopeFor(context);
150
- this.stack.push(scope);
151
- return scope;
152
- }
153
- pushModuleReactiveScopeFor(context) {
154
- const scope = ReactiveScope.moduleScopeFor(context);
155
- this.stack.push(scope);
156
- return scope;
157
- }
158
- pushGlobalReactiveScopeFor(context) {
159
- const scope = ReactiveScope.globalScopeFor(context);
105
+ pushReactiveScopeFor(context) {
106
+ const scope = ReactiveScope.for(context);
160
107
  this.stack.push(scope);
161
108
  return scope;
162
109
  }
@@ -180,7 +127,106 @@ export class Stack {
180
127
  return true;
181
128
  }
182
129
  copyStack() {
183
- return new Stack(this.stack.slice());
130
+ return new Stack(this.stack.slice(), this.resolver, this.moduleSource);
131
+ }
132
+ detach() {
133
+ this.getReactiveScopeControls().forEach(scope => scope.detach());
134
+ }
135
+ reattach() {
136
+ this.getReactiveScopeControls().forEach(scope => scope.reattach());
137
+ }
138
+ getReactiveScopeControls() {
139
+ return this.stack.filter(scope => scope instanceof ReactiveScopeControl);
140
+ }
141
+ importModule(source, importCallOptions) {
142
+ if (!this.resolver || !this.moduleScope) {
143
+ throw new Error('Module Resolver is undefined');
144
+ }
145
+ return this.resolver.resolve(source, this.moduleScope, importCallOptions);
146
+ }
147
+ getModule() {
148
+ return this.moduleScope;
149
+ }
150
+ onDestroy(action) {
151
+ this.onDestroyActions.push(action);
152
+ }
153
+ }
154
+ const ROOT_URL = 'https://root';
155
+ export function createRootURL(source) {
156
+ return new URL(source, ROOT_URL);
157
+ }
158
+ ;
159
+ export class ModuleScopeResolver {
160
+ constructor(config) {
161
+ this.config = config;
162
+ this.modules = [];
163
+ this.isValidHTTPUrl = (string) => {
164
+ let url;
165
+ try {
166
+ url = new URL(string);
167
+ }
168
+ catch (e) {
169
+ return false;
170
+ }
171
+ return url.protocol === 'http:' || url.protocol === 'https:';
172
+ };
173
+ }
174
+ register(source, moduleScope) {
175
+ const stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);
176
+ if (stackInfo) {
177
+ stackInfo[1] = moduleScope;
178
+ }
179
+ else {
180
+ this.modules.push([source, moduleScope]);
181
+ }
182
+ }
183
+ resolve(source, moduleScope, importCallOptions) {
184
+ if (this.isValidHTTPUrl(source)) {
185
+ return this.resolveExternalModule(source, importCallOptions);
186
+ }
187
+ if (source.startsWith('/')) {
188
+ return this.findScopeBySource(source, importCallOptions);
189
+ }
190
+ const currentSource = this.findSourceByScope(moduleScope);
191
+ const absoluteUrl = this.resolveURL(source, currentSource);
192
+ return this.findScopeBySource(absoluteUrl, importCallOptions);
193
+ }
194
+ resolveURL(specified, parent) {
195
+ const currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;
196
+ const importedUrl = new URL(specified, currentUrl).href;
197
+ const absoluteUrl = importedUrl.replace(ROOT_URL, '');
198
+ return absoluteUrl;
199
+ }
200
+ findScopeBySource(source, importCallOptions) {
201
+ if (importCallOptions?.assert?.type) {
202
+ const type = importCallOptions.assert.type;
203
+ if (!source.endsWith(`.${type}`)) {
204
+ throw new Error(`Can't find module scope`);
205
+ }
206
+ }
207
+ const importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];
208
+ if (!importedScope) {
209
+ throw new Error(`Can't find module scope`);
210
+ }
211
+ return importedScope;
212
+ }
213
+ findSourceByScope(moduleScope) {
214
+ const importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];
215
+ if (!importedSource) {
216
+ throw new Error(`Can't resolve scope source`);
217
+ }
218
+ return importedSource;
219
+ }
220
+ resolveExternalModule(source, importCallOptions) {
221
+ if (!this.config?.allowImportExternal) {
222
+ throw new Error(`Error: Import External Module is not allowed.`);
223
+ }
224
+ const webScope = new WebModuleScope();
225
+ this.modules.push([source, webScope]);
226
+ import(source).then(module => {
227
+ webScope.updateContext(module);
228
+ });
229
+ return webScope;
184
230
  }
185
231
  }
186
232
  //# sourceMappingURL=stack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,EAA2B,MAAM,YAAY,CAAC;AAuH3E,MAAM,OAAO,KAAK;IAkBjB,YAAY,KAAyB;QACpC,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC/C,CAAC;IAnBD,MAAM,CAAC,GAAG,CAAC,GAAG,QAAsB;QACnC,IAAI,QAAQ,CAAC,MAAM,KAAK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AW,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,CAAC,iBAAiB,EAA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CAAC,yBAAyB,CAAC,CAAC;aAC3C;SACD;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,aAAa,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC3C;QACD,OAAO,aAAa,CAAC;IACtB,CAAC;IACS,iBAAiB,CAAC,WAAwB;QACnD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,cAAc,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC9C;QACD,OAAO,cAAc,CAAC;IACvB,CAAC;IACS,qBAAqB,CAAC,MAAc,EAAE,iBAAqC;QACpF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SACjE;QACD,MAAM,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAA;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QAGtC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YAC5B,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IACjB,CAAC;CAUD","sourcesContent":["import type { CanDeclareExpression } from '../api/expression.js';\nimport { finalizerRegister } from './finalizer.js';\nimport {\n\tModuleContext, ModuleImport, ModuleScope, ReactiveScope,\n\tReactiveScopeControl, Scope, ScopeContext, WebModuleScope\n} from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: CanDeclareExpression;\n\n\tdeclareVariable: boolean;\n}\n\nexport interface AsyncIterableInfo {\n\titerable: AsyncIterable<any>;\n\tforAwaitBody: (iterator: any) => any;\n}\n\nexport interface Stack {\n\t/**\n\t * a list of promises to resolve in an 'async' scope as 'async function'\n\t */\n\tawaitPromise: Array<AwaitPromiseInfo>;\n\n\t/**\n\t * resolve await promise in 'await for in' scope\n\t */\n\tforAwaitAsyncIterable?: AsyncIterableInfo;\n\n\t/**\n\t * is this stack has a propertyKey\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get the first value for provided property key,\n\t * \n\t * will search current stack in all scope till find the first key, else undefined\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in its context provider with `value`.\n\t * else define it in the first scope 'local scope'\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean;\n\n\t/**\n\t * declare variable at last scope in the stack,\n\t * \n\t * @param propertyKey the name of property mey be string | number | symbol, \n\t * @param propertyValue if not exist will be initialize with 'undefined' value\n\t */\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any): any;\n\n\n\t/**\n\t * get context object of this provider,\n\t * search for the first context object that has `propertyKey`.\n\t * \n\t * search for the first context that have property key,\n\t * if not found will return the stack local scop as a default value\n\t * @param propertyKey the property key\n\t */\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends ScopeContext>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends ScopeContext>(): Scope<T>;\n\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\tpushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\t/**\n\t * create new stack instance with the same reference to the current scope array\n\t */\n\tcopyStack(): Stack;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * import module scope from another stack, by the help of ModuleScopeResolver.\n\t * \n\t * used with import statement\n\t */\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;\n\n\t/**\n\t * get the current module for this stack.\n\t * \n\t * used with export statement\n\t */\n\tgetModule(): ModuleScope | undefined;\n\n\t/**\n\t * register action to do on destroy this stack\n\t */\n\tonDestroy(action: () => void): void;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Scope<ScopeContext>[]): Stack {\n\t\tif (contexts.length === 0) {\n\t\t\treturn new Stack();\n\t\t}\n\t\treturn new Stack(contexts.map(context => new Scope<ScopeContext>(context)));\n\t}\n\tstatic forScopes(...scopes: Scope<ScopeContext>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.blockScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tstatic moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<ScopeContext>[]) {\n\t\treturn new Stack(globalScopes, resolver, moduleSource);\n\t}\n\tawaitPromise: AwaitPromiseInfo[];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\tprotected readonly moduleScope?: ModuleScope;\n\tprotected readonly moduleSource?: string;\n\tprotected readonly resolver?: ModuleScopeResolver;\n\n\tprotected readonly onDestroyActions: (() => void)[] = [];\n\n\tconstructor();\n\tconstructor(globalScope: Scope<ScopeContext>);\n\tconstructor(globalScope: Scope<ScopeContext>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Array<Scope<ScopeContext>>);\n\tconstructor(stack: Array<Scope<ScopeContext>>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(globals?: Array<Scope<ScopeContext>> | Scope<ScopeContext>, resolver?: ModuleScopeResolver, moduleSource?: string) {\n\t\tif (Array.isArray(globals)) {\n\t\t\tthis.stack = globals;\n\t\t} else if (typeof globals == 'object') {\n\t\t\tthis.stack = [globals];\n\t\t} else {\n\t\t\tthis.stack = [];\n\t\t}\n\t\tif (resolver && moduleSource) {\n\t\t\tthis.resolver = resolver;\n\t\t\tthis.moduleSource = moduleSource;\n\t\t\t// init module scope for import and export\n\t\t\tthis.moduleScope = new ModuleScope(this.initModuleContext());\n\t\t\tthis.pushScope(this.moduleScope);\n\t\t\t// for the rest of module body\n\t\t\tthis.pushReactiveScope();\n\t\t} else {\n\t\t\t// not a module scope\n\t\t\tthis.pushBlockScope();\n\t\t}\n\t\tfinalizerRegister(this, this.onDestroyActions, this);\n\t}\n\tprivate initModuleContext(): ModuleContext {\n\t\tconst importFunc = (path: string) => {\n\t\t\treturn this.importModule(path);\n\t\t};\n\t\timportFunc.meta = {\n\t\t\turl: createRootURL(this.moduleSource!),\n\t\t\tresolve: (specified: string, parent?: string | URL): Promise<string> => {\n\t\t\t\treturn Promise.resolve(this.resolver!.resolveURL(specified, parent ?? importFunc.meta.url));\n\t\t\t}\n\t\t};\n\t\tconst im: ModuleImport & ((path: string) => Promise<any>) = importFunc as any;\n\t\treturn { import: im };\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn this.stack.find(context => context.has(propertyKey)) ? true : false;\n\t}\n\tget(propertyKey: PropertyKey) {\n\t\treturn this.findScope<ScopeContext>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<ScopeContext>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any) {\n\t\treturn this.lastScope<ScopeContext>().set(propertyKey, propertyValue);\n\t}\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.for<T>(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.for(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice(), this.resolver!, this.moduleSource!);\n\t}\n\tdetach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.detach());\n\t}\n\treattach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.reattach());\n\t}\n\tprivate getReactiveScopeControls(): ReactiveScopeControl<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScopeControl) as ReactiveScopeControl<any>[];\n\t}\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (!this.resolver || !this.moduleScope) {\n\t\t\t// should o the parse and import the module\n\t\t\tthrow new Error('Module Resolver is undefined');\n\t\t}\n\t\treturn this.resolver.resolve(source, this.moduleScope, importCallOptions);\n\t}\n\tgetModule(): ModuleScope | undefined {\n\t\treturn this.moduleScope;\n\t}\n\n\tonDestroy(action: () => void): void {\n\t\tthis.onDestroyActions.push(action);\n\t}\n}\n\n\nexport interface ModuleScopeResolver {\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;\n\tresolveURL(specified: string, parent: string | URL): string;\n}\n\nconst ROOT_URL = 'https://root';\nexport function createRootURL(source: string): URL {\n\treturn new URL(source, ROOT_URL);\n}\n\n\nexport interface ResolverConfig {\n\t/**\n\t * \n\t */\n\tallowImportExternal?: boolean;\n\n};\nexport class ModuleScopeResolver implements ModuleScopeResolver {\n\tprotected modules: [string, ModuleScope][] = [];\n\tconstructor(protected config?: ResolverConfig) { }\n\tregister(source: string, moduleScope: ModuleScope) {\n\t\tconst stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);\n\t\tif (stackInfo) {\n\t\t\tstackInfo[1] = moduleScope;\n\t\t} else {\n\t\t\tthis.modules.push([source, moduleScope]);\n\t\t}\n\t}\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (this.isValidHTTPUrl(source)) {\n\t\t\treturn this.resolveExternalModule(source, importCallOptions);\n\t\t}\n\t\tif (source.startsWith('/')) {\n\t\t\treturn this.findScopeBySource(source, importCallOptions);\n\t\t}\n\t\tconst currentSource = this.findSourceByScope(moduleScope);\n\t\tconst absoluteUrl = this.resolveURL(source, currentSource);\n\t\treturn this.findScopeBySource(absoluteUrl, importCallOptions);\n\t}\n\tresolveURL(specified: string, parent: string | URL): string {\n\t\tconst currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;\n\t\tconst importedUrl = new URL(specified, currentUrl).href;\n\t\tconst absoluteUrl = importedUrl.replace(ROOT_URL, '');\n\t\treturn absoluteUrl;\n\t}\n\tprotected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (importCallOptions?.assert?.type) {\n\t\t\tconst type = importCallOptions.assert.type;\n\t\t\tif (!source.endsWith(`.${type}`)) {\n\t\t\t\tthrow new Error(`Can't find module scope`);\n\t\t\t}\n\t\t}\n\t\tconst importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];\n\t\tif (!importedScope) {\n\t\t\tthrow new Error(`Can't find module scope`);\n\t\t}\n\t\treturn importedScope;\n\t}\n\tprotected findSourceByScope(moduleScope: ModuleScope): string {\n\t\tconst importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];\n\t\tif (!importedSource) {\n\t\t\tthrow new Error(`Can't resolve scope source`);\n\t\t}\n\t\treturn importedSource;\n\t}\n\tprotected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope {\n\t\tif (!this.config?.allowImportExternal) {\n\t\t\tthrow new Error(`Error: Import External Module is not allowed.`);\n\t\t}\n\t\tconst webScope = new WebModuleScope()\n\t\tthis.modules.push([source, webScope]);\n\t\t// active later\n\t\t// import(source, importCallOptions)\n\t\timport(source).then(module => {\n\t\t\twebScope.updateContext(module);\n\t\t});\n\t\treturn webScope;\n\t}\n\tprotected readonly isValidHTTPUrl = (string: string) => {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(string);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn url.protocol === 'http:' || url.protocol === 'https:';\n\t}\n}\n"]}
package/v8/app.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/expressions/v8/app.ts"],"names":[],"mappings":"","sourcesContent":["// import type { ExpressionNode } from '../api/expression.js';\n// import {\n// \tAssignmentNode, ConstNode, FunctionType,\n// \tLetNode, NullNode, StringNode, Variable\n// } from '../api/index.js';\n// import { JavaScriptParser, PropertyKind } from './parser.js';\n// import { Token } from './token.js';\n// import { MetaProperty } from '../api/app/class.js';\n\n\n// export type ClassInfo = {\n// \tisAnonymous: boolean;\n// \textends: ExpressionNode;\n// \thasSeenConstructor: boolean;\n// \thasStaticComputedNames: boolean;\n// \trequiresBrand: boolean;\n// \thasPrivateMethods: boolean,\n// \thasStaticPrivateMethods: boolean;\n// \tcomputedFieldCount: number;\n// \thasStaticElements: boolean;\n// };\n\n// export enum FunctionNameValidity {\n// \tFunctionNameIsStrictReserved = 'FunctionNameIsStrictReserved',\n// \tSkipFunctionNameCheck = 'SkipFunctionNameCheck',\n// \tFunctionNameValidityUnknown = 'FunctionNameValidityUnknown'\n// };\n\n// export enum AllowLabelledFunctionStatement {\n// \tAllowLabelledFunctionStatement = 'AllowLabelledFunctionStatement',\n// \tDisallowLabelledFunctionStatement = 'DisallowLabelledFunctionStatement',\n// };\n\n// export enum ParsingArrowHeadFlag {\n// \tCertainlyNotArrowHead = 'CertainlyNotArrowHead',\n// \tMaybeArrowHead = 'MaybeArrowHead'\n// };\n\n// export enum PropertyPosition {\n// \tObjectLiteral = 'ObjectLiteral',\n// \tClassLiteral = 'ClassLiteral'\n// }\n\n// const FUNCTIONS_TYPES: FunctionType[][][] = [\n// \t[\n// \t\t// SubFunctionKind::kNormalFunction\n// \t\t[// is_generator=false\n// \t\t\tFunctionType.NORMAL,\n// \t\t\tFunctionType.ASYNC\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionType.GENERATOR,\n// \t\t\tFunctionType.ASYNC_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kNonStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionType.CONCISE,\n// \t\t\tFunctionType.ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionType.CONCISE_GENERATOR,\n// \t\t\tFunctionType.ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionType.STATIC_CONCISE,\n// \t\t\tFunctionType.STATIC_ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionType.STATIC_CONCISE_GENERATOR,\n// \t\t\tFunctionType.STATIC_ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t]\n// ];\n\n// export enum SubFunctionKind {\n// \tNormalFunction,\n// \tNonStaticMethod,\n// \tStaticMethod,\n// }\n\n// export function functionKindForImpl(subFunctionKind: SubFunctionKind, isGenerator: boolean, isAsync: boolean): FunctionType {\n// \treturn FUNCTIONS_TYPES[subFunctionKind as number][isGenerator ? 1 : 0][isAsync ? 1 : 0];\n// }\n\n// export class ParsePropertyInfo {\n// \tname: ExpressionNode;\n// \tposition = PropertyPosition.ClassLiteral;\n// \tfunctionFlags = FunctionType.NORMAL;\n// \tkind = PropertyKind.NotSet;\n// \tisComputedName = false;\n// \tisPrivate = false;\n// \tisStatic = false;\n// \tisRest = false;\n\n// \tPropertyKindFromToken(token: Token): boolean {\n// \t\t// This returns true, setting the property kind, iff the given token is\n// \t\t// one which must occur after a property name, indicating that the\n// \t\t// previous token was in fact a name and not a modifier (like the \"get\" in\n// \t\t// \"get x\").\n// \t\tswitch (token) {\n// \t\t\tcase Token.COLON:\n// \t\t\t\tthis.kind = PropertyKind.Value;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.COMMA:\n// \t\t\t\tthis.kind = PropertyKind.Shorthand;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.R_CURLY:\n// \t\t\t\tthis.kind = PropertyKind.ShorthandOrClassField;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.ASSIGN:\n// \t\t\t\tthis.kind = PropertyKind.Assign;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.L_PARENTHESES:\n// \t\t\t\tthis.kind = PropertyKind.Method;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.MUL:\n// \t\t\tcase Token.SEMICOLON:\n// \t\t\t\tthis.kind = PropertyKind.ClassField;\n// \t\t\t\treturn true;\n// \t\t\tdefault:\n// \t\t\t\tbreak;\n// \t\t}\n// \t\treturn false;\n// \t}\n\n// }\n// enum ObjectLiteralPropertyKind {\n// \tCONSTANT = 'CONSTANT',\t// Property with constant value (compile time).\n// \tCOMPUTED = 'COMPUTED',\t// Property with computed value (execution time).\n// \tMATERIALIZED_LITERAL = 'MATERIALIZED_LITERAL', // Property value is a materialized literal.\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\t\t// Property is an accessor function.\n// \tPROTOTYPE = 'PROTOTYPE',\t// Property is __proto__.\n// \tSPREAD = 'SPREAD'\n// }\n// export class ObjectLiteralProperty {\n// \tstatic Kind = ObjectLiteralPropertyKind;\n// }\n\n// enum ClassLiteralPropertyKind {\n// \tMETHOD = 'METHOD',\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\n// \tFIELD = 'FIELD'\n// }\n\n// export class ClassLiteralProperty {\n// \tstatic Kind = ClassLiteralPropertyKind;\n// }\n\n// function assertUnreachable(x: never): never {\n// \tthrow new Error(`Didn't expect to get here`);\n// }\n// export function classPropertyKindFor(kind: PropertyKind): ClassLiteralPropertyKind {\n// \tswitch (kind) {\n// \t\tcase PropertyKind.AccessorGetter:\n// \t\t\treturn ClassLiteralPropertyKind.GETTER;\n// \t\tcase PropertyKind.AccessorSetter:\n// \t\t\treturn ClassLiteralPropertyKind.SETTER;\n// \t\tcase PropertyKind.Method:\n// \t\t\treturn ClassLiteralPropertyKind.METHOD;\n// \t\tcase PropertyKind.ClassField:\n// \t\t\treturn ClassLiteralPropertyKind.FIELD;\n// \t}\n// \tthrow new Error(`unexpected property kind: ${kind}`);\n// }\n\n// export enum VariableMode {\n// \tConst = 'Const',\n// \tPrivateMethod = 'PrivateMethod',\n// \tPrivateGetterOnly = 'PrivateGetterOnly',\n// \tPrivateSetterOnly = 'PrivateSetterOnly'\n// }\n\n// export function getVariableMode(kind: ClassLiteralPropertyKind): VariableMode {\n// \tswitch (kind) {\n// \t\tcase ClassLiteralPropertyKind.FIELD:\n// \t\t\treturn VariableMode.Const;\n// \t\tcase ClassLiteralPropertyKind.METHOD:\n// \t\t\treturn VariableMode.PrivateMethod;\n// \t\tcase ClassLiteralPropertyKind.GETTER:\n// \t\t\treturn VariableMode.PrivateGetterOnly;\n// \t\tcase ClassLiteralPropertyKind.SETTER:\n// \t\t\treturn VariableMode.PrivateSetterOnly;\n// \t}\n// }\n\n// export class JavaScriptAppParser extends JavaScriptParser {\n// \tprotected parseNewTargetExpression(): ExpressionNode {\n// \t\tthis.consume(Token.PERIOD);\n//\t\t const target: ExpressionNode = this.parsePropertyName();\n//\t\t if (target.toString() !== 'target') {\n//\t\t \tthrow new Error(this.errorMessage(`Expression (new.${target.toString()}) not supported.`));\n//\t\t }\n//\t\t return MetaProperty.NewTarget;\n// \t}\n// \tprotected parseClassDeclaration(names: ExpressionNode[] | undefined, defaultExport: boolean): ExpressionNode {\n// \t\t// ClassDeclaration ::\n// \t\t// 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t// 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t//\n// \t\t// The anonymous form is allowed iff [default_export] is true.\n// \t\t//\n// \t\t// 'class' is expected to be consumed by the caller.\n// \t\t//\n// \t\t// A ClassDeclaration\n// \t\t//\n// \t\t// class C { ... }\n// \t\t//\n// \t\t// has the same semantics as:\n// \t\t//\n// \t\t// let C = class C { ... };\n// \t\t//\n// \t\t// so rewrite it as such.\n\n// \t\tconst nextToken = this.peek().token;\n// \t\tconst isStrictReserved = Token.isStrictReservedWord(nextToken);\n// \t\tlet name: ExpressionNode | undefined;\n// \t\tlet variableName: ExpressionNode | undefined;\n// \t\tif (defaultExport && (nextToken == Token.EXTENDS || nextToken == Token.L_CURLY)) {\n// \t\t\tname = new StringNode('default');\n// \t\t\tvariableName = new StringNode('.default');\n// \t\t} else {\n// \t\t\tname = this.parseIdentifier();\n// \t\t\tvariableName = name;\n// \t\t}\n// \t\tconst value = this.parseClassLiteral(name, isStrictReserved);\n// \t\treturn this.declareClass(variableName, value, names);\n// \t}\n// \tprotected parseClassLiteral(name: ExpressionNode | undefined, nameIsStrictReserved: boolean): ExpressionNode {\n// \t\t// throw new Error(this.errorMessage(`Expression (class) not supported.`));\n// \t\tconst isAnonymous = !!!name;\n\n// \t\t// All parts of a ClassDeclaration and ClassExpression are strict code.\n// \t\tif (!isAnonymous) {\n// \t\t\tif (nameIsStrictReserved) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Unexpected Strict Reserved class name`));\n// \t\t\t}\n// \t\t\tif (this.isEvalOrArguments(name!)) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Strict Eval Arguments not allowed for class name`));\n// \t\t\t}\n// \t\t}\n\n// \t\t// ClassScope * class_scope = NewClassScope(scope(), is_anonymous);\n// \t\t// BlockState block_state(& scope_, class_scope);\n// \t\t// RaiseLanguageMode(LanguageMode.kStrict);\n\n// \t\t// BlockState object_literal_scope_state(& object_literal_scope_, nullptr);\n\n// \t\t// ClassInfo classInfo(this);\n// \t\t// classInfo.is_anonymous = is_anonymous;\n\n// \t\tconst classInfo = { isAnonymous, computedFieldCount: 0 } as ClassInfo;\n\n// \t\t// scope() -> set_start_position(class_token_pos);\n// \t\tif (this.check(Token.EXTENDS)) {\n// \t\t\t// ClassScope.HeritageParsingScope heritage(class_scope);\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// ExpressionParsingScope scope(impl());\n// \t\t\tclassInfo.extends = this.parseLeftHandSideExpression();\n// \t\t\t// scope.ValidateExpression();\n// \t\t}\n\n// \t\tthis.expect(Token.L_CURLY);\n\n// \t\tconst hasExtends = !(classInfo.extends === undefined);\n\n// \t\tconst staticBlockList: ExpressionNode[] = [];\n// \t\tconst privateClassMemberList: ExpressionNode[] = [];\n// \t\tconst publicClassFieldList: ExpressionNode[] = [];\n// \t\tconst publicClassMethodList: ExpressionNode[] = [];\n\n// \t\twhile (this.peek().isNotType(Token.R_CURLY)) {\n// \t\t\tif (this.check(Token.SEMICOLON)) continue;\n\n// \t\t\t// Either we're parsing a `static { }` initialization block or a property.\n// \t\t\tif (this.peek().isType(Token.STATIC) && this.peekAhead().isType(Token.L_CURLY)) {\n// \t\t\t\tconst staticBlock = this.parseClassStaticBlock(classInfo);\n// \t\t\t\tstaticBlockList.push(staticBlock);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// If we haven't seen the constructor yet, it potentially is the next\n// \t\t\t// property.\n// \t\t\tlet isConstructor = !classInfo.hasSeenConstructor;\n// \t\t\tconst propInfo = new ParsePropertyInfo();\n// \t\t\tpropInfo.position = PropertyPosition.ClassLiteral;\n\n// \t\t\tconst property = this.parseClassPropertyDefinition(classInfo, propInfo, hasExtends);\n\n// \t\t\t// if (has_error()) return impl() -> FailureExpression();\n\n// \t\t\tconst propertyKind = classPropertyKindFor(propInfo.kind);\n// \t\t\tif (!classInfo.hasStaticComputedNames && propInfo.isStatic && propInfo.isComputedName) {\n// \t\t\t\tclassInfo.hasStaticComputedNames = true;\n// \t\t\t}\n// \t\t\tisConstructor &&= classInfo.hasSeenConstructor;\n\n// \t\t\tconst isField = propertyKind == ClassLiteralPropertyKind.FIELD;\n\n// \t\t\tif (propInfo.isPrivate) {\n// \t\t\t\tif (isConstructor) {\n// \t\t\t\t\tthrow new Error(this.errorMessage('private constructor is not allowed'));\n// \t\t\t\t}\n// \t\t\t\tclassInfo.requiresBrand ||= (!isField && !propInfo.isStatic);\n// \t\t\t\tconst isMethod = propertyKind == ClassLiteralPropertyKind.METHOD;\n// \t\t\t\tclassInfo.hasPrivateMethods ||= isMethod;\n// \t\t\t\tclassInfo.hasStaticPrivateMethods ||= isMethod && propInfo.isStatic;\n// \t\t\t\tconst privateClassMember = this.declarePrivateClassMember(propInfo.name, property, propertyKind, propInfo.isStatic, classInfo);\n// \t\t\t\tprivateClassMemberList.push(privateClassMember);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tif (isField) {\n// \t\t\t\tif (propInfo.isComputedName) {\n// \t\t\t\t\tclassInfo.computedFieldCount++;\n// \t\t\t\t}\n// \t\t\t\tconst publicClassField = this.declarePublicClassField(property, propInfo.isStatic, propInfo.isComputedName, classInfo);\n// \t\t\t\tpublicClassFieldList.push(publicClassField);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tconst publicClassMethod = this.declarePublicClassMethod(name, property, isConstructor, classInfo);\n// \t\t\tpublicClassMethodList.push(publicClassMethod);\n// \t\t}\n\n// \t\tthis.expect(Token.R_CURLY);\n// \t\t// int end_pos = end_position();\n// \t\t// class_scope -> set_end_position(end_pos);\n\n// \t\t// VariableProxy * unresolvable = class_scope -> ResolvePrivateNamesPartially();\n// \t\t// if (unresolvable != nullptr) {\n// \t\t// \timpl() -> ReportMessageAt(Scanner.Location(unresolvable -> position(),unresolvable -> position() + 1),\n// \t\t// \t\tMessageTemplate.kInvalidPrivateFieldResolution,\n// \t\t// \t\tunresolvable -> raw_name());\n// \t\t// \treturn impl() -> FailureExpression();\n// \t\t// }\n\n// \t\t// if (classInfo.requiresBrand) {\n// \t\t// \tclass_scope -> DeclareBrandVariable(ast_value_factory(), IsStaticFlag.kNotStatic, kNoSourcePosition);\n// \t\t// }\n\n// \t\t// if (class_scope -> needs_home_object()) {\n// \t\t// \tclassInfo.homeObjectVariable = class_scope -> DeclareHomeObjectVariable(ast_value_factory());\n// \t\t// \tclassInfo.staticHomeObjectVariable = class_scope -> DeclareStaticHomeObjectVariable(ast_value_factory());\n// \t\t// }\n\n// \t\t// bool should_save_class_variable_index = class_scope -> should_save_class_variable_index();\n// \t\t// if (!isAnonymous || should_save_class_variable_index) {\n// \t\t// \tthis.declareClassVariable(name, classInfo);\n// \t\t// \tif (should_save_class_variable_index) {\n// \t\t// \t\tclass_scope -> class_variable() -> set_is_used();\n// \t\t// \t\tclass_scope -> class_variable() -> ForceContextAllocation();\n// \t\t// \t}\n// \t\t// }\n// \t\treturn this.rewriteClassLiteral(name, classInfo);\n// \t}\n// \tprotected declarePublicClassMethod(name: ExpressionNode | undefined, property: ExpressionNode, isConstructor: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePublicClassField(property: ExpressionNode, isStatic: boolean, isComputedName: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected inferFunctionName() {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePrivateClassMember(name: ExpressionNode, property: ExpressionNode, propertyKind: ClassLiteralPropertyKind, isStatic: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassPropertyDefinition(classInfo: ClassInfo, propInfo: ParsePropertyInfo, hasExtends: boolean): ExpressionNode {\n// \t\tif (!classInfo) {\n// \t\t\tthrow new Error(this.errorMessage('class info is undefined'));\n// \t\t}\n// \t\tif (propInfo.position !== PropertyPosition.ClassLiteral) {\n// \t\t\tthrow new Error(this.errorMessage('expected property position ClassLiteral'));\n// \t\t}\n\n// \t\tconst nameToken = this.peek();\n// \t\tlet nameExpression: ExpressionNode;\n// \t\tif (nameToken.isType(Token.STATIC)) {\n// \t\t\tthis.consume(Token.STATIC);\n// \t\t\tif (this.peek().isType(Token.L_PARENTHESES)) {\n// \t\t\t\tpropInfo.kind = PropertyKind.Method;\n// \t\t\t\tpropInfo.name = this.parseIdentifier()!;\n// \t\t\t\tnameExpression = new StringNode(propInfo.name.toString());\n// \t\t\t} else if (this.peek().isType(Token.ASSIGN)\n// \t\t\t\t|| this.peek().isType(Token.SEMICOLON)\n// \t\t\t\t|| this.peek().isType(Token.R_BRACKETS)) {\n// \t\t\t\tpropInfo.name = this.parseIdentifier()!;\n// \t\t\t\tnameExpression = new StringNode(propInfo.name.toString());\n// \t\t\t} else {\n// \t\t\t\tpropInfo.isStatic = true;\n// \t\t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t\t}\n// \t\t} else {\n// \t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t}\n\n// \t\tswitch (propInfo.kind) {\n// \t\t\tcase PropertyKind.Assign:\n// \t\t\tcase PropertyKind.ClassField:\n// \t\t\tcase PropertyKind.ShorthandOrClassField:\n// \t\t\tcase PropertyKind.NotSet: {\n// \t\t\t\t// This case is a name followed by a\n// \t\t\t\t// name or other property. Here we have\n// \t\t\t\t// to assume that's an uninitialized\n// \t\t\t\t// field followed by a line break\n// \t\t\t\t// followed by a property, with ASI\n// \t\t\t\t// adding the semicolon. If not, there\n// \t\t\t\t// will be a syntax error after parsing\n// \t\t\t\t// the first name as an uninitialized\n// \t\t\t\t// field.\n// \t\t\t\tpropInfo.kind = PropertyKind.ClassField;\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassFieldName(propInfo.name, propInfo.isStatic);\n// \t\t\t\t// }\n\n// \t\t\t\tconst initializer: ExpressionNode = this.parseMemberInitializer(classInfo, propInfo.isStatic);\n// \t\t\t\tthis.expectSemicolon();\n\n// \t\t\t\tconst result: ExpressionNode = this.newClassLiteralProperty(\n// \t\t\t\t\tnameExpression,\n// \t\t\t\t\tinitializer,\n// \t\t\t\t\tClassLiteralPropertyKind.FIELD,\n// \t\t\t\t\tpropInfo.isStatic,\n// \t\t\t\t\tpropInfo.isComputedName,\n// \t\t\t\t\tpropInfo.isPrivate\n// \t\t\t\t);\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Method: {\n// \t\t\t\t// MethodDefinition\n// \t\t\t\t// PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// async PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n// \t\t\t\t// async '*' PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassMethodName(propInfo.name, PropertyKind.Method,propInfo.functionFlags, propInfo.isStatic,classInfo . hasSeenConstructor);\n// \t\t\t\t// }\n\n// \t\t\t\tlet kind: FunctionType = this.methodKindFor(propInfo.isStatic, propInfo.functionFlags);\n\n// \t\t\t\tif (!propInfo.isStatic && propInfo.name.toString() === 'constructor') {\n// \t\t\t\t\tclassInfo.hasSeenConstructor = true;\n// \t\t\t\t\tkind = hasExtends ? FunctionType.DERIVED_CONSTRUCTOR : FunctionType.BASE_CONSTRUCTOR;\n// \t\t\t\t}\n\n// \t\t\t\tconst value = this.parseFunctionLiteral(\n// \t\t\t\t\tkind,\n// \t\t\t\t\tpropInfo.name\n// \t\t\t\t\t// ,kSkipFunctionNameCheck, kind, FunctionSyntaxKind.kAccessorOrMethod\n// \t\t\t\t);\n\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\tname_expression, value, ClassLiteralProperty.METHOD,\n// \t\t\t\t\tpropInfo.is_static, propInfo.is_computed_name,\n// \t\t\t\t\tpropInfo.is_private);\n// \t\t\t\timpl() -> SetFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n\n// \t\t\tcase PropertyKind.AccessorGetter:\n// \t\t\tcase PropertyKind.AccessorSetter: {\n// \t\t\t\tDCHECK_EQ(propInfo.function_flags, ParseFunctionFlag.kIsNormal);\n// \t\t\t\tbool is_get = propInfo.kind == PropertyKind.kAccessorGetter;\n\n// \t\t\t\tif (!propInfo.is_computed_name) {\n// \t\t\t\t\tCheckClassMethodName(propInfo.name, propInfo.kind,\n// \t\t\t\t\t\tParseFunctionFlag.kIsNormal, propInfo.is_static,\n// & class_info -> has_seen_constructor);\n// \t\t\t\t\t// Make sure the name expression is a string since we need a Name for\n// \t\t\t\t\t// Runtime_DefineAccessorPropertyUnchecked and since we can determine\n// \t\t\t\t\t// this statically we can skip the extra runtime check.\n// \t\t\t\t\tname_expression = factory() -> NewStringLiteral(\n// \t\t\t\t\t\tpropInfo.name, name_expression -> position());\n// \t\t\t\t}\n\n// \t\t\t\tFunctionKind kind;\n// \t\t\t\tif (propInfo.is_static) {\n// \t\t\t\t\tkind = is_get ? FunctionKind.kStaticGetterFunction\n// \t\t\t\t\t\t: FunctionKind.kStaticSetterFunction;\n// \t\t\t\t} else {\n// \t\t\t\t\tkind = is_get ? FunctionKind.kGetterFunction\n// \t\t\t\t\t\t: FunctionKind.kSetterFunction;\n// \t\t\t\t}\n\n// \t\t\t\tFunctionLiteralT value = impl() -> ParseFunctionLiteral(\n// \t\t\t\t\tpropInfo.name, scanner() -> location(), kSkipFunctionNameCheck, kind,\n// \t\t\t\t\tname_token_position, FunctionSyntaxKind.kAccessorOrMethod,\n// \t\t\t\t\tlanguage_mode(), nullptr);\n\n// \t\t\t\tClassLiteralPropertyKind property_kind =\n// \t\t\t\t\tis_get ? ClassLiteralProperty.GETTER : ClassLiteralProperty.SETTER;\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\tname_expression, value, property_kind, propInfo.is_static,\n// \t\t\t\t\tpropInfo.is_computed_name, propInfo.is_private);\n// \t\t\t\tconst AstRawString* prefix =\n// \t\t\t\tis_get ? ast_value_factory() -> get_space_string()\n// \t\t\t\t\t: ast_value_factory() -> set_space_string();\n// \t\t\t\timpl() -> SetFunctionNameFromPropertyName(result, propInfo.name, prefix);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Value:\n// \t\t\tcase PropertyKind.Shorthand:\n// \t\t\tcase PropertyKind.Spread:\n// \t\t\t\t// throw new Error(this.errorMessage('Report Unexpected Token'));\n// \t\t\t\treturn NullNode;\n// \t\t}\n// \t\tthrow new Error(this.errorMessage('UNREACHABLE'));\n// \t}\n// \tprotected methodKindFor(isStatic: boolean, functionFlags: FunctionType): FunctionType {\n// \t\tconst isGenerator = functionFlags.includes('GENERATOR');\n// \t\tconst isAsync = functionFlags.includes('ASYNC');\n// \t\treturn functionKindForImpl(\n// \t\t\tisStatic ? SubFunctionKind.StaticMethod : SubFunctionKind.NonStaticMethod,\n// \t\t\tisGenerator,\n// \t\t\tisAsync\n// \t\t);\n// \t}\n// \tnewClassLiteralProperty(nameExpression: ExpressionNode, initializer: ExpressionNode, FIELD: ClassLiteralPropertyKind, isStatic: boolean, isComputedName: boolean, isPrivate: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tparseMemberInitializer(classInfo: ClassInfo, isStatic: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassStaticBlock(classInfo: ClassInfo): ExpressionNode {\n// \t\tthis.consume(Token.STATIC);\n// \t\t// Each static block has its own var and lexical scope, so make a new var\n// \t\t// block scope instead of using the synthetic members initializer function\n// \t\t// scope.\n// \t\tconst staticBlock = this.parseBlock();\n// \t\tclassInfo.hasStaticElements = true;\n// \t\treturn staticBlock;\n\n// \t}\n// \tprotected declareClass(variableName: ExpressionNode | undefined, value: ExpressionNode, names: ExpressionNode[] | undefined): ExpressionNode {\n// \t\tif (names && variableName) {\n// \t\t\tconst proxy = this.declareVariable(variableName, 'let');\n// \t\t\tnames.push(variableName);\n// \t\t\treturn new AssignmentNode('=', proxy, value);\n// \t\t}\n// \t\treturn value;\n// \t}\n// \tprotected parseSuperExpression(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (supper) not supported.'));\n// \t}\n// \tprotected parseImportExpressions(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (import) not supported.'));\n// \t}\n// \tprotected declareVariable(name: ExpressionNode | undefined, mode: 'let' | 'const' | 'var') {\n// \t\tif (!name) {\n// \t\t\tthrow new Error(this.errorMessage('Variable name is undefined'));\n// \t\t}\n// \t\tswitch (mode) {\n// \t\t\tcase 'const':\n// \t\t\t\treturn new ConstNode([new Variable(name)]);\n// \t\t\tdefault:\n// \t\t\tcase 'var':\n// \t\t\tcase 'let':\n// \t\t\t\treturn new LetNode([new Variable(name)]);\n// \t\t}\n// \t}\n// }\n"]}
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/expressions/v8/app.ts"],"names":[],"mappings":"","sourcesContent":["// import type { CanDeclareExpression, ExpressionNode } from '../api/expression.js';\n// import { JavaScriptParser, PropertyKind, PropertyKindInfo } from './parser.js';\n// import { Token } from './token.js';\n// import { MetaProperty } from '../api/app/class.js';\n// import { FunctionKind } from '../api/definition/function.js';\n// import { Identifier, Literal } from '../api/definition/values.js';\n// import { AssignmentExpression } from '../api/operators/assignment.js';\n// import { VariableDeclarationNode, VariableNode } from '../api/statement/declarations/declares.js';\n\n\n// export type ClassInfo = {\n// \tisAnonymous: boolean;\n// \textends: ExpressionNode;\n// \thasSeenConstructor: boolean;\n// \thasStaticComputedNames: boolean;\n// \trequiresBrand: boolean;\n// \thasPrivateMethods: boolean,\n// \thasStaticPrivateMethods: boolean;\n// \tcomputedFieldCount: number;\n// \thasStaticElements: boolean;\n// };\n\n// export enum FunctionNameValidity {\n// \tFunctionNameIsStrictReserved = 'FunctionNameIsStrictReserved',\n// \tSkipFunctionNameCheck = 'SkipFunctionNameCheck',\n// \tFunctionNameValidityUnknown = 'FunctionNameValidityUnknown'\n// };\n\n// export enum AllowLabelledFunctionStatement {\n// \tAllowLabelledFunctionStatement = 'AllowLabelledFunctionStatement',\n// \tDisallowLabelledFunctionStatement = 'DisallowLabelledFunctionStatement',\n// };\n\n// export enum ParsingArrowHeadFlag {\n// \tCertainlyNotArrowHead = 'CertainlyNotArrowHead',\n// \tMaybeArrowHead = 'MaybeArrowHead'\n// };\n\n// export enum PropertyPosition {\n// \tObjectLiteral = 'ObjectLiteral',\n// \tClassLiteral = 'ClassLiteral'\n// }\n\n// const FUNCTIONS_TYPES: FunctionKind[][][] = [\n// \t[\n// \t\t// SubFunctionKind::kNormalFunction\n// \t\t[// is_generator=false\n// \t\t\tFunctionKind.NORMAL,\n// \t\t\tFunctionKind.ASYNC\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionKind.GENERATOR,\n// \t\t\tFunctionKind.ASYNC_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kNonStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionKind.CONCISE,\n// \t\t\tFunctionKind.ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionKind.CONCISE_GENERATOR,\n// \t\t\tFunctionKind.ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t],\n// \t[\n// \t\t// SubFunctionKind::kStaticMethod\n// \t\t[// is_generator=false\n// \t\t\tFunctionKind.STATIC_CONCISE,\n// \t\t\tFunctionKind.STATIC_ASYNC_CONCISE\n// \t\t],\n// \t\t[// is_generator=true\n// \t\t\tFunctionKind.STATIC_CONCISE_GENERATOR,\n// \t\t\tFunctionKind.STATIC_ASYNC_CONCISE_GENERATOR\n// \t\t],\n// \t]\n// ];\n\n// export enum SubFunctionKind {\n// \tNormalFunction,\n// \tNonStaticMethod,\n// \tStaticMethod,\n// }\n\n// export function functionKindForImpl(subFunctionKind: SubFunctionKind, isGenerator: boolean, isAsync: boolean): FunctionKind {\n// \treturn FUNCTIONS_TYPES[subFunctionKind as number][isGenerator ? 1 : 0][isAsync ? 1 : 0];\n// }\n\n// export class ParsePropertyInfo implements PropertyKindInfo {\n// \tname: string;\n// \tposition = PropertyPosition.ClassLiteral;\n// \tfuncFlag = FunctionKind.NORMAL;\n// \tkind = PropertyKind.NotSet;\n// \tisComputedName = false;\n// \tisPrivate = false;\n// \tisStatic = false;\n// \tisRest = false;\n\n// \tPropertyKindFromToken(token: Token): boolean {\n// \t\t// This returns true, setting the property kind, iff the given token is\n// \t\t// one which must occur after a property name, indicating that the\n// \t\t// previous token was in fact a name and not a modifier (like the \"get\" in\n// \t\t// \"get x\").\n// \t\tswitch (token) {\n// \t\t\tcase Token.COLON:\n// \t\t\t\tthis.kind = PropertyKind.Value;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.COMMA:\n// \t\t\t\tthis.kind = PropertyKind.Shorthand;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.R_CURLY:\n// \t\t\t\tthis.kind = PropertyKind.ShorthandOrClassField;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.ASSIGN:\n// \t\t\t\tthis.kind = PropertyKind.Assign;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.L_PARENTHESES:\n// \t\t\t\tthis.kind = PropertyKind.Method;\n// \t\t\t\treturn true;\n// \t\t\tcase Token.MUL:\n// \t\t\tcase Token.SEMICOLON:\n// \t\t\t\tthis.kind = PropertyKind.ClassField;\n// \t\t\t\treturn true;\n// \t\t\tdefault:\n// \t\t\t\tbreak;\n// \t\t}\n// \t\treturn false;\n// \t}\n\n// }\n// enum ObjectLiteralPropertyKind {\n// \tCONSTANT = 'CONSTANT',\t// Property with constant value (compile time).\n// \tCOMPUTED = 'COMPUTED',\t// Property with computed value (execution time).\n// \tMATERIALIZED_LITERAL = 'MATERIALIZED_LITERAL', // Property value is a materialized literal.\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\t\t// Property is an accessor function.\n// \tPROTOTYPE = 'PROTOTYPE',\t// Property is __proto__.\n// \tSPREAD = 'SPREAD'\n// }\n// export class ObjectLiteralProperty {\n// \tstatic Kind = ObjectLiteralPropertyKind;\n// }\n\n// enum ClassLiteralPropertyKind {\n// \tMETHOD = 'METHOD',\n// \tGETTER = 'GETTER',\n// \tSETTER = 'SETTER',\n// \tFIELD = 'FIELD'\n// }\n\n// export class ClassLiteralProperty {\n// \tstatic Kind = ClassLiteralPropertyKind;\n// }\n\n// function assertUnreachable(x: never): never {\n// \tthrow new Error(`Didn't expect to get here`);\n// }\n// export function classPropertyKindFor(kind: PropertyKind): ClassLiteralPropertyKind {\n// \tswitch (kind) {\n// \t\tcase PropertyKind.AccessorGetter:\n// \t\t\treturn ClassLiteralPropertyKind.GETTER;\n// \t\tcase PropertyKind.AccessorSetter:\n// \t\t\treturn ClassLiteralPropertyKind.SETTER;\n// \t\tcase PropertyKind.Method:\n// \t\t\treturn ClassLiteralPropertyKind.METHOD;\n// \t\tcase PropertyKind.ClassField:\n// \t\t\treturn ClassLiteralPropertyKind.FIELD;\n// \t}\n// \tthrow new Error(`unexpected property kind: ${kind}`);\n// }\n\n// export enum VariableMode {\n// \tConst = 'Const',\n// \tPrivateMethod = 'PrivateMethod',\n// \tPrivateGetterOnly = 'PrivateGetterOnly',\n// \tPrivateSetterOnly = 'PrivateSetterOnly'\n// }\n\n// export function getVariableMode(kind: ClassLiteralPropertyKind): VariableMode {\n// \tswitch (kind) {\n// \t\tcase ClassLiteralPropertyKind.FIELD:\n// \t\t\treturn VariableMode.Const;\n// \t\tcase ClassLiteralPropertyKind.METHOD:\n// \t\t\treturn VariableMode.PrivateMethod;\n// \t\tcase ClassLiteralPropertyKind.GETTER:\n// \t\t\treturn VariableMode.PrivateGetterOnly;\n// \t\tcase ClassLiteralPropertyKind.SETTER:\n// \t\t\treturn VariableMode.PrivateSetterOnly;\n// \t}\n// }\n\n// export class JavaScriptAppParser extends JavaScriptParser {\n// \tprotected parseNewTargetExpression(): ExpressionNode {\n// \t\tthis.consume(Token.PERIOD);\n// \t\tconst target: ExpressionNode = this.parsePropertyName();\n// \t\tif (target.toString() !== 'target') {\n// \t\t\tthrow new Error(this.errorMessage(`Expression (new.${target.toString()}) not supported.`));\n// \t\t}\n// \t\treturn MetaProperty.NewTarget;\n// \t}\n// \tprotected parseClassDeclaration(names: ExpressionNode[] | undefined, defaultExport: boolean): ExpressionNode {\n// \t\t// ClassDeclaration ::\n// \t\t// 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t// 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'\n// \t\t//\n// \t\t// The anonymous form is allowed iff [default_export] is true.\n// \t\t//\n// \t\t// 'class' is expected to be consumed by the caller.\n// \t\t//\n// \t\t// A ClassDeclaration\n// \t\t//\n// \t\t// class C { ... }\n// \t\t//\n// \t\t// has the same semantics as:\n// \t\t//\n// \t\t// let C = class C { ... };\n// \t\t//\n// \t\t// so rewrite it as such.\n\n// \t\tconst nextToken = this.peek().token;\n// \t\tconst isStrictReserved = Token.isStrictReservedWord(nextToken);\n// \t\tlet name: ExpressionNode | undefined;\n// \t\tlet variableName: ExpressionNode | undefined;\n// \t\tif (defaultExport && (nextToken == Token.EXTENDS || nextToken == Token.L_CURLY)) {\n// \t\t\tname = new Literal('default');\n// \t\t\tvariableName = new Literal('.default');\n// \t\t} else {\n// \t\t\tname = this.parseIdentifier();\n// \t\t\tvariableName = name;\n// \t\t}\n// \t\tconst value = this.parseClassLiteral(name, isStrictReserved);\n// \t\treturn this.declareClass(variableName, value, names);\n// \t}\n// \tprotected parseClassLiteral(name: ExpressionNode | undefined, nameIsStrictReserved: boolean): ExpressionNode {\n// \t\tconst isAnonymous = !!!name;\n\n// \t\t// All parts of a ClassDeclaration and ClassExpression are strict code.\n// \t\tif (!isAnonymous) {\n// \t\t\tif (nameIsStrictReserved) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Unexpected Strict Reserved class name`));\n// \t\t\t}\n// \t\t\tif (this.isEvalOrArguments(name!)) {\n// \t\t\t\tthrow new Error(this.errorMessage(`Strict Eval Arguments not allowed for class name`));\n// \t\t\t}\n// \t\t}\n\n// \t\t// ClassScope * class_scope = NewClassScope(scope(), is_anonymous);\n// \t\t// BlockState block_state(& scope_, class_scope);\n// \t\t// RaiseLanguageMode(LanguageMode.kStrict);\n\n// \t\t// BlockState object_literal_scope_state(& object_literal_scope_, nullptr);\n\n// \t\t// ClassInfo classInfo(this);\n// \t\t// classInfo.is_anonymous = is_anonymous;\n\n// \t\tconst classInfo = { isAnonymous, computedFieldCount: 0 } as ClassInfo;\n\n// \t\t// scope() -> set_start_position(class_token_pos);\n// \t\tif (this.check(Token.EXTENDS)) {\n// \t\t\t// ClassScope.HeritageParsingScope heritage(class_scope);\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// ExpressionParsingScope scope(impl());\n// \t\t\tclassInfo.extends = this.parseLeftHandSideExpression();\n// \t\t\t// scope.ValidateExpression();\n// \t\t}\n\n// \t\tthis.expect(Token.L_CURLY);\n\n// \t\tconst hasExtends = !(classInfo.extends === undefined);\n\n// \t\tconst staticBlockList: ExpressionNode[] = [];\n// \t\tconst privateClassMemberList: ExpressionNode[] = [];\n// \t\tconst publicClassFieldList: ExpressionNode[] = [];\n// \t\tconst publicClassMethodList: ExpressionNode[] = [];\n\n// \t\twhile (this.peek().isNotType(Token.R_CURLY)) {\n// \t\t\tif (this.check(Token.SEMICOLON)) continue;\n\n// \t\t\t// Either we're parsing a `static { }` initialization block or a property.\n// \t\t\tif (this.peek().isType(Token.STATIC) && this.peekAhead().isType(Token.L_CURLY)) {\n// \t\t\t\tconst staticBlock = this.parseClassStaticBlock(classInfo);\n// \t\t\t\tstaticBlockList.push(staticBlock);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\t// FuncNameInferrerState fni_state(& fni_);\n// \t\t\t// If we haven't seen the constructor yet, it potentially is the next\n// \t\t\t// property.\n// \t\t\tlet isConstructor = !classInfo.hasSeenConstructor;\n// \t\t\tconst propInfo = new ParsePropertyInfo();\n// \t\t\tpropInfo.position = PropertyPosition.ClassLiteral;\n\n// \t\t\tconst property = this.parseClassPropertyDefinition(classInfo, propInfo, hasExtends);\n\n// \t\t\t// if (has_error()) return impl() -> FailureExpression();\n\n// \t\t\tconst propertyKind = classPropertyKindFor(propInfo.kind);\n// \t\t\tif (!classInfo.hasStaticComputedNames && propInfo.isStatic && propInfo.isComputedName) {\n// \t\t\t\tclassInfo.hasStaticComputedNames = true;\n// \t\t\t}\n// \t\t\tisConstructor &&= classInfo.hasSeenConstructor;\n\n// \t\t\tconst isField = propertyKind == ClassLiteralPropertyKind.FIELD;\n\n// \t\t\tif (propInfo.isPrivate) {\n// \t\t\t\tif (isConstructor) {\n// \t\t\t\t\tthrow new Error(this.errorMessage('private constructor is not allowed'));\n// \t\t\t\t}\n// \t\t\t\tclassInfo.requiresBrand ||= (!isField && !propInfo.isStatic);\n// \t\t\t\tconst isMethod = propertyKind == ClassLiteralPropertyKind.METHOD;\n// \t\t\t\tclassInfo.hasPrivateMethods ||= isMethod;\n// \t\t\t\tclassInfo.hasStaticPrivateMethods ||= isMethod && propInfo.isStatic;\n// \t\t\t\tconst privateClassMember = this.declarePrivateClassMember(propInfo.name, property, propertyKind, propInfo.isStatic, classInfo);\n// \t\t\t\tprivateClassMemberList.push(privateClassMember);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tif (isField) {\n// \t\t\t\tif (propInfo.isComputedName) {\n// \t\t\t\t\tclassInfo.computedFieldCount++;\n// \t\t\t\t}\n// \t\t\t\tconst publicClassField = this.declarePublicClassField(property, propInfo.isStatic, propInfo.isComputedName, classInfo);\n// \t\t\t\tpublicClassFieldList.push(publicClassField);\n// \t\t\t\tcontinue;\n// \t\t\t}\n\n// \t\t\tconst publicClassMethod = this.declarePublicClassMethod(name, property, isConstructor, classInfo);\n// \t\t\tpublicClassMethodList.push(publicClassMethod);\n// \t\t}\n\n// \t\tthis.expect(Token.R_CURLY);\n// \t\t// int end_pos = end_position();\n// \t\t// class_scope -> set_end_position(end_pos);\n\n// \t\t// VariableProxy * unresolvable = class_scope -> ResolvePrivateNamesPartially();\n// \t\t// if (unresolvable != nullptr) {\n// \t\t// \timpl() -> ReportMessageAt(Scanner.Location(unresolvable -> position(),unresolvable -> position() + 1),\n// \t\t// \t\tMessageTemplate.kInvalidPrivateFieldResolution,\n// \t\t// \t\tunresolvable -> raw_name());\n// \t\t// \treturn impl() -> FailureExpression();\n// \t\t// }\n\n// \t\t// if (classInfo.requiresBrand) {\n// \t\t// \tclass_scope -> DeclareBrandVariable(ast_value_factory(), IsStaticFlag.kNotStatic, kNoSourcePosition);\n// \t\t// }\n\n// \t\t// if (class_scope -> needs_home_object()) {\n// \t\t// \tclassInfo.homeObjectVariable = class_scope -> DeclareHomeObjectVariable(ast_value_factory());\n// \t\t// \tclassInfo.staticHomeObjectVariable = class_scope -> DeclareStaticHomeObjectVariable(ast_value_factory());\n// \t\t// }\n\n// \t\t// bool should_save_class_variable_index = class_scope -> should_save_class_variable_index();\n// \t\t// if (!isAnonymous || should_save_class_variable_index) {\n// \t\t// \tthis.declareClassVariable(name, classInfo);\n// \t\t// \tif (should_save_class_variable_index) {\n// \t\t// \t\tclass_scope -> class_variable() -> set_is_used();\n// \t\t// \t\tclass_scope -> class_variable() -> ForceContextAllocation();\n// \t\t// \t}\n// \t\t// }\n// \t\treturn this.rewriteClassLiteral(name, classInfo);\n// \t}\n// \tprotected declarePublicClassMethod(name: ExpressionNode | undefined, property: ExpressionNode, isConstructor: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePublicClassField(property: ExpressionNode, isStatic: boolean, isComputedName: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected inferFunctionName() {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected declarePrivateClassMember(name: string, property: ExpressionNode, propertyKind: ClassLiteralPropertyKind, isStatic: boolean, classInfo: ClassInfo): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassPropertyDefinition(classInfo: ClassInfo, propInfo: ParsePropertyInfo, hasExtends: boolean): ExpressionNode {\n// \t\tif (!classInfo) {\n// \t\t\tthrow new Error(this.errorMessage('class info is undefined'));\n// \t\t}\n// \t\tif (propInfo.position !== PropertyPosition.ClassLiteral) {\n// \t\t\tthrow new Error(this.errorMessage('expected property position ClassLiteral'));\n// \t\t}\n\n// \t\tconst nameToken = this.peek();\n// \t\tlet nameExpression: ExpressionNode;\n// \t\tif (nameToken.isType(Token.STATIC)) {\n// \t\t\tthis.consume(Token.STATIC);\n// \t\t\tif (this.peek().isType(Token.L_PARENTHESES)) {\n// \t\t\t\tpropInfo.kind = PropertyKind.Method;\n// \t\t\t\tnameExpression = this.parseIdentifier();\n// \t\t\t\tpropInfo.name = (nameExpression as Identifier).getName() as string;\n// \t\t\t} else if (this.peek().isType(Token.ASSIGN)\n// \t\t\t\t|| this.peek().isType(Token.SEMICOLON)\n// \t\t\t\t|| this.peek().isType(Token.R_BRACKETS)) {\n// \t\t\t\tnameExpression = this.parseIdentifier();\n// \t\t\t\tpropInfo.name = (nameExpression as Identifier).getName() as string;\n// \t\t\t} else {\n// \t\t\t\tpropInfo.isStatic = true;\n// \t\t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t\t}\n// \t\t} else {\n// \t\t\tnameExpression = this.parseProperty(propInfo);\n// \t\t}\n\n// \t\tswitch (propInfo.kind) {\n// \t\t\tcase PropertyKind.Assign:\n// \t\t\tcase PropertyKind.ClassField:\n// \t\t\tcase PropertyKind.ShorthandOrClassField:\n// \t\t\tcase PropertyKind.NotSet: {\n// \t\t\t\t// This case is a name followed by a\n// \t\t\t\t// name or other property. Here we have\n// \t\t\t\t// to assume that's an uninitialized\n// \t\t\t\t// field followed by a line break\n// \t\t\t\t// followed by a property, with ASI\n// \t\t\t\t// adding the semicolon. If not, there\n// \t\t\t\t// will be a syntax error after parsing\n// \t\t\t\t// the first name as an uninitialized\n// \t\t\t\t// field.\n// \t\t\t\tpropInfo.kind = PropertyKind.ClassField;\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassFieldName(propInfo.name, propInfo.isStatic);\n// \t\t\t\t// }\n\n// \t\t\t\tconst initializer: ExpressionNode = this.parseMemberInitializer(classInfo, propInfo.isStatic);\n// \t\t\t\tthis.expectSemicolon();\n\n// \t\t\t\tconst result: ExpressionNode = this.newClassLiteralProperty(\n// \t\t\t\t\tnameExpression,\n// \t\t\t\t\tinitializer,\n// \t\t\t\t\tClassLiteralPropertyKind.FIELD,\n// \t\t\t\t\tpropInfo.isStatic,\n// \t\t\t\t\tpropInfo.isComputedName,\n// \t\t\t\t\tpropInfo.isPrivate\n// \t\t\t\t);\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Method: {\n// \t\t\t\t// MethodDefinition\n// \t\t\t\t// PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}'\n// \t\t\t\t// async PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n// \t\t\t\t// async '*' PropertyName '(' StrictFormalParameters ')'\n// \t\t\t\t// '{' FunctionBody '}'\n\n// \t\t\t\t// if (!propInfo.isComputedName) {\n// \t\t\t\t// \tthis.checkClassMethodName(propInfo.name, PropertyKind.Method,propInfo.functionFlags, propInfo.isStatic,classInfo . hasSeenConstructor);\n// \t\t\t\t// }\n\n// \t\t\t\tlet kind: FunctionKind = this.methodKindFor(propInfo.isStatic, propInfo.funcFlag);\n\n// \t\t\t\tif (!propInfo.isStatic && propInfo.name.toString() === 'constructor') {\n// \t\t\t\t\tclassInfo.hasSeenConstructor = true;\n// \t\t\t\t\tkind = hasExtends ? FunctionKind.DERIVED_CONSTRUCTOR : FunctionKind.BASE_CONSTRUCTOR;\n// \t\t\t\t}\n\n// \t\t\t\tconst value = this.parseFunctionLiteral(\n// \t\t\t\t\tkind,\n// \t\t\t\t\tpropInfo.name\n// \t\t\t\t\t// ,kSkipFunctionNameCheck, kind, FunctionSyntaxKind.kAccessorOrMethod\n// \t\t\t\t);\n\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\tname_expression, value, ClassLiteralProperty.METHOD,\n// \t\t\t\t\tpropInfo.is_static, propInfo.is_computed_name,\n// \t\t\t\t\tpropInfo.is_private);\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name);\n// \t\t\t\treturn result;\n// \t\t\t}\n\n// \t\t\tcase PropertyKind.AccessorGetter:\n// \t\t\tcase PropertyKind.AccessorSetter: {\n// \t\t\t\tDCHECK_EQ(propInfo.function_flags, ParseFunctionFlag.kIsNormal);\n// \t\t\t\tbool is_get = propInfo.kind == PropertyKind.kAccessorGetter;\n\n// \t\t\t\tif (!propInfo.is_computed_name) {\n// \t\t\t\t\tCheckClassMethodName(propInfo.name, propInfo.kind,\n// \t\t\t\t\t\tParseFunctionFlag.kIsNormal, propInfo.is_static,\n// & class_info -> has_seen_constructor);\n// \t\t\t\t\t// Make sure the name expression is a string since we need a Name for\n// \t\t\t\t\t// Runtime_DefineAccessorPropertyUnchecked and since we can determine\n// \t\t\t\t\t// this statically we can skip the extra runtime check.\n// \t\t\t\t\tname_expression = factory() -> NewStringLiteral(\n// \t\t\t\t\t\tpropInfo.name, name_expression -> position());\n// \t\t\t\t}\n\n// \t\t\t\tlet kind: FunctionKind;\n// \t\t\t\tif (propInfo.is_static) {\n// \t\t\t\t\tkind = is_get ? FunctionKind.StaticGetterFunction\n// \t\t\t\t\t\t: FunctionKind.StaticSetterFunction;\n// \t\t\t\t} else {\n// \t\t\t\t\tkind = is_get ? FunctionKind.GetterFunction\n// \t\t\t\t\t\t: FunctionKind.SetterFunction;\n// \t\t\t\t}\n\n// \t\t\t\tFunctionLiteralT value = impl() -> ParseFunctionLiteral(\n// \t\t\t\t\tpropInfo.name, scanner() -> location(), kSkipFunctionNameCheck, kind,\n// \t\t\t\t\tname_token_position, FunctionSyntaxKind.kAccessorOrMethod,\n// \t\t\t\t\tlanguage_mode(), nullptr);\n\n// \t\t\t\tClassLiteralPropertyKind property_kind =\n// \t\t\t\t\tis_get ? ClassLiteralProperty.GETTER : ClassLiteralProperty.SETTER;\n// \t\t\t\tClassLiteralPropertyT result = factory() -> NewClassLiteralProperty(\n// \t\t\t\t\t\tname_expression, value, property_kind, propInfo.is_static,\n// \t\t\t\t\t\tpropInfo.is_computed_name, propInfo.is_private);\n// \t\t\t\tconst AstRawString* prefix =\n// \t\t\t\tis_get ? ast_value_factory() -> get_space_string()\n// \t\t\t\t\t: ast_value_factory() -> set_space_string();\n// \t\t\t\tthis.setFunctionNameFromPropertyName(result, propInfo.name, prefix);\n// \t\t\t\treturn result;\n// \t\t\t}\n// \t\t\tcase PropertyKind.Value:\n// \t\t\tcase PropertyKind.Shorthand:\n// \t\t\tcase PropertyKind.Spread:\n// \t\t\t\t// throw new Error(this.errorMessage('Report Unexpected Token'));\n// \t\t\t\treturn NullNode;\n// \t\t}\n// \t\tthrow new Error(this.errorMessage('UNREACHABLE'));\n// \t}\n// \tsetFunctionNameFromPropertyName(property: LiteralProperty, name: string, prefix?: string): void {\n// \t\t// Ignore \"__proto__\" as a name when it's being used to set the [[Prototype]]\n// \t\t// of an object literal.\n// \t\t// See ES #sec-__proto__-property-names-in-object-initializers.\n\n// \t\tif (property instanceof Identifier && property.getName() === '__proto__') {\n// \t\t\treturn;\n// \t\t}\n\n// \t\t// if (property -> IsPrototype() || has_error()) return;\n\n// \t\t// DCHECK(!property -> value() -> IsAnonymousFunctionDefinition() ||\n// \t\t// \tproperty -> kind() == ObjectLiteralProperty:: COMPUTED);\n\n// \t\t// SetFunctionNameFromPropertyName(static_cast < LiteralProperty *> (property), name,\n// \t\t// \tprefix);\n// \t}\n// \tprotected methodKindFor(isStatic: boolean, functionFlags: FunctionKind): FunctionKind {\n// \t\tconst isGenerator = functionFlags.includes('GENERATOR');\n// \t\tconst isAsync = functionFlags.includes('ASYNC');\n// \t\treturn functionKindForImpl(\n// \t\t\tisStatic ? SubFunctionKind.StaticMethod : SubFunctionKind.NonStaticMethod,\n// \t\t\tisGenerator,\n// \t\t\tisAsync\n// \t\t);\n// \t}\n// \tnewClassLiteralProperty(nameExpression: ExpressionNode, initializer: ExpressionNode, FIELD: ClassLiteralPropertyKind, isStatic: boolean, isComputedName: boolean, isPrivate: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tparseMemberInitializer(classInfo: ClassInfo, isStatic: boolean): ExpressionNode {\n// \t\tthrow new Error('Method not implemented.');\n// \t}\n// \tprotected parseClassStaticBlock(classInfo: ClassInfo): ExpressionNode {\n// \t\tthis.consume(Token.STATIC);\n// \t\t// Each static block has its own var and lexical scope, so make a new var\n// \t\t// block scope instead of using the synthetic members initializer function\n// \t\t// scope.\n// \t\tconst staticBlock = this.parseBlock();\n// \t\tclassInfo.hasStaticElements = true;\n// \t\treturn staticBlock;\n\n// \t}\n// \tprotected declareClass(variableName: ExpressionNode | undefined, value: ExpressionNode, names: ExpressionNode[] | undefined): ExpressionNode {\n// \t\tif (names && variableName) {\n// \t\t\tconst proxy = this.declareVariable(variableName, 'let');\n// \t\t\tnames.push(variableName);\n// \t\t\treturn new AssignmentExpression('=', proxy, value);\n// \t\t}\n// \t\treturn value;\n// \t}\n// \tprotected parseSuperExpression(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (supper) not supported.'));\n// \t}\n// \tprotected parseImportExpressions(): ExpressionNode {\n// \t\tthrow new Error(this.errorMessage('Expression (import) not supported.'));\n// \t}\n// \tprotected declareVariable(name: ExpressionNode | undefined, mode: 'let' | 'const' | 'var') {\n// \t\tif (!name) {\n// \t\t\tthrow new Error(this.errorMessage('Variable name is undefined'));\n// \t\t}\n// \t\tswitch (mode) {\n// \t\t\tcase 'const':\n// \t\t\t\treturn new VariableDeclarationNode([new VariableNode(name as CanDeclareExpression)], 'const');\n// \t\t\tdefault:\n// \t\t\tcase 'var':\n// \t\t\t\treturn new VariableDeclarationNode([new VariableNode(name as CanDeclareExpression)], 'var');\n// \t\t\tcase 'let':\n// \t\t\t\treturn new VariableDeclarationNode([new VariableNode(name as CanDeclareExpression)], 'let');\n// \t\t}\n// \t}\n// }\n"]}
package/v8/parser.d.ts CHANGED
@@ -106,7 +106,7 @@ export declare class JavaScriptParser extends AbstractParser {
106
106
  protected parseFunctionDeclaration(): ExpressionNode;
107
107
  protected parseFunctionDeclarationAndGenerator(): ExpressionNode;
108
108
  protected parseHoistableDeclaration(flag: FunctionKind): ExpressionNode;
109
- protected parseIdentifier(): ExpressionNode | undefined;
109
+ protected parseIdentifier(): ExpressionNode;
110
110
  protected getIdentifier(): ExpressionNode;
111
111
  protected parseFunctionLiteral(flag: FunctionKind, name?: ExpressionNode): ExpressionNode;
112
112
  protected parseArrowFunctionBody(): ExpressionNode | ExpressionNode[];
package/v8/parser.js CHANGED
@@ -21,7 +21,7 @@ import { SwitchCase, DefaultExpression, SwitchStatement } from '../api/statement
21
21
  import { BreakStatement, ContinueStatement } from '../api/statement/control/terminate.js';
22
22
  import { ReturnStatement } from '../api/computing/return.js';
23
23
  import { YieldExpression } from '../api/computing/yield.js';
24
- import { VariableNode, VariableDeclarationNode } from '../api/statement/declarations/declares.js';
24
+ import { VariableDeclarator, VariableDeclarationNode } from '../api/statement/declarations/declares.js';
25
25
  import { ForNode, ForOfNode, ForInNode, ForAwaitOfNode } from '../api/statement/iterations/for.js';
26
26
  import { ConditionalExpression } from '../api/operators/ternary.js';
27
27
  import { PipelineExpression } from '../api/operators/pipeline.js';
@@ -566,6 +566,7 @@ export class JavaScriptParser extends AbstractParser {
566
566
  case Token.VAR:
567
567
  this.consume(token);
568
568
  mode = 'var';
569
+ break;
569
570
  case Token.LET:
570
571
  default:
571
572
  this.consume(token);
@@ -593,7 +594,7 @@ export class JavaScriptParser extends AbstractParser {
593
594
  throw new Error(this.errorMessage(`Declaration Missing Initializer : ${this.position()}`));
594
595
  }
595
596
  }
596
- variables.push(new VariableNode(name, value));
597
+ variables.push(new VariableDeclarator(name, value));
597
598
  } while (this.check(Token.COMMA));
598
599
  return new VariableDeclarationNode(variables, mode);
599
600
  }