(node, options)
| 23 | const GLOBAL_SCSS_DIRECTIVE = /(\s*)(!global).*$/; |
| 24 | |
| 25 | function 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", |
no test coverage detected
searching dependent graphs…