Home / File/ _config.js — svelte Source File

_config.js — svelte Source File

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

Entity Profile

Dependency Diagram

graph LR
  9b44e71a_66ae_4baf_57a9_5cd698aa8602["_config.js"]
  032186a9_8a8b_b603_4335_6ade22d767cb["test.ts"]
  9b44e71a_66ae_4baf_57a9_5cd698aa8602 --> 032186a9_8a8b_b603_4335_6ade22d767cb
  f8929fbd_6327_2bb8_f43b_31a3db2e4d74["node:path"]
  9b44e71a_66ae_4baf_57a9_5cd698aa8602 --> f8929fbd_6327_2bb8_f43b_31a3db2e4d74
  6bc9684c_1a71_1bdf_8ee4_8d5d204604b3["magic-string"]
  9b44e71a_66ae_4baf_57a9_5cd698aa8602 --> 6bc9684c_1a71_1bdf_8ee4_8d5d204604b3
  style 9b44e71a_66ae_4baf_57a9_5cd698aa8602 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { PreprocessorGroup, Preprocessor } from '../../../../src/compiler/public' */
import * as path from 'node:path';
import MagicString from 'magic-string';
import { test } from '../../test';

let indent_size = 4;
let comment_multi = true;

/**
 *
 * @param {'script' | 'style'} tag_name
 * @param {string} search
 * @param {string} replace
 * @returns {PreprocessorGroup}
 */
function get_processor(tag_name, search, replace) {
	/** @type {Preprocessor} */
	const preprocessor = ({ content, filename = '' }) => {
		let code = content.slice();
		const ms = new MagicString(code);

		const idx = ms.original.indexOf(search);
		if (idx == -1) throw new Error('search not found in src');
		ms.overwrite(idx, idx + search.length, replace, { storeName: true });

		// change line + column
		const indent = Array.from({ length: indent_size }).join(' ');
		ms.prependLeft(idx, '\n' + indent);

		const map_opts = { source: path.basename(filename), hires: true, includeContent: false };
		const map = ms.generateMap(map_opts);
		const attach_line =
			tag_name == 'style' || comment_multi
				? `\n/*# sourceMappingURL=${map.toUrl()} */`
				: `\n//# sourceMappingURL=${map.toUrl()}`; // only in script
		code = ms.toString() + attach_line;

		indent_size += 2;
		if (tag_name == 'script') comment_multi = !comment_multi;
		return { code };
	};

	return {
		[tag_name]: preprocessor
	};
}

export default test({
	preprocess: [
		get_processor('script', 'replace_me_script', 'done_replace_script_1'),
		get_processor('script', 'done_replace_script_1', 'done_replace_script_2'),

		get_processor('style', '.replace_me_style', '.done_replace_style_1'),
		get_processor('style', '.done_replace_style_1', '.done_replace_style_2')
	],
	client: [
		{ str: 'replace_me_script', strGenerated: 'done_replace_script_2' },
		{ str: 'done_replace_script_2', idxGenerated: 1 }
	],
	css: [{ str: '.replace_me_style', strGenerated: '.done_replace_style_2.svelte-1vsrjd4' }],
	test({ assert, code_preprocessed, code_css }) {
		assert.equal(
			code_preprocessed.includes('\n/*# sourceMappingURL=data:application/json;base64,'),
			false,
			'magic-comment attachments were NOT removed'
		);
		assert.equal(
			code_css.includes('\n/*# sourceMappingURL=data:application/json;base64,'),
			false,
			'magic-comment attachments were NOT removed'
		);
	}
});

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does _config.js do?
_config.js is a source file in the svelte codebase, written in javascript. It belongs to the BuildSystem domain, MessageProcessor subdomain.
What functions are defined in _config.js?
_config.js defines 2 function(s): default.test, get_processor.
What does _config.js depend on?
_config.js imports 3 module(s): magic-string, node:path, test.ts.
Where is _config.js in the architecture?
_config.js is located at packages/svelte/tests/sourcemaps/samples/attached-sourcemap/_config.js (domain: BuildSystem, subdomain: MessageProcessor, directory: packages/svelte/tests/sourcemaps/samples/attached-sourcemap).

Analyze Your Own Codebase

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

Try Supermodel Free