Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes openlayers/openlayers#10075
Because regex are inherently bad at matching nested structures and I had fun in digging into grammar and especially pegjs (https://pegjs.org/), I wrote a grammar to perform the type rewrites. I also made a branch (#12), but I don't know if this should be merged because it would introduce a new syntax that might be difficult to maintain if not known and a new dependency.
The parser approach has 2 big advantages: It can easily handle nested structures and it can throw errors if it finds expressions that it should be able to parse, but some type is missing.
Nevertheless I used this grammar to check the output of our regular expression and found several issues. I created a new regex that does not produce any false positives and only misses a handful of rewrites in the whole code base.
Examples for expressions it can not handle are multiline types and some strangely nested types.
I also found some more incorrect annotations in the codebase, that I fix in PR on the main repository.