convert() — svelte Function Reference
Architecture documentation for the convert() function in legacy.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 739544c3_ed59_a35e_6bea_b1b4d2b50e81["convert()"] 21beed52_94ea_f810_11b8_87a2cf50432f["legacy.js"] 739544c3_ed59_a35e_6bea_b1b4d2b50e81 -->|defined in| 21beed52_94ea_f810_11b8_87a2cf50432f 6cb14a69_7fad_9de7_91fa_6dfba0162df4["to_public_ast()"] 6cb14a69_7fad_9de7_91fa_6dfba0162df4 -->|calls| 739544c3_ed59_a35e_6bea_b1b4d2b50e81 4422a3ac_4abf_f704_22f3_7d5d175ce307["extract_svelte_ignore()"] 739544c3_ed59_a35e_6bea_b1b4d2b50e81 -->|calls| 4422a3ac_4abf_f704_22f3_7d5d175ce307 59927267_2eb1_7776_901d_f15eb7398b08["remove_surrounding_whitespace_nodes()"] 739544c3_ed59_a35e_6bea_b1b4d2b50e81 -->|calls| 59927267_2eb1_7776_901d_f15eb7398b08 style 739544c3_ed59_a35e_6bea_b1b4d2b50e81 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/legacy.js lines 42–632
export function convert(source, ast) {
const root = /** @type {AST.SvelteNode | Legacy.LegacySvelteNode} */ (ast);
return /** @type {Legacy.LegacyRoot} */ (
walk(root, null, {
_(node, { next }) {
// @ts-ignore
delete node.metadata;
next();
},
// @ts-ignore
Root(node, { visit }) {
const { instance, module, options } = node;
// Insert svelte:options back into the root nodes
if (/** @type {any} */ (options)?.__raw__) {
let idx = node.fragment.nodes.findIndex(
(node) => /** @type {any} */ (options).end <= node.start
);
if (idx === -1) {
idx = node.fragment.nodes.length;
}
node.fragment.nodes.splice(idx, 0, /** @type {any} */ (options).__raw__);
}
/** @type {number | null} */
let start = null;
/** @type {number | null} */
let end = null;
if (node.fragment.nodes.length > 0) {
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;
while (/\s/.test(source[start])) start += 1;
while (/\s/.test(source[end - 1])) end -= 1;
}
if (instance) {
// @ts-ignore
delete instance.attributes;
}
if (module) {
// @ts-ignore
delete module.attributes;
}
return {
html: {
type: 'Fragment',
start,
end,
children: node.fragment.nodes.map((child) => visit(child))
},
instance,
module,
css: ast.css ? visit(ast.css) : undefined
};
},
AnimateDirective(node) {
return { ...node, type: 'Animation' };
},
// @ts-ignore
AwaitBlock(node, { visit }) {
let pendingblock = {
type: 'PendingBlock',
/** @type {number | null} */
start: null,
/** @type {number | null} */
end: null,
children: node.pending?.nodes.map((child) => visit(child)) ?? [],
skip: true
};
let thenblock = {
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does convert() do?
convert() is a function in the svelte codebase, defined in packages/svelte/src/compiler/legacy.js.
Where is convert() defined?
convert() is defined in packages/svelte/src/compiler/legacy.js at line 42.
What does convert() call?
convert() calls 2 function(s): extract_svelte_ignore, remove_surrounding_whitespace_nodes.
What calls convert()?
convert() is called by 1 function(s): to_public_ast.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free