-
Notifications
You must be signed in to change notification settings - Fork 108
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
{{grammarName}}Parser Typescript Class Should Be After the rule contexts #341
Comments
Ahh, thank you @petermetz. This sounds familiar, some other people have reported similar sounding problems I hadn't yet reproduced it or connected it to the decorators and order in the file. I'll have a look at this with that added information. |
@BurtHarris Awesome, thanks very much for checking on it! Once the template is sorted out I'll also submit a PR with this |
@petermetz, to be clear, when you said
Was this the problem message: c:\try\soql\SOQLLexer.js:30
|
@BurtHarris Nope, I was having issues with the Parser class not being defined at the point in the code that was creating/setting up the decorators. |
@petermetz Then exactly what is the problem? Is there an error message? From what tool, or is it at runtime? Can you give me step-by-step repro instructions? The thing that's got me puzzled is there really shouldn't be an order dependency, and I still haven't got a clear isolated repro case. Seems related to #326, #310, #283, I know that in #326 @fdeitelhoff was also trying to get this working in a browser. I'm afraid this may be related to Babel and our (current) use of native ES classes for the base classes both (Lexer and Parser.) I found https://stackoverflow.com/questions/36577683/babel-error-class-constructor-foo-cannot-be-invoked-without-new/
Another way to approach this is to change our build so that it generates .js files for ES5 rather than ES2015. That change is requested in #311, but we are currently planning to postpone that till after we release a stable NodeJS version. |
@BurtHarris Thanks again for checking on this and spending so much effort to make sure its covered. I pushed my local test bench here, hopefully you can reproduce it with this: https://github.com/petermetz/antlr-4-ts-test NodeJS 8 is being used on my machine at the moment. Should crash with something like this below:
|
Great. I'll have a look at that this evening (pacific time) |
you can find the |
OK, I was tied up on another project, I haven't gotten a chance to dig into it yet, but will soon. |
same issue here, a fix or a workaround would be welcome |
I am able to work around the issue by manually moving the Parser class to the bottom of the generated Parser file. Kind of a pain since I keep forgetting to edit the file. |
Manually moving a generated parser to last in the file works. I wonder if some are not getting this dependent on environment. I'm using a webpack. PS. If I put this to false: tsconfig.json @petermetz you can try that also, looking at your project you have emitDecoratorMetadata as true. |
Interesting observation about |
@Ciantic, I'm guessing that the fix of disabling |
@Ciantic @BurtHarris Thanks for pointing me to the right direction, I'm having the same issue ( typescript 2.6.2): Running a simple script like this
I get
Setting
I created a sample project Here |
Had the same issue. Manually moving the class definitions before they are referenced seems to fix the compiler issue. |
I ended up running a fix script that re-order the file, posting here in case might be usefull for someone else (you'd have to replace some of it):
#!/usr/bin/env bash
FILE='<Parser File Path>.ts'
START_LINE=`grep -n 'export class <your first context class here> extends ParserRuleContext' ${FILE} | cut -d: -f 1`
TMPFILE='tmpfile.ts'
echo '// tslint: disabled' > $TMPFILE
tail -n+${START_LINE} ${FILE} >> $TMPFILE
head -n$(($START_LINE - 1)) ${FILE} >> $TMPFILE
mv $TMPFILE $FILE |
btw, I created this issue in the Babel repo for something that affects this library right now: babel/babel#7736
|
@pedroteixeira I'm not sure exactly what the babel/babel#7736 has to do with this. I've not gotten into babel at all. Is this something a fix in this codebase could help with? Does it deserve a separate bug? |
💭 Need to figure out if this is still an issue with #361 merged. |
Just came upon this tool while exploring ANTLR, looks very promising. I've got the latest copy of the tool (0.4.0-alpha.4) working with Angular 6, and came across this issue. Manually re-ordering the file does fix it, but I want to make my generation dynamic. and automatic. Has there been any progress on solving it? |
This is still an issue as of version 6.4.1. The fix for me was also to set 'emitDecoratorMetadata' to false. |
Generating the files with emitDecoratorMetadata set to false does not fix the issue when the files are moved into a project that has emitDecoratorMetadata set to true. In my case I'm moving the files into an AG6 project and have to reorder it. |
After TS parser is generated, I use this Shell function to reorder the file content: reorderParser() {
FILE="$1"
TMPFILE=`mktemp`
# reorder classes in the generated parser
# see https://github.com/tunnelvisionlabs/antlr4ts/issues/341
PARSER_START_LINE=`grep -n "extends Parser " "$FILE" | head -n1 | cut -d: -f 1`
RULES_START_LINE=`grep -n "extends ParserRuleContext " "$FILE" | head -n1 | cut -d: -f 1`
# 0 .. PARSER_START_LINE
head -n$(($PARSER_START_LINE - 1)) "$FILE" >> "$TMPFILE"
# RULES_START_LINE .. end
tail -n+$RULES_START_LINE "$FILE" >> "$TMPFILE"
# PARSER_START_LINE .. RULES_START_LINE
tail -n+$PARSER_START_LINE "$FILE" | head -n$(($RULES_START_LINE - $PARSER_START_LINE - 1)) >> "$TMPFILE"
mv "$TMPFILE" "$FILE"
}
reorderParser "xxxParser.ts" |
@johnholliday @davidhockey22 @zakjan Can one of you create a small sample project demonstrating the issue so I can better understand it, and hopefully be able to add a regression test when it's fixed? |
Hiya,
This tool is a godsend, thank you very much for it!
I was giving this grammar a spin when I found out that the decorators generated (@RuleVersion) depend on the parser class being declared below them in the .ts file (which is not the case).
https://github.com/mulesoft/salesforce-soql-parser/blob/antlr4/SOQL.g4
I could fix it manually by going in to the generated typescript file and putting the parser class at the very end, but I suck at this JST syntax and couldn't (yet) figure out how to reposition the class in the template (without the rest of the code around it in that template function block).
If I figure it out I'll be happy to submit a PR (in case it's endorsed as a good solution), otherwise what I wanted to do is just placing the below block at the end of the template:
Does this sound like a good idea at all or I went the wrong way in the first place?
The text was updated successfully, but these errors were encountered: