visitImportElement method

  1. @override
List<Directive> visitImportElement(
  1. ImportElement importElement
)
override

Implementation

@override
List<Directive> visitImportElement(ImportElement importElement) {
  final String url;

  switch (importElement.package) {
    case DartSdkPackage(:final name):
      url = 'dart:$name';
    case ExternalPackage(:final name):
      final parts = name.split('/');

      if (parts case [final root]) {
        url = 'package:$root/$root.dart';
      } else {
        url = 'package:$name.dart';
      }
    case CurrentPackage():
      throw 'Nope'; // TODO(mateusfccp): CurrentPackage shouldn't exist
  }

  return [Directive.import(url)];
}