@@ -1277,18 +1277,6 @@ annotToFields annot =
1277
1277
Nothing
1278
1278
1279
1279
1280
- {- | Unwrap a type alias from a declaration (if it is one).
1281
- -}
1282
- getAlias : Node Declaration -> Maybe TypeAlias
1283
- getAlias node =
1284
- case Node . value node of
1285
- AliasDeclaration alias_ ->
1286
- Just alias_
1287
-
1288
- _ ->
1289
- Nothing
1290
-
1291
-
1292
1280
{- | Make subrecords for custom types, if appropriate.
1293
1281
-}
1294
1282
makeCustomTypeSubrecords : SubrecordCanonicity -> String -> List TypeWithPositionalVars -> List ( String , KnownRecord )
@@ -1364,20 +1352,91 @@ getExposedNames =
1364
1352
1365
1353
{- | Visit declarations, storing record field orders.
1366
1354
-}
1367
- declarationListVisitor : RuleConfig -> ModuleContext -> List (Node Declaration ) -> ModuleContext
1355
+ declarationListVisitor :
1356
+ RuleConfig
1357
+ ->
1358
+ { moduleName : ModuleName
1359
+ , lookupTable : ModuleNameLookupTable
1360
+ , aliases : Dict ModuleName ( Dict String TypeWithPositionalVars )
1361
+ , canonicalRecords : Dict ModuleName ( Dict String KnownRecord )
1362
+ , constructors : Dict ModuleName ( Dict String { customTypeName : Maybe String , type_ : TypeWithPositionalVars } )
1363
+ , functionTypes : Dict ModuleName ( Dict String Type )
1364
+ , exposingList : Maybe ExposedNames
1365
+ , fileIsIgnored : Bool
1366
+ }
1367
+ -> List ( Node Declaration )
1368
+ ->
1369
+ { aliases : Dict ModuleName ( Dict String TypeWithPositionalVars )
1370
+ , canonicalRecords : Dict ModuleName ( Dict String KnownRecord )
1371
+ , constructors : Dict ModuleName ( Dict String { customTypeName : Maybe String , type_ : TypeWithPositionalVars } )
1372
+ , functionTypes : Dict ModuleName ( Dict String Type )
1373
+ , exposed :
1374
+ { aliases : Dict String TypeWithPositionalVars
1375
+ , canonicalRecords : Dict String KnownRecord
1376
+ , constructors : Dict String { customTypeName : Maybe String , type_ : TypeWithPositionalVars }
1377
+ , functionTypes : Dict String Type
1378
+ }
1379
+ }
1368
1380
declarationListVisitor ( RuleConfig { subrecordTreatment } ) context declarations =
1369
- let
1370
- makeAliasInfo : TypeAlias -> ( String , TypeWithPositionalVars )
1371
- makeAliasInfo { name, generics, typeAnnotation } =
1372
- ( Node . value name
1373
- , typeAnnotToTypeWithPositionalVars context
1374
- -- Constrained type vars are not respected for aliases
1375
- { constrainedTypeVarsAreRespected = False
1376
- , subrecordIsAlsoCanonical = subrecordCanonicityForRecord subrecordTreatment
1377
- }
1378
- ( List . map Node . value generics)
1379
- typeAnnotation
1380
- )
1381
+ -- Find aliases, canonical records, and function types and store them
1382
+ List . foldl ( accumulateDeclarationInfo subrecordTreatment context)
1383
+ { aliases = []
1384
+ , canonicalRecords = []
1385
+ , constructors = []
1386
+ , functionTypes = []
1387
+ , exposedAliases = []
1388
+ , exposedCanonicalRecords = []
1389
+ , exposedConstructors = []
1390
+ , exposedFunctionTypes = []
1391
+ }
1392
+ declarations
1393
+ |> ( \ r ->
1394
+ if context. fileIsIgnored then
1395
+ { aliases = Dict . empty
1396
+ , canonicalRecords = Dict . empty
1397
+ , constructors = Dict . empty
1398
+ , functionTypes = Dict . empty
1399
+ , exposed =
1400
+ { aliases =
1401
+ Dict . fromList r. exposedAliases
1402
+ , canonicalRecords =
1403
+ Dict . fromList r. exposedCanonicalRecords
1404
+ , constructors =
1405
+ Dict . fromList r. exposedConstructors
1406
+ , functionTypes =
1407
+ Dict . fromList r. exposedFunctionTypes
1408
+ }
1409
+ }
1410
+
1411
+ else
1412
+ { aliases =
1413
+ validate ( not << List . isEmpty) r. aliases
1414
+ |> Maybe . map Dict . fromList
1415
+ |> MaybeX . unwrap context. aliases ( \ v -> Dict . insert context. moduleName v context. aliases)
1416
+ , canonicalRecords =
1417
+ validate ( not << List . isEmpty) r. canonicalRecords
1418
+ |> Maybe . map Dict . fromList
1419
+ |> MaybeX . unwrap context. canonicalRecords ( \ v -> Dict . insert context. moduleName v context. canonicalRecords)
1420
+ , constructors =
1421
+ validate ( not << List . isEmpty) r. constructors
1422
+ |> Maybe . map Dict . fromList
1423
+ |> MaybeX . unwrap context. constructors ( \ v -> Dict . insert context. moduleName v context. constructors)
1424
+ , functionTypes =
1425
+ validate ( not << List . isEmpty) r. functionTypes
1426
+ |> Maybe . map Dict . fromList
1427
+ |> MaybeX . unwrap context. functionTypes ( \ v -> Dict . insert context. moduleName v context. functionTypes)
1428
+ , exposed =
1429
+ { aliases =
1430
+ Dict . fromList r. exposedAliases
1431
+ , canonicalRecords =
1432
+ Dict . fromList r. exposedCanonicalRecords
1433
+ , constructors =
1434
+ Dict . fromList r. exposedConstructors
1435
+ , functionTypes =
1436
+ Dict . fromList r. exposedFunctionTypes
1437
+ }
1438
+ }
1439
+ )
1381
1440
1382
1441
makeConstructorAndSubrecords : TypeWithPositionalVars -> List ( Node String ) -> ValueConstructor -> ( String , TypeWithPositionalVars , List ( String , KnownRecord ) )
1383
1442
makeConstructorAndSubrecords return typeVars { name, arguments } =
0 commit comments