-
Notifications
You must be signed in to change notification settings - Fork 13
/
r3_pipe_compiler.js
executable file
·65 lines (65 loc) · 9.3 KB
/
r3_pipe_compiler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @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
*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define("@angular/compiler/src/render3/r3_pipe_compiler", ["require", "exports", "@angular/compiler/src/compile_metadata", "@angular/compiler/src/output/output_ast", "@angular/compiler/src/util", "@angular/compiler/src/render3/r3_factory", "@angular/compiler/src/render3/r3_identifiers"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var compile_metadata_1 = require("@angular/compiler/src/compile_metadata");
var o = require("@angular/compiler/src/output/output_ast");
var util_1 = require("@angular/compiler/src/util");
var r3_factory_1 = require("@angular/compiler/src/render3/r3_factory");
var r3_identifiers_1 = require("@angular/compiler/src/render3/r3_identifiers");
/**
* Write a pipe definition to the output context.
*/
function compilePipe(outputCtx, pipe, reflector) {
var definitionMapValues = [];
// e.g. `name: 'myPipe'`
definitionMapValues.push({ key: 'name', value: o.literal(pipe.name), quoted: false });
// e.g. `type: MyPipe`
definitionMapValues.push({ key: 'type', value: outputCtx.importExpr(pipe.type.reference), quoted: false });
// e.g. `factory: function MyPipe_Factory() { return new MyPipe(); }`
var deps = r3_factory_1.dependenciesFromGlobalMetadata(pipe.type, outputCtx, reflector);
var templateFactory = r3_factory_1.compileFactoryFunction({
name: compile_metadata_1.identifierName(pipe.type),
fnOrClass: outputCtx.importExpr(pipe.type.reference), deps: deps,
useNew: true,
injectFn: r3_identifiers_1.Identifiers.directiveInject,
useOptionalParam: false,
});
definitionMapValues.push({ key: 'factory', value: templateFactory, quoted: false });
// e.g. `pure: true`
if (pipe.pure) {
definitionMapValues.push({ key: 'pure', value: o.literal(true), quoted: false });
}
var className = compile_metadata_1.identifierName(pipe.type);
className || util_1.error("Cannot resolve the name of " + pipe.type);
var definitionField = outputCtx.constantPool.propertyNameOf(3 /* Pipe */);
var definitionFunction = o.importExpr(r3_identifiers_1.Identifiers.definePipe).callFn([o.literalMap(definitionMapValues)]);
outputCtx.statements.push(new o.ClassStmt(
/* name */ className,
/* parent */ null,
/* fields */ [new o.ClassField(
/* name */ definitionField,
/* type */ o.INFERRED_TYPE,
/* modifiers */ [o.StmtModifier.Static],
/* initializer */ definitionFunction)],
/* getters */ [],
/* constructorMethod */ new o.ClassMethod(null, [], []),
/* methods */ []));
}
exports.compilePipe = compilePipe;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicjNfcGlwZV9jb21waWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9yZW5kZXIzL3IzX3BpcGVfY29tcGlsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOzs7Ozs7Ozs7Ozs7SUFFSCwyRUFBd0U7SUFHeEUsMkRBQTBDO0lBQzFDLG1EQUE2QztJQUU3Qyx1RUFBb0Y7SUFDcEYsK0VBQW1EO0lBR25EOztPQUVHO0lBQ0gscUJBQ0ksU0FBd0IsRUFBRSxJQUF5QixFQUFFLFNBQTJCO1FBQ2xGLElBQU0sbUJBQW1CLEdBQTBELEVBQUUsQ0FBQztRQUV0Rix3QkFBd0I7UUFDeEIsbUJBQW1CLENBQUMsSUFBSSxDQUFDLEVBQUMsR0FBRyxFQUFFLE1BQU0sRUFBRSxLQUFL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