-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler): option to include html comments in `ParsedTemplat…
…e` (#41251) Adds a `collectCommentNodes` option on `ParseTemplateOptions` which will cause the returned `ParsedTemplate` to include an array of all html comments found in the template. PR Close #41251
- Loading branch information
1 parent
5e8afc9
commit 6dcea34
Showing
5 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/compiler/test/render3/view/parse_template_options_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @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.io/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> | ||
`; | ||
|
||
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(2); | ||
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![1]).toBeInstanceOf(Comment); | ||
expect(templateCommentsOptionEnabled.commentNodes![1].value).toEqual('some nested comment'); | ||
expect(templateCommentsOptionEnabled.commentNodes![1].sourceSpan) | ||
.toBeInstanceOf(ParseSourceSpan); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters