Search in sources :

Example 11 with SourceMapConsumerV3

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);
}
Also used : SourceMapConsumerV3(com.google.debugging.sourcemap.SourceMapConsumerV3) Test(org.junit.Test)

Example 12 with SourceMapConsumerV3

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();
}
Also used : OriginalMapping(com.google.debugging.sourcemap.proto.Mapping.OriginalMapping) StringWriter(java.io.StringWriter) SourceMapConsumerV3(com.google.debugging.sourcemap.SourceMapConsumerV3) FilePosition(com.google.debugging.sourcemap.FilePosition) Test(org.junit.Test)

Aggregations

SourceMapConsumerV3 (com.google.debugging.sourcemap.SourceMapConsumerV3)12 Test (org.junit.Test)8 OriginalMapping (com.google.debugging.sourcemap.proto.Mapping.OriginalMapping)3 File (java.io.File)3 StringWriter (java.io.StringWriter)2 Nullable (javax.annotation.Nullable)2 FilePosition (com.google.debugging.sourcemap.FilePosition)1 SourceMapParseException (com.google.debugging.sourcemap.SourceMapParseException)1 IOException (java.io.IOException)1