Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ private void visitBinaryUpdateExpression(TSCNode incrementor, List<JRightPadded<
}
Statement r = (Statement) visitNode(incrementor.getNodeProperty("right"));
Space after = whitespace();
if (sourceStartsWithAtCursor(",")) {
consumeToken(TSCSyntaxKind.CommaToken);
} else if (sourceStartsWithAtCursor(")")) {
consumeToken(TSCSyntaxKind.CloseParenToken);
if (tryConsume(TSCSyntaxKind.CommaToken)) {
// TODO check where to add this to LST
} else if (tryConsume(TSCSyntaxKind.CloseParenToken)) {
// TODO check where to add this to LST
}
updates.add(padRight(r, after));
}
Expand Down Expand Up @@ -3110,23 +3110,31 @@ private <T> JRightPadded<T> padRight(T tree, @Nullable Space right, Markers mark
}

private <K2 extends J> JRightPadded<K2> maybeSemicolon(K2 k) {
return tryConsumeWithPrefix(
TSCSyntaxKind.SemicolonToken,
prefix -> new JRightPadded<>(k, prefix, Markers.EMPTY.add(new Semicolon(randomId())))
).orElseGet(() -> JRightPadded.build(k));
}

private boolean tryConsume(TSCSyntaxKind kind) {
int saveCursor = getCursor();
Space beforeSemi = whitespace();
Semicolon semicolon = null;
if (sourceStartsWithAtCursor(";")) {
semicolon = new Semicolon(randomId());
consumeToken(TSCSyntaxKind.SemicolonToken);
if (scan() == kind) {
return true;
} else {
beforeSemi = EMPTY;
cursor(saveCursor);
cursorContext.resetScanner(saveCursor);
return false;
}
}

JRightPadded<K2> padded = JRightPadded.build(k).withAfter(beforeSemi);
if (semicolon != null) {
padded = padded.withMarkers(padded.getMarkers().add(semicolon));
private <T> Optional<T> tryConsumeWithPrefix(TSCSyntaxKind kind, Function<Space, T> whenMatched) {
int saveCursor = getCursor();
Space prefix = whitespace();
if (scan() == kind) {
return Optional.of(whenMatched.apply(prefix));
} else {
cursorContext.resetScanner(saveCursor);
return Optional.empty();
}

return padded;
}

private TSCSyntaxKind scan() {
Expand Down Expand Up @@ -3282,9 +3290,8 @@ private <T extends J> JContainer<T> mapContainer(TSCSyntaxKind open, List<TSCNod
after = sourceBefore(delimiter);
} else if (delimiter == TSCSyntaxKind.CommaToken) {
after = whitespace();
if (sourceStartsWithAtCursor(",")) {
consumeToken(delimiter);
markers = markers.addIfAbsent(new TrailingComma(randomId(), whitespace()));
if (tryConsume(TSCSyntaxKind.CommaToken)) {
markers = markers.add(new TrailingComma(randomId(), whitespace()));
}
} else {
after = whitespace();
Expand Down