11var utils = require ( './utils' ) ,
2-
32 diff = require ( 'diff' ) ,
43 htmlParser = require ( 'htmlparser2' ) ,
54 AST2Html = require ( 'htmlparser-to-html' ) ,
@@ -32,6 +31,8 @@ function htmlToAST(HTMLDoc) {
3231 * @returns {AST }
3332 */
3433function modifyASTTree ( tree , options ) {
34+ var delComments = [ ] ;
35+
3536 _ . forEach ( tree , function ( node ) {
3637 if ( options . ignoreWhitespace && node . type === 'text' ) {
3738
@@ -43,6 +44,12 @@ function modifyASTTree(tree, options) {
4344 return ;
4445 }
4546
47+ if ( options . ignoreHtmlComments && node . type === 'comment' ) {
48+ delComments . push ( tree . indexOf ( node ) ) ;
49+
50+ return ;
51+ }
52+
4653 if ( node . hasOwnProperty ( 'attribs' ) ) {
4754 var attrs = utils . sortObj ( node [ 'attribs' ] ) ;
4855
@@ -76,6 +83,10 @@ function modifyASTTree(tree, options) {
7683 }
7784 } ) ;
7885
86+ for ( var i = 0 ; i < delComments . length ; i ++ ) {
87+ tree . splice ( delComments [ i ] - i , 1 ) ;
88+ }
89+
7990 return tree ;
8091}
8192
@@ -194,7 +205,6 @@ function bemDiff(html1, html2) {
194205 loggerOptions = {
195206 showCharacters : 40
196207 } ,
197-
198208 htmlDiffer = new HtmlDiff ( options ) ;
199209
200210 logger . log ( htmlDiffer . diff ( html1 , html2 ) , loggerOptions ) ;
0 commit comments