Skip to content

Latest commit

 

History

History
154 lines (138 loc) · 2.69 KB

ast.md

File metadata and controls

154 lines (138 loc) · 2.69 KB

This document specifies the core WXML AST node types

Primitive Type

Position

interface Position {
  start: number;
  end: number;
  start: {
    line: number;
    column: number;
  },
  end: {
    line: number;
    column: number;
  },
  range: [number, number]
}

WXNode

type WXNode = WXScript | WXElement | WXComment | WXText;

Real Type

Program

interface Program extends Position {
  type: "Program";
  body: WXNode[];
  comments: WXComment[];
  errors: Array<WXLexerError | WXParseError>;
  tokens: []; // placeholder for future feature
}

WXLexerError

interface WXLexerError extends Position {
  type: "WXLexerError";
  value: string; // error.message
}

WXParseError

interface WXParseError extends Position {
  type: "WXParseError";
  value: string; // error.message
  rawType: string; // error.name
}

WXScript

interface WXScript extends Position {
  type: "WXScript",
  name: "wxs",
  startTag: WXStartTag
  endTag: WXEndTag | null
  value: string | null;
  error: WXScriptError | undefined;
  body: [WXScriptProgram] | undefined;
}

WXElement

interface WXElement extends Position {
  type: "WXElement";
  name: string;
  children: WXNode[];
  startTag: WXStartTag;
  endTag: WXEndTag | null;
}

WXStartTag

interface WXStartTag extends Position {
  type: "WXStartTag";
  name: string;
  attributes: WXAttribute[];
  selfClosing: boolean;
}

WXEndTag

interface WXEndTag extends Position {
  type: "WXEndTag";
  name: string;
}

WXAttribute

interface WXAttribute extends Position {
  type: "WXAttribute";
  key: string;
  quote: '\'' | '\"';
  value: string | null;
  rawValue: string | null;
  children: Array<WXAttributeInterpolation | WXText>;
  interpolations: WXInterpolation[];
}

WXInterpolation

same with WXAttributeInterpolation

interface WXInterpolation extends Position {
  type: "WXInterpolation";
  rawValue: string;
  value: string;
}

WXText

interface WXText extends Position {
  type: "WXText";
  value: string;
}

WXComment

<!-- I am a WXComment Node -->

interface WXComment extends Position {
  type: "WXComment";
  value: string;
}