@angular-wave/angular.ts 0.0.64 → 0.0.65
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/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.spec.js +2 -3
- 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/{injector.js → core/di/injector.js} +58 -45
- package/src/{injector.spec.js → core/di/injector.spec.js} +19 -6
- package/src/core/di/injector.test.js +12 -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.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.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 +6 -6
- package/src/loader.spec.js +4 -19
- package/src/public.spec.js +1 -1
- 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/types/core/di/injector.d.ts +12 -0
- package/types/core/{ng-module.d.ts → di/ng-module.d.ts} +30 -8
- package/types/loader.d.ts +5 -5
- package/types/shared/utils.d.ts +7 -1
- package/types/injector.d.ts +0 -12
- /package/src/{injector.md → core/di/injector.md} +0 -0
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.65",
|
|
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;
|
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", () => {
|
|
@@ -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>
|
|
@@ -9,17 +9,16 @@ import {
|
|
|
9
9
|
assertArg,
|
|
10
10
|
valueFn,
|
|
11
11
|
assertNotHasOwnProperty,
|
|
12
|
-
reverseParams,
|
|
13
12
|
isObject,
|
|
14
|
-
|
|
15
|
-
} from "
|
|
13
|
+
assert,
|
|
14
|
+
} from "../../shared/utils";
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const ARROW_ARG = /^([^(]+?)=>/;
|
|
17
|
+
const FN_ARGS = /^[^(]*\(\s*([^)]*)\)/m;
|
|
18
|
+
const FN_ARG_SPLIT = /,/;
|
|
19
|
+
const FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
|
|
20
|
+
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
21
|
+
const $injectorMinErr = minErr("$injector");
|
|
23
22
|
|
|
24
23
|
function stringifyFn(fn) {
|
|
25
24
|
return Function.prototype.toString.call(fn);
|
|
@@ -82,18 +81,19 @@ const INSTANTIATING = {};
|
|
|
82
81
|
|
|
83
82
|
/**
|
|
84
83
|
*
|
|
85
|
-
* @param {
|
|
86
|
-
* @param {
|
|
87
|
-
* @returns {import("
|
|
84
|
+
* @param {Array<String|Function>} modulesToLoad
|
|
85
|
+
* @param {boolean} [strictDi]
|
|
86
|
+
* @returns {import("../../types").InjectorService}
|
|
88
87
|
*/
|
|
89
|
-
export function createInjector(modulesToLoad, strictDi) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
strictDi = !!strictDi;
|
|
94
|
-
|
|
88
|
+
export function createInjector(modulesToLoad, strictDi = false) {
|
|
89
|
+
assert(Array.isArray(modulesToLoad), "modules required");
|
|
90
|
+
assert(isBoolean(strictDi));
|
|
91
|
+
/** @type {Array<string>} */
|
|
95
92
|
const path = [];
|
|
96
|
-
|
|
93
|
+
|
|
94
|
+
/** @type {Map<String|Function, boolean>} */
|
|
95
|
+
const loadedModules = new Map(); // Keep track of loaded modules to avoid circular dependencies
|
|
96
|
+
|
|
97
97
|
const providerCache = {
|
|
98
98
|
$provide: {
|
|
99
99
|
provider: supportObject(provider),
|
|
@@ -105,21 +105,22 @@ export function createInjector(modulesToLoad, strictDi) {
|
|
|
105
105
|
},
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
providerCache.$injector = createInternalInjector(
|
|
109
109
|
providerCache,
|
|
110
|
-
function (
|
|
110
|
+
function (caller) {
|
|
111
111
|
if (isString(caller)) {
|
|
112
112
|
path.push(caller);
|
|
113
113
|
}
|
|
114
114
|
throw $injectorMinErr("unpr", "Unknown provider: {0}", path.join(" <- "));
|
|
115
115
|
},
|
|
116
|
-
)
|
|
116
|
+
);
|
|
117
|
+
|
|
117
118
|
const instanceCache = {};
|
|
118
119
|
|
|
119
120
|
let protoInstanceInjector = createInternalInjector(
|
|
120
121
|
instanceCache,
|
|
121
122
|
(serviceName, caller) => {
|
|
122
|
-
const provider =
|
|
123
|
+
const provider = providerCache.$injector.get(
|
|
123
124
|
serviceName + providerSuffix,
|
|
124
125
|
caller,
|
|
125
126
|
);
|
|
@@ -136,8 +137,9 @@ export function createInjector(modulesToLoad, strictDi) {
|
|
|
136
137
|
$get: valueFn(protoInstanceInjector),
|
|
137
138
|
};
|
|
138
139
|
let instanceInjector = protoInstanceInjector;
|
|
139
|
-
instanceInjector.modules =
|
|
140
|
-
|
|
140
|
+
instanceInjector.modules = providerCache.$injector.modules =
|
|
141
|
+
Object.create(null);
|
|
142
|
+
const runBlocks = loadModules(modulesToLoad);
|
|
141
143
|
instanceInjector = protoInstanceInjector.get("$injector");
|
|
142
144
|
instanceInjector.strictDi = strictDi;
|
|
143
145
|
runBlocks.forEach((fn) => {
|
|
@@ -159,26 +161,28 @@ export function createInjector(modulesToLoad, strictDi) {
|
|
|
159
161
|
function supportObject(delegate) {
|
|
160
162
|
return function (key, value) {
|
|
161
163
|
if (isObject(key)) {
|
|
162
|
-
forEach(
|
|
164
|
+
Object.entries(key).forEach(([k, v]) => {
|
|
165
|
+
delegate(k, v);
|
|
166
|
+
});
|
|
163
167
|
} else {
|
|
164
168
|
return delegate(key, value);
|
|
165
169
|
}
|
|
166
170
|
};
|
|
167
171
|
}
|
|
168
172
|
|
|
169
|
-
function provider(name,
|
|
173
|
+
function provider(name, provider) {
|
|
170
174
|
assertNotHasOwnProperty(name, "service");
|
|
171
|
-
if (isFunction(
|
|
172
|
-
|
|
175
|
+
if (isFunction(provider) || Array.isArray(provider)) {
|
|
176
|
+
provider = providerCache.$injector.instantiate(provider);
|
|
173
177
|
}
|
|
174
|
-
if (!
|
|
178
|
+
if (!provider.$get) {
|
|
175
179
|
throw $injectorMinErr(
|
|
176
180
|
"pget",
|
|
177
181
|
"Provider '{0}' must define $get factory method.",
|
|
178
182
|
name,
|
|
179
183
|
);
|
|
180
184
|
}
|
|
181
|
-
return (providerCache[name + providerSuffix] =
|
|
185
|
+
return (providerCache[name + providerSuffix] = provider);
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
function enforceReturnValue(name, factory) {
|
|
@@ -221,7 +225,9 @@ export function createInjector(modulesToLoad, strictDi) {
|
|
|
221
225
|
}
|
|
222
226
|
|
|
223
227
|
function decorator(serviceName, decorFn) {
|
|
224
|
-
const origProvider =
|
|
228
|
+
const origProvider = providerCache.$injector.get(
|
|
229
|
+
serviceName + providerSuffix,
|
|
230
|
+
);
|
|
225
231
|
const orig$get = origProvider.$get;
|
|
226
232
|
|
|
227
233
|
origProvider.$get = function () {
|
|
@@ -235,6 +241,11 @@ export function createInjector(modulesToLoad, strictDi) {
|
|
|
235
241
|
////////////////////////////////////
|
|
236
242
|
// Module Loading
|
|
237
243
|
////////////////////////////////////
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* @param {Array<String|Function>} modulesToLoad
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
238
249
|
function loadModules(modulesToLoad) {
|
|
239
250
|
assertArg(
|
|
240
251
|
isUndefined(modulesToLoad) || Array.isArray(modulesToLoad),
|
|
@@ -242,34 +253,36 @@ export function createInjector(modulesToLoad, strictDi) {
|
|
|
242
253
|
"not an array",
|
|
243
254
|
);
|
|
244
255
|
let runBlocks = [];
|
|
245
|
-
|
|
246
|
-
forEach(
|
|
256
|
+
|
|
257
|
+
modulesToLoad.forEach((module) => {
|
|
247
258
|
if (loadedModules.get(module)) return;
|
|
248
259
|
loadedModules.set(module, true);
|
|
249
260
|
|
|
261
|
+
/**
|
|
262
|
+
*
|
|
263
|
+
* @param {Array<Array<any>>} queue
|
|
264
|
+
*/
|
|
250
265
|
function runInvokeQueue(queue) {
|
|
251
266
|
queue.forEach((invokeArgs) => {
|
|
252
|
-
const provider =
|
|
267
|
+
const provider = providerCache.$injector.get(invokeArgs[0]);
|
|
253
268
|
provider[invokeArgs[1]].apply(provider, invokeArgs[2]);
|
|
254
269
|
});
|
|
255
270
|
}
|
|
256
271
|
|
|
257
272
|
try {
|
|
258
273
|
if (isString(module)) {
|
|
259
|
-
|
|
274
|
+
/** @type {import('./ng-module').NgModule} */
|
|
275
|
+
let moduleFn = window["angular"].module(module);
|
|
260
276
|
instanceInjector.modules[module] = moduleFn;
|
|
261
277
|
runBlocks = runBlocks
|
|
262
278
|
.concat(loadModules(moduleFn.requires))
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
runInvokeQueue(moduleFn._invokeQueue);
|
|
267
|
-
// @ts-ignore
|
|
268
|
-
runInvokeQueue(moduleFn._configBlocks);
|
|
279
|
+
.concat(moduleFn.runBlocks);
|
|
280
|
+
runInvokeQueue(moduleFn.invokeQueue);
|
|
281
|
+
runInvokeQueue(moduleFn.configBlocks);
|
|
269
282
|
} else if (isFunction(module)) {
|
|
270
|
-
runBlocks.push(
|
|
283
|
+
runBlocks.push(providerCache.$injector.invoke(module));
|
|
271
284
|
} else if (Array.isArray(module)) {
|
|
272
|
-
runBlocks.push(
|
|
285
|
+
runBlocks.push(providerCache.$injector.invoke(module));
|
|
273
286
|
} else {
|
|
274
287
|
assertArgFn(module, "module");
|
|
275
288
|
}
|
|
@@ -283,7 +296,7 @@ export function createInjector(modulesToLoad, strictDi) {
|
|
|
283
296
|
// So if stack doesn't contain message, we create a new string that contains both.
|
|
284
297
|
// Since error.stack is read-only in Safari, I'm overriding e and not e.stack here.
|
|
285
298
|
|
|
286
|
-
e = `${e.message}\n${e.stack}`;
|
|
299
|
+
e.message = `${e.message}\n${e.stack}`;
|
|
287
300
|
}
|
|
288
301
|
throw $injectorMinErr(
|
|
289
302
|
"modulerr",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Angular } from "
|
|
1
|
+
import { Angular } from "../../loader";
|
|
2
2
|
import { createInjector } from "./injector";
|
|
3
|
-
import { valueFn, extend } from "
|
|
3
|
+
import { valueFn, extend } from "../../shared/utils";
|
|
4
4
|
|
|
5
5
|
describe("injector.modules", () => {
|
|
6
6
|
beforeEach(() => {
|
|
@@ -13,7 +13,7 @@ describe("injector.modules", () => {
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it("should have $injector", () => {
|
|
16
|
-
const $injector = createInjector();
|
|
16
|
+
const $injector = createInjector([]);
|
|
17
17
|
expect($injector.get("$injector")).toBe($injector);
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -274,7 +274,7 @@ describe("injector.modules", () => {
|
|
|
274
274
|
expect(injector.invoke(fn)).toBe(3);
|
|
275
275
|
});
|
|
276
276
|
|
|
277
|
-
it("invokes
|
|
277
|
+
it("invokes a class with static property with dependency injection", () => {
|
|
278
278
|
const module = angular.module("myModule", []);
|
|
279
279
|
module.constant("a", 1);
|
|
280
280
|
module.constant("b", 2);
|
|
@@ -288,6 +288,20 @@ describe("injector.modules", () => {
|
|
|
288
288
|
expect(injector.invoke(Foo).c).toBe(3);
|
|
289
289
|
});
|
|
290
290
|
|
|
291
|
+
it("invokes an annotated class with dependency injection", () => {
|
|
292
|
+
const module = angular.module("myModule", []);
|
|
293
|
+
module.constant("a", 1);
|
|
294
|
+
module.constant("b", 2);
|
|
295
|
+
const injector = createInjector(["myModule"]);
|
|
296
|
+
class Foo {
|
|
297
|
+
constructor(a, b) {
|
|
298
|
+
this.c = a + b;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
Foo.$inject = ["a", "b"];
|
|
302
|
+
expect(injector.invoke(Foo).c).toBe(3);
|
|
303
|
+
});
|
|
304
|
+
|
|
291
305
|
it("does not accept non-strings as injection tokens", () => {
|
|
292
306
|
const module = angular.module("myModule", []);
|
|
293
307
|
module.constant("a", 1);
|
|
@@ -325,7 +339,7 @@ describe("injector.modules", () => {
|
|
|
325
339
|
return one + this.two;
|
|
326
340
|
},
|
|
327
341
|
};
|
|
328
|
-
|
|
342
|
+
expect(injector.invoke(["a", obj.fn], obj)).toBe(3);
|
|
329
343
|
});
|
|
330
344
|
|
|
331
345
|
it("overrides dependencies with locals when invoking", () => {
|
|
@@ -392,7 +406,6 @@ describe("annotate", () => {
|
|
|
392
406
|
|
|
393
407
|
it("should create $inject", () => {
|
|
394
408
|
const extraParams = () => {};
|
|
395
|
-
/* eslint-disable space-before-function-paren */
|
|
396
409
|
// keep the multi-line to make sure we can handle it
|
|
397
410
|
function $f_n0 /*
|
|
398
411
|
*/(
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { test, expect } from "@playwright/test";
|
|
2
|
+
|
|
3
|
+
const TEST_URL = "src/core/di/injector.html";
|
|
4
|
+
|
|
5
|
+
test("unit tests contain no errors", async ({ page }) => {
|
|
6
|
+
await page.goto(TEST_URL);
|
|
7
|
+
await page.content();
|
|
8
|
+
await page.waitForTimeout(5000);
|
|
9
|
+
await expect(page.locator(".jasmine-overall-result")).toHaveText(
|
|
10
|
+
/0 failures/,
|
|
11
|
+
);
|
|
12
|
+
});
|
|
@@ -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/ng-module.spec.js"></script>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<div id="dummy"></div>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
isFunction,
|
|
3
|
+
isDefined,
|
|
4
|
+
isObject,
|
|
5
|
+
isString,
|
|
6
|
+
assert,
|
|
7
|
+
} from "../../shared/utils";
|
|
8
|
+
|
|
9
|
+
export const PROVIDE_LITERAL = "$provide";
|
|
10
|
+
export const INJECTOR_LITERAL = "$injector";
|
|
11
|
+
export const COMPILE_LITERAL = "$compileProvider";
|
|
12
|
+
export const ANIMATION_LITERAL = "$animateProvider";
|
|
13
|
+
export const FILTER_LITERAL = "$filterProvider";
|
|
14
|
+
export const CONTROLLER_LITERAL = "$controllerProvider";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Modules are collections of application configuration information for components:
|
|
18
|
+
* controllers, directives, filters, etc. They provide recipes for the injector
|
|
19
|
+
* to do the actual instantiation. A module itself has no behaviour but only state.
|
|
20
|
+
* A such, it acts as a data structure between the Angular instance and the injector service.
|
|
21
|
+
*
|
|
22
|
+
* Since this is an internal structure that is exposed only via the Angular instance,
|
|
23
|
+
* it contains no validation of the items it receives. It is up to the instantiator on
|
|
24
|
+
* modules to do the actual validation.
|
|
25
|
+
*/
|
|
5
26
|
export class NgModule {
|
|
6
27
|
/**
|
|
7
28
|
*
|
|
@@ -10,6 +31,8 @@ export class NgModule {
|
|
|
10
31
|
* @param {Function} [configFn]
|
|
11
32
|
*/
|
|
12
33
|
constructor(name, requires, configFn) {
|
|
34
|
+
assert(isString(name), "name required");
|
|
35
|
+
assert(Array.isArray(requires), "requires array required");
|
|
13
36
|
/**
|
|
14
37
|
* @type {string}
|
|
15
38
|
* Name of the module.
|
|
@@ -21,16 +44,17 @@ export class NgModule {
|
|
|
21
44
|
*/
|
|
22
45
|
this.requires = requires;
|
|
23
46
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Holds a collection of tasks, required to instantiate an angular component
|
|
49
|
+
* @type {!Array<Array<*>>}
|
|
50
|
+
*/
|
|
51
|
+
this.invokeQueue = [];
|
|
28
52
|
|
|
29
|
-
/** @type {!Array
|
|
30
|
-
this.
|
|
53
|
+
/** @type {!Array<Array<*>>} */
|
|
54
|
+
this.configBlocks = [];
|
|
31
55
|
|
|
32
56
|
/** @type {!Array.<Function>} */
|
|
33
|
-
this.
|
|
57
|
+
this.runBlocks = [];
|
|
34
58
|
|
|
35
59
|
/** @type {Object} */
|
|
36
60
|
this.infoState = {};
|
|
@@ -41,14 +65,12 @@ export class NgModule {
|
|
|
41
65
|
}
|
|
42
66
|
|
|
43
67
|
/**
|
|
44
|
-
*
|
|
45
68
|
* @param {Object} value
|
|
46
69
|
* @returns
|
|
47
70
|
*/
|
|
48
71
|
info(value) {
|
|
49
72
|
if (isDefined(value)) {
|
|
50
|
-
|
|
51
|
-
throw ngMinErr("aobj", "Argument '{0}' must be an object", "value");
|
|
73
|
+
assert(isObject(value), "module info value must be an object");
|
|
52
74
|
this.infoState = value;
|
|
53
75
|
return this;
|
|
54
76
|
}
|
|
@@ -61,7 +83,7 @@ export class NgModule {
|
|
|
61
83
|
* @returns {NgModule}
|
|
62
84
|
*/
|
|
63
85
|
value(name, object) {
|
|
64
|
-
this.
|
|
86
|
+
this.invokeQueue.push([PROVIDE_LITERAL, "value", [name, object]]);
|
|
65
87
|
return this;
|
|
66
88
|
}
|
|
67
89
|
|
|
@@ -71,17 +93,22 @@ export class NgModule {
|
|
|
71
93
|
* @returns {NgModule}
|
|
72
94
|
*/
|
|
73
95
|
constant(name, object) {
|
|
74
|
-
this.
|
|
96
|
+
this.invokeQueue.unshift([PROVIDE_LITERAL, "constant", [name, object]]);
|
|
75
97
|
return this;
|
|
76
98
|
}
|
|
77
99
|
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param {Function} configFn
|
|
103
|
+
* @returns {NgModule}
|
|
104
|
+
*/
|
|
78
105
|
config(configFn) {
|
|
79
|
-
this.
|
|
106
|
+
this.configBlocks.push([INJECTOR_LITERAL, "invoke", [configFn]]);
|
|
80
107
|
return this;
|
|
81
108
|
}
|
|
82
109
|
|
|
83
110
|
run(block) {
|
|
84
|
-
this.
|
|
111
|
+
this.runBlocks.push(block);
|
|
85
112
|
return this;
|
|
86
113
|
}
|
|
87
114
|
|
|
@@ -89,7 +116,7 @@ export class NgModule {
|
|
|
89
116
|
if (options && isFunction(options)) {
|
|
90
117
|
options.$$moduleName = name;
|
|
91
118
|
}
|
|
92
|
-
this.
|
|
119
|
+
this.invokeQueue.push([COMPILE_LITERAL, "component", [name, options]]);
|
|
93
120
|
return this;
|
|
94
121
|
}
|
|
95
122
|
|
|
@@ -97,7 +124,11 @@ export class NgModule {
|
|
|
97
124
|
if (providerFunction && isFunction(providerFunction)) {
|
|
98
125
|
providerFunction.$$moduleName = name;
|
|
99
126
|
}
|
|
100
|
-
this.
|
|
127
|
+
this.invokeQueue.push([
|
|
128
|
+
PROVIDE_LITERAL,
|
|
129
|
+
"factory",
|
|
130
|
+
[name, providerFunction],
|
|
131
|
+
]);
|
|
101
132
|
return this;
|
|
102
133
|
}
|
|
103
134
|
|
|
@@ -105,7 +136,11 @@ export class NgModule {
|
|
|
105
136
|
if (serviceFunction && isFunction(serviceFunction)) {
|
|
106
137
|
serviceFunction.$$moduleName = name;
|
|
107
138
|
}
|
|
108
|
-
this.
|
|
139
|
+
this.invokeQueue.push([
|
|
140
|
+
PROVIDE_LITERAL,
|
|
141
|
+
"service",
|
|
142
|
+
[name, serviceFunction],
|
|
143
|
+
]);
|
|
109
144
|
return this;
|
|
110
145
|
}
|
|
111
146
|
|
|
@@ -113,7 +148,7 @@ export class NgModule {
|
|
|
113
148
|
if (providerType && isFunction(providerType)) {
|
|
114
149
|
providerType.$$moduleName = name;
|
|
115
150
|
}
|
|
116
|
-
this.
|
|
151
|
+
this.invokeQueue.push([PROVIDE_LITERAL, "provider", [name, providerType]]);
|
|
117
152
|
return this;
|
|
118
153
|
}
|
|
119
154
|
|
|
@@ -121,7 +156,7 @@ export class NgModule {
|
|
|
121
156
|
if (decorFn && isFunction(decorFn)) {
|
|
122
157
|
decorFn.$$moduleName = name;
|
|
123
158
|
}
|
|
124
|
-
this.
|
|
159
|
+
this.configBlocks.push([PROVIDE_LITERAL, "decorator", [name, decorFn]]);
|
|
125
160
|
return this;
|
|
126
161
|
}
|
|
127
162
|
|
|
@@ -129,8 +164,8 @@ export class NgModule {
|
|
|
129
164
|
if (directiveFactory && isFunction(directiveFactory)) {
|
|
130
165
|
directiveFactory.$$moduleName = name;
|
|
131
166
|
}
|
|
132
|
-
this.
|
|
133
|
-
|
|
167
|
+
this.invokeQueue.push([
|
|
168
|
+
COMPILE_LITERAL,
|
|
134
169
|
"directive",
|
|
135
170
|
[name, directiveFactory],
|
|
136
171
|
]);
|
|
@@ -141,8 +176,8 @@ export class NgModule {
|
|
|
141
176
|
if (animationFactory && isFunction(animationFactory)) {
|
|
142
177
|
animationFactory.$$moduleName = name;
|
|
143
178
|
}
|
|
144
|
-
this.
|
|
145
|
-
|
|
179
|
+
this.invokeQueue.push([
|
|
180
|
+
ANIMATION_LITERAL,
|
|
146
181
|
"register",
|
|
147
182
|
[name, animationFactory],
|
|
148
183
|
]);
|
|
@@ -153,7 +188,7 @@ export class NgModule {
|
|
|
153
188
|
if (filterFn && isFunction(filterFn)) {
|
|
154
189
|
filterFn.$$moduleName = name;
|
|
155
190
|
}
|
|
156
|
-
this.
|
|
191
|
+
this.invokeQueue.push([FILTER_LITERAL, "register", [name, filterFn]]);
|
|
157
192
|
return this;
|
|
158
193
|
}
|
|
159
194
|
|
|
@@ -161,7 +196,7 @@ export class NgModule {
|
|
|
161
196
|
if (ctlFn && isFunction(ctlFn)) {
|
|
162
197
|
ctlFn.$$moduleName = name;
|
|
163
198
|
}
|
|
164
|
-
this.
|
|
199
|
+
this.invokeQueue.push([CONTROLLER_LITERAL, "register", [name, ctlFn]]);
|
|
165
200
|
return this;
|
|
166
201
|
}
|
|
167
202
|
}
|