Home / File/ ast.js — svelte Source File

ast.js — svelte Source File

Architecture documentation for ast.js, a javascript file in the svelte codebase. 2 imports, 58 dependents.

File javascript Compiler Migrator 2 imports 58 dependents 20 functions

Entity Profile

Dependency Diagram

graph LR
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c["ast.js"]
  c49ac9f8_b355_57a2_8d10_b5fd945c6144["zimmerframe"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c --> c49ac9f8_b355_57a2_8d10_b5fd945c6144
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  cab41022_1b55_3b7a_06c6_b90763bbea47["index.js"]
  cab41022_1b55_3b7a_06c6_b90763bbea47 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  90aa5201_1990_23b6_f05a_1ff5d9b22b14["script.js"]
  90aa5201_1990_23b6_f05a_1ff5d9b22b14 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  206889ff_1f9f_b6c1_d530_059d001e1cf4["element.js"]
  206889ff_1f9f_b6c1_d530_059d001e1cf4 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  cb1bf043_dade_7352_cc2b_976ffa2968d8["css-prune.js"]
  cb1bf043_dade_7352_cc2b_976ffa2968d8 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"]
  4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  17a1befc_da6e_74db_4a59_7e1534b65053["AssignmentExpression.js"]
  17a1befc_da6e_74db_4a59_7e1534b65053 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  28ec60f4_a82f_1f06_ded7_1786b05aa1c0["Attribute.js"]
  28ec60f4_a82f_1f06_ded7_1786b05aa1c0 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  6b8c189e_23e1_77d3_9ee3_3eec5012a9b2["BindDirective.js"]
  6b8c189e_23e1_77d3_9ee3_3eec5012a9b2 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  3f0209c9_7af2_542f_1c9c_3be0eb046971["CallExpression.js"]
  3f0209c9_7af2_542f_1c9c_3be0eb046971 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  7cf83ecb_26f4_e326_a28c_a905bbed7141["EachBlock.js"]
  7cf83ecb_26f4_e326_a28c_a905bbed7141 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  7e95d51f_5311_0710_b8b8_1d5f79e8b0a7["ExportNamedDeclaration.js"]
  7e95d51f_5311_0710_b8b8_1d5f79e8b0a7 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  5d572700_84fa_a20f_b641_c5b7becd2684["LabeledStatement.js"]
  5d572700_84fa_a20f_b641_c5b7becd2684 --> 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c
  style 0c5c28a7_226d_4e7c_e75e_0853c0a9fc2c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { AST, Scope } from '#compiler' */
/** @import * as ESTree from 'estree' */
import { walk } from 'zimmerframe';
import * as b from '#compiler/builders';

/**
 * Gets the left-most identifier of a member expression or identifier.
 * @param {ESTree.MemberExpression | ESTree.Identifier} expression
 * @returns {ESTree.Identifier | null}
 */
export function object(expression) {
	while (expression.type === 'MemberExpression') {
		expression = /** @type {ESTree.MemberExpression | ESTree.Identifier} */ (expression.object);
	}

	if (expression.type !== 'Identifier') {
		return null;
	}

	return expression;
}

/**
 * Returns true if the attribute contains a single static text node.
 * @param {AST.Attribute} attribute
 * @returns {attribute is AST.Attribute & { value: [AST.Text] }}
 */
export function is_text_attribute(attribute) {
	return (
		Array.isArray(attribute.value) &&
		attribute.value.length === 1 &&
		attribute.value[0].type === 'Text'
	);
}

/**
 * Returns true if the attribute contains a single expression node.
 * In Svelte 5, this also includes a single expression node wrapped in an array.
 * TODO change that in a future version
 * @param {AST.Attribute} attribute
 * @returns {attribute is AST.Attribute & { value: [AST.ExpressionTag] | AST.ExpressionTag }}
 */
export function is_expression_attribute(attribute) {
	return (
		(attribute.value !== true && !Array.isArray(attribute.value)) ||
		(Array.isArray(attribute.value) &&
			attribute.value.length === 1 &&
			attribute.value[0].type === 'ExpressionTag')
	);
}

/**
 * Returns the single attribute expression node.
 * In Svelte 5, this also includes a single expression node wrapped in an array.
 * TODO change that in a future version
 * @param { AST.Attribute & { value: [AST.ExpressionTag] | AST.ExpressionTag }} attribute
 * @returns {ESTree.Expression}
 */
export function get_attribute_expression(attribute) {
	return Array.isArray(attribute.value)
// ... (580 more lines)

Domain

Subdomains

Dependencies

  • builders
  • zimmerframe

Imported By

Frequently Asked Questions

What does ast.js do?
ast.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 ast.js?
ast.js defines 20 function(s): _extract_paths, build_assignment_value, build_fallback, extract_all_identifiers_from_expression, extract_identifiers, extract_identifiers_from_destructuring, extract_paths, get_attribute_chunks, get_attribute_expression, get_parent, and 10 more.
What does ast.js depend on?
ast.js imports 2 module(s): builders, zimmerframe.
What files import ast.js?
ast.js is imported by 58 file(s): AssignmentExpression.js, AssignmentExpression.js, AssignmentExpression.js, Attribute.js, Attribute.js, AwaitBlock.js, AwaitExpression.js, AwaitExpression.js, and 50 more.
Where is ast.js in the architecture?
ast.js is located at packages/svelte/src/compiler/utils/ast.js (domain: Compiler, subdomain: Migrator, directory: packages/svelte/src/compiler/utils).

Analyze Your Own Codebase

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

Try Supermodel Free