use of com.google.debugging.sourcemap.FilePosition in project st-js by st-js.
the class RhinoJavaScriptWriter method endPosition.
/**
* this is only for statements on several lines to be able to catch end of inline function defintions
*
* @param node a {@link org.mozilla.javascript.ast.AstNode} object.
*/
protected void endPosition(AstNode node) {
if (generateSourceMap) {
boolean hasPosition = javaScriptPosition != null && javaScriptPosition.getLine() != currentLine;
if (hasPosition) {
javaPosition = new FilePosition(RhinoJavaScriptBuilder.getEndLineNumber(node) - 1, RhinoJavaScriptBuilder.getEndColumnNumber(node) - 1);
javaScriptPosition = new FilePosition(currentLine, currentColumn);
}
}
}
use of com.google.debugging.sourcemap.FilePosition in project closure-compiler by google.
the class SourceMap method addMapping.
public void addMapping(Node node, FilePosition outputStartPosition, FilePosition outputEndPosition) {
String sourceFile = node.getSourceFileName();
// information for a mapping to be useful.
if (sourceFile == null || node.getLineno() < 0) {
return;
}
int lineNo = node.getLineno();
int charNo = node.getCharno();
String originalName = node.getOriginalName();
if (mapping != null) {
OriginalMapping sourceMapping = mapping.getSourceMapping(sourceFile, lineNo, charNo);
if (sourceMapping != null) {
sourceFile = sourceMapping.getOriginalFile();
lineNo = sourceMapping.getLineNumber();
charNo = sourceMapping.getColumnPosition();
originalName = sourceMapping.getIdentifier();
}
}
sourceFile = fixupSourceLocation(sourceFile);
// Rhino source lines are one based but for v3 source maps, we make
// them zero based.
int lineBaseOffset = 1;
generator.addMapping(sourceFile, originalName, new FilePosition(lineNo - lineBaseOffset, charNo), outputStartPosition, outputEndPosition);
}
use of com.google.debugging.sourcemap.FilePosition in project closure-compiler by google.
the class CompilerTest method testInputSourceMaps.
public void testInputSourceMaps() throws Exception {
FilePosition originalSourcePosition = new FilePosition(17, 25);
ImmutableMap<String, SourceMapInput> inputSourceMaps = ImmutableMap.of(normalize("generated_js/example.js"), sourcemap(normalize("generated_js/example.srcmap"), normalize("../original/source.html"), originalSourcePosition));
String origSourceName = normalize("original/source.html");
List<SourceFile> originalSources = ImmutableList.of(SourceFile.fromCode(origSourceName, "<div ng-show='foo()'>"));
CompilerOptions options = new CompilerOptions();
options.inputSourceMaps = inputSourceMaps;
Compiler compiler = new Compiler();
compiler.init(new ArrayList<SourceFile>(), originalSources, options);
assertEquals(OriginalMapping.newBuilder().setOriginalFile(origSourceName).setLineNumber(18).setColumnPosition(25).setIdentifier("testSymbolName").build(), compiler.getSourceMapping(normalize("generated_js/example.js"), 3, 3));
assertEquals("<div ng-show='foo()'>", compiler.getSourceLine(origSourceName, 1));
}
use of com.google.debugging.sourcemap.FilePosition in project closure-compiler by google.
the class CompilerTest method sourcemap.
private SourceMapInput sourcemap(String sourceMapPath, String originalSource, FilePosition originalSourcePosition) throws Exception {
SourceMapGeneratorV3 sourceMap = new SourceMapGeneratorV3();
sourceMap.addMapping(originalSource, "testSymbolName", originalSourcePosition, new FilePosition(1, 1), new FilePosition(100, 1));
StringBuilder output = new StringBuilder();
sourceMap.appendTo(output, "unused.js");
return new SourceMapInput(SourceFile.fromCode(sourceMapPath, output.toString()));
}
use of com.google.debugging.sourcemap.FilePosition in project st-js by st-js.
the class RhinoJavaScriptWriter method startPosition.
/**
* <p>startPosition.</p>
*
* @param node a {@link org.mozilla.javascript.ast.AstNode} object.
*/
protected void startPosition(AstNode node) {
if (generateSourceMap) {
javaPosition = new FilePosition(RhinoJavaScriptBuilder.getLineNumber(node) - 1, RhinoJavaScriptBuilder.getColumnNumber(node) - 1);
javaScriptPosition = new FilePosition(currentLine, currentColumn);
}
}
Aggregations