( ctx: VisitContext<AstNode>, )
| 186 | } |
| 187 | |
| 188 | export function cssContext( |
| 189 | ctx: VisitContext<AstNode>, |
| 190 | ): VisitContext<AstNode> & { context: Record<string, string | boolean> } { |
| 191 | return { |
| 192 | depth: ctx.depth, |
| 193 | index: ctx.index, |
| 194 | siblings: ctx.siblings, |
| 195 | get context() { |
| 196 | let context: Record<string, string | boolean> = {} |
| 197 | for (let child of ctx.path()) { |
| 198 | if (child.kind === class="st">'context') { |
| 199 | Object.assign(context, child.context) |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | class="cm">// Once computed, we never need to compute this again |
| 204 | Object.defineProperty(this, class="st">'context', { value: context }) |
| 205 | return context |
| 206 | }, |
| 207 | get parent() { |
| 208 | let parent = (this.path().pop() as Extract<AstNode, { nodes: AstNode[] }>) ?? null |
| 209 | |
| 210 | class="cm">// Once computed, we never need to compute this again |
| 211 | Object.defineProperty(this, class="st">'parent', { value: parent }) |
| 212 | return parent |
| 213 | }, |
| 214 | path() { |
| 215 | return ctx.path().filter((n) => n.kind !== class="st">'context') |
| 216 | }, |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | class="cm">// Optimize the AST for printing where all the special nodes that require custom |
| 221 | class="cm">// handling are handled such that the printing is a 1-to-1 transformation. |
no outgoing calls
no test coverage detected