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 '../util/ng_dev_mode';
|
---|
9 | import { getClosureSafeProperty } from '../util/property';
|
---|
10 | import { stringify } from '../util/stringify';
|
---|
11 | import { resolveForwardRef } from './forward_ref';
|
---|
12 | import { getInjectImplementation, injectRootLimpMode } from './inject_switch';
|
---|
13 | import { InjectFlags } from './interface/injector';
|
---|
14 | const _THROW_IF_NOT_FOUND = {};
|
---|
15 | export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
|
---|
16 | /*
|
---|
17 | * Name of a property (that we patch onto DI decorator), which is used as an annotation of which
|
---|
18 | * InjectFlag this decorator represents. This allows to avoid direct references to the DI decorators
|
---|
19 | * in the code, thus making them tree-shakable.
|
---|
20 | */
|
---|
21 | const DI_DECORATOR_FLAG = '__NG_DI_FLAG__';
|
---|
22 | export const NG_TEMP_TOKEN_PATH = 'ngTempTokenPath';
|
---|
23 | const NG_TOKEN_PATH = 'ngTokenPath';
|
---|
24 | const NEW_LINE = /\n/gm;
|
---|
25 | const NO_NEW_LINE = 'ɵ';
|
---|
26 | export const SOURCE = '__source';
|
---|
27 | const ɵ0 = getClosureSafeProperty;
|
---|
28 | export const USE_VALUE = getClosureSafeProperty({ provide: String, useValue: ɵ0 });
|
---|
29 | /**
|
---|
30 | * Current injector value used by `inject`.
|
---|
31 | * - `undefined`: it is an error to call `inject`
|
---|
32 | * - `null`: `inject` can be called but there is no injector (limp-mode).
|
---|
33 | * - Injector instance: Use the injector for resolution.
|
---|
34 | */
|
---|
35 | let _currentInjector = undefined;
|
---|
36 | export function setCurrentInjector(injector) {
|
---|
37 | const former = _currentInjector;
|
---|
38 | _currentInjector = injector;
|
---|
39 | return former;
|
---|
40 | }
|
---|
41 | export function injectInjectorOnly(token, flags = InjectFlags.Default) {
|
---|
42 | if (_currentInjector === undefined) {
|
---|
43 | throw new Error(`inject() must be called from an injection context`);
|
---|
44 | }
|
---|
45 | else if (_currentInjector === null) {
|
---|
46 | return injectRootLimpMode(token, undefined, flags);
|
---|
47 | }
|
---|
48 | else {
|
---|
49 | return _currentInjector.get(token, flags & InjectFlags.Optional ? null : undefined, flags);
|
---|
50 | }
|
---|
51 | }
|
---|
52 | export function ɵɵinject(token, flags = InjectFlags.Default) {
|
---|
53 | return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags);
|
---|
54 | }
|
---|
55 | /**
|
---|
56 | * Throws an error indicating that a factory function could not be generated by the compiler for a
|
---|
57 | * particular class.
|
---|
58 | *
|
---|
59 | * This instruction allows the actual error message to be optimized away when ngDevMode is turned
|
---|
60 | * off, saving bytes of generated code while still providing a good experience in dev mode.
|
---|
61 | *
|
---|
62 | * The name of the class is not mentioned here, but will be in the generated factory function name
|
---|
63 | * and thus in the stack trace.
|
---|
64 | *
|
---|
65 | * @codeGenApi
|
---|
66 | */
|
---|
67 | export function ɵɵinvalidFactoryDep(index) {
|
---|
68 | const msg = ngDevMode ?
|
---|
69 | `This constructor is not compatible with Angular Dependency Injection because its dependency at index ${index} of the parameter list is invalid.
|
---|
70 | This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator.
|
---|
71 |
|
---|
72 | Please check that 1) the type for the parameter at index ${index} is correct and 2) the correct Angular decorators are defined for this class and its ancestors.` :
|
---|
73 | 'invalid';
|
---|
74 | throw new Error(msg);
|
---|
75 | }
|
---|
76 | /**
|
---|
77 | * Injects a token from the currently active injector.
|
---|
78 | *
|
---|
79 | * Must be used in the context of a factory function such as one defined for an
|
---|
80 | * `InjectionToken`. Throws an error if not called from such a context.
|
---|
81 | *
|
---|
82 | * Within such a factory function, using this function to request injection of a dependency
|
---|
83 | * is faster and more type-safe than providing an additional array of dependencies
|
---|
84 | * (as has been common with `useFactory` providers).
|
---|
85 | *
|
---|
86 | * @param token The injection token for the dependency to be injected.
|
---|
87 | * @param flags Optional flags that control how injection is executed.
|
---|
88 | * The flags correspond to injection strategies that can be specified with
|
---|
89 | * parameter decorators `@Host`, `@Self`, `@SkipSef`, and `@Optional`.
|
---|
90 | * @returns the injected value if injection is successful, `null` otherwise.
|
---|
91 | *
|
---|
92 | * @usageNotes
|
---|
93 | *
|
---|
94 | * ### Example
|
---|
95 | *
|
---|
96 | * {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
|
---|
97 | *
|
---|
98 | * @publicApi
|
---|
99 | */
|
---|
100 | export const inject = ɵɵinject;
|
---|
101 | export function injectArgs(types) {
|
---|
102 | const args = [];
|
---|
103 | for (let i = 0; i < types.length; i++) {
|
---|
104 | const arg = resolveForwardRef(types[i]);
|
---|
105 | if (Array.isArray(arg)) {
|
---|
106 | if (arg.length === 0) {
|
---|
107 | throw new Error('Arguments array must have arguments.');
|
---|
108 | }
|
---|
109 | let type = undefined;
|
---|
110 | let flags = InjectFlags.Default;
|
---|
111 | for (let j = 0; j < arg.length; j++) {
|
---|
112 | const meta = arg[j];
|
---|
113 | const flag = getInjectFlag(meta);
|
---|
114 | if (typeof flag === 'number') {
|
---|
115 | // Special case when we handle @Inject decorator.
|
---|
116 | if (flag === -1 /* Inject */) {
|
---|
117 | type = meta.token;
|
---|
118 | }
|
---|
119 | else {
|
---|
120 | flags |= flag;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | else {
|
---|
124 | type = meta;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | args.push(ɵɵinject(type, flags));
|
---|
128 | }
|
---|
129 | else {
|
---|
130 | args.push(ɵɵinject(arg));
|
---|
131 | }
|
---|
132 | }
|
---|
133 | return args;
|
---|
134 | }
|
---|
135 | /**
|
---|
136 | * Attaches a given InjectFlag to a given decorator using monkey-patching.
|
---|
137 | * Since DI decorators can be used in providers `deps` array (when provider is configured using
|
---|
138 | * `useFactory`) without initialization (e.g. `Host`) and as an instance (e.g. `new Host()`), we
|
---|
139 | * attach the flag to make it available both as a static property and as a field on decorator
|
---|
140 | * instance.
|
---|
141 | *
|
---|
142 | * @param decorator Provided DI decorator.
|
---|
143 | * @param flag InjectFlag that should be applied.
|
---|
144 | */
|
---|
145 | export function attachInjectFlag(decorator, flag) {
|
---|
146 | decorator[DI_DECORATOR_FLAG] = flag;
|
---|
147 | decorator.prototype[DI_DECORATOR_FLAG] = flag;
|
---|
148 | return decorator;
|
---|
149 | }
|
---|
150 | /**
|
---|
151 | * Reads monkey-patched property that contains InjectFlag attached to a decorator.
|
---|
152 | *
|
---|
153 | * @param token Token that may contain monkey-patched DI flags property.
|
---|
154 | */
|
---|
155 | export function getInjectFlag(token) {
|
---|
156 | return token[DI_DECORATOR_FLAG];
|
---|
157 | }
|
---|
158 | export function catchInjectorError(e, token, injectorErrorName, source) {
|
---|
159 | const tokenPath = e[NG_TEMP_TOKEN_PATH];
|
---|
160 | if (token[SOURCE]) {
|
---|
161 | tokenPath.unshift(token[SOURCE]);
|
---|
162 | }
|
---|
163 | e.message = formatError('\n' + e.message, tokenPath, injectorErrorName, source);
|
---|
164 | e[NG_TOKEN_PATH] = tokenPath;
|
---|
165 | e[NG_TEMP_TOKEN_PATH] = null;
|
---|
166 | throw e;
|
---|
167 | }
|
---|
168 | export function formatError(text, obj, injectorErrorName, source = null) {
|
---|
169 | text = text && text.charAt(0) === '\n' && text.charAt(1) == NO_NEW_LINE ? text.substr(2) : text;
|
---|
170 | let context = stringify(obj);
|
---|
171 | if (Array.isArray(obj)) {
|
---|
172 | context = obj.map(stringify).join(' -> ');
|
---|
173 | }
|
---|
174 | else if (typeof obj === 'object') {
|
---|
175 | let parts = [];
|
---|
176 | for (let key in obj) {
|
---|
177 | if (obj.hasOwnProperty(key)) {
|
---|
178 | let value = obj[key];
|
---|
179 | parts.push(key + ':' + (typeof value === 'string' ? JSON.stringify(value) : stringify(value)));
|
---|
180 | }
|
---|
181 | }
|
---|
182 | context = `{${parts.join(', ')}}`;
|
---|
183 | }
|
---|
184 | return `${injectorErrorName}${source ? '(' + source + ')' : ''}[${context}]: ${text.replace(NEW_LINE, '\n ')}`;
|
---|
185 | }
|
---|
186 | export { ɵ0 };
|
---|
187 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5qZWN0b3JfY29tcGF0aWJpbGl0eS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvcmUvc3JjL2RpL2luamVjdG9yX2NvbXBhdGliaWxpdHkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxxQkFBcUIsQ0FBQztBQUc3QixPQUFPLEVBQUMsc0JBQXNCLEVBQUMsTUFBTSxrQkFBa0IsQ0FBQztBQUN4RCxPQUFPLEVBQUMsU0FBUyxFQUFDLE1BQU0sbUJBQW1CLENBQUM7QUFFNUMsT0FBTyxFQUFDLGlCQUFpQixFQUFDLE1BQU0sZUFBZSxDQUFDO0FBQ2hELE9BQU8sRUFBQyx1QkFBdUIsRUFBRSxrQkFBa0IsRUFBQyxNQUFNLGlCQUFpQixDQUFDO0FBRTVFLE9BQU8sRUFBaUIsV0FBVyxFQUFzQixNQUFNLHNCQUFzQixDQUFDO0FBS3RGLE1BQU0sbUJBQW1CLEdBQUcsRUFBRSxDQUFDO0FBQy9CLE1BQU0sQ0FBQyxNQUFNLGtCQUFrQixHQUFHLG1CQUFtQixDQUFDO0FBRXREOzs7O0dBSUc7QUFDSCxNQUFNLGlCQUFpQixHQUFHLGdCQUFnQixDQUFDO0FBRTNDLE1BQU0sQ0FBQyxNQUFNLGtCQUFrQixHQUFHLGlCQUFpQixDQUFDO0FBQ3BELE1BQU0sYUFBYSxHQUFHLGFBQWEsQ0FBQztBQUNwQyxNQUFNLFFBQVEsR0FBRyxNQUFNLENBQUM7QUFDeEIsTUFBTSxXQUFXLEdBQUcsR0FBR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bmdpZnkob2JqKTtcbiAgaWYgKEFycmF5LmlzQXJyYXkob2JqKSkge1xuICAgIGNvbnRleHQgPSBvYmoubWFwKHN0cmluZ2lmeSkuam9pbignIC0+ICcpO1xuICB9IGVsc2UgaWYgKHR5cGVvZiBvYmogPT09ICdvYmplY3QnKSB7XG4gICAgbGV0IHBhcnRzID0gPHN0cmluZ1tdPltdO1xuICAgIGZvciAobGV0IGtleSBpbiBvYmopIHtcbiAgICAgIGlmIChvYmouaGFzT3duUHJvcGVydHkoa2V5KSkge1xuICAgICAgICBsZXQgdmFsdWUgPSBvYmpba2V5XTtcbiAgICAgICAgcGFydHMucHVzaChcbiAgICAgICAgICAgIGtleSArICc6JyArICh0eXBlb2YgdmFsdWUgPT09ICdzdHJpbmcnID8gSlNPTi5zdHJpbmdpZnkodmFsdWUpIDogc3RyaW5naWZ5KHZhbHVlKSkpO1xuICAgICAgfVxuICAgIH1cbiAgICBjb250ZXh0ID0gYHske3BhcnRzLmpvaW4oJywgJyl9fWA7XG4gIH1cbiAgcmV0dXJuIGAke2luamVjdG9yRXJyb3JOYW1lfSR7c291cmNlID8gJygnICsgc291cmNlICsgJyknIDogJyd9WyR7Y29udGV4dH1dOiAke1xuICAgICAgdGV4dC5yZXBsYWNlKE5FV19MSU5FLCAnXFxuICAnKX1gO1xufVxuIl19 |
---|