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

Minified JS overestimates savings when esprima fails #5723

Closed
RonnieWinter opened this issue Jul 25, 2018 · 3 comments · Fixed by #5925
Closed

Minified JS overestimates savings when esprima fails #5723

RonnieWinter opened this issue Jul 25, 2018 · 3 comments · Fixed by #5925
Assignees

Comments

@RonnieWinter
Copy link

RonnieWinter commented Jul 25, 2018

Provide the steps to reproduce

When running lighthouse tests against our AMP pages we noticed that one of the js scripts shows up on the report as not being minified. The issue is on this file: https://cdn.ampproject.org/v0/amp-date-picker-0.1.js
This is because that file contains a copyright noticed that is hard coded into the minified javascript file, which contains carriage returns and whitespace.
I opened an issue in the AMPHTML repository asking if they could minify the copyright notice, but they said that they cannot change it and that the problem lies with Lighthouse being too picky.

For more information this is the issue I opened in the AMPHTML repository: Issue 17077

Environment Information

  • Affected Channels: CLI, Node, Extension, DevTools
  • Lighthouse version: 3.0.1
  • Operating System: All
    screen shot 2018-07-25 at 11 26 51
@patrickhulce
Copy link
Collaborator

Thanks for reporting @ro2ni3! This definitely seems like a bug. The copyright notices should definitely not be ~97% savings on the file we're saying :) We'll take a closer look

@patrickhulce
Copy link
Collaborator

Turns out this is a bug in esprima which we use to tokenize the JS. It seems to erroneously think the snippet from line 54 of that file (reproduced below) has an illegal token (though oddly when invoking esprima.parse it is able to handle it correctly)

if (-1 !== d.indexOf(","))
  for (d = d.split(","), k = 0; k < d.length; k++)
    /* fails on this regex here --> */ /^[+-]?\d+$/.test(d[k]) && (d[k] = Number(d[k]));

because LH uses tolerant mode, it reports what it was able to parse which is the first 3% of the file hence 97% savings :)

@patrickhulce patrickhulce changed the title Minified js with multiline copyright fails minification check. Minified JS overestimates savings when esprima fails Jul 25, 2018
@paulirish
Copy link
Member

basically esprima sucks with regex sometimes. we use tolerant because of that

options:

  1. switch from esprima to acorn or something else
  2. turn back off tolerant, and deal with the errors (airhorner, etc)
  3. fix this upstream in esprima? :/

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

Successfully merging a pull request may close this issue.

3 participants