astro/packages/astro-parser/src/interfaces.ts

147 lines
3 KiB
TypeScript
Raw Normal View History

import type { SourceMap } from 'magic-string';
export type { CompileError } from './utils/error';
export interface BaseNode {
2021-03-16 20:54:58 +00:00
start: number;
end: number;
type: string;
children?: TemplateNode[];
[prop_name: string]: any;
}
export interface Fragment extends BaseNode {
2021-03-16 20:54:58 +00:00
type: 'Fragment';
children: TemplateNode[];
}
export interface Text extends BaseNode {
2021-03-16 20:54:58 +00:00
type: 'Text';
data: string;
raw: string;
}
export interface Attribute extends BaseNode {
type: 'Attribute';
name: string;
value: Text[];
}
export interface MustacheTag extends BaseNode {
2021-03-16 20:54:58 +00:00
type: 'MustacheTag';
content: string;
}
2021-03-16 20:54:58 +00:00
export type DirectiveType = 'Action' | 'Animation' | 'Binding' | 'Class' | 'EventHandler' | 'Let' | 'Ref' | 'Transition';
interface BaseDirective extends BaseNode {
2021-03-16 20:54:58 +00:00
type: DirectiveType;
expression: null | Node;
name: string;
modifiers: string[];
}
2021-03-16 20:54:58 +00:00
export interface Transition extends BaseDirective {
type: 'Transition';
intro: boolean;
outro: boolean;
}
export type Directive = BaseDirective | Transition;
2021-03-16 20:54:58 +00:00
export type TemplateNode = Text | MustacheTag | BaseNode | Directive | Transition;
export interface Expression {
type: 'Expression';
start: number;
end: number;
codeChunks: string[];
children: BaseNode[];
}
export interface Parser {
2021-03-16 20:54:58 +00:00
readonly template: string;
readonly filename?: string;
2021-03-16 20:54:58 +00:00
index: number;
stack: Node[];
2021-03-16 20:54:58 +00:00
html: Node;
css: Node;
js: Node;
meta_tags: Map<string, string>;
}
export interface Script extends BaseNode {
2021-03-16 20:54:58 +00:00
type: 'Script';
2021-03-21 07:44:42 +00:00
context: 'runtime' | 'setup';
2021-03-16 20:54:58 +00:00
content: string;
}
export interface Style extends BaseNode {
2021-03-16 20:54:58 +00:00
type: 'Style';
attributes: any[]; // TODO
content: {
start: number;
end: number;
styles: string;
};
}
export interface Ast {
2021-03-16 20:54:58 +00:00
html: TemplateNode;
css: Style;
module: Script;
2021-03-21 07:44:42 +00:00
// instance: Script;
}
export interface Warning {
2021-03-16 20:54:58 +00:00
start?: { line: number; column: number; pos?: number };
end?: { line: number; column: number };
pos?: number;
code: string;
message: string;
filename?: string;
frame?: string;
toString: () => string;
}
export type ModuleFormat = 'esm' | 'cjs';
2021-03-16 20:54:58 +00:00
export type CssHashGetter = (args: { name: string; filename: string | undefined; css: string; hash: (input: string) => string }) => string;
export interface Visitor {
2021-03-16 20:54:58 +00:00
enter: (node: Node) => void;
leave?: (node: Node) => void;
}
export interface AppendTarget {
2021-03-16 20:54:58 +00:00
slots: Record<string, string>;
slot_stack: string[];
}
export interface Var {
2021-03-16 20:54:58 +00:00
name: string;
export_name?: string; // the `bar` in `export { foo as bar }`
injected?: boolean;
module?: boolean;
mutated?: boolean;
reassigned?: boolean;
referenced?: boolean; // referenced from template scope
referenced_from_script?: boolean; // referenced from script
writable?: boolean;
// used internally, but not exposed
global?: boolean;
internal?: boolean; // event handlers, bindings
initialised?: boolean;
hoistable?: boolean;
subscribable?: boolean;
is_reactive_dependency?: boolean;
imported?: boolean;
}
export interface CssResult {
2021-03-16 20:54:58 +00:00
code: string;
map: SourceMap;
}