2021-03-25 07:00:22 +00:00
|
|
|
import type { SourceMap } from 'magic-string';
|
2021-06-02 15:53:24 +00:00
|
|
|
export { CompileError } from './utils/error';
|
2021-03-16 20:08:11 +00:00
|
|
|
|
2021-04-09 18:09:13 +00:00
|
|
|
export 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-31 20:46:09 +00:00
|
|
|
raw: string;
|
|
|
|
}
|
|
|
|
|
2021-05-17 14:29:16 +00:00
|
|
|
export interface CodeFence extends BaseNode {
|
|
|
|
type: 'CodeFence';
|
|
|
|
metadata: string;
|
|
|
|
data: string;
|
|
|
|
raw: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CodeSpan extends BaseNode {
|
|
|
|
type: 'CodeFence';
|
|
|
|
metadata: string;
|
|
|
|
data: string;
|
|
|
|
raw: string;
|
|
|
|
}
|
|
|
|
|
2021-03-31 20:46:09 +00:00
|
|
|
export interface Attribute extends BaseNode {
|
|
|
|
type: 'Attribute';
|
|
|
|
name: string;
|
|
|
|
value: Text[];
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface MustacheTag extends BaseNode {
|
2021-03-16 20:54:58 +00:00
|
|
|
type: 'MustacheTag';
|
2021-03-25 07:00:22 +00:00
|
|
|
content: 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-05-17 14:29:16 +00:00
|
|
|
export type TemplateNode = Text | CodeSpan | CodeFence | MustacheTag | BaseNode | Directive | Transition;
|
2021-03-16 20:08:11 +00:00
|
|
|
|
2021-04-09 18:09:13 +00:00
|
|
|
export interface Expression {
|
|
|
|
type: 'Expression';
|
|
|
|
start: number;
|
|
|
|
end: number;
|
2021-04-22 19:10:06 +00:00
|
|
|
codeChunks: string[];
|
2021-04-09 18:09:13 +00:00
|
|
|
children: BaseNode[];
|
|
|
|
}
|
|
|
|
|
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;
|
2021-03-31 19:04:18 +00:00
|
|
|
meta_tags: Map<string, string>;
|
2021-03-16 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
module: Script;
|
2021-03-21 07:44:42 +00:00
|
|
|
// instance: Script;
|
2021-07-01 12:42:07 +00:00
|
|
|
meta: {
|
|
|
|
features: number;
|
2021-07-07 20:10:09 +00:00
|
|
|
};
|
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 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
|
|
|
}
|