[cfe] Remove LibraryBuilder.scope and DeclarationBuilder.scope

Scopes are now handled through fragments

Change-Id: I9d73ef2ba48222962ae28fd9787b83536126c88d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412600
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
diff --git a/pkg/front_end/lib/src/base/incremental_compiler.dart b/pkg/front_end/lib/src/base/incremental_compiler.dart
index 942afe2..6824b0d9 100644
--- a/pkg/front_end/lib/src/base/incremental_compiler.dart
+++ b/pkg/front_end/lib/src/base/incremental_compiler.dart
@@ -1987,7 +1987,7 @@
               new ImplicitLanguageVersion(libraryBuilder.languageVersion),
           loader: lastGoodKernelTarget.loader,
           nameOrigin: libraryBuilder,
-          parentScope: debugLibrary.scope,
+          parentScope: debugCompilationUnit.compilationUnitScope,
           isUnsupported: libraryBuilder.isUnsupported,
           forAugmentationLibrary: false,
           forPatchLibrary: false,
diff --git a/pkg/front_end/lib/src/base/scope.dart b/pkg/front_end/lib/src/base/scope.dart
index c334337..003b2c1 100644
--- a/pkg/front_end/lib/src/base/scope.dart
+++ b/pkg/front_end/lib/src/base/scope.dart
@@ -595,30 +595,6 @@
   }
 }
 
-abstract class ConstructorScope {
-  MemberBuilder? lookup(String name, int charOffset, Uri fileUri);
-}
-
-class DeclarationNameSpaceConstructorScope implements ConstructorScope {
-  final String _className;
-
-  final DeclarationNameSpace _nameSpace;
-
-  DeclarationNameSpaceConstructorScope(this._className, this._nameSpace);
-
-  @override
-  MemberBuilder? lookup(String name, int charOffset, Uri fileUri) {
-    MemberBuilder? builder = _nameSpace.lookupConstructor(name);
-    if (builder == null) return null;
-    if (builder.next != null) {
-      return new AmbiguousMemberBuilder(
-          name.isEmpty ? _className : name, builder, charOffset, fileUri);
-    } else {
-      return builder;
-    }
-  }
-}
-
 /// Computes a builder for the import collision between [declaration] and
 /// [other].
 Builder computeAmbiguousDeclarationForImport(ProblemReporting problemReporting,
diff --git a/pkg/front_end/lib/src/builder/class_builder.dart b/pkg/front_end/lib/src/builder/class_builder.dart
index c36be23..9e0a6fa 100644
--- a/pkg/front_end/lib/src/builder/class_builder.dart
+++ b/pkg/front_end/lib/src/builder/class_builder.dart
@@ -232,24 +232,6 @@
     return builder;
   }
 
-  // Coverage-ignore(suite): Not run.
-  /// Find the first member of this class with [name]. This method isn't
-  /// suitable for scope lookups as it will throw an error if the name isn't
-  /// declared. The [scope] should be used for that. This method is used to
-  /// find a member that is known to exist and it will pick the first
-  /// declaration if the name is ambiguous.
-  ///
-  /// For example, this method is convenient for use when building synthetic
-  /// members, such as those of an enum.
-  MemberBuilder? firstMemberNamed(String name) {
-    MemberBuilder declaration =
-        lookupLocalMember(name, required: true) as MemberBuilder;
-    while (declaration.next != null) {
-      declaration = declaration.next as MemberBuilder;
-    }
-    return declaration;
-  }
-
   @override
   InterfaceType get thisType {
     return _thisType ??= new InterfaceType(cls, Nullability.nonNullable,
diff --git a/pkg/front_end/lib/src/builder/declaration_builder.dart b/pkg/front_end/lib/src/builder/declaration_builder.dart
index a4e9897..f1722b6 100644
--- a/pkg/front_end/lib/src/builder/declaration_builder.dart
+++ b/pkg/front_end/lib/src/builder/declaration_builder.dart
@@ -5,12 +5,8 @@
 part of 'declaration_builders.dart';
 
 abstract class IDeclarationBuilder implements ITypeDeclarationBuilder {
-  LookupScope get scope;
-
   DeclarationNameSpace get nameSpace;
 
-  ConstructorScope get constructorScope;
-
   /// Type parameters declared on this declaration.
   ///
   /// This is `null` if the declaration is not generic.
@@ -75,11 +71,16 @@
       return null;
     }
     MemberBuilder? declaration =
-        constructorScope.lookup(name == 'new' ? '' : name, charOffset, uri);
+        nameSpace.lookupConstructor(name == 'new' ? '' : name);
     if (declaration == null && isAugmenting) {
       return origin.findConstructorOrFactory(
           name, charOffset, uri, accessingLibrary);
     }
+    if (declaration != null && declaration.next != null) {
+      return new AmbiguousMemberBuilder(
+          name.isEmpty ? this.name : name, declaration, charOffset, fileUri);
+    }
+
     return declaration;
   }
 
diff --git a/pkg/front_end/lib/src/builder/formal_parameter_builder.dart b/pkg/front_end/lib/src/builder/formal_parameter_builder.dart
index 0719373..9d6be15 100644
--- a/pkg/front_end/lib/src/builder/formal_parameter_builder.dart
+++ b/pkg/front_end/lib/src/builder/formal_parameter_builder.dart
@@ -263,12 +263,9 @@
   /// formal parameter on a const constructor or instance method.
   void buildOutlineExpressions(SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      {required bool buildDefaultValue}) {
+      {required LookupScope scope, required bool buildDefaultValue}) {
     if (buildDefaultValue) {
       if (initializerToken != null) {
-        LookupScope scope =
-            declarationBuilder?.scope ?? // Coverage-ignore(suite): Not run.
-                libraryBuilder.scope;
         BodyBuilderContext bodyBuilderContext = new ParameterBodyBuilderContext(
             libraryBuilder, declarationBuilder, this);
         BodyBuilder bodyBuilder = libraryBuilder.loader
diff --git a/pkg/front_end/lib/src/builder/library_builder.dart b/pkg/front_end/lib/src/builder/library_builder.dart
index 7e15e4c..2f9398f 100644
--- a/pkg/front_end/lib/src/builder/library_builder.dart
+++ b/pkg/front_end/lib/src/builder/library_builder.dart
@@ -3,7 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
-import 'package:kernel/ast.dart' show Class, Library, Version;
+import 'package:kernel/ast.dart' show Annotatable, Class, Library, Version;
 import 'package:kernel/reference_from_index.dart';
 
 import '../api_prototype/experimental_flags.dart';
@@ -26,6 +26,7 @@
 import '../base/scope.dart';
 import '../base/uri_offset.dart';
 import '../fragment/fragment.dart';
+import '../kernel/body_builder_context.dart';
 import '../kernel/load_library_builder.dart';
 import '../source/offset_map.dart';
 import '../source/outline_builder.dart';
@@ -222,6 +223,10 @@
       List<SourceCompilationUnit> includedParts,
       Set<Uri> usedParts);
 
+  void buildOutlineExpressions(
+      Annotatable annotatable, BodyBuilderContext bodyBuilderContext,
+      {required bool createFileUriExpression});
+
   /// Reports that [feature] is not enabled, using [charOffset] and
   /// [length] for the location of the message.
   ///
@@ -308,8 +313,6 @@
 }
 
 abstract class LibraryBuilder implements Builder, ProblemReporting {
-  LookupScope get scope;
-
   NameSpace get libraryNameSpace;
 
   NameSpace get exportNameSpace;
diff --git a/pkg/front_end/lib/src/builder/type_builder.dart b/pkg/front_end/lib/src/builder/type_builder.dart
index cdbf4b8..fb82264 100644
--- a/pkg/front_end/lib/src/builder/type_builder.dart
+++ b/pkg/front_end/lib/src/builder/type_builder.dart
@@ -600,9 +600,11 @@
   const PredefinedTypeName(this.name);
 
   @override
+  // Coverage-ignore(suite): Not run.
   String? get qualifier => null;
 
   @override
+  // Coverage-ignore(suite): Not run.
   int get nameOffset => TreeNode.noOffset;
 
   @override
diff --git a/pkg/front_end/lib/src/dill/dill_class_builder.dart b/pkg/front_end/lib/src/dill/dill_class_builder.dart
index ada6e1c..cfd0bc8 100644
--- a/pkg/front_end/lib/src/dill/dill_class_builder.dart
+++ b/pkg/front_end/lib/src/dill/dill_class_builder.dart
@@ -7,7 +7,6 @@
 
 import '../base/loader.dart';
 import '../base/name_space.dart';
-import '../base/scope.dart';
 import '../builder/builder.dart';
 import '../builder/declaration_builders.dart';
 import '../builder/library_builder.dart';
@@ -51,12 +50,8 @@
   @override
   final Class cls;
 
-  late final LookupScope _scope;
-
   final DeclarationNameSpace _nameSpace;
 
-  late final ConstructorScope _constructorScope;
-
   List<NominalParameterBuilder>? _typeParameters;
 
   TypeBuilder? _supertypeBuilder;
@@ -64,13 +59,7 @@
   List<TypeBuilder>? _interfaceBuilders;
 
   DillClassBuilder(this.cls, this.parent)
-      : _nameSpace = new DeclarationNameSpaceImpl() {
-    _scope = new NameSpaceLookupScope(
-        _nameSpace, ScopeKind.declaration, "class ${cls.name}",
-        parent: parent.scope);
-    _constructorScope =
-        new DeclarationNameSpaceConstructorScope(cls.name, _nameSpace);
-  }
+      : _nameSpace = new DeclarationNameSpaceImpl();
 
   @override
   int get fileOffset => cls.fileOffset;
@@ -82,16 +71,9 @@
   Uri get fileUri => cls.fileUri;
 
   @override
-  // Coverage-ignore(suite): Not run.
-  LookupScope get scope => _scope;
-
-  @override
   DeclarationNameSpace get nameSpace => _nameSpace;
 
   @override
-  ConstructorScope get constructorScope => _constructorScope;
-
-  @override
   bool get isEnum => cls.isEnum;
 
   @override
diff --git a/pkg/front_end/lib/src/dill/dill_extension_builder.dart b/pkg/front_end/lib/src/dill/dill_extension_builder.dart
index 6aad377..3e721d4 100644
--- a/pkg/front_end/lib/src/dill/dill_extension_builder.dart
+++ b/pkg/front_end/lib/src/dill/dill_extension_builder.dart
@@ -5,7 +5,6 @@
 import 'package:kernel/ast.dart';
 
 import '../base/name_space.dart';
-import '../base/scope.dart';
 import '../builder/declaration_builders.dart';
 import '../builder/type_builder.dart';
 import 'dill_builder_mixins.dart';
@@ -21,22 +20,13 @@
   @override
   final Extension extension;
 
-  late final LookupScope _scope;
-
   final DeclarationNameSpace _nameSpace;
 
-  late final ConstructorScope _constructorScope;
-
   List<NominalParameterBuilder>? _typeParameters;
   TypeBuilder? _onType;
 
   DillExtensionBuilder(this.extension, this.libraryBuilder)
       : _nameSpace = new DeclarationNameSpaceImpl() {
-    _scope = new NameSpaceLookupScope(
-        _nameSpace, ScopeKind.declaration, "extension ${extension.name}",
-        parent: parent.scope);
-    _constructorScope =
-        new DeclarationNameSpaceConstructorScope(extension.name, _nameSpace);
     for (ExtensionMemberDescriptor descriptor in extension.memberDescriptors) {
       Name name = descriptor.name;
       switch (descriptor.kind) {
@@ -111,17 +101,9 @@
   Uri get fileUri => extension.fileUri;
 
   @override
-  // Coverage-ignore(suite): Not run.
-  LookupScope get scope => _scope;
-
-  @override
   DeclarationNameSpace get nameSpace => _nameSpace;
 
   @override
-  // Coverage-ignore(suite): Not run.
-  ConstructorScope get constructorScope => _constructorScope;
-
-  @override
   List<NominalParameterBuilder>? get typeParameters {
     if (_typeParameters == null && extension.typeParameters.isNotEmpty) {
       _typeParameters = computeTypeParameterBuilders(
diff --git a/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart b/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart
index 45eed1d..23c620e 100644
--- a/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart
+++ b/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart
@@ -5,7 +5,6 @@
 import 'package:kernel/ast.dart';
 
 import '../base/name_space.dart';
-import '../base/scope.dart';
 import '../builder/declaration_builders.dart';
 import '../builder/type_builder.dart';
 import 'dill_builder_mixins.dart';
@@ -22,12 +21,8 @@
 
   final ExtensionTypeDeclaration _extensionTypeDeclaration;
 
-  late final LookupScope _scope;
-
   final DeclarationNameSpace _nameSpace;
 
-  late final ConstructorScope _constructorScope;
-
   List<NominalParameterBuilder>? _typeParameters;
 
   List<TypeBuilder>? _interfaceBuilders;
@@ -37,11 +32,6 @@
   DillExtensionTypeDeclarationBuilder(
       this._extensionTypeDeclaration, this.libraryBuilder)
       : _nameSpace = new DeclarationNameSpaceImpl() {
-    _scope = new NameSpaceLookupScope(_nameSpace, ScopeKind.declaration,
-        "extension type ${_extensionTypeDeclaration.name}",
-        parent: parent.scope);
-    _constructorScope = new DeclarationNameSpaceConstructorScope(
-        _extensionTypeDeclaration.name, _nameSpace);
     for (Procedure procedure in _extensionTypeDeclaration.procedures) {
       String name = procedure.name.text;
       switch (procedure.kind) {
@@ -164,16 +154,9 @@
   DillLibraryBuilder get parent => libraryBuilder;
 
   @override
-  // Coverage-ignore(suite): Not run.
-  LookupScope get scope => _scope;
-
-  @override
   DeclarationNameSpace get nameSpace => _nameSpace;
 
   @override
-  ConstructorScope get constructorScope => _constructorScope;
-
-  @override
   DartType get declaredRepresentationType =>
       _extensionTypeDeclaration.declaredRepresentationType;
 
diff --git a/pkg/front_end/lib/src/dill/dill_library_builder.dart b/pkg/front_end/lib/src/dill/dill_library_builder.dart
index 392de75..32367af 100644
--- a/pkg/front_end/lib/src/dill/dill_library_builder.dart
+++ b/pkg/front_end/lib/src/dill/dill_library_builder.dart
@@ -11,7 +11,6 @@
 import '../base/loader.dart';
 import '../base/name_space.dart';
 import '../base/problems.dart' show internalProblem, unhandled;
-import '../base/scope.dart';
 import '../base/uris.dart';
 import '../builder/builder.dart';
 import '../builder/declaration_builders.dart';
@@ -97,8 +96,6 @@
 }
 
 class DillLibraryBuilder extends LibraryBuilderImpl {
-  late final LookupScope _scope;
-
   late final DillLibraryNameSpace _nameSpace;
 
   late final DillExportNameSpace _exportScope;
@@ -131,14 +128,10 @@
 
   DillLibraryBuilder(this.library, this.loader) : super(library.fileUri) {
     _nameSpace = new DillLibraryNameSpace(this);
-    _scope = new NameSpaceLookupScope(_nameSpace, ScopeKind.library, 'top');
     _exportScope = new DillExportNameSpace(this);
   }
 
   @override
-  LookupScope get scope => _scope;
-
-  @override
   NameSpace get libraryNameSpace => _nameSpace;
 
   @override
diff --git a/pkg/front_end/lib/src/fragment/class.dart b/pkg/front_end/lib/src/fragment/class.dart
index 029487d..cd19cc94 100644
--- a/pkg/front_end/lib/src/fragment/class.dart
+++ b/pkg/front_end/lib/src/fragment/class.dart
@@ -36,6 +36,7 @@
   int get fileOffset => nameOffset;
 
   @override
+  // Coverage-ignore(suite): Not run.
   SourceClassBuilder get builder {
     assert(_builder != null, "Builder has not been computed for $this.");
     return _builder!;
diff --git a/pkg/front_end/lib/src/fragment/class/declaration.dart b/pkg/front_end/lib/src/fragment/class/declaration.dart
index cabbc6f..6d70b9f 100644
--- a/pkg/front_end/lib/src/fragment/class/declaration.dart
+++ b/pkg/front_end/lib/src/fragment/class/declaration.dart
@@ -8,6 +8,7 @@
   String get name;
   List<MetadataBuilder>? get metadata;
   LookupScope get compilationUnitScope;
+  LookupScope get bodyScope;
   Uri get fileUri;
   int get nameOffset;
   int get startOffset;
@@ -18,6 +19,12 @@
   TypeBuilder? get supertype;
   List<TypeBuilder>? get mixedInTypes;
   List<TypeBuilder>? get interfaces;
+
+  void buildOutlineExpressions(
+      {required Annotatable annotatable,
+      required SourceLibraryBuilder libraryBuilder,
+      required BodyBuilderContext bodyBuilderContext,
+      required bool createFileUriExpression});
 }
 
 class RegularClassDeclaration implements ClassDeclaration {
@@ -32,6 +39,9 @@
   LookupScope get compilationUnitScope => _fragment.enclosingScope;
 
   @override
+  LookupScope get bodyScope => _fragment.bodyScope;
+
+  @override
   Uri get fileUri => _fragment.fileUri;
 
   @override
@@ -61,6 +71,22 @@
 
   @override
   List<TypeBuilder>? get interfaces => _fragment.interfaces;
+
+  @override
+  void buildOutlineExpressions(
+      {required Annotatable annotatable,
+      required SourceLibraryBuilder libraryBuilder,
+      required BodyBuilderContext bodyBuilderContext,
+      required bool createFileUriExpression}) {
+    MetadataBuilder.buildAnnotations(
+        annotatable,
+        _fragment.metadata,
+        bodyBuilderContext,
+        libraryBuilder,
+        _fragment.fileUri,
+        _fragment.enclosingScope,
+        createFileUriExpression: createFileUriExpression);
+  }
 }
 
 class EnumDeclaration implements ClassDeclaration {
@@ -72,12 +98,16 @@
   EnumDeclaration(this._fragment, this.supertype);
 
   @override
+  // Coverage-ignore(suite): Not run.
   List<MetadataBuilder>? get metadata => _fragment.metadata;
 
   @override
   LookupScope get compilationUnitScope => _fragment.enclosingScope;
 
   @override
+  LookupScope get bodyScope => _fragment.bodyScope;
+
+  @override
   Uri get fileUri => _fragment.fileUri;
 
   @override
@@ -104,6 +134,22 @@
 
   @override
   List<TypeBuilder>? get interfaces => _fragment.interfaces;
+
+  @override
+  void buildOutlineExpressions(
+      {required Annotatable annotatable,
+      required SourceLibraryBuilder libraryBuilder,
+      required BodyBuilderContext bodyBuilderContext,
+      required bool createFileUriExpression}) {
+    MetadataBuilder.buildAnnotations(
+        annotatable,
+        _fragment.metadata,
+        bodyBuilderContext,
+        libraryBuilder,
+        _fragment.fileUri,
+        _fragment.enclosingScope,
+        createFileUriExpression: createFileUriExpression);
+  }
 }
 
 class NamedMixinApplication implements ClassDeclaration {
@@ -115,12 +161,17 @@
   NamedMixinApplication(this._fragment, this.mixedInTypes);
 
   @override
+  // Coverage-ignore(suite): Not run.
   List<MetadataBuilder>? get metadata => _fragment.metadata;
 
   @override
   LookupScope get compilationUnitScope => _fragment.enclosingScope;
 
   @override
+  // Coverage-ignore(suite): Not run.
+  LookupScope get bodyScope => compilationUnitScope;
+
+  @override
   Uri get fileUri => _fragment.fileUri;
 
   @override
@@ -147,6 +198,22 @@
 
   @override
   List<TypeBuilder>? get interfaces => _fragment.interfaces;
+
+  @override
+  void buildOutlineExpressions(
+      {required Annotatable annotatable,
+      required SourceLibraryBuilder libraryBuilder,
+      required BodyBuilderContext bodyBuilderContext,
+      required bool createFileUriExpression}) {
+    MetadataBuilder.buildAnnotations(
+        annotatable,
+        _fragment.metadata,
+        bodyBuilderContext,
+        libraryBuilder,
+        _fragment.fileUri,
+        _fragment.enclosingScope,
+        createFileUriExpression: createFileUriExpression);
+  }
 }
 
 class AnonymousMixinApplication implements ClassDeclaration {
@@ -195,7 +262,19 @@
       required this.interfaces});
 
   @override
+  // Coverage-ignore(suite): Not run.
+  LookupScope get bodyScope => compilationUnitScope;
+
+  @override
+  // Coverage-ignore(suite): Not run.
   List<MetadataBuilder>? get metadata => null;
+
+  @override
+  void buildOutlineExpressions(
+      {required Annotatable annotatable,
+      required SourceLibraryBuilder libraryBuilder,
+      required BodyBuilderContext bodyBuilderContext,
+      required bool createFileUriExpression}) {}
 }
 
 class MixinDeclaration implements ClassDeclaration {
@@ -204,12 +283,17 @@
   MixinDeclaration(this._fragment);
 
   @override
+  // Coverage-ignore(suite): Not run.
   List<MetadataBuilder>? get metadata => _fragment.metadata;
 
   @override
   LookupScope get compilationUnitScope => _fragment.enclosingScope;
 
   @override
+  // Coverage-ignore(suite): Not run.
+  LookupScope get bodyScope => _fragment.bodyScope;
+
+  @override
   Uri get fileUri => _fragment.fileUri;
 
   @override
@@ -239,4 +323,20 @@
 
   @override
   List<TypeBuilder>? get interfaces => _fragment.interfaces;
+
+  @override
+  void buildOutlineExpressions(
+      {required Annotatable annotatable,
+      required SourceLibraryBuilder libraryBuilder,
+      required BodyBuilderContext bodyBuilderContext,
+      required bool createFileUriExpression}) {
+    MetadataBuilder.buildAnnotations(
+        annotatable,
+        _fragment.metadata,
+        bodyBuilderContext,
+        libraryBuilder,
+        _fragment.fileUri,
+        _fragment.enclosingScope,
+        createFileUriExpression: createFileUriExpression);
+  }
 }
diff --git a/pkg/front_end/lib/src/fragment/constructor/declaration.dart b/pkg/front_end/lib/src/fragment/constructor/declaration.dart
index f0e51ea..862d38f 100644
--- a/pkg/front_end/lib/src/fragment/constructor/declaration.dart
+++ b/pkg/front_end/lib/src/fragment/constructor/declaration.dart
@@ -3,12 +3,15 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:kernel/ast.dart';
+import 'package:kernel/class_hierarchy.dart';
 import 'package:kernel/type_algebra.dart';
 
+import '../../base/scope.dart';
 import '../../builder/declaration_builders.dart';
 import '../../builder/formal_parameter_builder.dart';
 import '../../builder/metadata_builder.dart';
 import '../../builder/type_builder.dart';
+import '../../kernel/body_builder_context.dart';
 import '../../kernel/internal_ast.dart';
 import '../../kernel/kernel_helper.dart';
 import '../../source/name_scheme.dart';
@@ -29,6 +32,8 @@
 
   List<FormalParameterBuilder>? get formals;
 
+  LookupScope get typeParameterScope;
+
   Member get constructor;
 
   Procedure? get tearOff;
@@ -53,12 +58,13 @@
 
   List<Initializer> get initializers;
 
-  void createNode(
-      {required String name,
-      required SourceLibraryBuilder libraryBuilder,
-      required NameScheme nameScheme,
-      required Reference? constructorReference,
-      required Reference? tearOffReference});
+  void createNode({
+    required String name,
+    required SourceLibraryBuilder libraryBuilder,
+    required NameScheme nameScheme,
+    required Reference? constructorReference,
+    required Reference? tearOffReference,
+  });
 
   void buildOutlineNodes(
     BuildNodesCallback f, {
@@ -68,6 +74,15 @@
     required List<DelayedDefaultValueCloner> delayedDefaultValueCloners,
   });
 
+  void buildOutlineExpressions({
+    required Iterable<Annotatable> annotatables,
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required bool createFileUriExpression,
+  });
+
   void prepareInitializers();
 
   void prependInitializer(Initializer initializer);
@@ -206,6 +221,32 @@
         namedSuperParameters: namedSuperParameters,
         libraryBuilder: libraryBuilder);
   }
+
+  void _buildTypeParametersAndFormals({
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required LookupScope typeParameterScope,
+  }) {
+    if (typeParameters != null) {
+      for (int i = 0; i < typeParameters!.length; i++) {
+        typeParameters![i].buildOutlineExpressions(libraryBuilder,
+            bodyBuilderContext, classHierarchy, typeParameterScope);
+      }
+    }
+
+    if (formals != null) {
+      // For const constructors we need to include default parameter values
+      // into the outline. For all other formals we need to call
+      // buildOutlineExpressions to clear initializerToken to prevent
+      // consuming too much memory.
+      for (FormalParameterBuilder formal in formals!) {
+        formal.buildOutlineExpressions(libraryBuilder, declarationBuilder,
+            scope: typeParameterScope, buildDefaultValue: true);
+      }
+    }
+  }
 }
 
 class RegularConstructorDeclaration
@@ -228,6 +269,9 @@
             isExternal: _fragment.modifiers.isExternal);
 
   @override
+  LookupScope get typeParameterScope => _fragment.typeParameterScope;
+
+  @override
   List<MetadataBuilder>? get metadata => _fragment.metadata;
 
   @override
@@ -278,6 +322,33 @@
         formals: formals,
         delayedDefaultValueCloners: delayedDefaultValueCloners);
   }
+
+  @override
+  void buildOutlineExpressions({
+    required Iterable<Annotatable> annotatables,
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required bool createFileUriExpression,
+  }) {
+    for (Annotatable annotatable in annotatables) {
+      MetadataBuilder.buildAnnotations(
+          annotatable,
+          _fragment.metadata,
+          bodyBuilderContext,
+          libraryBuilder,
+          _fragment.fileUri,
+          _fragment.enclosingScope,
+          createFileUriExpression: createFileUriExpression);
+    }
+    _buildTypeParametersAndFormals(
+        libraryBuilder: libraryBuilder,
+        declarationBuilder: declarationBuilder,
+        bodyBuilderContext: bodyBuilderContext,
+        classHierarchy: classHierarchy,
+        typeParameterScope: _fragment.typeParameterScope);
+  }
 }
 
 // Coverage-ignore(suite): Not run.
@@ -292,6 +363,8 @@
   PrimaryConstructorDeclaration(this._fragment)
       : _encoding = new RegularConstructorEncoding(
             isExternal: _fragment.modifiers.isExternal);
+  @override
+  LookupScope get typeParameterScope => _fragment.typeParameterScope;
 
   @override
   OmittedTypeBuilder get returnType => _fragment.returnType;
@@ -346,6 +419,24 @@
         formals: formals,
         delayedDefaultValueCloners: delayedDefaultValueCloners);
   }
+
+  @override
+  void buildOutlineExpressions({
+    required Iterable<Annotatable> annotatables,
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required bool createFileUriExpression,
+  }) {
+    // There is no metadata on a primary constructor.
+    _buildTypeParametersAndFormals(
+        libraryBuilder: libraryBuilder,
+        declarationBuilder: declarationBuilder,
+        bodyBuilderContext: bodyBuilderContext,
+        classHierarchy: classHierarchy,
+        typeParameterScope: _fragment.typeParameterScope);
+  }
 }
 
 class DefaultEnumConstructorDeclaration
