@angular-wave/angular.ts 0.0.65 → 0.0.66

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
@@ -2,7 +2,7 @@
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "description": "A modern, optimized and typesafe version of AngularJS",
4
4
  "license": "MIT",
5
- "version": "0.0.65",
5
+ "version": "0.0.66",
6
6
  "type": "module",
7
7
  "main": "dist/angular-ts.esm.js",
8
8
  "browser": "dist/angular-ts.umd.js",
@@ -13,6 +13,12 @@ export function $$AnimateJsProvider($animateProvider) {
13
13
  this.$get = [
14
14
  "$injector",
15
15
  "$$AnimateRunner",
16
+ /**
17
+ *
18
+ * @param {import("../core/di/internal-injector").InjectorService} $injector
19
+ * @param {*} $$AnimateRunner
20
+ * @returns
21
+ */
16
22
  function ($injector, $$AnimateRunner) {
17
23
  const applyAnimationClasses = applyAnimationClassesFactory();
18
24
  // $animateJs(element, 'enter');
@@ -38,7 +38,7 @@ export function $$AnimationProvider() {
38
38
  /**
39
39
  *
40
40
  * @param {*} $rootScope
41
- * @param {*} $injector
41
+ * @param {import("../core/di/internal-injector").InjectorService} $injector
42
42
  * @param {*} $$AnimateRunner
43
43
  * @param {import("./raf-scheduler").RafScheduler} $$rAFScheduler
44
44
  * @param {*} $$animateCache
@@ -233,7 +233,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
233
233
  "$exceptionHandler",
234
234
  /**
235
235
  *
236
- * @param {*} $injector
236
+ * @param {import("../../core/di/internal-injector").InjectorService} $injector
237
237
  * @param {import('../exception-handler').ErrorHandler} $exceptionHandler
238
238
  * @returns
239
239
  */
@@ -619,6 +619,18 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
619
619
  "$rootScope",
620
620
  "$sce",
621
621
  "$animate",
622
+ /**
623
+ * @param {import("../../core/di/internal-injector").InjectorService} $injector
624
+ * @param {*} $interpolate
625
+ * @param {*} $exceptionHandler
626
+ * @param {*} $templateRequest
627
+ * @param {*} $parse
628
+ * @param {*} $controller
629
+ * @param {*} $rootScope
630
+ * @param {*} $sce
631
+ * @param {*} $animate
632
+ * @returns
633
+ */
622
634
  function (
623
635
  $injector,
624
636
  $interpolate,
@@ -63,6 +63,11 @@ export function $ControllerProvider() {
63
63
 
64
64
  this.$get = [
65
65
  "$injector",
66
+ /**
67
+ *
68
+ * @param {import("../../core/di/internal-injector").InjectorService} $injector
69
+ * @returns
70
+ */
66
71
  function ($injector) {
67
72
  /**
68
73
  * @ngdoc service
@@ -1,95 +1,36 @@
1
1
  import {
2
2
  assertArgFn,
3
3
  minErr,
4
- forEach,
5
4
  isFunction,
6
5
  isString,
7
- isBoolean,
8
6
  isUndefined,
9
7
  assertArg,
10
- valueFn,
11
8
  assertNotHasOwnProperty,
12
9
  isObject,
13
10
  assert,
14
11
  } from "../../shared/utils";
12
+ import { INJECTOR_LITERAL } from "./ng-module";
13
+ import { ProviderInjector, InjectorService } from "./internal-injector";
15
14
 
16
15
  const ARROW_ARG = /^([^(]+?)=>/;
17
16
  const FN_ARGS = /^[^(]*\(\s*([^)]*)\)/m;
18
17
  const FN_ARG_SPLIT = /,/;
19
18
  const FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
20
19
  const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
21
- const $injectorMinErr = minErr("$injector");
22
-
23
- function stringifyFn(fn) {
24
- return Function.prototype.toString.call(fn);
25
- }
26
-
27
- function extractArgs(fn) {
28
- var fnText = stringifyFn(fn).replace(STRIP_COMMENTS, ""),
29
- args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
30
- return args;
31
- }
32
-
33
- function anonFn(fn) {
34
- // For anonymous functions, showing at the very least the function signature can help in
35
- // debugging.
36
- var args = extractArgs(fn);
37
- if (args) {
38
- return "function(" + (args[1] || "").replace(/[\s\r\n]+/, " ") + ")";
39
- }
40
- return "fn";
41
- }
42
-
43
- function annotate(fn, strictDi, name) {
44
- var $inject, argDecl, last;
45
-
46
- if (typeof fn === "function") {
47
- if (!($inject = fn.$inject)) {
48
- $inject = [];
49
- if (fn.length) {
50
- if (strictDi) {
51
- if (!isString(name) || !name) {
52
- name = fn.name || anonFn(fn);
53
- }
54
- throw $injectorMinErr(
55
- "strictdi",
56
- "{0} is not using explicit annotation and cannot be invoked in strict mode",
57
- name,
58
- );
59
- }
60
- argDecl = extractArgs(fn);
61
- forEach(argDecl[1].split(FN_ARG_SPLIT), function (arg) {
62
- arg.replace(FN_ARG, function (all, underscore, name) {
63
- $inject.push(name);
64
- });
65
- });
66
- }
67
- fn.$inject = $inject;
68
- }
69
- } else if (Array.isArray(fn)) {
70
- last = fn.length - 1;
71
- assertArgFn(fn[last], "fn");
72
- $inject = fn.slice(0, last);
73
- } else {
74
- assertArgFn(fn, "fn", true);
75
- }
76
- return $inject;
77
- }
20
+ const $injectorMinErr = minErr(INJECTOR_LITERAL);
78
21
 
79
22
  const providerSuffix = "Provider";
80
- const INSTANTIATING = {};
23
+ /** @type {String[]} Used only for error reporting of circular dependencies*/
24
+ export const path = [];
81
25
 
82
26
  /**
83
27
  *
84
28
  * @param {Array<String|Function>} modulesToLoad
85
29
  * @param {boolean} [strictDi]
86
- * @returns {import("../../types").InjectorService}
30
+ * @returns {InjectorService}
87
31
  */
88
32
  export function createInjector(modulesToLoad, strictDi = false) {
89
33
  assert(Array.isArray(modulesToLoad), "modules required");
90
- assert(isBoolean(strictDi));
91
- /** @type {Array<string>} */
92
- const path = [];
93
34
 
94
35
  /** @type {Map<String|Function, boolean>} */
95
36
  const loadedModules = new Map(); // Keep track of loaded modules to avoid circular dependencies
@@ -105,42 +46,26 @@ export function createInjector(modulesToLoad, strictDi = false) {
105
46
  },
106
47
  };
107
48
 
108
- providerCache.$injector = createInternalInjector(
49
+ const providerInjector = (providerCache.$injector = new ProviderInjector(
109
50
  providerCache,
110
- function (caller) {
111
- if (isString(caller)) {
112
- path.push(caller);
113
- }
114
- throw $injectorMinErr("unpr", "Unknown provider: {0}", path.join(" <- "));
115
- },
116
- );
51
+ strictDi,
52
+ ));
117
53
 
118
54
  const instanceCache = {};
119
-
120
- let protoInstanceInjector = createInternalInjector(
55
+ const protoInstanceInjector = new InjectorService(
121
56
  instanceCache,
122
- (serviceName, caller) => {
123
- const provider = providerCache.$injector.get(
124
- serviceName + providerSuffix,
125
- caller,
126
- );
127
- return instanceInjector.invoke(
128
- provider.$get,
129
- provider,
130
- undefined,
131
- serviceName,
132
- );
133
- },
57
+ strictDi,
58
+ providerInjector,
134
59
  );
135
60
 
136
- providerCache["$injector" + providerSuffix] = {
137
- $get: valueFn(protoInstanceInjector),
61
+ providerCache.$injectorProvider = {
62
+ // $injectionProvider return instance injector
63
+ $get: () => protoInstanceInjector,
138
64
  };
139
65
  let instanceInjector = protoInstanceInjector;
140
- instanceInjector.modules = providerCache.$injector.modules =
141
- Object.create(null);
66
+ instanceInjector.modules = providerInjector.modules = {};
142
67
  const runBlocks = loadModules(modulesToLoad);
143
- instanceInjector = protoInstanceInjector.get("$injector");
68
+ instanceInjector = protoInstanceInjector.get(INJECTOR_LITERAL);
144
69
  instanceInjector.strictDi = strictDi;
145
70
  runBlocks.forEach((fn) => {
146
71
  if (fn) instanceInjector.invoke(fn);
@@ -158,64 +83,61 @@ export function createInjector(modulesToLoad, strictDi = false) {
158
83
  // $provider
159
84
  ////////////////////////////////////
160
85
 
161
- function supportObject(delegate) {
162
- return function (key, value) {
163
- if (isObject(key)) {
164
- Object.entries(key).forEach(([k, v]) => {
165
- delegate(k, v);
166
- });
167
- } else {
168
- return delegate(key, value);
169
- }
170
- };
171
- }
172
-
86
+ /**
87
+ *
88
+ * @param {string} name
89
+ * @param {import('../../types').ServiceProvider} provider
90
+ * @returns
91
+ */
173
92
  function provider(name, provider) {
174
93
  assertNotHasOwnProperty(name, "service");
94
+ let newProvider;
175
95
  if (isFunction(provider) || Array.isArray(provider)) {
176
- provider = providerCache.$injector.instantiate(provider);
96
+ newProvider = providerInjector.instantiate(provider);
97
+ } else {
98
+ newProvider = provider;
177
99
  }
178
- if (!provider.$get) {
100
+ if (!newProvider.$get) {
179
101
  throw $injectorMinErr(
180
102
  "pget",
181
103
  "Provider '{0}' must define $get factory method.",
182
104
  name,
183
105
  );
184
106
  }
185
- return (providerCache[name + providerSuffix] = provider);
107
+ providerCache[name + providerSuffix] = newProvider;
108
+ return newProvider;
186
109
  }
187
110
 
188
- function enforceReturnValue(name, factory) {
189
- return function enforcedReturnValue() {
190
- const result = instanceInjector.invoke(factory, this);
191
- if (isUndefined(result)) {
192
- throw $injectorMinErr(
193
- "undef",
194
- "Provider '{0}' must return a value from $get factory method.",
195
- name,
196
- );
197
- }
198
- return result;
199
- };
200
- }
201
-
202
- function factory(name, factoryFn, enforce) {
111
+ function factory(name, factoryFn) {
203
112
  return provider(name, {
204
- $get: enforce !== false ? enforceReturnValue(name, factoryFn) : factoryFn,
113
+ $get: () => {
114
+ const result = instanceInjector.invoke(factoryFn, this);
115
+ if (isUndefined(result)) {
116
+ throw $injectorMinErr(
117
+ "undef",
118
+ "Provider '{0}' must return a value from $get factory method.",
119
+ name,
120
+ );
121
+ }
122
+ return result;
123
+ },
205
124
  });
206
125
  }
207
126
 
208
127
  function service(name, constructor) {
209
128
  return factory(name, [
210
- "$injector",
211
- function ($injector) {
212
- return $injector.instantiate(constructor);
213
- },
129
+ INJECTOR_LITERAL,
130
+ ($injector) => $injector.instantiate(constructor),
214
131
  ]);
215
132
  }
216
133
 
134
+ /**
135
+ * @param {String} name
136
+ * @param {any} val
137
+ * @returns {import('../../types').ServiceProvider}
138
+ */
217
139
  function value(name, val) {
218
- return factory(name, valueFn(val), false);
140
+ return (providerCache[name + providerSuffix] = { $get: () => val });
219
141
  }
220
142
 
221
143
  function constant(name, value) {
@@ -225,22 +147,17 @@ export function createInjector(modulesToLoad, strictDi = false) {
225
147
  }
226
148
 
227
149
  function decorator(serviceName, decorFn) {
228
- const origProvider = providerCache.$injector.get(
229
- serviceName + providerSuffix,
230
- );
231
- const orig$get = origProvider.$get;
150
+ const origProvider = providerInjector.get(serviceName + providerSuffix);
151
+ const origGet = origProvider.$get;
232
152
 
233
153
  origProvider.$get = function () {
234
- const origInstance = instanceInjector.invoke(orig$get, origProvider);
154
+ const origInstance = instanceInjector.invoke(origGet, origProvider);
235
155
  return instanceInjector.invoke(decorFn, null, {
236
156
  $delegate: origInstance,
237
157
  });
238
158
  };
239
159
  }
240
160
 
241
- ////////////////////////////////////
242
- // Module Loading
243
- ////////////////////////////////////
244
161
  /**
245
162
  *
246
163
  * @param {Array<String|Function>} modulesToLoad
@@ -258,31 +175,26 @@ export function createInjector(modulesToLoad, strictDi = false) {
258
175
  if (loadedModules.get(module)) return;
259
176
  loadedModules.set(module, true);
260
177
 
261
- /**
262
- *
263
- * @param {Array<Array<any>>} queue
264
- */
265
- function runInvokeQueue(queue) {
266
- queue.forEach((invokeArgs) => {
267
- const provider = providerCache.$injector.get(invokeArgs[0]);
268
- provider[invokeArgs[1]].apply(provider, invokeArgs[2]);
269
- });
270
- }
271
-
272
178
  try {
273
179
  if (isString(module)) {
274
180
  /** @type {import('./ng-module').NgModule} */
275
181
  let moduleFn = window["angular"].module(module);
276
- instanceInjector.modules[module] = moduleFn;
182
+ instanceInjector.modules[/** @type {string } */ (module)] = moduleFn;
277
183
  runBlocks = runBlocks
278
184
  .concat(loadModules(moduleFn.requires))
279
185
  .concat(moduleFn.runBlocks);
280
- runInvokeQueue(moduleFn.invokeQueue);
281
- runInvokeQueue(moduleFn.configBlocks);
186
+
187
+ const invokeQueue = moduleFn.invokeQueue.concat(
188
+ moduleFn.configBlocks,
189
+ );
190
+ invokeQueue.forEach((invokeArgs) => {
191
+ const provider = providerInjector.get(invokeArgs[0]);
192
+ provider[invokeArgs[1]].apply(provider, invokeArgs[2]);
193
+ });
282
194
  } else if (isFunction(module)) {
283
- runBlocks.push(providerCache.$injector.invoke(module));
195
+ runBlocks.push(providerInjector.invoke(module));
284
196
  } else if (Array.isArray(module)) {
285
- runBlocks.push(providerCache.$injector.invoke(module));
197
+ runBlocks.push(providerInjector.invoke(module));
286
198
  } else {
287
199
  assertArgFn(module, "module");
288
200
  }
@@ -308,115 +220,80 @@ export function createInjector(modulesToLoad, strictDi = false) {
308
220
  });
309
221
  return runBlocks;
310
222
  }
223
+ }
311
224
 
312
- ////////////////////////////////////
313
- // internal Injector
314
- ////////////////////////////////////
225
+ // Helpers
315
226
 
316
- function createInternalInjector(cache, factory) {
317
- function get(serviceName, caller) {
318
- if (Object.prototype.hasOwnProperty.call(cache, serviceName)) {
319
- if (cache[serviceName] === INSTANTIATING) {
320
- throw $injectorMinErr(
321
- "cdep",
322
- "Circular dependency found: {0}",
323
- `${serviceName} <- ${path.join(" <- ")}`,
324
- );
325
- }
326
- return cache[serviceName];
327
- }
328
- try {
329
- path.unshift(serviceName);
330
- cache[serviceName] = INSTANTIATING;
331
- cache[serviceName] = factory(serviceName, caller);
332
- return cache[serviceName];
333
- } catch (err) {
334
- if (cache[serviceName] === INSTANTIATING) {
335
- delete cache[serviceName];
336
- }
337
- throw err;
338
- } finally {
339
- path.shift();
340
- }
341
- }
227
+ /**
228
+ * @param {String} fn
229
+ * @returns {String}
230
+ */
231
+ function stringifyFn(fn) {
232
+ return Function.prototype.toString.call(fn);
233
+ }
342
234
 
343
- function injectionArgs(fn, locals, serviceName) {
344
- const args = [];
345
- const $inject = annotate(fn, strictDi, serviceName);
235
+ /**
236
+ * @param {String} fn
237
+ * @returns {Array<any>}
238
+ */
239
+ function extractArgs(fn) {
240
+ const fnText = stringifyFn(fn).replace(STRIP_COMMENTS, "");
241
+ const args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
242
+ return args;
243
+ }
244
+
245
+ /**
246
+ *
247
+ * @param {any} fn
248
+ * @param {boolean} [strictDi]
249
+ * @param {String} [name]
250
+ * @returns {Array<string>}
251
+ */
252
+ export function annotate(fn, strictDi, name) {
253
+ var $inject, argDecl, last;
346
254
 
347
- for (let i = 0, { length } = $inject; i < length; i++) {
348
- const key = $inject[i];
349
- if (typeof key !== "string") {
255
+ if (typeof fn === "function") {
256
+ if (!($inject = fn.$inject)) {
257
+ $inject = [];
258
+ if (fn.length) {
259
+ if (strictDi) {
350
260
  throw $injectorMinErr(
351
- "itkn",
352
- "Incorrect injection token! Expected service name as string, got {0}",
353
- key,
261
+ "strictdi",
262
+ "{0} is not using explicit annotation and cannot be invoked in strict mode",
263
+ name,
354
264
  );
355
265
  }
356
- args.push(
357
- locals && Object.prototype.hasOwnProperty.call(locals, key)
358
- ? locals[key]
359
- : get(key, serviceName),
360
- );
361
- }
362
- return args;
363
- }
364
-
365
- function isClass(func) {
366
- let result = func.$$ngIsClass;
367
- if (!isBoolean(result)) {
368
- result = func.$$ngIsClass = /^class\b/.test(stringifyFn(func));
369
- }
370
- return result;
371
- }
372
-
373
- function invoke(fn, self, locals, serviceName) {
374
- if (typeof locals === "string") {
375
- serviceName = locals;
376
- locals = null;
377
- }
378
-
379
- const args = injectionArgs(fn, locals, serviceName);
380
- if (Array.isArray(fn)) {
381
- fn = fn[fn.length - 1];
382
- }
383
-
384
- if (!isClass(fn)) {
385
- // http://jsperf.com/angularjs-invoke-apply-vs-switch
386
- // #5388
387
- return fn.apply(self, args);
266
+ argDecl = extractArgs(/** @type {String} */ (fn));
267
+ argDecl[1].split(FN_ARG_SPLIT).forEach(function (arg) {
268
+ arg.replace(FN_ARG, function (all, underscore, name) {
269
+ $inject.push(name);
270
+ });
271
+ });
388
272
  }
389
- args.unshift(null);
390
- return new (Function.prototype.bind.apply(fn, args))();
391
- }
392
-
393
- function instantiate(Type, locals, serviceName) {
394
- // Check if Type is annotated and use just the given function at n-1 as parameter
395
- // e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]);
396
- const ctor = Array.isArray(Type) ? Type[Type.length - 1] : Type;
397
- const args = injectionArgs(Type, locals, serviceName);
398
- // Empty object at position 0 is ignored for invocation with `new`, but required.
399
- args.unshift(null);
400
- return new (Function.prototype.bind.apply(ctor, args))();
401
- }
402
-
403
- function has(name) {
404
- const hasProvider = Object.prototype.hasOwnProperty.call(
405
- providerCache,
406
- name + providerSuffix,
407
- );
408
- const hasCache = Object.prototype.hasOwnProperty.call(cache, name);
409
- return hasProvider || hasCache;
273
+ fn.$inject = $inject;
410
274
  }
411
-
412
- return {
413
- invoke,
414
- instantiate,
415
- get,
416
- annotate,
417
- has,
418
- };
275
+ } else if (Array.isArray(fn)) {
276
+ last = /** @type {Array} */ (fn).length - 1;
277
+ assertArgFn(fn[last], "fn");
278
+ $inject = /** @type {Array} */ (fn).slice(0, last);
279
+ } else {
280
+ assertArgFn(fn, "fn", true);
419
281
  }
282
+ return $inject;
420
283
  }
421
284
 
422
- createInjector.$$annotate = annotate;
285
+ /**
286
+ * @param {function(string, any):any} delegate
287
+ * @returns
288
+ */
289
+ function supportObject(delegate) {
290
+ return function (key, value) {
291
+ if (isObject(key)) {
292
+ Object.entries(key).forEach(([k, v]) => {
293
+ delegate(k, v);
294
+ });
295
+ } else {
296
+ return delegate(key, value);
297
+ }
298
+ };
299
+ }
@@ -250,7 +250,7 @@
250
250
  - }
251
251
  -
252
252
  - // Then
253
- - expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
253
+ - expect(annotate(MyController)).toEqual(['$scope', '$route']);
254
254
  - ```
255
255
 
256
256
  ```
@@ -277,7 +277,7 @@
277
277
  - MyController['$inject'] = ['$scope', '$route'];
278
278
  -
279
279
  - // Then
280
- - expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
280
+ - expect(annotate(MyController)).toEqual(['$scope', '$route']);
281
281
  - ```
282
282
 
283
283
  ```
@@ -311,7 +311,7 @@
311
311
  - }]);
312
312
  -
313
313
  - // Therefore
314
- - expect(injector.annotate(
314
+ - expect(annotate(
315
315
  - ['$compile', '$rootScope', function(obfus_$compile, obfus_$rootScope) {}])
316
316
  - ).toEqual(['$compile', '$rootScope']);
317
317
  - ```