Exemple #1
0
        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);
        }
        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;
        }
 internal static FunctionInformation MaybeMap(FunctionInformation funcInfo) {
     return MaybeMap(funcInfo, null);
 }
Exemple #4
0
 internal static FunctionInformation MaybeMap(FunctionInformation funcInfo)
 {
     return(MaybeMap(funcInfo, null));
 }