9

I am trying to use a 3rd party typescript library(antlr - https://github.com/tunnelvisionlabs/antlr4ts) in my angular 2 project created using angular-cli. It's failing with this error class constructor MyLexer cannot be invoked without 'new. If you look at below code snippet , it's failing while making call to super();.Also Lexer.js is sitting in node_modules of antlr library.

I am not using babel in my project but I found this other stackoverflow post which has similar error as mine Babel error: Class constructor Foo cannot be invoked without 'new'. It says that due to the way ES6 classes work, you cannot extend a native class with a transpiled class. Is it somehow related to my issue as well? Please guide.

Code snippet

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 (Generated code)

    export class MyLexer extends Lexer {
        constructor(input: CharStream) {
                super(input); // it fails here. 
                this._interp = new LexerATNSimulator(MyLexer._ATN, this);
            }    
        // more code
     }

Lexer.js (sitting in node_modules)

class Lexer extends Recognizer_1.Recognizer {
    constructor(input) {
        super();
//more code
Community
  • 1
  • 1
user911
  • 1,509
  • 6
  • 26
  • 52

0 Answers0