File tree Expand file tree Collapse file tree 4 files changed +38
-20
lines changed Expand file tree Collapse file tree 4 files changed +38
-20
lines changed Original file line number Diff line number Diff line change 3838
3939- Remove ignore in res_scanner.ml . https://github.com/rescript-lang/rescript/pull/7280
4040- Use the new stdlib modules in the analysis tests. https://github.com/rescript-lang/rescript/pull/7295
41- - Build with OCaml 5.3.0. https://github.com/rescript-lang/rescript-compiler/pull/7294
41+ - Build with OCaml 5.3.0. https://github.com/rescript-lang/rescript/pull/7294
42+ - Simplify JSON.Decode implementation. https://github.com/rescript-lang/rescript/pull/7304
4243
4344# 12.0.0-alpha.8
4445
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ function float(json) {
6969}
7070
7171function object ( json ) {
72- if ( typeof json === "object" && ! Array . isArray ( json ) && json !== null ) {
72+ if ( typeof json === "object" && json !== null && ! Array . isArray ( json ) ) {
7373 return json ;
7474 }
7575
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ function float(json) {
6969}
7070
7171function object ( json ) {
72- if ( typeof json === "object" && ! Array . isArray ( json ) && json !== null ) {
72+ if ( typeof json === "object" && json !== null && ! Array . isArray ( json ) ) {
7373 return json ;
7474 }
7575
Original file line number Diff line number Diff line change @@ -80,22 +80,39 @@ module Encode = {
8080}
8181
8282module Decode = {
83- let bool = (json : t ) =>
84- Stdlib_Type .typeof (json ) === #boolean ? Some ((Obj .magic (json ): bool )) : None
85- let null = (json : t ) => Obj .magic (json ) === Stdlib_Null .null ? Some (Stdlib_Null .null ) : None
86- let string = (json : t ) =>
87- Stdlib_Type .typeof (json ) === #string ? Some ((Obj .magic (json ): string )) : None
88- let float = (json : t ) =>
89- Stdlib_Type .typeof (json ) === #number ? Some ((Obj .magic (json ): float )) : None
90- let object = (json : t ) =>
91- if (
92- Stdlib_Type .typeof (json ) === #object &&
93- ! Stdlib_Array .isArray (json ) &&
94- ! (Obj .magic (json ) === Stdlib_Null .null )
95- ) {
96- Some ((Obj .magic (json ): dict <t >))
97- } else {
98- None
83+ let bool = json =>
84+ switch json {
85+ | Boolean (b ) => Some (b )
86+ | _ => None
87+ }
88+
89+ let null = json =>
90+ switch json {
91+ | Null => Some (Stdlib_Null .null )
92+ | _ => None
93+ }
94+
95+ let string = json =>
96+ switch json {
97+ | String (s ) => Some (s )
98+ | _ => None
99+ }
100+
101+ let float = json =>
102+ switch json {
103+ | Number (f ) => Some (f )
104+ | _ => None
105+ }
106+
107+ let object = json =>
108+ switch json {
109+ | Object (o ) => Some (o )
110+ | _ => None
111+ }
112+
113+ let array = (json : t ) =>
114+ switch json {
115+ | Array (a ) => Some (a )
116+ | _ => None
99117 }
100- let array = (json : t ) => Stdlib_Array .isArray (json ) ? Some ((Obj .magic (json ): array <t >)) : None
101118}
You can’t perform that action at this time.
0 commit comments