static void Test2() { SourceMaps.List<SourceFile> sources = new SourceMaps.List<SourceFile>(); sources.Add( new SourceFile("http://www.mysite.com/source1.txt", LoadFromFile(@"..\..\..\Website\source1.txt")) ); sources.Add( new SourceFile("http://www.mysite.com/source2.txt", LoadFromFile(@"..\..\..\Website\source2.txt")) ); string destfile = ""; foreach(var sf in sources) destfile+=sf.content.ToLower(); destfile +="\r\n//# sourceMappingURL=myapp.js.map"; SaveToFile(@"..\..\..\Website\myapp.js",destfile); SourceFile target = new SourceFile("http://www.mysite.com/myapp.js",destfile); // build tokens/source map entries SourceMaps.List<SourceMapEntry> sme = new SourceMaps.List<SourceMapEntry>(); // this will map every single character, no name specified int cumulative_l = 0; foreach(var sf in sources) { for(int cx=0;cx<sf.content.Length;cx++) { string c = ""; //sf.content[cx].ToString(); var tok = new TokenSourceFileLocation(sf, c, cx); sme.add( new SourceMapEntry(tok,cx+cumulative_l)); } cumulative_l += sf.length; } // this maps only identifiers /* Regex R = new Regex(@"[_a-zA-Z][_a-zA-Z0-9]*"); int cumulative_l = 0; foreach(var sf in sources) { MatchCollection mc = R.Matches(sf.content); foreach(Match match in mc) { var keyword = match.Value.ToLower(); var tok = new TokenSourceFileLocation(sf, match.Value.ToLower(), match.Index); sme.add( new SourceMapEntry(tok,match.Index+cumulative_l)); } cumulative_l += sf.length; } */ Uri sourceMapUri = Uri.parse("http://www.mysite.com/myapp.map"); Uri fileUri = Uri.parse("http://www.mysite.com/myapp.js"); SourceMapBuilder sourceMapBuilder = new SourceMapBuilder(sourceMapUri, fileUri, target); foreach(var e in sme) sourceMapBuilder.addMapping(e.targetOffset,e.sourceLocation); String sourceMap = sourceMapBuilder.build(); SaveToFile(@"..\..\..\Website\myapp.js.map",sourceMap); }
public SourceMapBuilder(Uri sourceMapUri, Uri p_fileUri, SourceFile compiledFile) { this.uri = sourceMapUri; this.fileUri = p_fileUri; this.targetFile = compiledFile; entries = new List<SourceMapEntry>(); sourceUrlMap = new Map<String, int>(); sourceUrlList = new List<String>(); sourceNameMap = new Map<String, int>(); sourceNameList = new List<String>(); previousTargetLine = 0; previousTargetColumn = 0; previousSourceUrlIndex = 0; previousSourceLine = 0; previousSourceColumn = 0; previousSourceNameIndex = 0; firstEntryInLine = true; }
public void writeEntry(SourceMapEntry entry, SourceFile targetFile, StringBuffer output) { int targetLine = targetFile.getLine(entry.targetOffset); int targetColumn = targetFile.getColumn(targetLine, entry.targetOffset); if (targetLine > previousTargetLine) { for (int i = previousTargetLine; i < targetLine; ++i) { output.write(";"); } previousTargetLine = targetLine; previousTargetColumn = 0; firstEntryInLine = true; } if (!firstEntryInLine) { output.write(","); } firstEntryInLine = false; encodeVLQ(output, targetColumn - previousTargetColumn); previousTargetColumn = targetColumn; if (entry.sourceLocation == null) return; String sourceUrl = entry.sourceLocation.getSourceUrl(); int sourceLine = entry.sourceLocation.getLine(); int sourceColumn = entry.sourceLocation.getColumn(); String sourceName = entry.sourceLocation.getSourceName(); int sourceUrlIndex = indexOf(sourceUrlList, sourceUrl, sourceUrlMap); encodeVLQ(output, sourceUrlIndex - previousSourceUrlIndex); encodeVLQ(output, sourceLine - previousSourceLine); encodeVLQ(output, sourceColumn - previousSourceColumn); if (sourceName != null) { int sourceNameIndex = indexOf(sourceNameList, sourceName, sourceNameMap); encodeVLQ(output, sourceNameIndex - previousSourceNameIndex); } // Update previous source location to ensure the next indices are relative // to those if [entry.sourceLocation]. updatePreviousSourceLocation(entry.sourceLocation); }
public SourceFileLocation(SourceFile sourceFile) { this.sourceFile = sourceFile; //if(!isValid()) throw new Exception("SourceFileLocation is not valid"); }
public TokenSourceFileLocation(SourceFile sourceFile, Token token, String name) : base(sourceFile) { this.token = token; this.name = name; }
public String name; // final public TokenSourceFileLocation(SourceFile sourceFile, String name, int offs) : base(sourceFile) { this.token = new Token(); this.token.charOffset = offs; this.name = name; }