MCPcopy Index your code
hub / github.com/prettier/prettier / parseNestedCSS

Function parseNestedCSS

src/language-css/parser-postcss.js:25–380  ·  view source on GitHub ↗
(node, options)

Source from the content-addressed store, hash-verified

23const GLOBAL_SCSS_DIRECTIVE = /(\s*)(!global).*$/;
24
25function parseNestedCSS(node, options) {
26 if (isObject(node)) {
27 delete node.parent;
28
29 for (const key in node) {
30 parseNestedCSS(node[key], options);
31 }
32
33 if (!node.type) {
34 return node;
35 }
36
37 /* c8 ignore next */
38 node.raws ??= {};
39
40 // Custom properties looks like declarations
41 if (
42 node.type === "css-decl" &&
43 typeof node.prop === "string" &&
44 node.prop.startsWith("--") &&
45 typeof node.value === "string" &&
46 node.value.startsWith("{")
47 ) {
48 let rules;
49 if (node.value.trimEnd().endsWith("}")) {
50 const textBefore = options.originalText.slice(
51 0,
52 node.source.start.offset,
53 );
54 const nodeText =
55 "a".repeat(node.prop.length) +
56 options.originalText.slice(
57 node.source.start.offset + node.prop.length,
58 node.source.end.offset,
59 );
60 const fakeContent =
61 replaceNonLineBreaksWithSpace(textBefore) + nodeText;
62 let parse;
63 if (options.parser === "scss") {
64 parse = parseScss;
65 } else if (options.parser === "less") {
66 parse = parseLess;
67 } else {
68 parse = parseCss;
69 }
70 let ast;
71 try {
72 ast = parse(fakeContent, { ...options });
73 } catch {
74 // noop
75 }
76 if (ast?.nodes?.length === 1 && ast.nodes[0].type === "css-rule") {
77 rules = ast.nodes[0].nodes;
78 }
79 }
80 if (rules) {
81 node.value = {
82 type: "css-rule",

Callers 1

parseWithParserFunction · 0.85

Calls 13

isObjectFunction · 0.85
parseValueFunction · 0.85
isSCSSNestedPropertyNodeFunction · 0.85
parseSelectorFunction · 0.85
isModuleRuleNameFunction · 0.85
parseMediaQueryFunction · 0.85
trimEndMethod · 0.80
splitMethod · 0.80
parseFunction · 0.50
trimMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…