tunnelvisionlabs / antlr4ts

Optimized TypeScript target for ANTLR 4
Other
629 stars 108 forks source link

Classes used before definition #308

Open shaunburdick opened 7 years ago

shaunburdick commented 7 years ago

I ran into an issue using this library with the newest version of Typescript and ts-node (tsc: 2.2.2, ts-node: 3.0.2, node: 7.8.0) The resulting Parser.ts was using the *Context classes before they were defined. This was causing the parser to throw an error saying they were not defined. I fixed it by moving all the Context classes above the Parser class.

shaunburdick commented 7 years ago

Yeah, played around a little more and seems to be an issue with class hoisting, JS doesn't do that.

nehaagrawal commented 7 years ago

I am getting the exact same error in the generated parser class. I changed the order of the defined class and it worked. More details on this stackoverflow post. http://stackoverflow.com/questions/43765160/uncaught-referenceerror-is-not-defined-typescript?noredirect=1#comment74575902_43765160

I have recently posted few issues here and never got a reply. Is this group active?

BurtHarris commented 7 years ago

The antlr4ts target is pre-release and too new to get any attention on stack overflow, this repository is the best place for now. We are still working on making this a stable production quality port, but can't commit to a schedule.

BurtHarris commented 7 years ago

Hi, @shaunburdick. I think this is like the issue reported secondarily in #326. Digging into it in that context, I'm thinking it may have been a TSLint (rather that TypeScript) error complaining about using a class before it's definition. As I understand it, that's allowed in TypeScript, and as this is generated code I'm expecting to address it by suppressing the TSLint checks in the generated files. #329.

Does this make sense for the case you're reporting?

pedroteixeira commented 6 years ago

I'm having the same issue with typescript 2.7.1 Disabling tslint did not fix, only re-ordering the classes definitions in the generated file.

BurtHarris commented 6 years ago

I've really not had time to work on this myself, but reordering the class definitions would be implemented in the file TyepScript.stg, which is in the StringTemplate language. I know that there is a PR #358 pending on that file from @ydarias that seems quite simple, I don't know but his fix might help the problem you are having.

I'm really hoping to recruit some additional coders who actually have a current need for antlr4ts, I currently have nothing pending dependent on it. What I would need is some error case I can check-out and reproduce this problem on, then I would feel more comfortable editing TyepScript.stg. Even if the repro case isn't integrated into our test suite, some repro case would really help.