2021-03-16 20:08:11 +00:00
|
|
|
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;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Fragment extends BaseNode {
|
2021-03-16 20:54:58 +00:00
|
|
|
type: 'Fragment';
|
|
|
|
children: TemplateNode[];
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Text extends BaseNode {
|
2021-03-16 20:54:58 +00:00
|
|
|
type: 'Text';
|
|
|
|
data: string;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface MustacheTag extends BaseNode {
|
2021-03-16 20:54:58 +00:00
|
|
|
type: 'MustacheTag';
|
|
|
|
expression: string;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 20:54:58 +00:00
|
|
|
export type DirectiveType = 'Action' | 'Animation' | 'Binding' | 'Class' | 'EventHandler' | 'Let' | 'Ref' | 'Transition';
|
2021-03-16 20:08:11 +00:00
|
|
|
|
|
|
|
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:08:11 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 20:54:58 +00:00
|
|
|
export interface Transition extends BaseDirective {
|
|
|
|
type: 'Transition';
|
|
|
|
intro: boolean;
|
|
|
|
outro: boolean;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type Directive = BaseDirective | Transition;
|
|
|
|
|
2021-03-16 20:54:58 +00:00
|
|
|
export type TemplateNode = Text | MustacheTag | BaseNode | Directive | Transition;
|
2021-03-16 20:08:11 +00:00
|
|
|
|
|
|
|
export interface Parser {
|
2021-03-16 20:54:58 +00:00
|
|
|
readonly template: string;
|
|
|
|
readonly filename?: string;
|
2021-03-16 20:08:11 +00:00
|
|
|
|
2021-03-16 20:54:58 +00:00
|
|
|
index: number;
|
|
|
|
stack: Node[];
|
2021-03-16 20:08:11 +00:00
|
|
|
|
2021-03-16 20:54:58 +00:00
|
|
|
html: Node;
|
|
|
|
css: Node;
|
|
|
|
js: Node;
|
|
|
|
meta_tags: {};
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Script extends BaseNode {
|
2021-03-16 20:54:58 +00:00
|
|
|
type: 'Script';
|
|
|
|
context: string;
|
|
|
|
content: string;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Ast {
|
2021-03-16 20:54:58 +00:00
|
|
|
html: TemplateNode;
|
|
|
|
css: Style;
|
|
|
|
instance: Script;
|
|
|
|
module: Script;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-03-16 20:08:11 +00:00
|
|
|
|
|
|
|
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;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ParserOptions {
|
2021-03-16 20:54:58 +00:00
|
|
|
filename?: string;
|
|
|
|
customElement?: boolean;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Visitor {
|
2021-03-16 20:54:58 +00:00
|
|
|
enter: (node: Node) => void;
|
|
|
|
leave?: (node: Node) => void;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface AppendTarget {
|
2021-03-16 20:54:58 +00:00
|
|
|
slots: Record<string, string>;
|
|
|
|
slot_stack: string[];
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CssResult {
|
2021-03-16 20:54:58 +00:00
|
|
|
code: string;
|
|
|
|
map: SourceMap;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|