Skip to content

Commit

Permalink
makes selector type check clearer and more performant by first decidi…
Browse files Browse the repository at this point in the history
…ng main type of selector and then checking subtypes #2
  • Loading branch information
GGAlanSmithee committed Oct 20, 2015
1 parent 0c67950 commit 6940a73
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/core/selector-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export const SelectorType = {
*
* @author Alan Smithee
*/
export const Regex = {
const Regex = {
None : '',
Invalid : '',
Universal : /\*/,
Type : /^[A-Za-z]+/,
Type : /^[A-Za-z]/,
TypeClass : /^[A-Za-z]+\.[A-Za-z]+$/,
TypeId : /^[A-Za-z]+\#[A-Za-z]+$/,
Class : /^\.[A-Za-z]+$/,
Expand All @@ -54,12 +54,13 @@ export default function getType(selector) {
return SelectorType.Universal;
}

return selector === '*' ? SelectorType.Universal :
Regex.Class.test(selector) ? SelectorType.Class :
Regex.Id.test(selector) ? SelectorType.Id :
Regex.Type.test(selector) ?
(Regex.TypeClass.test(selector) ? SelectorType.TypeClass :
Regex.TypeId.test(selector) ? SelectorType.TypeId :
SelectorType.Type) :
SelectorType.None;
if (Regex.Type.test(selector)) {
return Regex.TypeClass.test(selector) ? SelectorType.TypeClass :
Regex.TypeId.test(selector) ? SelectorType.TypeId :
SelectorType.Type;
}

return Regex.Class.test(selector) ? SelectorType.Class :
Regex.Id.test(selector) ? SelectorType.Id :
SelectorType.None;
}

0 comments on commit 6940a73

Please sign in to comment.