|
14 | 14 | #include "hermes/Runtime/Libhermes.h"
|
15 | 15 | #include "hermes/Sema/SemContext.h"
|
16 | 16 | #include "hermes/Sema/SemResolve.h"
|
| 17 | +#include "hermes/SourceMap/SourceMapParser.h" |
17 | 18 | #include "hermes/SourceMap/SourceMapTranslator.h"
|
18 | 19 | #include "hermes/Support/MemoryBuffer.h"
|
19 | 20 | #include "hermes/Support/SimpleDiagHandler.h"
|
@@ -87,7 +88,7 @@ std::pair<std::unique_ptr<BCProviderFromSrc>, std::string>
|
87 | 88 | BCProviderFromSrc::create(
|
88 | 89 | std::unique_ptr<Buffer> buffer,
|
89 | 90 | llvh::StringRef sourceURL,
|
90 |
| - std::unique_ptr<SourceMap> sourceMap, |
| 91 | + llvh::StringRef sourceMap, |
91 | 92 | const CompileFlags &compileFlags,
|
92 | 93 | llvh::StringRef topLevelFunctionName,
|
93 | 94 | SourceErrorManager::DiagHandlerTy diagHandler,
|
@@ -161,11 +162,26 @@ BCProviderFromSrc::create(
|
161 | 162 | buffer->size() >= context->getPreemptiveFileCompilationThreshold();
|
162 | 163 | int fileBufId = context->getSourceErrorManager().addNewSourceBuffer(
|
163 | 164 | std::make_unique<HermesLLVMMemoryBuffer>(std::move(buffer), sourceURL));
|
164 |
| - if (sourceMap != nullptr) { |
| 165 | + |
| 166 | + if (!sourceMap.empty()) { |
| 167 | + assert(sourceMap.back() == '\0' && "Must be null terminated"); |
| 168 | + // Convert the buffer into a form the parser needs. Note that the incoming |
| 169 | + // buffer has the null terminator embedded at the end, whereas for the |
| 170 | + // MemoryBuffer we want it past-the-end, so we shrink it by one. |
| 171 | + llvh::MemoryBufferRef mbref( |
| 172 | + llvh::StringRef{sourceMap.data(), sourceMap.size() - 1}, ""); |
| 173 | + SimpleDiagHandler diag; |
| 174 | + SourceErrorManager sm; |
| 175 | + diag.installInto(sm); |
| 176 | + std::unique_ptr<SourceMap> parsedSM = SourceMapParser::parse(mbref, {}, sm); |
| 177 | + if (!parsedSM) { |
| 178 | + auto errorStr = diag.getErrorString(); |
| 179 | + return std::make_pair(nullptr, "Error parsing source map: " + errorStr); |
| 180 | + } |
165 | 181 | auto sourceMapTranslator =
|
166 | 182 | std::make_shared<SourceMapTranslator>(context->getSourceErrorManager());
|
167 | 183 | context->getSourceErrorManager().setTranslator(sourceMapTranslator);
|
168 |
| - sourceMapTranslator->addSourceMap(fileBufId, std::move(sourceMap)); |
| 184 | + sourceMapTranslator->addSourceMap(fileBufId, std::move(parsedSM)); |
169 | 185 | }
|
170 | 186 |
|
171 | 187 | auto parserMode = parser::FullParse;
|
|
0 commit comments