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