@@ -364,15 +455,24 @@
   final RegularConstructorEncoding _encoding =
       new RegularConstructorEncoding(isExternal: false);
 
+  /// The scope in which to build the formal parameters.
+  final LookupScope _lookupScope;
+
   DefaultEnumConstructorDeclaration(
       {required this.returnType,
       required this.formals,
       required Uri fileUri,
-      required int fileOffset})
+      required int fileOffset,
+      required LookupScope lookupScope})
       : _fileUri = fileUri,
-        _fileOffset = fileOffset;
+        _fileOffset = fileOffset,
+        _lookupScope = lookupScope;
 
   @override
+  LookupScope get typeParameterScope => _lookupScope;
+
+  @override
+  // Coverage-ignore(suite): Not run.
   List<MetadataBuilder>? get metadata => null;
 
   @override
@@ -418,6 +518,24 @@
         formals: formals,
         delayedDefaultValueCloners: delayedDefaultValueCloners);
   }
+
+  @override
+  void buildOutlineExpressions({
+    required Iterable<Annotatable> annotatables,
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required bool createFileUriExpression,
+  }) {
+    // There is no metadata on a default enum constructor.
+    _buildTypeParametersAndFormals(
+        libraryBuilder: libraryBuilder,
+        declarationBuilder: declarationBuilder,
+        bodyBuilderContext: bodyBuilderContext,
+        classHierarchy: classHierarchy,
+        typeParameterScope: _lookupScope);
+  }
 }
 
 mixin ExtensionTypeConstructorDeclarationMixin
@@ -541,6 +659,32 @@
     throw new UnsupportedError(
         '$runtimeType.addSuperParameterDefaultValueCloners');
   }
+
+  void _buildTypeParametersAndFormals({
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required LookupScope typeParameterScope,
+  }) {
+    if (typeParameters != null) {
+      for (int i = 0; i < typeParameters!.length; i++) {
+        typeParameters![i].buildOutlineExpressions(libraryBuilder,
+            bodyBuilderContext, classHierarchy, typeParameterScope);
+      }
+    }
+
+    if (formals != null) {
+      // For const constructors we need to include default parameter values
+      // into the outline. For all other formals we need to call
+      // buildOutlineExpressions to clear initializerToken to prevent
+      // consuming too much memory.
+      for (FormalParameterBuilder formal in formals!) {
+        formal.buildOutlineExpressions(libraryBuilder, declarationBuilder,
+            scope: typeParameterScope, buildDefaultValue: true);
+      }
+    }
+  }
 }
 
 class ExtensionTypeConstructorDeclaration
@@ -558,8 +702,11 @@
       {required this.typeParameters})
       : _encoding = new ExtensionTypeConstructorEncoding(
             isExternal: _fragment.modifiers.isExternal);
+  @override
+  LookupScope get typeParameterScope => _fragment.typeParameterScope;
 
   @override
+  // Coverage-ignore(suite): Not run.
   List<MetadataBuilder>? get metadata => _fragment.metadata;
 
   @override
@@ -607,6 +754,33 @@
         formals: formals,
         delayedDefaultValueCloners: delayedDefaultValueCloners);
   }
+
+  @override
+  void buildOutlineExpressions({
+    required Iterable<Annotatable> annotatables,
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required bool createFileUriExpression,
+  }) {
+    for (Annotatable annotatable in annotatables) {
+      MetadataBuilder.buildAnnotations(
+          annotatable,
+          _fragment.metadata,
+          bodyBuilderContext,
+          libraryBuilder,
+          _fragment.fileUri,
+          _fragment.enclosingScope,
+          createFileUriExpression: createFileUriExpression);
+    }
+    _buildTypeParametersAndFormals(
+        libraryBuilder: libraryBuilder,
+        declarationBuilder: declarationBuilder,
+        bodyBuilderContext: bodyBuilderContext,
+        classHierarchy: classHierarchy,
+        typeParameterScope: _fragment.typeParameterScope);
+  }
 }
 
 class ExtensionTypePrimaryConstructorDeclaration
@@ -624,8 +798,11 @@
       {required this.typeParameters})
       : _encoding = new ExtensionTypeConstructorEncoding(
             isExternal: _fragment.modifiers.isExternal);
+  @override
+  LookupScope get typeParameterScope => _fragment.typeParameterScope;
 
   @override
+  // Coverage-ignore(suite): Not run.
   List<MetadataBuilder>? get metadata => null;
 
   @override
@@ -674,4 +851,22 @@
         formals: formals,
         delayedDefaultValueCloners: delayedDefaultValueCloners);
   }
+
+  @override
+  void buildOutlineExpressions({
+    required Iterable<Annotatable> annotatables,
+    required SourceLibraryBuilder libraryBuilder,
+    required DeclarationBuilder declarationBuilder,
+    required BodyBuilderContext bodyBuilderContext,
+    required ClassHierarchy classHierarchy,
+    required bool createFileUriExpression,
+  }) {
+    // There is no metadata on a primary constructor.
+    _buildTypeParametersAndFormals(
+        libraryBuilder: libraryBuilder,
+        declarationBuilder: declarationBuilder,
+        bodyBuilderContext: bodyBuilderContext,
+        classHierarchy: classHierarchy,
+        typeParameterScope: _fragment.typeParameterScope);
+  }
 }
diff --git a/pkg/front_end/lib/src/fragment/enum.dart b/pkg/front_end/lib/src/fragment/enum.dart
index a72b56b..c9aed08 100644
--- a/pkg/front_end/lib/src/fragment/enum.dart
+++ b/pkg/front_end/lib/src/fragment/enum.dart
@@ -38,6 +38,7 @@
   int get fileOffset => nameOffset;
 
   @override
+  // Coverage-ignore(suite): Not run.
   SourceEnumBuilder get builder {
     assert(_builder != null, "Builder has not been computed for $this.");
     return _builder!;
diff --git a/pkg/front_end/lib/src/fragment/enum_element.dart b/pkg/front_end/lib/src/fragment/enum_element.dart
index 45e569e..8aac616 100644
--- a/pkg/front_end/lib/src/fragment/enum_element.dart
+++ b/pkg/front_end/lib/src/fragment/enum_element.dart
@@ -128,13 +128,12 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       List<Annotatable> annotatables,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
     BodyBuilderContext bodyBuilderContext = createBodyBuilderContext();
     for (Annotatable annotatable in annotatables) {
-      _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
+      _buildMetadataForOutlineExpressions(libraryBuilder, enclosingScope,
           bodyBuilderContext, annotatable, metadata,
           fileUri: fileUri, createFileUriExpression: createFileUriExpression);
     }
@@ -212,7 +211,7 @@
           .createBodyBuilderForOutlineExpression(
               libraryBuilder,
               sourceEnumBuilder.createBodyBuilderContext(),
-              sourceEnumBuilder.scope,
+              enclosingScope,
               fileUri);
       bodyBuilder.constantContext = ConstantContext.inferred;
 
diff --git a/pkg/front_end/lib/src/fragment/extension.dart b/pkg/front_end/lib/src/fragment/extension.dart
index 6148f87..fd44ffc 100644
--- a/pkg/front_end/lib/src/fragment/extension.dart
+++ b/pkg/front_end/lib/src/fragment/extension.dart
@@ -35,6 +35,7 @@
   bool get isUnnamed => extensionName.isUnnamedExtension;
 
   @override
+  // Coverage-ignore(suite): Not run.
   SourceExtensionBuilder get builder {
     assert(_builder != null, "Builder has not been computed for $this.");
     return _builder!;
diff --git a/pkg/front_end/lib/src/fragment/extension_type.dart b/pkg/front_end/lib/src/fragment/extension_type.dart
index 1b9d3ed..8f97449 100644
--- a/pkg/front_end/lib/src/fragment/extension_type.dart
+++ b/pkg/front_end/lib/src/fragment/extension_type.dart
@@ -36,6 +36,7 @@
   int get fileOffset => nameOffset;
 
   @override
+  // Coverage-ignore(suite): Not run.
   SourceExtensionTypeDeclarationBuilder get builder {
     assert(_builder != null, "Builder has not been computed for $this.");
     return _builder!;
diff --git a/pkg/front_end/lib/src/fragment/field.dart b/pkg/front_end/lib/src/fragment/field.dart
index cb56950..0720d75 100644
--- a/pkg/front_end/lib/src/fragment/field.dart
+++ b/pkg/front_end/lib/src/fragment/field.dart
@@ -218,7 +218,7 @@
               .thisInterfaceType(
                   declarationBuilder.cls, libraryBuilder.library.nonNullable)
           : null;
-      LookupScope scope = declarationBuilder?.scope ?? libraryBuilder.scope;
+      LookupScope scope = enclosingScope;
       TypeInferrer typeInferrer =
           libraryBuilder.loader.typeInferenceEngine.createTopLevelTypeInferrer(
               fileUri,
@@ -293,13 +293,12 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       List<Annotatable> annotatables,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
     BodyBuilderContext bodyBuilderContext = createBodyBuilderContext();
     for (Annotatable annotatable in annotatables) {
-      _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
+      _buildMetadataForOutlineExpressions(libraryBuilder, enclosingScope,
           bodyBuilderContext, annotatable, metadata,
           fileUri: fileUri, createFileUriExpression: createFileUriExpression);
     }
@@ -313,7 +312,7 @@
                 (declarationBuilder as SourceClassBuilder)
                     .declaresConstConstructor)) &&
         token != null) {
-      LookupScope scope = declarationBuilder?.scope ?? libraryBuilder.scope;
+      LookupScope scope = enclosingScope;
       BodyBuilder bodyBuilder = libraryBuilder.loader
           .createBodyBuilderForOutlineExpression(
               libraryBuilder, createBodyBuilderContext(), scope, fileUri);
diff --git a/pkg/front_end/lib/src/fragment/getter.dart b/pkg/front_end/lib/src/fragment/getter.dart
index 3ab6a96..cc5f145 100644
--- a/pkg/front_end/lib/src/fragment/getter.dart
+++ b/pkg/front_end/lib/src/fragment/getter.dart
@@ -123,17 +123,11 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _encoding.buildOutlineExpressions(
-        classHierarchy,
-        libraryBuilder,
-        declarationBuilder,
-        parentScope,
-        createBodyBuilderContext(),
-        annotatable,
+    _encoding.buildOutlineExpressions(classHierarchy, libraryBuilder,
+        declarationBuilder, createBodyBuilderContext(), annotatable,
         isClassInstanceMember: isClassInstanceMember,
         createFileUriExpression: createFileUriExpression);
   }
@@ -257,7 +251,6 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
@@ -354,13 +347,16 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
-        bodyBuilderContext, annotatable, _fragment.metadata,
+    _buildMetadataForOutlineExpressions(
+        libraryBuilder,
+        _fragment.enclosingScope,
+        bodyBuilderContext,
+        annotatable,
+        _fragment.metadata,
         fileUri: _fragment.fileUri,
         createFileUriExpression: createFileUriExpression);
     _buildTypeParametersForOutlineExpressions(
@@ -374,6 +370,7 @@
             ?.builders);
     _buildFormalsForOutlineExpressions(
         libraryBuilder, declarationBuilder, _fragment.declaredFormals,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
   }
 
@@ -616,13 +613,16 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
-        bodyBuilderContext, annotatable, _fragment.metadata,
+    _buildMetadataForOutlineExpressions(
+        libraryBuilder,
+        _fragment.enclosingScope,
+        bodyBuilderContext,
+        annotatable,
+        _fragment.metadata,
         fileUri: _fragment.fileUri,
         createFileUriExpression: createFileUriExpression);
 
@@ -637,6 +637,7 @@
             ?.builders);
     _buildFormalsForOutlineExpressions(
         libraryBuilder, declarationBuilder, _fragment.declaredFormals,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
 
     _buildTypeParametersForOutlineExpressions(
@@ -647,6 +648,7 @@
         _clonedDeclarationTypeParameters);
     _buildFormalForOutlineExpressions(
         libraryBuilder, declarationBuilder, _thisFormal,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
   }
 
diff --git a/pkg/front_end/lib/src/fragment/method.dart b/pkg/front_end/lib/src/fragment/method.dart
index 5db47f1..b065940 100644
--- a/pkg/front_end/lib/src/fragment/method.dart
+++ b/pkg/front_end/lib/src/fragment/method.dart
@@ -124,17 +124,11 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _encoding.buildOutlineExpressions(
-        classHierarchy,
-        libraryBuilder,
-        declarationBuilder,
-        parentScope,
-        createBodyBuilderContext(),
-        annotatable,
+    _encoding.buildOutlineExpressions(classHierarchy, libraryBuilder,
+        declarationBuilder, createBodyBuilderContext(), annotatable,
         isClassInstanceMember: isClassInstanceMember,
         createFileUriExpression: createFileUriExpression);
   }
@@ -369,7 +363,6 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
@@ -465,13 +458,16 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
-        bodyBuilderContext, annotatable, _fragment.metadata,
+    _buildMetadataForOutlineExpressions(
+        libraryBuilder,
+        _fragment.enclosingScope,
+        bodyBuilderContext,
+        annotatable,
+        _fragment.metadata,
         fileUri: _fragment.fileUri,
         createFileUriExpression: createFileUriExpression);
     _buildTypeParametersForOutlineExpressions(
@@ -482,6 +478,7 @@
         _fragment.declaredTypeParameters);
     _buildFormalsForOutlineExpressions(
         libraryBuilder, declarationBuilder, _fragment.declaredFormals,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
   }
 
@@ -959,13 +956,16 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
-        bodyBuilderContext, annotatable, _fragment.metadata,
+    _buildMetadataForOutlineExpressions(
+        libraryBuilder,
+        _fragment.enclosingScope,
+        bodyBuilderContext,
+        annotatable,
+        _fragment.metadata,
         fileUri: _fragment.fileUri,
         createFileUriExpression: createFileUriExpression);
 
@@ -977,6 +977,7 @@
         _fragment.declaredTypeParameters);
     _buildFormalsForOutlineExpressions(
         libraryBuilder, declarationBuilder, _fragment.declaredFormals,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
 
     _buildTypeParametersForOutlineExpressions(
@@ -987,6 +988,7 @@
         _clonedDeclarationTypeParameters);
     _buildFormalForOutlineExpressions(
         libraryBuilder, declarationBuilder, _thisFormal,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
   }
 
diff --git a/pkg/front_end/lib/src/fragment/mixin.dart b/pkg/front_end/lib/src/fragment/mixin.dart
index b82c3a1..d4f61ee 100644
--- a/pkg/front_end/lib/src/fragment/mixin.dart
+++ b/pkg/front_end/lib/src/fragment/mixin.dart
@@ -36,6 +36,7 @@
   int get fileOffset => nameOffset;
 
   @override
+  // Coverage-ignore(suite): Not run.
   SourceClassBuilder get builder {
     assert(_builder != null, "Builder has not been computed for $this.");
     return _builder!;
diff --git a/pkg/front_end/lib/src/fragment/setter.dart b/pkg/front_end/lib/src/fragment/setter.dart
index b0cb6cd..9390254 100644
--- a/pkg/front_end/lib/src/fragment/setter.dart
+++ b/pkg/front_end/lib/src/fragment/setter.dart
@@ -115,17 +115,11 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _encoding.buildOutlineExpressions(
-        classHierarchy,
-        libraryBuilder,
-        declarationBuilder,
-        parentScope,
-        createBodyBuilderContext(),
-        annotatable,
+    _encoding.buildOutlineExpressions(classHierarchy, libraryBuilder,
+        declarationBuilder, createBodyBuilderContext(), annotatable,
         isClassInstanceMember: isClassInstanceMember,
         createFileUriExpression: createFileUriExpression);
   }
@@ -254,7 +248,6 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
@@ -390,13 +383,16 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
-        bodyBuilderContext, annotatable, _fragment.metadata,
+    _buildMetadataForOutlineExpressions(
+        libraryBuilder,
+        _fragment.enclosingScope,
+        bodyBuilderContext,
+        annotatable,
+        _fragment.metadata,
         fileUri: _fragment.fileUri,
         createFileUriExpression: createFileUriExpression);
 
@@ -411,6 +407,7 @@
             ?.builders);
     _buildFormalsForOutlineExpressions(
         libraryBuilder, declarationBuilder, _fragment.declaredFormals,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
   }
 
@@ -657,13 +654,16 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       BodyBuilderContext bodyBuilderContext,
       Annotatable annotatable,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
-    _buildMetadataForOutlineExpressions(libraryBuilder, parentScope,
-        bodyBuilderContext, annotatable, _fragment.metadata,
+    _buildMetadataForOutlineExpressions(
+        libraryBuilder,
+        _fragment.enclosingScope,
+        bodyBuilderContext,
+        annotatable,
+        _fragment.metadata,
         fileUri: _fragment.fileUri,
         createFileUriExpression: createFileUriExpression);
 
@@ -678,6 +678,7 @@
             ?.builders);
     _buildFormalsForOutlineExpressions(
         libraryBuilder, declarationBuilder, _fragment.declaredFormals,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
 
     _buildTypeParametersForOutlineExpressions(
@@ -688,6 +689,7 @@
         _clonedDeclarationTypeParameters);
     _buildFormalForOutlineExpressions(
         libraryBuilder, declarationBuilder, _thisFormal,
+        scope: _fragment.typeParameterScope,
         isClassInstanceMember: isClassInstanceMember);
   }
 
diff --git a/pkg/front_end/lib/src/fragment/util.dart b/pkg/front_end/lib/src/fragment/util.dart
index 372b351..2ac045b 100644
--- a/pkg/front_end/lib/src/fragment/util.dart
+++ b/pkg/front_end/lib/src/fragment/util.dart
@@ -76,25 +76,26 @@
     SourceLibraryBuilder libraryBuilder,
     DeclarationBuilder? declarationBuilder,
     List<FormalParameterBuilder>? formals,
-    {required bool isClassInstanceMember}) {
+    {required LookupScope scope,
+    required bool isClassInstanceMember}) {
   if (formals != null) {
     for (FormalParameterBuilder formal in formals) {
       _buildFormalForOutlineExpressions(
           libraryBuilder, declarationBuilder, formal,
-          isClassInstanceMember: isClassInstanceMember);
+          scope: scope, isClassInstanceMember: isClassInstanceMember);
     }
   }
 }
 
 void _buildFormalForOutlineExpressions(SourceLibraryBuilder libraryBuilder,
     DeclarationBuilder? declarationBuilder, FormalParameterBuilder formal,
-    {required bool isClassInstanceMember}) {
+    {required LookupScope scope, required bool isClassInstanceMember}) {
   // For const constructors we need to include default parameter values
   // into the outline. For all other formals we need to call
   // buildOutlineExpressions to clear initializerToken to prevent
   // consuming too much memory.
   formal.buildOutlineExpressions(libraryBuilder, declarationBuilder,
-      buildDefaultValue: isClassInstanceMember);
+      scope: scope, buildDefaultValue: isClassInstanceMember);
 }
 
 /// Common interface for fragments that can declare a field.
