@angular-wave/angular.ts 0.0.47 → 0.0.49
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/Makefile +3 -0
- package/README.md +1 -1
- package/css/angular.css +0 -6
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/jsdoc.json +24 -0
- package/package.json +6 -2
- package/src/angular.spec.js +1 -2
- package/src/animations/animate-queue.js +0 -1
- package/src/animations/animation.js +1 -1
- package/src/animations/raf-scheduler.js +0 -1
- package/src/animations/shared.js +1 -1
- package/src/core/animate/animate.js +0 -1
- package/src/core/compile/compile.md +1 -1
- package/src/core/compile/compile.spec.js +49 -47
- package/src/core/location/location.spec.js +1 -1
- package/src/core/on.spec.js +7 -12
- package/src/core/parser/ast-type.js +22 -0
- package/src/core/parser/ast.js +426 -0
- package/src/core/parser/compiler.js +561 -0
- package/src/core/parser/interpreter.js +422 -0
- package/src/core/parser/lexer.js +345 -0
- package/src/core/parser/parse.js +23 -1984
- package/src/core/parser/parse.md +57 -0
- package/src/core/parser/parse.spec.js +2 -2
- package/src/core/parser/parser.js +45 -0
- package/src/core/parser/shared.js +228 -0
- package/src/core/prop.spec.js +4 -4
- package/src/core/q/q.spec.js +0 -1
- package/src/core/sce/sce.js +3 -6
- package/src/core/scope/scope.js +33 -21
- package/src/core/task-tracker-factory.js +0 -1
- package/src/directive/class/class.js +0 -2
- package/src/directive/form/form.js +0 -3
- package/src/directive/form/form.spec.js +18 -18
- package/src/directive/include/include.js +1 -1
- package/src/directive/include/include.spec.js +18 -19
- package/src/directive/input/input.js +1 -2
- package/src/directive/model/model.js +1 -3
- package/src/directive/model/model.spec.js +0 -1
- package/src/directive/repeat/repeat.spec.js +0 -2
- package/src/directive/switch/switch.spec.js +4 -4
- package/src/exts/aria/aria.js +0 -1
- package/src/filters/filter.spec.js +0 -1
- package/src/injector.js +1 -1
- package/src/injector.spec.js +0 -5
- package/src/loader.js +0 -5
- package/src/services/cookie-reader.js +0 -1
- package/src/services/http/http.spec.js +0 -2
- package/src/shared/constants.js +3 -2
- package/src/shared/utils.js +18 -7
- package/src/types.js +10 -0
- package/types/core/parser/ast-type.d.ts +20 -0
- package/types/core/parser/ast.d.ts +86 -0
- package/types/core/parser/compiler.d.ts +49 -0
- package/types/core/parser/interpreter.d.ts +57 -0
- package/types/core/parser/lexer.d.ts +153 -0
- package/types/core/parser/parse.d.ts +68 -0
- package/types/core/parser/parser.d.ts +28 -0
- package/types/core/parser/shared.d.ts +29 -0
- package/types/core/scope/scope.d.ts +19 -12
- package/types/shared/utils.d.ts +18 -5
- package/types/types.d.ts +1 -0
- package/types-back/index.d.ts +0 -12
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { $parseMinErr } from "./parse";
|
|
2
|
+
import { isAssignable } from "./shared";
|
|
3
|
+
import { ASTType } from "./ast-type";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('./lexer').Lexer} lexer
|
|
7
|
+
* @param {*} options
|
|
8
|
+
*/
|
|
9
|
+
export function AST(lexer, options) {
|
|
10
|
+
this.lexer = lexer;
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
AST.prototype = {
|
|
15
|
+
ast(text) {
|
|
16
|
+
this.text = text;
|
|
17
|
+
this.tokens = this.lexer.lex(text);
|
|
18
|
+
|
|
19
|
+
const value = this.program();
|
|
20
|
+
|
|
21
|
+
if (this.tokens.length !== 0) {
|
|
22
|
+
this.throwError("is an unexpected token", this.tokens[0]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return value;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
program() {
|
|
29
|
+
const body = [];
|
|
30
|
+
let hasMore = true;
|
|
31
|
+
while (hasMore) {
|
|
32
|
+
if (this.tokens.length > 0 && !this.peek("}", ")", ";", "]"))
|
|
33
|
+
body.push(this.expressionStatement());
|
|
34
|
+
if (!this.expect(";")) {
|
|
35
|
+
hasMore = false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { type: ASTType.Program, body };
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
expressionStatement() {
|
|
42
|
+
return {
|
|
43
|
+
type: ASTType.ExpressionStatement,
|
|
44
|
+
expression: this.filterChain(),
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
filterChain() {
|
|
49
|
+
let left = this.expression();
|
|
50
|
+
while (this.expect("|")) {
|
|
51
|
+
left = this.filter(left);
|
|
52
|
+
}
|
|
53
|
+
return left;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
expression() {
|
|
57
|
+
return this.assignment();
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
assignment() {
|
|
61
|
+
let result = this.ternary();
|
|
62
|
+
if (this.expect("=")) {
|
|
63
|
+
if (!isAssignable(result)) {
|
|
64
|
+
throw $parseMinErr("lval", "Trying to assign a value to a non l-value");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
result = {
|
|
68
|
+
type: ASTType.AssignmentExpression,
|
|
69
|
+
left: result,
|
|
70
|
+
right: this.assignment(),
|
|
71
|
+
operator: "=",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
ternary() {
|
|
78
|
+
const test = this.logicalOR();
|
|
79
|
+
let alternate;
|
|
80
|
+
let consequent;
|
|
81
|
+
if (this.expect("?")) {
|
|
82
|
+
alternate = this.expression();
|
|
83
|
+
if (this.consume(":")) {
|
|
84
|
+
consequent = this.expression();
|
|
85
|
+
return {
|
|
86
|
+
type: ASTType.ConditionalExpression,
|
|
87
|
+
test,
|
|
88
|
+
alternate,
|
|
89
|
+
consequent,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return test;
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
logicalOR() {
|
|
97
|
+
let left = this.logicalAND();
|
|
98
|
+
while (this.expect("||")) {
|
|
99
|
+
left = {
|
|
100
|
+
type: ASTType.LogicalExpression,
|
|
101
|
+
operator: "||",
|
|
102
|
+
left,
|
|
103
|
+
right: this.logicalAND(),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return left;
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
logicalAND() {
|
|
110
|
+
let left = this.equality();
|
|
111
|
+
while (this.expect("&&")) {
|
|
112
|
+
left = {
|
|
113
|
+
type: ASTType.LogicalExpression,
|
|
114
|
+
operator: "&&",
|
|
115
|
+
left,
|
|
116
|
+
right: this.equality(),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return left;
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
equality() {
|
|
123
|
+
let left = this.relational();
|
|
124
|
+
let token;
|
|
125
|
+
while ((token = this.expect("==", "!=", "===", "!=="))) {
|
|
126
|
+
left = {
|
|
127
|
+
type: ASTType.BinaryExpression,
|
|
128
|
+
operator: token.text,
|
|
129
|
+
left,
|
|
130
|
+
right: this.relational(),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return left;
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
relational() {
|
|
137
|
+
let left = this.additive();
|
|
138
|
+
let token;
|
|
139
|
+
while ((token = this.expect("<", ">", "<=", ">="))) {
|
|
140
|
+
left = {
|
|
141
|
+
type: ASTType.BinaryExpression,
|
|
142
|
+
operator: token.text,
|
|
143
|
+
left,
|
|
144
|
+
right: this.additive(),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return left;
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
additive() {
|
|
151
|
+
let left = this.multiplicative();
|
|
152
|
+
let token;
|
|
153
|
+
while ((token = this.expect("+", "-"))) {
|
|
154
|
+
left = {
|
|
155
|
+
type: ASTType.BinaryExpression,
|
|
156
|
+
operator: token.text,
|
|
157
|
+
left,
|
|
158
|
+
right: this.multiplicative(),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return left;
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
multiplicative() {
|
|
165
|
+
let left = this.unary();
|
|
166
|
+
let token;
|
|
167
|
+
while ((token = this.expect("*", "/", "%"))) {
|
|
168
|
+
left = {
|
|
169
|
+
type: ASTType.BinaryExpression,
|
|
170
|
+
operator: token.text,
|
|
171
|
+
left,
|
|
172
|
+
right: this.unary(),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return left;
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
unary() {
|
|
179
|
+
let token;
|
|
180
|
+
if ((token = this.expect("+", "-", "!"))) {
|
|
181
|
+
return {
|
|
182
|
+
type: ASTType.UnaryExpression,
|
|
183
|
+
operator: token.text,
|
|
184
|
+
prefix: true,
|
|
185
|
+
argument: this.unary(),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return this.primary();
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
primary() {
|
|
192
|
+
let primary;
|
|
193
|
+
if (this.expect("(")) {
|
|
194
|
+
primary = this.filterChain();
|
|
195
|
+
this.consume(")");
|
|
196
|
+
} else if (this.expect("[")) {
|
|
197
|
+
primary = this.arrayDeclaration();
|
|
198
|
+
} else if (this.expect("{")) {
|
|
199
|
+
primary = this.object();
|
|
200
|
+
} else if (
|
|
201
|
+
Object.prototype.hasOwnProperty.call(
|
|
202
|
+
this.selfReferential,
|
|
203
|
+
this.peek().text,
|
|
204
|
+
)
|
|
205
|
+
) {
|
|
206
|
+
primary = structuredClone(this.selfReferential[this.consume().text]);
|
|
207
|
+
} else if (
|
|
208
|
+
Object.prototype.hasOwnProperty.call(
|
|
209
|
+
this.options.literals,
|
|
210
|
+
this.peek().text,
|
|
211
|
+
)
|
|
212
|
+
) {
|
|
213
|
+
primary = {
|
|
214
|
+
type: ASTType.Literal,
|
|
215
|
+
value: this.options.literals[this.consume().text],
|
|
216
|
+
};
|
|
217
|
+
} else if (this.peek().identifier) {
|
|
218
|
+
primary = this.identifier();
|
|
219
|
+
} else if (this.peek().constant) {
|
|
220
|
+
primary = this.constant();
|
|
221
|
+
} else {
|
|
222
|
+
this.throwError("not a primary expression", this.peek());
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let next;
|
|
226
|
+
while ((next = this.expect("(", "[", "."))) {
|
|
227
|
+
if (next.text === "(") {
|
|
228
|
+
primary = {
|
|
229
|
+
type: ASTType.CallExpression,
|
|
230
|
+
callee: primary,
|
|
231
|
+
arguments: this.parseArguments(),
|
|
232
|
+
};
|
|
233
|
+
this.consume(")");
|
|
234
|
+
} else if (next.text === "[") {
|
|
235
|
+
primary = {
|
|
236
|
+
type: ASTType.MemberExpression,
|
|
237
|
+
object: primary,
|
|
238
|
+
property: this.expression(),
|
|
239
|
+
computed: true,
|
|
240
|
+
};
|
|
241
|
+
this.consume("]");
|
|
242
|
+
} else if (next.text === ".") {
|
|
243
|
+
primary = {
|
|
244
|
+
type: ASTType.MemberExpression,
|
|
245
|
+
object: primary,
|
|
246
|
+
property: this.identifier(),
|
|
247
|
+
computed: false,
|
|
248
|
+
};
|
|
249
|
+
} else {
|
|
250
|
+
this.throwError("IMPOSSIBLE");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return primary;
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
filter(baseExpression) {
|
|
257
|
+
const args = [baseExpression];
|
|
258
|
+
const result = {
|
|
259
|
+
type: ASTType.CallExpression,
|
|
260
|
+
callee: this.identifier(),
|
|
261
|
+
arguments: args,
|
|
262
|
+
filter: true,
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
while (this.expect(":")) {
|
|
266
|
+
args.push(this.expression());
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return result;
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
parseArguments() {
|
|
273
|
+
const args = [];
|
|
274
|
+
if (this.peekToken().text !== ")") {
|
|
275
|
+
do {
|
|
276
|
+
args.push(this.filterChain());
|
|
277
|
+
} while (this.expect(","));
|
|
278
|
+
}
|
|
279
|
+
return args;
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
identifier() {
|
|
283
|
+
const token = this.consume();
|
|
284
|
+
if (!token.identifier) {
|
|
285
|
+
this.throwError("is not a valid identifier", token);
|
|
286
|
+
}
|
|
287
|
+
return { type: ASTType.Identifier, name: token.text };
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
constant() {
|
|
291
|
+
// TODO check that it is a constant
|
|
292
|
+
return { type: ASTType.Literal, value: this.consume().value };
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
arrayDeclaration() {
|
|
296
|
+
const elements = [];
|
|
297
|
+
if (this.peekToken().text !== "]") {
|
|
298
|
+
do {
|
|
299
|
+
if (this.peek("]")) {
|
|
300
|
+
// Support trailing commas per ES5.1.
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
elements.push(this.expression());
|
|
304
|
+
} while (this.expect(","));
|
|
305
|
+
}
|
|
306
|
+
this.consume("]");
|
|
307
|
+
|
|
308
|
+
return { type: ASTType.ArrayExpression, elements };
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
object() {
|
|
312
|
+
const properties = [];
|
|
313
|
+
let property;
|
|
314
|
+
if (this.peekToken().text !== "}") {
|
|
315
|
+
do {
|
|
316
|
+
if (this.peek("}")) {
|
|
317
|
+
// Support trailing commas per ES5.1.
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
property = { type: ASTType.Property, kind: "init" };
|
|
321
|
+
if (this.peek().constant) {
|
|
322
|
+
property.key = this.constant();
|
|
323
|
+
property.computed = false;
|
|
324
|
+
this.consume(":");
|
|
325
|
+
property.value = this.expression();
|
|
326
|
+
} else if (this.peek().identifier) {
|
|
327
|
+
property.key = this.identifier();
|
|
328
|
+
property.computed = false;
|
|
329
|
+
if (this.peek(":")) {
|
|
330
|
+
this.consume(":");
|
|
331
|
+
property.value = this.expression();
|
|
332
|
+
} else {
|
|
333
|
+
property.value = property.key;
|
|
334
|
+
}
|
|
335
|
+
} else if (this.peek("[")) {
|
|
336
|
+
this.consume("[");
|
|
337
|
+
property.key = this.expression();
|
|
338
|
+
this.consume("]");
|
|
339
|
+
property.computed = true;
|
|
340
|
+
this.consume(":");
|
|
341
|
+
property.value = this.expression();
|
|
342
|
+
} else {
|
|
343
|
+
this.throwError("invalid key", this.peek());
|
|
344
|
+
}
|
|
345
|
+
properties.push(property);
|
|
346
|
+
} while (this.expect(","));
|
|
347
|
+
}
|
|
348
|
+
this.consume("}");
|
|
349
|
+
|
|
350
|
+
return { type: ASTType.ObjectExpression, properties };
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
throwError(msg, token) {
|
|
354
|
+
throw $parseMinErr(
|
|
355
|
+
"syntax",
|
|
356
|
+
"Syntax Error: Token '{0}' {1} at column {2} of the expression [{3}] starting at [{4}].",
|
|
357
|
+
token.text,
|
|
358
|
+
msg,
|
|
359
|
+
token.index + 1,
|
|
360
|
+
this.text,
|
|
361
|
+
this.text.substring(token.index),
|
|
362
|
+
);
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
consume(e1) {
|
|
366
|
+
if (this.tokens.length === 0) {
|
|
367
|
+
throw $parseMinErr(
|
|
368
|
+
"ueoe",
|
|
369
|
+
"Unexpected end of expression: {0}",
|
|
370
|
+
this.text,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const token = this.expect(e1);
|
|
375
|
+
if (!token) {
|
|
376
|
+
this.throwError(`is unexpected, expecting [${e1}]`, this.peek());
|
|
377
|
+
}
|
|
378
|
+
return token;
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
peekToken() {
|
|
382
|
+
if (this.tokens.length === 0) {
|
|
383
|
+
throw $parseMinErr(
|
|
384
|
+
"ueoe",
|
|
385
|
+
"Unexpected end of expression: {0}",
|
|
386
|
+
this.text,
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
return this.tokens[0];
|
|
390
|
+
},
|
|
391
|
+
|
|
392
|
+
peek(e1, e2, e3, e4) {
|
|
393
|
+
return this.peekAhead(0, e1, e2, e3, e4);
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
peekAhead(i, e1, e2, e3, e4) {
|
|
397
|
+
if (this.tokens.length > i) {
|
|
398
|
+
const token = this.tokens[i];
|
|
399
|
+
const t = token.text;
|
|
400
|
+
if (
|
|
401
|
+
t === e1 ||
|
|
402
|
+
t === e2 ||
|
|
403
|
+
t === e3 ||
|
|
404
|
+
t === e4 ||
|
|
405
|
+
(!e1 && !e2 && !e3 && !e4)
|
|
406
|
+
) {
|
|
407
|
+
return token;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return false;
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
expect(e1, e2, e3, e4) {
|
|
414
|
+
const token = this.peek(e1, e2, e3, e4);
|
|
415
|
+
if (token) {
|
|
416
|
+
this.tokens.shift();
|
|
417
|
+
return token;
|
|
418
|
+
}
|
|
419
|
+
return false;
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
selfReferential: {
|
|
423
|
+
this: { type: ASTType.ThisExpression },
|
|
424
|
+
$locals: { type: ASTType.LocalsExpression },
|
|
425
|
+
},
|
|
426
|
+
};
|