diff --git a/src/core-tags/migrate/all-tags/control-flow-directives.js b/src/core-tags/migrate/all-tags/control-flow-directives.js index 9fda0063f..d739c94e4 100644 --- a/src/core-tags/migrate/all-tags/control-flow-directives.js +++ b/src/core-tags/migrate/all-tags/control-flow-directives.js @@ -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") // 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` diff --git a/src/core-tags/migrate/for-tag.js b/src/core-tags/migrate/for-tag.js index 3719db3ed..74ab2f92e 100644 --- a/src/core-tags/migrate/for-tag.js +++ b/src/core-tags/migrate/for-tag.js @@ -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; diff --git a/test/migrate/fixtures/control-flow-directives/snapshot-expected.marko b/test/migrate/fixtures/control-flow-directives/snapshot-expected.marko index 20f0c4a51..0bfa4eab3 100644 --- a/test/migrate/fixtures/control-flow-directives/snapshot-expected.marko +++ b/test/migrate/fixtures/control-flow-directives/snapshot-expected.marko @@ -18,3 +18,8 @@
+ + A + + +A diff --git a/test/migrate/fixtures/control-flow-directives/template.marko b/test/migrate/fixtures/control-flow-directives/template.marko index bd1fc0f5f..05e153a4e 100644 --- a/test/migrate/fixtures/control-flow-directives/template.marko +++ b/test/migrate/fixtures/control-flow-directives/template.marko @@ -5,3 +5,7 @@
+ +A + +A diff --git a/test/migrate/fixtures/legacy-for-syntax/snapshot-expected.marko b/test/migrate/fixtures/legacy-for-syntax/snapshot-expected.marko index 82bdeb404..7b092bb50 100644 --- a/test/migrate/fixtures/legacy-for-syntax/snapshot-expected.marko +++ b/test/migrate/fixtures/legacy-for-syntax/snapshot-expected.marko @@ -94,6 +94,7 @@ $ input.iterator(colors, function(item) { ${i} ${i} +${i} $ var i = 0; = i)> diff --git a/test/migrate/fixtures/legacy-for-syntax/template.marko b/test/migrate/fixtures/legacy-for-syntax/template.marko index fe7cb709b..f192fd5a4 100644 --- a/test/migrate/fixtures/legacy-for-syntax/template.marko +++ b/test/migrate/fixtures/legacy-for-syntax/template.marko @@ -92,6 +92,10 @@ ${i} + + ${i} + + = i; i++)> ${i}