aboutsummaryrefslogtreecommitdiffstats
path: root/src/selector.js
Commit message (Collapse)AuthorAgeFilesLines
* Selector: Properly deprecate `jQuery.expr[ ":" ]`/`jQuery.expr.filters`Michał Gołębiowski-Owczarek2024-11-041-1/+1
| | | | | | | | | | | Those APIs have formally been deprecated since `3.0.0`, but they never made its way into the deprecated module. `jQuery.expr[ ":" ]` has been removed when Sizzle got inlined into Core in gh-4395; this change restores it. Closes gh-5580 Ref gh-5570 Ref gh-4395
* Selector: Make `selector.js` module depend on `attributes/attr.js`Michał Gołębiowski-Owczarek2024-01-121-2/+1
| | | | | | | | | This fixes custom builds using the `--include` switch that don't include the `attributes` module. Fixes gh-5379 Closes gh-5384 Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
* CSS:Selector: Align with 3.x, remove the outer `selector.js` wrapperMichał Gołębiowski-Owczarek2023-09-201-13/+16
| | | | | | | | | | | | | | | | Bring some changes from `3.x-stable`: * rename `rtrim` to `rtrimCSS` to distinguish from the previous `rtrim` regex used for `jQuery.trim` * backport one `id` selector test that avoids the selector engine path Other changes: * remove the inner function wrapper from `selector.js` by renaming the imported `document.js` value * use `jQuery.error` in `selectorError` * make Selector tests pass in all-modules runs by fixing a sinon mistake in Core tests - Core tests had a spy set up for `jQuery.error` that wasn't cleaned up, influencing Selector tests when all were run together Closes gh-5295
* Core: Use named exports in `src/`Michał Gołębiowski-Owczarek2023-09-121-24/+26
| | | | | | | | | The `default` export is treated differently across tooling when transpiled to CommonJS - tools differ on whether `module.exports` represents the full module object or just its default export. Switch `src/` modules to named exports for tooling consistency. Fixes gh-5262 Closes gh-5292
* Selector: Re-expose jQuery.find.{tokenize,select,compile,setDocument}Michał Gołębiowski-Owczarek2023-06-121-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | `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
* Selector: Stop relying on CSS.supports( "selector(...)" )Michał Gołębiowski-Owczarek2023-02-141-27/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | `CSS.supports( "selector(...)" )` has different semantics than selectors passed to `querySelectorAll`. Apart from the fact that the former returns `false` for unrecognized selectors and the latter throws, `qSA` is more forgiving and accepts some invalid selectors, auto-correcting them where needed - for example, mismatched brackers are auto-closed. This behavior difference is breaking for many users. To add to that, a recent CSSWG resolution made `:is()` & `:where()` the only pseudos with forgiving parsing; browsers are in the process of making `:has()` parsing unforgiving. Taking all that into account, we go back to our previous try-catch approach without relying on `CSS.supports( "selector(...)" )`. The only difference is we detect forgiving parsing in `:has()` and mark the selector as buggy. The PR also updates `playwright-webkit` so that we test against a version of WebKit that already has non-forgiving `:has()`. Fixes gh-5194 Closes gh-5206 Ref gh-5098 Ref gh-5107 Ref w3c/csswg-drafts#7676 Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
* Selector: Backport jQuery selection context logic to selector-nativeMichał Gołębiowski-Owczarek2023-02-131-317/+63
| | | | | | | | | | | | | | | | | | | | | | This makes: ```js $div.find("div > *") ``` no longer matching children of `$div`. Also, leading combinators now work, e.g.: ```js $div.find( "> *" ); ``` returns children of `$div`. As a result of that, a number of tests are no longer skipped in the `selector-native` mode. Also, rename `rcombinators` to `rleadingCombinator`. Fixes gh-5185 Closes gh-5186 Ref gh-5085
* Selector: Make selector lists work with `qSA` againMichał Gołębiowski-Owczarek2022-12-191-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | jQuery 3.6.2 started using `CSS.supports( "selector(SELECTOR)" )` before using `querySelectorAll` on the selector. This was to solve gh-5098 - some selectors, like `:has()`, now had their parameters parsed in a forgiving way, meaning that `:has(:fakepseudo)` no longer throws but just returns 0 results, breaking that jQuery mechanism. A recent spec change made `CSS.supports( "selector(SELECTOR)" )` always use non-forgiving parsing, allowing us to use this API for what we've used `try-catch` before. To solve the issue on the spec side for older jQuery versions, `:has()` parameters are no longer using forgiving parsing in the latest spec update but our new mechanism is more future-proof anyway. However, the jQuery implementation has a bug - in `CSS.supports( "selector(SELECTOR)" )`, `SELECTOR` needs to be a `<complex-selector>` and not a `<complex-selector-list>`. Which means that selector lists now skip `qSA` and go to the jQuery custom traversal: ```js CSS.supports("selector(div:valid, span)"); // false CSS.supports("selector(div:valid)"); // true CSS.supports("selector(span)"); // true ``` To solve this, this commit wraps the selector list passed to `CSS.supports( "selector(:is(SELECTOR))" )` with `:is`, making it a single selector again. See: * https://w3c.github.io/csswg-drafts/css-conditional-4/#at-supports-ext * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector-list Fixes gh-5177 Closes gh-5178 Ref w3c/csswg-drafts#7280
* Core:Selector: Move jQuery.contains from the selector to the core moduleMichał Gołębiowski-Owczarek2022-12-121-1/+0
| | | | | | | The `jQuery.contains` method is quite simple in jQuery 4+. On the other side, it's a dependency of the core `isAttached` util which is not ideal; moving it from the `selector` the `core` module resolves the issue. Closes gh-5167
* Selector: Drop support for legacy pseudos, test custom pseudosMichał Gołębiowski-Owczarek2022-10-111-21/+2
| | | | | | | | | This backports custom pseudos tests from Sizzle; they were missed in original test backports. Also, the support for legacy custom pseudos has been dropped. The `jQuery.expr` test cleanup has been wrapped in `try-finally` for cleaner test isolation in case anything goes wrong. Closes gh-5137
* Selector: Use jQuery `:has` if `CSS.supports(selector(...))` non-compliantMichał Gołębiowski-Owczarek2022-09-191-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | jQuery has followed the following logic for selector handling for ages: 1. Modify the selector to adhere to scoping rules jQuery mandates. 2. Try `qSA` on the modified selector. If it succeeds, use the results. 3. If `qSA` threw an error, run the jQuery custom traversal instead. It worked fine so far but now CSS has a concept of forgiving selector lists that some selectors like `:is()` & `:has()` use. That means providing unrecognized selectors as parameters to `:is()` & `:has()` no longer throws an error, it will just return no results. That made browsers with native `:has()` support break selectors using jQuery extensions inside, e.g. `:has(:contains("Item"))`. Detecting support for selectors can also be done via: ```js CSS.supports( "selector(SELECTOR_TO_BE_TESTED)" ) ``` which returns a boolean. There was a recent spec change requiring this API to always use non-forgiving parsing: https://github.com/w3c/csswg-drafts/issues/7280#issuecomment-1143852187 However, no browsers have implemented this change so far. To solve this, two changes are being made: 1. In browsers supports the new spec change to `CSS.supports( "selector()" )`, use it before trying `qSA`. 2. Otherwise, add `:has` to the buggy selectors list. Fixes gh-5098 Closes gh-5107 Ref w3c/csswg-drafts#7676
* Docs: Replace `#NUMBER` Trac issue references with `trac-NUMBER`Michał Gołębiowski-Owczarek2022-01-041-4/+7
| | | | | | | | | | | | | The GitHub UI treats `#NUMBER` as referring to its own issues which is confusing when in jQuery source it's usually referring to the old deprecated Trac instance at https://bugs.jquery.com. This change replaces all such Trac references with `trac-NUMBER`. A few of the references came with the Sizzle integration and referred to the Sizzle GitHub bug tracker. Those have been replaced with full links instead. A new entry describing issue reference conventions has been added to README. Closes gh-4993
* CSS: Trim whitespace surrounding CSS Custom Properties valuesfecore12021-09-231-2/+2
| | | | | | | | The spec has recently changed and CSS Custom Properties values are trimmed now. This change makes jQuery polyfill that new behavior for all browsers. Ref w3c/csswg-drafts#774 Fixes gh-4926 Closes gh-4930
* Core: Drop support for Edge Legacy (i.e. non-Chromium Microsoft Edge)Michał Gołębiowski-Owczarek2020-09-221-20/+17
| | | | | | | | | | | | Drop support for Edge Legacy: the non-Chromium, EdgeHTML-based Microsoft Edge version. Also, restrict some workarounds that were applied unconditionally in all browsers to run only in IE now. This slightly increases the size but reduces the performance burden on modern browsers that don't need the workarounds. Also, clean up some comments & remove some obsolete workarounds. Fixes gh-4568 Closes gh-4792
* Build: Correct code indentations based on jQuery Style GuideWonseop Kim2020-05-051-2/+4
| | | | | | | | 1. Correct code indentations based on jQuery Style Guide (contribute.jquery.org/style-guide/js/#spacing). 2. Add rules to "src/.eslintrc.json" to enable "enforcing consistent indentation", with minimal changes to the current code. Closes gh-4672
* Selector: Make empty attribute selectors work in IE againMichał Gołębiowski-Owczarek2019-11-181-3/+1
| | | | | | | | | | qSA in IE 11/Edge often (but not always) don't find elements with an empty name attribute selector (`[name=""]`). Detect that & fall back to Sizzle traversal. Interestingly, IE 10 & older don't seem to have the issue. Fixes gh-4435 Closes gh-4510
* Core: Migrate from AMD to ES modules 🎉Michał Gołębiowski-Owczarek2019-11-181-21/+14
| | | | | | | | | | | | | | | | | | | | | | Migrate all source AMD modules to ECMAScript modules. The final bundle is compiled by a custom build process that uses Rollup under the hood. Test files themselves are still loaded via RequireJS as that has to work in IE 11. Tests can now be run in "Load as modules" mode which replaces the previous "Load with AMD" option. That option of running tests doesn't work in IE and Edge as it requires support for dynamic imports. Some of the changes required by the migration: * check `typeof` of `noGlobal` instead of using the variable directly as it's not available when modules are used * change the nonce module to be an object as ECMASscript module exports are immutable * remove some unused exports * import `./core/parseHTML.js` directly in `jquery.js` so that it's not being cut out when the `ajax` module is excluded in a custom compilation Closes gh-4541
* Docs: Update most URLs to HTTPSMichał Gołębiowski-Owczarek2019-10-211-7/+7
| | | Closes gh-4511
* Selector: Make selectors with leading combinators use qSA againMichał Gołębiowski-Owczarek2019-10-141-1/+4
| | | | | | | | | | | | | | An optimization added in jquery/sizzle#431 skips the temporary IDs for selectors not using child or descendant combinators. For sibling combinators, though, this pushes a selector with a leading combinator to qSA directly which crashes and falls back to a slower Sizzle route. This commit makes selectors with leading combinators not skip the selector rewriting. Note that after jquery/jquery#4454 & jquery/sizzle#453, all modern browsers other than Edge leverage the :scope pseudo-class, avoiding temporary id attributes. Closes gh-4509 Ref jquery/sizzle#431
* Manipulation:Selector: Use the nodeName util where possible to save sizeMichał Gołębiowski-Owczarek2019-10-081-18/+17
| | | | | Saves 20 bytes. Closes gh-4504
* Selector: Use shallow document comparisons to avoid IE/Edge crashesMichał Gołębiowski-Owczarek2019-09-251-13/+24
| | | | | | | | | IE/Edge sometimes crash when comparing documents between frames using the strict equality operator (`===` & `!==`). Funnily enough, shallow comparisons (`==` & `!=`) work without crashing. Fixes gh-4441 Closes gh-4471
* Core: Remove private copies of push, sort & splice from the jQuery prototypeMichał Gołębiowski-Owczarek2019-09-241-3/+3
| | | Closes gh-4473
* Selector: reduce size, simplify setDocumentMichał Gołębiowski-Owczarek2019-08-261-128/+82
| | | | | | | | | | | With new selector code doing less convoluted support tests, it was possible to extract a lot of logic out of setDocument & also reduce size. This commit also backports jquery/sizzle#439 that was reverted by mistake during a switch from JSHint + JSCS to ESLint. Closes gh-4462 Ref jquery/sizzle#442 Ref jquery/sizzle#439
* Selector: Leverage the :scope pseudo-class where possibleMichał Gołębiowski-Owczarek2019-08-191-11/+18
| | | | | | | | | | | | | | | | | | | The `:scope` pseudo-class[1] has surprisingly good browser support: Chrome, Firefox & Safari have supported if for a long time; only IE & Edge lack support. This commit leverages this pseudo-class to get rid of the ID hack in most cases. Adding a temporary ID may cause layout thrashing which was reported a few times in [the past. We can't completely eliminate the ID hack in modern browses as sibling selectors require us to change context to the parent and then `:scope` stops applying to what we'd like. But it'd still improve performance in the vast majority of cases. [1] https://developer.mozilla.org/en-US/docs/Web/CSS/:scope Fixes gh-4453 Closes gh-4454 Ref gh-4332 Ref jquery/sizzle#405
* Selector: Bring back querySelectorAll shortcut usageMichał Gołębiowski-Owczarek2019-08-091-2/+1
| | | | | | | Due to a faulty IE 8 workaround removal, the fast path qSA mode was skipped when jQuery's find was called on an element node - i.e. in most cases. 😱 Ref gh-4395 Closes gh-4452
* Selector: Inline Sizzle into the selector moduleMichał Gołębiowski-Owczarek2019-07-291-2/+1672
| | | | | | | | | | | | | | | | | | This commit removes Sizzle from jQuery, inlining its code & removing obsolete workarounds where applicable. The selector-native module has been removed. Further work on the selector module may decrease the size enough that it will no longer be necessary. If it turns out it's still useful, we'll reinstate it but the code will look different anyway as we'll want to share as much code as possible with the existing selector module. The Sizzle AUTHORS.txt file has been merged with the jQuery one - people are sorted by their first contributions to either of the two repositories. The commit reduces the gzipped jQuery size by 1460 bytes compared to master. Closes gh-4395
* Build: ESLint detailsOleg Gaidarenko2016-06-111-1/+3
| | | | | | Use eslint pragmas, fix new errors, etc Closes gh-3148
* Build: Update jscs and lint filesOleg Gaidarenko2015-09-071-1/+1
| | | | Fixes gh-2056
* Core: Follow the AMD specification for defineAlexander O'Mara2015-04-131-1/+1
| | | | | | AMD specification requires the factory argument be defined. Close gh-2179
* No ticket. Restore checking individual src/**/*.js files by jsHint.Michał Gołębiowski2013-09-061-1/+1
|
* AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.Timmy Willison2013-08-151-0/+1
|
* Pull in the Sizzle library dynamically using a submodule and make it part of ↵John Resig2009-10-261-1007/+0
| | | | the jQuery build process.
* Moved a bunch of methods out of the jQuery-specific Sizzle code into ↵John Resig2009-10-261-61/+0
| | | | more-appropriate files, in jQuery itself.
* A follow-up to [6578] (which stopped adding expandos to elements that didn't ↵John Resig2009-09-251-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | have data). That broke jQuery.unique() (so we're now using the unique from Sizzle). Using Sizzle's unique (which also sorts in document order) changed how add, andSelf, parents, nextAll, prevAll, and siblings work. after and before were changed to not use .add() (in order to guarantee their position in the jQuery set). Also, jQuery.data(elem) was updated to return that element's data object (instead of its ID). $("<div/>").after("<span/>") => [ div, span ] (calling after on a disconnected DOM node adds the nodes to the end of the jQuery set) $("<div/>").before("<span/>") => [ span, div ] (calling before on a disconnected DOM node adds the nodes to the beginning of the jQuery set) $("div").add("span") => [ div, span, span, div, span ] (results now come out in document order) $("div").find("code").andSelf(); => [ div, code, code ] (results now come out in document order) Same goes for .parents(), .nextAll(), .prevAll(), and .siblings(). Exception: .parents() will still return the results in reverse document order. jQuery.data(elem) => { object of data } (no longer returns the unique ID assigned to the node)
* Missing a var on a for loop, caused a variable to be leaked.John Resig2009-09-151-1/+1
|
* Missing a var on a for loop, caused a variable to be leaked.John Resig2009-09-151-1/+1
|
* fixed global variables introduced in for loop with missing var-keyword ↵Jörn Zaefferer2009-09-151-1/+1
| | | | (detected via QUnit's no ?noglobals)
* Make sure that at least one argument is provided to .slice(), in accordance ↵John Resig2009-07-231-2/+2
| | | | with the spec. Fixes jQuery bug #4942.
* Standardize on using .nodeName in place of .tagName. Fixes jQuery bug #4923.John Resig2009-07-191-1/+1
|
* Standardizing on .test() and .exec() - moving away from using .match() for ↵John Resig2009-07-191-3/+3
| | | | RegExp. Fixes jQuery bug #4113.
* reverting sizzle updates from previous commit, appears i had an outdated versionBrandon Aaron2009-06-231-3/+3
|
* fix for #4512 and minor sizzle updatesBrandon Aaron2009-06-231-14/+10
|
* Removed some cases of strict errors.John Resig2009-05-201-3/+3
|
* fix :hidden and :visible selectors. fixes #4512Brandon Aaron2009-05-181-2/+12
|
* fix :hidden selector that was accidentally reverted in previous commit, also ↵Brandon Aaron2009-05-041-1/+1
| | | | fixed tests for :hidden selector in IE6
* fix memory leak in IEBrandon Aaron2009-05-041-16/+24
|
* remove trailing spacesBrandon Aaron2009-03-231-14/+14
|
* fix for #4374, gap in :hidden, :visible logicBrandon Aaron2009-03-181-1/+1
|
* Backed out commit [6260], was causing too many problems. We'll have to bite ↵John Resig2009-03-171-12/+9
| | | | the bullet and assume that the incoming result set has array methods. Un-fixes jQuery bug #4250.
* Moved to a generic solution for copying methods over for ↵John Resig2009-02-271-4/+3
| | | | querySelectorAll-using browsers.