MappedCode Class — svelte Architecture
Architecture documentation for the MappedCode class in mapped_code.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD fd3be7c7_b876_965d_9025_a9b9bd4c6aaf["MappedCode"] d383a41d_5383_ee86_cab6_03bf1a2daf93["mapped_code.js"] fd3be7c7_b876_965d_9025_a9b9bd4c6aaf -->|defined in| d383a41d_5383_ee86_cab6_03bf1a2daf93 e64656f9_6ff7_1b3f_c5a7_c4a987972d5d["constructor()"] fd3be7c7_b876_965d_9025_a9b9bd4c6aaf -->|method| e64656f9_6ff7_1b3f_c5a7_c4a987972d5d 0b0d6cc0_5fd9_5ba4_3426_05a4a4d6e501["concat()"] fd3be7c7_b876_965d_9025_a9b9bd4c6aaf -->|method| 0b0d6cc0_5fd9_5ba4_3426_05a4a4d6e501 0306cc9d_f615_8a46_ac65_f39600cad75c["from_processed()"] fd3be7c7_b876_965d_9025_a9b9bd4c6aaf -->|method| 0306cc9d_f615_8a46_ac65_f39600cad75c f60b5bcd_c389_6937_b4c0_e720a97b643a["from_source()"] fd3be7c7_b876_965d_9025_a9b9bd4c6aaf -->|method| f60b5bcd_c389_6937_b4c0_e720a97b643a
Relationship Graph
Source Code
packages/svelte/src/compiler/utils/mapped_code.js lines 75–249
export class MappedCode {
/**
* @type {string}
*/
string = /** @type {any} */ (undefined);
/**
* @type {DecodedSourceMap}
*/
map = /** @type {any} */ (undefined);
/**
* @param {string} string
* @param {DecodedSourceMap | null} map
*/
constructor(string = '', map = null) {
this.string = string;
if (map) {
this.map = map;
} else {
this.map = {
version: 3,
mappings: [],
sources: [],
names: []
};
}
}
/**
* concat in-place (mutable), return this (chainable)
* will also mutate the `other` object
* @param {MappedCode} other
* @returns {MappedCode}
*/
concat(other) {
// noop: if one is empty, return the other
if (other.string == '') return this;
if (this.string == '') {
this.string = other.string;
this.map = other.map;
return this;
}
// compute last line length before mutating
const column_offset = last_line_length(this.string);
this.string += other.string;
const m1 = this.map;
const m2 = other.map;
if (m2.mappings.length == 0) return this;
// combine sources and names
const [sources, new_source_idx, sources_changed, sources_idx_changed] = merge_tables(
m1.sources,
m2.sources
);
const [names, new_name_idx, names_changed, names_idx_changed] = merge_tables(
m1.names,
m2.names
);
if (sources_changed) m1.sources = sources;
if (names_changed) m1.names = names;
// unswitched loops are faster
if (sources_idx_changed && names_idx_changed) {
for (let line = 0; line < m2.mappings.length; line++) {
const segment_list = m2.mappings[line];
for (let segment = 0; segment < segment_list.length; segment++) {
const seg = segment_list[segment];
// @ts-ignore
if (seg[1] >= 0) seg[1] = new_source_idx[seg[1]];
// @ts-ignore
if (seg[4] >= 0) seg[4] = new_name_idx[seg[4]];
}
}
} else if (sources_idx_changed) {
for (let line = 0; line < m2.mappings.length; line++) {
const segment_list = m2.mappings[line];
for (let segment = 0; segment < segment_list.length; segment++) {
const seg = segment_list[segment];
// @ts-ignore
if (seg[1] >= 0) seg[1] = new_source_idx[seg[1]];
}
}
} else if (names_idx_changed) {
Domain
Source
Frequently Asked Questions
What is the MappedCode class?
MappedCode is a class in the svelte codebase, defined in packages/svelte/src/compiler/utils/mapped_code.js.
Where is MappedCode defined?
MappedCode is defined in packages/svelte/src/compiler/utils/mapped_code.js at line 75.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free