Skip to content

Commit

Permalink
Fix selector-no-union-class-name throwing when parent.selector is und…
Browse files Browse the repository at this point in the history
…efined
  • Loading branch information
kristerkari committed Jul 17, 2019
1 parent 147b44c commit 124e835
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/rules/selector-no-union-class-name/__tests__/index.js
Expand Up @@ -95,6 +95,20 @@ testRule(rule, {
}
`,
description: "ignores an ampersand chained with an attribute"
},
{
code: `
@mixin demo() {
@content;
}
.a-selector {
@include demo() {
button:hover & {
background:purple
}
}
}`,
description: "should not throw an error when using nesting (issue #345)"
}
],

Expand Down
10 changes: 7 additions & 3 deletions src/rules/selector-no-union-class-name/index.js
Expand Up @@ -35,9 +35,13 @@ export default function(actual) {
root.walkRules(/&/, rule => {
const parentNodes = [];

parseSelector(rule.parent.selector, result, rule, fullSelector => {
fullSelector.walk(node => parentNodes.push(node));
});
if (rule.parent && rule.parent.selector) {
parseSelector(rule.parent.selector, result, rule, fullSelector => {
fullSelector.walk(node => parentNodes.push(node));
});
}

if (parentNodes.length === 0) return;

const lastParentNode = parentNodes[parentNodes.length - 1];

Expand Down

0 comments on commit 124e835

Please sign in to comment.