-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
is-pseudo : handle more complex selector patterns (#923)
* is-pseudo : handle more complex selector patterns * clarify
- Loading branch information
1 parent
62a8134
commit 51b3bc6
Showing
18 changed files
with
423 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...ins/postcss-is-pseudo-class/dist/split-selectors/complex/is-pseudo-in-first-compound.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare function isPseudoInFirstCompound(selector: any): boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
plugins/postcss-is-pseudo-class/src/split-selectors/complex/is-pseudo-in-first-compound.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// :-csstools-matches(.a > .b) > .c | ||
// equivalent to | ||
// .a > .b > .c | ||
// because `:is()` is in the left-most compound selector | ||
export function isPseudoInFirstCompound(selector): boolean { | ||
if (!selector || !selector.nodes) { | ||
return false; | ||
} | ||
if (selector.type !== 'selector') { | ||
return false; | ||
} | ||
|
||
let isPseudoIndex = -1; | ||
for (let i = 0; i < selector.nodes.length; i++) { | ||
const node = selector.nodes[i]; | ||
if (node.type === 'combinator') { | ||
return false; | ||
} | ||
|
||
if (node.type === 'pseudo' && node.value === ':-csstools-matches') { | ||
if (!node.nodes || node.nodes.length !== 1) { | ||
return false; | ||
} | ||
|
||
isPseudoIndex = i; | ||
break; | ||
} | ||
} | ||
|
||
if (isPseudoIndex === -1) { | ||
return false; | ||
} | ||
|
||
const before = selector.nodes.slice(0, isPseudoIndex); | ||
const isPseudo = selector.nodes[isPseudoIndex]; | ||
const after = selector.nodes.slice(isPseudoIndex + 1); | ||
|
||
before.forEach((node) => { | ||
isPseudo.nodes[0].append(node.clone()); | ||
}); | ||
|
||
after.forEach((node) => { | ||
isPseudo.nodes[0].append(node.clone()); | ||
}); | ||
|
||
isPseudo.replaceWith(...isPseudo.nodes); | ||
|
||
before.forEach((node) => { | ||
node.remove(); | ||
}); | ||
|
||
after.forEach((node) => { | ||
node.remove(); | ||
}); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.