/** * @license * Copyright Google LLC 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 * as o from '../output/output_ast'; import { Identifiers as R3 } from './r3_identifiers'; import { typeWithParameters } from './util'; export function compilePipeFromMetadata(metadata) { const definitionMapValues = []; // e.g. `name: 'myPipe'` definitionMapValues.push({ key: 'name', value: o.literal(metadata.pipeName), quoted: false }); // e.g. `type: MyPipe` definitionMapValues.push({ key: 'type', value: metadata.type.value, quoted: false }); // e.g. `pure: true` definitionMapValues.push({ key: 'pure', value: o.literal(metadata.pure), quoted: false }); if (metadata.isStandalone) { definitionMapValues.push({ key: 'standalone', value: o.literal(true), quoted: false }); } const expression = o.importExpr(R3.definePipe).callFn([o.literalMap(definitionMapValues)], undefined, true); const type = createPipeType(metadata); return { expression, type, statements: [] }; } export function createPipeType(metadata) { return new o.ExpressionType(o.importExpr(R3.PipeDeclaration, [ typeWithParameters(metadata.type.type, metadata.typeArgumentCount), new o.ExpressionType(new o.LiteralExpr(metadata.pipeName)), new o.ExpressionType(new o.LiteralExpr(metadata.isStandalone)), ])); } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicjNfcGlwZV9jb21waWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9yZW5kZXIzL3IzX3BpcGVfY29tcGlsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxLQUFLLENBQUMsTUFBTSxzQkFBc0IsQ0FBQztBQUcxQyxPQUFPLEVBQUMsV0FBVyxJQUFJLEVBQUUsRUFBQyxNQUFNLGtCQUFrQixDQUFDO0FBQ25ELE9BQU8sRUFBb0Msa0JBQWtCLEVBQUMsTUFBTSxRQUFRLENBQUM7QUF1QzdFLE1BQU0sVUFBVSx1QkF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