File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,8 +94,12 @@ noOpts :: Term Bool
9494noOpts = value $ flag $ (optInfo [ " no-opts" ])
9595 { optDoc = " Skip the optimization phase." }
9696
97+ browserNamespace :: Term String
98+ browserNamespace = value $ opt " PS" $ (optInfo [ " browser-namespace" ])
99+ { optDoc = " Specify the namespace that PureScript modules will be exported to when running in the browser." }
100+
97101options :: Term P. Options
98- options = P. Options <$> tco <*> performRuntimeTypeChecks <*> magicDo <*> runMain <*> noOpts
102+ options = P. Options <$> tco <*> performRuntimeTypeChecks <*> magicDo <*> runMain <*> noOpts <*> browserNamespace
99103
100104stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath ])
101105stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ getPreludeFilename :: IO FilePath
3535getPreludeFilename = Paths. getDataFileName " prelude/prelude.purs"
3636
3737options :: P. Options
38- options = P. Options True False True True True
38+ options = P. Options True False True True True " PS "
3939
4040completion :: [P. Module ] -> CompletionFunc IO
4141completion ms = completeWord Nothing " \t\n\r " findCompletions
Original file line number Diff line number Diff line change @@ -67,4 +67,4 @@ compile opts ms = do
6767 Left " Main.main is undefined"
6868 return $ js ++ [JSApp (JSAccessor " main" (JSAccessor " Main" (JSVar " _ps" ))) [] ]
6969 | otherwise -> return js
70- return (prettyPrintJS [(wrapExportsContainer js')], exts, env)
70+ return (prettyPrintJS [(wrapExportsContainer opts js')], exts, env)
Original file line number Diff line number Diff line change @@ -342,10 +342,12 @@ statementToJs opts m e (If ifst) = ifToJs ifst
342342 elseToJs (ElseIf elif) = ifToJs elif
343343statementToJs opts m e (Return value) = JSReturn (valueToJs opts m e value)
344344
345- wrapExportsContainer :: [JS ] -> JS
346- wrapExportsContainer modules = JSApp (JSFunction Nothing [" _ps" ] $ JSBlock $ (JSStringLiteral " use strict" ) : modules) [exportSelector]
347- where exportSelector = JSConditional (JSBinary And (JSBinary NotEqualTo (JSTypeOf $ JSVar " module" ) (JSStringLiteral " undefined" )) (JSAccessor " exports" (JSVar " module" )))
345+ wrapExportsContainer :: Options -> [JS ] -> JS
346+ wrapExportsContainer opts modules = JSApp (JSFunction Nothing [" _ps" ] $ JSBlock $ (JSStringLiteral " use strict" ) : modules) [exportSelector]
347+ where
348+ exportSelector = JSConditional (JSBinary And (JSBinary NotEqualTo (JSTypeOf $ JSVar " module" ) (JSStringLiteral " undefined" )) (JSAccessor " exports" (JSVar " module" )))
348349 (JSAccessor " exports" (JSVar " module" ))
349350 (JSConditional (JSBinary NotEqualTo (JSTypeOf $ JSVar " window" ) (JSStringLiteral " undefined" ))
350- (JSAssignment (JSAccessor " PS " (JSVar " window" )) (JSBinary Or (JSAccessor " PS " (JSVar " window" )) (JSObjectLiteral [] )))
351+ (JSAssignment (JSAccessor browserNamespace (JSVar " window" )) (JSBinary Or (JSAccessor browserNamespace (JSVar " window" )) (JSObjectLiteral [] )))
351352 (JSApp (JSFunction Nothing [] $ JSBlock [JSThrow $ JSStringLiteral " PureScript doesn't know how to export modules in the current environment" ]) [] ))
353+ browserNamespace = optionsBrowserNamespace opts
Original file line number Diff line number Diff line change @@ -39,10 +39,15 @@ data Options = Options {
3939 -- Skip all optimizations
4040 --
4141 , optionsNoOptimizations :: Bool
42+ -- |
43+ -- Specify the namespace that PureScript modules will be exported to when running in the
44+ -- browser.
45+ --
46+ , optionsBrowserNamespace :: String
4247 } deriving Show
4348
4449-- |
4550-- Default compiler options
4651--
4752defaultOptions :: Options
48- defaultOptions = Options False False False False False
53+ defaultOptions = Options False False False False False " PS "
You can’t perform that action at this time.
0 commit comments