@@ -6,15 +6,11 @@ import Ace (Annotation)
66import Control.Monad.Except (runExceptT )
77import Data.Array (fold )
88import Data.Array as Array
9- import Data.Either (Either (..), either )
9+ import Data.Either (Either (..))
1010import Data.Foldable (for_ , oneOf )
1111import Data.FoldableWithIndex (foldMapWithIndex )
1212import Data.Maybe (Maybe (..), fromMaybe , isNothing )
1313import Data.Symbol (SProxy (..))
14- import Data.String as String
15- import Data.String (Pattern (..))
16- import Data.String.Regex as Regex
17- import Data.String.Regex.Flags as RegexFlags
1814import Effect (Effect )
1915import Effect.Aff (Aff , makeAff )
2016import Effect.Aff as Aff
@@ -24,7 +20,6 @@ import Halogen as H
2420import Halogen.HTML as HH
2521import Halogen.HTML.Events as HE
2622import Halogen.HTML.Properties as HP
27- import Partial.Unsafe (unsafeCrashWith )
2823import Try.API (CompileError (..), CompileResult (..), CompilerError , ErrorPosition )
2924import Try.API as API
3025import Try.Config as Config
@@ -168,6 +163,10 @@ component = H.mkComponent
168163 H .liftEffect $ error err
169164 H .modify_ _ { compiled = Just (Left err) }
170165
166+ Right (Right res@(BundleFailed _)) -> do
167+ H .liftEffect teardownIFrame
168+ H .modify_ _ { compiled = Just (Right res) }
169+
171170 Right (Right res@(CompileFailed { error })) -> do
172171 H .liftEffect teardownIFrame
173172 H .modify_ _ { compiled = Just (Right res) }
@@ -182,7 +181,7 @@ component = H.mkComponent
182181 _ <- H .query _editor unit $ H .tell $ Editor.AddMarker MarkerError pos
183182 pure unit
184183
185- Right (Right res@(CompileSuccess { js , warnings })) -> do
184+ Right (Right res@(CompileSuccess { bundled, unbundled , warnings })) -> do
186185 { settings } <- H .get
187186 if settings.showJs then
188187 H .liftEffect teardownIFrame
@@ -192,20 +191,7 @@ component = H.mkComponent
192191 _ <- H .query _editor unit $ H .tell $ Editor.SetAnnotations anns
193192 pure unit
194193 let
195- importRegex :: Regex.Regex
196- importRegex = either (\_ -> unsafeCrashWith " Invalid regex" ) identity
197- $ Regex .regex """ ^import (.+) from "../([^"]+)";$""" RegexFlags .noFlags
198- replacement = " import $1 from \" " <> Config .loaderUrl <> " /$2\" ;"
199- codeFixImports = js
200- # String .split (Pattern " \n " )
201- # map (Regex .replace importRegex replacement)
202- finalCode = String .joinWith " \n " $ codeFixImports <>
203- [ " "
204- , " "
205- , " main();" -- actually call the `main` function
206- ]
207-
208- eventData = { code: finalCode }
194+ eventData = { code: bundled }
209195 H .liftEffect teardownIFrame
210196 H .liftAff $ makeAff \f -> do
211197 runEffectFn3 setupIFrame eventData (f (Right unit)) (f (Left $ Aff .error " Could not load iframe" ))
@@ -396,14 +382,16 @@ component = H.mkComponent
396382 Left err ->
397383 renderPlaintext err
398384 Right res -> case res of
385+ BundleFailed { bundleFailed } -> do
386+ renderPlaintext bundleFailed
399387 CompileFailed { error } -> case error of
400388 OtherError err ->
401389 renderPlaintext err
402390 CompilerErrors errs ->
403391 HH .div_ $ renderCompilerErrors errs
404- CompileSuccess { js } ->
392+ CompileSuccess { unbundled } ->
405393 whenElem state.settings.showJs \_ ->
406- renderPlaintext js
394+ renderPlaintext unbundled
407395
408396whenElem :: forall w i . Boolean -> (Unit -> HH.HTML w i ) -> HH.HTML w i
409397whenElem cond f = if cond then f unit else HH .text " "
0 commit comments