-
Notifications
You must be signed in to change notification settings - Fork 644
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
<for> switch to tag params #1238
Conversation
8f52b32
to
7c091ec
Compare
7c091ec
to
22056e6
Compare
Codecov Report
@@ Coverage Diff @@
## tag-param-core-tags #1238 +/- ##
=======================================================
+ Coverage 90.56% 90.59% +0.03%
=======================================================
Files 337 334 -3
Lines 12356 12339 -17
=======================================================
- Hits 11190 11179 -11
+ Misses 1166 1160 -6
Continue to review full report at Codecov.
|
${i} | ||
</for> | ||
|
||
<for(var i = 0; i <= listSize; i += 2)> | ||
<!-- Stange: backwards --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a few cases aren't handling the status var correctly
</for> | ||
<!-- Array | status-var iterator separator --> | ||
<for|color, loop, loopIndex, loopAll| of=input.iterator.bind(null, colors)> | ||
${color}${loop.getIndex() + 1}) of ${loop.getLength()}<if(loop.isFirst())> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${loop.getIndex() + 1}) of ${loop.getLength()}
${color}${loop.getIndex() + 1}) of ${loop.getLength()}<if(loop.isFirst())> | ||
- FIRST | ||
</if> | ||
<if(loop.isLast())>- LAST</if> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop.isLast()
d8aff27
to
565dc73
Compare
Description
This pr updates the
<for>
tag to use tag params instead of the existing special syntax.It also normalizes the for loop, and removes some unneeded functionality. Previously the
<for>
use a javascript like syntax that deviated in many ways.Here are some of the previous ways you could write a for loop:
for(item in array)
for(item in callbackGeneratorFunction)
for(key, value in object)
for(i from 0 to 10 step 2)
for(item in array | status-var=loop)
for(item in array | separator=" ,")
for(item in array | iterator=someFunction)
for(item in array | array)
Migrators have been added in this PR for all of the above variants where possible. Where a migration was not possible there now may be some additional runtime warnings, but all existing syntax should continue to work until a future version of Marko. You can automatically migrate the old syntax using marko migrate.
The new
<for>
loopThe
<for>
loop in this PR does not introduce any additional syntax and leverages the new tag parameters syntax.There are three variants, here are some examples of using the
<for>
loop:with an
of
attribute (iterates over an array/iterable).with an
in
attribute (iterates over an objects properties).with a
from
andto
attribute (iterates between a range of numbers).Checklist: