use of com.google.debugging.sourcemap.FilePosition in project st-js by st-js.
the class RhinoJavaScriptWriter method addMapping.
/**
* <p>addMapping.</p>
*/
protected void addMapping() {
if (generateSourceMap) {
FilePosition endJavaScriptPosition = new FilePosition(currentLine, currentColumn);
if (javaPosition != null && javaPosition.getLine() >= 0 && javaPosition.getColumn() >= 0) {
sourceMapGenerator.addMapping(inputFile.getName(), null, javaPosition, javaScriptPosition, endJavaScriptPosition);
javaPosition = null;
}
}
}
use of com.google.debugging.sourcemap.FilePosition in project closure-compiler by google.
the class JsMessageVisitorTest method testJsMessagesWithSrcMap.
public void testJsMessagesWithSrcMap() throws Exception {
SourceMapGeneratorV3 sourceMap = new SourceMapGeneratorV3();
sourceMap.addMapping("source1.html", null, new FilePosition(10, 0), new FilePosition(0, 0), new FilePosition(0, 100));
sourceMap.addMapping("source2.html", null, new FilePosition(10, 0), new FilePosition(1, 0), new FilePosition(1, 100));
StringBuilder output = new StringBuilder();
sourceMap.appendTo(output, "unused.js");
compilerOptions = new CompilerOptions();
compilerOptions.inputSourceMaps = ImmutableMap.of("[testcode]", new SourceMapInput(SourceFile.fromCode("example.srcmap", output.toString())));
extractMessagesSafely("/** @desc Hello */ var MSG_HELLO = goog.getMsg('a');\n" + "/** @desc Hi */ var MSG_HI = goog.getMsg('b');\n");
assertThat(compiler.getWarnings()).isEmpty();
assertThat(messages).hasSize(2);
JsMessage msg1 = messages.get(0);
assertEquals("MSG_HELLO", msg1.getKey());
assertEquals("Hello", msg1.getDesc());
assertEquals("source1.html", msg1.getSourceName());
JsMessage msg2 = messages.get(1);
assertEquals("MSG_HI", msg2.getKey());
assertEquals("Hi", msg2.getDesc());
assertEquals("source2.html", msg2.getSourceName());
}
use of com.google.debugging.sourcemap.FilePosition in project closure-compiler by google.
the class CompilerTest method testApplyInputSourceMaps.
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");
}
Aggregations