vendure-ecommerce / ngx-translate-extract

Extract translatable (using ngx-translate) strings and save as a JSON or Gettext pot file
MIT License
51 stars 19 forks source link

fix(pipe.parser): `RangeError: Maximum call stack size exceeded` on nested templates #34

Closed sod closed 1 year ago

sod commented 1 year ago

Thank you so much for maintaining this project!

With https://github.com/vendure-ecommerce/ngx-translate-extract/pull/27 we get the exception RangeError: Maximum call stack size exceeded on some templates. The findPipesInNode => extractPipesFromChildNodes => findPipesInNode recursion on a class fails on depth 18, e.g. this template:

<i><i><i><i><i><i><i><i><i><i><i><i><i><i><i><i><i><i>
    {{ 'deep' | translate }}
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>

Which apparently can happen if you dabble with some nested diffs, forms, bootstrap boilerplate, angular blocks and some ternary to finish it off.

This PR cleans up the recursion via two traversal methods that don't hold much context, allowing to traverse through nested templates (from before depth 18 to ~700 in this PR).

michaelbromley commented 1 year ago

Thank you for this PR! I'll make a new release shortly.