-
Notifications
You must be signed in to change notification settings - Fork 244
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
fmigrate to htmlparser2 #576
Conversation
87eea80
to
972d4eb
Compare
* no more monkey patching the node model * better compatibility with other tools relying on the htmlparser2 API * smaller output files as `=""` is no longer rendered * faster (not sure yet how much)
972d4eb
to
d60b748
Compare
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.
May be worth double checking one instance of calling html.firstChildByTag('head')
, instead of firstChildByTag(html, 'head')
. I didn't see it in other places throughout the code, so I'm wondering if it's actually wrong.
Otherwise, just a few nits.
@@ -64,7 +64,7 @@ async function customAmpTransformation(filePath, html) { | |||
} | |||
transform(tree, params) { | |||
this.log_.info('Running custom transformation for ', params.filePath); | |||
const html = tree.root.firstChildByTag('html'); | |||
const html = firstChildByTag(tree, 'html'); |
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.
nit: I do prefer firstChildByTag(tree, 'html')
instead of tree.root.firstChildByTag('html')
. I wonder if we could have tree.firstChildByTab('html')
, similar to the call on line 69.
'use strict'; | ||
|
||
const {Element, DataNode} = require('domhandler'); | ||
const domUtils = require('domutils'); |
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.
We're requiring the entire domutils
here and then a few selected methods below. Do we need both?
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's to avoid a name conflict
@@ -64,7 +64,7 @@ async function customAmpTransformation(filePath, html) { | |||
} | |||
transform(tree, params) { | |||
this.log_.info('Running custom transformation for ', params.filePath); | |||
const html = tree.root.firstChildByTag('html'); | |||
const html = firstChildByTag(tree, 'html'); | |||
if (!html) return; | |||
const head = html.firstChildByTag('head'); |
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.
I think this is the only place firstChildByTag is being used in this format. Wondering if this is actually wrong?
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.
yup, wrong
img.attribs.src = src; | ||
img.attribs.alt = ''; | ||
async addBlurryPlaceholder_(src) { | ||
const img = createElement('img', { |
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 syntax is nicer!
try { | ||
expectedOutput = getFileContents(expectedOutputPath); | ||
} catch (e) { | ||
// no snapshot written yet |
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.
nit: I don't really understand what this comment means. Maybe it's worth explaining more?
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.
done
@andreban PTAL |
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.
LGTM, Thank you!
=""
is no longer rendered