@angular-wave/angular.ts 0.0.65 → 0.0.67

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 (79) hide show
  1. package/dist/angular-ts.esm.js +2 -2
  2. package/dist/angular-ts.umd.js +2 -2
  3. package/package.json +1 -1
  4. package/src/animations/animate-js.js +6 -0
  5. package/src/animations/animate-swap.js +3 -0
  6. package/src/animations/animation.js +1 -1
  7. package/src/core/compile/compile.js +16 -4
  8. package/src/core/controller/controller.js +5 -5
  9. package/src/core/di/injector.js +133 -259
  10. package/src/core/di/injector.md +3 -3
  11. package/src/core/di/injector.spec.js +30 -24
  12. package/src/core/di/internal-injector.js +286 -0
  13. package/src/core/filter/filter.js +5 -0
  14. package/src/core/parser/parse.js +1 -12
  15. package/src/core/parser/parse.spec.js +96 -110
  16. package/src/core/sce/sce.js +6 -1
  17. package/src/core/timeout/timeout.js +110 -111
  18. package/src/directive/input/input.js +32 -726
  19. package/src/directive/input/input.md +706 -0
  20. package/src/directive/select/select.js +48 -122
  21. package/src/directive/select/select.md +74 -0
  22. package/src/directive/show-hide/show-hide.js +13 -224
  23. package/src/directive/show-hide/show-hide.md +257 -0
  24. package/src/filters/limit-to.spec.js +1 -1
  25. package/src/filters/order-by.spec.js +1 -1
  26. package/src/index.js +6 -2
  27. package/src/loader.js +8 -4
  28. package/src/public.js +1 -7
  29. package/src/router/services.js +9 -4
  30. package/src/router/state/state-builder.js +6 -7
  31. package/src/router/state/state-registry.js +5 -0
  32. package/src/router/state/state-service.js +1 -1
  33. package/src/router/state/views.js +2 -1
  34. package/src/router/state-provider.js +1 -1
  35. package/src/router/template-factory.js +15 -14
  36. package/src/router/url/url-service.js +4 -4
  37. package/src/services/anchor-scroll.js +2 -2
  38. package/src/services/browser.js +2 -9
  39. package/src/services/cache-factory.js +0 -67
  40. package/src/services/cache-factory.md +75 -0
  41. package/src/services/cookie-reader.js +36 -55
  42. package/src/services/http/http.js +73 -586
  43. package/src/services/http/http.md +413 -0
  44. package/src/services/http-backend/http-backend.js +19 -44
  45. package/src/services/template-request.js +1 -9
  46. package/src/shared/jqlite/jqlite.js +4 -69
  47. package/src/types.js +8 -12
  48. package/types/animations/animate-js.d.ts +1 -1
  49. package/types/animations/animate-swap.d.ts +4 -7
  50. package/types/animations/animation.d.ts +1 -1
  51. package/types/core/compile/compile.d.ts +7 -7
  52. package/types/core/controller/controller.d.ts +1 -6
  53. package/types/core/di/injector.d.ts +13 -7
  54. package/types/core/di/internal-injector.d.ts +91 -0
  55. package/types/core/exception-handler.d.ts +1 -1
  56. package/types/core/filter/filter.d.ts +1 -1
  57. package/types/core/parser/parse.d.ts +1 -1
  58. package/types/core/sce/sce.d.ts +1 -1
  59. package/types/core/timeout/timeout.d.ts +16 -26
  60. package/types/directive/input/input.d.ts +19 -124
  61. package/types/directive/select/select.d.ts +7 -74
  62. package/types/directive/show-hide/show-hide.d.ts +11 -224
  63. package/types/loader.d.ts +4 -4
  64. package/types/router/services.d.ts +8 -1
  65. package/types/router/state/state-builder.d.ts +1 -2
  66. package/types/router/state/state-registry.d.ts +2 -2
  67. package/types/router/state/state-service.d.ts +2 -2
  68. package/types/router/state-provider.d.ts +2 -2
  69. package/types/router/template-factory.d.ts +16 -16
  70. package/types/router/url/url-service.d.ts +4 -4
  71. package/types/services/anchor-scroll.d.ts +1 -1
  72. package/types/services/browser.d.ts +0 -10
  73. package/types/services/cache-factory.d.ts +0 -67
  74. package/types/services/cookie-reader.d.ts +2 -10
  75. package/types/services/http/http.d.ts +53 -61
  76. package/types/services/http-backend/http-backend.d.ts +8 -31
  77. package/types/services/template-request.d.ts +1 -9
  78. package/types/shared/jqlite/jqlite.d.ts +9 -9
  79. package/types/types.d.ts +5 -38
@@ -1,5 +1,5 @@
1
1
  import { Angular } from "../../loader";
2
- import { createInjector } from "./injector";
2
+ import { createInjector, annotate } from "./injector";
3
3
  import { valueFn, extend } from "../../shared/utils";
4
4
 
5
5
  describe("injector.modules", () => {
@@ -17,6 +17,19 @@ describe("injector.modules", () => {
17
17
  expect($injector.get("$injector")).toBe($injector);
18
18
  });
19
19
 
20
+ it("should have modules property", () => {
21
+ const $injector = createInjector([]);
22
+ expect($injector.modules).toEqual({});
23
+ });
24
+
25
+ it("should have methods", () => {
26
+ const $injector = createInjector([]);
27
+ expect($injector.has).toBeDefined();
28
+ expect($injector.invoke).toBeDefined();
29
+ expect($injector.instantiate).toBeDefined();
30
+ expect($injector.get).toBeDefined();
31
+ });
32
+
20
33
  it("should have a false strictDi property", () => {
21
34
  const injector = createInjector([]);
22
35
  expect(injector.strictDi).toBe(false);
@@ -30,13 +43,15 @@ describe("injector.modules", () => {
30
43
 
31
44
  it("should provide useful message if no provider", () => {
32
45
  expect(() => {
33
- createInjector([]).get("idontexist");
46
+ const injector = createInjector([]);
47
+ injector.get("idontexist");
34
48
  }).toThrowError(/Unknown provider/);
35
49
  });
36
50
 
37
51
  it("has a constant that has been registered to a module", () => {
38
52
  const module = angular.module("myModule", []);
39
53
  module.constant("aConstant", 42);
54
+
40
55
  const injector = createInjector(["myModule"]);
41
56
  expect(injector.has("aConstant")).toBe(true);
42
57
  });
@@ -108,6 +123,7 @@ describe("injector.modules", () => {
108
123
  log.push("initial");
109
124
  });
110
125
  const injector = createInjector(["initial"]);
126
+ expect(log).toEqual(["initial"]);
111
127
  log.push("created");
112
128
 
113
129
  angular
@@ -386,12 +402,10 @@ describe("injector.modules", () => {
386
402
  });
387
403
 
388
404
  describe("annotate", () => {
389
- let annotate;
390
405
  let injector;
391
406
  beforeEach(() => {
392
407
  window.angular = new Angular();
393
408
  injector = createInjector([]);
394
- annotate = injector.annotate;
395
409
  });
396
410
 
397
411
  it("should return $inject", () => {
@@ -511,43 +525,43 @@ describe("annotate", () => {
511
525
  const injector = createInjector([]);
512
526
  const fn = () => {};
513
527
  fn.$inject = ["a", "b"];
514
- expect(injector.annotate(fn)).toEqual(["a", "b"]);
528
+ expect(annotate(fn)).toEqual(["a", "b"]);
515
529
  });
516
530
 
517
531
  it("returns the array-style annotations of a function", () => {
518
532
  const injector = createInjector([]);
519
533
  const fn = ["a", "b", () => {}];
520
- expect(injector.annotate(fn)).toEqual(["a", "b"]);
534
+ expect(annotate(fn)).toEqual(["a", "b"]);
521
535
  });
522
536
 
523
537
  it("returns the array-style annotations of a function", () => {
524
538
  const injector = createInjector([]);
525
539
  const fn = ["a", "b", () => {}];
526
- expect(injector.annotate(fn)).toEqual(["a", "b"]);
540
+ expect(annotate(fn)).toEqual(["a", "b"]);
527
541
  });
528
542
 
529
543
  it("returns annotations parsed from function args when not annotated", () => {
530
544
  const injector = createInjector([]);
531
545
  const fn = function (a, b) {};
532
- expect(injector.annotate(fn)).toEqual(["a", "b"]);
546
+ expect(annotate(fn)).toEqual(["a", "b"]);
533
547
  });
534
548
 
535
549
  it("returns annotations parsed from arrow args when not annotated", () => {
536
550
  const injector = createInjector([]);
537
551
  const fn = (a, b) => {};
538
- expect(injector.annotate(fn)).toEqual(["a", "b"]);
552
+ expect(annotate(fn)).toEqual(["a", "b"]);
539
553
  });
540
554
 
541
555
  it("strips comments from argument lists when parsing", () => {
542
556
  const injector = createInjector([]);
543
557
  const fn = function (a, /*b,*/ c) {};
544
- expect(injector.annotate(fn)).toEqual(["a", "c"]);
558
+ expect(annotate(fn)).toEqual(["a", "c"]);
545
559
  });
546
560
 
547
561
  it("strips several comments from argument lists when parsing", () => {
548
562
  const injector = createInjector([]);
549
563
  const fn = function (a, /*b,*/ c /*, d*/) {};
550
- expect(injector.annotate(fn)).toEqual(["a", "c"]);
564
+ expect(annotate(fn)).toEqual(["a", "c"]);
551
565
  });
552
566
 
553
567
  it("strips // comments from argument lists when parsing", () => {
@@ -556,19 +570,13 @@ describe("annotate", () => {
556
570
  a, //b,
557
571
  c,
558
572
  ) {};
559
- expect(injector.annotate(fn)).toEqual(["a", "c"]);
573
+ expect(annotate(fn)).toEqual(["a", "c"]);
560
574
  });
561
575
 
562
576
  it("strips surrounding underscores from argument names when parsing", () => {
563
577
  const injector = createInjector([]);
564
578
  const fn = function (a, _b_, c_, _d, an_argument) {};
565
- expect(injector.annotate(fn)).toEqual([
566
- "a",
567
- "b",
568
- "c_",
569
- "_d",
570
- "an_argument",
571
- ]);
579
+ expect(annotate(fn)).toEqual(["a", "b", "c_", "_d", "an_argument"]);
572
580
  });
573
581
 
574
582
  it("throws when using a non-annotated fn in strict mode", () => {
@@ -1922,7 +1930,8 @@ describe("decorator", () => {
1922
1930
  "ng",
1923
1931
  function ($provide) {
1924
1932
  $provide.decorator("$injector", function ($delegate) {
1925
- return extend({}, $delegate, {
1933
+ // Don't forget the prototype
1934
+ return extend(Object.create($delegate), $delegate, {
1926
1935
  get: function (val) {
1927
1936
  if (val === "key") {
1928
1937
  return "value";
@@ -1933,7 +1942,6 @@ describe("decorator", () => {
1933
1942
  });
1934
1943
  },
1935
1944
  ]);
1936
-
1937
1945
  expect(injector.get("key")).toBe("value");
1938
1946
  expect(injector.get("$http")).not.toBeUndefined();
1939
1947
  });
@@ -2245,9 +2253,7 @@ describe("protection modes", () => {
2245
2253
  });
2246
2254
 
2247
2255
  it("should prevent instance lookup in module", () => {
2248
- function instanceLookupInModule(name) {
2249
- throw new Error("FAIL");
2250
- }
2256
+ function instanceLookupInModule(name) {}
2251
2257
  expect(() => {
2252
2258
  createInjector([
2253
2259
  function ($provide) {
@@ -0,0 +1,286 @@
1
+ import { assertArgFn, minErr } from "../../shared/utils";
2
+ import { INJECTOR_LITERAL } from "./ng-module";
3
+
4
+ const ARROW_ARG = /^([^(]+?)=>/;
5
+ const FN_ARGS = /^[^(]*\(\s*([^)]*)\)/m;
6
+ const FN_ARG_SPLIT = /,/;
7
+ const FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
8
+ const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
9
+ const $injectorMinErr = minErr(INJECTOR_LITERAL);
10
+
11
+ const providerSuffix = "Provider";
12
+ const INSTANTIATING = true;
13
+
14
+ class AbstractInjector {
15
+ /**
16
+ * @param {boolean} strictDi - Indicates if strict dependency injection is enforced.
17
+ */
18
+ constructor(strictDi) {
19
+ /**
20
+ * @type {Object<String, Function>}
21
+ */
22
+ this.cache = {};
23
+ /** @type {boolean} */
24
+ this.strictDi = strictDi;
25
+ this.path = [];
26
+ /** @type {Object.<string, import("../../types").Module>} */
27
+ this.modules = {};
28
+ }
29
+
30
+ /**
31
+ * Get a service by name.
32
+ *
33
+ * @param {String} serviceName
34
+ * @returns {any}
35
+ */
36
+ get(serviceName) {
37
+ if (Object.prototype.hasOwnProperty.call(this.cache, serviceName)) {
38
+ if (this.cache[serviceName] === INSTANTIATING) {
39
+ throw $injectorMinErr(
40
+ "cdep",
41
+ "Circular dependency found: {0}",
42
+ `${serviceName} <- ${this.path.join(" <- ")}`,
43
+ );
44
+ }
45
+ return this.cache[serviceName];
46
+ }
47
+
48
+ this.path.unshift(serviceName);
49
+ this.cache[serviceName] = INSTANTIATING;
50
+ try {
51
+ // this goes to line 60
52
+ this.cache[serviceName] = this.factory(serviceName);
53
+ } catch (err) {
54
+ // this is for the error handling being thrown by the providerCache multiple times
55
+ delete this.cache[serviceName];
56
+ throw err;
57
+ }
58
+ return this.cache[serviceName];
59
+ }
60
+
61
+ /**
62
+ * Get the injection arguments for a function.
63
+ *
64
+ * @param {Function|Array} fn
65
+ * @param {Object} locals
66
+ * @param {String} serviceName
67
+ * @returns
68
+ */
69
+ injectionArgs(fn, locals, serviceName) {
70
+ const args = [];
71
+ const $inject = annotate(fn, this.strictDi, serviceName);
72
+
73
+ for (let i = 0, { length } = $inject; i < length; i++) {
74
+ const key = $inject[i];
75
+ if (typeof key !== "string") {
76
+ throw $injectorMinErr(
77
+ "itkn",
78
+ "Incorrect injection token! Expected service name as string, got {0}",
79
+ key,
80
+ );
81
+ }
82
+ args.push(
83
+ locals && Object.prototype.hasOwnProperty.call(locals, key)
84
+ ? locals[key]
85
+ : this.get(key),
86
+ );
87
+ }
88
+ return args;
89
+ }
90
+
91
+ /**
92
+ * Invoke a function with optional context and locals.
93
+ *
94
+ * @param {Function|String|Array<any>} fn
95
+ * @param {*} [self]
96
+ * @param {Object} [locals]
97
+ * @param {String} [serviceName]
98
+ * @returns
99
+ */
100
+ invoke(fn, self, locals, serviceName) {
101
+ if (typeof locals === "string") {
102
+ serviceName = locals;
103
+ locals = null;
104
+ }
105
+
106
+ const args = this.injectionArgs(
107
+ /** @type {Function} */ (fn),
108
+ locals,
109
+ serviceName,
110
+ );
111
+ if (Array.isArray(fn)) {
112
+ fn = fn[fn.length - 1];
113
+ }
114
+
115
+ if (isClass(/** @type {String} */ (fn))) {
116
+ args.unshift(null);
117
+ return new (Function.prototype.bind.apply(fn, args))();
118
+ } else {
119
+ return /** @type {Function} */ (fn).apply(self, args);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Instantiate a type constructor with optional locals.
125
+ * @param {Function|Array} type
126
+ * @param {*} [locals]
127
+ * @param {String} [serviceName]
128
+ */
129
+ instantiate(type, locals, serviceName) {
130
+ // Check if type is annotated and use just the given function at n-1 as parameter
131
+ // e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]);
132
+ const ctor = Array.isArray(type) ? type[type.length - 1] : type;
133
+ const args = this.injectionArgs(type, locals, serviceName);
134
+ // Empty object at position 0 is ignored for invocation with `new`, but required.
135
+ args.unshift(null);
136
+ return new (Function.prototype.bind.apply(ctor, args))();
137
+ }
138
+
139
+ /**
140
+ * @abstract
141
+ */
142
+ loadNewModules() {}
143
+
144
+ /**
145
+ * @abstract
146
+ * @param {String} _serviceName
147
+ */
148
+ factory(_serviceName) {
149
+ console.error(`Unhandled ${_serviceName}`);
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Injector for providers
155
+ * @extends AbstractInjector
156
+ */
157
+ export class ProviderInjector extends AbstractInjector {
158
+ /**
159
+ * @param {Object} cache
160
+ * @param {boolean} strictDi - Indicates if strict dependency injection is enforced.
161
+ */
162
+ constructor(cache, strictDi) {
163
+ super(strictDi);
164
+ this.cache = cache;
165
+ }
166
+
167
+ /**
168
+ * Factory method for creating services.
169
+ * @param {String} caller - The name of the caller requesting the service.
170
+ * @throws {Error} If the provider is unknown.
171
+ */
172
+ factory(caller) {
173
+ this.path.push(caller);
174
+ // prevents lookups to providers through get
175
+ throw $injectorMinErr(
176
+ "unpr",
177
+ "Unknown provider: {0}",
178
+ this.path.join(" <- "),
179
+ );
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Injector for factories and services
185
+ * @extends AbstractInjector
186
+ */
187
+ export class InjectorService extends AbstractInjector {
188
+ /**
189
+ *
190
+ * @param {boolean} strictDi - Indicates if strict dependency injection is enforced.
191
+ * @param {ProviderInjector} providerInjector
192
+ */
193
+ constructor(strictDi, providerInjector) {
194
+ super(strictDi);
195
+ this.providerInjector = providerInjector;
196
+ this.modules = this.providerInjector.modules;
197
+ }
198
+
199
+ factory(serviceName) {
200
+ const provider = this.providerInjector.get(serviceName + providerSuffix);
201
+ const res = this.invoke(provider.$get, provider, undefined, serviceName);
202
+ return res;
203
+ }
204
+
205
+ /**
206
+ *
207
+ * @param {String} name
208
+ * @returns {boolean}
209
+ */
210
+ has(name) {
211
+ const hasProvider = Object.prototype.hasOwnProperty.call(
212
+ this.providerInjector.cache,
213
+ name + providerSuffix,
214
+ );
215
+ const hasCache = Object.prototype.hasOwnProperty.call(this.cache, name);
216
+ return hasProvider || hasCache;
217
+ }
218
+ }
219
+
220
+ // Helpers
221
+
222
+ /**
223
+ * @param {String} fn
224
+ * @returns {String}
225
+ */
226
+ function stringifyFn(fn) {
227
+ return Function.prototype.toString.call(fn);
228
+ }
229
+
230
+ /**
231
+ * @param {String} fn
232
+ * @returns {Array<any>}
233
+ */
234
+ function extractArgs(fn) {
235
+ const fnText = stringifyFn(fn).replace(STRIP_COMMENTS, "");
236
+ const args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
237
+ return args;
238
+ }
239
+
240
+ /**
241
+ * @param {String} func
242
+ * @returns {boolean}
243
+ */
244
+ function isClass(func) {
245
+ return /^class\b/.test(stringifyFn(func));
246
+ }
247
+
248
+ /**
249
+ *
250
+ * @param {any} fn
251
+ * @param {boolean} strictDi
252
+ * @param {String} name
253
+ * @returns {Array<string>}
254
+ */
255
+ function annotate(fn, strictDi, name) {
256
+ var $inject, argDecl, last;
257
+
258
+ if (typeof fn === "function") {
259
+ if (!($inject = fn.$inject)) {
260
+ $inject = [];
261
+ if (fn.length) {
262
+ if (strictDi) {
263
+ throw $injectorMinErr(
264
+ "strictdi",
265
+ "{0} is not using explicit annotation and cannot be invoked in strict mode",
266
+ name,
267
+ );
268
+ }
269
+ argDecl = extractArgs(/** @type {String} */ (fn));
270
+ argDecl[1].split(FN_ARG_SPLIT).forEach(function (arg) {
271
+ arg.replace(FN_ARG, function (_all, _underscore, name) {
272
+ $inject.push(name);
273
+ });
274
+ });
275
+ }
276
+ fn.$inject = $inject;
277
+ }
278
+ } else if (Array.isArray(fn)) {
279
+ last = /** @type {Array} */ (fn).length - 1;
280
+ assertArgFn(fn[last], "fn");
281
+ $inject = /** @type {Array} */ (fn).slice(0, last);
282
+ } else {
283
+ assertArgFn(fn, "fn", true);
284
+ }
285
+ return $inject;
286
+ }
@@ -22,6 +22,11 @@ export function $FilterProvider($provide) {
22
22
 
23
23
  this.$get = [
24
24
  "$injector",
25
+ /**
26
+ *
27
+ * @param {import("../../core/di/internal-injector").InjectorService} $injector
28
+ * @returns
29
+ */
25
30
  function ($injector) {
26
31
  return function (name) {
27
32
  return $injector.get(name + suffix);
@@ -15,7 +15,7 @@ import { Parser } from "./parser";
15
15
  */
16
16
 
17
17
  /**
18
- * @typedef {function} CompiledExpressionFunction
18
+ * @typedef {Function} CompiledExpressionFunction
19
19
  * @param {import('../scope/scope').Scope} context - An object against which any expressions embedded in the strings are evaluated against (typically a scope object).
20
20
  * @param {object} [locals] - local variables context object, useful for overriding values in `context`.
21
21
  * @param {any} [assign]
@@ -81,7 +81,6 @@ export function $ParseProvider() {
81
81
  isIdentifierStart: isFunction(identStart) && identStart,
82
82
  isIdentifierContinue: isFunction(identContinue) && identContinue,
83
83
  };
84
- $parse.$$getAst = $$getAst;
85
84
  return $parse;
86
85
 
87
86
  function $parse(exp, interceptorFn) {
@@ -111,16 +110,6 @@ export function $ParseProvider() {
111
110
  }
112
111
  }
113
112
 
114
- /**
115
- * @param {string} exp
116
- * @returns {import("./ast").ASTNode}
117
- */
118
- function $$getAst(exp) {
119
- var lexer = new Lexer($lexerOptions);
120
- var parser = new Parser(lexer, $filter);
121
- return parser.getAst(exp).ast;
122
- }
123
-
124
113
  function addInterceptor(parsedExpression, interceptorFn) {
125
114
  if (!interceptorFn) return parsedExpression;
126
115