Skip to content

compile parsed source type #183

@Kal-Aster

Description

@Kal-Aster

The package published on npm looks like it still has the "unknonw" typo in the compile declaration.

However obviously we can do better than "unknown", I already created a typing of the parser result while developing the vscode riot extension:

type Expression = {
    text: string,

    start: number,
    end: number
};

type Attribute = {
    name: string,
    value: string,

    start: number,
    end: number,

    unescape?: string,
    expressions?: Array<Expression>,

    valueStart?: number,
    parts?: Array<string>
};

type BaseParserNode = {
    type: number,
    name: string,

    start: number,
    end: number,

    attributes?: Array<Attribute>,

    isVoid?: true,
    isSelfClosing?: true
};

type ParserNode = BaseParserNode & {
    nodes?: Array<ParserNode>,

    isCustom?: true,

    text?: string,
    expressions?: Array<Expression>,
    parts?: Array<string>
};

type ParserCodeNode = BaseParserNode & {
    text?: {
        type: 3,
        text: string,
        start: number,
        end: number
    }
};

type ParserResult = {
    data: string,
    output: {
        template: ParserNode,
        css: ParserCodeNode | null,
        javascript: ParserCodeNode | null,
    }
};

This is not by any means complete, but I hope it can help to provide better typings.

Also I'm posting this here but the typings should be actually added in the parser and the compiler should reference them.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions