anchor.diff:      return _libraryBeingLoaded == element;
     }
   
  -  void _buildLibraryBody(LibraryElement element, ast.Library library) {
  +  void _buildLibraryBody(LibraryElement element, ast.Library library,
  +      List<CompilationUnit> units) {
       assert(_libraryBeingLoaded == null);
       _libraryBeingLoaded = element;
       var classes = <ast.Class>[];
       var procedures = <ast.Procedure>[];
       var fields = <ast.Field>[];
  -    void loadClass(ClassElement classElement) {
  -      var node = getClassReference(classElement);
  -      promoteToBodyLevel(node);
  +
  +    void loadClass(NamedCompilationUnitMember declaration) {
  +      // [declaration] can be a ClassDeclaration, EnumDeclaration, or a
  +      // ClassTypeAlias.
  +      ClassElement element = declaration.element;
  +      var node = getClassReference(element);
  +      promoteToBodyLevel(node, element, declaration);
         classes.add(node);
       }
   
  -    void loadProcedure(Element memberElement) {
  -      var node = getMemberReference(memberElement);
  -      _buildTopLevelMember(node, memberElement);
  +    void loadProcedure(FunctionDeclaration declaration) {
  +      var element = declaration.element;
  +      var node = getMemberReference(element);
  +      _buildTopLevelMember(node, element, declaration);
         procedures.add(node);
       }
   
  -    void loadField(Element memberElement) {
  -      var node = getMemberReference(memberElement);
  -      _buildTopLevelMember(node, memberElement);
  -      fields.add(node);
  -    }
  -
  -    for (var unit in element.units) {
  -      unit.types.forEach(loadClass);
  -      unit.enums.forEach(loadClass);
  -      for (var accessor in unit.accessors) {
  -        if (!accessor.isSynthetic) {
  -          loadProcedure(accessor);
  -        }
  -      }
  -      for (var function in unit.functions) {
  -        loadProcedure(function);
  -      }
  -      for (var field in unit.topLevelVariables) {
  +    void loadField(TopLevelVariableDeclaration declaration) {
  +      for (var field in declaration.variables.variables) {
  +        var element = field.element;
           // Ignore fields inserted through error recovery.
  -        if (!field.isSynthetic && field.name != '') {
  -          loadField(field);
  +        if (element.name == '') continue;
  +        var node = getMemberReference(element);
  +        _buildTopLevelMember(node, element, field);
  +        fields.add(node);
  +      }
  +    }
  +
  +    for (var unit in units) {
  +      for (CompilationUnitMember declaration in unit.declarations) {
  +        if (declaration is ClassDeclaration ||
  +            declaration is EnumDeclaration ||
  +            declaration is ClassTypeAlias) {
  +          loadClass(declaration);
  +        } else if (declaration is FunctionDeclaration) {
  +          loadProcedure(declaration);
  +        } else if (declaration is TopLevelVariableDeclaration) {
  +          loadField(declaration);
  +        } else if (declaration is FunctionTypeAlias) {
  +          // Nothing to do. Typedefs are handled lazily while constructing type
  +          // references.
  +        } else {
  +          throw "unexpected node: ${declaration.runtimeType} $declaration";
           }
         }
       }
  
positive.code:     for (LibraryElement libraryElement in libraryElements) {
        for (CompilationUnitElement compilationUnitElement
            in libraryElement.units) {
          // TODO(jensj): Get this another way?
          LineInfo lineInfo = compilationUnitElement.computeNode().lineInfo;
          program.uriToLineStarts[
                  "file://${compilationUnitElement.source.source.fullName}"] =
              new List<int>.generate(lineInfo.lineCount, lineInfo.getOffsetOfLine,
                  growable: false);
        }
  
negative.code:         .forUri2(applicationRoot.absoluteUri(node.importUri));
      assert(source != null);
      var element = context.computeLibraryElement(source);
      var units = <CompilationUnit>[];
      bool reportErrors = node.importUri.scheme != 'dart';
      var tree = context.resolveCompilationUnit(source, element);
      units.add(tree);
      if (reportErrors) _processErrors(source);
      for (var part in element.parts) {
        var source = part.source;
        units.add(context.resolveCompilationUnit(source, element));
        if (reportErrors) _processErrors(source);
      }
      _buildLibraryBody(element, node, units);
    }
  
    void _processErrors(Source source) {
      LineInfo lines;
      for (var error in context.computeErrors(source)) {
        if (error.errorCode is CompileTimeErrorCode ||
            error.errorCode is ParserErrorCode ||
            error.errorCode is ScannerErrorCode ||
            error.errorCode is StrongModeCode) {
          lines ??= context.computeLineInfo(source);
          errors.add(formatErrorMessage(error, source.shortName, lines));
        }
      }
    }
  