on master help sign in
Use Localizer when showing REPL types
commit0551bffd6bfeab34a5683166b1826acbe2b5e08a authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 18 Apr 2018, 16:25 (9 years ago) parentb93555a
1 file changed+11−9
compiler/src/Generate/JavaScript.hs+11−9
compiler/src/Generate/JavaScript.hs+11−9
@@ -21,8 +21,6 @@ import qualified AST.Canonical as Can
2121import qualified AST.Optimized as Opt
2222import qualified AST.Module.Name as ModuleName
2323import qualified Data.Index as Index
24−import qualified Elm.Compiler.Type as Type
25−import qualified Elm.Compiler.Type.Extract as Extract
2624import qualified Elm.Interface as I
2725import qualified Elm.Name as N
2826import qualified Generate.JavaScript.Builder as JS
@@ -30,6 +28,8 @@ import qualified Generate.JavaScript.Expression as Expr
3028import qualified Generate.JavaScript.Name as Name
3129import qualified Generate.JavaScript.Mode as Mode
3230import qualified Reporting.Doc as D
31+import qualified Reporting.Render.Type as RT
32+import qualified Reporting.Render.Type.Localizer as L
3333
3434
3535
@@ -68,26 +68,28 @@ addMain mode graph home _ state =
6868-- GENERATE FOR REPL
6969
7070
71−generateForRepl :: Bool -> Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
72−generateForRepl ansi (Opt.Graph _ graph _) iface home name =
71+generateForRepl :: Bool -> L.Localizer -> Opt.Graph -> I.Interface -> ModuleName.Canonical -> N.Name -> B.Builder
72+generateForRepl ansi localizer (Opt.Graph _ graph _) iface home name =
7373 let
7474 mode = Mode.dev Mode.Client
7575 debugState = addGlobal mode graph emptyState (Opt.Global ModuleName.debug "toString")
7676 evalState = addGlobal mode graph debugState (Opt.Global home name)
7777 in
78− stateToBuilder evalState <> print ansi home name (I._types iface ! name)
78+ stateToBuilder evalState
79+ <>
80+ print ansi localizer home name (I._types iface ! name)
7981
8082
81−print :: Bool -> ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
82−print ansi home name annotation =
83+print :: Bool -> L.Localizer -> ModuleName.Canonical -> N.Name -> Can.Annotation -> B.Builder
84+print ansi localizer home name (Can.Forall _ tipe) =
8385 let
8486 value = Name.toBuilder (Name.fromGlobal home name)
8587 toString = Name.toBuilder (Name.fromKernel N.debug "toAnsiString")
86− tipe = Type.toDoc Type.None (Extract.fromAnnotation annotation)
88+ tipeDoc = RT.canToDoc localizer RT.None tipe
8789 bool = if ansi then "true" else "false"
8890 in
8991 "var _value = " <> toString <> "(" <> bool <> ", " <> value <> ");\n\
90− \var _type = " <> B.stringUtf8 (show (D.toString tipe)) <> ";\n\
92+ \var _type = " <> B.stringUtf8 (show (D.toString tipeDoc)) <> ";\n\
9193 \function _print(t) { console.log(_value + (" <> bool <> " ? '\x1b[90m' + t + '\x1b[0m' : t)); }\n\
9294 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
9395 \ _print('\\n : ' + _type.split('\\n').join('\\n '));\n\