New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose tokenize() function #242
Comments
I don't have a problem with it. I'm curious, though. I'd be interested in hearing how you've used it in your own code. |
@thybzi what usecases are you looking to address? curious as well. |
I've wanted the same, maybe. And its nice that it shares the same Though, with the ability to drop Sizzle in jQuery itself, I don't think I would rely on a sizzle only API in practice. Its awkward to access Sizzle through It might be more interesting if something like |
Sorry for a long pause, somehow I missed GitHub answer notice. I use this function to parse a CSS selector to components and detect classes, IDs and other possible "attribute-driven stuff". That is used in my StyleDoc parser and showcase generator currently under development (insired with idea of https://github.com/Joony/styledoc, but fully rethought and rewritten). I use a modified version of jQuery with The code is a bit raw and ugly for now, here it is: styledoc.htmlApplyModifier = function(html, base, modifier)
{
var $wrapper = $('<styledoc-wrapper>').append(html);
var $elem = $(base, $wrapper);
if ($elem.length) {
var parsed = $.find.tokenize(modifier).pop();
var item,
attrName,
attrValue;
for (var i = 0; i < parsed.length; i++) {
item = parsed[i];
attrName = null;
attrValue = '';
switch (item.type) {
case 'ID':
attrName = 'id';
attrValue = item.matches[0];
break;
case 'CLASS':
attrName = 'class';
attrValue = item.matches[0];
break;
case 'ATTR':
attrName = item.matches[0];
attrValue = item.matches[2];
break;
case 'PSEUDO':
attrName = item.matches[0];
break;
}
if (attrName === 'class') {
$elem.addClass(attrValue);
} else if (attrName) {
$elem.attr(attrName, attrValue);
}
}
html = $wrapper.html();
}
return html;
}; |
So, would you do this? |
One of the concepts I've been toying with and may propose in the near future is rearranging tokens between combinators for more efficient right-to-left filtering (e.g., |
As for me, this shouldn't cause any problem, I just maybe replace pop() with shift(), if I'll need to :) |
If you're planning to use this in some kind of plugin or other public code that other less-capable people might use, we'd want to be careful with this kind of change. It's always the danger in exposing these kind of internals. |
If this was available, I'd use it to allow my project to suggest optimisations for jQuery selectors: https://github.com/jokeyrhyme/jqlint |
So, would you do this? I'd do it myself with a pull request, if someone tell my a right way (used by jQuery) to rebuild compiled/combined .js files when sources are changed. Such changes are also to be commited to repo, aren't they? I've found nothing about that at http://contribute.jquery.org/ :( |
okok, on it. By the way @thybzi, instructions for contributing to Sizzle are in the README under "Developing with Grunt". |
Be aware this is still an undocumented function and is subject to change. |
Is this missing now? jQuery 3.7.0.
We use this in pie6k/jquery.initialize. We watch the DOM for mutations that match a selector, and being able tokenise the selector allows us to ignore certain mutations that the selector would never match against. |
@bezborodow thanks for the info. I extracted your comment to a separate jQuery issue: jquery/jquery#5259. |
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` * `jQuery.find.tokenize` Fixes jquerygh-5259 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` * `jQuery.find.tokenize` Fixes jquerygh-5259 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` * `jQuery.find.tokenize` Fixes jquerygh-5259 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` * `jQuery.find.tokenize` Fixes jquerygh-5259 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` A new test was also added for `jQuery.find.tokenize` - even Sizzle was missing one. Fixes jquerygh-5259 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` A new test was also added for `jQuery.find.tokenize` - even Sizzle was missing one. Fixes jquerygh-5259 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` A new test was also added for `jQuery.find.tokenize` - even Sizzle was missing one. Fixes jquerygh-5259 Ref jquerygh-5260 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` A new test was also added for `jQuery.find.tokenize` - even Sizzle was missing one. Fixes jquerygh-5259 Ref jquerygh-5263 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. Some other APIs so far only exposed on the `3.x` line are also added back: * `jQuery.find.select` * `jQuery.find.compile` * `jQuery.find.setDocument` In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` A new test was also added for `jQuery.find.tokenize` - even Sizzle was missing one. Fixes jquerygh-5259 Ref jquerygh-5260 Ref jquery/sizzle#242 Ref jquerygh-5113 Ref jquerygh-4395 Ref jquerygh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. Some other APIs so far only exposed on the `3.x` line are also added back: * `jQuery.find.select` * `jQuery.find.compile` * `jQuery.find.setDocument` In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` A new test was also added for `jQuery.find.tokenize` - even Sizzle was missing one. Fixes gh-5259 Closes gh-5263 Ref gh-5260 Ref jquery/sizzle#242 Ref gh-5113 Ref gh-4395 Ref gh-4406
`Sizzle.tokenize` is an internal Sizzle API, but exposed. As a result, it has historically been available in jQuery via `jQuery.find.tokenize`. That got dropped during Sizzle removal; this change restores the API. In addition to that, Sizzle tests have been backported for the following APIs: * `jQuery.find.matchesSelector` * `jQuery.find.matches` * `jQuery.find.compile` * `jQuery.find.select` A new test was also added for `jQuery.find.tokenize` - even Sizzle was missing one. Fixes gh-5259 Closes gh-5260 Ref gh-5263 Ref jquery/sizzle#242 Ref gh-5113 Ref gh-4395 Ref gh-4406
Sometimes it's very useful to get tokenized CSS selector parsed by internal function
tokenize()
Why not expose it for public use? Just like that, for example:
The text was updated successfully, but these errors were encountered: