class 没有'new'就不能调用构造函数
class constructor cannot be invoked without 'new
我正在尝试在使用 angular-cli 创建的 angular 2 项目中使用第 3 方打字稿库(antlr - https://github.com/tunnelvisionlabs/antlr4ts)。失败并出现此错误
class 没有 'new 就不能调用构造函数 MyLexer。如果你看下面的代码片段,它在调用 super(); 时失败了。另外 Lexer.js 位于 antlr 库的 node_modules 中。
我没有在我的项目中使用 babel,但我发现另一个 Whosebug post 与我的 有类似的错误。它表示由于 ES6 classes 的工作方式,您不能使用转译的 class 扩展本机 class。它是否也与我的问题有关?请指导。
代码片段
let inputStream = new ANTLRInputStream("sometext");
let lexer = new MyLexer(inputStream); // it fails here
let tokenStream = new CommonTokenStream(lexer);
let parser = new MyParser(tokenStream);
MyLexer.ts(生成代码)
export class MyLexer extends Lexer {
constructor(input: CharStream) {
super(input); // it fails here.
this._interp = new LexerATNSimulator(MyLexer._ATN, this);
}
// more code
}
Lexer.js(坐在node_modules)
class Lexer extends Recognizer_1.Recognizer {
constructor(input) {
super();
//more code
这真是令人惊讶。我在我的节点模块 antlr4-graps, which has ES6 set as transpilation target 中使用与您相同的方法,一切都运行良好。仔细看看那里。也许您可以发现您的代码和我的代码之间的其他重要差异。我假设您已经安装了最新的 antlr4ts alpha。
我正在尝试在使用 angular-cli 创建的 angular 2 项目中使用第 3 方打字稿库(antlr - https://github.com/tunnelvisionlabs/antlr4ts)。失败并出现此错误 class 没有 'new 就不能调用构造函数 MyLexer。如果你看下面的代码片段,它在调用 super(); 时失败了。另外 Lexer.js 位于 antlr 库的 node_modules 中。
我没有在我的项目中使用 babel,但我发现另一个 Whosebug post 与我的
代码片段
let inputStream = new ANTLRInputStream("sometext");
let lexer = new MyLexer(inputStream); // it fails here
let tokenStream = new CommonTokenStream(lexer);
let parser = new MyParser(tokenStream);
MyLexer.ts(生成代码)
export class MyLexer extends Lexer {
constructor(input: CharStream) {
super(input); // it fails here.
this._interp = new LexerATNSimulator(MyLexer._ATN, this);
}
// more code
}
Lexer.js(坐在node_modules)
class Lexer extends Recognizer_1.Recognizer {
constructor(input) {
super();
//more code
这真是令人惊讶。我在我的节点模块 antlr4-graps, which has ES6 set as transpilation target 中使用与您相同的方法,一切都运行良好。仔细看看那里。也许您可以发现您的代码和我的代码之间的其他重要差异。我假设您已经安装了最新的 antlr4ts alpha。