Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/execute/ojs/ojs-tools.ts
6458 views
1
/*
2
* ojs-tools.ts
3
*
4
* Copyright (C) 2021-2022 Posit Software, PBC
5
*/
6
7
import { make, simple } from "acorn/walk";
8
import { error } from "../../deno_ral/log.ts";
9
import { InternalError } from "../../core/lib/error.ts";
10
11
// we need to patch the base walker ourselves because OJS sometimes
12
// emits Program nodes with "cells" rather than "body"
13
const walkerBase = make({
14
Import() {},
15
// deno-lint-ignore no-explicit-any
16
ViewExpression(node: any, st: any, c: any) {
17
c(node.id, st, "Identifier");
18
},
19
// deno-lint-ignore no-explicit-any
20
MutableExpression(node: any, st: any, c: any) {
21
c(node.id, st, "Identifier");
22
},
23
// deno-lint-ignore no-explicit-any
24
Cell(node: any, st: any, c: any) {
25
c(node.body, st);
26
},
27
// deno-lint-ignore no-explicit-any
28
Program(node: any, st: any, c: any) {
29
if (node.body) {
30
for (let i = 0, list = node.body; i < list.length; i += 1) {
31
const stmt = list[i];
32
c(stmt, st, "Statement");
33
}
34
} else if (node.cells) {
35
for (let i = 0, list = node.cells; i < list.length; i += 1) {
36
const stmt = list[i];
37
c(stmt, st);
38
}
39
} else {
40
error("I don't know how to walk this node", node);
41
throw new InternalError(
42
`OJS traversal: I don't know how to walk this node: ${node}`,
43
);
44
}
45
},
46
});
47
48
// deno-lint-ignore no-explicit-any
49
export function ojsSimpleWalker(parse: any, visitor: any) {
50
simple(parse, visitor, walkerBase);
51
}
52
53