faylang / fay

A proper subset of Haskell that compiles to JavaScript
https://github.com/faylang/fay/wiki
BSD 3-Clause "New" or "Revised" License
1.29k stars 86 forks source link

Multiple --strict modules clobber Strict #346

Closed kfish closed 10 years ago

kfish commented 10 years ago

The javascript generated by --strict includes:

var Strict = {};

If I generate two such modules and include both, then all the Strict.* objects declared by the first module are clobbered by the second:

...
var Module1 = {}:
var Strict = {};
Strict.Module1 = // module 1 defs
...
var Module2 = {};
var Strict = {};  // <-- *module 1 defs clobbered here*
Strict.Module2 = // module 2 defs
bergmark commented 10 years ago

I thought I just used the same code as for modules generation there, but nope.

I probably won't have time to fix this until next week. If you want to take a stab at it, there's a function createModulePath :: ModuleName a -> Compile [JsStmt] in Fay.Compiler that solves the override issues for normal modules, generateStrictExports should use that as well.

Another related problem would be if you have --strict A.B A or --strict A A.B. createModulePath handles that as well.

kfish commented 10 years ago

nb. this issue refers to separately generating two javascript files and including both from some html. In the output of a single fay invocation:

fay A.hs --strict A,B

(where A.hs imports B.hs) only one "var Strict = {}" is generated.

bergmark commented 10 years ago

Oh. There is no way for Fay to know this during compilation then. So it would have to defer all these checks to the runtime, unless #347 is fixed and used. It's vaguely related to #330.

kfish commented 10 years ago

Right, I was generating multiple javascript output files because i couldn't work out how to generate one file containing both modules (ie. #347).

When I posted this issue I thought it might be worth adding options to generate non-standalone --strict stub files which could then be individually sourced, but I agree it's cleaner to just generate one combined js file.