@auscope/angular2parse 4.0.1 → 18.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.
Files changed (71) hide show
  1. package/.editorconfig +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1 -1
  4. package/angular.json +30 -0
  5. package/package.json +42 -42
  6. package/projects/angular2parse/README.md +49 -0
  7. package/projects/angular2parse/ng-package.json +7 -0
  8. package/projects/angular2parse/package.json +19 -0
  9. package/projects/angular2parse/src/lib/angular/compiler/assertions.ts +49 -0
  10. package/projects/angular2parse/src/lib/angular/compiler/ast.ts +393 -0
  11. package/projects/angular2parse/src/lib/angular/compiler/chars.ts +89 -0
  12. package/projects/angular2parse/src/lib/angular/compiler/interpolation-config.ts +25 -0
  13. package/projects/angular2parse/src/lib/angular/compiler/lexer.ts +383 -0
  14. package/projects/angular2parse/src/lib/angular/compiler/parser.ts +811 -0
  15. package/{lib/angular/compiler.d.ts → projects/angular2parse/src/lib/angular/compiler.ts} +1 -1
  16. package/projects/angular2parse/src/lib/angular/facade/lang.ts +124 -0
  17. package/projects/angular2parse/src/lib/angular/facade.ts +1 -0
  18. package/{lib/angular.d.ts → projects/angular2parse/src/lib/angular.ts} +1 -1
  19. package/projects/angular2parse/src/lib/module.ts +12 -0
  20. package/projects/angular2parse/src/lib/parse.ts +78 -0
  21. package/projects/angular2parse/src/lib/util/binary-operations.ts +17 -0
  22. package/projects/angular2parse/src/lib/util/lang.ts +15 -0
  23. package/{lib/util.d.ts → projects/angular2parse/src/lib/util.ts} +1 -1
  24. package/projects/angular2parse/src/lib/visitors/parse-visitor-compiler.ts +149 -0
  25. package/projects/angular2parse/src/lib/visitors/parse-visitor-resolver.ts +208 -0
  26. package/projects/angular2parse/src/lib/visitors.ts +2 -0
  27. package/projects/angular2parse/src/public-api.ts +5 -0
  28. package/projects/angular2parse/tsconfig.lib.json +19 -0
  29. package/projects/angular2parse/tsconfig.lib.prod.json +9 -0
  30. package/tsconfig.json +33 -0
  31. package/esm2020/auscope-angular2parse.mjs +0 -5
  32. package/esm2020/lib/angular/compiler/assertions.mjs +0 -45
  33. package/esm2020/lib/angular/compiler/ast.mjs +0 -393
  34. package/esm2020/lib/angular/compiler/chars.mjs +0 -78
  35. package/esm2020/lib/angular/compiler/interpolation-config.mjs +0 -24
  36. package/esm2020/lib/angular/compiler/lexer.mjs +0 -344
  37. package/esm2020/lib/angular/compiler/parser.mjs +0 -721
  38. package/esm2020/lib/angular/compiler.mjs +0 -7
  39. package/esm2020/lib/angular/facade/lang.mjs +0 -85
  40. package/esm2020/lib/angular/facade.mjs +0 -2
  41. package/esm2020/lib/angular.mjs +0 -3
  42. package/esm2020/lib/module.mjs +0 -18
  43. package/esm2020/lib/parse.mjs +0 -66
  44. package/esm2020/lib/util/binary-operations.mjs +0 -18
  45. package/esm2020/lib/util/lang.mjs +0 -13
  46. package/esm2020/lib/util.mjs +0 -3
  47. package/esm2020/lib/visitors/parse-visitor-compiler.mjs +0 -96
  48. package/esm2020/lib/visitors/parse-visitor-resolver.mjs +0 -141
  49. package/esm2020/lib/visitors.mjs +0 -3
  50. package/esm2020/public-api.mjs +0 -6
  51. package/fesm2015/auscope-angular2parse.mjs +0 -2035
  52. package/fesm2015/auscope-angular2parse.mjs.map +0 -1
  53. package/fesm2020/auscope-angular2parse.mjs +0 -2033
  54. package/fesm2020/auscope-angular2parse.mjs.map +0 -1
  55. package/index.d.ts +0 -5
  56. package/lib/angular/compiler/assertions.d.ts +0 -9
  57. package/lib/angular/compiler/ast.d.ts +0 -242
  58. package/lib/angular/compiler/chars.d.ts +0 -69
  59. package/lib/angular/compiler/interpolation-config.d.ts +0 -14
  60. package/lib/angular/compiler/lexer.d.ts +0 -44
  61. package/lib/angular/compiler/parser.d.ts +0 -92
  62. package/lib/angular/facade/lang.d.ts +0 -44
  63. package/lib/angular/facade.d.ts +0 -1
  64. package/lib/module.d.ts +0 -9
  65. package/lib/parse.d.ts +0 -21
  66. package/lib/util/binary-operations.d.ts +0 -1
  67. package/lib/util/lang.d.ts +0 -4
  68. package/lib/visitors/parse-visitor-compiler.d.ts +0 -23
  69. package/lib/visitors/parse-visitor-resolver.d.ts +0 -25
  70. package/lib/visitors.d.ts +0 -2
  71. package/public-api.d.ts +0 -2
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ export const $EOF = 0;
10
+ export const $TAB = 9;
11
+ export const $LF = 10;
12
+ export const $VTAB = 11;
13
+ export const $FF = 12;
14
+ export const $CR = 13;
15
+ export const $SPACE = 32;
16
+ export const $BANG = 33;
17
+ export const $DQ = 34;
18
+ export const $HASH = 35;
19
+ export const $$ = 36;
20
+ export const $PERCENT = 37;
21
+ export const $AMPERSAND = 38;
22
+ export const $SQ = 39;
23
+ export const $LPAREN = 40;
24
+ export const $RPAREN = 41;
25
+ export const $STAR = 42;
26
+ export const $PLUS = 43;
27
+ export const $COMMA = 44;
28
+ export const $MINUS = 45;
29
+ export const $PERIOD = 46;
30
+ export const $SLASH = 47;
31
+ export const $COLON = 58;
32
+ export const $SEMICOLON = 59;
33
+ export const $LT = 60;
34
+ export const $EQ = 61;
35
+ export const $GT = 62;
36
+ export const $QUESTION = 63;
37
+
38
+ export const $0 = 48;
39
+ export const $9 = 57;
40
+
41
+ export const $A = 65;
42
+ export const $E = 69;
43
+ export const $F = 70;
44
+ export const $X = 88;
45
+ export const $Z = 90;
46
+
47
+ export const $LBRACKET = 91;
48
+ export const $BACKSLASH = 92;
49
+ export const $RBRACKET = 93;
50
+ export const $CARET = 94;
51
+ export const $_ = 95;
52
+
53
+ export const $a = 97;
54
+ export const $e = 101;
55
+ export const $f = 102;
56
+ export const $n = 110;
57
+ export const $r = 114;
58
+ export const $t = 116;
59
+ export const $u = 117;
60
+ export const $v = 118;
61
+ export const $x = 120;
62
+ export const $z = 122;
63
+
64
+ export const $LBRACE = 123;
65
+ export const $BAR = 124;
66
+ export const $RBRACE = 125;
67
+ export const $NBSP = 160;
68
+
69
+ export const $PIPE = 124;
70
+ export const $TILDA = 126;
71
+ export const $AT = 64;
72
+
73
+ export const $BT = 96;
74
+
75
+ export function isWhitespace(code: number): boolean {
76
+ return (code >= $TAB && code <= $SPACE) || (code == $NBSP);
77
+ }
78
+
79
+ export function isDigit(code: number): boolean {
80
+ return $0 <= code && code <= $9;
81
+ }
82
+
83
+ export function isAsciiLetter(code: number): boolean {
84
+ return code >= $a && code <= $z || code >= $A && code <= $Z;
85
+ }
86
+
87
+ export function isAsciiHexDigit(code: number): boolean {
88
+ return code >= $a && code <= $f || code >= $A && code <= $F || isDigit(code);
89
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ import {assertInterpolationSymbols} from './assertions';
10
+
11
+ export class InterpolationConfig {
12
+ static fromArray(markers: [string, string]): InterpolationConfig {
13
+ if (!markers) {
14
+ return DEFAULT_INTERPOLATION_CONFIG;
15
+ }
16
+
17
+ assertInterpolationSymbols('interpolation', markers);
18
+ return new InterpolationConfig(markers[0], markers[1]);
19
+ }
20
+
21
+ constructor(public start: string, public end: string){};
22
+ }
23
+
24
+ export const DEFAULT_INTERPOLATION_CONFIG: InterpolationConfig =
25
+ new InterpolationConfig('{{', '}}');
@@ -0,0 +1,383 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ import * as chars from './chars';
10
+ import {NumberWrapper} from '../facade/lang';
11
+
12
+ export enum TokenType {
13
+ Character,
14
+ Identifier,
15
+ Keyword,
16
+ String,
17
+ Operator,
18
+ Number,
19
+ Error
20
+ }
21
+
22
+ const KEYWORDS = ['var', 'let', 'null', 'undefined', 'true', 'false', 'if', 'else', 'this'];
23
+
24
+ export class Lexer {
25
+ tokenize(text: string): Token[] {
26
+ const scanner = new _Scanner(text);
27
+ const tokens: Token[] = [];
28
+ let token = scanner.scanToken();
29
+ while (token != null) {
30
+ tokens.push(token);
31
+ token = scanner.scanToken();
32
+ }
33
+ return tokens;
34
+ }
35
+ }
36
+
37
+ export class Token {
38
+ constructor(
39
+ public index: number, public type: TokenType, public numValue: number,
40
+ public strValue: string) {}
41
+
42
+ isCharacter(code: number): boolean {
43
+ return this.type == TokenType.Character && this.numValue == code;
44
+ }
45
+
46
+ isNumber(): boolean { return this.type == TokenType.Number; }
47
+
48
+ isString(): boolean { return this.type == TokenType.String; }
49
+
50
+ isOperator(operater: string): boolean {
51
+ return this.type == TokenType.Operator && this.strValue == operater;
52
+ }
53
+
54
+ isIdentifier(): boolean { return this.type == TokenType.Identifier; }
55
+
56
+ isKeyword(): boolean { return this.type == TokenType.Keyword; }
57
+
58
+ isKeywordLet(): boolean { return this.type == TokenType.Keyword && this.strValue == 'let'; }
59
+
60
+ isKeywordNull(): boolean { return this.type == TokenType.Keyword && this.strValue == 'null'; }
61
+
62
+ isKeywordUndefined(): boolean {
63
+ return this.type == TokenType.Keyword && this.strValue == 'undefined';
64
+ }
65
+
66
+ isKeywordTrue(): boolean { return this.type == TokenType.Keyword && this.strValue == 'true'; }
67
+
68
+ isKeywordFalse(): boolean { return this.type == TokenType.Keyword && this.strValue == 'false'; }
69
+
70
+ isKeywordThis(): boolean { return this.type == TokenType.Keyword && this.strValue == 'this'; }
71
+
72
+ isError(): boolean { return this.type == TokenType.Error; }
73
+
74
+ toNumber(): number { return this.type == TokenType.Number ? this.numValue : -1; }
75
+
76
+ toString(): string {
77
+ switch (this.type) {
78
+ case TokenType.Character:
79
+ case TokenType.Identifier:
80
+ case TokenType.Keyword:
81
+ case TokenType.Operator:
82
+ case TokenType.String:
83
+ case TokenType.Error:
84
+ return this.strValue;
85
+ case TokenType.Number:
86
+ return this.numValue.toString();
87
+ default:
88
+ return null;
89
+ }
90
+ }
91
+ }
92
+
93
+ function newCharacterToken(index: number, code: number): Token {
94
+ return new Token(index, TokenType.Character, code, String.fromCharCode(code));
95
+ }
96
+
97
+ function newIdentifierToken(index: number, text: string): Token {
98
+ return new Token(index, TokenType.Identifier, 0, text);
99
+ }
100
+
101
+ function newKeywordToken(index: number, text: string): Token {
102
+ return new Token(index, TokenType.Keyword, 0, text);
103
+ }
104
+
105
+ function newOperatorToken(index: number, text: string): Token {
106
+ return new Token(index, TokenType.Operator, 0, text);
107
+ }
108
+
109
+ function newStringToken(index: number, text: string): Token {
110
+ return new Token(index, TokenType.String, 0, text);
111
+ }
112
+
113
+ function newNumberToken(index: number, n: number): Token {
114
+ return new Token(index, TokenType.Number, n, '');
115
+ }
116
+
117
+ function newErrorToken(index: number, message: string): Token {
118
+ return new Token(index, TokenType.Error, 0, message);
119
+ }
120
+
121
+ export const EOF: Token = new Token(-1, TokenType.Character, 0, '');
122
+
123
+ class _Scanner {
124
+ length: number;
125
+ peek: number = 0;
126
+ index: number = -1;
127
+
128
+ constructor(public input: string) {
129
+ this.length = input.length;
130
+ this.advance();
131
+ }
132
+
133
+ advance() {
134
+ this.peek = ++this.index >= this.length ? chars.$EOF : this.input.charCodeAt(this.index);
135
+ }
136
+
137
+ scanToken(): Token {
138
+ const input = this.input, length = this.length;
139
+ let peek = this.peek, index = this.index;
140
+
141
+ // Skip whitespace.
142
+ while (peek <= chars.$SPACE) {
143
+ if (++index >= length) {
144
+ peek = chars.$EOF;
145
+ break;
146
+ } else {
147
+ peek = input.charCodeAt(index);
148
+ }
149
+ }
150
+
151
+ this.peek = peek;
152
+ this.index = index;
153
+
154
+ if (index >= length) {
155
+ return null;
156
+ }
157
+
158
+ // Handle identifiers and numbers.
159
+ if (isIdentifierStart(peek)) return this.scanIdentifier();
160
+ if (chars.isDigit(peek)) return this.scanNumber(index);
161
+
162
+ const start: number = index;
163
+ switch (peek) {
164
+ case chars.$PERIOD:
165
+ this.advance();
166
+ return chars.isDigit(this.peek) ? this.scanNumber(start) :
167
+ newCharacterToken(start, chars.$PERIOD);
168
+ case chars.$LPAREN:
169
+ case chars.$RPAREN:
170
+ case chars.$LBRACE:
171
+ case chars.$RBRACE:
172
+ case chars.$LBRACKET:
173
+ case chars.$RBRACKET:
174
+ case chars.$COMMA:
175
+ case chars.$COLON:
176
+ case chars.$SEMICOLON:
177
+ return this.scanCharacter(start, peek);
178
+ case chars.$SQ:
179
+ case chars.$DQ:
180
+ return this.scanString();
181
+ case chars.$HASH:
182
+ case chars.$PLUS:
183
+ case chars.$MINUS:
184
+ case chars.$STAR:
185
+ case chars.$SLASH:
186
+ case chars.$PERCENT:
187
+ case chars.$CARET:
188
+ return this.scanOperator(start, String.fromCharCode(peek));
189
+ case chars.$QUESTION:
190
+ return this.scanComplexOperator(start, '?', chars.$PERIOD, '.');
191
+ case chars.$LT:
192
+ case chars.$GT:
193
+ return this.scanComplexOperator(start, String.fromCharCode(peek), chars.$EQ, '=');
194
+ case chars.$BANG:
195
+ case chars.$EQ:
196
+ return this.scanComplexOperator(
197
+ start, String.fromCharCode(peek), chars.$EQ, '=', chars.$EQ, '=');
198
+ case chars.$AMPERSAND:
199
+ return this.scanComplexOperator(start, '&', chars.$AMPERSAND, '&');
200
+ case chars.$BAR:
201
+ return this.scanComplexOperator(start, '|', chars.$BAR, '|');
202
+ case chars.$NBSP:
203
+ while (chars.isWhitespace(this.peek)) this.advance();
204
+ return this.scanToken();
205
+ }
206
+
207
+ this.advance();
208
+ return this.error(`Unexpected character [${String.fromCharCode(peek)}]`, 0);
209
+ }
210
+
211
+ scanCharacter(start: number, code: number): Token {
212
+ this.advance();
213
+ return newCharacterToken(start, code);
214
+ }
215
+
216
+
217
+ scanOperator(start: number, str: string): Token {
218
+ this.advance();
219
+ return newOperatorToken(start, str);
220
+ }
221
+
222
+ /**
223
+ * Tokenize a 2/3 char long operator
224
+ *
225
+ * @param start start index in the expression
226
+ * @param one first symbol (always part of the operator)
227
+ * @param twoCode code point for the second symbol
228
+ * @param two second symbol (part of the operator when the second code point matches)
229
+ * @param threeCode code point for the third symbol
230
+ * @param three third symbol (part of the operator when provided and matches source expression)
231
+ * @returns {Token}
232
+ */
233
+ scanComplexOperator(
234
+ start: number, one: string, twoCode: number, two: string, threeCode?: number,
235
+ three?: string): Token {
236
+ this.advance();
237
+ let str: string = one;
238
+ if (this.peek == twoCode) {
239
+ this.advance();
240
+ str += two;
241
+ }
242
+ if (threeCode != null && this.peek == threeCode) {
243
+ this.advance();
244
+ str += three;
245
+ }
246
+ return newOperatorToken(start, str);
247
+ }
248
+
249
+ scanIdentifier(): Token {
250
+ const start: number = this.index;
251
+ this.advance();
252
+ while (isIdentifierPart(this.peek)) this.advance();
253
+ const str: string = this.input.substring(start, this.index);
254
+ return KEYWORDS.indexOf(str) > -1 ? newKeywordToken(start, str) :
255
+ newIdentifierToken(start, str);
256
+ }
257
+
258
+ scanNumber(start: number): Token {
259
+ let simple: boolean = (this.index === start);
260
+ this.advance(); // Skip initial digit.
261
+ while (true) {
262
+ if (chars.isDigit(this.peek)) {
263
+ // Do nothing.
264
+ } else if (this.peek == chars.$PERIOD) {
265
+ simple = false;
266
+ } else if (isExponentStart(this.peek)) {
267
+ this.advance();
268
+ if (isExponentSign(this.peek)) this.advance();
269
+ if (!chars.isDigit(this.peek)) return this.error('Invalid exponent', -1);
270
+ simple = false;
271
+ } else {
272
+ break;
273
+ }
274
+ this.advance();
275
+ }
276
+ const str: string = this.input.substring(start, this.index);
277
+ const value: number = simple ? NumberWrapper.parseIntAutoRadix(str) : parseFloat(str);
278
+ return newNumberToken(start, value);
279
+ }
280
+
281
+ scanString(): Token {
282
+ const start: number = this.index;
283
+ const quote: number = this.peek;
284
+ this.advance(); // Skip initial quote.
285
+
286
+ let buffer: string = '';
287
+ let marker: number = this.index;
288
+ const input: string = this.input;
289
+
290
+ while (this.peek != quote) {
291
+ if (this.peek == chars.$BACKSLASH) {
292
+ buffer += input.substring(marker, this.index);
293
+ this.advance();
294
+ let unescapedCode: number;
295
+ // Workaround for TS2.1-introduced type strictness
296
+ this.peek = this.peek;
297
+ if (this.peek == chars.$u) {
298
+ // 4 character hex code for unicode character.
299
+ const hex: string = input.substring(this.index + 1, this.index + 5);
300
+ if (/^[0-9a-f]+$/i.test(hex)) {
301
+ unescapedCode = parseInt(hex, 16);
302
+ } else {
303
+ return this.error(`Invalid unicode escape [\\u${hex}]`, 0);
304
+ }
305
+ for (let i: number = 0; i < 5; i++) {
306
+ this.advance();
307
+ }
308
+ } else {
309
+ unescapedCode = unescape(this.peek);
310
+ this.advance();
311
+ }
312
+ buffer += String.fromCharCode(unescapedCode);
313
+ marker = this.index;
314
+ } else if (this.peek == chars.$EOF) {
315
+ return this.error('Unterminated quote', 0);
316
+ } else {
317
+ this.advance();
318
+ }
319
+ }
320
+
321
+ const last: string = input.substring(marker, this.index);
322
+ this.advance(); // Skip terminating quote.
323
+
324
+ return newStringToken(start, buffer + last);
325
+ }
326
+
327
+ error(message: string, offset: number): Token {
328
+ const position: number = this.index + offset;
329
+ return newErrorToken(
330
+ position, `Lexer Error: ${message} at column ${position} in expression [${this.input}]`);
331
+ }
332
+ }
333
+
334
+ function isIdentifierStart(code: number): boolean {
335
+ return (chars.$a <= code && code <= chars.$z) || (chars.$A <= code && code <= chars.$Z) ||
336
+ (code == chars.$_) || (code == chars.$$);
337
+ }
338
+
339
+ export function isIdentifier(input: string): boolean {
340
+ if (input.length == 0) return false;
341
+ const scanner = new _Scanner(input);
342
+ if (!isIdentifierStart(scanner.peek)) return false;
343
+ scanner.advance();
344
+ while (scanner.peek !== chars.$EOF) {
345
+ if (!isIdentifierPart(scanner.peek)) return false;
346
+ scanner.advance();
347
+ }
348
+ return true;
349
+ }
350
+
351
+ function isIdentifierPart(code: number): boolean {
352
+ return chars.isAsciiLetter(code) || chars.isDigit(code) || (code == chars.$_) ||
353
+ (code == chars.$$);
354
+ }
355
+
356
+ function isExponentStart(code: number): boolean {
357
+ return code == chars.$e || code == chars.$E;
358
+ }
359
+
360
+ function isExponentSign(code: number): boolean {
361
+ return code == chars.$MINUS || code == chars.$PLUS;
362
+ }
363
+
364
+ export function isQuote(code: number): boolean {
365
+ return code === chars.$SQ || code === chars.$DQ || code === chars.$BT;
366
+ }
367
+
368
+ function unescape(code: number): number {
369
+ switch (code) {
370
+ case chars.$n:
371
+ return chars.$LF;
372
+ case chars.$f:
373
+ return chars.$FF;
374
+ case chars.$r:
375
+ return chars.$CR;
376
+ case chars.$t:
377
+ return chars.$TAB;
378
+ case chars.$v:
379
+ return chars.$VTAB;
380
+ default:
381
+ return code;
382
+ }
383
+ }