PreprocessResult Class — svelte Architecture
Architecture documentation for the PreprocessResult class in index.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 9ef48db2_c88d_10c7_b63f_fd4636d6af64["PreprocessResult"] ccf6927a_1f1b_1dda_8616_80903a72ba16["index.js"] 9ef48db2_c88d_10c7_b63f_fd4636d6af64 -->|defined in| ccf6927a_1f1b_1dda_8616_80903a72ba16 8b0fef22_ce16_3247_853b_ae59259233fc["constructor()"] 9ef48db2_c88d_10c7_b63f_fd4636d6af64 -->|method| 8b0fef22_ce16_3247_853b_ae59259233fc eb4cb57f_c661_15ec_a226_3092a5663cd9["update_source()"] 9ef48db2_c88d_10c7_b63f_fd4636d6af64 -->|method| eb4cb57f_c661_15ec_a226_3092a5663cd9 d378c79f_a5b8_3e96_866c_2dfa63c43532["to_processed()"] 9ef48db2_c88d_10c7_b63f_fd4636d6af64 -->|method| d378c79f_a5b8_3e96_866c_2dfa63c43532
Relationship Graph
Source Code
packages/svelte/src/compiler/preprocess/index.js lines 19–99
class PreprocessResult {
/** @type {string} */
source;
/** @type {string | undefined} The filename passed as-is to preprocess */
filename;
// sourcemap_list is sorted in reverse order from last map (index 0) to first map (index -1)
// so we use sourcemap_list.unshift() to add new maps
// https://github.com/jridgewell/sourcemaps/tree/main/packages/remapping#multiple-transformations-of-a-file
/**
* @default []
* @type {Array<DecodedSourceMap | RawSourceMap>}
*/
sourcemap_list = [];
/**
* @default []
* @type {string[]}
*/
dependencies = [];
/**
* @type {string | null} last part of the filename, as used for `sources` in sourcemaps
*/
file_basename = /** @type {any} */ (undefined);
/**
* @type {ReturnType<typeof getLocator>}
*/
get_location = /** @type {any} */ (undefined);
/**
* @param {string} source
* @param {string} [filename]
*/
constructor(source, filename) {
this.source = source;
this.filename = filename;
this.update_source({ string: source });
// preprocess source must be relative to itself or equal null
this.file_basename = filename == null ? null : get_basename(filename);
}
/**
* @param {SourceUpdate} opts
*/
update_source({ string: source, map, dependencies }) {
if (source != null) {
this.source = source;
this.get_location = getLocator(source);
}
if (map) {
this.sourcemap_list.unshift(map);
}
if (dependencies) {
this.dependencies.push(...dependencies);
}
}
/**
* @returns {Processed}
*/
to_processed() {
// Combine all the source maps for each preprocessor function into one
// @ts-expect-error TODO there might be a bug in hiding here
const map = combine_sourcemaps(this.file_basename, this.sourcemap_list);
return {
// TODO return separated output, in future version where svelte.compile supports it:
// style: { code: styleCode, map: styleMap },
// script { code: scriptCode, map: scriptMap },
// markup { code: markupCode, map: markupMap },
code: this.source,
dependencies: [...new Set(this.dependencies)],
// @ts-expect-error TODO there might be a bug in hiding here
map,
toString: () => this.source
};
}
}
Domain
Source
Frequently Asked Questions
What is the PreprocessResult class?
PreprocessResult is a class in the svelte codebase, defined in packages/svelte/src/compiler/preprocess/index.js.
Where is PreprocessResult defined?
PreprocessResult is defined in packages/svelte/src/compiler/preprocess/index.js at line 19.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free