File tree 2 files changed +21
-9
lines changed
2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -101,16 +101,16 @@ export const value = {
101
101
* @returns {* }
102
102
*/
103
103
decode ( value : Value ) : JsonValue {
104
- if ( value . listValue ) {
105
- return list . decode ( value . listValue ) ;
104
+ switch ( value . kind ) {
105
+ case 'listValue' :
106
+ return list . decode ( value . listValue ) ;
107
+ case 'structValue' :
108
+ return struct . decode ( value . structValue ) ;
109
+ case 'nullValue' :
110
+ return null ;
111
+ default :
112
+ return value [ value . kind ] as JsonValue ;
106
113
}
107
- if ( value . structValue ) {
108
- return struct . decode ( value . structValue ) ;
109
- }
110
- if ( typeof value . nullValue !== 'undefined' ) {
111
- return null ;
112
- }
113
- return value [ value . kind ] as JsonValue ;
114
114
}
115
115
} ;
116
116
Original file line number Diff line number Diff line change @@ -169,6 +169,18 @@ test('value.decode - boolValue', t => {
169
169
t . is ( actual , true ) ;
170
170
} ) ;
171
171
172
+ // https://github.com/callmehiphop/pb-util/issues/5
173
+ test ( 'value.decode - multiple values' , t => {
174
+ const encodedValue = {
175
+ kind : 'stringValue' ,
176
+ stringValue : 'foo' ,
177
+ nullValue : 0
178
+ } ;
179
+
180
+ const actual = value . decode ( encodedValue ) ;
181
+ t . is ( actual , 'foo' ) ;
182
+ } ) ;
183
+
172
184
test ( 'list.encode' , t => {
173
185
const actual = list . encode ( arr ) ;
174
186
t . deepEqual ( actual , listValue ) ;
You can’t perform that action at this time.
0 commit comments