Skip to content

Commit dbcf974

Browse files
authored
Add a debug flag for when building the web code (#3864)
1 parent 46564a6 commit dbcf974

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

lib/resources/docs.dart.js.map

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

lib/src/search.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ class IndexItem {
130130
EnclosedBy? enclosedBy;
131131
if (data['enclosedBy'] != null) {
132132
final map = data['enclosedBy'] as Map<String, dynamic>;
133+
assert(
134+
map['href'] != null,
135+
"'enclosedBy' element expected to have a non-null 'href', "
136+
"but was null: '${data['qualifiedName']}', "
137+
"enclosed by the ${Kind.values[map['kind'] as int]} '${map['name']}' "
138+
"('${map['qualifiedName']}')",
139+
);
133140
enclosedBy = EnclosedBy._(
134141
name: map['name'] as String,
135142
kind: Kind.values[map['kind'] as int],

tool/task.dart

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ import 'src/warnings_collection.dart';
2323
void main(List<String> args) async {
2424
var parser = ArgParser()
2525
..addCommand('analyze')
26-
..addCommand('build')
2726
..addCommand('buildbot')
2827
..addCommand('clean')
2928
..addCommand('compare')
3029
..addCommand('help')
3130
..addCommand('test')
3231
..addCommand('try-publish')
3332
..addCommand('validate');
33+
var buildCommand = parser.addCommand('build')
34+
..addFlag('debug', help: 'build unoptimized JavaScript');
3435
var docCommand = parser.addCommand('doc')
3536
..addOption('name', help: 'package name')
3637
..addOption('version', help: 'package version')
@@ -45,6 +46,7 @@ void main(List<String> args) async {
4546
return;
4647
}
4748

49+
buildUsage = buildCommand.usage;
4850
docUsage = docCommand.usage;
4951
serveUsage = serveCommand.usage;
5052

@@ -64,6 +66,7 @@ void main(List<String> args) async {
6466
};
6567
}
6668

69+
late String buildUsage;
6770
late String docUsage;
6871
late String serveUsage;
6972

@@ -116,15 +119,24 @@ Future<void> analyzeTestPackages() async {
116119
}
117120
}
118121

122+
Future<void> _buildHelp() async {
123+
print('''
124+
Usage:
125+
dart tool/task.dart build [renderers|dartdoc-options|web]
126+
$buildUsage
127+
''');
128+
}
129+
119130
Future<void> runBuild(ArgResults commandResults) async {
120131
if (commandResults.rest.isEmpty) {
121132
await buildAll();
122133
}
134+
var debug = (commandResults['debug'] ?? false) as bool;
123135
for (var target in commandResults.rest) {
124136
await switch (target) {
125137
'renderers' => buildRenderers(),
126138
'dartdoc-options' => buildDartdocOptions(),
127-
'web' => buildWeb(),
139+
'web' => buildWeb(debug: debug),
128140
_ => throw UnimplementedError('Unknown build target: "$target"'),
129141
};
130142
}
@@ -154,13 +166,14 @@ Future<void> buildDartdocOptions() async {
154166
''');
155167
}
156168

157-
Future<void> buildWeb() async {
169+
Future<void> buildWeb({bool debug = false}) async {
158170
await SubprocessLauncher('build').runStreamedDartCommand([
159171
'compile',
160172
'js',
161173
'--output=lib/resources/docs.dart.js',
162174
'web/docs.dart',
163-
'-O4',
175+
if (debug) '--enable-asserts',
176+
debug ? '-O0' : '-O4',
164177
]);
165178
_delete(File('lib/resources/docs.dart.js.deps'));
166179

@@ -294,7 +307,7 @@ Future<void> runDoc(ArgResults commandResults) async {
294307
throw ArgumentError('"doc" command requires a single target.');
295308
}
296309
var target = commandResults.rest.single;
297-
var stats = commandResults['stats'];
310+
var stats = commandResults['stats'] as bool;
298311
await switch (target) {
299312
'flutter' => docFlutter(withStats: stats),
300313
'help' => _docHelp(),
@@ -616,6 +629,7 @@ Help usage:
616629
}
617630
var command = commandResults.rest.single;
618631
return switch (command) {
632+
'build' => _buildHelp(),
619633
'doc' => _docHelp(),
620634
'serve' => _serveHelp(),
621635
_ => throw UnimplementedError(

0 commit comments

Comments
 (0)