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 @@ -1599,7 +1599,18 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
15991599
16001600 @override
16011601 void visitNullAwareElement (NullAwareElement node) {
1602- writePrefix (node.question, node.value);
1602+ // A null-aware element containing a dot shorthand means there is a `?` and
1603+ // `.` next to each other. In that case, make sure we put a space between
1604+ // them so that they don't incorrectly get collapsed into a `?.` null-aware
1605+ // access token.
1606+ var space = switch (node.value) {
1607+ DotShorthandConstructorInvocation () => true ,
1608+ DotShorthandInvocation () => true ,
1609+ DotShorthandPropertyAccess () => true ,
1610+ _ => false ,
1611+ };
1612+
1613+ writePrefix (node.question, space: space, node.value);
16031614 }
16041615
16051616 @override
Original file line number Diff line number Diff line change @@ -27,3 +27,17 @@ var list = [
2727 ?(veryLongExpression +
2828 thatIsForcedToSplit),
2929];
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 = {
3333 ? // c
3434 value,
3535};
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