mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Control flow and looping migration fixes
This commit is contained in:
parent
535daf9451
commit
e1a1d401ae
@ -10,15 +10,12 @@ const CONTROL_FLOW_ATTRIBUTES = [
|
||||
module.exports = function migrate(el, context) {
|
||||
const builder = context.builder;
|
||||
|
||||
if (CONTROL_FLOW_ATTRIBUTES.includes(el.tagName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.forEachAttribute(attr => {
|
||||
const name = attr.name;
|
||||
if (
|
||||
CONTROL_FLOW_ATTRIBUTES.includes(name) &&
|
||||
(name === "else" || attr.argument)
|
||||
(name === "else" || attr.argument) &&
|
||||
(el.tagName !== "else" || name !== "if") // <else if(x)> gets passed through
|
||||
) {
|
||||
context.deprecate(
|
||||
`The "${name}" attribute is deprecated. Please use the <${name}> tag instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-control-flow-directive`
|
||||
|
||||
@ -258,20 +258,23 @@ function normalizeParts(parsed, builder) {
|
||||
const update = parsed.update;
|
||||
const test = parsed.test;
|
||||
|
||||
if (
|
||||
!init ||
|
||||
!update ||
|
||||
!test ||
|
||||
init.type !== "Vars" ||
|
||||
init.declarations.length !== 1 ||
|
||||
test.type !== "BinaryExpression"
|
||||
) {
|
||||
if (!init || !update || !test || test.type !== "BinaryExpression") {
|
||||
return;
|
||||
}
|
||||
|
||||
const declarator = init.declarations[0];
|
||||
const varName = declarator.id;
|
||||
let from = declarator.init;
|
||||
let varName;
|
||||
let from;
|
||||
|
||||
if (init.type === "Vars" && init.declarations.length === 1) {
|
||||
const declarator = init.declarations[0];
|
||||
varName = declarator.id;
|
||||
from = declarator.init;
|
||||
} else if (init.type === "Assignment" && init.operator === "=") {
|
||||
varName = init.left;
|
||||
from = init.right;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!from) {
|
||||
return;
|
||||
|
||||
@ -18,3 +18,8 @@
|
||||
<if(!x)>
|
||||
<div/>
|
||||
</if>
|
||||
<if(y)>
|
||||
<if(x)>A</if>
|
||||
</if>
|
||||
<!-- passed through -->
|
||||
<else if(x)>A</else>
|
||||
|
||||
@ -5,3 +5,7 @@
|
||||
<span else(z)/>
|
||||
|
||||
<div unless(x)/>
|
||||
|
||||
<if(x) if(y)>A</if>
|
||||
<!-- passed through -->
|
||||
<else if(x)>A</else>
|
||||
|
||||
@ -94,6 +94,7 @@ $ input.iterator(colors, function(item) {
|
||||
<!-- Regular -->
|
||||
<for|i| from=0 to=(list.length - 1)>${i}</for>
|
||||
<for|i| from=0 to=listSize step=2>${i}</for>
|
||||
<for|i| from=0 to=listSize step=2>${i}</for>
|
||||
<!-- Stange: backwards -->
|
||||
$ var i = 0;
|
||||
<while(list.length >= i)>
|
||||
|
||||
@ -92,6 +92,10 @@
|
||||
${i}
|
||||
</for>
|
||||
|
||||
<for(i = 0; i <= listSize; i += 2)>
|
||||
${i}
|
||||
</for>
|
||||
|
||||
<!-- Stange: backwards -->
|
||||
<for(var i = 0; list.length >= i; i++)>
|
||||
${i}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user