Skip to content
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

Fix error in for await in await #359

Merged
merged 1 commit into from
Feb 19, 2024
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
10 changes: 9 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,11 +1161,19 @@ module.exports = grammar({
field("item", alias($._binding_pattern_no_expr, $.pattern)),
optional($.type_annotation),
"in",
field("collection", $._expression),
field("collection", $._for_statement_collection),
optional($.where_clause),
$._block
)
),
_for_statement_collection: ($) =>
// If this expression has "await", this triggers some special-cased logic to prefer function calls. We prefer
// the opposite, though, since function calls may contain trailing code blocks, which are undesirable here.
//
// To fix that, we simply undo the special casing by defining our own `await_expression`.
choice($._expression, alias($.for_statement_await, $.await_expression)),
for_statement_await: ($) => seq($._await_operator, $._expression),

while_statement: ($) =>
prec(
PRECS.loop,
Expand Down
1 change: 0 additions & 1 deletion script-data/known_failures.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ReactKit/ReactKitTests/OperationTests.swift
RxSwift/Tests/RxCocoaTests/SharedSequence+ConcurrencyTests.swift
GRDB/GRDB/Core/Statement.swift
lottie-ios/Sources/Public/Animation/LottieAnimationLayer.swift
21 changes: 21 additions & 0 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ outerLoop: for outerObject in dataArray {
(control_transfer_statement
(simple_identifier)))))))))

================================================================================
For await in await
================================================================================

for await _ in await driver.values {
//
}

--------------------------------------------------------------------------------

(source_file
(for_statement
(pattern
(wildcard_pattern))
(await_expression
(navigation_expression
(simple_identifier)
(navigation_suffix
(simple_identifier))))
(comment)))

================================================================================
While and friends
================================================================================
Expand Down
Loading