Skip to content

Commit

Permalink
#1372 recognize UI's Content.Page
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Apr 15, 2024
1 parent df11d58 commit 603580f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/compiler/WebSharper.Compiler.CSharp/CodeReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2778,6 +2778,12 @@ let contentType =
FullName = "WebSharper.Sitelets.Content`1"
}

let uiContentType =
TypeDefinition {
Assembly = "WebSharper.UI"
FullName = "WebSharper.UI.Server.Content"
}

exception BundleFail of message: string with
override this.ToString() = this.message

Expand All @@ -2791,7 +2797,7 @@ let scanExpression (env: Environment) (node: SyntaxNode) =
[ value ]
| _ ->
raise <| BundleFail $"Content.Bundle argument must be constant string %s{m.Value.MethodName} %O{arguments[1]}"
elif typ = contentType && m.Value.MethodName.StartsWith "Page" then
elif (typ = contentType || typ = uiContentType) && m.Value.MethodName.StartsWith "Page" then
match env.SemanticModel.GetConstantValue(Seq.last arguments).Value with
| :? string as value when value <> null ->
[ value ]
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/WebSharper.Compiler.FSharp/CodeReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,12 @@ let contentModule =
FullName = "WebSharper.Sitelets.ContentModule"
}

let uiContentType =
TypeDefinition {
Assembly = "WebSharper.UI"
FullName = "WebSharper.UI.Server.Content"
}

let contentType =
TypeDefinition {
Assembly = "WebSharper.Sitelets"
Expand All @@ -1340,7 +1346,7 @@ let getBundleMethod (typ: TypeDefinition, m: Method, arguments: FSharpExpr list)
[ string value ]
| a ->
raise <| BundleFail $"Content.Bundle argument must be constant string %s{m.Value.MethodName} %A{a}"
elif typ = contentType && m.Value.MethodName.StartsWith "Page" then
elif (typ = contentType || typ = uiContentType) && m.Value.MethodName.StartsWith "Page" then
match arguments |> List.last with
| P.NewUnionCase (_, c, [ P.Const (value, _) ]) when c.Name = "Some" ->
[ string value ]
Expand Down

0 comments on commit 603580f

Please sign in to comment.