astro/src/compiler/interfaces.ts

164 lines
3.4 KiB
TypeScript
Raw Normal View History

import { Node, Program } from 'estree';
import { SourceMap } from 'magic-string';
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;
}
export interface MustacheTag extends BaseNode {
2021-03-16 20:54:58 +00:00
type: 'MustacheTag';
expression: 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 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: {};
}
export interface Script extends BaseNode {
2021-03-16 20:54:58 +00:00
type: 'Script';
context: string;
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;
instance: Script;
module: 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 CompileOptions {
2021-03-16 20:54:58 +00:00
format?: ModuleFormat;
name?: string;
filename?: string;
generate?: 'dom' | 'ssr' | false;
sourcemap?: object | string;
outputFilename?: string;
cssOutputFilename?: string;
sveltePath?: string;
dev?: boolean;
accessors?: boolean;
immutable?: boolean;
hydratable?: boolean;
legacy?: boolean;
customElement?: boolean;
tag?: string;
css?: boolean;
loopGuardTimeout?: number;
namespace?: string;
cssHash?: CssHashGetter;
preserveComments?: boolean;
preserveWhitespace?: boolean;
}
export interface ParserOptions {
2021-03-16 20:54:58 +00:00
filename?: string;
customElement?: boolean;
}
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;
}