static-injector 2.0.0 → 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 +6 -6
- package/import/es2015/di/r3_injector.js +6 -6
- package/import/fesm2015/index.js +6 -6
- package/import/typings/di/injectable.d.ts +1 -1
- package/import/typings/di/interface/provider.d.ts +2 -2
- package/import/typings/di/provider_collection.d.ts +1 -1
- package/import/typings/di/provider_token.d.ts +1 -1
- package/import/typings/di/r3_injector.d.ts +1 -1
- package/import/typings/di/scope.d.ts +1 -1
- package/import/typings/render3/definition_factory.d.ts +1 -1
- 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
|
@@ -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`.
|
|
@@ -6,33 +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.reflectObjectLiteral = exports.TypeScriptReflectionHost = void 0;
|
|
34
|
-
const
|
|
35
|
-
const ts_compatibility_1 = require("../../ts_compatibility");
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
36
15
|
const host_1 = require("./host");
|
|
37
16
|
const type_to_value_1 = require("./type_to_value");
|
|
38
17
|
const util_1 = require("./util");
|
|
@@ -44,7 +23,9 @@ class TypeScriptReflectionHost {
|
|
|
44
23
|
this.checker = checker;
|
|
45
24
|
}
|
|
46
25
|
getDecoratorsOfDeclaration(declaration) {
|
|
47
|
-
const decorators =
|
|
26
|
+
const decorators = typescript_1.default.canHaveDecorators(declaration)
|
|
27
|
+
? typescript_1.default.getDecorators(declaration)
|
|
28
|
+
: undefined;
|
|
48
29
|
return decorators !== undefined && decorators.length
|
|
49
30
|
? decorators
|
|
50
31
|
.map((decorator) => this._reflectDecorator(decorator))
|
|
@@ -64,7 +45,7 @@ class TypeScriptReflectionHost {
|
|
|
64
45
|
// without a `body` are overloads whereas we want the implementation since it's the one that'll
|
|
65
46
|
// be executed and which can have decorators. For declaration files, we take the first one that
|
|
66
47
|
// we get.
|
|
67
|
-
const ctor = tsClazz.members.find((member) =>
|
|
48
|
+
const ctor = tsClazz.members.find((member) => typescript_1.default.isConstructorDeclaration(member) &&
|
|
68
49
|
(isDeclaration || member.body !== undefined));
|
|
69
50
|
if (ctor === undefined) {
|
|
70
51
|
return null;
|
|
@@ -81,9 +62,9 @@ class TypeScriptReflectionHost {
|
|
|
81
62
|
// and extract the type. More complex union types e.g. `foo: Foo|Bar` are not supported.
|
|
82
63
|
// We also don't need to support `foo: Foo|undefined` because Angular's DI injects `null` for
|
|
83
64
|
// optional tokes that don't have providers.
|
|
84
|
-
if (typeNode &&
|
|
85
|
-
let childTypeNodes = typeNode.types.filter((childTypeNode) => !(
|
|
86
|
-
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));
|
|
87
68
|
if (childTypeNodes.length === 1) {
|
|
88
69
|
typeNode = childTypeNodes[0];
|
|
89
70
|
}
|
|
@@ -103,10 +84,10 @@ class TypeScriptReflectionHost {
|
|
|
103
84
|
if (directImport !== null) {
|
|
104
85
|
return directImport;
|
|
105
86
|
}
|
|
106
|
-
else if (
|
|
87
|
+
else if (typescript_1.default.isQualifiedName(id.parent) && id.parent.right === id) {
|
|
107
88
|
return this.getImportOfNamespacedIdentifier(id, getQualifiedNameRoot(id.parent));
|
|
108
89
|
}
|
|
109
|
-
else if (
|
|
90
|
+
else if (typescript_1.default.isPropertyAccessExpression(id.parent) &&
|
|
110
91
|
id.parent.name === id) {
|
|
111
92
|
return this.getImportOfNamespacedIdentifier(id, getFarLeftIdentifier(id.parent));
|
|
112
93
|
}
|
|
@@ -123,11 +104,11 @@ class TypeScriptReflectionHost {
|
|
|
123
104
|
return this.getBaseClassExpression(clazz) !== null;
|
|
124
105
|
}
|
|
125
106
|
getBaseClassExpression(clazz) {
|
|
126
|
-
if (!(
|
|
107
|
+
if (!(typescript_1.default.isClassDeclaration(clazz) || typescript_1.default.isClassExpression(clazz)) ||
|
|
127
108
|
clazz.heritageClauses === undefined) {
|
|
128
109
|
return null;
|
|
129
110
|
}
|
|
130
|
-
const extendsClause = clazz.heritageClauses.find((clause) => clause.token ===
|
|
111
|
+
const extendsClause = clazz.heritageClauses.find((clause) => clause.token === typescript_1.default.SyntaxKind.ExtendsKeyword);
|
|
131
112
|
if (extendsClause === undefined) {
|
|
132
113
|
return null;
|
|
133
114
|
}
|
|
@@ -138,7 +119,7 @@ class TypeScriptReflectionHost {
|
|
|
138
119
|
return extendsType.expression;
|
|
139
120
|
}
|
|
140
121
|
getGenericArityOfClass(clazz) {
|
|
141
|
-
if (!
|
|
122
|
+
if (!typescript_1.default.isClassDeclaration(clazz)) {
|
|
142
123
|
return null;
|
|
143
124
|
}
|
|
144
125
|
return clazz.typeParameters !== undefined ? clazz.typeParameters.length : 0;
|
|
@@ -166,7 +147,7 @@ class TypeScriptReflectionHost {
|
|
|
166
147
|
return null;
|
|
167
148
|
}
|
|
168
149
|
// The module specifier is guaranteed to be a string literal, so this should always pass.
|
|
169
|
-
if (!
|
|
150
|
+
if (!typescript_1.default.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
170
151
|
// Not allowed to happen in TypeScript ASTs.
|
|
171
152
|
return null;
|
|
172
153
|
}
|
|
@@ -207,14 +188,14 @@ class TypeScriptReflectionHost {
|
|
|
207
188
|
if (!declaration) {
|
|
208
189
|
return null;
|
|
209
190
|
}
|
|
210
|
-
const namespaceDeclaration =
|
|
191
|
+
const namespaceDeclaration = typescript_1.default.isNamespaceImport(declaration)
|
|
211
192
|
? declaration
|
|
212
193
|
: null;
|
|
213
194
|
if (!namespaceDeclaration) {
|
|
214
195
|
return null;
|
|
215
196
|
}
|
|
216
197
|
const importDeclaration = namespaceDeclaration.parent.parent;
|
|
217
|
-
if (!
|
|
198
|
+
if (!typescript_1.default.isStringLiteral(importDeclaration.moduleSpecifier)) {
|
|
218
199
|
// Should not happen as this would be invalid TypesScript
|
|
219
200
|
return null;
|
|
220
201
|
}
|
|
@@ -230,7 +211,7 @@ class TypeScriptReflectionHost {
|
|
|
230
211
|
let decoratorExpr = node.expression;
|
|
231
212
|
let args = null;
|
|
232
213
|
// Check for call expressions.
|
|
233
|
-
if (
|
|
214
|
+
if (typescript_1.default.isCallExpression(decoratorExpr)) {
|
|
234
215
|
args = Array.from(decoratorExpr.arguments);
|
|
235
216
|
decoratorExpr = decoratorExpr.expression;
|
|
236
217
|
}
|
|
@@ -239,7 +220,7 @@ class TypeScriptReflectionHost {
|
|
|
239
220
|
if (!(0, host_1.isDecoratorIdentifier)(decoratorExpr)) {
|
|
240
221
|
return null;
|
|
241
222
|
}
|
|
242
|
-
const decoratorIdentifier =
|
|
223
|
+
const decoratorIdentifier = typescript_1.default.isIdentifier(decoratorExpr)
|
|
243
224
|
? decoratorExpr
|
|
244
225
|
: decoratorExpr.name;
|
|
245
226
|
const importDecl = this.getImportOfIdentifier(decoratorIdentifier);
|
|
@@ -256,33 +237,33 @@ class TypeScriptReflectionHost {
|
|
|
256
237
|
let value = null;
|
|
257
238
|
let name = null;
|
|
258
239
|
let nameNode = null;
|
|
259
|
-
if (
|
|
240
|
+
if (typescript_1.default.isPropertyDeclaration(node)) {
|
|
260
241
|
kind = host_1.ClassMemberKind.Property;
|
|
261
242
|
value = node.initializer || null;
|
|
262
243
|
}
|
|
263
|
-
else if (
|
|
244
|
+
else if (typescript_1.default.isGetAccessorDeclaration(node)) {
|
|
264
245
|
kind = host_1.ClassMemberKind.Getter;
|
|
265
246
|
}
|
|
266
|
-
else if (
|
|
247
|
+
else if (typescript_1.default.isSetAccessorDeclaration(node)) {
|
|
267
248
|
kind = host_1.ClassMemberKind.Setter;
|
|
268
249
|
}
|
|
269
|
-
else if (
|
|
250
|
+
else if (typescript_1.default.isMethodDeclaration(node)) {
|
|
270
251
|
kind = host_1.ClassMemberKind.Method;
|
|
271
252
|
}
|
|
272
|
-
else if (
|
|
253
|
+
else if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
273
254
|
kind = host_1.ClassMemberKind.Constructor;
|
|
274
255
|
}
|
|
275
256
|
else {
|
|
276
257
|
return null;
|
|
277
258
|
}
|
|
278
|
-
if (
|
|
259
|
+
if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
279
260
|
name = 'constructor';
|
|
280
261
|
}
|
|
281
|
-
else if (
|
|
262
|
+
else if (typescript_1.default.isIdentifier(node.name)) {
|
|
282
263
|
name = node.name.text;
|
|
283
264
|
nameNode = node.name;
|
|
284
265
|
}
|
|
285
|
-
else if (
|
|
266
|
+
else if (typescript_1.default.isStringLiteral(node.name)) {
|
|
286
267
|
name = node.name.text;
|
|
287
268
|
nameNode = node.name;
|
|
288
269
|
}
|
|
@@ -290,9 +271,9 @@ class TypeScriptReflectionHost {
|
|
|
290
271
|
return null;
|
|
291
272
|
}
|
|
292
273
|
const decorators = this.getDecoratorsOfDeclaration(node);
|
|
293
|
-
const modifiers =
|
|
274
|
+
const modifiers = typescript_1.default.getModifiers(node);
|
|
294
275
|
const isStatic = modifiers !== undefined &&
|
|
295
|
-
modifiers.some((mod) => mod.kind ===
|
|
276
|
+
modifiers.some((mod) => mod.kind === typescript_1.default.SyntaxKind.StaticKeyword);
|
|
296
277
|
return {
|
|
297
278
|
node,
|
|
298
279
|
implementation: node,
|
|
@@ -310,14 +291,14 @@ exports.TypeScriptReflectionHost = TypeScriptReflectionHost;
|
|
|
310
291
|
function reflectObjectLiteral(node) {
|
|
311
292
|
const map = new Map();
|
|
312
293
|
node.properties.forEach((prop) => {
|
|
313
|
-
if (
|
|
294
|
+
if (typescript_1.default.isPropertyAssignment(prop)) {
|
|
314
295
|
const name = propertyNameToString(prop.name);
|
|
315
296
|
if (name === null) {
|
|
316
297
|
return;
|
|
317
298
|
}
|
|
318
299
|
map.set(name, prop.initializer);
|
|
319
300
|
}
|
|
320
|
-
else if (
|
|
301
|
+
else if (typescript_1.default.isShorthandPropertyAssignment(prop)) {
|
|
321
302
|
map.set(prop.name.text, prop.name);
|
|
322
303
|
}
|
|
323
304
|
else {
|
|
@@ -328,13 +309,13 @@ function reflectObjectLiteral(node) {
|
|
|
328
309
|
}
|
|
329
310
|
exports.reflectObjectLiteral = reflectObjectLiteral;
|
|
330
311
|
function castDeclarationToClassOrDie(declaration) {
|
|
331
|
-
if (!
|
|
332
|
-
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.`);
|
|
333
314
|
}
|
|
334
315
|
return declaration;
|
|
335
316
|
}
|
|
336
317
|
function parameterName(name) {
|
|
337
|
-
if (
|
|
318
|
+
if (typescript_1.default.isIdentifier(name)) {
|
|
338
319
|
return name.text;
|
|
339
320
|
}
|
|
340
321
|
else {
|
|
@@ -342,9 +323,9 @@ function parameterName(name) {
|
|
|
342
323
|
}
|
|
343
324
|
}
|
|
344
325
|
function propertyNameToString(node) {
|
|
345
|
-
if (
|
|
346
|
-
|
|
347
|
-
|
|
326
|
+
if (typescript_1.default.isIdentifier(node) ||
|
|
327
|
+
typescript_1.default.isStringLiteral(node) ||
|
|
328
|
+
typescript_1.default.isNumericLiteral(node)) {
|
|
348
329
|
return node.text;
|
|
349
330
|
}
|
|
350
331
|
else {
|
|
@@ -358,10 +339,10 @@ function propertyNameToString(node) {
|
|
|
358
339
|
* @returns the left most identifier in the chain or `null` if it is not an identifier.
|
|
359
340
|
*/
|
|
360
341
|
function getQualifiedNameRoot(qualifiedName) {
|
|
361
|
-
while (
|
|
342
|
+
while (typescript_1.default.isQualifiedName(qualifiedName.left)) {
|
|
362
343
|
qualifiedName = qualifiedName.left;
|
|
363
344
|
}
|
|
364
|
-
return
|
|
345
|
+
return typescript_1.default.isIdentifier(qualifiedName.left) ? qualifiedName.left : null;
|
|
365
346
|
}
|
|
366
347
|
/**
|
|
367
348
|
* Compute the left most identifier in a property access chain. E.g. the `a` of `a.b.c.d`.
|
|
@@ -370,10 +351,10 @@ function getQualifiedNameRoot(qualifiedName) {
|
|
|
370
351
|
* @returns the left most identifier in the chain or `null` if it is not an identifier.
|
|
371
352
|
*/
|
|
372
353
|
function getFarLeftIdentifier(propertyAccess) {
|
|
373
|
-
while (
|
|
354
|
+
while (typescript_1.default.isPropertyAccessExpression(propertyAccess.expression)) {
|
|
374
355
|
propertyAccess = propertyAccess.expression;
|
|
375
356
|
}
|
|
376
|
-
return
|
|
357
|
+
return typescript_1.default.isIdentifier(propertyAccess.expression)
|
|
377
358
|
? propertyAccess.expression
|
|
378
359
|
: null;
|
|
379
360
|
}
|
|
@@ -382,9 +363,9 @@ function getFarLeftIdentifier(propertyAccess) {
|
|
|
382
363
|
* `NamespaceImport`. If not return `null`.
|
|
383
364
|
*/
|
|
384
365
|
function getContainingImportDeclaration(node) {
|
|
385
|
-
return
|
|
366
|
+
return typescript_1.default.isImportSpecifier(node)
|
|
386
367
|
? node.parent.parent.parent
|
|
387
|
-
:
|
|
368
|
+
: typescript_1.default.isNamespaceImport(node)
|
|
388
369
|
? node.parent.parent
|
|
389
370
|
: null;
|
|
390
371
|
}
|
|
@@ -394,8 +375,8 @@ function getContainingImportDeclaration(node) {
|
|
|
394
375
|
* then fallback to the `originalId`.
|
|
395
376
|
*/
|
|
396
377
|
function getExportedName(decl, originalId) {
|
|
397
|
-
return
|
|
378
|
+
return typescript_1.default.isImportSpecifier(decl)
|
|
398
379
|
? (decl.propertyName !== undefined ? decl.propertyName : decl.name).text
|
|
399
380
|
: originalId.text;
|
|
400
381
|
}
|
|
401
|
-
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>;
|