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.
Files changed (72) hide show
  1. package/import/commonjs/index.js +6 -6
  2. package/import/es2015/di/r3_injector.js +6 -6
  3. package/import/fesm2015/index.js +6 -6
  4. package/import/typings/di/injectable.d.ts +1 -1
  5. package/import/typings/di/interface/provider.d.ts +2 -2
  6. package/import/typings/di/provider_collection.d.ts +1 -1
  7. package/import/typings/di/provider_token.d.ts +1 -1
  8. package/import/typings/di/r3_injector.d.ts +1 -1
  9. package/import/typings/di/scope.d.ts +1 -1
  10. package/import/typings/render3/definition_factory.d.ts +1 -1
  11. package/package.json +3 -3
  12. package/transform/compiler/compiler.d.ts +8 -0
  13. package/transform/compiler/compiler.js +28 -0
  14. package/transform/compiler/index.d.ts +8 -5
  15. package/transform/compiler/index.js +12 -5
  16. package/transform/compiler/public_api.d.ts +13 -0
  17. package/transform/compiler/public_api.js +30 -0
  18. package/transform/compiler/src/compiler.d.ts +27 -0
  19. package/transform/compiler/src/compiler.js +47 -0
  20. package/transform/compiler/src/output/output_ast.d.ts +1 -1
  21. package/transform/compiler/src/render3/partial/api.d.ts +1 -1
  22. package/transform/compiler/src/render3/partial/api.js +7 -0
  23. package/transform/compiler/src/render3/r3_factory.d.ts +8 -15
  24. package/transform/compiler/src/render3/r3_factory.js +37 -56
  25. package/transform/compiler/src/render3/view/util.d.ts +0 -8
  26. package/transform/compiler/src/render3/view/util.js +0 -8
  27. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +10 -0
  28. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +26 -0
  29. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +37 -0
  30. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +197 -0
  31. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.d.ts +3 -3
  32. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.js +2 -2
  33. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +3 -34
  34. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +18 -216
  35. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
  36. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +31 -50
  37. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
  38. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +7 -0
  39. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
  40. package/transform/compiler-cli/src/ngtsc/imports/index.js +7 -0
  41. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +19 -0
  42. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +28 -0
  43. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +10 -3
  44. package/transform/compiler-cli/src/ngtsc/reflection/index.js +7 -0
  45. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +12 -13
  46. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +7 -28
  47. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +1 -1
  48. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +17 -41
  49. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
  50. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +46 -65
  51. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
  52. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -27
  53. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
  54. package/transform/compiler-cli/src/ngtsc/transform/index.js +7 -0
  55. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
  56. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +1 -1
  57. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +15 -35
  58. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
  59. package/transform/compiler-cli/src/ngtsc/translator/index.js +7 -0
  60. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +5 -5
  61. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +2 -2
  62. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -24
  63. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -2
  64. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +1 -1
  65. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +1 -1
  66. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +76 -95
  67. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
  68. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +20 -126
  69. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +23 -147
  70. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
  71. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -31
  72. package/transform/injectable-transform.js +36 -7
@@ -6,96 +6,14 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
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
- exports.isAbstractClassDeclaration = exports.toFactoryMetadata = exports.wrapTypeReference = exports.wrapFunctionExpressionsInParens = exports.tryUnwrapForwardRef = exports.unwrapExpression = exports.isAngularDecorator = exports.findAngularDecorator = exports.isAngularCore = exports.validateConstructorDependencies = exports.getValidConstructorDependencies = exports.unwrapConstructorDependencies = exports.valueReferenceToExpression = exports.getConstructorDependencies = void 0;
34
- const compiler_1 = require("../../../../../../compiler");
35
- const ts = __importStar(require("typescript"));
36
- const diagnostics_1 = require("../../../diagnostics");
13
+ exports.isAbstractClassDeclaration = exports.toFactoryMetadata = exports.wrapTypeReference = exports.wrapFunctionExpressionsInParens = exports.tryUnwrapForwardRef = exports.unwrapExpression = exports.isAngularDecorator = exports.findAngularDecorator = exports.isAngularCore = exports.valueReferenceToExpression = void 0;
14
+ const compiler_1 = require("static-injector/transform/compiler");
15
+ const typescript_1 = __importDefault(require("typescript"));
37
16
  const reflection_1 = require("../../../reflection");
38
- function getConstructorDependencies(clazz, reflector, isCore) {
39
- const deps = [];
40
- const errors = [];
41
- let ctorParams = reflector.getConstructorParameters(clazz);
42
- if (ctorParams === null) {
43
- if (reflector.hasBaseClass(clazz)) {
44
- return null;
45
- }
46
- else {
47
- ctorParams = [];
48
- }
49
- }
50
- ctorParams.forEach((param, idx) => {
51
- let token = valueReferenceToExpression(param.typeValueReference);
52
- let attributeNameType = null;
53
- let optional = false, self = false, skipSelf = false;
54
- (param.decorators || [])
55
- .filter((dec) => isCore || isAngularCore(dec))
56
- .forEach((dec) => {
57
- const name = isCore || dec.import === null ? dec.name : dec.import.name;
58
- if (name === 'Inject') {
59
- if (dec.args === null || dec.args.length !== 1) {
60
- throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARITY_WRONG, reflection_1.Decorator.nodeForError(dec), `Unexpected number of arguments to @Inject().`);
61
- }
62
- token = new compiler_1.WrappedNodeExpr(dec.args[0]);
63
- }
64
- else if (name === 'Optional') {
65
- optional = true;
66
- }
67
- else if (name === 'SkipSelf') {
68
- skipSelf = true;
69
- }
70
- else if (name === 'Self') {
71
- self = true;
72
- }
73
- else {
74
- throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_UNEXPECTED, reflection_1.Decorator.nodeForError(dec), `Unexpected decorator ${name} on parameter.`);
75
- }
76
- });
77
- if (token === null) {
78
- if (param.typeValueReference.kind !== 2 /* TypeValueReferenceKind.UNAVAILABLE */) {
79
- throw new Error('Illegal state: expected value reference to be unavailable if no token is present');
80
- }
81
- errors.push({
82
- index: idx,
83
- param,
84
- reason: param.typeValueReference.reason,
85
- });
86
- }
87
- else {
88
- deps.push({ token, attributeNameType, optional, self, skipSelf });
89
- }
90
- });
91
- if (errors.length === 0) {
92
- return { deps };
93
- }
94
- else {
95
- return { deps: null, errors };
96
- }
97
- }
98
- exports.getConstructorDependencies = getConstructorDependencies;
99
17
  function valueReferenceToExpression(valueRef) {
100
18
  if (valueRef.kind === 2 /* TypeValueReferenceKind.UNAVAILABLE */) {
101
19
  return null;
@@ -118,121 +36,6 @@ function valueReferenceToExpression(valueRef) {
118
36
  }
119
37
  }
120
38
  exports.valueReferenceToExpression = valueReferenceToExpression;
121
- /**
122
- * Convert `ConstructorDeps` into the `R3DependencyMetadata` array for those deps if they're valid,
123
- * or into an `'invalid'` signal if they're not.
124
- *
125
- * This is a companion function to `validateConstructorDependencies` which accepts invalid deps.
126
- */
127
- function unwrapConstructorDependencies(deps) {
128
- if (deps === null) {
129
- return null;
130
- }
131
- else if (deps.deps !== null) {
132
- // These constructor dependencies are valid.
133
- return deps.deps;
134
- }
135
- else {
136
- // These deps are invalid.
137
- return 'invalid';
138
- }
139
- }
140
- exports.unwrapConstructorDependencies = unwrapConstructorDependencies;
141
- function getValidConstructorDependencies(clazz, reflector, isCore) {
142
- return validateConstructorDependencies(clazz, getConstructorDependencies(clazz, reflector, isCore));
143
- }
144
- exports.getValidConstructorDependencies = getValidConstructorDependencies;
145
- /**
146
- * Validate that `ConstructorDeps` does not have any invalid dependencies and convert them into the
147
- * `R3DependencyMetadata` array if so, or raise a diagnostic if some deps are invalid.
148
- *
149
- * This is a companion function to `unwrapConstructorDependencies` which does not accept invalid
150
- * deps.
151
- */
152
- function validateConstructorDependencies(clazz, deps) {
153
- if (deps === null) {
154
- return null;
155
- }
156
- else if (deps.deps !== null) {
157
- return deps.deps;
158
- }
159
- else {
160
- // TODO(alxhub): this cast is necessary because the g3 typescript version doesn't narrow here.
161
- // There is at least one error.
162
- const error = deps.errors[0];
163
- throw createUnsuitableInjectionTokenError(clazz, error);
164
- }
165
- }
166
- exports.validateConstructorDependencies = validateConstructorDependencies;
167
- /**
168
- * Creates a fatal error with diagnostic for an invalid injection token.
169
- * @param clazz The class for which the injection token was unavailable.
170
- * @param error The reason why no valid injection token is available.
171
- */
172
- function createUnsuitableInjectionTokenError(clazz, error) {
173
- const { param, index, reason } = error;
174
- let chainMessage = undefined;
175
- let hints = undefined;
176
- switch (reason.kind) {
177
- case 5 /* ValueUnavailableKind.UNSUPPORTED */:
178
- chainMessage =
179
- 'Consider using the @Inject decorator to specify an injection token.';
180
- hints = [
181
- (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type is not supported as injection token.'),
182
- ];
183
- break;
184
- case 1 /* ValueUnavailableKind.NO_VALUE_DECLARATION */:
185
- chainMessage =
186
- 'Consider using the @Inject decorator to specify an injection token.';
187
- hints = [
188
- (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type does not have a value, so it cannot be used as injection token.'),
189
- ];
190
- if (reason.decl !== null) {
191
- hints.push((0, diagnostics_1.makeRelatedInformation)(reason.decl, 'The type is declared here.'));
192
- }
193
- break;
194
- case 2 /* ValueUnavailableKind.TYPE_ONLY_IMPORT */:
195
- chainMessage =
196
- 'Consider changing the type-only import to a regular import, or use the @Inject decorator to specify an injection token.';
197
- hints = [
198
- (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type is imported using a type-only import, which prevents it from being usable as an injection token.'),
199
- (0, diagnostics_1.makeRelatedInformation)(reason.node, 'The type-only import occurs here.'),
200
- ];
201
- break;
202
- case 4 /* ValueUnavailableKind.NAMESPACE */:
203
- chainMessage =
204
- 'Consider using the @Inject decorator to specify an injection token.';
205
- hints = [
206
- (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type corresponds with a namespace, which cannot be used as injection token.'),
207
- (0, diagnostics_1.makeRelatedInformation)(reason.importClause, 'The namespace import occurs here.'),
208
- ];
209
- break;
210
- case 3 /* ValueUnavailableKind.UNKNOWN_REFERENCE */:
211
- chainMessage = 'The type should reference a known declaration.';
212
- hints = [
213
- (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type could not be resolved.'),
214
- ];
215
- break;
216
- case 0 /* ValueUnavailableKind.MISSING_TYPE */:
217
- chainMessage =
218
- 'Consider adding a type to the parameter or use the @Inject decorator to specify an injection token.';
219
- break;
220
- }
221
- const chain = {
222
- messageText: `No suitable injection token for parameter '${param.name || index}' of class '${clazz.name.text}'.`,
223
- category: ts.DiagnosticCategory.Error,
224
- code: 0,
225
- next: [
226
- {
227
- messageText: chainMessage,
228
- category: ts.DiagnosticCategory.Message,
229
- code: 0,
230
- },
231
- ],
232
- };
233
- return new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.PARAM_MISSING_TOKEN, param.nameNode, chain, hints);
234
- }
235
- /** todo 需要改成自己的依赖包 */
236
39
  function isAngularCore(decorator) {
237
40
  return (decorator.import !== null && decorator.import.from === 'static-injector');
238
41
  }
@@ -258,7 +61,7 @@ exports.isAngularDecorator = isAngularDecorator;
258
61
  * For example, the expression "(foo as Type)" unwraps to "foo".
259
62
  */
260
63
  function unwrapExpression(node) {
261
- while (ts.isAsExpression(node) || ts.isParenthesizedExpression(node)) {
64
+ while (typescript_1.default.isAsExpression(node) || typescript_1.default.isParenthesizedExpression(node)) {
262
65
  node = node.expression;
263
66
  }
264
67
  return node;
@@ -266,18 +69,18 @@ function unwrapExpression(node) {
266
69
  exports.unwrapExpression = unwrapExpression;
267
70
  function expandForwardRef(arg) {
268
71
  arg = unwrapExpression(arg);
269
- if (!ts.isArrowFunction(arg) && !ts.isFunctionExpression(arg)) {
72
+ if (!typescript_1.default.isArrowFunction(arg) && !typescript_1.default.isFunctionExpression(arg)) {
270
73
  return null;
271
74
  }
272
75
  const body = arg.body;
273
76
  // Either the body is a ts.Expression directly, or a block with a single return statement.
274
- if (ts.isBlock(body)) {
77
+ if (typescript_1.default.isBlock(body)) {
275
78
  // Block body - look for a single return statement.
276
79
  if (body.statements.length !== 1) {
277
80
  return null;
278
81
  }
279
82
  const stmt = body.statements[0];
280
- if (!ts.isReturnStatement(stmt) || stmt.expression === undefined) {
83
+ if (!typescript_1.default.isReturnStatement(stmt) || stmt.expression === undefined) {
281
84
  return null;
282
85
  }
283
86
  return stmt.expression;
@@ -298,13 +101,13 @@ function expandForwardRef(arg) {
298
101
  */
299
102
  function tryUnwrapForwardRef(node, reflector) {
300
103
  node = unwrapExpression(node);
301
- if (!ts.isCallExpression(node) || node.arguments.length !== 1) {
104
+ if (!typescript_1.default.isCallExpression(node) || node.arguments.length !== 1) {
302
105
  return null;
303
106
  }
304
- const fn = ts.isPropertyAccessExpression(node.expression)
107
+ const fn = typescript_1.default.isPropertyAccessExpression(node.expression)
305
108
  ? node.expression.name
306
109
  : node.expression;
307
- if (!ts.isIdentifier(fn)) {
110
+ if (!typescript_1.default.isIdentifier(fn)) {
308
111
  return null;
309
112
  }
310
113
  const expr = expandForwardRef(node.arguments[0]);
@@ -312,7 +115,6 @@ function tryUnwrapForwardRef(node, reflector) {
312
115
  return null;
313
116
  }
314
117
  const imp = reflector.getImportOfIdentifier(fn);
315
- //todo 更换包名
316
118
  if (imp === null ||
317
119
  imp.from !== 'static-injector' ||
318
120
  imp.name !== 'forwardRef') {
@@ -323,13 +125,13 @@ function tryUnwrapForwardRef(node, reflector) {
323
125
  exports.tryUnwrapForwardRef = tryUnwrapForwardRef;
324
126
  const parensWrapperTransformerFactory = (context) => {
325
127
  const visitor = (node) => {
326
- const visited = ts.visitEachChild(node, visitor, context);
327
- if (ts.isArrowFunction(visited) || ts.isFunctionExpression(visited)) {
328
- return ts.createParen(visited);
128
+ const visited = typescript_1.default.visitEachChild(node, visitor, context);
129
+ if (typescript_1.default.isArrowFunction(visited) || typescript_1.default.isFunctionExpression(visited)) {
130
+ return typescript_1.default.factory.createParenthesizedExpression(visited);
329
131
  }
330
132
  return visited;
331
133
  };
332
- return (node) => ts.visitEachChild(node, visitor, context);
134
+ return (node) => typescript_1.default.visitEachChild(node, visitor, context);
333
135
  };
334
136
  /**
335
137
  * Wraps all functions in a given expression in parentheses. This is needed to avoid problems
@@ -342,7 +144,7 @@ const parensWrapperTransformerFactory = (context) => {
342
144
  * @param expression Expression where functions should be wrapped in parentheses
343
145
  */
344
146
  function wrapFunctionExpressionsInParens(expression) {
345
- return ts.transform(expression, [parensWrapperTransformerFactory])
147
+ return typescript_1.default.transform(expression, [parensWrapperTransformerFactory])
346
148
  .transformed[0];
347
149
  }
348
150
  exports.wrapFunctionExpressionsInParens = wrapFunctionExpressionsInParens;
@@ -374,6 +176,6 @@ function toFactoryMetadata(meta, target) {
374
176
  exports.toFactoryMetadata = toFactoryMetadata;
375
177
  function isAbstractClassDeclaration(clazz) {
376
178
  return (clazz.modifiers !== undefined &&
377
- clazz.modifiers.some((mod) => mod.kind === ts.SyntaxKind.AbstractKeyword));
179
+ clazz.modifiers.some((mod) => mod.kind === typescript_1.default.SyntaxKind.AbstractKeyword));
378
180
  }
379
181
  exports.isAbstractClassDeclaration = isAbstractClassDeclaration;
@@ -5,17 +5,17 @@
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 { R3DependencyMetadata, R3InjectableMetadata } from '../../../../../compiler';
8
+ import { R3DependencyMetadata, R3InjectableMetadata } from 'static-injector/transform/compiler';
9
9
  import { ClassDeclaration, Decorator, ReflectionHost } from '../../reflection';
10
10
  import { AnalysisOutput, CompileResult, DecoratorHandler, DetectResult } from '../../transform';
11
- interface InjectableHandlerData {
11
+ export interface InjectableHandlerData {
12
12
  meta: R3InjectableMetadata;
13
13
  ctorDeps: R3DependencyMetadata[] | 'invalid' | null;
14
14
  }
15
15
  /**
16
16
  * Adapts the `compileInjectable` compiler for `@Injectable` decorators to the Ivy compiler.
17
17
  */
18
- export declare class InjectableDecoratorHandler implements DecoratorHandler<Decorator, InjectableHandlerData, null, unknown> {
18
+ export declare class InjectableDecoratorHandler implements DecoratorHandler<Decorator, InjectableHandlerData, unknown> {
19
19
  private reflector;
20
20
  private isCore;
21
21
  private strictCtorDeps;
@@ -39,4 +39,3 @@ export declare class InjectableDecoratorHandler implements DecoratorHandler<Deco
39
39
  compileFull(node: ClassDeclaration, analysis: Readonly<InjectableHandlerData>): CompileResult[];
40
40
  private compile;
41
41
  }
42
- export {};
@@ -6,38 +6,17 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = { enumerable: true, get: function() { return m[k]; } };
14
- }
15
- Object.defineProperty(o, k2, desc);
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || function (mod) {
26
- if (mod && mod.__esModule) return mod;
27
- var result = {};
28
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
- __setModuleDefault(result, mod);
30
- return result;
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
31
11
  };
32
12
  Object.defineProperty(exports, "__esModule", { value: true });
33
13
  exports.InjectableDecoratorHandler = void 0;
34
- const compiler_1 = require("../../../../../compiler");
35
- const ts = __importStar(require("typescript"));
14
+ const compiler_1 = require("static-injector/transform/compiler");
15
+ const typescript_1 = __importDefault(require("typescript"));
16
+ const common_1 = require("../../annotations/common");
36
17
  const diagnostics_1 = require("../../diagnostics");
37
18
  const reflection_1 = require("../../reflection");
38
- const factory_1 = require("./factory");
39
- const util_1 = require("../common/src/util");
40
- const util_2 = require("../common/src/util");
19
+ const common_2 = require("../common");
41
20
  /**
42
21
  * Adapts the `compileInjectable` compiler for `@Injectable` decorators to the Ivy compiler.
43
22
  */
@@ -59,7 +38,7 @@ class InjectableDecoratorHandler {
59
38
  if (!decorators) {
60
39
  return undefined;
61
40
  }
62
- const decorator = (0, util_1.findAngularDecorator)(decorators, 'Injectable', this.isCore);
41
+ const decorator = (0, common_2.findAngularDecorator)(decorators, 'Injectable', this.isCore);
63
42
  if (decorator !== undefined) {
64
43
  return {
65
44
  trigger: decorator.node,
@@ -83,13 +62,15 @@ class InjectableDecoratorHandler {
83
62
  };
84
63
  }
85
64
  compileFull(node, analysis) {
86
- return this.compile(factory_1.compileNgFactoryDefField, (meta) => (0, compiler_1.compileInjectable)(meta, false), node, analysis);
65
+ return this.compile(common_2.compileNgFactoryDefField, (meta) => (0, compiler_1.compileInjectable)(meta, false), node, analysis);
87
66
  }
88
67
  compile(compileFactoryFn, compileInjectableFn, node, analysis) {
89
68
  const results = [];
90
- const meta = analysis.meta;
91
- const factoryRes = compileFactoryFn((0, util_1.toFactoryMetadata)(Object.assign(Object.assign({}, meta), { deps: analysis.ctorDeps }), compiler_1.FactoryTarget.Injectable));
92
- results.push(factoryRes);
69
+ if (true) {
70
+ const meta = analysis.meta;
71
+ const factoryRes = compileFactoryFn((0, common_2.toFactoryMetadata)(Object.assign(Object.assign({}, meta), { deps: analysis.ctorDeps }), compiler_1.FactoryTarget.Injectable));
72
+ results.push(factoryRes);
73
+ }
93
74
  const ɵprov = this.reflector
94
75
  .getMembersOfClass(node)
95
76
  .find((member) => member.name === 'ɵprov');
@@ -118,7 +99,7 @@ exports.InjectableDecoratorHandler = InjectableDecoratorHandler;
118
99
  */
119
100
  function extractInjectableMetadata(clazz, decorator, reflector) {
120
101
  const name = clazz.name.text;
121
- const type = (0, util_1.wrapTypeReference)(reflector, clazz);
102
+ const type = (0, common_2.wrapTypeReference)(reflector, clazz);
122
103
  const internalType = new compiler_1.WrappedNodeExpr(reflector.getInternalNameOfClass(clazz));
123
104
  const typeArgumentCount = reflector.getGenericArityOfClass(clazz) || 0;
124
105
  if (decorator.args === null) {
@@ -138,7 +119,7 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
138
119
  // Firstly make sure the decorator argument is an inline literal - if not, it's illegal to
139
120
  // transport references from one location to another. This is the problem that lowering
140
121
  // used to solve - if this restriction proves too undesirable we can re-implement lowering.
141
- if (!ts.isObjectLiteralExpression(metaNode)) {
122
+ if (!typescript_1.default.isObjectLiteralExpression(metaNode)) {
142
123
  throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARG_NOT_LITERAL, metaNode, `@Injectable argument must be an object literal`);
143
124
  }
144
125
  // Resolve the fields of the literal into a map of field name to expression.
@@ -149,7 +130,7 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
149
130
  let deps = undefined;
150
131
  if ((meta.has('useClass') || meta.has('useFactory')) && meta.has('deps')) {
151
132
  const depsExpr = meta.get('deps');
152
- if (!ts.isArrayLiteralExpression(depsExpr)) {
133
+ if (!typescript_1.default.isArrayLiteralExpression(depsExpr)) {
153
134
  throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.VALUE_NOT_LITERAL, depsExpr, `@Injectable deps metadata must be an inline array`);
154
135
  }
155
136
  deps = depsExpr.elements.map((dep) => getDep(dep, reflector));
@@ -189,7 +170,7 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
189
170
  * object to indicate whether the value needed unwrapping.
190
171
  */
191
172
  function getProviderExpression(expression, reflector) {
192
- const forwardRefValue = (0, util_1.tryUnwrapForwardRef)(expression, reflector);
173
+ const forwardRefValue = (0, common_2.tryUnwrapForwardRef)(expression, reflector);
193
174
  return (0, compiler_1.createMayBeForwardRefExpression)(new compiler_1.WrappedNodeExpr(forwardRefValue !== null && forwardRefValue !== void 0 ? forwardRefValue : expression), forwardRefValue !== null
194
175
  ? 2 /* ForwardRefHandling.Unwrapped */
195
176
  : 0 /* ForwardRefHandling.None */);
@@ -208,25 +189,25 @@ function extractInjectableCtorDeps(clazz, meta, decorator, reflector, isCore, st
208
189
  // To deal with this, @Injectable() without an argument is more lenient, and if the
209
190
  // constructor signature does not work for DI then a factory definition (ɵfac) that throws is
210
191
  // generated.
211
- if (strictCtorDeps) {
212
- ctorDeps = (0, util_1.getValidConstructorDependencies)(clazz, reflector, isCore);
192
+ if (strictCtorDeps && !(0, common_1.isAbstractClassDeclaration)(clazz)) {
193
+ ctorDeps = (0, common_2.getValidConstructorDependencies)(clazz, reflector, isCore);
213
194
  }
214
195
  else {
215
- ctorDeps = (0, util_1.unwrapConstructorDependencies)((0, util_1.getConstructorDependencies)(clazz, reflector, isCore));
196
+ ctorDeps = (0, common_2.unwrapConstructorDependencies)((0, common_2.getConstructorDependencies)(clazz, reflector, isCore));
216
197
  }
217
198
  return ctorDeps;
218
199
  }
219
200
  else if (decorator.args.length === 1) {
220
- const rawCtorDeps = (0, util_1.getConstructorDependencies)(clazz, reflector, isCore);
201
+ const rawCtorDeps = (0, common_2.getConstructorDependencies)(clazz, reflector, isCore);
221
202
  if (strictCtorDeps &&
222
- !(0, util_2.isAbstractClassDeclaration)(clazz) &&
203
+ !(0, common_1.isAbstractClassDeclaration)(clazz) &&
223
204
  requiresValidCtor(meta)) {
224
205
  // Since use* was not provided for a concrete class, validate the deps according to
225
206
  // strictCtorDeps.
226
- ctorDeps = (0, util_1.validateConstructorDependencies)(clazz, rawCtorDeps);
207
+ ctorDeps = (0, common_2.validateConstructorDependencies)(clazz, rawCtorDeps);
227
208
  }
228
209
  else {
229
- ctorDeps = (0, util_1.unwrapConstructorDependencies)(rawCtorDeps);
210
+ ctorDeps = (0, common_2.unwrapConstructorDependencies)(rawCtorDeps);
230
211
  }
231
212
  }
232
213
  return ctorDeps;
@@ -270,18 +251,18 @@ function getDep(dep, reflector) {
270
251
  }
271
252
  return true;
272
253
  }
273
- if (ts.isArrayLiteralExpression(dep)) {
254
+ if (typescript_1.default.isArrayLiteralExpression(dep)) {
274
255
  dep.elements.forEach((el) => {
275
- let isParametersDecorator = false;
276
- if (ts.isIdentifier(el)) {
277
- isParametersDecorator = maybeUpdateDecorator(el, reflector);
256
+ let isDecorator = false;
257
+ if (typescript_1.default.isIdentifier(el)) {
258
+ isDecorator = maybeUpdateDecorator(el, reflector);
278
259
  }
279
- else if (ts.isNewExpression(el) && ts.isIdentifier(el.expression)) {
260
+ else if (typescript_1.default.isNewExpression(el) && typescript_1.default.isIdentifier(el.expression)) {
280
261
  const token = (el.arguments && el.arguments.length > 0 && el.arguments[0]) ||
281
262
  undefined;
282
- isParametersDecorator = maybeUpdateDecorator(el.expression, reflector, token);
263
+ isDecorator = maybeUpdateDecorator(el.expression, reflector, token);
283
264
  }
284
- if (!isParametersDecorator) {
265
+ if (!isDecorator) {
285
266
  meta.token = new compiler_1.WrappedNodeExpr(el);
286
267
  }
287
268
  });
@@ -1,2 +1,9 @@
1
- export * from "./error";
2
- export * from "./error_code";
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export * from './error';
9
+ export * from './error_code';
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
2
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
10
  if (k2 === undefined) k2 = k;
4
11
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1 +1,8 @@
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
+ */
1
8
  export * from './src/core';
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
2
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
10
  if (k2 === undefined) k2 = k;
4
11
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { WrappedNodeExpr } from 'static-injector/transform/compiler';
9
+ import ts from 'typescript';
10
+ /**
11
+ * Attaches a default import declaration to `expr` to indicate the dependency of `expr` on the
12
+ * default import.
13
+ */
14
+ export declare function attachDefaultImportDeclaration(expr: WrappedNodeExpr<unknown>, importDecl: ts.ImportDeclaration): void;
15
+ /**
16
+ * Obtains the default import declaration that `expr` depends on, or `null` if there is no such
17
+ * dependency.
18
+ */
19
+ export declare function getDefaultImportDeclaration(expr: WrappedNodeExpr<unknown>): ts.ImportDeclaration | null;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.getDefaultImportDeclaration = exports.attachDefaultImportDeclaration = void 0;
11
+ const DefaultImportDeclaration = Symbol('DefaultImportDeclaration');
12
+ /**
13
+ * Attaches a default import declaration to `expr` to indicate the dependency of `expr` on the
14
+ * default import.
15
+ */
16
+ function attachDefaultImportDeclaration(expr, importDecl) {
17
+ expr[DefaultImportDeclaration] = importDecl;
18
+ }
19
+ exports.attachDefaultImportDeclaration = attachDefaultImportDeclaration;
20
+ /**
21
+ * Obtains the default import declaration that `expr` depends on, or `null` if there is no such
22
+ * dependency.
23
+ */
24
+ function getDefaultImportDeclaration(expr) {
25
+ var _a;
26
+ return ((_a = expr[DefaultImportDeclaration]) !== null && _a !== void 0 ? _a : null);
27
+ }
28
+ exports.getDefaultImportDeclaration = getDefaultImportDeclaration;
@@ -1,3 +1,10 @@
1
- export * from "./src/host";
2
- export * from "./src/typescript";
3
- export * from "./src/util";
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export * from './src/host';
9
+ export * from './src/typescript';
10
+ export * from './src/util';
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
2
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
10
  if (k2 === undefined) k2 = k;
4
11
  var desc = Object.getOwnPropertyDescriptor(m, k);