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 | (function (factory) {
|
---|
9 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
10 | var v = factory(require, exports);
|
---|
11 | if (v !== undefined) module.exports = v;
|
---|
12 | }
|
---|
13 | else if (typeof define === "function" && define.amd) {
|
---|
14 | define("@angular/compiler/src/output/value_util", ["require", "exports", "@angular/compiler/src/util", "@angular/compiler/src/output/output_ast"], factory);
|
---|
15 | }
|
---|
16 | })(function (require, exports) {
|
---|
17 | "use strict";
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | exports.convertValueToOutputAst = exports.QUOTED_KEYS = void 0;
|
---|
20 | var util_1 = require("@angular/compiler/src/util");
|
---|
21 | var o = require("@angular/compiler/src/output/output_ast");
|
---|
22 | exports.QUOTED_KEYS = '$quoted$';
|
---|
23 | function convertValueToOutputAst(ctx, value, type) {
|
---|
24 | if (type === void 0) { type = null; }
|
---|
25 | return util_1.visitValue(value, new _ValueOutputAstTransformer(ctx), type);
|
---|
26 | }
|
---|
27 | exports.convertValueToOutputAst = convertValueToOutputAst;
|
---|
28 | var _ValueOutputAstTransformer = /** @class */ (function () {
|
---|
29 | function _ValueOutputAstTransformer(ctx) {
|
---|
30 | this.ctx = ctx;
|
---|
31 | }
|
---|
32 | _ValueOutputAstTransformer.prototype.visitArray = function (arr, type) {
|
---|
33 | var values = [];
|
---|
34 | // Note Array.map() must not be used to convert the values because it will
|
---|
35 | // skip over empty elements in arrays constructed using `new Array(length)`,
|
---|
36 | // resulting in `undefined` elements. This breaks the type guarantee that
|
---|
37 | // all values in `o.LiteralArrayExpr` are of type `o.Expression`.
|
---|
38 | // See test case in `value_util_spec.ts`.
|
---|
39 | for (var i = 0; i < arr.length; ++i) {
|
---|
40 | values.push(util_1.visitValue(arr[i], this, null /* context */));
|
---|
41 | }
|
---|
42 | return o.literalArr(values, type);
|
---|
43 | };
|
---|
44 | _ValueOutputAstTransformer.prototype.visitStringMap = function (map, type) {
|
---|
45 | var _this = this;
|
---|
46 | var entries = [];
|
---|
47 | var quotedSet = new Set(map && map[exports.QUOTED_KEYS]);
|
---|
48 | Object.keys(map).forEach(function (key) {
|
---|
49 | entries.push(new o.LiteralMapEntry(key, util_1.visitValue(map[key], _this, null), quotedSet.has(key)));
|
---|
50 | });
|
---|
51 | return new o.LiteralMapExpr(entries, type);
|
---|
52 | };
|
---|
53 | _ValueOutputAstTransformer.prototype.visitPrimitive = function (value, type) {
|
---|
54 | return o.literal(value, type);
|
---|
55 | };
|
---|
56 | _ValueOutputAstTransformer.prototype.visitOther = function (value, type) {
|
---|
57 | if (value instanceof o.Expression) {
|
---|
58 | return value;
|
---|
59 | }
|
---|
60 | else {
|
---|
61 | return this.ctx.importExpr(value);
|
---|
62 | }
|
---|
63 | };
|
---|
64 | return _ValueOutputAstTransformer;
|
---|
65 | }());
|
---|
66 | });
|
---|
67 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsdWVfdXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9vdXRwdXQvdmFsdWVfdXRpbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7Ozs7Ozs7Ozs7Ozs7SUFJSCxtREFBcUQ7SUFFckQsMkRBQWtDO0lBRXJCLFFBQUEsV0FBVyxHQUFHLFVBQVUsQ0FBQztJQUV0QyxTQUFnQix1QkFBdUIsQ0FDbkMsR0FBa0IsRUFBRSxLQUFVLEVBQUUsSUFBd0I7UUFBeEIscUJBQUEsRUFBQSxXQUF3QjtRQUMxRCxPQUFPLGlCQUFVLENBQUMsS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