static-injector 1.0.10 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/import/commonjs/index.js +337 -124
  2. package/import/es2015/di/create_injector.js +30 -0
  3. package/import/es2015/di/initializer_token.js +15 -0
  4. package/import/es2015/di/inject_switch.js +27 -6
  5. package/import/es2015/di/injection_token.js +6 -0
  6. package/import/es2015/di/injector.js +6 -8
  7. package/import/es2015/di/injector_compatibility.js +90 -34
  8. package/import/es2015/di/injector_token.js +1 -1
  9. package/import/es2015/di/interface/defs.js +39 -0
  10. package/import/es2015/di/interface/injector.js +1 -0
  11. package/import/es2015/di/internal_tokens.js +9 -0
  12. package/import/es2015/di/metadata.js +4 -4
  13. package/import/es2015/di/provider_collection.js +49 -0
  14. package/import/es2015/di/r3_injector.js +102 -72
  15. package/import/es2015/di/scope.js +2 -2
  16. package/import/es2015/index.js +1 -1
  17. package/import/es2015/render3/errors_di.js +1 -1
  18. package/import/fesm2015/index.js +328 -114
  19. package/import/typings/di/create_injector.d.ts +23 -0
  20. package/import/typings/di/initializer_token.d.ts +15 -0
  21. package/import/typings/di/inject_switch.d.ts +7 -2
  22. package/import/typings/{decorator → di}/injectable.d.ts +2 -2
  23. package/import/typings/di/injection_token.d.ts +4 -0
  24. package/import/typings/di/injector.d.ts +20 -7
  25. package/import/typings/di/injector_compatibility.d.ts +42 -21
  26. package/import/typings/di/interface/defs.d.ts +10 -0
  27. package/import/typings/di/interface/injector.d.ts +26 -0
  28. package/import/typings/di/interface/provider.d.ts +3 -8
  29. package/import/typings/di/internal_tokens.d.ts +10 -0
  30. package/import/typings/di/provider_collection.d.ts +30 -0
  31. package/import/typings/di/provider_token.d.ts +1 -1
  32. package/import/typings/di/r3_injector.d.ts +68 -37
  33. package/import/typings/di/scope.d.ts +3 -2
  34. package/import/typings/index.d.ts +1 -1
  35. package/import/typings/render3/definition_factory.d.ts +1 -1
  36. package/package.json +5 -3
  37. package/{import/es2015/decorator/interface/provider.js → transform/compiler/compiler.d.ts} +1 -1
  38. package/transform/compiler/compiler.js +28 -0
  39. package/transform/compiler/index.d.ts +8 -5
  40. package/transform/compiler/index.js +17 -6
  41. package/transform/compiler/public_api.d.ts +13 -0
  42. package/transform/compiler/public_api.js +30 -0
  43. package/transform/compiler/src/compiler.d.ts +27 -0
  44. package/transform/compiler/src/compiler.js +47 -0
  45. package/transform/compiler/src/injectable_compiler_2.d.ts +7 -36
  46. package/transform/compiler/src/injectable_compiler_2.js +20 -23
  47. package/transform/compiler/src/output/output_ast.d.ts +30 -109
  48. package/transform/compiler/src/output/output_ast.js +66 -188
  49. package/transform/compiler/src/render3/partial/api.d.ts +1 -1
  50. package/transform/compiler/src/render3/partial/api.js +7 -0
  51. package/transform/compiler/src/render3/r3_factory.d.ts +8 -15
  52. package/transform/compiler/src/render3/r3_factory.js +46 -61
  53. package/transform/compiler/src/render3/util.d.ts +64 -0
  54. package/transform/compiler/src/render3/util.js +52 -9
  55. package/transform/compiler/src/render3/view/util.d.ts +0 -8
  56. package/transform/compiler/src/render3/view/util.js +5 -9
  57. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +10 -0
  58. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +26 -0
  59. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +37 -0
  60. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +197 -0
  61. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.d.ts +3 -3
  62. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.js +3 -3
  63. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +4 -34
  64. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +181 -0
  65. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
  66. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +46 -53
  67. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
  68. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
  69. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +12 -1
  70. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
  71. package/transform/compiler-cli/src/ngtsc/imports/index.js +12 -1
  72. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +19 -0
  73. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +28 -0
  74. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +10 -3
  75. package/transform/compiler-cli/src/ngtsc/reflection/index.js +12 -1
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +13 -14
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +8 -25
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +44 -55
  80. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
  81. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +55 -69
  82. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
  83. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -23
  84. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
  85. package/transform/compiler-cli/src/ngtsc/transform/index.js +12 -1
  86. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
  87. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
  88. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +16 -31
  89. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
  90. package/transform/compiler-cli/src/ngtsc/translator/index.js +12 -1
  91. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +5 -5
  92. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +4 -4
  93. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +5 -21
  94. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -6
  95. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +6 -18
  96. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
  97. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +83 -90
  98. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
  99. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +8 -0
  100. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
  101. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +45 -0
  102. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +86 -0
  103. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
  104. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -27
  105. package/transform/index.js +5 -1
  106. package/transform/injectable-transform.js +59 -38
  107. package/import/typings/decorator/interface/provider.d.ts +0 -312
  108. package/transform/compiler/src/render3/partial/util.d.ts +0 -16
  109. package/transform/compiler/src/render3/partial/util.js +0 -44
  110. package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +0 -370
  111. /package/import/es2015/{decorator → di}/injectable.js +0 -0
