static-injector 2.0.0 → 2.1.1
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/import/commonjs/index.js +425 -163
- package/import/es2015/di/create_injector.js +5 -1
- package/import/es2015/di/forward_ref.js +3 -3
- package/import/es2015/di/injection_token.js +18 -11
- package/import/es2015/di/injector_compatibility.js +19 -10
- package/import/es2015/di/injector_token.js +3 -3
- package/import/es2015/di/interface/defs.js +21 -12
- package/import/es2015/di/interface/provider.js +3 -1
- package/import/es2015/di/null_injector.js +3 -3
- package/import/es2015/di/provider_collection.js +196 -1
- package/import/es2015/di/r3_injector.js +31 -28
- package/import/es2015/error_details_base_url.js +19 -0
- package/import/es2015/errors.js +42 -0
- package/import/es2015/interface/type.js +14 -1
- package/import/es2015/render3/definition_factory.js +2 -3
- package/import/es2015/render3/errors_di.js +2 -3
- package/import/es2015/render3/instructions/di.js +0 -7
- package/import/es2015/render3/util/stringify_utils.js +5 -5
- package/import/es2015/util/array_utils.js +0 -7
- package/import/es2015/util/decorators.js +24 -1
- package/import/es2015/util/empty.js +4 -0
- package/import/es2015/util/stringify.js +5 -5
- package/import/fesm2015/index.js +422 -161
- package/import/typings/di/forward_ref.d.ts +1 -1
- package/import/typings/di/injectable.d.ts +5 -4
- package/import/typings/di/injection_token.d.ts +21 -6
- package/import/typings/di/injector.d.ts +16 -0
- package/import/typings/di/injector_compatibility.d.ts +11 -5
- package/import/typings/di/injector_token.d.ts +2 -2
- package/import/typings/di/interface/defs.d.ts +15 -8
- package/import/typings/di/interface/provider.d.ts +62 -2
- package/import/typings/di/null_injector.d.ts +1 -1
- package/import/typings/di/provider_collection.d.ts +55 -2
- package/import/typings/di/provider_token.d.ts +3 -3
- package/import/typings/di/r3_injector.d.ts +3 -8
- package/import/typings/di/scope.d.ts +1 -1
- package/import/typings/error_details_base_url.d.ts +19 -0
- package/import/typings/errors.d.ts +89 -0
- package/import/typings/interface/type.d.ts +45 -0
- package/import/typings/render3/definition_factory.d.ts +1 -1
- package/import/typings/render3/errors_di.d.ts +7 -0
- package/import/typings/render3/instructions/di.d.ts +0 -7
- package/import/typings/util/array_utils.d.ts +15 -7
- package/import/typings/util/decorators.d.ts +2 -1
- package/import/typings/util/empty.d.ts +1 -0
- package/package.json +3 -3
- package/transform/compiler/compiler.d.ts +8 -0
- package/transform/compiler/compiler.js +28 -0
- package/transform/compiler/index.d.ts +8 -5
- package/transform/compiler/index.js +12 -5
- package/transform/compiler/public_api.d.ts +13 -0
- package/transform/compiler/public_api.js +30 -0
- package/transform/compiler/src/compiler.d.ts +27 -0
- package/transform/compiler/src/compiler.js +47 -0
- package/transform/compiler/src/output/output_ast.d.ts +1 -1
- package/transform/compiler/src/render3/partial/api.d.ts +1 -1
- package/transform/compiler/src/render3/partial/api.js +7 -0
- package/transform/compiler/src/render3/r3_factory.d.ts +8 -15
- package/transform/compiler/src/render3/r3_factory.js +37 -56
- package/transform/compiler/src/render3/view/util.d.ts +0 -8
- package/transform/compiler/src/render3/view/util.js +0 -8
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +10 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +26 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +37 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +197 -0
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.d.ts +3 -3
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.js +2 -2
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +3 -34
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +18 -216
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +31 -50
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +19 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/default.js +28 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +10 -3
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +12 -13
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +7 -28
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +17 -41
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +46 -65
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -27
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/transform/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +15 -35
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
- package/transform/compiler-cli/src/ngtsc/translator/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +5 -5
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -24
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +1 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +76 -95
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +20 -126
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +23 -147
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -31
- package/transform/injectable-transform.js +36 -7
|
@@ -6,38 +6,17 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
11
|
};
|
|
32
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
13
|
exports.InjectableDecoratorHandler = void 0;
|
|
34
|
-
const compiler_1 = require("
|
|
35
|
-
const
|
|
14
|
+
const compiler_1 = require("static-injector/transform/compiler");
|
|
15
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
16
|
+
const common_1 = require("../../annotations/common");
|
|
36
17
|
const diagnostics_1 = require("../../diagnostics");
|
|
37
18
|
const reflection_1 = require("../../reflection");
|
|
38
|
-
const
|
|
39
|
-
const util_1 = require("../common/src/util");
|
|
40
|
-
const util_2 = require("../common/src/util");
|
|
19
|
+
const common_2 = require("../common");
|
|
41
20
|
/**
|
|
42
21
|
* Adapts the `compileInjectable` compiler for `@Injectable` decorators to the Ivy compiler.
|
|
43
22
|
*/
|
|
@@ -59,7 +38,7 @@ class InjectableDecoratorHandler {
|
|
|
59
38
|
if (!decorators) {
|
|
60
39
|
return undefined;
|
|
61
40
|
}
|
|
62
|
-
const decorator = (0,
|
|
41
|
+
const decorator = (0, common_2.findAngularDecorator)(decorators, 'Injectable', this.isCore);
|
|
63
42
|
if (decorator !== undefined) {
|
|
64
43
|
return {
|
|
65
44
|
trigger: decorator.node,
|
|
@@ -83,13 +62,15 @@ class InjectableDecoratorHandler {
|
|
|
83
62
|
};
|
|
84
63
|
}
|
|
85
64
|
compileFull(node, analysis) {
|
|
86
|
-
return this.compile(
|
|
65
|
+
return this.compile(common_2.compileNgFactoryDefField, (meta) => (0, compiler_1.compileInjectable)(meta, false), node, analysis);
|
|
87
66
|
}
|
|
88
67
|
compile(compileFactoryFn, compileInjectableFn, node, analysis) {
|
|
89
68
|
const results = [];
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
69
|
+
if (true) {
|
|
70
|
+
const meta = analysis.meta;
|
|
71
|
+
const factoryRes = compileFactoryFn((0, common_2.toFactoryMetadata)(Object.assign(Object.assign({}, meta), { deps: analysis.ctorDeps }), compiler_1.FactoryTarget.Injectable));
|
|
72
|
+
results.push(factoryRes);
|
|
73
|
+
}
|
|
93
74
|
const ɵprov = this.reflector
|
|
94
75
|
.getMembersOfClass(node)
|
|
95
76
|
.find((member) => member.name === 'ɵprov');
|
|
@@ -118,7 +99,7 @@ exports.InjectableDecoratorHandler = InjectableDecoratorHandler;
|
|
|
118
99
|
*/
|
|
119
100
|
function extractInjectableMetadata(clazz, decorator, reflector) {
|
|
120
101
|
const name = clazz.name.text;
|
|
121
|
-
const type = (0,
|
|
102
|
+
const type = (0, common_2.wrapTypeReference)(reflector, clazz);
|
|
122
103
|
const internalType = new compiler_1.WrappedNodeExpr(reflector.getInternalNameOfClass(clazz));
|
|
123
104
|
const typeArgumentCount = reflector.getGenericArityOfClass(clazz) || 0;
|
|
124
105
|
if (decorator.args === null) {
|
|
@@ -138,7 +119,7 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
|
|
|
138
119
|
// Firstly make sure the decorator argument is an inline literal - if not, it's illegal to
|
|
139
120
|
// transport references from one location to another. This is the problem that lowering
|
|
140
121
|
// used to solve - if this restriction proves too undesirable we can re-implement lowering.
|
|
141
|
-
if (!
|
|
122
|
+
if (!typescript_1.default.isObjectLiteralExpression(metaNode)) {
|
|
142
123
|
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARG_NOT_LITERAL, metaNode, `@Injectable argument must be an object literal`);
|
|
143
124
|
}
|
|
144
125
|
// Resolve the fields of the literal into a map of field name to expression.
|
|
@@ -149,7 +130,7 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
|
|
|
149
130
|
let deps = undefined;
|
|
150
131
|
if ((meta.has('useClass') || meta.has('useFactory')) && meta.has('deps')) {
|
|
151
132
|
const depsExpr = meta.get('deps');
|
|
152
|
-
if (!
|
|
133
|
+
if (!typescript_1.default.isArrayLiteralExpression(depsExpr)) {
|
|
153
134
|
throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_NOT_LITERAL, depsExpr, `@Injectable deps metadata must be an inline array`);
|
|
154
135
|
}
|
|
155
136
|
deps = depsExpr.elements.map((dep) => getDep(dep, reflector));
|
|
@@ -189,7 +170,7 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
|
|
|
189
170
|
* object to indicate whether the value needed unwrapping.
|
|
190
171
|
*/
|
|
191
172
|
function getProviderExpression(expression, reflector) {
|
|
192
|
-
const forwardRefValue = (0,
|
|
173
|
+
const forwardRefValue = (0, common_2.tryUnwrapForwardRef)(expression, reflector);
|
|
193
174
|
return (0, compiler_1.createMayBeForwardRefExpression)(new compiler_1.WrappedNodeExpr(forwardRefValue !== null && forwardRefValue !== void 0 ? forwardRefValue : expression), forwardRefValue !== null
|
|
194
175
|
? 2 /* ForwardRefHandling.Unwrapped */
|
|
195
176
|
: 0 /* ForwardRefHandling.None */);
|
|
@@ -208,25 +189,25 @@ function extractInjectableCtorDeps(clazz, meta, decorator, reflector, isCore, st
|
|
|
208
189
|
// To deal with this, @Injectable() without an argument is more lenient, and if the
|
|
209
190
|
// constructor signature does not work for DI then a factory definition (ɵfac) that throws is
|
|
210
191
|
// generated.
|
|
211
|
-
if (strictCtorDeps) {
|
|
212
|
-
ctorDeps = (0,
|
|
192
|
+
if (strictCtorDeps && !(0, common_1.isAbstractClassDeclaration)(clazz)) {
|
|
193
|
+
ctorDeps = (0, common_2.getValidConstructorDependencies)(clazz, reflector, isCore);
|
|
213
194
|
}
|
|
214
195
|
else {
|
|
215
|
-
ctorDeps = (0,
|
|
196
|
+
ctorDeps = (0, common_2.unwrapConstructorDependencies)((0, common_2.getConstructorDependencies)(clazz, reflector, isCore));
|
|
216
197
|
}
|
|
217
198
|
return ctorDeps;
|
|
218
199
|
}
|
|
219
200
|
else if (decorator.args.length === 1) {
|
|
220
|
-
const rawCtorDeps = (0,
|
|
201
|
+
const rawCtorDeps = (0, common_2.getConstructorDependencies)(clazz, reflector, isCore);
|
|
221
202
|
if (strictCtorDeps &&
|
|
222
|
-
!(0,
|
|
203
|
+
!(0, common_1.isAbstractClassDeclaration)(clazz) &&
|
|
223
204
|
requiresValidCtor(meta)) {
|
|
224
205
|
// Since use* was not provided for a concrete class, validate the deps according to
|
|
225
206
|
// strictCtorDeps.
|
|
226
|
-
ctorDeps = (0,
|
|
207
|
+
ctorDeps = (0, common_2.validateConstructorDependencies)(clazz, rawCtorDeps);
|
|
227
208
|
}
|
|
228
209
|
else {
|
|
229
|
-
ctorDeps = (0,
|
|
210
|
+
ctorDeps = (0, common_2.unwrapConstructorDependencies)(rawCtorDeps);
|
|
230
211
|
}
|
|
231
212
|
}
|
|
232
213
|
return ctorDeps;
|
|
@@ -270,18 +251,18 @@ function getDep(dep, reflector) {
|
|
|
270
251
|
}
|
|
271
252
|
return true;
|
|
272
253
|
}
|
|
273
|
-
if (
|
|
254
|
+
if (typescript_1.default.isArrayLiteralExpression(dep)) {
|
|
274
255
|
dep.elements.forEach((el) => {
|
|
275
|
-
let
|
|
276
|
-
if (
|
|
277
|
-
|
|
256
|
+
let isDecorator = false;
|
|
257
|
+
if (typescript_1.default.isIdentifier(el)) {
|
|
258
|
+
isDecorator = maybeUpdateDecorator(el, reflector);
|
|
278
259
|
}
|
|
279
|
-
else if (
|
|
260
|
+
else if (typescript_1.default.isNewExpression(el) && typescript_1.default.isIdentifier(el.expression)) {
|
|
280
261
|
const token = (el.arguments && el.arguments.length > 0 && el.arguments[0]) ||
|
|
281
262
|
undefined;
|
|
282
|
-
|
|
263
|
+
isDecorator = maybeUpdateDecorator(el.expression, reflector, token);
|
|
283
264
|
}
|
|
284
|
-
if (!
|
|
265
|
+
if (!isDecorator) {
|
|
285
266
|
meta.token = new compiler_1.WrappedNodeExpr(el);
|
|
286
267
|
}
|
|
287
268
|
});
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
export * from './error';
|
|
9
|
+
export * from './error_code';
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { WrappedNodeExpr } from 'static-injector/transform/compiler';
|
|
9
|
+
import ts from 'typescript';
|
|
10
|
+
/**
|
|
11
|
+
* Attaches a default import declaration to `expr` to indicate the dependency of `expr` on the
|
|
12
|
+
* default import.
|
|
13
|
+
*/
|
|
14
|
+
export declare function attachDefaultImportDeclaration(expr: WrappedNodeExpr<unknown>, importDecl: ts.ImportDeclaration): void;
|
|
15
|
+
/**
|
|
16
|
+
* Obtains the default import declaration that `expr` depends on, or `null` if there is no such
|
|
17
|
+
* dependency.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getDefaultImportDeclaration(expr: WrappedNodeExpr<unknown>): ts.ImportDeclaration | null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.getDefaultImportDeclaration = exports.attachDefaultImportDeclaration = void 0;
|
|
11
|
+
const DefaultImportDeclaration = Symbol('DefaultImportDeclaration');
|
|
12
|
+
/**
|
|
13
|
+
* Attaches a default import declaration to `expr` to indicate the dependency of `expr` on the
|
|
14
|
+
* default import.
|
|
15
|
+
*/
|
|
16
|
+
function attachDefaultImportDeclaration(expr, importDecl) {
|
|
17
|
+
expr[DefaultImportDeclaration] = importDecl;
|
|
18
|
+
}
|
|
19
|
+
exports.attachDefaultImportDeclaration = attachDefaultImportDeclaration;
|
|
20
|
+
/**
|
|
21
|
+
* Obtains the default import declaration that `expr` depends on, or `null` if there is no such
|
|
22
|
+
* dependency.
|
|
23
|
+
*/
|
|
24
|
+
function getDefaultImportDeclaration(expr) {
|
|
25
|
+
var _a;
|
|
26
|
+
return ((_a = expr[DefaultImportDeclaration]) !== null && _a !== void 0 ? _a : null);
|
|
27
|
+
}
|
|
28
|
+
exports.getDefaultImportDeclaration = getDefaultImportDeclaration;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
export * from './src/host';
|
|
9
|
+
export * from './src/typescript';
|
|
10
|
+
export * from './src/util';
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import ts from 'typescript';
|
|
9
9
|
/**
|
|
10
10
|
* Metadata extracted from an instance of a decorator on another declaration, or synthesized from
|
|
11
11
|
* other information about a class.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type Decorator = ConcreteDecorator | SyntheticDecorator;
|
|
14
14
|
export interface BaseDecorator {
|
|
15
15
|
/**
|
|
16
16
|
* Name by which the decorator was invoked in the user's code.
|
|
@@ -68,12 +68,11 @@ export declare const Decorator: {
|
|
|
68
68
|
* A decorator is identified by either a simple identifier (e.g. `Decorator`) or, in some cases,
|
|
69
69
|
* a namespaced property access (e.g. `core.Decorator`).
|
|
70
70
|
*/
|
|
71
|
-
export
|
|
72
|
-
export
|
|
71
|
+
export type DecoratorIdentifier = ts.Identifier | NamespacedIdentifier;
|
|
72
|
+
export type NamespacedIdentifier = ts.PropertyAccessExpression & {
|
|
73
73
|
expression: ts.Identifier;
|
|
74
74
|
name: ts.Identifier;
|
|
75
75
|
};
|
|
76
|
-
/** 装饰器可能是 Injectable或者xx.Injectable */
|
|
77
76
|
export declare function isDecoratorIdentifier(exp: ts.Expression): exp is DecoratorIdentifier;
|
|
78
77
|
/**
|
|
79
78
|
* The `ts.Declaration` of a "class".
|
|
@@ -90,7 +89,7 @@ export declare function isDecoratorIdentifier(exp: ts.Expression): exp is Decora
|
|
|
90
89
|
* For `ReflectionHost` purposes, a class declaration should always have a `name` identifier,
|
|
91
90
|
* because we need to be able to reference it in other parts of the program.
|
|
92
91
|
*/
|
|
93
|
-
export
|
|
92
|
+
export type ClassDeclaration<T extends DeclarationNode = DeclarationNode> = T & {
|
|
94
93
|
name: ts.Identifier;
|
|
95
94
|
};
|
|
96
95
|
/**
|
|
@@ -307,7 +306,7 @@ export interface MissingType {
|
|
|
307
306
|
/**
|
|
308
307
|
* The various reasons why a type node may not be referred to as a value.
|
|
309
308
|
*/
|
|
310
|
-
export
|
|
309
|
+
export type UnavailableValue = UnsupportedType | NoValueDeclaration | TypeOnlyImport | NamespaceImport | UnknownReference | MissingType;
|
|
311
310
|
/**
|
|
312
311
|
* A reference to a value that originated from a type position.
|
|
313
312
|
*
|
|
@@ -317,7 +316,7 @@ export declare type UnavailableValue = UnsupportedType | NoValueDeclaration | Ty
|
|
|
317
316
|
*
|
|
318
317
|
* See the individual types for additional information.
|
|
319
318
|
*/
|
|
320
|
-
export
|
|
319
|
+
export type TypeValueReference = LocalTypeValueReference | ImportedTypeValueReference | UnavailableTypeValueReference;
|
|
321
320
|
/**
|
|
322
321
|
* A parameter to a constructor.
|
|
323
322
|
*/
|
|
@@ -441,7 +440,7 @@ export interface Import {
|
|
|
441
440
|
/**
|
|
442
441
|
* The module from which the symbol was imported.
|
|
443
442
|
*
|
|
444
|
-
* This could either be an absolute module name (
|
|
443
|
+
* This could either be an absolute module name (@angular/core for example) or a relative path.
|
|
445
444
|
*/
|
|
446
445
|
from: string;
|
|
447
446
|
}
|
|
@@ -470,7 +469,7 @@ export interface EnumMember {
|
|
|
470
469
|
* An example of this is `exports.someVar = 42` where the declaration expression would be
|
|
471
470
|
* `exports.someVar`.
|
|
472
471
|
*/
|
|
473
|
-
export
|
|
472
|
+
export type DeclarationNode = ts.Declaration | ts.Expression;
|
|
474
473
|
/**
|
|
475
474
|
* The type of a Declaration - whether its node is concrete (ts.Declaration) or inline
|
|
476
475
|
* (ts.Expression). See `ConcreteDeclaration`, `InlineDeclaration` and `DeclarationNode` for more
|
|
@@ -516,7 +515,7 @@ export interface ConcreteDeclaration<T extends ts.Declaration = ts.Declaration>
|
|
|
516
515
|
*/
|
|
517
516
|
identity: SpecialDeclarationIdentity | null;
|
|
518
517
|
}
|
|
519
|
-
export
|
|
518
|
+
export type SpecialDeclarationIdentity = DownleveledEnum;
|
|
520
519
|
export declare const enum SpecialDeclarationKind {
|
|
521
520
|
DownleveledEnum = 0
|
|
522
521
|
}
|
|
@@ -544,7 +543,7 @@ export interface InlineDeclaration extends BaseDeclaration<Exclude<DeclarationNo
|
|
|
544
543
|
* The declaration of a symbol, along with information about how it was imported into the
|
|
545
544
|
* application.
|
|
546
545
|
*/
|
|
547
|
-
export
|
|
546
|
+
export type Declaration<T extends ts.Declaration = ts.Declaration> = ConcreteDeclaration<T> | InlineDeclaration;
|
|
548
547
|
/**
|
|
549
548
|
* Abstracts reflection operations on a TypeScript AST.
|
|
550
549
|
*
|
|
@@ -599,7 +598,7 @@ export interface ReflectionHost {
|
|
|
599
598
|
* Determine if an identifier was imported from another module and return `Import` metadata
|
|
600
599
|
* describing its origin.
|
|
601
600
|
*
|
|
602
|
-
* @param id a TypeScript `ts.
|
|
601
|
+
* @param id a TypeScript `ts.Identifier` to reflect.
|
|
603
602
|
*
|
|
604
603
|
* @returns metadata about the `Import` if the identifier was imported from another module, or
|
|
605
604
|
* `null` if the identifier doesn't resolve to an import but instead is locally defined.
|
|
@@ -6,32 +6,12 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
11
|
};
|
|
32
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
13
|
exports.isConcreteDeclaration = exports.KnownDeclaration = exports.ClassMemberKind = exports.isDecoratorIdentifier = exports.Decorator = void 0;
|
|
34
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
35
15
|
exports.Decorator = {
|
|
36
16
|
nodeForError: (decorator) => {
|
|
37
17
|
if (decorator.node !== null) {
|
|
@@ -43,12 +23,11 @@ exports.Decorator = {
|
|
|
43
23
|
}
|
|
44
24
|
},
|
|
45
25
|
};
|
|
46
|
-
/** 装饰器可能是 Injectable或者xx.Injectable */
|
|
47
26
|
function isDecoratorIdentifier(exp) {
|
|
48
|
-
return (
|
|
49
|
-
(
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
return (typescript_1.default.isIdentifier(exp) ||
|
|
28
|
+
(typescript_1.default.isPropertyAccessExpression(exp) &&
|
|
29
|
+
typescript_1.default.isIdentifier(exp.expression) &&
|
|
30
|
+
typescript_1.default.isIdentifier(exp.name)));
|
|
52
31
|
}
|
|
53
32
|
exports.isDecoratorIdentifier = isDecoratorIdentifier;
|
|
54
33
|
/**
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import ts from 'typescript';
|
|
9
9
|
import { TypeValueReference } from './host';
|
|
10
10
|
/**
|
|
11
11
|
* Potentially convert a `ts.TypeNode` to a `TypeValueReference`, which indicates how to use the
|
|
@@ -6,32 +6,12 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
-
}
|
|
15
|
-
Object.defineProperty(o, k2, desc);
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
11
|
};
|
|
32
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
13
|
exports.typeNodeToValueExpr = exports.typeToValue = void 0;
|
|
34
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
35
15
|
/**
|
|
36
16
|
* Potentially convert a `ts.TypeNode` to a `TypeValueReference`, which indicates how to use the
|
|
37
17
|
* type given in the `ts.TypeNode` in a value position.
|
|
@@ -44,7 +24,7 @@ function typeToValue(typeNode, checker) {
|
|
|
44
24
|
if (typeNode === null) {
|
|
45
25
|
return missingType();
|
|
46
26
|
}
|
|
47
|
-
if (!
|
|
27
|
+
if (!typescript_1.default.isTypeReferenceNode(typeNode)) {
|
|
48
28
|
return unsupportedType(typeNode);
|
|
49
29
|
}
|
|
50
30
|
const symbols = resolveTypeSymbols(typeNode, checker);
|
|
@@ -56,7 +36,7 @@ function typeToValue(typeNode, checker) {
|
|
|
56
36
|
// has a value declaration associated with it. Note that const enums are an exception,
|
|
57
37
|
// because while they do have a value declaration, they don't exist at runtime.
|
|
58
38
|
if (decl.valueDeclaration === undefined ||
|
|
59
|
-
decl.flags &
|
|
39
|
+
decl.flags & typescript_1.default.SymbolFlags.ConstEnum) {
|
|
60
40
|
let typeOnlyDecl = null;
|
|
61
41
|
if (decl.declarations !== undefined && decl.declarations.length > 0) {
|
|
62
42
|
typeOnlyDecl = decl.declarations[0];
|
|
@@ -69,7 +49,7 @@ function typeToValue(typeNode, checker) {
|
|
|
69
49
|
// statement. If so, extract the module specifier and the name of the imported type.
|
|
70
50
|
const firstDecl = local.declarations && local.declarations[0];
|
|
71
51
|
if (firstDecl !== undefined) {
|
|
72
|
-
if (
|
|
52
|
+
if (typescript_1.default.isImportClause(firstDecl) && firstDecl.name !== undefined) {
|
|
73
53
|
// This is a default import.
|
|
74
54
|
// import Foo from 'foo';
|
|
75
55
|
if (firstDecl.isTypeOnly) {
|
|
@@ -82,7 +62,7 @@ function typeToValue(typeNode, checker) {
|
|
|
82
62
|
defaultImportStatement: firstDecl.parent,
|
|
83
63
|
};
|
|
84
64
|
}
|
|
85
|
-
else if (
|
|
65
|
+
else if (typescript_1.default.isImportSpecifier(firstDecl)) {
|
|
86
66
|
// The symbol was imported by name
|
|
87
67
|
// import {Foo} from 'foo';
|
|
88
68
|
// or
|
|
@@ -111,7 +91,7 @@ function typeToValue(typeNode, checker) {
|
|
|
111
91
|
nestedPath,
|
|
112
92
|
};
|
|
113
93
|
}
|
|
114
|
-
else if (
|
|
94
|
+
else if (typescript_1.default.isNamespaceImport(firstDecl)) {
|
|
115
95
|
// The import is a namespace import
|
|
116
96
|
// import * as Foo from 'foo';
|
|
117
97
|
if (firstDecl.parent.isTypeOnly) {
|
|
@@ -165,11 +145,7 @@ function noValueDeclaration(typeNode, decl) {
|
|
|
165
145
|
function typeOnlyImport(typeNode, node) {
|
|
166
146
|
return {
|
|
167
147
|
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
168
|
-
reason: {
|
|
169
|
-
kind: 2 /* ValueUnavailableKind.TYPE_ONLY_IMPORT */,
|
|
170
|
-
typeNode,
|
|
171
|
-
node: node,
|
|
172
|
-
},
|
|
148
|
+
reason: { kind: 2 /* ValueUnavailableKind.TYPE_ONLY_IMPORT */, typeNode, node },
|
|
173
149
|
};
|
|
174
150
|
}
|
|
175
151
|
function unknownReference(typeNode) {
|
|
@@ -197,7 +173,7 @@ function missingType() {
|
|
|
197
173
|
* This will return `null` if an equivalent expression cannot be constructed.
|
|
198
174
|
*/
|
|
199
175
|
function typeNodeToValueExpr(node) {
|
|
200
|
-
if (
|
|
176
|
+
if (typescript_1.default.isTypeReferenceNode(node)) {
|
|
201
177
|
return entityNameToValue(node.typeName);
|
|
202
178
|
}
|
|
203
179
|
else {
|
|
@@ -242,7 +218,7 @@ function resolveTypeSymbols(typeRef, checker) {
|
|
|
242
218
|
// type is not qualified.
|
|
243
219
|
let leftMost = typeName;
|
|
244
220
|
const symbolNames = [];
|
|
245
|
-
while (
|
|
221
|
+
while (typescript_1.default.isQualifiedName(leftMost)) {
|
|
246
222
|
symbolNames.unshift(leftMost.right.text);
|
|
247
223
|
leftMost = leftMost.left;
|
|
248
224
|
}
|
|
@@ -255,20 +231,20 @@ function resolveTypeSymbols(typeRef, checker) {
|
|
|
255
231
|
}
|
|
256
232
|
// De-alias the top-level type reference symbol to get the symbol of the actual declaration.
|
|
257
233
|
let decl = typeRefSymbol;
|
|
258
|
-
if (typeRefSymbol.flags &
|
|
234
|
+
if (typeRefSymbol.flags & typescript_1.default.SymbolFlags.Alias) {
|
|
259
235
|
decl = checker.getAliasedSymbol(typeRefSymbol);
|
|
260
236
|
}
|
|
261
237
|
return { local, decl, symbolNames };
|
|
262
238
|
}
|
|
263
239
|
function entityNameToValue(node) {
|
|
264
|
-
if (
|
|
240
|
+
if (typescript_1.default.isQualifiedName(node)) {
|
|
265
241
|
const left = entityNameToValue(node.left);
|
|
266
242
|
return left !== null
|
|
267
|
-
?
|
|
243
|
+
? typescript_1.default.factory.createPropertyAccessExpression(left, node.right)
|
|
268
244
|
: null;
|
|
269
245
|
}
|
|
270
|
-
else if (
|
|
271
|
-
const clone =
|
|
246
|
+
else if (typescript_1.default.isIdentifier(node)) {
|
|
247
|
+
const clone = typescript_1.default.setOriginalNode(typescript_1.default.factory.createIdentifier(node.text), node);
|
|
272
248
|
clone.parent = node.parent;
|
|
273
249
|
return clone;
|
|
274
250
|
}
|
|
@@ -277,7 +253,7 @@ function entityNameToValue(node) {
|
|
|
277
253
|
}
|
|
278
254
|
}
|
|
279
255
|
function extractModuleName(node) {
|
|
280
|
-
if (!
|
|
256
|
+
if (!typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
|
|
281
257
|
throw new Error('not a module specifier');
|
|
282
258
|
}
|
|
283
259
|
return node.moduleSpecifier.text;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import ts from 'typescript';
|
|
9
9
|
import { ClassDeclaration, ClassMember, CtorParameter, DeclarationNode, Decorator, Import, ReflectionHost } from './host';
|
|
10
10
|
/**
|
|
11
11
|
* reflector.ts implements static reflection of declarations using the TypeScript `ts.TypeChecker`.
|