@angular-wave/angular.ts 0.0.49 → 0.0.50

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.
@@ -8,11 +8,19 @@ import {
8
8
  import { forEach, isDefined } from "../../shared/utils";
9
9
  import { ASTType } from "./ast-type";
10
10
 
11
- export function ASTInterpreter($filter) {
12
- this.$filter = $filter;
13
- }
11
+ export class ASTInterpreter {
12
+ /**
13
+ * @param {function(any):any} $filter
14
+ */
15
+ constructor($filter) {
16
+ this.$filter = $filter;
17
+ }
14
18
 
15
- ASTInterpreter.prototype = {
19
+ /**
20
+ * Compiles the AST into a function.
21
+ * @param {import("./ast").ASTNode} ast - The AST to compile.
22
+ * @returns
23
+ */
16
24
  compile(ast) {
17
25
  const self = this;
18
26
  findConstantAndWatchExpressions(ast, self.$filter);
@@ -37,6 +45,7 @@ ASTInterpreter.prototype = {
37
45
  forEach(ast.body, (expression) => {
38
46
  expressions.push(self.recurse(expression.expression));
39
47
  });
48
+
40
49
  const fn =
41
50
  ast.body.length === 0
42
51
  ? () => {}
@@ -58,8 +67,15 @@ ASTInterpreter.prototype = {
58
67
  fn.inputs = inputs;
59
68
  }
60
69
  return fn;
61
- },
70
+ }
62
71
 
72
+ /**
73
+ * Recurses the AST nodes.
74
+ * @param {import("./ast").ASTNode} ast - The AST node.
75
+ * @param {Object} [context] - The context.
76
+ * @param {boolean|number} [create] - The create flag.
77
+ * @returns {function} The recursive function.
78
+ */
63
79
  recurse(ast, context, create) {
64
80
  let left;
65
81
  let right;
@@ -200,9 +216,15 @@ ASTInterpreter.prototype = {
200
216
  return context ? { value: assign } : assign;
201
217
  };
202
218
  }
203
- },
219
+ }
204
220
 
205
- "unary+": function (argument, context) {
221
+ /**
222
+ * Unary plus operation.
223
+ * @param {function} argument - The argument function.
224
+ * @param {Object} [context] - The context.
225
+ * @returns {function} The unary plus function.
226
+ */
227
+ "unary+"(argument, context) {
206
228
  return function (scope, locals, assign, inputs) {
207
229
  let arg = argument(scope, locals, assign, inputs);
208
230
  if (isDefined(arg)) {
@@ -212,9 +234,15 @@ ASTInterpreter.prototype = {
212
234
  }
213
235
  return context ? { value: arg } : arg;
214
236
  };
215
- },
237
+ }
216
238
 
217
- "unary-": function (argument, context) {
239
+ /**
240
+ * Unary minus operation.
241
+ * @param {function} argument - The argument function.
242
+ * @param {Object} [context] - The context.
243
+ * @returns {function} The unary minus function.
244
+ */
245
+ "unary-"(argument, context) {
218
246
  return function (scope, locals, assign, inputs) {
219
247
  let arg = argument(scope, locals, assign, inputs);
220
248
  if (isDefined(arg)) {
@@ -224,146 +252,289 @@ ASTInterpreter.prototype = {
224
252
  }
225
253
  return context ? { value: arg } : arg;
226
254
  };
227
- },
228
- "unary!": function (argument, context) {
255
+ }
256
+
257
+ /**
258
+ * Unary negation operation.
259
+ * @param {function} argument - The argument function.
260
+ * @param {Object} [context] - The context.
261
+ * @returns {function} The unary negation function.
262
+ */
263
+ "unary!"(argument, context) {
229
264
  return function (scope, locals, assign, inputs) {
230
265
  const arg = !argument(scope, locals, assign, inputs);
231
266
  return context ? { value: arg } : arg;
232
267
  };
233
- },
234
- "binary+": function (left, right, context) {
268
+ }
269
+
270
+ /**
271
+ * Binary plus operation.
272
+ * @param {function} left - The left operand function.
273
+ * @param {function} right - The right operand function.
274
+ * @param {Object} [context] - The context.
275
+ * @returns {function} The binary plus function.
276
+ */
277
+ "binary+"(left, right, context) {
235
278
  return function (scope, locals, assign, inputs) {
236
279
  const lhs = left(scope, locals, assign, inputs);
237
280
  const rhs = right(scope, locals, assign, inputs);
238
281
  const arg = plusFn(lhs, rhs);
239
282
  return context ? { value: arg } : arg;
240
283
  };
241
- },
242
- "binary-": function (left, right, context) {
284
+ }
285
+
286
+ /**
287
+ * Binary minus operation.
288
+ * @param {function} left - The left operand function.
289
+ * @param {function} right - The right operand function.
290
+ * @param {Object} [context] - The context.
291
+ * @returns {function} The binary minus function.
292
+ */
293
+ "binary-"(left, right, context) {
243
294
  return function (scope, locals, assign, inputs) {
244
295
  const lhs = left(scope, locals, assign, inputs);
245
296
  const rhs = right(scope, locals, assign, inputs);
246
297
  const arg = (isDefined(lhs) ? lhs : 0) - (isDefined(rhs) ? rhs : 0);
247
298
  return context ? { value: arg } : arg;
248
299
  };
249
- },
250
- "binary*": function (left, right, context) {
300
+ }
301
+
302
+ /**
303
+ * Binary multiplication operation.
304
+ * @param {function} left - The left operand function.
305
+ * @param {function} right - The right operand function.
306
+ * @param {Object} [context] - The context.
307
+ * @returns {function} The binary multiplication function.
308
+ */
309
+ "binary*"(left, right, context) {
251
310
  return function (scope, locals, assign, inputs) {
252
311
  const arg =
253
312
  left(scope, locals, assign, inputs) *
254
313
  right(scope, locals, assign, inputs);
255
314
  return context ? { value: arg } : arg;
256
315
  };
257
- },
258
- "binary/": function (left, right, context) {
316
+ }
317
+
318
+ "binary/"(left, right, context) {
259
319
  return function (scope, locals, assign, inputs) {
260
320
  const arg =
261
321
  left(scope, locals, assign, inputs) /
262
322
  right(scope, locals, assign, inputs);
263
323
  return context ? { value: arg } : arg;
264
324
  };
265
- },
266
- "binary%": function (left, right, context) {
325
+ }
326
+
327
+ /**
328
+ * Binary division operation.
329
+ * @param {function} left - The left operand function.
330
+ * @param {function} right - The right operand function.
331
+ * @param {Object} [context] - The context.
332
+ * @returns {function} The binary division function.
333
+ */
334
+ "binary%"(left, right, context) {
267
335
  return function (scope, locals, assign, inputs) {
268
336
  const arg =
269
337
  left(scope, locals, assign, inputs) %
270
338
  right(scope, locals, assign, inputs);
271
339
  return context ? { value: arg } : arg;
272
340
  };
273
- },
274
- "binary===": function (left, right, context) {
341
+ }
342
+
343
+ /**
344
+ * Binary strict equality operation.
345
+ * @param {function} left - The left operand function.
346
+ * @param {function} right - The right operand function.
347
+ * @param {Object} [context] - The context.
348
+ * @returns {function} The binary strict equality function.
349
+ */
350
+ "binary==="(left, right, context) {
275
351
  return function (scope, locals, assign, inputs) {
276
352
  const arg =
277
353
  left(scope, locals, assign, inputs) ===
278
354
  right(scope, locals, assign, inputs);
279
355
  return context ? { value: arg } : arg;
280
356
  };
281
- },
282
- "binary!==": function (left, right, context) {
357
+ }
358
+
359
+ /**
360
+ * Binary strict inequality operation.
361
+ * @param {function} left - The left operand function.
362
+ * @param {function} right - The right operand function.
363
+ * @param {Object} [context] - The context.
364
+ * @returns {function} The binary strict inequality function.
365
+ */
366
+ "binary!=="(left, right, context) {
283
367
  return function (scope, locals, assign, inputs) {
284
368
  const arg =
285
369
  left(scope, locals, assign, inputs) !==
286
370
  right(scope, locals, assign, inputs);
287
371
  return context ? { value: arg } : arg;
288
372
  };
289
- },
290
- "binary==": function (left, right, context) {
373
+ }
374
+
375
+ /**
376
+ * Binary equality operation.
377
+ * @param {function} left - The left operand function.
378
+ * @param {function} right - The right operand function.
379
+ * @param {Object} [context] - The context.
380
+ * @returns {function} The binary equality function.
381
+ */
382
+ "binary=="(left, right, context) {
291
383
  return function (scope, locals, assign, inputs) {
292
384
  const arg =
293
385
  left(scope, locals, assign, inputs) ==
294
386
  right(scope, locals, assign, inputs);
295
387
  return context ? { value: arg } : arg;
296
388
  };
297
- },
298
- "binary!=": function (left, right, context) {
389
+ }
390
+
391
+ /**
392
+ * Binary inequality operation.
393
+ * @param {function} left - The left operand function.
394
+ * @param {function} right - The right operand function.
395
+ * @param {Object} [context] - The context.
396
+ * @returns {function} The binary inequality function.
397
+ */
398
+ "binary!="(left, right, context) {
299
399
  return function (scope, locals, assign, inputs) {
300
400
  const arg =
301
401
  left(scope, locals, assign, inputs) !=
302
402
  right(scope, locals, assign, inputs);
303
403
  return context ? { value: arg } : arg;
304
404
  };
305
- },
306
- "binary<": function (left, right, context) {
405
+ }
406
+
407
+ /**
408
+ * Binary less-than operation.
409
+ * @param {function} left - The left operand function.
410
+ * @param {function} right - The right operand function.
411
+ * @param {Object} [context] - The context.
412
+ * @returns {function} The binary less-than function.
413
+ */
414
+ "binary<"(left, right, context) {
307
415
  return function (scope, locals, assign, inputs) {
308
416
  const arg =
309
417
  left(scope, locals, assign, inputs) <
310
418
  right(scope, locals, assign, inputs);
311
419
  return context ? { value: arg } : arg;
312
420
  };
313
- },
314
- "binary>": function (left, right, context) {
421
+ }
422
+
423
+ /**
424
+ * Binary greater-than operation.
425
+ * @param {function} left - The left operand function.
426
+ * @param {function} right - The right operand function.
427
+ * @param {Object} [context] - The context.
428
+ * @returns {function} The binary greater-than function.
429
+ */
430
+ "binary>"(left, right, context) {
315
431
  return function (scope, locals, assign, inputs) {
316
432
  const arg =
317
433
  left(scope, locals, assign, inputs) >
318
434
  right(scope, locals, assign, inputs);
319
435
  return context ? { value: arg } : arg;
320
436
  };
321
- },
322
- "binary<=": function (left, right, context) {
437
+ }
438
+
439
+ /**
440
+ * Binary less-than-or-equal-to operation.
441
+ * @param {function} left - The left operand function.
442
+ * @param {function} right - The right operand function.
443
+ * @param {Object} [context] - The context.
444
+ * @returns {function} The binary less-than-or-equal-to function.
445
+ */
446
+ "binary<="(left, right, context) {
323
447
  return function (scope, locals, assign, inputs) {
324
448
  const arg =
325
449
  left(scope, locals, assign, inputs) <=
326
450
  right(scope, locals, assign, inputs);
327
451
  return context ? { value: arg } : arg;
328
452
  };
329
- },
330
- "binary>=": function (left, right, context) {
453
+ }
454
+
455
+ /**
456
+ * Binary greater-than-or-equal-to operation.
457
+ * @param {function} left - The left operand function.
458
+ * @param {function} right - The right operand function.
459
+ * @param {Object} [context] - The context.
460
+ * @returns {function} The binary greater-than-or-equal-to function.
461
+ */
462
+ "binary>="(left, right, context) {
331
463
  return function (scope, locals, assign, inputs) {
332
464
  const arg =
333
465
  left(scope, locals, assign, inputs) >=
334
466
  right(scope, locals, assign, inputs);
335
467
  return context ? { value: arg } : arg;
336
468
  };
337
- },
338
- "binary&&": function (left, right, context) {
469
+ }
470
+ /**
471
+ * Binary logical AND operation.
472
+ * @param {function} left - The left operand function.
473
+ * @param {function} right - The right operand function.
474
+ * @param {Object} [context] - The context.
475
+ * @returns {function} The binary logical AND function.
476
+ */
477
+ "binary&&"(left, right, context) {
339
478
  return function (scope, locals, assign, inputs) {
340
479
  const arg =
341
480
  left(scope, locals, assign, inputs) &&
342
481
  right(scope, locals, assign, inputs);
343
482
  return context ? { value: arg } : arg;
344
483
  };
345
- },
346
- "binary||": function (left, right, context) {
484
+ }
485
+
486
+ /**
487
+ * Binary logical OR operation.
488
+ * @param {function} left - The left operand function.
489
+ * @param {function} right - The right operand function.
490
+ * @param {Object} [context] - The context.
491
+ * @returns {function} The binary logical OR function.
492
+ */
493
+ "binary||"(left, right, context) {
347
494
  return function (scope, locals, assign, inputs) {
348
495
  const arg =
349
496
  left(scope, locals, assign, inputs) ||
350
497
  right(scope, locals, assign, inputs);
351
498
  return context ? { value: arg } : arg;
352
499
  };
353
- },
354
- "ternary?:": function (test, alternate, consequent, context) {
500
+ }
501
+
502
+ /**
503
+ * Ternary conditional operation.
504
+ * @param {function} test - The test function.
505
+ * @param {function} alternate - The alternate function.
506
+ * @param {function} consequent - The consequent function.
507
+ * @param {Object} [context] - The context.
508
+ * @returns {function} The ternary conditional function.
509
+ */
510
+ "ternary?:"(test, alternate, consequent, context) {
355
511
  return function (scope, locals, assign, inputs) {
356
512
  const arg = test(scope, locals, assign, inputs)
357
513
  ? alternate(scope, locals, assign, inputs)
358
514
  : consequent(scope, locals, assign, inputs);
359
515
  return context ? { value: arg } : arg;
360
516
  };
361
- },
517
+ }
518
+
519
+ /**
520
+ * Returns the value of a literal.
521
+ * @param {*} value - The literal value.
522
+ * @param {Object} [context] - The context.
523
+ * @returns {function} The function returning the literal value.
524
+ */
362
525
  value(value, context) {
363
526
  return function () {
364
527
  return context ? { context: undefined, name: undefined, value } : value;
365
528
  };
366
- },
529
+ }
530
+
531
+ /**
532
+ * Returns the value of an identifier.
533
+ * @param {string} name - The identifier name.
534
+ * @param {Object} [context] - The context.
535
+ * @param {boolean} [create] - Whether to create the identifier if it does not exist.
536
+ * @returns {function} The function returning the identifier value.
537
+ */
367
538
  identifier(name, context, create) {
368
539
  return function (scope, locals) {
369
540
  const base = locals && name in locals ? locals : scope;
@@ -376,7 +547,16 @@ ASTInterpreter.prototype = {
376
547
  }
377
548
  return value;
378
549
  };
379
- },
550
+ }
551
+
552
+ /**
553
+ * Returns the value of a computed member expression.
554
+ * @param {function} left - The left operand function.
555
+ * @param {function} right - The right operand function.
556
+ * @param {Object} [context] - The context.
557
+ * @param {boolean} [create] - Whether to create the member if it does not exist.
558
+ * @returns {function} The function returning the computed member value.
559
+ */
380
560
  computedMember(left, right, context, create) {
381
561
  return function (scope, locals, assign, inputs) {
382
562
  const lhs = left(scope, locals, assign, inputs);
@@ -397,7 +577,16 @@ ASTInterpreter.prototype = {
397
577
  }
398
578
  return value;
399
579
  };
400
- },
580
+ }
581
+
582
+ /**
583
+ * Returns the value of a non-computed member expression.
584
+ * @param {function} left - The left operand function.
585
+ * @param {string} right - The right operand function.
586
+ * @param {Object} [context] - The context.
587
+ * @param {boolean} [create] - Whether to create the member if it does not exist.
588
+ * @returns {function} The function returning the non-computed member value.
589
+ */
401
590
  nonComputedMember(left, right, context, create) {
402
591
  return function (scope, locals, assign, inputs) {
403
592
  const lhs = left(scope, locals, assign, inputs);
@@ -412,11 +601,18 @@ ASTInterpreter.prototype = {
412
601
  }
413
602
  return value;
414
603
  };
415
- },
604
+ }
605
+
606
+ /**
607
+ * Returns the value of an input expression.
608
+ * @param {function} input - The input function.
609
+ * @param {number} watchId - The watch identifier.
610
+ * @returns {function} The function returning the input value.
611
+ */
416
612
  inputs(input, watchId) {
417
613
  return function (scope, value, locals, inputs) {
418
614
  if (inputs) return inputs[watchId];
419
615
  return input(scope, value, locals);
420
616
  };
421
- },
422
- };
617
+ }
618
+ }
@@ -1,5 +1,4 @@
1
1
  import { $parseMinErr } from "./parse";
