legacy.js — svelte Source File
Architecture documentation for legacy.js, a javascript file in the svelte codebase. 4 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 21beed52_94ea_f810_11b8_87a2cf50432f["legacy.js"] ce051dbd_4cf1_f117_d66e_12cfa122de37["patterns.js"] 21beed52_94ea_f810_11b8_87a2cf50432f --> ce051dbd_4cf1_f117_d66e_12cfa122de37 d1869e84_a713_3c60_3aae_40e1a6b78424["extract_svelte_ignore.js"] 21beed52_94ea_f810_11b8_87a2cf50432f --> d1869e84_a713_3c60_3aae_40e1a6b78424 4422a3ac_4abf_f704_22f3_7d5d175ce307["extract_svelte_ignore"] 21beed52_94ea_f810_11b8_87a2cf50432f --> 4422a3ac_4abf_f704_22f3_7d5d175ce307 c49ac9f8_b355_57a2_8d10_b5fd945c6144["zimmerframe"] 21beed52_94ea_f810_11b8_87a2cf50432f --> c49ac9f8_b355_57a2_8d10_b5fd945c6144 cc8de3ad_4bae_f883_44db_d90442053943["index.js"] cc8de3ad_4bae_f883_44db_d90442053943 --> 21beed52_94ea_f810_11b8_87a2cf50432f style 21beed52_94ea_f810_11b8_87a2cf50432f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { Expression } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import * as Legacy from './types/legacy-nodes.js' */
import { walk } from 'zimmerframe';
import {
regex_ends_with_whitespaces,
regex_not_whitespace,
regex_starts_with_whitespaces
} from './phases/patterns.js';
import { extract_svelte_ignore } from './utils/extract_svelte_ignore.js';
/**
* Some of the legacy Svelte AST nodes remove whitespace from the start and end of their children.
* @param {AST.TemplateNode[]} nodes
*/
function remove_surrounding_whitespace_nodes(nodes) {
const first = nodes.at(0);
const last = nodes.at(-1);
if (first?.type === 'Text') {
if (!regex_not_whitespace.test(first.data)) {
nodes.shift();
} else {
first.data = first.data.replace(regex_starts_with_whitespaces, '');
}
}
if (last?.type === 'Text') {
if (!regex_not_whitespace.test(last.data)) {
nodes.pop();
} else {
last.data = last.data.replace(regex_ends_with_whitespaces, '');
}
}
}
/**
* Transform our nice modern AST into the monstrosity emitted by Svelte 4
* @param {string} source
* @param {AST.Root} ast
* @returns {Legacy.LegacyRoot}
*/
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
);
// ... (573 more lines)
Domain
Subdomains
Dependencies
Imported By
Source
Frequently Asked Questions
What does legacy.js do?
legacy.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Migrator subdomain.
What functions are defined in legacy.js?
legacy.js defines 2 function(s): convert, remove_surrounding_whitespace_nodes.
What does legacy.js depend on?
legacy.js imports 4 module(s): extract_svelte_ignore, extract_svelte_ignore.js, patterns.js, zimmerframe.
What files import legacy.js?
legacy.js is imported by 1 file(s): index.js.
Where is legacy.js in the architecture?
legacy.js is located at packages/svelte/src/compiler/legacy.js (domain: Compiler, subdomain: Migrator, directory: packages/svelte/src/compiler).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free