@jridgewell/trace-mapping
Advanced tools
Comparing version 0.2.6 to 0.2.7
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('sourcemap-codec'), require('@jridgewell/resolve-uri')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'sourcemap-codec', '@jridgewell/resolve-uri'], factory) : | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@jridgewell/sourcemap-codec'), require('@jridgewell/resolve-uri')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@jridgewell/sourcemap-codec', '@jridgewell/resolve-uri'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.traceMapping = {}, global.sourcemapCodec, global.resolveURI)); | ||
@@ -73,9 +73,2 @@ })(this, (function (exports, sourcemapCodec, resolveUri) { 'use strict'; | ||
* | ||
* The `comparator` callback receives both the `item` under comparison and the | ||
* needle we are searching for. It must return `0` if the `item` is a match, | ||
* any negative number if `item` is too small (and we must search after it), or | ||
* any positive number if the `item` is too large (and we must search before | ||
* it). | ||
* | ||
* | ||
* ```js | ||
@@ -109,5 +102,5 @@ * const array = [1, 3]; | ||
return { | ||
_lastLine: -1, | ||
_lastColumn: -1, | ||
_lastIndex: -1, | ||
lastKey: -1, | ||
lastNeedle: -1, | ||
lastIndex: -1, | ||
}; | ||
@@ -119,11 +112,12 @@ } | ||
*/ | ||
function memoizedBinarySearch(haystack, needle, state, line, column) { | ||
const { _lastLine: lastLine, _lastColumn: lastColumn, _lastIndex: lastIndex } = state; | ||
function memoizedBinarySearch(haystack, needle, state, key) { | ||
const { lastKey, lastNeedle, lastIndex } = state; | ||
let low = 0; | ||
let high = haystack.length - 1; | ||
if (line === lastLine) { | ||
if (column === lastColumn) { | ||
if (key === lastKey) { | ||
if (needle === lastNeedle) { | ||
return lastIndex; | ||
} | ||
if (column >= lastColumn) { | ||
if (needle >= lastNeedle) { | ||
// lastIndex may be -1 if the previous needle was not found. | ||
low = Math.max(lastIndex, 0); | ||
@@ -135,5 +129,5 @@ } | ||
} | ||
state._lastLine = line; | ||
state._lastColumn = column; | ||
return (state._lastIndex = binarySearch(haystack, needle, low, high)); | ||
state.lastKey = key; | ||
state.lastNeedle = needle; | ||
return (state.lastIndex = binarySearch(haystack, needle, low, high)); | ||
} | ||
@@ -222,3 +216,3 @@ | ||
const segments = decoded[line]; | ||
const index = memoizedBinarySearch(segments, column, this._binarySearchMemo, line, column); | ||
const index = memoizedBinarySearch(segments, column, this._binarySearchMemo, line); | ||
// we come before any mapped segment | ||
@@ -225,0 +219,0 @@ if (index < 0) |
import type { SourceMapSegment } from './types'; | ||
declare type MemoState = { | ||
_lastLine: number; | ||
_lastColumn: number; | ||
_lastIndex: number; | ||
lastKey: number; | ||
lastNeedle: number; | ||
lastIndex: number; | ||
}; | ||
@@ -13,9 +13,2 @@ /** | ||
* | ||
* The `comparator` callback receives both the `item` under comparison and the | ||
* needle we are searching for. It must return `0` if the `item` is a match, | ||
* any negative number if `item` is too small (and we must search after it), or | ||
* any positive number if the `item` is too large (and we must search before | ||
* it). | ||
* | ||
* | ||
* ```js | ||
@@ -37,3 +30,3 @@ * const array = [1, 3]; | ||
*/ | ||
export declare function memoizedBinarySearch(haystack: SourceMapSegment[], needle: number, state: MemoState, line: number, column: number): number; | ||
export declare function memoizedBinarySearch(haystack: SourceMapSegment[], needle: number, state: MemoState, key: number): number; | ||
export {}; |
{ | ||
"name": "@jridgewell/trace-mapping", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Trace the original position through a source map", | ||
@@ -65,3 +65,2 @@ "keywords": [ | ||
"source-map-js": "1.0.2", | ||
"tslib": "2.3.1", | ||
"typescript": "4.5.4" | ||
@@ -71,4 +70,4 @@ }, | ||
"@jridgewell/resolve-uri": "^3.0.3", | ||
"sourcemap-codec": "1.4.8" | ||
"@jridgewell/sourcemap-codec": "^1.4.9" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
16
41881
594
+ Added@jridgewell/sourcemap-codec@1.4.15(transitive)
- Removedsourcemap-codec@1.4.8
- Removedsourcemap-codec@1.4.8(transitive)