Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Fix a bug which caused optional properties not to be recognized as optional (#312).

## [1.4.4] - 2022-05-09
- Fix a bug which caused ts2ocaml to crash when encountering an optional field with type `null | undefined`.

Expand Down
9 changes: 6 additions & 3 deletions build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ let setup () =

Target.create "TestComplete" ignore

"Clean" ?=> "Build"

"Clean"
==> "YarnInstall"
?=> "YarnInstall"
==> "Restore"
==> "Prepare"
==> "Build"
?=> "Build"

"Prepare"
?=> "BuildForTest"
Expand Down Expand Up @@ -247,7 +249,8 @@ let main argv =
Publish.setup ()

Target.create "All" ignore
"Build"
"Prepare"
==> "Build"
==> "Test"
==> "Publish"
==> "All"
Expand Down
9 changes: 6 additions & 3 deletions lib/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ module private ParserImpl =
| UnknownType None ->
nodeWarn ctx nd "type not specified for field '%s'" (getText nd.name)
| _ -> ()
let fl = { name = name; isOptional = false; value = ty }
let isOptional = nd.questionToken |> Option.isSome
let fl = { name = name; isOptional = isOptional; value = ty }
attr, Field (fl, (if isReadOnly nd.modifiers then ReadOnly else Mutable))
| None ->
match getPropertyExpression nd.name with
Expand All @@ -590,7 +591,8 @@ module private ParserImpl =
| UnknownType None ->
nodeWarn ctx nd "type not specified for field '%s'" (getText nd.name)
| _ -> ()
let fl = { name = name; isOptional = false; value = ty }
let isOptional = nd.questionToken |> Option.isSome
let fl = { name = name; isOptional = isOptional; value = ty }
attr, Field (fl, (if isReadOnly nd.modifiers then ReadOnly else Mutable))
| None -> nodeWarn ctx nd "unsupported property name '%s' in PropertyDeclaration" (getText nd.name); (attr, UnknownMember (Some (getText nd)))
| Kind.CallSignature ->
Expand Down Expand Up @@ -640,7 +642,8 @@ module private ParserImpl =
| Some name ->
let localTyprm, ty = extractType nd
if not (List.isEmpty localTyprm) then nodeWarn ctx nd "getter with type argument is not supported"
let fl = { name = name; isOptional = false; value = ty }
let isOptional = nd.questionToken |> Option.isSome
let fl = { name = name; isOptional = isOptional; value = ty }
attr, Getter fl
| None -> nodeWarn ctx nd "unsupported property name '%s' in GetAccessor" (getText nd.name); (attr, UnknownMember (Some (getText nd)))
| Kind.SetAccessor ->
Expand Down
Loading