Home / File/ ExpressionStatement.js — svelte Source File

ExpressionStatement.js — svelte Source File

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

File javascript Compiler Transformer 2 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  dbb15ae0_a432_16e3_1429_24ffed462356["ExpressionStatement.js"]
  56a689f9_11c0_cc76_bd60_41bb6dc96475["warnings.js"]
  dbb15ae0_a432_16e3_1429_24ffed462356 --> 56a689f9_11c0_cc76_bd60_41bb6dc96475
  3246e0bc_b9fc_f638_5e35_41e8c39a2408["w"]
  dbb15ae0_a432_16e3_1429_24ffed462356 --> 3246e0bc_b9fc_f638_5e35_41e8c39a2408
  4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"]
  4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> dbb15ae0_a432_16e3_1429_24ffed462356
  style dbb15ae0_a432_16e3_1429_24ffed462356 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { ExpressionStatement, ImportDeclaration } from 'estree' */
/** @import { Context } from '../types' */
import * as w from '../../../warnings.js';

/**
 * @param {ExpressionStatement} node
 * @param {Context} context
 */
export function ExpressionStatement(node, context) {
	// warn on `new Component({ target: ... })` if imported from a `.svelte` file
	if (
		node.expression.type === 'NewExpression' &&
		node.expression.callee.type === 'Identifier' &&
		node.expression.arguments.length === 1 &&
		node.expression.arguments[0].type === 'ObjectExpression' &&
		node.expression.arguments[0].properties.some(
			(p) => p.type === 'Property' && p.key.type === 'Identifier' && p.key.name === 'target'
		)
	) {
		const binding = context.state.scope.get(node.expression.callee.name);

		if (binding?.kind === 'normal' && binding.declaration_kind === 'import') {
			const declaration = /** @type {ImportDeclaration} */ (binding.initial);

			// Theoretically someone could import a class from a `.svelte.js` module, but that's too rare to worry about
			if (
				/** @type {string} */ (declaration.source.value).endsWith('.svelte') &&
				declaration.specifiers.find(
					(s) => s.local.name === binding.node.name && s.type === 'ImportDefaultSpecifier'
				)
			) {
				w.legacy_component_creation(node.expression);
			}
		}
	}

	context.next();
}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does ExpressionStatement.js do?
ExpressionStatement.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 ExpressionStatement.js?
ExpressionStatement.js defines 1 function(s): ExpressionStatement.
What does ExpressionStatement.js depend on?
ExpressionStatement.js imports 2 module(s): w, warnings.js.
What files import ExpressionStatement.js?
ExpressionStatement.js is imported by 1 file(s): index.js.
Where is ExpressionStatement.js in the architecture?
ExpressionStatement.js is located at packages/svelte/src/compiler/phases/2-analyze/visitors/ExpressionStatement.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/visitors).

Analyze Your Own Codebase

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

Try Supermodel Free