source: trip-planner-front/node_modules/@angular/compiler/esm2015/src/injectable_compiler.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 16.8 KB
Line 
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 */
8import { Identifiers } from './identifiers';
9import * as o from './output/output_ast';
10import { convertValueToOutputAst } from './output/value_util';
11import { identifierName } from './parse_util';
12import { Identifiers as R3 } from './render3/r3_identifiers';
13function mapEntry(key, value) {
14 return { key, value, quoted: false };
15}
16export class InjectableCompiler {
17 constructor(reflector, alwaysGenerateDef) {
18 this.reflector = reflector;
19 this.alwaysGenerateDef = alwaysGenerateDef;
20 this.tokenInjector = reflector.resolveExternalReference(Identifiers.Injector);
21 }
22 depsArray(deps, ctx) {
23 return deps.map(dep => {
24 let token = dep;
25 let args = [token];
26 let flags = 0 /* Default */;
27 if (Array.isArray(dep)) {
28 for (let i = 0; i < dep.length; i++) {
29 const v = dep[i];
30 if (v) {
31 if (v.ngMetadataName === 'Optional') {
32 flags |= 8 /* Optional */;
33 }
34 else if (v.ngMetadataName === 'SkipSelf') {
35 flags |= 4 /* SkipSelf */;
36 }
37 else if (v.ngMetadataName === 'Self') {
38 flags |= 2 /* Self */;
39 }
40 else if (v.ngMetadataName === 'Inject') {
41 token = v.token;
42 }
43 else {
44 token = v;
45 }
46 }
47 }
48 }
49 let tokenExpr;
50 if (typeof token === 'string') {
51 tokenExpr = o.literal(token);
52 }
53 else if (token === this.tokenInjector) {
54 tokenExpr = o.importExpr(Identifiers.INJECTOR);
55 }
56 else {
57 tokenExpr = ctx.importExpr(token);
58 }
59 if (flags !== 0 /* Default */) {
60 args = [tokenExpr, o.literal(flags)];
61 }
62 else {
63 args = [tokenExpr];
64 }
65 return o.importExpr(Identifiers.inject).callFn(args);
66 });
67 }
68 factoryFor(injectable, ctx) {
69 let retValue;
70 if (injectable.useExisting) {
71 retValue = o.importExpr(Identifiers.inject).callFn([ctx.importExpr(injectable.useExisting)]);
72 }
73 else if (injectable.useFactory) {
74 const deps = injectable.deps || [];
75 if (deps.length > 0) {
76 retValue = ctx.importExpr(injectable.useFactory).callFn(this.depsArray(deps, ctx));
77 }
78 else {
79 return ctx.importExpr(injectable.useFactory);
80 }
81 }
82 else if (injectable.useValue) {
83 retValue = convertValueToOutputAst(ctx, injectable.useValue);
84 }
85 else {
86 const clazz = injectable.useClass || injectable.symbol;
87 const depArgs = this.depsArray(this.reflector.parameters(clazz), ctx);
88 retValue = new o.InstantiateExpr(ctx.importExpr(clazz), depArgs);
89 }
90 return o.fn([], [new o.ReturnStatement(retValue)], undefined, undefined, injectable.symbol.name + '_Factory');
91 }
92 injectableDef(injectable, ctx) {
93 let providedIn = o.NULL_EXPR;
94 if (injectable.providedIn !== undefined) {
95 if (injectable.providedIn === null) {
96 providedIn = o.NULL_EXPR;
97 }
98 else if (typeof injectable.providedIn === 'string') {
99 providedIn = o.literal(injectable.providedIn);
100 }
101 else {
102 providedIn = ctx.importExpr(injectable.providedIn);
103 }
104 }
105 const def = [
106 mapEntry('factory', this.factoryFor(injectable, ctx)),
107 mapEntry('token', ctx.importExpr(injectable.type.reference)),
108 mapEntry('providedIn', providedIn),
109 ];
110 return o.importExpr(R3.ɵɵdefineInjectable).callFn([o.literalMap(def)], undefined, true);
111 }
112 compile(injectable, ctx) {
113 if (this.alwaysGenerateDef || injectable.providedIn !== undefined) {
114 const className = identifierName(injectable.type);
115 const clazz = new o.ClassStmt(className, null, [
116 new o.ClassField('ɵprov', o.INFERRED_TYPE, [o.StmtModifier.Static], this.injectableDef(injectable, ctx)),
117 ], [], new o.ClassMethod(null, [], []), []);
118 ctx.statements.push(clazz);
119 }
120 }
121}
122//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5qZWN0YWJsZV9jb21waWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJ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4gIHByaXZhdGUgZGVwc0FycmF5KGRlcHM6IGFueVtdLCBjdHg6IE91dHB1dENvbnRleHQpOiBvLkV4cHJlc3Npb25bXSB7XG4gICAgcmV0dXJuIGRlcHMubWFwKGRlcCA9PiB7XG4gICAgICBsZXQgdG9rZW4gPSBkZXA7XG4gICAgICBsZXQgYXJncyA9IFt0b2tlbl07XG4gICAgICBsZXQgZmxhZ3M6IEluamVjdEZsYWdzID0gSW5qZWN0RmxhZ3MuRGVmYXVsdDtcbiAgICAgIGlmIChBcnJheS5pc0FycmF5KGRlcCkpIHtcbiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBkZXAubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICBjb25zdCB2ID0gZGVwW2ldO1xuICAgICAgICAgIGlmICh2KSB7XG4gICAgICAgICAgICBpZiAodi5uZ01ldGFkYXRhTmFtZSA9PT0gJ09wdGlvbmFsJykge1xuICAgICAgICAgICAgICBmbGFncyB8PSBJbmplY3RGbGFncy5PcHRpb25hbDtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodi5uZ01ldGFkYXRhTmFtZSA9PT0gJ1NraXBTZWxmJykge1xuICAgICAgICAgICAgICBmbGFncyB8PSBJbmplY3RGbGFncy5Ta2lwU2VsZjtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAodi5uZ01ldGFkYXRhTmFtZSA9PT0gJ1NlbGYnKSB7XG4gICAgICAgICAgICAgIGZsYWdzIHw9IEluamVjdEZsYWdzLlNlbGY7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKHYubmdNZXRhZGF0YU5hbWUgPT09ICdJbmplY3QnKSB7XG4gICAgICAgICAgICAgIHRva2VuID0gdi50b2tlbjtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHRva2VuID0gdjtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgbGV0IHRva2VuRXhwcjogby5FeHByZ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zTmFtZSA9IGlkZW50aWZpZXJOYW1lKGluamVjdGFibGUudHlwZSkhO1xuICAgICAgY29uc3QgY2xhenogPSBuZXcgby5DbGFzc1N0bXQoXG4gICAgICAgICAgY2xhc3NOYW1lLCBudWxsLFxuICAgICAgICAgIFtcbiAgICAgICAgICAgIG5ldyBvLkNsYXNzRmllbGQoXG4gICAgICAgICAgICAgICAgJ8m1cHJvdicsIG8uSU5GRVJSRURfVFlQRSwgW28uU3RtdE1vZGlmaWVyLlN0YXRpY10sXG4gICAgICAgICAgICAgICAgdGhpcy5pbmplY3RhYmxlRGVmKGluamVjdGFibGUsIGN0eCkpLFxuICAgICAgICAgIF0sXG4gICAgICAgICAgW10sIG5ldyBvLkNsYXNzTWV0aG9kKG51bGwsIFtdLCBbXSksIFtdKTtcbiAgICAgIGN0eC5zdGF0ZW1lbnRzLnB1c2goY2xhenopO1xuICAgIH1cbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.