Add type information to the nodes of an elm-syntax tree.
⚠️ You should not rely on this for anything serious right now! It might still have bugs (e.g. recursive substitutions of identity type aliases) and it's also slow: for 10k lines, expect 0.2-2s depending on the amount of un-annotated declarations (report if you have other numbers)
The purpose of publishing this early is for easy use in personal experiments and for especially interested folks to check API, documentation etc.
import Elm.Syntax.Node
import Elm.Syntax.Expression
import ElmSyntaxTypeInfer
[ { declaration =
Elm.Syntax.Node.empty
{ expression =
Elm.Syntax.Node.empty
(Elm.Syntax.Expression.ListExpr
[ Elm.Syntax.Node.empty
(Elm.Syntax.Expression.Integer 1)
]
)
, name = Elm.Syntax.Node.empty "majorVersions"
, arguments = []
}
, signature = Nothing
, documentation = Nothing
}
]
|> ElmSyntaxTypeInfer.valueAndFunctionDeclarations
{ importedTypes = ElmSyntaxTypeInfer.elmCoreTypes
, moduleOriginLookup = exampleModuleOriginLookup
, otherModuleDeclaredTypes =
[]
|> ElmSyntaxTypeInfer.moduleDeclarationsToTypes
exampleModuleOriginLookup
|> .types
}
-->
Ok
(FastDict.singleton "majorVersions"
{ type_ =
ElmSyntaxTypeInfer.TypeNotVariable
(ElmSyntaxTypeInfer.TypeConstruct
{ moduleOrigin = [ "List" ]
, name = "List"
, arguments =
[ ElmSyntaxTypeInfer.TypeVariable "number" ]
}
)
...
}
)
exampleModuleOriginLookup : ElmSyntaxTypeInfer.ModuleOriginLookup
exampleModuleOriginLookup =
[]
|> ElmSyntaxTypeInfer.importsToModuleOriginLookup
ElmSyntaxTypeInfer.elmCoreTypes