Skip to content

Commit

Permalink
Make Sizzle JSHinty-fresh by marking a switch fall-through and cleani…
Browse files Browse the repository at this point in the history
…ng up some spacing issues.
  • Loading branch information
dmethvin committed Dec 9, 2011
1 parent 2e66482 commit 9358740
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions sizzle.js
Expand Up @@ -34,7 +34,7 @@ var Sizzle = function( selector, context, results, seed ) {
if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
return [];
}

if ( !selector || typeof selector !== "string" ) {
return results;
}
Expand All @@ -44,17 +44,17 @@ var Sizzle = function( selector, context, results, seed ) {
contextXML = Sizzle.isXML( context ),
parts = [],
soFar = selector;

// Reset the position of the chunker regexp (start from head)
do {
chunker.exec( "" );
m = chunker.exec( soFar );

if ( m ) {
soFar = m[3];

parts.push( m[1] );

if ( m[2] ) {
extra = m[3];
break;
Expand All @@ -78,7 +78,7 @@ var Sizzle = function( selector, context, results, seed ) {
if ( Expr.relative[ selector ] ) {
selector += parts.shift();
}

set = posProcess( selector, set, seed );
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ Sizzle.find = function( expr, context, isXML ) {

for ( i = 0, len = Expr.order.length; i < len; i++ ) {
type = Expr.order[i];

if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
left = match[1];
match.splice( 1, 1 );
Expand Down Expand Up @@ -578,7 +578,7 @@ var Expr = Sizzle.selectors = {

ATTR: function( match, curLoop, inplace, result, not, isXML ) {
var name = match[1] = match[1].replace( rBackslash, "" );

if ( !isXML && Expr.attrMap[name] ) {
match[1] = Expr.attrMap[name];
}
Expand Down Expand Up @@ -612,7 +612,7 @@ var Expr = Sizzle.selectors = {
} else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
return true;
}

return match;
},

Expand All @@ -622,7 +622,7 @@ var Expr = Sizzle.selectors = {
return match;
}
},

filters: {
enabled: function( elem ) {
return elem.disabled === false && elem.type !== "hidden";
Expand All @@ -635,14 +635,14 @@ var Expr = Sizzle.selectors = {
checked: function( elem ) {
return elem.checked === true;
},

selected: function( elem ) {
// Accessing this property makes selected-by-default
// options in Safari work properly
if ( elem.parentNode ) {
elem.parentNode.selectedIndex;
}

return elem.selected === true;
},

Expand All @@ -664,7 +664,7 @@ var Expr = Sizzle.selectors = {

text: function( elem ) {
var attr = elem.getAttribute( "type" ), type = elem.type;
// IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
// IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
// use getAttribute instead to test this case
return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
},
Expand Down Expand Up @@ -782,22 +782,23 @@ var Expr = Sizzle.selectors = {
switch ( type ) {
case "only":
case "first":
while ( (node = node.previousSibling) ) {
if ( node.nodeType === 1 ) {
return false;
while ( (node = node.previousSibling) ) {
if ( node.nodeType === 1 ) {
return false;
}
}

if ( type === "first" ) {
return true;
if ( type === "first" ) {
return true;
}

node = elem;

/* falls through */
case "last":
while ( (node = node.nextSibling) ) {
if ( node.nodeType === 1 ) {
return false;
while ( (node = node.nextSibling) ) {
if ( node.nodeType === 1 ) {
return false;
}
}

Expand All @@ -810,22 +811,22 @@ var Expr = Sizzle.selectors = {
if ( first === 1 && last === 0 ) {
return true;
}

doneName = match[0];
parent = elem.parentNode;

if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {
count = 0;

for ( node = parent.firstChild; node; node = node.nextSibling ) {
if ( node.nodeType === 1 ) {
node.nodeIndex = ++count;
}
}
}

parent[ expando ] = doneName;
}

diff = elem.nodeIndex - last;

if ( first === 0 ) {
Expand All @@ -844,7 +845,7 @@ var Expr = Sizzle.selectors = {
TAG: function( elem, match ) {
return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;
},

CLASS: function( elem, match ) {
return (" " + (elem.className || elem.getAttribute("class")) + " ")
.indexOf( match ) > -1;
Expand Down Expand Up @@ -914,7 +915,7 @@ var makeArray = function( array, results ) {
results.push.apply( results, array );
return results;
}

return array;
};

Expand Down Expand Up @@ -1146,7 +1147,7 @@ if ( document.querySelectorAll ) {
if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
return;
}

Sizzle = function( query, context, extra, seed ) {
context = context || document;

Expand All @@ -1155,24 +1156,24 @@ if ( document.querySelectorAll ) {
if ( !seed && !Sizzle.isXML(context) ) {
// See if we find a selector to speed up
var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );

if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
// Speed-up: Sizzle("TAG")
if ( match[1] ) {
return makeArray( context.getElementsByTagName( query ), extra );

// Speed-up: Sizzle(".CLASS")
} else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
return makeArray( context.getElementsByClassName( match[2] ), extra );
}
}

if ( context.nodeType === 9 ) {
// Speed-up: Sizzle("body")
// The body element only exists once, optimize finding it
if ( query === "body" && context.body ) {
return makeArray( [ context.body ], extra );

// Speed-up: Sizzle("#ID")
} else if ( match && match[3] ) {
var elem = context.getElementById( match[3] );
Expand All @@ -1185,12 +1186,12 @@ if ( document.querySelectorAll ) {
if ( elem.id === match[3] ) {
return makeArray( [ elem ], extra );
}

} else {
return makeArray( [], extra );
}
}

try {
return makeArray( context.querySelectorAll(query), extra );
} catch(qsaError) {}
Expand Down Expand Up @@ -1228,7 +1229,7 @@ if ( document.querySelectorAll ) {
}
}
}

return oldSizzle(query, context, extra, seed);
};

Expand All @@ -1255,7 +1256,7 @@ if ( document.querySelectorAll ) {
// This should fail with an exception
// Gecko does not error, returns false instead
matches.call( document.documentElement, "[test!='']:sizzle" );

} catch( pseudoError ) {
pseudoWorks = true;
}
Expand All @@ -1265,7 +1266,7 @@ if ( document.querySelectorAll ) {
expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");

if ( !Sizzle.isXML( node ) ) {
try {
try {
if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
var ret = matches.call( node, expr );

Expand Down Expand Up @@ -1302,7 +1303,7 @@ if ( document.querySelectorAll ) {
if ( div.getElementsByClassName("e").length === 1 ) {
return;
}

Expr.order.splice(1, 0, "CLASS");
Expr.find.CLASS = function( match, context, isXML ) {
if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
Expand Down Expand Up @@ -1353,7 +1354,7 @@ function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {

if ( elem ) {
var match = false;

elem = elem[dir];

while ( elem ) {
Expand Down Expand Up @@ -1406,7 +1407,7 @@ if ( document.documentElement.contains ) {

Sizzle.isXML = function( elem ) {
// documentElement is verified for cases where it doesn't yet exist
// (such as loading iframes in IE - #4833)
// (such as loading iframes in IE - #4833)
var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;

return documentElement ? documentElement.nodeName !== "HTML" : false;
Expand Down

0 comments on commit 9358740

Please sign in to comment.