Home / File/ index.js — svelte Source File

index.js — svelte Source File

Architecture documentation for index.js, a javascript file in the svelte codebase. 4 imports, 0 dependents.

File javascript Compiler Transformer 4 imports 59 functions

Entity Profile

Dependency Diagram

graph LR
  f0404eed_e134_3c7c_7b38_1cb13c71f197["index.js"]
  2aa63f4e_82c9_33e3_ac6c_5f3d46250522["utils.js"]
  f0404eed_e134_3c7c_7b38_1cb13c71f197 --> 2aa63f4e_82c9_33e3_ac6c_5f3d46250522
  02a8b5a2_13c5_e5b3_1ed2_617763d0904d["is_void"]
  f0404eed_e134_3c7c_7b38_1cb13c71f197 --> 02a8b5a2_13c5_e5b3_1ed2_617763d0904d
  16640ae7_e3c7_97fb_f758_13b5051448f7["esrap"]
  f0404eed_e134_3c7c_7b38_1cb13c71f197 --> 16640ae7_e3c7_97fb_f758_13b5051448f7
  3e77edba_57e8_d5f4_66c6_80c999e42f8a["ts"]
  f0404eed_e134_3c7c_7b38_1cb13c71f197 --> 3e77edba_57e8_d5f4_66c6_80c999e42f8a
  style f0404eed_e134_3c7c_7b38_1cb13c71f197 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AST } from '#compiler'; */
/** @import { Context, Visitors } from 'esrap' */
import * as esrap from 'esrap';
import ts from 'esrap/languages/ts';
import { is_void } from '../../utils.js';

/** Threshold for when content should be formatted on separate lines */
const LINE_BREAK_THRESHOLD = 50;

/**
 * `print` converts a Svelte AST node back into Svelte source code.
 * It is primarily intended for tools that parse and transform components using the compiler’s modern AST representation.
 *
 * `print(ast)` requires an AST node produced by parse with modern: true, or any sub-node within that modern AST.
 * The result contains the generated source and a corresponding source map.
 * The output is valid Svelte, but formatting details such as whitespace or quoting may differ from the original.
 * @param {AST.SvelteNode} ast
 * @param {import('./types.js').Options | undefined} options
 */
export function print(ast, options = undefined) {
	return esrap.print(
		ast,
		/** @type {Visitors<AST.SvelteNode>} */ ({
			...ts({
				comments: ast.type === 'Root' ? ast.comments : [],
				getLeadingComments: options?.getLeadingComments,
				getTrailingComments: options?.getTrailingComments
			}),
			...svelte_visitors,
			...css_visitors
		})
	);
}

/**
 * @param {Context} context
 * @param {AST.SvelteNode} node
 * @param {boolean} allow_inline
 */
function block(context, node, allow_inline = false) {
	const child_context = context.new();
	child_context.visit(node);

	if (child_context.empty()) {
		return;
	}

	if (allow_inline && !child_context.multiline) {
		context.append(child_context);
	} else {
		context.indent();
		context.newline();
		context.append(child_context);
		context.dedent();
		context.newline();
	}
}

/**
 * @param {AST.BaseElement['attributes']} attributes
// ... (795 more lines)

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does index.js do?
index.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in index.js?
index.js defines 59 function(s): attributes, base_element, block, css_visitors.Atrule, css_visitors.AttributeSelector, css_visitors.Block, css_visitors.ClassSelector, css_visitors.ComplexSelector, css_visitors.Declaration, css_visitors.IdSelector, and 49 more.
What does index.js depend on?
index.js imports 4 module(s): esrap, is_void, ts, utils.js.
Where is index.js in the architecture?
index.js is located at packages/svelte/src/compiler/print/index.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/print).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free