use of com.google.debugging.sourcemap.SourceMapConsumerV3 in project closure-compiler by google.
the class CompilerTest method testInputSourceMapInline.
@Test
public void testInputSourceMapInline() {
Compiler compiler = new Compiler();
compiler.initCompilerOptionsIfTesting();
String code = SOURCE_MAP_TEST_CODE + "\n//# sourceMappingURL=" + BASE64_ENCODED_SOURCE_MAP;
CompilerInput input = new CompilerInput(SourceFile.fromCode("tmp", code));
input.getAstRoot(compiler);
SourceMapInput inputSourceMap = compiler.inputSourceMaps.get("tmp");
SourceMapConsumerV3 sourceMap = inputSourceMap.getSourceMap(null);
assertThat(sourceMap.getOriginalSources()).containsExactly("foo.ts");
assertThat(sourceMap.getOriginalSourcesContent()).isNull();
}
use of com.google.debugging.sourcemap.SourceMapConsumerV3 in project st-js by st-js.
the class SourceMapUtils method mergeMapSection.
/**
* <p>mergeMapSection.</p>
*
* @param sourceMapFile a {@link java.io.File} object.
* @param packSourcemap a {@link com.google.debugging.sourcemap.SourceMapGeneratorV3} object.
* @param line a int.
* @param column a int.
* @param mapSectionContents a {@link java.lang.String} object.
* @throws com.google.debugging.sourcemap.SourceMapParseException if any.
*/
public static void mergeMapSection(File sourceMapFile, SourceMapGeneratorV3 packSourcemap, int line, int column, String mapSectionContents) throws SourceMapParseException {
packSourcemap.setStartingPosition(line, column);
SourceMapConsumerV3 section = new SourceMapConsumerV3();
section.parse(mapSectionContents);
section.visitMappings(new ConsumerEntryVisitor(packSourcemap, sourceMapFile));
}
use of com.google.debugging.sourcemap.SourceMapConsumerV3 in project closure-compiler by google.
the class Compiler method addSourceMapSourceFiles.
/**
* Adds file name to content mappings for all sources found in a source map. This is used to
* populate sourcesContent array in the output source map even for sources embedded in the input
* source map.
*/
private synchronized void addSourceMapSourceFiles(SourceMapInput inputSourceMap) {
// synchronized annotation guards concurrent access to sourceMap during parsing.
SourceMapConsumerV3 consumer = inputSourceMap.getSourceMap(errorManager);
if (consumer == null) {
return;
}
Collection<String> sourcesContent = consumer.getOriginalSourcesContent();
if (sourcesContent == null) {
return;
}
Iterator<String> content = sourcesContent.iterator();
Iterator<String> sources = consumer.getOriginalSources().iterator();
while (sources.hasNext() && content.hasNext()) {
String code = content.next();
SourceFile source = SourceMapResolver.getRelativePath(inputSourceMap.getOriginalPath(), sources.next());
if (source != null) {
sourceMap.addSourceFile(source.getName(), code);
}
}
if (sources.hasNext() || content.hasNext()) {
throw new RuntimeException("Source map's \"sources\" and \"sourcesContent\" lengths do not match.");
}
}
use of com.google.debugging.sourcemap.SourceMapConsumerV3 in project closure-compiler by google.
the class CoverageInstrumenterTest method testCompilerSupplier_instruments.
// Tests for CompilerSupplier
@Test
public void testCompilerSupplier_instruments() throws Exception {
CoverageInstrumenter.CompileResult result = compiler.compile(SOURCE_JS, "var x = 42;");
String[] expected = new String[] { "if(!self.window){self.window=self;self.window.top=self}", "var __jscov=window.top[\"__jscov\"]||", "(window.top[\"__jscov\"]={\"fileNames\":[],\"instrumentedLines\":[],\"executedLines\":[]});", "var JSCompiler_lcov_data_source_js=[];", "__jscov[\"executedLines\"].push(JSCompiler_lcov_data_source_js);", "__jscov[\"instrumentedLines\"].push(\"01\");", "__jscov[\"fileNames\"].push(\"source.js\");", "JSCompiler_lcov_data_source_js[0]=true;var x=42;" };
assertThat(result.source).isEqualTo(Joiner.on("").join(expected));
assertThat(result.errors).isEmpty();
assertThat(result.transformed).isTrue();
// Ensure that source map for "x" is correct.
SourceMapConsumerV3 sourceMap = new SourceMapConsumerV3();
sourceMap.parse(result.sourceMap);
OriginalMapping mappingFoX = sourceMap.getMappingForLine(1, result.source.indexOf("x=42") + 1);
assertThat(mappingFoX).isEqualTo(OriginalMapping.newBuilder().setOriginalFile(SOURCE_JS.toString()).setLineNumber(1).setColumnPosition(5).setIdentifier("x").setPrecision(Precision.EXACT).build());
}
use of com.google.debugging.sourcemap.SourceMapConsumerV3 in project closure-compiler by google.
the class CompilerTest method testResolveRelativeDirSourceMap.
// Make sure that the sourcemap resolution can find a sourcemap in a relative directory.
@Test
public void testResolveRelativeDirSourceMap() throws Exception {
Compiler compiler = new Compiler();
compiler.initCompilerOptionsIfTesting();
File tempDir = Files.createTempDir();
File relativedir = new File(tempDir, "/relativedir");
relativedir.mkdir();
String code = SOURCE_MAP_TEST_CODE + "\n//# sourceMappingURL=relativedir/foo.js.map";
File jsFile = new File(tempDir, "foo.js");
Files.asCharSink(jsFile, UTF_8).write(code);
File sourceMapFile = new File(relativedir, "foo.js.map");
Files.asCharSink(sourceMapFile, UTF_8).write(SOURCE_MAP);
CompilerInput input = new CompilerInput(SourceFile.fromFile(jsFile.getAbsolutePath()));
input.getAstRoot(compiler);
// The source map is still
assertThat(compiler.inputSourceMaps).hasSize(1);
for (SourceMapInput inputSourceMap : compiler.inputSourceMaps.values()) {
SourceMapConsumerV3 sourceMap = inputSourceMap.getSourceMap(null);
assertThat(sourceMap.getOriginalSources()).containsExactly("foo.ts");
}
}
Aggregations