Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Fix "-1" array accesses in CommentsParser. #777

Merged
merged 1 commit into from
Oct 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/parser/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ export default class CommentsParser extends BaseParser {
this.state.trailingComments.length = 0;
}
} else {
const lastInStack = last(stack);
if (
stack.length > 0 &&
lastInStack.trailingComments &&
lastInStack.trailingComments[0].start >= node.end
) {
trailingComments = lastInStack.trailingComments;
lastInStack.trailingComments = null;
if (stack.length > 0) {
const lastInStack = last(stack);
if (
lastInStack.trailingComments &&
lastInStack.trailingComments[0].start >= node.end
) {
trailingComments = lastInStack.trailingComments;
lastInStack.trailingComments = null;
}
}
}

Expand Down Expand Up @@ -138,6 +139,7 @@ export default class CommentsParser extends BaseParser {
if (lastChild.leadingComments) {
if (
lastChild !== node &&
lastChild.leadingComments.length > 0 &&
last(lastChild.leadingComments).end <= node.start
) {
node.leadingComments = lastChild.leadingComments;
Expand Down