-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathsource_span.dart
38 lines (33 loc) · 1.36 KB
/
source_span.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2021 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'package:path/path.dart' as p;
import 'package:source_span/source_span.dart';
import '../util/lazy_file_span.dart';
import '../util/multi_span.dart';
import '../util/nullable.dart';
import 'reflection.dart';
import 'utils.dart';
/// Modifies the prototype of the `SourceFile` and `SourceLocation` classes so
/// that they match the JS API.
void updateSourceSpanPrototype() {
var span = SourceFile.fromString('').span(0);
var multiSpan = MultiSpan(span, '', {});
var lazySpan = LazyFileSpan(() => span);
for (var item in [span, multiSpan, lazySpan]) {
getJSClass(item).defineGetters({
'start': (FileSpan span) => span.start,
'end': (FileSpan span) => span.end,
'url': (FileSpan span) => span.sourceUrl.andThen((url) => dartToJSUrl(
url.scheme == '' ? p.toUri(p.absolute(p.fromUri(url))) : url)),
'text': (FileSpan span) => span.text,
'context': (FileSpan span) => span.context,
});
}
// Offset is already accessible from JS because it's defined as a field rather
// than a getter.
getJSClass(span.start).defineGetters({
'line': (SourceLocation location) => location.line,
'column': (SourceLocation location) => location.column,
});
}