WebSharper

This may not be a bug, if WebSharper is not intended to be used this way, but here it is.

I have a form with code that includes a function the requires WebSharper.Collections.js

1
  let addClass    (classes:string) (add:string) = classes.Split ' ' |> Set.ofSeq |> Set.union  (Set.ofSeq <| add.Split ' ') |> String.concat " "

this function is not actually used in the form, and so WebSharper.Collections.js is not included.

Later on a dynamically compiled module calls this function, the function fails with error:

1
test.js:488 Uncaught TypeError: Cannot read property 'New$1' of undefined

on this line:

1
2
3
4
5
6
Val.addClass=function(classes,add)
  {
  var s,x,e,s$1,e$1;
  s=(x=(e=Strings.SplitChars(classes,[32],0),new FSharpSet.New$1(BalancedTree.OfSeq(e))),(s$1=(e$1=Strings.SplitChars(add,[32],0),new FSharpSet.New$1(BalancedTree.OfSeq(e$1))),new FSharpSet.New$1(BalancedTree.OfSeq(Seq.append(s$1,x)))));
  return Strings.concat(" ",s);
 };

because FSharpSet is undefined.

The workaround is really simple, I just need to include a call to the function in the form. This is a rare case and only happens because a module is loaded later on You may want to take a look at this case, but it is low priority.