Skip to content

Commit 2ef575e

Browse files
authored
Merge pull request #314 from ocsigen/fix-312
Fix a bug which caused optional properties not to be recognized as optional (#312)
2 parents 4a8a02d + a8d80ee commit 2ef575e

File tree

4 files changed

+15
-960
lines changed

4 files changed

+15
-960
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
- Fix a bug which caused optional properties not to be recognized as optional (#312).
9+
710
## [1.4.4] - 2022-05-09
811
- Fix a bug which caused ts2ocaml to crash when encountering an optional field with type `null | undefined`.
912

build.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ let setup () =
7777

7878
Target.create "TestComplete" ignore
7979

80+
"Clean" ?=> "Build"
81+
8082
"Clean"
81-
==> "YarnInstall"
83+
?=> "YarnInstall"
8284
==> "Restore"
8385
==> "Prepare"
84-
==> "Build"
86+
?=> "Build"
8587

8688
"Prepare"
8789
?=> "BuildForTest"
@@ -247,7 +249,8 @@ let main argv =
247249
Publish.setup ()
248250

249251
Target.create "All" ignore
250-
"Build"
252+
"Prepare"
253+
==> "Build"
251254
==> "Test"
252255
==> "Publish"
253256
==> "All"

lib/Parser.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ module private ParserImpl =
571571
| UnknownType None ->
572572
nodeWarn ctx nd "type not specified for field '%s'" (getText nd.name)
573573
| _ -> ()
574-
let fl = { name = name; isOptional = false; value = ty }
574+
let isOptional = nd.questionToken |> Option.isSome
575+
let fl = { name = name; isOptional = isOptional; value = ty }
575576
attr, Field (fl, (if isReadOnly nd.modifiers then ReadOnly else Mutable))
576577
| None ->
577578
match getPropertyExpression nd.name with
@@ -590,7 +591,8 @@ module private ParserImpl =
590591
| UnknownType None ->
591592
nodeWarn ctx nd "type not specified for field '%s'" (getText nd.name)
592593
| _ -> ()
593-
let fl = { name = name; isOptional = false; value = ty }
594+
let isOptional = nd.questionToken |> Option.isSome
595+
let fl = { name = name; isOptional = isOptional; value = ty }
594596
attr, Field (fl, (if isReadOnly nd.modifiers then ReadOnly else Mutable))
595597
| None -> nodeWarn ctx nd "unsupported property name '%s' in PropertyDeclaration" (getText nd.name); (attr, UnknownMember (Some (getText nd)))
596598
| Kind.CallSignature ->
@@ -640,7 +642,8 @@ module private ParserImpl =
640642
| Some name ->
641643
let localTyprm, ty = extractType nd
642644
if not (List.isEmpty localTyprm) then nodeWarn ctx nd "getter with type argument is not supported"
643-
let fl = { name = name; isOptional = false; value = ty }
645+
let isOptional = nd.questionToken |> Option.isSome
646+
let fl = { name = name; isOptional = isOptional; value = ty }
644647
attr, Getter fl
645648
| None -> nodeWarn ctx nd "unsupported property name '%s' in GetAccessor" (getText nd.name); (attr, UnknownMember (Some (getText nd)))
646649
| Kind.SetAccessor ->

0 commit comments

Comments
 (0)