Skip to content
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

Merged
merged 8 commits into from
Jan 22, 2020
Merged

fmigrate to htmlparser2 #576

merged 8 commits into from
Jan 22, 2020

Conversation

sebastianbenz
Copy link
Collaborator

  • 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)

@sebastianbenz sebastianbenz force-pushed the htmlparser2 branch 3 times, most recently from 87eea80 to 972d4eb Compare January 20, 2020 22:09
* 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)
Copy link
Member

@andreban andreban left a 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');
Copy link
Member

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');
Copy link
Member

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?

Copy link
Collaborator Author

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');
Copy link
Member

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?

Copy link
Collaborator Author

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', {
Copy link
Member

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
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sebastianbenz
Copy link
Collaborator Author

@andreban PTAL

Copy link
Member

@andreban andreban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants