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

core(minification): properly handle regex character classes #6745

Merged
merged 4 commits into from
Dec 7, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Dec 7, 2018

Summary
The minification estimator heuristics weren't accounting for regex character classes properly which meant that it could leave a regex prematurely.

Related Issues/PRs
fixes #6744

} else if (char === '[') {
// Register that we're entering a character class so we don't leave the regex prematurely
isInRegexCharacterClass = true;
} else if (char === ']') {
Copy link
Member

Choose a reason for hiding this comment

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

should the condition also check that isInRegexCharacterClass is true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

shouldn't affect the execution but it's definitely a lot more clear :) 👍 done

@connorjclark
Copy link
Collaborator

connorjclark commented Dec 7, 2018

Two tangential things:

  1. I noticed strings don't get parsed correctly so I made Minification audit early exits on string interpolation #6746
  2. Chrome autocorrect thinks minification should be "magnification"! Almost got me in the making of the above ticket, and it got Patrick in the original post :P

image

@patrickhulce
Copy link
Collaborator Author

I noticed strings don't get parsed correctly so I made #6746

sigh 😞, I don't think we'll ever nail all the edge cases. I'm thinking we might want to do a second gut check of, "Hey if it thinks there's a crazy amount of savings when there's like no whitespace in this file, we should just ignore it's result"

Chrome autocorrect thinks minification should be "magnification"! Almost got me in the making of the above ticket, and I got Patrick in the original post :P

😆 hahaha it totally did

Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

Nice changes to a weird edge case! But the regex tests are confusing me a bit, they are a little opaque as to what they are testing. I think I need more comments on the case it is testing or clarifications on why my comments are unfounded.

Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

Gotcha, the string escaping was throwing me for a loop, thx for the comments. LGTM

@patrickhulce patrickhulce merged commit 95b084b into master Dec 7, 2018
@patrickhulce patrickhulce deleted the fix_minification_estimator branch December 7, 2018 20:22
mattzeunert pushed a commit to kdzwinel/lighthouse that referenced this pull request Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minification estimation erroneously reports very large savings
4 participants