[parser] Don't crash on comment after trailing comma after eli… (#10490)
This commit is contained in:
@@ -40,7 +40,7 @@ export default class CommentsParser extends BaseParser {
|
||||
|
||||
adjustCommentsAfterTrailingComma(
|
||||
node: Node,
|
||||
elements: Node[],
|
||||
elements: (Node | null)[],
|
||||
// When the current node is followed by a token which hasn't a respective AST node, we
|
||||
// need to take all the trailing comments to prevent them from being attached to an
|
||||
// unrelated node. e.g. in
|
||||
@@ -55,12 +55,15 @@ export default class CommentsParser extends BaseParser {
|
||||
return;
|
||||
}
|
||||
|
||||
if (elements.length === 0) {
|
||||
let lastElement = null;
|
||||
let i = elements.length;
|
||||
while (lastElement === null && i > 0) {
|
||||
lastElement = elements[--i];
|
||||
}
|
||||
if (lastElement === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const lastElement = last(elements);
|
||||
|
||||
for (let j = 0; j < this.state.leadingComments.length; j++) {
|
||||
if (
|
||||
this.state.leadingComments[j].end < this.state.commentPreviousNode.end
|
||||
|
||||
Reference in New Issue
Block a user