DartFile constructor

DartFile({
  1. required String basename,
  2. required String content,
  3. List<String> segments = const [],
  4. List<PartFile> parts = const [],
})

Implementation

DartFile({
  required super.basename,
  required super.content,
  super.segments,
  List<PartFile> parts = const [],
}) : parts = parts.map((e) {
       if (e.path.isEmpty) {
         throw AssertionError('Part file path cannot be empty.');
       }

       for (final partPath in e.path) {
         if (partPath.isEmpty) {
           throw AssertionError('Part file path cannot contain empty parts.');
         }

         if (partPath.contains(RegExp(r'\\|\/|\.\\|\.{2,}|^\.'))) {
           throw AssertionError(
             'Part file path cannot contain relative paths.',
           );
         }
       }

       if (e.path.last.endsWith('.dart')) {
         throw AssertionError('Part file path must not end with .dart.');
       }

       return e;
     }).toList(),
     assert(
       parts.toSet().length == parts.length,
       'Part files must be unique within a Dart file.',
     ),
     super(extension: 'dart') {
  for (final part in parts) {
    part.parent = this;
  }
}