无法缩小 javascript class

Unable to minify javascript class

我创建了一个JavaScriptclass。当我尝试使用 javascript-minifier 缩小代码时出现错误。你能帮我解决这个问题吗?

我的代码:

class Test {
  onCompleted = () => {};
  onDismissed = () => {};
  onError = () => {};
  isProgress = false;
  popup;
  payment;

  startPayment(payment) {
    this.payment = payment;
    this.isProgress = true;
    this.popup = window.open('---');
    var timer = setInterval(function () {
      if (this.Test.popup.closed) {
        clearInterval(timer);
        if (this.Test.isProgress) {
          this.Test.isProgress = false;
          this.Test.onDismissed();
        }
      }
    }, 500);
  }
}

const Test = new Test();

window.addEventListener('beforeunload', function () {
  if (Test.popup != null && !Test.popup.closed) {
    Test.popup.close();
  }
});

window.Test = Test;

错误信息:

// Error : Unexpected token: operator (=)
// Line  : 2
// Col   : 18

您创建 class 的方式似乎有误。在 classes 中,您可以使用这样的函数:onCompleted() {}; 并且您可以在构造函数中创建变量。我还解决了一个问题,您将 Test 定义了两次,一次定义为 class ,一次定义为变量。我将变量重命名为 TestInstance

这是一个固定的例子:

class Test {
    constructor() {
        this.isProgress = false;
        this.popup;
        this.payment;
    }

    onCompleted () {};
    onDismissed () {};
    onError () {};
  
    startPayment(payment) {
      this.payment = payment;
      this.isProgress = true;
      this.popup = window.open("---");
      var timer = setInterval(function () {
        if (this.Test.popup.closed) {
          clearInterval(timer);
          if (this.Test.isProgress) {
            this.Test.isProgress = false;
            this.Test.onDismissed();
          }
        }
      }, 500);
    }
  }
  
  const TestInstance = new Test();
  
  window.addEventListener("beforeunload", function () {
    if (TestInstance.popup != null && !TestInstance.popup.closed) {
      TestInstance.popup.close();
    }
  });
  
  window.Test = TestInstance;

缩小版:

class Test{constructor(){this.isProgress=!1,this.popup,this.payment}onCompleted(){}onDismissed(){}onError(){}startPayment(s){this.payment=s,this.isProgress=!0,this.popup=window.open("---");var t=setInterval(function(){this.Test.popup.closed&&(clearInterval(t),this.Test.isProgress&&(this.Test.isProgress=!1,this.Test.onDismissed()))},500)}}const TestInstance=new Test;window.addEventListener("beforeunload",function(){null==TestInstance.popup||TestInstance.popup.closed||TestInstance.popup.close()}),window.Test=TestInstance;