decaffeinate-parser
Version:
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
21 lines (20 loc) • 924 B
JavaScript
import { SourceType } from 'coffee-lex';
import { inspect } from 'util';
export default function rangeOfBracketTokensForIndexNode(context, indexNode) {
var start = context.linesAndColumns.indexForLocation({
line: indexNode.locationData.first_line,
column: indexNode.locationData.first_column
});
if (start !== null) {
var startTokenIndex = context.sourceTokens.indexOfTokenStartingAtSourceIndex(start);
if (startTokenIndex !== null) {
var range = context.sourceTokens.rangeOfMatchingTokensContainingTokenIndex(SourceType.LBRACKET, SourceType.RBRACKET, startTokenIndex);
if (range !== null) {
return range;
}
}
}
throw new Error("cannot find braces surrounding index at " +
(indexNode.locationData.first_line + 1 + ":" + indexNode.locationData.first_column + ": ") +
("" + inspect(indexNode)));
}