Path: blob/main/tools/sass-variable-explainer/group-arguments.ts
6433 views
import { withType } from './ast-utils.ts';12// FIXME in SCSS, _declarations_ have a `!default` flag, not _values_3// but the parser we have puts the `!default` flag on the values4// we need to lift it up to the declaration level56export const groupArguments = (outer: any) =>7withType(outer, (node: any) => {8if (node.type !== "function") {9return node;10}11const newArguments: any[] = [];12const newGroup = (): any => {13return {14type: "node_group",15start: node.start, // just so that simplifyLineInfo can handle it later16next: node.next,17children: [],18};19}20let thisArgument = newGroup();21const flushGroup = () => {22if (thisArgument.children.length > 1) {23newArguments.push(thisArgument);24} else {25newArguments.push(thisArgument.children[0]);26}27thisArgument = newGroup();28}29if (node.children.length < 2) {30throw new Error("function node has no arguments");31}32for (const arg of node.children[1].children) {33if (arg.type === "punctuation" && arg.value === ",") {34flushGroup();35} else {36thisArgument.children.push(arg);37}38}39if (thisArgument.children.length > 0) {40flushGroup();41}42node.children[1].children = newArguments;43return node;44});454647