File tree 4 files changed +38
-20
lines changed
4 files changed +38
-20
lines changed Original file line number Diff line number Diff line change 38
38
39
39
- Remove ignore in res_scanner.ml . https://github.com/rescript-lang/rescript/pull/7280
40
40
- 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
42
43
43
44
# 12.0.0-alpha.8
44
45
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ function float(json) {
69
69
}
70
70
71
71
function object ( json ) {
72
- if ( typeof json === "object" && ! Array . isArray ( json ) && json !== null ) {
72
+ if ( typeof json === "object" && json !== null && ! Array . isArray ( json ) ) {
73
73
return json ;
74
74
}
75
75
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ function float(json) {
69
69
}
70
70
71
71
function object ( json ) {
72
- if ( typeof json === "object" && ! Array . isArray ( json ) && json !== null ) {
72
+ if ( typeof json === "object" && json !== null && ! Array . isArray ( json ) ) {
73
73
return json ;
74
74
}
75
75
Original file line number Diff line number Diff line change @@ -80,22 +80,39 @@ module Encode = {
80
80
}
81
81
82
82
module 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
99
117
}
100
- let array = (json : t ) => Stdlib_Array .isArray (json ) ? Some ((Obj .magic (json ): array <t >)) : None
101
118
}
You can’t perform that action at this time.
0 commit comments