public SourceMap ParseSourceMap()

in src/SourcemapToolkit.SourcemapParser/SourceMapParser.cs [20:53]


		public SourceMap ParseSourceMap(StreamReader sourceMapStream)
		{
			if (sourceMapStream == null)
			{
				return null;
			}
			using (JsonTextReader jsonTextReader = new JsonTextReader(sourceMapStream))
			{
				JsonSerializer serializer = new JsonSerializer();

				SourceMapDeserializable deserializedSourceMap = serializer.Deserialize<SourceMapDeserializable>(jsonTextReader);

				// Since SourceMap is immutable we need to allocate a new one and copy over all the information
				List<MappingEntry> parsedMappings = _mappingsListParser.ParseMappings(deserializedSourceMap.Mappings, deserializedSourceMap.Names, deserializedSourceMap.Sources);

				// Resize to free unused memory
				RemoveExtraSpaceFromList(parsedMappings);
				RemoveExtraSpaceFromList(deserializedSourceMap.Sources);
				RemoveExtraSpaceFromList(deserializedSourceMap.Names);
				RemoveExtraSpaceFromList(deserializedSourceMap.SourcesContent);

				SourceMap result = new SourceMap(
					version: deserializedSourceMap.Version,
					file: deserializedSourceMap.File,
					mappings: deserializedSourceMap.Mappings,
					sources: deserializedSourceMap.Sources,
					names: deserializedSourceMap.Names,
					parsedMappings: parsedMappings,
					sourcesContent: deserializedSourceMap.SourcesContent);

				sourceMapStream.Close();
				return result;
			}
		}