loadModule method

  1. @override
LoadedModule loadModule(
  1. Uri uri, {
  2. Set<String>? showNames,
  3. Set<String>? hideNames,
})
override

Loads a module from the given URI.

uri The resolved URI of the module to load (package:, dart:, or file:). showNames Optional set of names to show (import ... show x, y). hideNames Optional set of names to hide (import ... hide x, y).

Returns a LoadedModule containing the AST and exported environment.

Throws RuntimeD4rtException if the module cannot be loaded.

Implementation

@override
LoadedModule loadModule(
  Uri uri, {
  Set<String>? showNames,
  Set<String>? hideNames,
}) {
  // 1. Check cache
  if (_moduleCache.containsKey(uri)) {
    Logger.debug('[AstModuleLoader] Cache hit for module: $uri');
    return _moduleCache[uri]!;
  }

  Logger.debug(
    '[AstModuleLoader] Loading module: $uri '
    '(show: $showNames, hide: $hideNames)',
  );

  // 2. Handle dart:* stdlib modules (may return null if has bridged content)
  if (uri.isScheme('dart')) {
    final stdlibModule = _loadStdlibModule(uri);
    if (stdlibModule != null) {
      return stdlibModule;
    }
    // Fall through to bridged library handling
  }

  // 3. Handle bridged library URIs
  final bridgedModule = _tryLoadBridgedModule(uri, showNames, hideNames);
  if (bridgedModule != null) {
    return bridgedModule;
  }

  // 4. Lookup in bundle modules
  final uriString = uri.toString();
  final ast = modules[uriString];
  if (ast != null) {
    return _loadBundleModule(uri, ast);
  }

  // 5. Not found
  throw RuntimeD4rtException(
    'Module "$uriString" not found in bundle. '
    'Available: ${modules.keys.join(", ")}',
  );
}