Improve string concatenation logic #364
Merged
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 #360
This PR improves string concatenation for expressions.
What was improved
Before we evaluate for each expressions but it could not lint "time calculation" case.
The "time calculation" is special behavior that is not documented on Fastly (maybe Varnish feature).
Time Calculation
On evaluating expressions, the left hand is
TIME
time and right hand isRTIME(Literal)
with explicit plus sign(+
), it works as "time calculation". additionally, the minus sign (-
) is also accepted for subtracting the TIME.On the above example, the expression should be treated as time calculation, the result is
TIME
which is added (or subracted) 5 minutes.This is very complicated syntax because we will misunderstand that is string concatenation or syntax error.
Followings are confusing example:
Then we couldn't recognize above cases by current string concatenation linting process so we improved that.
+
or not) for each seriesYou also will feel that time calculation is complicated, and Fastly undocumented I think we should not use this syntax, so we will raise an lint error as
INFO
level (VCL is valid, but we recommend to fix).And I also improved interpreter implementation follows the above way to evaluate.
See actual Fastly behavior on the fiddle: https://fiddle.fastly.dev/fiddle/befec89e