@angular-wave/angular.ts 0.0.50 → 0.0.51

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "license": "MIT",
4
- "version": "0.0.50",
4
+ "version": "0.0.51",
5
5
  "type": "module",
6
6
  "main": "dist/angular-ts.esm.js",
7
7
  "browser": "dist/angular-ts.umd.js",
@@ -1,5 +1,6 @@
1
1
  import { forEach, isString, minErr, extend } from "../shared/utils";
2
2
  import { JQLite } from "../shared/jqlite/jqlite";
3
+ import { ASTType } from "../core/parser/ast-type";
3
4
 
4
5
  export const ADD_CLASS_SUFFIX = "-add";
5
6
  export const REMOVE_CLASS_SUFFIX = "-remove";
@@ -51,7 +52,7 @@ if (
51
52
  }
52
53
 
53
54
  export const DURATION_KEY = "Duration";
54
- export const PROPERTY_KEY = "Property";
55
+ export const PROPERTY_KEY = ASTType.Property;
55
56
  export const DELAY_KEY = "Delay";
56
57
  export const TIMING_KEY = "TimingFunction";
57
58
  export const ANIMATION_ITERATION_COUNT_KEY = "IterationCount";
@@ -1,22 +1,23 @@
1
1
  /**
2
- * @typedef {("Program"|"ExpressionStatement"|"AssignmentExpression"|"ConditionalExpression"|"LogicalExpression"|"BinaryExpression"|"UnaryExpression"|"CallExpression"|"MemberExpression"|"Identifier"|"Literal"|"ArrayExpression"|"Property"|"ObjectExpression"|"ThisExpression"|"LocalsExpression"|"NGValueParameter")} ASTType
2
+ * @readonly
3
+ * @enum {number}
3
4
  */
4
- export const ASTType = {
5
- Program: "Program",
6
- ExpressionStatement: "ExpressionStatement",
7
- AssignmentExpression: "AssignmentExpression",
8
- ConditionalExpression: "ConditionalExpression",
9
- LogicalExpression: "LogicalExpression",
10
- BinaryExpression: "BinaryExpression",
11
- UnaryExpression: "UnaryExpression",
12
- CallExpression: "CallExpression",
13
- MemberExpression: "MemberExpression",
14
- Identifier: "Identifier",
15
- Literal: "Literal",
16
- ArrayExpression: "ArrayExpression",
17
- Property: "Property",
18
- ObjectExpression: "ObjectExpression",
19
- ThisExpression: "ThisExpression",
20
- LocalsExpression: "LocalsExpression",
21
- NGValueParameter: "NGValueParameter",
22
- };
5
+ export const ASTType = Object.freeze({
6
+ Program: 1,
7
+ ExpressionStatement: 2,
8
+ AssignmentExpression: 3,
9
+ ConditionalExpression: 4,
10
+ LogicalExpression: 5,
11
+ BinaryExpression: 6,
12
+ UnaryExpression: 7,
13
+ CallExpression: 8,
14
+ MemberExpression: 9,
15
+ Identifier: 10,
16
+ Literal: 11,
17
+ ArrayExpression: 12,
18
+ Property: 13,
19
+ ObjectExpression: 14,
20
+ ThisExpression: 15,
21
+ LocalsExpression: 16,
22
+ NGValueParameter: 17,
23
+ });
@@ -1,10 +1,12 @@
1
- import { $parseMinErr } from "./parse";
2
- import { isAssignable } from "./shared";
1
+ import { isAssignable } from "./interpreter";
3
2
  import { ASTType } from "./ast-type";
3
+ import { minErr } from "../../shared/utils";
4
+
5
+ const $parseMinErr = minErr("$parse");
4
6
 
5
7
  /**
6
8
  * @typedef {Object} ASTNode
7
- * @property {string} type - The type of the AST node.
9
+ * @property {number} type - The type of the AST node.
8
10
  * @property {string} [name] - The name of the identifier.
9
11
  * @property {string} [kind] - The kind of the property (e.g., 'init').
10
12
  * @property {*} [value] - The value of the node if it is a literal.
@@ -27,19 +29,30 @@ import { ASTType } from "./ast-type";
27
29
  * @property {ASTNode} [property] - The property of a member expression.
28
30
  * @property {boolean} [computed] - Indicates if a member expression is computed.
29
31
  * @property {string} [operator] - The operator of a binary or logical expression.
32
+ * @property {boolean} [filter]
30
33
  */
31
34
 
35
+ // Keep this exported in case modification is required
36
+ /** @type {Map<string,any>} */
37
+ export const literals = new Map(
38
+ Object.entries({
39
+ true: true,
40
+ false: false,
41
+ null: null,
42
+ undefined,
43
+ }),
44
+ );
45
+
32
46
  /**
33
- * @param {import('./lexer').Lexer} lexer - The lexer instance for tokenizing input
34
- * @param {import("./parser").ParserOptions} options
47
+ * @class
35
48
  */
