Home / File/ compile-errors.js — svelte Source File

compile-errors.js — svelte Source File

Architecture documentation for compile-errors.js, a javascript file in the svelte codebase. 1 imports, 0 dependents.

File javascript BuildSystem QualityControl 1 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  70e3acd4_0094_ad98_da32_055904bb4f55["compile-errors.js"]
  0d9214ee_ca0d_3c8d_6cc4_cfb71f9e09a6["./utils/compile_diagnostic.js"]
  70e3acd4_0094_ad98_da32_055904bb4f55 --> 0d9214ee_ca0d_3c8d_6cc4_cfb71f9e09a6
  style 70e3acd4_0094_ad98_da32_055904bb4f55 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { CompileDiagnostic } from './utils/compile_diagnostic.js';

/** @typedef {{ start?: number, end?: number }} NodeLike */

class InternalCompileError extends Error {
	message = ''; // ensure this property is enumerable
	#diagnostic;

	/**
	 * @param {string} code
	 * @param {string} message
	 * @param {[number, number] | undefined} position
	 */
	constructor(code, message, position) {
		super(message);
		this.stack = ''; // avoid unnecessary noise; don't set it as a class property or it becomes enumerable

		// We want to extend from Error so that various bundler plugins properly handle it.
		// But we also want to share the same object shape with that of warnings, therefore
		// we create an instance of the shared class an copy over its properties.
		this.#diagnostic = new CompileDiagnostic(code, message, position);
		Object.assign(this, this.#diagnostic);
		this.name = 'CompileError';
	}

	toString() {
		return this.#diagnostic.toString();
	}

	toJSON() {
		return this.#diagnostic.toJSON();
	}
}

/**
 * @param {null | number | NodeLike} node
 * @param {string} code
 * @param {string} message
 * @returns {never}
 */
function e(node, code, message) {
	const start = typeof node === 'number' ? node : node?.start;
	const end = typeof node === 'number' ? node : node?.end;

	throw new InternalCompileError(
		code,
		message,
		start !== undefined ? [start, end ?? start] : undefined
	);
}

/**
 * MESSAGE
 * @param {null | number | NodeLike} node
 * @param {string} PARAMETER
 * @returns {never}
 */
export function CODE(node, PARAMETER) {
	e(node, 'CODE', `${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
}

Domain

Subdomains

Functions

Dependencies

  • ./utils/compile_diagnostic.js

Frequently Asked Questions

What does compile-errors.js do?
compile-errors.js is a source file in the svelte codebase, written in javascript. It belongs to the BuildSystem domain, QualityControl subdomain.
What functions are defined in compile-errors.js?
compile-errors.js defines 2 function(s): CODE, e.
What does compile-errors.js depend on?
compile-errors.js imports 1 module(s): ./utils/compile_diagnostic.js.
Where is compile-errors.js in the architecture?
compile-errors.js is located at packages/svelte/scripts/process-messages/templates/compile-errors.js (domain: BuildSystem, subdomain: QualityControl, directory: packages/svelte/scripts/process-messages/templates).

Analyze Your Own Codebase

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

Try Supermodel Free