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

Incorrect const A declaration after a class B extends A is moved and becomes unnamed during minification #627

Closed
goto-bus-stop opened this issue Mar 31, 2020 · 5 comments

Comments

@goto-bus-stop
Copy link
Contributor

goto-bus-stop commented Mar 31, 2020

Bug report or Feature request?
Bug report.

Version (complete output of terser -V or specific git commit)

terser 4.6.9

According to git bisect, this regressed in 0e40b8d.

Complete CLI command or minify() options used

terser input.js --compress --beautify

terser input

(function () {
    const HtmlContent = require('./html-content.js')
    class BreadcrumbPanel extends HtmlContent {}
    module.exports = BreadcrumbPanel
}())

From my tests, it seems to only happen with a combination of factors:

  • The HtmlContent variable is used in a class's extends node
  • The class that it is used in (BreadcrumbPanel) is named
  • The class that it is used in (BreadcrumbPanel) becomes anonymous during minification, and/or the class that it is used in is moved during minification (to module.exports = class {})

For example, using the HtmlContent value in these patterns do not have this bug:

console.log(HtmlContent)
const BreadcrumbPanel = class extends HtmlContent {}
module.exports = class BreadcrumbPanel extends HtmlContent {}

terser output or error
The initializer is separated from the const declaration by a semicolon, which is invalid:

!function() {
    const HtmlContent;
    require("./html-content.js");
    module.exports = class extends HtmlContent {};
}();

Expected result

!function() {
    const HtmlContent = require("./html-content.js");
    module.exports = class extends HtmlContent {};
}();
@fabiosantoscode
Copy link
Collaborator

Nasty! I'll have a look right away.

@200Puls
Copy link

200Puls commented Mar 31, 2020

I think I encountered the same issue. This happens since 4.6.8.

Chrome Console says: Uncaught SyntaxError: Missing initializer in const declaration

{const e;Wt(t);return class extends e{

I havent looked up the source as it occurs in a library I use (Polymer)

@goto-bus-stop
Copy link
Contributor Author

That does the trick 🎉 Thanks for the quick fix @fabiosantoscode!

@fabiosantoscode
Copy link
Collaborator

I'm waiting for the functional tests to ship 4.6.10

@Haprog
Copy link

Haprog commented Mar 31, 2020

Thanks a lot for the quick fix!

goto-bus-stop referenced this issue in clinicjs/node-clinic-doctor Jun 8, 2020
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

4 participants