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