static-injector 4.0.2 → 5.0.0-alpha.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 → commonjs}/index.js +29 -197
- package/{import/es2022 → es2022}/di/interface/defs.js +5 -1
- package/{import/es2022 → es2022}/index.js +0 -1
- package/{transform/compiler/index.d.ts → es2022/interface/lifecycle_hooks.js} +1 -1
- package/{transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js → es2022/render3/definition_factory.js} +3 -2
- package/es2022/util/decorators.js +31 -0
- package/{import/fesm2022 → fesm2022}/index.js +30 -196
- package/package.json +17 -14
- package/readme.md +32 -12
- package/{import/typings → typings}/di/injectable.d.ts +0 -7
- package/{import/typings → typings}/index.d.ts +0 -1
- package/import/es2022/di/injectable.js +0 -14
- package/import/es2022/error_details_base_url.js +0 -19
- package/import/es2022/render3/definition_factory.js +0 -14
- package/import/es2022/render3/di.js +0 -49
- package/import/es2022/render3/error_code.js +0 -30
- package/import/es2022/util/array_utils.js +0 -17
- package/import/es2022/util/decorators.js +0 -53
- package/import/typings/error_details_base_url.d.ts +0 -19
- package/import/typings/render3/di.d.ts +0 -12
- package/import/typings/render3/error_code.d.ts +0 -24
- package/import/typings/util/array_utils.d.ts +0 -25
- package/transform/compiler/compiler.d.ts +0 -8
- package/transform/compiler/compiler.js +0 -28
- package/transform/compiler/index.js +0 -28
- package/transform/compiler/public_api.d.ts +0 -13
- package/transform/compiler/public_api.js +0 -30
- package/transform/compiler/src/compiler.d.ts +0 -5
- package/transform/compiler/src/compiler.js +0 -21
- package/transform/compiler/src/core.d.ts +0 -25
- package/transform/compiler/src/core.js +0 -22
- package/transform/compiler/src/injectable_compiler_2.d.ts +0 -23
- package/transform/compiler/src/injectable_compiler_2.js +0 -171
- package/transform/compiler/src/output/output_ast.d.ts +0 -512
- package/transform/compiler/src/output/output_ast.js +0 -1109
- package/transform/compiler/src/parse_util.d.ts +0 -50
- package/transform/compiler/src/parse_util.js +0 -71
- package/transform/compiler/src/render3/partial/api.d.ts +0 -171
- package/transform/compiler/src/render3/partial/api.js +0 -18
- package/transform/compiler/src/render3/r3_factory.d.ts +0 -82
- package/transform/compiler/src/render3/r3_factory.js +0 -225
- package/transform/compiler/src/render3/r3_identifiers.d.ts +0 -20
- package/transform/compiler/src/render3/r3_identifiers.js +0 -55
- package/transform/compiler/src/render3/util.d.ts +0 -85
- package/transform/compiler/src/render3/util.js +0 -82
- package/transform/compiler/src/render3/view/util.d.ts +0 -24
- package/transform/compiler/src/render3/view/util.js +0 -59
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +0 -3
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +0 -19
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +0 -37
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +0 -195
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.d.ts +0 -11
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +0 -22
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +0 -64
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +0 -189
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +0 -43
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +0 -277
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +0 -24
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +0 -84
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +0 -188
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +0 -206
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +0 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +0 -18
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +0 -1
- package/transform/compiler-cli/src/ngtsc/imports/index.js +0 -17
- package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +0 -36
- package/transform/compiler-cli/src/ngtsc/imports/src/core.js +0 -25
- package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +0 -19
- package/transform/compiler-cli/src/ngtsc/imports/src/default.js +0 -27
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +0 -3
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +0 -19
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +0 -522
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +0 -34
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +0 -25
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +0 -271
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +0 -53
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +0 -393
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +0 -12
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +0 -29
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +0 -2
- package/transform/compiler-cli/src/ngtsc/transform/index.js +0 -18
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +0 -115
- package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -29
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +0 -15
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +0 -79
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +0 -5
- package/transform/compiler-cli/src/ngtsc/translator/index.js +0 -21
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +0 -289
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +0 -27
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +0 -9
- package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +0 -18
- package/transform/compiler-cli/src/ngtsc/translator/src/context.js +0 -28
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +0 -47
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +0 -66
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -56
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +0 -270
- package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.d.ts +0 -12
- package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.js +0 -27
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +0 -53
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +0 -250
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +0 -13
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +0 -21
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +0 -8
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +0 -24
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +0 -45
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +0 -86
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +0 -4
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +0 -16
- package/transform/index.d.ts +0 -1
- package/transform/index.js +0 -17
- package/transform/injectable-transform.d.ts +0 -41
- package/transform/injectable-transform.js +0 -245
- package/transform/node-Iteration.d.ts +0 -2
- package/transform/node-Iteration.js +0 -12
- /package/{import/es2022 → es2022}/di/create_injector.js +0 -0
- /package/{import/es2022 → es2022}/di/forward_ref.js +0 -0
- /package/{import/es2022 → es2022}/di/index.js +0 -0
- /package/{import/es2022 → es2022}/di/initializer_token.js +0 -0
- /package/{import/es2022 → es2022}/di/inject_switch.js +0 -0
- /package/{import/es2022/di/injector_marker.js → es2022/di/injectable.js} +0 -0
- /package/{import/es2022 → es2022}/di/injection_token.js +0 -0
- /package/{import/es2022 → es2022}/di/injector.js +0 -0
- /package/{import/es2022 → es2022}/di/injector_compatibility.js +0 -0
- /package/{import/es2022/di/provider_token.js → es2022/di/injector_marker.js} +0 -0
- /package/{import/es2022 → es2022}/di/injector_token.js +0 -0
- /package/{import/es2022 → es2022}/di/interface/injector.js +0 -0
- /package/{import/es2022 → es2022}/di/interface/provider.js +0 -0
- /package/{import/es2022 → es2022}/di/internal_tokens.js +0 -0
- /package/{import/es2022 → es2022}/di/metadata.js +0 -0
- /package/{import/es2022 → es2022}/di/null_injector.js +0 -0
- /package/{import/es2022 → es2022}/di/provider_collection.js +0 -0
- /package/{import/es2022/interface/lifecycle_hooks.js → es2022/di/provider_token.js} +0 -0
- /package/{import/es2022 → es2022}/di/r3_injector.js +0 -0
- /package/{import/es2022 → es2022}/di/scope.js +0 -0
- /package/{import/es2022 → es2022}/di.js +0 -0
- /package/{import/es2022 → es2022}/errors.js +0 -0
- /package/{import/es2022 → es2022}/interface/type.js +0 -0
- /package/{import/es2022 → es2022}/render3/errors_di.js +0 -0
- /package/{import/es2022 → es2022}/render3/fields.js +0 -0
- /package/{import/es2022 → es2022}/render3/instructions/di.js +0 -0
- /package/{import/es2022 → es2022}/render3/util/stringify_utils.js +0 -0
- /package/{import/es2022 → es2022}/util/closure.js +0 -0
- /package/{import/es2022 → es2022}/util/empty.js +0 -0
- /package/{import/es2022 → es2022}/util/property.js +0 -0
- /package/{import/es2022 → es2022}/util/stringify.js +0 -0
- /package/{import/typings → typings}/di/create_injector.d.ts +0 -0
- /package/{import/typings → typings}/di/forward_ref.d.ts +0 -0
- /package/{import/typings → typings}/di/index.d.ts +0 -0
- /package/{import/typings → typings}/di/initializer_token.d.ts +0 -0
- /package/{import/typings → typings}/di/inject_switch.d.ts +0 -0
- /package/{import/typings → typings}/di/injection_token.d.ts +0 -0
- /package/{import/typings → typings}/di/injector.d.ts +0 -0
- /package/{import/typings → typings}/di/injector_compatibility.d.ts +0 -0
- /package/{import/typings → typings}/di/injector_marker.d.ts +0 -0
- /package/{import/typings → typings}/di/injector_token.d.ts +0 -0
- /package/{import/typings → typings}/di/interface/defs.d.ts +0 -0
- /package/{import/typings → typings}/di/interface/injector.d.ts +0 -0
- /package/{import/typings → typings}/di/interface/provider.d.ts +0 -0
- /package/{import/typings → typings}/di/internal_tokens.d.ts +0 -0
- /package/{import/typings → typings}/di/metadata.d.ts +0 -0
- /package/{import/typings → typings}/di/null_injector.d.ts +0 -0
- /package/{import/typings → typings}/di/provider_collection.d.ts +0 -0
- /package/{import/typings → typings}/di/provider_token.d.ts +0 -0
- /package/{import/typings → typings}/di/r3_injector.d.ts +0 -0
- /package/{import/typings → typings}/di/scope.d.ts +0 -0
- /package/{import/typings → typings}/di.d.ts +0 -0
- /package/{import/typings → typings}/errors.d.ts +0 -0
- /package/{import/typings → typings}/interface/lifecycle_hooks.d.ts +0 -0
- /package/{import/typings → typings}/interface/type.d.ts +0 -0
- /package/{import/typings → typings}/render3/definition_factory.d.ts +0 -0
- /package/{import/typings → typings}/render3/errors_di.d.ts +0 -0
- /package/{import/typings → typings}/render3/fields.d.ts +0 -0
- /package/{import/typings → typings}/render3/instructions/di.d.ts +0 -0
- /package/{import/typings → typings}/render3/util/stringify_utils.d.ts +0 -0
- /package/{import/typings → typings}/util/closure.d.ts +0 -0
- /package/{import/typings → typings}/util/decorators.d.ts +0 -0
- /package/{import/typings → typings}/util/empty.d.ts +0 -0
- /package/{import/typings → typings}/util/property.d.ts +0 -0
- /package/{import/typings → typings}/util/stringify.d.ts +0 -0
|
@@ -1,271 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.entityNameToValue = exports.typeNodeToValueExpr = exports.typeToValue = void 0;
|
|
14
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
-
/**
|
|
16
|
-
* Potentially convert a `ts.TypeNode` to a `TypeValueReference`, which indicates how to use the
|
|
17
|
-
* type given in the `ts.TypeNode` in a value position.
|
|
18
|
-
*
|
|
19
|
-
* This can return `null` if the `typeNode` is `null`, if it does not refer to a symbol with a value
|
|
20
|
-
* declaration, or if it is not possible to statically understand.
|
|
21
|
-
*/
|
|
22
|
-
function typeToValue(typeNode, checker, isLocalCompilation) {
|
|
23
|
-
// It's not possible to get a value expression if the parameter doesn't even have a type.
|
|
24
|
-
if (typeNode === null) {
|
|
25
|
-
return missingType();
|
|
26
|
-
}
|
|
27
|
-
if (!typescript_1.default.isTypeReferenceNode(typeNode)) {
|
|
28
|
-
return unsupportedType(typeNode);
|
|
29
|
-
}
|
|
30
|
-
const symbols = resolveTypeSymbols(typeNode, checker);
|
|
31
|
-
if (symbols === null) {
|
|
32
|
-
return unknownReference(typeNode);
|
|
33
|
-
}
|
|
34
|
-
const { local, decl } = symbols;
|
|
35
|
-
// It's only valid to convert a type reference to a value reference if the type actually
|
|
36
|
-
// has a value declaration associated with it. Note that const enums are an exception,
|
|
37
|
-
// because while they do have a value declaration, they don't exist at runtime.
|
|
38
|
-
if (decl.valueDeclaration === undefined ||
|
|
39
|
-
decl.flags & typescript_1.default.SymbolFlags.ConstEnum) {
|
|
40
|
-
let typeOnlyDecl = null;
|
|
41
|
-
if (decl.declarations !== undefined && decl.declarations.length > 0) {
|
|
42
|
-
typeOnlyDecl = decl.declarations[0];
|
|
43
|
-
}
|
|
44
|
-
// In local compilation mode a declaration is considered invalid only if it is a type related
|
|
45
|
-
// declaration.
|
|
46
|
-
if (!isLocalCompilation ||
|
|
47
|
-
(typeOnlyDecl &&
|
|
48
|
-
[
|
|
49
|
-
typescript_1.default.SyntaxKind.TypeParameter,
|
|
50
|
-
typescript_1.default.SyntaxKind.TypeAliasDeclaration,
|
|
51
|
-
typescript_1.default.SyntaxKind.InterfaceDeclaration,
|
|
52
|
-
].includes(typeOnlyDecl.kind))) {
|
|
53
|
-
return noValueDeclaration(typeNode, typeOnlyDecl);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// The type points to a valid value declaration. Rewrite the TypeReference into an
|
|
57
|
-
// Expression which references the value pointed to by the TypeReference, if possible.
|
|
58
|
-
// Look at the local `ts.Symbol`'s declarations and see if it comes from an import
|
|
59
|
-
// statement. If so, extract the module specifier and the name of the imported type.
|
|
60
|
-
const firstDecl = local.declarations && local.declarations[0];
|
|
61
|
-
if (firstDecl !== undefined) {
|
|
62
|
-
if (typescript_1.default.isImportClause(firstDecl) && firstDecl.name !== undefined) {
|
|
63
|
-
// This is a default import.
|
|
64
|
-
// import Foo from 'foo';
|
|
65
|
-
if (firstDecl.isTypeOnly) {
|
|
66
|
-
// Type-only imports cannot be represented as value.
|
|
67
|
-
return typeOnlyImport(typeNode, firstDecl);
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
kind: 0 /* TypeValueReferenceKind.LOCAL */,
|
|
71
|
-
expression: firstDecl.name,
|
|
72
|
-
defaultImportStatement: firstDecl.parent,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
else if (typescript_1.default.isImportSpecifier(firstDecl)) {
|
|
76
|
-
// The symbol was imported by name
|
|
77
|
-
// import {Foo} from 'foo';
|
|
78
|
-
// or
|
|
79
|
-
// import {Foo as Bar} from 'foo';
|
|
80
|
-
if (firstDecl.isTypeOnly) {
|
|
81
|
-
// The import specifier can't be type-only (e.g. `import {type Foo} from '...')`.
|
|
82
|
-
return typeOnlyImport(typeNode, firstDecl);
|
|
83
|
-
}
|
|
84
|
-
if (firstDecl.parent.parent.isTypeOnly) {
|
|
85
|
-
// The import specifier can't be inside a type-only import clause
|
|
86
|
-
// (e.g. `import type {Foo} from '...')`.
|
|
87
|
-
return typeOnlyImport(typeNode, firstDecl.parent.parent);
|
|
88
|
-
}
|
|
89
|
-
// Determine the name to import (`Foo`) from the import specifier, as the symbol names of
|
|
90
|
-
// the imported type could refer to a local alias (like `Bar` in the example above).
|
|
91
|
-
const importedName = (firstDecl.propertyName || firstDecl.name).text;
|
|
92
|
-
// The first symbol name refers to the local name, which is replaced by `importedName` above.
|
|
93
|
-
// Any remaining symbol names make up the complete path to the value.
|
|
94
|
-
const [_localName, ...nestedPath] = symbols.symbolNames;
|
|
95
|
-
const moduleName = extractModuleName(firstDecl.parent.parent.parent);
|
|
96
|
-
return {
|
|
97
|
-
kind: 1 /* TypeValueReferenceKind.IMPORTED */,
|
|
98
|
-
valueDeclaration: decl.valueDeclaration ?? null,
|
|
99
|
-
moduleName,
|
|
100
|
-
importedName,
|
|
101
|
-
nestedPath,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
else if (typescript_1.default.isNamespaceImport(firstDecl)) {
|
|
105
|
-
// The import is a namespace import
|
|
106
|
-
// import * as Foo from 'foo';
|
|
107
|
-
if (firstDecl.parent.isTypeOnly) {
|
|
108
|
-
// Type-only imports cannot be represented as value.
|
|
109
|
-
return typeOnlyImport(typeNode, firstDecl.parent);
|
|
110
|
-
}
|
|
111
|
-
if (symbols.symbolNames.length === 1) {
|
|
112
|
-
// The type refers to the namespace itself, which cannot be represented as a value.
|
|
113
|
-
return namespaceImport(typeNode, firstDecl.parent);
|
|
114
|
-
}
|
|
115
|
-
// The first symbol name refers to the local name of the namespace, which is is discarded
|
|
116
|
-
// as a new namespace import will be generated. This is followed by the symbol name that needs
|
|
117
|
-
// to be imported and any remaining names that constitute the complete path to the value.
|
|
118
|
-
const [_ns, importedName, ...nestedPath] = symbols.symbolNames;
|
|
119
|
-
const moduleName = extractModuleName(firstDecl.parent.parent);
|
|
120
|
-
return {
|
|
121
|
-
kind: 1 /* TypeValueReferenceKind.IMPORTED */,
|
|
122
|
-
valueDeclaration: decl.valueDeclaration ?? null,
|
|
123
|
-
moduleName,
|
|
124
|
-
importedName,
|
|
125
|
-
nestedPath,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// If the type is not imported, the type reference can be converted into an expression as is.
|
|
130
|
-
const expression = typeNodeToValueExpr(typeNode);
|
|
131
|
-
if (expression !== null) {
|
|
132
|
-
return {
|
|
133
|
-
kind: 0 /* TypeValueReferenceKind.LOCAL */,
|
|
134
|
-
expression,
|
|
135
|
-
defaultImportStatement: null,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return unsupportedType(typeNode);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.typeToValue = typeToValue;
|
|
143
|
-
function unsupportedType(typeNode) {
|
|
144
|
-
return {
|
|
145
|
-
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
146
|
-
reason: { kind: 5 /* ValueUnavailableKind.UNSUPPORTED */, typeNode },
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function noValueDeclaration(typeNode, decl) {
|
|
150
|
-
return {
|
|
151
|
-
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
152
|
-
reason: { kind: 1 /* ValueUnavailableKind.NO_VALUE_DECLARATION */, typeNode, decl },
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function typeOnlyImport(typeNode, node) {
|
|
156
|
-
return {
|
|
157
|
-
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
158
|
-
reason: { kind: 2 /* ValueUnavailableKind.TYPE_ONLY_IMPORT */, typeNode, node },
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function unknownReference(typeNode) {
|
|
162
|
-
return {
|
|
163
|
-
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
164
|
-
reason: { kind: 3 /* ValueUnavailableKind.UNKNOWN_REFERENCE */, typeNode },
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function namespaceImport(typeNode, importClause) {
|
|
168
|
-
return {
|
|
169
|
-
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
170
|
-
reason: { kind: 4 /* ValueUnavailableKind.NAMESPACE */, typeNode, importClause },
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function missingType() {
|
|
174
|
-
return {
|
|
175
|
-
kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
|
|
176
|
-
reason: { kind: 0 /* ValueUnavailableKind.MISSING_TYPE */ },
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Attempt to extract a `ts.Expression` that's equivalent to a `ts.TypeNode`, as the two have
|
|
181
|
-
* different AST shapes but can reference the same symbols.
|
|
182
|
-
*
|
|
183
|
-
* This will return `null` if an equivalent expression cannot be constructed.
|
|
184
|
-
*/
|
|
185
|
-
function typeNodeToValueExpr(node) {
|
|
186
|
-
if (typescript_1.default.isTypeReferenceNode(node)) {
|
|
187
|
-
return entityNameToValue(node.typeName);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
exports.typeNodeToValueExpr = typeNodeToValueExpr;
|
|
194
|
-
/**
|
|
195
|
-
* Resolve a `TypeReference` node to the `ts.Symbol`s for both its declaration and its local source.
|
|
196
|
-
*
|
|
197
|
-
* In the event that the `TypeReference` refers to a locally declared symbol, these will be the
|
|
198
|
-
* same. If the `TypeReference` refers to an imported symbol, then `decl` will be the fully resolved
|
|
199
|
-
* `ts.Symbol` of the referenced symbol. `local` will be the `ts.Symbol` of the `ts.Identifier`
|
|
200
|
-
* which points to the import statement by which the symbol was imported.
|
|
201
|
-
*
|
|
202
|
-
* All symbol names that make up the type reference are returned left-to-right into the
|
|
203
|
-
* `symbolNames` array, which is guaranteed to include at least one entry.
|
|
204
|
-
*/
|
|
205
|
-
function resolveTypeSymbols(typeRef, checker) {
|
|
206
|
-
const typeName = typeRef.typeName;
|
|
207
|
-
// typeRefSymbol is the ts.Symbol of the entire type reference.
|
|
208
|
-
const typeRefSymbol = checker.getSymbolAtLocation(typeName);
|
|
209
|
-
if (typeRefSymbol === undefined) {
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
// `local` is the `ts.Symbol` for the local `ts.Identifier` for the type.
|
|
213
|
-
// If the type is actually locally declared or is imported by name, for example:
|
|
214
|
-
// import {Foo} from './foo';
|
|
215
|
-
// then it'll be the same as `typeRefSymbol`.
|
|
216
|
-
//
|
|
217
|
-
// If the type is imported via a namespace import, for example:
|
|
218
|
-
// import * as foo from './foo';
|
|
219
|
-
// and then referenced as:
|
|
220
|
-
// constructor(f: foo.Foo)
|
|
221
|
-
// then `local` will be the `ts.Symbol` of `foo`, whereas `typeRefSymbol` will be the `ts.Symbol`
|
|
222
|
-
// of `foo.Foo`. This allows tracking of the import behind whatever type reference exists.
|
|
223
|
-
let local = typeRefSymbol;
|
|
224
|
-
// Destructure a name like `foo.X.Y.Z` as follows:
|
|
225
|
-
// - in `leftMost`, the `ts.Identifier` of the left-most name (`foo`) in the qualified name.
|
|
226
|
-
// This identifier is used to resolve the `ts.Symbol` for `local`.
|
|
227
|
-
// - in `symbolNames`, all names involved in the qualified path, or a single symbol name if the
|
|
228
|
-
// type is not qualified.
|
|
229
|
-
let leftMost = typeName;
|
|
230
|
-
const symbolNames = [];
|
|
231
|
-
while (typescript_1.default.isQualifiedName(leftMost)) {
|
|
232
|
-
symbolNames.unshift(leftMost.right.text);
|
|
233
|
-
leftMost = leftMost.left;
|
|
234
|
-
}
|
|
235
|
-
symbolNames.unshift(leftMost.text);
|
|
236
|
-
if (leftMost !== typeName) {
|
|
237
|
-
const localTmp = checker.getSymbolAtLocation(leftMost);
|
|
238
|
-
if (localTmp !== undefined) {
|
|
239
|
-
local = localTmp;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
// De-alias the top-level type reference symbol to get the symbol of the actual declaration.
|
|
243
|
-
let decl = typeRefSymbol;
|
|
244
|
-
if (typeRefSymbol.flags & typescript_1.default.SymbolFlags.Alias) {
|
|
245
|
-
decl = checker.getAliasedSymbol(typeRefSymbol);
|
|
246
|
-
}
|
|
247
|
-
return { local, decl, symbolNames };
|
|
248
|
-
}
|
|
249
|
-
function entityNameToValue(node) {
|
|
250
|
-
if (typescript_1.default.isQualifiedName(node)) {
|
|
251
|
-
const left = entityNameToValue(node.left);
|
|
252
|
-
return left !== null
|
|
253
|
-
? typescript_1.default.factory.createPropertyAccessExpression(left, node.right)
|
|
254
|
-
: null;
|
|
255
|
-
}
|
|
256
|
-
else if (typescript_1.default.isIdentifier(node)) {
|
|
257
|
-
const clone = typescript_1.default.setOriginalNode(typescript_1.default.factory.createIdentifier(node.text), node);
|
|
258
|
-
clone.parent = node.parent;
|
|
259
|
-
return clone;
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
exports.entityNameToValue = entityNameToValue;
|
|
266
|
-
function extractModuleName(node) {
|
|
267
|
-
if (!typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
|
|
268
|
-
throw new Error('not a module specifier');
|
|
269
|
-
}
|
|
270
|
-
return node.moduleSpecifier.text;
|
|
271
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
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 ts from 'typescript';
|
|
9
|
-
import { ClassDeclaration, ClassMember, CtorParameter, DeclarationNode, Decorator, Import, ReflectionHost } from './host';
|
|
10
|
-
/**
|
|
11
|
-
* reflector.ts implements static reflection of declarations using the TypeScript `ts.TypeChecker`.
|
|
12
|
-
*/
|
|
13
|
-
export declare class TypeScriptReflectionHost implements ReflectionHost {
|
|
14
|
-
protected checker: ts.TypeChecker;
|
|
15
|
-
private readonly isLocalCompilation;
|
|
16
|
-
constructor(checker: ts.TypeChecker, isLocalCompilation?: boolean);
|
|
17
|
-
getDecoratorsOfDeclaration(declaration: DeclarationNode): Decorator[] | null;
|
|
18
|
-
getMembersOfClass(clazz: ClassDeclaration): ClassMember[];
|
|
19
|
-
getConstructorParameters(clazz: ClassDeclaration): CtorParameter[] | null;
|
|
20
|
-
getImportOfIdentifier(id: ts.Identifier): Import | null;
|
|
21
|
-
isClass(node: ts.Node): node is ClassDeclaration;
|
|
22
|
-
hasBaseClass(clazz: ClassDeclaration): boolean;
|
|
23
|
-
getBaseClassExpression(clazz: ClassDeclaration): ts.Expression | null;
|
|
24
|
-
getGenericArityOfClass(clazz: ClassDeclaration): number | null;
|
|
25
|
-
protected getDirectImportOfIdentifier(id: ts.Identifier): Import | null;
|
|
26
|
-
/**
|
|
27
|
-
* Try to get the import info for this identifier as though it is a namespaced import.
|
|
28
|
-
*
|
|
29
|
-
* For example, if the identifier is the `Directive` part of a qualified type chain like:
|
|
30
|
-
*
|
|
31
|
-
* ```
|
|
32
|
-
* core.Directive
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* then it might be that `core` is a namespace import such as:
|
|
36
|
-
*
|
|
37
|
-
* ```
|
|
38
|
-
* import * as core from 'tslib';
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @param id the TypeScript identifier to find the import info for.
|
|
42
|
-
* @returns The import info if this is a namespaced import or `null`.
|
|
43
|
-
*/
|
|
44
|
-
protected getImportOfNamespacedIdentifier(id: ts.Identifier, namespaceIdentifier: ts.Identifier | null): Import | null;
|
|
45
|
-
private _reflectDecorator;
|
|
46
|
-
private _reflectMember;
|
|
47
|
-
private _viaModule;
|
|
48
|
-
}
|
|
49
|
-
export declare function reflectObjectLiteral(node: ts.ObjectLiteralExpression): Map<string, ts.Expression>;
|
|
50
|
-
/**
|
|
51
|
-
* Gets the closest ancestor `ImportDeclaration` to a node.
|
|
52
|
-
*/
|
|
53
|
-
export declare function getContainingImportDeclaration(node: ts.Node): ts.ImportDeclaration | null;
|