This commit is contained in:
CHEVALLIER Abel
2025-11-13 16:23:22 +01:00
parent de9c515a47
commit cb235644dc
34924 changed files with 3811102 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export { ContentOrigin } from './src/content_origin';
export { MapAndPath, RawSourceMap } from './src/raw_source_map';
export { Mapping, SourceFile } from './src/source_file';
export { SourceFileLoader } from './src/source_file_loader';
+33
View File
@@ -0,0 +1,33 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/**
* From where the content for a source file or source-map came.
*
* - Source files can be linked to source-maps by:
* - providing the content inline via a base64 encoded data comment,
* - providing a URL to the file path in a comment,
* - the loader inferring the source-map path from the source file path.
* - Source-maps can link to source files by:
* - providing the content inline in the `sourcesContent` property
* - providing the path to the file in the `sources` property
*/
export declare enum ContentOrigin {
/**
* The contents were provided programmatically when calling `loadSourceFile()`.
*/
Provided = 0,
/**
* The contents were extracted directly form the contents of the referring file.
*/
Inline = 1,
/**
* The contents were loaded from the file-system, after being explicitly referenced or inferred
* from the referring file.
*/
FileSystem = 2
}
+38
View File
@@ -0,0 +1,38 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { AbsoluteFsPath } from '../../file_system';
import { ContentOrigin } from './content_origin';
/**
* This interface is the basic structure of the JSON in a raw source map that one might load from
* disk.
*/
export interface RawSourceMap {
version: number | string;
file?: string;
sourceRoot?: string;
sources: string[];
names: string[];
sourcesContent?: (string | null)[];
mappings: string;
}
/**
* The path and content of a source-map.
*/
export interface MapAndPath {
/** The path to the source map if it was external or `null` if it was inline. */
mapPath: AbsoluteFsPath | null;
/** The raw source map itself. */
map: RawSourceMap;
}
/**
* Information about a loaded source-map.
*/
export interface SourceMapInfo extends MapAndPath {
/** From where the content for this source-map came. */
origin: ContentOrigin;
}
+35
View File
@@ -0,0 +1,35 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
/**
* A marker that indicates the start of a segment in a mapping.
*
* The end of a segment is indicated by the first segment-marker of another mapping whose start
* is greater or equal to this one.
*/
export interface SegmentMarker {
readonly line: number;
readonly column: number;
readonly position: number;
next: SegmentMarker | undefined;
}
/**
* Compare two segment-markers, for use in a search or sorting algorithm.
*
* @returns a positive number if `a` is after `b`, a negative number if `b` is after `a`
* and zero if they are at the same position.
*/
export declare function compareSegments(a: SegmentMarker, b: SegmentMarker): number;
/**
* Return a new segment-marker that is offset by the given number of characters.
*
* @param startOfLinePositions the position of the start of each line of content of the source file
* whose segment-marker we are offsetting.
* @param marker the segment to offset.
* @param offset the number of character to offset by.
*/
export declare function offsetSegment(startOfLinePositions: number[], marker: SegmentMarker, offset: number): SegmentMarker;
+106
View File
@@ -0,0 +1,106 @@
import { AbsoluteFsPath, PathManipulation } from '../../file_system';
import { RawSourceMap, SourceMapInfo } from './raw_source_map';
import { SegmentMarker } from './segment_marker';
export declare function removeSourceMapComments(contents: string): string;
export declare class SourceFile {
/** The path to this source file. */
readonly sourcePath: AbsoluteFsPath;
/** The contents of this source file. */
readonly contents: string;
/** The raw source map (if any) referenced by this source file. */
readonly rawMap: SourceMapInfo | null;
/** Any source files referenced by the raw source map associated with this source file. */
readonly sources: (SourceFile | null)[];
private fs;
/**
* The parsed mappings that have been flattened so that any intermediate source mappings have been
* flattened.
*
* The result is that any source file mentioned in the flattened mappings have no source map (are
* pure original source files).
*/
readonly flattenedMappings: Mapping[];
readonly startOfLinePositions: number[];
constructor(
/** The path to this source file. */
sourcePath: AbsoluteFsPath,
/** The contents of this source file. */
contents: string,
/** The raw source map (if any) referenced by this source file. */
rawMap: SourceMapInfo | null,
/** Any source files referenced by the raw source map associated with this source file. */
sources: (SourceFile | null)[], fs: PathManipulation);
/**
* Render the raw source map generated from the flattened mappings.
*/
renderFlattenedSourceMap(): RawSourceMap;
/**
* Find the original mapped location for the given `line` and `column` in the generated file.
*
* First we search for a mapping whose generated segment is at or directly before the given
* location. Then we compute the offset between the given location and the matching generated
* segment. Finally we apply this offset to the original source segment to get the desired
* original location.
*/
getOriginalLocation(line: number, column: number): {
file: AbsoluteFsPath;
line: number;
column: number;
} | null;
/**
* Flatten the parsed mappings for this source file, so that all the mappings are to pure original
* source files with no transitive source maps.
*/
private flattenMappings;
}
/**
*
* @param mappings The collection of mappings whose segment-markers we are searching.
* @param marker The segment-marker to match against those of the given `mappings`.
* @param exclusive If exclusive then we must find a mapping with a segment-marker that is
* exclusively earlier than the given `marker`.
* If not exclusive then we can return the highest mappings with an equivalent segment-marker to the
* given `marker`.
* @param lowerIndex If provided, this is used as a hint that the marker we are searching for has an
* index that is no lower than this.
*/
export declare function findLastMappingIndexBefore(mappings: Mapping[], marker: SegmentMarker, exclusive: boolean, lowerIndex: number): number;
/**
* A Mapping consists of two segment markers: one in the generated source and one in the original
* source, which indicate the start of each segment. The end of a segment is indicated by the first
* segment marker of another mapping whose start is greater or equal to this one.
*
* It may also include a name associated with the segment being mapped.
*/
export interface Mapping {
readonly generatedSegment: SegmentMarker;
readonly originalSource: SourceFile;
readonly originalSegment: SegmentMarker;
readonly name?: string;
}
/**
* Merge two mappings that go from A to B and B to C, to result in a mapping that goes from A to C.
*/
export declare function mergeMappings(generatedSource: SourceFile, ab: Mapping, bc: Mapping): Mapping;
/**
* Parse the `rawMappings` into an array of parsed mappings, which reference source-files provided
* in the `sources` parameter.
*/
export declare function parseMappings(rawMap: RawSourceMap | null, sources: (SourceFile | null)[], generatedSourceStartOfLinePositions: number[]): Mapping[];
/**
* Extract the segment markers from the original source files in each mapping of an array of
* `mappings`.
*
* @param mappings The mappings whose original segments we want to extract
* @returns Return a map from original source-files (referenced in the `mappings`) to arrays of
* segment-markers sorted by their order in their source file.
*/
export declare function extractOriginalSegments(mappings: Mapping[]): Map<SourceFile, SegmentMarker[]>;
/**
* Update the original segments of each of the given `mappings` to include a link to the next
* segment in the source file.
*
* @param mappings the mappings whose segments should be updated
*/
export declare function ensureOriginalSegmentLinks(mappings: Mapping[]): void;
export declare function computeStartOfLinePositions(str: string): number[];
+114
View File
@@ -0,0 +1,114 @@
import { AbsoluteFsPath, ReadonlyFileSystem } from '../../file_system';
import { Logger } from '../../logging';
import { MapAndPath } from './raw_source_map';
import { SourceFile } from './source_file';
/**
* This class can be used to load a source file, its associated source map and any upstream sources.
*
* Since a source file might reference (or include) a source map, this class can load those too.
* Since a source map might reference other source files, these are also loaded as needed.
*
* This is done recursively. The result is a "tree" of `SourceFile` objects, each containing
* mappings to other `SourceFile` objects as necessary.
*/
export declare class SourceFileLoader {
private fs;
private logger;
/** A map of URL schemes to base paths. The scheme name should be lowercase. */
private schemeMap;
private currentPaths;
constructor(fs: ReadonlyFileSystem, logger: Logger,
/** A map of URL schemes to base paths. The scheme name should be lowercase. */
schemeMap: Record<string, AbsoluteFsPath>);
/**
* Load a source file from the provided content and source map, and recursively load any
* referenced source files.
*
* @param sourcePath The path to the source file to load.
* @param contents The contents of the source file to load.
* @param mapAndPath The raw source-map and the path to the source-map file.
* @returns a SourceFile object created from the `contents` and provided source-map info.
*/
loadSourceFile(sourcePath: AbsoluteFsPath, contents: string, mapAndPath: MapAndPath): SourceFile;
/**
* Load a source file from the provided content, compute its source map, and recursively load any
* referenced source files.
*
* @param sourcePath The path to the source file to load.
* @param contents The contents of the source file to load.
* @returns a SourceFile object created from the `contents` and computed source-map info.
*/
loadSourceFile(sourcePath: AbsoluteFsPath, contents: string): SourceFile;
/**
* Load a source file from the file-system, compute its source map, and recursively load any
* referenced source files.
*
* @param sourcePath The path to the source file to load.
* @returns a SourceFile object if its contents could be loaded from disk, or null otherwise.
*/
loadSourceFile(sourcePath: AbsoluteFsPath): SourceFile | null;
/**
* The overload used internally to load source files referenced in a source-map.
*
* In this case there is no guarantee that it will return a non-null SourceMap.
*
* @param sourcePath The path to the source file to load.
* @param contents The contents of the source file to load, if provided inline. If `null`,
* the contents will be read from the file at the `sourcePath`.
* @param sourceOrigin Describes where the source content came from.
* @param sourceMapInfo The raw contents and path of the source-map file. If `null` the
* source-map will be computed from the contents of the source file, either inline or loaded
* from the file-system.
*
* @returns a SourceFile if the content for one was provided or was able to be loaded from disk,
* `null` otherwise.
*/
private loadSourceFileInternal;
/**
* Find the source map associated with the source file whose `sourcePath` and `contents` are
* provided.
*
* Source maps can be inline, as part of a base64 encoded comment, or external as a separate file
* whose path is indicated in a comment or implied from the name of the source file itself.
*
* @param sourcePath the path to the source file.
* @param sourceContents the contents of the source file.
* @param sourceOrigin where the content of the source file came from.
* @returns the parsed contents and path of the source-map, if loading was successful, null
* otherwise.
*/
private loadSourceMap;
/**
* Iterate over each of the "sources" for this source file's source map, recursively loading each
* source file and its associated source map.
*/
private processSources;
/**
* Load the contents of the source file from disk.
*
* @param sourcePath The path to the source file.
*/
private readSourceFile;
/**
* Load the source map from the file at `mapPath`, parsing its JSON contents into a `RawSourceMap`
* object.
*
* @param mapPath The path to the source-map file.
*/
private readRawSourceMap;
/**
* Track source file paths if we have loaded them from disk so that we don't get into an infinite
* recursion.
*/
private trackPath;
private getLastNonEmptyLine;
/**
* Replace any matched URL schemes with their corresponding path held in the schemeMap.
*
* Some build tools replace real file paths with scheme prefixed paths - e.g. `webpack://`.
* We use the `schemeMap` passed to this class to convert such paths to "real" file paths.
* In some cases, this is not possible, since the file was actually synthesized by the build tool.
* But the end result is better than prefixing the sourceRoot in front of the scheme.
*/
private replaceSchemeWithPath;
}