mike-lischke / antlr4ng

Next Generation TypeScript runtime for ANTLR4
Other
66 stars 11 forks source link

Terser produces incorrect code after compression #31

Closed nashbridges closed 5 months ago

nashbridges commented 5 months ago

We found that after importing antlr4ng into our project the resulting bundle becomes invalid. The error is quite cryptic

TypeError: Cannot read properties of undefined (reading 'Symbol(immer-state)')

We use redux toolkit (and therefore - immerjs) on the project, but the stacktrace somehow points to

var Gt = class o {
  static DEFAULT = new o; // <--this line
  walk(e, t) {
    if (t instanceof Q)
      e.visitErrorNode(t);
    else if (t instanceof F)
      e.visitTerminal(t);
    else {
      let n = t;
      this.enterRule(e, n);
      for (let i = 0; i < t.getChildCount(); i++)
        this.walk(e, t.getChild(i));
      this.exitRule(e, n)
    }
  }

which is the ParseTreeWalker.

To fix it we had to disable "compress -> unused" option from Terser.

So clearly there's something special about the library it confuses the Terser. We tried to produce it on a clean repo, but with no luck.

I do believe this is a Terser bug, so nothing to do here. Perhaps the report would be helpful for someone with the same problem.

mike-lischke commented 5 months ago

Thanks @nashbridges. In another project of mine I also use terser together with antlr4ng and have no problems like that.

nashbridges commented 5 months ago

Yes. I think, this an unfortunate combination of antlr4 plus all the libraries we had so far plus the project setup, but alas I can't share it. Feel free to close it.