Beispiel #1
0
        internal static List <SourceMapMappingEntry> ParseMappings(string mappings, List <string> names, List <string> sources)
        {
            var result = new List <SourceMapMappingEntry>();
            var state  = new MappingParserState();

            var lines = mappings.Split(';');

            for (var lineNumber = 0; lineNumber < lines.Length; lineNumber++)
            {
                state.GeneratedLineNumber   = lineNumber;
                state.GeneratedColumnNumber = 0;

                var segments = lines[lineNumber].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var segment in segments)
                {
                    ApplyMappingSegment(Base64Vlq.Decode(segment), ref state);
                    result.Add(state.GetCurrentSourceMapMappingEntry(names, sources));
                }
            }

            return(result);
        }
Beispiel #2
0
        internal static void ApplyMappingSegment(List <int> segmentFields, ref MappingParserState state)
        {
            _ = segmentFields ?? throw new ArgumentNullException(nameof(segmentFields));

            if (segmentFields.Count != 1 && segmentFields.Count != 4 && segmentFields.Count != 5)
            {
                throw new ArgumentOutOfRangeException(nameof(segmentFields), $"Expected 1, 4 or 5 decoded segments, got {segmentFields.Count}");
            }

            state.SegmentCount           = segmentFields.Count;
            state.GeneratedColumnNumber += segmentFields[0];

            if (state.ContainsSourceLocation)
            {
                state.SourcesListIndex     += segmentFields[1];
                state.OriginalLineNumber   += segmentFields[2];
                state.OriginalColumnNumber += segmentFields[3];
            }

            if (state.ContainsOriginalName)
            {
                state.NamesListIndex += segmentFields[4];
            }
        }