Skip to content

Commit 758e185

Browse files
authored
Switch dart:js and some dart:js_util usages to use static interop (#3299)
1 parent 9735d89 commit 758e185

File tree

9 files changed

+3037
-3277
lines changed

9 files changed

+3037
-3277
lines changed

lib/resources/docs.dart.js

Lines changed: 2973 additions & 3256 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/resources/docs.dart.js.map

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: A non-interactive HTML documentation generator for Dart source code
55
repository: https://github.com/dart-lang/dartdoc
66

77
environment:
8-
sdk: '>=2.17.0 <3.0.0'
8+
sdk: '>=2.18.0 <3.0.0'
99

1010
dependencies:
1111
analyzer: "^5.2.0"
@@ -35,6 +35,7 @@ dev_dependencies:
3535
dart_style: ^2.2.0
3636
grinder: ^0.9.0
3737
http: ^0.13.3
38+
js: 0.6.5
3839
lints: ^2.0.0
3940
test: ^1.19.0
4041
test_descriptor: ^2.0.0

web/docs.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:js' as js;
6-
5+
import 'highlight.dart' as highlight;
76
import 'search.dart' as search;
87
import 'sidenav.dart' as sidenav;
98
import 'theme.dart' as theme;
109

1110
void main() {
12-
inithighlightJS();
11+
highlight.init();
1312
sidenav.init();
1413
search.init();
1514
theme.init();
1615
}
17-
18-
void inithighlightJS() {
19-
js.JsObject hljs = js.context['hljs'];
20-
hljs.callMethod('highlightAll');
21-
}

web/highlight.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:js/js.dart';
6+
7+
void init() {
8+
highlight?.highlightAll();
9+
}
10+
11+
@JS()
12+
@staticInterop
13+
class HighlightJs {}
14+
15+
extension HighlightJsExtension on HighlightJs {
16+
external void highlightAll();
17+
}
18+
19+
@JS('hljs')
20+
external HighlightJs? get highlight;

web/search.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import 'dart:convert';
66
import 'dart:html';
7-
import 'dart:js_util' as js_util;
7+
8+
import 'web_interop.dart';
89

910
final String _htmlBase = () {
1011
final body = document.querySelector('body')!;
@@ -34,14 +35,14 @@ void init() {
3435
}
3536

3637
window.fetch('${_htmlBase}index.json').then((response) async {
37-
int code = js_util.getProperty(response, 'status');
38+
response = response as FetchResponse;
39+
var code = response.status;
3840
if (code == 404) {
3941
disableSearch();
4042
return;
4143
}
4244

43-
var textPromise = js_util.callMethod<Object>(response, 'text', []);
44-
var text = await promiseToFuture<String>(textPromise);
45+
var text = await response.text;
4546
var jsonIndex = (jsonDecode(text) as List).cast<Map<String, dynamic>>();
4647
final index = jsonIndex.map(_IndexItem.fromMap).toList();
4748

@@ -167,7 +168,7 @@ class _Search {
167168
..append(moreResults)
168169
..append(searchResults);
169170

170-
/// Element used in [listbox] to inform the functionality of hitting enter in
171+
/// Element used in [listBox] to inform the functionality of hitting enter in
171172
/// search box.
172173
late final moreResults = document.createElement('div')
173174
..classes.add('enter-search-message');

web/sig.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
C6415C6028582DE4EC42B10F54BE3554
1+
6EB4A5A121E44E4224AB759B79E251E7

web/theme.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
15
import 'dart:html';
26

37
void init() {

web/web_interop.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:js_util' as js_util;
6+
7+
import 'package:js/js.dart';
8+
9+
@JS('Response')
10+
@staticInterop
11+
class FetchResponse {}
12+
13+
extension FetchResponseExtension on FetchResponse {
14+
external int get status;
15+
16+
@JS('text')
17+
external Promise _text();
18+
Future<String> get text => js_util.promiseToFuture(_text());
19+
}
20+
21+
@JS()
22+
@staticInterop
23+
class Promise {}

0 commit comments

Comments
 (0)