mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:04:53 +00:00
Updating pkg:sourcemap_testing function resolution for method definition syntax.
Change-Id: Ia3aa2d64226fa178eee72787c12ca0569390eb67 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206327 Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Mark Zhou <markzipan@google.com>
This commit is contained in:
parent
1bfc46ec2b
commit
978c4fe6ef
|
@ -436,12 +436,39 @@ class LineException {
|
|||
TargetEntry findEnclosingFunction(
|
||||
String sources, SourceFile file, int start, SingleMapping mapping) {
|
||||
if (sources == null) return null;
|
||||
int index = sources.lastIndexOf(': function(', start);
|
||||
if (index < 0) return null;
|
||||
index += 2;
|
||||
var line = file.getLine(index);
|
||||
var lineEntry = _findLineInternal(mapping, line);
|
||||
return _findColumn(line, file.getColumn(index), lineEntry);
|
||||
var index = start;
|
||||
while (true) {
|
||||
index = nextDeclarationCandidate(sources, index);
|
||||
if (index < 0) return null;
|
||||
var line = file.getLine(index);
|
||||
var lineEntry = _findLineInternal(mapping, line);
|
||||
var result = _findColumn(line, file.getColumn(index), lineEntry);
|
||||
if (result?.column == file.getColumn(index)) return result;
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the index of a candidate location of a enclosing function
|
||||
/// declaration. We try to find the beginning of a `function` keyword or the
|
||||
/// `(` of an ES6 method definition, but the search contains some false
|
||||
/// positives. To rule out false positives, [findEnclosingFunction]
|
||||
/// validates that the returned location contains a source-map entry, searching
|
||||
/// for another candidate if not.
|
||||
int nextDeclarationCandidate(String sources, int start) {
|
||||
var indexForFunctionKeyword = sources.lastIndexOf('function', start);
|
||||
// We attempt to identify potential method definitions by looking for any '('
|
||||
// that precedes a '{'. This method will fail if 1) Dart2JS starts emitting
|
||||
// functions with initializers or 2) sourcemap boundaries appear at '(' for
|
||||
// non-method-definition constructs.
|
||||
var indexForMethodDefinition = sources.lastIndexOf('{', start);
|
||||
if (indexForFunctionKeyword > indexForMethodDefinition ||
|
||||
indexForFunctionKeyword < 0) {
|
||||
return indexForFunctionKeyword;
|
||||
}
|
||||
indexForMethodDefinition = sources.lastIndexOf('(', indexForMethodDefinition);
|
||||
return indexForFunctionKeyword > indexForMethodDefinition
|
||||
? indexForFunctionKeyword
|
||||
: indexForMethodDefinition;
|
||||
}
|
||||
|
||||
Map<int, List<FrameEntry>> _loadInlinedFrameData(
|
||||
|
|
Loading…
Reference in a new issue