[_fe_analyzer_shared] handle $this in String interpolation

Fixes #50263

Change-Id: I4fdfab69a2d462768848f01aceb450f266e09072
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265083
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Ahmed Ashour 2022-10-24 16:41:13 +00:00 committed by Commit Queue
parent 79b11174a2
commit 5e75bb14a5
2 changed files with 32 additions and 1 deletions

View file

@ -1632,7 +1632,7 @@ abstract class AbstractScanner implements Scanner {
if (($A <= next && next <= $Z) ||
($0 <= next && next <= $9) ||
identical(next, $_) ||
identical(next, $$)) {
(allowDollar && identical(next, $$))) {
return tokenizeIdentifier(next, start, allowDollar);
} else {
appendKeywordToken(keyword);

View file

@ -1783,6 +1783,37 @@ final v = """a${bb}ccc""";
expect(node.isSingleQuoted, isFalse);
}
}
void test_this_followedByDollar() {
final parseResult = parseStringWithErrors(r'''
class C {
void m(int foo) {
'$this$foo';
}
}
''');
parseResult.assertNoErrors();
var node = parseResult.findNode.stringInterpolation('this');
assertParsedNodeText(node, r'''
StringInterpolation
elements
InterpolationString
contents: '
InterpolationExpression
leftBracket: $
expression: ThisExpression
thisKeyword: this
InterpolationString
contents: <empty> <synthetic>
InterpolationExpression
leftBracket: $
expression: SimpleIdentifier
token: foo
InterpolationString
contents: '
stringValue: null
''');
}
}
@reflectiveTest