@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/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +1 -1
- package/src/animations/animate-js.js +6 -0
- package/src/animations/animation.js +1 -1
- package/src/core/compile/compile.js +13 -1
- package/src/core/controller/controller.js +5 -0
- package/src/core/di/injector.js +129 -252
- package/src/core/di/injector.md +3 -3
- package/src/core/di/injector.spec.js +30 -24
- package/src/core/di/internal-injector.js +233 -0
- package/src/core/filter/filter.js +5 -0
- package/src/core/sce/sce.js +6 -1
- package/src/loader.js +1 -1
- package/src/router/services.js +9 -4
- package/src/router/state/state-builder.js +4 -3
- package/src/router/state/state-registry.js +5 -0
- package/src/router/state/views.js +2 -1
- package/src/router/template-factory.js +5 -4
- package/src/services/http/http.js +12 -0
- package/src/types.js +9 -11
- package/types/animations/animate-js.d.ts +1 -1
- package/types/animations/animation.d.ts +1 -1
- package/types/core/compile/compile.d.ts +1 -1
- package/types/core/controller/controller.d.ts +1 -1
- package/types/core/di/injector.d.ts +13 -7
- package/types/core/di/internal-injector.d.ts +36 -0
- package/types/core/filter/filter.d.ts +1 -1
- package/types/core/sce/sce.d.ts +1 -1
- package/types/router/services.d.ts +8 -1
- package/types/router/state/state-registry.d.ts +2 -2
- package/types/router/template-factory.d.ts +2 -2
- package/types/services/http/http.d.ts +1 -1
- package/types/types.d.ts +7 -32
|
@@ -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([])
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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,233 @@
|
|
|
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 = "INSTANTIATING";
|
|
13
|
+
|
|
14
|
+
export class ProviderInjector {
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} cache
|
|
18
|
+
* @param {boolean} strictDi
|
|
19
|
+
*/
|
|
20
|
+
constructor(cache, strictDi) {
|
|
21
|
+
this.cache = cache;
|
|
22
|
+
this.strictDi = strictDi;
|
|
23
|
+
this.path = [];
|
|
24
|
+
this.providerCache = cache;
|
|
25
|
+
this.modules = undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
factory(caller) {
|
|
29
|
+
this.path.push(caller);
|
|
30
|
+
// prevents lookups to providers through get
|
|
31
|
+
throw $injectorMinErr(
|
|
32
|
+
"unpr",
|
|
33
|
+
"Unknown provider: {0}",
|
|
34
|
+
this.path.join(" <- "),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {String} serviceName
|
|
41
|
+
* @returns {any}
|
|
42
|
+
*/
|
|
43
|
+
get(serviceName) {
|
|
44
|
+
if (Object.prototype.hasOwnProperty.call(this.cache, serviceName)) {
|
|
45
|
+
if (this.cache[serviceName] === INSTANTIATING) {
|
|
46
|
+
throw $injectorMinErr(
|
|
47
|
+
"cdep",
|
|
48
|
+
"Circular dependency found: {0}",
|
|
49
|
+
`${serviceName} <- ${this.path.join(" <- ")}`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return this.cache[serviceName];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.path.unshift(serviceName);
|
|
56
|
+
this.cache[serviceName] = INSTANTIATING;
|
|
57
|
+
try {
|
|
58
|
+
// this goes to line 60
|
|
59
|
+
this.cache[serviceName] = this.factory(serviceName);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
// this is for the error handling being thrown by the providerCache multiple times
|
|
62
|
+
delete this.cache[serviceName];
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
return this.cache[serviceName];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
injectionArgs(fn, locals, serviceName) {
|
|
69
|
+
const args = [];
|
|
70
|
+
const $inject = annotate(fn, this.strictDi, serviceName);
|
|
71
|
+
|
|
72
|
+
for (let i = 0, { length } = $inject; i < length; i++) {
|
|
73
|
+
const key = $inject[i];
|
|
74
|
+
if (typeof key !== "string") {
|
|
75
|
+
throw $injectorMinErr(
|
|
76
|
+
"itkn",
|
|
77
|
+
"Incorrect injection token! Expected service name as string, got {0}",
|
|
78
|
+
key,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
args.push(
|
|
82
|
+
locals && Object.prototype.hasOwnProperty.call(locals, key)
|
|
83
|
+
? locals[key]
|
|
84
|
+
: this.get(key),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return args;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
invoke(fn, self, locals, serviceName) {
|
|
91
|
+
if (typeof locals === "string") {
|
|
92
|
+
serviceName = locals;
|
|
93
|
+
locals = null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const args = this.injectionArgs(fn, locals, serviceName);
|
|
97
|
+
if (Array.isArray(fn)) {
|
|
98
|
+
fn = fn[fn.length - 1];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (isClass(fn)) {
|
|
102
|
+
args.unshift(null);
|
|
103
|
+
return new (Function.prototype.bind.apply(fn, args))();
|
|
104
|
+
} else {
|
|
105
|
+
return fn.apply(self, args);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
instantiate(Type, locals, serviceName) {
|
|
110
|
+
// Check if Type is annotated and use just the given function at n-1 as parameter
|
|
111
|
+
// e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]);
|
|
112
|
+
const ctor = Array.isArray(Type) ? Type[Type.length - 1] : Type;
|
|
113
|
+
const args = this.injectionArgs(Type, locals, serviceName);
|
|
114
|
+
// Empty object at position 0 is ignored for invocation with `new`, but required.
|
|
115
|
+
args.unshift(null);
|
|
116
|
+
return new (Function.prototype.bind.apply(ctor, args))();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @param {String} name
|
|
122
|
+
* @returns {boolean}
|
|
123
|
+
*/
|
|
124
|
+
has(name) {
|
|
125
|
+
const hasProvider = Object.prototype.hasOwnProperty.call(
|
|
126
|
+
this.providerCache,
|
|
127
|
+
name + providerSuffix,
|
|
128
|
+
);
|
|
129
|
+
const hasCache = Object.prototype.hasOwnProperty.call(this.cache, name);
|
|
130
|
+
return hasProvider || hasCache;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// /**
|
|
135
|
+
// * @typedef {Object} LegacyInjectorService
|
|
136
|
+
// * @property {function(Function, boolean=): string[]} annotate - Annotate a function or an array of inline annotations.
|
|
137
|
+
// * @property {function(string, string=): any} get - Get a service by name.
|
|
138
|
+
// * @property {function(Function, any?): any} instantiate - Instantiate a type constructor with optional locals.
|
|
139
|
+
// * @property {function(import("../../types").Injectable<Function | ((...args: any[]) => any)>, any=, any=): any} invoke - Invoke a function with optional context and locals.
|
|
140
|
+
// * @property {function(Array<import("../../types").Module | string | import("../../types").Injectable<(...args: any[]) => void>>): void} [loadNewModules] - Add and load new modules to the injector.
|
|
141
|
+
// * @property {Object.<string, import("../../types").Module>} [modules] - A map of all the modules loaded into the injector.
|
|
142
|
+
// * @property {boolean} [strictDi] - Indicates if strict dependency injection is enforced.
|
|
143
|
+
// */
|
|
144
|
+
|
|
145
|
+
export class InjectorService extends ProviderInjector {
|
|
146
|
+
constructor(cache, strictDi, providerInjector) {
|
|
147
|
+
super(cache, strictDi);
|
|
148
|
+
this.strictDi = strictDi;
|
|
149
|
+
this.providerInjector = providerInjector;
|
|
150
|
+
this.providerCache = providerInjector.cache;
|
|
151
|
+
this.modules = undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
factory(serviceName, caller) {
|
|
155
|
+
const provider = this.providerInjector.get(
|
|
156
|
+
serviceName + providerSuffix,
|
|
157
|
+
caller,
|
|
158
|
+
);
|
|
159
|
+
const res = this.invoke(provider.$get, provider, undefined, serviceName);
|
|
160
|
+
return res;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Gets overridden
|
|
164
|
+
loadNewModules() {}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Helpers
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @param {String} fn
|
|
171
|
+
* @returns {String}
|
|
172
|
+
*/
|
|
173
|
+
function stringifyFn(fn) {
|
|
174
|
+
return Function.prototype.toString.call(fn);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @param {String} fn
|
|
179
|
+
* @returns {Array<any>}
|
|
180
|
+
*/
|
|
181
|
+
function extractArgs(fn) {
|
|
182
|
+
const fnText = stringifyFn(fn).replace(STRIP_COMMENTS, "");
|
|
183
|
+
const args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
|
|
184
|
+
return args;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {String} func
|
|
189
|
+
* @returns {boolean}
|
|
190
|
+
*/
|
|
191
|
+
function isClass(func) {
|
|
192
|
+
return /^class\b/.test(stringifyFn(func));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @param {any} fn
|
|
198
|
+
* @param {boolean} strictDi
|
|
199
|
+
* @param {String} name
|
|
200
|
+
* @returns {Array<string>}
|
|
201
|
+
*/
|
|
202
|
+
function annotate(fn, strictDi, name) {
|
|
203
|
+
var $inject, argDecl, last;
|
|
204
|
+
|
|
205
|
+
if (typeof fn === "function") {
|
|
206
|
+
if (!($inject = fn.$inject)) {
|
|
207
|
+
$inject = [];
|
|
208
|
+
if (fn.length) {
|
|
209
|
+
if (strictDi) {
|
|
210
|
+
throw $injectorMinErr(
|
|
211
|
+
"strictdi",
|
|
212
|
+
"{0} is not using explicit annotation and cannot be invoked in strict mode",
|
|
213
|
+
name,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
argDecl = extractArgs(/** @type {String} */ (fn));
|
|
217
|
+
argDecl[1].split(FN_ARG_SPLIT).forEach(function (arg) {
|
|
218
|
+
arg.replace(FN_ARG, function (all, underscore, name) {
|
|
219
|
+
$inject.push(name);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
fn.$inject = $inject;
|
|
224
|
+
}
|
|
225
|
+
} else if (Array.isArray(fn)) {
|
|
226
|
+
last = /** @type {Array} */ (fn).length - 1;
|
|
227
|
+
assertArgFn(fn[last], "fn");
|
|
228
|
+
$inject = /** @type {Array} */ (fn).slice(0, last);
|
|
229
|
+
} else {
|
|
230
|
+
assertArgFn(fn, "fn", true);
|
|
231
|
+
}
|
|
232
|
+
return $inject;
|
|
233
|
+
}
|
|
@@ -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);
|
package/src/core/sce/sce.js
CHANGED
|
@@ -248,7 +248,12 @@ export function $SceDelegateProvider() {
|
|
|
248
248
|
this.$get = [
|
|
249
249
|
"$injector",
|
|
250
250
|
"$$sanitizeUri",
|
|
251
|
-
|
|
251
|
+
/**
|
|
252
|
+
*
|
|
253
|
+
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
254
|
+
* @param {*} $$sanitizeUri
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
252
257
|
function ($injector, $$sanitizeUri) {
|
|
253
258
|
let htmlSanitizer = function () {
|
|
254
259
|
throw $sceMinErr(
|
package/src/loader.js
CHANGED
|
@@ -144,7 +144,7 @@ export class Angular {
|
|
|
144
144
|
* @param {*} scope
|
|
145
145
|
* @param {JQLite} el
|
|
146
146
|
* @param {*} compile
|
|
147
|
-
* @param {
|
|
147
|
+
* @param {import("./core/di/internal-injector").InjectorService} $injector
|
|
148
148
|
*/
|
|
149
149
|
function (scope, el, compile, $injector) {
|
|
150
150
|
scope.$apply(() => {
|
package/src/router/services.js
CHANGED
|
@@ -10,8 +10,16 @@
|
|
|
10
10
|
import { services } from "./common/coreservices";
|
|
11
11
|
import { unnestR } from "../shared/common";
|
|
12
12
|
import { trace } from "./common/trace";
|
|
13
|
+
import { annotate } from "../core/di/injector";
|
|
13
14
|
|
|
14
15
|
runBlock.$inject = ["$injector", "$q", "$stateRegistry", "$urlService"];
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {import("../core/di/internal-injector").InjectorService} $injector
|
|
19
|
+
* @param {*} $q
|
|
20
|
+
* @param {*} $stateRegistry
|
|
21
|
+
* @param {*} $urlService
|
|
22
|
+
*/
|
|
15
23
|
export function runBlock($injector, $q, $stateRegistry, $urlService) {
|
|
16
24
|
services.$injector = $injector;
|
|
17
25
|
services.$q = $q;
|
|
@@ -32,10 +40,7 @@ export function runBlock($injector, $q, $stateRegistry, $urlService) {
|
|
|
32
40
|
.filter((x) => x.deps === "deferred")
|
|
33
41
|
.forEach(
|
|
34
42
|
(resolvable) =>
|
|
35
|
-
(resolvable.deps = $injector.
|
|
36
|
-
resolvable.resolveFn,
|
|
37
|
-
$injector.strictDi,
|
|
38
|
-
)),
|
|
43
|
+
(resolvable.deps = annotate(resolvable.resolveFn, $injector.strictDi)),
|
|
39
44
|
);
|
|
40
45
|
// Start listening for url changes
|
|
41
46
|
$urlService.listen();
|
|
@@ -11,6 +11,7 @@ import { stringify } from "../../shared/strings";
|
|
|
11
11
|
import { is, pattern, pipe, prop, val } from "../../shared/hof";
|
|
12
12
|
import { Resolvable } from "../resolve/resolvable";
|
|
13
13
|
import { services } from "../common/coreservices";
|
|
14
|
+
import { annotate } from "../../core/di/injector";
|
|
14
15
|
const parseUrl = (url) => {
|
|
15
16
|
if (!isString(url)) return false;
|
|
16
17
|
const root = url.charAt(0) === "^";
|
|
@@ -145,14 +146,14 @@ export function resolvablesBuilder(state) {
|
|
|
145
146
|
policy: resolvePolicies[token],
|
|
146
147
|
}));
|
|
147
148
|
/** fetch DI annotations from a function or ng1-style array */
|
|
148
|
-
const
|
|
149
|
+
const annotateFn = (fn) => {
|
|
149
150
|
const $injector = services.$injector;
|
|
150
151
|
// ng1 doesn't have an $injector until runtime.
|
|
151
152
|
// If the $injector doesn't exist, use "deferred" literal as a
|
|
152
153
|
// marker indicating they should be annotated when runtime starts
|
|
153
154
|
return (
|
|
154
155
|
fn["$inject"] ||
|
|
155
|
-
($injector &&
|
|
156
|
+
($injector && annotate(fn, $injector.strictDi)) ||
|
|
156
157
|
"deferred"
|
|
157
158
|
);
|
|
158
159
|
};
|
|
@@ -207,7 +208,7 @@ export function resolvablesBuilder(state) {
|
|
|
207
208
|
const tuple2Resolvable = pattern([
|
|
208
209
|
[pipe(prop('val'), isString), (tuple) => new Resolvable(tuple.token, ((x) => x), [tuple.val], tuple.policy)],
|
|
209
210
|
[pipe(prop('val'), Array.isArray), (tuple) => new Resolvable(tuple.token, tail(tuple.val), tuple.val.slice(0, -1), tuple.policy)],
|
|
210
|
-
[pipe(prop('val'), isFunction), (tuple) => new Resolvable(tuple.token, tuple.val,
|
|
211
|
+
[pipe(prop('val'), isFunction), (tuple) => new Resolvable(tuple.token, tuple.val, annotateFn(tuple.val), tuple.policy)],
|
|
211
212
|
]);
|
|
212
213
|
// prettier-ignore
|
|
213
214
|
const item2Resolvable = pattern([
|
|
@@ -50,6 +50,11 @@ export class StateRegistry {
|
|
|
50
50
|
|
|
51
51
|
$get = [
|
|
52
52
|
"$injector",
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
53
58
|
($injector) => {
|
|
54
59
|
this.$injector = $injector;
|
|
55
60
|
this.builder.$injector = $injector;
|
|
@@ -5,6 +5,7 @@ import { services } from "../common/coreservices";
|
|
|
5
5
|
import { trace } from "../common/trace";
|
|
6
6
|
import { ResolveContext } from "../resolve/resolve-context";
|
|
7
7
|
import { Resolvable } from "../resolve/resolvable";
|
|
8
|
+
import { annotate } from "../../core/di/injector";
|
|
8
9
|
|
|
9
10
|
export function getNg1ViewConfigFactory() {
|
|
10
11
|
let templateFactory = null;
|
|
@@ -141,7 +142,7 @@ export class Ng1ViewConfig {
|
|
|
141
142
|
getController(context) {
|
|
142
143
|
const provider = this.viewDecl.controllerProvider;
|
|
143
144
|
if (!isInjectable(provider)) return this.viewDecl.controller;
|
|
144
|
-
const deps =
|
|
145
|
+
const deps = annotate(provider);
|
|
145
146
|
const providerFn = Array.isArray(provider) ? tail(provider) : provider;
|
|
146
147
|
const resolvable = new Resolvable("", providerFn, deps);
|
|
147
148
|
return resolvable.get(context);
|
|
@@ -3,6 +3,7 @@ import { services } from "./common/coreservices";
|
|
|
3
3
|
import { tail, unnestR } from "../shared/common";
|
|
4
4
|
import { Resolvable } from "./resolve/resolvable";
|
|
5
5
|
import { kebobString } from "../shared/strings";
|
|
6
|
+
import { annotate } from "../core/di/injector";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @typedef BindingTuple
|
|
@@ -30,7 +31,7 @@ export class TemplateFactory {
|
|
|
30
31
|
* @param {angular.ITemplateCacheService} $templateCache
|
|
31
32
|
* @param {angular.ITemplateRequestService} $templateRequest
|
|
32
33
|
* @param {angular.IQService} $q
|
|
33
|
-
* @param {
|
|
34
|
+
* @param {import("../core/di/internal-injector").InjectorService} $injector
|
|
34
35
|
* @returns
|
|
35
36
|
*/
|
|
36
37
|
($http, $templateCache, $templateRequest, $q, $injector) => {
|
|
@@ -146,7 +147,7 @@ export class TemplateFactory {
|
|
|
146
147
|
* for that string.
|
|
147
148
|
*/
|
|
148
149
|
fromProvider(provider, params, context) {
|
|
149
|
-
const deps =
|
|
150
|
+
const deps = annotate(provider);
|
|
150
151
|
const providerFn = Array.isArray(provider) ? tail(provider) : provider;
|
|
151
152
|
const resolvable = new Resolvable("", providerFn, deps);
|
|
152
153
|
return resolvable.get(context);
|
|
@@ -159,7 +160,7 @@ export class TemplateFactory {
|
|
|
159
160
|
* @return {string} The template html as a string: "<component-name input1='::$resolve.foo'></component-name>".
|
|
160
161
|
*/
|
|
161
162
|
fromComponentProvider(provider, params, context) {
|
|
162
|
-
const deps =
|
|
163
|
+
const deps = annotate(provider);
|
|
163
164
|
const providerFn = Array.isArray(provider) ? tail(provider) : provider;
|
|
164
165
|
const resolvable = new Resolvable("", providerFn, deps);
|
|
165
166
|
return resolvable.get(context);
|
|
@@ -207,7 +208,7 @@ export class TemplateFactory {
|
|
|
207
208
|
if (type === "&") {
|
|
208
209
|
const res = context.getResolvable(resolveName);
|
|
209
210
|
const fn = res && res.data;
|
|
210
|
-
const args = (fn &&
|
|
211
|
+
const args = (fn && annotate(fn)) || [];
|
|
211
212
|
// account for array style injection, i.e., ['foo', function(foo) {}]
|
|
212
213
|
const arrayIdxStr = Array.isArray(fn) ? `[${fn.length - 1}]` : "";
|
|
213
214
|
return `${attrName}='$resolve.${resolveName}${arrayIdxStr}(${args.join(",")})'`;
|
|
@@ -499,6 +499,18 @@ export function $HttpProvider() {
|
|
|
499
499
|
"$q",
|
|
500
500
|
"$injector",
|
|
501
501
|
"$sce",
|
|
502
|
+
/**
|
|
503
|
+
*
|
|
504
|
+
* @param {*} $browser
|
|
505
|
+
* @param {*} $httpBackend
|
|
506
|
+
* @param {*} $$cookieReader
|
|
507
|
+
* @param {*} $cacheFactory
|
|
508
|
+
* @param {*} $rootScope
|
|
509
|
+
* @param {*} $q
|
|
510
|
+
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
511
|
+
* @param {*} $sce
|
|
512
|
+
* @returns
|
|
513
|
+
*/
|
|
502
514
|
function (
|
|
503
515
|
$browser,
|
|
504
516
|
$httpBackend,
|
package/src/types.js
CHANGED
|
@@ -10,6 +10,15 @@
|
|
|
10
10
|
* @template T
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @typedef {Object} Annotated
|
|
16
|
+
* @property {Array<String>} $inject
|
|
17
|
+
* *
|
|
18
|
+
* @typedef {Function & Annotated & Array<any>} AnnotatedFunction
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
13
22
|
/**
|
|
14
23
|
* @typedef {Object} ComponentOptions
|
|
15
24
|
* @description Component definition object (a simplified directive definition object)
|
|
@@ -444,15 +453,4 @@
|
|
|
444
453
|
* @property {function(any, any): IPromise<any>} [index] - Async validator function for each index.
|
|
445
454
|
*/
|
|
446
455
|
|
|
447
|
-
/**
|
|
448
|
-
* @typedef {Object} InjectorService
|
|
449
|
-
* @property {function(Function, boolean=): string[]} annotate - Annotate a function or an array of inline annotations.
|
|
450
|
-
* @property {function(string, string=): any} get - Get a service by name.
|
|
451
|
-
* @property {function(Function, any?): any} instantiate - Instantiate a type constructor with optional locals.
|
|
452
|
-
* @property {function(Injectable<Function | ((...args: any[]) => any)>, any=, any=): any} invoke - Invoke a function with optional context and locals.
|
|
453
|
-
* @property {function(Array<Module | string | Injectable<(...args: any[]) => void>>): void} [loadNewModules] - Add and load new modules to the injector.
|
|
454
|
-
* @property {Object.<string, Module>} [modules] - A map of all the modules loaded into the injector.
|
|
455
|
-
* @property {boolean} [strictDi] - Indicates if strict dependency injection is enforced.
|
|
456
|
-
*/
|
|
457
|
-
|
|
458
456
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function $$AnimateJsProvider($animateProvider: any): void;
|
|
2
2
|
export class $$AnimateJsProvider {
|
|
3
3
|
constructor($animateProvider: any);
|
|
4
|
-
$get: (string | (($injector:
|
|
4
|
+
$get: (string | (($injector: import("../core/di/internal-injector").InjectorService, $$AnimateRunner: any) => (element: any, event: any, classes: any, options: any, ...args: any[]) => {
|
|
5
5
|
$$willAnimate: boolean;
|
|
6
6
|
end(): any;
|
|
7
7
|
start(): any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function $$AnimationProvider(): void;
|
|
2
2
|
export class $$AnimationProvider {
|
|
3
3
|
drivers: any[];
|
|
4
|
-
$get: (string | (($rootScope: any, $injector:
|
|
4
|
+
$get: (string | (($rootScope: any, $injector: import("../core/di/internal-injector").InjectorService, $$AnimateRunner: any, $$rAFScheduler: import("./raf-scheduler").RafScheduler, $$animateCache: any) => (element: any, event: any, options: any) => any))[];
|
|
5
5
|
}
|
|
@@ -161,7 +161,7 @@ export class $CompileProvider {
|
|
|
161
161
|
* @returns {object} `this` for chaining
|
|
162
162
|
*/
|
|
163
163
|
addPropertySecurityContext: (elementName: string, propertyName: string, ctx: string) => object;
|
|
164
|
-
$get: (string | (($injector:
|
|
164
|
+
$get: (string | (($injector: import("../../core/di/internal-injector").InjectorService, $interpolate: any, $exceptionHandler: any, $templateRequest: any, $parse: any, $controller: any, $rootScope: any, $sce: any, $animate: any) => ($compileNodes: string | NodeList, transcludeFn: any, maxPriority: any, ignoreDirective: any, previousCompileContext: any) => (scope: any, cloneConnectFn: any, options: any) => string | NodeList | JQLite))[];
|
|
165
165
|
}
|
|
166
166
|
export namespace $CompileProvider {
|
|
167
167
|
let $inject: string[];
|
|
@@ -28,5 +28,5 @@ export class $ControllerProvider {
|
|
|
28
28
|
* annotations in the array notation).
|
|
29
29
|
*/
|
|
30
30
|
register: (name: string | any, constructor: Function | any[]) => void;
|
|
31
|
-
$get: (string | (($injector:
|
|
31
|
+
$get: (string | (($injector: import("../../core/di/internal-injector").InjectorService) => (expression: Function | string, locals: any, later: any, ident: any) => any))[];
|
|
32
32
|
}
|