@@ -8,15 +8,14 @@ var utils = require('./utils'),
88/**
99 * Converts the HTML document to the AST Tree
1010 * @param {String } HTMLDoc
11- * @param {Object } options
1211 * @returns {AST }
1312 */
1413function htmlToAST ( HTMLDoc ) {
1514 var parser ,
1615 parserHandler ;
1716
18- parserHandler = new htmlParser . DomHandler ( function ( err ) {
19- if ( err ) console . log ( err ) ;
17+ parserHandler = new htmlParser . DomHandler ( function ( err ) {
18+ if ( err ) { console . log ( err ) ; }
2019 } ) ;
2120
2221 parser = new htmlParser . Parser ( parserHandler ) ;
@@ -34,9 +33,8 @@ function htmlToAST(HTMLDoc) {
3433function modifyASTTree ( tree , options ) {
3534 var delComments = [ ] ;
3635
37- _ . forEach ( tree , function ( node ) {
36+ _ . forEach ( tree , function ( node ) {
3837 if ( options . ignoreWhitespaces && node . type === 'text' ) {
39-
4038 node . data = node . data
4139 . replace ( / ( \n | \r | \t | \v | \f ) + / g, '' )
4240 . replace ( / \s + / g, ' ' )
@@ -52,31 +50,30 @@ function modifyASTTree(tree, options) {
5250 }
5351
5452 if ( node . hasOwnProperty ( 'attribs' ) ) {
55- var attrs = utils . sortObj ( node [ ' attribs' ] ) ;
53+ var attrs = utils . sortObj ( node . attribs ) ;
5654
5755 if ( attrs . hasOwnProperty ( 'class' ) ) {
5856 attrs [ 'class' ] = utils . sortCssClasses ( attrs [ 'class' ] ) ;
5957 }
6058
61- _ . forEach ( options . compareHtmlAttrsAsJSON , function ( attr ) {
59+ _ . forEach ( options . compareHtmlAttrsAsJSON , function ( attr ) {
6260 var attrValue ,
6361 isFunction = ( attr === 'onclick' || attr === 'ondblclick' ) ; // @FIXME : should be configurable
6462
6563 if ( attrs . hasOwnProperty ( attr ) ) {
66-
6764 attrValue = utils . parseAttr ( attrs [ attr ] . replace ( / & q u o t ; / g, '"' ) , isFunction ) ;
6865 attrValue = utils . sortObj ( attrValue ) ;
6966 attrValue = JSON . stringify ( attrValue ) ;
7067
71- attrs [ attr ] = ( isFunction ? 'return ' : '' ) + attrValue . replace ( / " / g, '"' )
68+ attrs [ attr ] = ( isFunction ? 'return ' : '' ) + attrValue . replace ( / " / g, '"' ) ;
7269 }
7370 } ) ;
7471
75- _ . forEach ( options . ignoreHtmlAttrs , function ( attr ) {
72+ _ . forEach ( options . ignoreHtmlAttrs , function ( attr ) {
7673 attrs . hasOwnProperty ( attr ) && ( attrs [ attr ] = '' ) ;
7774 } ) ;
7875
79- node [ ' attribs' ] = attrs ;
76+ node . attribs = attrs ;
8077 }
8178
8279 if ( node . hasOwnProperty ( 'children' ) ) {
@@ -93,19 +90,18 @@ function modifyASTTree(tree, options) {
9390
9491/**
9592 *
96- * @param [options]
93+ * @param { Object } [options]
9794 * @param {String[] } [options.ignoreHtmlAttrs]
9895 * @param {String[] } [options.compareHtmlAttrsAsJSON]
9996 * @param {Boolean } [options.verbose]
10097 * @param {Boolean } [options.ignoreWhitespaces=true]
10198 * @param {Boolean } [options.bem=false]
10299 * @constructor
103100 */
104- var HtmlDiff = function ( options ) {
101+ var HtmlDiff = function ( options ) {
105102 this . options = utils . defaults ( options ) ;
106- } ;
107-
108- var Diff = diff . Diff ;
103+ } ,
104+ Diff = diff . Diff ;
109105
110106HtmlDiff . prototype = Diff . prototype ;
111107
@@ -114,7 +110,7 @@ HtmlDiff.prototype = Diff.prototype;
114110 * @param {String } value
115111 * @returns {Array }
116112 */
117- HtmlDiff . prototype . tokenize = function ( value ) {
113+ HtmlDiff . prototype . tokenize = function ( value ) {
118114 var options = this . options ,
119115 ASTTree = htmlToAST ( value , options ) ;
120116
@@ -132,18 +128,18 @@ HtmlDiff.prototype.tokenize = function(value) {
132128
133129/**
134130 *
135- * @param [options]
131+ * @param { Object } [options]
136132 * @param {String[] } [options.ignoreHtmlAttrs]
137133 * @param {String[] } [options.compareHtmlAttrsAsJSON]
138134 * @param {Boolean } [options.verbose]
139135 * @param {Boolean } [options.ignoreWhitespaces=true]
140136 * @param {Boolean } [options.bem=false]
141137 * @constructor
142138 */
143- var HtmlDiffer = function ( options ) {
139+ var HtmlDiffer = function ( options ) {
144140 options = utils . defaults ( options ) ;
145141
146- if ( options [ ' bem' ] ) {
142+ if ( options . bem ) {
147143 options . ignoreHtmlAttrs = [ 'id' , 'for' ] ;
148144 options . compareHtmlAttrsAsJSON = [ 'data-bem' , 'onclick' , 'ondblclick' ] ;
149145 }
@@ -158,7 +154,7 @@ var HtmlDiffer = function(options) {
158154 * @param {Object } [options]
159155 * @returns {Diff }
160156 */
161- HtmlDiffer . prototype . diffHtml = function ( html1 , html2 , options ) {
157+ HtmlDiffer . prototype . diffHtml = function ( html1 , html2 , options ) {
162158 if ( options ) {
163159 console . warn ( 'WARNING! The third param of \'diffHtml\' method is deprecated!' . bold . red ) ;
164160 }
@@ -177,7 +173,7 @@ HtmlDiffer.prototype.diffHtml = function(html1, html2, options) {
177173 * @param {Object } [options]
178174 * @returns {Boolean }
179175 */
180- HtmlDiffer . prototype . isEqual = function ( html1 , html2 , options ) {
176+ HtmlDiffer . prototype . isEqual = function ( html1 , html2 , options ) {
181177 if ( options ) {
182178 console . warn ( 'WARNING! The third param of \'isEqual\' method is deprecated!' . bold . red ) ;
183179 }
@@ -211,7 +207,6 @@ function bemDiff(html1, html2) {
211207 logger . log ( htmlDiffer . diff ( html1 , html2 ) , loggerOptions ) ;
212208}
213209
214-
215210var htmlDiffer = new HtmlDiffer ( ) ;
216211
217212module . exports = {
0 commit comments