1.8 KiB
Himalaya AST Specification - Version 0
This document describes the abstract syntax tree output of Himalaya's parsing. This specification aims to provide context as to what may be expected as valid output from Himalaya.
Node
interface Node {
type: string;
}
All nodes are represented as Node objects. These object all have a property called type that designate what type of node it is.
enum Type {
"Element" | "Comment" | "Text"
}
Nodes can be of type:
-
Element, which are tags such as<body>,<div>,<style> -
Comment, which are<!-- {...} -->sections -
Text, which are text contents
Element Node
interface Element <: Node {
type: "Element";
tagName: string;
attributes: Attributes;
}
All element nodes have a tagName and attributes property. These nodes also have some optional properties:
-
children: [ Node ];Element nodes can have child nodes of any type. -
content: string;Elements that do not have their contents parsed (i.e.scriptandstyletags) will have their content placed in this property.
Attributes
interface Attributes <: Object {}
Attributes is a dictionary of keys and their values. All keys are strings and values can be strings, numbers, or objects. When they are objects, they must be one of the parsed sub-properties:
-
dataset: object;If the element has anydata-*attributes, they will be placed in this property. -
style: object;If the element has anystylevalue declarations, they will be placed in this property.
Note: the attribute class is changed to className.
Comment Node
interface Comment <: Node {
type: "Comment";
content: string;
}
A <!-- comment --> node.
Text Node
interface Text <: Node {
type: "Text";
content: string;
}
A text node.