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