Skip to content
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

Fix parsing error when there are no parens around = in a type alias declaration #116

Merged
merged 7 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Elm/Parser/Declarations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ letDestructuringDeclarationWithPattern p =
succeed (LetDestructuring p)
|> Combine.ignore (maybe Layout.layout)
|> Combine.ignore (string "=")
|> Combine.ignore Layout.layout
|> Combine.ignore (maybe Layout.layout)
|> Combine.andMap expression
)

Expand Down
4 changes: 2 additions & 2 deletions src/Elm/Parser/Typings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ typeDefinition =
(Combine.choice
[ succeed (TypeAlias Nothing)
|> Combine.ignore (string "alias" |> Combine.continueWith Layout.layout)
|> Combine.andMap (Node.parser typeName |> Combine.ignore Layout.layout)
|> Combine.andMap (Node.parser typeName |> Combine.ignore (maybe Layout.layout))
|> Combine.andMap genericList
|> Combine.ignore (string "=")
|> Combine.ignore Layout.layout
|> Combine.ignore (maybe Layout.layout)
|> Combine.andMap typeAnnotation
|> Combine.map
(\typeAlias ->
Expand Down
2 changes: 1 addition & 1 deletion src/Elm/Syntax/Expression.elm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type alias LetBlock =
}


{-| Union type for all possible declations in a let block
{-| Union type for all possible declarations in a let block
-}
type LetDeclaration
= LetFunction Function
Expand Down
40 changes: 40 additions & 0 deletions tests/tests/Elm/Parser/DeclarationsTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,46 @@ all =
}
}
)
, test "let destructuring with no spaces around '='" <|
\() ->
parseFullStringWithNullState "foo =\n let\n (b, c)=(1, 2)\n in\n b" Parser.function
|> Maybe.map Node.value
|> Maybe.map noRangeDeclaration
|> Expect.equal
(Just <|
FunctionDeclaration
{ signature = Nothing
, documentation = Nothing
, declaration =
Node emptyRange <|
{ name = Node emptyRange "foo"
, arguments = []
, expression =
Node emptyRange <|
LetExpression
{ declarations =
[ Node emptyRange <|
LetDestructuring
(Node emptyRange
(TuplePattern
[ Node emptyRange (VarPattern "b")
, Node emptyRange (VarPattern "c")
]
)
)
(Node emptyRange
(TupledExpression
[ Node emptyRange (Integer 1)
, Node emptyRange (Integer 2)
]
)
)
]
, expression = Node emptyRange <| FunctionOrValue [] "b"
}
}
}
)
, test "declaration with record" <|
\() ->
parseFullStringWithNullState "main =\n beginnerProgram { model = 0, view = view, update = update }" Parser.function
Expand Down
20 changes: 20 additions & 0 deletions tests/tests/Elm/Parser/TypingsTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ all =
]
}
)
, test "type alias without spacings around '='" <|
\() ->
parseFullStringWithNullState "type alias Foo={color: String }" Parser.typeDefinition
|> Maybe.andThen asTypeAlias
|> Maybe.map noRangeTypeAlias
|> Expect.equal
(Just <|
{ documentation = Nothing
, name = Node emptyRange "Foo"
, generics = []
, typeAnnotation =
Node emptyRange <|
Record
[ Node emptyRange <|
( Node emptyRange <| "color"
, Node emptyRange <| Typed (Node emptyRange <| ( [], "String" )) []
)
]
}
)
, test "type alias with GenericType " <|
\() ->
parseFullStringWithNullState "type alias Foo a = {some : a }" Parser.typeDefinition
Expand Down