MCPcopy Create free account
hub / github.com/Snapchat/Valdi / Source

Class Source

valdi/vscode_debugger/src/adapter/sources.ts:105–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103// source1._compiledToSourceUrl.get(compiled1) === sourceUrl
104//
105export class Source {
106 private readonly _sourceReference: number;
107 private readonly _name: string;
108 private readonly _fqname: string;
109
110 /**
111 * Function to retrieve the content of the source.
112 */
113 private readonly _contentGetter: ContentGetter;
114
115 private readonly _container: SourceContainer;
116
117 // Url has been mapped to some absolute path.
118 private readonly _absolutePath: string;
119
120 public sourceMap?: ISourceWithMap['sourceMap'];
121
122 // This is the same as |_absolutePath|, but additionally checks that file exists to
123 // avoid errors when page refers to non-existing paths/urls.
124 private readonly _existingAbsolutePath: Promise<string | undefined>;
125 private readonly _scriptIds: Cdp.Runtime.ScriptId[] = [];
126
127 /**
128 * @param inlineScriptOffset Offset of the start location of the script in
129 * its source file. This is used on scripts in HTML pages, where the script
130 * is nested in the content.
131 * @param contentHash Optional hash of the file contents. This is used to
132 * check whether the script we get is the same one as what's on disk. This
133 * can be used to detect in-place transpilation.
134 */
135 constructor(
136 container: SourceContainer,
137 public readonly url: string,
138 absolutePath: string | undefined,
139 contentGetter: ContentGetter,
140 sourceMapUrl?: string,
141 public readonly inlineScriptOffset?: InlineScriptOffset,
142 contentHash?: string,
143 ) {
144 this._sourceReference = container.getSourceReference(url);
145 this._contentGetter = once(contentGetter);
146 this._container = container;
147 this._absolutePath = absolutePath || '';
148 this._fqname = this._fullyQualifiedName();
149 this._name = this._humanName();
150 this.setSourceMapUrl(sourceMapUrl);
151
152 this._existingAbsolutePath = sourceUtils.checkContentHash(
153 this._absolutePath,
154 // Inline scripts will never match content of the html file. We skip the content check.
155 inlineScriptOffset ? undefined : contentHash,
156 container._fileContentOverridesForTest.get(this._absolutePath),
157 );
158 }
159
160 private setSourceMapUrl(sourceMapUrl?: string) {
161 if (!sourceMapUrl) {
162 this.sourceMap = undefined;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected