Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.1.3-wip

* Don't force a space between `?` and `.` if a null-aware element contains a
dot shorthand.

## 3.1.2

* Support dot shorthand syntax.
Expand Down
13 changes: 1 addition & 12 deletions lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1605,18 +1605,7 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {

@override
void visitNullAwareElement(NullAwareElement node) {
// A null-aware element containing a dot shorthand means there is a `?` and
// `.` next to each other. In that case, make sure we put a space between
// them so that they don't incorrectly get collapsed into a `?.` null-aware
// access token.
var space = switch (node.value) {
DotShorthandConstructorInvocation() => true,
DotShorthandInvocation() => true,
DotShorthandPropertyAccess() => true,
_ => false,
};

writePrefix(node.question, space: space, node.value);
writePrefix(node.question, node.value);
}

@override
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
version: 3.1.2
version: 3.1.3-wip
description: >-
Opinionated, automatic Dart source code formatter.
Provides an API and a CLI tool.
Expand All @@ -9,7 +9,7 @@ environment:
sdk: ^3.7.0

dependencies:
analyzer: ^8.0.0
analyzer: ^8.1.0
args: ^2.0.0
collection: ^1.19.0
package_config: ^2.1.0
Expand Down
18 changes: 14 additions & 4 deletions test/tall/expression/collection_null_aware.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,23 @@ var list = [
### If the space between `?` and `.` is removed, it would become a single `?.`
### token and thus a parse error.
var list = [
? . property ,
?. property ,
? . invocation ( ) ,
? . new ( ) ,
];
<<< 3.10
var list = [
? .property,
? .invocation(),
? .new(),
?.property,
?.invocation(),
?.new(),
];
>>> (experiment dot-shorthands) Ambiguous dot shorthand versus null-aware.
### Because there is no space in "?.", it must be a null-aware access in a map.
c = { e1 ?. e2 : e3 };
<<< 3.10
c = {e1?.e2: e3};
>>> (experiment dot-shorthands) Ambiguous dot shorthand versus null-aware.
### Because there is a space in "? .", it must be a dot shorthand in a set.
c = { e1 ? . e2 : e3 };
<<< 3.10
c = {e1 ? .e2 : e3};