@@ -908,7 +908,8 @@ module Statement =
908
908
909
909
let createDefinitionsMap ( stmts : Statement list ) : Trie < string , Definition list > =
910
910
let add ns name x trie =
911
- trie |> Trie.addOrUpdate ( List.rev ( name :: ns)) [ x] List.append
911
+ let key = List.rev ( name :: ns)
912
+ trie |> Trie.addOrUpdate key [ x] List.append
912
913
let rec go ( ns : string list ) trie s =
913
914
match s with
914
915
| Export _
@@ -1415,14 +1416,16 @@ let inferEnumCaseValue (stmts: Statement list) : Statement list =
1415
1416
{ c with value = v }, v
1416
1417
Enum { e with cases = e.cases |> List.mapFold f None |> fst }
1417
1418
| Module m -> Module { m with statements = m.statements |> List.map go }
1419
+ | Global m -> Global { m with statements = m.statements |> List.map go }
1418
1420
| s -> s
1419
1421
stmts |> List.map go
1420
1422
1421
1423
let rec mergeStatements ( stmts : Statement list ) =
1422
- let mutable result : Choice < Statement , Class ref , Module ref > list = []
1424
+ let mutable result : Choice < Statement , Class ref , Module ref , Global ref > list = []
1423
1425
1424
1426
let mutable intfMap = Map.empty
1425
1427
let mutable nsMap = Map.empty
1428
+ let mutable globalM = None
1426
1429
let mutable otherStmtSet = Set.empty
1427
1430
let mergeTypeParams tps1 tps2 =
1428
1431
let rec go acc = function
@@ -1456,7 +1459,7 @@ let rec mergeStatements (stmts: Statement list) =
1456
1459
| None ->
1457
1460
let iref = ref i
1458
1461
intfMap <- ( intfMap |> Map.add i.name iref)
1459
- result <- Choice2Of3 iref :: result
1462
+ result <- Choice2Of4 iref :: result
1460
1463
| Some iref' ->
1461
1464
let i ' = iref'.Value
1462
1465
assert ( i.accessibility = i'.accessibility)
@@ -1474,25 +1477,38 @@ let rec mergeStatements (stmts: Statement list) =
1474
1477
| None ->
1475
1478
let nref = ref n
1476
1479
nsMap <- ( nsMap |> Map.add n.name nref)
1477
- result <- Choice3Of3 nref :: result
1480
+ result <- Choice3Of4 nref :: result
1478
1481
| Some nref' ->
1479
1482
let n ' = nref'.Value
1480
1483
nref'.Value <-
1481
1484
{ n with
1482
1485
loc = n.loc ++ n'.loc
1483
1486
comments = n.comments @ n'.comments |> List.distinct
1484
1487
statements = n'.statements @ n.statements }
1488
+ | Global n ->
1489
+ match globalM with
1490
+ | None ->
1491
+ let nref = ref n
1492
+ globalM <- Some nref
1493
+ result <- Choice4Of4 nref :: result
1494
+ | Some nref ->
1495
+ let n ' = nref.Value
1496
+ nref.Value <-
1497
+ { n with
1498
+ loc = n.loc ++ n'.loc
1499
+ comments = n.comments @ n'.comments |> List.distinct
1500
+ statements = n'.statements @ n.statements }
1485
1501
| stmt ->
1486
1502
if otherStmtSet |> Set.contains stmt |> not then
1487
1503
otherStmtSet <- otherStmtSet |> Set.add stmt
1488
- result <- Choice1Of3 stmt :: result
1504
+ result <- Choice1Of4 stmt :: result
1489
1505
result
1490
1506
|> List.rev
1491
1507
|> List.map ( function
1492
- | Choice1Of3 s -> s
1493
- | Choice2Of3 i -> Class i.Value
1494
- | Choice3Of3 n ->
1495
- Module { n.Value with statements = mergeStatements n.Value.statements }
1508
+ | Choice1Of4 s -> s
1509
+ | Choice2Of4 i -> Class i.Value
1510
+ | Choice3Of4 n -> Module { n.Value with statements = mergeStatements n.Value.statements }
1511
+ | Choice4Of4 n -> Global { n.Value with statements = mergeStatements n.Value.statements }
1496
1512
)
1497
1513
1498
1514
let mergeSources newFileName ( srcs : SourceFile list ) =
@@ -1527,7 +1543,7 @@ let addDefaultConstructorToClass (ctx: TyperContext<_, _>) (stmts: Statement lis
1527
1543
else
1528
1544
match m.TryGetValue( c.loc) with
1529
1545
| true , ( c, cs) -> c, cs
1530
- | false , _ ->
1546
+ | _ , _ ->
1531
1547
let parentConstructors =
1532
1548
let (| Dummy |) _ = []
1533
1549
let rec picker = function
@@ -1563,9 +1579,9 @@ let addDefaultConstructorToClass (ctx: TyperContext<_, _>) (stmts: Statement lis
1563
1579
( c, cs)
1564
1580
let rec go stmts =
1565
1581
stmts |> List.map ( function
1566
- | Class c when not c.isInterface ->
1567
- Class ( addConstructors c |> fst)
1582
+ | Class c when not c.isInterface -> Class ( addConstructors c |> fst)
1568
1583
| Module m -> Module { m with statements = go m.statements }
1584
+ | Global m -> Global { m with statements = go m.statements }
1569
1585
| x -> x)
1570
1586
go stmts
1571
1587
@@ -1629,6 +1645,7 @@ let introduceAdditionalInheritance (ctx: IContext<#TyperOptions>) (stmts: Statem
1629
1645
1630
1646
Class { c with implements = List.ofSeq inherits |> List.distinct }
1631
1647
| Module m -> Module { m with statements = go m.statements }
1648
+ | Global m -> Global { m with statements = go m.statements }
1632
1649
| x -> x
1633
1650
)
1634
1651
go stmts
@@ -1691,14 +1708,15 @@ let detectPatterns (stmts: Statement list) : Statement list =
1691
1708
else Some ( Class intf)
1692
1709
else Some ( Class intf)
1693
1710
| Module m -> Some ( Module { m with statements = go m.statements })
1711
+ | Global m -> Global { m with statements = go m.statements } |> Some
1694
1712
| x -> Some x
1695
1713
)
1696
1714
go stmts
1697
1715
1698
1716
let replaceAliasToFunction ( ctx : #IContext< #TyperOptions> ) stmts =
1699
1717
let rec go = function
1700
- | Module m ->
1701
- Module { m with statements = List.map go m.statements }
1718
+ | Module m -> Module { m with statements = List.map go m.statements }
1719
+ | Global m -> Global { m with statements = List.map go m.statements }
1702
1720
| TypeAlias ta ->
1703
1721
match ta.target with
1704
1722
| Func ( f, typrms, loc) ->
@@ -1852,6 +1870,7 @@ let mergeESLibDefinitions (srcs: SourceFile list) =
1852
1870
let vo , s = map None s.loc s
1853
1871
match s with
1854
1872
| Module m -> Module { m with statements = List.map mapStmt m.statements }
1873
+ | Global m -> Global { m with statements = List.map mapStmt m.statements }
1855
1874
| Enum e -> Enum { e with cases = e.cases |> List.map ( fun c -> map vo c.loc c |> snd) }
1856
1875
| Class c -> Class { c with members = c.members |> List.map ( fun ( a , m ) -> map vo a.loc a |> snd, m) }
1857
1876
| _ -> s
0 commit comments