@@ -112,7 +113,6 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       List<Annotatable> annotatables,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression});
diff --git a/pkg/front_end/lib/src/kernel/body_builder_context.dart b/pkg/front_end/lib/src/kernel/body_builder_context.dart
index 42d0993..5d3459b 100644
--- a/pkg/front_end/lib/src/kernel/body_builder_context.dart
+++ b/pkg/front_end/lib/src/kernel/body_builder_context.dart
@@ -925,9 +925,12 @@
   final Procedure _procedure;
 
   ExpressionCompilerProcedureBodyBuildContext(
-      DietListener listener, this._procedure,
+      DietListener listener,
+      this._procedure,
+      SourceLibraryBuilder libraryBuilder,
+      DeclarationBuilder? declarationBuilder,
       {required bool isDeclarationInstanceMember})
-      : super(listener.libraryBuilder, listener.currentDeclaration,
+      : super(libraryBuilder, declarationBuilder,
             isDeclarationInstanceMember: isDeclarationInstanceMember);
 
   @override
diff --git a/pkg/front_end/lib/src/kernel/kernel_target.dart b/pkg/front_end/lib/src/kernel/kernel_target.dart
index 7df0adb..5c2b46f 100644
--- a/pkg/front_end/lib/src/kernel/kernel_target.dart
+++ b/pkg/front_end/lib/src/kernel/kernel_target.dart
@@ -80,6 +80,7 @@
 import 'dynamic_module_validator.dart' as dynamic_module_validator;
 import 'kernel_constants.dart' show KernelConstantErrorReporter;
 import 'kernel_helper.dart';
+import 'utils.dart';
 
 class KernelTarget {
   final Ticker ticker;
@@ -1240,25 +1241,16 @@
         enclosingClass.enclosingLibrary.nonNullable, typeParameterTypes);
   }
 
