feat: provide AST node types with internal types stripped out (alternative) (#12968)

Uses new dts-buddy capabilities and the corresponding tsconfig option to strip away types/properties (and their dependencies) that are marked with `@internal`

Also hides the legacy AST types from the output

To not clutter the exports, the AST types are moved into a namespace named AST

closes #12292
pull/13085/head
Simon H 1 year ago committed by GitHub
parent b70d12c2e3
commit 2d03dc55c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: provide AST node types with internal types stripped out

@ -123,7 +123,7 @@
"@rollup/plugin-virtual": "^3.0.2",
"@types/aria-query": "^5.0.4",
"@types/node": "^20.11.5",
"dts-buddy": "^0.5.1",
"dts-buddy": "^0.5.3",
"esbuild": "^0.21.5",
"rollup": "^4.21.0",
"source-map": "^0.7.4",

@ -21,6 +21,10 @@ fs.writeFileSync(`${dir}/types/compiler/interfaces.d.ts`, "import '../index.js';
await createBundle({
output: `${dir}/types/index.d.ts`,
compilerOptions: {
// so that types/properties with `@internal` (and its dependencies) are removed from the output
stripInternal: true
},
modules: {
[pkg.name]: `${dir}/src/index.d.ts`,
[`${pkg.name}/action`]: `${dir}/src/action/public.d.ts`,

@ -1,5 +1,6 @@
/** @import { LegacyRoot } from './types/legacy-nodes.js' */
/** @import { CompileOptions, CompileResult, ValidatedCompileOptions, ModuleCompileOptions, Root } from '#compiler' */
/** @import { CompileOptions, CompileResult, ValidatedCompileOptions, ModuleCompileOptions } from '#compiler' */
/** @import { AST } from './public.js' */
import { walk as zimmerframe_walk } from 'zimmerframe';
import { convert } from './legacy.js';
import { parse as parse_acorn } from './phases/1-parse/acorn.js';
@ -77,7 +78,7 @@ export function compileModule(source, options) {
* @overload
* @param {string} source
* @param {{ filename?: string; modern: true }} options
* @returns {Root}
* @returns {AST.Root}
*/
/**
@ -90,7 +91,7 @@ export function compileModule(source, options) {
* @overload
* @param {string} source
* @param {{ filename?: string; modern?: false }} [options]
* @returns {LegacyRoot}
* @returns {Record<string, any>}
*/
/**
@ -102,7 +103,7 @@ export function compileModule(source, options) {
* https://svelte.dev/docs/svelte-compiler#svelte-parse
* @param {string} source
* @param {{ filename?: string; rootDir?: string; modern?: boolean }} [options]
* @returns {Root | LegacyRoot}
* @returns {AST.Root | LegacyRoot}
*/
export function parse(source, { filename, rootDir, modern } = {}) {
state.reset_warning_filter(() => false);
@ -114,7 +115,7 @@ export function parse(source, { filename, rootDir, modern } = {}) {
/**
* @param {string} source
* @param {Root} ast
* @param {AST.Root} ast
* @param {boolean | undefined} modern
*/
function to_public_ast(source, ast, modern) {

@ -1,5 +1,5 @@
/** @import { Expression } from 'estree' */
/** @import { BaseNode, ConstTag, Root, SvelteNode, TemplateNode, Text } from '#compiler' */
/** @import { AST, SvelteNode, TemplateNode } from '#compiler' */
/** @import * as Legacy from './types/legacy-nodes.js' */
import { walk } from 'zimmerframe';
import {
@ -36,7 +36,7 @@ function remove_surrounding_whitespace_nodes(nodes) {
/**
* Transform our nice modern AST into the monstrosity emitted by Svelte 4
* @param {string} source
* @param {Root} ast
* @param {AST.Root} ast
* @returns {Legacy.LegacyRoot}
*/
export function convert(source, ast) {
@ -74,8 +74,8 @@ export function convert(source, ast) {
let end = null;
if (node.fragment.nodes.length > 0) {
const first = /** @type {BaseNode} */ (node.fragment.nodes.at(0));
const last = /** @type {BaseNode} */ (node.fragment.nodes.at(-1));
const first = /** @type {AST.BaseNode} */ (node.fragment.nodes.at(0));
const last = /** @type {AST.BaseNode} */ (node.fragment.nodes.at(-1));
start = first.start;
end = last.end;
@ -242,7 +242,7 @@ export function convert(source, ast) {
return node;
}
const modern_node = /** @type {ConstTag} */ (node);
const modern_node = /** @type {AST.ConstTag} */ (node);
const { id: left } = { ...modern_node.declaration.declarations[0] };
// @ts-ignore
delete left.typeAnnotation;
@ -584,7 +584,7 @@ export function convert(source, ast) {
const parent = path.at(-1);
if (parent?.type === 'RegularElement' && parent.name === 'style') {
// these text nodes are missing `raw` for some dumb reason
return /** @type {Text} */ ({
return /** @type {AST.Text} */ ({
type: 'Text',
start: node.start,
end: node.end,

@ -2,7 +2,7 @@
/** @import { Visitors } from 'zimmerframe' */
/** @import { ComponentAnalysis } from '../phases/types.js' */
/** @import { Scope } from '../phases/scope.js' */
/** @import * as Compiler from '#compiler' */
/** @import { AST, Binding, SvelteNode, ValidatedCompileOptions } from '#compiler' */
import MagicString from 'magic-string';
import { walk } from 'zimmerframe';
import { parse } from '../phases/1-parse/index.js';
@ -30,7 +30,7 @@ export function migrate(source) {
const { customElement: customElementOptions, ...parsed_options } = parsed.options || {};
/** @type {Compiler.ValidatedCompileOptions} */
/** @type {ValidatedCompileOptions} */
const combined_options = {
...validate_component_options({}, ''),
...parsed_options,
@ -160,7 +160,7 @@ export function migrate(source) {
let needs_reordering = false;
for (const [node, { dependencies }] of state.analysis.reactive_statements) {
/** @type {Compiler.Binding[]} */
/** @type {Binding[]} */
let ids = [];
if (
node.body.type === 'ExpressionStatement' &&
@ -229,7 +229,7 @@ export function migrate(source) {
* }} State
*/
/** @type {Visitors<Compiler.SvelteNode, State>} */
/** @type {Visitors<SvelteNode, State>} */
const instance_script = {
_(node, { state, next }) {
// @ts-expect-error
@ -335,7 +335,7 @@ const instance_script = {
// }
}
const binding = /** @type {Compiler.Binding} */ (state.scope.get(declarator.id.name));
const binding = /** @type {Binding} */ (state.scope.get(declarator.id.name));
if (state.analysis.uses_props && (declarator.init || binding.updated)) {
throw new Error(
@ -478,7 +478,7 @@ const instance_script = {
}
};
/** @type {Visitors<Compiler.SvelteNode, State>} */
/** @type {Visitors<SvelteNode, State>} */
const template = {
Identifier(node, { state, path }) {
handle_identifier(node, state, path);
@ -596,7 +596,7 @@ const template = {
/**
* @param {VariableDeclarator} declarator
* @param {MagicString} str
* @param {Array<Compiler.SvelteNode>} path
* @param {SvelteNode[]} path
*/
function extract_type_and_comment(declarator, str, path) {
const parent = path.at(-1);
@ -641,11 +641,11 @@ function extract_type_and_comment(declarator, str, path) {
}
/**
* @param {Compiler.RegularElement | Compiler.SvelteElement | Compiler.SvelteWindow | Compiler.SvelteDocument | Compiler.SvelteBody} element
* @param {AST.RegularElement | AST.SvelteElement | AST.SvelteWindow | AST.SvelteDocument | AST.SvelteBody} element
* @param {State} state
*/
function handle_events(element, state) {
/** @type {Map<string, Compiler.OnDirective[]>} */
/** @type {Map<string, AST.OnDirective[]>} */
const handlers = new Map();
for (const attribute of element.attributes) {
if (attribute.type !== 'OnDirective') continue;
@ -880,7 +880,7 @@ function get_node_range(source, node) {
}
/**
* @param {Compiler.OnDirective} last
* @param {AST.OnDirective} last
* @param {State} state
*/
function generate_event_name(last, state) {

@ -1,4 +1,4 @@
/** @import { TemplateNode, Fragment, Root, SvelteOptionsRaw } from '#compiler' */
/** @import { AST, TemplateNode } from '#compiler' */
// @ts-expect-error acorn type definitions are borked in the release we use
import { isIdentifierStart, isIdentifierChar } from 'acorn';
import fragment from './state/fragment.js';
@ -31,10 +31,10 @@ export class Parser {
/** @type {TemplateNode[]} */
stack = [];
/** @type {Fragment[]} */
/** @type {AST.Fragment[]} */
fragments = [];
/** @type {Root} */
/** @type {AST.Root} */
root;
/** @type {Record<string, boolean>} */
@ -122,7 +122,7 @@ export class Parser {
(thing) => thing.type === 'SvelteOptions'
);
if (options_index !== -1) {
const options = /** @type {SvelteOptionsRaw} */ (this.root.fragment.nodes[options_index]);
const options = /** @type {AST.SvelteOptionsRaw} */ (this.root.fragment.nodes[options_index]);
this.root.fragment.nodes.splice(options_index, 1);
this.root.options = read_options(options);
@ -292,7 +292,7 @@ export class Parser {
/**
* @param {string} template
* @returns {Root}
* @returns {AST.Root}
*/
export function parse(template) {
const parser = new Parser(template);

@ -1,16 +1,16 @@
/** @import { ObjectExpression } from 'estree' */
/** @import { SvelteOptionsRaw, Root, SvelteOptions } from '#compiler' */
/** @import { AST } from '#compiler' */
import { NAMESPACE_MATHML, NAMESPACE_SVG } from '../../../../constants.js';
import * as e from '../../../errors.js';
const regex_valid_tag_name = /^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/;
/**
* @param {SvelteOptionsRaw} node
* @returns {Root['options']}
* @param {AST.SvelteOptionsRaw} node
* @returns {AST.Root['options']}
*/
export default function read_options(node) {
/** @type {SvelteOptions} */
/** @type {AST.SvelteOptions} */
const component_options = {
start: node.start,
end: node.end,
@ -39,7 +39,7 @@ export default function read_options(node) {
break; // eslint doesn't know this is unnecessary
}
case 'customElement': {
/** @type {SvelteOptions['customElement']} */
/** @type {AST.SvelteOptions['customElement']} */
const ce = {};
const { value: v } = attribute;
const value = v === true || Array.isArray(v) ? v : [v];

@ -1,5 +1,5 @@
/** @import { Program } from 'estree' */
/** @import { Attribute, SpreadAttribute, Directive, Script } from '#compiler' */
/** @import { AST, Directive } from '#compiler' */
/** @import { Parser } from '../index.js' */
import * as acorn from '../acorn.js';
import { regex_not_newline_characters } from '../../patterns.js';
@ -16,8 +16,8 @@ const ALLOWED_ATTRIBUTES = ['context', 'generics', 'lang', 'module'];
/**
* @param {Parser} parser
* @param {number} start
* @param {Array<Attribute | SpreadAttribute | Directive>} attributes
* @returns {Script}
* @param {Array<AST.Attribute | AST.SpreadAttribute | Directive>} attributes
* @returns {AST.Script}
*/
export function read_script(parser, start, attributes) {
const script_start = parser.index;
@ -45,7 +45,7 @@ export function read_script(parser, start, attributes) {
/** @type {'default' | 'module'} */
let context = 'default';
for (const attribute of /** @type {Attribute[]} */ (attributes)) {
for (const attribute of /** @type {AST.Attribute[]} */ (attributes)) {
if (RESERVED_ATTRIBUTES.includes(attribute.name)) {
e.script_reserved_attribute(attribute, attribute.name);
}

@ -1,4 +1,4 @@
/** @import { Attribute, SpreadAttribute, Directive, Css } from '#compiler' */
/** @import { AST, Css, Directive } from '#compiler' */
/** @import { Parser } from '../index.js' */
import * as e from '../../../errors.js';
@ -18,7 +18,7 @@ const REGEX_HTML_COMMENT_CLOSE = /-->/;
/**
* @param {Parser} parser
* @param {number} start
* @param {Array<Attribute | SpreadAttribute | Directive>} attributes
* @param {Array<AST.Attribute | AST.SpreadAttribute | Directive>} attributes
* @returns {Css.StyleSheet}
*/
export default function read_style(parser, start, attributes) {

@ -1,5 +1,5 @@
/** @import { Expression } from 'estree' */
/** @import * as Compiler from '#compiler' */
/** @import { AST, Directive, ElementLike, TemplateNode } from '#compiler' */
/** @import { Parser } from '../index.js' */
import { is_void } from '../../../../utils.js';
import read_expression from '../read/expression.js';
@ -26,7 +26,7 @@ const regex_valid_element_name =
const regex_valid_component_name =
/^(?:[A-Z][A-Za-z0-9_$.]*|[a-z][A-Za-z0-9_$]*(?:\.[A-Za-z0-9_$]+)+)$/;
/** @type {Map<string, Compiler.ElementLike['type']>} */
/** @type {Map<string, ElementLike['type']>} */
const root_only_meta_tags = new Map([
['svelte:head', 'SvelteHead'],
['svelte:options', 'SvelteOptions'],
@ -35,7 +35,7 @@ const root_only_meta_tags = new Map([
['svelte:body', 'SvelteBody']
]);
/** @type {Map<string, Compiler.ElementLike['type']>} */
/** @type {Map<string, ElementLike['type']>} */
const meta_tags = new Map([
...root_only_meta_tags,
['svelte:element', 'SvelteElement'],
@ -54,7 +54,7 @@ export default function element(parser) {
const data = parser.read_until(regex_closing_comment);
parser.eat('-->', true);
/** @type {ReturnType<typeof parser.append<Compiler.Comment>>} */
/** @type {ReturnType<typeof parser.append<AST.Comment>>} */
parser.append({
type: 'Comment',
start,
@ -77,7 +77,7 @@ export default function element(parser) {
}
// close any elements that don't have their own closing tags, e.g. <div><p></div>
while (/** @type {Compiler.RegularElement} */ (parent).name !== name) {
while (/** @type {AST.RegularElement} */ (parent).name !== name) {
if (parent.type !== 'RegularElement') {
if (parser.last_auto_closed_tag && parser.last_auto_closed_tag.tag === name) {
e.element_invalid_closing_tag_autoclosed(start, name, parser.last_auto_closed_tag.reason);
@ -135,7 +135,7 @@ export default function element(parser) {
? 'SlotElement'
: 'RegularElement';
/** @type {Compiler.ElementLike} */
/** @type {ElementLike} */
const element =
type === 'RegularElement'
? {
@ -153,7 +153,7 @@ export default function element(parser) {
},
parent: null
}
: /** @type {Compiler.ElementLike} */ ({
: /** @type {ElementLike} */ ({
type,
start,
end: -1,
@ -211,7 +211,7 @@ export default function element(parser) {
e.svelte_component_missing_this(start);
}
const definition = /** @type {Compiler.Attribute} */ (element.attributes.splice(index, 1)[0]);
const definition = /** @type {AST.Attribute} */ (element.attributes.splice(index, 1)[0]);
if (!is_expression_attribute(definition)) {
e.svelte_component_invalid_this(definition.start);
}
@ -228,7 +228,7 @@ export default function element(parser) {
e.svelte_element_missing_this(start);
}
const definition = /** @type {Compiler.Attribute} */ (element.attributes.splice(index, 1)[0]);
const definition = /** @type {AST.Attribute} */ (element.attributes.splice(index, 1)[0]);
if (definition.value === true) {
e.svelte_element_missing_this(definition);
@ -241,9 +241,7 @@ export default function element(parser) {
// it would be much better to just error here, but we are preserving the existing buggy
// Svelte 4 behaviour out of an overabundance of caution regarding breaking changes.
// TODO in 6.0, error
const chunk = /** @type {Array<Compiler.ExpressionTag | Compiler.Text>} */ (
definition.value
)[0];
const chunk = /** @type {Array<AST.ExpressionTag | AST.Text>} */ (definition.value)[0];
element.tag =
chunk.type === 'Text'
? {
@ -262,7 +260,7 @@ export default function element(parser) {
if (is_top_level_script_or_style) {
parser.eat('>', true);
/** @type {Compiler.Comment | null} */
/** @type {AST.Comment | null} */
let prev_comment = null;
for (let i = current.fragment.nodes.length - 1; i >= 0; i--) {
const node = current.fragment.nodes[i];
@ -329,7 +327,7 @@ export default function element(parser) {
const data = parser.read_until(new RegExp(`</${name}>`));
const end = parser.index;
/** @type {Compiler.Text} */
/** @type {AST.Text} */
const node = {
start,
end,
@ -348,7 +346,7 @@ export default function element(parser) {
}
}
/** @param {Compiler.TemplateNode[]} stack */
/** @param {TemplateNode[]} stack */
function parent_is_head(stack) {
let i = stack.length;
while (i--) {
@ -359,14 +357,14 @@ function parent_is_head(stack) {
return false;
}
/** @param {Compiler.TemplateNode[]} stack */
/** @param {TemplateNode[]} stack */
function parent_is_shadowroot_template(stack) {
// https://developer.chrome.com/docs/css-ui/declarative-shadow-dom#building_a_declarative_shadow_root
let i = stack.length;
while (i--) {
if (
stack[i].type === 'RegularElement' &&
/** @type {Compiler.RegularElement} */ (stack[i]).attributes.some(
/** @type {AST.RegularElement} */ (stack[i]).attributes.some(
(a) => a.type === 'Attribute' && a.name === 'shadowrootmode'
)
) {
@ -378,7 +376,7 @@ function parent_is_shadowroot_template(stack) {
/**
* @param {Parser} parser
* @returns {Compiler.Attribute | null}
* @returns {AST.Attribute | null}
*/
function read_static_attribute(parser) {
const start = parser.index;
@ -386,7 +384,7 @@ function read_static_attribute(parser) {
const name = parser.read_until(regex_token_ending_character);
if (!name) return null;
/** @type {true | Array<Compiler.Text | Compiler.ExpressionTag>} */
/** @type {true | Array<AST.Text | AST.ExpressionTag>} */
let value = true;
if (parser.eat('=')) {
@ -424,7 +422,7 @@ function read_static_attribute(parser) {
/**
* @param {Parser} parser
* @returns {Compiler.Attribute | Compiler.SpreadAttribute | Compiler.Directive | null}
* @returns {AST.Attribute | AST.SpreadAttribute | Directive | null}
*/
function read_attribute(parser) {
const start = parser.index;
@ -438,7 +436,7 @@ function read_attribute(parser) {
parser.allow_whitespace();
parser.eat('}', true);
/** @type {Compiler.SpreadAttribute} */
/** @type {AST.SpreadAttribute} */
const spread = {
type: 'SpreadAttribute',
start,
@ -462,7 +460,7 @@ function read_attribute(parser) {
parser.allow_whitespace();
parser.eat('}', true);
/** @type {Compiler.ExpressionTag} */
/** @type {AST.ExpressionTag} */
const expression = {
type: 'ExpressionTag',
start: value_start,
@ -493,7 +491,7 @@ function read_attribute(parser) {
const colon_index = name.indexOf(':');
const type = colon_index !== -1 && get_directive_type(name.slice(0, colon_index));
/** @type {true | Compiler.ExpressionTag | Array<Compiler.Text | Compiler.ExpressionTag>} */
/** @type {true | AST.ExpressionTag | Array<AST.Text | AST.ExpressionTag>} */
let value = true;
if (parser.eat('=')) {
parser.allow_whitespace();
@ -542,7 +540,7 @@ function read_attribute(parser) {
}
}
/** @type {Compiler.Directive} */
/** @type {Directive} */
// @ts-expect-error TODO can't figure out this error
const directive = {
start,
@ -599,7 +597,7 @@ function get_directive_type(name) {
/**
* @param {Parser} parser
* @return {Compiler.ExpressionTag | Array<Compiler.ExpressionTag | Compiler.Text>}
* @return {AST.ExpressionTag | Array<AST.ExpressionTag | AST.Text>}
*/
function read_attribute_value(parser) {
const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
@ -616,7 +614,7 @@ function read_attribute_value(parser) {
];
}
/** @type {Array<Compiler.ExpressionTag | Compiler.Text>} */
/** @type {Array<AST.ExpressionTag | AST.Text>} */
let value;
try {
value = read_sequence(
@ -662,7 +660,7 @@ function read_attribute_value(parser) {
* @returns {any[]}
*/
function read_sequence(parser, done, location) {
/** @type {Compiler.Text} */
/** @type {AST.Text} */
let current_chunk = {
start: parser.index,
end: -1,
@ -672,7 +670,7 @@ function read_sequence(parser, done, location) {
parent: null
};
/** @type {Array<Compiler.Text | Compiler.ExpressionTag>} */
/** @type {Array<AST.Text | AST.ExpressionTag>} */
const chunks = [];
/** @param {number} end */
@ -710,7 +708,7 @@ function read_sequence(parser, done, location) {
parser.allow_whitespace();
parser.eat('}', true);
/** @type {Compiler.ExpressionTag} */
/** @type {AST.ExpressionTag} */
const chunk = {
type: 'ExpressionTag',
start: index,

@ -1,5 +1,5 @@
/** @import { ArrowFunctionExpression, Expression, Identifier } from 'estree' */
/** @import { AwaitBlock, ConstTag, DebugTag, EachBlock, ExpressionTag, HtmlTag, IfBlock, KeyBlock, RenderTag, SnippetBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Parser } from '../index.js' */
import read_pattern from '../read/context.js';
import read_expression from '../read/expression.js';
@ -33,7 +33,7 @@ export default function tag(parser) {
parser.allow_whitespace();
parser.eat('}', true);
/** @type {ReturnType<typeof parser.append<ExpressionTag>>} */
/** @type {ReturnType<typeof parser.append<AST.ExpressionTag>>} */
parser.append({
type: 'ExpressionTag',
start,
@ -53,7 +53,7 @@ function open(parser) {
if (parser.eat('if')) {
parser.require_whitespace();
/** @type {ReturnType<typeof parser.append<IfBlock>>} */
/** @type {ReturnType<typeof parser.append<AST.IfBlock>>} */
const block = parser.append({
type: 'IfBlock',
elseif: false,
@ -174,7 +174,7 @@ function open(parser) {
parser.eat('}', true);
/** @type {ReturnType<typeof parser.append<EachBlock>>} */
/** @type {ReturnType<typeof parser.append<AST.EachBlock>>} */
const block = parser.append({
type: 'EachBlock',
start,
@ -198,7 +198,7 @@ function open(parser) {
const expression = read_expression(parser);
parser.allow_whitespace();
/** @type {ReturnType<typeof parser.append<AwaitBlock>>} */
/** @type {ReturnType<typeof parser.append<AST.AwaitBlock>>} */
const block = parser.append({
type: 'AwaitBlock',
start,
@ -252,7 +252,7 @@ function open(parser) {
parser.eat('}', true);
/** @type {ReturnType<typeof parser.append<KeyBlock>>} */
/** @type {ReturnType<typeof parser.append<AST.KeyBlock>>} */
const block = parser.append({
type: 'KeyBlock',
start,
@ -303,7 +303,7 @@ function open(parser) {
parser.allow_whitespace();
parser.eat('}', true);
/** @type {ReturnType<typeof parser.append<SnippetBlock>>} */
/** @type {ReturnType<typeof parser.append<AST.SnippetBlock>>} */
const block = parser.append({
type: 'SnippetBlock',
start,
@ -355,7 +355,7 @@ function next(parser) {
let elseif_start = start - 1;
while (parser.template[elseif_start] !== '{') elseif_start -= 1;
/** @type {ReturnType<typeof parser.append<IfBlock>>} */
/** @type {ReturnType<typeof parser.append<AST.IfBlock>>} */
const child = parser.append({
start: elseif_start,
end: -1,
@ -451,7 +451,7 @@ function close(parser) {
while (block.elseif) {
block.end = parser.index;
parser.stack.pop();
block = /** @type {IfBlock} */ (parser.current());
block = /** @type {AST.IfBlock} */ (parser.current());
}
block.end = parser.index;
parser.pop();
@ -499,7 +499,7 @@ function special(parser) {
parser.allow_whitespace();
parser.eat('}', true);
/** @type {ReturnType<typeof parser.append<HtmlTag>>} */
/** @type {ReturnType<typeof parser.append<AST.HtmlTag>>} */
parser.append({
type: 'HtmlTag',
start,
@ -537,7 +537,7 @@ function special(parser) {
parser.eat('}', true);
}
/** @type {ReturnType<typeof parser.append<DebugTag>>} */
/** @type {ReturnType<typeof parser.append<AST.DebugTag>>} */
parser.append({
type: 'DebugTag',
start,
@ -570,7 +570,7 @@ function special(parser) {
parser.eat('}', true);
/** @type {ReturnType<typeof parser.append<ConstTag>>} */
/** @type {ReturnType<typeof parser.append<AST.ConstTag>>} */
parser.append({
type: 'ConstTag',
start,
@ -601,7 +601,7 @@ function special(parser) {
parser.allow_whitespace();
parser.eat('}', true);
/** @type {ReturnType<typeof parser.append<RenderTag>>} */
/** @type {ReturnType<typeof parser.append<AST.RenderTag>>} */
parser.append({
type: 'RenderTag',
start,

@ -1,4 +1,4 @@
/** @import { Text } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Parser } from '../index.js' */
import { decode_character_references } from '../utils/html.js';
@ -12,7 +12,7 @@ export default function text(parser) {
data += parser.template[parser.index++];
}
/** @type {ReturnType<typeof parser.append<Text>>} */
/** @type {ReturnType<typeof parser.append<AST.Text>>} */
parser.append({
type: 'Text',
start,

@ -1,7 +1,8 @@
/** @import { Fragment } from '#compiler' */
/** @import { AST } from '#compiler' */
/**
* @param {any} transparent
* @returns {Fragment}
* @returns {AST.Fragment}
*/
export function create_fragment(transparent = false) {
return {

@ -8,7 +8,7 @@ import { get_attribute_chunks, is_text_attribute } from '../../../utils/ast.js';
/**
* @typedef {{
* stylesheet: Compiler.Css.StyleSheet;
* element: Compiler.RegularElement | Compiler.SvelteElement;
* element: Compiler.AST.RegularElement | Compiler.AST.SvelteElement;
* }} State
*/
/** @typedef {NODE_PROBABLY_EXISTS | NODE_DEFINITELY_EXISTS} NodeExistsValue */
@ -53,7 +53,7 @@ const nesting_selector = {
/**
*
* @param {Compiler.Css.StyleSheet} stylesheet
* @param {Compiler.RegularElement | Compiler.SvelteElement} element
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
*/
export function prune(stylesheet, element) {
walk(stylesheet, { stylesheet, element }, visitors);
@ -120,7 +120,7 @@ function truncate(node) {
/**
* @param {Compiler.Css.RelativeSelector[]} relative_selectors
* @param {Compiler.Css.Rule} rule
* @param {Compiler.RegularElement | Compiler.SvelteElement} element
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
* @param {Compiler.Css.StyleSheet} stylesheet
* @returns {boolean}
*/
@ -222,7 +222,7 @@ function apply_selector(relative_selectors, rule, element, stylesheet) {
* Mark both the compound selector and the node it selects as encapsulated,
* for transformation in a later step
* @param {Compiler.Css.RelativeSelector} relative_selector
* @param {Compiler.RegularElement | Compiler.SvelteElement} element
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
*/
function mark(relative_selector, element) {
relative_selector.metadata.scoped = true;
@ -279,7 +279,7 @@ const regex_backslash_and_following_character = /\\(.)/g;
*
* @param {Compiler.Css.RelativeSelector} relative_selector
* @param {Compiler.Css.Rule} rule
* @param {Compiler.RegularElement | Compiler.SvelteElement} element
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
* @param {Compiler.Css.StyleSheet} stylesheet
* @returns {boolean}
*/
@ -435,7 +435,7 @@ function test_attribute(operator, expected_value, case_insensitive, value) {
}
/**
* @param {Compiler.RegularElement | Compiler.SvelteElement} node
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} node
* @param {string} name
* @param {string | null} expected_value
* @param {string | null} operator
@ -542,8 +542,8 @@ function unquote(str) {
}
/**
* @param {Compiler.RegularElement | Compiler.SvelteElement} node
* @returns {Compiler.RegularElement | Compiler.SvelteElement | null}
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} node
* @returns {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | null}
*/
function get_element_parent(node) {
/** @type {Compiler.SvelteNode | null} */
@ -611,10 +611,10 @@ function find_previous_sibling(node) {
/**
* @param {Compiler.SvelteNode} node
* @param {boolean} adjacent_only
* @returns {Map<Compiler.RegularElement | Compiler.SvelteElement | Compiler.SlotElement | Compiler.RenderTag, NodeExistsValue>}
* @returns {Map<Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.SlotElement | Compiler.AST.RenderTag, NodeExistsValue>}
*/
function get_possible_element_siblings(node, adjacent_only) {
/** @type {Map<Compiler.RegularElement | Compiler.SvelteElement | Compiler.SlotElement | Compiler.RenderTag, NodeExistsValue>} */
/** @type {Map<Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.SlotElement | Compiler.AST.RenderTag, NodeExistsValue>} */
const result = new Map();
/** @type {Compiler.SvelteNode} */
@ -676,12 +676,12 @@ function get_possible_element_siblings(node, adjacent_only) {
}
/**
* @param {Compiler.EachBlock | Compiler.IfBlock | Compiler.AwaitBlock} relative_selector
* @param {Compiler.AST.EachBlock | Compiler.AST.IfBlock | Compiler.AST.AwaitBlock} relative_selector
* @param {boolean} adjacent_only
* @returns {Map<Compiler.RegularElement, NodeExistsValue>}
* @returns {Map<Compiler.AST.RegularElement, NodeExistsValue>}
*/
function get_possible_last_child(relative_selector, adjacent_only) {
/** @typedef {Map<Compiler.RegularElement, NodeExistsValue>} NodeMap */
/** @typedef {Map<Compiler.AST.RegularElement, NodeExistsValue>} NodeMap */
/** @type {NodeMap} */
const result = new Map();
@ -783,7 +783,7 @@ function higher_existence(exist1, exist2) {
return exist1 > exist2 ? exist1 : exist2;
}
/** @param {Map<Compiler.RegularElement, NodeExistsValue>} result */
/** @param {Map<Compiler.AST.RegularElement, NodeExistsValue>} result */
function mark_as_probably(result) {
for (const key of result.keys()) {
result.set(key, NODE_PROBABLY_EXISTS);
@ -795,7 +795,7 @@ function mark_as_probably(result) {
* @param {boolean} adjacent_only
*/
function loop_child(children, adjacent_only) {
/** @type {Map<Compiler.RegularElement, NodeExistsValue>} */
/** @type {Map<Compiler.AST.RegularElement, NodeExistsValue>} */
const result = new Map();
for (let i = children.length - 1; i >= 0; i--) {
const child = children[i];

@ -1,4 +1,4 @@
/** @import { Text, ExpressionTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Node } from 'estree' */
const UNKNOWN = {};
@ -18,7 +18,7 @@ function gather_possible_values(node, set) {
}
/**
* @param {Text | ExpressionTag} chunk
* @param {AST.Text | AST.ExpressionTag} chunk
* @returns {Set<string> | null}
*/
export function get_possible_values(chunk) {

@ -1,5 +1,5 @@
/** @import { Expression, Node, Program } from 'estree' */
/** @import { Binding, Root, Script, SvelteNode, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
/** @import { Binding, AST, SvelteNode, ValidatedCompileOptions, ValidatedModuleCompileOptions } from '#compiler' */
/** @import { AnalysisState, Visitors } from './types' */
/** @import { Analysis, ComponentAnalysis, Js, ReactiveStatement, Template } from '../types' */
import { walk } from 'zimmerframe';
@ -178,7 +178,7 @@ const visitors = {
};
/**
* @param {Script | null} script
* @param {AST.Script | null} script
* @param {ScopeRoot} root
* @param {boolean} allow_reactive_declarations
* @param {Scope | null} parent
@ -257,7 +257,7 @@ export function analyze_module(ast, options) {
}
/**
* @param {Root} root
* @param {AST.Root} root
* @param {string} source
* @param {ValidatedCompileOptions} options
* @returns {ComponentAnalysis}
@ -580,7 +580,7 @@ export function analyze_component(root, source, options) {
// bind:this doesn't need to be a state reference if it will never change
if (
type === 'BindDirective' &&
/** @type {import('#compiler').BindDirective} */ (path[i]).name === 'this'
/** @type {AST.BindDirective} */ (path[i]).name === 'this'
) {
for (let j = i - 1; j >= 0; j -= 1) {
const type = path[j].type;
@ -688,7 +688,7 @@ export function analyze_component(root, source, options) {
// TODO this happens during the analysis phase, which shouldn't know anything about client vs server
if (element.type === 'SvelteElement' && options.generate === 'client') continue;
/** @type {import('#compiler').Attribute | undefined} */
/** @type {AST.Attribute | undefined} */
let class_attribute = undefined;
for (const attribute of element.attributes) {
@ -707,7 +707,7 @@ export function analyze_component(root, source, options) {
if (is_text_attribute(class_attribute)) {
class_attribute.value[0].data += ` ${analysis.css.hash}`;
} else {
/** @type {import('#compiler').Text} */
/** @type {AST.Text} */
const css_text = {
type: 'Text',
data: ` ${analysis.css.hash}`,

@ -1,6 +1,6 @@
import type { Scope } from '../scope.js';
import type { ComponentAnalysis, ReactiveStatement } from '../types.js';
import type { ExpressionMetadata, RenderTag, SvelteNode, ValidatedCompileOptions } from '#compiler';
import type { ExpressionMetadata, AST, ValidatedCompileOptions, SvelteNode } from '#compiler';
import type { LabeledStatement } from 'estree';
export interface AnalysisState {
@ -16,7 +16,7 @@ export interface AnalysisState {
/** Information about the current expression/directive/block value */
expression: ExpressionMetadata | null;
/** The current {@render ...} tag, if any */
render_tag: null | RenderTag;
render_tag: null | AST.RenderTag;
private_derived_state: string[];
function_depth: number;

@ -1,5 +1,5 @@
/** @import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression } from 'estree' */
/** @import { Attribute, DelegatedEvent, RegularElement, SvelteNode } from '#compiler' */
/** @import { AST, DelegatedEvent, SvelteNode } from '#compiler' */
/** @import { Context } from '../types' */
import { is_capture_event, is_delegated } from '../../../../utils.js';
import {
@ -10,7 +10,7 @@ import {
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {Attribute} node
* @param {AST.Attribute} node
* @param {Context} context
*/
export function Attribute(node, context) {
@ -107,20 +107,20 @@ function get_delegated_event(event_name, handler, context) {
const grandparent = path.at(-2);
/** @type {RegularElement | null} */
/** @type {AST.RegularElement | null} */
let element = null;
/** @type {string | null} */
let event_name = null;
if (parent.type === 'OnDirective') {
element = /** @type {RegularElement} */ (grandparent);
element = /** @type {AST.RegularElement} */ (grandparent);
event_name = parent.name;
} else if (
parent.type === 'ExpressionTag' &&
grandparent?.type === 'Attribute' &&
is_event_attribute(grandparent)
) {
element = /** @type {RegularElement} */ (path.at(-3));
const attribute = /** @type {Attribute} */ (grandparent);
element = /** @type {AST.RegularElement} */ (path.at(-3));
const attribute = /** @type {AST.Attribute} */ (grandparent);
event_name = get_attribute_event_name(attribute.name);
}

@ -1,11 +1,11 @@
/** @import { AwaitBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { validate_block_not_empty, validate_opening_tag } from './shared/utils.js';
import * as e from '../../../errors.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {AwaitBlock} node
* @param {AST.AwaitBlock} node
* @param {Context} context
*/
export function AwaitBlock(node, context) {

@ -1,4 +1,4 @@
/** @import { Attribute, BindDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import {
extract_all_identifiers_from_expression,
@ -13,7 +13,7 @@ import fuzzymatch from '../../1-parse/utils/fuzzymatch.js';
import { is_content_editable_binding, is_svg } from '../../../../utils.js';
/**
* @param {BindDirective} node
* @param {AST.BindDirective} node
* @param {Context} context
*/
export function BindDirective(node, context) {
@ -152,7 +152,7 @@ export function BindDirective(node, context) {
}
if (parent.name === 'input' && node.name !== 'this') {
const type = /** @type {Attribute | undefined} */ (
const type = /** @type {AST.Attribute | undefined} */ (
parent.attributes.find((a) => a.type === 'Attribute' && a.name === 'type')
);
@ -194,7 +194,7 @@ export function BindDirective(node, context) {
}
if (is_content_editable_binding(node.name)) {
const contenteditable = /** @type {Attribute} */ (
const contenteditable = /** @type {AST.Attribute} */ (
parent.attributes.find((a) => a.type === 'Attribute' && a.name === 'contenteditable')
);

@ -1,5 +1,5 @@
/** @import { CallExpression, VariableDeclarator } from 'estree' */
/** @import { SvelteNode } from '#compiler' */
/** @import { AST, SvelteNode } from '#compiler' */
/** @import { Context } from '../types' */
import { get_rune } from '../../scope.js';
import * as e from '../../../errors.js';

@ -1,8 +1,8 @@
/** @import { ClassDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
/**
* @param {ClassDirective} node
* @param {AST.ClassDirective} node
* @param {Context} context
*/
export function ClassDirective(node, context) {

@ -1,9 +1,9 @@
/** @import { Component } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { visit_component } from './shared/component.js';
/**
* @param {Component} node
* @param {AST.Component} node
* @param {Context} context
*/
export function Component(node, context) {

@ -1,10 +1,10 @@
/** @import { ConstTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { validate_opening_tag } from './shared/utils.js';
/**
* @param {ConstTag} node
* @param {AST.ConstTag} node
* @param {Context} context
*/
export function ConstTag(node, context) {

@ -1,9 +1,9 @@
/** @import { DebugTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { validate_opening_tag } from './shared/utils.js';
/**
* @param {DebugTag} node
* @param {AST.DebugTag} node
* @param {Context} context
*/
export function DebugTag(node, context) {

@ -1,4 +1,4 @@
/** @import { EachBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
/** @import { Scope } from '../../scope' */
import * as e from '../../../errors.js';
@ -6,7 +6,7 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
import { validate_block_not_empty, validate_opening_tag } from './shared/utils.js';
/**
* @param {EachBlock} node
* @param {AST.EachBlock} node
* @param {Context} context
*/
export function EachBlock(node, context) {

@ -1,11 +1,11 @@
/** @import { ExpressionTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_tag_valid_with_parent } from '../../../../html-tree-validation.js';
import * as e from '../../../errors.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {ExpressionTag} node
* @param {AST.ExpressionTag} node
* @param {Context} context
*/
export function ExpressionTag(node, context) {

@ -1,10 +1,10 @@
/** @import { HtmlTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { mark_subtree_dynamic } from './shared/fragment.js';
import { validate_opening_tag } from './shared/utils.js';
/**
* @param {HtmlTag} node
* @param {AST.HtmlTag} node
* @param {Context} context
*/
export function HtmlTag(node, context) {

@ -1,10 +1,10 @@
/** @import { IfBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { mark_subtree_dynamic } from './shared/fragment.js';
import { validate_block_not_empty, validate_opening_tag } from './shared/utils.js';
/**
* @param {IfBlock} node
* @param {AST.IfBlock} node
* @param {Context} context
*/
export function IfBlock(node, context) {

@ -1,10 +1,10 @@
/** @import { KeyBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { mark_subtree_dynamic } from './shared/fragment.js';
import { validate_block_not_empty, validate_opening_tag } from './shared/utils.js';
/**
* @param {KeyBlock} node
* @param {AST.KeyBlock} node
* @param {Context} context
*/
export function KeyBlock(node, context) {

@ -1,10 +1,9 @@
/** @import { Expression, LabeledStatement } from 'estree' */
/** @import { ReactiveStatement, SvelteNode } from '#compiler' */
/** @import { AST, ReactiveStatement, SvelteNode } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { extract_identifiers, object } from '../../../utils/ast.js';
import * as w from '../../../warnings.js';
import { is_state_source } from '../../3-transform/client/utils.js';
/**
* @param {LabeledStatement} node

@ -1,9 +1,9 @@
/** @import { LetDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
/**
* @param {LetDirective} node
* @param {AST.LetDirective} node
* @param {Context} context
*/
export function LetDirective(node, context) {

@ -1,10 +1,10 @@
/** @import { OnDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as w from '../../../warnings.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {OnDirective} node
* @param {AST.OnDirective} node
* @param {Context} context
*/
export function OnDirective(node, context) {

@ -1,4 +1,4 @@
/** @import { RegularElement } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_mathml, is_svg, is_void } from '../../../../utils.js';
import {
@ -14,7 +14,7 @@ import { validate_element } from './shared/element.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {RegularElement} node
* @param {AST.RegularElement} node
* @param {Context} context
*/
export function RegularElement(node, context) {
@ -48,8 +48,8 @@ export function RegularElement(node, context) {
node.attributes.push(
create_attribute(
'value',
/** @type {import('#compiler').Text} */ (node.fragment.nodes.at(0)).start,
/** @type {import('#compiler').Text} */ (node.fragment.nodes.at(-1)).end,
/** @type {AST.Text} */ (node.fragment.nodes.at(0)).start,
/** @type {AST.Text} */ (node.fragment.nodes.at(-1)).end,
// @ts-ignore
node.fragment.nodes
)

@ -1,4 +1,4 @@
/** @import { RenderTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { unwrap_optional } from '../../../utils/ast.js';
import * as e from '../../../errors.js';
@ -6,7 +6,7 @@ import { validate_opening_tag } from './shared/utils.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {RenderTag} node
* @param {AST.RenderTag} node
* @param {Context} context
*/
export function RenderTag(node, context) {

@ -1,4 +1,4 @@
/** @import { SlotElement } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_text_attribute } from '../../../utils/ast.js';
import * as e from '../../../errors.js';
@ -6,7 +6,7 @@ import * as w from '../../../warnings.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {SlotElement} node
* @param {AST.SlotElement} node
* @param {Context} context
*/
export function SlotElement(node, context) {

@ -1,10 +1,10 @@
/** @import { SnippetBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { validate_block_not_empty, validate_opening_tag } from './shared/utils.js';
import * as e from '../../../errors.js';
/**
* @param {SnippetBlock} node
* @param {AST.SnippetBlock} node
* @param {Context} context
*/
export function SnippetBlock(node, context) {

@ -1,10 +1,10 @@
/** @import { SpreadAttribute } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {SpreadAttribute} node
* @param {AST.SpreadAttribute} node
* @param {Context} context
*/
export function SpreadAttribute(node, context) {

@ -1,11 +1,11 @@
/** @import { StyleDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { get_attribute_chunks } from '../../../utils/ast.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {StyleDirective} node
* @param {AST.StyleDirective} node
* @param {Context} context
*/
export function StyleDirective(node, context) {

@ -1,11 +1,11 @@
/** @import { SvelteBody } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { is_event_attribute } from '../../../utils/ast.js';
import { disallow_children } from './shared/special-element.js';
/**
* @param {SvelteBody} node
* @param {AST.SvelteBody} node
* @param {Context} context
*/
export function SvelteBody(node, context) {

@ -1,10 +1,10 @@
/** @import { SvelteComponent } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as w from '../../../warnings.js';
import { visit_component } from './shared/component.js';
/**
* @param {SvelteComponent} node
* @param {AST.SvelteComponent} node
* @param {Context} context
*/
export function SvelteComponent(node, context) {

@ -1,9 +1,9 @@
/** @import { SvelteDocument } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { disallow_children } from './shared/special-element.js';
/**
* @param {SvelteDocument} node
* @param {AST.SvelteDocument} node
* @param {Context} context
*/
export function SvelteDocument(node, context) {

@ -1,4 +1,4 @@
/** @import { Attribute, SvelteElement, Text } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { NAMESPACE_MATHML, NAMESPACE_SVG } from '../../../../constants.js';
import { is_text_attribute } from '../../../utils/ast.js';
@ -7,7 +7,7 @@ import { validate_element } from './shared/element.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {SvelteElement} node
* @param {AST.SvelteElement} node
* @param {Context} context
*/
export function SvelteElement(node, context) {
@ -17,7 +17,7 @@ export function SvelteElement(node, context) {
context.state.analysis.elements.push(node);
const xmlns = /** @type {Attribute & { value: [Text] } | undefined} */ (
const xmlns = /** @type {AST.Attribute & { value: [AST.Text] } | undefined} */ (
node.attributes.find(
(a) => a.type === 'Attribute' && a.name === 'xmlns' && is_text_attribute(a)
)

@ -1,10 +1,10 @@
/** @import { SvelteFragment } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { validate_slot_attribute } from './shared/attribute.js';
/**
* @param {SvelteFragment} node
* @param {AST.SvelteFragment} node
* @param {Context} context
*/
export function SvelteFragment(node, context) {

@ -1,10 +1,10 @@
/** @import { SvelteHead } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {SvelteHead} node
* @param {AST.SvelteHead} node
* @param {Context} context
*/
export function SvelteHead(node, context) {

@ -1,10 +1,10 @@
/** @import { SvelteSelf } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { visit_component } from './shared/component.js';
import * as e from '../../../errors.js';
/**
* @param {SvelteSelf} node
* @param {AST.SvelteSelf} node
* @param {Context} context
*/
export function SvelteSelf(node, context) {

@ -1,9 +1,9 @@
/** @import { SvelteWindow } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { disallow_children } from './shared/special-element.js';
/**
* @param {SvelteWindow} node
* @param {AST.SvelteWindow} node
* @param {Context} context
*/
export function SvelteWindow(node, context) {

@ -1,11 +1,11 @@
/** @import { Text } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { is_tag_valid_with_parent } from '../../../../html-tree-validation.js';
import { regex_not_whitespace } from '../../patterns.js';
import * as e from '../../../errors.js';
/**
* @param {Text} node
* @param {AST.Text} node
* @param {Context} context
*/
export function Text(node, context) {

@ -1,9 +1,9 @@
/** @import { TitleElement } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
/**
* @param {TitleElement} node
* @param {AST.TitleElement} node
* @param {Context} context
*/
export function TitleElement(node, context) {

@ -1,9 +1,9 @@
/** @import { UseDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { mark_subtree_dynamic } from './shared/fragment.js';
/**
* @param {UseDirective} node
* @param {AST.UseDirective} node
* @param {Context} context
*/
export function UseDirective(node, context) {

@ -1,6 +1,5 @@
/** @import { Visitors } from 'zimmerframe' */
/** @import { AnalysisState } from '../../types.js' */
/** @import { Attribute, SvelteNode, TemplateNode, RegularElement, SvelteElement } from '#compiler' */
/** @import { AST, SvelteNode, TemplateNode } from '#compiler' */
/** @import { ARIARoleDefinitionKey, ARIARoleRelationConcept, ARIAProperty, ARIAPropertyDefinition, ARIARoleDefinition } from 'aria-query' */
import { roles as roles_map, aria, elementRoles } from 'aria-query';
// @ts-expect-error package doesn't provide typings
@ -78,7 +77,7 @@ function is_presentation_role(role) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
*/
function is_hidden_from_screen_reader(tag_name, attribute_map) {
if (tag_name === 'input') {
@ -96,7 +95,7 @@ function is_hidden_from_screen_reader(tag_name, attribute_map) {
}
/**
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
*/
function has_disabled_attribute(attribute_map) {
const disabled_attr_value = get_static_value(attribute_map.get('disabled'));
@ -173,7 +172,7 @@ elementAXObjects.entries().forEach(
/**
* @param {ARIARoleRelationConcept} schema
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
*/
function match_schema(schema, tag_name, attribute_map) {
if (schema.name !== tag_name) return false;
@ -196,7 +195,7 @@ const ElementInteractivity = /** @type {const} */ ({
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
* @returns {ElementInteractivity[keyof ElementInteractivity]}
*/
function element_interactivity(tag_name, attribute_map) {
@ -232,7 +231,7 @@ function element_interactivity(tag_name, attribute_map) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
* @returns {boolean}
*/
function is_interactive_element(tag_name, attribute_map) {
@ -241,7 +240,7 @@ function is_interactive_element(tag_name, attribute_map) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
* @returns {boolean}
*/
function is_non_interactive_element(tag_name, attribute_map) {
@ -250,7 +249,7 @@ function is_non_interactive_element(tag_name, attribute_map) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
* @returns {boolean}
*/
function is_static_element(tag_name, attribute_map) {
@ -260,7 +259,7 @@ function is_static_element(tag_name, attribute_map) {
/**
* @param {ARIARoleDefinitionKey} role
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
*/
function is_semantic_role_element(role, tag_name, attribute_map) {
for (const [schema, ax_object] of elementAXObjects.entries()) {
@ -544,7 +543,7 @@ const a11y_non_interactive_element_to_interactive_role_exceptions = {
const combobox_if_list = ['email', 'search', 'tel', 'text', 'url'];
/** @param {Map<string, Attribute>} attribute_map */
/** @param {Map<string, AST.Attribute>} attribute_map */
function input_implicit_role(attribute_map) {
const type_attribute = attribute_map.get('type');
if (!type_attribute) return;
@ -557,7 +556,7 @@ function input_implicit_role(attribute_map) {
return input_type_to_implicit_role.get(type);
}
/** @param {Map<string, Attribute>} attribute_map */
/** @param {Map<string, AST.Attribute>} attribute_map */
function menuitem_implicit_role(attribute_map) {
const type_attribute = attribute_map.get('type');
if (!type_attribute) return;
@ -568,7 +567,7 @@ function menuitem_implicit_role(attribute_map) {
/**
* @param {string} name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, AST.Attribute>} attribute_map
*/
function get_implicit_role(name, attribute_map) {
if (name === 'menuitem') {
@ -598,7 +597,7 @@ function is_parent(parent, elements) {
}
/**
* @param {Attribute} attribute
* @param {AST.Attribute} attribute
* @param {ARIAProperty} name
* @param {ARIAPropertyDefinition} schema
* @param {string | true | null} value
@ -648,7 +647,7 @@ function validate_aria_attribute_value(attribute, name, schema, value) {
}
/**
* @param {RegularElement |SvelteElement} node
* @param {AST.RegularElement |AST.SvelteElement} node
* @param {string[]} attributes
* @param {string} name
*/
@ -664,7 +663,7 @@ function warn_missing_attribute(node, attributes, name = node.name) {
}
/**
* @param {Attribute | undefined} attribute
* @param {AST.Attribute | undefined} attribute
*/
function get_static_value(attribute) {
if (!attribute) return null;
@ -674,7 +673,7 @@ function get_static_value(attribute) {
}
/**
* @param {Attribute | undefined} attribute
* @param {AST.Attribute | undefined} attribute
*/
function get_static_text_value(attribute) {
const value = get_static_value(attribute);
@ -683,17 +682,17 @@ function get_static_text_value(attribute) {
}
/**
* @param {RegularElement | SvelteElement} node
* @param {AST.RegularElement | AST.SvelteElement} node
* @param {AnalysisState} state
*/
export function check_element(node, state) {
/** @type {Map<string, Attribute>} */
/** @type {Map<string, AST.Attribute>} */
const attribute_map = new Map();
/** @type {Set<string>} */
const handlers = new Set();
/** @type {Attribute[]} */
/** @type {AST.Attribute[]} */
const attributes = [];
const is_dynamic_element = node.type === 'SvelteElement';
@ -1098,7 +1097,7 @@ export function check_element(node, state) {
return;
}
let has_caption = false;
const track = /** @type {RegularElement | undefined} */ (
const track = /** @type {AST.RegularElement | undefined} */ (
node.fragment.nodes.find((i) => i.type === 'RegularElement' && i.name === 'track')
);
if (track) {

@ -1,4 +1,4 @@
/** @import { Attribute, ElementLike } from '#compiler' */
/** @import { AST, ElementLike } from '#compiler' */
/** @import { Context } from '../../types' */
import * as e from '../../../../errors.js';
import { is_text_attribute } from '../../../../utils/ast.js';
@ -7,7 +7,7 @@ import { is_custom_element_node } from '../../../nodes.js';
import { regex_only_whitespaces } from '../../../patterns.js';
/**
* @param {Attribute} attribute
* @param {AST.Attribute} attribute
*/
export function validate_attribute_name(attribute) {
if (
@ -21,7 +21,7 @@ export function validate_attribute_name(attribute) {
}
/**
* @param {Attribute} attribute
* @param {AST.Attribute} attribute
* @param {ElementLike} parent
*/
export function validate_attribute(attribute, parent) {
@ -50,7 +50,7 @@ export function validate_attribute(attribute, parent) {
/**
* @param {Context} context
* @param {Attribute} attribute
* @param {AST.Attribute} attribute
* @param {boolean} is_component
*/
export function validate_slot_attribute(context, attribute, is_component = false) {

@ -1,4 +1,4 @@
/** @import { Comment, Component, Fragment, SvelteComponent, SvelteSelf } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../../types' */
import * as e from '../../../../errors.js';
import { get_attribute_expression, is_expression_attribute } from '../../../../utils/ast.js';
@ -11,7 +11,7 @@ import {
import { mark_subtree_dynamic } from './fragment.js';
/**
* @param {Component | SvelteComponent | SvelteSelf} node
* @param {AST.Component | AST.SvelteComponent | AST.SvelteSelf} node
* @param {Context} context
*/
export function visit_component(node, context) {
@ -75,10 +75,10 @@ export function visit_component(node, context) {
context.visit(attribute, attribute.type === 'LetDirective' ? default_state : context.state);
}
/** @type {Comment[]} */
/** @type {AST.Comment[]} */
let comments = [];
/** @type {Record<string, Fragment['nodes']>} */
/** @type {Record<string, AST.Fragment['nodes']>} */
const nodes = { default: [] };
for (const child of node.fragment.nodes) {

@ -1,4 +1,4 @@
/** @import { Component, RegularElement, SvelteComponent, SvelteElement, SvelteSelf, TransitionDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../../types' */
import { get_attribute_expression, is_expression_attribute } from '../../../../utils/ast.js';
import { regex_illegal_attribute_character } from '../../../patterns.js';
@ -23,16 +23,16 @@ const EVENT_MODIFIERS = [
];
/**
* @param {import('#compiler').RegularElement | SvelteElement} node
* @param {AST.RegularElement | AST.SvelteElement} node
* @param {Context} context
*/
export function validate_element(node, context) {
let has_animate_directive = false;
/** @type {TransitionDirective | null} */
/** @type {AST.TransitionDirective | null} */
let in_transition = null;
/** @type {TransitionDirective | null} */
/** @type {AST.TransitionDirective | null} */
let out_transition = null;
for (const attribute of node.attributes) {
@ -75,7 +75,7 @@ export function validate_element(node, context) {
}
if (attribute.name === 'slot') {
/** @type {RegularElement | SvelteElement | Component | SvelteComponent | SvelteSelf | undefined} */
/** @type {AST.RegularElement | AST.SvelteElement | AST.Component | AST.SvelteComponent | AST.SvelteSelf | undefined} */
validate_slot_attribute(context, attribute);
}
@ -112,7 +112,7 @@ export function validate_element(node, context) {
has_animate_directive = true;
}
} else if (attribute.type === 'TransitionDirective') {
const existing = /** @type {TransitionDirective | null} */ (
const existing = /** @type {AST.TransitionDirective | null} */ (
(attribute.intro && in_transition) || (attribute.outro && out_transition)
);

@ -1,4 +1,4 @@
/** @import { SvelteNode } from '#compiler' */
/** @import { AST, SvelteNode } from '#compiler' */
/**
* @param {SvelteNode[]} path

@ -1,8 +1,8 @@
/** @import { SvelteBody, SvelteDocument, SvelteOptionsRaw, SvelteWindow } from '#compiler' */
/** @import { AST } from '#compiler' */
import * as e from '../../../../errors.js';
/**
* @param {SvelteBody | SvelteDocument | SvelteOptionsRaw | SvelteWindow} node
* @param {AST.SvelteBody | AST.SvelteDocument | AST.SvelteOptionsRaw | AST.SvelteWindow} node
*/
export function disallow_children(node) {
const { nodes } = node.fragment;

@ -1,5 +1,5 @@
/** @import { AssignmentExpression, CallExpression, Expression, Pattern, PrivateIdentifier, Super, TaggedTemplateExpression, UpdateExpression, VariableDeclarator } from 'estree' */
/** @import { Fragment } from '#compiler' */
/** @import { AssignmentExpression, Expression, Pattern, PrivateIdentifier, Super, UpdateExpression, VariableDeclarator } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { AnalysisState, Context } from '../../types' */
/** @import { Scope } from '../../../scope' */
/** @import { NodeLike } from '../../../../errors.js' */
@ -118,7 +118,7 @@ export function validate_opening_tag(node, state, expected) {
}
/**
* @param {Fragment | null | undefined} node
* @param {AST.Fragment | null | undefined} node
* @param {Context} context
*/
export function validate_block_not_empty(node, context) {

@ -1,5 +1,5 @@
/** @import * as ESTree from 'estree' */
/** @import { ValidatedCompileOptions, SvelteNode, ValidatedModuleCompileOptions } from '#compiler' */
/** @import { ValidatedCompileOptions, AST, ValidatedModuleCompileOptions, SvelteNode } from '#compiler' */
/** @import { ComponentAnalysis, Analysis } from '../../types' */
/** @import { Visitors, ComponentClientTransformState, ClientTransformState } from './types' */
import { walk } from 'zimmerframe';

@ -1,11 +1,11 @@
/** @import { Expression } from 'estree' */
/** @import { AnimateDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { parse_directive_name } from './shared/utils.js';
/**
* @param {AnimateDirective} node
* @param {AST.AnimateDirective} node
* @param {ComponentContext} context
*/
export function AnimateDirective(node, context) {

@ -1,10 +1,10 @@
/** @import { Attribute } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { is_event_attribute } from '../../../../utils/ast.js';
import { visit_event_attribute } from './shared/events.js';
/**
* @param {Attribute} node
* @param {AST.Attribute} node
* @param {ComponentContext} context
*/
export function Attribute(node, context) {

@ -1,11 +1,11 @@
/** @import { BlockStatement, Expression, Pattern, Statement } from 'estree' */
/** @import { AwaitBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { create_derived_block_argument } from '../utils.js';
/**
* @param {AwaitBlock} node
* @param {AST.AwaitBlock} node
* @param {ComponentContext} context
*/
export function AwaitBlock(node, context) {

@ -1,5 +1,5 @@
/** @import { CallExpression, Expression, MemberExpression } from 'estree' */
/** @import { Attribute, BindDirective } from '#compiler' */
/** @import { AST, SvelteNode } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { dev, is_ignored } from '../../../../state.js';
import { is_text_attribute } from '../../../../utils/ast.js';
@ -9,14 +9,14 @@ import { build_attribute_value } from './shared/element.js';
import { build_bind_this, validate_binding } from './shared/utils.js';
/**
* @param {BindDirective} node
* @param {AST.BindDirective} node
* @param {ComponentContext} context
*/
export function BindDirective(node, context) {
const expression = node.expression;
const property = binding_properties[node.name];
const parent = /** @type {import('#compiler').SvelteNode} */ (context.path.at(-1));
const parent = /** @type {SvelteNode} */ (context.path.at(-1));
if (
dev &&
@ -188,7 +188,7 @@ export function BindDirective(node, context) {
if (parent?.type === 'RegularElement') {
const value = /** @type {any[]} */ (
/** @type {Attribute} */ (
/** @type {AST.Attribute} */ (
parent.attributes.find(
(a) =>
a.type === 'Attribute' &&

@ -1,8 +1,8 @@
/** @import { Comment } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
/**
* @param {Comment} node
* @param {AST.Comment} node
* @param {ComponentContext} context
*/
export function Comment(node, context) {

@ -1,11 +1,11 @@
/** @import { Expression } from 'estree' */
/** @import { Component } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { build_component } from './shared/component.js';
/**
* @param {Component} node
* @param {AST.Component} node
* @param {ComponentContext} context
*/
export function Component(node, context) {

@ -1,5 +1,5 @@
/** @import { Expression, Pattern } from 'estree' */
/** @import { ConstTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { dev } from '../../../../state.js';
import { extract_identifiers } from '../../../../utils/ast.js';
@ -8,7 +8,7 @@ import { create_derived } from '../utils.js';
import { get_value } from './shared/declarations.js';
/**
* @param {ConstTag} node
* @param {AST.ConstTag} node
* @param {ComponentContext} context
*/
export function ConstTag(node, context) {

@ -1,10 +1,10 @@
/** @import { Expression} from 'estree' */
/** @import { DebugTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
/**
* @param {DebugTag} node
* @param {AST.DebugTag} node
* @param {ComponentContext} context
*/
export function DebugTag(node, context) {

@ -1,5 +1,5 @@
/** @import { BlockStatement, Expression, Identifier, Pattern, Statement } from 'estree' */
/** @import { Binding, EachBlock } from '#compiler' */
/** @import { AST, Binding } from '#compiler' */
/** @import { ComponentContext } from '../types' */
/** @import { Scope } from '../../../scope' */
import {
@ -16,7 +16,7 @@ import { build_getter } from '../utils.js';
import { get_value } from './shared/declarations.js';
/**
* @param {EachBlock} node
* @param {AST.EachBlock} node
* @param {ComponentContext} context
*/
export function EachBlock(node, context) {
@ -289,7 +289,7 @@ export function EachBlock(node, context) {
* @param {ComponentContext} context
*/
function collect_parent_each_blocks(context) {
return /** @type {EachBlock[]} */ (context.path.filter((node) => node.type === 'EachBlock'));
return /** @type {AST.EachBlock[]} */ (context.path.filter((node) => node.type === 'EachBlock'));
}
/**

@ -1,5 +1,5 @@
/** @import { Expression, Identifier, Statement } from 'estree' */
/** @import { Fragment, Namespace, RegularElement } from '#compiler' */
/** @import { AST, Namespace } from '#compiler' */
/** @import { SourceLocation } from '#shared' */
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
import { TEMPLATE_FRAGMENT, TEMPLATE_USE_IMPORT_NODE } from '../../../../../constants.js';
@ -10,7 +10,7 @@ import { process_children } from './shared/fragment.js';
import { build_render_statement } from './shared/utils.js';
/**
* @param {Fragment} node
* @param {AST.Fragment} node
* @param {ComponentContext} context
*/
export function Fragment(node, context) {
@ -105,7 +105,7 @@ export function Fragment(node, context) {
};
if (is_single_element) {
const element = /** @type {RegularElement} */ (trimmed[0]);
const element = /** @type {AST.RegularElement} */ (trimmed[0]);
const id = b.id(context.state.scope.generate(element.name));

@ -1,11 +1,11 @@
/** @import { Expression } from 'estree' */
/** @import { HtmlTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { is_ignored } from '../../../../state.js';
import * as b from '../../../../utils/builders.js';
/**
* @param {HtmlTag} node
* @param {AST.HtmlTag} node
* @param {ComponentContext} context
*/
export function HtmlTag(node, context) {

@ -1,10 +1,10 @@
/** @import { BlockStatement, Expression } from 'estree' */
/** @import { IfBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
/**
* @param {IfBlock} node
* @param {AST.IfBlock} node
* @param {ComponentContext} context
*/
export function IfBlock(node, context) {

@ -1,10 +1,10 @@
/** @import { Expression } from 'estree' */
/** @import { KeyBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
/**
* @param {KeyBlock} node
* @param {AST.KeyBlock} node
* @param {ComponentContext} context
*/
export function KeyBlock(node, context) {

@ -1,11 +1,11 @@
/** @import { Expression } from 'estree' */
/** @import { LetDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { create_derived } from '../utils.js';
/**
* @param {LetDirective} node
* @param {AST.LetDirective} node
* @param {ComponentContext} context
*/
export function LetDirective(node, context) {

@ -1,4 +1,4 @@
/** @import { OnDirective, SvelteNode } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { build_event, build_event_handler } from './shared/events.js';
@ -13,7 +13,7 @@ const modifiers = [
];
/**
* @param {OnDirective} node
* @param {AST.OnDirective} node
* @param {ComponentContext} context
*/
export function OnDirective(node, context) {

@ -1,5 +1,5 @@
/** @import { Expression, ExpressionStatement, Identifier, Literal, MemberExpression, ObjectExpression, Statement } from 'estree' */
/** @import { Attribute, BindDirective, ClassDirective, RegularElement, SpreadAttribute, StyleDirective } from '#compiler' */
/** @import { Expression, ExpressionStatement, Identifier, MemberExpression, ObjectExpression, Statement } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { SourceLocation } from '#shared' */
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
/** @import { Scope } from '../../../scope' */
@ -36,7 +36,7 @@ import {
import { visit_event_attribute } from './shared/events.js';
/**
* @param {RegularElement} node
* @param {AST.RegularElement} node
* @param {ComponentContext} context
*/
export function RegularElement(node, context) {
@ -69,13 +69,13 @@ export function RegularElement(node, context) {
context.state.template.push(`<${node.name}`);
/** @type {Array<Attribute | SpreadAttribute>} */
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
const attributes = [];
/** @type {ClassDirective[]} */
/** @type {AST.ClassDirective[]} */
const class_directives = [];
/** @type {StyleDirective[]} */
/** @type {AST.StyleDirective[]} */
const style_directives = [];
/** @type {ExpressionStatement[]} */
@ -85,7 +85,7 @@ export function RegularElement(node, context) {
let needs_input_reset = false;
let needs_content_reset = false;
/** @type {BindDirective | null} */
/** @type {AST.BindDirective | null} */
let value_binding = null;
/** If true, needs `__value` for inputs */
@ -215,7 +215,7 @@ export function RegularElement(node, context) {
);
is_attributes_reactive = true;
} else {
for (const attribute of /** @type {Attribute[]} */ (attributes)) {
for (const attribute of /** @type {AST.Attribute[]} */ (attributes)) {
if (is_event_attribute(attribute)) {
if (
(attribute.name === 'onload' || attribute.name === 'onerror') &&
@ -384,7 +384,7 @@ export function RegularElement(node, context) {
/**
* Special case: if we have a value binding on a select element, we need to set up synchronization
* between the value binding and inner signals, for indirect updates
* @param {BindDirective} value_binding
* @param {AST.BindDirective} value_binding
* @param {ComponentContext} context
*/
function setup_select_synchronization(value_binding, context) {
@ -436,9 +436,9 @@ function setup_select_synchronization(value_binding, context) {
}
/**
* @param {Array<Attribute | SpreadAttribute>} attributes
* @param {Array<AST.Attribute | AST.SpreadAttribute>} attributes
* @param {ComponentContext} context
* @param {RegularElement} element
* @param {AST.RegularElement} element
* @param {Identifier} element_id
* @param {boolean} needs_select_handling
*/
@ -559,9 +559,9 @@ function build_element_spread_attributes(
* });
* ```
* Returns true if attribute is deemed reactive, false otherwise.
* @param {RegularElement} element
* @param {AST.RegularElement} element
* @param {Identifier} node_id
* @param {Attribute} attribute
* @param {AST.Attribute} attribute
* @param {ComponentContext} context
* @returns {boolean}
*/
@ -623,7 +623,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
/**
* Like `build_element_attribute_update_assignment` but without any special attribute treatment.
* @param {Identifier} node_id
* @param {Attribute} attribute
* @param {AST.Attribute} attribute
* @param {ComponentContext} context
* @returns {boolean}
*/
@ -653,7 +653,7 @@ function build_custom_element_attribute_update_assignment(node_id, attribute, co
* Returns true if attribute is deemed reactive, false otherwise.
* @param {string} element
* @param {Identifier} node_id
* @param {Attribute} attribute
* @param {AST.Attribute} attribute
* @param {ComponentContext} context
* @returns {boolean}
*/

@ -1,11 +1,11 @@
/** @import { Expression } from 'estree' */
/** @import { RenderTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { unwrap_optional } from '../../../../utils/ast.js';
import * as b from '../../../../utils/builders.js';
/**
* @param {RenderTag} node
* @param {AST.RenderTag} node
* @param {ComponentContext} context
*/
export function RenderTag(node, context) {

@ -1,11 +1,11 @@
/** @import { BlockStatement, Expression, ExpressionStatement, Property } from 'estree' */
/** @import { SlotElement } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { build_attribute_value } from './shared/element.js';
/**
* @param {SlotElement} node
* @param {AST.SlotElement} node
* @param {ComponentContext} context
*/
export function SlotElement(node, context) {

@ -1,5 +1,5 @@
/** @import { BlockStatement, Expression, Identifier, Pattern, Statement } from 'estree' */
/** @import { SnippetBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { dev } from '../../../../state.js';
import { extract_paths } from '../../../../utils/ast.js';
@ -7,7 +7,7 @@ import * as b from '../../../../utils/builders.js';
import { get_value } from './shared/declarations.js';
/**
* @param {SnippetBlock} node
* @param {AST.SnippetBlock} node
* @param {ComponentContext} context
*/
export function SnippetBlock(node, context) {

@ -1,8 +1,8 @@
/** @import { SpreadAttribute } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
/**
* @param {SpreadAttribute} node
* @param {AST.SpreadAttribute} node
* @param {ComponentContext} context
*/
export function SpreadAttribute(node, context) {

@ -1,9 +1,9 @@
/** @import { SvelteBody } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { visit_special_element } from './shared/special_element.js';
/**
* @param {SvelteBody} node
* @param {AST.SvelteBody} node
* @param {ComponentContext} context
*/
export function SvelteBody(node, context) {

@ -1,9 +1,9 @@
/** @import { SvelteComponent } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { build_component } from './shared/component.js';
/**
* @param {SvelteComponent} node
* @param {AST.SvelteComponent} node
* @param {ComponentContext} context
*/
export function SvelteComponent(node, context) {

@ -1,9 +1,9 @@
/** @import { SvelteDocument } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { visit_special_element } from './shared/special_element.js';
/**
* @param {SvelteDocument} node
* @param {AST.SvelteDocument} node
* @param {ComponentContext} context
*/
export function SvelteDocument(node, context) {

@ -1,8 +1,6 @@
/** @import { BlockStatement, Expression, ExpressionStatement, Identifier, Literal, MemberExpression, ObjectExpression, Statement } from 'estree' */
/** @import { Attribute, ClassDirective, SpreadAttribute, StyleDirective, SvelteElement } from '#compiler' */
/** @import { SourceLocation } from '#shared' */
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
/** @import { Scope } from '../../../scope' */
/** @import { BlockStatement, Expression, ExpressionStatement, Identifier, ObjectExpression, Statement } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { dev, locator } from '../../../../state.js';
import {
get_attribute_expression,
@ -19,22 +17,22 @@ import {
import { build_render_statement, build_update } from './shared/utils.js';
/**
* @param {SvelteElement} node
* @param {AST.SvelteElement} node
* @param {ComponentContext} context
*/
export function SvelteElement(node, context) {
context.state.template.push(`<!>`);
/** @type {Array<Attribute | SpreadAttribute>} */
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
const attributes = [];
/** @type {Attribute['value'] | undefined} */
/** @type {AST.Attribute['value'] | undefined} */
let dynamic_namespace = undefined;
/** @type {ClassDirective[]} */
/** @type {AST.ClassDirective[]} */
const class_directives = [];
/** @type {StyleDirective[]} */
/** @type {AST.StyleDirective[]} */
const style_directives = [];
/** @type {ExpressionStatement[]} */
@ -139,7 +137,7 @@ export function SvelteElement(node, context) {
/**
* Serializes dynamic element attribute assignments.
* Returns the `true` if spread is deemed reactive.
* @param {Array<Attribute | SpreadAttribute>} attributes
* @param {Array<AST.Attribute | AST.SpreadAttribute>} attributes
* @param {ComponentContext} context
* @param {Identifier} element_id
* @returns {boolean}

@ -1,9 +1,9 @@
/** @import { BlockStatement, ExpressionStatement } from 'estree' */
/** @import { SvelteFragment } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
/**
* @param {SvelteFragment} node
* @param {AST.SvelteFragment} node
* @param {ComponentContext} context
*/
export function SvelteFragment(node, context) {

@ -1,10 +1,10 @@
/** @import { BlockStatement } from 'estree' */
/** @import { SvelteHead } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
/**
* @param {SvelteHead} node
* @param {AST.SvelteHead} node
* @param {ComponentContext} context
*/
export function SvelteHead(node, context) {

@ -1,9 +1,9 @@
/** @import { SvelteSelf } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { build_component } from './shared/component.js';
/**
* @param {SvelteSelf} node
* @param {AST.SvelteSelf} node
* @param {ComponentContext} context
*/
export function SvelteSelf(node, context) {

@ -1,10 +1,9 @@
/** @import { Expression } from 'estree' */
/** @import { SvelteWindow } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { visit_special_element } from './shared/special_element.js';
/**
* @param {SvelteWindow} node
* @param {AST.SvelteWindow} node
* @param {ComponentContext} context
*/
export function SvelteWindow(node, context) {

@ -1,10 +1,10 @@
/** @import { TitleElement, Text } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { build_template_literal } from './shared/utils.js';
/**
* @param {TitleElement} node
* @param {AST.TitleElement} node
* @param {ComponentContext} context
*/
export function TitleElement(node, context) {

@ -1,12 +1,12 @@
/** @import { Expression } from 'estree' */
/** @import { TransitionDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import { TRANSITION_GLOBAL, TRANSITION_IN, TRANSITION_OUT } from '../../../../../constants.js';
import * as b from '../../../../utils/builders.js';
import { parse_directive_name } from './shared/utils.js';
/**
* @param {TransitionDirective} node
* @param {AST.TransitionDirective} node
* @param {ComponentContext} context
*/
export function TransitionDirective(node, context) {

@ -1,11 +1,11 @@
/** @import { Expression } from 'estree' */
/** @import { UseDirective } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */
import * as b from '../../../../utils/builders.js';
import { parse_directive_name } from './shared/utils.js';
/**
* @param {UseDirective} node
* @param {AST.UseDirective} node
* @param {ComponentContext} context
*/
export function UseDirective(node, context) {

@ -1,5 +1,5 @@
/** @import { BlockStatement, Expression, ExpressionStatement, Identifier, MemberExpression, Property, Statement } from 'estree' */
/** @import { Component, SvelteComponent, SvelteSelf, TemplateNode } from '#compiler' */
/** @import { AST, TemplateNode } from '#compiler' */
/** @import { ComponentContext } from '../../types.js' */
import { dev, is_ignored } from '../../../../../state.js';
import { get_attribute_chunks } from '../../../../../utils/ast.js';
@ -11,7 +11,7 @@ import { build_event_handler } from './events.js';
import { determine_slot } from '../../../../../utils/slot.js';
/**
* @param {Component | SvelteComponent | SvelteSelf} node
* @param {AST.Component | AST.SvelteComponent | AST.SvelteSelf} node
* @param {string} component_name
* @param {ComponentContext} context
* @param {Expression} anchor

@ -1,5 +1,5 @@
/** @import { Expression, Identifier } from 'estree' */
/** @import { Attribute, ClassDirective, ExpressionMetadata, Namespace, RegularElement, StyleDirective, SvelteElement } from '#compiler' */
/** @import { AST, Namespace } from '#compiler' */
/** @import { ComponentContext } from '../../types' */
import { normalize_attribute } from '../../../../../../utils.js';
import * as b from '../../../../../utils/builders.js';
@ -9,7 +9,7 @@ import { build_template_literal, build_update } from './utils.js';
/**
* Serializes each style directive into something like `$.set_style(element, style_property, value)`
* and adds it either to init or update, depending on whether or not the value or the attributes are dynamic.
* @param {StyleDirective[]} style_directives
* @param {AST.StyleDirective[]} style_directives
* @param {Identifier} element_id
* @param {ComponentContext} context
* @param {boolean} is_attributes_reactive
@ -56,7 +56,7 @@ export function build_style_directives(
/**
* Serializes each class directive into something like `$.class_toogle(element, class_name, value)`
* and adds it either to init or update, depending on whether or not the value or the attributes are dynamic.
* @param {ClassDirective[]} class_directives
* @param {AST.ClassDirective[]} class_directives
* @param {Identifier} element_id
* @param {ComponentContext} context
* @param {boolean} is_attributes_reactive
@ -85,7 +85,7 @@ export function build_class_directives(
}
/**
* @param {Attribute['value']} value
* @param {AST.Attribute['value']} value
* @param {ComponentContext} context
*/
export function build_attribute_value(value, context) {
@ -111,8 +111,8 @@ export function build_attribute_value(value, context) {
}
/**
* @param {RegularElement | SvelteElement} element
* @param {Attribute} attribute
* @param {AST.RegularElement | AST.SvelteElement} element
* @param {AST.Attribute} attribute
* @param {{ state: { metadata: { namespace: Namespace }}}} context
*/
export function get_attribute_name(element, attribute, context) {

@ -1,12 +1,12 @@
/** @import { Expression } from 'estree' */
/** @import { Attribute, ExpressionMetadata, ExpressionTag, SvelteNode } from '#compiler' */
/** @import { AST, ExpressionMetadata, SvelteNode } from '#compiler' */
/** @import { ComponentContext } from '../../types' */
import { is_capture_event, is_passive_event } from '../../../../../../utils.js';
import { dev, locator } from '../../../../../state.js';
import * as b from '../../../../../utils/builders.js';
/**
* @param {Attribute} node
* @param {AST.Attribute} node
* @param {ComponentContext} context
*/
export function visit_event_attribute(node, context) {
@ -20,8 +20,8 @@ export function visit_event_attribute(node, context) {
// we still need to support the weird `onclick="{() => {...}}" form
const tag = Array.isArray(node.value)
? /** @type {ExpressionTag} */ (node.value[0])
: /** @type {ExpressionTag} */ (node.value);
? /** @type {AST.ExpressionTag} */ (node.value[0])
: /** @type {AST.ExpressionTag} */ (node.value);
let handler = build_event_handler(tag.expression, tag.metadata.expression, context);

@ -1,5 +1,5 @@
/** @import { Expression } from 'estree' */
/** @import { ExpressionTag, SvelteNode, Text } from '#compiler' */
/** @import { AST, SvelteNode } from '#compiler' */
/** @import { ComponentContext } from '../../types' */
import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js';
import * as b from '../../../../../utils/builders.js';
@ -19,7 +19,7 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
let prev = initial;
let skipped = 0;
/** @typedef {Array<Text | ExpressionTag>} Sequence */
/** @typedef {Array<AST.Text | AST.ExpressionTag>} Sequence */
/** @type {Sequence} */
let sequence = [];
@ -123,7 +123,6 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
}
/**
*
* @param {SvelteNode} node
*/
function is_static_element(node) {

@ -1,11 +1,11 @@
/** @import { Expression } from 'estree' */
/** @import { SvelteBody, SvelteDocument, SvelteWindow } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../../types' */
import * as b from '../../../../../utils/builders.js';
/**
*
* @param {SvelteBody | SvelteDocument | SvelteWindow} node
* @param {AST.SvelteBody | AST.SvelteDocument | AST.SvelteWindow} node
* @param {string} id
* @param {ComponentContext} context
*/

@ -1,6 +1,6 @@
/** @import { Expression, ExpressionStatement, Identifier, MemberExpression, Statement, Super, TemplateElement, TemplateLiteral } from 'estree' */
/** @import { BindDirective, DelegatedEvent, ExpressionMetadata, ExpressionTag, OnDirective, SvelteNode, Text } from '#compiler' */
/** @import { ComponentClientTransformState, ComponentContext } from '../../types' */
/** @import { Expression, ExpressionStatement, Identifier, MemberExpression, Statement, Super } from 'estree' */
/** @import { AST, SvelteNode } from '#compiler' */
/** @import { ComponentClientTransformState } from '../../types' */
import { walk } from 'zimmerframe';
import { object } from '../../../../../utils/ast.js';
import * as b from '../../../../../utils/builders.js';
@ -11,7 +11,7 @@ import is_reference from 'is-reference';
import { locator } from '../../../../../state.js';
/**
* @param {Array<Text | ExpressionTag>} values
* @param {Array<AST.Text | AST.ExpressionTag>} values
* @param {(node: SvelteNode, state: any) => any} visit
* @param {ComponentClientTransformState} state
*/
@ -221,7 +221,7 @@ export function build_bind_this(expression, value, { state, visit }) {
/**
* @param {ComponentClientTransformState} state
* @param {BindDirective} binding
* @param {AST.BindDirective} binding
* @param {MemberExpression} expression
*/
export function validate_binding(state, binding, expression) {

@ -1,5 +1,5 @@
import type { Expression, Statement, ModuleDeclaration, LabeledStatement } from 'estree';
import type { SvelteNode, Namespace, ValidatedCompileOptions } from '#compiler';
import type { Namespace, SvelteNode, ValidatedCompileOptions } from '#compiler';
import type { TransformState } from '../types.js';
import type { ComponentAnalysis } from '../../types.js';
import type { StateField } from '../client/types.js';

@ -1,11 +1,11 @@
/** @import { BlockStatement, Expression, Pattern } from 'estree' */
/** @import { AwaitBlock } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '../../../../utils/builders.js';
import { empty_comment } from './shared/utils.js';
/**
* @param {AwaitBlock} node
* @param {AST.AwaitBlock} node
* @param {ComponentContext} context
*/
export function AwaitBlock(node, context) {

@ -1,10 +1,10 @@
/** @import { Component } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '../../../../utils/builders.js';
import { build_inline_component } from './shared/component.js';
/**
* @param {Component} node
* @param {AST.Component} node
* @param {ComponentContext} context
*/
export function Component(node, context) {

@ -1,10 +1,10 @@
/** @import { Expression, Pattern } from 'estree' */
/** @import { ConstTag } from '#compiler' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '../../../../utils/builders.js';
/**
* @param {ConstTag} node
* @param {AST.ConstTag} node
* @param {ComponentContext} context
*/
export function ConstTag(node, context) {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save