File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -1587,7 +1587,18 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
1587
1587
1588
1588
@override
1589
1589
void visitNullAwareElement (NullAwareElement node) {
1590
- writePrefix (node.question, node.value);
1590
+ // A null-aware element containing a dot shorthand means there is a `?` and
1591
+ // `.` next to each other. In that case, make sure we put a space between
1592
+ // them so that they don't incorrectly get collapsed into a `?.` null-aware
1593
+ // access token.
1594
+ var space = switch (node.value) {
1595
+ DotShorthandConstructorInvocation () => true ,
1596
+ DotShorthandInvocation () => true ,
1597
+ DotShorthandPropertyAccess () => true ,
1598
+ _ => false ,
1599
+ };
1600
+
1601
+ writePrefix (node.question, space: space, node.value);
1591
1602
}
1592
1603
1593
1604
@override
Original file line number Diff line number Diff line change @@ -27,3 +27,17 @@ var list = [
27
27
?(veryLongExpression +
28
28
thatIsForcedToSplit),
29
29
];
30
+ >>> (experiment dot-shorthands) Preserves space for dot shorthand.
31
+ ### If the space between `?` and `.` is removed, it would become a single `?.`
32
+ ### token and thus a parse error.
33
+ var list = [
34
+ ? . property ,
35
+ ? . invocation ( ) ,
36
+ ? . new ( ) ,
37
+ ];
38
+ <<< 3.10
39
+ var list = [
40
+ ? .property,
41
+ ? .invocation(),
42
+ ? .new(),
43
+ ];
Original file line number Diff line number Diff line change @@ -33,3 +33,20 @@ var map = {
33
33
? // c
34
34
value,
35
35
};
36
+ >>> (experiment dot-shorthands) Comment between `?` and `.` of dot shorthand.
37
+ var list = [
38
+ ? /* c */ . property ,
39
+ ? // c
40
+ . invocation ( ) ,
41
+ ? /// c
42
+ . new ( ) ,
43
+ ];
44
+ <<< 3.10
45
+ var list = [
46
+ ? /* c */ .property,
47
+ ? // c
48
+ .invocation(),
49
+ ?
50
+ /// c
51
+ .new(),
52
+ ];
You can’t perform that action at this time.
0 commit comments