-  void _bindCoreType(NamedTypeBuilder typeBuilder, {bool isNullClass = false}) {
-    TypeDeclarationBuilder typeDeclarationBuilder = loader.coreLibrary
-            .lookupLocalMember(typeBuilder.typeName.name, required: true)
-        as TypeDeclarationBuilder;
-    typeBuilder.bind(loader.coreLibrary, typeDeclarationBuilder);
-    if (isNullClass) {
-      (typeDeclarationBuilder as ClassBuilder).isNullClass = true;
-    }
-  }
-
   void setupTopAndBottomTypes() {
-    _bindCoreType(objectType);
-    _bindCoreType(stringType);
-    _bindCoreType(intType);
-    _bindCoreType(dynamicType);
-    _bindCoreType(nullType, isNullClass: true);
-    _bindCoreType(bottomType);
-    _bindCoreType(enumType);
-    _bindCoreType(underscoreEnumType);
+    LibraryBuilder coreLibrary = loader.coreLibrary;
+    bindCoreType(coreLibrary, objectType);
+    bindCoreType(coreLibrary, stringType);
+    bindCoreType(coreLibrary, intType);
+    bindCoreType(coreLibrary, dynamicType);
+    bindCoreType(coreLibrary, nullType, isNullClass: true);
+    bindCoreType(coreLibrary, bottomType);
+    bindCoreType(coreLibrary, enumType);
+    bindCoreType(coreLibrary, underscoreEnumType);
   }
 
   void computeCoreTypes() {
diff --git a/pkg/front_end/lib/src/kernel/macro/metadata.dart b/pkg/front_end/lib/src/kernel/macro/metadata.dart
index aa24c73..5382efc 100644
--- a/pkg/front_end/lib/src/kernel/macro/metadata.dart
+++ b/pkg/front_end/lib/src/kernel/macro/metadata.dart
@@ -193,10 +193,7 @@
   @override
   shared.Proto lookup(String name,
       [List<shared.TypeAnnotation>? typeArguments]) {
-    int fileOffset = -1;
-    Uri fileUri = dummyUri;
-    MemberBuilder? constructor =
-        builder.constructorScope.lookup(name, fileOffset, fileUri);
+    MemberBuilder? constructor = builder.nameSpace.lookupConstructor(name);
     if (constructor != null) {
       return createConstructorProto(
           typeArguments, new ConstructorReference(constructor));
@@ -265,10 +262,7 @@
   @override
   shared.Proto lookup(String name,
       [List<shared.TypeAnnotation>? typeArguments]) {
-    int fileOffset = -1;
-    Uri fileUri = dummyUri;
-    MemberBuilder? constructor =
-        builder.constructorScope.lookup(name, fileOffset, fileUri);
+    MemberBuilder? constructor = builder.nameSpace.lookupConstructor(name);
     if (constructor != null) {
       return createConstructorProto(
           typeArguments, new ConstructorReference(constructor));
@@ -290,12 +284,10 @@
   @override
   shared.Proto lookup(String name,
       [List<shared.TypeAnnotation>? typeArguments]) {
-    int fileOffset = -1;
-    Uri fileUri = dummyUri;
     TypeDeclarationBuilder? typeDeclaration = builder.unaliasDeclaration(null);
     if (typeDeclaration is ClassBuilder) {
       MemberBuilder? constructor =
-          typeDeclaration.constructorScope.lookup(name, fileOffset, fileUri);
+          typeDeclaration.nameSpace.lookupConstructor(name);
       if (constructor != null) {
         return createConstructorProto(
             typeArguments, new ConstructorReference(constructor));
diff --git a/pkg/front_end/lib/src/kernel/utils.dart b/pkg/front_end/lib/src/kernel/utils.dart
index b25cd7f..1d98887 100644
--- a/pkg/front_end/lib/src/kernel/utils.dart
+++ b/pkg/front_end/lib/src/kernel/utils.dart
@@ -21,6 +21,7 @@
 import '../builder/declaration_builders.dart';
 import '../builder/fixed_type_builder.dart';
 import '../builder/formal_parameter_builder.dart';
+import '../builder/library_builder.dart';
 import '../builder/metadata_builder.dart';
 import '../builder/omitted_type_builder.dart';
 import '../builder/record_type_builder.dart';
@@ -71,6 +72,17 @@
   }
 }
 
+void bindCoreType(LibraryBuilder coreLibrary, NamedTypeBuilder typeBuilder,
+    {bool isNullClass = false}) {
+  TypeDeclarationBuilder typeDeclarationBuilder =
+      coreLibrary.lookupLocalMember(typeBuilder.typeName.name, required: true)
+          as TypeDeclarationBuilder;
+  typeBuilder.bind(coreLibrary, typeDeclarationBuilder);
+  if (isNullClass) {
+    (typeDeclarationBuilder as ClassBuilder).isNullClass = true;
+  }
+}
+
 // Coverage-ignore(suite): Not run.
 /// Print the given [component].  Do nothing if it is `null`.  If the
 /// [libraryFilter] is provided, then only libraries that satisfy it are
diff --git a/pkg/front_end/lib/src/source/class_declaration.dart b/pkg/front_end/lib/src/source/class_declaration.dart
index a6c7dcd..97e8d7b 100644
--- a/pkg/front_end/lib/src/source/class_declaration.dart
+++ b/pkg/front_end/lib/src/source/class_declaration.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import '../base/problems.dart';
+import '../base/scope.dart';
 import '../builder/builder.dart';
 import '../builder/constructor_reference_builder.dart';
 import '../builder/declaration_builders.dart';
@@ -85,11 +86,13 @@
 mixin ClassDeclarationBuilderMixin implements ClassDeclarationBuilder {
   List<ConstructorReferenceBuilder>? get constructorReferences;
 
+  LookupScope get bodyScope;
+
   @override
   int resolveConstructors(SourceLibraryBuilder library) {
     if (constructorReferences == null) return 0;
     for (ConstructorReferenceBuilder ref in constructorReferences!) {
-      ref.resolveIn(scope, library);
+      ref.resolveIn(bodyScope, library);
     }
     int count = constructorReferences!.length;
     if (count != 0) {
diff --git a/pkg/front_end/lib/src/source/diet_listener.dart b/pkg/front_end/lib/src/source/diet_listener.dart
index 6bd7960..ea3ec33 100644
--- a/pkg/front_end/lib/src/source/diet_listener.dart
+++ b/pkg/front_end/lib/src/source/diet_listener.dart
@@ -32,7 +32,6 @@
 import '../base/local_scope.dart';
 import '../base/problems.dart' show DebugAbort;
 import '../base/scope.dart';
-import '../builder/declaration_builders.dart';
 import '../codes/cfe_codes.dart'
     show Code, LocatedMessage, Message, messageExpectedBlockToSkip;
 import '../fragment/fragment.dart';
@@ -47,10 +46,18 @@
 import 'offset_map.dart';
 import 'source_library_builder.dart' show SourceLibraryBuilder;
 import 'stack_listener_impl.dart';
+import 'type_parameter_scope_builder.dart';
 
 class DietListener extends StackListenerImpl {
   final SourceLibraryBuilder libraryBuilder;
 
+  /// The outermost scope used by this listener.
+  ///
+  /// Normally this is the compilation unit scope for the compilation unit being
+  /// parsed, but for expression evaluate it can be the body scope of the
+  /// declaration in which the expression should be evaluated.
+  final LookupScope outermostScope;
+
   final ClassHierarchy hierarchy;
 
   final CoreTypes coreTypes;
@@ -59,14 +66,13 @@
 
   final TypeInferenceEngine typeInferenceEngine;
 
-  DeclarationBuilder? _currentDeclaration;
   bool _inRedirectingFactory = false;
 
   bool currentClassIsParserRecovery = false;
 
   /// For top-level declarations, this is the library scope. For class members,
   /// this is the instance scope of [currentDeclaration].
-  LookupScope memberScope;
+  LookupScope _memberScope;
 
   @override
   final Uri uri;
@@ -75,11 +81,11 @@
 
   final OffsetMap _offsetMap;
 
-  DietListener(SourceLibraryBuilder library, this.hierarchy, this.coreTypes,
-      this.typeInferenceEngine, this._offsetMap)
+  DietListener(SourceLibraryBuilder library, this.outermostScope,
+      this.hierarchy, this.coreTypes, this.typeInferenceEngine, this._offsetMap)
       : libraryBuilder = library,
         uri = _offsetMap.uri,
-        memberScope = library.scope,
+        _memberScope = outermostScope,
         enableNative =
             library.loader.target.backendTarget.enableNative(library.importUri),
         _benchmarker = library.loader.target.benchmarker;
@@ -99,16 +105,6 @@
         feature, uri, charOffset, length);
   }
 
-  DeclarationBuilder? get currentDeclaration => _currentDeclaration;
-
-  void set currentDeclaration(DeclarationBuilder? builder) {
-    if (builder == null) {
-      _currentDeclaration = null;
-    } else {
-      _currentDeclaration = builder;
-    }
-  }
-
   @override
   void endMetadataStar(int count) {
     assert(checkState(null, repeatedKind(ValueKinds.Token, count)));
@@ -823,10 +819,12 @@
     // member, since that provides better error recovery.
     // TODO(johnniwinther): Provide a dummy this on static extension methods
     // for better error recovery?
-    InterfaceType? thisType =
-        thisVariable == null ? currentDeclaration?.thisType : null;
     TypeInferrer typeInferrer = typeInferenceEngine.createLocalTypeInferrer(
-        uri, thisType, libraryBuilder, memberScope, inferenceDataForTesting);
+        uri,
+        bodyBuilderContext.thisType,
+        libraryBuilder,
+        memberScope,
+        inferenceDataForTesting);
     ConstantContext constantContext = bodyBuilderContext.constantContext;
     BodyBuilder result = createListenerInternal(
         bodyBuilderContext,
@@ -937,7 +935,7 @@
     // for type inference.
     _parseFields(
         _offsetMap,
-        createListener(fragment.createBodyBuilderContext(), memberScope,
+        createListener(fragment.createBodyBuilderContext(), _memberScope,
             inferenceDataForTesting: fragment
                 .builder
                 .dataForTesting
@@ -983,28 +981,27 @@
     Token beginToken = pop() as Token;
     Object? name = pop();
     pop(); // Annotation begin token.
-    assert(currentDeclaration == null);
-    assert(memberScope == libraryBuilder.scope);
+    assert(_memberScope == outermostScope);
     if (name is ParserRecovery) {
       // Coverage-ignore-block(suite): Not run.
       currentClassIsParserRecovery = true;
       return;
     }
+    DeclarationFragmentImpl currentDeclaration;
     if (name is Identifier) {
       currentDeclaration = _offsetMap.lookupNamedDeclaration(name);
     } else {
       currentDeclaration = _offsetMap.lookupUnnamedDeclaration(beginToken);
     }
-    memberScope = currentDeclaration!.scope;
+    _memberScope = currentDeclaration.bodyScope;
   }
 
   @override
   void endClassOrMixinOrExtensionBody(
       DeclarationKind kind, int memberCount, Token beginToken, Token endToken) {
     debugEvent("ClassOrMixinBody");
-    currentDeclaration = null;
     currentClassIsParserRecovery = false;
-    memberScope = libraryBuilder.scope;
+    _memberScope = outermostScope;
   }
 
   @override
@@ -1067,14 +1064,13 @@
     push(identifier);
     push(extensionKeyword);
 
-    // The current declaration is set in [beginClassOrMixinOrExtensionBody] but
+    // The [memberScope] is set in [beginClassOrMixinOrExtensionBody] but
     // for primary constructors we need it before the body so we set it here.
-    // TODO(johnniwinther): Normalize the setting of the current declaration.
-    assert(currentDeclaration == null);
-    assert(memberScope == libraryBuilder.scope);
+    assert(_memberScope == outermostScope);
 
-    currentDeclaration = _offsetMap.lookupNamedDeclaration(identifier);
-    memberScope = currentDeclaration!.scope;
+    DeclarationFragmentImpl currentDeclaration =
+        _offsetMap.lookupNamedDeclaration(identifier);
+    _memberScope = currentDeclaration.bodyScope;
   }
 
   @override
@@ -1104,20 +1100,18 @@
           createFunctionListener(functionBodyBuildingContext), formalsToken);
     }
 
-    // The current declaration is set in [beginClassOrMixinOrExtensionBody],
-    // assuming that it is currently `null`, so we reset it here.
-    // TODO(johnniwinther): Normalize the setting of the current declaration.
-    currentDeclaration = null;
-    memberScope = libraryBuilder.scope;
+    // The [memberScope] is set in [beginClassOrMixinOrExtensionBody],
+    // assuming that it is currently the [compilationUnitScope], so we reset it
+    // here.
+    _memberScope = outermostScope;
   }
 
   @override
   void handleNoPrimaryConstructor(Token token, Token? constKeyword) {
-    // The current declaration is set in [beginClassOrMixinOrExtensionBody],
-    // assuming that it is currently `null`, so we reset it here.
-    // TODO(johnniwinther): Normalize the setting of the current declaration.
-    currentDeclaration = null;
-    memberScope = libraryBuilder.scope;
+    // The [memberScope] is set in [beginClassOrMixinOrExtensionBody],
+    // assuming that it is currently the [compilationUnitScope], so we reset it
+    // here.
+    _memberScope = outermostScope;
   }
 
   @override
@@ -1133,8 +1127,7 @@
     debugEvent("Enum");
     Object? name = pop();
 
-    assert(currentDeclaration == null);
-    assert(memberScope == libraryBuilder.scope);
+    assert(_memberScope == outermostScope);
 
     if (name is ParserRecovery) {
       currentClassIsParserRecovery = true;
@@ -1142,8 +1135,9 @@
     }
 
     Identifier identifier = name as Identifier;
-    currentDeclaration = _offsetMap.lookupNamedDeclaration(identifier);
-    memberScope = currentDeclaration!.scope;
+    DeclarationFragmentImpl currentDeclaration =
+        _offsetMap.lookupNamedDeclaration(identifier);
+    _memberScope = currentDeclaration.bodyScope;
   }
 
   @override
@@ -1151,8 +1145,7 @@
       int memberCount, Token endToken) {
     debugEvent("Enum");
     checkEmpty(enumKeyword.charOffset);
-    currentDeclaration = null;
-    memberScope = libraryBuilder.scope;
+    _memberScope = outermostScope;
   }
 
   @override
@@ -1336,7 +1329,7 @@
   List<Expression>? parseMetadata(BodyBuilderContext bodyBuilderContext,
       Token? metadata, Annotatable? parent) {
     if (metadata != null) {
-      BodyBuilder listener = createListener(bodyBuilderContext, memberScope);
+      BodyBuilder listener = createListener(bodyBuilderContext, _memberScope);
       Parser parser = new Parser(listener,
           useImplicitCreationExpression: useImplicitCreationExpressionInCfe,
           allowPatterns: libraryFeatures.patterns.isEnabled,
diff --git a/pkg/front_end/lib/src/source/offset_map.dart b/pkg/front_end/lib/src/source/offset_map.dart
index 94229fb..455cfd7 100644
--- a/pkg/front_end/lib/src/source/offset_map.dart
+++ b/pkg/front_end/lib/src/source/offset_map.dart
@@ -10,8 +10,6 @@
 import '../base/identifiers.dart';
 import '../base/import.dart';
 import '../base/problems.dart';
-import '../builder/builder.dart';
-import '../builder/declaration_builders.dart';
 import '../codes/cfe_codes.dart';
 import '../fragment/fragment.dart';
 
@@ -79,9 +77,9 @@
     _declarations[identifier.nameOffset] = fragment;
   }
 
-  DeclarationBuilder lookupNamedDeclaration(Identifier identifier) {
-    return _checkBuilder(_declarations[identifier.nameOffset]?.builder,
-        identifier.name, identifier.nameOffset);
+  DeclarationFragmentImpl lookupNamedDeclaration(Identifier identifier) {
+    return _checkFragment(_declarations[identifier.nameOffset], identifier.name,
+        identifier.nameOffset);
   }
 
   void registerUnnamedDeclaration(
@@ -89,8 +87,8 @@
     _declarations[beginToken.charOffset] = fragment;
   }
 
-  DeclarationBuilder lookupUnnamedDeclaration(Token beginToken) {
-    return _checkBuilder(_declarations[beginToken.charOffset]?.builder,
+  DeclarationFragmentImpl lookupUnnamedDeclaration(Token beginToken) {
+    return _checkFragment(_declarations[beginToken.charOffset],
         '<unnamed-declaration>', beginToken.charOffset);
   }
 
@@ -164,19 +162,6 @@
     return directive;
   }
 
-  T _checkBuilder<T extends Builder>(
-      T? declaration, String name, int charOffset) {
-    if (declaration == null) {
-      internalProblem(
-          templateInternalProblemNotFound.withArguments(name), charOffset, uri);
-    }
-    if (uri != declaration.fileUri) {
-      unexpected("$uri", "${declaration.fileUri}", declaration.fileOffset,
-          declaration.fileUri);
-    }
-    return declaration;
-  }
-
   T _checkFragment<T>(T? fragment, String name, int fileOffset) {
     if (fragment == null) {
       internalProblem(
diff --git a/pkg/front_end/lib/src/source/source_class_builder.dart b/pkg/front_end/lib/src/source/source_class_builder.dart
index b356df5..98ca9af 100644
--- a/pkg/front_end/lib/src/source/source_class_builder.dart
+++ b/pkg/front_end/lib/src/source/source_class_builder.dart
@@ -112,12 +112,8 @@
 
   final DeclarationNameSpaceBuilder nameSpaceBuilder;
 
-  late final LookupScope _scope;
-
   late final DeclarationNameSpace _nameSpace;
 
-  late final ConstructorScope _constructorScope;
-
   @override
   List<NominalParameterBuilder>? typeParameters;
 
@@ -183,6 +179,11 @@
     actualCls.hasConstConstructor = declaresConstConstructor;
   }
 
+  // TODO(johnniwinther): Remove this when augmentations are handled through
+  //  fragments.
+  @override
+  LookupScope get bodyScope => _introductory.bodyScope;
+
   @override
   int get fileOffset => nameOffset;
 
@@ -230,17 +231,11 @@
   bool get isMixinDeclaration => _introductory.isMixinDeclaration;
 
   @override
-  LookupScope get scope => _scope;
-
-  @override
   DeclarationNameSpace get nameSpace => _nameSpace;
 
   List<MetadataBuilder>? get metadata => _introductory.metadata;
 
   @override
-  ConstructorScope get constructorScope => _constructorScope;
-
-  @override
   void buildScopes(LibraryBuilder coreLibrary) {
     _nameSpace = nameSpaceBuilder.buildNameSpace(
         loader: libraryBuilder.loader,
@@ -251,11 +246,6 @@
         indexedContainer: indexedClass,
         containerType: ContainerType.Class,
         containerName: new ClassName(name));
-    _scope = new NameSpaceLookupScope(
-        _nameSpace, ScopeKind.declaration, "class $name",
-        parent: typeParameterScope);
-    _constructorScope =
-        new DeclarationNameSpaceConstructorScope(name, _nameSpace);
   }
 
   MergedClassMemberScope get mergedScope => _mergedScope ??= isAugmenting
@@ -526,14 +516,12 @@
           classHierarchy, delayedDefaultValueCloners);
     }
 
-    MetadataBuilder.buildAnnotations(
-        isAugmenting ? origin.cls : cls,
-        metadata,
-        createBodyBuilderContext(),
-        libraryBuilder,
-        fileUri,
-        libraryBuilder.scope,
+    _introductory.buildOutlineExpressions(
+        annotatable: isAugmenting ? origin.cls : cls,
+        bodyBuilderContext: createBodyBuilderContext(),
+        libraryBuilder: libraryBuilder,
         createFileUriExpression: isAugmenting);
+
     if (typeParameters != null) {
       for (int i = 0; i < typeParameters!.length; i++) {
         typeParameters![i].buildOutlineExpressions(libraryBuilder,
diff --git a/pkg/front_end/lib/src/source/source_compilation_unit.dart b/pkg/front_end/lib/src/source/source_compilation_unit.dart
index 9c3a806..c71ecd8 100644
--- a/pkg/front_end/lib/src/source/source_compilation_unit.dart
+++ b/pkg/front_end/lib/src/source/source_compilation_unit.dart
@@ -811,6 +811,15 @@
   }
 
   @override
+  void buildOutlineExpressions(
+      Annotatable annotatable, BodyBuilderContext bodyBuilderContext,
+      {required bool createFileUriExpression}) {
+    MetadataBuilder.buildAnnotations(annotatable, metadata, bodyBuilderContext,
+        libraryBuilder, fileUri, compilationUnitScope,
+        createFileUriExpression: createFileUriExpression);
+  }
+
+  @override
   void collectUnboundTypeParameters(
       SourceLibraryBuilder libraryBuilder,
       Map<NominalParameterBuilder, SourceLibraryBuilder> nominalVariables,
diff --git a/pkg/front_end/lib/src/source/source_constructor_builder.dart b/pkg/front_end/lib/src/source/source_constructor_builder.dart
index b570d56..da6ba41 100644
--- a/pkg/front_end/lib/src/source/source_constructor_builder.dart
+++ b/pkg/front_end/lib/src/source/source_constructor_builder.dart
@@ -349,17 +349,6 @@
         local: local);
   }
 
-  // TODO(johnniwinther): Remove this.
-  LookupScope computeTypeParameterScope(LookupScope parent) {
-    if (typeParameters == null) return parent;
-    Map<String, Builder> local = <String, Builder>{};
-    for (NominalParameterBuilder variable in typeParameters!) {
-      if (variable.isWildcard) continue;
-      local[variable.name] = variable;
-    }
-    return new TypeParameterScope(parent, local);
-  }
-
   @override
   FormalParameterBuilder? getFormal(Identifier identifier) {
     if (formals != null) {
@@ -527,21 +516,22 @@
     }
   }
 
-  void _buildConstructorForOutline(
-      Token? beginInitializers, LookupScope declarationScope) {
+  void _buildConstructorForOutline(Token? beginInitializers) {
     if (beginInitializers != null) {
       final LocalScope? formalParameterScope;
       if (isConst) {
         // We're going to fully build the constructor so we need scopes.
         formalParameterScope = computeFormalParameterInitializerScope(
-            computeFormalParameterScope(
-                computeTypeParameterScope(declarationBuilder.scope)));
+            computeFormalParameterScope(_introductory.typeParameterScope));
       } else {
         formalParameterScope = null;
       }
       BodyBuilder bodyBuilder = libraryBuilder.loader
-          .createBodyBuilderForOutlineExpression(libraryBuilder,
-              createBodyBuilderContext(), declarationScope, fileUri,
+          .createBodyBuilderForOutlineExpression(
+              libraryBuilder,
+              createBodyBuilderContext(),
+              _introductory.typeParameterScope,
+              fileUri,
               formalParameterScope: formalParameterScope);
       if (isConst) {
         bodyBuilder.constantContext = ConstantContext.required;
@@ -690,41 +680,20 @@
     if (!hasBuiltOutlineExpressions) {
       formals?.infer(classHierarchy);
 
-      LookupScope parentScope = declarationBuilder.scope;
-      for (Annotatable annotatable in annotatables) {
-        MetadataBuilder.buildAnnotations(annotatable, metadata,
-            createBodyBuilderContext(), libraryBuilder, fileUri, parentScope,
-            createFileUriExpression: isAugmented);
-      }
-      if (typeParameters != null) {
-        for (int i = 0; i < typeParameters!.length; i++) {
-          typeParameters![i].buildOutlineExpressions(
-              libraryBuilder,
-              createBodyBuilderContext(),
-              classHierarchy,
-              computeTypeParameterScope(parentScope));
-        }
-      }
+      _introductory.buildOutlineExpressions(
+          annotatables: annotatables,
+          libraryBuilder: libraryBuilder,
+          declarationBuilder: declarationBuilder,
+          bodyBuilderContext: createBodyBuilderContext(),
+          classHierarchy: classHierarchy,
+          createFileUriExpression: isAugmented);
 
-      if (formals != null) {
-        // For const constructors we need to include default parameter values
-        // into the outline. For all other formals we need to call
-        // buildOutlineExpressions to clear initializerToken to prevent
-        // consuming too much memory.
-        for (FormalParameterBuilder formal in formals!) {
-          formal.buildOutlineExpressions(libraryBuilder, declarationBuilder,
-              buildDefaultValue: FormalParameterBuilder
-                  .needsDefaultValuesBuiltAsOutlineExpressions(this));
-        }
-      }
       hasBuiltOutlineExpressions = true;
     }
     if (isConst || _introductory.hasSuperInitializingFormals) {
       // For modular compilation purposes we need to include initializers
       // for const constructors into the outline.
-      LookupScope typeParameterScope =
-          computeTypeParameterScope(declarationBuilder.scope);
-      _buildConstructorForOutline(beginInitializers, typeParameterScope);
+      _buildConstructorForOutline(beginInitializers);
       _introductory.buildBody();
     }
 
@@ -818,8 +787,8 @@
         initializers.last is SuperInitializer) {
       superTarget = (initializers.last as SuperInitializer).target;
     } else {
-      MemberBuilder? memberBuilder = superclassBuilder.constructorScope
-          .lookup("", fileOffset, libraryBuilder.fileUri);
+      MemberBuilder? memberBuilder = superclassBuilder.findConstructorOrFactory(
+          "", fileOffset, fileUri, libraryBuilder);
       if (memberBuilder is ConstructorBuilder) {
         superTarget = memberBuilder.invokeTarget;
       } else {
@@ -832,8 +801,8 @@
     }
 
     MemberBuilder? constructorBuilder =
-        superclassBuilder.findConstructorOrFactory(superTarget.name.text,
-            fileOffset, libraryBuilder.fileUri, libraryBuilder);
+        superclassBuilder.findConstructorOrFactory(
+            superTarget.name.text, fileOffset, fileUri, libraryBuilder);
     if (constructorBuilder is ConstructorBuilder) {
       return constructorBuilder;
     } else {
@@ -878,8 +847,11 @@
       List<Initializer>? initializers;
       if (beginInitializers != null) {
         BodyBuilder bodyBuilder = libraryBuilder.loader
-            .createBodyBuilderForOutlineExpression(libraryBuilder,
-                createBodyBuilderContext(), declarationBuilder.scope, fileUri);
+            .createBodyBuilderForOutlineExpression(
+                libraryBuilder,
+                createBodyBuilderContext(),
+                _introductory.typeParameterScope,
+                fileUri);
         if (isConst) {
           bodyBuilder.constantContext = ConstantContext.required;
         }
diff --git a/pkg/front_end/lib/src/source/source_enum_builder.dart b/pkg/front_end/lib/src/source/source_enum_builder.dart
index ed2fe0e..8eb6e25 100644
--- a/pkg/front_end/lib/src/source/source_enum_builder.dart
+++ b/pkg/front_end/lib/src/source/source_enum_builder.dart
@@ -42,6 +42,7 @@
 import '../kernel/kernel_helper.dart';
 import '../kernel/member_covariance.dart';
 import '../kernel/type_algorithms.dart';
+import '../kernel/utils.dart';
 import 'name_scheme.dart';
 import 'source_class_builder.dart' show SourceClassBuilder;
 import 'source_constructor_builder.dart';
@@ -55,6 +56,8 @@
   final int startOffset;
   final int endOffset;
 
+  final ClassDeclaration _introductory;
+
   final List<EnumElementFragment> _enumElements;
 
   final TypeBuilder _underscoreEnumTypeBuilder;
@@ -85,6 +88,7 @@
       required IndexedClass? indexedClass,
       required ClassDeclaration classDeclaration})
       : _underscoreEnumTypeBuilder = underscoreEnumTypeBuilder,
+        _introductory = classDeclaration,
         _enumElements = enumElements,
         super(
             modifiers: Modifiers.empty,
@@ -311,7 +315,8 @@
                 nameFormalParameterBuilder
               ],
               fileUri: fileUri,
-              fileOffset: fileOffset);
+              fileOffset: fileOffset,
+              lookupScope: _introductory.compilationUnitScope);
       synthesizedDefaultConstructorBuilder = new SourceConstructorBuilderImpl(
           modifiers: Modifiers.Const,
           name: "",
@@ -388,9 +393,8 @@
       }
     }
 
-    objectType.resolveIn(
-        coreLibrary.scope, fileOffset, fileUri, libraryBuilder);
-    listType.resolveIn(coreLibrary.scope, fileOffset, fileUri, libraryBuilder);
+    bindCoreType(coreLibrary, objectType);
+    bindCoreType(coreLibrary, listType);
 
     Class cls = super.build(coreLibrary);
     cls.isEnum = true;
@@ -579,7 +583,6 @@
       ClassHierarchy classHierarchy,
       SourceLibraryBuilder libraryBuilder,
       DeclarationBuilder? declarationBuilder,
-      LookupScope parentScope,
       List<Annotatable> annotatables,
       {required bool isClassInstanceMember,
       required bool createFileUriExpression}) {
diff --git a/pkg/front_end/lib/src/source/source_extension_builder.dart b/pkg/front_end/lib/src/source/source_extension_builder.dart
index 2c33fa5..a6ff525 100644
--- a/pkg/front_end/lib/src/source/source_extension_builder.dart
+++ b/pkg/front_end/lib/src/source/source_extension_builder.dart
@@ -50,12 +50,8 @@
 
   final DeclarationNameSpaceBuilder _nameSpaceBuilder;
 
-  late final LookupScope _scope;
-
   late final DeclarationNameSpace _nameSpace;
 
-  late final ConstructorScope _constructorScope;
-
   @override
   final List<NominalParameterBuilder>? typeParameters;
 
@@ -119,17 +115,10 @@
   String get name => extensionName.name;
 
   @override
-  LookupScope get scope => _scope;
-
-  @override
   DeclarationNameSpace get nameSpace => _nameSpace;
 
   @override
   // Coverage-ignore(suite): Not run.
-  ConstructorScope get constructorScope => _constructorScope;
-
-  @override
-  // Coverage-ignore(suite): Not run.
   bool get isConst => _modifiers.isConst;
 
   @override
@@ -153,11 +142,6 @@
         containerType: ContainerType.Extension,
         containerName: extensionName,
         includeConstructors: false);
-    _scope = new NameSpaceLookupScope(
-        _nameSpace, ScopeKind.declaration, "extension ${extensionName.name}",
-        parent: typeParameterScope);
-    _constructorScope =
-        new DeclarationNameSpaceConstructorScope(name, _nameSpace);
   }
 
   @override
@@ -216,7 +200,7 @@
         createBodyBuilderContext(),
         libraryBuilder,
         _introductory.fileUri,
-        libraryBuilder.scope);
+        _introductory.enclosingScope);
 
     super.buildOutlineExpressions(classHierarchy, delayedDefaultValueCloners);
   }
diff --git a/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart b/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart
index 830bc84..471f1d0 100644
--- a/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart
+++ b/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart
@@ -71,12 +71,8 @@
 
   final DeclarationNameSpaceBuilder _nameSpaceBuilder;
 
-  late final LookupScope _scope;
-
   late final DeclarationNameSpace _nameSpace;
 
-  late final ConstructorScope _constructorScope;
-
   @override
   final List<NominalParameterBuilder>? typeParameters;
 
@@ -128,21 +124,20 @@
       ..fileOffset = nameOffset;
   }
 
+  // TODO(johnniwinther): Remove this when augmentations are handled through
+  //  fragments.
+  @override
+  LookupScope get bodyScope => _introductory.bodyScope;
+
   // Coverage-ignore(suite): Not run.
   // TODO(johnniwinther): Avoid exposing this. Annotations for macros and
   //  patches should be computing from within the builder.
   List<MetadataBuilder>? get metadata => _introductory.metadata;
 
   @override
-  LookupScope get scope => _scope;
-
-  @override
   DeclarationNameSpace get nameSpace => _nameSpace;
 
   @override
-  ConstructorScope get constructorScope => _constructorScope;
-
-  @override
   // Coverage-ignore(suite): Not run.
   bool get isConst => _modifiers.isConst;
 
@@ -167,11 +162,6 @@
         indexedContainer: indexedContainer,
         containerType: ContainerType.ExtensionType,
         containerName: new ClassName(name));
-    _scope = new NameSpaceLookupScope(
-        _nameSpace, ScopeKind.declaration, "extension type $name",
-        parent: typeParameterScope);
-    _constructorScope =
-        new DeclarationNameSpaceConstructorScope(name, _nameSpace);
   }
 
   @override
@@ -719,7 +709,7 @@
         createBodyBuilderContext(),
         libraryBuilder,
         _introductory.fileUri,
-        libraryBuilder.scope);
+        _introductory.enclosingScope);
 
     super.buildOutlineExpressions(classHierarchy, delayedDefaultValueCloners);
 
diff --git a/pkg/front_end/lib/src/source/source_factory_builder.dart b/pkg/front_end/lib/src/source/source_factory_builder.dart
index 3ce0c53..8a1e03f 100644
--- a/pkg/front_end/lib/src/source/source_factory_builder.dart
+++ b/pkg/front_end/lib/src/source/source_factory_builder.dart
@@ -681,17 +681,6 @@
                 : BuiltMemberKind.Factory));
   }
 
