コード例 #1
0
ファイル: SourceMapper.cs プロジェクト: zhoffice/nodejstools
        internal static FunctionInformation MaybeMap(FunctionInformation funcInfo, Dictionary <string, SourceMap> sourceMaps)
        {
            if (funcInfo.Filename != null &&
                funcInfo.Filename.IndexOfAny(InvalidPathChars) == -1 &&
                File.Exists(funcInfo.Filename) &&
                File.Exists(funcInfo.Filename + ".map") &&
                funcInfo.LineNumber != null)
            {
                SourceMap map = null;
                if (sourceMaps == null || !sourceMaps.TryGetValue(funcInfo.Filename, out map))
                {
                    try {
                        using (StreamReader reader = new StreamReader(funcInfo.Filename + ".map")) {
                            map = new SourceMap(reader);
                        }
                    } catch (InvalidOperationException) {
                    } catch (FileNotFoundException) {
                    } catch (DirectoryNotFoundException) {
                    } catch (IOException) {
                    }

                    if (sourceMaps != null && map != null)
                    {
                        sourceMaps[funcInfo.Filename] = map;
                    }
                }

                SourceMapInfo mapping;
                // We explicitly don't convert our 1 based line numbers into 0 based
                // line numbers here.  V8 is giving us the starting line of the function,
                // and TypeScript doesn't give the right name for the declaring name.
                // But TypeScript also happens to always emit a newline after the {
                // for a function definition, and we're always mapping line numbers from
                // function definitions, so mapping line + 1 happens to work out for
                // the time being.
                if (map != null && map.TryMapLine(funcInfo.LineNumber.Value, out mapping))
                {
                    string filename = mapping.FileName;
                    if (filename != null && !Path.IsPathRooted(filename))
                    {
                        filename = Path.Combine(Path.GetDirectoryName(funcInfo.Filename), filename);
                    }

                    return(new FunctionInformation(
                               funcInfo.Namespace,
                               mapping.Name ?? funcInfo.Function,
                               mapping.Line + 1,
                               filename ?? funcInfo.Filename,
                               funcInfo.IsRecompilation
                               ));
                }
            }
            return(funcInfo);
        }
コード例 #2
0
ファイル: SourceMapper.cs プロジェクト: zjherp/nodejstools
        private JavaScriptSourceMapInfo TryGetMapInfo(string filename)
        {
            if (!this._originalFileToSourceMap.TryGetValue(filename, out var mapInfo))
            {
                if (File.Exists(filename))
                {
                    var          contents = File.ReadAllLines(filename);
                    const string marker   = "# sourceMappingURL=";
                    int          markerStart;
                    var          markerLine = contents.Reverse().FirstOrDefault(x => x.IndexOf(marker, StringComparison.Ordinal) != -1);
                    if (markerLine != null && (markerStart = markerLine.IndexOf(marker, StringComparison.Ordinal)) != -1)
                    {
                        var sourceMapFilename = markerLine.Substring(markerStart + marker.Length).Trim();

                        try
                        {
                            if (!File.Exists(sourceMapFilename))
                            {
                                sourceMapFilename = Path.Combine(Path.GetDirectoryName(filename) ?? string.Empty, Path.GetFileName(sourceMapFilename));
                            }

                            if (File.Exists(sourceMapFilename))
                            {
                                using (var reader = new StreamReader(sourceMapFilename))
                                {
                                    var sourceMap = new SourceMap(reader);
                                    this._originalFileToSourceMap[filename] = mapInfo = new JavaScriptSourceMapInfo(sourceMap, contents);
                                    // clear all of our cached _generatedFileToSourceMap files...
                                    foreach (var cachedInvalid in this._generatedFileToSourceMap.Where(x => x.Value == null).Select(x => x.Key).ToArray())
                                    {
                                        this._generatedFileToSourceMap.Remove(cachedInvalid);
                                    }
                                }
                            }
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (PathTooLongException)
                        {
                        }
                        catch (NotSupportedException)
                        {
                        }
                        catch (InvalidOperationException)
                        {
                        }
                    }
                }
            }
            return(mapInfo);
        }
コード例 #3
0
ファイル: SourceMapper.cs プロジェクト: zjherp/nodejstools
 public ReverseSourceMap(SourceMap mapping, string javaScriptFile)
 {
     this.Mapping        = mapping;
     this.JavaScriptFile = javaScriptFile;
 }