MCPcopy Create free account
hub / github.com/nodejs/node / prepareRangeContainsErrorFunction

Function prepareRangeContainsErrorFunction

test/fixtures/snapshot/typescript.js:147123–147158  ·  view source on GitHub ↗

formatting is not applied to ranges that contain parse errors. * This function will return a predicate that for a given text range will tell * if there are any parse errors that overlap with the range.

(errors, originalRange)

Source from the content-addressed store, hash-verified

147121 * if there are any parse errors that overlap with the range.
147122 */
147123 function prepareRangeContainsErrorFunction(errors, originalRange) {
147124 if (!errors.length) {
147125 return rangeHasNoErrors;
147126 }
147127 // pick only errors that fall in range
147128 var sorted = errors
147129 .filter(function (d) { return ts.rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length); }) // TODO: GH#18217
147130 .sort(function (e1, e2) { return e1.start - e2.start; });
147131 if (!sorted.length) {
147132 return rangeHasNoErrors;
147133 }
147134 var index = 0;
147135 return function (r) {
147136 // in current implementation sequence of arguments [r1, r2...] is monotonically increasing.
147137 // 'index' tracks the index of the most recent error that was checked.
147138 while (true) {
147139 if (index >= sorted.length) {
147140 // all errors in the range were already checked -> no error in specified range
147141 return false;
147142 }
147143 var error = sorted[index];
147144 if (r.end <= error.start) {
147145 // specified range ends before the error referred by 'index' - no error in range
147146 return false;
147147 }
147148 if (ts.startEndOverlapsWithStartEnd(r.pos, r.end, error.start, error.start + error.length)) {
147149 // specified range overlaps with error range
147150 return true;
147151 }
147152 index++;
147153 }
147154 };
147155 function rangeHasNoErrors() {
147156 return false;
147157 }
147158 }
147159 /**
147160 * Start of the original range might fall inside the comment - scanner will not yield appropriate results
147161 * This function will look for token that is located before the start of target range

Callers 1

formatSpanFunction · 0.85

Calls 2

sortMethod · 0.80
filterMethod · 0.65

Tested by

no test coverage detected