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