-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
report: use source maps to show original file name #10930
Changes from 4 commits
25493dd
15009ae
cfd62ed
d61abda
f22bd04
5cd23f8
832ceca
7af5053
9ceca12
3feb713
16b7771
c63b65e
0fbf2fc
e853c83
49d19be
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 | ||||
---|---|---|---|---|---|---|
|
@@ -137,7 +137,7 @@ class DetailsRenderer { | |||||
|
||||||
/** | ||||||
* @param {{text: string, url: string}} details | ||||||
* @return {Element} | ||||||
* @return {HTMLElement} | ||||||
*/ | ||||||
_renderLink(details) { | ||||||
const allowedProtocols = ['https:', 'http:']; | ||||||
|
@@ -539,24 +539,57 @@ class DetailsRenderer { | |||||
return null; | ||||||
} | ||||||
|
||||||
/** @param {HTMLElement} el */ | ||||||
function addDevToolsData(el) { | ||||||
el.classList.add('lh-source-location'); | ||||||
el.setAttribute('data-source-url', item.url); | ||||||
// DevTools expects zero-indexed lines. | ||||||
el.setAttribute('data-source-line', String(item.line)); | ||||||
el.setAttribute('data-source-column', String(item.column)); | ||||||
return el; | ||||||
} | ||||||
|
||||||
// Lines are shown as one-indexed. | ||||||
const line = item.line + 1; | ||||||
const column = item.column; | ||||||
const line = (item.original ? item.original.line : item.line) + 1; | ||||||
const column = item.original ? item.original.column : item.column; | ||||||
|
||||||
let element; | ||||||
const file = item.original && item.original.file || '<unmapped>'; | ||||||
const originalLocation = item.original && `${file}:${line}:${column}`; | ||||||
const generatedLocation = `${item.url}:${line}:${column}`; | ||||||
|
||||||
// First two cases: url is from network. | ||||||
if (item.urlProvider === 'network') { | ||||||
element = this.renderTextURL(item.url); | ||||||
this._dom.find('a', element).textContent += `:${line}:${column}`; | ||||||
let element; | ||||||
if (originalLocation) { | ||||||
element = this._renderLink({ | ||||||
url: item.url, | ||||||
text: originalLocation, | ||||||
}); | ||||||
element.title = | ||||||
`Location ${generatedLocation} maps to original location ${originalLocation}`; | ||||||
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. noted about this being too long.. since the text on display is now the
Suggested change
|
||||||
} else { | ||||||
element = this.renderTextURL(item.url); | ||||||
this._dom.find('a', element).textContent += `:${line}:${column}`; | ||||||
} | ||||||
|
||||||
return addDevToolsData(element); | ||||||
} | ||||||
|
||||||
// Two cases remain: | ||||||
// 1) urlProvider === 'comment' && item.original | ||||||
// -> Show the source filename in text, source mapped URL in tooltip. | ||||||
// 2) urlProvider === 'comment' && !item.original | ||||||
// -> Show the source mapped URL. | ||||||
|
||||||
let element; | ||||||
if (originalLocation) { | ||||||
element = this._renderText(`${originalLocation} (from source map)`); | ||||||
element.title = `${generatedLocation} (from sourceURL)`; | ||||||
} else { | ||||||
element = this._renderText(`${item.url}:${line}:${column} (from sourceURL)`); | ||||||
element = this._renderText(`${generatedLocation} (from sourceURL)`); | ||||||
} | ||||||
|
||||||
element.classList.add('lh-source-location'); | ||||||
element.setAttribute('data-source-url', item.url); | ||||||
// DevTools expects zero-indexed lines. | ||||||
element.setAttribute('data-source-line', String(item.line)); | ||||||
element.setAttribute('data-source-column', String(item.column)); | ||||||
return element; | ||||||
return addDevToolsData(element); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -224,6 +224,13 @@ declare global { | |||||
urlProvider: 'network' | 'comment'; | ||||||
line: number; | ||||||
column: number; | ||||||
/** The original file location from the source map. */ | ||||||
original?: { | ||||||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/** The associate file from the map's `sources` array. If missing, could not associate mapping with a specific file ("unmapped" in other tools). */ | ||||||
file?: string; | ||||||
line: number; | ||||||
column: number; | ||||||
}; | ||||||
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... do you know what's up with this comment? lighthouse/types/audit-details.d.ts Line 221 in 40baa22
" urls from the network are always valid urls" vs "urls [...] may not be well-formed" 🤔 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. You can put absolutely anything in a soruceMappingURL comment or the associated header. Treating this user input as a well-formed URL is error prone. In some cases the protocol hides the true resource (network) url from us, if there is a comment url present. see
so we must have a distinction between these two sources of "url", which is what |
||||||
} | ||||||
|
||||||
/** | ||||||
|
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.
it seems like there's gotta be a better way to structure these conditionals.
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.
There are certainly different ways to structure this. I went with handling one "provider" at a time. What other way would be simpler?
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.
you have four cases. i figure just an
if else
handling all those.plus they all get addDevToolsData so that you can just return once.
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.
this is much better thx