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

Method populateSourceMap

valdi/src/valdi/runtime/Resources/ResourceManager.cpp:390–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

388 result.push_back(*it);
389 }
390 }
391 return result;
392}
393
394void ResourceManager::populateSourceMap(const StringBox& bundleName, Bundle& bundle) {
395 auto sourceMapFilePath = resolveSourceMapFilePath(bundleName);
396 auto sourceMapContent = _resourceLoader->loadModuleContent(sourceMapFilePath);
397 if (!sourceMapContent) {
398 return;
399 }
400 auto sourceMapIndexJson = jsonToValue(sourceMapContent.value().data(), sourceMapContent.value().size());
401 if (!sourceMapIndexJson || !sourceMapIndexJson.value().isMap()) {
402 VALDI_WARN(_logger, "Invalid source map index file");
403 return;
404 }
405
406 auto expectedPrefix = bundleName.append("/");
407 auto expectedSuffix = STRING_LITERAL(".js");
408
409 for (const auto& it : *sourceMapIndexJson.value().getMap()) {
410 if (!it.second.isString() || !it.first.hasPrefix(expectedPrefix) || !it.first.hasSuffix(expectedSuffix)) {
411 VALDI_WARN(_logger, "Invalid source map entry for {}", it.first);
412 continue;
413 }
414
415 auto fileKey = it.first.substring(expectedPrefix.length(), it.first.length() - expectedSuffix.length());
416
417 // Inject the source map content into the bundle
418 auto jsFile = bundle.getJs(fileKey);
419
420 if (jsFile) {
421 bundle.setJs(fileKey, JavaScriptFile(jsFile.value().content, it.second.toStringBox()));
422 }
423 }

Callers

nothing calls this directly

Calls 15

resolveSourceMapFilePathFunction · 0.85
JavaScriptFileClass · 0.85
hasPrefixMethod · 0.80
hasSuffixMethod · 0.80
substringMethod · 0.80
getJsMethod · 0.80
setJsMethod · 0.80
valueMethod · 0.65
appendMethod · 0.65
getMapMethod · 0.65
jsonToValueFunction · 0.50
loadModuleContentMethod · 0.45

Tested by

no test coverage detected