Skip to content

Commit 9526441

Browse files
committed
Fix Closure types for internal conformance checks.
1 parent 4756d22 commit 9526441

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

packages/shadydom/src/patches/ParentNode.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ export const ParentNodePatches = utils.getOwnPropertyDescriptors({
135135
*
136136
* See <./logicalQuerySelectorAll.md> for implementation details.
137137
*
138-
* @param {!Element} contextElement
138+
* @param {!ParentNode} contextNode
139139
* @param {string} selectorList
140140
* @return {!Array<!Element>}
141141
*/
142-
const logicalQuerySelectorAll = (contextElement, selectorList) => {
142+
const logicalQuerySelectorAll = (contextNode, selectorList) => {
143143
/**
144144
* @type {!Array<!ComplexSelectorParts>}
145145
*/
@@ -152,16 +152,15 @@ const logicalQuerySelectorAll = (contextElement, selectorList) => {
152152
/**
153153
* Determines if a single compound selector matches an element. If the
154154
* 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`.
156156
*
157157
* @param {!Element} element
158158
* @param {string} compoundSelector
159159
* @return {boolean}
160160
*/
161161
const matchesCompoundSelector = (element, compoundSelector) => {
162162
return (
163-
(element === contextElement ||
164-
compoundSelector.indexOf(':scope') === -1) &&
163+
(element === contextNode || compoundSelector.indexOf(':scope') === -1) &&
165164
utils.matchesSelector(element, compoundSelector)
166165
);
167166
};
@@ -192,13 +191,13 @@ const logicalQuerySelectorAll = (contextElement, selectorList) => {
192191

193192
/**
194193
* 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`.
197196
*
198197
* @type {!Array<!SelectorMatchingCursor>}
199198
*/
200199
let cursors = utils.flat(
201-
query(contextElement, (_element) => true).map((element) => {
200+
query(contextNode, (_element) => true).map((element) => {
202201
return utils.flat(
203202
complexSelectors.map((complexSelectorParts) => {
204203
const {compoundSelectors} = complexSelectorParts;
@@ -342,13 +341,16 @@ const querySelectorImplementation =
342341

343342
export const QueryPatches = utils.getOwnPropertyDescriptors({
344343
/**
345-
* @this {Element}
346-
* @param {string} selector
344+
* @this {!ParentNode}
345+
* @param {string} selector
347346
*/
348347
querySelector(selector) {
349348
if (querySelectorImplementation === 'native') {
350349
// 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;
352354
const candidates = Array.prototype.slice.call(
353355
target[utils.NATIVE_PREFIX + 'querySelectorAll'](selector)
354356
);
@@ -383,17 +385,20 @@ export const QueryPatches = utils.getOwnPropertyDescriptors({
383385
},
384386

385387
/**
386-
* @this {Element}
387-
* @param {string} selector
388-
* @param {boolean} useNative
388+
* @this {!ParentNode}
389+
* @param {string} selector
390+
* @param {boolean} useNative
389391
*/
390392
// TODO(sorvell): `useNative` option relies on native querySelectorAll and
391393
// misses distributed nodes, see
392394
// https://github.com/webcomponents/shadydom/pull/210#issuecomment-361435503
393395
querySelectorAll(selector, useNative) {
394396
if (useNative || querySelectorImplementation === 'native') {
395397
// 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;
397402
const candidates = Array.prototype.slice.call(
398403
target[utils.NATIVE_PREFIX + 'querySelectorAll'](selector)
399404
);

0 commit comments

Comments
 (0)