SyntheticArtifact emArt = null;
// no need to adjust source map
if (editArtifact == null) {
emArt = emitSourceMapString(logger, sourceMapString, partialPath);
} else {
SourceMapGeneratorV3 sourceMapGenerator = new SourceMapGeneratorV3();
if (se.getSourceRoot() != null) {
// Reapply source root since mergeMapSection() will not copy it.
sourceMapGenerator.setSourceRoot(se.getSourceRoot());
}
try {
int totalPrefixLines = 0;
for (ScriptFragmentEditsArtifact.EditOperation op : editArtifact.editOperations) {
if (op.getOp() == ScriptFragmentEditsArtifact.Edit.PREFIX) {
totalPrefixLines += op.getNumLines();
}
}
// TODO(cromwellian): apply insert and remove edits
sourceMapGenerator.mergeMapSection(totalPrefixLines, 0, sourceMapString,
new ExtensionMergeAction() {
@Override
public Object merge(String extKey, Object oldVal, Object newVal) {
return newVal;
}
});
StringWriter stringWriter = new StringWriter();
sourceMapGenerator.appendTo(stringWriter, "sourceMap");
emArt = emitSourceMapString(logger, stringWriter.toString(), partialPath);
} catch (Exception e) {
logger.log(TreeLogger.Type.WARN, "Can't write source map " + partialPath, e);
}
}