@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.
- 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/animate-swap.js +3 -0
- package/src/animations/animation.js +1 -1
- package/src/core/compile/compile.js +16 -4
- package/src/core/controller/controller.js +5 -5
- package/src/core/di/injector.js +133 -259
- package/src/core/di/injector.md +3 -3
- package/src/core/di/injector.spec.js +30 -24
- package/src/core/di/internal-injector.js +286 -0
- package/src/core/filter/filter.js +5 -0
- package/src/core/parser/parse.js +1 -12
- package/src/core/parser/parse.spec.js +96 -110
- package/src/core/sce/sce.js +6 -1
- package/src/core/timeout/timeout.js +110 -111
- package/src/directive/input/input.js +32 -726
- package/src/directive/input/input.md +706 -0
- package/src/directive/select/select.js +48 -122
- package/src/directive/select/select.md +74 -0
- package/src/directive/show-hide/show-hide.js +13 -224
- package/src/directive/show-hide/show-hide.md +257 -0
- package/src/filters/limit-to.spec.js +1 -1
- package/src/filters/order-by.spec.js +1 -1
- package/src/index.js +6 -2
- package/src/loader.js +8 -4
- package/src/public.js +1 -7
- package/src/router/services.js +9 -4
- package/src/router/state/state-builder.js +6 -7
- package/src/router/state/state-registry.js +5 -0
- package/src/router/state/state-service.js +1 -1
- package/src/router/state/views.js +2 -1
- package/src/router/state-provider.js +1 -1
- package/src/router/template-factory.js +15 -14
- package/src/router/url/url-service.js +4 -4
- package/src/services/anchor-scroll.js +2 -2
- package/src/services/browser.js +2 -9
- package/src/services/cache-factory.js +0 -67
- package/src/services/cache-factory.md +75 -0
- package/src/services/cookie-reader.js +36 -55
- package/src/services/http/http.js +73 -586
- package/src/services/http/http.md +413 -0
- package/src/services/http-backend/http-backend.js +19 -44
- package/src/services/template-request.js +1 -9
- package/src/shared/jqlite/jqlite.js +4 -69
- package/src/types.js +8 -12
- package/types/animations/animate-js.d.ts +1 -1
- package/types/animations/animate-swap.d.ts +4 -7
- package/types/animations/animation.d.ts +1 -1
- package/types/core/compile/compile.d.ts +7 -7
- package/types/core/controller/controller.d.ts +1 -6
- package/types/core/di/injector.d.ts +13 -7
- package/types/core/di/internal-injector.d.ts +91 -0
- package/types/core/exception-handler.d.ts +1 -1
- package/types/core/filter/filter.d.ts +1 -1
- package/types/core/parser/parse.d.ts +1 -1
- package/types/core/sce/sce.d.ts +1 -1
- package/types/core/timeout/timeout.d.ts +16 -26
- package/types/directive/input/input.d.ts +19 -124
- package/types/directive/select/select.d.ts +7 -74
- package/types/directive/show-hide/show-hide.d.ts +11 -224
- package/types/loader.d.ts +4 -4
- package/types/router/services.d.ts +8 -1
- package/types/router/state/state-builder.d.ts +1 -2
- package/types/router/state/state-registry.d.ts +2 -2
- package/types/router/state/state-service.d.ts +2 -2
- package/types/router/state-provider.d.ts +2 -2
- package/types/router/template-factory.d.ts +16 -16
- package/types/router/url/url-service.d.ts +4 -4
- package/types/services/anchor-scroll.d.ts +1 -1
- package/types/services/browser.d.ts +0 -10
- package/types/services/cache-factory.d.ts +0 -67
- package/types/services/cookie-reader.d.ts +2 -10
- package/types/services/http/http.d.ts +53 -61
- package/types/services/http-backend/http-backend.d.ts +8 -31
- package/types/services/template-request.d.ts +1 -9
- package/types/shared/jqlite/jqlite.d.ts +9 -9
- package/types/types.d.ts +5 -38
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.
|
|
5
|
+
"version": "0.0.67",
|
|
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 {
|
|
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
|
|
@@ -218,7 +218,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
218
218
|
* are the factories.
|
|
219
219
|
* @param {Function|Array} directiveFactory An injectable directive factory function. See the
|
|
220
220
|
* {@link guide/directive directive guide} and the {@link $compile compile API} for more info.
|
|
221
|
-
* @returns {
|
|
221
|
+
* @returns {$CompileProvider} Self for chaining.
|
|
222
222
|
*/
|
|
223
223
|
this.directive = function registerDirective(name, directiveFactory) {
|
|
224
224
|
assertArg(name, "name");
|
|
@@ -233,7 +233,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
233
233
|
"$exceptionHandler",
|
|
234
234
|
/**
|
|
235
235
|
*
|
|
236
|
-
* @param {
|
|
236
|
+
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
237
237
|
* @param {import('../exception-handler').ErrorHandler} $exceptionHandler
|
|
238
238
|
* @returns
|
|
239
239
|
*/
|
|
@@ -442,7 +442,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
442
442
|
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
|
|
443
443
|
*
|
|
444
444
|
* @param {RegExp=} regexp New regexp to trust urls with.
|
|
445
|
-
* @returns {RegExp
|
|
445
|
+
* @returns {RegExp|$CompileProvider} Current RegExp if called without value or self for
|
|
446
446
|
* chaining otherwise.
|
|
447
447
|
*/
|
|
448
448
|
this.aHrefSanitizationTrustedUrlList = function (regexp) {
|
|
@@ -470,7 +470,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
|
|
|
470
470
|
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
|
|
471
471
|
*
|
|
472
472
|
* @param {RegExp=} regexp New regexp to trust urls with.
|
|
473
|
-
* @returns {RegExp
|
|
473
|
+
* @returns {RegExp|$CompileProvider} Current RegExp if called without value or self for
|
|
474
474
|
* chaining otherwise.
|
|
475
475
|
*/
|
|
476
476
|
this.imgSrcSanitizationTrustedUrlList = function (regexp) {
|
|
@@ -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,
|
|
@@ -21,11 +21,6 @@ export function identifierForController(controller, ident) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @ngdoc provider
|
|
25
|
-
* @name $controllerProvider
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @description
|
|
29
24
|
* The {@link ng.$controller $controller service} is used by AngularJS to create new
|
|
30
25
|
* controllers.
|
|
31
26
|
*
|
|
@@ -63,6 +58,11 @@ export function $ControllerProvider() {
|
|
|
63
58
|
|
|
64
59
|
this.$get = [
|
|
65
60
|
"$injector",
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param {import("../../core/di/internal-injector").InjectorService} $injector
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
66
|
function ($injector) {
|
|
67
67
|
/**
|
|
68
68
|
* @ngdoc service
|
package/src/core/di/injector.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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 {
|
|
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,43 +46,22 @@ export function createInjector(modulesToLoad, strictDi = false) {
|
|
|
105
46
|
},
|
|
106
47
|
};
|
|
107
48
|
|
|
108
|
-
providerCache.$injector =
|
|
49
|
+
const providerInjector = (providerCache.$injector = new ProviderInjector(
|
|
109
50
|
providerCache,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
path.push(caller);
|
|
113
|
-
}
|
|
114
|
-
throw $injectorMinErr("unpr", "Unknown provider: {0}", path.join(" <- "));
|
|
115
|
-
},
|
|
116
|
-
);
|
|
51
|
+
strictDi,
|
|
52
|
+
));
|
|
117
53
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
let protoInstanceInjector = createInternalInjector(
|
|
121
|
-
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
|
-
},
|
|
134
|
-
);
|
|
54
|
+
const protoInstanceInjector = new InjectorService(strictDi, providerInjector);
|
|
135
55
|
|
|
136
|
-
providerCache
|
|
137
|
-
$
|
|
56
|
+
providerCache.$injectorProvider = {
|
|
57
|
+
// $injectionProvider return instance injector
|
|
58
|
+
$get: () => protoInstanceInjector,
|
|
138
59
|
};
|
|
60
|
+
|
|
139
61
|
let instanceInjector = protoInstanceInjector;
|
|
140
|
-
instanceInjector.modules = providerCache.$injector.modules =
|
|
141
|
-
Object.create(null);
|
|
142
62
|
const runBlocks = loadModules(modulesToLoad);
|
|
143
|
-
instanceInjector = protoInstanceInjector.get(
|
|
144
|
-
|
|
63
|
+
instanceInjector = protoInstanceInjector.get(INJECTOR_LITERAL);
|
|
64
|
+
|
|
145
65
|
runBlocks.forEach((fn) => {
|
|
146
66
|
if (fn) instanceInjector.invoke(fn);
|
|
147
67
|
});
|
|
@@ -158,89 +78,83 @@ export function createInjector(modulesToLoad, strictDi = false) {
|
|
|
158
78
|
// $provider
|
|
159
79
|
////////////////////////////////////
|
|
160
80
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
} else {
|
|
168
|
-
return delegate(key, value);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @param {string} name
|
|
84
|
+
* @param {import('../../types').ServiceProvider} provider
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
173
87
|
function provider(name, provider) {
|
|
174
88
|
assertNotHasOwnProperty(name, "service");
|
|
89
|
+
let newProvider;
|
|
175
90
|
if (isFunction(provider) || Array.isArray(provider)) {
|
|
176
|
-
|
|
91
|
+
newProvider = providerInjector.instantiate(
|
|
92
|
+
/** @type {Function} */ (provider),
|
|
93
|
+
);
|
|
94
|
+
} else {
|
|
95
|
+
newProvider = provider;
|
|
177
96
|
}
|
|
178
|
-
if (!
|
|
97
|
+
if (!newProvider.$get) {
|
|
179
98
|
throw $injectorMinErr(
|
|
180
99
|
"pget",
|
|
181
100
|
"Provider '{0}' must define $get factory method.",
|
|
182
101
|
name,
|
|
183
102
|
);
|
|
184
103
|
}
|
|
185
|
-
|
|
104
|
+
providerCache[name + providerSuffix] = newProvider;
|
|
105
|
+
return newProvider;
|
|
186
106
|
}
|
|
187
107
|
|
|
188
|
-
function
|
|
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) {
|
|
108
|
+
function factory(name, factoryFn) {
|
|
203
109
|
return provider(name, {
|
|
204
|
-
$get:
|
|
110
|
+
$get: () => {
|
|
111
|
+
const result = instanceInjector.invoke(factoryFn, this);
|
|
112
|
+
if (isUndefined(result)) {
|
|
113
|
+
throw $injectorMinErr(
|
|
114
|
+
"undef",
|
|
115
|
+
"Provider '{0}' must return a value from $get factory method.",
|
|
116
|
+
name,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
},
|
|
205
121
|
});
|
|
206
122
|
}
|
|
207
123
|
|
|
208
124
|
function service(name, constructor) {
|
|
209
125
|
return factory(name, [
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return $injector.instantiate(constructor);
|
|
213
|
-
},
|
|
126
|
+
INJECTOR_LITERAL,
|
|
127
|
+
($injector) => $injector.instantiate(constructor),
|
|
214
128
|
]);
|
|
215
129
|
}
|
|
216
130
|
|
|
131
|
+
/**
|
|
132
|
+
* @param {String} name
|
|
133
|
+
* @param {any} val
|
|
134
|
+
* @returns {import('../../types').ServiceProvider}
|
|
135
|
+
*/
|
|
217
136
|
function value(name, val) {
|
|
218
|
-
return
|
|
137
|
+
return (providerCache[name + providerSuffix] = { $get: () => val });
|
|
219
138
|
}
|
|
220
139
|
|
|
221
140
|
function constant(name, value) {
|
|
222
141
|
assertNotHasOwnProperty(name, "constant");
|
|
223
|
-
|
|
224
|
-
|
|
142
|
+
providerInjector.cache[name] = value;
|
|
143
|
+
protoInstanceInjector.cache[name] = value;
|
|
225
144
|
}
|
|
226
145
|
|
|
227
146
|
function decorator(serviceName, decorFn) {
|
|
228
|
-
const origProvider =
|
|
229
|
-
|
|
230
|
-
);
|
|
231
|
-
const orig$get = origProvider.$get;
|
|
147
|
+
const origProvider = providerInjector.get(serviceName + providerSuffix);
|
|
148
|
+
const origGet = origProvider.$get;
|
|
232
149
|
|
|
233
150
|
origProvider.$get = function () {
|
|
234
|
-
const origInstance = instanceInjector.invoke(
|
|
151
|
+
const origInstance = instanceInjector.invoke(origGet, origProvider);
|
|
235
152
|
return instanceInjector.invoke(decorFn, null, {
|
|
236
153
|
$delegate: origInstance,
|
|
237
154
|
});
|
|
238
155
|
};
|
|
239
156
|
}
|
|
240
157
|
|
|
241
|
-
////////////////////////////////////
|
|
242
|
-
// Module Loading
|
|
243
|
-
////////////////////////////////////
|
|
244
158
|
/**
|
|
245
159
|
*
|
|
246
160
|
* @param {Array<String|Function>} modulesToLoad
|
|
@@ -258,31 +172,26 @@ export function createInjector(modulesToLoad, strictDi = false) {
|
|
|
258
172
|
if (loadedModules.get(module)) return;
|
|
259
173
|
loadedModules.set(module, true);
|
|
260
174
|
|
|
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
175
|
try {
|
|
273
176
|
if (isString(module)) {
|
|
274
177
|
/** @type {import('./ng-module').NgModule} */
|
|
275
|
-
|
|
276
|
-
instanceInjector.modules[module] = moduleFn;
|
|
178
|
+
const moduleFn = window["angular"].module(module);
|
|
179
|
+
instanceInjector.modules[/** @type {string } */ (module)] = moduleFn;
|
|
277
180
|
runBlocks = runBlocks
|
|
278
181
|
.concat(loadModules(moduleFn.requires))
|
|
279
182
|
.concat(moduleFn.runBlocks);
|
|
280
|
-
|
|
281
|
-
|
|
183
|
+
|
|
184
|
+
const invokeQueue = moduleFn.invokeQueue.concat(
|
|
185
|
+
moduleFn.configBlocks,
|
|
186
|
+
);
|
|
187
|
+
invokeQueue.forEach((invokeArgs) => {
|
|
188
|
+
const provider = providerInjector.get(invokeArgs[0]);
|
|
189
|
+
provider[invokeArgs[1]].apply(provider, invokeArgs[2]);
|
|
190
|
+
});
|
|
282
191
|
} else if (isFunction(module)) {
|
|
283
|
-
runBlocks.push(
|
|
192
|
+
runBlocks.push(providerInjector.invoke(module));
|
|
284
193
|
} else if (Array.isArray(module)) {
|
|
285
|
-
runBlocks.push(
|
|
194
|
+
runBlocks.push(providerInjector.invoke(module));
|
|
286
195
|
} else {
|
|
287
196
|
assertArgFn(module, "module");
|
|
288
197
|
}
|
|
@@ -308,115 +217,80 @@ export function createInjector(modulesToLoad, strictDi = false) {
|
|
|
308
217
|
});
|
|
309
218
|
return runBlocks;
|
|
310
219
|
}
|
|
220
|
+
}
|
|
311
221
|
|
|
312
|
-
|
|
313
|
-
// internal Injector
|
|
314
|
-
////////////////////////////////////
|
|
222
|
+
// Helpers
|
|
315
223
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
}
|
|
224
|
+
/**
|
|
225
|
+
* @param {String} fn
|
|
226
|
+
* @returns {String}
|
|
227
|
+
*/
|
|
228
|
+
function stringifyFn(fn) {
|
|
229
|
+
return Function.prototype.toString.call(fn);
|
|
230
|
+
}
|
|
342
231
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
232
|
+
/**
|
|
233
|
+
* @param {String} fn
|
|
234
|
+
* @returns {Array<any>}
|
|
235
|
+
*/
|
|
236
|
+
function extractArgs(fn) {
|
|
237
|
+
const fnText = stringifyFn(fn).replace(STRIP_COMMENTS, "");
|
|
238
|
+
const args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
|
|
239
|
+
return args;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
* @param {any} fn
|
|
245
|
+
* @param {boolean} [strictDi]
|
|
246
|
+
* @param {String} [name]
|
|
247
|
+
* @returns {Array<string>}
|
|
248
|
+
*/
|
|
249
|
+
export function annotate(fn, strictDi, name) {
|
|
250
|
+
var $inject, argDecl, last;
|
|
346
251
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
252
|
+
if (typeof fn === "function") {
|
|
253
|
+
if (!($inject = fn.$inject)) {
|
|
254
|
+
$inject = [];
|
|
255
|
+
if (fn.length) {
|
|
256
|
+
if (strictDi) {
|
|
350
257
|
throw $injectorMinErr(
|
|
351
|
-
"
|
|
352
|
-
"
|
|
353
|
-
|
|
258
|
+
"strictdi",
|
|
259
|
+
"{0} is not using explicit annotation and cannot be invoked in strict mode",
|
|
260
|
+
name,
|
|
354
261
|
);
|
|
355
262
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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);
|
|
263
|
+
argDecl = extractArgs(/** @type {String} */ (fn));
|
|
264
|
+
argDecl[1].split(FN_ARG_SPLIT).forEach(function (arg) {
|
|
265
|
+
arg.replace(FN_ARG, function (all, underscore, name) {
|
|
266
|
+
$inject.push(name);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
388
269
|
}
|
|
389
|
-
|
|
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;
|
|
270
|
+
fn.$inject = $inject;
|
|
410
271
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
has,
|
|
418
|
-
};
|
|
272
|
+
} else if (Array.isArray(fn)) {
|
|
273
|
+
last = /** @type {Array} */ (fn).length - 1;
|
|
274
|
+
assertArgFn(fn[last], "fn");
|
|
275
|
+
$inject = /** @type {Array} */ (fn).slice(0, last);
|
|
276
|
+
} else {
|
|
277
|
+
assertArgFn(fn, "fn", true);
|
|
419
278
|
}
|
|
279
|
+
return $inject;
|
|
420
280
|
}
|
|
421
281
|
|
|
422
|
-
|
|
282
|
+
/**
|
|
283
|
+
* @param {function(string, any):any} delegate
|
|
284
|
+
* @returns
|
|
285
|
+
*/
|
|
286
|
+
function supportObject(delegate) {
|
|
287
|
+
return function (key, value) {
|
|
288
|
+
if (isObject(key)) {
|
|
289
|
+
Object.entries(key).forEach(([k, v]) => {
|
|
290
|
+
delegate(k, v);
|
|
291
|
+
});
|
|
292
|
+
} else {
|
|
293
|
+
return delegate(key, value);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
package/src/core/di/injector.md
CHANGED
|
@@ -250,7 +250,7 @@
|
|
|
250
250
|
- }
|
|
251
251
|
-
|
|
252
252
|
- // Then
|
|
253
|
-
- expect(
|
|
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(
|
|
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(
|
|
314
|
+
- expect(annotate(
|
|
315
315
|
- ['$compile', '$rootScope', function(obfus_$compile, obfus_$rootScope) {}])
|
|
316
316
|
- ).toEqual(['$compile', '$rootScope']);
|
|
317
317
|
- ```
|