public virtual MappingEntry? GetMappingEntryForGeneratedSourcePosition()

in src/SourcemapToolkit.SourcemapParser/SourceMap.cs [199:224]


		public virtual MappingEntry? GetMappingEntryForGeneratedSourcePosition(SourcePosition generatedSourcePosition)
		{
			if (ParsedMappings == null)
			{
				return null;
			}

			MappingEntry mappingEntryToFind = new MappingEntry(generatedSourcePosition: generatedSourcePosition);

			int index = ParsedMappings.BinarySearch(mappingEntryToFind, _comparer);

			// If we didn't get an exact match, let's try to return the closest piece of code to the given line
			if (index < 0)
			{
				// The BinarySearch method returns the bitwise complement of the nearest element that is larger than the desired element when there isn't a match.
				// Based on tests with source maps generated with the Closure Compiler, we should consider the closest source position that is smaller than the target value when we don't have a match.
				int correctIndex = ~index - 1;

				if (correctIndex >= 0 && ParsedMappings[correctIndex].GeneratedSourcePosition.IsEqualish(generatedSourcePosition))
				{
					index = correctIndex;
				}
			}

			return index >= 0 ? (MappingEntry?)ParsedMappings[index] : null;
		}