-  // TODO(johnniwinther): Remove this.
-  LookupScope _computeTypeParameterScope(LookupScope parent) {
-    if (typeParameters == null) return parent;
-    Map<String, Builder> local = <String, Builder>{};
-    for (NominalParameterBuilder variable in typeParameters!) {
-      if (variable.isWildcard) continue;
-      local[variable.name] = variable;
-    }
-    return new TypeParameterScope(parent, local);
-  }
-
   void buildOutlineExpressions(ClassHierarchy classHierarchy,
       List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
     _fragment.formals?.infer(classHierarchy);
@@ -700,7 +689,6 @@
       delayedDefaultValueCloners.add(_delayedDefaultValueCloner!);
     }
 
-    LookupScope parentScope = _fragment.builder.declarationBuilder.scope;
     for (Annotatable annotatable in _fragment.builder.annotatables) {
       MetadataBuilder.buildAnnotations(
           annotatable,
@@ -708,7 +696,7 @@
           _fragment.builder.createBodyBuilderContext(),
           _fragment.builder.libraryBuilder,
           _fragment.fileUri,
-          parentScope,
+          _fragment.enclosingScope,
           createFileUriExpression: _fragment.builder.isAugmented);
     }
     if (typeParameters != null) {
@@ -717,7 +705,7 @@
             _fragment.builder.libraryBuilder,
             _fragment.builder.createBodyBuilderContext(),
             classHierarchy,
-            _computeTypeParameterScope(parentScope));
+            _fragment.typeParameterScope);
       }
     }
 
@@ -729,6 +717,7 @@
       for (FormalParameterBuilder formal in _fragment.formals!) {
         formal.buildOutlineExpressions(_fragment.builder.libraryBuilder,
             _fragment.builder.declarationBuilder,
+            scope: _fragment.typeParameterScope,
             buildDefaultValue: FormalParameterBuilder
                 .needsDefaultValuesBuiltAsOutlineExpressions(
                     _fragment.builder));
@@ -760,7 +749,7 @@
           .createBodyBuilderForOutlineExpression(
               _fragment.builder.libraryBuilder,
               _fragment.builder.createBodyBuilderContext(),
-              _fragment.builder.declarationBuilder.scope,
+              _fragment.enclosingScope,
               _fragment.fileUri);
       Builder? targetBuilder = _fragment.redirectionTarget!.target;
 
diff --git a/pkg/front_end/lib/src/source/source_library_builder.dart b/pkg/front_end/lib/src/source/source_library_builder.dart
index f6beb4d..0011b37 100644
--- a/pkg/front_end/lib/src/source/source_library_builder.dart
+++ b/pkg/front_end/lib/src/source/source_library_builder.dart
@@ -152,8 +152,6 @@
   @override
   LibraryBuilder? get partOfLibrary => compilationUnit.partOfLibrary;
 
-  List<MetadataBuilder>? get metadata => compilationUnit.metadata;
-
   @override
   final Library library;
 
@@ -384,9 +382,6 @@
         feature, fileUri, charOffset, length);
   }
 
-  @override
-  LookupScope get scope => compilationUnit.compilationUnitScope;
-
   LookupScope? get parentScope => _parentScope;
 
   @override
@@ -1008,8 +1003,7 @@
       }
     }
 
-    MetadataBuilder.buildAnnotations(
-        library, metadata, createBodyBuilderContext(), this, fileUri, scope,
+    compilationUnit.buildOutlineExpressions(library, createBodyBuilderContext(),
         createFileUriExpression: isAugmenting);
 
     Iterator<Builder> iterator = localMembersIterator;
diff --git a/pkg/front_end/lib/src/source/source_loader.dart b/pkg/front_end/lib/src/source/source_loader.dart
index 29ac623..a7f0ff2 100644
--- a/pkg/front_end/lib/src/source/source_loader.dart
+++ b/pkg/front_end/lib/src/source/source_loader.dart
@@ -1289,8 +1289,8 @@
       }
     }
 
-    DietListener listener =
-        createDietListener(library, compilationUnit.offsetMap);
+    DietListener listener = createDietListener(library,
+        compilationUnit.compilationUnitScope, compilationUnit.offsetMap);
     DietParser parser = new DietParser(listener,
         allowPatterns: library.libraryFeatures.patterns.isEnabled,
         enableFeatureEnhancedParts:
@@ -1299,8 +1299,8 @@
     for (SourceCompilationUnit compilationUnit in library.parts) {
       Token tokens = await tokenize(compilationUnit,
           suppressLexicalErrors: true, allowLazyStrings: false);
-      DietListener listener =
-          createDietListener(library, compilationUnit.offsetMap);
+      DietListener listener = createDietListener(library,
+          compilationUnit.compilationUnitScope, compilationUnit.offsetMap);
       DietParser parser = new DietParser(listener,
           allowPatterns: library.libraryFeatures.patterns.isEnabled,
           enableFeatureEnhancedParts:
@@ -1316,37 +1316,37 @@
       bool isClassInstanceMember,
       Procedure procedure,
       VariableDeclaration? extensionThis) async {
-    Token token = await tokenize(libraryBuilder.compilationUnit,
-        suppressLexicalErrors: false, allowLazyStrings: false);
-    DietListener dietListener = createDietListener(
-        libraryBuilder,
-        // Expression compilation doesn't build an outline, and thus doesn't
-        // support members from source, so we provide an empty [DeclarationMap].
-        new OffsetMap(libraryBuilder.fileUri));
+    // TODO(johnniwinther): Support expression compilation in a specific
+    //  compilation unit.
+    LookupScope memberScope =
+        libraryBuilder.compilationUnit.compilationUnitScope;
 
+    DeclarationBuilder? declarationBuilder;
     if (enclosingClassOrExtension != null) {
-      Builder? builder = dietListener.memberScope
-          .lookupGetable(enclosingClassOrExtension, -1, libraryBuilder.fileUri);
+      Builder? builder = memberScope.lookupGetable(
+          enclosingClassOrExtension, -1, libraryBuilder.fileUri);
       if (builder is TypeDeclarationBuilder) {
         switch (builder) {
           case ClassBuilder():
-            dietListener
-              ..currentDeclaration = builder
-              ..memberScope = new NameSpaceLookupScope(
-                  builder.nameSpace,
-                  ScopeKind.declaration,
-                  "debugExpression in class $enclosingClassOrExtension",
-                  parent: TypeParameterScope.fromList(
-                      dietListener.memberScope, builder.typeParameters));
+            declarationBuilder = builder;
+            // TODO(johnniwinther): This should be the body scope of the
+            //  fragment in which we are compiling the expression.
+            memberScope = new NameSpaceLookupScope(
+                builder.nameSpace,
+                ScopeKind.declaration,
+                "debugExpression in class $enclosingClassOrExtension",
+                parent: TypeParameterScope.fromList(
+                    memberScope, builder.typeParameters));
           case ExtensionBuilder():
-            dietListener
-              ..currentDeclaration = builder
-              ..memberScope = new NameSpaceLookupScope(
-                  builder.nameSpace,
-                  ScopeKind.declaration,
-                  "debugExpression in extension $enclosingClassOrExtension",
-                  // TODO(johnniwinther): Shouldn't type parameters be in scope?
-                  parent: dietListener.memberScope);
+            declarationBuilder = builder;
+            // TODO(johnniwinther): This should be the body scope of the
+            //  fragment in which we are compiling the expression.
+            memberScope = new NameSpaceLookupScope(
+                builder.nameSpace,
+                ScopeKind.declaration,
+                "debugExpression in extension $enclosingClassOrExtension",
+                // TODO(johnniwinther): Shouldn't type parameters be in scope?
+                parent: memberScope);
           case ExtensionTypeDeclarationBuilder():
           // TODO(johnniwinther): Handle this case.
           case TypeAliasBuilder():
@@ -1358,10 +1358,20 @@
       }
     }
 
+    Token token = await tokenize(libraryBuilder.compilationUnit,
+        suppressLexicalErrors: false, allowLazyStrings: false);
+    DietListener dietListener = createDietListener(
+        libraryBuilder,
+        memberScope,
+        // Expression compilation doesn't build an outline, and thus doesn't
+        // support members from source, so we provide an empty [DeclarationMap].
+        new OffsetMap(libraryBuilder.fileUri));
+
     BodyBuilder listener = dietListener.createListener(
-        new ExpressionCompilerProcedureBodyBuildContext(dietListener, procedure,
+        new ExpressionCompilerProcedureBodyBuildContext(
+            dietListener, procedure, libraryBuilder, declarationBuilder,
             isDeclarationInstanceMember: isClassInstanceMember),
-        dietListener.memberScope,
+        memberScope,
         thisVariable: extensionThis);
     for (VariableDeclaration variable
         in procedure.function.positionalParameters) {
@@ -1378,10 +1388,10 @@
         procedure.function);
   }
 
-  DietListener createDietListener(
-      SourceLibraryBuilder library, OffsetMap offsetMap) {
-    return new DietListener(
-        library, hierarchy, coreTypes, typeInferenceEngine, offsetMap);
+  DietListener createDietListener(SourceLibraryBuilder library,
+      LookupScope compilationUnitScope, OffsetMap offsetMap) {
+    return new DietListener(library, compilationUnitScope, hierarchy, coreTypes,
+        typeInferenceEngine, offsetMap);
   }
 
   void resolveParts() {
diff --git a/pkg/front_end/lib/src/source/source_method_builder.dart b/pkg/front_end/lib/src/source/source_method_builder.dart
index 2ded4bf..5b11390 100644
--- a/pkg/front_end/lib/src/source/source_method_builder.dart
+++ b/pkg/front_end/lib/src/source/source_method_builder.dart
@@ -8,7 +8,6 @@
 
 import '../base/modifiers.dart';
 import '../base/name_space.dart';
-import '../base/scope.dart';
 import '../builder/builder.dart';
 import '../builder/declaration_builders.dart';
 import '../builder/formal_parameter_builder.dart';
@@ -266,10 +265,8 @@
   void buildOutlineExpressions(ClassHierarchy classHierarchy,
       List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
     if (!hasBuiltOutlineExpressions) {
-      LookupScope parentScope =
-          declarationBuilder?.scope ?? libraryBuilder.scope;
       _introductory.buildOutlineExpressions(classHierarchy, libraryBuilder,
-          declarationBuilder, parentScope, invokeTarget as Annotatable,
+          declarationBuilder, invokeTarget as Annotatable,
           isClassInstanceMember: isClassInstanceMember,
           createFileUriExpression: isAugmented);
       hasBuiltOutlineExpressions = true;
diff --git a/pkg/front_end/lib/src/source/source_property_builder.dart b/pkg/front_end/lib/src/source/source_property_builder.dart
index 3a5c3b9..50ab4b8 100644
--- a/pkg/front_end/lib/src/source/source_property_builder.dart
+++ b/pkg/front_end/lib/src/source/source_property_builder.dart
@@ -11,7 +11,6 @@
 
 import '../base/modifiers.dart';
 import '../base/name_space.dart';
-import '../base/scope.dart';
 import '../builder/builder.dart';
 import '../builder/declaration_builders.dart';
 import '../builder/formal_parameter_builder.dart';
@@ -387,13 +386,10 @@
   void buildOutlineExpressions(ClassHierarchy classHierarchy,
       List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
     if (!hasBuiltOutlineExpressions) {
-      LookupScope parentScope =
-          declarationBuilder?.scope ?? libraryBuilder.scope;
       _introductoryField?.buildOutlineExpressions(
           classHierarchy,
           libraryBuilder,
           declarationBuilder,
-          parentScope,
           [
             readTarget as Annotatable,
             if (writeTarget != null && readTarget != writeTarget)
@@ -401,20 +397,12 @@
           ],
           isClassInstanceMember: isClassInstanceMember,
           createFileUriExpression: isAugmented);
-      _introductoryGetable?.buildOutlineExpressions(
-          classHierarchy,
-          libraryBuilder,
-          declarationBuilder,
-          parentScope,
-          readTarget as Annotatable,
+      _introductoryGetable?.buildOutlineExpressions(classHierarchy,
+          libraryBuilder, declarationBuilder, readTarget as Annotatable,
           isClassInstanceMember: isClassInstanceMember,
           createFileUriExpression: isAugmented);
-      _introductorySetable?.buildOutlineExpressions(
-          classHierarchy,
-          libraryBuilder,
-          declarationBuilder,
-          parentScope,
-          writeTarget as Annotatable,
+      _introductorySetable?.buildOutlineExpressions(classHierarchy,
+          libraryBuilder, declarationBuilder, writeTarget as Annotatable,
           isClassInstanceMember: isClassInstanceMember,
           createFileUriExpression: isAugmented);
       hasBuiltOutlineExpressions = true;
diff --git a/pkg/front_end/lib/src/source/source_type_alias_builder.dart b/pkg/front_end/lib/src/source/source_type_alias_builder.dart
index cd55668..1d2a994 100644
--- a/pkg/front_end/lib/src/source/source_type_alias_builder.dart
+++ b/pkg/front_end/lib/src/source/source_type_alias_builder.dart
@@ -6,8 +6,6 @@
 import 'package:kernel/class_hierarchy.dart';
 
 import '../base/problems.dart' show unhandled;
-import '../base/scope.dart';
-import '../builder/builder.dart';
 import '../builder/declaration_builders.dart';
 import '../builder/formal_parameter_builder.dart';
 import '../builder/invalid_type_builder.dart';
@@ -374,14 +372,14 @@
         createBodyBuilderContext(),
         libraryBuilder,
         fileUri,
-        libraryBuilder.scope);
+        _introductory.enclosingScope);
     if (typeParameters != null) {
       for (int i = 0; i < typeParameters!.length; i++) {
         typeParameters![i].buildOutlineExpressions(
             libraryBuilder,
             createBodyBuilderContext(),
             classHierarchy,
-            computeTypeParameterScope(libraryBuilder.scope));
+            _introductory.typeParameterScope);
       }
     }
     _tearOffDependencies?.forEach((Procedure tearOff, Member target) {
@@ -400,15 +398,6 @@
     return count;
   }
 
-  LookupScope computeTypeParameterScope(LookupScope parent) {
-    if (typeParameters == null) return parent;
-    Map<String, Builder> local = <String, Builder>{};
-    for (NominalParameterBuilder variable in typeParameters!) {
-      local[variable.name] = variable;
-    }
-    return new TypeParameterScope(parent, local);
-  }
-
   Map<Procedure, Member>? _tearOffDependencies;
 
   DelayedDefaultValueCloner? buildTypedefTearOffs(
diff --git a/pkg/front_end/test/compiler_test_helper.dart b/pkg/front_end/test/compiler_test_helper.dart
index 372e83d..fe64369 100644
--- a/pkg/front_end/test/compiler_test_helper.dart
+++ b/pkg/front_end/test/compiler_test_helper.dart
@@ -219,10 +219,10 @@
       : super(fileSystem, includeComments, target);
 
   @override
-  DietListener createDietListener(
-      SourceLibraryBuilder library, OffsetMap offsetMap) {
-    return new DietListenerTest(library, hierarchy, coreTypes,
-        typeInferenceEngine, offsetMap, bodyBuilderCreator);
+  DietListener createDietListener(SourceLibraryBuilder library,
+      LookupScope compilationUnitScope, OffsetMap offsetMap) {
+    return new DietListenerTest(library, compilationUnitScope, hierarchy,
+        coreTypes, typeInferenceEngine, offsetMap, bodyBuilderCreator);
   }
 
   @override
@@ -252,8 +252,14 @@
 class DietListenerTest extends DietListener {
   final BodyBuilderCreator bodyBuilderCreator;
 
-  DietListenerTest(super.library, super.hierarchy, super.coreTypes,
-      super.typeInferenceEngine, super.offsetMap, this.bodyBuilderCreator);
+  DietListenerTest(
+      super.library,
+      super.compilationUnitScope,
+      super.hierarchy,
+      super.coreTypes,
+      super.typeInferenceEngine,
+      super.offsetMap,
+      this.bodyBuilderCreator);
 
   @override
   BodyBuilder createListenerInternal(
diff --git a/pkg/front_end/test/coverage_suite_expected.dart b/pkg/front_end/test/coverage_suite_expected.dart
index 3926175..3a0d338 100644
--- a/pkg/front_end/test/coverage_suite_expected.dart
+++ b/pkg/front_end/test/coverage_suite_expected.dart
@@ -210,7 +210,7 @@
   ),
   // 100.0%.
   "package:front_end/src/base/scope.dart": (
-    hitCount: 679,
+    hitCount: 671,
     missCount: 0,
   ),
   // 100.0%.
@@ -265,7 +265,7 @@
   ),
   // 100.0%.
   "package:front_end/src/builder/declaration_builder.dart": (
-    hitCount: 23,
+    hitCount: 28,
     missCount: 0,
   ),
   // 100.0%.
@@ -290,7 +290,7 @@
   ),
   // 100.0%.
   "package:front_end/src/builder/formal_parameter_builder.dart": (
-    hitCount: 170,
+    hitCount: 169,
     missCount: 0,
   ),
   // 100.0%.
@@ -380,7 +380,7 @@
   ),
   // 100.0%.
   "package:front_end/src/builder/type_builder.dart": (
-    hitCount: 53,
+    hitCount: 51,
     missCount: 0,
   ),
   // 100.0%.
@@ -415,12 +415,12 @@
   ),
   // 100.0%.
   "package:front_end/src/dill/dill_class_builder.dart": (
-    hitCount: 188,
+    hitCount: 173,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/dill/dill_extension_builder.dart": (
-    hitCount: 99,
+    hitCount: 86,
     missCount: 0,
   ),
   // 100.0%.
@@ -430,7 +430,7 @@
   ),
   // 100.0%.
   "package:front_end/src/dill/dill_extension_type_declaration_builder.dart": (
-    hitCount: 172,
+    hitCount: 157,
     missCount: 0,
   ),
   // 100.0%.
@@ -440,7 +440,7 @@
   ),
   // 100.0%.
   "package:front_end/src/dill/dill_library_builder.dart": (
-    hitCount: 339,
+    hitCount: 334,
     missCount: 0,
   ),
   // 100.0%.
@@ -465,12 +465,12 @@
   ),
   // 100.0%.
   "package:front_end/src/fragment/class.dart": (
-    hitCount: 9,
+    hitCount: 6,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/fragment/class/declaration.dart": (
-    hitCount: 142,
+    hitCount: 171,
     missCount: 0,
   ),
   // 100.0%.
@@ -480,7 +480,7 @@
   ),
   // 100.0%.
   "package:front_end/src/fragment/constructor/declaration.dart": (
-    hitCount: 248,
+    hitCount: 315,
     missCount: 0,
   ),
   // 100.0%.
@@ -490,22 +490,22 @@
   ),
   // 100.0%.
   "package:front_end/src/fragment/enum.dart": (
-    hitCount: 13,
+    hitCount: 10,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/fragment/enum_element.dart": (
-    hitCount: 242,
+    hitCount: 243,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/fragment/extension.dart": (
-    hitCount: 16,
+    hitCount: 13,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/fragment/extension_type.dart": (
-    hitCount: 13,
+    hitCount: 10,
     missCount: 0,
   ),
   // 100.0%.
@@ -515,7 +515,7 @@
   ),
   // 100.0%.
   "package:front_end/src/fragment/field.dart": (
-    hitCount: 302,
+    hitCount: 301,
     missCount: 0,
   ),
   // 100.0%.
@@ -535,17 +535,17 @@
   ),
   // 100.0%.
   "package:front_end/src/fragment/getter.dart": (
-    hitCount: 527,
+    hitCount: 537,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/fragment/method.dart": (
-    hitCount: 773,
+    hitCount: 783,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/fragment/mixin.dart": (
-    hitCount: 9,
+    hitCount: 6,
     missCount: 0,
   ),
   // 100.0%.
@@ -560,7 +560,7 @@
   ),
   // 100.0%.
   "package:front_end/src/fragment/setter.dart": (
-    hitCount: 547,
+    hitCount: 557,
     missCount: 0,
   ),
   // 100.0%.
@@ -740,7 +740,7 @@
   ),
   // 100.0%.
   "package:front_end/src/kernel/kernel_target.dart": (
-    hitCount: 1051,
+    hitCount: 1043,
     missCount: 0,
   ),
   // 100.0%.
