Ejemplo n.º 1
0
            public void Build()
            {
                var entries = new List <Entry>();
                var temp    = new List <int>(MAX_ENTRY_VALUES);

                for (var i = 0; i < _lineMap.Length;)
                {
                    switch (_lineMap[i])
                    {
                    case ',':
                        // ',' denotes a new entry on the same _line, just consume it
                        i++;
                        break;

                    case ';':
                        // ';' denotes a new _line.
                        // The _line is complete, store the result
                        CompleteLine(entries);

                        i++;     // consume token
                        break;

                    default:
                        // grab the next entry for the current _line.
                        for (; i < _lineMap.Length && _lineMap[i] != ';' && _lineMap[i] != ','; i++)
                        {
                            i = Base64VLQ.VLQDecode(_lineMap, i, temp);
                        }
                        var entry = DecodeEntry(temp);
                        ValidateEntry(entry);
                        entries.Add(entry);
                        break;
                    }
                }

                // Some source map generator (e.g.UglifyJS) generates _lines without
                // a trailing _line separator. So add the rest of the content.
                if (entries.Any())
                {
                    CompleteLine(entries);
                }
            }
Ejemplo n.º 2
0
        private string SerializeMappings(out int lineCount)
        {
            var mappingsBuilder = new StringBuilder();

            // The destination.
            var previousLine   = UNMAPPED;
            var previousColumn = UNMAPPED;

            // Previous values used for storing relative ids.
            var previousSourceFileId = 0;
            var previousSourceLine   = 0;
            var previousSourceColumn = 0;
            var previousNameId       = 0;

            lineCount = LineCount ?? (Mappings(sort: false).Max(x => x.Generated?.Line ?? 0) + 1);

            foreach (var m in Mappings(sort: true))
            {
                var current = m.Generated;
                if (previousLine != current.Line)
                {
                    previousColumn = 0;
                }

                if (current.Line != previousLine || current.Column != previousColumn)
                {
                    for (var i = Math.Max(0, previousLine); i < current.Line && i < lineCount; i++)
                    {
                        mappingsBuilder.Append(";"); // close line
                    }

                    if (current.Line < lineCount)
                    {
                        if (previousLine == current.Line)
                        {
                            // not the first entry for the line
                            mappingsBuilder.Append(',');
                        }
                        var column = current.Column;
                        // The relative generated column number
                        Base64VLQ.VLQEncode(column - previousColumn, mappingsBuilder);
                        previousColumn = column;
                        if (m != null)
                        {
                            // The relative source file id
                            var sourceId = _sourceFileMap.IndexFor(m.Source);
                            Base64VLQ.VLQEncode(sourceId - previousSourceFileId, mappingsBuilder);
                            previousSourceFileId = sourceId;

                            // The relative source file line and column
                            var srcline   = m.Original.Line;
                            var srcColumn = m.Original.Column;
                            Base64VLQ.VLQEncode(srcline - previousSourceLine, mappingsBuilder);
                            previousSourceLine = srcline;

                            Base64VLQ.VLQEncode(srcColumn - previousSourceColumn, mappingsBuilder);
                            previousSourceColumn = srcColumn;

                            if (m.Name != null)
                            {
                                // The relative id for the associated symbol name
                                var nameId = _nameMap.IndexFor(m.Name);
                                Base64VLQ.VLQEncode(nameId - previousNameId, mappingsBuilder);
                                previousNameId = nameId;
                            }
                        }
                        else
                        {
                        }

                        previousLine   = current.Line;
                        previousColumn = current.Column;
                    }
                    else
                    {
                        Preconditions.checkState(m == null);
                    }
                }
                else
                {
                }
            }

            mappingsBuilder.Append(";");
            var mappings = mappingsBuilder.ToString();

            return(mappings);
        }