feat(compiler): change html parser to preserve comments
This commit is contained in:
@ -17,6 +17,7 @@ import {
|
||||
HtmlElementAst,
|
||||
HtmlAttrAst,
|
||||
HtmlTextAst,
|
||||
HtmlCommentAst,
|
||||
htmlVisitAll
|
||||
} from 'angular2/src/compiler/html_ast';
|
||||
import {ParseError, ParseLocation, ParseSourceSpan} from 'angular2/src/compiler/parse_util';
|
||||
@ -233,9 +234,9 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('comments', () => {
|
||||
it('should ignore comments', () => {
|
||||
it('should preserve comments', () => {
|
||||
expect(humanizeDom(parser.parse('<!-- comment --><div></div>', 'TestComp')))
|
||||
.toEqual([[HtmlElementAst, 'div', 0]]);
|
||||
.toEqual([[HtmlCommentAst, 'comment', 0], [HtmlElementAst, 'div', 0]]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -362,6 +363,12 @@ class Humanizer implements HtmlAstVisitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
visitComment(ast: HtmlCommentAst, context: any): any {
|
||||
var res = this._appendContext(ast, [HtmlCommentAst, ast.value, this.elDepth]);
|
||||
this.result.push(res);
|
||||
return null;
|
||||
}
|
||||
|
||||
private _appendContext(ast: HtmlAst, input: any[]): any[] {
|
||||
if (!this.includeSourceSpan) return input;
|
||||
input.push(ast.sourceSpan.toString());
|
||||
|
Reference in New Issue
Block a user