| 388 | result.push_back(*it); |
| 389 | } |
| 390 | } |
| 391 | return result; |
| 392 | } |
| 393 | |
| 394 | void 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 | } |
nothing calls this directly
no test coverage detected