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/render3/view/i18n/context", ["require", "exports", "tslib", "@angular/compiler/src/render3/view/i18n/util"], factory);
|
---|
15 | }
|
---|
16 | })(function (require, exports) {
|
---|
17 | "use strict";
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | exports.I18nContext = void 0;
|
---|
20 | var tslib_1 = require("tslib");
|
---|
21 | var util_1 = require("@angular/compiler/src/render3/view/i18n/util");
|
---|
22 | var TagType;
|
---|
23 | (function (TagType) {
|
---|
24 | TagType[TagType["ELEMENT"] = 0] = "ELEMENT";
|
---|
25 | TagType[TagType["TEMPLATE"] = 1] = "TEMPLATE";
|
---|
26 | })(TagType || (TagType = {}));
|
---|
27 | /**
|
---|
28 | * Generates an object that is used as a shared state between parent and all child contexts.
|
---|
29 | */
|
---|
30 | function setupRegistry() {
|
---|
31 | return { getUniqueId: util_1.getSeqNumberGenerator(), icus: new Map() };
|
---|
32 | }
|
---|
33 | /**
|
---|
34 | * I18nContext is a helper class which keeps track of all i18n-related aspects
|
---|
35 | * (accumulates placeholders, bindings, etc) between i18nStart and i18nEnd instructions.
|
---|
36 | *
|
---|
37 | * When we enter a nested template, the top-level context is being passed down
|
---|
38 | * to the nested component, which uses this context to generate a child instance
|
---|
39 | * of I18nContext class (to handle nested template) and at the end, reconciles it back
|
---|
40 | * with the parent context.
|
---|
41 | *
|
---|
42 | * @param index Instruction index of i18nStart, which initiates this context
|
---|
43 | * @param ref Reference to a translation const that represents the content if thus context
|
---|
44 | * @param level Nestng level defined for child contexts
|
---|
45 | * @param templateIndex Instruction index of a template which this context belongs to
|
---|
46 | * @param meta Meta information (id, meaning, description, etc) associated with this context
|
---|
47 | */
|
---|
48 | var I18nContext = /** @class */ (function () {
|
---|
49 | function I18nContext(index, ref, level, templateIndex, meta, registry) {
|
---|
50 | if (level === void 0) { level = 0; }
|
---|
51 | if (templateIndex === void 0) { templateIndex = null; }
|
---|
52 | this.index = index;
|
---|
53 | this.ref = ref;
|
---|
54 | this.level = level;
|
---|
55 | this.templateIndex = templateIndex;
|
---|
56 | this.meta = meta;
|
---|
57 | this.registry = registry;
|
---|
58 | this.bindings = new Set();
|
---|
59 | this.placeholders = new Map();
|
---|
60 | this.isEmitted = false;
|
---|
61 | this._unresolvedCtxCount = 0;
|
---|
62 | this._registry = registry || setupRegistry();
|
---|
63 | this.id = this._registry.getUniqueId();
|
---|
64 | }
|
---|
65 | I18nContext.prototype.appendTag = function (type, node, index, closed) {
|
---|
66 | if (node.isVoid && closed) {
|
---|
67 | return; // ignore "close" for void tags
|
---|
68 | }
|
---|
69 | var ph = node.isVoid || !closed ? node.startName : node.closeName;
|
---|
70 | var content = { type: type, index: index, ctx: this.id, isVoid: node.isVoid, closed: closed };
|
---|
71 | util_1.updatePlaceholderMap(this.placeholders, ph, content);
|
---|
72 | };
|
---|
73 | Object.defineProperty(I18nContext.prototype, "icus", {
|
---|
74 | get: function () {
|
---|
75 | return this._registry.icus;
|
---|
76 | },
|
---|
77 | enumerable: false,
|
---|
78 | configurable: true
|
---|
79 | });
|
---|
80 | Object.defineProperty(I18nContext.prototype, "isRoot", {
|
---|
81 | get: function () {
|
---|
82 | return this.level === 0;
|
---|
83 | },
|
---|
84 | enumerable: false,
|
---|
85 | configurable: true
|
---|
86 | });
|
---|
87 | Object.defineProperty(I18nContext.prototype, "isResolved", {
|
---|
88 | get: function () {
|
---|
89 | return this._unresolvedCtxCount === 0;
|
---|
90 | },
|
---|
91 | enumerable: false,
|
---|
92 | configurable: true
|
---|
93 | });
|
---|
94 | I18nContext.prototype.getSerializedPlaceholders = function () {
|
---|
95 | var result = new Map();
|
---|
96 | this.placeholders.forEach(function (values, key) { return result.set(key, values.map(serializePlaceholderValue)); });
|
---|
97 | return result;
|
---|
98 | };
|
---|
99 | // public API to accumulate i18n-related content
|
---|
100 | I18nContext.prototype.appendBinding = function (binding) {
|
---|
101 | this.bindings.add(binding);
|
---|
102 | };
|
---|
103 | I18nContext.prototype.appendIcu = function (name, ref) {
|
---|
104 | util_1.updatePlaceholderMap(this._registry.icus, name, ref);
|
---|
105 | };
|
---|
106 | I18nContext.prototype.appendBoundText = function (node) {
|
---|
107 | var _this = this;
|
---|
108 | var phs = util_1.assembleBoundTextPlaceholders(node, this.bindings.size, this.id);
|
---|
109 | phs.forEach(function (values, key) { return util_1.updatePlaceholderMap.apply(void 0, tslib_1.__spreadArray([_this.placeholders, key], tslib_1.__read(values))); });
|
---|
110 | };
|
---|
111 | I18nContext.prototype.appendTemplate = function (node, index) {
|
---|
112 | // add open and close tags at the same time,
|
---|
113 | // since we process nested templates separately
|
---|
114 | this.appendTag(TagType.TEMPLATE, node, index, false);
|
---|
115 | this.appendTag(TagType.TEMPLATE, node, index, true);
|
---|
116 | this._unresolvedCtxCount++;
|
---|
117 | };
|
---|
118 | I18nContext.prototype.appendElement = function (node, index, closed) {
|
---|
119 | this.appendTag(TagType.ELEMENT, node, index, closed);
|
---|
120 | };
|
---|
121 | I18nContext.prototype.appendProjection = function (node, index) {
|
---|
122 | // Add open and close tags at the same time, since `<ng-content>` has no content,
|
---|
123 | // so when we come across `<ng-content>` we can register both open and close tags.
|
---|
124 | // Note: runtime i18n logic doesn't distinguish `<ng-content>` tag placeholders and
|
---|
125 | // regular element tag placeholders, so we generate element placeholders for both types.
|
---|
126 | this.appendTag(TagType.ELEMENT, node, index, false);
|
---|
127 | this.appendTag(TagType.ELEMENT, node, index, true);
|
---|
128 | };
|
---|
129 | /**
|
---|
130 | * Generates an instance of a child context based on the root one,
|
---|
131 | * when we enter a nested template within I18n section.
|
---|
132 | *
|
---|
133 | * @param index Instruction index of corresponding i18nStart, which initiates this context
|
---|
134 | * @param templateIndex Instruction index of a template which this context belongs to
|
---|
135 | * @param meta Meta information (id, meaning, description, etc) associated with this context
|
---|
136 | *
|
---|
137 | * @returns I18nContext instance
|
---|
138 | */
|
---|
139 | I18nContext.prototype.forkChildContext = function (index, templateIndex, meta) {
|
---|
140 | return new I18nContext(index, this.ref, this.level + 1, templateIndex, meta, this._registry);
|
---|
141 | };
|
---|
142 | /**
|
---|
143 | * Reconciles child context into parent one once the end of the i18n block is reached (i18nEnd).
|
---|
144 | *
|
---|
145 | * @param context Child I18nContext instance to be reconciled with parent context.
|
---|
146 | */
|
---|
147 | I18nContext.prototype.reconcileChildContext = function (context) {
|
---|
148 | var _this = this;
|
---|
149 | // set the right context id for open and close
|
---|
150 | // template tags, so we can use it as sub-block ids
|
---|
151 | ['start', 'close'].forEach(function (op) {
|
---|
152 | var key = context.meta[op + "Name"];
|
---|
153 | var phs = _this.placeholders.get(key) || [];
|
---|
154 | var tag = phs.find(findTemplateFn(_this.id, context.templateIndex));
|
---|
155 | if (tag) {
|
---|
156 | tag.ctx = context.id;
|
---|
157 | }
|
---|
158 | });
|
---|
159 | // reconcile placeholders
|
---|
160 | var childPhs = context.placeholders;
|
---|
161 | childPhs.forEach(function (values, key) {
|
---|
162 | var phs = _this.placeholders.get(key);
|
---|
163 | if (!phs) {
|
---|
164 | _this.placeholders.set(key, values);
|
---|
165 | return;
|
---|
166 | }
|
---|
167 | // try to find matching template...
|
---|
168 | var tmplIdx = phs.findIndex(findTemplateFn(context.id, context.templateIndex));
|
---|
169 | if (tmplIdx >= 0) {
|
---|
170 | // ... if found - replace it with nested template content
|
---|
171 | var isCloseTag = key.startsWith('CLOSE');
|
---|
172 | var isTemplateTag = key.endsWith('NG-TEMPLATE');
|
---|
173 | if (isTemplateTag) {
|
---|
174 | // current template's content is placed before or after
|
---|
175 | // parent template tag, depending on the open/close atrribute
|
---|
176 | phs.splice.apply(phs, tslib_1.__spreadArray([tmplIdx + (isCloseTag ? 0 : 1), 0], tslib_1.__read(values)));
|
---|
177 | }
|
---|
178 | else {
|
---|
179 | var idx = isCloseTag ? values.length - 1 : 0;
|
---|
180 | values[idx].tmpl = phs[tmplIdx];
|
---|
181 | phs.splice.apply(phs, tslib_1.__spreadArray([tmplIdx, 1], tslib_1.__read(values)));
|
---|
182 | }
|
---|
183 | }
|
---|
184 | else {
|
---|
185 | // ... otherwise just append content to placeholder value
|
---|
186 | phs.push.apply(phs, tslib_1.__spreadArray([], tslib_1.__read(values)));
|
---|
187 | }
|
---|
188 | _this.placeholders.set(key, phs);
|
---|
189 | });
|
---|
190 | this._unresolvedCtxCount--;
|
---|
191 | };
|
---|
192 | return I18nContext;
|
---|
193 | }());
|
---|
194 | exports.I18nContext = I18nContext;
|
---|
195 | //
|
---|
196 | // Helper methods
|
---|
197 | //
|
---|
198 | function wrap(symbol, index, contextId, closed) {
|
---|
199 | var state = closed ? '/' : '';
|
---|
200 | return util_1.wrapI18nPlaceholder("" + state + symbol + index, contextId);
|
---|
201 | }
|
---|
202 | function wrapTag(symbol, _a, closed) {
|
---|
203 | var index = _a.index, ctx = _a.ctx, isVoid = _a.isVoid;
|
---|
204 | return isVoid ? wrap(symbol, index, ctx) + wrap(symbol, index, ctx, true) :
|
---|
205 | wrap(symbol, index, ctx, closed);
|
---|
206 | }
|
---|
207 | function findTemplateFn(ctx, templateIndex) {
|
---|
208 | return function (token) { return typeof token === 'object' && token.type === TagType.TEMPLATE &&
|
---|
209 | token.index === templateIndex && token.ctx === ctx; };
|
---|
210 | }
|
---|
211 | function serializePlaceholderValue(value) {
|
---|
212 | var element = function (data, closed) { return wrapTag('#', data, closed); };
|
---|
213 | var template = function (data, closed) { return wrapTag('*', data, closed); };
|
---|
214 | var projection = function (data, closed) { return wrapTag('!', data, closed); };
|
---|
215 | switch (value.type) {
|
---|
216 | case TagType.ELEMENT:
|
---|
217 | // close element tag
|
---|
218 | if (value.closed) {
|
---|
219 | return element(value, true) + (value.tmpl ? template(value.tmpl, true) : '');
|
---|
220 | }
|
---|
221 | // open element tag that also initiates a template
|
---|
222 | if (value.tmpl) {
|
---|
223 | return template(value.tmpl) + element(value) +
|
---|
224 | (value.isVoid ? template(value.tmpl, true) : '');
|
---|
225 | }
|
---|
226 | return element(value);
|
---|
227 | case TagType.TEMPLATE:
|
---|
228 | return template(value, value.closed);
|
---|
229 | default:
|
---|
230 | return value;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | });
|
---|
234 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9yZW5kZXIzL3ZpZXcvaTE4bi9jb250ZXh0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRzs7Ozs7Ozs7Ozs7Ozs7SUFNSCxxRUFBdUg7SUFFdkgsSUFBSyxPQUdKO0lBSEQsV0FBSyxPQUFPO1FBQ1YsMkNBQU8sQ0FBQTtRQUNQLDZDQUFRLENBQUE7SUFDVixDQUFDLEVBSEksT0FBTyxLQUFQLE9BQU8sUUFHWDtJQUVEOztPQUVHO0lBQ0gsU0FBUyxhQUFhO1FBQ3BCLE9BQU8sRUFBQyxXQUFXLEVBQUUsNEJBQXFCLEVBQUUsRUFBRSxJQUFJLEVBQUUsSUFBSSxHQUFHLEVBQWlCLEVBQUMsQ0FBQztJQUNoRixDQUFDO0lBRUQ7Ozs7Ozs7Ozs7Ozs7O09BY0c7SUFDSDtRQVNFLHFCQUNhLEtBQWEsRUFBVyxHQUFrQixFQUFXLEtBQWlCLEVBQ3RFLGFBQWlDLEVBQVcsSUFBbUIsRUFDaEUsUUFBYztZQUZ3Qyxz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