Skip to content

fix: do not crash on yield static imports #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ function defineRules($, t) {
$.OR({
DEF: [
{ ALT: () => $.SUBRULE($.block) },
{ ALT: () => $.SUBRULE($.yieldStatement) },
{
GATE: () => this.BACKTRACK_LOOKAHEAD($.yieldStatement),
ALT: () => $.SUBRULE($.yieldStatement)
},
{ ALT: () => $.SUBRULE($.emptyStatement) },
{
GATE: () => !tokenMatcher(this.LA(1).tokenType, t.Switch),
Expand Down
7 changes: 7 additions & 0 deletions packages/java-parser/test/bugs-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ describe("The Java Parser fixed bugs", () => {
const input = "double[][]";
expect(() => javaParser.parse(input, "primaryPrefix")).to.not.throw();
});

it("issue #498 - should not throw on yield static imports", () => {
const inputs = ["Thread.yield();", "yield();", "yield(a);"];
inputs.forEach(input => {
expect(() => javaParser.parse(input, "statement")).to.not.throw();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ public int calculate(Day d) {
}
};
}

void should_not_throw_on_yield_static_imports() {
Thread.yield ();
yield();
yield(a);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public int calculate(Day d) {
}
};
}

void should_not_throw_on_yield_static_imports() {
Thread.yield();
yield();
yield (a);
}
}