From bc06a727602e712374ecbf9c1494ec372f087c84 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 8 Mar 2014 23:18:17 +0200 Subject: [PATCH] Enable `curly` check. --- .jshintrc | 2 +- src/htmlparser.js | 65 +++++++++++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/.jshintrc b/.jshintrc index 82dacc9..19da2b0 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,6 +1,6 @@ { "browser": true, - "curly": false, + "curly": true, "eqeqeq": true, "expr": true, "immed": true, diff --git a/src/htmlparser.js b/src/htmlparser.js index b1f389f..06ed2d8 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -77,8 +77,9 @@ index = html.indexOf('-->'); if ( index >= 0 ) { - if ( handler.comment ) + if ( handler.comment ) { handler.comment( html.substring( 4, index ) ); + } html = html.substring( index + 3 ); chars = false; } @@ -97,8 +98,9 @@ // Doctype: else if ( (match = doctype.exec( html )) ) { - if ( handler.doctype ) + if ( handler.doctype ) { handler.doctype( match[0] ); + } html = html.substring( match[0].length ); chars = false; } @@ -145,8 +147,9 @@ } } - if ( handler.chars ) + if ( handler.chars ) { handler.chars(text, prevTag, nextTag); + } } @@ -162,8 +165,9 @@ .replace(//g, '$1'); } - if ( handler.chars ) + if ( handler.chars ) { handler.chars( text ); + } return ''; }); @@ -171,8 +175,9 @@ parseEndTag( '', stackedTag ); } - if ( html === last ) + if ( html === last ) { throw 'Parse Error: ' + html; + } last = html; } @@ -213,8 +218,9 @@ }); }); - if ( handler.start ) + if ( handler.start ) { handler.start( tagName, attrs, unary, unarySlash ); + } } } @@ -222,20 +228,23 @@ var pos; // If no tag name is provided, clean shop - if ( !tagName ) + if ( !tagName ) { pos = 0; - - // Find the closest opened tag of the same type - else - for ( pos = stack.length - 1; pos >= 0; pos-- ) - if ( stack[ pos ] === tagName ) + } else { // Find the closest opened tag of the same type + for ( pos = stack.length - 1; pos >= 0; pos-- ) { + if ( stack[ pos ] === tagName ) { break; + } + } + } if ( pos >= 0 ) { // Close all the open elements, up the stack - for ( var i = stack.length - 1; i >= pos; i-- ) - if ( handler.end ) + for ( var i = stack.length - 1; i >= pos; i-- ) { + if ( handler.end ) { handler.end( stack[ i ] ); + } + } // Remove the open elements from the stack stack.length = pos; @@ -250,8 +259,9 @@ start: function( tag, attrs, unary ) { results += '<' + tag; - for ( var i = 0; i < attrs.length; i++ ) + for ( var i = 0; i < attrs.length; i++ ) { results += ' ' + attrs[i].name + '="' + attrs[i].escaped + '"'; + } results += (unary ? '/' : '') + '>'; }, @@ -283,17 +293,19 @@ }; if ( !doc ) { - if ( typeof DOMDocument !== 'undefined' ) + if ( typeof DOMDocument !== 'undefined' ) { doc = new DOMDocument(); - else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) + } else if ( typeof document !== 'undefined' && document.implementation && document.implementation.createDocument ) { doc = document.implementation.createDocument('', '', null); - else if ( typeof ActiveX !== 'undefined' ) + } else if ( typeof ActiveX !== 'undefined' ) { doc = new ActiveXObject('Msxml.DOMDocument'); + } - } else + } else { doc = doc.ownerDocument || doc.getOwnerDocument && doc.getOwnerDocument() || doc; + } var elems = [], documentElement = doc.documentElement || @@ -313,9 +325,11 @@ } // Find all the unique elements - if ( doc.getElementsByTagName ) - for ( var i in one ) + if ( doc.getElementsByTagName ) { + for ( var i in one ) { one[ i ] = doc.getElementsByTagName( i )[0]; + } + } // If we're working with a document, inject contents into // the body element @@ -332,14 +346,15 @@ var elem = doc.createElement( tagName ); - for ( var attr in attrs ) + for ( var attr in attrs ) { elem.setAttribute( attrs[ attr ].name, attrs[ attr ].value ); + } - if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) + if ( structure[ tagName ] && typeof one[ structure[ tagName ] ] !== 'boolean' ) { one[ structure[ tagName ] ].appendChild( elem ); - - else if ( curParentNode && curParentNode.appendChild ) + } else if ( curParentNode && curParentNode.appendChild ) { curParentNode.appendChild( elem ); + } if ( !unary ) { elems.push( elem ); -- 2.34.1