Skip to content

Commit 644f141

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Fix for matching AST when add/remove tokens at the end.
Change-Id: I3ef648383f183cdfe9f7698218a2188ae050d02c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444540 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 04ce7a8 commit 644f141

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

pkg/analyzer/lib/src/fine/manifest_ast.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ class ManifestNode {
142142
var tokenOffset = 0;
143143
var token = node.beginToken;
144144
while (true) {
145+
if (tokenIndex >= tokenLengthList.length) {
146+
return false;
147+
}
148+
145149
var tokenLength = token.lexeme.length;
146150
if (tokenLengthList[tokenIndex++] != tokenLength) {
147151
return false;
@@ -158,6 +162,10 @@ class ManifestNode {
158162
token = token.next ?? (throw StateError('endToken not found'));
159163
}
160164

165+
if (tokenIndex != tokenLengthList.length) {
166+
return false;
167+
}
168+
161169
var collector = _ElementCollector(
162170
indexOfTypeParameter: context.indexOfTypeParameter,
163171
indexOfFormalParameter: context.indexOfFormalParameter,

pkg/analyzer/test/src/dart/analysis/driver_test.dart

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43997,6 +43997,98 @@ const b = 0 as int;
4399743997
);
4399843998
}
4399943999

44000+
test_manifest_constInitializer_identifier_addIdentifier() async {
44001+
configuration.withElementManifests = true;
44002+
await _runLibraryManifestScenario(
44003+
initialCode: r'''
44004+
@foo
44005+
class A {}
44006+
''',
44007+
expectedInitialEvents: r'''
44008+
[operation] linkLibraryCycle SDK
44009+
[operation] linkLibraryCycle
44010+
package:test/test.dart
44011+
declaredClasses
44012+
A: #M0
44013+
metadata
44014+
[0]
44015+
tokenBuffer: @foo
44016+
tokenLengthList: [1, 3]
44017+
elementIndexList
44018+
0 = null
44019+
0 = null
44020+
supertype: Object @ dart:core
44021+
interface: #M1
44022+
''',
44023+
updatedCode: r'''
44024+
@foo.bar
44025+
class A {}
44026+
''',
44027+
expectedUpdatedEvents: r'''
44028+
[operation] linkLibraryCycle
44029+
package:test/test.dart
44030+
declaredClasses
44031+
A: #M2
44032+
metadata
44033+
[0]
44034+
tokenBuffer: @foo.bar
44035+
tokenLengthList: [1, 3, 1, 3]
44036+
elementIndexList
44037+
0 = null
44038+
0 = null
44039+
0 = null
44040+
supertype: Object @ dart:core
44041+
interface: #M3
44042+
''',
44043+
);
44044+
}
44045+
44046+
test_manifest_constInitializer_identifierIdentifier_removeIdentifier() async {
44047+
configuration.withElementManifests = true;
44048+
await _runLibraryManifestScenario(
44049+
initialCode: r'''
44050+
@foo.bar
44051+
class A {}
44052+
''',
44053+
expectedInitialEvents: r'''
44054+
[operation] linkLibraryCycle SDK
44055+
[operation] linkLibraryCycle
44056+
package:test/test.dart
44057+
declaredClasses
44058+
A: #M0
44059+
metadata
44060+
[0]
44061+
tokenBuffer: @foo.bar
44062+
tokenLengthList: [1, 3, 1, 3]
44063+
elementIndexList
44064+
0 = null
44065+
0 = null
44066+
0 = null
44067+
supertype: Object @ dart:core
44068+
interface: #M1
44069+
''',
44070+
updatedCode: r'''
44071+
@foo
44072+
class A {}
44073+
''',
44074+
expectedUpdatedEvents: r'''
44075+
[operation] linkLibraryCycle
44076+
package:test/test.dart
44077+
declaredClasses
44078+
A: #M2
44079+
metadata
44080+
[0]
44081+
tokenBuffer: @foo
44082+
tokenLengthList: [1, 3]
44083+
elementIndexList
44084+
0 = null
44085+
0 = null
44086+
supertype: Object @ dart:core
44087+
interface: #M3
44088+
''',
44089+
);
44090+
}
44091+
4400044092
test_manifest_constInitializer_importPrefixReference() async {
4400144093
configuration.withElementManifests = true;
4400244094
await _runLibraryManifestScenario(

0 commit comments

Comments
 (0)