Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findTokensForRangeIgnoringInvalidTrailingCharacters(source, start, end) {
var candidateEnd = end;
var error;
while (start <= candidateEnd) {
var slice = source.slice(start, candidateEnd);
try {
return {
tokens: tokens(slice, { rewrite: false }),
start: start,
end: candidateEnd
};
} catch (ex) {
if (!error) {
error = ex;
}
candidateEnd--;
}
}
throw error;
}