File size: 18,891 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
import type ESTree from "estree";
import type { TSESTree } from "@typescript-eslint/types";
import type { BaseNode } from "./base";
import type { Token, Comment } from "./common";
export type SvelteHTMLNode = SvelteProgram | SvelteScriptElement | SvelteStyleElement | SvelteElement | SvelteStartTag | SvelteEndTag | SvelteName | SvelteMemberExpressionName | SvelteText | SvelteLiteral | SvelteMustacheTag | SvelteDebugTag | SvelteConstTag | SvelteRenderTag | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock | SvelteAwaitBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock | SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective | SvelteStyleDirective | SvelteSpecialDirective | SvelteGenericsDirective | SvelteDirectiveKey | SvelteSpecialDirectiveKey | SvelteHTMLComment;
/** Node of Svelte program root */
export interface SvelteProgram extends BaseNode {
type: "Program";
body: (SvelteScriptElement | SvelteStyleElement | Child)[];
sourceType: "script" | "module";
comments: Comment[];
tokens: Token[];
parent: null;
}
/** Node of elements like HTML element. */
export type SvelteElement = SvelteHTMLElement | SvelteComponentElement | SvelteSpecialElement;
type BaseSvelteElement = BaseNode;
/** Node of `<script>` element. */
export interface SvelteScriptElement extends BaseSvelteElement {
type: "SvelteScriptElement";
name: SvelteName;
startTag: SvelteStartTag;
body: ESTree.Program["body"];
endTag: SvelteEndTag | null;
parent: SvelteProgram;
}
/** Node of `<style>` element. */
export interface SvelteStyleElement extends BaseSvelteElement {
type: "SvelteStyleElement";
name: SvelteName;
startTag: SvelteStartTag;
children: [SvelteText];
endTag: SvelteEndTag | null;
parent: SvelteProgram;
}
/** Node of HTML element. */
export interface SvelteHTMLElement extends BaseSvelteElement {
type: "SvelteElement";
kind: "html";
name: SvelteName;
startTag: SvelteStartTag;
children: Child[];
endTag: SvelteEndTag | null;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of Svelte component element. */
export interface SvelteComponentElement extends BaseSvelteElement {
type: "SvelteElement";
kind: "component";
name: ESTree.Identifier | SvelteMemberExpressionName;
startTag: SvelteStartTag;
children: Child[];
endTag: SvelteEndTag | null;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of Svelte special component element. e.g. `<svelte:window>` */
export interface SvelteSpecialElement extends BaseSvelteElement {
type: "SvelteElement";
kind: "special";
name: SvelteName;
startTag: SvelteStartTag;
children: Child[];
endTag: SvelteEndTag | null;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of start tag. */
export interface SvelteStartTag extends BaseNode {
type: "SvelteStartTag";
attributes: (SvelteAttribute | SvelteShorthandAttribute | SvelteSpreadAttribute | SvelteDirective | SvelteStyleDirective | SvelteSpecialDirective | SvelteGenericsDirective)[];
selfClosing: boolean;
parent: SvelteElement | SvelteScriptElement | SvelteStyleElement;
}
/** Node of end tag. */
export interface SvelteEndTag extends BaseNode {
type: "SvelteEndTag";
parent: SvelteElement | SvelteScriptElement | SvelteStyleElement;
}
/** Node of names. It is used for element names other than components and normal attribute names. */
export interface SvelteName extends BaseNode {
type: "SvelteName";
name: string;
parent: SvelteElement | SvelteScriptElement | SvelteStyleElement | SvelteAttribute | SvelteMemberExpressionName | SvelteDirectiveKey;
}
/** Nodes that may be used in component names. The component names separated by dots. */
export interface SvelteMemberExpressionName extends BaseNode {
type: "SvelteMemberExpressionName";
object: SvelteMemberExpressionName | ESTree.Identifier;
property: SvelteName;
parent: SvelteComponentElement;
}
type Child = SvelteElement | SvelteText | SvelteMustacheTag | SvelteDebugTag | SvelteConstTag | SvelteRenderTag | SvelteIfBlockAlone | SvelteEachBlock | SvelteAwaitBlock | SvelteKeyBlock | SvelteSnippetBlock | SvelteHTMLComment;
/** Node of text. like HTML text. */
export interface SvelteText extends BaseNode {
type: "SvelteText";
value: string;
parent: SvelteProgram | SvelteElement | SvelteStyleElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of literal. */
export interface SvelteLiteral extends BaseNode {
type: "SvelteLiteral";
value: string;
parent: SvelteAttribute | SvelteStyleDirective;
}
/** Node of mustache tag. e.g. `{...}`, `{@html ...}`. Like JSXExpressionContainer */
export type SvelteMustacheTag = SvelteMustacheTagText | SvelteMustacheTagRaw;
interface BaseSvelteMustacheTag extends BaseNode {
type: "SvelteMustacheTag";
kind: "text" | "raw";
expression: ESTree.Expression;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock | SvelteAttribute | SvelteStyleDirective;
}
/** Node of mustache tag. e.g. `{...}``. Like JSXExpressionContainer */
export interface SvelteMustacheTagText extends BaseSvelteMustacheTag {
kind: "text";
}
/** Node of mustache tag. e.g. `{@html ...}`. Like JSXExpressionContainer */
export interface SvelteMustacheTagRaw extends BaseSvelteMustacheTag {
kind: "raw";
}
/** Node of debug mustache tag. e.g. `{@debug}` */
export interface SvelteDebugTag extends BaseNode {
type: "SvelteDebugTag";
identifiers: ESTree.Identifier[];
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock | SvelteAttribute;
}
/** Node of const tag. e.g. `{@const}` */
export interface SvelteConstTag extends BaseNode {
type: "SvelteConstTag";
declaration: ESTree.VariableDeclarator;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock | SvelteAttribute;
}
/** Node of render tag. e.g. `{@render}` */
export interface SvelteRenderTag extends BaseNode {
type: "SvelteRenderTag";
expression: ESTree.SimpleCallExpression | (ESTree.ChainExpression & {
expression: ESTree.SimpleCallExpression;
});
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of if block. e.g. `{#if}` */
export type SvelteIfBlock = SvelteIfBlockAlone | SvelteIfBlockElseIf;
interface BaseSvelteIfBlock extends BaseNode {
type: "SvelteIfBlock";
elseif: boolean;
expression: ESTree.Expression;
children: Child[];
else: SvelteElseBlock | null;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of if block. e.g. `{#if}` */
export interface SvelteIfBlockAlone extends BaseSvelteIfBlock {
elseif: false;
parent: Exclude<BaseSvelteIfBlock["parent"], SvelteElseBlockElseIf>;
}
/** Node of if block. e.g. `{:else if}` */
export interface SvelteIfBlockElseIf extends BaseSvelteIfBlock {
elseif: true;
parent: SvelteElseBlockElseIf;
}
/** Node of else block. e.g. `{:else}` */
export type SvelteElseBlock = SvelteElseBlockAlone | SvelteElseBlockElseIf;
interface BaseSvelteElseBlock extends BaseNode {
type: "SvelteElseBlock";
elseif: boolean;
children: (Child | SvelteIfBlockElseIf)[];
parent: SvelteIfBlock | SvelteEachBlock;
}
/** Node of else block. e.g. `{:else}` */
export interface SvelteElseBlockAlone extends BaseSvelteElseBlock {
elseif: false;
children: Child[];
}
/** Node of else block. e.g. `{:else if ...}` */
export interface SvelteElseBlockElseIf extends BaseSvelteElseBlock {
elseif: true;
children: [SvelteIfBlockElseIf];
}
/** Node of each block. e.g. `{#each}` */
export interface SvelteEachBlock extends BaseNode {
type: "SvelteEachBlock";
expression: ESTree.Expression;
context: ESTree.Pattern;
index: ESTree.Identifier | null;
key: ESTree.Expression | null;
children: Child[];
else: SvelteElseBlockAlone | null;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of await block. e.g. `{#await}`, `{#await ... then ... }`, `{#await ... catch ... }` */
export type SvelteAwaitBlock = SvelteAwaitBlockAwaitPending | SvelteAwaitBlockAwaitThen | SvelteAwaitBlockAwaitCatch;
interface BaseSvelteAwaitBlock extends BaseNode {
type: "SvelteAwaitBlock";
expression: ESTree.Expression;
kind: "await" | "await-then" | "await-catch";
pending: SvelteAwaitPendingBlock | null;
then: SvelteAwaitThenBlock | null;
catch: SvelteAwaitCatchBlock | null;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of await block. e.g. `{#await}` */
export interface SvelteAwaitBlockAwaitPending extends BaseSvelteAwaitBlock {
kind: "await";
pending: SvelteAwaitPendingBlock;
then: SvelteAwaitThenBlockAlone | null;
catch: SvelteAwaitCatchBlockAlone | null;
}
/** Node of await block. e.g. `{#await ... then ... }` */
export interface SvelteAwaitBlockAwaitThen extends BaseSvelteAwaitBlock {
kind: "await-then";
pending: null;
then: SvelteAwaitThenBlockAwaitThen;
catch: SvelteAwaitCatchBlockAlone | null;
}
/** Node of await block. e.g. `{#await ... catch ... }` */
export interface SvelteAwaitBlockAwaitCatch extends BaseSvelteAwaitBlock {
kind: "await-catch";
pending: null;
then: null;
catch: SvelteAwaitCatchBlockAwaitCatch;
}
/** Node of await pending block. e.g. `{#await expr} ... {:then}` */
export interface SvelteAwaitPendingBlock extends BaseNode {
type: "SvelteAwaitPendingBlock";
children: Child[];
parent: SvelteAwaitBlock;
}
/** Node of await then block. e.g. `{:then}`, `{#await ... then ...}` */
export type SvelteAwaitThenBlock = SvelteAwaitThenBlockAlone | SvelteAwaitThenBlockAwaitThen;
interface BaseSvelteAwaitThenBlock extends BaseNode {
type: "SvelteAwaitThenBlock";
awaitThen: boolean;
value: ESTree.Pattern | null;
children: Child[];
parent: SvelteAwaitBlock;
}
/** Node of await then block. e.g. `{:then}` */
export interface SvelteAwaitThenBlockAlone extends BaseSvelteAwaitThenBlock {
awaitThen: false;
parent: SvelteAwaitBlockAwaitPending;
}
/** Node of await then block. e.g. `{#await ... then ...}` */
export interface SvelteAwaitThenBlockAwaitThen extends BaseSvelteAwaitThenBlock {
awaitThen: true;
parent: SvelteAwaitBlockAwaitThen;
}
/** Node of await catch block. e.g. `{:catch}`, `{#await ... catch ... }` */
export type SvelteAwaitCatchBlock = SvelteAwaitCatchBlockAlone | SvelteAwaitCatchBlockAwaitCatch;
interface BaseSvelteAwaitCatchBlock extends BaseNode {
type: "SvelteAwaitCatchBlock";
awaitCatch: boolean;
error: ESTree.Pattern | null;
children: Child[];
parent: SvelteAwaitBlock;
}
/** Node of await catch block. e.g. `{:catch}` */
export interface SvelteAwaitCatchBlockAlone extends BaseSvelteAwaitCatchBlock {
awaitCatch: false;
parent: SvelteAwaitBlockAwaitPending | SvelteAwaitBlockAwaitThen;
}
/** Node of await catch block. e.g. `{#await ... catch ... }` */
export interface SvelteAwaitCatchBlockAwaitCatch extends BaseSvelteAwaitCatchBlock {
awaitCatch: true;
error: ESTree.Pattern | null;
children: Child[];
parent: SvelteAwaitBlockAwaitCatch;
}
/** Node of key block. e.g. `{#key}` */
export interface SvelteKeyBlock extends BaseNode {
type: "SvelteKeyBlock";
expression: ESTree.Expression;
children: Child[];
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of snippet block. e.g. `{#snippet}` */
export interface SvelteSnippetBlock extends BaseNode {
type: "SvelteSnippetBlock";
id: ESTree.Identifier;
params: ESTree.Pattern[];
children: Child[];
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of HTML comment. */
export interface SvelteHTMLComment extends BaseNode {
type: "SvelteHTMLComment";
value: string;
parent: SvelteProgram | SvelteElement | SvelteIfBlock | SvelteElseBlockAlone | SvelteEachBlock | SvelteAwaitPendingBlock | SvelteAwaitThenBlock | SvelteAwaitCatchBlock | SvelteKeyBlock | SvelteSnippetBlock;
}
/** Node of HTML attribute. */
export interface SvelteAttribute extends BaseNode {
type: "SvelteAttribute";
key: SvelteName;
boolean: boolean;
value: (SvelteLiteral | SvelteMustacheTagText)[];
parent: SvelteStartTag;
}
/** Node of shorthand attribute. e.g. `<img {src}>` */
export interface SvelteShorthandAttribute extends BaseNode {
type: "SvelteShorthandAttribute";
key: ESTree.Identifier;
value: ESTree.Identifier;
parent: SvelteStartTag;
}
/** Node of spread attribute. e.g. `<Info {...pkg}/>`. Like JSXSpreadAttribute */
export interface SvelteSpreadAttribute extends BaseNode {
type: "SvelteSpreadAttribute";
argument: ESTree.Expression;
parent: SvelteStartTag;
}
/** Node of directive. e.g. `<input bind:value />` */
export type SvelteDirective = SvelteActionDirective | SvelteAnimationDirective | SvelteBindingDirective | SvelteClassDirective | SvelteEventHandlerDirective | SvelteLetDirective | SvelteRefDirective | SvelteTransitionDirective;
export type SvelteDirectiveKey = SvelteDirectiveKeyTextName | SvelteDirectiveKeyFunctionName | SvelteDirectiveKeyForEventHandler | SvelteDirectiveKeyForAction | SvelteDirectiveKeyForStyleShorthand;
interface BaseSvelteDirectiveKey<N extends ESTree.Expression | SvelteName> extends BaseNode {
type: "SvelteDirectiveKey";
name: N;
modifiers: string[];
parent: SvelteDirective | SvelteStyleDirective;
}
export type SvelteDirectiveKeyTextName = BaseSvelteDirectiveKey<SvelteName>;
export type SvelteDirectiveKeyFunctionName = BaseSvelteDirectiveKey<ESTree.Identifier>;
export type SvelteDirectiveKeyForEventHandler = BaseSvelteDirectiveKey<SvelteName>;
export type SvelteDirectiveKeyForAction = BaseSvelteDirectiveKey<ESTree.Identifier | ESTree.MemberExpression | SvelteName>;
export type SvelteDirectiveKeyForStyleShorthand = BaseSvelteDirectiveKey<ESTree.Identifier>;
interface BaseSvelteDirective extends BaseNode {
type: "SvelteDirective";
key: SvelteDirectiveKey;
parent: SvelteStartTag;
}
export interface SvelteActionDirective extends BaseSvelteDirective {
kind: "Action";
key: SvelteDirectiveKeyForAction;
expression: null | ESTree.Expression;
}
export interface SvelteAnimationDirective extends BaseSvelteDirective {
kind: "Animation";
key: SvelteDirectiveKeyFunctionName;
expression: null | ESTree.Expression;
}
export interface SvelteBindingDirective extends BaseSvelteDirective {
kind: "Binding";
key: SvelteDirectiveKeyTextName;
shorthand: boolean;
expression: null | ESTree.Expression;
}
export interface SvelteClassDirective extends BaseSvelteDirective {
kind: "Class";
key: SvelteDirectiveKeyTextName;
shorthand: boolean;
expression: null | ESTree.Expression;
}
export interface SvelteEventHandlerDirective extends BaseSvelteDirective {
kind: "EventHandler";
key: SvelteDirectiveKeyForEventHandler;
expression: null | ESTree.Expression;
}
export interface SvelteLetDirective extends BaseSvelteDirective {
kind: "Let";
key: SvelteDirectiveKeyTextName;
expression: null | ESTree.Pattern;
}
export interface SvelteRefDirective extends BaseSvelteDirective {
kind: "Ref";
key: SvelteDirectiveKeyTextName;
expression: null | ESTree.Expression;
}
export interface SvelteTransitionDirective extends BaseSvelteDirective {
kind: "Transition";
key: SvelteDirectiveKeyFunctionName;
intro: boolean;
outro: boolean;
expression: null | ESTree.Expression;
}
/** Node of style directive. e.g. `<input style:color />` */
export type SvelteStyleDirective = SvelteStyleDirectiveShorthand | SvelteStyleDirectiveLongform;
interface BaseSvelteStyleDirective extends BaseNode {
type: "SvelteStyleDirective";
key: SvelteDirectiveKeyTextName | SvelteDirectiveKeyForStyleShorthand;
value: (SvelteLiteral | SvelteMustacheTagText)[];
parent: SvelteStartTag;
}
export interface SvelteStyleDirectiveShorthand extends BaseSvelteStyleDirective {
key: SvelteDirectiveKeyForStyleShorthand;
shorthand: true;
value: [];
}
export interface SvelteStyleDirectiveLongform extends BaseSvelteStyleDirective {
key: SvelteDirectiveKeyTextName;
shorthand: false;
value: (SvelteLiteral | SvelteMustacheTagText)[];
}
export interface SvelteSpecialDirectiveKey extends BaseNode {
type: "SvelteSpecialDirectiveKey";
parent: SvelteSpecialDirective;
}
export interface SvelteSpecialDirective extends BaseNode {
type: "SvelteSpecialDirective";
kind: "this";
key: SvelteSpecialDirectiveKey;
expression: ESTree.Expression;
parent: SvelteStartTag;
}
export interface SvelteGenericsDirective extends BaseNode {
type: "SvelteGenericsDirective";
key: SvelteName & {
name: "generics";
};
params: TSESTree.TSTypeParameterDeclaration["params"];
parent: SvelteStartTag;
}
export {};
|