com.google.javascript.jscomp
Class SourceMap2

java.lang.Object
  extended by com.google.javascript.jscomp.SourceMap2
All Implemented Interfaces:
SourceMap

public class SourceMap2
extends Object
implements SourceMap

Collects information mapping the generated (compiled) source back to its original source for debugging purposes.

See Also:
CodeConsumer, CodeGenerator, CodePrinter

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.SourceMap
SourceMap.DetailLevel, SourceMap.Format
 
Constructor Summary
SourceMap2()
           
 
Method Summary
 void addMapping(Node node, com.google.javascript.jscomp.Position startPosition, com.google.javascript.jscomp.Position endPosition)
          Adds a mapping for the given node.
 void appendTo(Appendable out, String name)
          Writes out the source map in the following format (line numbers are for reference only and are not part of the format): 1.
 void reset()
          Resets the source map for reuse.
 void setStartingPosition(int offsetLine, int offsetIndex)
          Sets the source code that exists in the buffer for which the generated code is being generated.
 void setWrapperPrefix(String prefix)
          Sets the prefix used for wrapping the generated source file before it is written.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceMap2

public SourceMap2()
Method Detail

reset

public void reset()
Resets the source map for reuse. A reset needs to be called between each generated output file.

Specified by:
reset in interface SourceMap

setWrapperPrefix

public void setWrapperPrefix(String prefix)
Sets the prefix used for wrapping the generated source file before it is written. This ensures that the source map is adjusted for the change in character offsets.

Specified by:
setWrapperPrefix in interface SourceMap
Parameters:
prefix - The prefix that is added before the generated source code.

setStartingPosition

public void setStartingPosition(int offsetLine,
                                int offsetIndex)
Sets the source code that exists in the buffer for which the generated code is being generated. This ensures that the source map accurately reflects the fact that the source is being appended to an existing buffer and as such, does not start at line 0, position 0 but rather some other line and position.

Specified by:
setStartingPosition in interface SourceMap
Parameters:
offsetLine - The index of the current line being printed.
offsetIndex - The column index of the current character being printed.

addMapping

public void addMapping(Node node,
                       com.google.javascript.jscomp.Position startPosition,
                       com.google.javascript.jscomp.Position endPosition)
Adds a mapping for the given node. Mappings must be added in order.

Specified by:
addMapping in interface SourceMap
Parameters:
node - The node that the new mapping represents.
startPosition - The position on the starting line
endPosition - The position on the ending line.

appendTo

public void appendTo(Appendable out,
                     String name)
              throws IOException
Writes out the source map in the following format (line numbers are for reference only and are not part of the format): 1. { 2. version: 2, 3. file: “out.js” 4. lineCount: 2 5. lineMaps: [ 6. "ABAAA", 7. "ABAA" 8. ], 9. sourceRoot: "", 10. sources: ["foo.js", "bar.js"], 11. names: ["src", "maps", "are", "fun"], 12. mappings: [ 13. [1, 1, 2, 4], 14. [2, 1, 2, "yack"], 15. ], 16. } Line 1: The entire file is a single JSON object Line 2: File revision (always the first entry in the object) Line 3: The name of the file that this source map is associated with. Line 4: The number of lines represented in the sourcemap. Line 5: “lineMaps” field is a JSON array, where each entry represents a line in the generated text. Line 6: A line entry, representing a series of line segments, where each segment encodes an mappings-id and repetition count. Line 9: An optional source root, useful for relocating source files on a server or removing repeated prefix values in the “sources” entry. Line 10: A list of sources used by the “mappings” entry relative to the sourceRoot. Line 11: A list of symbol names used by the “mapping” entry. This list may be incomplete. Line 12: The mappings field. Line 13: Each entry represent a block of text in the original source, and consists four fields: The source file name The line in the source file the text begins The column in the line that the text begins An optional name (from the original source) that this entry represents. This can either be an string or index into the “names” field.

Specified by:
appendTo in interface SourceMap
Parameters:
out - The stream to which the map will be appended.
name - The name of the generated source file that this source map represents.
Throws:
IOException