-
Notifications
You must be signed in to change notification settings - Fork 146
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
Invalid/unclosed FOR loops yield no errors #322
Comments
Good find, and thanks for the clear writeup. This is a duplicate of #180 but with better context and documentation. I think the easiest solution for this would be to throw an error if the 'tree walking' of the document concludes without encountering an |
I think I have it. See af8ab37. Being able to close a FOR loop without naming its target is too complicated for now. I also think that 'naming' the FOR loop that you are terminating helps readability, but that is very subjective. |
Thanks for looking at this @jjhbw, really appreciate your efforts 👍 I tried out the latest
produces two errors now: [
[Error: Incomplete IF/END-IF statement. Make sure each IF-statement has a corresponding END-IF command.],
[Error: Unterminated FOR-loop ('FOR __if_0'). Make sure each FOR loop has a corresponding END-FOR command.]
] This bit of the code docx-templates/src/processTemplate.ts Lines 770 to 780 in af8ab37
IF commands into the ctx.loops array, which causes the error to be thrown.
|
…ing END-IF` should result in only the `Incomplete IF/END-IF statement` error, but it currently also erroneously results in the `Unterminated FOR-loop ('FOR __if_0')` error.
…also returning `Unterminated FOR-loop ('FOR __if_0')` when `failFast==false`.
Looks good to me, thanks @jjhbw - really appreciate your work 👍 |
If a mistake is made within
FOR
loop syntax, due to either a missing or incorrectEND-FOR
command, no errors are produced when callingcreateReport
.Examples
Each of these examples yields the same screenshot .docx result and explanation below.
Example 1:
Example 2:
Example 3:
Screenshot and explanation
No errors are thrown nor any in-document errors appear with
failFast: true
. Anything in the document after the broken loop will not appear (e.g. theAfter
text).In the examples above, it would be useful to:
FOR
statement (like anIncompleteConditionalStatementError
forIF
without anEND-IF
)FOR
loop without needing to name its target. An invalidEND-FOR
that closes an unknown loop would still error though to avoid subtle bugs (e.g. example 1 working and the invalid variable namepersons
being ignored).Compiler and toolchain
Information about your compiler toolchain version (e.g. Angular, Webpack, etc.): Directly testing with ESM/Node script:
Runtime
docx-templates
master from GitThe text was updated successfully, but these errors were encountered: