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

164 lines
3.3 KiB
TypeScript
Raw Normal View History

import type { SourceMap } from 'magic-string';
export { 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;
}
Fix markdown issues (#208) * Init fix/markdown * Astro Markdown (#207) * Add Astro Markdown to VSCode Extension * Add Astro Markdown to Astro * refactor: update astro-markdown example * feat: remove embedded components from `.md` files * fix: resolve `.md.astro` files at runtime * chore: update markdown tests * feat: add <Markdown> component * chore: bump examples * chore: update example * fix: improve Markdown child handling * feat: harden markdown support, add code fence support, add automatic dedenting * chore: add weird markdown edge cases * chore: update remote-markdown examples * chore: add comment to Markdown.astro * feat: improve markdown support (codefences, nested inside HTML) * refactor: extract import specifier types to set * refactor: conditionally import markdown renderer * refactor: revert special-cased "astro/components" * refactor: revert special-cased "astro/components" * refactor: use astro/components/Markdown.astro * refactor: remove `.md.astro` support in favor of Markdown component * refactor: use regular .astro files * refactor: remove unused code * refactor: move Markdown inside Layout * wip: markdown scoped styles * feat: improve scoped styles in Markdown * feat: micromark => remark ecosystem * fix: markdown build * fix: markdown build * chore: add todo * fix: collect headers text * docs: add Markdown doc * chore: add changeset * docs: improve Markdown highlighting * refactor: prefer Set * refactor: exclude large unified deps * docs: update markdown docs Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com> * chore: remove extra markdown deps * perf: optimize markdown * fix: unified/rehype deps * temp: fix markdown test * test: add TODO comment * fix: do not namespace frontmatter, just astro metadata * test: fix astro-markdown test * test: add realworld markdown example * fix: prism language bug * docs: update markdown docs * chore: bump dependencies * fix: escape codespan * fix: unterminated string literal * fix(vscode): inline dependencies * fix(vscode): dependencies * feat(vscode): embedded markdown * feat: add Markdown syntax highlighting * chore: improve markdown example * fix: markdown example * feat: highlighting improvements * chore: add changeset * fix: CodeBlock => CodeSpan * chore: get astro-markdown example running Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com>
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;
}
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;
Fix markdown issues (#208) * Init fix/markdown * Astro Markdown (#207) * Add Astro Markdown to VSCode Extension * Add Astro Markdown to Astro * refactor: update astro-markdown example * feat: remove embedded components from `.md` files * fix: resolve `.md.astro` files at runtime * chore: update markdown tests * feat: add <Markdown> component * chore: bump examples * chore: update example * fix: improve Markdown child handling * feat: harden markdown support, add code fence support, add automatic dedenting * chore: add weird markdown edge cases * chore: update remote-markdown examples * chore: add comment to Markdown.astro * feat: improve markdown support (codefences, nested inside HTML) * refactor: extract import specifier types to set * refactor: conditionally import markdown renderer * refactor: revert special-cased "astro/components" * refactor: revert special-cased "astro/components" * refactor: use astro/components/Markdown.astro * refactor: remove `.md.astro` support in favor of Markdown component * refactor: use regular .astro files * refactor: remove unused code * refactor: move Markdown inside Layout * wip: markdown scoped styles * feat: improve scoped styles in Markdown * feat: micromark => remark ecosystem * fix: markdown build * fix: markdown build * chore: add todo * fix: collect headers text * docs: add Markdown doc * chore: add changeset * docs: improve Markdown highlighting * refactor: prefer Set * refactor: exclude large unified deps * docs: update markdown docs Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com> * chore: remove extra markdown deps * perf: optimize markdown * fix: unified/rehype deps * temp: fix markdown test * test: add TODO comment * fix: do not namespace frontmatter, just astro metadata * test: fix astro-markdown test * test: add realworld markdown example * fix: prism language bug * docs: update markdown docs * chore: bump dependencies * fix: escape codespan * fix: unterminated string literal * fix(vscode): inline dependencies * fix(vscode): dependencies * feat(vscode): embedded markdown * feat: add Markdown syntax highlighting * chore: improve markdown example * fix: markdown example * feat: highlighting improvements * chore: add changeset * fix: CodeBlock => CodeSpan * chore: get astro-markdown example running Co-authored-by: Jonathan Neal <jonathantneal@hotmail.com>
2021-05-17 14:29:16 +00:00
export type TemplateNode = Text | CodeSpan | CodeFence | 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[];
2021-03-16 20:54:58 +00:00
module: Script;
2021-03-21 07:44:42 +00:00
// instance: Script;
meta: {
features: number;
2021-07-07 20:10:09 +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;
}
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;
}