diff --git a/grammar.js b/grammar.js index 19d97e6..7cab56a 100644 --- a/grammar.js +++ b/grammar.js @@ -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, diff --git a/script-data/known_failures.txt b/script-data/known_failures.txt index 7c88645..db4c0c9 100644 --- a/script-data/known_failures.txt +++ b/script-data/known_failures.txt @@ -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 diff --git a/test/corpus/statements.txt b/test/corpus/statements.txt index 1a28810..e427233 100755 --- a/test/corpus/statements.txt +++ b/test/corpus/statements.txt @@ -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 ================================================================================