@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.
@@ -1,5 +1,6 @@
1
- import { $parseMinErr } from "./parse";
2
- import { isDefined } from "../../shared/utils";
1
+ import { isDefined, minErr } from "../../shared/utils";
2
+
3
+ const $parseMinErr = minErr("$parse");
3
4
 
4
5
  const ESCAPE = {
5
6
  n: "\n",
@@ -22,7 +23,7 @@ const OPERATORS = new Set(
22
23
  */
23
24
 
24
25
  /**
25
- * Represents a token produced by the lexer.
26
+ * Represents a token produced by the lexer, which will be used by the AST to construct an abstract syntax tree.
26
27
  * @typedef {Object} Token
27
28
  * @property {number} index - Index of the token.
28
29
  * @property {string} text - Text of the token.
@@ -66,7 +67,10 @@ export class Lexer {
66
67
  (ch === "." && this.isNumber(/** @type {string} */ (this.peek())))
67
68
  ) {
68
69
  this.readNumber();
69
- } else if (this.isIdentifierStart(this.peekMultichar())) {
70
+ } else if (
71
+ this.isIdentifierStart &&
72
+ this.isIdentifierStart(this.peekMultichar())
73
+ ) {
70
74
  this.readIdent();
71
75
  } else if (this.is(ch, "(){}[].,;:?")) {
72
76
  this.tokens.push({ index: this.index, text: ch });
@@ -132,14 +136,8 @@ export class Lexer {
132
136
  * @returns {boolean} True if character is whitespace, false otherwise.
133
137
  */
134
138
  isWhitespace(ch) {
135
- // IE treats non-breaking space as \u00A0
136
139
  return (
137
- ch === " " ||
138
- ch === "\r" ||
139
- ch === "\t" ||
140
- ch === "\n" ||
141
- ch === "\v" ||
142
- ch === "\u00A0"
140
+ ch === " " || ch === "\r" || ch === "\t" || ch === "\n" || ch === "\v"
143
141
  );
144
142
  }
145
143
 
@@ -179,7 +177,6 @@ export class Lexer {
179
177
  */
180
178
  codePointAt(ch) {
181
179
  if (ch.length === 1) return ch.charCodeAt(0);
182
-
183
180
  return (ch.charCodeAt(0) << 10) + ch.charCodeAt(1) - 0x35fdc00;
184
181
  }
185
182
 
@@ -230,6 +227,7 @@ export class Lexer {
230
227
 
231
228
  /**
232
229
  * Reads and tokenizes a number from the text.
230
+ * @return {void}
233
231
  */
234
232
  readNumber() {
235
233
  let number = "";
@@ -277,7 +275,7 @@ export class Lexer {
277
275
  this.index += this.peekMultichar().length;
278
276
  while (this.index < this.text.length) {
279
277
  const ch = this.peekMultichar();
280
- if (!this.isIdentifierContinue(ch)) {
278
+ if (this.isIdentifierContinue && !this.isIdentifierContinue(ch)) {
281
279
  break;
282
280
  }
283
281
  this.index += ch.length;
@@ -333,6 +331,9 @@ export class Lexer {
333
331
  this.throwError("Unterminated quote", start);
334
332
  }
335
333
 
334
+ /**
335
+ * @returns {string}
336
+ */
336
337
  handleUnicodeEscape() {
337
338
  const hex = this.text.substring(this.index + 1, this.index + 5);
338
339
  if (!hex.match(/[\da-f]{4}/i)) {
@@ -1,63 +1,46 @@
1
- import { forEach, isDefined, isFunction, minErr } from "../../shared/utils";
2
- import { getValueOf, PURITY_RELATIVE } from "./shared";
1
+ import { forEach, isDefined, isFunction } from "../../shared/utils";
2
+ import { PURITY_RELATIVE } from "./interpreter";
3
3
  import { Lexer } from "./lexer";
4
4
  import { Parser } from "./parser";
5
5
 
6
6
  /**
7
- * @typedef {function} CompiledExpression
8
- * @param {import('../scope/scope').Scope} context - An object against which any expressions embedded in the strings are evaluated against (typically a scope object).
9
- * @param {object} [locals] - local variables context object, useful for overriding values in `context`.
10
- * @returns {any}
7
+ * @typedef {Object} CompiledExpressionProps
11
8
  * @property {boolean} literal - Indicates if the expression is a literal.
12
9
  * @property {boolean} constant - Indicates if the expression is constant.
10
+ * @property {boolean} isPure
11
+ * @property {boolean} oneTime
12
+ * @property {any[]} inputs
13
13
  * @property {function(any, any): any} assign - Assigns a value to a context. If value is not provided,
14
+ */
15
+
16
+ /**
17
+ * @typedef {function } CompiledExpressionFunction
18
+ * @param {import('../scope/scope').Scope} context - An object against which any expressions embedded in the strings are evaluated against (typically a scope object).
19
+ * @param {object} [locals] - local variables context object, useful for overriding values in `context`.
20
+ * @param {any} [assign]
21
+ * @returns {any}
14
22
  * undefined is gonna be used since the implementation
15
23
  * does not check the parameter. Let's force a value for consistency. If consumer
16
24
  * wants to undefine it, pass the undefined value explicitly.
17
25
  */
18
26
 
19
27
  /**
20
- * @typedef {function(string|function(import('../scope/scope').Scope):any, function(any, import('../scope/scope').Scope, any):any=, boolean=): CompiledExpression} ParseService
28
+ * @typedef {CompiledExpressionFunction & CompiledExpressionProps} CompiledExpression
21
29
  */
22
30
 
23
- export const $parseMinErr = minErr("$parse");
24
-
25
- export const literals = {
26
- true: true,
27
- false: false,
28
- null: null,
29
- undefined,
30
- };
31
+ /**
32
+ * @typedef {function(string|function(import('../scope/scope').Scope):any, function(any, import('../scope/scope').Scope, any):any=, boolean=): CompiledExpression} ParseService
33
+ */
31
34
 
32
35
  export function $ParseProvider() {
33
36
  const cache = Object.create(null);
34
- const literals = {
35
- true: true,
36
- false: false,
37
- null: null,
38
- undefined: undefined,
39
- };
37
+
40
38
  /** @type {function(any):boolean?} */
41
39
  var identStart;
42
40
 
43
41
  /** @type {function(any):boolean?} */
44
42
  var identContinue;
45
43
 
46
- /**
47
- * @ngdoc method
48
- * @name $parseProvider#addLiteral
49
- * @description
50
- *
51
- * Configure $parse service to add literal values that will be present as literal at expressions.
52
- *
53
- * @param {string} literalName Token for the literal value. The literal name value must be a valid literal name.
54
- * @param {*} literalValue Value for this literal. All literal values must be primitives or `undefined`.
55
- *
56
- **/
57
- this.addLiteral = function (literalName, literalValue) {
58
- literals[literalName] = literalValue;
59
- };
60
-
61
44
  /**
62
45
  * Allows defining the set of characters that are allowed in AngularJS expressions. The function
63
46
  * `identifierStart` will get called to know if a given character is a valid character to be the
@@ -87,8 +70,8 @@ export function $ParseProvider() {
87
70
  this.$get = [
88
71
  "$filter",
89
72
  function ($filter) {
90
- var $parseOptions = {
91
- literals: structuredClone(literals),
73
+ /** @type {import("./lexer").LexerOptions} */
74
+ var $lexerOptions = {
92
75
  isIdentifierStart: isFunction(identStart) && identStart,
93
76
  isIdentifierContinue: isFunction(identContinue) && identContinue,
94
77
  };
@@ -106,11 +89,8 @@ export function $ParseProvider() {
106
89
  parsedExpression = cache[cacheKey];
107
90
 
108
91
  if (!parsedExpression) {
109
- var lexer = new Lexer({
110
- isIdentifierContinue: $parseOptions.isIdentifierContinue,
111
- isIdentifierStart: $parseOptions.isIdentifierStart,
112
- });
113
- var parser = new Parser(lexer, $filter, $parseOptions);
92
+ var lexer = new Lexer($lexerOptions);
93
+ var parser = new Parser(lexer, $filter);
114
94
  parsedExpression = parser.parse(exp);
115
95
 
116
96
  cache[cacheKey] = addWatchDelegate(parsedExpression);
@@ -130,8 +110,8 @@ export function $ParseProvider() {
130
110
  * @returns {import("./ast").ASTNode}
131
111
  */
132
112
  function $$getAst(exp) {
133
- var lexer = new Lexer($parseOptions);
134
- var parser = new Parser(lexer, $filter, $parseOptions);
113
+ var lexer = new Lexer($lexerOptions);
114
+ var parser = new Parser(lexer, $filter);
135
115
  return parser.getAst(exp).ast;
136
116
  }
137
117
 
@@ -396,3 +376,9 @@ function isAllDefined(value) {
396
376
  });
397
377
  return allDefined;
398
378
  }
379
+
380
+ function getValueOf(value) {
381
+ return isFunction(value.valueOf)
382
+ ? value.valueOf()
383
+ : {}.constructor.prototype.valueOf.call(value);
384
+ }