MCPcopy Create free account
hub / github.com/angular/angular / visitComment

Method visitComment

packages/compiler/src/i18n/extractor_merger.ts:191–242  ·  view source on GitHub ↗
(comment: html.Comment, context: any)

Source from the content-addressed store, hash-verified

189 }
190
191 visitComment(comment: html.Comment, context: any): any {
192 const isOpening = _isOpeningComment(comment);
193
194 if (isOpening && this._isInTranslatableSection) {
195 this._reportError(comment, 'Could not start a block inside a translatable section');
196 return;
197 }
198
199 const isClosing = _isClosingComment(comment);
200
201 if (isClosing && !this._inI18nBlock) {
202 this._reportError(comment, 'Trying to close an unopened block');
203 return;
204 }
205
206 if (!this._inI18nNode && !this._inIcu) {
207 if (!this._inI18nBlock) {
208 if (isOpening) {
209 // deprecated from v5 you should use <ng-container i18n> instead of i18n comments
210 if (!i18nCommentsWarned && typeof console?.warn === 'function') {
211 i18nCommentsWarned = true;
212 const details = comment.sourceSpan.details ? `, ${comment.sourceSpan.details}` : '';
213 // TODO(ocombe): use a log service once there is a public one available
214 console.warn(
215 `I18n comments are deprecated, use an <ng-container> element instead (${comment.sourceSpan.start}${details})`,
216 );
217 }
218 this._inI18nBlock = true;
219 this._blockStartDepth = this._depth;
220 this._blockChildren = [];
221 this._blockMeaningAndDesc = comment
222 .value!.replace(_I18N_COMMENT_PREFIX_REGEXP, '')
223 .trim();
224 this._openTranslatableSection(comment);
225 }
226 } else {
227 if (isClosing) {
228 if (this._depth == this._blockStartDepth) {
229 this._closeTranslatableSection(comment, this._blockChildren);
230 this._inI18nBlock = false;
231 const message = this._addMessage(this._blockChildren, this._blockMeaningAndDesc)!;
232 // merge attributes in sections
233 const nodes = this._translateMessage(comment, message);
234 return html.visitAll(this, nodes);
235 } else {
236 this._reportError(comment, 'I18N blocks should not cross element boundaries');
237 return;
238 }
239 }
240 }
241 }
242 }
243
244 visitText(text: html.Text, context: any): html.Text {
245 if (this._isInTranslatableSection) {

Callers

nothing calls this directly

Calls 10

_reportErrorMethod · 0.95
_addMessageMethod · 0.95
_translateMessageMethod · 0.95
_isOpeningCommentFunction · 0.85
_isClosingCommentFunction · 0.85
warnMethod · 0.65
replaceMethod · 0.45
visitAllMethod · 0.45

Tested by

no test coverage detected