use of com.google.debugging.sourcemap.SourceMapConsumerV3 in project closure-compiler by google.
the class CompilerTest method testInputSourceMapInlineContent.
@Test
public void testInputSourceMapInlineContent() {
Compiler compiler = new Compiler();
compiler.initCompilerOptionsIfTesting();
String code = SOURCE_MAP_TEST_CODE + "\n//# sourceMappingURL=" + BASE64_ENCODED_SOURCE_MAP_WITH_CONTENT;
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("../test/foo.ts");
assertThat(sourceMap.getOriginalSourcesContent()).containsExactly(SOURCE_MAP_TEST_CONTENT);
}
use of com.google.debugging.sourcemap.SourceMapConsumerV3 in project closure-compiler by google.
the class CompilerTest method testApplyInputSourceMaps.
@Test
public void testApplyInputSourceMaps() throws Exception {
FilePosition originalSourcePosition = new FilePosition(17, 25);
ImmutableMap<String, SourceMapInput> inputSourceMaps = ImmutableMap.of("input.js", sourcemap("input.js.map", "input.ts", originalSourcePosition));
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT3);
options.sourceMapOutputPath = "fake/source_map_path.js.map";
options.inputSourceMaps = inputSourceMaps;
options.applyInputSourceMaps = true;
Compiler compiler = new Compiler();
compiler.compile(EMPTY_EXTERNS.get(0), SourceFile.fromCode("input.js", "// Unmapped line\nvar x = 1;\nalert(x);"), options);
assertThat(compiler.toSource()).isEqualTo("var x=1;alert(x);");
SourceMap sourceMap = compiler.getSourceMap();
StringWriter out = new StringWriter();
sourceMap.appendTo(out, "source.js.map");
SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
consumer.parse(out.toString());
// Column 5 contains the first actually mapped code ('x').
OriginalMapping mapping = consumer.getMappingForLine(1, 5);
assertThat(mapping.getOriginalFile()).isEqualTo("input.ts");
// FilePosition above is 0-based, whereas OriginalMapping is 1-based, thus 18 & 26.
assertThat(mapping.getLineNumber()).isEqualTo(18);
assertThat(mapping.getColumnPosition()).isEqualTo(26);
assertThat(mapping.getIdentifier()).isEqualTo("testSymbolName");
assertThat(consumer.getOriginalSources()).containsExactly("input.js", "input.ts");
assertThat(consumer.getOriginalSourcesContent()).isNull();
}
Aggregations