36
49
  export class AST {
37
- constructor(lexer, options) {
50
+ /**
51
+ * @param {import('./lexer').Lexer} lexer - The lexer instance for tokenizing input
52
+ */
53
+ constructor(lexer) {
38
54
  /** @type {import('./lexer').Lexer} */
39
55
  this.lexer = lexer;
40
-
41
- /** @type {import("./parser").ParserOptions} */
42
- this.options = options;
43
56
  this.selfReferential = {
44
57
  this: { type: ASTType.ThisExpression },
45
58
  $locals: { type: ASTType.LocalsExpression },
@@ -54,13 +67,10 @@ export class AST {
54
67
  ast(text) {
55
68
  this.text = text;
56
69
  this.tokens = this.lexer.lex(text);
57
-
58
70
  const value = this.program();
59
-
60
71
  if (this.tokens.length !== 0) {
61
72
  this.throwError("is an unexpected token", this.tokens[0]);
62
73
  }
63
-
64
74
  return value;
65
75
  }
66
76
 
@@ -97,21 +107,13 @@ export class AST {
97
107
  * @returns {ASTNode} The filter chain node.
98
108
  */
99
109
  filterChain() {
100
- let left = this.expression();
110
+ let left = this.assignment();
101
111
  while (this.expect("|")) {
102
112
  left = this.filter(left);
103
113
  }
104
114
  return left;
105
115
  }
106
116
 
107
- /**
108
- * Parses an expression.
109
- * @returns {ASTNode} The expression node.
110
- */
111
- expression() {
112
- return this.assignment();
113
- }
114
-
115
117
  /**
116
118
  * Parses an assignment expression.
117
119
  * @returns {ASTNode} The assignment expression node.
@@ -142,9 +144,9 @@ export class AST {
142
144
  let alternate;
143
145
  let consequent;
144
146
  if (this.expect("?")) {
145
- alternate = this.expression();
147
+ alternate = this.assignment();
146
148
  if (this.consume(":")) {
147
- consequent = this.expression();
149
+ consequent = this.assignment();
148
150
  return {
149
151
  type: ASTType.ConditionalExpression,
150
152
  test,
@@ -300,14 +302,11 @@ export class AST {
300
302
  ) {
301
303
  primary = structuredClone(this.selfReferential[this.consume().text]);
302
304
  } else if (
303
- Object.prototype.hasOwnProperty.call(
304
- this.options.literals,
305
- /** @type {import("./lexer").Token} */ (this.peek()).text,
306
- )
305
+ literals.has(/** @type {import("./lexer").Token} */ (this.peek()).text)
307
306
  ) {
308
307
  primary = {
309
308
  type: ASTType.Literal,
310
- value: this.options.literals[this.consume().text],
309
+ value: literals.get(this.consume().text),
311
310
  };
312
311
  } else if (
313
312
  /** @type {import("./lexer").Token} */ (this.peek()).identifier
@@ -335,7 +334,7 @@ export class AST {
335
334
  primary = {
336
335
  type: ASTType.MemberExpression,
337
336
  object: primary,
338
- property: this.expression(),
337
+ property: this.assignment(),
339
338
  computed: true,
340
339
  };
341
340
  this.consume("]");
@@ -369,7 +368,7 @@ export class AST {
369
368
  };
370
369
 
371
370
  while (this.expect(":")) {
372
- args.push(this.expression());
371
+ args.push(this.assignment());
373
372
  }
374
373
 
375
374
  return result;
@@ -424,7 +423,7 @@ export class AST {
424
423
  // Support trailing commas per ES5.1.
425
424
  break;
426
425
  }
427
- elements.push(this.expression());
426
+ elements.push(this.assignment());
428
427
  } while (this.expect(","));
429
428
  }
430
429
  this.consume("]");
@@ -452,7 +451,7 @@ export class AST {
452
451
  property.key = this.constant();
453
452
  property.computed = false;
454
453
  this.consume(":");
455
- property.value = this.expression();
454
+ property.value = this.assignment();
456
455
  } else if (
457
456
  /** @type {import("./lexer").Token} */ (this.peek()).identifier
458
457
  ) {
@@ -460,17 +459,17 @@ export class AST {
460
459
  property.computed = false;
461
460
  if (this.peek(":")) {
462
461
  this.consume(":");
463
- property.value = this.expression();
462
+ property.value = this.assignment();
464
463
  } else {
465
464
  property.value = property.key;
466
465
  }
467
466
  } else if (this.peek("[")) {
468
467
  this.consume("[");
469
- property.key = this.expression();
468
+ property.key = this.assignment();
470
469
  this.consume("]");
471
470
  property.computed = true;
472
471
  this.consume(":");
473
- property.value = this.expression();
472
+ property.value = this.assignment();
474
473
  } else {
475
474
  this.throwError(
476
475
  "invalid key",