Skip to content

Commit 01bd10c

Browse files
egorpavlikhinEgor Pavlikhin
andauthored
fix: parsing spreads in function call returns (francoismassart#285)
* fix: Parsing spreads in function call returns * Revert style change --------- Co-authored-by: Egor Pavlikhin <egor@pavlikhin.com>
1 parent 5fdb806 commit 01bd10c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/util/ast.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ function extractRangeFromNode(node) {
184184
if (node.type === 'TextAttribute' && node.name === 'class') {
185185
return [node.valueSpan.fullStart.offset, node.valueSpan.end.offset];
186186
}
187+
if (node.value === undefined) {
188+
return [0,0];
189+
}
187190
switch (node.value.type) {
188191
case 'JSXExpressionContainer':
189192
return node.value.expression.range;
@@ -196,6 +199,10 @@ function extractValueFromNode(node) {
196199
if (node.type === 'TextAttribute' && node.name === 'class') {
197200
return node.value;
198201
}
202+
if (node.value === undefined) {
203+
return node.value;
204+
}
205+
199206
switch (node.value.type) {
200207
case 'JSXExpressionContainer':
201208
return node.value.expression.value;

tests/lib/rules/classnames-order.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ ruleTester.run("classnames-order", rule, {
281281
{
282282
code: `<div class="py-1\u3000px-2 block">Do not treat full width space as class separator</div>`,
283283
},
284+
{
285+
code: `
286+
const func = () => ({ a: 12 });
287+
<div className={clsx(['text-sm', {
288+
...func()
289+
}])}>Spread of a function return inside clsx</div>
290+
`,
291+
},
284292
],
285293
invalid: [
286294
{

0 commit comments

Comments
 (0)