static-injector 1.0.10 → 2.1.0
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 +337 -124
- package/import/es2015/di/create_injector.js +30 -0
- package/import/es2015/di/initializer_token.js +15 -0
- package/import/es2015/di/inject_switch.js +27 -6
- package/import/es2015/di/injection_token.js +6 -0
- package/import/es2015/di/injector.js +6 -8
- package/import/es2015/di/injector_compatibility.js +90 -34
- package/import/es2015/di/injector_token.js +1 -1
- package/import/es2015/di/interface/defs.js +39 -0
- package/import/es2015/di/interface/injector.js +1 -0
- package/import/es2015/di/internal_tokens.js +9 -0
- package/import/es2015/di/metadata.js +4 -4
- package/import/es2015/di/provider_collection.js +49 -0
- package/import/es2015/di/r3_injector.js +102 -72
- package/import/es2015/di/scope.js +2 -2
- package/import/es2015/index.js +1 -1
- package/import/es2015/render3/errors_di.js +1 -1
- package/import/fesm2015/index.js +328 -114
- package/import/typings/di/create_injector.d.ts +23 -0
- package/import/typings/di/initializer_token.d.ts +15 -0
- package/import/typings/di/inject_switch.d.ts +7 -2
- package/import/typings/{decorator → di}/injectable.d.ts +2 -2
- package/import/typings/di/injection_token.d.ts +4 -0
- package/import/typings/di/injector.d.ts +20 -7
- package/import/typings/di/injector_compatibility.d.ts +42 -21
- package/import/typings/di/interface/defs.d.ts +10 -0
- package/import/typings/di/interface/injector.d.ts +26 -0
- package/import/typings/di/interface/provider.d.ts +3 -8
- package/import/typings/di/internal_tokens.d.ts +10 -0
- package/import/typings/di/provider_collection.d.ts +30 -0
- package/import/typings/di/provider_token.d.ts +1 -1
- package/import/typings/di/r3_injector.d.ts +68 -37
- package/import/typings/di/scope.d.ts +3 -2
- package/import/typings/index.d.ts +1 -1
- package/import/typings/render3/definition_factory.d.ts +1 -1
- package/package.json +5 -3
- package/{import/es2015/decorator/interface/provider.js → transform/compiler/compiler.d.ts} +1 -1
- package/transform/compiler/compiler.js +28 -0
- package/transform/compiler/index.d.ts +8 -5
- package/transform/compiler/index.js +17 -6
- 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/injectable_compiler_2.d.ts +7 -36
- package/transform/compiler/src/injectable_compiler_2.js +20 -23
- package/transform/compiler/src/output/output_ast.d.ts +30 -109
- package/transform/compiler/src/output/output_ast.js +66 -188
- 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 +46 -61
- package/transform/compiler/src/render3/util.d.ts +64 -0
- package/transform/compiler/src/render3/util.js +52 -9
- package/transform/compiler/src/render3/view/util.d.ts +0 -8
- package/transform/compiler/src/render3/view/util.js +5 -9
- 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 +3 -3
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +4 -34
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +181 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +46 -53
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +12 -1
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +12 -1
- 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 +12 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +13 -14
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +8 -25
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +44 -55
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +55 -69
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -23
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/transform/index.js +12 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +16 -31
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
- package/transform/compiler-cli/src/ngtsc/translator/index.js +12 -1
- 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 +4 -4
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +5 -21
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -6
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +6 -18
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +83 -90
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +8 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +45 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +86 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -27
- package/transform/index.js +5 -1
- package/transform/injectable-transform.js +59 -38
- package/import/typings/decorator/interface/provider.d.ts +0 -312
- package/transform/compiler/src/render3/partial/util.d.ts +0 -16
- package/transform/compiler/src/render3/partial/util.js +0 -44
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +0 -370
- /package/import/es2015/{decorator → di}/injectable.js +0 -0
|
@@ -6,28 +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
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
-
}) : function(o, v) {
|
|
19
|
-
o["default"] = v;
|
|
20
|
-
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
11
|
};
|
|
28
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
13
|
exports.typeNodeToValueExpr = exports.typeToValue = void 0;
|
|
30
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
31
15
|
/**
|
|
32
16
|
* Potentially convert a `ts.TypeNode` to a `TypeValueReference`, which indicates how to use the
|
|
33
17
|
* type given in the `ts.TypeNode` in a value position.
|
|
@@ -40,7 +24,7 @@ function typeToValue(typeNode, checker) {
|
|
|
40
24
|
if (typeNode === null) {
|
|
41
25
|
return missingType();
|
|
42
26
|
}
|
|
43
|
-
if (!
|
|
27
|
+
if (!typescript_1.default.isTypeReferenceNode(typeNode)) {
|
|
44
28
|
return unsupportedType(typeNode);
|
|
45
29
|
}
|
|
46
30
|
const symbols = resolveTypeSymbols(typeNode, checker);
|
|
@@ -52,7 +36,7 @@ function typeToValue(typeNode, checker) {
|
|
|
52
36
|
// has a value declaration associated with it. Note that const enums are an exception,
|
|
53
37
|
// because while they do have a value declaration, they don't exist at runtime.
|
|
54
38
|
if (decl.valueDeclaration === undefined ||
|
|
55
|
-
decl.flags &
|
|
39
|
+
decl.flags & typescript_1.default.SymbolFlags.ConstEnum) {
|
|
56
40
|
let typeOnlyDecl = null;
|
|
57
41
|
if (decl.declarations !== undefined && decl.declarations.length > 0) {
|
|
58
42
|
typeOnlyDecl = decl.declarations[0];
|
|
@@ -65,7 +49,7 @@ function typeToValue(typeNode, checker) {
|
|
|
65
49
|
// statement. If so, extract the module specifier and the name of the imported type.
|
|
66
50
|
const firstDecl = local.declarations && local.declarations[0];
|
|
67
51
|
if (firstDecl !== undefined) {
|
|
68
|
-
if (
|
|
52
|
+
if (typescript_1.default.isImportClause(firstDecl) && firstDecl.name !== undefined) {
|
|
69
53
|
// This is a default import.
|
|
70
54
|
// import Foo from 'foo';
|
|
71
55
|
if (firstDecl.isTypeOnly) {
|
|
@@ -73,18 +57,23 @@ function typeToValue(typeNode, checker) {
|
|
|
73
57
|
return typeOnlyImport(typeNode, firstDecl);
|
|
74
58
|
}
|
|
75
59
|
return {
|
|
76
|
-
kind: 0 /* LOCAL */,
|
|
60
|
+
kind: 0 /* TypeValueReferenceKind.LOCAL */,
|
|
77
61
|
expression: firstDecl.name,
|
|
78
62
|
defaultImportStatement: firstDecl.parent,
|
|
79
63
|
};
|
|
80
64
|
}
|
|
81
|
-
else if (
|
|
65
|
+
else if (typescript_1.default.isImportSpecifier(firstDecl)) {
|
|
82
66
|
// The symbol was imported by name
|
|
83
67
|
// import {Foo} from 'foo';
|
|
84
68
|
// or
|
|
85
69
|
// import {Foo as Bar} from 'foo';
|
|
70
|
+
if (firstDecl.isTypeOnly) {
|
|
71
|
+
// The import specifier can't be type-only (e.g. `import {type Foo} from '...')`.
|
|
72
|
+
return typeOnlyImport(typeNode, firstDecl);
|
|
73
|
+
}
|
|
86
74
|
if (firstDecl.parent.parent.isTypeOnly) {
|
|
87
|
-
//
|
|
75
|
+
// The import specifier can't be inside a type-only import clause
|
|
76
|
+
// (e.g. `import type {Foo} from '...')`.
|
|
88
77
|
return typeOnlyImport(typeNode, firstDecl.parent.parent);
|
|
89
78
|
}
|
|
90
79
|
// Determine the name to import (`Foo`) from the import specifier, as the symbol names of
|
|
@@ -95,14 +84,14 @@ function typeToValue(typeNode, checker) {
|
|
|
95
84
|
const [_localName, ...nestedPath] = symbols.symbolNames;
|
|
96
85
|
const moduleName = extractModuleName(firstDecl.parent.parent.parent);
|
|
97
86
|
return {
|
|
98
|
-
kind: 1 /* IMPORTED */,
|
|
87
|
+
kind: 1 /* TypeValueReferenceKind.IMPORTED */,
|
|
99
88
|
valueDeclaration: decl.valueDeclaration,
|
|
100
89
|
moduleName,
|
|
101
90
|
importedName,
|
|
102
91
|
nestedPath,
|
|
103
92
|
};
|
|
104
93
|
}
|
|
105
|
-
else if (
|
|
94
|
+
else if (typescript_1.default.isNamespaceImport(firstDecl)) {
|
|
106
95
|
// The import is a namespace import
|
|
107
96
|
// import * as Foo from 'foo';
|
|
108
97
|
if (firstDecl.parent.isTypeOnly) {
|
|
@@ -119,7 +108,7 @@ function typeToValue(typeNode, checker) {
|
|
|
119
108
|
const [_ns, importedName, ...nestedPath] = symbols.symbolNames;
|
|
120
109
|
const moduleName = extractModuleName(firstDecl.parent.parent);
|
|
121
110
|
return {
|
|
122
|
-
kind: 1 /* IMPORTED */,
|
|
111
|
+
kind: 1 /* TypeValueReferenceKind.IMPORTED */,
|
|
123
112
|
valueDeclaration: decl.valueDeclaration,
|
|
124
113
|
moduleName,
|
|
125
114
|
importedName,
|
|
@@ -131,7 +120,7 @@ function typeToValue(typeNode, checker) {
|
|
|
131
120
|
const expression = typeNodeToValueExpr(typeNode);
|
|
132
121
|
if (expression !== null) {
|
|
133
122
|
return {
|
|
134
|
-
kind: 0 /* LOCAL */,
|
|
123
|
+
kind: 0 /* TypeValueReferenceKind.LOCAL */,
|
|
135
124
|
expression,
|
|
136
125
|
defaultImportStatement: null,
|
|
137
126
|
};
|
|
@@ -143,42 +132,38 @@ function typeToValue(typeNode, checker) {
|
|
|
143
132
|
exports.typeToValue = typeToValue;
|
|
144
133
|
function unsupportedType(typeNode) {
|
|
145
134
|
return {
|
|
146
|
-
kind: 2 /* UNAVAILABLE */,
|
|
147
|
-
reason: { kind: 5 /* UNSUPPORTED */, typeNode },
|
|
135
|
+
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
136
|
+
reason: { kind: 5 /* ValueUnavailableKind.UNSUPPORTED */, typeNode },
|
|
148
137
|
};
|
|
149
138
|
}
|
|
150
139
|
function noValueDeclaration(typeNode, decl) {
|
|
151
140
|
return {
|
|
152
|
-
kind: 2 /* UNAVAILABLE */,
|
|
153
|
-
reason: { kind: 1 /* NO_VALUE_DECLARATION */, typeNode, decl },
|
|
141
|
+
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
142
|
+
reason: { kind: 1 /* ValueUnavailableKind.NO_VALUE_DECLARATION */, typeNode, decl },
|
|
154
143
|
};
|
|
155
144
|
}
|
|
156
|
-
function typeOnlyImport(typeNode,
|
|
145
|
+
function typeOnlyImport(typeNode, node) {
|
|
157
146
|
return {
|
|
158
|
-
kind: 2 /* UNAVAILABLE */,
|
|
159
|
-
reason: {
|
|
160
|
-
kind: 2 /* TYPE_ONLY_IMPORT */,
|
|
161
|
-
typeNode,
|
|
162
|
-
importClause,
|
|
163
|
-
},
|
|
147
|
+
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
148
|
+
reason: { kind: 2 /* ValueUnavailableKind.TYPE_ONLY_IMPORT */, typeNode, node },
|
|
164
149
|
};
|
|
165
150
|
}
|
|
166
151
|
function unknownReference(typeNode) {
|
|
167
152
|
return {
|
|
168
|
-
kind: 2 /* UNAVAILABLE */,
|
|
169
|
-
reason: { kind: 3 /* UNKNOWN_REFERENCE */, typeNode },
|
|
153
|
+
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
154
|
+
reason: { kind: 3 /* ValueUnavailableKind.UNKNOWN_REFERENCE */, typeNode },
|
|
170
155
|
};
|
|
171
156
|
}
|
|
172
157
|
function namespaceImport(typeNode, importClause) {
|
|
173
158
|
return {
|
|
174
|
-
kind: 2 /* UNAVAILABLE */,
|
|
175
|
-
reason: { kind: 4 /* NAMESPACE */, typeNode, importClause },
|
|
159
|
+
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
160
|
+
reason: { kind: 4 /* ValueUnavailableKind.NAMESPACE */, typeNode, importClause },
|
|
176
161
|
};
|
|
177
162
|
}
|
|
178
163
|
function missingType() {
|
|
179
164
|
return {
|
|
180
|
-
kind: 2 /* UNAVAILABLE */,
|
|
181
|
-
reason: { kind: 0 /* MISSING_TYPE */ },
|
|
165
|
+
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
166
|
+
reason: { kind: 0 /* ValueUnavailableKind.MISSING_TYPE */ },
|
|
182
167
|
};
|
|
183
168
|
}
|
|
184
169
|
/**
|
|
@@ -188,7 +173,7 @@ function missingType() {
|
|
|
188
173
|
* This will return `null` if an equivalent expression cannot be constructed.
|
|
189
174
|
*/
|
|
190
175
|
function typeNodeToValueExpr(node) {
|
|
191
|
-
if (
|
|
176
|
+
if (typescript_1.default.isTypeReferenceNode(node)) {
|
|
192
177
|
return entityNameToValue(node.typeName);
|
|
193
178
|
}
|
|
194
179
|
else {
|
|
@@ -233,7 +218,7 @@ function resolveTypeSymbols(typeRef, checker) {
|
|
|
233
218
|
// type is not qualified.
|
|
234
219
|
let leftMost = typeName;
|
|
235
220
|
const symbolNames = [];
|
|
236
|
-
while (
|
|
221
|
+
while (typescript_1.default.isQualifiedName(leftMost)) {
|
|
237
222
|
symbolNames.unshift(leftMost.right.text);
|
|
238
223
|
leftMost = leftMost.left;
|
|
239
224
|
}
|
|
@@ -246,26 +231,30 @@ function resolveTypeSymbols(typeRef, checker) {
|
|
|
246
231
|
}
|
|
247
232
|
// De-alias the top-level type reference symbol to get the symbol of the actual declaration.
|
|
248
233
|
let decl = typeRefSymbol;
|
|
249
|
-
if (typeRefSymbol.flags &
|
|
234
|
+
if (typeRefSymbol.flags & typescript_1.default.SymbolFlags.Alias) {
|
|
250
235
|
decl = checker.getAliasedSymbol(typeRefSymbol);
|
|
251
236
|
}
|
|
252
237
|
return { local, decl, symbolNames };
|
|
253
238
|
}
|
|
254
239
|
function entityNameToValue(node) {
|
|
255
|
-
if (
|
|
240
|
+
if (typescript_1.default.isQualifiedName(node)) {
|
|
256
241
|
const left = entityNameToValue(node.left);
|
|
257
|
-
return left !== null
|
|
242
|
+
return left !== null
|
|
243
|
+
? typescript_1.default.factory.createPropertyAccessExpression(left, node.right)
|
|
244
|
+
: null;
|
|
258
245
|
}
|
|
259
|
-
else if (
|
|
260
|
-
|
|
246
|
+
else if (typescript_1.default.isIdentifier(node)) {
|
|
247
|
+
const clone = typescript_1.default.setOriginalNode(typescript_1.default.factory.createIdentifier(node.text), node);
|
|
248
|
+
clone.parent = node.parent;
|
|
249
|
+
return clone;
|
|
261
250
|
}
|
|
262
251
|
else {
|
|
263
252
|
return null;
|
|
264
253
|
}
|
|
265
254
|
}
|
|
266
255
|
function extractModuleName(node) {
|
|
267
|
-
if (!
|
|
268
|
-
throw new Error(
|
|
256
|
+
if (!typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
|
|
257
|
+
throw new Error('not a module specifier');
|
|
269
258
|
}
|
|
270
259
|
return node.moduleSpecifier.text;
|
|
271
260
|
}
|
|
@@ -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`.
|
|
@@ -6,28 +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
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
-
}) : function(o, v) {
|
|
19
|
-
o["default"] = v;
|
|
20
|
-
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
11
|
};
|
|
28
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
13
|
exports.reflectObjectLiteral = exports.TypeScriptReflectionHost = void 0;
|
|
30
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
31
15
|
const host_1 = require("./host");
|
|
32
16
|
const type_to_value_1 = require("./type_to_value");
|
|
33
17
|
const util_1 = require("./util");
|
|
@@ -39,13 +23,14 @@ class TypeScriptReflectionHost {
|
|
|
39
23
|
this.checker = checker;
|
|
40
24
|
}
|
|
41
25
|
getDecoratorsOfDeclaration(declaration) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
26
|
+
const decorators = typescript_1.default.canHaveDecorators(declaration)
|
|
27
|
+
? typescript_1.default.getDecorators(declaration)
|
|
28
|
+
: undefined;
|
|
29
|
+
return decorators !== undefined && decorators.length
|
|
30
|
+
? decorators
|
|
31
|
+
.map((decorator) => this._reflectDecorator(decorator))
|
|
32
|
+
.filter((dec) => dec !== null)
|
|
33
|
+
: null;
|
|
49
34
|
}
|
|
50
35
|
getMembersOfClass(clazz) {
|
|
51
36
|
const tsClazz = castDeclarationToClassOrDie(clazz);
|
|
@@ -60,7 +45,7 @@ class TypeScriptReflectionHost {
|
|
|
60
45
|
// without a `body` are overloads whereas we want the implementation since it's the one that'll
|
|
61
46
|
// be executed and which can have decorators. For declaration files, we take the first one that
|
|
62
47
|
// we get.
|
|
63
|
-
const ctor = tsClazz.members.find((member) =>
|
|
48
|
+
const ctor = tsClazz.members.find((member) => typescript_1.default.isConstructorDeclaration(member) &&
|
|
64
49
|
(isDeclaration || member.body !== undefined));
|
|
65
50
|
if (ctor === undefined) {
|
|
66
51
|
return null;
|
|
@@ -77,14 +62,14 @@ class TypeScriptReflectionHost {
|
|
|
77
62
|
// and extract the type. More complex union types e.g. `foo: Foo|Bar` are not supported.
|
|
78
63
|
// We also don't need to support `foo: Foo|undefined` because Angular's DI injects `null` for
|
|
79
64
|
// optional tokes that don't have providers.
|
|
80
|
-
if (typeNode &&
|
|
81
|
-
let childTypeNodes = typeNode.types.filter((childTypeNode) => !(
|
|
82
|
-
childTypeNode.literal.kind ===
|
|
65
|
+
if (typeNode && typescript_1.default.isUnionTypeNode(typeNode)) {
|
|
66
|
+
let childTypeNodes = typeNode.types.filter((childTypeNode) => !(typescript_1.default.isLiteralTypeNode(childTypeNode) &&
|
|
67
|
+
childTypeNode.literal.kind === typescript_1.default.SyntaxKind.NullKeyword));
|
|
83
68
|
if (childTypeNodes.length === 1) {
|
|
84
69
|
typeNode = childTypeNodes[0];
|
|
85
70
|
}
|
|
86
71
|
}
|
|
87
|
-
const typeValueReference = type_to_value_1.typeToValue(typeNode, this.checker);
|
|
72
|
+
const typeValueReference = (0, type_to_value_1.typeToValue)(typeNode, this.checker);
|
|
88
73
|
return {
|
|
89
74
|
name,
|
|
90
75
|
nameNode: node.name,
|
|
@@ -99,10 +84,10 @@ class TypeScriptReflectionHost {
|
|
|
99
84
|
if (directImport !== null) {
|
|
100
85
|
return directImport;
|
|
101
86
|
}
|
|
102
|
-
else if (
|
|
87
|
+
else if (typescript_1.default.isQualifiedName(id.parent) && id.parent.right === id) {
|
|
103
88
|
return this.getImportOfNamespacedIdentifier(id, getQualifiedNameRoot(id.parent));
|
|
104
89
|
}
|
|
105
|
-
else if (
|
|
90
|
+
else if (typescript_1.default.isPropertyAccessExpression(id.parent) &&
|
|
106
91
|
id.parent.name === id) {
|
|
107
92
|
return this.getImportOfNamespacedIdentifier(id, getFarLeftIdentifier(id.parent));
|
|
108
93
|
}
|
|
@@ -113,17 +98,17 @@ class TypeScriptReflectionHost {
|
|
|
113
98
|
isClass(node) {
|
|
114
99
|
// For our purposes, classes are "named" ts.ClassDeclarations;
|
|
115
100
|
// (`node.name` can be undefined in unnamed default exports: `default export class { ... }`).
|
|
116
|
-
return util_1.isNamedClassDeclaration(node);
|
|
101
|
+
return (0, util_1.isNamedClassDeclaration)(node);
|
|
117
102
|
}
|
|
118
103
|
hasBaseClass(clazz) {
|
|
119
104
|
return this.getBaseClassExpression(clazz) !== null;
|
|
120
105
|
}
|
|
121
106
|
getBaseClassExpression(clazz) {
|
|
122
|
-
if (!(
|
|
107
|
+
if (!(typescript_1.default.isClassDeclaration(clazz) || typescript_1.default.isClassExpression(clazz)) ||
|
|
123
108
|
clazz.heritageClauses === undefined) {
|
|
124
109
|
return null;
|
|
125
110
|
}
|
|
126
|
-
const extendsClause = clazz.heritageClauses.find((clause) => clause.token ===
|
|
111
|
+
const extendsClause = clazz.heritageClauses.find((clause) => clause.token === typescript_1.default.SyntaxKind.ExtendsKeyword);
|
|
127
112
|
if (extendsClause === undefined) {
|
|
128
113
|
return null;
|
|
129
114
|
}
|
|
@@ -134,7 +119,7 @@ class TypeScriptReflectionHost {
|
|
|
134
119
|
return extendsType.expression;
|
|
135
120
|
}
|
|
136
121
|
getGenericArityOfClass(clazz) {
|
|
137
|
-
if (!
|
|
122
|
+
if (!typescript_1.default.isClassDeclaration(clazz)) {
|
|
138
123
|
return null;
|
|
139
124
|
}
|
|
140
125
|
return clazz.typeParameters !== undefined ? clazz.typeParameters.length : 0;
|
|
@@ -162,7 +147,7 @@ class TypeScriptReflectionHost {
|
|
|
162
147
|
return null;
|
|
163
148
|
}
|
|
164
149
|
// The module specifier is guaranteed to be a string literal, so this should always pass.
|
|
165
|
-
if (!
|
|
150
|
+
if (!typescript_1.default.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
166
151
|
// Not allowed to happen in TypeScript ASTs.
|
|
167
152
|
return null;
|
|
168
153
|
}
|
|
@@ -203,14 +188,14 @@ class TypeScriptReflectionHost {
|
|
|
203
188
|
if (!declaration) {
|
|
204
189
|
return null;
|
|
205
190
|
}
|
|
206
|
-
const namespaceDeclaration =
|
|
191
|
+
const namespaceDeclaration = typescript_1.default.isNamespaceImport(declaration)
|
|
207
192
|
? declaration
|
|
208
193
|
: null;
|
|
209
194
|
if (!namespaceDeclaration) {
|
|
210
195
|
return null;
|
|
211
196
|
}
|
|
212
197
|
const importDeclaration = namespaceDeclaration.parent.parent;
|
|
213
|
-
if (!
|
|
198
|
+
if (!typescript_1.default.isStringLiteral(importDeclaration.moduleSpecifier)) {
|
|
214
199
|
// Should not happen as this would be invalid TypesScript
|
|
215
200
|
return null;
|
|
216
201
|
}
|
|
@@ -226,16 +211,16 @@ class TypeScriptReflectionHost {
|
|
|
226
211
|
let decoratorExpr = node.expression;
|
|
227
212
|
let args = null;
|
|
228
213
|
// Check for call expressions.
|
|
229
|
-
if (
|
|
214
|
+
if (typescript_1.default.isCallExpression(decoratorExpr)) {
|
|
230
215
|
args = Array.from(decoratorExpr.arguments);
|
|
231
216
|
decoratorExpr = decoratorExpr.expression;
|
|
232
217
|
}
|
|
233
218
|
// The final resolved decorator should be a `ts.Identifier` - if it's not, then something is
|
|
234
219
|
// wrong and the decorator can't be resolved statically.
|
|
235
|
-
if (!host_1.isDecoratorIdentifier(decoratorExpr)) {
|
|
220
|
+
if (!(0, host_1.isDecoratorIdentifier)(decoratorExpr)) {
|
|
236
221
|
return null;
|
|
237
222
|
}
|
|
238
|
-
const decoratorIdentifier =
|
|
223
|
+
const decoratorIdentifier = typescript_1.default.isIdentifier(decoratorExpr)
|
|
239
224
|
? decoratorExpr
|
|
240
225
|
: decoratorExpr.name;
|
|
241
226
|
const importDecl = this.getImportOfIdentifier(decoratorIdentifier);
|
|
@@ -252,33 +237,33 @@ class TypeScriptReflectionHost {
|
|
|
252
237
|
let value = null;
|
|
253
238
|
let name = null;
|
|
254
239
|
let nameNode = null;
|
|
255
|
-
if (
|
|
240
|
+
if (typescript_1.default.isPropertyDeclaration(node)) {
|
|
256
241
|
kind = host_1.ClassMemberKind.Property;
|
|
257
242
|
value = node.initializer || null;
|
|
258
243
|
}
|
|
259
|
-
else if (
|
|
244
|
+
else if (typescript_1.default.isGetAccessorDeclaration(node)) {
|
|
260
245
|
kind = host_1.ClassMemberKind.Getter;
|
|
261
246
|
}
|
|
262
|
-
else if (
|
|
247
|
+
else if (typescript_1.default.isSetAccessorDeclaration(node)) {
|
|
263
248
|
kind = host_1.ClassMemberKind.Setter;
|
|
264
249
|
}
|
|
265
|
-
else if (
|
|
250
|
+
else if (typescript_1.default.isMethodDeclaration(node)) {
|
|
266
251
|
kind = host_1.ClassMemberKind.Method;
|
|
267
252
|
}
|
|
268
|
-
else if (
|
|
253
|
+
else if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
269
254
|
kind = host_1.ClassMemberKind.Constructor;
|
|
270
255
|
}
|
|
271
256
|
else {
|
|
272
257
|
return null;
|
|
273
258
|
}
|
|
274
|
-
if (
|
|
259
|
+
if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
275
260
|
name = 'constructor';
|
|
276
261
|
}
|
|
277
|
-
else if (
|
|
262
|
+
else if (typescript_1.default.isIdentifier(node.name)) {
|
|
278
263
|
name = node.name.text;
|
|
279
264
|
nameNode = node.name;
|
|
280
265
|
}
|
|
281
|
-
else if (
|
|
266
|
+
else if (typescript_1.default.isStringLiteral(node.name)) {
|
|
282
267
|
name = node.name.text;
|
|
283
268
|
nameNode = node.name;
|
|
284
269
|
}
|
|
@@ -286,8 +271,9 @@ class TypeScriptReflectionHost {
|
|
|
286
271
|
return null;
|
|
287
272
|
}
|
|
288
273
|
const decorators = this.getDecoratorsOfDeclaration(node);
|
|
289
|
-
const
|
|
290
|
-
|
|
274
|
+
const modifiers = typescript_1.default.getModifiers(node);
|
|
275
|
+
const isStatic = modifiers !== undefined &&
|
|
276
|
+
modifiers.some((mod) => mod.kind === typescript_1.default.SyntaxKind.StaticKeyword);
|
|
291
277
|
return {
|
|
292
278
|
node,
|
|
293
279
|
implementation: node,
|
|
@@ -305,14 +291,14 @@ exports.TypeScriptReflectionHost = TypeScriptReflectionHost;
|
|
|
305
291
|
function reflectObjectLiteral(node) {
|
|
306
292
|
const map = new Map();
|
|
307
293
|
node.properties.forEach((prop) => {
|
|
308
|
-
if (
|
|
294
|
+
if (typescript_1.default.isPropertyAssignment(prop)) {
|
|
309
295
|
const name = propertyNameToString(prop.name);
|
|
310
296
|
if (name === null) {
|
|
311
297
|
return;
|
|
312
298
|
}
|
|
313
299
|
map.set(name, prop.initializer);
|
|
314
300
|
}
|
|
315
|
-
else if (
|
|
301
|
+
else if (typescript_1.default.isShorthandPropertyAssignment(prop)) {
|
|
316
302
|
map.set(prop.name.text, prop.name);
|
|
317
303
|
}
|
|
318
304
|
else {
|
|
@@ -323,13 +309,13 @@ function reflectObjectLiteral(node) {
|
|
|
323
309
|
}
|
|
324
310
|
exports.reflectObjectLiteral = reflectObjectLiteral;
|
|
325
311
|
function castDeclarationToClassOrDie(declaration) {
|
|
326
|
-
if (!
|
|
327
|
-
throw new Error(`Reflecting on a ${
|
|
312
|
+
if (!typescript_1.default.isClassDeclaration(declaration)) {
|
|
313
|
+
throw new Error(`Reflecting on a ${typescript_1.default.SyntaxKind[declaration.kind]} instead of a ClassDeclaration.`);
|
|
328
314
|
}
|
|
329
315
|
return declaration;
|
|
330
316
|
}
|
|
331
317
|
function parameterName(name) {
|
|
332
|
-
if (
|
|
318
|
+
if (typescript_1.default.isIdentifier(name)) {
|
|
333
319
|
return name.text;
|
|
334
320
|
}
|
|
335
321
|
else {
|
|
@@ -337,9 +323,9 @@ function parameterName(name) {
|
|
|
337
323
|
}
|
|
338
324
|
}
|
|
339
325
|
function propertyNameToString(node) {
|
|
340
|
-
if (
|
|
341
|
-
|
|
342
|
-
|
|
326
|
+
if (typescript_1.default.isIdentifier(node) ||
|
|
327
|
+
typescript_1.default.isStringLiteral(node) ||
|
|
328
|
+
typescript_1.default.isNumericLiteral(node)) {
|
|
343
329
|
return node.text;
|
|
344
330
|
}
|
|
345
331
|
else {
|
|
@@ -353,10 +339,10 @@ function propertyNameToString(node) {
|
|
|
353
339
|
* @returns the left most identifier in the chain or `null` if it is not an identifier.
|
|
354
340
|
*/
|
|
355
341
|
function getQualifiedNameRoot(qualifiedName) {
|
|
356
|
-
while (
|
|
342
|
+
while (typescript_1.default.isQualifiedName(qualifiedName.left)) {
|
|
357
343
|
qualifiedName = qualifiedName.left;
|
|
358
344
|
}
|
|
359
|
-
return
|
|
345
|
+
return typescript_1.default.isIdentifier(qualifiedName.left) ? qualifiedName.left : null;
|
|
360
346
|
}
|
|
361
347
|
/**
|
|
362
348
|
* Compute the left most identifier in a property access chain. E.g. the `a` of `a.b.c.d`.
|
|
@@ -365,10 +351,10 @@ function getQualifiedNameRoot(qualifiedName) {
|
|
|
365
351
|
* @returns the left most identifier in the chain or `null` if it is not an identifier.
|
|
366
352
|
*/
|
|
367
353
|
function getFarLeftIdentifier(propertyAccess) {
|
|
368
|
-
while (
|
|
354
|
+
while (typescript_1.default.isPropertyAccessExpression(propertyAccess.expression)) {
|
|
369
355
|
propertyAccess = propertyAccess.expression;
|
|
370
356
|
}
|
|
371
|
-
return
|
|
357
|
+
return typescript_1.default.isIdentifier(propertyAccess.expression)
|
|
372
358
|
? propertyAccess.expression
|
|
373
359
|
: null;
|
|
374
360
|
}
|
|
@@ -377,9 +363,9 @@ function getFarLeftIdentifier(propertyAccess) {
|
|
|
377
363
|
* `NamespaceImport`. If not return `null`.
|
|
378
364
|
*/
|
|
379
365
|
function getContainingImportDeclaration(node) {
|
|
380
|
-
return
|
|
366
|
+
return typescript_1.default.isImportSpecifier(node)
|
|
381
367
|
? node.parent.parent.parent
|
|
382
|
-
:
|
|
368
|
+
: typescript_1.default.isNamespaceImport(node)
|
|
383
369
|
? node.parent.parent
|
|
384
370
|
: null;
|
|
385
371
|
}
|
|
@@ -389,8 +375,8 @@ function getContainingImportDeclaration(node) {
|
|
|
389
375
|
* then fallback to the `originalId`.
|
|
390
376
|
*/
|
|
391
377
|
function getExportedName(decl, originalId) {
|
|
392
|
-
return
|
|
378
|
+
return typescript_1.default.isImportSpecifier(decl)
|
|
393
379
|
? (decl.propertyName !== undefined ? decl.propertyName : decl.name).text
|
|
394
380
|
: originalId.text;
|
|
395
381
|
}
|
|
396
|
-
const
|
|
382
|
+
const LocalExportedDeclarations = Symbol('LocalExportedDeclarations');
|
|
@@ -5,8 +5,8 @@
|
|
|
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
|
|
9
|
-
import { ClassDeclaration } from
|
|
8
|
+
import ts from 'typescript';
|
|
9
|
+
import { ClassDeclaration } from './host';
|
|
10
10
|
export declare function isNamedClassDeclaration(node: ts.Node): node is ClassDeclaration<ts.ClassDeclaration>;
|
|
11
11
|
export declare function isNamedFunctionDeclaration(node: ts.Node): node is ClassDeclaration<ts.FunctionDeclaration>;
|
|
12
12
|
export declare function isNamedVariableDeclaration(node: ts.Node): node is ClassDeclaration<ts.VariableDeclaration>;
|
|
@@ -6,40 +6,24 @@
|
|
|
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
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
-
}) : function(o, v) {
|
|
19
|
-
o["default"] = v;
|
|
20
|
-
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
11
|
};
|
|
28
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
13
|
exports.isNamedVariableDeclaration = exports.isNamedFunctionDeclaration = exports.isNamedClassDeclaration = void 0;
|
|
30
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
31
15
|
function isNamedClassDeclaration(node) {
|
|
32
|
-
return
|
|
16
|
+
return typescript_1.default.isClassDeclaration(node) && isIdentifier(node.name);
|
|
33
17
|
}
|
|
34
18
|
exports.isNamedClassDeclaration = isNamedClassDeclaration;
|
|
35
19
|
function isNamedFunctionDeclaration(node) {
|
|
36
|
-
return
|
|
20
|
+
return typescript_1.default.isFunctionDeclaration(node) && isIdentifier(node.name);
|
|
37
21
|
}
|
|
38
22
|
exports.isNamedFunctionDeclaration = isNamedFunctionDeclaration;
|
|
39
23
|
function isNamedVariableDeclaration(node) {
|
|
40
|
-
return
|
|
24
|
+
return typescript_1.default.isVariableDeclaration(node) && isIdentifier(node.name);
|
|
41
25
|
}
|
|
42
26
|
exports.isNamedVariableDeclaration = isNamedVariableDeclaration;
|
|
43
27
|
function isIdentifier(node) {
|
|
44
|
-
return node !== undefined &&
|
|
28
|
+
return node !== undefined && typescript_1.default.isIdentifier(node);
|
|
45
29
|
}
|
|
@@ -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 './src/api';
|
|
9
|
+
export * from './src/utils';
|
|
@@ -1,7 +1,18 @@
|
|
|
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
|
-
Object.
|
|
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);
|
|
5
16
|
}) : (function(o, m, k, k2) {
|
|
6
17
|
if (k2 === undefined) k2 = k;
|
|
7
18
|
o[k2] = m[k];
|