Skip to content

Program with non-trivial Flags type does not compile #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marc136 opened this issue Nov 15, 2020 · 2 comments
Closed

Program with non-trivial Flags type does not compile #3

marc136 opened this issue Nov 15, 2020 · 2 comments

Comments

@marc136
Copy link

marc136 commented Nov 15, 2020

Hello,

the following bug was created on my https://github.com/marc136/snowpack-plugin-elm/issues/3 by @andreasewering
And as I copied the code to turn the compiled elm code into an es module from your repository, I think the change should also be propagated into your tool.

I fixed it in my repo with this change.

Regards,
marc


Full description

When comipling the following file with npx elm-esm make src/DocumentWithFlags.elm --output=elm-esm-output.js, you can open the compiled js output and will notice that at the end the call to _Platform_export is not fully replaced.

module DocumentWithFlags exposing (main)

import Browser
import Html exposing (..)
import Json.Decode


type alias Flags =
    -- Json.Decode.Value -- this would work
    { test : String }


main : Program Flags Model Msg
main =
    Browser.document
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }


type alias Model =
    { property : String
    }


init : Flags -> ( Model, Cmd Msg )
init _ =
    ( Model "", Cmd.none )


type Msg
    = Msg1
    | Msg2


update : Msg -> Model -> ( Model, Cmd Msg )
update _ model =
    ( model, Cmd.none )


subscriptions : Model -> Sub Msg
subscriptions _ =
    Sub.none


view : Model -> Browser.Document Msg
view _ =
    { title = "Document Title"
    , body =
        [ h1 [] [ text "loaded" ] ]
    }

The output ends with the following lines:

var $author$project$DocumentWithFlags$main = $elm$browser$Browser$document(
	{init: $author$project$DocumentWithFlags$init, subscriptions: $author$project$DocumentWithFlags$subscriptions, update: $author$project$DocumentWithFlags$update, view: $author$project$DocumentWithFlags$view});
/*
_Platform_export({'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
	A2(
		$elm$json$Json$Decode$andThen,
		function (test) {
			return $elm$json$Json$Decode$succeed(
				{test: test});
*/
		},
		A2($elm$json$Json$Decode$field, 'test', $elm$json$Json$Decode$string)))(0)}});}(this));
export const Elm = {'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
	A2(
		$elm$json$Json$Decode$andThen,
		function (test) {
			return $elm$json$Json$Decode$succeed(
				{test: test};

But it should be:

var $author$project$DocumentWithFlags$main = $elm$browser$Browser$document(
	{au: $author$project$DocumentWithFlags$init, aB: $author$project$DocumentWithFlags$subscriptions, aD: $author$project$DocumentWithFlags$update, aE: $author$project$DocumentWithFlags$view});
/*
_Platform_export({'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
	A2(
		$elm$json$Json$Decode$andThen,
		function (test) {
			return $elm$json$Json$Decode$succeed(
				{ag: test});
		},
		A2($elm$json$Json$Decode$field, 'test', $elm$json$Json$Decode$string)))(0)}});}(this));
*/
export const Elm = {'DocumentWithFlags':{'init':$author$project$DocumentWithFlags$main(
	A2(
		$elm$json$Json$Decode$andThen,
		function (test) {
			return $elm$json$Json$Decode$succeed(
				{ag: test});
		},
		A2($elm$json$Json$Decode$field, 'test', $elm$json$Json$Decode$string)))(0)}});};
@ChristophP
Copy link
Owner

ChristophP commented Nov 16, 2020

Oh awesome, thanks for reporting this back and also providing the solution. 😄 I will make the adjustments.

@ChristophP
Copy link
Owner

Fixed in v1.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants