feat(compiler): change html parser to preserve comments

This commit is contained in:
vsavkin
2016-03-06 20:21:20 -08:00
committed by Victor Savkin
parent f1796d67f4
commit 70d18b5b53
6 changed files with 36 additions and 6 deletions

View File

@ -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());