MCPcopy
hub / github.com/ampproject/amphtml / selectorNeedsScope

Function selectorNeedsScope

build-system/eslint-rules/query-selector.js:207–218  ·  view source on GitHub ↗

* Checks if the selector is using grandchild selector semantics * `node.querySelector('child grandchild')` or `'child>grandchild'` But, * specifically allow multi-selectors `'div, span'`. * @param {string} selector * @return {boolean}

(selector)

Source from the content-addressed store, hash-verified

205 * @return {boolean}
206 */
207 function selectorNeedsScope(selector) {
208 // strip out things that can't affect children selection
209 selector = selector.replace(/\(.*\)|\[.*\]/, function (match) {
210 return match[0] + match[match.length - 1];
211 });
212
213 // This regex actually verifies there is no whitespace (implicit child
214 // semantics) or `>` chars (direct child semantics). The one exception is
215 // for `,` multi-selectors, which can have whitespace.
216 const noChildSemantics = /^(\s*,\s*|(?!\s|>).)*$/.test(selector);
217 return !noChildSemantics;
218 }
219
220 return {
221 CallExpression(node) {

Callers 2

callQuerySelectorFunction · 0.85
callScopedQuerySelectorFunction · 0.85

Calls 2

replaceMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected