compileToMap method

Map<String, String> compileToMap()

Compile all user-defined modules and return a map from relative file path to Dart source code.

Keys follow the layout described in the class documentation. The entry module is compiled with a main() function; all others are compiled without one.

Implementation

Map<String, String> compileToMap() {
  final compiler = DartCompiler(program);
  final result = <String, String>{};

  for (final module in program.modules) {
    if (_baseModuleNames.contains(module.name)) continue;
    if (_isExternalStub(module)) continue;

    final filePath = PackageEncoder.moduleNameToFilePath(module.name);
    final String dartSource;
    if (module.name == program.entryModule) {
      dartSource = compiler.compile();
    } else {
      dartSource = compiler.compileModule(module.name);
    }
    result[filePath] = dartSource;
  }

  return result;
}