{ isCommentToken } = require("eslint-utils"),
TokenStore = require("./token-store"),
astUtils = require("../shared/ast-utils"),
- Traverser = require("../shared/traverser"),
- lodash = require("lodash");
+ Traverser = require("../shared/traverser");
//------------------------------------------------------------------------------
// Private
let currentToken = this.getTokenBefore(node, { includeComments: true });
while (currentToken && isCommentToken(currentToken)) {
- if (node.parent && (currentToken.start < node.parent.start)) {
+ if (node.parent && node.parent.type !== "Program" && (currentToken.start < node.parent.start)) {
break;
}
comments.leading.push(currentToken);
currentToken = this.getTokenAfter(node, { includeComments: true });
while (currentToken && isCommentToken(currentToken)) {
- if (node.parent && (currentToken.end > node.parent.end)) {
+ if (node.parent && node.parent.type !== "Program" && (currentToken.end > node.parent.end)) {
break;
}
comments.trailing.push(currentToken);
}
/*
- * To figure out which line rangeIndex is on, determine the last index at which rangeIndex could
- * be inserted into lineIndices to keep the list sorted.
+ * To figure out which line index is on, determine the last place at which index could
+ * be inserted into lineStartIndices to keep the list sorted.
*/
- const lineNumber = lodash.sortedLastIndex(this.lineStartIndices, index);
+ const lineNumber = index >= this.lineStartIndices[this.lineStartIndices.length - 1]
+ ? this.lineStartIndices.length
+ : this.lineStartIndices.findIndex(el => index < el);
return { line: lineNumber, column: index - this.lineStartIndices[lineNumber - 1] };
}