Home / Function/ constructor() — svelte Function Reference

constructor() — svelte Function Reference

Architecture documentation for the constructor() function in index.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  3220db43_dde7_5166_5db8_db3c6d68258d["constructor()"]
  042e583c_5e12_9bde_ddd8_8091d5ea0f7d["Parser"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|defined in| 042e583c_5e12_9bde_ddd8_8091d5ea0f7d
  3cddfbc5_2f69_6147_3f68_deab3d5175dd["current()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| 3cddfbc5_2f69_6147_3f68_deab3d5175dd
  c16a81c5_56e2_1ecd_2a57_14f0095ebae7["constructor()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| c16a81c5_56e2_1ecd_2a57_14f0095ebae7
  ba32e941_2eb9_1bb2_8ee0_1eca52813eb8["create_fragment()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| ba32e941_2eb9_1bb2_8ee0_1eca52813eb8
  d33ef143_a2e5_8235_a012_3924877b988c["element_unclosed()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| d33ef143_a2e5_8235_a012_3924877b988c
  fa0b6c20_a2f0_9119_6be9_d597511abbe7["block_unclosed()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| fa0b6c20_a2f0_9119_6be9_d597511abbe7
  feea79ed_c6f7_4068_9c81_9734e5dcbfb7["unexpected_eof()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| feea79ed_c6f7_4068_9c81_9734e5dcbfb7
  6a48e790_0ca5_6fae_197c_7c93c49d9b66["read_options()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| 6a48e790_0ca5_6fae_197c_7c93c49d9b66
  cdcd4a9e_8be5_ea03_69d9_c5b2dd208707["disallow_children()"]
  3220db43_dde7_5166_5db8_db3c6d68258d -->|calls| cdcd4a9e_8be5_ea03_69d9_c5b2dd208707
  style 3220db43_dde7_5166_5db8_db3c6d68258d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/1-parse/index.js lines 73–154

	constructor(template, loose) {
		if (typeof template !== 'string') {
			throw new TypeError('Template must be a string');
		}

		this.loose = loose;
		this.template = template.trimEnd();

		let match_lang;

		do match_lang = regex_lang_attribute.exec(template);
		while (match_lang && match_lang[0][1] !== 's'); // ensure it starts with '<s' to match script tags

		regex_lang_attribute.lastIndex = 0; // reset matched index to pass tests - otherwise declare the regex inside the constructor

		this.ts = match_lang?.[2] === 'ts';

		this.root = {
			css: null,
			js: [],
			// @ts-ignore
			start: null,
			// @ts-ignore
			end: null,
			type: 'Root',
			fragment: create_fragment(),
			options: null,
			comments: [],
			metadata: {
				ts: this.ts
			}
		};

		this.stack.push(this.root);
		this.fragments.push(this.root.fragment);

		/** @type {ParserState} */
		let state = fragment;

		while (this.index < this.template.length) {
			state = state(this) || fragment;
		}

		if (this.stack.length > 1) {
			const current = this.current();

			if (this.loose) {
				current.end = this.template.length;
			} else if (current.type === 'RegularElement') {
				current.end = current.start + 1;
				e.element_unclosed(current, current.name);
			} else {
				current.end = current.start + 1;
				e.block_unclosed(current);
			}
		}

		if (state !== fragment) {
			e.unexpected_eof(this.index);
		}

		this.root.start = 0;
		this.root.end = template.length;

		const options_index = this.root.fragment.nodes.findIndex(
			/** @param {any} thing */
			(thing) => thing.type === 'SvelteOptions'
		);
		if (options_index !== -1) {
			const options = /** @type {AST.SvelteOptionsRaw} */ (this.root.fragment.nodes[options_index]);
			this.root.fragment.nodes.splice(options_index, 1);
			this.root.options = read_options(options);

			disallow_children(options);

			// We need this for the old AST format
			Object.defineProperty(this.root.options, '__raw__', {
				value: options,
				enumerable: false
			});
		}

Domain

Subdomains

Frequently Asked Questions

What does constructor() do?
constructor() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/1-parse/index.js.
Where is constructor() defined?
constructor() is defined in packages/svelte/src/compiler/phases/1-parse/index.js at line 73.
What does constructor() call?
constructor() calls 8 function(s): block_unclosed, constructor, create_fragment, current, disallow_children, element_unclosed, read_options, unexpected_eof.

Analyze Your Own Codebase

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

Try Supermodel Free