Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Class constructor Lexer cannot be invoked without 'new' #283

Closed
willpugh opened this issue Feb 16, 2017 · 12 comments
Closed

Comments

@willpugh
Copy link

I'm getting an error when trying to "new" a generated file that extends Lexer.

I suspect the problem is that our project is compiled down from TS to ES5.

Is the NPM module delivered as ES6. Is there an ES5 variant? Has anyone else run into this?

@sharwell
Copy link
Member

💭 We're using target es2015. I assume that means ES6?

@willpugh
Copy link
Author

Yup. es2015 is ES6 (ES6 is the old name for it, I just haven't broken my habit yet :). It's still not supported by several browsers, which forces us to use ES5, even though many browsers do support it. Here's a cool graph:
http://kangax.github.io/compat-table/es6/

Are you guys using language features that require using ES 6 as a target? If not, you can probably simply change the typescript target, and a lot more projects would be able to easily use it.

For our project, we actually need to generate ES 6 from typescript (because we use generator functions), but we then run it through Babel to get to ES5.
https://babeljs.io/

Not sure if that would be an option.

Thanks!

@sharwell
Copy link
Member

Are you guys using language features that require using ES 6 as a target?

I have no idea. There's a fairly comprehensive test suite, so if you send a pull request that changes the target it will probably fail the automated build and tell you if something broke. :)

@willpugh
Copy link
Author

Hmm. I tried doing a build before trying any changes and am getting a problem. The build seems to be running fine, and then I get the following errors. Is there something I'm doing wrong?

I'm trying to build using 'npm install'

antlr4ts-root@0.4.0-dev tsc /Users/wpugh/projects/antlr4ts/antlr4ts
tsc

benchmark/TestPerformance.ts(61,40): error TS2307: Cannot find module './gen/std/JavaLexer'.
benchmark/TestPerformance.ts(62,43): error TS2307: Cannot find module './gen/std-atn/JavaLexer'.
benchmark/TestPerformance.ts(63,44): error TS2307: Cannot find module './gen/lr/JavaLRLexer'.

@BurtHarris
Copy link
Collaborator

BurtHarris commented Mar 6, 2017

So far, we've only been testing on Node.js. Browser support should probably be added to our roadmap.

We are using ES2015 types and methods. Simply switching to the ES5 target currently generates a lot of tsc error messages. These are probably mostly addressable with available polyfills, but I don't have much expertise integrating them.

@willpugh, are you sure you have the prerequisites installed? See CONTRIBUTING.md. There's a particular oddity in the required build order you may be running into, but I'm just now brushing the cobwebs out of my way so I don't remember the details too well. I think those files should have been generated during the Maven (mvn/Java) part of the build.

@willpugh
Copy link
Author

willpugh commented Mar 8, 2017

O.K. Looked through this again. I think my pre-requisites are fine.

However, when I go into reference/antlr4ts and run
mvn clean install

I get:
Failed tests:
TestPerformance.compileJdk:426 The JDK_SOURCE_ROOT environment variable must be set for performance testing.

I wonder if this is related to the root cause, and I need to get the JDK source code installed on my machine? I couldn't find instructions on this, but I'll see if I can just grab the source, and point that at it. . .

@BurtHarris
Copy link
Collaborator

Ahh, yes. I forgot about that, but it rings a bell. If I remember however there may be licensing challenges related to that. @sharwell would know better than me.

@sharwell
Copy link
Member

sharwell commented Mar 8, 2017

@willpugh You can point it at any folder really. You only need Java source (maybe limited to Java 6 syntax) in it if you want to play with the performance tests.

@willpugh
Copy link
Author

willpugh commented Mar 9, 2017

Hmm. I'm simply running
npm install

but it seems to want to run the performance tests. The first error (of the hundreds I end up getting) is:

antlr4ts-root@0.4.0-dev tsc /Users/wpugh/projects/antlr4ts/antlr4ts
tsc

benchmark/TestPerformance.ts(61,40): error TS2307: Cannot find module './gen/std/JavaLexer'.
benchmark/TestPerformance.ts(62,43): error TS2307: Cannot find module './gen/std-atn/JavaLexer'.
benchmark/TestPerformance.ts(63,44): error TS2307: Cannot find module './gen/lr/JavaLRLexer'.
benchmark/TestPerformance.ts(64,47): error TS2307: Cannot find module './gen/lr-atn/JavaLRLexer'.
benchmark/TestPerformance.ts(66,42): error TS2307: Cannot find module './gen/std/JavaParser'.
benchmark/TestPerformance.ts(67,45): error TS2307: Cannot find module './gen/std-atn/JavaParser'.
benchmark/TestPerformance.ts(68,46): error TS2307: Cannot find module './gen/lr/JavaLRParser'.
benchmark/TestPerformance.ts(69,49): error TS2307: Cannot find module './gen/lr-atn/JavaLRParser'.

This is after I JDK_SOURCE_ROOT set. My tools look like they are approriately setup:

wpugh-mac2:antlr4ts wpugh$ npm -v
4.1.2

wpugh-mac2:antlr4ts wpugh$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_77, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"

@BurtHarris
Copy link
Collaborator

BurtHarris commented Mar 10, 2017

That seems to confirm a similar problem in discussion on PR #252, which @carlansley submitted but closed before it got merged. That PR was supposed to be a Mac/Linux build issue fix, unfortunately I'm not very experienced in those environments. I'm setting up Travis CI to let me repro without a local Linux machine, and seem to succeeded in reproducing the same problem.

@BurtHarris
Copy link
Collaborator

Thanks @willpugh, it a separate platform specific bug causing the error TS2307: Cannot find module messages. I've opened #303 to track that bug, and issue #302 to catch this sort of platform specific issue in the future.

@sharwell
Copy link
Member

Duplicate of #326

@sharwell sharwell marked this as a duplicate of #326 Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants