mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
src,lib: retrieve parsed source map url from v8
V8 already parses the source map magic comments. Currently, only scripts and functions expose the parsed source map URLs. It is unnecessary to parse the source map magic comments again when the parsed information is available. PR-URL: https://github.com/nodejs/node/pull/44798 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
This commit is contained in:
1 parent
3ddb6ccb2a
commit
12779b3e02
10 files changed
+282
-143
No files matched your search
@@ -97,7 +97,21 @@ function extractSourceURLMagicComment(content) {
|
||||
return sourceURL;
|
||||
}
|
||||
|
||||
function maybeCacheSourceMap(filename, content, cjsModuleInstance, isGeneratedSource, sourceURL) {
|
||||
function extractSourceMapURLMagicComment(content) {
|
||||
let match;
|
||||
let lastMatch;
|
||||
// A while loop is used here to get the last occurrence of sourceMappingURL.
|
||||
// This is needed so that we don't match sourceMappingURL in string literals.
|
||||
while ((match = RegExpPrototypeExec(kSourceMappingURLMagicComment, content))) {
|
||||
lastMatch = match;
|
||||
}
|
||||
if (lastMatch == null) {
|
||||
return null;
|
||||
}
|
||||
return lastMatch.groups.sourceMappingURL;
|
||||
}
|
||||
|
||||
function maybeCacheSourceMap(filename, content, cjsModuleInstance, isGeneratedSource, sourceURL, sourceMapURL) {
|
||||
const sourceMapsEnabled = getSourceMapsEnabled();
|
||||
if (!(process.env.NODE_V8_COVERAGE || sourceMapsEnabled)) return;
|
||||
try {
|
||||
@@ -108,52 +122,52 @@ function maybeCacheSourceMap(filename, content, cjsModuleInstance, isGeneratedSo
|
||||
return;
|
||||
}
|
||||
|
||||
let match;
|
||||
let lastMatch;
|
||||
// A while loop is used here to get the last occurrence of sourceMappingURL.
|
||||
// This is needed so that we don't match sourceMappingURL in string literals.
|
||||
while ((match = RegExpPrototypeExec(kSourceMappingURLMagicComment, content))) {
|
||||
lastMatch = match;
|
||||
if (sourceMapURL === undefined) {
|
||||
sourceMapURL = extractSourceMapURLMagicComment(content);
|
||||
}
|
||||
|
||||
// Bail out when there is no source map url.
|
||||
if (typeof sourceMapURL !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sourceURL === undefined) {
|
||||
sourceURL = extractSourceURLMagicComment(content);
|
||||
}
|
||||
if (lastMatch) {
|
||||
const data = dataFromUrl(filename, lastMatch.groups.sourceMappingURL);
|
||||
const url = data ? null : lastMatch.groups.sourceMappingURL;
|
||||
if (cjsModuleInstance) {
|
||||
cjsSourceMapCache.set(cjsModuleInstance, {
|
||||
filename,
|
||||
lineLengths: lineLengths(content),
|
||||
data,
|
||||
url,
|
||||
sourceURL,
|
||||
});
|
||||
} else if (isGeneratedSource) {
|
||||
const entry = {
|
||||
lineLengths: lineLengths(content),
|
||||
data,
|
||||
url,
|
||||
sourceURL
|
||||
};
|
||||
generatedSourceMapCache.set(filename, entry);
|
||||
if (sourceURL) {
|
||||
generatedSourceMapCache.set(sourceURL, entry);
|
||||
}
|
||||
} else {
|
||||
// If there is no cjsModuleInstance and is not generated source assume we are in a
|
||||
// "modules/esm" context.
|
||||
const entry = {
|
||||
lineLengths: lineLengths(content),
|
||||
data,
|
||||
url,
|
||||
sourceURL,
|
||||
};
|
||||
esmSourceMapCache.set(filename, entry);
|
||||
if (sourceURL) {
|
||||
esmSourceMapCache.set(sourceURL, entry);
|
||||
}
|
||||
|
||||
const data = dataFromUrl(filename, sourceMapURL);
|
||||
const url = data ? null : sourceMapURL;
|
||||
if (cjsModuleInstance) {
|
||||
cjsSourceMapCache.set(cjsModuleInstance, {
|
||||
filename,
|
||||
lineLengths: lineLengths(content),
|
||||
data,
|
||||
url,
|
||||
sourceURL,
|
||||
});
|
||||
} else if (isGeneratedSource) {
|
||||
const entry = {
|
||||
lineLengths: lineLengths(content),
|
||||
data,
|
||||
url,
|
||||
sourceURL
|
||||
};
|
||||
generatedSourceMapCache.set(filename, entry);
|
||||
if (sourceURL) {
|
||||
generatedSourceMapCache.set(sourceURL, entry);
|
||||
}
|
||||
} else {
|
||||
// If there is no cjsModuleInstance and is not generated source assume we are in a
|
||||
// "modules/esm" context.
|
||||
const entry = {
|
||||
lineLengths: lineLengths(content),
|
||||
data,
|
||||
url,
|
||||
sourceURL,
|
||||
};
|
||||
esmSourceMapCache.set(filename, entry);
|
||||
if (sourceURL) {
|
||||
esmSourceMapCache.set(sourceURL, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user