
There is an encoding issue with using delta `Δ`, where the browser will attempt to detect the file encoding if the character set is not explicitly declared on a `<script/>` tag, and Chrome will find the `Δ` character and decide it is window-1252 encoding, which misinterprets the `Δ` character to be some other character that is not a valid JS identifier character So back to the frog eyes we go. ``` __ /ɵɵ\ ( -- ) - I am ineffable. I am forever. _/ \_ / \ / \ == == == ``` PR Close #30546
56 lines
2.4 KiB
TypeScript
56 lines
2.4 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {Type} from '../interface/type';
|
|
import {ReflectionCapabilities} from '../reflection/reflection_capabilities';
|
|
import {getClosureSafeProperty} from '../util/property';
|
|
|
|
import {injectArgs, ɵɵinject} from './injector_compatibility';
|
|
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueProvider, ValueSansProvider} from './interface/provider';
|
|
|
|
const USE_VALUE =
|
|
getClosureSafeProperty<ValueProvider>({provide: String, useValue: getClosureSafeProperty});
|
|
const EMPTY_ARRAY: any[] = [];
|
|
|
|
export function convertInjectableProviderToFactory(
|
|
type: Type<any>, provider?: ValueSansProvider | ExistingSansProvider | StaticClassSansProvider |
|
|
ConstructorSansProvider | FactorySansProvider | ClassSansProvider): () => any {
|
|
if (!provider) {
|
|
const reflectionCapabilities = new ReflectionCapabilities();
|
|
const deps = reflectionCapabilities.parameters(type);
|
|
// TODO - convert to flags.
|
|
return () => new type(...injectArgs(deps as any[]));
|
|
}
|
|
|
|
if (USE_VALUE in provider) {
|
|
const valueProvider = (provider as ValueSansProvider);
|
|
return () => valueProvider.useValue;
|
|
} else if ((provider as ExistingSansProvider).useExisting) {
|
|
const existingProvider = (provider as ExistingSansProvider);
|
|
return () => ɵɵinject(existingProvider.useExisting);
|
|
} else if ((provider as FactorySansProvider).useFactory) {
|
|
const factoryProvider = (provider as FactorySansProvider);
|
|
return () => factoryProvider.useFactory(...injectArgs(factoryProvider.deps || EMPTY_ARRAY));
|
|
} else if ((provider as StaticClassSansProvider | ClassSansProvider).useClass) {
|
|
const classProvider = (provider as StaticClassSansProvider | ClassSansProvider);
|
|
let deps = (provider as StaticClassSansProvider).deps;
|
|
if (!deps) {
|
|
const reflectionCapabilities = new ReflectionCapabilities();
|
|
deps = reflectionCapabilities.parameters(type);
|
|
}
|
|
return () => new classProvider.useClass(...injectArgs(deps));
|
|
} else {
|
|
let deps = (provider as ConstructorSansProvider).deps;
|
|
if (!deps) {
|
|
const reflectionCapabilities = new ReflectionCapabilities();
|
|
deps = reflectionCapabilities.parameters(type);
|
|
}
|
|
return () => new type(...injectArgs(deps !));
|
|
}
|
|
}
|