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.
Files changed (179) hide show
  1. package/{import/commonjs → commonjs}/index.js +29 -197
  2. package/{import/es2022 → es2022}/di/interface/defs.js +5 -1
  3. package/{import/es2022 → es2022}/index.js +0 -1
  4. package/{transform/compiler/index.d.ts → es2022/interface/lifecycle_hooks.js} +1 -1
  5. package/{transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js → es2022/render3/definition_factory.js} +3 -2
  6. package/es2022/util/decorators.js +31 -0
  7. package/{import/fesm2022 → fesm2022}/index.js +30 -196
  8. package/package.json +17 -14
  9. package/readme.md +32 -12
  10. package/{import/typings → typings}/di/injectable.d.ts +0 -7
  11. package/{import/typings → typings}/index.d.ts +0 -1
  12. package/import/es2022/di/injectable.js +0 -14
  13. package/import/es2022/error_details_base_url.js +0 -19
  14. package/import/es2022/render3/definition_factory.js +0 -14
  15. package/import/es2022/render3/di.js +0 -49
  16. package/import/es2022/render3/error_code.js +0 -30
  17. package/import/es2022/util/array_utils.js +0 -17
  18. package/import/es2022/util/decorators.js +0 -53
  19. package/import/typings/error_details_base_url.d.ts +0 -19
  20. package/import/typings/render3/di.d.ts +0 -12
  21. package/import/typings/render3/error_code.d.ts +0 -24
  22. package/import/typings/util/array_utils.d.ts +0 -25
  23. package/transform/compiler/compiler.d.ts +0 -8
  24. package/transform/compiler/compiler.js +0 -28
  25. package/transform/compiler/index.js +0 -28
  26. package/transform/compiler/public_api.d.ts +0 -13
  27. package/transform/compiler/public_api.js +0 -30
  28. package/transform/compiler/src/compiler.d.ts +0 -5
  29. package/transform/compiler/src/compiler.js +0 -21
  30. package/transform/compiler/src/core.d.ts +0 -25
  31. package/transform/compiler/src/core.js +0 -22
  32. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -23
  33. package/transform/compiler/src/injectable_compiler_2.js +0 -171
  34. package/transform/compiler/src/output/output_ast.d.ts +0 -512
  35. package/transform/compiler/src/output/output_ast.js +0 -1109
  36. package/transform/compiler/src/parse_util.d.ts +0 -50
  37. package/transform/compiler/src/parse_util.js +0 -71
  38. package/transform/compiler/src/render3/partial/api.d.ts +0 -171
  39. package/transform/compiler/src/render3/partial/api.js +0 -18
  40. package/transform/compiler/src/render3/r3_factory.d.ts +0 -82
  41. package/transform/compiler/src/render3/r3_factory.js +0 -225
  42. package/transform/compiler/src/render3/r3_identifiers.d.ts +0 -20
  43. package/transform/compiler/src/render3/r3_identifiers.js +0 -55
  44. package/transform/compiler/src/render3/util.d.ts +0 -85
  45. package/transform/compiler/src/render3/util.js +0 -82
  46. package/transform/compiler/src/render3/view/util.d.ts +0 -24
  47. package/transform/compiler/src/render3/view/util.js +0 -59
  48. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +0 -3
  49. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +0 -19
  50. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +0 -37
  51. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +0 -195
  52. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.d.ts +0 -11
  53. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +0 -22
  54. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +0 -64
  55. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +0 -189
  56. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +0 -43
  57. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +0 -277
  58. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +0 -24
  59. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +0 -84
  60. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +0 -188
  61. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +0 -206
  62. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +0 -2
  63. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +0 -18
  64. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +0 -1
  65. package/transform/compiler-cli/src/ngtsc/imports/index.js +0 -17
  66. package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +0 -36
  67. package/transform/compiler-cli/src/ngtsc/imports/src/core.js +0 -25
  68. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +0 -19
  69. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +0 -27
  70. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +0 -3
  71. package/transform/compiler-cli/src/ngtsc/reflection/index.js +0 -19
  72. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +0 -522
  73. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +0 -34
  74. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +0 -25
  75. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +0 -271
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +0 -53
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +0 -393
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +0 -12
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +0 -29
  80. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +0 -2
  81. package/transform/compiler-cli/src/ngtsc/transform/index.js +0 -18
  82. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +0 -115
  83. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -29
  84. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +0 -15
  85. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +0 -79
  86. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +0 -5
  87. package/transform/compiler-cli/src/ngtsc/translator/index.js +0 -21
  88. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +0 -289
  89. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +0 -27
  90. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +0 -9
  91. package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +0 -18
  92. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +0 -28
  93. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +0 -47
  94. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +0 -66
  95. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -56
  96. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +0 -270
  97. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.d.ts +0 -12
  98. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.js +0 -27
  99. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +0 -53
  100. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +0 -250
  101. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +0 -13
  102. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +0 -21
  103. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +0 -8
  104. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +0 -24
  105. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +0 -45
  106. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +0 -86
  107. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +0 -4
  108. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +0 -16
  109. package/transform/index.d.ts +0 -1
  110. package/transform/index.js +0 -17
  111. package/transform/injectable-transform.d.ts +0 -41
  112. package/transform/injectable-transform.js +0 -245
  113. package/transform/node-Iteration.d.ts +0 -2
  114. package/transform/node-Iteration.js +0 -12
  115. /package/{import/es2022 → es2022}/di/create_injector.js +0 -0
  116. /package/{import/es2022 → es2022}/di/forward_ref.js +0 -0
  117. /package/{import/es2022 → es2022}/di/index.js +0 -0
  118. /package/{import/es2022 → es2022}/di/initializer_token.js +0 -0
  119. /package/{import/es2022 → es2022}/di/inject_switch.js +0 -0
  120. /package/{import/es2022/di/injector_marker.js → es2022/di/injectable.js} +0 -0
  121. /package/{import/es2022 → es2022}/di/injection_token.js +0 -0
  122. /package/{import/es2022 → es2022}/di/injector.js +0 -0
  123. /package/{import/es2022 → es2022}/di/injector_compatibility.js +0 -0
  124. /package/{import/es2022/di/provider_token.js → es2022/di/injector_marker.js} +0 -0
  125. /package/{import/es2022 → es2022}/di/injector_token.js +0 -0
  126. /package/{import/es2022 → es2022}/di/interface/injector.js +0 -0
  127. /package/{import/es2022 → es2022}/di/interface/provider.js +0 -0
  128. /package/{import/es2022 → es2022}/di/internal_tokens.js +0 -0
  129. /package/{import/es2022 → es2022}/di/metadata.js +0 -0
  130. /package/{import/es2022 → es2022}/di/null_injector.js +0 -0
  131. /package/{import/es2022 → es2022}/di/provider_collection.js +0 -0
  132. /package/{import/es2022/interface/lifecycle_hooks.js → es2022/di/provider_token.js} +0 -0
  133. /package/{import/es2022 → es2022}/di/r3_injector.js +0 -0
  134. /package/{import/es2022 → es2022}/di/scope.js +0 -0
  135. /package/{import/es2022 → es2022}/di.js +0 -0
  136. /package/{import/es2022 → es2022}/errors.js +0 -0
  137. /package/{import/es2022 → es2022}/interface/type.js +0 -0
  138. /package/{import/es2022 → es2022}/render3/errors_di.js +0 -0
  139. /package/{import/es2022 → es2022}/render3/fields.js +0 -0
  140. /package/{import/es2022 → es2022}/render3/instructions/di.js +0 -0
  141. /package/{import/es2022 → es2022}/render3/util/stringify_utils.js +0 -0
  142. /package/{import/es2022 → es2022}/util/closure.js +0 -0
  143. /package/{import/es2022 → es2022}/util/empty.js +0 -0
  144. /package/{import/es2022 → es2022}/util/property.js +0 -0
  145. /package/{import/es2022 → es2022}/util/stringify.js +0 -0
  146. /package/{import/typings → typings}/di/create_injector.d.ts +0 -0
  147. /package/{import/typings → typings}/di/forward_ref.d.ts +0 -0
  148. /package/{import/typings → typings}/di/index.d.ts +0 -0
  149. /package/{import/typings → typings}/di/initializer_token.d.ts +0 -0
  150. /package/{import/typings → typings}/di/inject_switch.d.ts +0 -0
  151. /package/{import/typings → typings}/di/injection_token.d.ts +0 -0
  152. /package/{import/typings → typings}/di/injector.d.ts +0 -0
  153. /package/{import/typings → typings}/di/injector_compatibility.d.ts +0 -0
  154. /package/{import/typings → typings}/di/injector_marker.d.ts +0 -0
  155. /package/{import/typings → typings}/di/injector_token.d.ts +0 -0
  156. /package/{import/typings → typings}/di/interface/defs.d.ts +0 -0
  157. /package/{import/typings → typings}/di/interface/injector.d.ts +0 -0
  158. /package/{import/typings → typings}/di/interface/provider.d.ts +0 -0
  159. /package/{import/typings → typings}/di/internal_tokens.d.ts +0 -0
  160. /package/{import/typings → typings}/di/metadata.d.ts +0 -0
  161. /package/{import/typings → typings}/di/null_injector.d.ts +0 -0
  162. /package/{import/typings → typings}/di/provider_collection.d.ts +0 -0
  163. /package/{import/typings → typings}/di/provider_token.d.ts +0 -0
  164. /package/{import/typings → typings}/di/r3_injector.d.ts +0 -0
  165. /package/{import/typings → typings}/di/scope.d.ts +0 -0
  166. /package/{import/typings → typings}/di.d.ts +0 -0
  167. /package/{import/typings → typings}/errors.d.ts +0 -0
  168. /package/{import/typings → typings}/interface/lifecycle_hooks.d.ts +0 -0
  169. /package/{import/typings → typings}/interface/type.d.ts +0 -0
  170. /package/{import/typings → typings}/render3/definition_factory.d.ts +0 -0
  171. /package/{import/typings → typings}/render3/errors_di.d.ts +0 -0
  172. /package/{import/typings → typings}/render3/fields.d.ts +0 -0
  173. /package/{import/typings → typings}/render3/instructions/di.d.ts +0 -0
  174. /package/{import/typings → typings}/render3/util/stringify_utils.d.ts +0 -0
  175. /package/{import/typings → typings}/util/closure.d.ts +0 -0
  176. /package/{import/typings → typings}/util/decorators.d.ts +0 -0
  177. /package/{import/typings → typings}/util/empty.d.ts +0 -0
  178. /package/{import/typings → typings}/util/property.d.ts +0 -0
  179. /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;