有没有办法在babelify中关闭"超级之前不允许这样的规则"?

res*_*ive 3 javascript ecmascript-6 gulp babeljs

我正在使用Gulp运行babelify 7.2.0并且我在以下代码中收到错误:

class One {}

class Two extends One {
  constructor() {
    this.name = 'John';
  }
}
Run Code Online (Sandbox Code Playgroud)

以下是错误的关键:

SyntaxError: [the file path in question]: 'this' is not allowed before super()
  20 | class Two extends One {
  21 |   constructor() {
> 22 |     this.name = 'John';
     |     ^
  23 |   }
  24 | }
  25 | 
Run Code Online (Sandbox Code Playgroud)

在我看来,这不应该被解雇,因为我根本没有super在构造函数中进行任何调用,因此没有冲突的风险.我已经在Github上提交了一个问题,但我想知道是否有办法可以在同一时间关闭它.

vau*_*tah 6

这不是一个错误.子类必须在尝试访问之前super 显式调用this:

class Two extends One {
    constructor(...args) {
        super(...args);
        this.name = 'John';
    }
}
Run Code Online (Sandbox Code Playgroud)

这在ECMAScript标准中定义(参见答案),Babel密切关注它.