Skip to content

Commit

Permalink
#1301 fix metadata for bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Dec 19, 2022
1 parent 7e860c2 commit b404272
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
35 changes: 27 additions & 8 deletions src/compiler/WebSharper.Compiler/Compilation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Compilation(meta: Info, ?hasGraph) =
let notResolvedInterfaces = Dictionary<TypeDefinition, NotResolvedInterface>()
let notResolvedClasses = Dictionary<TypeDefinition, NotResolvedClass>()
let proxies = Dictionary<TypeDefinition, TypeDefinition>()
let internalProxies = HashSet<TypeDefinition>()
let internalProxies = Dictionary<TypeDefinition, TypeDefinition>()

let classes = MergedDictionary meta.Classes
let interfaces = MergedDictionary meta.Interfaces
Expand Down Expand Up @@ -404,14 +404,33 @@ type Compilation(meta: Info, ?hasGraph) =
ExtraBundles = this.CurrentExtraBundles
}

member this.RemoveInternalProxies(meta) =
member this.HideInternalProxies(meta) =
if internalProxies.Count > 0 then
let withoutInternalProxies d =
d |> Dict.filter (fun t _ -> not (internalProxies.Contains(t)))
let updateType t =
match internalProxies.TryGetValue(t) with
| true, p -> p
| _ -> t
let updateNode n =
match n with
| MethodNode (td, m) ->
MethodNode(updateType td, m)
| ConstructorNode (td, c) ->
ConstructorNode(updateType td, c)
| ImplementationNode (td, i, m) ->
ImplementationNode (updateType td, updateType i, m)
| AbstractMethodNode (td, m) ->
AbstractMethodNode (updateType td, m)
| TypeNode td ->
TypeNode (updateType td)
| _ -> n
{ meta with
Interfaces = meta.Interfaces |> withoutInternalProxies
Classes = meta.Classes |> withoutInternalProxies
CustomTypes = meta.CustomTypes |> withoutInternalProxies
Interfaces = meta.Interfaces |> Dict.mapKeys updateType
Classes = meta.Classes |> Dict.mapKeys updateType
CustomTypes = meta.CustomTypes |> Dict.mapKeys updateType
Dependencies =
{ meta.Dependencies with
Nodes = meta.Dependencies.Nodes |> Array.map updateNode
}
}
else
meta
Expand All @@ -436,7 +455,7 @@ type Compilation(meta: Info, ?hasGraph) =
else
proxies.Add(tProxy, tTarget)
if isInternal then
internalProxies.Add(tTarget) |> ignore
internalProxies.Add(tTarget, tProxy) |> ignore

member this.ResolveProxySignature (meth: Method) =
if proxies.Count = 0 then meth else
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/WebSharper.Compiler/FrontEnd.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let CreateResources (logger: LoggerBase) (comp: Compilation option) (refMeta: M.

let currentPosFixed =
match comp with
| Some c -> c.RemoveInternalProxies currentPosFixed
| Some c -> c.HideInternalProxies currentPosFixed
| _ -> currentPosFixed

logger.TimedStage "Source position transformations"
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/WebSharper.Core/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ module Dict =
r.Add(k, mapping v)
r

/// Map keys of an IDictionary
let mapKeys mapping (d: IDictionary<_,_>) =
let r = Dictionary() :> IDictionary<_,_>
for KeyValue(k, v) in d do
r.Add(mapping k, v)
r

exception UnionError of key: obj with
override this.Message = failwithf "Error merging dictionaries on key: %A" this.key

Expand Down

0 comments on commit b404272

Please sign in to comment.