@@ -795,7 +795,7 @@
   ),
   // 100.0%.
   "package:front_end/src/kernel/utils.dart": (
-    hitCount: 72,
+    hitCount: 78,
     missCount: 0,
   ),
   // 100.0%.
@@ -820,7 +820,7 @@
   ),
   // 100.0%.
   "package:front_end/src/source/diet_listener.dart": (
-    hitCount: 675,
+    hitCount: 647,
     missCount: 0,
   ),
   // 100.0%.
@@ -835,7 +835,7 @@
   ),
   // 100.0%.
   "package:front_end/src/source/offset_map.dart": (
-    hitCount: 150,
+    hitCount: 144,
     missCount: 0,
   ),
   // 100.0%.
@@ -860,38 +860,38 @@
   ),
   // 100.0%.
   "package:front_end/src/source/source_class_builder.dart": (
-    hitCount: 1411,
+    hitCount: 1397,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_compilation_unit.dart": (
-    hitCount: 652,
+    hitCount: 658,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_constructor_builder.dart": (
-    hitCount: 730,
+    hitCount: 694,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_enum_builder.dart": (
-    hitCount: 403,
+    hitCount: 397,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_extension_builder.dart": (
-    hitCount: 147,
+    hitCount: 134,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_extension_type_declaration_builder.dart":
       (
-    hitCount: 506,
+    hitCount: 495,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_factory_builder.dart": (
-    hitCount: 1005,
+    hitCount: 994,
     missCount: 0,
   ),
   // 100.0%.
@@ -901,12 +901,12 @@
   ),
   // 100.0%.
   "package:front_end/src/source/source_library_builder.dart": (
-    hitCount: 1246,
+    hitCount: 1238,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_loader.dart": (
-    hitCount: 1842,
+    hitCount: 1844,
     missCount: 0,
   ),
   // 100.0%.
@@ -916,17 +916,17 @@
   ),
   // 100.0%.
   "package:front_end/src/source/source_method_builder.dart": (
-    hitCount: 283,
+    hitCount: 279,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_property_builder.dart": (
-    hitCount: 771,
+    hitCount: 767,
     missCount: 0,
   ),
   // 100.0%.
   "package:front_end/src/source/source_type_alias_builder.dart": (
-    hitCount: 359,
+    hitCount: 349,
     missCount: 0,
   ),
   // 100.0%.
diff --git a/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart
new file mode 100644
index 0000000..3b7fad9
--- /dev/null
+++ b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart
@@ -0,0 +1,14 @@
+// Copyright (c) 2025, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class Super {
+  final int field;
+
+  Super(this.field);
+  Super(this.field);
+}
+
+class Sub extends Super {
+  Sub(super.field);
+}
diff --git a/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.expect b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.expect
new file mode 100644
index 0000000..2f0cea4d
--- /dev/null
+++ b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.expect
@@ -0,0 +1,25 @@
+library;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:9:3: Error: 'Super' is already declared in this scope.
+//   Super(this.field);
+//   ^^^^^
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:8:3: Context: Previous declaration of 'Super'.
+//   Super(this.field);
+//   ^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+class Super extends core::Object {
+  final field core::int field;
+  constructor •(core::int field) → self::Super
+    : self::Super::field = field, super core::Object::•()
+    ;
+}
+class Sub extends self::Super {
+  constructor •(invalid-type field) → self::Sub
+    : super self::Super::•(field)
+    ;
+}
diff --git a/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.modular.expect b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.modular.expect
new file mode 100644
index 0000000..2f0cea4d
--- /dev/null
+++ b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.modular.expect
@@ -0,0 +1,25 @@
+library;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:9:3: Error: 'Super' is already declared in this scope.
+//   Super(this.field);
+//   ^^^^^
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:8:3: Context: Previous declaration of 'Super'.
+//   Super(this.field);
+//   ^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+class Super extends core::Object {
+  final field core::int field;
+  constructor •(core::int field) → self::Super
+    : self::Super::field = field, super core::Object::•()
+    ;
+}
+class Sub extends self::Super {
+  constructor •(invalid-type field) → self::Sub
+    : super self::Super::•(field)
+    ;
+}
diff --git a/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.outline.expect b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.outline.expect
new file mode 100644
index 0000000..c1ca2ff
--- /dev/null
+++ b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.outline.expect
@@ -0,0 +1,23 @@
+library;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:9:3: Error: 'Super' is already declared in this scope.
+//   Super(this.field);
+//   ^^^^^
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:8:3: Context: Previous declaration of 'Super'.
+//   Super(this.field);
+//   ^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+class Super extends core::Object {
+  final field core::int field;
+  constructor •(core::int field) → self::Super
+    ;
+}
+class Sub extends self::Super {
+  constructor •(invalid-type field) → self::Sub
+    ;
+}
diff --git a/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.transformed.expect b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.transformed.expect
new file mode 100644
index 0000000..2f0cea4d
--- /dev/null
+++ b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.strong.transformed.expect
@@ -0,0 +1,25 @@
+library;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:9:3: Error: 'Super' is already declared in this scope.
+//   Super(this.field);
+//   ^^^^^
+// pkg/front_end/testcases/super_parameters/duplicate_constructor.dart:8:3: Context: Previous declaration of 'Super'.
+//   Super(this.field);
+//   ^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+class Super extends core::Object {
+  final field core::int field;
+  constructor •(core::int field) → self::Super
+    : self::Super::field = field, super core::Object::•()
+    ;
+}
+class Sub extends self::Super {
+  constructor •(invalid-type field) → self::Sub
+    : super self::Super::•(field)
+    ;
+}
diff --git a/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.textual_outline.expect b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.textual_outline.expect
new file mode 100644
index 0000000..359cdaa
--- /dev/null
+++ b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.textual_outline.expect
@@ -0,0 +1,9 @@
+class Super {
+  final int field;
+  Super(this.field);
+  Super(this.field);
+}
+
+class Sub extends Super {
+  Sub(super.field);
+}
diff --git a/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.textual_outline_modelled.expect
new file mode 100644
index 0000000..d3f28e24
--- /dev/null
+++ b/pkg/front_end/testcases/super_parameters/duplicate_constructor.dart.textual_outline_modelled.expect
@@ -0,0 +1,9 @@
+class Sub extends Super {
+  Sub(super.field);
+}
+
+class Super {
+  Super(this.field);
+  Super(this.field);
+  final int field;
+}
diff --git a/pkg/front_end/tool/dart_doctest_impl.dart b/pkg/front_end/tool/dart_doctest_impl.dart
index a3f10fc..eb12a7d 100644
--- a/pkg/front_end/tool/dart_doctest_impl.dart
+++ b/pkg/front_end/tool/dart_doctest_impl.dart
@@ -31,6 +31,7 @@
 import 'package:front_end/src/base/hybrid_file_system.dart';
 import 'package:front_end/src/base/incremental_compiler.dart';
 import 'package:front_end/src/base/processed_options.dart';
+import 'package:front_end/src/base/scope.dart';
 import 'package:front_end/src/base/uri_translator.dart';
 import 'package:front_end/src/builder/library_builder.dart';
 import 'package:front_end/src/codes/cfe_codes.dart';
@@ -971,7 +972,8 @@
       packageLanguageVersion:
           new ImplicitLanguageVersion(libraryBuilder.languageVersion),
       loader: loader,
-      parentScope: libraryBuilder.scope,
+      parentScope: new NameSpaceLookupScope(
+          libraryBuilder.libraryNameSpace, ScopeKind.library, 'top'),
       nameOrigin: libraryBuilder,
       isUnsupported: false,
       forAugmentationLibrary: false,