@@ -135,11 +135,11 @@ export const ParentNodePatches = utils.getOwnPropertyDescriptors({
135
135
*
136
136
* See <./logicalQuerySelectorAll.md> for implementation details.
137
137
*
138
- * @param {!Element } contextElement
138
+ * @param {!ParentNode } contextNode
139
139
* @param {string } selectorList
140
140
* @return {!Array<!Element> }
141
141
*/
142
- const logicalQuerySelectorAll = ( contextElement , selectorList ) => {
142
+ const logicalQuerySelectorAll = ( contextNode , selectorList ) => {
143
143
/**
144
144
* @type {!Array<!ComplexSelectorParts> }
145
145
*/
@@ -152,16 +152,15 @@ const logicalQuerySelectorAll = (contextElement, selectorList) => {
152
152
/**
153
153
* Determines if a single compound selector matches an element. If the
154
154
* selector contains `:scope` (as a substring), then the selector only is only
155
- * considered matching if `element` is `contextElement `.
155
+ * considered matching if `element` is `contextNode `.
156
156
*
157
157
* @param {!Element } element
158
158
* @param {string } compoundSelector
159
159
* @return {boolean }
160
160
*/
161
161
const matchesCompoundSelector = ( element , compoundSelector ) => {
162
162
return (
163
- ( element === contextElement ||
164
- compoundSelector . indexOf ( ':scope' ) === - 1 ) &&
163
+ ( element === contextNode || compoundSelector . indexOf ( ':scope' ) === - 1 ) &&
165
164
utils . matchesSelector ( element , compoundSelector )
166
165
) ;
167
166
} ;
@@ -192,13 +191,13 @@ const logicalQuerySelectorAll = (contextElement, selectorList) => {
192
191
193
192
/**
194
193
* The list of `SelectorMatchingCursor`s, initialized with cursors pointing at
195
- * all descendants of `contextElement ` that match the last compound selector
196
- * in any complex selector in `selectorList`.
194
+ * all descendants of `contextNode ` that match the last compound selector in
195
+ * any complex selector in `selectorList`.
197
196
*
198
197
* @type {!Array<!SelectorMatchingCursor> }
199
198
*/
200
199
let cursors = utils . flat (
201
- query ( contextElement , ( _element ) => true ) . map ( ( element ) => {
200
+ query ( contextNode , ( _element ) => true ) . map ( ( element ) => {
202
201
return utils . flat (
203
202
complexSelectors . map ( ( complexSelectorParts ) => {
204
203
const { compoundSelectors} = complexSelectorParts ;
@@ -342,13 +341,16 @@ const querySelectorImplementation =
342
341
343
342
export const QueryPatches = utils . getOwnPropertyDescriptors ( {
344
343
/**
345
- * @this {Element }
346
- * @param {string } selector
344
+ * @this {!ParentNode }
345
+ * @param {string } selector
347
346
*/
348
347
querySelector ( selector ) {
349
348
if ( querySelectorImplementation === 'native' ) {
350
349
// Polyfilled `ShadowRoot`s don't have a native `querySelectorAll`.
351
- const target = this instanceof ShadowRoot ? this . host : this ;
350
+ const target =
351
+ this instanceof ShadowRoot
352
+ ? /** @type {!ShadowRoot } */ ( this ) . host
353
+ : this ;
352
354
const candidates = Array . prototype . slice . call (
353
355
target [ utils . NATIVE_PREFIX + 'querySelectorAll' ] ( selector )
354
356
) ;
@@ -383,17 +385,20 @@ export const QueryPatches = utils.getOwnPropertyDescriptors({
383
385
} ,
384
386
385
387
/**
386
- * @this {Element }
387
- * @param {string } selector
388
- * @param {boolean } useNative
388
+ * @this {!ParentNode }
389
+ * @param {string } selector
390
+ * @param {boolean } useNative
389
391
*/
390
392
// TODO(sorvell): `useNative` option relies on native querySelectorAll and
391
393
// misses distributed nodes, see
392
394
// https://github.com/webcomponents/shadydom/pull/210#issuecomment-361435503
393
395
querySelectorAll ( selector , useNative ) {
394
396
if ( useNative || querySelectorImplementation === 'native' ) {
395
397
// Polyfilled `ShadowRoot`s don't have a native `querySelectorAll`.
396
- const target = this instanceof ShadowRoot ? this . host : this ;
398
+ const target =
399
+ this instanceof ShadowRoot
400
+ ? /** @type {!ShadowRoot } */ ( this ) . host
401
+ : this ;
397
402
const candidates = Array . prototype . slice . call (
398
403
target [ utils . NATIVE_PREFIX + 'querySelectorAll' ] ( selector )
399
404
) ;
0 commit comments