@@ -1,26 +1,10 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
21
5
  Object.defineProperty(exports, "__esModule", { value: true });
22
6
  exports.InjectableTransformerFactory = exports.createTransformer = void 0;
23
- const typescript_1 = __importStar(require("typescript"));
7
+ const typescript_1 = __importDefault(require("typescript"));
24
8
  const injectable_1 = require("./compiler-cli/src/ngtsc/annotations/src/injectable");
25
9
  const imports_1 = require("./compiler-cli/src/ngtsc/imports");
26
10
  const reflection_1 = require("./compiler-cli/src/ngtsc/reflection");
@@ -48,8 +32,18 @@ class InjectableTransformerFactory {
48
32
  return typescript_1.default.visitEachChild(node, (node) => {
49
33
  let result = map.get(node);
50
34
  if (result) {
51
- let decoratorList = node.decorators.filter((item) => item !== result.decorator);
52
- return typescript_1.factory.updateClassDeclaration(node, decoratorList.length ? decoratorList : undefined, node.modifiers, node.name, node.typeParameters, node.heritageClauses, [
35
+ const filteredDecorators =
36
+ // Remove the decorator which triggered this compilation, leaving the others alone.
37
+ maybeFilterDecorator(typescript_1.default.getDecorators(node), [result.decorator]);
38
+ const nodeModifiers = typescript_1.default.getModifiers(node);
39
+ let updatedModifiers;
40
+ if ((filteredDecorators === null || filteredDecorators === void 0 ? void 0 : filteredDecorators.length) || (nodeModifiers === null || nodeModifiers === void 0 ? void 0 : nodeModifiers.length)) {
41
+ updatedModifiers = [
42
+ ...(filteredDecorators || []),
43
+ ...(nodeModifiers || []),
44
+ ];
45
+ }
46
+ return typescript_1.default.factory.updateClassDeclaration(node, updatedModifiers, node.name, node.typeParameters, node.heritageClauses, [
53
47
  ...node.members.map((node) => this._stripAngularDecorators(node)),
54
48
  ...result.members,
55
49
  ]);
@@ -68,9 +62,9 @@ class InjectableTransformerFactory {
68
62
  let classMetadataMap = new Map();
69
63
  let write = new imports_1.NoopImportRewriter();
70
64
  let importManager = new translator_1.ImportManager(write);
71
- node_Iteration_1.nodeIteration(sf, (node) => {
65
+ (0, node_Iteration_1.nodeIteration)(sf, (node) => {
72
66
  if (typescript_1.default.isClassDeclaration(node) &&
73
- node.decorators &&
67
+ typescript_1.default.getDecorators(node) &&
74
68
  this.reflectionHost.isClass(node)) {
75
69
  const decorators = this.reflectionHost.getDecoratorsOfDeclaration(node);
76
70
  let result = this.handler.detect(node, decorators);
@@ -95,9 +89,9 @@ class InjectableTransformerFactory {
95
89
  const members = [];
96
90
  for (const field of compileResult) {
97
91
  // Translate the initializer for the field into TS nodes.
98
- const exprNode = translator_1.translateExpression(field.initializer, importManager);
92
+ const exprNode = (0, translator_1.translateExpression)(field.initializer, importManager);
99
93
  // Create a static property declaration for the new field.
100
- const property = typescript_1.default.createProperty(undefined, [typescript_1.default.createToken(typescript_1.default.SyntaxKind.StaticKeyword)], field.name, undefined, undefined, exprNode);
94
+ const property = typescript_1.default.factory.createPropertyDeclaration([typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.StaticKeyword)], field.name, undefined, undefined, exprNode);
101
95
  if (false) {
102
96
  // Closure compiler transforms the form `Service.ɵprov = X` into `Service$ɵprov = X`. To
103
97
  // prevent this transformation, such assignments need to be annotated with @nocollapse.
@@ -107,7 +101,7 @@ class InjectableTransformerFactory {
107
101
  /* hasTrailingNewLine */ false);
108
102
  }
109
103
  field.statements
110
- .map((stmt) => translator_1.translateStatement(stmt, importManager))
104
+ .map((stmt) => (0, translator_1.translateStatement)(stmt, importManager))
111
105
  .forEach((stmt) => statements.push(stmt));
112
106
  members.push(property);
113
107
  }
@@ -120,14 +114,24 @@ class InjectableTransformerFactory {
120
114
  * as parameters of constructors.
121
115
  */
122
116
  _stripAngularDecorators(node) {
117
+ const modifiers = typescript_1.default.canHaveModifiers(node)
118
+ ? typescript_1.default.getModifiers(node)
119
+ : undefined;
120
+ const nonCoreDecorators = typescript_1.default.canHaveDecorators(node)
121
+ ? this._nonCoreDecoratorsOnly(node)
122
+ : undefined;
123
+ const combinedModifiers = [
124
+ ...(nonCoreDecorators || []),
125
+ ...(modifiers || []),
126
+ ];
123
127
  if (typescript_1.default.isParameter(node)) {
124
128
  // Strip decorators from parameters (probably of the constructor).
125
- node = typescript_1.default.updateParameter(node, this._nonCoreDecoratorsOnly(node), node.modifiers, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer);
129
+ node = typescript_1.default.factory.updateParameterDeclaration(node, combinedModifiers, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer);
126
130
  }
127
131
  else if (typescript_1.default.isConstructorDeclaration(node)) {
128
132
  // For constructors, strip decorators of the parameters.
129
133
  const parameters = node.parameters.map((param) => this._stripAngularDecorators(param));
130
- node = typescript_1.default.updateConstructor(node, node.decorators, node.modifiers, parameters, node.body);
134
+ node = typescript_1.default.factory.updateConstructorDeclaration(node, modifiers, parameters, node.body);
131
135
  }
132
136
  return node;
133
137
  }
@@ -158,35 +162,33 @@ class InjectableTransformerFactory {
158
162
  * `undefined`.
159
163
  */
160
164
  _nonCoreDecoratorsOnly(node) {
165
+ const decorators = typescript_1.default.getDecorators(node);
161
166
  // Shortcut if the node has no decorators.
162
- if (node.decorators === undefined) {
167
+ if (decorators === undefined) {
163
168
  return undefined;
164
169
  }
165
- // Build a Set of the decorators on this node from static-injector.
170
+ // Build a Set of the decorators on this node from @angular/core.
166
171
  const coreDecorators = this._angularCoreDecorators(node);
167
- if (coreDecorators.size === node.decorators.length) {
172
+ if (coreDecorators.size === decorators.length) {
168
173
  // If all decorators are to be removed, return `undefined`.
169
174
  return undefined;
170
175
  }
171
176
  else if (coreDecorators.size === 0) {
172
177
  // If no decorators need to be removed, return the original decorators array.
173
- return node.decorators;
178
+ return nodeArrayFromDecoratorsArray(decorators);
174
179
  }
175
180
  // Filter out the core decorators.
176
- const filtered = node.decorators.filter((dec) => !coreDecorators.has(dec));
181
+ const filtered = decorators.filter((dec) => !coreDecorators.has(dec));
177
182
  // If no decorators survive, return `undefined`. This can only happen if a core decorator is
178
183
  // repeated on the node.
179
184
  if (filtered.length === 0) {
180
185
  return undefined;
181
186
  }
182
187
  // Create a new `NodeArray` with the filtered decorators that sourcemaps back to the original.
183
- const array = typescript_1.default.createNodeArray(filtered);
184
- array.pos = node.decorators.pos;
185
- array.end = node.decorators.end;
186
- return array;
188
+ return nodeArrayFromDecoratorsArray(filtered);
187
189
  }
188
190
  updateStatements(node, importManager) {
189
- return transform_1.addImports(importManager, node);
191
+ return (0, transform_1.addImports)(importManager, node);
190
192
  }
191
193
  }
192
194
  exports.InjectableTransformerFactory = InjectableTransformerFactory;
@@ -196,3 +198,22 @@ exports.InjectableTransformerFactory = InjectableTransformerFactory;
196
198
  function isFromAngularCore(decorator) {
197
199
  return (decorator.import !== null && decorator.import.from === 'static-injector');
198
200
  }
201
+ /** Creates a `NodeArray` with the correct offsets from an array of decorators. */
202
+ function nodeArrayFromDecoratorsArray(decorators) {
203
+ const array = typescript_1.default.factory.createNodeArray(decorators);
204
+ if (array.length > 0) {
205
+ array.pos = decorators[0].pos;
206
+ array.end = decorators[decorators.length - 1].end;
207
+ }
208
+ return array;
209
+ }
210
+ function maybeFilterDecorator(decorators, toRemove) {
211
+ if (decorators === undefined) {
212
+ return undefined;
213
+ }
214
+ const filtered = decorators.filter((dec) => toRemove.find((decToRemove) => typescript_1.default.getOriginalNode(dec) === decToRemove) === undefined);
215
+ if (filtered.length === 0) {
216
+ return undefined;
217
+ }
218
+ return typescript_1.default.factory.createNodeArray(filtered);
219
+ }
@@ -1,312 +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 { Type } from '../../interface/type';
9
- /**
10
- * Configures the `Injector` to return a value for a token.
11
- * Base for `ValueProvider` decorator.
12
- *
13
- * @publicApi
14
- */
15
- export interface ValueSansProvider {
16
- /**
17
- * The value to inject.
18
- */
19
- useValue: any;
20
- }
21
- /**
22
- * Configures the `Injector` to return a value for a token.
23
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
24
- *
25
- * @usageNotes
26
- *
27
- * ### Example
28
- *
29
- * {@example core/di/ts/provider_spec.ts region='ValueProvider'}
30
- *
31
- * ### Multi-value example
32
- *
33
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
34
- *
35
- * @publicApi
36
- */
37
- export interface ValueProvider extends ValueSansProvider {
38
- /**
39
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
40
- */
41
- provide: any;
42
- /**
43
- * When true, injector returns an array of instances. This is useful to allow multiple
44
- * providers spread across many files to provide configuration information to a common token.
45
- */
46
- multi?: boolean;
47
- }
48
- /**
49
- * Configures the `Injector` to return an instance of `useClass` for a token.
50
- * Base for `StaticClassProvider` decorator.
51
- *
52
- * @publicApi
53
- */
54
- export interface StaticClassSansProvider {
55
- /**
56
- * An optional class to instantiate for the `token`. By default, the `provide`
57
- * class is instantiated.
58
- */
59
- useClass: Type<any>;
60
- /**
61
- * A list of `token`s to be resolved by the injector. The list of values is then
62
- * used as arguments to the `useClass` constructor.
63
- */
64
- deps: any[];
65
- }
66
- /**
67
- * Configures the `Injector` to return an instance of `useClass` for a token.
68
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
69
- *
70
- * @usageNotes
71
- *
72
- * {@example core/di/ts/provider_spec.ts region='StaticClassProvider'}
73
- *
74
- * Note that following two providers are not equal:
75
- *
76
- * {@example core/di/ts/provider_spec.ts region='StaticClassProviderDifference'}
77
- *
78
- * ### Multi-value example
79
- *
80
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
81
- *
82
- * @publicApi
83
- */
84
- export interface StaticClassProvider extends StaticClassSansProvider {
85
- /**
86
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
87
- */
88
- provide: any;
89
- /**
90
- * When true, injector returns an array of instances. This is useful to allow multiple
91
- * providers spread across many files to provide configuration information to a common token.
92
- */
93
- multi?: boolean;
94
- }
95
- /**
96
- * Configures the `Injector` to return an instance of a token.
97
- *
98
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
99
- *
100
- * @usageNotes
101
- *
102
- * ```ts
103
- * @Injectable(SomeModule, {deps: []})
104
- * class MyService {}
105
- * ```
106
- *
107
- * @publicApi
108
- */
109
- export interface ConstructorSansProvider {
110
- /**
111
- * A list of `token`s to be resolved by the injector.
112
- */
113
- deps?: any[];
114
- }
115
- /**
116
- * Configures the `Injector` to return an instance of a token.
117
- *
118
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
119
- *
120
- * @usageNotes
121
- *
122
- * {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
123
- *
124
- * ### Multi-value example
125
- *
126
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
127
- *
128
- * @publicApi
129
- */
130
- export interface ConstructorProvider extends ConstructorSansProvider {
131
- /**
132
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
133
- */
134
- provide: Type<any>;
135
- /**
136
- * When true, injector returns an array of instances. This is useful to allow multiple
137
- * providers spread across many files to provide configuration information to a common token.
138
- */
139
- multi?: boolean;
140
- }
141
- /**
142
- * Configures the `Injector` to return a value of another `useExisting` token.
143
- *
144
- * @see `ExistingProvider`
145
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
146
- *
147
- * @publicApi
148
- */
149
- export interface ExistingSansProvider {
150
- /**
151
- * Existing `token` to return. (Equivalent to `injector.get(useExisting)`)
152
- */
153
- useExisting: any;
154
- }
155
- /**
156
- * Configures the `Injector` to return a value of another `useExisting` token.
157
- *
158
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
159
- *
160
- * @usageNotes
161
- *
162
- * {@example core/di/ts/provider_spec.ts region='ExistingProvider'}
163
- *
164
- * ### Multi-value example
165
- *
166
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
167
- *
168
- * @publicApi
169
- */
170
- export interface ExistingProvider extends ExistingSansProvider {
171
- /**
172
- * An injection token. Typically an instance of `Type` or `InjectionToken`, but can be `any`.
173
- */
174
- provide: any;
175
- /**
176
- * When true, injector returns an array of instances. This is useful to allow multiple
177
- * providers spread across many files to provide configuration information to a common token.
178
- */
179
- multi?: boolean;
180
- }
181
- /**
182
- * Configures the `Injector` to return a value by invoking a `useFactory` function.
183
- *
184
- * @see `FactoryProvider`
185
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
186
- *
187
- * @publicApi
188
- */
189
- export interface FactorySansProvider {
190
- /**
191
- * A function to invoke to create a value for this `token`. The function is invoked with
192
- * resolved values of `token`s in the `deps` field.
193
- */
194
- useFactory: Function;
195
- /**
196
- * A list of `token`s to be resolved by the injector. The list of values is then
197
- * used as arguments to the `useFactory` function.
198
- */
199
- deps?: any[];
200
- }
201
- /**
202
- * Configures the `Injector` to return a value by invoking a `useFactory` function.
203
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
204
- *
205
- * @usageNotes
206
- *
207
- * {@example core/di/ts/provider_spec.ts region='FactoryProvider'}
208
- *
209
- * Dependencies can also be marked as optional:
210
- *
211
- * {@example core/di/ts/provider_spec.ts region='FactoryProviderOptionalDeps'}
212
- *
213
- * ### Multi-value example
214
- *
215
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
216
- *
217
- * @publicApi
218
- */
219
- export interface FactoryProvider extends FactorySansProvider {
220
- /**
221
- * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
222
- */
223
- provide: any;
224
- /**
225
- * When true, injector returns an array of instances. This is useful to allow multiple
226
- * providers spread across many files to provide configuration information to a common token.
227
- */
228
- multi?: boolean;
229
- }
230
- /**
231
- * Describes how an `Injector` should be configured as static (that is, without reflection).
232
- * A static provider provides tokens to an injector for various types of dependencies.
233
- *
234
- * @see `Injector.create()`.
235
- * @see ["Dependency Injection Guide"](guide/dependency-injection-providers).
236
- *
237
- * @publicApi
238
- */
239
- export declare type StaticProvider = ValueProvider | ExistingProvider | StaticClassProvider | ConstructorProvider | FactoryProvider | any[];
240
- /**
241
- * Configures the `Injector` to return an instance of `Type` when `Type' is used as the token.
242
- *
243
- * Create an instance by invoking the `new` operator and supplying additional arguments.
244
- * This form is a short form of `TypeProvider`;
245
- *
246
- * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
247
- *
248
- * @usageNotes
249
- *
250
- * {@example core/di/ts/provider_spec.ts region='TypeProvider'}
251
- *
252
- * @publicApi
253
- */
254
- export interface TypeProvider extends Type<any> {
255
- }
256
- /**
257
- * Configures the `Injector` to return a value by invoking a `useClass` function.
258
- * Base for `ClassProvider` decorator.
259
- *
260
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
261
- *
262
- * @publicApi
263
- */
264
- export interface ClassSansProvider {
265
- /**
266
- * Class to instantiate for the `token`.
267
- */
268
- useClass: Type<any>;
269
- }
270
- /**
271
- * Configures the `Injector` to return an instance of `useClass` for a token.
272
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
273
- *
274
- * @usageNotes
275
- *
276
- * {@example core/di/ts/provider_spec.ts region='ClassProvider'}
277
- *
278
- * Note that following two providers are not equal:
279
- *
280
- * {@example core/di/ts/provider_spec.ts region='ClassProviderDifference'}
281
- *
282
- * ### Multi-value example
283
- *
284
- * {@example core/di/ts/provider_spec.ts region='MultiProviderAspect'}
285
- *
286
- * @publicApi
287
- */
288
- export interface ClassProvider extends ClassSansProvider {
289
- /**
290
- * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
291
- */
292
- provide: any;
293
- /**
294
- * When true, injector returns an array of instances. This is useful to allow multiple
295
- * providers spread across many files to provide configuration information to a common token.
296
- */
297
- multi?: boolean;
298
- }
299
- /**
300
- * Describes how the `Injector` should be configured.
301
- * @see ["Dependency Injection Guide"](guide/dependency-injection).
302
- *
303
- * @see `StaticProvider`
304
- *
305
- * @publicApi
306
- */
307
- export declare type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | any[];
308
- /**
309
- * Describes a function that is used to process provider lists (such as provider
310
- * overrides).
311
- */
312
- export declare type ProcessProvidersFunction = (providers: Provider[]) => Provider[];
@@ -1,16 +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 * as o from "../../output/output_ast";
9
- /**
10
- * Generate an expression that has the given `expr` wrapped in the following form:
11
- *
12
- * ```
13
- * forwardRef(() => expr)
14
- * ```
15
- */
16
- export declare function generateForwardRef(expr: o.Expression): o.Expression;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.generateForwardRef = void 0;
23
- /**
24
- * @license
25
- * Copyright Google LLC All Rights Reserved.
26
- *
27
- * Use of this source code is governed by an MIT-style license that can be
28
- * found in the LICENSE file at https://angular.io/license
29
- */
30
- const o = __importStar(require("../../output/output_ast"));
31
- const r3_identifiers_1 = require("../r3_identifiers");
32
- /**
33
- * Generate an expression that has the given `expr` wrapped in the following form:
34
- *
35
- * ```
36
- * forwardRef(() => expr)
37
- * ```
38
- */
39
- function generateForwardRef(expr) {
40
- return o
41
- .importExpr(r3_identifiers_1.Identifiers.forwardRef)
42
- .callFn([o.fn([], [new o.ReturnStatement(expr)])]);
43
- }
44
- exports.generateForwardRef = generateForwardRef;