Skip to content

Commit

Permalink
fix(707): do not throw if the record-pattern contains dims
Browse files Browse the repository at this point in the history
  • Loading branch information
clementdessoude committed Dec 21, 2024
1 parent d5fd515 commit b5d7f91
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
strategy:
matrix:
node_version:
- 18.x
- 20.x
- 22.x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
Expand All @@ -33,15 +33,15 @@ jobs:
test_repository:
- e2e-jhipster1
- e2e-jhipster2
node_version: [18.x]
node_version: [22.x]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
- uses: actions/setup-java@v3
with:
java-version: 17.x
java-version: 21.x
distribution: zulu
- name: Install dependencies
run: yarn
Expand Down
10 changes: 7 additions & 3 deletions packages/java-parser/src/productions/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ export function defineRules($, t) {
$.SUBRULE($.variableDeclarator);
$.MANY({
// required to distinguish from patternList
GATE: () =>
!tokenMatcher(this.LA(3), t.Identifier) &&
!tokenMatcher(this.LA(3), t.Underscore),
// TODO: complexify lookahed logic to see if we can avoid backtracking
GATE: () => this.BACKTRACK_LOOKAHEAD($.isFollowingVariableDeclarator),
DEF: () => {
$.CONSUME(t.Comma);
$.SUBRULE2($.variableDeclarator);
Expand Down Expand Up @@ -732,4 +731,9 @@ export function defineRules($, t) {
tokenMatcher(this.LA(2).tokenType, t.RSquare)
);
});

$.RULE("isFollowingVariableDeclarator", () => {
$.CONSUME(t.Comma);
$.SUBRULE2($.variableDeclarator);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ describe("Pattern matching", () => {
javaParser.parse(input, "componentPatternList")
).to.not.throw();
});

it("should parse pattern list with dims", () => {
const input = `A a, B[] b`;
expect(() =>
javaParser.parse(input, "componentPatternList")
).to.not.throw();
});
});

0 comments on commit b5d7f91

Please sign in to comment.