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

After using minify to compress JS, the code reports an error: uncaught syntax error: unexpected token ' #339

Closed
LiuJun0 opened this issue Oct 15, 2020 · 1 comment

Comments

@LiuJun0
Copy link

LiuJun0 commented Oct 15, 2020

chrome console error

Uncaught SyntaxError: Unexpected token '.'
app.f08b896.js:1 Error: Loading chunk 3 failed.
    at HTMLScriptElement.i (manifest.7941de6.js:1)

After compress Error code

f>.e-9&&(a.width+=b/f,a.height+=b/f,a.x-=b/f/2,a.y-=b/f/2)),a):c}

I use nodejs uglifyjs, which has no errors

I found the source code and tested compression

function test() {
    var m = this.transform; // Get the line scale.
    // Determinant of `m` means how much the area is enlarged by the
    // transformation. So its square root can be used as a scale factor
    // for width.

    return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10 ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1])) : 1;
}

After compression

function test(){var m=this.transform;return m&&abs(m[0]-1)>.e-9&&abs(m[3]-1)>.e-9?Math.sqrt(abs(m[0]*m[3]-m[2]*m[1])):1}
@tdewolff
Copy link
Owner

tdewolff commented Oct 15, 2020

That is an embarrassing bug that has been in there for a long time. The test can be compressed to 1e-10 which invalidly in minified to .e-9. I will fix this ASAP, thank you for the report!

To be clear, this bug only applied to the specific number 1e-10 but also to 1e-100, 1e-1000 etc., any other numbers such as 1e-9 and 1e-11 were fine. There is also a test that generates random numbers (10.000 for every commit), minifies them, and checks whether the same number is outputted, but by chance it hasn't been able to detect this bug so far. Bad luck! But embarrassing nonetheless.

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

No branches or pull requests

2 participants