@@ -14,23 +14,8 @@ void main(List<String> arguments) {
1414 (_) => 'Error while reading source from "${sourceFile .path }"' ,
1515 );
1616
17- final classes = RegExp (r'new self.([A-Za-z]+)\(' )
18- .allMatches (sourceString)
19- .map ((e) => e.group (1 ))
20- .whereNotNull ()
21- .toSet ()
22- .intersection (config.classes)
23- .whereNot ((e) => sourceString.contains ('import { $e }' ))
24- .toList ();
25-
26- if (classes.isEmpty) return ;
27-
28- final newSource = [
29- ...[config.importStringForClass, (e) => 'self.$e = $e ' ]
30- .map (classes.map)
31- .flattened,
32- sourceString,
33- ].join ('\n ' );
17+ final newSource = createNewSource (sourceString, config);
18+ if (newSource == sourceString) return ;
3419
3520 mapException (
3621 () => sourceFile.writeAsStringSync (newSource),
@@ -56,3 +41,21 @@ void main(List<String> arguments) {
5641
5742 return (File (filename), config);
5843}
44+
45+ String createNewSource (String sourceString, Config config) {
46+ final classes = RegExp (r'new self.([A-Za-z]+)\(' )
47+ .allMatches (sourceString)
48+ .map ((e) => e.group (1 ))
49+ .whereNotNull ()
50+ .toSet ()
51+ .intersection (config.classes)
52+ .whereNot ((e) => sourceString.contains ('import { $e }' ))
53+ .toList ();
54+
55+ return [
56+ ...[config.importStringForClass, (e) => 'self.$e = $e ' ]
57+ .map (classes.map)
58+ .flattened,
59+ sourceString,
60+ ].join ('\n ' );
61+ }
0 commit comments