@@ -8,6 +8,7 @@ import 'dart:convert';
88import 'package:flutter/material.dart' ;
99import 'package:flutter/services.dart' show rootBundle;
1010
11+ import '../../shared/config_specific/logger/logger.dart' ;
1112import '../../shared/primitives/utils.dart' ;
1213import '../../shared/theme.dart' ;
1314import 'span_parser.dart' ;
@@ -41,7 +42,19 @@ class SyntaxHighlighter {
4142 final grammarJson = json.decode (
4243 await rootBundle.loadString ('assets/dart_syntax.json' ),
4344 );
44- _grammar = Grammar .fromJson (grammarJson);
45+ try {
46+ _grammar = Grammar .fromJson (grammarJson);
47+ } catch (error) {
48+ // Safari does not support negative-lookbehind regex which are currently
49+ // required by the syntax highlighting. An unhandled exception here will
50+ // prevent DevTools initializing, so just print the error and leave
51+ // syntax highlighting disabled if this happens.
52+ log (
53+ 'Failed to load Dart Syntax Highlighting:\n '
54+ '$error ' ,
55+ LogLevel .warning,
56+ );
57+ }
4558 }
4659 }
4760
@@ -60,11 +73,15 @@ class SyntaxHighlighter {
6073 .sublist (lineRange.begin - 1 , lineRange.end)
6174 .join ('\n ' );
6275 }
76+ final grammar = _grammar;
77+ if (grammar == null ) {
78+ return TextSpan (text: _processedSource);
79+ }
6380 return TextSpan (
6481 children: _highlightLoopHelper (
6582 currentScope: null ,
6683 loopCondition: () => _currentPosition < _processedSource.length,
67- scopes: SpanParser .parse (_grammar ! , _processedSource),
84+ scopes: SpanParser .parse (grammar , _processedSource),
6885 ),
6986 );
7087 }
0 commit comments