pull lowercasing out of class matcher#141
Merged
michaelficarra merged 5 commits intoestools:masterfrom Mar 7, 2023
Merged
Conversation
Member
|
I mean, we could also pull out the comparisons. Not sure how far we want to go with this. But this is an improvement, so we can merge as-is. case 'class': {
switch(selector.name.toLowerCase()) {
case 'statement':
return (node, ancestry, options) => {
if (options && options.matchClass) {
return options.matchClass(selector.name, node, ancestry);
}
if (options && options.nodeTypeKey) return false;
if(node.type.slice(-9) === 'Statement') return true;
return node.type.slice(-11) === 'Declaration';
};
case 'declaration':
return (node, ancestry, options) => {
if (options && options.matchClass) {
return options.matchClass(selector.name, node, ancestry);
}
if (options && options.nodeTypeKey) return false;
return node.type.slice(-11) === 'Declaration';
}
case 'pattern':
return (node, ancestry, options) => {
if (options && options.matchClass) {
return options.matchClass(selector.name, node, ancestry);
}
if (options && options.nodeTypeKey) return false;
if(node.type.slice(-7) === 'Pattern') return true;
return node.type.slice(-10) === 'Expression' ||
node.type.slice(-7) === 'Literal' ||
(
node.type === 'Identifier' &&
(ancestry.length === 0 || ancestry[0].type !== 'MetaProperty')
) ||
node.type === 'MetaProperty';
}
case 'expression':
return (node, ancestry, options) => {
if (options && options.matchClass) {
return options.matchClass(selector.name, node, ancestry);
}
if (options && options.nodeTypeKey) return false;
return node.type.slice(-10) === 'Expression' ||
node.type.slice(-7) === 'Literal' ||
(
node.type === 'Identifier' &&
(ancestry.length === 0 || ancestry[0].type !== 'MetaProperty')
) ||
node.type === 'MetaProperty';
}
case 'function':
return (node, ancestry, options) => {
if (options && options.matchClass) {
return options.matchClass(selector.name, node, ancestry);
}
if (options && options.nodeTypeKey) return false;
return node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression' ||
node.type === 'ArrowFunctionExpression';
}
}
} |
michaelficarra
approved these changes
Mar 7, 2023
Contributor
Author
|
I just wanted to restore to the previous state. Too many refactors while I was working on it. :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves the selector name
.toLowerCase()back outside of the created function to avoid multiple calls.