Skip to content

Commit

Permalink
feat: else if to else-if migration
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Aug 18, 2023
1 parent 0044e93 commit c6b3b0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-stingrays-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/compat-v4": patch
---

Migrate if attribute on else tag to an else-if tag.
22 changes: 16 additions & 6 deletions packages/compat-v4/src/migrate/if-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ export default {
const {
node: { name, arguments: args },
} = attr;
const tag = attr.parentPath as t.NodePath<t.MarkoTag>;
if (
name === "if" &&
tag.node.name.type === "StringLiteral" &&
tag.node.name.value === "else"
) {
diagnosticDeprecate(attr, {
label: `The "if" attribute on an <else> tag is deprecated. Please use "<else-if>" tag instead.`,
fix() {
tag.node.arguments = args;
tag.node.name = t.stringLiteral("else-if");
},
});
return;
}

switch (name) {
case "if":
Expand All @@ -20,12 +35,7 @@ export default {
return;
}

const tag = attr.parentPath as t.NodePath<t.MarkoTag>;
if (
(tag.node.name.type === "StringLiteral" &&
tag.node.name.value === "if") ||
willMigrateAllAttrs(tag)
) {
if (willMigrateAllAttrs(tag)) {
return;
}

Expand Down

0 comments on commit c6b3b0b

Please sign in to comment.