Home / File/ acorn.js — svelte Source File

acorn.js — svelte Source File

Architecture documentation for acorn.js, a javascript file in the svelte codebase. 3 imports, 5 dependents.

File javascript Compiler Parser 3 imports 5 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  2627a38d_1d02_8fc1_b764_b2aaf06f372b["acorn.js"]
  ddbd69fe_bca5_b6ae_d174_765ac7fa34f7["acorn"]
  2627a38d_1d02_8fc1_b764_b2aaf06f372b --> ddbd69fe_bca5_b6ae_d174_765ac7fa34f7
  c49ac9f8_b355_57a2_8d10_b5fd945c6144["zimmerframe"]
  2627a38d_1d02_8fc1_b764_b2aaf06f372b --> c49ac9f8_b355_57a2_8d10_b5fd945c6144
  60dc75d5_2937_4ccd_75d5_90e8ed967826["acorn-typescript"]
  2627a38d_1d02_8fc1_b764_b2aaf06f372b --> 60dc75d5_2937_4ccd_75d5_90e8ed967826
  caefc1b2_dc4c_2cff_4013_e8ded13e7974["context.js"]
  caefc1b2_dc4c_2cff_4013_e8ded13e7974 --> 2627a38d_1d02_8fc1_b764_b2aaf06f372b
  8b705104_0cb9_c5c8_5bed_6dcfe73592d3["expression.js"]
  8b705104_0cb9_c5c8_5bed_6dcfe73592d3 --> 2627a38d_1d02_8fc1_b764_b2aaf06f372b
  90aa5201_1990_23b6_f05a_1ff5d9b22b14["script.js"]
  90aa5201_1990_23b6_f05a_1ff5d9b22b14 --> 2627a38d_1d02_8fc1_b764_b2aaf06f372b
  367a364a_2912_a1aa_b2e1_d97a82783c38["tag.js"]
  367a364a_2912_a1aa_b2e1_d97a82783c38 --> 2627a38d_1d02_8fc1_b764_b2aaf06f372b
  4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"]
  4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> 2627a38d_1d02_8fc1_b764_b2aaf06f372b
  style 2627a38d_1d02_8fc1_b764_b2aaf06f372b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Comment, Program } from 'estree' */
/** @import { AST } from '#compiler' */
import * as acorn from 'acorn';
import { walk } from 'zimmerframe';
import { tsPlugin } from '@sveltejs/acorn-typescript';

const ParserWithTS = acorn.Parser.extend(tsPlugin());

/**
 * @typedef {Comment & {
 *   start: number;
 *   end: number;
 * }} CommentWithLocation
 */

/**
 * @param {string} source
 * @param {AST.JSComment[]} comments
 * @param {boolean} typescript
 * @param {boolean} [is_script]
 */
export function parse(source, comments, typescript, is_script) {
	const parser = typescript ? ParserWithTS : acorn.Parser;

	const { onComment, add_comments } = get_comment_handlers(
		source,
		/** @type {CommentWithLocation[]} */ (comments)
	);

	// @ts-ignore
	const parse_statement = parser.prototype.parseStatement;

	// If we're dealing with a <script> then it might contain an export
	// for something that doesn't exist directly inside but is inside the
	// component instead, so we need to ensure that Acorn doesn't throw
	// an error in these cases
	if (is_script) {
		// @ts-ignore
		parser.prototype.parseStatement = function (...args) {
			const v = parse_statement.call(this, ...args);
			// @ts-ignore
			this.undefinedExports = {};
			return v;
		};
	}

	let ast;

	try {
		ast = parser.parse(source, {
			onComment,
			sourceType: 'module',
			ecmaVersion: 16,
			locations: true
		});
	} finally {
		if (is_script) {
			// @ts-ignore
			parser.prototype.parseStatement = parse_statement;
		}
// ... (139 more lines)

Domain

Subdomains

Dependencies

  • acorn
  • acorn-typescript
  • zimmerframe

Frequently Asked Questions

What does acorn.js do?
acorn.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Parser subdomain.
What functions are defined in acorn.js?
acorn.js defines 3 function(s): get_comment_handlers, parse, parse_expression_at.
What does acorn.js depend on?
acorn.js imports 3 module(s): acorn, acorn-typescript, zimmerframe.
What files import acorn.js?
acorn.js is imported by 5 file(s): context.js, expression.js, index.js, script.js, tag.js.
Where is acorn.js in the architecture?
acorn.js is located at packages/svelte/src/compiler/phases/1-parse/acorn.js (domain: Compiler, subdomain: Parser, directory: packages/svelte/src/compiler/phases/1-parse).

Analyze Your Own Codebase

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

Try Supermodel Free