Skip to content

Commit ca752c9

Browse files
committed
Fix parseNodeRecursive: Correctly recurse into TemplateLiteral expressions
In the fuction `parseNodeRecursive` of `lib/util/ast.js`, the case for TemplateListeral nodes would always recurse over `exp.right` for all expressions in the template. However, these expressions are not necessarily binary expressions. Removing the `.right` will make sure that e.g. ConditionalExpressions are also checked.
1 parent 7fdbbdb commit ca752c9

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

lib/util/ast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function parseNodeRecursive(node, arg, cb, skipConditional = false, isolate = fa
189189
switch (arg.type) {
190190
case 'TemplateLiteral':
191191
arg.expressions.forEach((exp) => {
192-
parseNodeRecursive(node, exp.right, cb, skipConditional, forceIsolation);
192+
parseNodeRecursive(node, exp, cb, skipConditional, forceIsolation);
193193
});
194194
arg.quasis.forEach((quasis) => {
195195
parseNodeRecursive(node, quasis, cb, skipConditional, isolate);

tests/lib/rules/no-contradicting-classname.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ ruleTester.run("no-contradicting-classname", rule, {
403403
options: [{ tags: ["myTag"] }],
404404
errors: generateErrors("px-2 px-0"),
405405
},
406+
{
407+
code: `myTag\`\${enabled ? "px-2 px-0" : ""}\``,
408+
options: [{ tags: ["myTag"] }],
409+
errors: generateErrors("px-2 px-0"),
410+
},
406411
{
407412
code: `
408413
<div class="shrink shrink-0 shrink-[inherit] shrink-[initial] shrink-[unset] shrink-[var(--some)] shrink-[0.5] shrink-[5]">

tests/lib/rules/no-custom-classname.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,11 @@ ruleTester.run("no-custom-classname", rule, {
985985
options: [{ tags: ["myTag"] }],
986986
errors: generateErrors("custom-2 custom-3 custom-1"),
987987
},
988+
{
989+
code: `myTag\`custom-1 \${isDisabled ? "custom-2" : "m-4"}\``,
990+
options: [{ tags: ["myTag"] }],
991+
errors: generateErrors("custom-2 custom-1"),
992+
},
988993
{
989994
code: `
990995
<div class="bg-red-600 p-10">

0 commit comments

Comments
 (0)