2
-
3
2
  import { isDefined } from "../../shared/utils";
4
3
 
5
4
  const ESCAPE = {
@@ -18,19 +17,19 @@ const OPERATORS = new Set(
18
17
 
19
18
  /**
20
19
  * @typedef {Object} LexerOptions
21
- * @property {(ch: string, codePoint: number) => boolean} [isIdentifierStart] Custom function to determine if a character is a valid identifier start.
22
- * @property {(ch: string, codePoint: number) => boolean} [isIdentifierContinue] Custom function to determine if a character is a valid identifier continuation.
20
+ * @property {(ch: string, codePoint: number) => boolean} [isIdentifierStart] - Custom function to determine if a character is a valid identifier start.
21
+ * @property {(ch: string, codePoint: number) => boolean} [isIdentifierContinue] - Custom function to determine if a character is a valid identifier continuation.
23
22
  */
24
23
 
25
24
  /**
26
25
  * Represents a token produced by the lexer.
27
26
  * @typedef {Object} Token
28
- * @property {number} index Index of the token.
29
- * @property {string} text Text of the token.
30
- * @property {boolean} [identifier] Indicates if token is an identifier.
31
- * @property {boolean} [constant] Indicates if token is a constant.
32
- * @property {string|number} [value] Value of the token if it's a constant.
33
- * @property {boolean} [operator] Indicates if token is an operator.
27
+ * @property {number} index - Index of the token.
28
+ * @property {string} text - Text of the token.
29
+ * @property {boolean} [identifier] - Indicates if token is an identifier.
30
+ * @property {boolean} [constant] - Indicates if token is a constant.
31
+ * @property {string|number} [value] - Value of the token if it's a constant.
32
+ * @property {boolean} [operator] - Indicates if token is an operator.
34
33
  */
35
34
 
36
35
  /**
@@ -40,7 +39,7 @@ const OPERATORS = new Set(
40
39
  export class Lexer {
41
40
  /**
42
41
  * Creates an instance of Lexer.
43
- * @param {LexerOptions} options Lexer options.
42
+ * @param {LexerOptions} options - Lexer options.
44
43
  */
45
44
  constructor(options) {
46
45
  /** @type {LexerOptions} */