public void AddMappingDirective(string generatedFilename, string mappingFilename)
        {
            var mapCode = SourceMappingHelper.GetJsMappingCode(Path.GetFileName(mappingFilename));

            File.AppendAllText(generatedFilename, mapCode);
            //file.JsFile.Units.Add(new JsUnit { Statements = new List<JsStatement> { Js.Code(mapCode).Statement() } });
        }
Exemplo n.º 2
0
 public void ParseMappings()
 {
     ParsedMappings = new List <List <SourceMappingV3Item> >();
     foreach (var line in mappings.Split(';'))
     {
         var line2 = new List <SourceMappingV3Item>();
         foreach (var token in line.Split(','))
         {
             //Console.WriteLine(token);
             var data    = SourceMappingHelper.DecodeAll(token);
             var numbers = data.Cast <int?>().ToList();
             while (numbers.Count < 5)
             {
                 numbers.Add(null);
             }
             var map = new SourceMappingV3Item
             {
                 GeneratedColumn     = numbers[0],
                 SourceFilenameIndex = numbers[1],
                 SourceLine          = numbers[2],
                 SourceColumn        = numbers[3],
                 SourceNameIndex     = numbers[4],
                 OriginalData        = data,
             };
             line2.Add(map);
         }
         ParsedMappings.Add(line2);
     }
 }
Exemplo n.º 3
0
        public void GenerateMappings()
        {
            var sb = new StringBuilder();

            foreach (var line in ParsedMappings)
            {
                var firstMap = true;
                foreach (var map in line)
                {
                    if (firstMap)
                    {
                        firstMap = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }

                    var numbers = new List <int?> {
                        map.GeneratedColumn, map.SourceFilenameIndex, map.SourceLine, map.SourceColumn, map.SourceNameIndex
                    };
                    while (numbers.Count > 0 && numbers.Last() == null)
                    {
                        numbers.RemoveAt(numbers.Count - 1);
                    }
                    var nums = numbers.Select(t => t.GetValueOrDefault()).ToList();
                    var x    = SourceMappingHelper.EncodeAll(nums);
                    sb.Append(x);
                }
                sb.Append(";");
            }
            mappings  = sb.ToString();
            lineCount = ParsedMappings.Count;
            if (sourceRoot == null)
            {
                sourceRoot = "";
            }
            if (names == null)
            {
                names = new List <string>();
            }
        }