Add ancestors getter and hasAncestor() to AstPath (#14004)
This commit is contained in:
1 parent
65c384303a
commit
3aaafa7ecf
12 files changed
+102
-153
No files matched your search
@@ -26,7 +26,6 @@ import { insertPragma } from "./pragma.js";
|
||||
import getVisitorKeys from "./get-visitor-keys.js";
|
||||
|
||||
import {
|
||||
getAncestorNode,
|
||||
getPropOfDeclNode,
|
||||
maybeToLowerCase,
|
||||
insideValueFunctionNode,
|
||||
@@ -356,7 +355,11 @@ function genericPrint(path, options, print) {
|
||||
case "selector-root":
|
||||
return group([
|
||||
insideAtRuleNode(path, "custom-selector")
|
||||
? [getAncestorNode(path, "css-atrule").customSelector, line]
|
||||
? [
|
||||
path.findAncestor((node) => node.type === "css-atrule")
|
||||
.customSelector,
|
||||
line,
|
||||
]
|
||||
: "",
|
||||
join(
|
||||
[
|
||||
@@ -464,7 +467,9 @@ function genericPrint(path, options, print) {
|
||||
return node.value;
|
||||
|
||||
case "selector-unknown": {
|
||||
const ruleAncestorNode = getAncestorNode(path, "css-rule");
|
||||
const ruleAncestorNode = path.findAncestor(
|
||||
(node) => node.type === "css-rule"
|
||||
);
|
||||
|
||||
// Nested SCSS property
|
||||
if (ruleAncestorNode?.isSCSSNesterProperty) {
|
||||
@@ -516,7 +521,9 @@ function genericPrint(path, options, print) {
|
||||
parentNode.type === "value-value" &&
|
||||
(declAncestorProp === "grid" ||
|
||||
declAncestorProp.startsWith("grid-template"));
|
||||
const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
|
||||
const atRuleAncestorNode = path.findAncestor(
|
||||
(node) => node.type === "css-atrule"
|
||||
);
|
||||
const isControlDirective =
|
||||
atRuleAncestorNode &&
|
||||
isSCSSControlDirectiveNode(atRuleAncestorNode, options);
|
||||
|
||||
Reference in new issue
Block a user