summaryrefslogtreecommitdiff
path: root/src/ast.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ast.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ast.ts b/src/ast.ts
new file mode 100644
index 000000000..6c0bd7bd2
--- /dev/null
+++ b/src/ast.ts
@@ -0,0 +1,23 @@
+import type { Attribute } from './parser/interfaces';
+
+// AST utility functions
+
+export function getAttr(attributes: Attribute[], name: string): Attribute | undefined {
+ const attr = attributes.find((a) => a.name === name);
+ return attr;
+}
+
+export function getAttrValue(attributes: Attribute[], name: string): string | undefined {
+ const attr = getAttr(attributes, name);
+ if (attr) {
+ return attr.value[0]?.data;
+ }
+}
+
+export function setAttrValue(attributes: Attribute[], name: string, value: string): void {
+ const attr = attributes.find((a) => a.name === name);
+ if (attr) {
+ attr.value[0]!.data = value;
+ attr.value[0]!.raw = value;
+ }
+}