Skip to content

Commit

Permalink
#159 warn on some problematic tags in template instantiations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Oct 20, 2022
1 parent bc5ddf0 commit e4ca0e3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions WebSharper.UI.Templating.Common/Parsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,20 @@ let transitiveClosure err (direct: Map<'A, Set<'A>>) : Map<'A, Set<'A>> =
||> Map.add k
Map.foldBack (closureOf []) direct Map.empty

let private warnOnHoleNames =
HashSet [|
"html"
"base"
"head"
"link"
"meta"
"style"
"body"
|]

let private checkInstantiations (items: ParseItem[]) =
for item in items do
item.Templates |> Seq.iter (fun (KeyValue(_, t)) ->
item.Templates |> Seq.iter (fun (KeyValue(tn, t)) ->
let rec checkNode = function
| Node.DocHole _
| Node.Text _ -> ()
Expand All @@ -649,7 +660,10 @@ let private checkInstantiations (items: ParseItem[]) =
|> Option.bind (fun it -> it.Templates.TryFind (WrappedTemplateName.OfOption templateName))
|> Option.iter (fun t' ->
let fail holeId fmt = failwithf fmt (defaultArg fileName "") (defaultArg templateName "") holeId
let findAndTest test holeId =
let findAndTest test (holeId: string) =
if warnOnHoleNames.Contains(holeId.ToLowerInvariant()) then
eprintfn "WebSharper.UI warning WS9002: Special html tag name '%s' should not be used as hole name%s" holeId
(match tn.NameAsOption with Some n -> " in template " + n | _ -> "")
match t'.Holes.TryGetValue holeId with
| false, _ -> fail holeId "Instantiation of %s/%s fills hole that doesn't exist: %s."
| true, { Kind = kind } -> test kind
Expand Down

0 comments on commit e4ca0e3

Please sign in to comment.