vladx 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +256 -0
- package/bin/cli.js +486 -0
- package/bin/vlad.js +539 -0
- package/bin/vladpm.js +710 -0
- package/bin/vladx.js +491 -0
- package/package.json +57 -0
- package/src/engine/jit-compiler.js +285 -0
- package/src/engine/vladx-engine.js +941 -0
- package/src/index.js +44 -0
- package/src/interpreter/interpreter.js +2114 -0
- package/src/lexer/lexer.js +658 -0
- package/src/lexer/optimized-lexer.js +106 -0
- package/src/lexer/regex-cache.js +83 -0
- package/src/parser/ast-nodes.js +472 -0
- package/src/parser/parser.js +1408 -0
- package/src/runtime/advanced-type-system.js +209 -0
- package/src/runtime/async-manager.js +252 -0
- package/src/runtime/builtins.js +143 -0
- package/src/runtime/bundler.js +422 -0
- package/src/runtime/cache-manager.js +126 -0
- package/src/runtime/data-structures.js +612 -0
- package/src/runtime/debugger.js +260 -0
- package/src/runtime/enhanced-module-system.js +196 -0
- package/src/runtime/environment-enhanced.js +272 -0
- package/src/runtime/environment.js +140 -0
- package/src/runtime/event-emitter.js +232 -0
- package/src/runtime/formatter.js +280 -0
- package/src/runtime/functional.js +359 -0
- package/src/runtime/io-operations.js +390 -0
- package/src/runtime/linter.js +374 -0
- package/src/runtime/logging.js +314 -0
- package/src/runtime/minifier.js +242 -0
- package/src/runtime/module-system.js +377 -0
- package/src/runtime/network-operations.js +373 -0
- package/src/runtime/profiler.js +295 -0
- package/src/runtime/repl.js +336 -0
- package/src/runtime/security-manager.js +244 -0
- package/src/runtime/source-map-generator.js +208 -0
- package/src/runtime/test-runner.js +394 -0
- package/src/runtime/transformer.js +277 -0
- package/src/runtime/type-system.js +244 -0
- package/src/runtime/vladx-object.js +250 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OptimizedLexer — Оптимизированный лексер с кэшированием
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Lexer } from './lexer.js';
|
|
6
|
+
import { RegexCache } from './regex-cache.js';
|
|
7
|
+
|
|
8
|
+
export class OptimizedLexer extends Lexer {
|
|
9
|
+
constructor(source, filename = '<anonymous>') {
|
|
10
|
+
super(source, filename);
|
|
11
|
+
this.regexCache = new RegexCache({ maxSize: 50 });
|
|
12
|
+
this.charCache = new Map();
|
|
13
|
+
this.lineCache = new Map();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Быстрая проверка символа с кэшированием
|
|
18
|
+
*/
|
|
19
|
+
isDigitFast(char) {
|
|
20
|
+
const cacheKey = `digit_${char}`;
|
|
21
|
+
if (this.charCache.has(cacheKey)) {
|
|
22
|
+
return this.charCache.get(cacheKey);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const result = char >= '0' && char <= '9';
|
|
26
|
+
this.charCache.set(cacheKey, result);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Быстрая проверка буквы
|
|
32
|
+
*/
|
|
33
|
+
isAlphaFast(char) {
|
|
34
|
+
const cacheKey = `alpha_${char}`;
|
|
35
|
+
if (this.charCache.has(cacheKey)) {
|
|
36
|
+
return this.charCache.get(cacheKey);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const result = this.isAlpha(char);
|
|
40
|
+
this.charCache.set(cacheKey, result);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Кэшированное получение regex
|
|
46
|
+
*/
|
|
47
|
+
getRegex(pattern, flags = '') {
|
|
48
|
+
return this.regexCache.get(pattern, flags);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Оптимизированный skipWhitespace
|
|
53
|
+
*/
|
|
54
|
+
skipWhitespace() {
|
|
55
|
+
const startLine = this.line;
|
|
56
|
+
|
|
57
|
+
while (this.currentChar !== null && /\s/.test(this.currentChar)) {
|
|
58
|
+
if (this.currentChar === '\n') {
|
|
59
|
+
this.line++;
|
|
60
|
+
this.column = 0;
|
|
61
|
+
}
|
|
62
|
+
this.advance();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Кэширование результатов токенизации
|
|
68
|
+
*/
|
|
69
|
+
tokenizeCached() {
|
|
70
|
+
const cacheKey = `${this.filename}_${this.source.length}_${this.source.substring(0, 100)}`;
|
|
71
|
+
|
|
72
|
+
if (this.lineCache.has(cacheKey)) {
|
|
73
|
+
return [...this.lineCache.get(cacheKey)];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const tokens = this.tokenize();
|
|
77
|
+
|
|
78
|
+
if (this.lineCache.size < 10) {
|
|
79
|
+
this.lineCache.set(cacheKey, [...tokens]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return tokens;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Получить статистику оптимизации
|
|
87
|
+
*/
|
|
88
|
+
getOptimizationStats() {
|
|
89
|
+
return {
|
|
90
|
+
regexCache: this.regexCache.getStats(),
|
|
91
|
+
charCacheSize: this.charCache.size,
|
|
92
|
+
lineCacheSize: this.lineCache.size
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Очистить кэши
|
|
98
|
+
*/
|
|
99
|
+
clearCaches() {
|
|
100
|
+
this.regexCache.clear();
|
|
101
|
+
this.charCache.clear();
|
|
102
|
+
this.lineCache.clear();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default OptimizedLexer;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RegexCache — Кэширование и оптимизация регулярных выражений
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export class RegexCache {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this.cache = new Map();
|
|
8
|
+
this.maxSize = options.maxSize || 100;
|
|
9
|
+
this.compiledCount = 0;
|
|
10
|
+
this.hitCount = 0;
|
|
11
|
+
this.missCount = 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Получить или создать regex из кэша
|
|
16
|
+
*/
|
|
17
|
+
get(pattern, flags = '') {
|
|
18
|
+
const key = `${pattern}::${flags}`;
|
|
19
|
+
|
|
20
|
+
if (this.cache.has(key)) {
|
|
21
|
+
this.hitCount++;
|
|
22
|
+
return this.cache.get(key);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.missCount++;
|
|
26
|
+
const regex = new RegExp(pattern, flags);
|
|
27
|
+
|
|
28
|
+
if (this.cache.size >= this.maxSize) {
|
|
29
|
+
this.evictOldest();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.cache.set(key, regex);
|
|
33
|
+
this.compiledCount++;
|
|
34
|
+
|
|
35
|
+
return regex;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Очистить кэш
|
|
40
|
+
*/
|
|
41
|
+
clear() {
|
|
42
|
+
this.cache.clear();
|
|
43
|
+
this.compiledCount = 0;
|
|
44
|
+
this.hitCount = 0;
|
|
45
|
+
this.missCount = 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Evict самый старый regex
|
|
50
|
+
*/
|
|
51
|
+
evictOldest() {
|
|
52
|
+
let oldestKey = null;
|
|
53
|
+
let oldestTime = Infinity;
|
|
54
|
+
|
|
55
|
+
for (const [key, entry] of this.cache) {
|
|
56
|
+
if (entry.timestamp < oldestTime) {
|
|
57
|
+
oldestTime = entry.timestamp;
|
|
58
|
+
oldestKey = key;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (oldestKey) {
|
|
63
|
+
this.cache.delete(oldestKey);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Получить статистику
|
|
69
|
+
*/
|
|
70
|
+
getStats() {
|
|
71
|
+
const total = this.hitCount + this.missCount;
|
|
72
|
+
return {
|
|
73
|
+
size: this.cache.size,
|
|
74
|
+
maxSize: this.maxSize,
|
|
75
|
+
compiledCount: this.compiledCount,
|
|
76
|
+
hitCount: this.hitCount,
|
|
77
|
+
missCount: this.missCount,
|
|
78
|
+
hitRate: total > 0 ? (this.hitCount / total * 100).toFixed(2) + '%' : '0%'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default RegexCache;
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VladX AST Nodes — Узлы абстрактного синтаксического дерева
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Базовые узлы
|
|
6
|
+
export class Node {
|
|
7
|
+
constructor(type) {
|
|
8
|
+
this.type = type;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class Program extends Node {
|
|
13
|
+
constructor() {
|
|
14
|
+
super('Program');
|
|
15
|
+
this.body = [];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Statements
|
|
20
|
+
export class ExpressionStatement extends Node {
|
|
21
|
+
constructor(expression) {
|
|
22
|
+
super('ExpressionStatement');
|
|
23
|
+
this.expression = expression;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class EmptyStatement extends Node {
|
|
28
|
+
constructor() {
|
|
29
|
+
super('EmptyStatement');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class LetStatement extends Node {
|
|
34
|
+
constructor(name, initializer) {
|
|
35
|
+
super('LetStatement');
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.initializer = initializer;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class ConstStatement extends Node {
|
|
42
|
+
constructor(name, initializer) {
|
|
43
|
+
super('ConstStatement');
|
|
44
|
+
this.name = name;
|
|
45
|
+
this.initializer = initializer;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class ReturnStatement extends Node {
|
|
50
|
+
constructor(argument) {
|
|
51
|
+
super('ReturnStatement');
|
|
52
|
+
this.argument = argument;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class BlockStatement extends Node {
|
|
57
|
+
constructor(body = []) {
|
|
58
|
+
super('BlockStatement');
|
|
59
|
+
this.body = body;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class IfStatement extends Node {
|
|
64
|
+
constructor(condition, thenBranch, elseBranch = null) {
|
|
65
|
+
super('IfStatement');
|
|
66
|
+
this.condition = condition;
|
|
67
|
+
this.thenBranch = thenBranch;
|
|
68
|
+
this.elseBranch = elseBranch;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class WhileStatement extends Node {
|
|
73
|
+
constructor(condition, body) {
|
|
74
|
+
super('WhileStatement');
|
|
75
|
+
this.condition = condition;
|
|
76
|
+
this.body = body;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class ForStatement extends Node {
|
|
81
|
+
constructor(initializer, condition, update, body) {
|
|
82
|
+
super('ForStatement');
|
|
83
|
+
this.initializer = initializer;
|
|
84
|
+
this.condition = condition;
|
|
85
|
+
this.update = update;
|
|
86
|
+
this.body = body;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export class BreakStatement extends Node {
|
|
91
|
+
constructor() {
|
|
92
|
+
super('BreakStatement');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class ContinueStatement extends Node {
|
|
97
|
+
constructor() {
|
|
98
|
+
super('ContinueStatement');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class FunctionDeclaration extends Node {
|
|
103
|
+
constructor(name, params, body, isAsync = false) {
|
|
104
|
+
super('FunctionDeclaration');
|
|
105
|
+
this.name = name;
|
|
106
|
+
this.params = params;
|
|
107
|
+
this.body = body;
|
|
108
|
+
this.isAsync = isAsync;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export class ClassDeclaration extends Node {
|
|
113
|
+
constructor(name, methods, superClass = null) {
|
|
114
|
+
super('ClassDeclaration');
|
|
115
|
+
this.name = name;
|
|
116
|
+
this.methods = methods;
|
|
117
|
+
this.superClass = superClass;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export class TryStatement extends Node {
|
|
122
|
+
constructor(block, handler = null, finalizer = null) {
|
|
123
|
+
super('TryStatement');
|
|
124
|
+
this.block = block;
|
|
125
|
+
this.handler = handler;
|
|
126
|
+
this.finalizer = finalizer;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export class ThrowStatement extends Node {
|
|
131
|
+
constructor(argument) {
|
|
132
|
+
super('ThrowStatement');
|
|
133
|
+
this.argument = argument;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Expressions
|
|
138
|
+
export class Literal extends Node {
|
|
139
|
+
constructor(value) {
|
|
140
|
+
super('Literal');
|
|
141
|
+
this.value = value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export class Identifier extends Node {
|
|
146
|
+
constructor(name) {
|
|
147
|
+
super('Identifier');
|
|
148
|
+
this.name = name;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export class ThisExpression extends Node {
|
|
153
|
+
constructor() {
|
|
154
|
+
super('ThisExpression');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export class SuperExpression extends Node {
|
|
159
|
+
constructor() {
|
|
160
|
+
super('SuperExpression');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export class NewExpression extends Node {
|
|
165
|
+
constructor(callee, args = []) {
|
|
166
|
+
super('NewExpression');
|
|
167
|
+
this.callee = callee;
|
|
168
|
+
this.args = args;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export class ClassMethod extends FunctionDeclaration {
|
|
173
|
+
constructor(name, params, body, isStatic = false, isGetter = false, isSetter = false, isAsync = false) {
|
|
174
|
+
super(name, params, body, isAsync);
|
|
175
|
+
this.isStatic = isStatic;
|
|
176
|
+
this.isGetter = isGetter;
|
|
177
|
+
this.isSetter = isSetter;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export class BinaryExpression extends Node {
|
|
182
|
+
constructor(operator, left, right) {
|
|
183
|
+
super('BinaryExpression');
|
|
184
|
+
this.operator = operator;
|
|
185
|
+
this.left = left;
|
|
186
|
+
this.right = right;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export class UnaryExpression extends Node {
|
|
191
|
+
constructor(operator, operand) {
|
|
192
|
+
super('UnaryExpression');
|
|
193
|
+
this.operator = operator;
|
|
194
|
+
this.operand = operand;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export class CallExpression extends Node {
|
|
199
|
+
constructor(callee, args = []) {
|
|
200
|
+
super('CallExpression');
|
|
201
|
+
this.callee = callee;
|
|
202
|
+
this.args = args;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export class MemberExpression extends Node {
|
|
207
|
+
constructor(object, property, computed = false) {
|
|
208
|
+
super('MemberExpression');
|
|
209
|
+
this.object = object;
|
|
210
|
+
this.property = property;
|
|
211
|
+
this.computed = computed;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export class MemberAssignment extends Node {
|
|
216
|
+
constructor(object, property, value) {
|
|
217
|
+
super('MemberAssignment');
|
|
218
|
+
this.object = object;
|
|
219
|
+
this.property = property;
|
|
220
|
+
this.value = value;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class Assignment extends Node {
|
|
225
|
+
constructor(name, value) {
|
|
226
|
+
super('Assignment');
|
|
227
|
+
this.name = name;
|
|
228
|
+
this.value = value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class ArrayExpression extends Node {
|
|
233
|
+
constructor(elements = []) {
|
|
234
|
+
super('ArrayExpression');
|
|
235
|
+
this.elements = elements;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export class ObjectExpression extends Node {
|
|
240
|
+
constructor(properties = []) {
|
|
241
|
+
super('ObjectExpression');
|
|
242
|
+
this.properties = properties;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export class PropertyDefinition extends Node {
|
|
247
|
+
constructor(key, value) {
|
|
248
|
+
super('PropertyDefinition');
|
|
249
|
+
this.key = key;
|
|
250
|
+
this.value = value;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export class PropertyKey extends Node {
|
|
255
|
+
constructor(value) {
|
|
256
|
+
super('PropertyKey');
|
|
257
|
+
this.value = value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class ArrowFunctionExpression extends Node {
|
|
262
|
+
constructor(params, body, isAsync = false) {
|
|
263
|
+
super('ArrowFunctionExpression');
|
|
264
|
+
this.params = params;
|
|
265
|
+
this.body = body;
|
|
266
|
+
this.isAsync = isAsync;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export class TernaryExpression extends Node {
|
|
271
|
+
constructor(condition, thenExpr, elseExpr) {
|
|
272
|
+
super('TernaryExpression');
|
|
273
|
+
this.condition = condition;
|
|
274
|
+
this.thenExpr = thenExpr;
|
|
275
|
+
this.elseExpr = elseExpr;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export class AssignmentExpression extends Node {
|
|
280
|
+
constructor(left, operator, right) {
|
|
281
|
+
super('AssignmentExpression');
|
|
282
|
+
this.left = left;
|
|
283
|
+
this.operator = operator;
|
|
284
|
+
this.right = right;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export class CompoundAssignmentExpression extends Node {
|
|
289
|
+
constructor(left, operator, right) {
|
|
290
|
+
super('CompoundAssignmentExpression');
|
|
291
|
+
this.left = left;
|
|
292
|
+
this.operator = operator;
|
|
293
|
+
this.right = right;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export class BitwiseExpression extends Node {
|
|
298
|
+
constructor(operator, left, right) {
|
|
299
|
+
super('BitwiseExpression');
|
|
300
|
+
this.operator = operator;
|
|
301
|
+
this.left = left;
|
|
302
|
+
this.right = right;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export class TemplateLiteral extends Node {
|
|
307
|
+
constructor(expressions, quasis) {
|
|
308
|
+
super('TemplateLiteral');
|
|
309
|
+
this.expressions = expressions;
|
|
310
|
+
this.quasis = quasis;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export class AwaitExpression extends Node {
|
|
315
|
+
constructor(argument) {
|
|
316
|
+
super('AwaitExpression');
|
|
317
|
+
this.argument = argument;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export class ArrayPattern extends Node {
|
|
322
|
+
constructor(elements) {
|
|
323
|
+
super('ArrayPattern');
|
|
324
|
+
this.elements = elements || [];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export class ObjectPattern extends Node {
|
|
329
|
+
constructor(properties) {
|
|
330
|
+
super('ObjectPattern');
|
|
331
|
+
this.properties = properties || [];
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export class Property extends Node {
|
|
336
|
+
constructor(key, value, computed = false) {
|
|
337
|
+
super('Property');
|
|
338
|
+
this.key = key;
|
|
339
|
+
this.value = value;
|
|
340
|
+
this.computed = computed;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export class VariableDeclarationWithPattern extends Node {
|
|
345
|
+
constructor(kind, pattern, initializer) {
|
|
346
|
+
super('VariableDeclarationWithPattern');
|
|
347
|
+
this.kind = kind; // 'let' or 'const'
|
|
348
|
+
this.pattern = pattern;
|
|
349
|
+
this.initializer = initializer;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export class SpreadElement extends Node {
|
|
354
|
+
constructor(argument) {
|
|
355
|
+
super('SpreadElement');
|
|
356
|
+
this.argument = argument;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export class AssignmentPattern extends Node {
|
|
361
|
+
constructor(left, right) {
|
|
362
|
+
super('AssignmentPattern');
|
|
363
|
+
this.left = left;
|
|
364
|
+
this.right = right;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export class RestElement extends Node {
|
|
369
|
+
constructor(argument) {
|
|
370
|
+
super('RestElement');
|
|
371
|
+
this.argument = argument;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export class ImportExpression extends Node {
|
|
376
|
+
constructor(path) {
|
|
377
|
+
super('ImportExpression');
|
|
378
|
+
this.path = path;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export class SequenceExpression extends Node {
|
|
383
|
+
constructor(expressions) {
|
|
384
|
+
super('SequenceExpression');
|
|
385
|
+
this.expressions = expressions;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Импорт модуля (как инструкция)
|
|
390
|
+
export class ImportStatement extends Node {
|
|
391
|
+
constructor(path, alias = null) {
|
|
392
|
+
super('ImportStatement');
|
|
393
|
+
this.path = path;
|
|
394
|
+
this.alias = alias; // Новое: имя переменной после "как"
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Экспорт имен
|
|
399
|
+
export class ExportStatement extends Node {
|
|
400
|
+
constructor(identifiers = []) {
|
|
401
|
+
super('ExportStatement');
|
|
402
|
+
this.identifiers = identifiers;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export class SwitchStatement extends Node {
|
|
407
|
+
constructor(discriminant, cases, defaultCase) {
|
|
408
|
+
super('SwitchStatement');
|
|
409
|
+
this.discriminant = discriminant; // The switch expression
|
|
410
|
+
this.cases = cases; // Array of case objects
|
|
411
|
+
this.defaultCase = defaultCase; // Default case or null
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Экспорт всех узлов
|
|
416
|
+
export const ASTNodes = {
|
|
417
|
+
Node,
|
|
418
|
+
Program,
|
|
419
|
+
ExpressionStatement,
|
|
420
|
+
EmptyStatement,
|
|
421
|
+
LetStatement,
|
|
422
|
+
ConstStatement,
|
|
423
|
+
ReturnStatement,
|
|
424
|
+
BlockStatement,
|
|
425
|
+
IfStatement,
|
|
426
|
+
WhileStatement,
|
|
427
|
+
ForStatement,
|
|
428
|
+
BreakStatement,
|
|
429
|
+
ContinueStatement,
|
|
430
|
+
FunctionDeclaration,
|
|
431
|
+
ClassMethod,
|
|
432
|
+
ClassDeclaration,
|
|
433
|
+
TryStatement,
|
|
434
|
+
ThrowStatement,
|
|
435
|
+
Literal,
|
|
436
|
+
Identifier,
|
|
437
|
+
ThisExpression,
|
|
438
|
+
SuperExpression,
|
|
439
|
+
NewExpression,
|
|
440
|
+
BinaryExpression,
|
|
441
|
+
UnaryExpression,
|
|
442
|
+
CallExpression,
|
|
443
|
+
MemberExpression,
|
|
444
|
+
MemberAssignment,
|
|
445
|
+
Assignment,
|
|
446
|
+
AssignmentExpression,
|
|
447
|
+
CompoundAssignmentExpression,
|
|
448
|
+
BitwiseExpression,
|
|
449
|
+
TemplateLiteral,
|
|
450
|
+
ArrayExpression,
|
|
451
|
+
ObjectExpression,
|
|
452
|
+
PropertyDefinition,
|
|
453
|
+
PropertyKey,
|
|
454
|
+
ArrowFunctionExpression,
|
|
455
|
+
TernaryExpression,
|
|
456
|
+
ImportStatement,
|
|
457
|
+
ImportExpression,
|
|
458
|
+
ExportStatement,
|
|
459
|
+
SwitchStatement,
|
|
460
|
+
AwaitExpression,
|
|
461
|
+
ArrayPattern,
|
|
462
|
+
ObjectPattern,
|
|
463
|
+
Property,
|
|
464
|
+
VariableDeclarationWithPattern,
|
|
465
|
+
SpreadElement,
|
|
466
|
+
AssignmentPattern,
|
|
467
|
+
RestElement,
|
|
468
|
+
SequenceExpression
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
export default ASTNodes;
|