/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/compiler/test/render3/view/parse_template_options_spec.ts
94 строки
4 KB
Matthieu Riegler
refactor(compiler): Collect in-element comments
15 июн 2026, 20:54
15 июн 2026, 20:54
471dcb4
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC 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.dev/license */ import {ParseSourceSpan} from '../../../src/parse_util'; import {Comment} from '../../../src/render3/r3_ast'; import {parseTemplate} from '../../../src/render3/view/template'; describe('collectCommentNodes', () => { it('should include an array of HTML comment nodes on the returned R3 AST', () => { const html = ` <!-- eslint-disable-next-line --> <div *ngFor="let item of items"> {{item.name}} </div> <div> <p> <!-- some nested comment --> <span>Text</span> </p> <div // some comment in the middle of an element /*some other comment*/ /* some other comment with trailing space */ ></div> </div> `; const templateNoCommentsOption = parseTemplate(html, '', {}); expect(templateNoCommentsOption.commentNodes).toBeUndefined(); const templateCommentsOptionDisabled = parseTemplate(html, '', {collectCommentNodes: false}); expect(templateCommentsOptionDisabled.commentNodes).toBeUndefined(); const templateCommentsOptionEnabled = parseTemplate(html, '', {collectCommentNodes: true}); expect(templateCommentsOptionEnabled.commentNodes!.length).toEqual(5); expect(templateCommentsOptionEnabled.commentNodes![0]).toBeInstanceOf(Comment); expect(templateCommentsOptionEnabled.commentNodes![0].value).toEqual( 'eslint-disable-next-line', ); expect(templateCommentsOptionEnabled.commentNodes![0].sourceSpan).toBeInstanceOf( ParseSourceSpan, ); expect(templateCommentsOptionEnabled.commentNodes![0].sourceSpan.toString()).toEqual( '<!-- eslint-disable-next-line -->', ); expect(templateCommentsOptionEnabled.commentNodes![1]).toBeInstanceOf(Comment); expect(templateCommentsOptionEnabled.commentNodes![1].value).toEqual('some nested comment'); expect(templateCommentsOptionEnabled.commentNodes![1].sourceSpan).toBeInstanceOf( ParseSourceSpan, ); expect(templateCommentsOptionEnabled.commentNodes![1].sourceSpan.toString()).toEqual( '<!-- some nested comment -->', ); expect(templateCommentsOptionEnabled.commentNodes![2]).toBeInstanceOf(Comment); expect(templateCommentsOptionEnabled.commentNodes![2].value).toEqual( ' some comment in the middle of an element', ); expect(templateCommentsOptionEnabled.commentNodes![2].sourceSpan).toBeInstanceOf( ParseSourceSpan, ); expect(templateCommentsOptionEnabled.commentNodes![2].sourceSpan.toString()).toEqual( '// some comment in the middle of an element', ); expect(templateCommentsOptionEnabled.commentNodes![3]).toBeInstanceOf(Comment); expect(templateCommentsOptionEnabled.commentNodes![3].value).toEqual('some other comment'); expect(templateCommentsOptionEnabled.commentNodes![3].sourceSpan).toBeInstanceOf( ParseSourceSpan, ); expect(templateCommentsOptionEnabled.commentNodes![3].sourceSpan.toString()).toEqual( '/*some other comment*/', ); // This is capturing the trailing space behavior expect(templateCommentsOptionEnabled.commentNodes![4]).toBeInstanceOf(Comment); expect(templateCommentsOptionEnabled.commentNodes![4].value).toEqual( ' some other comment with trailing space ', ); expect(templateCommentsOptionEnabled.commentNodes![4].sourceSpan).toBeInstanceOf( ParseSourceSpan, ); expect(templateCommentsOptionEnabled.commentNodes![4].sourceSpan.toString()).toEqual( '/* some other comment with trailing space */', ); }); });