Add ancestors getter and hasAncestor() to AstPath (#14004)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-12-28 14:48:25 +08:00
1 parent 65c384303a
commit 3aaafa7ecf
12 files changed
+102 -153

No files matched your search

+11 -4
View File
@@ -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);