-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
misc: use typed-query-selector for native querySelector #11990
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,7 @@ class CategoryRenderer { | |
/** | ||
* @param {LH.ReportResult.Category} category | ||
* @param {Record<string, LH.Result.ReportGroup>} groupDefinitions | ||
* @return {Element} | ||
* @return {DocumentFragment} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this just remain Element? I don't see benefit in making the return type more specific. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It would be a |
||
*/ | ||
renderCategoryHeader(category, groupDefinitions) { | ||
const tmpl = this.dom.cloneTemplate('#tmpl-lh-category-header', this.templateContext); | ||
|
@@ -184,7 +184,7 @@ class CategoryRenderer { | |
this.dom.find('.lh-category-header__description', tmpl).appendChild(descEl); | ||
} | ||
|
||
return /** @type {Element} */ (tmpl.firstElementChild); | ||
return tmpl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a |
||
} | ||
|
||
/** | ||
|
@@ -336,8 +336,7 @@ class CategoryRenderer { | |
// Cast `null` to 0 | ||
const numericScore = Number(category.score); | ||
const gauge = this.dom.find('.lh-gauge', tmpl); | ||
/** @type {?SVGCircleElement} */ | ||
const gaugeArc = gauge.querySelector('.lh-gauge-arc'); | ||
const gaugeArc = this.dom.find('circle.lh-gauge-arc', gauge); | ||
|
||
if (gaugeArc) this._setGaugeArc(gaugeArc, numericScore); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,8 +238,7 @@ class ReportUIFeatures { | |
]; | ||
|
||
// Get all tables with a text url column. | ||
/** @type {Array<HTMLTableElement>} */ | ||
const tables = Array.from(this._document.querySelectorAll('.lh-table')); | ||
const tables = Array.from(this._document.querySelectorAll('table.lh-table')); | ||
const tablesWithUrls = tables | ||
.filter(el => | ||
el.querySelector('td.lh-table-column--url, td.lh-table-column--source-location')) | ||
|
@@ -335,8 +334,7 @@ class ReportUIFeatures { | |
for (const rowEl of rowEls) { | ||
if (rowEl.classList.contains('lh-sub-item-row')) continue; | ||
|
||
/** @type {HTMLElement|null} */ | ||
const urlItem = rowEl.querySelector('.lh-text__url'); | ||
const urlItem = rowEl.querySelector('div.lh-text__url'); | ||
if (!urlItem) continue; | ||
|
||
const datasetUrl = urlItem.dataset.url; | ||
|
@@ -834,11 +832,11 @@ class DropDown { | |
|
||
/** | ||
* @param {Array<Node>} allNodes | ||
* @param {?Node=} startNode | ||
* @returns {Node} | ||
* @param {?HTMLElement=} startNode | ||
* @returns {HTMLElement} | ||
*/ | ||
_getNextSelectableNode(allNodes, startNode) { | ||
const nodes = allNodes.filter((node) => { | ||
const nodes = allNodes.filter(/** @return {node is HTMLElement} */ (node) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also not |
||
if (!(node instanceof HTMLElement)) { | ||
return false; | ||
} | ||
|
@@ -865,21 +863,21 @@ class DropDown { | |
} | ||
|
||
/** | ||
* @param {?Element=} startEl | ||
* @param {?HTMLElement=} startEl | ||
* @returns {HTMLElement} | ||
*/ | ||
_getNextMenuItem(startEl) { | ||
const nodes = Array.from(this._menuEl.childNodes); | ||
return /** @type {HTMLElement} */ (this._getNextSelectableNode(nodes, startEl)); | ||
return this._getNextSelectableNode(nodes, startEl); | ||
} | ||
|
||
/** | ||
* @param {?Element=} startEl | ||
* @param {?HTMLElement=} startEl | ||
* @returns {HTMLElement} | ||
*/ | ||
_getPreviousMenuItem(startEl) { | ||
const nodes = Array.from(this._menuEl.childNodes).reverse(); | ||
return /** @type {HTMLElement} */ (this._getNextSelectableNode(nodes, startEl)); | ||
return this._getNextSelectableNode(nodes, startEl); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,11 @@ | |
/** | ||
* Guaranteed context.querySelector. Always returns an element or throws if | ||
* nothing matches query. | ||
* @param {string} query | ||
* @template {string} T | ||
* @param {T} query | ||
* @param {ParentNode} context | ||
* @return {HTMLElement} | ||
*/ | ||
function find(query, context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we apparently have four copies of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. soon to be 5 with #11832 I often copy |
||
/** @type {?HTMLElement} */ | ||
const result = context.querySelector(query); | ||
if (result === null) { | ||
throw new Error(`query ${query} not found`); | ||
|
@@ -67,7 +66,7 @@ class LighthouseReportViewer { | |
gistUrlInput.addEventListener('change', this._onUrlInputChange); | ||
|
||
// Hidden file input to trigger manual file selector. | ||
const fileInput = find('#hidden-file-input', document); | ||
const fileInput = find('input#hidden-file-input', document); | ||
fileInput.addEventListener('change', e => { | ||
if (!e.target) { | ||
return; | ||
|
@@ -283,8 +282,7 @@ class LighthouseReportViewer { | |
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onload = function(e) { | ||
const readerTarget = /** @type {?FileReader} */ (e.target); | ||
const result = /** @type {?string} */ (readerTarget && readerTarget.result); | ||
const result = /** @type {?string} */ (e.target && e.target.result); | ||
if (!result) { | ||
reject('Could not read file'); | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing the lines in this file is real nice