@angular-wave/angular.ts 0.0.64 → 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/public/jasmine/jasmine-5.1.2/jasmine-html.js +0 -1
- package/src/angular.spec.js +1 -1
- package/src/animations/animate-js.js +6 -0
- package/src/animations/animation.js +1 -1
- package/src/binding.spec.js +1 -1
- package/src/core/animate/animate.spec.js +1 -1
- package/src/core/cache/cache-factory.spec.js +1 -1
- package/src/core/compile/compile.js +13 -1
- package/src/core/compile/compile.spec.js +2 -3
- package/src/core/controller/controller.js +5 -0
- package/src/core/controller/controller.spec.js +1 -1
- package/src/core/cookie-reader.spec.js +1 -1
- package/src/core/di/injector.html +18 -0
- package/src/core/di/injector.js +299 -0
- package/src/{injector.md → core/di/injector.md} +3 -3
- package/src/{injector.spec.js → core/di/injector.spec.js} +49 -30
- package/src/core/di/injector.test.js +12 -0
- package/src/core/di/internal-injector.js +233 -0
- package/src/core/di/ng-module.html +18 -0
- package/src/core/{ng-module.js → di/ng-module.js} +64 -29
- package/src/core/di/ng-module.spec.js +269 -0
- package/src/core/di/ng-module.test.js +12 -0
- package/src/core/filter/filter.js +5 -0
- package/src/core/filter/filter.spec.js +1 -1
- package/src/core/interpolate/interpolate.spec.js +1 -1
- package/src/core/interval/interval.spec.js +1 -1
- package/src/core/location/location.spec.js +1 -1
- package/src/core/on.spec.js +1 -1
- package/src/core/parser/lexer.spec.js +1 -1
- package/src/core/parser/parse.spec.js +1 -1
- package/src/core/prop.spec.js +1 -1
- package/src/core/q/q.spec.js +1 -4
- package/src/core/q/q.test.js +12 -0
- package/src/core/sce/sce.js +6 -1
- package/src/core/sce/sce.spec.js +1 -1
- package/src/core/scope/scope.js +0 -1
- package/src/core/scope/scope.spec.js +1 -1
- package/src/core/timeout/timeout.spec.js +1 -1
- package/src/directive/attrs/attrs.spec.js +2 -2
- package/src/directive/attrs/boolean.spec.js +1 -1
- package/src/directive/attrs/element-style.spec.js +1 -1
- package/src/directive/attrs/src.spec.js +2 -2
- package/src/directive/bind/bind.spec.js +2 -2
- package/src/directive/bind/bing-html.spec.js +1 -1
- package/src/directive/change/change.spec.js +1 -1
- package/src/directive/class/class.spec.js +1 -1
- package/src/directive/cloak/cloak.spec.js +1 -1
- package/src/directive/controller/controller.spec.js +1 -1
- package/src/directive/events/click.spec.js +2 -2
- package/src/directive/events/event.spec.js +1 -1
- package/src/directive/form/form.spec.js +1 -1
- package/src/directive/if/if.spec.js +1 -1
- package/src/directive/include/include.spec.js +1 -1
- package/src/directive/init/init.spec.js +1 -1
- package/src/directive/input/input.spec.js +1 -2
- package/src/directive/list/list.spec.js +2 -2
- package/src/directive/model/model.spec.js +1 -1
- package/src/directive/model-options/model-options.spec.js +1 -1
- package/src/directive/non-bindable/non-bindable.spec.js +2 -2
- package/src/directive/options/options.spec.js +1 -1
- package/src/directive/ref/href.spec.js +1 -1
- package/src/directive/ref/ref.spec.js +1 -1
- package/src/directive/repeat/repeat.spec.js +1 -1
- package/src/directive/script/script.spec.js +1 -1
- package/src/directive/select/select.spec.js +1 -1
- package/src/directive/show-hide/show-hide.spec.js +1 -1
- package/src/directive/style/style.spec.js +1 -1
- package/src/directive/switch/switch.spec.js +1 -1
- package/src/directive/validators/validators.spec.js +1 -1
- package/src/exts/aria/aria.spec.js +1 -1
- package/src/exts/messages/messages.spec.js +1 -1
- package/src/filters/filter.spec.js +1 -1
- package/src/filters/filters.spec.js +1 -1
- package/src/filters/limit-to.spec.js +1 -1
- package/src/filters/order-by.spec.js +1 -1
- package/src/loader.js +7 -7
- package/src/loader.spec.js +4 -19
- package/src/public.spec.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/services/http/http.spec.js +1 -1
- package/src/services/http/template-request.spec.js +1 -1
- package/src/services/http-backend/http-backend.spec.js +1 -1
- package/src/shared/jqlite/jqlite.js +0 -2
- package/src/shared/jqlite/jqlite.spec.js +1 -1
- package/src/shared/utils.js +10 -1
- package/src/src.html +0 -1
- 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 +18 -0
- package/types/core/di/internal-injector.d.ts +36 -0
- package/types/core/{ng-module.d.ts → di/ng-module.d.ts} +30 -8
- package/types/core/filter/filter.d.ts +1 -1
- package/types/core/sce/sce.d.ts +1 -1
- package/types/loader.d.ts +5 -5
- 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/shared/utils.d.ts +7 -1
- package/types/types.d.ts +7 -32
- package/src/injector.js +0 -409
- package/types/injector.d.ts +0 -12
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.66",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/angular-ts.esm.js",
|
|
8
8
|
"browser": "dist/angular-ts.umd.js",
|
|
@@ -21,7 +21,6 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
// eslint-disable-next-line no-var
|
|
25
24
|
var jasmineRequire = window.jasmineRequire || require("./jasmine.js");
|
|
26
25
|
|
|
27
26
|
jasmineRequire.html = function (j$) {
|
package/src/angular.spec.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from "./shared/utils";
|
|
27
27
|
import { dealoc, JQLite, startingTag } from "./shared/jqlite/jqlite";
|
|
28
28
|
import { Angular } from "./loader";
|
|
29
|
-
import { createInjector } from "./injector";
|
|
29
|
+
import { createInjector } from "./core/di/injector";
|
|
30
30
|
|
|
31
31
|
describe("angular", () => {
|
|
32
32
|
let element, document, module, injector, $rootScope, $compile;
|
|
@@ -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
|
package/src/binding.spec.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JQLite, dealoc } from "./shared/jqlite/jqlite";
|
|
2
2
|
import { Angular } from "./loader";
|
|
3
|
-
import { createInjector } from "./injector";
|
|
3
|
+
import { createInjector } from "./core/di/injector";
|
|
4
4
|
import { browserTrigger } from "./shared/test-utils";
|
|
5
5
|
|
|
6
6
|
describe("binding", () => {
|
|
@@ -2,7 +2,7 @@ import { dealoc, JQLite } from "../../shared/jqlite/jqlite";
|
|
|
2
2
|
import { Angular } from "../../loader";
|
|
3
3
|
import { isObject } from "../../shared/utils";
|
|
4
4
|
import { isFunction } from "../../shared/utils";
|
|
5
|
-
import { createInjector } from "
|
|
5
|
+
import { createInjector } from "../di/injector";
|
|
6
6
|
|
|
7
7
|
describe("$animate", () => {
|
|
8
8
|
describe("without animation", () => {
|
|
@@ -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
|
*/
|
|
@@ -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,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Angular } from "../../loader";
|
|
2
|
-
import { createInjector } from "
|
|
2
|
+
import { createInjector } from "../di/injector";
|
|
3
3
|
import { dealoc, JQLite, getOrSetCacheData } from "../../shared/jqlite/jqlite";
|
|
4
4
|
import {
|
|
5
5
|
forEach,
|
|
@@ -11094,7 +11094,6 @@ describe("$compile", () => {
|
|
|
11094
11094
|
|
|
11095
11095
|
it("should eventually expose isolate scope variables on ES6 class controller with controllerAs when bindToController is true", () => {
|
|
11096
11096
|
var controllerCalled = false;
|
|
11097
|
-
// eslint-disable-next-line no-eval
|
|
11098
11097
|
var Controller = eval(
|
|
11099
11098
|
"(\n" +
|
|
11100
11099
|
"class Foo {\n" +
|
|
@@ -17386,7 +17385,7 @@ describe("$compile", () => {
|
|
|
17386
17385
|
$customAnnotation: "XXX",
|
|
17387
17386
|
});
|
|
17388
17387
|
initInjector("test1");
|
|
17389
|
-
expect(myModule.
|
|
17388
|
+
expect(myModule.invokeQueue.pop().pop()[1]).toEqual(
|
|
17390
17389
|
jasmine.objectContaining({
|
|
17391
17390
|
$canActivate: "canActivate",
|
|
17392
17391
|
$routeConfig: "routeConfig",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>AngularTS Test Runner</title>
|
|
6
|
+
|
|
7
|
+
<link rel="shortcut icon" type="image/png" href="/images/favicon.ico" />
|
|
8
|
+
<link rel="stylesheet" href="/jasmine/jasmine-5.1.2/jasmine.css" />
|
|
9
|
+
<script src="/jasmine/jasmine-5.1.2/jasmine.js"></script>
|
|
10
|
+
<script src="/jasmine/jasmine-5.1.2/jasmine-html.js"></script>
|
|
11
|
+
<script src="/jasmine/jasmine-5.1.2/boot0.js"></script>
|
|
12
|
+
<script src="/jasmine/jasmine-5.1.2/boot1.js"></script>
|
|
13
|
+
<script type="module" src="/src/core/di/injector.spec.js"></script>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<div id="dummy"></div>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertArgFn,
|
|
3
|
+
minErr,
|
|
4
|
+
isFunction,
|
|
5
|
+
isString,
|
|
6
|
+
isUndefined,
|
|
7
|
+
assertArg,
|
|
8
|
+
assertNotHasOwnProperty,
|
|
9
|
+
isObject,
|
|
10
|
+
assert,
|
|
11
|
+
} from "../../shared/utils";
|
|
12
|
+
import { INJECTOR_LITERAL } from "./ng-module";
|
|
13
|
+
import { ProviderInjector, InjectorService } from "./internal-injector";
|
|
14
|
+
|
|
15
|
+
const ARROW_ARG = /^([^(]+?)=>/;
|
|
16
|
+
const FN_ARGS = /^[^(]*\(\s*([^)]*)\)/m;
|
|
17
|
+
const FN_ARG_SPLIT = /,/;
|
|
18
|
+
const FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
|
|
19
|
+
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
20
|
+
const $injectorMinErr = minErr(INJECTOR_LITERAL);
|
|
21
|
+
|
|
22
|
+
const providerSuffix = "Provider";
|
|
23
|
+
/** @type {String[]} Used only for error reporting of circular dependencies*/
|
|
24
|
+
export const path = [];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param {Array<String|Function>} modulesToLoad
|
|
29
|
+
* @param {boolean} [strictDi]
|
|
30
|
+
* @returns {InjectorService}
|
|
31
|
+
*/
|
|
32
|
+
export function createInjector(modulesToLoad, strictDi = false) {
|
|
33
|
+
assert(Array.isArray(modulesToLoad), "modules required");
|
|
34
|
+
|
|
35
|
+
/** @type {Map<String|Function, boolean>} */
|
|
36
|
+
const loadedModules = new Map(); // Keep track of loaded modules to avoid circular dependencies
|
|
37
|
+
|
|
38
|
+
const providerCache = {
|
|
39
|
+
$provide: {
|
|
40
|
+
provider: supportObject(provider),
|
|
41
|
+
factory: supportObject(factory),
|
|
42
|
+
service: supportObject(service),
|
|
43
|
+
value: supportObject(value),
|
|
44
|
+
constant: supportObject(constant),
|
|
45
|
+
decorator,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const providerInjector = (providerCache.$injector = new ProviderInjector(
|
|
50
|
+
providerCache,
|
|
51
|
+
strictDi,
|
|
52
|
+
));
|
|
53
|
+
|
|
54
|
+
const instanceCache = {};
|
|
55
|
+
const protoInstanceInjector = new InjectorService(
|
|
56
|
+
instanceCache,
|
|
57
|
+
strictDi,
|
|
58
|
+
providerInjector,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
providerCache.$injectorProvider = {
|
|
62
|
+
// $injectionProvider return instance injector
|
|
63
|
+
$get: () => protoInstanceInjector,
|
|
64
|
+
};
|
|
65
|
+
let instanceInjector = protoInstanceInjector;
|
|
66
|
+
instanceInjector.modules = providerInjector.modules = {};
|
|
67
|
+
const runBlocks = loadModules(modulesToLoad);
|
|
68
|
+
instanceInjector = protoInstanceInjector.get(INJECTOR_LITERAL);
|
|
69
|
+
instanceInjector.strictDi = strictDi;
|
|
70
|
+
runBlocks.forEach((fn) => {
|
|
71
|
+
if (fn) instanceInjector.invoke(fn);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
instanceInjector.loadNewModules = function (mods) {
|
|
75
|
+
loadModules(mods).forEach((fn) => {
|
|
76
|
+
if (fn) instanceInjector.invoke(fn);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return instanceInjector;
|
|
81
|
+
|
|
82
|
+
////////////////////////////////////
|
|
83
|
+
// $provider
|
|
84
|
+
////////////////////////////////////
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @param {string} name
|
|
89
|
+
* @param {import('../../types').ServiceProvider} provider
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
function provider(name, provider) {
|
|
93
|
+
assertNotHasOwnProperty(name, "service");
|
|
94
|
+
let newProvider;
|
|
95
|
+
if (isFunction(provider) || Array.isArray(provider)) {
|
|
96
|
+
newProvider = providerInjector.instantiate(provider);
|
|
97
|
+
} else {
|
|
98
|
+
newProvider = provider;
|
|
99
|
+
}
|
|
100
|
+
if (!newProvider.$get) {
|
|
101
|
+
throw $injectorMinErr(
|
|
102
|
+
"pget",
|
|
103
|
+
"Provider '{0}' must define $get factory method.",
|
|
104
|
+
name,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
providerCache[name + providerSuffix] = newProvider;
|
|
108
|
+
return newProvider;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function factory(name, factoryFn) {
|
|
112
|
+
return provider(name, {
|
|
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
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function service(name, constructor) {
|
|
128
|
+
return factory(name, [
|
|
129
|
+
INJECTOR_LITERAL,
|
|
130
|
+
($injector) => $injector.instantiate(constructor),
|
|
131
|
+
]);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {String} name
|
|
136
|
+
* @param {any} val
|
|
137
|
+
* @returns {import('../../types').ServiceProvider}
|
|
138
|
+
*/
|
|
139
|
+
function value(name, val) {
|
|
140
|
+
return (providerCache[name + providerSuffix] = { $get: () => val });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function constant(name, value) {
|
|
144
|
+
assertNotHasOwnProperty(name, "constant");
|
|
145
|
+
providerCache[name] = value;
|
|
146
|
+
instanceCache[name] = value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function decorator(serviceName, decorFn) {
|
|
150
|
+
const origProvider = providerInjector.get(serviceName + providerSuffix);
|
|
151
|
+
const origGet = origProvider.$get;
|
|
152
|
+
|
|
153
|
+
origProvider.$get = function () {
|
|
154
|
+
const origInstance = instanceInjector.invoke(origGet, origProvider);
|
|
155
|
+
return instanceInjector.invoke(decorFn, null, {
|
|
156
|
+
$delegate: origInstance,
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
* @param {Array<String|Function>} modulesToLoad
|
|
164
|
+
* @returns
|
|
165
|
+
*/
|
|
166
|
+
function loadModules(modulesToLoad) {
|
|
167
|
+
assertArg(
|
|
168
|
+
isUndefined(modulesToLoad) || Array.isArray(modulesToLoad),
|
|
169
|
+
"modulesToLoad",
|
|
170
|
+
"not an array",
|
|
171
|
+
);
|
|
172
|
+
let runBlocks = [];
|
|
173
|
+
|
|
174
|
+
modulesToLoad.forEach((module) => {
|
|
175
|
+
if (loadedModules.get(module)) return;
|
|
176
|
+
loadedModules.set(module, true);
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
if (isString(module)) {
|
|
180
|
+
/** @type {import('./ng-module').NgModule} */
|
|
181
|
+
let moduleFn = window["angular"].module(module);
|
|
182
|
+
instanceInjector.modules[/** @type {string } */ (module)] = moduleFn;
|
|
183
|
+
runBlocks = runBlocks
|
|
184
|
+
.concat(loadModules(moduleFn.requires))
|
|
185
|
+
.concat(moduleFn.runBlocks);
|
|
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
|
+
});
|
|
194
|
+
} else if (isFunction(module)) {
|
|
195
|
+
runBlocks.push(providerInjector.invoke(module));
|
|
196
|
+
} else if (Array.isArray(module)) {
|
|
197
|
+
runBlocks.push(providerInjector.invoke(module));
|
|
198
|
+
} else {
|
|
199
|
+
assertArgFn(module, "module");
|
|
200
|
+
}
|
|
201
|
+
} catch (e) {
|
|
202
|
+
if (Array.isArray(module)) {
|
|
203
|
+
module = module[module.length - 1];
|
|
204
|
+
}
|
|
205
|
+
if (e.message && e.stack && e.stack.indexOf(e.message) === -1) {
|
|
206
|
+
// Safari & FF's stack traces don't contain error.message content
|
|
207
|
+
// unlike those of Chrome and IE
|
|
208
|
+
// So if stack doesn't contain message, we create a new string that contains both.
|
|
209
|
+
// Since error.stack is read-only in Safari, I'm overriding e and not e.stack here.
|
|
210
|
+
|
|
211
|
+
e.message = `${e.message}\n${e.stack}`;
|
|
212
|
+
}
|
|
213
|
+
throw $injectorMinErr(
|
|
214
|
+
"modulerr",
|
|
215
|
+
"Failed to instantiate module {0} due to:\n{1}",
|
|
216
|
+
module,
|
|
217
|
+
e.stack || e.message || e,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
return runBlocks;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Helpers
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @param {String} fn
|
|
229
|
+
* @returns {String}
|
|
230
|
+
*/
|
|
231
|
+
function stringifyFn(fn) {
|
|
232
|
+
return Function.prototype.toString.call(fn);
|
|
233
|
+
}
|
|
234
|
+
|
|
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;
|
|
254
|
+
|
|
255
|
+
if (typeof fn === "function") {
|
|
256
|
+
if (!($inject = fn.$inject)) {
|
|
257
|
+
$inject = [];
|
|
258
|
+
if (fn.length) {
|
|
259
|
+
if (strictDi) {
|
|
260
|
+
throw $injectorMinErr(
|
|
261
|
+
"strictdi",
|
|
262
|
+
"{0} is not using explicit annotation and cannot be invoked in strict mode",
|
|
263
|
+
name,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
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
|
+
});
|
|
272
|
+
}
|
|
273
|
+
fn.$inject = $inject;
|
|
274
|
+
}
|
|
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);
|
|
281
|
+
}
|
|
282
|
+
return $inject;
|
|
283
|
+
}
|
|
284
|
+
|
|
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(
|
|
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
|
- ```
|